双重预防项目-国泰新华二开定制版
kongzy
2024-08-14 135a322f44708b1187d37ea4b6859b5d82113e89
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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
package com.ruoyi.project.tr.specialCheck.service.impl;
 
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.ruoyi.common.utils.BeanCopyUtils;
import com.ruoyi.doublePrevention.entity.PreventRiskControlMeasure;
import com.ruoyi.doublePrevention.enums.ErrorCodes;
import com.ruoyi.doublePrevention.enums.ResultCodes;
import com.ruoyi.doublePrevention.vo.ResultVO;
import com.ruoyi.project.system.user.domain.User;
import com.ruoyi.project.tr.riskList.domain.RiskList;
import com.ruoyi.project.tr.riskList.service.IRiskListService;
import com.ruoyi.project.tr.specialCheck.domin.BO.*;
import com.ruoyi.project.tr.specialCheck.domin.TbSpecialCheckTaskLog;
import com.ruoyi.project.tr.specialCheck.mapper.*;
import com.ruoyi.project.tr.specialCheck.service.SpecialCheckTaskService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;
 
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.Date;
import java.util.List;
import java.util.UUID;
 
import static com.ruoyi.common.utils.security.ShiroUtils.getSysUser;
 
@Service
public class SpecialCheckTaskServiceImpl implements SpecialCheckTaskService {
 
    @Autowired
    private TbBaseCheckCompanyMapper companyTbRepository;
    @Autowired
    private TbBaseCheckItemMapper itemTbRepository;
    @Autowired
    private TbBaseCheckScoreMapper scoreTbRepository;
    @Autowired
    private TbBaseCheckTaskMapper taskTbRepository;
    @Autowired
    private TbSpecialCheckTaskLogMapper taskSpecialLogMapper;
    @Autowired
    private IRiskListService riskListService;
 
    @Override
    public ResultVO<List<TbSpecialCheckTaskLog>> selectSpecialCheckTaskLogPage(TbSpecialCheckTaskLogBO specialCheckTaskLogBO) {
        Integer pageIndex = specialCheckTaskLogBO.getPageNum();
        Integer pageSize = specialCheckTaskLogBO.getPageSize();
        if (pageIndex == 0 || pageSize == 0){
            return new ResultVO<>(ErrorCodes.REQUEST_PARAM_ERROR.getCode(),"当前页码或当前页显示数不能为0");
        }
 
        Page<TbSpecialCheckTaskLog> page = PageHelper.startPage(pageIndex, pageSize);
        taskSpecialLogMapper.selectSpecialCheckTaskLogPage(specialCheckTaskLogBO);
 
        Long total = page.getTotal();
        int count = total.intValue();
        List<TbSpecialCheckTaskLog> pageResult = null;
 
        ResultVO<List<TbSpecialCheckTaskLog>> resultVO = new ResultVO<>(ResultCodes.OK,pageResult);
 
        resultVO.setData(page.getResult());
        resultVO.setCount(count);
        resultVO.setCount((int) page.getTotal());
        resultVO.setPageNum(page.getPageNum());
        resultVO.setPageSize(page.getPageSize());
        return resultVO;
    }
 
    @Override
    public ResultVO<TbSpecialCheckTaskLog> addSpecialTask(TbSpecialCheckTaskLogEditBO taskLogEditBO) {
        User sysUser = getSysUser();
        ResultVO resultVO = new ResultVO<>();
        resultVO.setCode(ErrorCodes.REQUEST_PARAM_ERROR.getCode());
 
        TbSpecialCheckTaskLog tbSpecialCheckTaskLog = BeanCopyUtils.copyBean(taskLogEditBO, TbSpecialCheckTaskLog.class);
        if (tbSpecialCheckTaskLog.getHazardCode() == null){
            resultVO.setMsg("重大风险源不能为空");
            return resultVO;
        }
        RiskList infoByRiskListNum = riskListService.getInfoByRiskListNum(tbSpecialCheckTaskLog.getHazardCode());
        if (ObjectUtils.isEmpty(infoByRiskListNum)){
            resultVO.setMsg("请检查重大风险源是否存在");
            return resultVO;
        }
        if (tbSpecialCheckTaskLog.getTaskId() == null){
            resultVO.setMsg("专项任务不能为空");
            return resultVO;
        }
        if (tbSpecialCheckTaskLog.getCheckType() == null){
            resultVO.setMsg("检查类型不能为空");
            return resultVO;
        }
        if (tbSpecialCheckTaskLog.getResultStatus() == null){
            resultVO.setMsg("结果不能为空");
            return resultVO;
        }
        if (taskLogEditBO.getCheckDate() == null){
            resultVO.setMsg("检查日期不能为空");
            return resultVO;
        }
        LocalDateTime dateTime = LocalDateTime.now();
        String uuid = UUID.randomUUID().toString();
 
        tbSpecialCheckTaskLog.setId(uuid);
        tbSpecialCheckTaskLog.setHazardSource(infoByRiskListNum.getRiskListName());
        tbSpecialCheckTaskLog.setCompanyCode("652310082");
        tbSpecialCheckTaskLog.setCreateDate(dateTime);
        tbSpecialCheckTaskLog.setUpdateDate(dateTime);
        tbSpecialCheckTaskLog.setCreateBy(sysUser.getUserName());
        tbSpecialCheckTaskLog.setUpdateBy(sysUser.getUserName());
        tbSpecialCheckTaskLog.setReportStatus((byte) 1);
        tbSpecialCheckTaskLog.setReportTime(null);
        tbSpecialCheckTaskLog.setDeleted((byte) 0);
        tbSpecialCheckTaskLog.setCheckDate(LocalDateTime.ofInstant(taskLogEditBO.getCheckDate().toInstant(), ZoneId.systemDefault()));
 
        int saveResult = taskSpecialLogMapper.save(tbSpecialCheckTaskLog);
        if (saveResult == 0){
            resultVO.setCode(ResultCodes.SERVER_ADD_ERROR.getCode());
            resultVO.setMsg(ResultCodes.SERVER_ADD_ERROR.getDesc());
            return resultVO;
        }
        resultVO.setCode(ResultCodes.OK.getCode());
        resultVO.setMsg("新增任务成功");
        return resultVO;
    }
 
    @Override
    public TbSpecialCheckTaskLog getSpecialCheckTaskLogByIndexId(Long id) {
        return taskSpecialLogMapper.getSpecialCheckTaskLogByIndexId(id);
    }
 
    @Override
    public ResultVO<TbSpecialCheckTaskLog> updateSpecialCheckTaskLog(TbSpecialCheckTaskLogEditBO taskLogEditBO) {
        User sysUser = getSysUser();
        ResultVO resultVO = new ResultVO<>();
        resultVO.setCode(ErrorCodes.REQUEST_PARAM_ERROR.getCode());
 
        TbSpecialCheckTaskLogUpdateBO updateBO = BeanCopyUtils.copyBean(taskLogEditBO, TbSpecialCheckTaskLogUpdateBO.class);
 
        if (updateBO.getIndexId() == null){
            resultVO.setMsg("任务不能为空");
            return resultVO;
        }
        TbSpecialCheckTaskLog specialCheckTaskLogByIndexId = taskSpecialLogMapper.getSpecialCheckTaskLogByIndexId(updateBO.getIndexId());
        if (ObjectUtils.isEmpty(specialCheckTaskLogByIndexId)){
            resultVO.setMsg("任务不存在");
            return resultVO;
        }
        if (updateBO.getHazardCode() == null){
            resultVO.setMsg("重大风险源不能为空");
            return resultVO;
        }
        RiskList infoByRiskListNum = riskListService.getInfoByRiskListNum(updateBO.getHazardCode());
        if (ObjectUtils.isEmpty(infoByRiskListNum)){
            resultVO.setMsg("请检查重大风险源是否存在");
            return resultVO;
        }
        if (updateBO.getTaskId() == null){
            resultVO.setMsg("专项任务不能为空");
            return resultVO;
        }
        if (updateBO.getCheckType() == null){
            resultVO.setMsg("检查类型不能为空");
            return resultVO;
        }
        if (updateBO.getResultStatus() == null){
            resultVO.setMsg("结果不能为空");
            return resultVO;
        }
        if (taskLogEditBO.getCheckDate() == null){
            resultVO.setMsg("检查日期不能为空");
            return resultVO;
        }
 
        LocalDateTime dateTime = LocalDateTime.now();
        updateBO.setHazardSource(infoByRiskListNum.getRiskListName());
        updateBO.setUpdateDate(dateTime);
        updateBO.setUpdateBy(sysUser.getUserName());
        updateBO.setReportStatus((byte) 1);
        updateBO.setCheckDate(LocalDateTime.ofInstant(taskLogEditBO.getCheckDate().toInstant(), ZoneId.systemDefault()));
 
        int updateResult = taskSpecialLogMapper.updateSpecialCheckTaskLogById(updateBO);
        if (updateResult == 0){
            resultVO.setCode(ResultCodes.SERVER_UPDATE_ERROR.getCode());
            resultVO.setMsg(ResultCodes.SERVER_UPDATE_ERROR.getDesc());
            return resultVO;
        }
        resultVO.setCode(ResultCodes.OK.getCode());
        resultVO.setMsg("更新任务成功");
        return resultVO;
    }
 
    @Override
    public ResultVO<TbSpecialCheckTaskLog> deleteTbSpecialCheckTaskLog(TbSpecialCheckTaskLogUpdateBO updateBO) {
        User sysUser = getSysUser();
        ResultVO resultVO = new ResultVO<>();
        resultVO.setCode(ErrorCodes.REQUEST_PARAM_ERROR.getCode());
 
        if (updateBO.getIndexId() == null){
            resultVO.setMsg("任务为空,删除失败");
            return resultVO;
        }
        TbSpecialCheckTaskLog specialCheckTaskLogByIndexId = taskSpecialLogMapper.getSpecialCheckTaskLogByIndexId(updateBO.getIndexId());
        if (ObjectUtils.isEmpty(specialCheckTaskLogByIndexId)){
            resultVO.setMsg("任务不存在,删除失败");
            return resultVO;
        }
        TbSpecialCheckTaskLog tbSpecialCheckTaskLog = new TbSpecialCheckTaskLog();
        LocalDateTime dateTime = LocalDateTime.now();
 
        tbSpecialCheckTaskLog.setIndexId(updateBO.getIndexId());
        tbSpecialCheckTaskLog.setUpdateDate(dateTime);
        tbSpecialCheckTaskLog.setUpdateBy(sysUser.getUserName());
        tbSpecialCheckTaskLog.setReportStatus((byte) 1);
        tbSpecialCheckTaskLog.setDeleted((byte) 1);
 
        int deleteResult = taskSpecialLogMapper.deleteTbSpecialCheckTaskLog(tbSpecialCheckTaskLog);
        if (deleteResult == 0){
            resultVO.setCode(ResultCodes.SERVER_DEL_ERROR.getCode());
            resultVO.setMsg(ResultCodes.SERVER_DEL_ERROR.getDesc());
            return resultVO;
        }
        resultVO.setCode(ResultCodes.OK.getCode());
        resultVO.setMsg("删除成功");
        return resultVO;
    }
 
 
}