shenyijian
2024-06-17 e1cdb7930d2eb4baccff2809a420a1f0f544c934
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 cn.gistack.sm.sg.service.impl;
 
import cn.gistack.sm.sg.DO.SgDeviceDO;
import cn.gistack.sm.sg.DO.SgGxDO;
import cn.gistack.sm.sg.DO.SgGxStepDO;
import cn.gistack.sm.sg.DO.SgProjectInfoDO;
import cn.gistack.sm.sg.DTO.ProjectSearchDTO;
import cn.gistack.sm.sg.VO.SgProjectInfoVO;
import cn.gistack.sm.sg.mapper.SgProjectInfoMapper;
import cn.gistack.sm.sg.service.SgProjectInfoService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
 
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
 
/**
 * <p>
 * 施工项目表 服务实现类
 * </p>
 *
 * @author shenyijian
 * @since 2024-06-13 11:51:20
 */
@Service
public class SgProjectInfoServiceImpl extends ServiceImpl<SgProjectInfoMapper, SgProjectInfoDO> implements SgProjectInfoService {
    @Autowired
    private SgProjectInfoMapper sgProjectInfoMapper;
    @Override
    public IPage<SgProjectInfoDO> queryPageList(IPage<SgProjectInfoDO> page, ProjectSearchDTO searchDTO) {
        List<SgProjectInfoDO> sgProjectInfoDOS = baseMapper.queryPageList(page,searchDTO);
        return page.setRecords(sgProjectInfoDOS);
    }
 
    @Override
    public List<SgProjectInfoDO> queryStepByProject(ProjectSearchDTO searchDTO) {
        List<SgProjectInfoVO> list = sgProjectInfoMapper.queryStepByProject( searchDTO);
        //项目分组
        Map<Long, List<SgProjectInfoVO>> projectMap = list.stream().collect(Collectors.groupingBy(SgProjectInfoVO::getId));
        List<SgProjectInfoDO> result = new ArrayList<>();
        for (Map.Entry<Long, List<SgProjectInfoVO>> entry : projectMap.entrySet()) {
            Long porId = entry.getKey();
            List<SgProjectInfoVO> value = entry.getValue();
            if (CollectionUtils.isEmpty(value)){
                continue;
            }
            SgProjectInfoDO sgProjectInfoDO = SgProjectInfoDO.builder().id(porId).projectName(value.get(0).getProjectName()).build();
            List<SgGxDO> sgGxDOS = new ArrayList<>();
            //工序分组
            Map<Long, List<SgProjectInfoVO>> GxMap = value.stream().filter(s->s.getGxId()!=null).collect(Collectors.groupingBy(SgProjectInfoVO::getGxId));
            for (Map.Entry<Long, List<SgProjectInfoVO>> gx : GxMap.entrySet()) {
                Long gxId = gx.getKey();
                List<SgProjectInfoVO> gxList = gx.getValue();
                if (CollectionUtils.isEmpty(gxList)){
                    continue;
                }
                SgGxDO gxDO = SgGxDO.builder().id(gxId).gxName(gxList.get(0).getGxName()).build();
                List<SgDeviceDO> deviceDOS = new ArrayList<>();
                //设备分组
                Map<Long, List<SgProjectInfoVO>> dMap = gxList.stream().collect(Collectors.groupingBy(SgProjectInfoVO::getDId));
                for (Map.Entry<Long, List<SgProjectInfoVO>> device : dMap.entrySet()) {
                    Long dId = device.getKey();
                    List<SgProjectInfoVO> deList = device.getValue();
                    SgDeviceDO sgDeviceDO = new SgDeviceDO();
                    sgDeviceDO.setId(dId);
                    sgDeviceDO.setDeviceName(deList.get(0).getDeviceName());
                    sgDeviceDO.setStepDOList(deList.stream().map(s->SgGxStepDO.builder().gxStepName(s.getGxStepName()).approvalStatus(s.getSTATUS()).build()).collect(Collectors.toList()));
                    deviceDOS.add(sgDeviceDO);
                }
                gxDO.setDeviceDOS(deviceDOS);
                sgGxDOS.add(gxDO);
            }
            sgProjectInfoDO.setSgGxDOS(sgGxDOS);
            result.add(sgProjectInfoDO);
        }
        return result;
    }
}