xuhy
2 天以前 dda2e3f49fe9c942fb6a487204ff8c8e66e46a12
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
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.TExperimentDispatchMapper;
import com.ruoyi.system.mapper.TExperimentDispatchParticipantsMapper;
import com.ruoyi.system.mapper.TProjectProposalMapper;
import com.ruoyi.system.model.TExperimentDispatch;
import com.ruoyi.system.model.TExperimentDispatchParticipants;
import com.ruoyi.system.model.TProjectProposal;
import com.ruoyi.system.query.TExperimentDispatchQuery;
import com.ruoyi.system.service.TExperimentDispatchService;
import com.ruoyi.system.vo.TExperimentDispatchVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
 
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
 
/**
 * <p>
 * 实验调度管理 服务实现类
 * </p>
 *
 * @author xiaochen
 * @since 2025-04-08
 */
@Service
public class TExperimentDispatchServiceImpl extends ServiceImpl<TExperimentDispatchMapper, TExperimentDispatch> implements TExperimentDispatchService {
 
    @Autowired
    private TExperimentDispatchParticipantsMapper experimentDispatchParticipantsMapper;
    @Autowired
    private TProjectProposalMapper projectProposalMapper;
    @Autowired
    private SysUserMapper sysUserMapper;
 
    @Override
    public PageInfo<TExperimentDispatchVO> pageList(TExperimentDispatchQuery query) {
        PageInfo<TExperimentDispatchVO> pageInfo = new PageInfo<>(query.getPageNum(), query.getPageSize());
        // 查询自己已通过的实验调度
        if(Objects.nonNull(query.getOtherStatus())){
            List<TExperimentDispatchParticipants> experimentDispatchParticipants1 = experimentDispatchParticipantsMapper.selectList(Wrappers.lambdaQuery(TExperimentDispatchParticipants.class)
                    .eq(TExperimentDispatchParticipants::getUserId, query.getUserId())
                    .eq(TExperimentDispatchParticipants::getStatus, query.getOtherStatus()));
            if(!CollectionUtils.isEmpty(experimentDispatchParticipants1)){
                List<String> dispatchIdList = experimentDispatchParticipants1.stream().map(TExperimentDispatchParticipants::getDispatchId).distinct().collect(Collectors.toList());
                query.setDispatchIdList(dispatchIdList);
            }else{
                return pageInfo;
            }
        }
        List<TExperimentDispatchVO> list = this.baseMapper.pageList(query,pageInfo);
        // 查询参与人员
        List<String> ids = list.stream().map(TExperimentDispatchVO::getId).collect(Collectors.toList());
        if(!CollectionUtils.isEmpty(ids)){
            List<TExperimentDispatchParticipants> tExperimentDispatchParticipants = experimentDispatchParticipantsMapper.selectList(Wrappers.lambdaQuery(TExperimentDispatchParticipants.class)
                    .in(TExperimentDispatchParticipants::getDispatchId, ids));
            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());
                }
            });
            for (TExperimentDispatchVO tExperimentDispatchVO : list) {
                List<TExperimentDispatchParticipants> experimentDispatchParticipants = tExperimentDispatchParticipants.stream().filter(tExperimentDispatchParticipant -> tExperimentDispatchParticipant.getDispatchId().equals(tExperimentDispatchVO.getId())).collect(Collectors.toList());
                String participantsName = experimentDispatchParticipants.stream().map(TExperimentDispatchParticipants::getNickName).collect(Collectors.joining(";"));
                tExperimentDispatchVO.setParticipantsName(participantsName);
                experimentDispatchParticipants.stream().filter(e->e.getUserId().equals(query.getUserId()) && e.getDispatchId().equals(tExperimentDispatchVO.getId())).findFirst().ifPresent(tExperimentDispatchParticipant -> {
                    tExperimentDispatchVO.setOtherStatus(tExperimentDispatchParticipant.getStatus());
                });
            }
        }
        pageInfo.setRecords(list);
        return pageInfo;
    }
 
    @Override
    public PageInfo<TExperimentDispatch> chemistSignList(TExperimentDispatchQuery query) {
        PageInfo<TExperimentDispatch> pageInfo = new PageInfo<>(query.getPageNum(), query.getPageSize());
        List<TExperimentDispatch> list = this.baseMapper.chemistSignList(query,pageInfo);
        if(CollectionUtils.isEmpty(list)){
            return pageInfo;
        }
        // 查询参与人员
        List<String> ids = list.stream().map(TExperimentDispatch::getId).collect(Collectors.toList());
        List<String> proposalIds = list.stream().map(TExperimentDispatch::getProposalId).collect(Collectors.toList());
        List<TProjectProposal> projectProposals = projectProposalMapper.selectList(Wrappers.lambdaQuery(TProjectProposal.class).in(TProjectProposal::getId, proposalIds));
 
        if(!CollectionUtils.isEmpty(ids)){
            List<TExperimentDispatchParticipants> tExperimentDispatchParticipants = experimentDispatchParticipantsMapper.selectList(Wrappers.lambdaQuery(TExperimentDispatchParticipants.class)
                    .in(TExperimentDispatchParticipants::getDispatchId, ids));
            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());
                }
            });
            list.forEach(experimentDispatch -> {
                projectProposals.stream().filter(projectProposal -> projectProposal.getId().equals(experimentDispatch.getProposalId())).findFirst().ifPresent(projectProposal -> {
                    experimentDispatch.setProjectName(projectProposal.getProjectName());
                });
                List<TExperimentDispatchParticipants> experimentDispatchParticipantsList = tExperimentDispatchParticipants.stream().filter(tExperimentDispatchParticipant -> tExperimentDispatchParticipant.getDispatchId().equals(experimentDispatch.getId())).collect(Collectors.toList());
                String participantsName = experimentDispatchParticipantsList.stream().map(TExperimentDispatchParticipants::getNickName).collect(Collectors.joining(";"));
                experimentDispatch.setParticipantsName(participantsName);
            });
        }
        pageInfo.setRecords(list);
        return pageInfo;
    }
}