From 5dffce196f0a240d9dfb9d64ecf2f55a7df86520 Mon Sep 17 00:00:00 2001 From: yf001217 <834502597@qq.com> Date: Fri, 5 Jun 2026 11:49:38 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E5=BA=93=E5=AD=98?= =?UTF-8?q?=E5=AD=97=E6=AE=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...IncomingInspectionTaskControllerService.java | 13 +++++++++++++ .../service/QmsQcMaterialControllerService.java | 9 ++++++++- ...msIncomingInspectionTaskCallbackService.java | 17 +++++++++++++++-- .../common/pojo/dto/QmsQcMaterialExportDTO.java | 6 ++++++ .../common/pojo/dto/QmsQcMaterialImportDTO.java | 6 ++++++ .../wms/common/pojo/qo/InventorySearchQO.java | 10 ++++++++++ .../wms/common/pojo/qo/QmsQcMaterialAddQO.java | 5 +++++ .../common/pojo/qo/QmsQcMaterialSearchQO.java | 5 +++++ .../common/pojo/qo/QmsQcMaterialUpdateQO.java | 5 +++++ .../nflg/wms/common/pojo/vo/InventoryVO.java | 10 ++++++++++ .../wms/common/pojo/vo/QmsQcMaterialVO.java | 5 +++++ .../wms/repository/entity/QmsQcMaterial.java | 5 +++++ .../wms/repository/entity/WmsInventory.java | 10 ++++++++++ .../service/impl/WmsInventoryServiceImpl.java | 4 ++++ .../resources/mapper/QmsQcMaterialMapper.xml | 10 ++++++++++ .../resources/mapper/WmsInventoryMapper.xml | 8 +++++++- 16 files changed, 124 insertions(+), 4 deletions(-) diff --git a/nflg-qms-admin/src/main/java/com/nflg/qms/admin/service/IncomingInspectionTaskControllerService.java b/nflg-qms-admin/src/main/java/com/nflg/qms/admin/service/IncomingInspectionTaskControllerService.java index 74201f6c..40b8458f 100644 --- a/nflg-qms-admin/src/main/java/com/nflg/qms/admin/service/IncomingInspectionTaskControllerService.java +++ b/nflg-qms-admin/src/main/java/com/nflg/qms/admin/service/IncomingInspectionTaskControllerService.java @@ -113,6 +113,9 @@ public class IncomingInspectionTaskControllerService { @Resource private List sendMessageServices; + @Resource + private IWmsInventoryService inventoryService; + /** * 来料检验申请(对外接口) * 业务规则: @@ -372,6 +375,16 @@ public class IncomingInspectionTaskControllerService { .eq(QmsIncomingInspectionTask::getId, task.getId()) .update(); + boolean inventoryUpdated = inventoryService.lambdaUpdate() + .set(WmsInventory::getDetectionStatus, (short) 1) + .set(WmsInventory::getDetectionResults, null) + .eq(WmsInventory::getMaterialNo, request.getMaterialNo()) + .eq(WmsInventory::getFactoryNo, request.getFactory()) + .eq(WmsInventory::getWarehouseNo, request.getWarehouse()) + .eq(WmsInventory::getBinLocation, request.getStorageLocation()) + .update(); + VUtil.trueThrowBusinessError(!inventoryUpdated).throwMessage("未找到对应库存,无法更新检测状态"); + QmsTodoItem qmsTodoItem = new QmsTodoItem() .setTitle("新的IQC库存检测任务" + task.getTaskNo()) .setCode(basdeSerialNumberControllerService.generateSerialNumber(32)) diff --git a/nflg-qms-admin/src/main/java/com/nflg/qms/admin/service/QmsQcMaterialControllerService.java b/nflg-qms-admin/src/main/java/com/nflg/qms/admin/service/QmsQcMaterialControllerService.java index 59614215..ad0299ee 100644 --- a/nflg-qms-admin/src/main/java/com/nflg/qms/admin/service/QmsQcMaterialControllerService.java +++ b/nflg-qms-admin/src/main/java/com/nflg/qms/admin/service/QmsQcMaterialControllerService.java @@ -161,6 +161,7 @@ public class QmsQcMaterialControllerService { .setMaterialName(request.getMaterialName()) .setMaterialTexture(request.getMaterialTexture()) .setMaterialSpecifications(request.getMaterialSpecifications()) + .setValidityPeriod(request.getValidityPeriod()) .setIsStandardMaintained(request.getIsStandardMaintained() != null ? request.getIsStandardMaintained() : false) .setCreatedType(0) .setCreateBy(userId) @@ -234,6 +235,9 @@ public class QmsQcMaterialControllerService { if (request.getMaterialSpecifications() != null) { updateChain.set(QmsQcMaterial::getMaterialSpecifications, request.getMaterialSpecifications()); } + if (request.getValidityPeriod() != null) { + updateChain.set(QmsQcMaterial::getValidityPeriod, request.getValidityPeriod()); + } // 更新规则是否已维护 if (request.getIsStandardMaintained() != null) { updateChain.set(QmsQcMaterial::getIsStandardMaintained, request.getIsStandardMaintained()); @@ -360,6 +364,7 @@ public class QmsQcMaterialControllerService { .setMaterialName(dto.getMaterialName()) .setMaterialTexture(dto.getMaterialTexture()) .setMaterialSpecifications(dto.getMaterialSpecifications()) + .setValidityPeriod(dto.getValidityPeriod()) .setIsStandardMaintained(false) .setCreatedType(0) .setCreateBy(userId) @@ -380,6 +385,7 @@ public class QmsQcMaterialControllerService { .set(QmsQcMaterial::getMaterialName, dto.getMaterialName()) .set(QmsQcMaterial::getMaterialTexture, dto.getMaterialTexture()) .set(QmsQcMaterial::getMaterialSpecifications, dto.getMaterialSpecifications()) + .set(QmsQcMaterial::getValidityPeriod, dto.getValidityPeriod()) .set(QmsQcMaterial::getUpdateBy, userId) .set(QmsQcMaterial::getUpdateByName, operator) .set(QmsQcMaterial::getUpdateTime, now) @@ -435,7 +441,8 @@ public class QmsQcMaterialControllerService { .setDrawingNoVer("示例版本号") .setMaterialName("示例物料名称") .setMaterialTexture("示例材质") - .setMaterialSpecifications("示例规格"); + .setMaterialSpecifications("示例规格") + .setValidityPeriod((short) 12); EecExcelUtil.export("质检物料导入模板", "质检物料导入模板", List.of(example), response); } diff --git a/nflg-qms-admin/src/main/java/com/nflg/qms/admin/service/WmsIncomingInspectionTaskCallbackService.java b/nflg-qms-admin/src/main/java/com/nflg/qms/admin/service/WmsIncomingInspectionTaskCallbackService.java index 73c69eb9..94b29cf2 100644 --- a/nflg-qms-admin/src/main/java/com/nflg/qms/admin/service/WmsIncomingInspectionTaskCallbackService.java +++ b/nflg-qms-admin/src/main/java/com/nflg/qms/admin/service/WmsIncomingInspectionTaskCallbackService.java @@ -9,9 +9,11 @@ import com.nflg.wms.common.util.VUtil; import com.nflg.wms.repository.entity.QmsIncomingInspectionTask; import com.nflg.wms.repository.entity.QmsIncomingInspectionTaskRecord; import com.nflg.wms.repository.entity.QmsIssueTicket; +import com.nflg.wms.repository.entity.WmsInventory; import com.nflg.wms.repository.service.IQmsIncomingInspectionTaskRecordService; import com.nflg.wms.repository.service.IQmsIncomingInspectionTaskService; import com.nflg.wms.repository.service.IQmsIssueTicketService; +import com.nflg.wms.repository.service.IWmsInventoryService; import jakarta.annotation.Resource; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Value; @@ -46,6 +48,9 @@ public class WmsIncomingInspectionTaskCallbackService { @Resource private IQmsIssueTicketService issueTicketService; + @Resource + private IWmsInventoryService inventoryService; + /** * 向WMS系统发送来料检验任务回调 */ @@ -134,6 +139,14 @@ public class WmsIncomingInspectionTaskCallbackService { boolean callbackResult = true; try { wmsApiService.post(inventoryUrl, qo, "库存检验任务回调WMS"); + inventoryService.lambdaUpdate() + .set(WmsInventory::getDetectionStatus, (short) 2) + .set(WmsInventory::getDetectionResults, taskVO.getInspectionResult()) + .eq(WmsInventory::getMaterialNo, taskVO.getMaterialNo()) + .eq(WmsInventory::getFactoryNo, taskVO.getFactory()) + .eq(WmsInventory::getWarehouseNo, taskVO.getWarehouse()) + .eq(WmsInventory::getBinLocation, taskVO.getStorageLocation()) + .update(); } catch (Exception e) { callbackResult = false; throw new NflgException(STATE.BusinessError, "调用WMS接口失败:" + e.getMessage()); @@ -185,10 +198,10 @@ public class WmsIncomingInspectionTaskCallbackService { */ private void process(QmsIncomingInspectionTaskVO taskVO, Short processingResult) { switch (taskVO.getInspectionType()) { - case 1: + case 0: incoming(taskVO,processingResult); break; - case 2: + case 1: inventory(taskVO,processingResult); break; default: diff --git a/nflg-wms-common/src/main/java/com/nflg/wms/common/pojo/dto/QmsQcMaterialExportDTO.java b/nflg-wms-common/src/main/java/com/nflg/wms/common/pojo/dto/QmsQcMaterialExportDTO.java index a13972f7..3db74803 100644 --- a/nflg-wms-common/src/main/java/com/nflg/wms/common/pojo/dto/QmsQcMaterialExportDTO.java +++ b/nflg-wms-common/src/main/java/com/nflg/wms/common/pojo/dto/QmsQcMaterialExportDTO.java @@ -65,6 +65,12 @@ public class QmsQcMaterialExportDTO { @ExcelColumn("物料规格") private String materialSpecifications; + /** + * Validity period in months. + */ + @ExcelColumn("有效周期(月)") + private Short validityPeriod; + /** * 规则是否已维护 */ diff --git a/nflg-wms-common/src/main/java/com/nflg/wms/common/pojo/dto/QmsQcMaterialImportDTO.java b/nflg-wms-common/src/main/java/com/nflg/wms/common/pojo/dto/QmsQcMaterialImportDTO.java index cade7402..998f42e0 100644 --- a/nflg-wms-common/src/main/java/com/nflg/wms/common/pojo/dto/QmsQcMaterialImportDTO.java +++ b/nflg-wms-common/src/main/java/com/nflg/wms/common/pojo/dto/QmsQcMaterialImportDTO.java @@ -59,6 +59,12 @@ public class QmsQcMaterialImportDTO { @ExcelColumn("物料规格") private String materialSpecifications; + /** + * Validity period in months. + */ + @ExcelColumn("有效周期(月)") + private Short validityPeriod; + /** * 错误信息 */ diff --git a/nflg-wms-common/src/main/java/com/nflg/wms/common/pojo/qo/InventorySearchQO.java b/nflg-wms-common/src/main/java/com/nflg/wms/common/pojo/qo/InventorySearchQO.java index 8982548e..c00b1845 100644 --- a/nflg-wms-common/src/main/java/com/nflg/wms/common/pojo/qo/InventorySearchQO.java +++ b/nflg-wms-common/src/main/java/com/nflg/wms/common/pojo/qo/InventorySearchQO.java @@ -24,4 +24,14 @@ public class InventorySearchQO extends PageQO { * 库存地点编号 */ private String warehouseNo; + + /** + * 检测状态:0=未检测,1=检测中,2=已检测 + */ + private Short detectionStatus; + + /** + * 检测结果 + */ + private Boolean detectionResults; } diff --git a/nflg-wms-common/src/main/java/com/nflg/wms/common/pojo/qo/QmsQcMaterialAddQO.java b/nflg-wms-common/src/main/java/com/nflg/wms/common/pojo/qo/QmsQcMaterialAddQO.java index c4ad9943..1514decc 100644 --- a/nflg-wms-common/src/main/java/com/nflg/wms/common/pojo/qo/QmsQcMaterialAddQO.java +++ b/nflg-wms-common/src/main/java/com/nflg/wms/common/pojo/qo/QmsQcMaterialAddQO.java @@ -56,6 +56,11 @@ public class QmsQcMaterialAddQO { */ private String materialSpecifications; + /** + * Validity period in months. + */ + private Short validityPeriod; + /** * 规则是否已维护:false=未维护,true=已维护 */ diff --git a/nflg-wms-common/src/main/java/com/nflg/wms/common/pojo/qo/QmsQcMaterialSearchQO.java b/nflg-wms-common/src/main/java/com/nflg/wms/common/pojo/qo/QmsQcMaterialSearchQO.java index d0f66397..b0f1d51f 100644 --- a/nflg-wms-common/src/main/java/com/nflg/wms/common/pojo/qo/QmsQcMaterialSearchQO.java +++ b/nflg-wms-common/src/main/java/com/nflg/wms/common/pojo/qo/QmsQcMaterialSearchQO.java @@ -66,6 +66,11 @@ public class QmsQcMaterialSearchQO extends PageQO { */ private String materialSpecifications; + /** + * Validity period in months. + */ + private Short validityPeriod; + /** * 规则是否已维护(精确匹配):false=未维护,true=已维护 */ diff --git a/nflg-wms-common/src/main/java/com/nflg/wms/common/pojo/qo/QmsQcMaterialUpdateQO.java b/nflg-wms-common/src/main/java/com/nflg/wms/common/pojo/qo/QmsQcMaterialUpdateQO.java index b760cc20..3273912e 100644 --- a/nflg-wms-common/src/main/java/com/nflg/wms/common/pojo/qo/QmsQcMaterialUpdateQO.java +++ b/nflg-wms-common/src/main/java/com/nflg/wms/common/pojo/qo/QmsQcMaterialUpdateQO.java @@ -61,6 +61,11 @@ public class QmsQcMaterialUpdateQO { */ private String materialSpecifications; + /** + * Validity period in months. + */ + private Short validityPeriod; + /** * 规则是否已维护:false=未维护,true=已维护 */ diff --git a/nflg-wms-common/src/main/java/com/nflg/wms/common/pojo/vo/InventoryVO.java b/nflg-wms-common/src/main/java/com/nflg/wms/common/pojo/vo/InventoryVO.java index af6e7f11..481353c2 100644 --- a/nflg-wms-common/src/main/java/com/nflg/wms/common/pojo/vo/InventoryVO.java +++ b/nflg-wms-common/src/main/java/com/nflg/wms/common/pojo/vo/InventoryVO.java @@ -43,4 +43,14 @@ public class InventoryVO { * 序列号 */ private String serialNo; + + /** + * 检测状态:0=未检测,1=检测中,2=已检测 + */ + private Short detectionStatus; + + /** + * 检测结果:true=合格,false=不合格,null=无结果 + */ + private Boolean detectionResults; } diff --git a/nflg-wms-common/src/main/java/com/nflg/wms/common/pojo/vo/QmsQcMaterialVO.java b/nflg-wms-common/src/main/java/com/nflg/wms/common/pojo/vo/QmsQcMaterialVO.java index 8138bc6b..9a1874eb 100644 --- a/nflg-wms-common/src/main/java/com/nflg/wms/common/pojo/vo/QmsQcMaterialVO.java +++ b/nflg-wms-common/src/main/java/com/nflg/wms/common/pojo/vo/QmsQcMaterialVO.java @@ -74,6 +74,11 @@ public class QmsQcMaterialVO { */ private String materialSpecifications; + /** + * Validity period in months. + */ + private Short validityPeriod; + /** * 规则是否已维护:false=未维护,true=已维护 */ diff --git a/nflg-wms-repository/src/main/java/com/nflg/wms/repository/entity/QmsQcMaterial.java b/nflg-wms-repository/src/main/java/com/nflg/wms/repository/entity/QmsQcMaterial.java index 51b082b6..d7808ead 100644 --- a/nflg-wms-repository/src/main/java/com/nflg/wms/repository/entity/QmsQcMaterial.java +++ b/nflg-wms-repository/src/main/java/com/nflg/wms/repository/entity/QmsQcMaterial.java @@ -81,6 +81,11 @@ public class QmsQcMaterial implements Serializable { */ private String materialSpecifications; + /** + * Validity period in months. + */ + private Short validityPeriod; + /** * 规则是否已维护:false=未维护,true=已维护 */ diff --git a/nflg-wms-repository/src/main/java/com/nflg/wms/repository/entity/WmsInventory.java b/nflg-wms-repository/src/main/java/com/nflg/wms/repository/entity/WmsInventory.java index 0e086c68..cb8e75f7 100644 --- a/nflg-wms-repository/src/main/java/com/nflg/wms/repository/entity/WmsInventory.java +++ b/nflg-wms-repository/src/main/java/com/nflg/wms/repository/entity/WmsInventory.java @@ -96,4 +96,14 @@ public class WmsInventory implements Serializable { * 储位 */ private String binLocation; + + /** + * 检测状态:0=未检测,1=检测中,2=已检测 + */ + private Short detectionStatus; + + /** + * 检测结果:true=合格,false=不合格 + */ + private Boolean detectionResults; } diff --git a/nflg-wms-repository/src/main/java/com/nflg/wms/repository/service/impl/WmsInventoryServiceImpl.java b/nflg-wms-repository/src/main/java/com/nflg/wms/repository/service/impl/WmsInventoryServiceImpl.java index b9eb42b3..39d08028 100644 --- a/nflg-wms-repository/src/main/java/com/nflg/wms/repository/service/impl/WmsInventoryServiceImpl.java +++ b/nflg-wms-repository/src/main/java/com/nflg/wms/repository/service/impl/WmsInventoryServiceImpl.java @@ -135,12 +135,16 @@ public class WmsInventoryServiceImpl extends ServiceImpl AND material_specifications ilike concat('%', #{request.materialSpecifications}, '%') + + AND validity_period = #{request.validityPeriod} + AND is_standard_maintained = #{request.isStandardMaintained} @@ -109,6 +113,7 @@ material_name material_texture material_specifications + validity_period is_standard_maintained created_type create_by_name @@ -145,6 +150,7 @@ material_name, material_texture, material_specifications, + validity_period, CASE WHEN is_standard_maintained THEN '是' ELSE '否' END AS is_standard_maintained, CASE created_type WHEN 0 THEN '人工操作' WHEN 1 THEN '系统同步' ELSE '未知' END AS created_type, create_by_name, @@ -189,6 +195,9 @@ AND material_specifications ilike concat('%', #{request.materialSpecifications}, '%') + + AND validity_period = #{request.validityPeriod} + AND is_standard_maintained = #{request.isStandardMaintained} @@ -229,6 +238,7 @@ material_name material_texture material_specifications + validity_period is_standard_maintained created_type create_by_name diff --git a/nflg-wms-repository/src/main/resources/mapper/WmsInventoryMapper.xml b/nflg-wms-repository/src/main/resources/mapper/WmsInventoryMapper.xml index b6a587df..fd173501 100644 --- a/nflg-wms-repository/src/main/resources/mapper/WmsInventoryMapper.xml +++ b/nflg-wms-repository/src/main/resources/mapper/WmsInventoryMapper.xml @@ -4,7 +4,7 @@ From 5cb45125e405011b80d74e14513ed1b6a01887d8 Mon Sep 17 00:00:00 2001 From: yf001217 <834502597@qq.com> Date: Fri, 5 Jun 2026 15:19:35 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E6=89=8B=E5=8A=A8?= =?UTF-8?q?=E5=8F=91=E8=B5=B7=E5=BA=93=E5=AD=98=E6=A3=80=E6=B5=8B=E4=BB=BB?= =?UTF-8?q?=E5=8A=A1=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...comingInspectionTaskControllerService.java | 13 ------ .../admin/controller/InventoryController.java | 15 +++++++ .../nflg/wms/admin/service/QmsService.java | 42 ++++++++++++++++++- .../pojo/qo/InventoryDetectionApplyQO.java | 26 ++++++++++++ 4 files changed, 82 insertions(+), 14 deletions(-) create mode 100644 nflg-wms-common/src/main/java/com/nflg/wms/common/pojo/qo/InventoryDetectionApplyQO.java diff --git a/nflg-qms-admin/src/main/java/com/nflg/qms/admin/service/IncomingInspectionTaskControllerService.java b/nflg-qms-admin/src/main/java/com/nflg/qms/admin/service/IncomingInspectionTaskControllerService.java index 0cd84a2e..e79629a2 100644 --- a/nflg-qms-admin/src/main/java/com/nflg/qms/admin/service/IncomingInspectionTaskControllerService.java +++ b/nflg-qms-admin/src/main/java/com/nflg/qms/admin/service/IncomingInspectionTaskControllerService.java @@ -113,9 +113,6 @@ public class IncomingInspectionTaskControllerService { @Resource private List sendMessageServices; - @Resource - private IWmsInventoryService inventoryService; - /** * 来料检验申请(对外接口) * 业务规则: @@ -384,16 +381,6 @@ public class IncomingInspectionTaskControllerService { .eq(QmsIncomingInspectionTask::getId, task.getId()) .update(); - boolean inventoryUpdated = inventoryService.lambdaUpdate() - .set(WmsInventory::getDetectionStatus, (short) 1) - .set(WmsInventory::getDetectionResults, null) - .eq(WmsInventory::getMaterialNo, request.getMaterialNo()) - .eq(WmsInventory::getFactoryNo, request.getFactory()) - .eq(WmsInventory::getWarehouseNo, request.getWarehouse()) - .eq(WmsInventory::getBinLocation, request.getStorageLocation()) - .update(); - VUtil.trueThrowBusinessError(!inventoryUpdated).throwMessage("未找到对应库存,无法更新检测状态"); - QmsTodoItem qmsTodoItem = new QmsTodoItem() .setTitle("新的IQC库存检测任务" + task.getTaskNo()) .setCode(basdeSerialNumberControllerService.generateSerialNumber(32)) diff --git a/nflg-wms-admin/src/main/java/com/nflg/wms/admin/controller/InventoryController.java b/nflg-wms-admin/src/main/java/com/nflg/wms/admin/controller/InventoryController.java index 11ad743a..c22654a2 100644 --- a/nflg-wms-admin/src/main/java/com/nflg/wms/admin/controller/InventoryController.java +++ b/nflg-wms-admin/src/main/java/com/nflg/wms/admin/controller/InventoryController.java @@ -5,6 +5,7 @@ import cn.hutool.core.util.IdUtil; import cn.hutool.core.util.NumberUtil; import cn.hutool.core.util.StrUtil; import com.nflg.wms.admin.repository.InventoryCheckTaskScanRecordResitory; +import com.nflg.wms.admin.service.QmsService; import com.nflg.wms.common.constant.STATE; import com.nflg.wms.common.pojo.ApiResult; import com.nflg.wms.common.pojo.PageData; @@ -59,6 +60,9 @@ public class InventoryController extends BaseController { @Resource private IWmsQrCodeMasterService qrCodeMasterService; + @Resource + private QmsService qmsService; + /** * 库存查看 * @@ -69,6 +73,17 @@ public class InventoryController extends BaseController { return ApiResult.success(inventoryService.search(request)); } + /** + * 发起库存检测任务 + * + * @param request 库存检测申请参数 + */ + @PostMapping("detection/apply") + public ApiResult applyInventoryDetection(@Valid @RequestBody InventoryDetectionApplyQO request) { + qmsService.pushInventoryInspection(request); + return ApiResult.success(); + } + /** * 保存库存盘点任务 * diff --git a/nflg-wms-admin/src/main/java/com/nflg/wms/admin/service/QmsService.java b/nflg-wms-admin/src/main/java/com/nflg/wms/admin/service/QmsService.java index fdf2ba3e..1272afcb 100644 --- a/nflg-wms-admin/src/main/java/com/nflg/wms/admin/service/QmsService.java +++ b/nflg-wms-admin/src/main/java/com/nflg/wms/admin/service/QmsService.java @@ -3,7 +3,11 @@ package com.nflg.wms.admin.service; import cn.hutool.json.JSONUtil; import com.nflg.wms.common.pojo.ApiResult; import com.nflg.wms.common.pojo.qo.ExternalIncomingInspectionApplyQO; +import com.nflg.wms.common.pojo.qo.ExternalInventoryInspectionApplyQO; +import com.nflg.wms.common.pojo.qo.InventoryDetectionApplyQO; import com.nflg.wms.common.util.VUtil; +import com.nflg.wms.repository.entity.WmsInventory; +import com.nflg.wms.repository.service.IWmsInventoryService; import jakarta.annotation.Resource; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Value; @@ -26,6 +30,9 @@ public class QmsService { @Resource private RestTemplate restTemplate; + @Resource + private IWmsInventoryService inventoryService; + @Value("${qms.inspection.url:}") private String qmsUrl; @@ -49,4 +56,37 @@ public class QmsService { Objects.isNull(response.getBody()) || response.getBody().getCode() != 200 ).throwMessage("推送来料检验申请到QMS失败:" + response.getBody().getMessage()); } -} \ No newline at end of file + + public void pushInventoryInspection(InventoryDetectionApplyQO request) { + ExternalInventoryInspectionApplyQO apply = request.getApply(); + log.info("推送库存检测申请到QMS:申请参数={},二维码={}", + JSONUtil.toJsonStr(apply), JSONUtil.toJsonStr(request.getQrCodes())); + + HttpHeaders headers = new HttpHeaders(); + headers.setContentType(MediaType.APPLICATION_JSON); + HttpEntity requestEntity = new HttpEntity<>(apply, headers); + + ResponseEntity> response = restTemplate.exchange( + qmsUrl + "/external/incoming-inspection-task/inventory-apply", + HttpMethod.POST, + requestEntity, + new ParameterizedTypeReference>() {} + ); + + ApiResult body = response.getBody(); + log.info("推送库存检测申请到QMS结果:{},{}", + response.getStatusCode().value(), JSONUtil.toJsonStr(body)); + VUtil.trueThrowBusinessError(Objects.isNull(body) || body.getCode() != 200) + .throwMessage("推送库存检测申请到QMS失败:" + (Objects.isNull(body) ? "无响应内容" : body.getMessage())); + + boolean inventoryUpdated = inventoryService.lambdaUpdate() + .set(WmsInventory::getDetectionStatus, (short) 1) + .set(WmsInventory::getDetectionResults, null) + .eq(WmsInventory::getMaterialNo, apply.getMaterialNo()) + .eq(WmsInventory::getFactoryNo, apply.getFactory()) + .eq(WmsInventory::getWarehouseNo, apply.getWarehouse()) + .eq(WmsInventory::getBinLocation, apply.getStorageLocation()) + .update(); + VUtil.trueThrowBusinessError(!inventoryUpdated).throwMessage("未找到对应库存,无法更新检测状态"); + } +} diff --git a/nflg-wms-common/src/main/java/com/nflg/wms/common/pojo/qo/InventoryDetectionApplyQO.java b/nflg-wms-common/src/main/java/com/nflg/wms/common/pojo/qo/InventoryDetectionApplyQO.java new file mode 100644 index 00000000..05d47cf9 --- /dev/null +++ b/nflg-wms-common/src/main/java/com/nflg/wms/common/pojo/qo/InventoryDetectionApplyQO.java @@ -0,0 +1,26 @@ +package com.nflg.wms.common.pojo.qo; + +import jakarta.validation.Valid; +import jakarta.validation.constraints.NotNull; +import lombok.Data; + +import java.util.List; + +/** + * WMS发起库存检测申请 + */ +@Data +public class InventoryDetectionApplyQO { + + /** + * 库存检测申请参数 + */ + @Valid + @NotNull(message = "库存检测申请参数不能为空") + private ExternalInventoryInspectionApplyQO apply; + + /** + * 物料二维码列表,允许为空;后续落库使用,本次仅预留 + */ + private List qrCodes; +} From e51f5cf4e7ba6a8e588245c00939110a4aaa16ec Mon Sep 17 00:00:00 2001 From: yf001217 <834502597@qq.com> Date: Fri, 5 Jun 2026 16:22:13 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E5=AE=9A=E6=97=B6?= =?UTF-8?q?=E5=8F=91=E8=B5=B7=E5=BA=93=E5=AD=98=E6=A3=80=E6=B5=8B=E4=BB=BB?= =?UTF-8?q?=E5=8A=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...toryExpirationInspectionScheduledTask.java | 103 ++++++++++++++++++ .../nflg/wms/admin/service/QmsService.java | 52 +++++++-- .../pojo/qo/InventoryDetectionApplyQO.java | 24 ++-- 3 files changed, 163 insertions(+), 16 deletions(-) create mode 100644 nflg-wms-admin/src/main/java/com/nflg/wms/admin/schedule/InventoryExpirationInspectionScheduledTask.java diff --git a/nflg-wms-admin/src/main/java/com/nflg/wms/admin/schedule/InventoryExpirationInspectionScheduledTask.java b/nflg-wms-admin/src/main/java/com/nflg/wms/admin/schedule/InventoryExpirationInspectionScheduledTask.java new file mode 100644 index 00000000..6f502eb6 --- /dev/null +++ b/nflg-wms-admin/src/main/java/com/nflg/wms/admin/schedule/InventoryExpirationInspectionScheduledTask.java @@ -0,0 +1,103 @@ +package com.nflg.wms.admin.schedule; + +import com.nflg.wms.admin.service.QmsService; +import com.nflg.wms.common.pojo.qo.InventoryDetectionApplyQO; +import com.nflg.wms.repository.entity.QmsQcMaterial; +import com.nflg.wms.repository.entity.WmsInventory; +import com.nflg.wms.repository.service.IQmsQcMaterialService; +import com.nflg.wms.repository.service.IWmsInventoryService; +import jakarta.annotation.Resource; +import lombok.extern.slf4j.Slf4j; +import org.springframework.scheduling.annotation.Scheduled; +import org.springframework.stereotype.Component; + +import java.math.BigDecimal; +import java.time.LocalDateTime; +import java.time.temporal.ChronoUnit; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import java.util.Set; +import java.util.function.Function; +import java.util.stream.Collectors; + +/** + * 库存物料过期自动发起检测任务 + */ +@Slf4j +@Component +public class InventoryExpirationInspectionScheduledTask { + + @Resource + private IWmsInventoryService inventoryService; + + @Resource + private IQmsQcMaterialService qcMaterialService; + + @Resource + private QmsService qmsService; + + /** + * 每天凌晨1点检查库存物料是否过期 + */ + @Scheduled(cron = "0 0 1 * * ?") + public void applyExpiredInventoryInspection() { + LocalDateTime now = LocalDateTime.now(); + List inventories = inventoryService.lambdaQuery() + .gt(WmsInventory::getNum, BigDecimal.ZERO) + .isNotNull(WmsInventory::getCreateTime) + .eq(WmsInventory::getDetectionStatus, (short) 0) + .list(); + if (inventories.isEmpty()) { + log.info("库存物料过期检测任务执行完成:无待检查库存"); + return; + } + + Set materialNos = inventories.stream() + .map(WmsInventory::getMaterialNo) + .filter(Objects::nonNull) + .collect(Collectors.toSet()); + if (materialNos.isEmpty()) { + log.info("库存物料过期检测任务执行完成:待检查库存均无物料编号"); + return; + } + + Map materialMap = qcMaterialService.lambdaQuery() + .in(QmsQcMaterial::getMaterialNo, materialNos) + .orderByDesc(QmsQcMaterial::getId) + .list() + .stream() + .collect(Collectors.toMap(QmsQcMaterial::getMaterialNo, Function.identity(), (first, ignored) -> first)); + + int applied = 0; + int skipped = 0; + int failed = 0; + for (WmsInventory inventory : inventories) { + QmsQcMaterial material = materialMap.get(inventory.getMaterialNo()); + if (Objects.isNull(material) || Objects.isNull(material.getValidityPeriod())) { + skipped++; + continue; + } + + LocalDateTime expiredTime = inventory.getCreateTime().plusMonths(material.getValidityPeriod()); + if (!expiredTime.isBefore(now)) { + skipped++; + continue; + } + + InventoryDetectionApplyQO request = new InventoryDetectionApplyQO(); + request.setInventoryId(inventory.getId()); + request.setInspectionQty(inventory.getNum().intValue()); + request.setStorageDays(Math.max(1, (int) ChronoUnit.DAYS.between(inventory.getCreateTime(), now))); + try { + qmsService.pushInventoryInspection(request); + applied++; + } catch (Exception ex) { + failed++; + log.error("库存物料过期检测任务发起失败,库存ID:{}", inventory.getId(), ex); + } + } + log.info("库存物料过期检测任务执行完成:检查库存数={},发起检测数={},跳过数={},失败数={}", + inventories.size(), applied, skipped, failed); + } +} diff --git a/nflg-wms-admin/src/main/java/com/nflg/wms/admin/service/QmsService.java b/nflg-wms-admin/src/main/java/com/nflg/wms/admin/service/QmsService.java index 1272afcb..68f661b9 100644 --- a/nflg-wms-admin/src/main/java/com/nflg/wms/admin/service/QmsService.java +++ b/nflg-wms-admin/src/main/java/com/nflg/wms/admin/service/QmsService.java @@ -7,7 +7,9 @@ import com.nflg.wms.common.pojo.qo.ExternalInventoryInspectionApplyQO; import com.nflg.wms.common.pojo.qo.InventoryDetectionApplyQO; import com.nflg.wms.common.util.VUtil; import com.nflg.wms.repository.entity.WmsInventory; +import com.nflg.wms.repository.entity.WmsQrCodeMaster; import com.nflg.wms.repository.service.IWmsInventoryService; +import com.nflg.wms.repository.service.IWmsQrCodeMasterService; import jakarta.annotation.Resource; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Value; @@ -20,6 +22,9 @@ import org.springframework.http.ResponseEntity; import org.springframework.stereotype.Component; import org.springframework.web.client.RestTemplate; +import java.math.BigDecimal; +import java.time.LocalDateTime; +import java.time.format.DateTimeFormatter; import java.util.List; import java.util.Objects; @@ -27,12 +32,17 @@ import java.util.Objects; @Component public class QmsService { + private static final DateTimeFormatter INVENTORY_INSPECTION_REQUEST_NO_FORMATTER = DateTimeFormatter.ofPattern("yyyyMMddHH"); + @Resource private RestTemplate restTemplate; @Resource private IWmsInventoryService inventoryService; + @Resource + private IWmsQrCodeMasterService qrCodeMasterService; + @Value("${qms.inspection.url:}") private String qmsUrl; @@ -58,9 +68,36 @@ public class QmsService { } public void pushInventoryInspection(InventoryDetectionApplyQO request) { - ExternalInventoryInspectionApplyQO apply = request.getApply(); - log.info("推送库存检测申请到QMS:申请参数={},二维码={}", - JSONUtil.toJsonStr(apply), JSONUtil.toJsonStr(request.getQrCodes())); + WmsInventory inventory = inventoryService.getById(request.getInventoryId()); + VUtil.trueThrowBusinessError(Objects.isNull(inventory)).throwMessage("未找到对应库存"); + VUtil.trueThrowBusinessError(Objects.equals(inventory.getDetectionStatus(), (short) 1)) + .throwMessage("该库存正在检测中,不能重复发起检测任务"); + VUtil.trueThrowBusinessError( + Objects.isNull(inventory.getNum()) + || BigDecimal.valueOf(request.getInspectionQty()).compareTo(inventory.getNum()) > 0 + ).throwMessage("检验数量不能大于库存数量"); + + ExternalInventoryInspectionApplyQO apply = new ExternalInventoryInspectionApplyQO(); + apply.setRequestNo(generateInventoryInspectionRequestNo(request.getInventoryId())); + apply.setMaterialNo(inventory.getMaterialNo()); + apply.setFactory(inventory.getFactoryNo()); + apply.setInspectionQty(request.getInspectionQty()); + apply.setWarehouse(inventory.getWarehouseNo()); + apply.setStorageLocation(inventory.getBinLocation()); + apply.setStorageDays(request.getStorageDays()); + + List qrCodes = qrCodeMasterService.lambdaQuery() + .select(WmsQrCodeMaster::getBarcodeCode) + .eq(WmsQrCodeMaster::getMaterialCode, apply.getMaterialNo()) + .eq(WmsQrCodeMaster::getFactoryCode, apply.getFactory()) + .eq(WmsQrCodeMaster::getStorageLocation, apply.getWarehouse()) + .eq(WmsQrCodeMaster::getBinLocation, apply.getStorageLocation()) + .list() + .stream() + .map(WmsQrCodeMaster::getBarcodeCode) + .toList(); + log.info("推送库存检测申请到QMS:申请参数={},关联二维码={}", + JSONUtil.toJsonStr(apply), JSONUtil.toJsonStr(qrCodes)); HttpHeaders headers = new HttpHeaders(); headers.setContentType(MediaType.APPLICATION_JSON); @@ -82,11 +119,12 @@ public class QmsService { boolean inventoryUpdated = inventoryService.lambdaUpdate() .set(WmsInventory::getDetectionStatus, (short) 1) .set(WmsInventory::getDetectionResults, null) - .eq(WmsInventory::getMaterialNo, apply.getMaterialNo()) - .eq(WmsInventory::getFactoryNo, apply.getFactory()) - .eq(WmsInventory::getWarehouseNo, apply.getWarehouse()) - .eq(WmsInventory::getBinLocation, apply.getStorageLocation()) + .eq(WmsInventory::getId, request.getInventoryId()) .update(); VUtil.trueThrowBusinessError(!inventoryUpdated).throwMessage("未找到对应库存,无法更新检测状态"); } + + private String generateInventoryInspectionRequestNo(Long inventoryId) { + return LocalDateTime.now().format(INVENTORY_INSPECTION_REQUEST_NO_FORMATTER) + inventoryId; + } } diff --git a/nflg-wms-common/src/main/java/com/nflg/wms/common/pojo/qo/InventoryDetectionApplyQO.java b/nflg-wms-common/src/main/java/com/nflg/wms/common/pojo/qo/InventoryDetectionApplyQO.java index 05d47cf9..dbda070a 100644 --- a/nflg-wms-common/src/main/java/com/nflg/wms/common/pojo/qo/InventoryDetectionApplyQO.java +++ b/nflg-wms-common/src/main/java/com/nflg/wms/common/pojo/qo/InventoryDetectionApplyQO.java @@ -1,11 +1,9 @@ package com.nflg.wms.common.pojo.qo; -import jakarta.validation.Valid; +import jakarta.validation.constraints.Min; import jakarta.validation.constraints.NotNull; import lombok.Data; -import java.util.List; - /** * WMS发起库存检测申请 */ @@ -13,14 +11,22 @@ import java.util.List; public class InventoryDetectionApplyQO { /** - * 库存检测申请参数 + * 库存ID */ - @Valid - @NotNull(message = "库存检测申请参数不能为空") - private ExternalInventoryInspectionApplyQO apply; + @NotNull(message = "库存ID不能为空") + private Long inventoryId; /** - * 物料二维码列表,允许为空;后续落库使用,本次仅预留 + * 检验数量 */ - private List qrCodes; + @NotNull(message = "检验数量不能为空") + @Min(value = 1, message = "检验数量必须大于0") + private Integer inspectionQty; + + /** + * 存储时长(单位:天) + */ + @NotNull(message = "存储时长不能为空") + @Min(value = 1, message = "存储时长必须大于0") + private Integer storageDays; }