From 416558785276159b8730b2826e71995fc16b59a7 Mon Sep 17 00:00:00 2001
From: xiaoyi <908147524@qq.com>
Date: 星期四, 29 十月 2026 11:47:44 +0800
Subject: [PATCH] refactor(safety): 人员与车间字段全面改为主数据关联
---
yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/safety/SafetyInspectionService.java | 63 +++++++++++++++++++++++++++++++
1 files changed, 62 insertions(+), 1 deletions(-)
diff --git a/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/safety/SafetyInspectionService.java b/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/safety/SafetyInspectionService.java
index fb1bb45..aa4df41 100644
--- a/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/safety/SafetyInspectionService.java
+++ b/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/safety/SafetyInspectionService.java
@@ -1,5 +1,6 @@
package cn.iocoder.yudao.module.mes.service.safety;
+import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.StrUtil;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
@@ -35,6 +36,8 @@
private SafetyInspectionPointMapper pointMapper;
@Resource
private SafetyInspectionMapper inspectionMapper;
+ @Resource
+ private SafetyRefResolver refResolver;
// ==================== 宸℃鐐逛綅 ====================
@@ -48,6 +51,7 @@
point.setCode(code);
point.setName(StrUtil.trim(reqVO.getName()));
point.setInspectCycle(StrUtil.blankToDefault(reqVO.getInspectCycle(), SafetyInspectCycleEnum.DAILY.getCycle()));
+ applyPointRefs(point, reqVO.getWorkshopId(), reqVO.getOwnerId());
pointMapper.insert(point);
return point.getId();
}
@@ -62,6 +66,7 @@
SafetyInspectionPointDO point = BeanUtils.toBean(reqVO, SafetyInspectionPointDO.class);
point.setCode(code);
point.setName(StrUtil.trim(reqVO.getName()));
+ applyPointRefs(point, reqVO.getWorkshopId(), reqVO.getOwnerId());
pointMapper.updateById(point);
}
@@ -83,6 +88,45 @@
*/
public List<SafetyInspectionPointDO> getEnabledPointList() {
return pointMapper.selectListByStatus(0);
+ }
+
+ /**
+ * 鐐逛綅鐨勪富鏁版嵁寮曠敤锛氳溅闂� + 璐d换浜猴紝浠庝富鏁版嵁甯﹀嚭鍚嶇О钀藉揩鐓�
+ */
+ private void applyPointRefs(SafetyInspectionPointDO point, Long workshopId, Long ownerId) {
+ point.setWorkshopId(workshopId);
+ if (workshopId == null) {
+ point.setWorkshopName("");
+ } else {
+ point.setWorkshopName(refResolver.requireWorkshop(workshopId).getName());
+ }
+ point.setOwnerId(ownerId);
+ if (ownerId == null) {
+ point.setOwnerName("");
+ } else {
+ point.setOwnerName(refResolver.requireEmployee(ownerId, SAFETY_EMPLOYEE_REQUIRED).getName());
+ }
+ }
+
+ /**
+ * 鎵归噺鍥炲~鐐逛綅鐨勮溅闂村悕涓庤矗浠讳汉濮撳悕锛堢敤涓绘暟鎹渶鏂板�艰鐩栧揩鐓э級
+ */
+ public void fillPointRefs(List<SafetyInspectionPointDO> points) {
+ if (CollUtil.isEmpty(points)) {
+ return;
+ }
+ var workshopMap = refResolver.workshopMap(points.stream().map(SafetyInspectionPointDO::getWorkshopId).toList());
+ var employeeMap = refResolver.employeeMap(points.stream().map(SafetyInspectionPointDO::getOwnerId).toList());
+ points.forEach(point -> {
+ var workshop = workshopMap.get(point.getWorkshopId());
+ if (workshop != null) {
+ point.setWorkshopName(workshop.getName());
+ }
+ var employee = employeeMap.get(point.getOwnerId());
+ if (employee != null) {
+ point.setOwnerName(employee.getName());
+ }
+ });
}
public static void fillPointDisplay(SafetyInspectionPointDO point, SafetyInspectionPointRespVO respVO) {
@@ -129,7 +173,8 @@
inspection.setPointId(point.getId());
inspection.setPointName(point.getName());
inspection.setPointType(point.getPointType());
- inspection.setInspector(StrUtil.trim(reqVO.getInspector()));
+ inspection.setInspectorId(reqVO.getInspectorId());
+ inspection.setInspector(refResolver.requireEmployee(reqVO.getInspectorId(), SAFETY_EMPLOYEE_REQUIRED).getName());
inspection.setResult(StrUtil.blankToDefault(reqVO.getResult(), "NORMAL"));
inspection.setInspectTime(reqVO.getInspectTime() == null ? LocalDateTime.now() : reqVO.getInspectTime());
inspection.setHazardCount(reqVO.getHazardCount() == null ? 0 : reqVO.getHazardCount());
@@ -137,6 +182,22 @@
return inspection;
}
+ /**
+ * 鎵归噺鍥炲~宸℃浜烘渶鏂板鍚�
+ */
+ public void fillInspectorNames(List<SafetyInspectionDO> records) {
+ if (CollUtil.isEmpty(records)) {
+ return;
+ }
+ var employeeMap = refResolver.employeeMap(records.stream().map(SafetyInspectionDO::getInspectorId).toList());
+ records.forEach(record -> {
+ var employee = employeeMap.get(record.getInspectorId());
+ if (employee != null) {
+ record.setInspector(employee.getName());
+ }
+ });
+ }
+
/** 鏈�杩戜竴娆″贰妫�鏃堕棿锛堢敤浜庣偣浣嶅垪琛ㄥ睍绀猴級 */
public LocalDateTime getLastInspectTime(Long pointId) {
SafetyInspectionDO latest = inspectionMapper.selectLatestByPointId(pointId);
--
Gitblit v1.9.3