liding
2026-06-29 68ea0f2cb0272bdf4427995501034a6932c17a66
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
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);
            }
        }
    }
}