diff --git a/zt-module-qms/zt-module-qms-api/src/main/java/com/zt/plat/module/qms/enums/AdjustType.java b/zt-module-qms/zt-module-qms-api/src/main/java/com/zt/plat/module/qms/enums/AdjustType.java index c13d41d1..37d974fd 100644 --- a/zt-module-qms/zt-module-qms-api/src/main/java/com/zt/plat/module/qms/enums/AdjustType.java +++ b/zt-module-qms/zt-module-qms-api/src/main/java/com/zt/plat/module/qms/enums/AdjustType.java @@ -1,6 +1,12 @@ package com.zt.plat.module.qms.enums; public enum AdjustType { + /** + * 加 + */ add, + /** + * 减 + */ subtract, } diff --git a/zt-module-qms/zt-module-qms-api/src/main/java/com/zt/plat/module/qms/enums/LockType.java b/zt-module-qms/zt-module-qms-api/src/main/java/com/zt/plat/module/qms/enums/LockType.java new file mode 100644 index 00000000..753bf19c --- /dev/null +++ b/zt-module-qms/zt-module-qms-api/src/main/java/com/zt/plat/module/qms/enums/LockType.java @@ -0,0 +1,12 @@ +package com.zt.plat.module.qms.enums; + +public enum LockType { + /** + * 锁定 + */ + lock, + /** + * 解锁 + */ + unlock, +} diff --git a/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/resource/material/controller/admin/MaterialLifecycleController.java b/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/resource/material/controller/admin/MaterialLifecycleController.java index 9a10ce22..e5e795fd 100644 --- a/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/resource/material/controller/admin/MaterialLifecycleController.java +++ b/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/resource/material/controller/admin/MaterialLifecycleController.java @@ -13,7 +13,6 @@ import com.zt.plat.framework.datapermission.core.annotation.DeptDataPermissionIg import com.zt.plat.framework.excel.core.util.ExcelUtils; import com.zt.plat.module.qms.resource.material.controller.vo.*; import com.zt.plat.module.qms.resource.material.dal.dataobject.MaterialLifecycleDO; -import com.zt.plat.module.qms.resource.material.service.MaterialBatchService; import com.zt.plat.module.qms.resource.material.service.MaterialLifecycleService; import com.zt.plat.module.qms.resource.material.valid.AddGroup; import com.zt.plat.module.qms.resource.material.valid.UpdateGroup; @@ -23,7 +22,6 @@ import io.swagger.v3.oas.annotations.tags.Tag; import jakarta.annotation.Resource; import jakarta.servlet.http.HttpServletResponse; import jakarta.validation.Valid; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; @@ -90,7 +88,7 @@ public class MaterialLifecycleController extends AbstractFileUploadController im @Parameter(name = "id", description = "编号", required = true, example = "1024") // @PreAuthorize("@ss.hasPermission('qms:material-lifecycle:query')") public CommonResult getMaterialLifecycle(@RequestParam("id") Long id) { - MaterialLifecycleRespVO lifecycleRespVO = materialLifecycleService.getMaterialLifecycle(id); + MaterialLifecycleRespVO lifecycleRespVO = materialLifecycleService.getMaterialLifecycleWithDetailList(id); return success(lifecycleRespVO); } diff --git a/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/resource/material/controller/vo/MaterialBatchRespVO.java b/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/resource/material/controller/vo/MaterialBatchRespVO.java index 921e1cf4..5c19c536 100644 --- a/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/resource/material/controller/vo/MaterialBatchRespVO.java +++ b/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/resource/material/controller/vo/MaterialBatchRespVO.java @@ -69,6 +69,10 @@ public class MaterialBatchRespVO { @ExcelProperty("已入库数量") private BigDecimal inboundEndQuantity; + @Schema(description = "锁定数量") + @ExcelProperty("锁定数量") + private BigDecimal lockQuantity; + @Schema(description = "存放位置描述") @ExcelProperty("存放位置描述") private String location; @@ -97,6 +101,10 @@ public class MaterialBatchRespVO { @ExcelProperty("提交状态,0-未提交,1-已提交") private Integer submitStatus; + @Schema(description = "提交日期") + @ExcelProperty("提交日期") + private LocalDateTime submitDate; + @Schema(description = "验收状态", example = "1") @ExcelProperty("验收状态") private String acceptanceStatus; diff --git a/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/resource/material/controller/vo/MaterialLifecycleDetailRespVO.java b/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/resource/material/controller/vo/MaterialLifecycleDetailRespVO.java index a756352b..bdb65cbc 100644 --- a/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/resource/material/controller/vo/MaterialLifecycleDetailRespVO.java +++ b/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/resource/material/controller/vo/MaterialLifecycleDetailRespVO.java @@ -5,6 +5,7 @@ import com.alibaba.excel.annotation.ExcelProperty; import io.swagger.v3.oas.annotations.media.Schema; import lombok.Data; +import java.math.BigDecimal; import java.time.LocalDateTime; @Schema(description = "管理后台 - 物料通用流程明细 Response VO") @@ -20,6 +21,9 @@ public class MaterialLifecycleDetailRespVO { @ExcelProperty("父id") private Long lifecycleId; + @Schema(description = "工段或批次父id", example = "6294") + @ExcelProperty("工段或批次父id") + private Long gongParentId; @Schema(description = "物料大类id", example = "31283") @ExcelProperty("物料大类id") @@ -105,6 +109,10 @@ public class MaterialLifecycleDetailRespVO { @ExcelProperty("物料实例单位") private String infomationUnit; + @Schema(description = "批次或工段数量") + @ExcelProperty("批次或工段数量") + private BigDecimal inboundQuantity; + @Schema(description = "影响数量", example = "15772") @ExcelProperty("影响数量") private String influenceCount; diff --git a/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/resource/material/controller/vo/MaterialUseEndReuseDetailRespVO.java b/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/resource/material/controller/vo/MaterialUseEndReuseDetailRespVO.java index 12d6d88c..9839b782 100644 --- a/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/resource/material/controller/vo/MaterialUseEndReuseDetailRespVO.java +++ b/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/resource/material/controller/vo/MaterialUseEndReuseDetailRespVO.java @@ -5,6 +5,7 @@ import com.alibaba.excel.annotation.ExcelProperty; import io.swagger.v3.oas.annotations.media.Schema; import lombok.Data; +import java.math.BigDecimal; import java.time.LocalDateTime; @Schema(description = "管理后台 - 物料用完标记或清洗回收明细 Response VO") @@ -52,6 +53,14 @@ public class MaterialUseEndReuseDetailRespVO { @ExcelProperty("型号") private String modelNo; + @Schema(description = "数量") + @ExcelProperty("数量") + private BigDecimal quantity; + + @Schema(description = "物料类型:玻璃,塑料") + @ExcelProperty("物料类型:玻璃,塑料") + private String materialType; + @Schema(description = "所属部门") @ExcelProperty("所属部门") private String systemDepartmentCode; diff --git a/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/resource/material/controller/vo/MaterialUseEndReuseDetailSaveReqVO.java b/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/resource/material/controller/vo/MaterialUseEndReuseDetailSaveReqVO.java index e28a6b88..76cf9c5e 100644 --- a/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/resource/material/controller/vo/MaterialUseEndReuseDetailSaveReqVO.java +++ b/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/resource/material/controller/vo/MaterialUseEndReuseDetailSaveReqVO.java @@ -1,8 +1,11 @@ package com.zt.plat.module.qms.resource.material.controller.vo; +import com.baomidou.mybatisplus.annotation.TableField; import io.swagger.v3.oas.annotations.media.Schema; import lombok.Data; +import java.math.BigDecimal; + @Schema(description = "管理后台 - 物料用完标记或清洗回收明细新增/修改 Request VO") @Data public class MaterialUseEndReuseDetailSaveReqVO { @@ -16,6 +19,12 @@ public class MaterialUseEndReuseDetailSaveReqVO { @Schema(description = "物料id", example = "7953") private Long infomationId; + @Schema(description = "数量") + private BigDecimal quantity; + + @Schema(description = "物料类型:玻璃,塑料") + private String materialType; + @Schema(description = "所属部门") private String systemDepartmentCode; diff --git a/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/resource/material/controller/vo/MaterialUseEndReuseSaveReqVO.java b/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/resource/material/controller/vo/MaterialUseEndReuseSaveReqVO.java index 484a4401..0a8c3d84 100644 --- a/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/resource/material/controller/vo/MaterialUseEndReuseSaveReqVO.java +++ b/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/resource/material/controller/vo/MaterialUseEndReuseSaveReqVO.java @@ -35,7 +35,10 @@ public class MaterialUseEndReuseSaveReqVO { private String remark; @Schema(description = "物料ids") - @NotEmpty private List infomationIds; + @Schema(description = "明细列表") + @NotEmpty + private List detailList; + } \ No newline at end of file diff --git a/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/resource/material/dal/dataobject/MaterialBatchDO.java b/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/resource/material/dal/dataobject/MaterialBatchDO.java index 2ffa652b..51229bff 100644 --- a/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/resource/material/dal/dataobject/MaterialBatchDO.java +++ b/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/resource/material/dal/dataobject/MaterialBatchDO.java @@ -6,6 +6,7 @@ import com.zt.plat.framework.mybatis.core.dataobject.BusinessBaseDO; import java.math.BigDecimal; import java.time.LocalDate; +import java.time.LocalDateTime; /** * 物料批次 DO @@ -72,6 +73,11 @@ public class MaterialBatchDO extends BusinessBaseDO { */ @TableField("INB_END_QTY") private BigDecimal inboundEndQuantity; + /** + * 锁定数量 + */ + @TableField("LC_QTY") + private BigDecimal lockQuantity; /** * 存放位置描述 */ @@ -107,6 +113,11 @@ public class MaterialBatchDO extends BusinessBaseDO { */ @TableField("SBM_STS") private Integer submitStatus; + /** + * 提交日期 + */ + @TableField("SBM_DT") + private LocalDateTime submitDate; /** * 验收状态 */ diff --git a/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/resource/material/dal/dataobject/MaterialInfomationDO.java b/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/resource/material/dal/dataobject/MaterialInfomationDO.java index bd2968bf..4eda5957 100644 --- a/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/resource/material/dal/dataobject/MaterialInfomationDO.java +++ b/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/resource/material/dal/dataobject/MaterialInfomationDO.java @@ -109,7 +109,7 @@ public class MaterialInfomationDO extends BusinessBaseDO { @TableField("PUB_STS") private Integer publishStatus; /** - * 领用状态,0-未领用,1-已领用 + * 领用状态,0-未领用,1-已领用,2-锁定 */ @TableField("USG_STS") private Integer usageStatus; diff --git a/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/resource/material/dal/dataobject/MaterialUseEndReuseDetailDO.java b/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/resource/material/dal/dataobject/MaterialUseEndReuseDetailDO.java index f6bc23a0..592ad3bd 100644 --- a/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/resource/material/dal/dataobject/MaterialUseEndReuseDetailDO.java +++ b/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/resource/material/dal/dataobject/MaterialUseEndReuseDetailDO.java @@ -3,6 +3,9 @@ package com.zt.plat.module.qms.resource.material.dal.dataobject; import com.baomidou.mybatisplus.annotation.*; import com.zt.plat.framework.mybatis.core.dataobject.BusinessBaseDO; import lombok.*; + +import java.math.BigDecimal; + /** * 物料用完标记或清洗回收明细 DO * @@ -39,6 +42,16 @@ public class MaterialUseEndReuseDetailDO extends BusinessBaseDO { @TableField("INF_ID") private Long infomationId; /** + * 数量 + */ + @TableField("QTY") + private BigDecimal quantity; + /** + * 物料类型:玻璃,塑料 + */ + @TableField("MTRL_TP") + private String materialType; + /** * 所属部门 */ @TableField("SYS_DEPT_CD") diff --git a/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/resource/material/dal/mapper/MaterialLifecycleDetailMapper.java b/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/resource/material/dal/mapper/MaterialLifecycleDetailMapper.java index c49f8038..16863a0f 100644 --- a/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/resource/material/dal/mapper/MaterialLifecycleDetailMapper.java +++ b/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/resource/material/dal/mapper/MaterialLifecycleDetailMapper.java @@ -53,15 +53,9 @@ public interface MaterialLifecycleDetailMapper extends BaseMapperX (Long) map.get("QUANTITY") )); } + + default List selectListWithReturnExchangeInfo(Long id) { + MPJLambdaWrapper wrapper = new MPJLambdaWrapper() + .selectAll(MaterialLifecycleDetailDO.class) + .selectAs("batch.BAT_NO", MaterialLifecycleDetailRespVO::getBatchNo) + .selectAs("gongduan.ASN_DEPT_NAME", MaterialLifecycleDetailRespVO::getAssignDepartmentName) + .selectAs(MaterialInfomationDO::getCode, MaterialLifecycleDetailRespVO::getInfomationCode) + .selectAs("product_infomation.NAME", MaterialLifecycleDetailRespVO::getInfomationName) + .selectAs("product_infomation.MDL_NO", MaterialLifecycleDetailRespVO::getInfomationModelNo) + .selectAs("product_infomation.UNT", MaterialLifecycleDetailRespVO::getInfomationUnit) + .leftJoin(MaterialBatchDO.class, "batch", MaterialBatchDO::getId, MaterialLifecycleDetailDO::getBatchId) + .leftJoin(MaterialBatchDO.class, "gongduan", MaterialBatchDO::getId, MaterialLifecycleDetailDO::getBatchGongduanId) + .leftJoin(MaterialInfomationDO.class, MaterialInfomationDO::getId, MaterialLifecycleDetailDO::getInfomationId) + .leftJoin(MaterialProductDO.class, "product_infomation", MaterialProductDO::getId, MaterialInfomationDO::getProductId) + .eq(MaterialLifecycleDetailDO::getLifecycleId, id); + + return selectJoinList(MaterialLifecycleDetailRespVO.class, wrapper); + } } \ No newline at end of file diff --git a/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/resource/material/dal/mapper/MaterialLifecycleMapper.java b/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/resource/material/dal/mapper/MaterialLifecycleMapper.java index 6e211f5e..4d72bd85 100644 --- a/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/resource/material/dal/mapper/MaterialLifecycleMapper.java +++ b/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/resource/material/dal/mapper/MaterialLifecycleMapper.java @@ -38,7 +38,7 @@ public interface MaterialLifecycleMapper extends BaseMapperX gongs, AdjustType adjustType); + + /** + * 根据批次ids 获取批次信息 + * + * @param ids 批次ids + * @return 批次信息 + */ + List getListByIds(List ids); + + /** + * 锁定批次退换数量 + * + * @param batches 批次信息 + * @param lockType 锁定类型 + */ + void lockBatchReturnExchangeCount(List batches, LockType lockType); + + /** + * 锁定工段退换数量 + * + * @param gongs 工段信息 + * @param lockType 锁定类型 + */ + void lockGongduanReturnExchangeCount(List gongs, LockType lockType); } \ No newline at end of file diff --git a/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/resource/material/service/MaterialBatchServiceImpl.java b/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/resource/material/service/MaterialBatchServiceImpl.java index a55c84dc..5d6bef82 100644 --- a/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/resource/material/service/MaterialBatchServiceImpl.java +++ b/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/resource/material/service/MaterialBatchServiceImpl.java @@ -7,6 +7,7 @@ import com.zt.plat.framework.common.pojo.PageResult; import com.zt.plat.framework.common.util.object.BeanUtils; import com.zt.plat.module.qms.core.code.SequenceUtil; import com.zt.plat.module.qms.enums.AdjustType; +import com.zt.plat.module.qms.enums.LockType; import com.zt.plat.module.qms.resource.material.controller.vo.MaterialBatchPageReqVO; import com.zt.plat.module.qms.resource.material.controller.vo.MaterialBatchRespVO; import com.zt.plat.module.qms.resource.material.controller.vo.MaterialBatchSaveReqVO; @@ -23,6 +24,7 @@ import org.springframework.transaction.annotation.Transactional; import org.springframework.validation.annotation.Validated; import java.math.BigDecimal; +import java.time.LocalDateTime; import java.util.List; import java.util.Map; import java.util.Set; @@ -264,10 +266,10 @@ public class MaterialBatchServiceImpl implements MaterialBatchService { boolean exists = materialBatchMapper.exists(Wrappers.lambdaQuery(MaterialBatchDO.class) .eq(MaterialBatchDO::getParentId, id)); if (!exists) throw new ServiceException(1_032_160_000, "批次还未拆分,不可提交"); - batchDO.setSubmitStatus(1); + batchDO.setSubmitStatus(1).setSubmitDate(LocalDateTime.now()); materialBatchMapper.updateById(batchDO); // 提交工段 - MaterialBatchDO updateBatch = new MaterialBatchDO().setSubmitStatus(1); + MaterialBatchDO updateBatch = new MaterialBatchDO().setSubmitStatus(1).setSubmitDate(LocalDateTime.now()); materialBatchMapper.update(updateBatch, Wrappers.lambdaQuery(MaterialBatchDO.class) .eq(MaterialBatchDO::getParentId, id)); return true; @@ -357,7 +359,7 @@ public class MaterialBatchServiceImpl implements MaterialBatchService { if (CollUtil.isEmpty(batDOS)) return; Map batIdMapByGongId = gongDOS.stream().collect(Collectors.toMap(MaterialBatchDO::getId, MaterialBatchDO::getParentId)); for (MaterialLifecycleDetailDO gong : gongs) { - gong.setBatchId(batIdMapByGongId.get(gong.getId())); + gong.setBatchId(batIdMapByGongId.get(gong.getBatchGongduanId())); } Map> detailGroupByBatId = gongs.stream().collect(Collectors.groupingBy(MaterialLifecycleDetailDO::getBatchId)); List batches = batIds.stream().map(batId -> { @@ -371,9 +373,66 @@ public class MaterialBatchServiceImpl implements MaterialBatchService { } - private void adjustBatchOrGongReturnExchangeCount(AdjustType adjustType, List batchOrGongDOS, Map lifecycleDetailDOMapByGongId) { + @Override + public List getListByIds(List ids) { + return materialBatchMapper.selectByIds(ids); + } + + @Override + public void lockBatchReturnExchangeCount(List batches, LockType lockType) { + List batIds = batches.stream().map(MaterialLifecycleDetailDO::getBatchId).toList(); + List batchDOS = getBatchListByBatchIds(batIds); + Map lifecycleDetailDOMapByBatchId = batches.stream().collect(Collectors.toMap(MaterialLifecycleDetailDO::getBatchId, Function.identity())); + lockBatchOrGongReturnExchangeCount(lockType, batchDOS, lifecycleDetailDOMapByBatchId); + materialBatchMapper.updateBatch(batchDOS); + } + + @Override + public void lockGongduanReturnExchangeCount(List gongs, LockType lockType) { + List gongIds = gongs.stream().map(MaterialLifecycleDetailDO::getBatchGongduanId).toList(); + List gongDOS = getGongduanListByGongIds(gongIds); + Map lifecycleDetailDOMapByGongId = gongs.stream().collect(Collectors.toMap(MaterialLifecycleDetailDO::getBatchGongduanId, Function.identity())); + // 调整工段锁定数量 + lockBatchOrGongReturnExchangeCount(lockType, gongDOS, lifecycleDetailDOMapByGongId); + materialBatchMapper.updateBatch(gongDOS); + // 调整批次锁定数量 + List batIds = gongDOS.stream().map(MaterialBatchDO::getParentId).toList(); + List batDOS = getBatchListByBatchIds(batIds); + if (CollUtil.isEmpty(batDOS)) return; + Map batIdMapByGongId = gongDOS.stream().collect(Collectors.toMap(MaterialBatchDO::getId, MaterialBatchDO::getParentId)); + for (MaterialLifecycleDetailDO gong : gongs) { + gong.setBatchId(batIdMapByGongId.get(gong.getBatchGongduanId())); + } + Map> detailGroupByBatId = gongs.stream().collect(Collectors.groupingBy(MaterialLifecycleDetailDO::getBatchId)); + List batches = batIds.stream().map(batId -> { + List detailDOS = detailGroupByBatId.get(batId); + BigDecimal influenceCount = detailDOS.stream().map(MaterialLifecycleDetailDO::getInfluenceCount).reduce(BigDecimal.ZERO, BigDecimal::add); + return new MaterialLifecycleDetailDO().setBatchId(batId).setInfluenceCount(influenceCount); + }).toList(); + Map lifecycleDetailDOMapByBatId = batches.stream().collect(Collectors.toMap(MaterialLifecycleDetailDO::getBatchId, Function.identity())); + lockBatchOrGongReturnExchangeCount(lockType, batDOS, lifecycleDetailDOMapByBatId); + materialBatchMapper.updateBatch(batDOS); + } + + private void lockBatchOrGongReturnExchangeCount(LockType lockType, List batchOrGongDOS, Map lifecycleDetailDOMapByBatOrGongId) { for (MaterialBatchDO batOrGong : batchOrGongDOS) { - MaterialLifecycleDetailDO detailDO = lifecycleDetailDOMapByGongId.get(batOrGong.getId()); + MaterialLifecycleDetailDO detailDO = lifecycleDetailDOMapByBatOrGongId.get(batOrGong.getId()); + BigDecimal influenceCount = detailDO.getInfluenceCount(); + switch (lockType) { + case lock -> { + BigDecimal lockQuantity = batOrGong.getLockQuantity().add(influenceCount); + if (lockQuantity.compareTo(batOrGong.getInboundQuantity()) > 0) + throw new ServiceException(1_032_160_000, "退换货数量大于可用数量"); + batOrGong.setLockQuantity(lockQuantity); + } + case unlock -> batOrGong.setLockQuantity(batOrGong.getLockQuantity().subtract(influenceCount)); + } + } + } + + private void adjustBatchOrGongReturnExchangeCount(AdjustType adjustType, List batchOrGongDOS, Map lifecycleDetailDOMapByBatOrGongId) { + for (MaterialBatchDO batOrGong : batchOrGongDOS) { + MaterialLifecycleDetailDO detailDO = lifecycleDetailDOMapByBatOrGongId.get(batOrGong.getId()); String businessType = detailDO.getBusinessType(); BigDecimal influenceCount = detailDO.getInfluenceCount(); if (MaterialFlowType.return_material.getName().equals(businessType)) { @@ -388,6 +447,11 @@ public class MaterialBatchServiceImpl implements MaterialBatchService { } BigDecimal inboundQuantity = adjustType == AdjustType.add ? batOrGong.getInboundQuantity().subtract(influenceCount) : batOrGong.getInboundQuantity().add(influenceCount); + if (inboundQuantity.compareTo(BigDecimal.ZERO) < 0) + throw new ServiceException(1_032_160_000, " 退换货数量大于可用数量"); + if (inboundQuantity.compareTo(batOrGong.getInitialQuantity()) > 0) + throw new ServiceException(1_032_160_000, "批次数量不能大于初始数量"); + batOrGong.setInboundQuantity(inboundQuantity); } } diff --git a/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/resource/material/service/MaterialInfomationService.java b/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/resource/material/service/MaterialInfomationService.java index f9eb7ba6..300bf87d 100644 --- a/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/resource/material/service/MaterialInfomationService.java +++ b/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/resource/material/service/MaterialInfomationService.java @@ -4,6 +4,7 @@ import java.math.BigDecimal; import java.util.*; import com.zt.plat.module.qms.enums.AdjustType; +import com.zt.plat.module.qms.enums.LockType; import com.zt.plat.module.qms.resource.material.controller.vo.MaterialInfomationPageReqVO; import com.zt.plat.module.qms.resource.material.controller.vo.MaterialInfomationRespVO; import com.zt.plat.module.qms.resource.material.controller.vo.MaterialInfomationSaveReqVO; @@ -186,4 +187,12 @@ public interface MaterialInfomationService { * @param adjustType 入库/出库 */ void updateInfomationInbOrOutbStatus(List infomations, AdjustType adjustType); + + /** + * 批量锁物料 入库/出库 状态 + * + * @param infomations 物料信息 + * @param lockType 入库/出库 + */ + void lockInfomationInbOrOutbStatus(List infomations, LockType lockType); } \ No newline at end of file diff --git a/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/resource/material/service/MaterialInfomationServiceImpl.java b/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/resource/material/service/MaterialInfomationServiceImpl.java index 523d2343..11061be2 100644 --- a/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/resource/material/service/MaterialInfomationServiceImpl.java +++ b/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/resource/material/service/MaterialInfomationServiceImpl.java @@ -3,10 +3,12 @@ package com.zt.plat.module.qms.resource.material.service; import cn.hutool.core.collection.CollUtil; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.toolkit.Wrappers; +import com.zt.plat.framework.common.exception.ServiceException; import com.zt.plat.framework.common.pojo.PageResult; import com.zt.plat.framework.common.util.object.BeanUtils; import com.zt.plat.module.qms.core.code.SequenceUtil; import com.zt.plat.module.qms.enums.AdjustType; +import com.zt.plat.module.qms.enums.LockType; import com.zt.plat.module.qms.resource.material.constant.MaterialConstants; import com.zt.plat.module.qms.resource.material.controller.vo.MaterialInfomationPageReqVO; import com.zt.plat.module.qms.resource.material.controller.vo.MaterialInfomationRespVO; @@ -265,4 +267,23 @@ public class MaterialInfomationServiceImpl implements MaterialInfomationService } + @Override + public void lockInfomationInbOrOutbStatus(List infomations, LockType lockType) { + List infIds = infomations.stream().map(MaterialLifecycleDetailDO::getInfomationId).toList(); + List infomationDOS = getMaterialInfomationsByIds(infIds); + for (MaterialInfomationDO infomationDO : infomationDOS) { + switch (lockType) { + case lock: + if (infomationDO.getUsageStatus() == 2) + throw new ServiceException(1_032_160_000, String.format("物料【%s】已被锁定", infomationDO.getCode())); + infomationDO.setUsageStatus(2); + break; + case unlock: + infomationDO.setUsageStatus(0); + break; + } + } + this.updateBatch(infomationDOS); + } + } \ No newline at end of file diff --git a/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/resource/material/service/MaterialInventoryOutboundService.java b/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/resource/material/service/MaterialInventoryOutboundService.java index e413a23b..32770ef9 100644 --- a/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/resource/material/service/MaterialInventoryOutboundService.java +++ b/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/resource/material/service/MaterialInventoryOutboundService.java @@ -5,6 +5,7 @@ import com.zt.plat.module.qms.resource.material.controller.vo.MaterialInventoryO import com.zt.plat.module.qms.resource.material.controller.vo.MaterialInventoryOutboundRespVO; import com.zt.plat.module.qms.resource.material.controller.vo.MaterialInventoryOutboundSaveReqVO; import com.zt.plat.module.qms.resource.material.dal.dataobject.MaterialInventoryOutboundDO; +import com.zt.plat.module.qms.resource.material.dal.dataobject.MaterialLifecycleDO; import jakarta.validation.Valid; import java.util.List; @@ -61,4 +62,10 @@ public interface MaterialInventoryOutboundService { */ PageResult getMaterialInventoryOutboundPage(MaterialInventoryOutboundPageReqVO pageReqVO); + /** + * 批量添加物料出库 + * + * @param lifecycleDO 物料退换货记录 + */ + void addMaterialInventoryOutboundsByLfc(MaterialLifecycleDO lifecycleDO); } \ No newline at end of file diff --git a/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/resource/material/service/MaterialInventoryOutboundServiceImpl.java b/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/resource/material/service/MaterialInventoryOutboundServiceImpl.java index 1b418ede..e2b33bb6 100644 --- a/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/resource/material/service/MaterialInventoryOutboundServiceImpl.java +++ b/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/resource/material/service/MaterialInventoryOutboundServiceImpl.java @@ -5,14 +5,13 @@ import com.zt.plat.framework.common.exception.ServiceException; import com.zt.plat.framework.common.pojo.CommonResult; import com.zt.plat.framework.common.pojo.PageResult; import com.zt.plat.framework.common.util.object.BeanUtils; +import com.zt.plat.framework.security.core.util.SecurityFrameworkUtils; import com.zt.plat.module.qms.resource.material.controller.vo.MaterialInventoryOutboundPageReqVO; import com.zt.plat.module.qms.resource.material.controller.vo.MaterialInventoryOutboundRespVO; import com.zt.plat.module.qms.resource.material.controller.vo.MaterialInventoryOutboundSaveReqVO; -import com.zt.plat.module.qms.resource.material.dal.dataobject.MaterialInfomationDO; -import com.zt.plat.module.qms.resource.material.dal.dataobject.MaterialInventoryOutboundDO; -import com.zt.plat.module.qms.resource.material.dal.dataobject.MaterialInventoryOutboundDetailDO; -import com.zt.plat.module.qms.resource.material.dal.dataobject.MaterialProductDO; +import com.zt.plat.module.qms.resource.material.dal.dataobject.*; import com.zt.plat.module.qms.resource.material.dal.mapper.MaterialInventoryOutboundMapper; +import com.zt.plat.module.qms.resource.material.enums.MaterialFlowType; import com.zt.plat.module.qms.resource.material.enums.MaterialOutboundType; import com.zt.plat.module.system.api.dept.DeptApi; import com.zt.plat.module.system.api.dept.dto.DeptRespDTO; @@ -21,6 +20,7 @@ import com.zt.plat.module.system.api.user.dto.AdminUserRespDTO; import jakarta.annotation.Resource; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Lazy; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import org.springframework.validation.annotation.Validated; @@ -62,6 +62,10 @@ public class MaterialInventoryOutboundServiceImpl implements MaterialInventoryOu @Autowired private MaterialUseRecordService materialUseRecordService; + @Lazy + @Autowired + private MaterialLifecycleService materialLifecycleService; + @Transactional @Override public MaterialInventoryOutboundRespVO createMaterialInventoryOutbound(MaterialInventoryOutboundSaveReqVO createReqVO) { @@ -103,7 +107,7 @@ public class MaterialInventoryOutboundServiceImpl implements MaterialInventoryOu materialInfomationService.updateByIds(infIds, infomationUpdate); // 如果是危化品领用出库,保存使用记录 List pdtIds = infs.stream().map(MaterialInfomationDO::getProductId).collect(Collectors.toSet()).stream().toList(); - if (MaterialOutboundType.receiveOutbound.getName().equals(createReqVO.getBusinessType())) { + if (MaterialOutboundType.receive_outbound.getName().equals(createReqVO.getBusinessType())) { List pdts = materialProductService.getMaterialProductListByPdtIds(pdtIds); Map productDOMapById = pdts.stream().collect(Collectors.toMap(MaterialProductDO::getId, Function.identity())); List hzrdInfs = infs.stream().filter(inf -> productDOMapById.get(inf.getProductId()).getHazardous().equals(1)).toList(); @@ -165,4 +169,31 @@ public class MaterialInventoryOutboundServiceImpl implements MaterialInventoryOu return materialInventoryOutboundMapper.selectPage(pageReqVO); } + @Override + public void addMaterialInventoryOutboundsByLfc(MaterialLifecycleDO lifecycleDO) { + List detailList = materialLifecycleService.getDetailListByLfcId(lifecycleDO.getId()); + if (CollUtil.isEmpty(detailList)) return; + Set infIds = detailList.stream().map(MaterialLifecycleDetailDO::getInfomationId).collect(Collectors.toSet()); + if (CollUtil.isEmpty(infIds)) return; + MaterialFlowType flowType = MaterialFlowType.fromName(lifecycleDO.getBusinessType()); + String outboundType = switch (flowType) { + case return_material -> MaterialOutboundType.return_outbound.getName(); + case exchange_material -> MaterialOutboundType.replace_outbound.getName(); + case acceptance, make_apply -> null; + }; + MaterialInventoryOutboundDO outboundDO = new MaterialInventoryOutboundDO(); + outboundDO.setApplyUserId(lifecycleDO.getApplyUserId()) + .setApplyUser(lifecycleDO.getApplyUser()) + .setApplyDepartmentId(lifecycleDO.getApplyDepartmentId()) + .setApplyDepartment(lifecycleDO.getApplyDepartment()) + .setApplyTime(lifecycleDO.getApplyTime()) + .setBusinessType(outboundType); + materialInventoryOutboundMapper.insert(outboundDO); + List outboundDetailDOS = infIds.stream().map(infId -> new MaterialInventoryOutboundDetailDO() + .setOutboundId(outboundDO.getId()) + .setInfomationId(infId) + .setQuantity(BigDecimal.valueOf(1))).toList(); + materialInventoryOutboundDetailService.saveBatch(outboundDetailDOS); + } + } \ No newline at end of file diff --git a/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/resource/material/service/MaterialLifecycleDetailService.java b/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/resource/material/service/MaterialLifecycleDetailService.java index 4af35403..865f6c18 100644 --- a/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/resource/material/service/MaterialLifecycleDetailService.java +++ b/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/resource/material/service/MaterialLifecycleDetailService.java @@ -4,6 +4,7 @@ import com.zt.plat.framework.common.pojo.PageResult; import com.zt.plat.module.qms.resource.material.controller.vo.MaterialLifecycleDetailPageReqVO; import com.zt.plat.module.qms.resource.material.controller.vo.MaterialLifecycleDetailRespVO; import com.zt.plat.module.qms.resource.material.controller.vo.MaterialLifecycleDetailSaveReqVO; +import com.zt.plat.module.qms.resource.material.dal.dataobject.MaterialLifecycleDO; import com.zt.plat.module.qms.resource.material.dal.dataobject.MaterialLifecycleDetailDO; import jakarta.validation.Valid; @@ -86,10 +87,10 @@ public interface MaterialLifecycleDetailService { /** * 根据流程id 获取流程明细数据 * - * @param id 流程id + * @param lifecycleDO 流程 * @return 明细列表 */ - List getDetailListWithPdtInfoByLfcId(Long id); + List getDetailListWithPdtInfoByLfcId(MaterialLifecycleDO lifecycleDO); /** * 根据工段id 获取流程明细数据 diff --git a/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/resource/material/service/MaterialLifecycleDetailServiceImpl.java b/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/resource/material/service/MaterialLifecycleDetailServiceImpl.java index c15ca25a..126c3b9d 100644 --- a/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/resource/material/service/MaterialLifecycleDetailServiceImpl.java +++ b/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/resource/material/service/MaterialLifecycleDetailServiceImpl.java @@ -10,18 +10,20 @@ import com.zt.plat.module.qms.enums.QmsCommonConstant; import com.zt.plat.module.qms.resource.material.controller.vo.MaterialLifecycleDetailPageReqVO; import com.zt.plat.module.qms.resource.material.controller.vo.MaterialLifecycleDetailRespVO; import com.zt.plat.module.qms.resource.material.controller.vo.MaterialLifecycleDetailSaveReqVO; -import com.zt.plat.module.qms.resource.material.dal.dataobject.MaterialInfomationDO; -import com.zt.plat.module.qms.resource.material.dal.dataobject.MaterialLifecycleDetailDO; +import com.zt.plat.module.qms.resource.material.dal.dataobject.*; import com.zt.plat.module.qms.resource.material.dal.mapper.MaterialLifecycleDetailMapper; +import com.zt.plat.module.qms.resource.material.enums.MaterialFlowType; import jakarta.annotation.Resource; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Lazy; import org.springframework.stereotype.Service; import org.springframework.validation.annotation.Validated; -import java.util.HashMap; -import java.util.List; -import java.util.Map; +import java.math.BigDecimal; +import java.util.*; +import java.util.function.Function; import java.util.stream.Collectors; +import java.util.stream.Stream; import static com.zt.plat.framework.common.exception.util.ServiceExceptionUtil.exception; import static com.zt.plat.module.qms.enums.ErrorCodeConstants.MATERIAL_LIFECYCLE_DETAIL_NOT_EXISTS; @@ -37,6 +39,12 @@ public class MaterialLifecycleDetailServiceImpl implements MaterialLifecycleDeta @Resource private MaterialLifecycleDetailMapper materialLifecycleDetailMapper; + @Lazy + @Autowired + private MaterialBatchService materialBatchService; + @Lazy + @Autowired + private MaterialProductService materialProductService; @Override public MaterialLifecycleDetailRespVO createMaterialLifecycleDetail(MaterialLifecycleDetailSaveReqVO createReqVO) { @@ -115,9 +123,48 @@ public class MaterialLifecycleDetailServiceImpl implements MaterialLifecycleDeta } @Override - public List getDetailListWithPdtInfoByLfcId(Long id) { + public List getDetailListWithPdtInfoByLfcId(MaterialLifecycleDO lifecycleDO) { + // 退换货时单独处理 + String businessType = lifecycleDO.getBusinessType(); + MaterialFlowType flowType = MaterialFlowType.fromName(businessType); + if (MaterialFlowType.return_material.equals(flowType) || MaterialFlowType.exchange_material.equals(flowType)) { + List detailRespVOS = materialLifecycleDetailMapper.selectListWithReturnExchangeInfo(lifecycleDO.getId()); + if (CollUtil.isEmpty(detailRespVOS)) return detailRespVOS; + List batOrGongIds = detailRespVOS.stream() + .flatMap(detail -> Stream.of(detail.getBatchId(), detail.getBatchGongduanId()).filter(Objects::nonNull)) + .toList(); + List batOrGongDOS = materialBatchService.getListByIds(batOrGongIds); + if (CollUtil.isEmpty(batOrGongDOS)) return detailRespVOS; + Set pdtIds = batOrGongDOS.stream().map(MaterialBatchDO::getProductId).collect(Collectors.toSet()); + List products = materialProductService.getMaterialProductListByPdtIds(new ArrayList<>(pdtIds)); + if (CollUtil.isEmpty(products)) return detailRespVOS; + Map batOrGongMapById = batOrGongDOS.stream().collect(Collectors.toMap(MaterialBatchDO::getId, Function.identity())); + Map productMapById = products.stream().collect(Collectors.toMap(MaterialProductDO::getId, Function.identity())); + for (MaterialLifecycleDetailRespVO detailRespVO : detailRespVOS) { + MaterialProductDO productDO = new MaterialProductDO(); + if (detailRespVO.getBatchId() != null) { + MaterialBatchDO batchDO = batOrGongMapById.get(detailRespVO.getBatchId()); + detailRespVO.setGongParentId(0L); + detailRespVO.setInboundQuantity(batchDO.getInboundQuantity()); + productDO = productMapById.get(batchDO.getProductId()); + } else if (detailRespVO.getBatchGongduanId() != null) { + MaterialBatchDO gongDO = batOrGongMapById.get(detailRespVO.getBatchGongduanId()); + detailRespVO.setGongParentId(gongDO.getParentId()); + detailRespVO.setBatchNo(gongDO.getBatchNo()); + detailRespVO.setInboundQuantity(gongDO.getInboundQuantity()); + productDO = productMapById.get(gongDO.getProductId()); + } + detailRespVO + .setProductId(productDO.getId()) + .setProductName(productDO.getName()) + .setProductCode(productDO.getCode()) + .setProductModelNo(productDO.getModelNo()); + } + return detailRespVOS; + } else { + return materialLifecycleDetailMapper.selectListWithPdtBatInfo(lifecycleDO.getId()); + } - return materialLifecycleDetailMapper.selectListWithPdtBatInfo(id); } diff --git a/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/resource/material/service/MaterialLifecycleService.java b/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/resource/material/service/MaterialLifecycleService.java index 321f8dbf..c0e2732e 100644 --- a/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/resource/material/service/MaterialLifecycleService.java +++ b/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/resource/material/service/MaterialLifecycleService.java @@ -5,6 +5,7 @@ import com.zt.plat.module.qms.resource.material.controller.vo.MaterialLifecycleP import com.zt.plat.module.qms.resource.material.controller.vo.MaterialLifecycleRespVO; import com.zt.plat.module.qms.resource.material.controller.vo.MaterialLifecycleSaveReqVO; import com.zt.plat.module.qms.resource.material.dal.dataobject.MaterialLifecycleDO; +import com.zt.plat.module.qms.resource.material.dal.dataobject.MaterialLifecycleDetailDO; import jakarta.validation.Valid; import java.util.List; @@ -51,7 +52,7 @@ public interface MaterialLifecycleService { * @param id 编号 * @return 物料通用流程,物料验收、退换货 */ - MaterialLifecycleRespVO getMaterialLifecycle(Long id); + MaterialLifecycleRespVO getMaterialLifecycleWithDetailList(Long id); /** * 获得物料通用流程,物料验收、退换货分页 @@ -76,4 +77,20 @@ public interface MaterialLifecycleService { * @return 物料通用流程分页 */ PageResult getMaterialLifecycleRespVOPage(@Valid MaterialLifecyclePageReqVO pageReqVO); + + /** + * 获得物料通用流程 + * + * @param id 编号 + * @return 物料通用流程 + */ + MaterialLifecycleDO getMaterialLifecycle(Long id); + + /** + * 获得物料通用流程明细 + * + * @param lfcId 流程编号 + * @return 物料通用流程明细 + */ + List getDetailListByLfcId(Long lfcId); } \ No newline at end of file diff --git a/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/resource/material/service/MaterialLifecycleServiceImpl.java b/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/resource/material/service/MaterialLifecycleServiceImpl.java index a4dcd2ee..f8c0637e 100644 --- a/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/resource/material/service/MaterialLifecycleServiceImpl.java +++ b/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/resource/material/service/MaterialLifecycleServiceImpl.java @@ -24,6 +24,7 @@ import com.zt.plat.module.qms.common.dic.dal.dataobject.DictionaryBusinessDO; import com.zt.plat.module.qms.common.dic.service.DictionaryBusinessService; import com.zt.plat.module.qms.common.service.BusinessFileService; import com.zt.plat.module.qms.enums.AdjustType; +import com.zt.plat.module.qms.enums.LockType; import com.zt.plat.module.qms.enums.QmsBpmConstant; import com.zt.plat.module.qms.enums.QmsCommonConstant; import com.zt.plat.module.qms.resource.material.constant.MaterialConstants; @@ -88,6 +89,8 @@ public class MaterialLifecycleServiceImpl implements MaterialLifecycleService , private BusinessFileService businessFileService; @Autowired private MaterialInfomationService materialInfomationService; + @Autowired + private MaterialInventoryOutboundService materialInventoryOutboundService; @Transactional @Override @@ -114,15 +117,33 @@ public class MaterialLifecycleServiceImpl implements MaterialLifecycleService , List detailDOS = getLifecycleDetailDOSByBusinessType(detailList, mtrlLfc); materialLifecycleDetailService.saveBatch(detailDOS); - // 如果有退换货,更新相关数据的退换货数量 + // 如果有退换货,锁定相关退换货资源 if (MaterialFlowType.return_material.getName().equals(mtrlLfc.getBusinessType()) || MaterialFlowType.exchange_material.getName().equals(mtrlLfc.getBusinessType())) { - updateReturnExchangeCount(detailDOS, AdjustType.add); + lockReturnExchangeResources(detailDOS, LockType.lock); } return BeanUtils.toBean(mtrlLfc, MaterialLifecycleRespVO.class); } - private void updateReturnExchangeCount(List detailDOS, AdjustType adjustType) { + private void lockReturnExchangeResources(List detailDOS, LockType lockType) { + // 批次 + List batches = detailDOS.stream().filter(detail -> detail.getBatchId() != null).toList(); + // 工段 + List gongs = detailDOS.stream().filter(detail -> detail.getBatchGongduanId() != null).toList(); + // 实例 + List infomations = detailDOS.stream().filter(detail -> detail.getInfomationId() != null).toList(); + if (CollUtil.isNotEmpty(batches)) { + materialBatchService.lockBatchReturnExchangeCount(batches, lockType); + } + if (CollUtil.isNotEmpty(gongs)) { + materialBatchService.lockGongduanReturnExchangeCount(gongs, lockType); + } + if (CollUtil.isNotEmpty(infomations)) { + materialInfomationService.lockInfomationInbOrOutbStatus(infomations, lockType); + } + } + + private void updateReturnExchangeResources(List detailDOS, AdjustType adjustType) { // 批次 List batches = detailDOS.stream().filter(detail -> detail.getBatchId() != null).toList(); // 工段 @@ -137,7 +158,6 @@ public class MaterialLifecycleServiceImpl implements MaterialLifecycleService , } if (CollUtil.isNotEmpty(infomations)) { materialInfomationService.updateInfomationInbOrOutbStatus(infomations, adjustType); - // TODO 添加出入库记录 } } @@ -189,11 +209,11 @@ public class MaterialLifecycleServiceImpl implements MaterialLifecycleService , boolean isReturnExchangeMaterial = MaterialFlowType.return_material.getName().equals(mtrlLfc.getBusinessType()) || MaterialFlowType.exchange_material.getName().equals(mtrlLfc.getBusinessType()); if (isReturnExchangeMaterial) - updateReturnExchangeCount(oriDetailList, AdjustType.subtract); + lockReturnExchangeResources(oriDetailList, LockType.unlock); List detailDOS = getLifecycleDetailDOSByBusinessType(detailList, mtrlLfc); // 保存新的明细 materialLifecycleDetailService.saveBatch(detailDOS); - if (isReturnExchangeMaterial) updateReturnExchangeCount(detailDOS, AdjustType.add); + if (isReturnExchangeMaterial) lockReturnExchangeResources(detailDOS, LockType.lock); materialLifecycleMapper.updateById(mtrlLfc); } @@ -368,7 +388,7 @@ public class MaterialLifecycleServiceImpl implements MaterialLifecycleService , || MaterialFlowType.exchange_material.getName().equals(lifecycleDO.getBusinessType()); if (isReturnExchangeMaterial) { List detailList = materialLifecycleDetailService.getDetailListByLfcId(id); - this.updateReturnExchangeCount(detailList, AdjustType.subtract); + this.lockReturnExchangeResources(detailList, LockType.unlock); } // 删除流程 @@ -395,7 +415,7 @@ public class MaterialLifecycleServiceImpl implements MaterialLifecycleService , if (CollUtil.isNotEmpty(rtnRepLifecycleDOS)) { List rtnRepIds = rtnRepLifecycleDOS.stream().map(MaterialLifecycleDO::getId).toList(); List detailList = materialLifecycleDetailService.getDetailListByLfcIds(rtnRepIds); - this.updateReturnExchangeCount(detailList, AdjustType.subtract); + this.lockReturnExchangeResources(detailList, LockType.unlock); } // 删除流程 materialLifecycleMapper.deleteByIds(ids); @@ -415,12 +435,12 @@ public class MaterialLifecycleServiceImpl implements MaterialLifecycleService , } @Override - public MaterialLifecycleRespVO getMaterialLifecycle(Long id) { + public MaterialLifecycleRespVO getMaterialLifecycleWithDetailList(Long id) { MaterialLifecycleDO lifecycleDO = materialLifecycleMapper.selectById(id); if (lifecycleDO == null) return null; MaterialLifecycleRespVO respVO = BeanUtils.toBean(lifecycleDO, MaterialLifecycleRespVO.class); // 获取明细 - List detailRespVOS = materialLifecycleDetailService.getDetailListWithPdtInfoByLfcId(id); + List detailRespVOS = materialLifecycleDetailService.getDetailListWithPdtInfoByLfcId(lifecycleDO); respVO.setDetailList(detailRespVOS); CommonResult> result = businessFileService.getBusinessFileList(id); respVO.setBusinessFileRet(result.getData()); @@ -443,6 +463,7 @@ public class MaterialLifecycleServiceImpl implements MaterialLifecycleService , return pageResult; } + @Transactional @Override public Boolean submitLifecycle(Long id) { MaterialLifecycleDO lifecycleDO = materialLifecycleMapper.selectById(id); @@ -453,6 +474,14 @@ public class MaterialLifecycleServiceImpl implements MaterialLifecycleService , if (MaterialFlowType.acceptance.getName().equals(lifecycleDO.getBusinessType())) { // 如果是验收需要发起流程 this.createProcessInstance(lifecycleDO); + } else if (MaterialFlowType.return_material.getName().equals(lifecycleDO.getBusinessType()) + || MaterialFlowType.exchange_material.getName().equals(lifecycleDO.getBusinessType())) { + // 如果是退换货需要释放锁定的资源并更新退换货数量或更新实例状态 + List detailList = materialLifecycleDetailService.getDetailListByLfcId(id); + this.lockReturnExchangeResources(detailList, LockType.unlock); + this.updateReturnExchangeResources(detailList, AdjustType.add); + // 添加退换货出库记录 + materialInventoryOutboundService.addMaterialInventoryOutboundsByLfc(lifecycleDO); } lifecycleDO.setSubmitStatus(1); @@ -491,6 +520,16 @@ public class MaterialLifecycleServiceImpl implements MaterialLifecycleService , return respVOPageResult; } + @Override + public MaterialLifecycleDO getMaterialLifecycle(Long id) { + return materialLifecycleMapper.selectById(id); + } + + @Override + public List getDetailListByLfcId(Long lfcId) { + return materialLifecycleDetailService.getDetailListByLfcId(lfcId); + } + private void createProcessInstance(MaterialLifecycleDO lifecycleDO) { String flowInstanceId = lifecycleDO.getFlowInstanceId(); diff --git a/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/resource/material/service/MaterialStandardSolutionServiceImpl.java b/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/resource/material/service/MaterialStandardSolutionServiceImpl.java index 67dcc729..7091eb06 100644 --- a/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/resource/material/service/MaterialStandardSolutionServiceImpl.java +++ b/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/resource/material/service/MaterialStandardSolutionServiceImpl.java @@ -15,13 +15,12 @@ import com.zt.plat.module.qms.resource.device.service.DeviceProductService; import com.zt.plat.module.qms.resource.material.constant.MaterialConstants; import com.zt.plat.module.qms.resource.material.controller.vo.*; import com.zt.plat.module.qms.resource.material.dal.dataobject.MaterialInfomationDO; +import com.zt.plat.module.qms.resource.material.dal.dataobject.MaterialLifecycleDO; import com.zt.plat.module.qms.resource.material.dal.dataobject.MaterialLifecycleDetailDO; import com.zt.plat.module.qms.resource.material.dal.dataobject.MaterialStandardSolutionDO; import com.zt.plat.module.qms.resource.material.dal.mapper.MaterialStandardSolutionMapper; -import com.zt.plat.module.qms.resource.material.enums.MaterialInfomationOrigin; import jakarta.annotation.Resource; import lombok.extern.slf4j.Slf4j; -import org.jspecify.annotations.NonNull; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -83,7 +82,7 @@ public class MaterialStandardSolutionServiceImpl implements MaterialStandardSolu MaterialLifecycleDetailDO lifecycleDetail = materialLifecycleDetailService.getMaterialLifecycleDetail(detailId); if (lifecycleDetail == null) throw new ServiceException(1_032_160_000, "配置申请明细不存在"); // 已提交的申请才可配置 - MaterialLifecycleRespVO lifecycle = materialLifecycleService.getMaterialLifecycle(lifecycleDetail.getLifecycleId()); + MaterialLifecycleDO lifecycle = materialLifecycleService.getMaterialLifecycle(lifecycleDetail.getLifecycleId()); if (lifecycle == null) throw new ServiceException(1_032_160_000, "配置申请不存在"); if (lifecycle.getSubmitStatus() != 1) throw new ServiceException(1_032_160_000, "配置申请未提交"); // 已配置数量不大于申请数量 diff --git a/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/resource/material/service/MaterialUseEndReuseServiceImpl.java b/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/resource/material/service/MaterialUseEndReuseServiceImpl.java index e527bdde..b647e904 100644 --- a/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/resource/material/service/MaterialUseEndReuseServiceImpl.java +++ b/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/resource/material/service/MaterialUseEndReuseServiceImpl.java @@ -5,10 +5,7 @@ import com.zt.plat.framework.common.exception.ServiceException; import com.zt.plat.framework.common.pojo.PageResult; import com.zt.plat.framework.common.util.object.BeanUtils; import com.zt.plat.framework.security.core.util.SecurityFrameworkUtils; -import com.zt.plat.module.qms.resource.material.controller.vo.MaterialUseEndReuseDetailRespVO; -import com.zt.plat.module.qms.resource.material.controller.vo.MaterialUseEndReusePageReqVO; -import com.zt.plat.module.qms.resource.material.controller.vo.MaterialUseEndReuseRespVO; -import com.zt.plat.module.qms.resource.material.controller.vo.MaterialUseEndReuseSaveReqVO; +import com.zt.plat.module.qms.resource.material.controller.vo.*; import com.zt.plat.module.qms.resource.material.dal.dataobject.MaterialInfomationDO; import com.zt.plat.module.qms.resource.material.dal.dataobject.MaterialProductDO; import com.zt.plat.module.qms.resource.material.dal.dataobject.MaterialUseEndReuseDO; @@ -24,6 +21,7 @@ import org.springframework.validation.annotation.Validated; import java.time.LocalDateTime; import java.util.List; import java.util.Map; +import java.util.Objects; import java.util.stream.Collectors; import static com.zt.plat.framework.common.exception.util.ServiceExceptionUtil.exception; @@ -51,10 +49,18 @@ public class MaterialUseEndReuseServiceImpl implements MaterialUseEndReuseServic @Transactional @Override public MaterialUseEndReuseRespVO createMaterialUseEndReuse(MaterialUseEndReuseSaveReqVO createReqVO) { - List infomationIds = createReqVO.getInfomationIds(); - List infomations = materialInfomationService.getMaterialInfomationsByIds(infomationIds); - if (CollUtil.isEmpty(infomations) || infomations.size() != infomationIds.size()) - throw new ServiceException(1_032_160_000, "物料实例不存在或与传入的数量不匹配"); + List detailList = createReqVO.getDetailList(); + MaterialNormalOperationType operationType = MaterialNormalOperationType.fromName(createReqVO.getBusinessType()); + + List infomationIds = detailList.stream().map(MaterialUseEndReuseDetailSaveReqVO::getInfomationId) + .filter(Objects::nonNull).toList(); + if (MaterialNormalOperationType.used_mark.equals(operationType)) { + if (CollUtil.isEmpty(infomationIds)) throw new ServiceException(1_032_160_000, "用完标记请选择物料实例"); + List infomations = materialInfomationService.getMaterialInfomationsByIds(infomationIds); + if (CollUtil.isEmpty(infomations) || infomations.size() != infomationIds.size()) + throw new ServiceException(1_032_160_000, "物料实例不存在或与传入的数量不匹配"); + } + // 插入 MaterialUseEndReuseDO useEndReuseDO = BeanUtils.toBean(createReqVO, MaterialUseEndReuseDO.class); @@ -67,12 +73,15 @@ public class MaterialUseEndReuseServiceImpl implements MaterialUseEndReuseServic materialUseEndReuseMapper.insert(useEndReuseDO); // 保存明细 - List detailDOS = infomationIds.stream().map(infomationId -> - new MaterialUseEndReuseDetailDO().setParentId(useEndReuseDO.getId()).setInfomationId(infomationId)).toList(); + List detailDOS = detailList.stream().map(detail -> { + MaterialUseEndReuseDetailDO detailDO = BeanUtils.toBean(detail, MaterialUseEndReuseDetailDO.class); + detailDO.setParentId(useEndReuseDO.getId()); + return detailDO; + }).toList(); materialUseEndReuseDetailService.saveBatch(detailDOS); // 变更物料用完标记状态 - if (MaterialNormalOperationType.usedMark.getName().equals(createReqVO.getBusinessType())) { + if (MaterialNormalOperationType.used_mark.equals(operationType) && CollUtil.isNotEmpty(infomationIds)) { materialInfomationService.updateByIds(infomationIds, new MaterialInfomationDO().setUseEndFlag(1)); } // 返回 @@ -94,7 +103,7 @@ public class MaterialUseEndReuseServiceImpl implements MaterialUseEndReuseServic MaterialUseEndReuseDO useEndReuseDO = materialUseEndReuseMapper.selectById(id); if (useEndReuseDO == null) throw exception(MATERIAL_USE_END_REUSE_NOT_EXISTS); // 用完标记不可删除 - if (MaterialNormalOperationType.usedMark.getName().equals(useEndReuseDO.getBusinessType())) + if (MaterialNormalOperationType.used_mark.getName().equals(useEndReuseDO.getBusinessType())) throw new ServiceException(1_032_160_000, "用完标记记录不可删除"); // 删除明细 materialUseEndReuseDetailService.deleteDetailListByParentId(id); @@ -111,7 +120,7 @@ public class MaterialUseEndReuseServiceImpl implements MaterialUseEndReuseServic } for (MaterialUseEndReuseDO useEndReuseDO : useEndReuseDOS) { // 用完标记不可删除 - if (MaterialNormalOperationType.usedMark.getName().equals(useEndReuseDO.getBusinessType())) + if (MaterialNormalOperationType.used_mark.getName().equals(useEndReuseDO.getBusinessType())) throw new ServiceException(1_032_160_000, "用完标记记录不可删除"); } // 删除明细 diff --git a/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/resource/material/service/MaterialUseRecordDetailServiceImpl.java b/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/resource/material/service/MaterialUseRecordDetailServiceImpl.java index 1fc11dcd..4585d423 100644 --- a/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/resource/material/service/MaterialUseRecordDetailServiceImpl.java +++ b/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/resource/material/service/MaterialUseRecordDetailServiceImpl.java @@ -18,7 +18,6 @@ import com.zt.plat.module.qms.resource.material.dal.mapper.MaterialUseRecordDeta import com.zt.plat.module.qms.resource.material.enums.MaterialOutboundType; import jakarta.annotation.Resource; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.context.annotation.Lazy; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import org.springframework.validation.annotation.Validated; @@ -28,7 +27,6 @@ import java.time.LocalDateTime; import java.util.*; import java.util.function.Function; import java.util.stream.Collectors; -import java.util.stream.Stream; import static com.zt.plat.framework.common.exception.util.ServiceExceptionUtil.exception; import static com.zt.plat.module.qms.enums.ErrorCodeConstants.MATERIAL_USE_RECORD_DETAIL_NOT_EXISTS; @@ -225,7 +223,7 @@ public class MaterialUseRecordDetailServiceImpl implements MaterialUseRecordDeta // 保存领用记录 MaterialInventoryOutboundSaveReqVO outboundSaveReqVO = new MaterialInventoryOutboundSaveReqVO() - .setBusinessType(MaterialOutboundType.receiveOutbound.getName()) + .setBusinessType(MaterialOutboundType.receive_outbound.getName()) .setInfomationIds(Collections.singletonList(infomationDO.getId())) .setApplyUser(recordDOS.get(0).getUserName()).setApplyUserId(recordDOS.get(0).getUserId()) .setSuperviseUser(recordDOS.get(0).getSupervisorName()) diff --git a/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/resource/material/service/MaterialUseRecordServiceImpl.java b/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/resource/material/service/MaterialUseRecordServiceImpl.java index 7b1cf580..a97dbdb7 100644 --- a/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/resource/material/service/MaterialUseRecordServiceImpl.java +++ b/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/resource/material/service/MaterialUseRecordServiceImpl.java @@ -11,6 +11,7 @@ import com.zt.plat.module.qms.resource.material.controller.vo.*; import com.zt.plat.module.qms.resource.material.dal.dataobject.*; import com.zt.plat.module.qms.resource.material.dal.mapper.MaterialUseRecordMapper; import com.zt.plat.module.qms.resource.material.enums.MaterialInfomationOrigin; +import com.zt.plat.module.qms.resource.material.enums.MaterialNormalOperationType; import com.zt.plat.module.qms.resource.material.enums.MaterialOutboundType; import jakarta.annotation.Resource; import org.jspecify.annotations.NonNull; @@ -43,6 +44,8 @@ public class MaterialUseRecordServiceImpl implements MaterialUseRecordService { @Autowired private MaterialInfomationService materialInfomationService; + @Autowired + private MaterialUseEndReuseService materialUseEndReuseService; @Transactional @Override @@ -72,6 +75,10 @@ public class MaterialUseRecordServiceImpl implements MaterialUseRecordService { if (operationQuantity.compareTo(remainingVolume) >= 0) { infomationDO.setUseEndFlag(1); // TODO 新增用完标记记录 + /*materialUseEndReuseService.createMaterialUseEndReuse(new MaterialUseEndReuseSaveReqVO() + .setBusinessType(MaterialNormalOperationType.used_mark.getName()) + .setRemark("物料已用完,自动标记") + .setDetailList(new ArrayList<>()))*/ } materialInfomationService.updateById(infomationDO);