耗材 开关

This commit is contained in:
2026-04-01 10:38:55 +08:00
parent a5fdb6eac7
commit fb0b74a0cb
6 changed files with 65 additions and 38 deletions

View File

@@ -164,6 +164,22 @@ public class ConsInfoController {
return CzgResult.success();
}
/**
* 退款退回开关
*
* @param id 耗材信息id
*/
@PostMapping("onOffIsRefundStock")
@OperationLog("耗材信息-退款退回开关")
//@SaAdminCheckPermission("consInfo:on-off")
public CzgResult<Void> onOffIsRefundStock(@RequestParam Long id, @RequestParam Integer isRefundStockConsInfo) {
//效验数据
AssertUtil.isNull(id, "{}不能为空", "id");
AssertUtil.isNull(isRefundStockConsInfo, "退款退回开关值不能为空");
consInfoService.isRefundStockConsInfo(id, isRefundStockConsInfo);
return CzgResult.success();
}
/**
* 编辑副单位
*/

View File

@@ -76,6 +76,10 @@ public class ConsInfoDTO implements Serializable {
* 是否检测耗材: 1 检测 0 不检测
*/
private Integer isStock;
/**
* 是否退款退回: 1 退回 0 不退回
*/
private Integer isRefundStock;
/**
* 第二单位
*/

View File

@@ -69,6 +69,10 @@ public class ConsInfo implements Serializable {
* 是否检测耗材: 1 检测 0 不检测
*/
private Integer isStock;
/**
* 是否退款退回: 1 退回 0 不退回
*/
private Integer isRefundStock;
/**
* 第二单位
*/

View File

@@ -87,6 +87,11 @@ public interface ConsInfoService extends IService<ConsInfo> {
*/
void onOffConsInfo(Long id, Integer isStock);
/**
* 是否退款退回
*/
void isRefundStockConsInfo(Long id, Integer isRefundStock);
/**
* 修改耗材单位
*

View File

@@ -176,6 +176,14 @@ public class ConsInfoServiceImpl extends ServiceImpl<ConsInfoMapper, ConsInfo> i
super.updateById(entity);
}
@Override
public void isRefundStockConsInfo(Long id, Integer isRefundStock) {
Long shopId = StpKit.USER.getShopId();
ConsInfo entity = super.getOne(query().eq(ConsInfo::getId, id).eq(ConsInfo::getShopId, shopId));
entity.setIsRefundStock(isRefundStock);
super.updateById(entity);
}
@Override
public void modifySubUnit(ConsSubUnitParam param) {
Long shopId = StpKit.USER.getShopId(0L);

View File

@@ -77,7 +77,7 @@ public class ProductRpcServiceImpl implements ProductRpcService {
if (product == null) {
continue;
}
// 商品开启库存
// 商品开启库存
if (product.getIsStock() == SystemConstants.OneZero.ONE) {
productMapper.updateProductStockNum(dto.getProductId(), dto.getShopId(), "sub", dto.getNum());
// 记录商品库存流水
@@ -112,13 +112,13 @@ public class ProductRpcServiceImpl implements ProductRpcService {
Long consInfoId = prodConsRelation.getConsInfoId();
// 耗材消耗数量
BigDecimal surplusStock = prodConsRelation.getSurplusStock();
if (surplusStock == null) {
if (surplusStock == null || surplusStock.compareTo(BigDecimal.ZERO) == 0) {
continue;
}
// 实际消耗数量 = 耗材消耗数量 * 商品购买数量
surplusStock = NumberUtil.mul(surplusStock, dto.getNum());
ConsInfo consInfo = consInfoMapper.selectOneById(consInfoId);
if (consInfo == null) {
if (consInfo == null || consInfo.getIsStock() == SystemConstants.OneZero.ZERO) {
continue;
}
BigDecimal stockNumber = consInfo.getStockNumber();
@@ -239,43 +239,33 @@ public class ProductRpcServiceImpl implements ProductRpcService {
if (CollUtil.isEmpty(list)) {
return;
}
log.info(">>>>>>>>>>>>>>>>>入参1{}", list.size());
boolean isLowWarnLine = false;
for (ProductStockSubtractDTO dto : list) {
Product product = productMapper.selectOneById(dto.getProductId());
log.info(">>>>>>>>>>>>>>>>>入参2{}", product.getName());
// 商品是否允许退款退货时归还库存
if (SystemConstants.OneZero.ZERO == product.getIsRefundStock()) {
continue;
}
// 商品未开启库存
if (SystemConstants.OneZero.ZERO == product.getIsStock()) {
continue;
}
log.info(">>>>>>>>>>>>>>>>>入参3{}", product.getName());
productMapper.updateProductStockNum(dto.getProductId(), dto.getShopId(), "add", dto.getNum());
// 记录商品库存流水
ProductStockFlow flow = new ProductStockFlow();
flow.setCreateUserId(1L);
flow.setCreateUserName("银收客");
flow.setShopId(shopId);
flow.setProductId(product.getId());
flow.setProductName(product.getName());
flow.setBeforeNumber(NumberUtil.toBigDecimal(product.getStockNumber()));
flow.setInOutNumber(NumberUtil.toBigDecimal(dto.getNum()));
flow.setAfterNumber(NumberUtil.add(NumberUtil.toBigDecimal(product.getStockNumber()), NumberUtil.toBigDecimal(dto.getNum())));
flow.setInOutType(InOutTypeEnum.OUT.value());
flow.setInOutItem(InOutItemEnum.ORDER_OUT.value());
flow.setRemark("红冲订单取消/退菜/退单消耗的库存");
flow.setOrderId(orderId);
productStockFlowService.saveFlow(flow);
String key = StrUtil.format(SHOP_PRODUCT_STOCK, shopId, product.getId());
log.info(">>>>>>>>>>>>>>>>>入参4{}", redisService.get(key));
refreshRedisProdStock(shopId, product.getId(), flow.getAfterNumber());
log.info(">>>>>>>>>>>>>>>>>入参5{}", redisService.get(key));
Integer warnLine = ObjUtil.defaultIfNull(product.getWarnLine(), 10);
if (!isLowWarnLine && (NumberUtil.isLessOrEqual(flow.getBeforeNumber(), BigDecimal.ZERO) || NumberUtil.isLess(flow.getAfterNumber(), Convert.toBigDecimal(warnLine)))) {
isLowWarnLine = true;
if (SystemConstants.OneZero.ONE == product.getIsRefundStock() && SystemConstants.OneZero.ONE == product.getIsStock()) {
productMapper.updateProductStockNum(dto.getProductId(), dto.getShopId(), "add", dto.getNum());
// 记录商品库存流水
ProductStockFlow flow = new ProductStockFlow();
flow.setCreateUserId(1L);
flow.setCreateUserName("银收客");
flow.setShopId(shopId);
flow.setProductId(product.getId());
flow.setProductName(product.getName());
flow.setBeforeNumber(NumberUtil.toBigDecimal(product.getStockNumber()));
flow.setInOutNumber(NumberUtil.toBigDecimal(dto.getNum()));
flow.setAfterNumber(NumberUtil.add(NumberUtil.toBigDecimal(product.getStockNumber()), NumberUtil.toBigDecimal(dto.getNum())));
flow.setInOutType(InOutTypeEnum.OUT.value());
flow.setInOutItem(InOutItemEnum.ORDER_OUT.value());
flow.setRemark("红冲订单取消/退菜/退单消耗的库存");
flow.setOrderId(orderId);
productStockFlowService.saveFlow(flow);
// String key = StrUtil.format(SHOP_PRODUCT_STOCK, shopId, product.getId());
refreshRedisProdStock(shopId, product.getId(), flow.getAfterNumber());
Integer warnLine = ObjUtil.defaultIfNull(product.getWarnLine(), 10);
if (!isLowWarnLine && (NumberUtil.isLessOrEqual(flow.getBeforeNumber(), BigDecimal.ZERO) || NumberUtil.isLess(flow.getAfterNumber(), Convert.toBigDecimal(warnLine)))) {
isLowWarnLine = true;
}
}
// 查询商品绑定耗材信息
List<ProdConsRelation> relationList = prodConsRelationMapper.selectListByQuery(QueryWrapper.create().eq(ProdConsRelation::getProductId, dto.getProductId()));
@@ -287,13 +277,13 @@ public class ProductRpcServiceImpl implements ProductRpcService {
Long consInfoId = prodConsRelation.getConsInfoId();
// 耗材消耗数量
BigDecimal surplusStock = prodConsRelation.getSurplusStock();
if (surplusStock == null) {
if (surplusStock == null || surplusStock.compareTo(BigDecimal.ZERO) == 0) {
continue;
}
// 实际消耗数量 = 耗材消耗数量 * 商品购买数量
surplusStock = NumberUtil.mul(surplusStock, dto.getNum());
ConsInfo consInfo = consInfoMapper.selectOneById(consInfoId);
if (consInfo == null) {
if (consInfo == null || consInfo.getIsStock() == SystemConstants.OneZero.ZERO || consInfo.getIsRefundStock() == SystemConstants.OneZero.ZERO) {
continue;
}
BigDecimal stockNumber = consInfo.getStockNumber();