shenyijian
2024-08-21 a4b8b53d4b59a5f9e5c4d19e5f4db7829b81e07d
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
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.DO.SgReportUserDO;
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.mapper.SgGxStepMapper;
import cn.gistack.sm.sg.mapper.SgProgressReportMapper;
import cn.gistack.sm.sg.service.SgGxService;
import cn.gistack.sm.sg.service.SgGxStepService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springblade.core.log.exception.ServiceException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
 
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;
 
    @Autowired
    private SgGxStepMapper sgGxStepMapper;
 
    @Autowired
    private SgGxStepService sgGxStepService;
 
    @Autowired
    private SgProgressReportMapper sgProgressReportMapper;
    @Override
    public IPage<SgGxVO> queryPageList(IPage<SgGxVO> page, ProjectSearchDTO searchDTO) {
        List<SgGxVO> list = sgGxMapper.queryPageList(page,searchDTO);
        if (CollectionUtils.isNotEmpty(list)){
            List<Long> ids = list.stream().map(SgGxDO::getId).collect(Collectors.toList());
            List<Long> userIds = list.stream().map(SgGxDO::getCreateUser).collect(Collectors.toList());
            List<Map<String,Object>> users = sgProgressReportMapper.getUserByIds(userIds);
            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) {
                    for (Map<String, Object> user : users) {
                        if (user.get("ID").equals(sgGxDO.getCreateUser())){
                            sgGxDO.setCreateUserName(user.get("REAL_NAME").toString());
                        }
                    }
                    List<SgGxStepDO> sgGxStepDOS = map.get(sgGxDO.getId());
                    if (CollectionUtils.isNotEmpty(sgGxStepDOS)){
                        sgGxDO.setStepDOList(sgGxStepDOS);
                        sgGxDO.setGxStepCount(sgGxStepDOS.size());
                    }
                }
            }
        }
        return page.setRecords(list);
    }
 
    @Override
    public void add(SgGxDO sgGxDO) {
        sgGxDO.setCreateUpdateTime();
        if (sgGxMapper.selectByGxType(sgGxDO.getGxType())!= null){
            throw  new ServiceException("工序类型已存在");
        }
        this.save(sgGxDO);
    }
 
    @Override
    public void update(SgGxDO sgGxDO) {
        sgGxDO.setCreateUpdateTime();
        SgGxDO one = sgGxMapper.selectByGxType(sgGxDO.getGxType());
        if (one != null && one.getId()!= sgGxDO.getId()  ){
            throw  new ServiceException("工序类型已存在");
        }
        this.updateById(sgGxDO);
    }
 
    @Override
    public SgGxVO detail(Long id) {
        SgGxVO byId = sgGxMapper.getById(id);
        List<SgGxStepDO> stepDOS = sgGxMapper.queryStepByIds(List.of(id));
        byId.setStepDOList(stepDOS);
        return byId;
    }
 
    @Override
    @Transactional
    public void delete(Long id) {
        SgGxDO byId = this.getById(id);
        List<SgGxStepDO> list = new LambdaQueryChainWrapper<>(sgGxStepMapper).eq(SgGxStepDO::getGxInfoId, id).list();
        if (CollectionUtils.isNotEmpty(list)){
            throw  new ServiceException("此工序存在工序步骤,不允许删除");
        }
        sgGxMapper.deleteById(id);
    }
}