From c3916419ed18986e6ed2f18db6fb80efa1ea13f5 Mon Sep 17 00:00:00 2001 From: yf001217 <834502597@qq.com> Date: Mon, 8 Jun 2026 09:34:47 +0800 Subject: [PATCH] =?UTF-8?q?=E6=88=90=E5=93=81=E5=8F=91=E8=B4=A7=E4=BF=AE?= =?UTF-8?q?=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...xternalPdiTaskRecordControllerService.java | 45 +++++++++++++++++-- .../controller/OutProduceController.java | 15 +++++++ .../nflg/wms/admin/service/QmsService.java | 44 ++++++++++++++++++ .../common/pojo/qo/QmsPdiTaskRecordAddQO.java | 13 ++---- .../pojo/vo/OutProduceTicketInfoVO.java | 10 ----- .../nflg/wms/common/pojo/vo/OutProduceVO.java | 9 ---- .../wms/repository/entity/WmsOutProduce.java | 9 ---- 7 files changed, 103 insertions(+), 42 deletions(-) diff --git a/nflg-qms-admin/src/main/java/com/nflg/qms/admin/service/ExternalPdiTaskRecordControllerService.java b/nflg-qms-admin/src/main/java/com/nflg/qms/admin/service/ExternalPdiTaskRecordControllerService.java index 6e053df9..3586ce40 100644 --- a/nflg-qms-admin/src/main/java/com/nflg/qms/admin/service/ExternalPdiTaskRecordControllerService.java +++ b/nflg-qms-admin/src/main/java/com/nflg/qms/admin/service/ExternalPdiTaskRecordControllerService.java @@ -1,5 +1,6 @@ package com.nflg.qms.admin.service; +import cn.hutool.core.util.StrUtil; import com.nflg.wms.common.constant.STATE; import com.nflg.wms.common.exception.NflgException; import com.nflg.wms.common.pojo.qo.QmsPdiTaskRecordAddQO; @@ -28,6 +29,8 @@ import java.util.Objects; @Service public class ExternalPdiTaskRecordControllerService { + private static final int PDI_TASK_RECORD_SERIAL_TYPE = 45; + @Resource private IQmsPdiTaskRecordService taskRecordService; @@ -43,6 +46,9 @@ public class ExternalPdiTaskRecordControllerService { @Resource private IQmsPdiInspectionResultsService inspectionResultsService; + @Resource + private BasdeSerialNumberControllerService basdeSerialNumberControllerService; + // ========================= 新增 ========================= /** @@ -54,7 +60,10 @@ public class ExternalPdiTaskRecordControllerService { @Transactional public void add(QmsPdiTaskRecordAddQO request) { // 查检测规则,获取 inspection_cycle - QmsPdiDetectionRules rule = pdiDetectionRulesService.getById(request.getDetectionRulesId()); + QmsPdiDetectionRules rule = getPublishedRuleByOrderNo(request.getOrderNo()); + if (Objects.isNull(rule)) { + rule = getPublishedRuleByModelNo(request.getModelNo()); + } if (Objects.isNull(rule)) { throw new NflgException(STATE.BusinessError, "PDI检测规则不存在"); } @@ -76,11 +85,15 @@ public class ExternalPdiTaskRecordControllerService { LocalDateTime requiredCompletionTime = submissionTime.plusDays( rule.getInspectionCycle() != null ? rule.getInspectionCycle() : 0 ); + String taskNo = basdeSerialNumberControllerService.generateSerialNumber(PDI_TASK_RECORD_SERIAL_TYPE); + if (StrUtil.isBlank(taskNo)) { + throw new NflgException(STATE.BusinessError, "PDI检测任务编号生成失败"); + } // 1. 保存任务单 QmsPdiTaskRecord record = new QmsPdiTaskRecord() - .setDetectionRulesId(request.getDetectionRulesId()) - .setTaskNo(request.getTaskNo()) + .setDetectionRulesId(rule.getId()) + .setTaskNo(taskNo) .setDeviceNo(request.getDeviceNo()) .setOrderNo(request.getOrderNo()) .setFactoryNo(request.getFactoryNo()) @@ -90,7 +103,7 @@ public class ExternalPdiTaskRecordControllerService { .setRequiredCompletionTime(requiredCompletionTime); taskRecordService.save(record); Long taskId = record.getId(); - Long detectionRulesId = request.getDetectionRulesId(); + Long detectionRulesId = rule.getId(); // 2. 初始化空白检测结果行 List resultRows = new ArrayList<>(); @@ -142,5 +155,29 @@ public class ExternalPdiTaskRecordControllerService { inspectionResultsService.saveBatch(resultRows); } } + + private QmsPdiDetectionRules getPublishedRuleByOrderNo(String orderNo) { + return pdiDetectionRulesService.lambdaQuery() + .eq(QmsPdiDetectionRules::getOrderNo, orderNo) + .eq(QmsPdiDetectionRules::getInspectionType, 0) + .eq(QmsPdiDetectionRules::getEnable, true) + .eq(QmsPdiDetectionRules::getPublishEnable, true) + .orderByDesc(QmsPdiDetectionRules::getPublishTime) + .orderByDesc(QmsPdiDetectionRules::getId) + .last("LIMIT 1") + .one(); + } + + private QmsPdiDetectionRules getPublishedRuleByModelNo(String modelNo) { + return pdiDetectionRulesService.lambdaQuery() + .eq(QmsPdiDetectionRules::getModelNo, modelNo) + .eq(QmsPdiDetectionRules::getInspectionType, 0) + .eq(QmsPdiDetectionRules::getEnable, true) + .eq(QmsPdiDetectionRules::getPublishEnable, true) + .orderByDesc(QmsPdiDetectionRules::getPublishTime) + .orderByDesc(QmsPdiDetectionRules::getId) + .last("LIMIT 1") + .one(); + } } diff --git a/nflg-wms-admin/src/main/java/com/nflg/wms/admin/controller/OutProduceController.java b/nflg-wms-admin/src/main/java/com/nflg/wms/admin/controller/OutProduceController.java index 37867e3f..697e75d5 100644 --- a/nflg-wms-admin/src/main/java/com/nflg/wms/admin/controller/OutProduceController.java +++ b/nflg-wms-admin/src/main/java/com/nflg/wms/admin/controller/OutProduceController.java @@ -14,6 +14,7 @@ import com.nflg.wms.admin.repository.InventoryForOutRepository; import com.nflg.wms.admin.repository.OutMaterialScanRecordRespository; import com.nflg.wms.admin.service.BasdeSerialNumberControllerService; import com.nflg.wms.admin.service.NoScanningBaseControllerService; +import com.nflg.wms.admin.service.QmsService; import com.nflg.wms.admin.service.SapService; import com.nflg.wms.admin.util.PdfGeneratorUtil; import com.nflg.wms.admin.util.QRCodeUtil; @@ -111,6 +112,9 @@ public class OutProduceController extends BaseController { @Resource private NoScanningBaseControllerService noScanningBaseControllerService; + @Resource + private QmsService qmsService; + /** * 查询SAP领料订单数据 */ @@ -278,6 +282,17 @@ public class OutProduceController extends BaseController { return ApiResult.success(outProduceService.search(request)); } + /** + * 发起PDI检测任务 + * + * @param id 成品发货单ID + */ + @PostMapping("pdi/apply") + public ApiResult applyPdiInspection(@Valid @RequestParam @NotNull Long id) { + qmsService.pushPdiInspection(id); + return ApiResult.success(); + } + // /** // * 解锁库存(根据订单) // * @deprecated 不需要这个方法了 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 93928faa..201379f9 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 @@ -1,14 +1,18 @@ package com.nflg.wms.admin.service; +import cn.hutool.core.util.StrUtil; 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.pojo.qo.QmsPdiTaskRecordAddQO; import com.nflg.wms.common.util.VUtil; import com.nflg.wms.repository.entity.WmsInventory; +import com.nflg.wms.repository.entity.WmsOutProduce; import com.nflg.wms.repository.entity.WmsQrCodeMaster; import com.nflg.wms.repository.service.IWmsInventoryService; +import com.nflg.wms.repository.service.IWmsOutProduceService; import com.nflg.wms.repository.service.IWmsQrCodeMasterService; import jakarta.annotation.Resource; import lombok.extern.slf4j.Slf4j; @@ -42,6 +46,9 @@ public class QmsService { @Resource private IWmsInventoryService inventoryService; + @Resource + private IWmsOutProduceService outProduceService; + @Resource private IWmsQrCodeMasterService qrCodeMasterService; @@ -126,7 +133,44 @@ public class QmsService { VUtil.trueThrowBusinessError(!inventoryUpdated).throwMessage("未找到对应库存,无法更新检测状态"); } + public void pushPdiInspection(Long outProduceId) { + WmsOutProduce outProduce = outProduceService.getById(outProduceId); + VUtil.trueThrowBusinessError(Objects.isNull(outProduce)).throwMessage("未找到对应成品发货单"); + VUtil.trueThrowBusinessError(!Objects.equals(outProduce.getType(), 0) || !Objects.equals(outProduce.getDataType(), 1)) + .throwMessage("仅成品发货单允许发起PDI检测任务"); + VUtil.trueThrowBusinessError(StrUtil.hasBlank(outProduce.getPlnbez(), outProduce.getJtsn(), outProduce.getAufnr(), outProduce.getDwerk())) + .throwMessage("成品物料号、机台编号、生产订单号、工厂编号不能为空"); + + QmsPdiTaskRecordAddQO apply = new QmsPdiTaskRecordAddQO(); + apply.setModelNo(outProduce.getPlnbez()); + apply.setDeviceNo(outProduce.getJtsn()); + apply.setOrderNo(outProduce.getAufnr()); + apply.setFactoryNo(outProduce.getDwerk()); + apply.setWarehouseNo(outProduce.getLgort2()); + + log.info("推送PDI检测任务到QMS:{}", JSONUtil.toJsonStr(apply)); + + HttpHeaders headers = new HttpHeaders(); + headers.setContentType(MediaType.APPLICATION_JSON); + HttpEntity requestEntity = new HttpEntity<>(apply, headers); + + ResponseEntity> response = restTemplate.exchange( + qmsHost + "/external/pdi-task-record/add", + HttpMethod.POST, + requestEntity, + new ParameterizedTypeReference>() {} + ); + + ApiResult body = response.getBody(); + log.info("推送PDI检测任务到QMS结果:{},{}", + response.getStatusCode().value(), JSONUtil.toJsonStr(body)); + VUtil.trueThrowBusinessError(Objects.isNull(body) || body.getCode() != 200) + .throwMessage("推送PDI检测任务到QMS失败:" + (Objects.isNull(body) ? "无响应内容" : body.getMessage())); + + } + 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/QmsPdiTaskRecordAddQO.java b/nflg-wms-common/src/main/java/com/nflg/wms/common/pojo/qo/QmsPdiTaskRecordAddQO.java index 86622bb6..3d18a906 100644 --- a/nflg-wms-common/src/main/java/com/nflg/wms/common/pojo/qo/QmsPdiTaskRecordAddQO.java +++ b/nflg-wms-common/src/main/java/com/nflg/wms/common/pojo/qo/QmsPdiTaskRecordAddQO.java @@ -1,7 +1,6 @@ package com.nflg.wms.common.pojo.qo; import jakarta.validation.constraints.NotBlank; -import jakarta.validation.constraints.NotNull; import lombok.Data; /** @@ -11,16 +10,10 @@ import lombok.Data; public class QmsPdiTaskRecordAddQO { /** - * PDI检测规则ID(必传) + * 机型编号(必传) */ - @NotNull(message = "PDI检测规则ID不能为空") - private Long detectionRulesId; - - /** - * 检测任务编号(必传) - */ - @NotBlank(message = "检测任务编号不能为空") - private String taskNo; + @NotBlank(message = "机型编号不能为空") + private String modelNo; /** * 机台编号(必传) diff --git a/nflg-wms-common/src/main/java/com/nflg/wms/common/pojo/vo/OutProduceTicketInfoVO.java b/nflg-wms-common/src/main/java/com/nflg/wms/common/pojo/vo/OutProduceTicketInfoVO.java index 1e74b40f..3eca45d1 100644 --- a/nflg-wms-common/src/main/java/com/nflg/wms/common/pojo/vo/OutProduceTicketInfoVO.java +++ b/nflg-wms-common/src/main/java/com/nflg/wms/common/pojo/vo/OutProduceTicketInfoVO.java @@ -120,15 +120,5 @@ public class OutProduceTicketInfoVO { */ private String docYear; - /** - * 检测状态:0=未检测,1=检测中,2=已检测 - */ - private Short detectionStatus; - - /** - * 检测结果:true=合格,false=不合格 - */ - private Boolean detectionResults; - private List items; } diff --git a/nflg-wms-common/src/main/java/com/nflg/wms/common/pojo/vo/OutProduceVO.java b/nflg-wms-common/src/main/java/com/nflg/wms/common/pojo/vo/OutProduceVO.java index 8b6b35cd..2077f965 100644 --- a/nflg-wms-common/src/main/java/com/nflg/wms/common/pojo/vo/OutProduceVO.java +++ b/nflg-wms-common/src/main/java/com/nflg/wms/common/pojo/vo/OutProduceVO.java @@ -116,13 +116,4 @@ public class OutProduceVO { */ private String docYear; - /** - * 检测状态:0=未检测,1=检测中,2=已检测 - */ - private Short detectionStatus; - - /** - * 检测结果:true=合格,false=不合格 - */ - private Boolean detectionResults; } diff --git a/nflg-wms-repository/src/main/java/com/nflg/wms/repository/entity/WmsOutProduce.java b/nflg-wms-repository/src/main/java/com/nflg/wms/repository/entity/WmsOutProduce.java index 2fcc76d0..0be0c29c 100644 --- a/nflg-wms-repository/src/main/java/com/nflg/wms/repository/entity/WmsOutProduce.java +++ b/nflg-wms-repository/src/main/java/com/nflg/wms/repository/entity/WmsOutProduce.java @@ -137,13 +137,4 @@ public class WmsOutProduce implements Serializable { @TableField("data_type") private Integer dataType; - /** - * 检测状态:0=未检测,1=检测中,2=已检测 - */ - private Short detectionStatus; - - /** - * 检测结果:true=合格,false=不合格 - */ - private Boolean detectionResults; }