16639036659
2024-05-14 964dd88319269c16d4ebb99007a954b51e625ef2
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
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
package com.gkhy.labRiskManage.domain.basic.service.impl;
 
import com.gkhy.labRiskManage.api.controller.basic.dto.repDto.OldRiskAssessQueryReqBO;
import com.gkhy.labRiskManage.api.controller.basic.dto.respDto.OldRiskAssessQueryRespDTO;
import com.gkhy.labRiskManage.commons.domain.SearchResult;
import com.gkhy.labRiskManage.commons.enums.ResultCode;
import com.gkhy.labRiskManage.commons.enums.StatusEnum;
import com.gkhy.labRiskManage.commons.exception.BusinessException;
import com.gkhy.labRiskManage.commons.utils.BeanCopyUtils;
import com.gkhy.labRiskManage.domain.account.model.dto.UserInfoDomainDTO;
import com.gkhy.labRiskManage.domain.account.service.UserDomainService;
import com.gkhy.labRiskManage.domain.basic.entity.OldRiskAssess;
import com.gkhy.labRiskManage.domain.basic.repository.jpa.OldRiskAssessRepository;
import com.gkhy.labRiskManage.domain.basic.service.OldRiskAssessService;
import org.apache.poi.hssf.usermodel.*;
import org.apache.poi.ss.usermodel.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Sort;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.ObjectUtils;
import org.springframework.web.multipart.MultipartFile;
 
import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.text.NumberFormat;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
 
 
/**
 * 基础仪器设备表
 */
@Service
public class OldRiskAssessServiceImpl implements OldRiskAssessService {
 
    @Autowired
    private UserDomainService userDomainService;
 
    @Autowired
    private OldRiskAssessRepository repository;
 
 
 
    @Override
    public int insertOldRiskAssess(Long currentUserId, OldRiskAssess oldRiskAssess) {
 
        if (ObjectUtils.isEmpty(oldRiskAssess)){
            throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR.getCode() ,"要保存的数据不能为空");
        }
        if (ObjectUtils.isEmpty(oldRiskAssess.getRegion())){
            throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR.getCode() ,"区域不能为空");
        }
        if (ObjectUtils.isEmpty(oldRiskAssess.getPotentialAccident())){
            throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR.getCode() ,"潜在事故不能为空");
        }
        if (ObjectUtils.isEmpty(oldRiskAssess.getDangerReason())){
            throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR.getCode() ,"危险、危害因素不能为空");
        }
        if (ObjectUtils.isEmpty(oldRiskAssess.getTriggerFactor())){
            throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR.getCode() ,"触发条件不能为空");
        }
        if (ObjectUtils.isEmpty(oldRiskAssess.getAccidentResult())){
            throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR.getCode() ,"事故后果不能为空");
        }
        if (ObjectUtils.isEmpty(oldRiskAssess.getL())){
            throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR.getCode() ,"L数值不能为空");
        }
        if (ObjectUtils.isEmpty(oldRiskAssess.getD())){
            throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR.getCode() ,"D数值不能为空");
        }
        if (ObjectUtils.isEmpty(oldRiskAssess.getC())){
            throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR.getCode() ,"C数值不能为空");
        }
        if (ObjectUtils.isEmpty(oldRiskAssess.getE())){
            throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR.getCode() ,"E数值不能为空");
        }
        if (ObjectUtils.isEmpty(oldRiskAssess.getDangerLevel())){
            throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR.getCode() ,"危险等级不能为空");
        }
        if (ObjectUtils.isEmpty(oldRiskAssess.getControlMeasure())){
            throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR.getCode() ,"现有安全控制措施不能为空");
        }
        if (ObjectUtils.isEmpty(oldRiskAssess.getControlLevel())){
            throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR.getCode() ,"管控层级不能为空");
        }
 
        LocalDateTime nowDate = LocalDateTime.now();
        oldRiskAssess.setUpdateTime(nowDate);
        oldRiskAssess.setCreateTime(nowDate);
        oldRiskAssess.setCreateByUserId(currentUserId);
        oldRiskAssess.setUpdateByUserId(currentUserId);
        oldRiskAssess.setDeleteStatus((byte)0);
 
        OldRiskAssess saveResult = repository.save(oldRiskAssess);
        if (ObjectUtils.isEmpty(saveResult)){
            return StatusEnum.FAIL.getCode();
        }
 
        return StatusEnum.SUCCESS.getCode();
    }
 
    @Override
    public int updateOldRiskAssess(Long currentUserId, OldRiskAssess oldRiskAssess) {
 
        OldRiskAssess oldRiskAssessById = repository.getOldRiskAssessById(oldRiskAssess.getId());
        if (ObjectUtils.isEmpty(oldRiskAssessById)){
            throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR.getCode() ,"要修改的数据不存在,或已被删除");
        }
        if (ObjectUtils.isEmpty(oldRiskAssess.getRegion())){
            throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR.getCode() ,"区域不能为空");
        }
        if (ObjectUtils.isEmpty(oldRiskAssess.getPotentialAccident())){
            throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR.getCode() ,"潜在事故不能为空");
        }
        if (ObjectUtils.isEmpty(oldRiskAssess.getDangerReason())){
            throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR.getCode() ,"危险、危害因素不能为空");
        }
        if (ObjectUtils.isEmpty(oldRiskAssess.getTriggerFactor())){
            throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR.getCode() ,"触发条件不能为空");
        }
        if (ObjectUtils.isEmpty(oldRiskAssess.getAccidentResult())){
            throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR.getCode() ,"事故后果不能为空");
        }
        if (ObjectUtils.isEmpty(oldRiskAssess.getL())){
            throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR.getCode() ,"L数值不能为空");
        }
        if (ObjectUtils.isEmpty(oldRiskAssess.getD())){
            throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR.getCode() ,"D数值不能为空");
        }
        if (ObjectUtils.isEmpty(oldRiskAssess.getC())){
            throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR.getCode() ,"C数值不能为空");
        }
        if (ObjectUtils.isEmpty(oldRiskAssess.getE())){
            throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR.getCode() ,"E数值不能为空");
        }
        if (ObjectUtils.isEmpty(oldRiskAssess.getDangerLevel())){
            throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR.getCode() ,"危险等级不能为空");
        }
        if (ObjectUtils.isEmpty(oldRiskAssess.getControlMeasure())){
            throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR.getCode() ,"现有安全控制措施不能为空");
        }
        if (ObjectUtils.isEmpty(oldRiskAssess.getControlLevel())){
            throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR.getCode() ,"管控层级不能为空");
        }
 
        LocalDateTime nowDate = LocalDateTime.now();
        oldRiskAssessById.setUpdateTime(nowDate);
        oldRiskAssessById.setDeleteStatus((byte)0);
        oldRiskAssessById.setUpdateByUserId(currentUserId);
        oldRiskAssessById.setUpdateTime(nowDate);
 
        oldRiskAssessById.setRegion(oldRiskAssess.getRegion());
        oldRiskAssessById.setPotentialAccident(oldRiskAssess.getPotentialAccident());
        oldRiskAssessById.setDangerReason(oldRiskAssess.getDangerReason());
        oldRiskAssessById.setTriggerFactor(oldRiskAssess.getTriggerFactor());
        oldRiskAssessById.setAccidentResult(oldRiskAssess.getAccidentResult());
        oldRiskAssessById.setL(oldRiskAssess.getL());
        oldRiskAssessById.setE(oldRiskAssess.getE());
        oldRiskAssessById.setD(oldRiskAssess.getD());
        oldRiskAssessById.setC(oldRiskAssess.getC());
        oldRiskAssessById.setDangerLevel(oldRiskAssess.getDangerLevel());
        oldRiskAssessById.setControlMeasure(oldRiskAssess.getControlMeasure());
        oldRiskAssessById.setControlLevel(oldRiskAssess.getControlLevel());
 
        OldRiskAssess saveResult = repository.save(oldRiskAssessById);
        if (ObjectUtils.isEmpty(saveResult)){
            return StatusEnum.FAIL.getCode();
        }
 
        return StatusEnum.SUCCESS.getCode();
    }
 
    @Override
    public int deleteOldRiskAssess(Long currentUserId, Long id) {
        if (currentUserId < 0){
            throw new BusinessException(this.getClass(), ResultCode.BUSINESS_ERROR_NOT_ALLOWED.getCode() ,"当前用户无效,请重新登陆");
        }
        if (ObjectUtils.isEmpty(id)){
            throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode() ,"请选择正常的数据进行删除");
        }
        OldRiskAssess oldRiskAssessById = repository.getOldRiskAssessById(id);
        if (ObjectUtils.isEmpty(oldRiskAssessById)){
            throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR.getCode() ,"要删除的数据不存在,或已被删除");
        }
        UserInfoDomainDTO userInfoById = userDomainService.getUserInfoById(currentUserId);
 
        LocalDateTime date = LocalDateTime.now();
        //设置数据为删除
        oldRiskAssessById.setDeleteStatus(StatusEnum.DELETED.getCode().byteValue());
        oldRiskAssessById.setUpdateByUserId(userInfoById.getId());
        oldRiskAssessById.setUpdateTime(date);
 
        OldRiskAssess deleteResult = repository.save(oldRiskAssessById);
 
        if (ObjectUtils.isEmpty(deleteResult)){
            return StatusEnum.FAIL.getCode();
        }
 
        return StatusEnum.SUCCESS.getCode();
    }
 
    @Transactional
    @Override
    public int importOldRiskAssess(Long currentUserId, MultipartFile file) {
 
        if (currentUserId < 0){
            throw new BusinessException(this.getClass(), ResultCode.BUSINESS_ERROR_NOT_ALLOWED.getCode() ,"当前用户无效,请重新登陆");
        }
        //根据路径获取这个操作excel的实例
        HSSFWorkbook wb = null;
        List<OldRiskAssess> list = new ArrayList<>();
        try {
            wb = new HSSFWorkbook(file.getInputStream());
            //根据页面index 获取sheet页
            HSSFSheet sheet = wb.getSheetAt(0);
            HSSFRow row = null;
            //循环sheet页中数据从第二行开始,第一行是标题
 
            LocalDateTime nowDate = LocalDateTime.now();
            for (int i = 1; i <= sheet.getPhysicalNumberOfRows()-1; i++) {
                //获取每一行数据
                row = sheet.getRow(i);
                OldRiskAssess oldRiskAssess = new OldRiskAssess();
                oldRiskAssess.setUpdateTime(nowDate);
                oldRiskAssess.setCreateTime(nowDate);
                oldRiskAssess.setCreateByUserId(currentUserId);
                oldRiskAssess.setUpdateByUserId(currentUserId);
                oldRiskAssess.setDeleteStatus((byte)0);
 
                if (ObjectUtils.isEmpty(row.getCell(1))){
                    throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR.getCode() , "第"+ (i+1) +"行:区域不能为空");
                }
                if (ObjectUtils.isEmpty(row.getCell(2))){
                    throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR.getCode() ,"第"+ (i+1) +"行:潜在事故不能为空");
                }
                if (ObjectUtils.isEmpty(row.getCell(3))){
                    throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR.getCode() ,"第"+ (i+1) +"行:危险、危害因素不能为空");
                }
                if (ObjectUtils.isEmpty(row.getCell(4))){
                    throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR.getCode() ,"第"+ (i+1) +"行:触发条件不能为空");
                }
                if (ObjectUtils.isEmpty(row.getCell(5))){
                    throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR.getCode() ,"第"+ (i+1) +"行:事故后果不能为空");
                }
                if (ObjectUtils.isEmpty(row.getCell(6))){
                    throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR.getCode() ,"第"+ (i+1) +"行:L数值不能为空");
                }
                if (ObjectUtils.isEmpty(row.getCell(7))){
                    throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR.getCode() ,"第"+ (i+1) +"行:D数值不能为空");
                }
                if (ObjectUtils.isEmpty(row.getCell(8))){
                    throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR.getCode() ,"第"+ (i+1) +"行:C数值不能为空");
                }
                if (ObjectUtils.isEmpty(row.getCell(9))){
                    throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR.getCode() ,"第"+ (i+1) +"行:E数值不能为空");
                }
                if (ObjectUtils.isEmpty(row.getCell(10))){
                    throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR.getCode() ,"第"+ (i+1) +"行:危险等级不能为空");
                }
                if (ObjectUtils.isEmpty(row.getCell(11))){
                    throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR.getCode() ,"第"+ (i+1) +"行:现有安全控制措施不能为空");
                }
                if (ObjectUtils.isEmpty(row.getCell(12))){
                    throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR.getCode() ,"第"+ (i+1) +"行:管控层级不能为空");
                }
 
                oldRiskAssess.setRegion(row.getCell(1).toString());
                oldRiskAssess.setPotentialAccident(row.getCell(2).toString());
                oldRiskAssess.setDangerReason(row.getCell(3).toString());
                oldRiskAssess.setTriggerFactor(row.getCell(4).toString());
                oldRiskAssess.setAccidentResult(row.getCell(5).toString());
                oldRiskAssess.setDangerLevel(row.getCell(10).toString());
                oldRiskAssess.setControlMeasure(row.getCell(11).toString());
                oldRiskAssess.setControlLevel(row.getCell(12).toString());
 
                double cellL = row.getCell(6).getNumericCellValue();
                double cellE = row.getCell(7).getNumericCellValue();
                double cellC = row.getCell(8).getNumericCellValue();
                double cellD = row.getCell(9).getNumericCellValue();
                NumberFormat nf = NumberFormat.getInstance();
                String L = nf.format(cellL);
                String E = nf.format(cellE);
                String C = nf.format(cellC);
                String D = nf.format(cellD);
//                if (L.indexOf(",") >= 0) {
//                    L = L.replace(",", "");
//                }
                oldRiskAssess.setL(L);
                oldRiskAssess.setE(E);
                oldRiskAssess.setC(C);
                oldRiskAssess.setD(D);
 
                list.add(oldRiskAssess);
            }
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
 
        for (OldRiskAssess oldRiskAssess : list) {
            OldRiskAssess save = repository.save(oldRiskAssess);
            if (ObjectUtils.isEmpty(save)){
                throw new BusinessException(this.getClass(), ResultCode.BUSINESS_ERROR_NOT_ALLOWED.getCode() ,"导入出错");
            }
        }
 
        return StatusEnum.SUCCESS.getCode();
    }
 
    @Override
    public int exportOldRiskAssess(Long currentUserId, OldRiskAssessQueryReqBO queryReqDO) {
 
        //组装查询条件
        Specification<OldRiskAssess> specification = new Specification<OldRiskAssess>() {
            @Override
            public Predicate toPredicate(Root<OldRiskAssess> root, CriteriaQuery<?> query, CriteriaBuilder criteriaBuilder) {
                List<Predicate> predicateList = new ArrayList<>();
                if(queryReqDO.getRegion() != null && !queryReqDO.getRegion().equals("")){
                    predicateList.add(criteriaBuilder.like(root.get("region"),'%'+ queryReqDO.getRegion() +'%'));
                }
                if(queryReqDO.getPotentialAccident() != null && !queryReqDO.getPotentialAccident().equals("")){
                    predicateList.add(criteriaBuilder.like(root.get("potentialAccident"),'%'+queryReqDO.getPotentialAccident() +'%'));
                }
                if(queryReqDO.getDangerReason() != null && !queryReqDO.getDangerReason().equals("")){
                    predicateList.add(criteriaBuilder.like(root.get("dangerReason"),'%'+queryReqDO.getDangerReason() +'%'));
                }
                if(queryReqDO.getTriggerFactor() != null && !queryReqDO.getTriggerFactor().equals("")){
                    predicateList.add(criteriaBuilder.like(root.get("triggerFactor"),'%'+queryReqDO.getTriggerFactor() +'%'));
                }
                if(queryReqDO.getAccidentResult() != null && !queryReqDO.getAccidentResult().equals("")){
                    predicateList.add(criteriaBuilder.like(root.get("accidentResult"),'%'+queryReqDO.getAccidentResult() +'%'));
                }
                if(queryReqDO.getDangerLevel() != null && !queryReqDO.getDangerLevel().equals("")){
                    predicateList.add(criteriaBuilder.like(root.get("dangerLevel"),'%'+queryReqDO.getDangerLevel() +'%'));
                }
                if(queryReqDO.getControlMeasure() != null && !queryReqDO.getControlMeasure().equals("")){
                    predicateList.add(criteriaBuilder.like(root.get("controlMeasure"),'%'+queryReqDO.getControlMeasure() +'%'));
                }
                if(queryReqDO.getControlLevel() != null && !queryReqDO.getControlLevel().equals("")){
                    predicateList.add(criteriaBuilder.like(root.get("controlLevel"),'%'+queryReqDO.getControlLevel() +'%'));
                }
                predicateList.add(criteriaBuilder.equal(root.get("deleteStatus"),StatusEnum.DELETE_NOT.getCode()));
                //返回组装的条件
                return criteriaBuilder.and(predicateList.toArray(predicateList.toArray(new Predicate[0])));
            }
        };
        List<OldRiskAssess> list = repository.findAll(specification);
 
        //创建工作薄
        HSSFWorkbook workbook = new HSSFWorkbook();
        //创建sheet
        HSSFSheet sheet=workbook.createSheet("评分标准");
        //创建第一行
        HSSFRow  header = sheet.createRow(0);
        //创建单元格并插入表头
        HSSFCell cell = null;
        String[] infos={"编号","区域","潜在事故","危险、有害因素","触发条件","事故后果","L","E","C","D",
                "危险等级","现有安全控制措施(工程技术、管理、培训教育、个体防护、应急处置)","管控层级(公司级、部门级、岗位级)"};
        for(int i = 0; i < infos.length; i++){
            cell = header.createCell(i);
            cell.setCellValue(infos[i]);
        }
 
        //写入数据
        for (int j = 1; j < list.size(); j++) {
            OldRiskAssess oldRiskAssess = list.get(j - 1);
            HSSFRow row = sheet.createRow(j);
            cell= row.createCell(0);
            cell.setCellValue(j);
            cell = row.createCell(1);
            cell.setCellValue(oldRiskAssess.getRegion());
            cell = row.createCell(2);
            cell.setCellValue(oldRiskAssess.getPotentialAccident());
            cell = row.createCell(3);
            cell.setCellValue(oldRiskAssess.getDangerReason());
            cell = row.createCell(4);
            cell.setCellValue(oldRiskAssess.getTriggerFactor());
            cell = row.createCell(5);
            cell.setCellValue(oldRiskAssess.getAccidentResult());
            cell = row.createCell(6);
            cell.setCellValue(oldRiskAssess.getL());
            cell = row.createCell(7);
            cell.setCellValue(oldRiskAssess.getE());
            cell = row.createCell(8);
            cell.setCellValue(oldRiskAssess.getC());
            cell = row.createCell(9);
            cell.setCellValue(oldRiskAssess.getD());
            cell = row.createCell(10);
            cell.setCellValue(oldRiskAssess.getDangerLevel());
            cell = row.createCell(11);
            cell.setCellValue(oldRiskAssess.getControlMeasure());
            cell = row.createCell(12);
            cell.setCellValue(oldRiskAssess.getControlLevel());
        }
 
        // 保存Excel文件
        try{
            // 获取桌面路径
            String desktopPath = System.getProperty("user.home") + "/Desktop/";
            // 导出文件名
            String fileName = desktopPath + "评分标准.xlsx";
            FileOutputStream fileOutputStream = new FileOutputStream(new File(fileName));
            // 将工作簿写入文件
            workbook.write(fileOutputStream);
            workbook.close();
            fileOutputStream.close();
        } catch (Exception e) {
            e.printStackTrace();
        }finally{
            if (workbook != null){
                try {
                    workbook.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
        return  StatusEnum.SUCCESS.getCode();
    }
 
    @Override
    public SearchResult<OldRiskAssessQueryRespDTO> getOldRiskAssessPage(Long currentUserId, OldRiskAssessQueryReqBO queryReqDO) {
 
        //校验参数
        if (ObjectUtils.isEmpty(queryReqDO.getPageSize())){
            throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR.getCode() ,"分页信息不能为空");
        }
        if (ObjectUtils.isEmpty(queryReqDO.getPageIndex())){
            throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR.getCode() ,"分页信息不能为空");
        }
        SearchResult searchResult = new SearchResult<>();
 
        //组装查询条件
        Specification<OldRiskAssess> specification = new Specification<OldRiskAssess>() {
            @Override
            public Predicate toPredicate(Root<OldRiskAssess> root, CriteriaQuery<?> query, CriteriaBuilder criteriaBuilder) {
                List<Predicate> predicateList = new ArrayList<>();
                if(queryReqDO.getRegion() != null && !queryReqDO.getRegion().equals("")){
                    predicateList.add(criteriaBuilder.like(root.get("region"),'%'+ queryReqDO.getRegion() +'%'));
                }
                if(queryReqDO.getPotentialAccident() != null && !queryReqDO.getPotentialAccident().equals("")){
                    predicateList.add(criteriaBuilder.like(root.get("potentialAccident"),'%'+queryReqDO.getPotentialAccident() +'%'));
                }
                if(queryReqDO.getDangerReason() != null && !queryReqDO.getDangerReason().equals("")){
                    predicateList.add(criteriaBuilder.like(root.get("dangerReason"),'%'+queryReqDO.getDangerReason() +'%'));
                }
                if(queryReqDO.getTriggerFactor() != null && !queryReqDO.getTriggerFactor().equals("")){
                    predicateList.add(criteriaBuilder.like(root.get("triggerFactor"),'%'+queryReqDO.getTriggerFactor() +'%'));
                }
                if(queryReqDO.getAccidentResult() != null && !queryReqDO.getAccidentResult().equals("")){
                    predicateList.add(criteriaBuilder.like(root.get("accidentResult"),'%'+queryReqDO.getAccidentResult() +'%'));
                }
                if(queryReqDO.getDangerLevel() != null && !queryReqDO.getDangerLevel().equals("")){
                    predicateList.add(criteriaBuilder.like(root.get("dangerLevel"),'%'+queryReqDO.getDangerLevel() +'%'));
                }
                if(queryReqDO.getControlMeasure() != null && !queryReqDO.getControlMeasure().equals("")){
                    predicateList.add(criteriaBuilder.like(root.get("controlMeasure"),'%'+queryReqDO.getControlMeasure() +'%'));
                }
                if(queryReqDO.getControlLevel() != null && !queryReqDO.getControlLevel().equals("")){
                    predicateList.add(criteriaBuilder.like(root.get("controlLevel"),'%'+queryReqDO.getControlLevel() +'%'));
                }
                predicateList.add(criteriaBuilder.equal(root.get("deleteStatus"),StatusEnum.DELETE_NOT.getCode()));
                //返回组装的条件
                return criteriaBuilder.and(predicateList.toArray(predicateList.toArray(new Predicate[0])));
            }
        };
 
        PageRequest page = PageRequest.of(queryReqDO.getPageIndex() - 1, queryReqDO.getPageSize(), Sort.Direction.DESC, "updateTime");
 
        Page<OldRiskAssess> pageResult = repository.findAll(specification, page);
        List<OldRiskAssessQueryRespDTO> oldRiskAssessQueryRespDTO = BeanCopyUtils.copyBeanList(pageResult.getContent(), OldRiskAssessQueryRespDTO.class);
 
        List<UserInfoDomainDTO> userList = userDomainService.getUserList();
        for (OldRiskAssessQueryRespDTO oldRiskAssess : oldRiskAssessQueryRespDTO) {
            for (UserInfoDomainDTO userInfo : userList) {
                if (userInfo.getId() == oldRiskAssess.getCreateByUserId()){
                    oldRiskAssess.setCreateByUserName(userInfo.getRealName());
                }
                if (userInfo.getId() == oldRiskAssess.getUpdateByUserId()){
                    oldRiskAssess.setUpdateByUserName(userInfo.getRealName());
                }
            }
        }
 
 
        searchResult.setTotal(pageResult.getTotalElements());
        searchResult.setData(oldRiskAssessQueryRespDTO);
 
        return searchResult;
    }
 
 
 
 
}