xiaoyi
6 天以前 05ab6e3f69a5e73624b2573db043f5923e8f7d8b
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);
    }
    /**
     * 点位的主数据引用:车间 + 责任人,从主数据带出名称落快照
     */
    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);