From d6ffbf2958eefb57fb36acc12709fe42f7bce556 Mon Sep 17 00:00:00 2001
From: gaoluyang <2820782392@qq.com>
Date: 星期五, 09 十月 2026 14:51:13 +0800
Subject: [PATCH] fix: HRM 删除员工级联删除关联系统用户;MES 首页统计 summary 兼容设备状态为空
---
yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/dv/machinery/MesDvMachineryServiceImpl.java | 57 +++++++++++++++++++++++++++++++++++++++++++--------------
1 files changed, 43 insertions(+), 14 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..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
@@ -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