xuhy
2 天以前 b7ec3aff011f05e236e76be844540dbe776f7353
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
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.TSamplingRecordMapper;
import com.ruoyi.system.mapper.TSamplingRecordOperationMapper;
import com.ruoyi.system.model.TExperimentDispatchParticipants;
import com.ruoyi.system.model.TSamplingRecord;
import com.ruoyi.system.model.TSamplingRecordOperation;
import com.ruoyi.system.query.TSamplingRecordQuery;
import com.ruoyi.system.service.TSamplingRecordService;
import com.ruoyi.system.vo.TSamplingRecordVO;
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 TSamplingRecordServiceImpl extends ServiceImpl<TSamplingRecordMapper, TSamplingRecord> implements TSamplingRecordService {
 
    @Autowired
    private TSamplingRecordOperationMapper samplingRecordOperationMapper;
    @Autowired
    private TExperimentDispatchParticipantsMapper experimentDispatchParticipantsMapper;
    @Autowired
    private SysUserMapper sysUserMapper;
 
    @Override
    public PageInfo<TSamplingRecordVO> pageList(TSamplingRecordQuery query) {
        PageInfo<TSamplingRecordVO> pageInfo = new PageInfo<>(query.getPageNum(), query.getPageSize());
        List<TSamplingRecordVO> list = this.baseMapper.pageList(query,pageInfo);
        if(CollectionUtils.isEmpty(list)){
            return pageInfo;
        }
 
        List<String> recordIds = list.stream().map(TSamplingRecordVO::getId).collect(Collectors.toList());
        List<TSamplingRecordOperation> recordOperationList = samplingRecordOperationMapper.selectList(Wrappers.lambdaQuery(TSamplingRecordOperation.class)
                .in(TSamplingRecordOperation::getSamplingId, recordIds));
 
        list.forEach(item->{
            item.setSendCount(recordOperationList.stream().filter(recordOperation -> recordOperation.getSamplingId().equals(item.getId()) && recordOperation.getStatus() == 1).count());
            item.setReceiveCount(recordOperationList.stream().filter(recordOperation -> recordOperation.getSamplingId().equals(item.getId()) && recordOperation.getStatus() == 2).count());
            item.setReceivedCount(recordOperationList.stream().filter(recordOperation -> recordOperation.getSamplingId().equals(item.getId()) && recordOperation.getStatus() == 3).count());
        });
 
        // 查询实验调度参与实验员
        List<String> dispatchIds = list.stream().map(TSamplingRecordVO::getDispatchId).collect(Collectors.toList());
        List<TExperimentDispatchParticipants> teamStaffs = experimentDispatchParticipantsMapper.selectList(Wrappers.lambdaQuery(TExperimentDispatchParticipants.class)
                .in(TExperimentDispatchParticipants::getDispatchId, dispatchIds)
                .eq(TExperimentDispatchParticipants::getRoleType, 5));
        List<Long> userIds = teamStaffs.stream().map(TExperimentDispatchParticipants::getUserId).collect(Collectors.toList());
        List<SysUser> sysUsers = sysUserMapper.selectUserByIds(userIds);
        teamStaffs.stream().forEach(teamStaff -> {
            sysUsers.stream().filter(sysUser -> sysUser.getUserId().equals(teamStaff.getUserId())).findFirst().ifPresent(sysUser -> {
                teamStaff.setNickName(sysUser.getNickName());
            });
        });
 
        for (TSamplingRecordVO tSamplingRecordVO : list) {
            List<TExperimentDispatchParticipants> experimentDispatchParticipants = teamStaffs.stream().filter(teamStaff -> teamStaff.getDispatchId().equals(tSamplingRecordVO.getDispatchId())).collect(Collectors.toList());
            if(!CollectionUtils.isEmpty(experimentDispatchParticipants)){
                tSamplingRecordVO.setTesterNames(experimentDispatchParticipants.stream().map(TExperimentDispatchParticipants::getNickName).collect(Collectors.joining(",")));
            }
        }
 
        pageInfo.setRecords(list);
        return pageInfo;
    }
}