From 227eff61120aaca63e068035d745d86452e6499a Mon Sep 17 00:00:00 2001
From: hsy <1029150275@qq.com>
Date: 星期一, 17 八月 2026 09:35:12 +0800
Subject: [PATCH] feat(mes): 优化生产订单与排产任务列表显示,新增启停工及校验逻辑 1. 生产订单列表展示优化 (WorkOrder)   - 新增「生产状态」列,全局注册 `ORDER_PRODUCTION_STATUS` 常量并绑定系统动态字典。   - 彻底重构「工序生产进度」单元格显示:弃用臃肿的 Steps 组件,改为极简横向布局(彩色状态圆点 + 进度百分比),解决表格行高被强行撑开及内容截断问题,支持横向滚动。   - 优化「完成进度」列宽及展示样式,将百分比数值外置同行显示,更加直观。 2. 排产任务列表改造 (Task)   - 顶部表头重构,由单一标题重构为「全部 / 未完成 / 已完成」的 Tabs 标签页切换结构。   - 重写数据过滤逻辑,剥离写死的 status 查询,改为使用 `scheduleStatus` 字段动态响应 Tabs 切换 (0: 未完成, 1: 已完成)。 3. 工单业务逻辑增强与状态流转   - 落实「工单查询逻辑设计方案」,优化底层的工单条件检索逻辑。   - 实现「添加工单启停功能」与「停工状态」,支持工单在执行过程中的暂停与恢复业务流转。   - 强化容错与防呆设计:操作「完成订单」时增加前置校验 `handleCheckFinish`,若生产状态为未完成,强制弹出二次确认 Modal,避免误操作。 # 相关讨论/参考方案 # - 添加工单启停功能 # - 停工状态功能设计方案 # - 工单查询逻辑设计方案 # - 工单完成进度显示优化

---
 yudao-module-mdm/src/main/java/cn/iocoder/yudao/module/mdm/service/item/MdmItemServiceImpl.java |   86 ++++++++++++++++++++++++++++--------------
 1 files changed, 57 insertions(+), 29 deletions(-)

diff --git a/yudao-module-mdm/src/main/java/cn/iocoder/yudao/module/mdm/service/item/MdmItemServiceImpl.java b/yudao-module-mdm/src/main/java/cn/iocoder/yudao/module/mdm/service/item/MdmItemServiceImpl.java
index e210590..11509cb 100644
--- a/yudao-module-mdm/src/main/java/cn/iocoder/yudao/module/mdm/service/item/MdmItemServiceImpl.java
+++ b/yudao-module-mdm/src/main/java/cn/iocoder/yudao/module/mdm/service/item/MdmItemServiceImpl.java
@@ -2,8 +2,10 @@
 
 import cn.hutool.core.collection.CollUtil;
 import cn.hutool.core.util.ObjUtil;
+import cn.iocoder.yudao.framework.common.pojo.CommonResult;
 import cn.iocoder.yudao.framework.common.pojo.PageResult;
 import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
+import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
 import cn.iocoder.yudao.module.mdm.controller.admin.item.vo.MdmItemPageReqVO;
 import cn.iocoder.yudao.module.mdm.controller.admin.item.vo.MdmItemSaveReqVO;
 import cn.iocoder.yudao.module.mdm.dal.dataobject.category.MdmItemCategoryDO;
@@ -15,8 +17,12 @@
 import cn.iocoder.yudao.module.mdm.service.category.MdmItemCategoryService;
 import cn.iocoder.yudao.module.mdm.service.unit.MdmUnitMeasureService;
 import cn.iocoder.yudao.module.mes.api.item.MesMdItemApi;
+import cn.iocoder.yudao.module.mes.api.item.MesMdItemTypeApi;
 import cn.iocoder.yudao.module.mes.api.item.dto.MesMdItemSyncReqDTO;
+import cn.iocoder.yudao.module.mes.api.item.dto.MesMdItemTypeRespDTO;
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 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;
@@ -32,7 +38,7 @@
 /**
  * MDM 鐗╂枡涓绘暟鎹� Service 瀹炵幇绫�
  *
- * @author 鑺嬮亾婧愮爜
+ * @author 瓒呯骇绠$悊鍛�
  */
 @Service
 @Validated
@@ -54,6 +60,10 @@
     @Resource
     private MdmItemBatchConfigMapper itemBatchConfigMapper;
 
+    @Resource
+    private MesMdItemTypeApi mesMdItemTypeApi;
+
+
     @Override
     @Transactional(rollbackFor = Exception.class)
     public Long createItem(MdmItemSaveReqVO createReqVO) {
@@ -67,10 +77,9 @@
         // 淇濆瓨鎵规閰嶇疆锛堝鏋滄湁锛�
         saveBatchConfig(item.getId(), createReqVO);
 
-        // 鍚屾鍒� MES锛堝嬀閫� syncMes 鏃讹級
-        if (Boolean.TRUE.equals(createReqVO.getSyncMes())) {
-            syncItemToMes(createReqVO);
-        }
+        // 濮嬬粓鍚屾鍒� MES
+        createReqVO.setId(item.getId());
+        syncItemToMes(createReqVO);
         return item.getId();
     }
 
@@ -89,10 +98,8 @@
         // 淇濆瓨鎵规閰嶇疆锛堝鏋滄湁锛�
         saveBatchConfig(updateReqVO.getId(), updateReqVO);
 
-        // 鍚屾鍒� MES锛堝嬀閫� syncMes 鏃讹級
-        if (Boolean.TRUE.equals(updateReqVO.getSyncMes())) {
-            syncItemToMes(updateReqVO);
-        }
+        // 濮嬬粓鍚屾鍒� MES
+        syncItemToMes(updateReqVO);
     }
 
     private void validateItemSaveData(MdmItemSaveReqVO reqVO) {
@@ -120,25 +127,13 @@
         // 瑙f瀽鍒嗙被 id -> code锛堜娇鐢� MDM 鏈湴鍒嗙被鏈嶅姟锛�
         String itemTypeCode = null;
         if (reqVO.getCategoryId() != null) {
-            MdmItemCategoryDO category = itemCategoryService.getItemCategory(reqVO.getCategoryId());
-            if (category != null) {
-                itemTypeCode = category.getCode();
-            }
-        } else if (reqVO.getItemType() != null) {
-            // 鏍规嵁 itemType 鏌ユ壘瀵瑰簲鍒嗙被缂栫爜
-            // itemType: 1鍘熸枡, 2鍗婃垚鍝�, 3鎴愬搧, 4杈呮枡
-            String itemTypeName = convertItemTypeToName(reqVO.getItemType());
-            List<MdmItemCategoryDO> categories = itemCategoryService.getItemCategoryList(
-                    itemCategoryService.getItemCategoryChildrenList(null).stream().map(MdmItemCategoryDO::getId).collect(Collectors.toSet()));
-            itemTypeCode = categories.stream()
-                    .filter(c -> c.getName() != null && c.getName().equals(itemTypeName))
-                    .findFirst()
-                    .map(MdmItemCategoryDO::getCode)
-                    .orElse(null);
+            CommonResult<MesMdItemTypeRespDTO> itemType = mesMdItemTypeApi.getItemType(reqVO.getCategoryId());
+            itemTypeCode = itemType.getData().getCode();
         }
         // 缁勮鍚屾 DTO
         MesMdItemSyncReqDTO syncReqDTO = new MesMdItemSyncReqDTO();
         syncReqDTO.setCode(reqVO.getCode());
+        syncReqDTO.setMdmItemId(reqVO.getId());
         syncReqDTO.setName(reqVO.getName());
         syncReqDTO.setSpecification(reqVO.getSpecification());
         syncReqDTO.setUnitCode(unitCode);
@@ -166,11 +161,14 @@
     }
 
     @Override
+    @Transactional(rollbackFor = Exception.class)
     public void updateItemStatus(Long id, Integer status) {
         // 鏍¢獙瀛樺湪
         validateItemExists(id);
         // 鏇存柊鐘舵��
         itemMapper.updateById(new MdmItemDO().setId(id).setStatus(status));
+        // 鍚屾鐘舵�佸埌 MES
+        mesMdItemApi.updateItemStatus(id, status);
     }
 
     @Override
@@ -178,13 +176,37 @@
     public void deleteItem(Long id) {
         // 鏍¢獙瀛樺湪
         MdmItemDO item = validateItemExists(id);
-        // 瑙e喅杞垹闄ゅ敮涓�閿啿绐侊細濡傛灉宸插瓨鍦ㄧ浉鍚� code 涓斿凡杞垹闄ょ殑璁板綍锛屽厛鐗╃悊鍒犻櫎瀹�
-//        MdmItemDO existingDeleted = itemMapper.selectByCodeAndDeleted(item.getCode(), true);
-//        if (existingDeleted != null && !existingDeleted.getId().equals(id)) {
-//            itemMapper.physicalDeleteById(existingDeleted.getId());
-//        }
+        // 鏍¢獙鐗╂枡鏄惁琚笟鍔″紩鐢�
+        validateItemNoReference(id);
         // 杞垹闄ゅ綋鍓嶈褰�
         itemMapper.deleteById(id);
+        // 鍚屾鍒犻櫎鍒� MES
+        mesMdItemApi.deleteItem(id);
+    }
+
+    /**
+     * 鏍¢獙鐗╂枡鏈涓氬姟寮曠敤锛堥攢鍞�侀噰璐�佺敓浜с�佽川妫�銆佸簱瀛樼瓑锛�
+     *
+     * @param id 鐗╂枡缂栧彿
+     */
+    private void validateItemNoReference(Long id) {
+        List<Map<String, Object>> references = itemMapper.selectItemReferenceCount(id);
+        if (CollUtil.isNotEmpty(references)) {
+            String refDesc = references.stream()
+                    .map(r -> r.get("source") + "(" + r.get("cnt") + ")")
+                    .collect(Collectors.joining("銆�"));
+            throw exception(MDM_ITEM_EXISTS_REFERENCE, refDesc);
+        }
+    }
+
+    @Override
+    @Transactional(rollbackFor = Exception.class)
+    public void deleteItemList(Collection<Long> ids) {
+        if (CollUtil.isEmpty(ids)) {
+            return;
+        }
+        // 閫愪釜鍒犻櫎锛堝鐢ㄥ崟鏉″垹闄ら�昏緫锛屼繚鎸佹牎楠岋級
+        ids.forEach(this::deleteItem);
     }
 
     @Override
@@ -310,6 +332,12 @@
         return itemMapper.selectByCode(code);
     }
 
+    @Override
+    public List<MdmItemDO> getItemSimpleList() {
+        return itemMapper.selectList(MdmItemDO::getStatus,
+                cn.iocoder.yudao.framework.common.enums.CommonStatusEnum.ENABLE.getStatus());
+    }
+
     /**
      * 淇濆瓨鎵规閰嶇疆锛堝埌 MDM 鏈湴琛級
      */

--
Gitblit v1.9.3