| | |
| | | |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.ruoyi.basic.dto.StorageBlobVO; |
| | | import com.ruoyi.basic.enums.RecordTypeEnum; |
| | | import com.ruoyi.basic.utils.FileUtil; |
| | | import com.ruoyi.common.utils.SecurityUtils; |
| | | import com.ruoyi.project.system.domain.SysUser; |
| | | import com.ruoyi.project.system.mapper.SysUserMapper; |
| | | import com.ruoyi.safe.pojo.SafeFacilityInspection; |
| | | import com.ruoyi.safe.pojo.SafeFacilityLedger; |
| | | import com.ruoyi.safe.pojo.SafeFacilityRectification; |
| | | import com.ruoyi.safe.mapper.SafeFacilityRectificationMapper; |
| | | import com.ruoyi.safe.service.SafeFacilityInspectionService; |
| | | import com.ruoyi.safe.service.SafeFacilityLedgerService; |
| | | import com.ruoyi.safe.service.SafeFacilityRectificationService; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import java.io.Serializable; |
| | | import java.time.LocalDateTime; |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | | * <p> |
| | |
| | | @Service |
| | | public class SafeFacilityRectificationServiceImpl extends ServiceImpl<SafeFacilityRectificationMapper, SafeFacilityRectification> implements SafeFacilityRectificationService { |
| | | |
| | | @Autowired |
| | | private SafeFacilityLedgerService safeFacilityLedgerService; |
| | | @Autowired |
| | | private SafeFacilityInspectionService safeFacilityInspectionService; |
| | | @Autowired |
| | | private SysUserMapper sysUserMapper; |
| | | @Autowired |
| | | private FileUtil fileUtil; |
| | | |
| | | @Override |
| | | public SafeFacilityRectification getById(Serializable id) { |
| | | SafeFacilityRectification record = super.getById(id); |
| | | if (record != null) { |
| | | fillExtraInfo(Collections.singletonList(record)); |
| | | } |
| | | return record; |
| | | } |
| | | |
| | | @Override |
| | | public IPage<SafeFacilityRectification> pageSafeFacilityRectification(Page page, SafeFacilityRectification safeFacilityRectification) { |
| | | return this.lambdaQuery() |
| | | IPage<SafeFacilityRectification> result = this.lambdaQuery() |
| | | .eq(safeFacilityRectification.getInspectionId() != null, SafeFacilityRectification::getInspectionId, safeFacilityRectification.getInspectionId()) |
| | | .eq(safeFacilityRectification.getFacilityId() != null, SafeFacilityRectification::getFacilityId, safeFacilityRectification.getFacilityId()) |
| | | .eq(safeFacilityRectification.getStatus() != null, SafeFacilityRectification::getStatus, safeFacilityRectification.getStatus()) |
| | | .orderByDesc(SafeFacilityRectification::getCreateTime) |
| | | .page(page); |
| | | |
| | | fillExtraInfo(result.getRecords()); |
| | | return result; |
| | | } |
| | | |
| | | private void fillExtraInfo(List<SafeFacilityRectification> records) { |
| | | if (records == null || records.isEmpty()) { |
| | | return; |
| | | } |
| | | |
| | | List<Integer> inspectionIds = records.stream() |
| | | .map(SafeFacilityRectification::getInspectionId) |
| | | .filter(Objects::nonNull) |
| | | .distinct() |
| | | .collect(Collectors.toList()); |
| | | |
| | | Map<Integer, SafeFacilityInspection> inspectionMap = inspectionIds.isEmpty() ? Collections.emptyMap() |
| | | : safeFacilityInspectionService.listByIds(inspectionIds).stream() |
| | | .collect(Collectors.toMap(SafeFacilityInspection::getId, inspection -> inspection, (v1, v2) -> v1)); |
| | | |
| | | // 收集设施ID |
| | | Set<Integer> facilityIdSet = records.stream() |
| | | .map(SafeFacilityRectification::getFacilityId) |
| | | .filter(Objects::nonNull) |
| | | .collect(Collectors.toSet()); |
| | | inspectionMap.values().stream() |
| | | .map(SafeFacilityInspection::getFacilityId) |
| | | .filter(Objects::nonNull) |
| | | .forEach(facilityIdSet::add); |
| | | List<Integer> facilityIds = new ArrayList<>(facilityIdSet); |
| | | |
| | | // 收集所有用户ID(整改责任人 + 验收人) |
| | | Set<Long> userIds = new HashSet<>(); |
| | | records.stream().map(SafeFacilityRectification::getRectifyUserId).filter(Objects::nonNull).forEach(id -> userIds.add(id.longValue())); |
| | | records.stream().map(SafeFacilityRectification::getVerifyUserId).filter(Objects::nonNull).forEach(id -> userIds.add(id.longValue())); |
| | | |
| | | // 批量查询设施信息 |
| | | Map<Integer, SafeFacilityLedger> facilityMap = facilityIds.isEmpty() ? Collections.emptyMap() |
| | | : safeFacilityLedgerService.listByIds(facilityIds).stream() |
| | | .collect(Collectors.toMap(SafeFacilityLedger::getId, f -> f, (v1, v2) -> v1)); |
| | | |
| | | // 批量查询用户信息 |
| | | Map<Long, String> userMap = userIds.isEmpty() ? Collections.emptyMap() |
| | | : sysUserMapper.selectUserByIds(new ArrayList<>(userIds)).stream() |
| | | .collect(Collectors.toMap(SysUser::getUserId, SysUser::getNickName, (v1, v2) -> v1)); |
| | | |
| | | for (SafeFacilityRectification record : records) { |
| | | SafeFacilityInspection inspection = record.getInspectionId() == null ? null : inspectionMap.get(record.getInspectionId()); |
| | | if (inspection != null) { |
| | | record.setInspectionCode(inspection.getInspectionCode()); |
| | | if (record.getFacilityId() == null) { |
| | | record.setFacilityId(inspection.getFacilityId()); |
| | | } |
| | | List<StorageBlobVO> attachments = fileUtil.getStorageBlobVOsByRecordTypeAndRecordId( |
| | | RecordTypeEnum.SAFE_FACILITY_INSPECTION, |
| | | inspection.getId().longValue() |
| | | ); |
| | | record.setStorageBlobVOs(attachments == null ? Collections.emptyList() : attachments); |
| | | } |
| | | if (record.getFacilityId() != null) { |
| | | SafeFacilityLedger facility = facilityMap.get(record.getFacilityId()); |
| | | if (facility != null) { |
| | | record.setFacilityName(facility.getFacilityName()); |
| | | record.setFacilityCode(facility.getFacilityCode()); |
| | | } |
| | | } |
| | | if (record.getRectifyUserId() != null) { |
| | | record.setRectifyUserName(userMap.getOrDefault(record.getRectifyUserId().longValue(), "未知用户")); |
| | | } |
| | | if (record.getVerifyUserId() != null) { |
| | | record.setVerifyUserName(userMap.getOrDefault(record.getVerifyUserId().longValue(), "未知用户")); |
| | | } |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public boolean save(SafeFacilityRectification entity) { |
| | | Long currentUserId = SecurityUtils.getUserId(); |
| | | if (entity.getRectifyUserId() == null) { |
| | | entity.setRectifyUserId(currentUserId.intValue()); |
| | | } |
| | | if (entity.getStatus() == null) { |
| | | entity.setStatus("待整改"); |
| | | } |
| | | return super.save(entity); |
| | | } |
| | | |
| | | @Override |
| | | public boolean updateById(SafeFacilityRectification entity) { |
| | | Long currentUserId = SecurityUtils.getUserId(); |
| | | if ("已整改".equals(entity.getStatus()) && entity.getActualTime() == null) { |
| | | entity.setActualTime(LocalDateTime.now()); |
| | | } |
| | | if ("已验收".equals(entity.getStatus())) { |
| | | if (entity.getVerifyUserId() == null) { |
| | | entity.setVerifyUserId(currentUserId.intValue()); |
| | | } |
| | | entity.setVerifyTime(LocalDateTime.now()); |
| | | } |
| | | return super.updateById(entity); |
| | | } |
| | | } |