ke
2024-07-19 08a962d2925baa255207fdf979e6fee794f1773b
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
package cn.gistack.sm.sg.service.impl;
 
import cn.gistack.sm.sg.DO.SgGxRoleDO;
import cn.gistack.sm.sg.DO.SgGxStepDO;
import cn.gistack.sm.sg.DO.SgProgressReportDO;
import cn.gistack.sm.sg.DTO.ProjectSearchDTO;
import cn.gistack.sm.sg.VO.SgGxRoleVO;
import cn.gistack.sm.sg.mapper.SgGxRoleMapper;
import cn.gistack.sm.sg.mapper.SgGxStepMapper;
import cn.gistack.sm.sg.mapper.SgProgressReportMapper;
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 org.springblade.core.log.exception.ServiceException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.transaction.annotation.Transactional;
 
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
 
/**
 * <p>
 * 施工工序步骤表 服务实现类
 * </p>
 *
 * @author shenyijian
 * @since 2024-06-13 15:46:18
 */
@Service
public class SgGxStepServiceImpl extends ServiceImpl<SgGxStepMapper, SgGxStepDO> implements SgGxStepService {
    @Autowired
    private SgGxStepMapper sgGxStepMapper;
    @Autowired
    private SgGxRoleMapper sgGxRoleMapper;
 
    @Autowired
    private SgProgressReportMapper sgProgressReportMapper;
 
    @Override
    public void add(SgGxStepDO sgGxStepDO) {
    List<SgGxStepDO> list= sgGxStepMapper.selectByGxInfoId(sgGxStepDO.getGxInfoId());
    if (CollectionUtils.isNotEmpty(list)){
        if (Integer.parseInt(sgGxStepDO.getGxStepNum()) - Integer.parseInt(list.get(0).getGxStepNum()) != 1){
            throw  new ServiceException("请按顺序配置工序");
        }
    }
    this.save(sgGxStepDO);
    }
 
    @Override
    public void updateOne(SgGxStepDO sgGxStepDO) {
        this.updateById(sgGxStepDO);
    }
 
    @Override
    public void delete(String id) {
        SgGxStepDO sgGxStepDO = sgGxStepMapper.selectById(id);
        if (!new LambdaQueryChainWrapper<>(sgGxRoleMapper).eq(SgGxRoleDO::getGxStepId,id).list().isEmpty()){
            throw  new ServiceException(sgGxStepDO.getGxStepName()+ "已绑定角色,无法删除");
        }
        List<SgGxStepDO> list= sgGxStepMapper.selectByGxInfoId(sgGxStepDO.getGxInfoId());
        if (!sgGxStepDO.getGxStepNum().equals(list.get(0).getGxStepNum())){
            throw  new ServiceException("请按顺序删除工序步骤");
        }
        this.removeById(id);
    }
 
    @Override
    public IPage<SgGxStepDO> queryPageList(IPage<SgGxStepDO> page, ProjectSearchDTO searchDTO) {
        List<SgGxStepDO> list =  sgGxStepMapper.queryPageList(page,searchDTO);
        return page.setRecords(list);
    }
 
    /**
     * 新增工序角色配置逻辑
     * @param sgGxRoleVO
     */
    @Override
    public void insertSgGxRole(SgGxRoleVO sgGxRoleVO){
 
 
        if (sgGxRoleVO.getGxStepId()==null){
            throw  new ServiceException("工序步骤参数错误");
        }
        if (sgGxRoleVO.getGxDeviceType()==null){
            throw  new ServiceException("工序类型参数错误");
        }
 
        List<SgGxRoleDO> sgGxRoleDOS = sgGxRoleMapper.selectSgGxRole(sgGxRoleVO.getGxDeviceType(), sgGxRoleVO.getGxStepId());
        if (sgGxRoleDOS==null||sgGxRoleDOS.size()>0){
            throw  new ServiceException("已存在相同的工序角色配置");
        }
        List<SgGxRoleDO> sgGxRoles=new ArrayList<>();
 
        if (sgGxRoleVO.getRoleIds()==null||sgGxRoleVO.getRoleIds().size()==0){
            throw  new ServiceException("工序角色参数错误");
        }
        List<String> roleIds = sgGxRoleVO.getRoleIds();
        for (int i = 0; i <roleIds.size() ; i++) {
            SgGxRoleDO sgGxRoleDO=new SgGxRoleDO();
            sgGxRoleDO.setGxDeviceType(sgGxRoleVO.getGxDeviceType());
            sgGxRoleDO.setGxStepId(sgGxRoleVO.getGxStepId());
            sgGxRoleDO.setRoleId(roleIds.get(i));
            sgGxRoleDO.setSgOrder(sgGxRoleVO.getOrders().get(i));
            sgGxRoles.add(sgGxRoleDO);
        }
        sgGxRoleMapper.insertBach(sgGxRoles);
    }
 
 
    /**
     * 更新工序角色配置
     * @param sgGxRoleVO
     */
    @Override
@Transactional
public void updateSgGxRole(SgGxRoleVO sgGxRoleVO){
        String gxStepId = sgGxRoleVO.getGxStepId();
        List<SgProgressReportDO> reportDOS = new LambdaQueryChainWrapper<>(sgProgressReportMapper).eq(SgProgressReportDO::getGxStepId, gxStepId).list();
        List<SgGxRoleDO> list = new LambdaQueryChainWrapper<>(sgGxRoleMapper).eq(SgGxRoleDO::getGxStepId, gxStepId).orderByAsc(SgGxRoleDO::getSgOrder).list();
        List<String> roles = list.stream().map(SgGxRoleDO::getRoleId).map(Object::toString).collect(Collectors.toList());
        List<Integer> orders  = list.stream().map(SgGxRoleDO::getSgOrder).collect(Collectors.toList());
        if (!reportDOS.isEmpty()){
            if (! roles.equals(sgGxRoleVO.getRoleIds()) || ! orders.equals(sgGxRoleVO.getOrders()))    {
                throw  new ServiceException("此配置已有上报记录,不允许修改");
            }
        }
        if (sgGxRoleVO.getGxStepId()==null){
        throw  new ServiceException("工序步骤参数错误");
    }
    if (sgGxRoleVO.getGxDeviceType()==null){
        throw  new ServiceException("工序类型参数错误");
    }
 
    List<SgGxRoleDO> sgGxRoleDOS = sgGxRoleMapper.selectSgGxRole(sgGxRoleVO.getGxDeviceType(), sgGxRoleVO.getGxStepId());
    if (sgGxRoleDOS==null||sgGxRoleDOS.size()>0){
        //删除原来的
        sgGxRoleMapper.deleteSgGxRoleDOs(sgGxRoleVO.getGxDeviceType(),sgGxRoleVO.getGxStepId());
    }
    List<SgGxRoleDO> sgGxRoles=new ArrayList<>();
 
    if (sgGxRoleVO.getRoleIds()==null||sgGxRoleVO.getRoleIds().size()==0){
        throw  new ServiceException("工序角色参数错误");
    }
    List<String> roleIds = sgGxRoleVO.getRoleIds();
    for (int i = 0; i <roleIds.size() ; i++) {
        SgGxRoleDO sgGxRoleDO=new SgGxRoleDO();
        sgGxRoleDO.setGxDeviceType(sgGxRoleVO.getGxDeviceType());
        sgGxRoleDO.setGxStepId(sgGxRoleVO.getGxStepId());
        sgGxRoleDO.setRoleId(roleIds.get(i));
        sgGxRoleDO.setSgOrder(sgGxRoleVO.getOrders().get(i));
        sgGxRoles.add(sgGxRoleDO);
    }
    sgGxRoleMapper.insertBach(sgGxRoles);
}
 
    /**
     * 获取绑定的角色进行回显
     *
     * @param gxDeviceType
     * @param gxStepId
     * @return
     */
    @Override
    public List<String> getSgGxRoles(String gxDeviceType, String gxStepId) {
        return     sgGxRoleMapper.getSgGxRoles(gxDeviceType, gxStepId);
 
    }
 
    @Override
    public List<SgGxStepDO> sgGxStepList() {
        return sgGxStepMapper.getDEviceGXtwo();
    }
}