| | |
| | | |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | 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.mapper.SafeFacilityInspectionMapper; |
| | | import com.ruoyi.safe.service.SafeFacilityInspectionService; |
| | | import com.ruoyi.safe.service.SafeFacilityLedgerService; |
| | | 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.util.Collections; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | | * <p> |
| | |
| | | @Service |
| | | public class SafeFacilityInspectionServiceImpl extends ServiceImpl<SafeFacilityInspectionMapper, SafeFacilityInspection> implements SafeFacilityInspectionService { |
| | | |
| | | @Autowired |
| | | private SafeFacilityLedgerService safeFacilityLedgerService; |
| | | @Autowired |
| | | private SysUserMapper sysUserMapper; |
| | | |
| | | @Override |
| | | public SafeFacilityInspection getById(Serializable id) { |
| | | SafeFacilityInspection record = super.getById(id); |
| | | if (record != null) { |
| | | fillExtraInfo(Collections.singletonList(record)); |
| | | } |
| | | return record; |
| | | } |
| | | |
| | | @Override |
| | | public IPage<SafeFacilityInspection> pageSafeFacilityInspection(Page page, SafeFacilityInspection safeFacilityInspection) { |
| | | return this.lambdaQuery() |
| | | IPage<SafeFacilityInspection> result = this.lambdaQuery() |
| | | .like(safeFacilityInspection.getInspectionCode() != null, SafeFacilityInspection::getInspectionCode, safeFacilityInspection.getInspectionCode()) |
| | | .eq(safeFacilityInspection.getFacilityId() != null, SafeFacilityInspection::getFacilityId, safeFacilityInspection.getFacilityId()) |
| | | .eq(safeFacilityInspection.getStatus() != null, SafeFacilityInspection::getStatus, safeFacilityInspection.getStatus()) |
| | | .orderByDesc(SafeFacilityInspection::getCreateTime) |
| | | .page(page); |
| | | |
| | | fillExtraInfo(result.getRecords()); |
| | | return result; |
| | | } |
| | | |
| | | private void fillExtraInfo(List<SafeFacilityInspection> records) { |
| | | if (records == null || records.isEmpty()) { |
| | | return; |
| | | } |
| | | |
| | | // 收集所有设施ID |
| | | List<Integer> facilityIds = records.stream() |
| | | .map(SafeFacilityInspection::getFacilityId) |
| | | .filter(id -> id != null) |
| | | .distinct() |
| | | .collect(Collectors.toList()); |
| | | |
| | | // 收集所有巡检人ID |
| | | List<Long> inspectorIds = records.stream() |
| | | .map(SafeFacilityInspection::getInspectorId) |
| | | .filter(id -> id != null) |
| | | .map(Integer::longValue) |
| | | .distinct() |
| | | .collect(Collectors.toList()); |
| | | |
| | | // 批量查询设施信息 |
| | | Map<Integer, SafeFacilityLedger> facilityMap = Map.of(); |
| | | if (!facilityIds.isEmpty()) { |
| | | facilityMap = safeFacilityLedgerService.listByIds(facilityIds).stream() |
| | | .collect(Collectors.toMap(SafeFacilityLedger::getId, f -> f, (v1, v2) -> v1)); |
| | | } |
| | | |
| | | // 批量查询巡检人信息 |
| | | Map<Long, String> userMap = Map.of(); |
| | | if (!inspectorIds.isEmpty()) { |
| | | List<SysUser> users = sysUserMapper.selectUserByIds(inspectorIds); |
| | | userMap = users.stream() |
| | | .collect(Collectors.toMap(SysUser::getUserId, SysUser::getNickName, (v1, v2) -> v1)); |
| | | } |
| | | |
| | | // 填充字段 |
| | | for (SafeFacilityInspection record : records) { |
| | | if (record.getFacilityId() != null) { |
| | | SafeFacilityLedger facility = facilityMap.get(record.getFacilityId()); |
| | | if (facility != null) { |
| | | record.setFacilityName(facility.getFacilityName()); |
| | | record.setFacilityCode(facility.getFacilityCode()); |
| | | } |
| | | } |
| | | if (record.getInspectorId() != null) { |
| | | record.setInspectorName(userMap.getOrDefault(record.getInspectorId().longValue(), "未知用户")); |
| | | } |
| | | } |
| | | } |
| | | } |