package com.ruoyi.safe.service.impl;
|
|
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.safe.pojo.SafeLineInspection;
|
import com.ruoyi.safe.mapper.SafeLineInspectionMapper;
|
import com.ruoyi.safe.service.SafeLineInspectionService;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.ruoyi.project.system.mapper.SysUserMapper;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.stereotype.Service;
|
|
import java.util.Arrays;
|
import java.util.List;
|
import java.util.Map;
|
import java.util.stream.Collectors;
|
|
/**
|
* <p>
|
* 安全生产--线路巡检任务 服务实现类
|
* </p>
|
*
|
* @author 芯导软件(江苏)有限公司
|
* @since 2026-06-29
|
*/
|
@Service
|
public class SafeLineInspectionServiceImpl extends ServiceImpl<SafeLineInspectionMapper, SafeLineInspection> implements SafeLineInspectionService {
|
|
@Autowired
|
private SysUserMapper sysUserMapper;
|
|
@Override
|
public IPage<SafeLineInspection> pageSafeLineInspection(Page page, SafeLineInspection safeLineInspection) {
|
IPage<SafeLineInspection> result = this.lambdaQuery()
|
.like(safeLineInspection.getInspectionCode() != null, SafeLineInspection::getInspectionCode, safeLineInspection.getInspectionCode())
|
.like(safeLineInspection.getInspectionName() != null, SafeLineInspection::getInspectionName, safeLineInspection.getInspectionName())
|
.like(safeLineInspection.getLineName() != null, SafeLineInspection::getLineName, safeLineInspection.getLineName())
|
.eq(safeLineInspection.getStatus() != null, SafeLineInspection::getStatus, safeLineInspection.getStatus())
|
.orderByDesc(SafeLineInspection::getCreateTime)
|
.page(page);
|
|
// 关联查询巡检人名称
|
fillInspectorName(result.getRecords());
|
|
return result;
|
}
|
|
/**
|
* 填充巡检人名称(支持多巡检人,逗号分隔)
|
*/
|
private void fillInspectorName(List<SafeLineInspection> records) {
|
if (records == null || records.isEmpty()) {
|
return;
|
}
|
|
// 收集所有巡检人ID(处理逗号分隔的多个ID)
|
List<Long> allInspectorIds = records.stream()
|
.map(SafeLineInspection::getInspectorId)
|
.filter(ids -> ids != null && !ids.isEmpty())
|
.flatMap(ids -> Arrays.stream(ids.split(",")))
|
.map(String::trim)
|
.filter(s -> !s.isEmpty())
|
.map(Long::parseLong)
|
.distinct()
|
.collect(Collectors.toList());
|
|
if (allInspectorIds.isEmpty()) {
|
return;
|
}
|
|
// 批量查询用户信息
|
List<SysUser> users = sysUserMapper.selectUserByIds(allInspectorIds);
|
Map<Long, String> userMap = users.stream()
|
.collect(Collectors.toMap(SysUser::getUserId, SysUser::getNickName, (v1, v2) -> v1));
|
|
// 设置巡检人名称
|
for (SafeLineInspection record : records) {
|
if (record.getInspectorId() != null && !record.getInspectorId().isEmpty()) {
|
String inspectorNames = Arrays.stream(record.getInspectorId().split(","))
|
.map(String::trim)
|
.filter(s -> !s.isEmpty())
|
.map(idStr -> {
|
try {
|
Long id = Long.parseLong(idStr);
|
return userMap.getOrDefault(id, "未知用户");
|
} catch (NumberFormatException e) {
|
return "未知用户";
|
}
|
})
|
.collect(Collectors.joining(","));
|
record.setInspectorName(inspectorNames);
|
}
|
}
|
}
|
}
|