From e10c196ff7348a4461e8facee10a208779244ece Mon Sep 17 00:00:00 2001
From: 吴羡 <16976746+Xian-TT3@user.noreply.gitee.com>
Date: 星期三, 30 九月 2026 15:33:30 +0800
Subject: [PATCH] 宁夏万通需求:出库单行支持主/辅单位录入;考勤节假日配置改为时间段;物料型号维护;设备批量删除;来料检验默认方案解析

---
 yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/dv/machinery/MesDvMachineryServiceImpl.java |   55 ++++++++++++++++++++++++++++++++++++++++++-------------
 1 files changed, 42 insertions(+), 13 deletions(-)

diff --git a/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/dv/machinery/MesDvMachineryServiceImpl.java b/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/dv/machinery/MesDvMachineryServiceImpl.java
index 35ded24..792b4be 100644
--- a/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/dv/machinery/MesDvMachineryServiceImpl.java
+++ b/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/dv/machinery/MesDvMachineryServiceImpl.java
@@ -4,6 +4,7 @@
 import cn.hutool.core.util.ObjUtil;
 import cn.hutool.core.util.StrUtil;
 import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum;
+import cn.iocoder.yudao.framework.common.exception.ServiceException;
 import cn.iocoder.yudao.framework.common.pojo.PageResult;
 import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
 import cn.iocoder.yudao.module.mes.controller.admin.dv.machinery.vo.MesDvMachineryImportExcelVO;
@@ -109,26 +110,54 @@
     @Override
     public void deleteMachinery(Long id) {
         // 鏍¢獙瀛樺湪
-        validateMachineryExists(id);
+        MesDvMachineryDO machinery = machineryMapper.selectById(id);
+        if (machinery == null) {
+            throw exception(DV_MACHINERY_NOT_EXISTS);
+        }
         // 鏍¢獙鍏宠仈鏁版嵁
-        if (checkPlanMachineryService.getCheckPlanMachineryCountByMachineryId(id) > 0) {
-            throw exception(DV_MACHINERY_HAS_CHECK_PLAN);
-        }
-        if (checkRecordService.getCheckRecordCountByMachineryId(id) > 0) {
-            throw exception(DV_MACHINERY_HAS_CHECK_RECORD);
-        }
-        if (maintenRecordService.getMaintenRecordCountByMachineryId(id) > 0) {
-            throw exception(DV_MACHINERY_HAS_MAINTEN_RECORD);
-        }
-        if (repairService.getRepairCountByMachineryId(id) > 0) {
-            throw exception(DV_MACHINERY_HAS_REPAIR);
-        }
+        validateMachineryDeletable(machinery);
 
         // 鍒犻櫎
         machineryMapper.deleteById(id);
     }
 
     @Override
+    @Transactional(rollbackFor = Exception.class)
+    public void deleteMachineryList(Collection<Long> ids) {
+        if (CollUtil.isEmpty(ids)) {
+            return;
+        }
+        // 閫愪釜鍒犻櫎锛堝鐢ㄥ崟鏉″垹闄ら�昏緫锛屼繚鎸佹牎楠岋級锛屼换涓�澶辫触鍒欐暣浣撳洖婊�
+        ids.forEach(this::deleteMachinery);
+    }
+
+    /**
+     * 鏍¢獙璁惧鏄惁鍙垹闄わ紙鍏宠仈鐐规璁″垝/鐐规璁板綍/淇濆吇璁板綍/缁翠慨璁板綍浠讳竴瀛樺湪鍒欎笉鍏佽锛�
+     *
+     * @param machinery 璁惧
+     */
+    private void validateMachineryDeletable(MesDvMachineryDO machinery) {
+        Long id = machinery.getId();
+        String label = StrUtil.format("{}锛坽}锛�", machinery.getName(), machinery.getCode());
+        if (checkPlanMachineryService.getCheckPlanMachineryCountByMachineryId(id) > 0) {
+            throw new ServiceException(DV_MACHINERY_HAS_CHECK_PLAN.getCode(),
+                    StrUtil.format("璁惧{}宸插叧鑱旂偣妫�璁″垝锛屾棤娉曞垹闄わ紱璇峰厛鍦ㄧ偣妫�璁″垝涓Щ闄よ璁惧鍚庨噸璇�", label));
+        }
+        if (checkRecordService.getCheckRecordCountByMachineryId(id) > 0) {
+            throw new ServiceException(DV_MACHINERY_HAS_CHECK_RECORD.getCode(),
+                    StrUtil.format("璁惧{}宸插瓨鍦ㄧ偣妫�璁板綍锛屾棤娉曞垹闄わ紱濡傞渶鍒犻櫎璇峰厛澶勭悊璇ヨ澶囩殑鐐规璁板綍", label));
+        }
+        if (maintenRecordService.getMaintenRecordCountByMachineryId(id) > 0) {
+            throw new ServiceException(DV_MACHINERY_HAS_MAINTEN_RECORD.getCode(),
+                    StrUtil.format("璁惧{}宸插瓨鍦ㄤ繚鍏昏褰曪紝鏃犳硶鍒犻櫎锛涘闇�鍒犻櫎璇峰厛澶勭悊璇ヨ澶囩殑淇濆吇璁板綍", label));
+        }
+        if (repairService.getRepairCountByMachineryId(id) > 0) {
+            throw new ServiceException(DV_MACHINERY_HAS_REPAIR.getCode(),
+                    StrUtil.format("璁惧{}宸插瓨鍦ㄧ淮淇褰曪紝鏃犳硶鍒犻櫎锛涘闇�鍒犻櫎璇峰厛澶勭悊璇ヨ澶囩殑缁翠慨璁板綍", label));
+        }
+    }
+
+    @Override
     public void validateMachineryExists(Long id) {
         if (machineryMapper.selectById(id) == null) {
             throw exception(DV_MACHINERY_NOT_EXISTS);

--
Gitblit v1.9.3