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 | 67 +++++++++++++++++++++++++++++++--
1 files changed, 62 insertions(+), 5 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 9e74cf6..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
@@ -53,6 +56,9 @@
@Resource
@Lazy
private MesMdWorkshopService workshopService;
+ @Resource
+ @Lazy
+ private cn.iocoder.yudao.module.mes.service.md.workstation.MesMdWorkstationService workstationService;
@Resource
private MesWmBarcodeService barcodeService;
@Resource
@@ -76,6 +82,8 @@
workshopService.getWorkshop(createReqVO.getWorkshopId());
// 鏍¢獙缂栫爜鍞竴
validateMachineryCodeUnique(null, createReqVO.getCode());
+ // 鏍¢獙鏁伴噰璁惧缂栧彿鍞竴
+ validateCollectDeviceCodeUnique(null, createReqVO.getCollectDeviceCode());
// 鎻掑叆
MesDvMachineryDO machinery = BeanUtils.toBean(createReqVO, MesDvMachineryDO.class);
@@ -97,6 +105,8 @@
workshopService.getWorkshop(updateReqVO.getWorkshopId());
// 鏍¢獙缂栫爜鍞竴
validateMachineryCodeUnique(updateReqVO.getId(), updateReqVO.getCode());
+ // 鏍¢獙鏁伴噰璁惧缂栧彿鍞竴
+ validateCollectDeviceCodeUnique(updateReqVO.getId(), updateReqVO.getCollectDeviceCode());
// 鏇存柊
MesDvMachineryDO updateObj = BeanUtils.toBean(updateReqVO, MesDvMachineryDO.class);
@@ -142,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);
}
}
@@ -194,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. 鍙傛暟鏍¢獙
@@ -201,7 +226,7 @@
throw exception(DV_MACHINERY_IMPORT_LIST_IS_EMPTY);
}
- // 2. 鎵归噺鍔犺浇璁惧绫诲瀷鍜岃溅闂达紝鏋勫缓缂栫爜鍒板疄浣撶殑鏄犲皠
+ // 2. 鎵归噺鍔犺浇璁惧绫诲瀷銆佽溅闂村拰宸ヤ綔绔欙紝鏋勫缓缂栫爜鍒板疄浣撶殑鏄犲皠
List<MesDvMachineryTypeDO> allTypes = machineryTypeService.getMachineryTypeList(
new cn.iocoder.yudao.module.mes.controller.admin.dv.machinery.vo.type.MesDvMachineryTypeListReqVO());
Map<String, MesDvMachineryTypeDO> typeCodeMap = allTypes.stream()
@@ -210,6 +235,13 @@
cn.iocoder.yudao.framework.common.enums.CommonStatusEnum.ENABLE.getStatus());
Map<String, MesMdWorkshopDO> workshopCodeMap = allWorkshops.stream()
.collect(Collectors.toMap(MesMdWorkshopDO::getCode, w -> w, (a, b) -> a));
+ List<cn.iocoder.yudao.module.mes.dal.dataobject.md.workstation.MesMdWorkstationDO> allWorkstations =
+ workstationService.getWorkstationListByStatus(
+ cn.iocoder.yudao.framework.common.enums.CommonStatusEnum.ENABLE.getStatus());
+ Map<String, cn.iocoder.yudao.module.mes.dal.dataobject.md.workstation.MesMdWorkstationDO> workstationCodeMap =
+ allWorkstations.stream().collect(Collectors.toMap(
+ cn.iocoder.yudao.module.mes.dal.dataobject.md.workstation.MesMdWorkstationDO::getCode,
+ w -> w, (a, b) -> a));
// 3. 閬嶅巻锛岄�愪釜鍒涘缓 or 鏇存柊
MesDvMachineryImportRespVO respVO = MesDvMachineryImportRespVO.builder()
@@ -249,24 +281,47 @@
return;
}
- // 3.4 鍒ゆ柇锛氬垱寤� or 鏇存柊
+ // 3.4 鏍¢獙宸ヤ綔绔欑紪鐮侊紙鍙�夛級
+ Long workstationId = null;
+ if (StrUtil.isNotBlank(importItem.getWorkstationCode())) {
+ cn.iocoder.yudao.module.mes.dal.dataobject.md.workstation.MesMdWorkstationDO workstation =
+ workstationCodeMap.get(importItem.getWorkstationCode());
+ if (workstation == null) {
+ respVO.getFailureCodes().put(key, "宸ヤ綔绔欑紪鐮乕" + importItem.getWorkstationCode() + "]涓嶅瓨鍦�");
+ return;
+ }
+ workstationId = workstation.getId();
+ }
+
+ // 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.4.1 鍒涘缓
+ // 3.5.1 鍒涘缓
MesDvMachineryDO machinery = BeanUtils.toBean(importItem, MesDvMachineryDO.class);
machinery.setMachineryTypeId(machineryType.getId());
machinery.setWorkshopId(workshop.getId());
+ machinery.setWorkstationId(workstationId);
machineryMapper.insert(machinery);
// 鑷姩鐢熸垚鏉$爜
barcodeService.autoGenerateBarcode(BarcodeBizTypeEnum.MACHINERY.getValue(),
machinery.getId(), machinery.getCode(), machinery.getName());
respVO.getCreateCodes().add(importItem.getCode());
} else if (updateSupport) {
- // 3.4.2 鏇存柊
+ // 3.5.2 鏇存柊
MesDvMachineryDO updateObj = BeanUtils.toBean(importItem, MesDvMachineryDO.class);
updateObj.setId(existMachinery.getId());
updateObj.setMachineryTypeId(machineryType.getId());
updateObj.setWorkshopId(workshop.getId());
+ updateObj.setWorkstationId(workstationId);
machineryMapper.updateById(updateObj);
respVO.getUpdateCodes().add(importItem.getCode());
} else {
@@ -274,6 +329,8 @@
respVO.getFailureCodes().put(key, "璁惧缂栫爜宸插瓨鍦�");
}
});
+ // 璁板綍瀵煎叆缁撴灉姹囨�伙紝渚� @LogRecord 鐨� success 鏂囨寮曠敤
+ OperateLogUtils.putImportSummary(respVO.getCreateCodes(), respVO.getUpdateCodes(), respVO.getFailureCodes());
return respVO;
}
--
Gitblit v1.9.3