xuhy
4 天以前 7e9fea768cf8ef436c6378bf29170523721bfc77
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
package com.ruoyi.system.service.impl;
 
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.common.basic.PageInfo;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.system.mapper.SysUserMapper;
import com.ruoyi.system.mapper.TExperimentDispatchParticipantsMapper;
import com.ruoyi.system.mapper.TExperimentResultReportMapper;
import com.ruoyi.system.mapper.TResultWorkEvaluateMapper;
import com.ruoyi.system.model.TExperimentDispatchParticipants;
import com.ruoyi.system.model.TExperimentResultReport;
import com.ruoyi.system.model.TResultWorkEvaluate;
import com.ruoyi.system.query.TExperimentResultReportQuery;
import com.ruoyi.system.service.TExperimentResultReportService;
import com.ruoyi.system.vo.TExperimentResultReportVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
 
import java.util.List;
import java.util.stream.Collectors;
 
/**
 * <p>
 * 实验结果汇报 服务实现类
 * </p>
 *
 * @author xiaochen
 * @since 2025-04-08
 */
@Service
public class TExperimentResultReportServiceImpl extends ServiceImpl<TExperimentResultReportMapper, TExperimentResultReport> implements TExperimentResultReportService {
 
    @Autowired
    private TExperimentResultReportMapper tExperimentResultReportMapper;
    @Autowired
    private TExperimentDispatchParticipantsMapper experimentDispatchParticipantsMapper;
    @Autowired
    private TResultWorkEvaluateMapper resultWorkEvaluateMapper;
    @Autowired
    private SysUserMapper sysUserMapper;
 
    @Override
    public PageInfo<TExperimentResultReportVO> pageList(TExperimentResultReportQuery query) {
        PageInfo<TExperimentResultReportVO> pageInfo = new PageInfo<>(query.getPageNum(), query.getPageSize());
        List<TExperimentResultReportVO> list = this.baseMapper.pageList(query,pageInfo);
        if(CollectionUtils.isEmpty(list)){
            return pageInfo;
        }
        List<String> dispatchIds = list.stream().map(TExperimentResultReportVO::getDispatchId).distinct().collect(Collectors.toList());
        // 查询参与人员
        List<TExperimentDispatchParticipants> tExperimentDispatchParticipants = experimentDispatchParticipantsMapper.selectList(Wrappers.lambdaQuery(TExperimentDispatchParticipants.class)
                .in(TExperimentDispatchParticipants::getDispatchId, dispatchIds));
 
        // 设置参与人员名称
        List<Long> userIds = tExperimentDispatchParticipants.stream().map(TExperimentDispatchParticipants::getUserId).collect(Collectors.toList());
        List<SysUser> sysUsers = sysUserMapper.selectUserByIds(userIds);
        tExperimentDispatchParticipants.forEach(tExperimentDispatchParticipant -> {
            SysUser sysUser = sysUsers.stream().filter(user -> user.getUserId().equals(tExperimentDispatchParticipant.getUserId())).findFirst().orElse(null);
            if(sysUser != null){
                tExperimentDispatchParticipant.setNickName(sysUser.getNickName());
                tExperimentDispatchParticipant.setAvatar(sysUser.getAvatar());
            }
        });
 
        List<String> ids = list.stream().map(TExperimentResultReportVO::getId).distinct().collect(Collectors.toList());
        // 查询结果汇报评价
        List<TResultWorkEvaluate> resultWorkEvaluates = resultWorkEvaluateMapper.selectList(Wrappers.lambdaQuery(TResultWorkEvaluate.class)
                .in(TResultWorkEvaluate::getResultReportId, ids));
 
        for (TExperimentResultReportVO experimentResultReportVO : list) {
            experimentResultReportVO.setExperimentDispatchParticipants(tExperimentDispatchParticipants.stream().filter(participants -> participants.getDispatchId().equals(experimentResultReportVO.getDispatchId())).collect(Collectors.toList()));
            experimentResultReportVO.setResultWorkEvaluates(resultWorkEvaluates.stream().filter(evaluate -> evaluate.getResultReportId().equals(experimentResultReportVO.getId())).collect(Collectors.toList()));
            // 设置工艺工程师名称
            TExperimentDispatchParticipants dispatchParticipants = tExperimentDispatchParticipants.stream()
                    .filter(participants -> participants.getDispatchId().equals(experimentResultReportVO.getDispatchId())
                            && participants.getRoleType().equals(3)).findFirst().orElse(null);
            if(dispatchParticipants != null){
                experimentResultReportVO.setProcessEngineerName(dispatchParticipants.getNickName());
            }
            // 设置化验师名称
            List<TExperimentDispatchParticipants> laboratoryChemist = tExperimentDispatchParticipants.stream()
                    .filter(participants -> participants.getDispatchId().equals(experimentResultReportVO.getDispatchId())
                            && participants.getRoleType().equals(4)).collect(Collectors.toList());
            List<TResultWorkEvaluate> chemistEvaluates = resultWorkEvaluates.stream()
                    .filter(workEvaluate -> workEvaluate.getDispatchId().equals(experimentResultReportVO.getDispatchId())
                            && workEvaluate.getEvaluateType().equals(2)).collect(Collectors.toList());
            if(laboratoryChemist.size() == chemistEvaluates.size()){
                experimentResultReportVO.setLaboratoryChemistEvaluate(1);
            }
            if(!CollectionUtils.isEmpty(laboratoryChemist)){
                String laboratoryChemistName = laboratoryChemist.stream().map(TExperimentDispatchParticipants::getNickName).collect(Collectors.joining(","));
                experimentResultReportVO.setLaboratoryChemistName(laboratoryChemistName);
            }
            // 设置实验员名称
            List<TExperimentDispatchParticipants> experimenter = tExperimentDispatchParticipants.stream()
                    .filter(participants -> participants.getDispatchId().equals(experimentResultReportVO.getDispatchId())
                            && participants.getRoleType().equals(5)).collect(Collectors.toList());
            List<TResultWorkEvaluate> experimenterEvaluates = resultWorkEvaluates.stream()
                    .filter(workEvaluate -> workEvaluate.getDispatchId().equals(experimentResultReportVO.getDispatchId())
                            && workEvaluate.getEvaluateType().equals(3)).collect(Collectors.toList());
            if(experimenter.size() == experimenterEvaluates.size()){
                experimentResultReportVO.setExperimenterEvaluate(1);
            }
            if(!CollectionUtils.isEmpty(experimenter)){
                String experimenterName = experimenter.stream().map(TExperimentDispatchParticipants::getNickName).collect(Collectors.joining(","));
                experimentResultReportVO.setExperimenterName(experimenterName);
            }
        }
 
        pageInfo.setRecords(list);
        return pageInfo;
    }
 
    @Override
    public PageInfo<TExperimentResultReportVO> evaluatePageList(TExperimentResultReportQuery query) {
        PageInfo<TExperimentResultReportVO> pageInfo = new PageInfo<>(query.getPageNum(), query.getPageSize());
        List<TExperimentResultReportVO> list = this.baseMapper.evaluatePageList(query,pageInfo);
        if(CollectionUtils.isEmpty(list)){
            return pageInfo;
        }
        List<String> dispatchIds = list.stream().map(TExperimentResultReportVO::getDispatchId).distinct().collect(Collectors.toList());
        // 查询参与人员
        List<TExperimentDispatchParticipants> tExperimentDispatchParticipants = experimentDispatchParticipantsMapper.selectList(Wrappers.lambdaQuery(TExperimentDispatchParticipants.class)
                .in(TExperimentDispatchParticipants::getDispatchId, dispatchIds));
 
        // 设置参与人员名称
        List<Long> userIds = tExperimentDispatchParticipants.stream().map(TExperimentDispatchParticipants::getUserId).collect(Collectors.toList());
        List<SysUser> sysUsers = sysUserMapper.selectUserByIds(userIds);
        tExperimentDispatchParticipants.forEach(tExperimentDispatchParticipant -> {
            SysUser sysUser = sysUsers.stream().filter(user -> user.getUserId().equals(tExperimentDispatchParticipant.getUserId())).findFirst().orElse(null);
            if(sysUser != null){
                tExperimentDispatchParticipant.setNickName(sysUser.getNickName());
                tExperimentDispatchParticipant.setAvatar(sysUser.getAvatar());
            }
        });
 
        List<String> ids = list.stream().map(TExperimentResultReportVO::getId).distinct().collect(Collectors.toList());
        // 查询结果汇报评价
        List<TResultWorkEvaluate> resultWorkEvaluates = resultWorkEvaluateMapper.selectList(Wrappers.lambdaQuery(TResultWorkEvaluate.class)
                .in(TResultWorkEvaluate::getResultReportId, ids));
        for (TExperimentResultReportVO experimentResultReportVO : list) {
            experimentResultReportVO.setExperimentDispatchParticipants(tExperimentDispatchParticipants.stream().filter(participants -> participants.getDispatchId().equals(experimentResultReportVO.getDispatchId())).collect(Collectors.toList()));
            experimentResultReportVO.setResultWorkEvaluates(resultWorkEvaluates.stream().filter(evaluate -> evaluate.getResultReportId().equals(experimentResultReportVO.getId())).collect(Collectors.toList()));
            // 设置工艺工程师名称
            TExperimentDispatchParticipants dispatchParticipants = tExperimentDispatchParticipants.stream()
                    .filter(participants -> participants.getDispatchId().equals(experimentResultReportVO.getDispatchId())
                            && participants.getRoleType().equals(3)).findFirst().orElse(null);
            if(dispatchParticipants != null){
                experimentResultReportVO.setProcessEngineerName(dispatchParticipants.getNickName());
            }
            // 设置化验师名称
            List<TExperimentDispatchParticipants> laboratoryChemist = tExperimentDispatchParticipants.stream()
                    .filter(participants -> participants.getDispatchId().equals(experimentResultReportVO.getDispatchId())
                            && participants.getRoleType().equals(4)).collect(Collectors.toList());
            List<TResultWorkEvaluate> chemistEvaluates = resultWorkEvaluates.stream()
                    .filter(workEvaluate -> workEvaluate.getDispatchId().equals(experimentResultReportVO.getDispatchId())
                            && workEvaluate.getEvaluateType().equals(2)).collect(Collectors.toList());
            if(laboratoryChemist.size() == chemistEvaluates.size()){
                experimentResultReportVO.setLaboratoryChemistEvaluate(1);
            }
            if(!CollectionUtils.isEmpty(laboratoryChemist)){
                String laboratoryChemistName = laboratoryChemist.stream().map(TExperimentDispatchParticipants::getNickName).collect(Collectors.joining(","));
                experimentResultReportVO.setLaboratoryChemistName(laboratoryChemistName);
            }
            // 设置实验员名称
            List<TExperimentDispatchParticipants> experimenter = tExperimentDispatchParticipants.stream()
                    .filter(participants -> participants.getDispatchId().equals(experimentResultReportVO.getDispatchId())
                            && participants.getRoleType().equals(5)).collect(Collectors.toList());
            List<TResultWorkEvaluate> experimenterEvaluates = resultWorkEvaluates.stream()
                    .filter(workEvaluate -> workEvaluate.getDispatchId().equals(experimentResultReportVO.getDispatchId())
                            && workEvaluate.getEvaluateType().equals(3)).collect(Collectors.toList());
            if(experimenter.size() == experimenterEvaluates.size()){
                experimentResultReportVO.setExperimenterEvaluate(1);
            }
            if(!CollectionUtils.isEmpty(experimenter)){
                String experimenterName = experimenter.stream().map(TExperimentDispatchParticipants::getNickName).collect(Collectors.joining(","));
                experimentResultReportVO.setExperimenterName(experimenterName);
            }
        }
        pageInfo.setRecords(list);
        return pageInfo;
    }
}