From 05ab6e3f69a5e73624b2573db043f5923e8f7d8b Mon Sep 17 00:00:00 2001
From: xiaoyi <908147524@qq.com>
Date: 星期四, 05 十一月 2026 14:17:19 +0800
Subject: [PATCH] fix 修复bug

---
 yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/dv/machinery/MesDvMachineryServiceImpl.java |   35 ++++++++++++++++++++++++++++++++++-
 1 files changed, 34 insertions(+), 1 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 2325b04..52f1094 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
@@ -6,6 +6,7 @@
 import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum;
 import cn.iocoder.yudao.framework.common.pojo.PageResult;
 import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
+import cn.iocoder.yudao.framework.operatelog.core.util.OperateLogUtils;
 import cn.iocoder.yudao.module.mes.controller.admin.dv.machinery.vo.MesDvMachineryImportExcelVO;
 import cn.iocoder.yudao.module.mes.controller.admin.dv.machinery.vo.MesDvMachineryImportRespVO;
 import cn.iocoder.yudao.module.mes.controller.admin.dv.machinery.vo.MesDvMachineryPageReqVO;
@@ -21,6 +22,7 @@
 import cn.iocoder.yudao.module.mes.service.dv.repair.MesDvRepairService;
 import cn.iocoder.yudao.module.mes.service.md.workstation.MesMdWorkshopService;
 import cn.iocoder.yudao.module.mes.service.wm.barcode.MesWmBarcodeService;
+import com.mzt.logapi.starter.annotation.LogRecord;
 import jakarta.annotation.Resource;
 import org.springframework.context.annotation.Lazy;
 import org.springframework.stereotype.Service;
@@ -34,11 +36,12 @@
 
 import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
 import static cn.iocoder.yudao.module.mes.enums.ErrorCodeConstants.*;
+import static cn.iocoder.yudao.module.mes.enums.LogRecordConstants.*;
 
 /**
  * MES 璁惧鍙拌处 Service 瀹炵幇绫�
  *
- * @author 鑺嬮亾婧愮爜
+ * @author 瓒呯骇绠$悊鍛�
  */
 @Service
 @Validated
@@ -79,6 +82,8 @@
         workshopService.getWorkshop(createReqVO.getWorkshopId());
         // 鏍¢獙缂栫爜鍞竴
         validateMachineryCodeUnique(null, createReqVO.getCode());
+        // 鏍¢獙鏁伴噰璁惧缂栧彿鍞竴
+        validateCollectDeviceCodeUnique(null, createReqVO.getCollectDeviceCode());
 
         // 鎻掑叆
         MesDvMachineryDO machinery = BeanUtils.toBean(createReqVO, MesDvMachineryDO.class);
@@ -100,6 +105,8 @@
         workshopService.getWorkshop(updateReqVO.getWorkshopId());
         // 鏍¢獙缂栫爜鍞竴
         validateMachineryCodeUnique(updateReqVO.getId(), updateReqVO.getCode());
+        // 鏍¢獙鏁伴噰璁惧缂栧彿鍞竴
+        validateCollectDeviceCodeUnique(updateReqVO.getId(), updateReqVO.getCollectDeviceCode());
 
         // 鏇存柊
         MesDvMachineryDO updateObj = BeanUtils.toBean(updateReqVO, MesDvMachineryDO.class);
@@ -145,6 +152,19 @@
         }
         if (ObjUtil.notEqual(machinery.getId(), id)) {
             throw exception(DV_MACHINERY_CODE_DUPLICATE);
+        }
+    }
+
+    private void validateCollectDeviceCodeUnique(Long id, String collectDeviceCode) {
+        if (StrUtil.isBlank(collectDeviceCode)) {
+            return;
+        }
+        MesDvMachineryDO machinery = machineryMapper.selectByCollectDeviceCode(collectDeviceCode);
+        if (machinery == null) {
+            return;
+        }
+        if (ObjUtil.notEqual(machinery.getId(), id)) {
+            throw exception(DV_MACHINERY_COLLECT_CODE_DUPLICATE);
         }
     }
 
@@ -197,6 +217,8 @@
 
     @Override
     @Transactional(rollbackFor = Exception.class)
+    @LogRecord(type = MES_DV_MACHINERY_TYPE, subType = MES_DV_MACHINERY_IMPORT_SUB_TYPE, bizNo = "0",
+            success = MES_DV_MACHINERY_IMPORT_SUCCESS)
     public MesDvMachineryImportRespVO importMachineryList(List<MesDvMachineryImportExcelVO> importMachineryList,
                                                           boolean updateSupport) {
         // 1. 鍙傛暟鏍¢獙
@@ -273,6 +295,15 @@
 
             // 3.5 鍒ゆ柇锛氬垱寤� or 鏇存柊
             MesDvMachineryDO existMachinery = machineryMapper.selectByCode(importItem.getCode());
+            if (StrUtil.isNotBlank(importItem.getCollectDeviceCode())) {
+                MesDvMachineryDO collectOwner = machineryMapper.selectByCollectDeviceCode(importItem.getCollectDeviceCode());
+                if (collectOwner != null && (existMachinery == null
+                        || ObjUtil.notEqual(collectOwner.getId(), existMachinery.getId()))) {
+                    respVO.getFailureCodes().put(key, "鏁伴噰璁惧缂栧彿[" + importItem.getCollectDeviceCode() + "]宸茶璁惧["
+                            + collectOwner.getCode() + "]鍗犵敤");
+                    return;
+                }
+            }
             if (existMachinery == null) {
                 // 3.5.1 鍒涘缓
                 MesDvMachineryDO machinery = BeanUtils.toBean(importItem, MesDvMachineryDO.class);
@@ -298,6 +329,8 @@
                 respVO.getFailureCodes().put(key, "璁惧缂栫爜宸插瓨鍦�");
             }
         });
+        // 璁板綍瀵煎叆缁撴灉姹囨�伙紝渚� @LogRecord 鐨� success 鏂囨寮曠敤
+        OperateLogUtils.putImportSummary(respVO.getCreateCodes(), respVO.getUpdateCodes(), respVO.getFailureCodes());
         return respVO;
     }
 

--
Gitblit v1.9.3