| | |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.ruoyi.common.utils.SecurityUtils; |
| | | import com.ruoyi.safe.pojo.SafeLineInspectionHazard; |
| | | import com.ruoyi.project.system.domain.SysUser; |
| | | import com.ruoyi.project.system.mapper.SysUserMapper; |
| | | import com.ruoyi.safe.mapper.SafeLineInspectionHazardMapper; |
| | | import com.ruoyi.safe.pojo.SafeLineInspectionHazard; |
| | | import com.ruoyi.safe.service.SafeLineInspectionHazardService; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import java.time.LocalDateTime; |
| | | import java.util.List; |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | | * <p> |
| | |
| | | @Service |
| | | public class SafeLineInspectionHazardServiceImpl extends ServiceImpl<SafeLineInspectionHazardMapper, SafeLineInspectionHazard> implements SafeLineInspectionHazardService { |
| | | |
| | | @Autowired |
| | | private SysUserMapper sysUserMapper; |
| | | |
| | | @Override |
| | | public IPage<SafeLineInspectionHazard> pageSafeLineInspectionHazard(Page page, SafeLineInspectionHazard safeLineInspectionHazard) { |
| | | return this.lambdaQuery() |
| | | IPage<SafeLineInspectionHazard> result = this.lambdaQuery() |
| | | .eq(safeLineInspectionHazard.getInspectionId() != null, SafeLineInspectionHazard::getInspectionId, safeLineInspectionHazard.getInspectionId()) |
| | | .like(safeLineInspectionHazard.getHazardCode() != null, SafeLineInspectionHazard::getHazardCode, safeLineInspectionHazard.getHazardCode()) |
| | | .eq(safeLineInspectionHazard.getStatus() != null, SafeLineInspectionHazard::getStatus, safeLineInspectionHazard.getStatus()) |
| | | .orderByDesc(SafeLineInspectionHazard::getCreateTime) |
| | | .page(page); |
| | | fillRectifyUserName(result.getRecords()); |
| | | return result; |
| | | } |
| | | |
| | | @Override |
| | | public List<SafeLineInspectionHazard> listByInspectionId(Integer inspectionId) { |
| | | return this.lambdaQuery() |
| | | List<SafeLineInspectionHazard> records = this.lambdaQuery() |
| | | .eq(SafeLineInspectionHazard::getInspectionId, inspectionId) |
| | | .orderByDesc(SafeLineInspectionHazard::getCreateTime) |
| | | .list(); |
| | | fillRectifyUserName(records); |
| | | return records; |
| | | } |
| | | |
| | | @Override |
| | |
| | | long count = this.count() + 1; |
| | | return "YH" + String.format("%05d", count); |
| | | } |
| | | |
| | | private void fillRectifyUserName(List<SafeLineInspectionHazard> records) { |
| | | if (records == null || records.isEmpty()) { |
| | | return; |
| | | } |
| | | List<Long> userIds = records.stream() |
| | | .map(SafeLineInspectionHazard::getRectifyUserId) |
| | | .filter(Objects::nonNull) |
| | | .map(Integer::longValue) |
| | | .distinct() |
| | | .collect(Collectors.toList()); |
| | | if (userIds.isEmpty()) { |
| | | return; |
| | | } |
| | | Map<Long, String> userMap = sysUserMapper.selectUserByIds(userIds).stream() |
| | | .collect(Collectors.toMap(SysUser::getUserId, SysUser::getNickName, (v1, v2) -> v1)); |
| | | records.forEach(record -> { |
| | | if (record.getRectifyUserId() != null) { |
| | | record.setRectifyUserName(userMap.getOrDefault(record.getRectifyUserId().longValue(), "未知用户")); |
| | | } |
| | | }); |
| | | } |
| | | } |