| | |
| | | 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; |
| | |
| | | private SafetyInspectionPointMapper pointMapper; |
| | | @Resource |
| | | private SafetyInspectionMapper inspectionMapper; |
| | | @Resource |
| | | private SafetyRefResolver refResolver; |
| | | |
| | | // ==================== 巡检点位 ==================== |
| | | |
| | |
| | | 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(); |
| | | } |
| | |
| | | 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); |
| | | } |
| | | |
| | |
| | | */ |
| | | 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) { |
| | |
| | | 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()); |
| | |
| | | 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); |