From 58aa53eb682127c4165dc0eee23cccbc4ddfdf79 Mon Sep 17 00:00:00 2001 From: shusir <497819738@qq.com> Date: Wed, 25 Mar 2026 14:30:03 +0800 Subject: [PATCH] =?UTF-8?q?fix:=E7=89=A9=E6=96=99=E7=9B=98=E7=82=B9?= =?UTF-8?q?=E5=87=BA=E5=85=A5=E5=BA=93=EF=BC=9B=E4=BF=AE=E5=A4=8D=E5=BE=AA?= =?UTF-8?q?=E7=8E=AF=E4=BE=9D=E8=B5=96=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...aterialInventoryCheckDetailController.java | 8 +- .../admin/MaterialLifecycleController.java | 6 + .../MaterialInventoryCheckDetailRespVO.java | 3 + .../MaterialInventoryCheckDetailDO.java | 5 + .../material/enums/MaterialFlowType.java | 2 +- .../material/enums/MaterialInboundType.java | 2 +- .../material/enums/MaterialOutboundType.java | 2 +- .../service/MaterialBatchService.java | 29 +- .../service/MaterialBatchServiceImpl.java | 81 +----- .../service/MaterialInfomationService.java | 2 +- .../MaterialInfomationServiceImpl.java | 15 +- .../MaterialInventoryCheckDetailService.java | 39 +++ ...terialInventoryCheckDetailServiceImpl.java | 92 +++--- .../MaterialInventoryCheckItemService.java | 8 - ...MaterialInventoryCheckItemServiceImpl.java | 9 - .../MaterialInventoryInboundService.java | 9 + .../MaterialInventoryInboundServiceImpl.java | 14 + .../MaterialInventoryOutboundService.java | 8 +- .../MaterialInventoryOutboundServiceImpl.java | 40 +-- .../MaterialLifecycleDetailServiceImpl.java | 4 +- .../service/MaterialLifecycleService.java | 12 +- .../service/MaterialLifecycleServiceImpl.java | 263 +++++++++++++++--- .../service/MaterialProductService.java | 9 + .../service/MaterialProductServiceImpl.java | 8 +- .../MaterialUseEndReuseServiceImpl.java | 2 +- .../MaterialUseRecordDetailServiceImpl.java | 2 +- .../service/MaterialUseRecordServiceImpl.java | 9 +- 27 files changed, 413 insertions(+), 270 deletions(-) diff --git a/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/resource/material/controller/admin/MaterialInventoryCheckDetailController.java b/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/resource/material/controller/admin/MaterialInventoryCheckDetailController.java index 5b7de1c0..4c282888 100644 --- a/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/resource/material/controller/admin/MaterialInventoryCheckDetailController.java +++ b/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/resource/material/controller/admin/MaterialInventoryCheckDetailController.java @@ -39,19 +39,13 @@ public class MaterialInventoryCheckDetailController implements BusinessControlle @Resource private MaterialInventoryCheckDetailService materialInventoryCheckDetailService; - @PostMapping("/add") +// @PostMapping("/add") @Operation(summary = "新增库存盘点明细") // @PreAuthorize("@ss.hasPermission('qms:material-inventory-check-detail:create')") public CommonResult createMaterialInventoryCheckDetail(@Valid @RequestBody MaterialInventoryCheckDetailSaveReqVO createReqVO) { return success(materialInventoryCheckDetailService.createMaterialInventoryCheckDetail(createReqVO)); } - @PutMapping("/inventory-inf") - @Operation(summary = "盘点物料") - public CommonResult inventoryCheckInfomation(@Valid @RequestBody MaterialInventoryCheckDetailSaveReqVO inventoryReqVO) { - return success(materialInventoryCheckDetailService.inventoryCheckInfomation(inventoryReqVO)); - } - // @PutMapping("/update") @Operation(summary = "更新库存盘点明细") @PreAuthorize("@ss.hasPermission('qms:material-inventory-check-detail:update')") 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 b9783e96..51e362c3 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 @@ -116,6 +116,12 @@ public class MaterialLifecycleController extends AbstractFileUploadController im return success(materialLifecycleService.operatorSubmitLifecycle(id)); } + @PutMapping("/inventory-inf") + @Operation(summary = "盘点物料") + public CommonResult inventoryCheckInfomation(@Valid @RequestBody MaterialInventoryCheckDetailSaveReqVO inventoryReqVO) { + return success(materialLifecycleService.inventoryCheckInfomation(inventoryReqVO)); + } + @GetMapping("/export-excel") @Operation(summary = "导出物料通用流程,物料验收、退换货 Excel") @PreAuthorize("@ss.hasPermission('qms:material-lifecycle:export')") diff --git a/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/resource/material/controller/vo/MaterialInventoryCheckDetailRespVO.java b/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/resource/material/controller/vo/MaterialInventoryCheckDetailRespVO.java index bb86a43e..c932b2ff 100644 --- a/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/resource/material/controller/vo/MaterialInventoryCheckDetailRespVO.java +++ b/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/resource/material/controller/vo/MaterialInventoryCheckDetailRespVO.java @@ -45,6 +45,9 @@ public class MaterialInventoryCheckDetailRespVO { @ExcelProperty("是否存在,1-存在,0-不存在") private Integer present; + @Schema(description = "是否在库,1-在库,0-不在库") + private Integer atWarehouse; + @Schema(description = "当前数量") @ExcelProperty("当前数量") private String currentQuantity; diff --git a/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/resource/material/dal/dataobject/MaterialInventoryCheckDetailDO.java b/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/resource/material/dal/dataobject/MaterialInventoryCheckDetailDO.java index 41587f16..5dfb8926 100644 --- a/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/resource/material/dal/dataobject/MaterialInventoryCheckDetailDO.java +++ b/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/resource/material/dal/dataobject/MaterialInventoryCheckDetailDO.java @@ -52,6 +52,11 @@ public class MaterialInventoryCheckDetailDO extends BusinessBaseDO { @TableField("PRST") private Integer present; /** + * 是否在库,1-在库,0-不在库 + */ + @TableField("AT_WRH") + private Integer atWarehouse; + /** * 当前数量 */ @TableField("CRNT_QTY") diff --git a/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/resource/material/enums/MaterialFlowType.java b/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/resource/material/enums/MaterialFlowType.java index 409f5ebc..6c2c65e8 100644 --- a/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/resource/material/enums/MaterialFlowType.java +++ b/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/resource/material/enums/MaterialFlowType.java @@ -9,7 +9,7 @@ public enum MaterialFlowType { return_material("退货"), - exchange_material("换货"), + replace_material("换货"), make_apply("配置申请"), diff --git a/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/resource/material/enums/MaterialInboundType.java b/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/resource/material/enums/MaterialInboundType.java index 1472629d..ed93e4b0 100644 --- a/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/resource/material/enums/MaterialInboundType.java +++ b/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/resource/material/enums/MaterialInboundType.java @@ -9,7 +9,7 @@ import lombok.Getter; public enum MaterialInboundType { acceptance_inbound("验收入库"), - check_over_inbound("盘盈入库"); + check_inbound("盘点入库"); private final String name; diff --git a/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/resource/material/enums/MaterialOutboundType.java b/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/resource/material/enums/MaterialOutboundType.java index b83b0466..2eea45f6 100644 --- a/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/resource/material/enums/MaterialOutboundType.java +++ b/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/resource/material/enums/MaterialOutboundType.java @@ -13,7 +13,7 @@ public enum MaterialOutboundType { replace_outbound("换货出库"), - check_short_outbound("盘亏出库"); + check_outbound("盘点出库"); private final String name; diff --git a/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/resource/material/service/MaterialBatchService.java b/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/resource/material/service/MaterialBatchService.java index ce8e5ffb..e8cd9ef0 100644 --- a/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/resource/material/service/MaterialBatchService.java +++ b/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/resource/material/service/MaterialBatchService.java @@ -105,14 +105,6 @@ public interface MaterialBatchService { */ void updateById(MaterialBatchDO gongDO); - /** - * 更新批次工段验收状态 - * - * @param lfcId 流程id - * @param status 验收状态 - */ - void updateMaterialBatchAcceptStatusByLfcId(Long lfcId, String status); - /** * 根据批次id 获取批次信息 * @@ -185,13 +177,6 @@ public interface MaterialBatchService { */ void updateBatchVerifyCalibrateCount(List batches, AdjustType adjustType); - /** - * 创建批次检定拆分工段 - * - * @param id 流程id - */ - void createVerifyBatchAssignsByLfcId(Long id); - /** * 导入物料批次列表 * @@ -199,4 +184,18 @@ public interface MaterialBatchService { * @return 导入结果 */ MaterialBatchImportRespVO importMaterialBatchList(List importList); + + /** + * 根据ids 更新 + * + * @param ids ids + */ + void updateByIds(List ids, MaterialBatchDO updateEntity); + + /** + * 批量保存 + * + * @param dos 实体集合 + */ + void saveBatch(List dos); } \ 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 e408d5da..87a4c60d 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 @@ -69,11 +69,6 @@ public class MaterialBatchServiceImpl implements MaterialBatchService { @Autowired private MaterialProductService materialProductService; - @Lazy - @Autowired - private MaterialLifecycleService materialLifecycleService; - @Autowired - private BpmProcessInstanceApi bpmProcessInstanceApi; @Autowired private SupplierService supplierService; @@ -270,17 +265,6 @@ public class MaterialBatchServiceImpl implements MaterialBatchService { materialBatchMapper.updateById(gongDO); } - @Override - public void updateMaterialBatchAcceptStatusByLfcId(Long lfcId, String status) { - List detailList = materialLifecycleService.getDetailListByLfcId(lfcId); - if (CollUtil.isEmpty(detailList)) return; - List gongIds = detailList.stream().map(MaterialLifecycleDetailDO::getBatchGongduanId).toList(); - if (CollUtil.isEmpty(gongIds)) return; - MaterialBatchDO updateEntity = new MaterialBatchDO().setAcceptanceStatus(status); - materialBatchMapper.update(updateEntity, Wrappers.lambdaQuery(MaterialBatchDO.class) - .in(MaterialBatchDO::getId, gongIds)); - } - @Override public List getBatchListByBatchIds(List batchIds) { @@ -489,39 +473,6 @@ public class MaterialBatchServiceImpl implements MaterialBatchService { materialBatchMapper.updateBatch(batchDOS); } - @Override - public void createVerifyBatchAssignsByLfcId(Long id) { - MaterialLifecycleDO lifecycleDO = materialLifecycleService.getMaterialLifecycle(id); - if (lifecycleDO == null) return; - List lifecycleDetailDOs = materialLifecycleService.getDetailListByLfcId(id); - if (CollUtil.isEmpty(lifecycleDetailDOs)) return; - String flowInstanceId = lifecycleDO.getFlowInstanceId(); - if (StrUtil.isEmpty(flowInstanceId)) return; - CommonResult processInstance = bpmProcessInstanceApi.getProcessInstance(flowInstanceId); - BpmProcessInstanceRespDTO instanceData = processInstance.getData(); - UserSimpleDTO startUser = instanceData.getStartUser(); - List batIds = lifecycleDetailDOs.stream().map(MaterialLifecycleDetailDO::getBatchId).toList(); - List batchDOS = this.getBatchListByBatchIds(batIds); - Map batchDOMap = batchDOS.stream().collect(Collectors.toMap(MaterialBatchDO::getId, Function.identity())); - List gongs = lifecycleDetailDOs.stream().map(detailDO -> { - MaterialBatchDO batchDO = batchDOMap.get(detailDO.getBatchId()); - Long deptId = startUser.getDeptId(); - return new MaterialBatchDO() - .setParentId(detailDO.getBatchId()) - .setProductId(batchDO.getProductId()) - .setAssignDepartmentId(deptId) - .setAssignDepartmentName(startUser.getDeptName()) - .setInboundQuantity(detailDO.getQualifiedCount()) - .setBatchNo(batchDO.getBatchNo()) - .setRemaineQuantity(detailDO.getQualifiedCount()) - .setAcceptanceStatus(MaterialAcceptStatus.accepted.name()) - .setSubmitStatus(1).setSubmitDate(batchDO.getSubmitDate()) - .setRemark(String.format("【%s】于%s发起检定,检定数量:%s,合格数量:%s", startUser.getNickname(), instanceData.getStartTime().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")), - detailDO.getInfluenceCount(), detailDO.getQualifiedCount())); - }).toList(); - materialBatchMapper.insertBatch(gongs); - } - @Override public MaterialBatchImportRespVO importMaterialBatchList(List importList) { if (CollUtil.isEmpty(importList)) throw new ServiceException(1_032_160_000, "导入数据不能为空"); @@ -534,22 +485,7 @@ public class MaterialBatchServiceImpl implements MaterialBatchService { if (batch.getInboundQuantity() == null || batch.getInboundQuantity().compareTo(BigDecimal.ZERO) <= 0) throw new ServiceException(1_032_160_000, "批次数量需要大于0"); } - // 获取大类id 每个物料都得校验是否存在 - /*Set pdtCodes = importList.stream().map(MaterialBatchImportExcelVO::getProductCode).collect(Collectors.toSet()); - List products = materialProductService.getProductListByPdtCodes(new ArrayList<>(pdtCodes)); - if (CollUtil.isEmpty(products)) throw new ServiceException(1_032_160_000, "未找到对应的物料"); - Map productDOMapByCode = products.stream().collect(Collectors.toMap(MaterialProductDO::getCode, Function.identity())); - if (pdtCodes.size() != products.size()) { - List notFoundCodes = new ArrayList<>(); - for (String pdtCode : pdtCodes) { - if (!productDOMapByCode.containsKey(pdtCode)) { - notFoundCodes.add(pdtCode); - } - } - if (CollUtil.isNotEmpty(notFoundCodes)) { - throw new ServiceException(1_032_160_000, "未找到以下物料:" + String.join(", ", notFoundCodes)); - } - }*/ + // 获取物料编码和规格,使用编码 + 规格匹配物料 Set pdtCodes = importList.stream().map(MaterialBatchImportExcelVO::getProductCode).collect(Collectors.toSet()); Set specifications = importList.stream().map(MaterialBatchImportExcelVO::getProductSpecification).collect(Collectors.toSet()); @@ -631,6 +567,19 @@ public class MaterialBatchServiceImpl implements MaterialBatchService { .setSuccessCount(successBatchNos.size()); } + @Override + public void updateByIds(List ids, MaterialBatchDO updateEntity) { + if (CollUtil.isEmpty(ids)) return; + materialBatchMapper.update(updateEntity, Wrappers.lambdaQuery(MaterialBatchDO.class) + .in(MaterialBatchDO::getId, ids)); + } + + @Override + public void saveBatch(List dos) { + if (CollUtil.isEmpty(dos)) return; + materialBatchMapper.insertBatch(dos); + } + private void lockBatchOrGongReturnExchangeCount(LockType lockType, List batchOrGongDOS, Map lifecycleDetailDOMapByBatOrGongId) { for (MaterialBatchDO batOrGong : batchOrGongDOS) { @@ -661,7 +610,7 @@ public class MaterialBatchServiceImpl implements MaterialBatchService { BigDecimal returnQuantity = adjustType == AdjustType.add ? batOrGong.getReturnQuantity().add(influenceCount) : batOrGong.getReturnQuantity().subtract(influenceCount); batOrGong.setReturnQuantity(returnQuantity); - } else if (MaterialFlowType.exchange_material.getName().equals(businessType)) { + } else if (MaterialFlowType.replace_material.getName().equals(businessType)) { BigDecimal replaceQuantity = adjustType == AdjustType.add ? batOrGong.getReplaceQuantity().add(influenceCount) : batOrGong.getReplaceQuantity().subtract(influenceCount); batOrGong.setReplaceQuantity(replaceQuantity); 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 a1120831..3bfd32db 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 @@ -105,7 +105,7 @@ public interface MaterialInfomationService { * @param infomationIds id集合 * @return 物料信息 */ - List getMaterialInfomationsByIds(List infomationIds); + List getListByIds(List infomationIds); /** * 保存物料实例 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 e020e492..8cb53f57 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 @@ -24,7 +24,6 @@ import com.zt.plat.module.qms.resource.material.dal.dataobject.*; import com.zt.plat.module.qms.resource.material.dal.mapper.MaterialInfomationMapper; import com.zt.plat.module.qms.resource.material.enums.MaterialInfomationOneBusinessType; import com.zt.plat.module.qms.resource.material.enums.MaterialInfomationOrigin; -import com.zt.plat.module.qms.resource.material.enums.MaterialInfomationPageBusinessType; import com.zt.plat.module.system.api.dept.DeptApi; import com.zt.plat.module.system.api.dept.dto.DeptRespDTO; import groovy.util.logging.Slf4j; @@ -65,12 +64,6 @@ public class MaterialInfomationServiceImpl implements MaterialInfomationService private DeptApi deptApi; @Autowired private ConfigWarehouseLocationService configWarehouseLocationService; - @Lazy - @Autowired - private MaterialInventoryCheckItemService materialInventoryCheckItemService; - @Lazy - @Autowired - private MaterialLifecycleService materialLifecycleService; @Override public MaterialInfomationRespVO createMaterialInfomation(MaterialInfomationSaveReqVO createReqVO) { @@ -205,7 +198,7 @@ public class MaterialInfomationServiceImpl implements MaterialInfomationService } @Override - public List getMaterialInfomationsByIds(List infomationIds) { + public List getListByIds(List infomationIds) { return materialInfomationMapper.selectByIds(infomationIds); } @@ -320,7 +313,7 @@ public class MaterialInfomationServiceImpl implements MaterialInfomationService @Override public void updateInfomationInbOrOutbStatus(List infomations, AdjustType adjustType) { List infIds = infomations.stream().map(MaterialLifecycleDetailDO::getInfomationId).toList(); - List infomationDOS = getMaterialInfomationsByIds(infIds); + List infomationDOS = getListByIds(infIds); for (MaterialInfomationDO infomationDO : infomationDOS) { switch (adjustType) { case add: @@ -338,7 +331,7 @@ 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); + List infomationDOS = getListByIds(infIds); for (MaterialInfomationDO infomationDO : infomationDOS) { switch (lockType) { case lock: @@ -356,7 +349,7 @@ public class MaterialInfomationServiceImpl implements MaterialInfomationService @Override public void openSealTreatment(List infomationIds, MaterialUseEndReuseDO openInfo) { - List infomations = this.getMaterialInfomationsByIds(infomationIds); + List infomations = this.getListByIds(infomationIds); if (CollUtil.isEmpty(infomations)) return; List productIds = infomations.stream().map(MaterialInfomationDO::getProductId).toList(); List products = materialProductService.getListByIds(productIds); diff --git a/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/resource/material/service/MaterialInventoryCheckDetailService.java b/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/resource/material/service/MaterialInventoryCheckDetailService.java index 01fa43c1..01c63ec2 100644 --- a/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/resource/material/service/MaterialInventoryCheckDetailService.java +++ b/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/resource/material/service/MaterialInventoryCheckDetailService.java @@ -91,4 +91,43 @@ public interface MaterialInventoryCheckDetailService { * @return 盘点列表 */ PageResult getPageWithInf(@Valid MaterialInventoryCheckDetailPageReqVO pageReqVO); + + /** + * 盘点明细列表 - 实际存在但不在库的 + * + * @param lfcId 仓库id + * @return 盘点列表 + */ + List getListNotAtWarehouse(Long lfcId); + + /** + * 盘点明细列表 - 在库但实际不存在的 + * + * @param lfcId 仓库id + * @return 盘点列表 + */ + List getListNotPresentAndAtWarehouse(Long lfcId); + + /** + * 根据盘点id和物料id查询盘点明细 + * + * @param checkId 盘点id + * @param infId 物料id + * @return 盘点明细 + */ + MaterialInventoryCheckDetailDO getByCheckIdAndInfId(Long checkId, Long infId); + + /** + * 保存盘点明细 + * + * @param checkDetailDO 盘点明细 + */ + void save(MaterialInventoryCheckDetailDO checkDetailDO); + + /** + * 根据id更新盘点明细 + * + * @param checkDetailDO 盘点明细 + */ + void updateById(MaterialInventoryCheckDetailDO checkDetailDO); } \ 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/MaterialInventoryCheckDetailServiceImpl.java b/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/resource/material/service/MaterialInventoryCheckDetailServiceImpl.java index 12323c0b..bdeeda18 100644 --- a/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/resource/material/service/MaterialInventoryCheckDetailServiceImpl.java +++ b/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/resource/material/service/MaterialInventoryCheckDetailServiceImpl.java @@ -43,14 +43,6 @@ public class MaterialInventoryCheckDetailServiceImpl implements MaterialInventor @Resource private MaterialInventoryCheckDetailMapper materialInventoryCheckDetailMapper; - @Autowired - private MaterialInfomationService materialInfomationService; - @Autowired - private MaterialLifecycleService materialLifecycleService; - @Autowired - private MaterialInventoryCheckItemService materialInventoryCheckItemService; - @Autowired - private ConfigWarehouseLocationService configWarehouseLocationService; @Transactional @Override @@ -124,56 +116,7 @@ public class MaterialInventoryCheckDetailServiceImpl implements MaterialInventor @Override public MaterialInventoryCheckDetailRespVO inventoryCheckInfomation(MaterialInventoryCheckDetailSaveReqVO inventoryReqVO) { - Long infomationId = inventoryReqVO.getInfomationId(); - MaterialInfomationDO infomationDO = materialInfomationService.getMaterialInfomation(infomationId); - if (infomationDO == null) throw exception(MATERIAL_INFOMATION_NOT_EXISTS); - Long checkId = inventoryReqVO.getCheckId(); - MaterialLifecycleDO lifecycleDO = materialLifecycleService.getMaterialLifecycle(checkId); - if (lifecycleDO == null) throw exception(MATERIAL_LIFECYCLE_NOT_EXISTS); - if (lifecycleDO.getSubmitStatus() != 1) throw new ServiceException(1_032_160_000, "盘点单未提交"); - - LocalDateTime checkTime = lifecycleDO.getApplyTime(); - if (infomationDO.getCreateTime().isAfter(checkTime)) throw new ServiceException(1_032_160_000, "此物料在发起盘点后入库,不可盘点"); - - // 检查是否已经盘点过 - MaterialInventoryCheckDetailDO checkDetailDO = materialInventoryCheckDetailMapper.selectOne(Wrappers.lambdaQuery(MaterialInventoryCheckDetailDO.class) - .eq(MaterialInventoryCheckDetailDO::getCheckId, checkId) - .eq(MaterialInventoryCheckDetailDO::getInfomationId, infomationId)); - MaterialInventoryCheckItemDO item = materialInventoryCheckItemService.getItemByCheckIdAndPdtId(checkId, infomationDO.getProductId()); - if (checkDetailDO != null) { - if (checkDetailDO.getPresent() == 1) throw new ServiceException(1_032_160_000, "此物料已盘点过"); - } else { - // 检查是否未领用了没拿走的情况 - if (infomationDO.getUsageStatus() != 1) throw new ServiceException(1_032_160_000, "此盘点单不可盘点该物料"); - // 根据仓库和盘点项匹配物料 - // 1. 匹配上 新建盘点明细(领用了没拿走) - // 2. 匹配不上 新建盘点项和盘点明细(领用了没拿走且大类不在盘点项中) - JSONObject cstCfgObj = JSONUtil.parseObj(lifecycleDO.getCustomConfig()); - JSONArray jsonWarehouseIds = cstCfgObj.getJSONArray("warehouseIds"); - List warehouseIds = CollUtil.isEmpty(jsonWarehouseIds) ? List.of() : jsonWarehouseIds.toList(Long.class); - if (CollUtil.isEmpty(warehouseIds)) throw new ServiceException(1_032_160_000, "此盘点单没有配置盘点仓库"); - ConfigWarehouseLocationDO location = configWarehouseLocationService.getConfigWarehouseLocation(infomationDO.getLocationId()); - if (location == null) throw exception(CONFIG_WAREHOUSE_LOCATION_NOT_EXISTS); - // 仓库匹配不成功, - if (!warehouseIds.contains(location.getParentId())) throw new ServiceException(1_032_160_000, "该物料所在的仓库不在此盘点单中"); - if (item == null) { - // 盘点项匹配不成功,新建盘点项 - item = new MaterialInventoryCheckItemDO() - .setParentId(checkId).setProductId(infomationDO.getProductId()) - .setExpected(BigDecimal.valueOf(0)) - .setRemark("盘点过程中新增的盘点项"); - materialInventoryCheckItemService.save(item); - } - checkDetailDO = new MaterialInventoryCheckDetailDO() - .setCheckId(checkId).setItemId(item.getId()).setInfomationId(infomationId) - .setCurrentQuantity(inventoryReqVO.getCurrentQuantity()) - .setRemark(StrUtil.isEmpty(inventoryReqVO.getRemark()) ? "已领用未拿走" : inventoryReqVO.getRemark()); - } - checkDetailDO.setPresent(1); - materialInventoryCheckDetailMapper.updateById(checkDetailDO); - item.setActual(item.getActual().add(BigDecimal.valueOf(1))); - materialInventoryCheckItemService.updateById(item); - return BeanUtils.toBean(checkDetailDO, MaterialInventoryCheckDetailRespVO.class); + return null; } @Override @@ -181,4 +124,37 @@ public class MaterialInventoryCheckDetailServiceImpl implements MaterialInventor return materialInventoryCheckDetailMapper.selectPageWithInf(pageReqVO); } + @Override + public List getListNotAtWarehouse(Long lfcId) { + return materialInventoryCheckDetailMapper.selectList(Wrappers.lambdaQuery(MaterialInventoryCheckDetailDO.class) + .eq(MaterialInventoryCheckDetailDO::getCheckId, lfcId) + .eq(MaterialInventoryCheckDetailDO::getAtWarehouse, 0) + .eq(MaterialInventoryCheckDetailDO::getPresent, 1)); + } + + @Override + public List getListNotPresentAndAtWarehouse(Long lfcId) { + return materialInventoryCheckDetailMapper.selectList(Wrappers.lambdaQuery(MaterialInventoryCheckDetailDO.class) + .eq(MaterialInventoryCheckDetailDO::getCheckId, lfcId) + .eq(MaterialInventoryCheckDetailDO::getAtWarehouse, 1) + .eq(MaterialInventoryCheckDetailDO::getPresent, 0)); + } + + @Override + public MaterialInventoryCheckDetailDO getByCheckIdAndInfId(Long checkId, Long infId) { + return materialInventoryCheckDetailMapper.selectOne(Wrappers.lambdaQuery(MaterialInventoryCheckDetailDO.class) + .eq(MaterialInventoryCheckDetailDO::getCheckId, checkId) + .eq(MaterialInventoryCheckDetailDO::getInfomationId, infId)); + } + + @Override + public void save(MaterialInventoryCheckDetailDO checkDetailDO) { + materialInventoryCheckDetailMapper.insert(checkDetailDO); + } + + @Override + public void updateById(MaterialInventoryCheckDetailDO checkDetailDO) { + materialInventoryCheckDetailMapper.updateById(checkDetailDO); + } + } \ 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/MaterialInventoryCheckItemService.java b/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/resource/material/service/MaterialInventoryCheckItemService.java index da0ae9a5..8b96ebb8 100644 --- a/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/resource/material/service/MaterialInventoryCheckItemService.java +++ b/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/resource/material/service/MaterialInventoryCheckItemService.java @@ -115,14 +115,6 @@ public interface MaterialInventoryCheckItemService { */ void updateBatch(List items); - /** - * 根据盘点项id查询盘点明细 - * - * @param id 盘点项id - * @return 盘点项详情 - */ - List getDetailListById(Long id); - /** * 保存盘点项 * diff --git a/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/resource/material/service/MaterialInventoryCheckItemServiceImpl.java b/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/resource/material/service/MaterialInventoryCheckItemServiceImpl.java index 3d6efe73..a9a3ec8a 100644 --- a/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/resource/material/service/MaterialInventoryCheckItemServiceImpl.java +++ b/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/resource/material/service/MaterialInventoryCheckItemServiceImpl.java @@ -33,10 +33,6 @@ public class MaterialInventoryCheckItemServiceImpl implements MaterialInventoryC @Resource private MaterialInventoryCheckItemMapper materialInventoryCheckItemMapper; - @Lazy - @Autowired - private MaterialInventoryCheckDetailService materialInventoryCheckDetailService; - @Override public MaterialInventoryCheckItemRespVO createMaterialInventoryCheckItem(MaterialInventoryCheckItemSaveReqVO createReqVO) { // 插入 @@ -135,11 +131,6 @@ public class MaterialInventoryCheckItemServiceImpl implements MaterialInventoryC materialInventoryCheckItemMapper.updateBatch(items); } - @Override - public List getDetailListById(Long id) { - return materialInventoryCheckDetailService.getListByItemId(id); - } - @Override public void save(MaterialInventoryCheckItemDO item) { materialInventoryCheckItemMapper.insert(item); diff --git a/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/resource/material/service/MaterialInventoryInboundService.java b/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/resource/material/service/MaterialInventoryInboundService.java index 4b4e1058..876d2ec2 100644 --- a/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/resource/material/service/MaterialInventoryInboundService.java +++ b/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/resource/material/service/MaterialInventoryInboundService.java @@ -5,6 +5,7 @@ import com.zt.plat.module.qms.resource.material.controller.vo.MaterialInventoryI import com.zt.plat.module.qms.resource.material.controller.vo.MaterialInventoryInboundRespVO; import com.zt.plat.module.qms.resource.material.controller.vo.MaterialInventoryInboundSaveReqVO; import com.zt.plat.module.qms.resource.material.dal.dataobject.MaterialInventoryInboundDO; +import com.zt.plat.module.qms.resource.material.dal.dataobject.MaterialLifecycleDO; import jakarta.validation.Valid; import java.math.BigDecimal; @@ -68,4 +69,12 @@ public interface MaterialInventoryInboundService { * @param reqQuantity 入库数量 */ void inboundQtyLimit(BigDecimal reqQuantity); + + + /** + * 批量保存入库 + * + * @param inbounds 入库 + */ + void saveBatch(List inbounds); } \ 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/MaterialInventoryInboundServiceImpl.java b/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/resource/material/service/MaterialInventoryInboundServiceImpl.java index c5ab3a6f..06fe1834 100644 --- a/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/resource/material/service/MaterialInventoryInboundServiceImpl.java +++ b/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/resource/material/service/MaterialInventoryInboundServiceImpl.java @@ -19,16 +19,25 @@ import com.zt.plat.module.qms.resource.material.controller.vo.MaterialInventoryI import com.zt.plat.module.qms.resource.material.dal.dataobject.*; import com.zt.plat.module.qms.resource.material.dal.mapper.MaterialInventoryInboundMapper; import com.zt.plat.module.qms.resource.material.enums.MaterialAcceptStatus; +import com.zt.plat.module.qms.resource.material.enums.MaterialInboundType; +import com.zt.plat.module.system.api.dept.DeptApi; +import com.zt.plat.module.system.api.dept.dto.DeptRespDTO; +import com.zt.plat.module.system.api.user.AdminUserApi; +import com.zt.plat.module.system.api.user.dto.AdminUserRespDTO; 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; import java.math.BigDecimal; import java.time.LocalDateTime; +import java.util.ArrayList; import java.util.Collections; import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; import static com.zt.plat.framework.common.exception.util.ServiceExceptionUtil.exception; import static com.zt.plat.module.qms.enums.ErrorCodeConstants.*; @@ -132,6 +141,11 @@ public class MaterialInventoryInboundServiceImpl implements MaterialInventoryInb } } + @Override + public void saveBatch(List inbounds) { + materialInventoryInboundMapper.insertBatch(inbounds); + } + private MaterialInventoryInboundDO getInbound(MaterialInventoryInboundSaveReqVO createReqVO, MaterialBatchDO gongDO) { MaterialInventoryInboundDO inbound = BeanUtils.toBean(createReqVO, MaterialInventoryInboundDO.class); LoginUser loginUser = SecurityFrameworkUtils.getLoginUser(); 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 80f9d0b6..c4ecc403 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 @@ -62,13 +62,6 @@ public interface MaterialInventoryOutboundService { */ PageResult getMaterialInventoryOutboundPage(MaterialInventoryOutboundPageReqVO pageReqVO); - /** - * 批量添加物料出库 - * - * @param lifecycleDO 物料退换货记录 - */ - void addMaterialInventoryOutboundsByLfc(MaterialLifecycleDO lifecycleDO); - /** * 按部门消耗统计 * @@ -76,4 +69,5 @@ public interface MaterialInventoryOutboundService { * @return 统计结果 */ List getUsageOutboundStatisticsByDept(@Valid MaterialInventoryOutboundPageReqVO reqVO); + } \ 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 51e2bb66..bc0a0493 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 @@ -62,10 +62,6 @@ public class MaterialInventoryOutboundServiceImpl implements MaterialInventoryOu @Autowired private MaterialUseRecordService materialUseRecordService; - @Lazy - @Autowired - private MaterialLifecycleService materialLifecycleService; - @Transactional @Override public MaterialInventoryOutboundRespVO createMaterialInventoryOutbound(MaterialInventoryOutboundSaveReqVO createReqVO) { @@ -74,7 +70,7 @@ public class MaterialInventoryOutboundServiceImpl implements MaterialInventoryOu List infomationIds = createReqVO.getInfomationIds(); if (CollUtil.isEmpty(infomationIds)) return BeanUtils.toBean(outboundDO, MaterialInventoryOutboundRespVO.class); - List infs = materialInfomationService.getMaterialInfomationsByIds(infomationIds); + List infs = materialInfomationService.getListByIds(infomationIds); if (CollUtil.isEmpty(infs) || infs.size() != infomationIds.size()) throw new ServiceException(1_032_160_000, "物料信息不存在或与传入的数量不匹配"); for (MaterialInfomationDO inf : infs) { @@ -94,9 +90,10 @@ public class MaterialInventoryOutboundServiceImpl implements MaterialInventoryOu // 保存出库明细 List outboundDetailDOS = infomationIds.stream().map( id -> new MaterialInventoryOutboundDetailDO() - .setOutboundId(outboundDO.getId()) - .setInfomationId(id) - .setQuantity(BigDecimal.valueOf(1))).toList(); + .setOutboundId(outboundDO.getId()) + .setInfomationId(id) + .setQuantity(BigDecimal.valueOf(1)) + .setRemark(outboundDO.getRemark())).toList(); materialInventoryOutboundDetailService.saveBatch(outboundDetailDOS); // 修改物料实例状态 List infIds = infs.stream().map(MaterialInfomationDO::getId).toList(); @@ -169,33 +166,6 @@ 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, verify_calibrate, inventory_check -> 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); - } - @Override public List getUsageOutboundStatisticsByDept(MaterialInventoryOutboundPageReqVO reqVO) { List outboundRespVOS = materialInventoryOutboundMapper.selectListUsageStatisticsMainDataByDept(reqVO); 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 1437f5f9..6cde7420 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 @@ -37,10 +37,8 @@ public class MaterialLifecycleDetailServiceImpl implements MaterialLifecycleDeta @Resource private MaterialLifecycleDetailMapper materialLifecycleDetailMapper; - @Lazy @Autowired private MaterialBatchService materialBatchService; - @Lazy @Autowired private MaterialProductService materialProductService; @@ -140,7 +138,7 @@ public class MaterialLifecycleDetailServiceImpl implements MaterialLifecycleDeta case verify_calibrate -> { return materialLifecycleDetailMapper.selectListWithBatchPdtBatInfo(lifecycleDO.getId()); } - case return_material, exchange_material -> { + case return_material, replace_material -> { List detailRespVOS = materialLifecycleDetailMapper.selectListWithReturnExchangeInfo(lifecycleDO.getId()); if (CollUtil.isEmpty(detailRespVOS)) return detailRespVOS; List batOrGongIds = detailRespVOS.stream() 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 ff534b40..9a13cf24 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 @@ -1,9 +1,7 @@ package com.zt.plat.module.qms.resource.material.service; import com.zt.plat.framework.common.pojo.PageResult; -import com.zt.plat.module.qms.resource.material.controller.vo.MaterialLifecyclePageReqVO; -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.controller.vo.*; 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; @@ -101,4 +99,12 @@ public interface MaterialLifecycleService { * @return 是否成功 */ Boolean operatorSubmitLifecycle(Long id); + + /** + * 盘点物料 + * + * @param inventoryReqVO 盘点信息 + * @return 盘点信息 + */ + MaterialInventoryCheckDetailRespVO inventoryCheckInfomation(@Valid MaterialInventoryCheckDetailSaveReqVO inventoryReqVO); } \ 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 e40fb0e3..7f1d67db 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 @@ -5,6 +5,7 @@ import cn.hutool.core.util.StrUtil; import cn.hutool.json.JSONUtil; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; +import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.zt.plat.framework.common.exception.ServiceException; import com.zt.plat.framework.common.pojo.CommonResult; import com.zt.plat.framework.common.pojo.PageResult; @@ -13,9 +14,7 @@ import com.zt.plat.framework.security.core.LoginUser; import com.zt.plat.framework.security.core.util.SecurityFrameworkUtils; import com.zt.plat.module.bpm.api.task.BpmProcessInstanceApi; import com.zt.plat.module.bpm.api.task.BpmTaskApi; -import com.zt.plat.module.bpm.api.task.dto.BpmProcessInstanceCreateReqDTO; -import com.zt.plat.module.bpm.api.task.dto.BpmTaskApproveReqDTO; -import com.zt.plat.module.bpm.api.task.dto.BpmTaskRespDTO; +import com.zt.plat.module.bpm.api.task.dto.*; import com.zt.plat.module.infra.api.businessfile.dto.BusinessFileWithUrlRespDTO; import com.zt.plat.module.qms.api.task.BMPCallbackInterface; import com.zt.plat.module.qms.api.task.dto.QmsBpmDTO; @@ -35,6 +34,8 @@ import com.zt.plat.module.qms.resource.material.dal.dataobject.*; import com.zt.plat.module.qms.resource.material.dal.mapper.MaterialLifecycleMapper; import com.zt.plat.module.qms.resource.material.enums.MaterialAcceptStatus; import com.zt.plat.module.qms.resource.material.enums.MaterialFlowType; +import com.zt.plat.module.qms.resource.material.enums.MaterialInboundType; +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; import com.zt.plat.module.system.api.user.AdminUserApi; @@ -50,14 +51,15 @@ import org.springframework.validation.annotation.Validated; import java.math.BigDecimal; import java.text.SimpleDateFormat; import java.time.LocalDateTime; +import java.time.format.DateTimeFormatter; import java.util.*; import java.util.function.Function; import java.util.stream.Collectors; import static com.zt.plat.framework.common.exception.util.ServiceExceptionUtil.exception; import static com.zt.plat.framework.common.exception.util.ServiceExceptionUtil.exception0; -import static com.zt.plat.module.qms.enums.ErrorCodeConstants.ERROR_CODE_MODULE_COMMON; -import static com.zt.plat.module.qms.enums.ErrorCodeConstants.MATERIAL_LIFECYCLE_NOT_EXISTS; +import static com.zt.plat.module.qms.enums.ErrorCodeConstants.*; +import static com.zt.plat.module.qms.enums.ErrorCodeConstants.CONFIG_WAREHOUSE_LOCATION_NOT_EXISTS; import static com.zt.plat.module.qms.enums.QmsBpmConstant.BPM_CALLBACK_BEAN_NAME; /** @@ -72,22 +74,16 @@ public class MaterialLifecycleServiceImpl implements MaterialLifecycleService , @Resource private MaterialLifecycleMapper materialLifecycleMapper; - @Autowired private MaterialBatchService materialBatchService; - @Autowired private MaterialLifecycleDetailService materialLifecycleDetailService; - @Autowired private BpmTaskApi bpmTaskApi; - @Autowired private BpmProcessInstanceApi bpmProcessInstanceApi; - @Autowired private DataKeyCheckService dataKeyCheckService; - @Autowired private DictionaryBusinessService dictionaryBusinessService; @Autowired @@ -106,9 +102,12 @@ public class MaterialLifecycleServiceImpl implements MaterialLifecycleService , private AdminUserApi adminUserApi; @Autowired private MaterialInventoryCheckItemService materialInventoryCheckItemService; - @Lazy @Autowired private MaterialInventoryCheckDetailService materialInventoryCheckDetailService; + @Autowired + private MaterialInventoryInboundService materialInventoryInboundService; + @Autowired + private MaterialInventoryInboundDetailService materialInventoryInboundDetailService; @Transactional @Override @@ -139,14 +138,14 @@ public class MaterialLifecycleServiceImpl implements MaterialLifecycleService , materialLifecycleDetailService.saveBatch(detailDOS); switch (flowType) { - case return_material, exchange_material -> lockReturnExchangeResources(detailDOS, LockType.lock); + case return_material, replace_material -> lockReturnExchangeResources(detailDOS, LockType.lock); case verify_calibrate -> lockVerifyCalibrateResources(detailDOS, LockType.lock); case inventory_check -> { List checkItems = validProductAndOperator(createReqVO); JSONObject customConfigObj = getCheckCustomConfigObj(createReqVO); mtrlLfc.setCustomConfig(customConfigObj.toJSONString()); materialLifecycleMapper.updateById(mtrlLfc); - List checkItemDOS = getCheckItemDOS(checkItems, mtrlLfc.getId()); + List checkItemDOS = getCheckItemDOS(checkItems, mtrlLfc); materialInventoryCheckItemService.saveBatch(checkItemDOS); } @@ -170,12 +169,14 @@ public class MaterialLifecycleServiceImpl implements MaterialLifecycleService , return checkItems; } - private List getCheckItemDOS(List checkItems, Long lfcId) { + private List getCheckItemDOS(List checkItems, MaterialLifecycleDO mtrlLfc) { List productIds = checkItems.stream().map(MaterialInventoryCheckItemSaveReqVO::getProductId).toList(); - Map stockQuantityByPdtIds = materialProductService.getStockQuantityByPdtIds(productIds); + cn.hutool.json.JSONObject customConfig = JSONUtil.parseObj(mtrlLfc.getCustomConfig()); + cn.hutool.json.JSONArray warehouseIds = customConfig.getJSONArray("warehouseIds"); + Map stockQuantityByPdtIds = materialProductService.getStockQuantityByPdtIds(productIds, warehouseIds.toList(Long.class)); return checkItems.stream().map(item -> new MaterialInventoryCheckItemDO() - .setParentId(lfcId) + .setParentId(mtrlLfc.getId()) .setProductId(item.getProductId()) .setExpected(BigDecimal.valueOf(stockQuantityByPdtIds.get(item.getProductId()) == null ? 0 : stockQuantityByPdtIds.get(item.getProductId()))) .setRemark(item.getRemark())).toList(); @@ -252,7 +253,7 @@ public class MaterialLifecycleServiceImpl implements MaterialLifecycleService , case acceptance -> getLifecycleDetailDOSByAcceptance(detailList, mtrlLfc); case make_apply -> getLifecycleDetailDOSByMakeApply(detailList, mtrlLfc); case return_material, - exchange_material -> + replace_material -> getLifecycleDetailDOSByReturnExchangeMaterial(detailList, mtrlLfc); case verify_calibrate -> getLifecycleDetailDOSByVerifyCalibrate(detailList, mtrlLfc); case inventory_check -> List.of(); @@ -293,7 +294,7 @@ public class MaterialLifecycleServiceImpl implements MaterialLifecycleService , JSONObject customConfigObj = getCheckCustomConfigObj(updateReqVO); mtrlLfc.setCustomConfig(customConfigObj.toJSONString()); materialLifecycleMapper.updateById(mtrlLfc); - List checkItemDOS = getCheckItemDOS(checkItems, mtrlLfc.getId()); + List checkItemDOS = getCheckItemDOS(checkItems, mtrlLfc); materialInventoryCheckItemService.saveBatch(checkItemDOS); return; } @@ -306,7 +307,7 @@ public class MaterialLifecycleServiceImpl implements MaterialLifecycleService , List oriDetailList = materialLifecycleDetailService.getDetailListByLfcId(reqId); // 释放原来退换货资源 boolean isReturnExchangeMaterial = - MaterialFlowType.return_material == flowType || MaterialFlowType.exchange_material == flowType; + MaterialFlowType.return_material == flowType || MaterialFlowType.replace_material == flowType; if (isReturnExchangeMaterial) lockReturnExchangeResources(oriDetailList, LockType.unlock); // 释放原理物料检定资源 @@ -433,7 +434,7 @@ public class MaterialLifecycleServiceImpl implements MaterialLifecycleService , */ private void validInfomationReturnExchangeMaterial(List reqInfomations) { List infomationIds = reqInfomations.stream().map(MaterialLifecycleDetailSaveReqVO::getInfomationId).toList(); - List infomations = materialInfomationService.getMaterialInfomationsByIds(infomationIds); + List infomations = materialInfomationService.getListByIds(infomationIds); if (CollUtil.isEmpty(infomations) || infomations.size() != infomationIds.size()) throw new ServiceException(1_032_160_000, "物料信息不存在或与传入的物料信息数量不匹配"); // 已出库的物料不可退换货 @@ -517,7 +518,7 @@ public class MaterialLifecycleServiceImpl implements MaterialLifecycleService , if (lifecycleDO.getSubmitStatus() == 1) throw new ServiceException(1_032_160_000, "流程已提交,不可删除"); MaterialFlowType flowType = MaterialFlowType.fromName(lifecycleDO.getBusinessType()); boolean isReturnExchangeMaterial = MaterialFlowType.return_material == flowType - || MaterialFlowType.exchange_material == flowType; + || MaterialFlowType.replace_material == flowType; boolean isVerifyCalibrate = MaterialFlowType.verify_calibrate == flowType; if (isReturnExchangeMaterial || isVerifyCalibrate) { @@ -548,7 +549,7 @@ public class MaterialLifecycleServiceImpl implements MaterialLifecycleService , // 释放退换货锁定资源 List rtnRepLifecycleDOS = list.stream().filter(lifecycleDO -> MaterialFlowType.return_material.getName().equals(lifecycleDO.getBusinessType()) - || MaterialFlowType.exchange_material.getName().equals(lifecycleDO.getBusinessType())).toList(); + || MaterialFlowType.replace_material.getName().equals(lifecycleDO.getBusinessType())).toList(); if (CollUtil.isNotEmpty(rtnRepLifecycleDOS)) { List rtnRepIds = rtnRepLifecycleDOS.stream().map(MaterialLifecycleDO::getId).toList(); List detailList = materialLifecycleDetailService.getDetailListByLfcIds(rtnRepIds); @@ -607,7 +608,7 @@ public class MaterialLifecycleServiceImpl implements MaterialLifecycleService , return respVO; } List pdtIds = checkItems.stream().map(MaterialInventoryCheckItemRespVO::getProductId).toList(); - Map stockQuantityByPdtId = materialProductService.getStockQuantityByPdtIds(pdtIds); + Map stockQuantityByPdtId = materialProductService.getStockQuantityByPdtIds(pdtIds, warehouseIds.toList(Long.class)); if (CollUtil.isEmpty(stockQuantityByPdtId)) return respVO; checkItems.forEach(item -> { Long qty = stockQuantityByPdtId.get(item.getProductId()); @@ -654,13 +655,13 @@ public class MaterialLifecycleServiceImpl implements MaterialLifecycleService , case acceptance -> // 验收需要发起流程 this.createProcessInstance(lifecycleDO); - case return_material, exchange_material -> { + case return_material, replace_material -> { // 退换货需要释放锁定的资源并更新退换货数量或更新实例状态 List detailList = materialLifecycleDetailService.getDetailListByLfcId(id); this.lockReturnExchangeResources(detailList, LockType.unlock); this.updateReturnExchangeResources(detailList, AdjustType.add); // 添加退换货出库记录 - materialInventoryOutboundService.addMaterialInventoryOutboundsByLfc(lifecycleDO); + addOutboundByLfc(lifecycleDO); } case verify_calibrate -> { // 检定需要发起检定流程 @@ -679,7 +680,9 @@ public class MaterialLifecycleServiceImpl implements MaterialLifecycleService , // 更新盘点项库存数量 List checkItemDOS = BeanUtils.toBean(checkItems, MaterialInventoryCheckItemDO.class); List pdtIds = checkItemDOS.stream().map(MaterialInventoryCheckItemDO::getProductId).toList(); - Map stockQuantityByPdtId = materialProductService.getStockQuantityByPdtIds(pdtIds); + cn.hutool.json.JSONObject customConfig = JSONUtil.parseObj(lifecycleDO.getCustomConfig()); + cn.hutool.json.JSONArray warehouseIds = customConfig.getJSONArray("warehouseIds"); + Map stockQuantityByPdtId = materialProductService.getStockQuantityByPdtIds(pdtIds, warehouseIds.toList(Long.class)); checkItemDOS.forEach(item -> { Long qty = stockQuantityByPdtId.get(item.getProductId()); item.setExpected(BigDecimal.valueOf(qty == null ? 0L : qty)); @@ -710,6 +713,26 @@ public class MaterialLifecycleServiceImpl implements MaterialLifecycleService , return true; } + private void addOutboundByLfc(MaterialLifecycleDO lifecycleDO) { + List detailList = materialLifecycleDetailService.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 replace_material -> MaterialOutboundType.replace_outbound.getName(); + case acceptance, make_apply, verify_calibrate, inventory_check -> null; + }; + MaterialInventoryOutboundSaveReqVO outboundSaveReqVO = new MaterialInventoryOutboundSaveReqVO() + .setTitle("退换货出库") + .setBusinessType(outboundType) + .setApplyUserId(lifecycleDO.getApplyUserId()) + .setInfomationIds(new ArrayList<>(infIds)) + .setRemark("退换货出库"); + materialInventoryOutboundService.createMaterialInventoryOutbound(outboundSaveReqVO); + } + private void updateVerifyCalibrateResources(List detailList, AdjustType adjustType) { // 批次 List batches = detailList.stream().filter(detail -> detail.getBatchId() != null).toList(); @@ -793,6 +816,61 @@ public class MaterialLifecycleServiceImpl implements MaterialLifecycleService , return true; } + @Override + public MaterialInventoryCheckDetailRespVO inventoryCheckInfomation(MaterialInventoryCheckDetailSaveReqVO inventoryReqVO) { + Long infomationId = inventoryReqVO.getInfomationId(); + MaterialInfomationDO infomationDO = materialInfomationService.getMaterialInfomation(infomationId); + if (infomationDO == null) throw exception(MATERIAL_INFOMATION_NOT_EXISTS); + Long checkId = inventoryReqVO.getCheckId(); + MaterialLifecycleDO lifecycleDO = this.getMaterialLifecycle(checkId); + if (lifecycleDO == null) throw exception(MATERIAL_LIFECYCLE_NOT_EXISTS); + if (lifecycleDO.getSubmitStatus() != 1) throw new ServiceException(1_032_160_000, "盘点单未提交"); + + LocalDateTime checkTime = lifecycleDO.getApplyTime(); + if (infomationDO.getCreateTime().isAfter(checkTime)) throw new ServiceException(1_032_160_000, "此物料在发起盘点后入库,不可盘点"); + + // 检查是否已经盘点过 + MaterialInventoryCheckDetailDO checkDetailDO = materialInventoryCheckDetailService.getByCheckIdAndInfId(checkId, infomationId); + MaterialInventoryCheckItemDO item = materialInventoryCheckItemService.getItemByCheckIdAndPdtId(checkId, infomationDO.getProductId()); + if (checkDetailDO != null) { + if (checkDetailDO.getPresent() == 1) throw new ServiceException(1_032_160_000, "此物料已盘点过"); + } else { + // 检查是否未领用了没拿走的情况 + if (infomationDO.getUsageStatus() != 1) throw new ServiceException(1_032_160_000, "此盘点单不可盘点该物料"); + // 根据仓库和盘点项匹配物料 + // 1. 匹配上 新建盘点明细(领用了没拿走) + // 2. 匹配不上 新建盘点项和盘点明细(领用了没拿走且大类不在盘点项中) + cn.hutool.json.JSONObject cstCfgObj = JSONUtil.parseObj(lifecycleDO.getCustomConfig()); + cn.hutool.json.JSONArray jsonWarehouseIds = cstCfgObj.getJSONArray("warehouseIds"); + List warehouseIds = CollUtil.isEmpty(jsonWarehouseIds) ? List.of() : jsonWarehouseIds.toList(Long.class); + if (CollUtil.isEmpty(warehouseIds)) throw new ServiceException(1_032_160_000, "此盘点单没有配置盘点仓库"); + ConfigWarehouseLocationDO location = configWarehouseLocationService.getConfigWarehouseLocation(infomationDO.getLocationId()); + if (location == null) throw exception(CONFIG_WAREHOUSE_LOCATION_NOT_EXISTS); + // 仓库匹配不成功, + if (!warehouseIds.contains(location.getParentId())) throw new ServiceException(1_032_160_000, "该物料所在的仓库不在此盘点单中"); + if (item == null) { + // 盘点项匹配不成功,新建盘点项 + item = new MaterialInventoryCheckItemDO() + .setParentId(checkId).setProductId(infomationDO.getProductId()) + .setExpected(BigDecimal.valueOf(0)) + .setRemark("盘点过程中新增的盘点项"); + materialInventoryCheckItemService.save(item); + } + checkDetailDO = new MaterialInventoryCheckDetailDO() + .setCheckId(checkId).setItemId(item.getId()).setInfomationId(infomationId) + .setCurrentQuantity(inventoryReqVO.getCurrentQuantity()) + // 不在库 + .setAtWarehouse(0) + .setRemark(StrUtil.isEmpty(inventoryReqVO.getRemark()) ? "已领用未拿走" : inventoryReqVO.getRemark()); + materialInventoryCheckDetailService.save(checkDetailDO); + } + checkDetailDO.setPresent(1); + materialInventoryCheckDetailService.updateById(checkDetailDO); + item.setActual(item.getActual().add(BigDecimal.valueOf(1))); + materialInventoryCheckItemService.updateById(item); + return BeanUtils.toBean(checkDetailDO, MaterialInventoryCheckDetailRespVO.class); + } + private void createProcessInstance(MaterialLifecycleDO lifecycleDO) { String flowInstanceId = lifecycleDO.getFlowInstanceId(); @@ -936,12 +1014,20 @@ public class MaterialLifecycleServiceImpl implements MaterialLifecycleService , entity.setFlowStatus(QmsCommonConstant.COMPLETED); // 更新明细处理状态 materialLifecycleDetailService.updateDetailTreatStatusByLfcId(entity.getId(), true); - if (MaterialFlowType.acceptance.equals(flowType)) - // 更新批次工段验收状态 - materialBatchService.updateMaterialBatchAcceptStatusByLfcId(entity.getId(), MaterialAcceptStatus.accepted.name()); - if (MaterialFlowType.verify_calibrate.equals(flowType)) - // 批次检定完成后生成批次拆分 - materialBatchService.createVerifyBatchAssignsByLfcId(entity.getId()); + switch (flowType) { + case acceptance: + // 更新批次工段验收状态 + this.updateMaterialBatchAcceptStatusByLfcId(entity.getId(), MaterialAcceptStatus.accepted.name()); + break; + case verify_calibrate: + // 批次检定完成后生成批次拆分 + this.createVerifyBatchAssignsByLfcId(entity.getId()); + break; + case inventory_check: + // 库存盘点通过,对相应物料进行出入库 + this.inventoryCheckPassHandle(entity.getId()); + } + } @@ -949,4 +1035,115 @@ public class MaterialLifecycleServiceImpl implements MaterialLifecycleService , materialLifecycleMapper.updateById(entity); return CommonResult.success(new JSONObject()); } + + private void createVerifyBatchAssignsByLfcId(Long id) { + MaterialLifecycleDO lifecycleDO = this.getMaterialLifecycle(id); + if (lifecycleDO == null) return; + List lifecycleDetailDOs = this.getDetailListByLfcId(id); + if (CollUtil.isEmpty(lifecycleDetailDOs)) return; + String flowInstanceId = lifecycleDO.getFlowInstanceId(); + if (StrUtil.isEmpty(flowInstanceId)) return; + CommonResult processInstance = bpmProcessInstanceApi.getProcessInstance(flowInstanceId); + BpmProcessInstanceRespDTO instanceData = processInstance.getData(); + UserSimpleDTO startUser = instanceData.getStartUser(); + List batIds = lifecycleDetailDOs.stream().map(MaterialLifecycleDetailDO::getBatchId).toList(); + List batchDOS = materialBatchService.getBatchListByBatchIds(batIds); + Map batchDOMap = batchDOS.stream().collect(Collectors.toMap(MaterialBatchDO::getId, Function.identity())); + List gongs = lifecycleDetailDOs.stream().map(detailDO -> { + MaterialBatchDO batchDO = batchDOMap.get(detailDO.getBatchId()); + Long deptId = startUser.getDeptId(); + return new MaterialBatchDO() + .setParentId(detailDO.getBatchId()) + .setProductId(batchDO.getProductId()) + .setAssignDepartmentId(deptId) + .setAssignDepartmentName(startUser.getDeptName()) + .setInboundQuantity(detailDO.getQualifiedCount()) + .setBatchNo(batchDO.getBatchNo()) + .setRemaineQuantity(detailDO.getQualifiedCount()) + .setAcceptanceStatus(MaterialAcceptStatus.accepted.name()) + .setSubmitStatus(1).setSubmitDate(batchDO.getSubmitDate()) + .setRemark(String.format("【%s】于%s发起检定,检定数量:%s,合格数量:%s", startUser.getNickname(), instanceData.getStartTime().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")), + detailDO.getInfluenceCount(), detailDO.getQualifiedCount())); + }).toList(); + materialBatchService.saveBatch(gongs); + } + + private void updateMaterialBatchAcceptStatusByLfcId(Long lfcId, String status) { + List detailList = this.getDetailListByLfcId(lfcId); + if (CollUtil.isEmpty(detailList)) return; + List gongIds = detailList.stream().map(MaterialLifecycleDetailDO::getBatchGongduanId).toList(); + if (CollUtil.isEmpty(gongIds)) return; + MaterialBatchDO updateEntity = new MaterialBatchDO().setAcceptanceStatus(status); + materialBatchService.updateByIds(gongIds, updateEntity); + } + + /** + * 库存盘点通过处理 + * + * @param lfcId 流程id + */ + @Transactional + private void inventoryCheckPassHandle(Long lfcId) { + MaterialLifecycleDO lifecycleDO = this.getMaterialLifecycle(lfcId); + // 不在库的入库 + this.addInboundByInventoryCheck(lifecycleDO); + // 不存在的出库 + this.addOutboundByInventoryCheck(lifecycleDO); + } + + private void addOutboundByInventoryCheck(MaterialLifecycleDO lifecycleDO) { + List outboundDetails = materialInventoryCheckDetailService.getListNotPresentAndAtWarehouse(lifecycleDO.getId()); + if (CollUtil.isEmpty(outboundDetails)) return; + List infIds = outboundDetails.stream().map(MaterialInventoryCheckDetailDO::getInfomationId).toList(); + MaterialInventoryOutboundSaveReqVO outboundSaveReqVO = new MaterialInventoryOutboundSaveReqVO() + .setTitle("盘点出库") + .setBusinessType(MaterialOutboundType.check_outbound.getName()) + .setApplyUserId(lifecycleDO.getOperatorId()) + .setInfomationIds(infIds) + .setRemark("盘点出库,可能是没登记就拿走"); + materialInventoryOutboundService.createMaterialInventoryOutbound(outboundSaveReqVO); + } + + private void addInboundByInventoryCheck(MaterialLifecycleDO lifecycleDO) { + List checkInbDetails = materialInventoryCheckDetailService.getListNotAtWarehouse(lifecycleDO.getId()); + if (CollUtil.isEmpty(checkInbDetails)) return; + List inbInfIds = checkInbDetails.stream().map(MaterialInventoryCheckDetailDO::getInfomationId).toList(); + List infs = materialInfomationService.getListByIds(inbInfIds); + // 需要按库位入库 + if (CollUtil.isEmpty(infs)) return; + CommonResult userResult = adminUserApi.getUser(lifecycleDO.getOperatorId()); + AdminUserRespDTO user = userResult.getData(); + CommonResult deptResult = deptApi.getDept(user.getDeptId()); + DeptRespDTO dept = deptResult.getData(); + List inbounds = new ArrayList<>(); + List inboundDetails = new ArrayList<>(); + Map> infsGroupByLoc = infs.stream().collect(Collectors.groupingBy(MaterialInfomationDO::getLocationId)); + infsGroupByLoc.forEach((locationId, infList) -> { + if (CollUtil.isNotEmpty(infList)) { + MaterialInventoryInboundDO inbound = new MaterialInventoryInboundDO(); + inbound.setTitle("盘点入库").setBusinessType(MaterialInboundType.check_inbound.getName()) + .setApplyUser(user.getNickname()).setApplyUserId(user.getId()) + .setApplyDepartment(dept.getName()).setApplyDepartmentId(dept.getId()) + .setApplyTime(lifecycleDO.getApplyTime()) + .setLocationId(locationId).setQuantity(BigDecimal.valueOf(infList.size())) + .setRemark("盘点后不在库的入库"); + inbounds.add(inbound); + List detailDOS = infList.stream().map(inf -> new MaterialInventoryInboundDetailDO() + .setInboundId(inbound.getId()) + .setMaterialInfomationId(inf.getId()) + .setInboundUserName(inbound.getApplyUser()) + .setInboundUserId(inbound.getApplyUserId()) + .setInboundDepartmentName(inbound.getApplyDepartment()) + .setInboundDepartmentId(inbound.getApplyDepartmentId()) + .setInboundTime(LocalDateTime.now()) + .setRemark("盘点后入库")).toList(); + inboundDetails.addAll(detailDOS); + } + }); + materialInventoryInboundService.saveBatch(inbounds); + materialInventoryInboundDetailService.saveBatch(inboundDetails); + // 更新物料在库状态 + List infIds = infs.stream().map(MaterialInfomationDO::getId).toList(); + materialInfomationService.updateByIds(infIds, new MaterialInfomationDO().setUsageStatus(0)); + } } \ 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/MaterialProductService.java b/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/resource/material/service/MaterialProductService.java index be23a606..0a0aefcd 100644 --- a/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/resource/material/service/MaterialProductService.java +++ b/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/resource/material/service/MaterialProductService.java @@ -141,6 +141,15 @@ public interface MaterialProductService { */ Map getStockQuantityByPdtIds(List mtrlIds); + /** + * 获取物料大类库存数量 + * + * @param mtrlIds 大类ids + * @param warehouseIds 仓库ids + * @return 物料数据 + */ + Map getStockQuantityByPdtIds(List mtrlIds, List warehouseIds); + /** * 获取顶级分类 * diff --git a/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/resource/material/service/MaterialProductServiceImpl.java b/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/resource/material/service/MaterialProductServiceImpl.java index d578dd72..5f219f84 100644 --- a/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/resource/material/service/MaterialProductServiceImpl.java +++ b/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/resource/material/service/MaterialProductServiceImpl.java @@ -396,7 +396,7 @@ public class MaterialProductServiceImpl implements MaterialProductService { List mtrlIds = mtrlDos.stream().map(MaterialProductDO::getId).toList(); List voList = mtrlDos.stream().map(m -> BeanUtils.toBean(m, MaterialProductRespVO.class)).toList(); // 一次性获取大类下的库存数量 - Map stockQuantityMap = materialProductMapper.getStockQuantityByPdtIds(mtrlIds, warehouseIds); + Map stockQuantityMap = this.getStockQuantityByPdtIds(mtrlIds, warehouseIds); for (MaterialProductRespVO vo : voList) { Long val = stockQuantityMap.get(vo.getId()); vo.setInventoryQuantity(BigDecimal.valueOf(val == null ? 0L : val)); @@ -468,6 +468,12 @@ public class MaterialProductServiceImpl implements MaterialProductService { return materialProductMapper.getStockQuantityByPdtIds(mtrlIds); } + @Override + public Map getStockQuantityByPdtIds(List mtrlIds, List warehouseIds) { + if (CollUtil.isEmpty(warehouseIds)) return materialProductMapper.getStockQuantityByPdtIds(mtrlIds); + return materialProductMapper.getStockQuantityByPdtIds(mtrlIds, warehouseIds); + } + @Override public List getTopCategoriesByPdtIds(List pdtIds) { List productDOS = materialProductMapper.selectByIds(pdtIds); 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 c05595a1..6816be02 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 @@ -59,7 +59,7 @@ public class MaterialUseEndReuseServiceImpl implements MaterialUseEndReuseServic if (MaterialNormalOperationType.used_mark.equals(operationType) || MaterialNormalOperationType.open_seal.equals(operationType)) { if (CollUtil.isEmpty(infomationIds)) throw new ServiceException(1_032_160_000, String.format("【%s】的物料实例不能为空", MaterialNormalOperationType.used_mark == operationType ? "用完标记" : "开封")); - List infomations = materialInfomationService.getMaterialInfomationsByIds(infomationIds); + List infomations = materialInfomationService.getListByIds(infomationIds); if (CollUtil.isEmpty(infomations) || infomations.size() != infomationIds.size()) 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 4585d423..5c2c9994 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 @@ -199,7 +199,7 @@ public class MaterialUseRecordDetailServiceImpl implements MaterialUseRecordDeta if (product == null) throw new ServiceException(1_032_160_000, "配置大类不存在"); if (totalOperationQuantity.compareTo(product.getStandardCapacity()) > 0) throw new ServiceException(1_032_160_000, "配置的总容量超过了额定容量"); Set infIds = records.stream().map(MaterialUseRecordSaveReqVO::getInfomationId).collect(Collectors.toSet()); - List infomations = materialInfomationService.getMaterialInfomationsByIds(new ArrayList<>(infIds)); + List infomations = materialInfomationService.getListByIds(new ArrayList<>(infIds)); if (CollUtil.isEmpty(infomations)) throw new ServiceException(1_032_160_000, "物料实例不存在"); Map> recordMapByInfId = records.stream().collect(Collectors.groupingBy(MaterialUseRecordSaveReqVO::getInfomationId)); 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 51adce40..14315ce5 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 @@ -6,26 +6,19 @@ 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.core.code.SequenceUtil; -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.*; 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; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import org.springframework.validation.annotation.Validated; import java.math.BigDecimal; -import java.time.LocalDate; import java.time.LocalDateTime; import java.util.*; -import java.util.function.Function; import java.util.stream.Collectors; import static com.zt.plat.framework.common.exception.util.ServiceExceptionUtil.exception; @@ -119,7 +112,7 @@ public class MaterialUseRecordServiceImpl implements MaterialUseRecordService { if (CollUtil.isEmpty(recordDOS) || recordDOS.size() != ids.size()) throw exception(MATERIAL_USE_RECORD_NOT_EXISTS); // 恢复物料剩余量 Set infIds = recordDOS.stream().map(MaterialUseRecordDO::getInfomationId).collect(Collectors.toSet()); - List infomationDOS = materialInfomationService.getMaterialInfomationsByIds(new ArrayList<>(infIds)); + List infomationDOS = materialInfomationService.getListByIds(new ArrayList<>(infIds)); if (CollUtil.isEmpty(infomationDOS)) throw new ServiceException(1_032_160_000, "物料实例不存在"); Map> groupRecordDOS = recordDOS.stream().collect(Collectors.groupingBy(MaterialUseRecordDO::getInfomationId)); for (MaterialInfomationDO infomationDO : infomationDOS) {