无关风月
2025-06-06 0ac5cf2c2bf4b7a16a61fdaab27b2b8d6e8b72ee
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
package com.ruoyi.system.service.impl;
 
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
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.common.utils.bean.BeanUtils;
import com.ruoyi.system.mapper.SysUserMapper;
import com.ruoyi.system.mapper.TProjectTeamMapper;
import com.ruoyi.system.mapper.TStrainReportDetailMapper;
import com.ruoyi.system.mapper.TStrainReportMapper;
import com.ruoyi.system.model.TProjectTeam;
import com.ruoyi.system.model.TStrainReport;
import com.ruoyi.system.model.TStrainReportDetail;
import com.ruoyi.system.model.TTrainLibrary;
import com.ruoyi.system.query.TProjectTeamQuery;
import com.ruoyi.system.query.TStrainReportProjectQuery;
import com.ruoyi.system.query.TStrainReportQuery;
import com.ruoyi.system.query.TTrainLibraryQuery;
import com.ruoyi.system.service.TStrainReportDetailService;
import com.ruoyi.system.service.TStrainReportService;
import com.ruoyi.system.vo.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
 
import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.List;
import java.util.stream.Collectors;
 
/**
 * <p>
 * 菌种报告库 服务实现类
 * </p>
 *
 * @author 无关风月
 * @since 2025-04-12
 */
@Service
public class TStrainReportServiceImpl extends ServiceImpl<TStrainReportMapper, TStrainReport> implements TStrainReportService {
 
    @Resource
    private TProjectTeamMapper projectTeamMapper;
    @Resource
    private TStrainReportDetailMapper strainReportDetailMapper;
    @Resource
    private SysUserMapper sysUserMapper;
    @Override
    public PageInfo<TStrainReportVO> pageList(TStrainReportQuery query) {
        PageInfo<TStrainReportVO> pageInfo = new PageInfo<>(query.getPageNum(), query.getPageSize());
        List<TStrainReportVO> list = this.baseMapper.pageList(query,pageInfo);
        pageInfo.setRecords(list);
        return pageInfo;
    }
 
    @Override
    public PageInfo<TStrainReportProjectVO> pageListProject(TStrainReportProjectQuery query) {
        PageInfo<TStrainReportProjectVO> pageInfo = new PageInfo<>(query.getPageNum(), query.getPageSize());
        List<TStrainReportProjectVO> list = this.baseMapper.pageListProject(query,pageInfo);
        List<TStrainReport> tStrainReports = this.baseMapper.selectList(new LambdaQueryWrapper<TStrainReport>().eq(TStrainReport::getStatus,3));
        List<TStrainReportDetail> tStrainReportDetails = strainReportDetailMapper.selectList(new LambdaQueryWrapper<TStrainReportDetail>());
        for (TStrainReportProjectVO tStrainReportProjectVO : list) {
            List<TStrainReport> collect = tStrainReports.stream().filter(e -> e.getProjectId().equals(tStrainReportProjectVO.getProjectId())).collect(Collectors.toList());
            BigDecimal sum = new BigDecimal("0");
            BigDecimal sum1 = new BigDecimal("0");
            BigDecimal sum2 = new BigDecimal("0");
            Integer temp = 0;
            for (TStrainReport tStrainReport : collect) {
                List<TStrainReportDetail> collect1 = tStrainReportDetails.stream()
                        .filter(e -> e.getReportId().equals(tStrainReport.getId())&&
                                e.getEvaluateHumanType()==1).collect(Collectors.toList());
                List<TStrainReportDetail> collect2 = tStrainReportDetails.stream()
                        .filter(e -> e.getReportId().equals(tStrainReport.getId())&&
                                e.getEvaluateHumanType()==2).collect(Collectors.toList());
                // 菌种工程积分
                sum1 = collect2.stream()
                        .filter(e -> e.getEvaluateHumanType().equals(1))
                        .map(TStrainReportDetail::getEvaluateTotal)
                        .reduce(BigDecimal::add)
                        .orElse(BigDecimal.ZERO);
                // 菌种实验员积分
                sum2 = collect1.stream()
                        .filter(e -> e.getEvaluateHumanType().equals(2))
                        .map(TStrainReportDetail::getEvaluateTotal)
                        .reduce(BigDecimal::add)
                        .orElse(BigDecimal.ZERO);
                List<TStrainReportDetail> collect3 = tStrainReportDetails.stream().filter(e -> e.getReportType() == 1).collect(Collectors.toList());
                for (TStrainReportDetail tStrainReportDetail : collect3) {
                    // 根据评定等级统计失败次数
                    if (StringUtils.hasLength(tStrainReportDetail.getEvaluate())&&  tStrainReportDetail.getEvaluate().split(",").length>=5){
                        if (tStrainReportDetail.getEvaluate().split(",")[4].equals("2")){
                            temp++;
                        }
                    }
                }
            }
            tStrainReportProjectVO.setTeamIntegral(sum1.add(sum2));
            tStrainReportProjectVO.setEngineerIntegral(sum1);
            tStrainReportProjectVO.setExperimenterIntegral(sum2);
            tStrainReportProjectVO.setFailCount(temp);
            List<TStrainReport> collect1 = tStrainReports.stream().filter(e -> e.getProjectId().equals(tStrainReportProjectVO.getProjectId())).collect(Collectors.toList());
            if (!collect1.isEmpty()){
                tStrainReportProjectVO.setEndTime(collect1.get(0).getEvaluateTime());
            }
            TProjectTeam projectTeam = projectTeamMapper.selectById(tStrainReportProjectVO.getProjectId());
            tStrainReportProjectVO.setStartTime(projectTeam.getCreateTime());
        }
        pageInfo.setRecords(list);
        return pageInfo;
    }
 
    @Override
    public PageInfo<TStrainReportVO> pageListAll(TStrainReportQuery query) {
        PageInfo<TStrainReportVO> pageInfo = new PageInfo<>(query.getPageNum(), query.getPageSize());
        List<TStrainReportVO> list = this.baseMapper.pageListAll(query,pageInfo);
        List<TStrainReportDetail> tStrainReportDetails = strainReportDetailMapper.selectList(null);
 
        for (TStrainReportVO tStrainReportVO : list) {
            List<TStrainReportDetail> collect = tStrainReportDetails.stream().filter(e -> e.getReportId().equals(tStrainReportVO.getId())).collect(Collectors.toList());
            for (TStrainReportDetail tStrainReportDetail : collect) {
                if (tStrainReportDetail.getEvaluateHumanType()==1){
                    if (tStrainReportDetail.getExperimentId()!=null){
                        SysUser sysUser = sysUserMapper.selectUserById(Long.valueOf(tStrainReportDetail.getExperimentId()));
                        tStrainReportVO.setExperimentName(sysUser.getNickName());
                    }
                }else if (tStrainReportDetail.getEvaluateHumanType()==2){
                    if (tStrainReportDetail.getExperimentId()!=null){
                        SysUser sysUser = sysUserMapper.selectUserById(Long.valueOf(tStrainReportDetail.getExperimentId()));
                        tStrainReportVO.setExperimentName(sysUser.getNickName());
                    }
                }
            }
 
        }
        pageInfo.setRecords(list);
        return pageInfo;
    }
}