双重预防项目-国泰新华二开定制版
heheng
2025-06-19 46c37398a52d1dcf81788960ec90faa91249e77f
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
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
package com.ruoyi.doublePrevention.service.baseService.impl;
 
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.ruoyi.common.exception.BusinessException;
import com.ruoyi.common.utils.BeanCopyUtils;
import com.ruoyi.common.utils.text.Convert;
import com.ruoyi.doublePrevention.entity.PreventOverhaulLog;
import com.ruoyi.doublePrevention.entity.PreventReportConfig;
import com.ruoyi.doublePrevention.entity.dto.req.PreventOverhaulLogInsertReqBO;
import com.ruoyi.doublePrevention.entity.dto.req.PreventOverhaulLogReqBO;
import com.ruoyi.doublePrevention.entity.dto.req.PreventOverhaulLogUpdateReqBO;
import com.ruoyi.doublePrevention.entity.dto.resp.PreventOverhaulLogRespDTO;
import com.ruoyi.doublePrevention.enums.ErrorCodes;
import com.ruoyi.doublePrevention.enums.SyncEnum;
import com.ruoyi.doublePrevention.repository.PreventOverhaulLogRepository;
import com.ruoyi.doublePrevention.repository.param.HandlerReportParam;
import com.ruoyi.doublePrevention.service.baseService.PreventOverhaulLogService;
import com.ruoyi.doublePrevention.service.baseService.PreventReportConfigService;
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 org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;
 
import java.util.Date;
import java.util.List;
import java.util.UUID;
 
import static com.ruoyi.common.utils.security.ShiroUtils.getSysUser;
 
@Service
public class PreventOverhaulLogServiceImpl implements PreventOverhaulLogService {
 
    @Autowired
    private PreventOverhaulLogRepository overhaulLogRepository;
    @Autowired
    private PreventReportConfigService preventReportConfigService;
    @Autowired
    private IRiskListService iRiskListService;
 
 
    @Override
    public ResultVO<PreventOverhaulLogRespDTO> selectOverhaulLogPage(PreventOverhaulLogReqBO overhaulLogReqBO) {
 
        ResultVO resultVO = new ResultVO<>();
 
        if (ObjectUtils.isEmpty(overhaulLogReqBO.getPageSize())){
            throw new BusinessException("分页信息不能为空");
        }
        if (ObjectUtils.isEmpty(overhaulLogReqBO.getPageNum())){
            throw new BusinessException("分页信息不能为空");
        }
        Integer pageIndex = overhaulLogReqBO.getPageNum();
        Integer pageSize = overhaulLogReqBO.getPageSize();
 
        Page<PreventOverhaulLog> page = PageHelper.startPage(pageIndex, pageSize);
        List<PreventOverhaulLog> preventOverhaulLogs = overhaulLogRepository.selectOverhaulLogPage(overhaulLogReqBO);
        List<PreventOverhaulLog> result = page.getResult();
 
        List<PreventOverhaulLogRespDTO> preventOverhaulLogRespDTOS = BeanCopyUtils.copyBeanList(result, PreventOverhaulLogRespDTO.class);
 
        List<RiskList> riskUnitLists = iRiskListService.getRiskUnitLists();
        for (PreventOverhaulLogRespDTO overhaulLog : preventOverhaulLogRespDTOS) {
            for (RiskList riskUnit : riskUnitLists) {
                if (overhaulLog.getRiskUnitId() == riskUnit.getRiskListId()){
                    overhaulLog.setRiskUnitName(riskUnit.getRiskListName());
                }
            }
        }
 
        resultVO.setData(preventOverhaulLogRespDTOS);
        resultVO.setCount((int) page.getTotal());
        resultVO.setPageNum(page.getPageNum());
        resultVO.setPageSize(page.getPageSize());
 
        return resultVO;
    }
 
    @Override
    public ResultVO<PreventOverhaulLog> savePreventOverhaulLog(PreventOverhaulLogInsertReqBO insertReqBO) {
 
        User sysUser = getSysUser();
        ResultVO resultVO = new ResultVO<>();
        resultVO.setCode(ErrorCodes.REQUEST_PARAM_ERROR.getCode());
 
 
        if (ObjectUtils.isEmpty(insertReqBO.getRiskUnitId())){
            throw new RuntimeException("安全风险分析单元为空");
        }
        if (ObjectUtils.isEmpty(insertReqBO.getStopStartTime())){
            throw new RuntimeException("装置停用或者检维修开始时间为空");
        }
        if (ObjectUtils.isEmpty(insertReqBO.getStopEndTime())){
            throw new RuntimeException("装置停用或者检维修结束时间为空");
        }
        if (insertReqBO.getStopReason().isEmpty()){
            throw new RuntimeException("停用原因为空");
        }
 
        Date date = new Date();
        String uuid = UUID.randomUUID().toString();
 
        PreventOverhaulLog preventOverhaulLog = BeanCopyUtils.copyBean(insertReqBO, PreventOverhaulLog.class);
 
        preventOverhaulLog.setUuid(uuid);
        preventOverhaulLog.setDeleteStatus((byte) 0);
        preventOverhaulLog.setCreateByUserName(sysUser.getUserName());
        preventOverhaulLog.setGmtCreate(date);
        preventOverhaulLog.setLastEditUserName(sysUser.getUserName());
        preventOverhaulLog.setGmtModitify(date);
 
        //todo 对所属企业id和uuid没有进行设置
        PreventReportConfig reportConfigById = preventReportConfigService.getReportConfigById(SyncEnum.REPORT_CONFIG_RISK_ANA_UNIT.getCode());
        //设置上报时间为空
        preventOverhaulLog.setReportTime(null);
        //设置本条数据上报更新时间
        preventOverhaulLog.setUpdateReportDataTime(date);
        //读取上报主配置,进行任务记录上报配置,如果开启上报功能,且设置为自动上报,开启上报相关配置
        if (reportConfigById.getReportState() == SyncEnum.REPORT_ON.getCode()
                && reportConfigById.getReportType() == SyncEnum.REPORT_HAND_EXEC_CONFIG.getCode()){
            //设置上报状态为-等待上报
            preventOverhaulLog.setReportStatus(SyncEnum.SYNC_WAIT_EXEC.getCode());
            //设置本条数据上报开关为-开启
            preventOverhaulLog.setReportSwitch(SyncEnum.REPORT_ON.getCode());
            //其他情况默认不开启上报数据,如果是手动上报,可对单条数据进行操作
        }else {
            //设置上报状态为-不上报
            preventOverhaulLog.setReportStatus(SyncEnum.SYNC_NOT_EXEC.getCode());
            //设置本条数据上报开关为-关闭
            preventOverhaulLog.setReportSwitch(SyncEnum.REPORT_OFF.getCode());
        }
 
        int result = overhaulLogRepository.savePreventOverhaulLog(preventOverhaulLog);
 
        resultVO.setCount(result);
        resultVO.setCode("200");
        resultVO.setMsg("保存成功");
 
        return resultVO;
    }
 
    /**
     * 查询 by id
     * */
    @Override
    public PreventOverhaulLog getOverhaulLogById(Long id) {
        return overhaulLogRepository.getOverhaulLogById(id);
    }
 
    /**
     * 修改保存
     * */
    @Override
    public ResultVO<PreventOverhaulLog> updateOverhaulLog(PreventOverhaulLogUpdateReqBO updateReqBO) {
 
 
        User sysUser = getSysUser();
        ResultVO resultVO = new ResultVO<>();
        resultVO.setCode(ErrorCodes.REQUEST_PARAM_ERROR.getCode());
 
        resultVO.setCode("200");
        resultVO.setMsg("保存成功");
 
        if (ObjectUtils.isEmpty(updateReqBO.getId())){
            throw new RuntimeException("所选记录不能为空");
        }
        PreventOverhaulLog overhaulLogById = overhaulLogRepository.getOverhaulLogById(updateReqBO.getId());
        if (ObjectUtils.isEmpty(overhaulLogById)){
            throw new RuntimeException("记录不存在或已被被删除");
        }
        if (ObjectUtils.isEmpty(updateReqBO.getRiskUnitId())){
            throw new RuntimeException("安全风险分析单元为空");
        }
        if (ObjectUtils.isEmpty(updateReqBO.getStopStartTime())){
            throw new RuntimeException("装置停用或者检维修开始时间为空");
        }
        if (ObjectUtils.isEmpty(updateReqBO.getStopEndTime())){
            throw new RuntimeException("装置停用或者检维修结束时间为空");
        }
        if (updateReqBO.getStopReason().isEmpty()){
            throw new RuntimeException("停用原因为空");
        }
 
        Date date = new Date();
        String uuid = UUID.randomUUID().toString();
 
        PreventOverhaulLog preventOverhaulLog = BeanCopyUtils.copyBean(updateReqBO, PreventOverhaulLog.class);
 
        preventOverhaulLog.setUuid(uuid);
        preventOverhaulLog.setDeleteStatus((byte) 0);
        preventOverhaulLog.setLastEditUserName(sysUser.getUserName());
        preventOverhaulLog.setGmtModitify(date);
        preventOverhaulLog.setLastEditUserName(sysUser.getUserName());
        preventOverhaulLog.setGmtModitify(date);
 
 
        //todo 对所属企业id和uuid没有进行设置
        PreventReportConfig reportConfigById = preventReportConfigService.getReportConfigById(SyncEnum.REPORT_CONFIG_RISK_ANA_UNIT.getCode());
        //设置上报时间为空
        preventOverhaulLog.setReportTime(null);
        //设置本条数据上报更新时间
        preventOverhaulLog.setUpdateReportDataTime(date);
        //读取上报主配置,进行任务记录上报配置,如果开启上报功能,且设置为自动上报,开启上报相关配置
        if (reportConfigById.getReportState() == SyncEnum.REPORT_ON.getCode()
                && reportConfigById.getReportType() == SyncEnum.REPORT_HAND_EXEC_CONFIG.getCode()){
            //设置上报状态为-等待上报
            preventOverhaulLog.setReportStatus(SyncEnum.SYNC_WAIT_EXEC.getCode());
            //设置本条数据上报开关为-开启
            preventOverhaulLog.setReportSwitch(SyncEnum.REPORT_ON.getCode());
            //其他情况默认不开启上报数据,如果是手动上报,可对单条数据进行操作
        }else {
            //设置上报状态为-不上报
            preventOverhaulLog.setReportStatus(SyncEnum.SYNC_NOT_EXEC.getCode());
            //设置本条数据上报开关为-关闭
            preventOverhaulLog.setReportSwitch(SyncEnum.REPORT_OFF.getCode());
        }
 
        int result = overhaulLogRepository.updateOverhaulLog(preventOverhaulLog);
        if (result < 1){
            throw new RuntimeException("操作失败");
        }
 
        resultVO.setCount(result);
 
        return resultVO;
    }
 
    @Override
    public int deleteOverhaulLogByIds(String ids) {
        return overhaulLogRepository.deleteOverhaulLogByIds(Convert.toStrArray(ids));
    }
 
    @Override
    public List<PreventOverhaulLog> listReportOverhaulLog() {
        return overhaulLogRepository.listReportOverhaulLog();
    }
 
    @Override
    public int updateOverhaulReportStatus(HandlerReportParam handlerReportParam) {
        return overhaulLogRepository.updateOverhaulReportStatus(handlerReportParam);
    }
 
 
}