| | |
| | | package com.ruoyi.safe.service.impl; |
| | | |
| | | import com.ruoyi.common.utils.SecurityUtils; |
| | | import com.ruoyi.safe.pojo.SafeLineInspection; |
| | | import com.ruoyi.safe.pojo.SafeLineInspectionRecord; |
| | | import com.ruoyi.safe.mapper.SafeLineInspectionRecordMapper; |
| | | import com.ruoyi.safe.service.SafeLineInspectionRecordService; |
| | | import com.ruoyi.safe.service.SafeLineInspectionService; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.ruoyi.basic.dto.StorageBlobVO; |
| | | import com.ruoyi.basic.enums.ApplicationTypeEnum; |
| | | import com.ruoyi.basic.enums.RecordTypeEnum; |
| | | import com.ruoyi.basic.utils.FileUtil; |
| | | import com.ruoyi.safe.mapper.SafeLineInspectionRecordMapper; |
| | | import com.ruoyi.safe.pojo.SafeLineInspectionRecord; |
| | | import com.ruoyi.safe.service.SafeLineInspectionRecordService; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import java.time.LocalDateTime; |
| | | import java.util.Collections; |
| | | import java.util.List; |
| | | |
| | | /** |
| | |
| | | public class SafeLineInspectionRecordServiceImpl extends ServiceImpl<SafeLineInspectionRecordMapper, SafeLineInspectionRecord> implements SafeLineInspectionRecordService { |
| | | |
| | | @Autowired |
| | | private SafeLineInspectionService safeLineInspectionService; |
| | | private FileUtil fileUtil; |
| | | |
| | | @Override |
| | | public List<SafeLineInspectionRecord> listByInspectionId(Integer inspectionId) { |
| | | return this.lambdaQuery() |
| | | List<SafeLineInspectionRecord> records = this.lambdaQuery() |
| | | .eq(SafeLineInspectionRecord::getInspectionId, inspectionId) |
| | | .orderByDesc(SafeLineInspectionRecord::getCheckTime) |
| | | .list(); |
| | | fillAttachments(records); |
| | | return records; |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public boolean save(SafeLineInspectionRecord entity) { |
| | | // 保存巡检记录 |
| | | boolean result = super.save(entity); |
| | | |
| | | if (result && entity.getInspectionId() != null) { |
| | | // 更新巡检任务状态为"巡检中",并设置巡检人为当前登录用户 |
| | | updateInspectionStatus(entity.getInspectionId()); |
| | | } |
| | | |
| | | return result; |
| | | boolean saved = super.save(entity); |
| | | syncAttachments(saved, entity); |
| | | return saved; |
| | | } |
| | | |
| | | /** |
| | | * 更新巡检任务状态为"巡检中",并添加当前用户到巡检人列表 |
| | | */ |
| | | private void updateInspectionStatus(Integer inspectionId) { |
| | | SafeLineInspection inspection = safeLineInspectionService.getById(inspectionId); |
| | | if (inspection != null && "待巡检".equals(inspection.getStatus())) { |
| | | Long currentUserId = SecurityUtils.getUserId(); |
| | | String currentUserIdStr = String.valueOf(currentUserId); |
| | | @Override |
| | | public boolean updateById(SafeLineInspectionRecord entity) { |
| | | boolean updated = super.updateById(entity); |
| | | syncAttachments(updated, entity); |
| | | return updated; |
| | | } |
| | | |
| | | // 添加当前用户到巡检人列表(如果不存在) |
| | | String inspectorId = inspection.getInspectorId(); |
| | | if (inspectorId == null || inspectorId.isEmpty()) { |
| | | inspectorId = currentUserIdStr; |
| | | } else if (!inspectorId.contains(currentUserIdStr)) { |
| | | inspectorId = inspectorId + "," + currentUserIdStr; |
| | | } |
| | | |
| | | inspection.setStatus("巡检中"); |
| | | inspection.setInspectorId(inspectorId); |
| | | inspection.setUpdateTime(LocalDateTime.now()); |
| | | inspection.setUpdateUser(currentUserId.intValue()); |
| | | safeLineInspectionService.updateById(inspection); |
| | | private void syncAttachments(boolean success, SafeLineInspectionRecord entity) { |
| | | if (!success || entity == null || entity.getId() == null || entity.getStorageBlobDTOs() == null) { |
| | | return; |
| | | } |
| | | fileUtil.saveStorageAttachment( |
| | | ApplicationTypeEnum.IMAGE, |
| | | RecordTypeEnum.SAFE_LINE_INSPECTION_RECORD, |
| | | entity.getId().longValue(), |
| | | entity.getStorageBlobDTOs() |
| | | ); |
| | | } |
| | | |
| | | private void fillAttachments(List<SafeLineInspectionRecord> records) { |
| | | if (records == null || records.isEmpty()) { |
| | | return; |
| | | } |
| | | records.forEach(record -> { |
| | | if (record.getId() == null) { |
| | | return; |
| | | } |
| | | List<StorageBlobVO> attachments = fileUtil.getStorageBlobVOsByRecordTypeAndRecordId( |
| | | RecordTypeEnum.SAFE_LINE_INSPECTION_RECORD, |
| | | record.getId().longValue() |
| | | ); |
| | | record.setStorageBlobVOs(attachments == null ? Collections.emptyList() : attachments); |
| | | }); |
| | | } |
| | | } |