shenyijian
2024-06-14 48dd237062ca63973503b63134ad3cc5e70296f0
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
package cn.gistack.sm.sg.service.impl;
 
import cn.gistack.sm.sg.DO.SgGxDO;
import cn.gistack.sm.sg.DO.SgGxStepDO;
import cn.gistack.sm.sg.DTO.ProjectSearchDTO;
import cn.gistack.sm.sg.VO.SgGxVO;
import cn.gistack.sm.sg.mapper.SgGxMapper;
import cn.gistack.sm.sg.service.SgGxService;
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.List;
import java.util.Map;
import java.util.stream.Collectors;
 
/**
 * <p>
 * 施工工序基本表 服务实现类
 * </p>
 *
 * @author shenyijian
 * @since 2024-06-13 15:46:18
 */
@Service
public class SgGxServiceImpl extends ServiceImpl<SgGxMapper, SgGxDO> implements SgGxService {
    @Autowired
    private SgGxMapper sgGxMapper;
    @Override
    public IPage<SgGxVO> queryPageList(IPage<SgGxVO> page, ProjectSearchDTO searchDTO) {
        List<SgGxVO> list = sgGxMapper.queryPageList(searchDTO);
        if (CollectionUtils.isNotEmpty(list)){
            List<Long> ids = list.stream().map(SgGxDO::getId).collect(Collectors.toList());
            List<SgGxStepDO> stepDOS = sgGxMapper.queryStepByIds(ids);
            if (CollectionUtils.isNotEmpty(stepDOS)){
                Map<Long, List<SgGxStepDO>> map = stepDOS.stream().collect(Collectors.groupingBy(SgGxStepDO::getGxInfoId));
                for (SgGxVO sgGxDO : list) {
                    sgGxDO.setStepDOList(map.get(sgGxDO.getId()));
                }
            }
        }
        return page.setRecords(list);
    }
 
    @Override
    public void add(SgGxDO sgGxDO) {
        if (sgGxMapper.selectByGxType(sgGxDO.getGxType())!= null){
            throw  new RuntimeException("工序类型已存在");
        }
        this.save(sgGxDO);
    }
 
    @Override
    public void update(SgGxDO sgGxDO) {
        if (sgGxMapper.selectByGxType(sgGxDO.getGxType())!= null){
            throw  new RuntimeException("工序类型已存在");
        }
        this.updateById(sgGxDO);
    }
 
    @Override
    public SgGxVO detail(Long id) {
        SgGxVO byId = (SgGxVO) this.getById(id);
        byId.setStepDOList(sgGxMapper.queryStepByIds(List.of(id)));
        return byId;
    }
}