From fbc80648adf176fed54046c3aa52173b20e5d12e Mon Sep 17 00:00:00 2001
From: gaoluyang <2820782392@qq.com>
Date: 星期一, 12 十月 2026 14:57:32 +0800
Subject: [PATCH] 宁夏万通需求:商机状态组改为非必填;过程检验单生产订单、工位改为非必填
---
yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/dv/machinery/MesDvMachineryServiceImpl.java | 89 +++++++++++++++++++++++++++++++++++---------
1 files changed, 71 insertions(+), 18 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..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;
@@ -38,7 +39,7 @@
/**
* MES 璁惧鍙拌处 Service 瀹炵幇绫�
*
- * @author 鑺嬮亾婧愮爜
+ * @author 瓒呯骇绠$悊鍛�
*/
@Service
@Validated
@@ -53,6 +54,9 @@
@Resource
@Lazy
private MesMdWorkshopService workshopService;
+ @Resource
+ @Lazy
+ private cn.iocoder.yudao.module.mes.service.md.workstation.MesMdWorkstationService workstationService;
@Resource
private MesWmBarcodeService barcodeService;
@Resource
@@ -106,23 +110,51 @@
@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
@@ -201,7 +233,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 +242,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 +288,38 @@
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 (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 {
--
Gitblit v1.9.3