From 7ac5fb62d3ac852ec9505eb5c1999064aafee85f Mon Sep 17 00:00:00 2001
From: 云 <2163098428@qq.com>
Date: 星期四, 13 八月 2026 16:26:39 +0800
Subject: [PATCH] feat(mes): 添加MES模块配置和功能
---
yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/wm/batch/MesWmBatchServiceImpl.java | 204 +++++++++++++++++++++++++++++----------------------
1 files changed, 116 insertions(+), 88 deletions(-)
diff --git a/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/wm/batch/MesWmBatchServiceImpl.java b/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/wm/batch/MesWmBatchServiceImpl.java
index bed3c88..ea88533 100644
--- a/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/wm/batch/MesWmBatchServiceImpl.java
+++ b/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/wm/batch/MesWmBatchServiceImpl.java
@@ -6,9 +6,14 @@
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.module.mes.controller.admin.wm.batch.vo.MesWmBatchGenerateReqVO;
import cn.iocoder.yudao.module.mes.controller.admin.wm.batch.vo.MesWmBatchPageReqVO;
+import cn.iocoder.yudao.module.mes.controller.admin.wm.batch.vo.MesWmBatchProcessTraceRespVO;
+import cn.iocoder.yudao.module.mes.controller.admin.wm.batch.vo.MesWmBatchPurchaseSourceRespVO;
+import cn.iocoder.yudao.module.mes.controller.admin.wm.batch.vo.MesWmBatchSalesTargetRespVO;
import cn.iocoder.yudao.module.mes.dal.dataobject.mdm.MesMdmItemDO;
import cn.iocoder.yudao.module.mes.dal.dataobject.wm.batch.MesWmBatchDO;
+import cn.iocoder.yudao.module.mes.dal.dataobject.wm.sn.MesWmSnDO;
import cn.iocoder.yudao.module.mes.dal.mysql.wm.batch.MesWmBatchMapper;
+import cn.iocoder.yudao.module.mes.dal.mysql.wm.sn.MesWmSnMapper;
import cn.iocoder.yudao.module.mes.enums.MesBizTypeConstants;
import cn.iocoder.yudao.module.mes.enums.md.autocode.MesMdAutoCodeRuleCodeEnum;
import cn.iocoder.yudao.module.mes.service.md.autocode.MesMdAutoCodeRecordService;
@@ -24,6 +29,7 @@
import org.springframework.validation.annotation.Validated;
import java.util.ArrayList;
+import java.util.Comparator;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
@@ -34,7 +40,7 @@
/**
* 鎵规绠$悊 Service 瀹炵幇绫�
*
- * @author 鑺嬮亾婧愮爜
+ * @author 瓒呯骇绠$悊鍛�
*/
@Service
@Validated
@@ -51,6 +57,8 @@
@Resource
private MesMdmItemService mdmItemService;
+ @Resource
+ private MesWmSnMapper snMapper;
@Resource
private MdmItemBatchConfigApi itemBatchConfigApi;
@Resource
@@ -97,122 +105,107 @@
// 2. 鏍规嵁閰嶇疆鏍¢獙蹇呭~鍙傛暟骞舵竻绌轰笉闇�瑕佺殑鍙傛暟
MesWmBatchDO batch = MesWmBatchDO.builder().itemId(reqVO.getItemId()).build();
if (config != null) {
+ // ========== 蹇呭~鏍¢獙锛坒lag=true 琛ㄧず璇ュ瓧娈典负蹇呭~锛� ==========
// 鐢熶骇鏃ユ湡
- if (Boolean.TRUE.equals(config.getProduceDateFlag())) {
- if (ObjUtil.isNull(reqVO.getProduceDate())) {
- throw exception(WM_BATCH_PRODUCE_DATE_REQUIRED);
- }
- batch.setProduceDate(reqVO.getProduceDate());
+ if (Boolean.TRUE.equals(config.getProduceDateFlag()) && ObjUtil.isNull(reqVO.getProduceDate())) {
+ throw exception(WM_BATCH_PRODUCE_DATE_REQUIRED);
}
// 鍏ュ簱鏃ユ湡
- if (Boolean.TRUE.equals(config.getReceiptDateFlag())) {
- if (ObjUtil.isNull(reqVO.getReceiptDate())) {
- throw exception(WM_BATCH_RECEIPT_DATE_REQUIRED);
- }
- batch.setReceiptDate(reqVO.getReceiptDate());
+ if (Boolean.TRUE.equals(config.getReceiptDateFlag()) && ObjUtil.isNull(reqVO.getReceiptDate())) {
+ throw exception(WM_BATCH_RECEIPT_DATE_REQUIRED);
}
// 鏈夋晥鏈�
- if (Boolean.TRUE.equals(config.getExpireDateFlag())) {
- if (ObjUtil.isNull(reqVO.getExpireDate())) {
- throw exception(WM_BATCH_EXPIRE_DATE_REQUIRED);
- }
- batch.setExpireDate(reqVO.getExpireDate());
+ if (Boolean.TRUE.equals(config.getExpireDateFlag()) && ObjUtil.isNull(reqVO.getExpireDate())) {
+ throw exception(WM_BATCH_EXPIRE_DATE_REQUIRED);
}
// 渚涘簲鍟�
- if (Boolean.TRUE.equals(config.getVendorFlag())) {
- if (ObjUtil.isNull(reqVO.getVendorId())) {
- throw exception(WM_BATCH_VENDOR_REQUIRED);
- }
- batch.setVendorId(reqVO.getVendorId());
+ if (Boolean.TRUE.equals(config.getVendorFlag()) && ObjUtil.isNull(reqVO.getVendorId())) {
+ throw exception(WM_BATCH_VENDOR_REQUIRED);
}
// 瀹㈡埛
- if (Boolean.TRUE.equals(config.getClientFlag())) {
- if (ObjUtil.isNull(reqVO.getClientId())) {
- throw exception(WM_BATCH_CLIENT_REQUIRED);
- }
- batch.setClientId(reqVO.getClientId());
+ if (Boolean.TRUE.equals(config.getClientFlag()) && ObjUtil.isNull(reqVO.getClientId())) {
+ throw exception(WM_BATCH_CLIENT_REQUIRED);
}
// 閲囪喘璁㈠崟缂栧彿
- if (Boolean.TRUE.equals(config.getPurchaseOrderCodeFlag())) {
- if (ObjUtil.isNull(reqVO.getPurchaseOrderCode())) {
- throw exception(WM_BATCH_PURCHASE_ORDER_CODE_REQUIRED);
- }
- batch.setPurchaseOrderCode(reqVO.getPurchaseOrderCode());
+ if (Boolean.TRUE.equals(config.getPurchaseOrderCodeFlag()) && ObjUtil.isNull(reqVO.getPurchaseOrderCode())) {
+ throw exception(WM_BATCH_PURCHASE_ORDER_CODE_REQUIRED);
}
// 閿�鍞鍗曠紪鍙�
- if (Boolean.TRUE.equals(config.getSalesOrderCodeFlag())) {
- if (ObjUtil.isNull(reqVO.getSalesOrderCode())) {
- throw exception(WM_BATCH_CUSTOMER_ORDER_CODE_REQUIRED);
- }
- batch.setSalesOrderCode(reqVO.getSalesOrderCode());
+ if (Boolean.TRUE.equals(config.getSalesOrderCodeFlag()) && ObjUtil.isNull(reqVO.getSalesOrderCode())) {
+ throw exception(WM_BATCH_CUSTOMER_ORDER_CODE_REQUIRED);
}
// 鐢熶骇宸ュ崟
- if (Boolean.TRUE.equals(config.getWorkOrderFlag())) {
- if (ObjUtil.isNull(reqVO.getWorkOrderId())) {
- throw exception(WM_BATCH_WORK_ORDER_REQUIRED);
- }
- batch.setWorkOrderId(reqVO.getWorkOrderId());
+ if (Boolean.TRUE.equals(config.getWorkOrderFlag()) && ObjUtil.isNull(reqVO.getWorkOrderId())) {
+ throw exception(WM_BATCH_WORK_ORDER_REQUIRED);
}
// 鐢熶骇浠诲姟
- if (Boolean.TRUE.equals(config.getTaskFlag())) {
- if (ObjUtil.isNull(reqVO.getTaskId())) {
- throw exception(WM_BATCH_TASK_REQUIRED);
- }
- batch.setTaskId(reqVO.getTaskId());
+ if (Boolean.TRUE.equals(config.getTaskFlag()) && ObjUtil.isNull(reqVO.getTaskId())) {
+ throw exception(WM_BATCH_TASK_REQUIRED);
}
// 宸ヤ綔绔�
- if (Boolean.TRUE.equals(config.getWorkstationFlag())) {
- if (ObjUtil.isNull(reqVO.getWorkstationId())) {
- throw exception(WM_BATCH_WORKSTATION_REQUIRED);
- }
- batch.setWorkstationId(reqVO.getWorkstationId());
+ if (Boolean.TRUE.equals(config.getWorkstationFlag()) && ObjUtil.isNull(reqVO.getWorkstationId())) {
+ throw exception(WM_BATCH_WORKSTATION_REQUIRED);
}
// 宸ュ叿
- if (Boolean.TRUE.equals(config.getToolFlag())) {
- if (ObjUtil.isNull(reqVO.getToolId())) {
- throw exception(WM_BATCH_TOOL_REQUIRED);
- }
- batch.setToolId(reqVO.getToolId());
+ if (Boolean.TRUE.equals(config.getToolFlag()) && ObjUtil.isNull(reqVO.getToolId())) {
+ throw exception(WM_BATCH_TOOL_REQUIRED);
}
// 妯″叿
- if (Boolean.TRUE.equals(config.getMoldFlag())) {
- if (ObjUtil.isNull(reqVO.getMoldId())) {
- throw exception(WM_BATCH_MOLD_REQUIRED);
- }
- batch.setMoldId(reqVO.getMoldId());
+ if (Boolean.TRUE.equals(config.getMoldFlag()) && ObjUtil.isNull(reqVO.getMoldId())) {
+ throw exception(WM_BATCH_MOLD_REQUIRED);
}
// 鐢熶骇鎵瑰彿
- if (Boolean.TRUE.equals(config.getLotNumberFlag())) {
- if (ObjUtil.isNull(reqVO.getLotNumber())) {
- throw exception(WM_BATCH_LOT_NUMBER_REQUIRED);
- }
- batch.setLotNumber(reqVO.getLotNumber());
+ if (Boolean.TRUE.equals(config.getLotNumberFlag()) && ObjUtil.isNull(reqVO.getLotNumber())) {
+ throw exception(WM_BATCH_LOT_NUMBER_REQUIRED);
}
// 璐ㄩ噺鐘舵��
- if (Boolean.TRUE.equals(config.getQualityStatusFlag())) {
- if (ObjUtil.isNull(reqVO.getQualityStatus())) {
- throw exception(WM_BATCH_QUALITY_STATUS_REQUIRED);
- }
- batch.setQualityStatus(reqVO.getQualityStatus());
+ if (Boolean.TRUE.equals(config.getQualityStatusFlag()) && ObjUtil.isNull(reqVO.getQualityStatus())) {
+ throw exception(WM_BATCH_QUALITY_STATUS_REQUIRED);
}
}
- // 鏃犳壒娆¢厤缃椂锛屼娇鐢ㄤ紶鍏ョ殑鍙傛暟锛堝鏉炬ā寮忥紝閫傜敤浜庤嚜瀹氫箟鍏ュ簱绛夊満鏅級
- else {
- if (reqVO.getProduceDate() != null) {
- batch.setProduceDate(reqVO.getProduceDate());
- }
- if (reqVO.getReceiptDate() != null) {
- batch.setReceiptDate(reqVO.getReceiptDate());
- }
- if (reqVO.getExpireDate() != null) {
- batch.setExpireDate(reqVO.getExpireDate());
- }
- if (reqVO.getVendorId() != null) {
- batch.setVendorId(reqVO.getVendorId());
- }
- if (reqVO.getClientId() != null) {
- batch.setClientId(reqVO.getClientId());
- }
+
+ // ========== 淇濆瓨瀛楁锛堟棤璁烘湁鏃犻厤缃紝鍙璋冪敤鏂逛紶浜嗗氨淇濆瓨锛� ==========
+ if (reqVO.getProduceDate() != null) {
+ batch.setProduceDate(reqVO.getProduceDate());
+ }
+ if (reqVO.getReceiptDate() != null) {
+ batch.setReceiptDate(reqVO.getReceiptDate());
+ }
+ if (reqVO.getExpireDate() != null) {
+ batch.setExpireDate(reqVO.getExpireDate());
+ }
+ if (reqVO.getVendorId() != null) {
+ batch.setVendorId(reqVO.getVendorId());
+ }
+ if (reqVO.getClientId() != null) {
+ batch.setClientId(reqVO.getClientId());
+ }
+ if (reqVO.getPurchaseOrderCode() != null) {
+ batch.setPurchaseOrderCode(reqVO.getPurchaseOrderCode());
+ }
+ if (reqVO.getSalesOrderCode() != null) {
+ batch.setSalesOrderCode(reqVO.getSalesOrderCode());
+ }
+ if (reqVO.getWorkOrderId() != null) {
+ batch.setWorkOrderId(reqVO.getWorkOrderId());
+ }
+ if (reqVO.getTaskId() != null) {
+ batch.setTaskId(reqVO.getTaskId());
+ }
+ if (reqVO.getWorkstationId() != null) {
+ batch.setWorkstationId(reqVO.getWorkstationId());
+ }
+ if (reqVO.getToolId() != null) {
+ batch.setToolId(reqVO.getToolId());
+ }
+ if (reqVO.getMoldId() != null) {
+ batch.setMoldId(reqVO.getMoldId());
+ }
+ if (reqVO.getLotNumber() != null) {
+ batch.setLotNumber(reqVO.getLotNumber());
+ }
+ if (reqVO.getQualityStatus() != null) {
+ batch.setQualityStatus(reqVO.getQualityStatus());
}
// 3.1 鎯呭喌涓�锛氫紶鍏ヤ簡 batchCode锛屾煡璇㈡槸鍚﹀瓨鍦ㄨ鎵规鍙�
@@ -387,4 +380,39 @@
return batchMapper.selectCountByToolId(toolId);
}
+ @Override
+ public List<MesWmBatchPurchaseSourceRespVO> getPurchaseSourceList(String code) {
+ return batchMapper.selectPurchaseSourceList(code);
+ }
+
+ @Override
+ public List<MesWmBatchSalesTargetRespVO> getSalesTargetList(String code) {
+ return batchMapper.selectSalesTargetList(code);
+ }
+
+ @Override
+ public List<MesWmBatchProcessTraceRespVO> getProcessTraceList(String code) {
+ List<MesWmBatchProcessTraceRespVO> list = batchMapper.selectProcessTraceList(code);
+ if (CollUtil.isEmpty(list)) {
+ return list;
+ }
+ // 鎸夊伐鍗曘�佸伐搴忓簭鍙枫�佷簨浠舵椂闂存帓搴忥紙sort 鍙兘涓虹┖锛岀┖鍊煎厹搴曪級
+ list.sort(Comparator.comparing(MesWmBatchProcessTraceRespVO::getWorkOrderId,
+ Comparator.nullsLast(Comparator.naturalOrder()))
+ .thenComparing(MesWmBatchProcessTraceRespVO::getProcessSort,
+ Comparator.nullsLast(Comparator.naturalOrder()))
+ .thenComparing(MesWmBatchProcessTraceRespVO::getEventTime,
+ Comparator.nullsLast(Comparator.naturalOrder())));
+ return list;
+ }
+
+ @Override
+ public MesWmBatchDO getBatchBySn(String sn) {
+ MesWmSnDO snDO = snMapper.selectOne(MesWmSnDO::getCode, sn);
+ if (snDO == null || StrUtil.isBlank(snDO.getBatchCode())) {
+ return null;
+ }
+ return batchMapper.selectByCode(snDO.getBatchCode());
+ }
+
}
--
Gitblit v1.9.3