| | |
| | | |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | 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.SafeFacilityLedger; |
| | | import com.ruoyi.safe.pojo.SafeFacilityRectification; |
| | | import com.ruoyi.safe.mapper.SafeFacilityRectificationMapper; |
| | | 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 SysUserMapper sysUserMapper; |
| | | |
| | | @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; |
| | | } |
| | | |
| | | // 收集设施ID |
| | | List<Integer> facilityIds = records.stream() |
| | | .map(SafeFacilityRectification::getFacilityId) |
| | | .filter(Objects::nonNull) |
| | | .distinct() |
| | | .collect(Collectors.toList()); |
| | | |
| | | // 收集所有用户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) { |
| | | if (record.getFacilityId() != null) { |
| | | SafeFacilityLedger facility = facilityMap.get(record.getFacilityId()); |
| | | if (facility != null) { |
| | | record.setFacilityName(facility.getFacilityName()); |
| | | } |
| | | } |
| | | 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())) { |
| | | entity.setVerifyUserId(currentUserId.intValue()); |
| | | entity.setVerifyTime(LocalDateTime.now()); |
| | | } |
| | | return super.updateById(entity); |
| | | } |
| | | } |