91 lines
2.8 KiB
Java
91 lines
2.8 KiB
Java
package io.as.modules.openapi.controller;
|
|||
|
|
|
||
|
|
import io.as.common.annotation.AuditAction;
|
||
|
|
import io.as.common.exception.ASException;
|
||
|
|
import io.as.common.utils.PageUtils;
|
||
|
|
import io.as.common.utils.R;
|
||
|
|
import io.as.modules.openapi.service.PartnerCardPoolService;
|
||
|
|
import io.swagger.annotations.Api;
|
||
|
|
import io.swagger.annotations.ApiOperation;
|
||
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
||
|
|
import org.springframework.web.bind.annotation.*;
|
||
|
|
|
||
|
|
import java.util.HashMap;
|
||
|
|
import java.util.Map;
|
||
|
|
|
||
|
|
/**
|
||
|
|
* 合作伙伴天卡池(代销)
|
||
|
|
*/
|
||
|
|
@Api(tags = "合作伙伴天卡池(代销)")
|
||
|
|
@RestController
|
||
|
|
@RequestMapping("/manage/partner-card")
|
||
|
|
public class PartnerCardPurchaseController {
|
||
|
|
|
||
|
|
@Autowired
|
||
|
|
private PartnerCardPoolService partnerCardPoolService;
|
||
|
|
|
||
|
|
/**
|
||
|
|
* 采购天卡到合作伙伴池子
|
||
|
|
*/
|
||
|
|
@ApiOperation("采购天卡")
|
||
|
|
@AuditAction(value = "PARTNER_CARD_PURCHASE", description = "采购天卡到合作伙伴池子")
|
||
|
|
@PostMapping("/purchase")
|
||
|
|
public R purchase(@RequestParam("partnerId") String partnerId,
|
||
|
|
@RequestParam("quantity") int quantity) {
|
||
|
|
if (partnerId == null || partnerId.trim().isEmpty()) {
|
||
|
|
throw new ASException("partnerId不能为空");
|
||
|
|
}
|
||
|
|
if (quantity <= 0) {
|
||
|
|
throw new ASException("quantity必须大于0");
|
||
|
|
}
|
||
|
|
int purchased = partnerCardPoolService.purchase(partnerId, quantity);
|
||
|
|
Map<String, Object> data = new HashMap<>();
|
||
|
|
data.put("purchased", purchased);
|
||
|
|
return R.dataSuccess(data);
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* 库存查询
|
||
|
|
*/
|
||
|
|
@ApiOperation("库存查询")
|
||
|
|
@GetMapping("/stock")
|
||
|
|
public R stock(@RequestParam("partnerId") String partnerId) {
|
||
|
|
int count = partnerCardPoolService.getAvailableCount(partnerId);
|
||
|
|
Map<String, Object> data = new HashMap<>();
|
||
|
|
data.put("available", count);
|
||
|
|
return R.dataSuccess(data);
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* 分页查询池子记录
|
||
|
|
*/
|
||
|
|
@ApiOperation("分页查询池子记录")
|
||
|
|
@GetMapping("/list")
|
||
|
|
public R list(@RequestParam Map<String, Object> params) {
|
||
|
|
PageUtils page = partnerCardPoolService.queryPage(params);
|
||
|
|
Map<String, Object> data = new HashMap<>();
|
||
|
|
data.put("page", page);
|
||
|
|
return R.dataSuccess(data);
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* 回退天卡:把partner池子里未消耗(AVAILABLE)的天卡回退到平台天卡池
|
||
|
|
*/
|
||
|
|
@ApiOperation("回退天卡")
|
||
|
|
@AuditAction(value = "PARTNER_CARD_REVERT", description = "回退天卡到平台池子")
|
||
|
|
@PostMapping("/revert")
|
||
|
|
public R revert(@RequestParam("partnerId") String partnerId,
|
||
|
|
@RequestParam("quantity") int quantity) {
|
||
|
|
if (partnerId == null || partnerId.trim().isEmpty()) {
|
||
|
|
throw new ASException("partnerId不能为空");
|
||
|
|
}
|
||
|
|
if (quantity <= 0) {
|
||
|
|
throw new ASException("回退数量必须大于0");
|
||
|
|
}
|
||
|
|
int reverted = partnerCardPoolService.revert(partnerId, quantity);
|
||
|
|
Map<String, Object> data = new HashMap<>();
|
||
|
|
data.put("reverted", reverted);
|
||
|
|
return R.dataSuccess(data);
|
||
|
|
}
|
||
|
|
}
|