耗材报损

This commit is contained in:
Tankaikai
2025-03-07 10:55:41 +08:00
parent 9da75ef98b
commit 1b84a435ff
7 changed files with 113 additions and 3 deletions

View File

@@ -3,6 +3,7 @@ package com.czg.controller.admin;
import com.czg.log.annotation.OperationLog;
import com.czg.product.param.ConsCheckStockParam;
import com.czg.product.param.ConsInOutStockHeadParam;
import com.czg.product.param.ConsReportDamageParam;
import com.czg.product.service.ConsStockFlowService;
import com.czg.product.vo.ConsCheckStockRecordVo;
import com.czg.resp.CzgResult;
@@ -77,4 +78,16 @@ public class ConsStockFlowController {
consStockFlowService.checkStock(param);
return CzgResult.success();
}
/**
* 耗材报损
*/
@PostMapping("reportDamage")
@OperationLog("库存盘点")
//@SaAdminCheckPermission("consStockFlow:reportDamage")
public CzgResult<Void> reportDamage(@RequestBody ConsReportDamageParam param) {
ValidatorUtil.validateEntity(param, DefaultGroup.class);
consStockFlowService.reportDamage(param);
return CzgResult.success();
}
}

View File

@@ -105,6 +105,10 @@ public class ConsStockFlowDTO implements Serializable {
* 商品订单id
*/
private Long orderId;
/**
* 相关图片urlsjson数组
*/
private String imgUrls;
/**
* 创建人id
*/

View File

@@ -43,7 +43,7 @@ public class ConsStockFlow implements Serializable {
*/
private String inOutType;
/**
* 出入库名目 manual-in:手动入库 manual-out:手动出库 win-in:盘盈入库 loss-out:盘亏出库 order-in:订单退款入库 order-out:订单消费出库
* 出入库名目 manual-in:手动入库 manual-out:手动出库 win-in:盘盈入库 loss-out:盘亏出库 order-in:订单退款入库 order-out:订单消费出库 damage-out:损耗出库
*/
private String inOutItem;
/**
@@ -110,6 +110,10 @@ public class ConsStockFlow implements Serializable {
* 商品订单id
*/
private Long orderId;
/**
* 相关图片urlsjson数组
*/
private String imgUrls;
/**
* 创建人id
*/

View File

@@ -36,7 +36,12 @@ public enum InOutItemEnum {
/**
* 订单消费出库
*/
ORDER_OUT("order-out");
ORDER_OUT("order-out"),
/**
* 损耗出库
*/
DAMAGE_OUT("damage-out");
private String value;

View File

@@ -0,0 +1,42 @@
package com.czg.product.param;
import com.czg.validator.group.DefaultGroup;
import jakarta.validation.constraints.DecimalMin;
import jakarta.validation.constraints.NotNull;
import lombok.Data;
import java.io.Serial;
import java.io.Serializable;
import java.math.BigDecimal;
import java.util.List;
/**
* 耗材报损入参
*
* @author tankaikai
* @since 2025-03-06 18:35
*/
@Data
public class ConsReportDamageParam implements Serializable {
@Serial
private static final long serialVersionUID = 1L;
/**
* 耗材id
*/
@NotNull(message = "耗材id不能为空", groups = DefaultGroup.class)
private Long conId;
/**
* 报损数量
*/
@NotNull(message = "报损数量不能为空", groups = DefaultGroup.class)
@DecimalMin(value = "0", message = "报损数量不能小于0")
private BigDecimal number;
/**
* 报损照片
*/
private List<String> imgUrls;
}

View File

@@ -3,6 +3,7 @@ package com.czg.product.service;
import com.czg.product.entity.ConsStockFlow;
import com.czg.product.param.ConsCheckStockParam;
import com.czg.product.param.ConsInOutStockHeadParam;
import com.czg.product.param.ConsReportDamageParam;
import com.czg.product.vo.ConsCheckStockRecordVo;
import com.mybatisflex.core.service.IService;
@@ -45,5 +46,12 @@ public interface ConsStockFlowService extends IService<ConsStockFlow> {
*/
List<ConsCheckStockRecordVo> getCheckStockRecordList(Long conId);
/**
* 耗材报损
*
* @param param 耗材报损入参
*/
void reportDamage(ConsReportDamageParam param);
}

View File

@@ -4,6 +4,7 @@ import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.bean.copier.CopyOptions;
import cn.hutool.core.util.NumberUtil;
import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson2.JSON;
import com.czg.exception.CzgException;
import com.czg.product.dto.ConsStockFlowDTO;
import com.czg.product.entity.ConsInfo;
@@ -12,6 +13,7 @@ import com.czg.product.enums.InOutItemEnum;
import com.czg.product.enums.InOutTypeEnum;
import com.czg.product.param.ConsCheckStockParam;
import com.czg.product.param.ConsInOutStockHeadParam;
import com.czg.product.param.ConsReportDamageParam;
import com.czg.product.service.ConsStockFlowService;
import com.czg.product.vo.ConsCheckStockRecordVo;
import com.czg.sa.StpKit;
@@ -136,7 +138,7 @@ public class ConsStockFlowServiceImpl extends ServiceImpl<ConsStockFlowMapper, C
}
BigDecimal winLossNumber = NumberUtil.sub(param.getActualNumber(), param.getStockNumber());
if (!NumberUtil.equals(winLossNumber, param.getWinLossNumber())) {
throw new CzgException(StrUtil.format("耗材{}存在发生变动,请刷新后重试", entity.getConName()));
throw new CzgException(StrUtil.format("耗材{}存在发生变动,请刷新后重试", entity.getConName()));
}
entity.setBeforeNumber(consInfo.getStockNumber());
entity.setInOutNumber(winLossNumber);
@@ -161,4 +163,36 @@ public class ConsStockFlowServiceImpl extends ServiceImpl<ConsStockFlowMapper, C
return super.mapper.selectListByQueryAs(query().eq(ConsStockFlow::getShopId, shopId).eq(ConsStockFlow::getConId, conId).orderBy(ConsStockFlow::getId, true), ConsCheckStockRecordVo.class);
}
@Override
public void reportDamage(ConsReportDamageParam param) {
Long shopId = StpKit.USER.getShopId(0L);
Long createUserId = StpKit.USER.getLoginIdAsLong();
String createUserName = StpKit.USER.getAccount();
ConsInfo consInfo = consInfoMapper.selectOneById(param.getConId());
if (consInfo == null) {
throw new CzgException("耗材不存在");
}
ConsStockFlow entity = new ConsStockFlow();
entity.setCreateUserId(createUserId);
entity.setCreateUserName(createUserName);
entity.setShopId(shopId);
entity.setConId(param.getConId());
entity.setConName(consInfo.getConName());
entity.setPurchasePrice(consInfo.getPrice());
BigDecimal balance = NumberUtil.sub(consInfo.getStockNumber(), param.getNumber());
if (NumberUtil.isLess(balance, BigDecimal.ZERO)) {
throw new CzgException(StrUtil.format("耗材{}存在发生变动,请刷新后重试", entity.getConName()));
}
entity.setBeforeNumber(consInfo.getStockNumber());
entity.setInOutNumber(NumberUtil.sub(BigDecimal.ZERO, balance));
entity.setAfterNumber(balance);
entity.setInOutType(InOutTypeEnum.OUT.value());
entity.setInOutItem(InOutItemEnum.DAMAGE_OUT.value());
entity.setSubTotal(NumberUtil.mul(param.getNumber(), consInfo.getPrice()));
entity.setImgUrls(JSON.toJSONString(param.getImgUrls()));
super.save(entity);
consInfo.setStockNumber(entity.getAfterNumber());
consInfoMapper.update(consInfo);
}
}