无关风月
2 天以前 0b4f853f6b05b28e3201386bdda3e8af0bfcfc7f
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
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.model.TExperimentDispatch;
import com.ruoyi.system.model.TExperimentDispatchParticipants;
import com.ruoyi.system.model.TProjectTeamStaff;
import com.ruoyi.system.query.TExperimentDispatchQuery;
import com.ruoyi.system.service.TExperimentDispatchService;
import com.ruoyi.system.vo.TExperimentDispatchVO;
import com.ruoyi.system.vo.TProjectTeamVO;
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 TExperimentDispatchServiceImpl extends ServiceImpl<TExperimentDispatchMapper, TExperimentDispatch> implements TExperimentDispatchService {
 
    @Autowired
    private TExperimentDispatchParticipantsMapper experimentDispatchParticipantsMapper;
    @Autowired
    private SysUserMapper sysUserMapper;
 
    @Override
    public PageInfo<TExperimentDispatchVO> pageList(TExperimentDispatchQuery query) {
        PageInfo<TExperimentDispatchVO> pageInfo = new PageInfo<>(query.getPageNum(), query.getPageSize());
        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);
            }
        }
        pageInfo.setRecords(list);
        return pageInfo;
    }
}