heheng
2025-03-10 c0ae989839d8323974048b71f7dadc29a20a4b15
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
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
package com.gkhy.labRiskManage.domain.riskReport.service.impl;
 
import com.gkhy.labRiskManage.api.controller.basic.dto.respDto.OldRiskAssessResDTO;
import com.gkhy.labRiskManage.api.controller.experiment.dto.req.ExperimentAndPersonInsertReqBO;
import com.gkhy.labRiskManage.api.controller.riskReport.dto.repDto.ReportReqBO;
import com.gkhy.labRiskManage.api.controller.riskReport.dto.respDto.ReportExperimentSiteQueryRespDTO;
import com.gkhy.labRiskManage.api.controller.riskReport.dto.respDto.ReportPersonQueryRespDTO;
import com.gkhy.labRiskManage.api.controller.riskReport.dto.respDto.ReportRiskSourceQueryRespDTO;
import com.gkhy.labRiskManage.api.controller.riskReport.dto.respDto.ReportSourceTypeQueryRespDTO;
import com.gkhy.labRiskManage.application.riskReport.dto.bo.ReportAppQueryBO;
import com.gkhy.labRiskManage.application.riskReport.dto.bo.ReportAppUpdateBO;
import com.gkhy.labRiskManage.application.riskReport.dto.dto.ReportAppQueryDTO;
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.enums.UserTagEnum;
import com.gkhy.labRiskManage.commons.enums.UserRoleEnum;
import com.gkhy.labRiskManage.commons.exception.BusinessException;
import com.gkhy.labRiskManage.commons.utils.BeanCopyUtils;
import com.gkhy.labRiskManage.domain.account.model.dto.SysUserRoleBindDomainDTO;
import com.gkhy.labRiskManage.domain.account.model.dto.UserInfoDomainDTO;
import com.gkhy.labRiskManage.domain.account.service.UserDomainService;
import com.gkhy.labRiskManage.domain.basic.entity.BasicRiskUnitType;
import com.gkhy.labRiskManage.domain.basic.entity.OldRiskAssess;
import com.gkhy.labRiskManage.domain.basic.model.dto.SiteQueryDTO;
import com.gkhy.labRiskManage.domain.basic.service.BasicExperimentPersonService;
import com.gkhy.labRiskManage.domain.basic.service.BasicExperimentSiteService;
import com.gkhy.labRiskManage.domain.basic.service.BasicRiskUnitTypeService;
import com.gkhy.labRiskManage.domain.basic.service.OldRiskAssessService;
import com.gkhy.labRiskManage.domain.experiment.entity.ExperimentAndSite;
import com.gkhy.labRiskManage.domain.experiment.entity.ExperimentAssessLog;
import com.gkhy.labRiskManage.domain.experiment.entity.ExperimentInfo;
import com.gkhy.labRiskManage.domain.experiment.enums.ExperimentApprovalStatusEnum;
import com.gkhy.labRiskManage.domain.experiment.enums.ExperimentRectifyStatusEnum;
import com.gkhy.labRiskManage.domain.experiment.model.dto.ExperimentInfoDTO;
import com.gkhy.labRiskManage.domain.experiment.service.ExperimentAndSiteService;
import com.gkhy.labRiskManage.domain.experiment.service.ExperimentAndTypeService;
import com.gkhy.labRiskManage.domain.experiment.service.ExperimentAssessLogService;
import com.gkhy.labRiskManage.domain.experiment.service.ExperimentInfoService;
import com.gkhy.labRiskManage.domain.riskReport.entity.*;
import com.gkhy.labRiskManage.domain.riskReport.model.bo.ReportQueryBO;
import com.gkhy.labRiskManage.domain.riskReport.model.bo.UpdateExperimentInfoBO;
import com.gkhy.labRiskManage.domain.riskReport.model.dto.*;
import com.gkhy.labRiskManage.domain.riskReport.repository.jpa.ReportRiskAssessInfoRepository;
import com.gkhy.labRiskManage.domain.riskReport.service.*;
import com.gkhy.labRiskManage.domain.riskReport.utils.GetRoleTagUtils;
import com.gkhy.labRiskManage.domain.riskReport.utils.RiskSourceTypeUtils;
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.util.StringUtils;
 
import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
 
 
/**
 * 风险评估报告
 */
@Service
public class ReportRiskAssessInfoServiceImpl implements ReportRiskAssessInfoService {
 
    @Autowired
    private ReportRiskAssessInfoRepository reportRepository;
    @Autowired
    private ExperimentInfoService experimentInfoService;
    @Autowired
    private RiskAssessPlanService assessPlanService;
    @Autowired
    private BasicExperimentPersonService basicPersonService;
    @Autowired
    private BasicExperimentSiteService basicSiteService;
    @Autowired
    private RiskUnitService riskUnitService;
    @Autowired
    private ExperimentAndSiteService experimentAndSiteService;
    @Autowired
    private ReportExperimentSiteService reportExperimentSiteService;
    @Autowired
    private BasicRiskUnitTypeService basicRiskUnitTypeService;
 
    @Autowired
    private ReportRiskAssessPersonService reportPersonService;
    @Autowired
    private ReportExperimentRiskSourceTypeService reportSourceTypeService;
    @Autowired
    private ReportExperimentRiskSourceService reportSourceService;
    @Autowired
    private ExperimentAssessLogService experimentAssessLogService;
 
    @Autowired
    private UserDomainService userDomainService;
 
    @Autowired
    private RiskAssessPlanEvaluateLecService lecService;
    @Autowired
    private RiskAssessPlanEvaluateLsService lsService;
    @Autowired
    private RiskAssessPlanEvaluateMesService mesService;
    @Autowired
    private RiskAssessPlanEvaluateRsService rsService;
 
    @Autowired
    private ExperimentAndTypeService experimentAndTypeService;
    
    @Autowired
    private OldRiskAssessService oldRiskAssessService;
 
 
    /**
     * 风险评估报告 - 查询
     */
    @Override
    public SearchResult<ReportAppQueryDTO> selectRiskReportPage(Long currentUserId, ReportAppQueryBO queryBO) {
 
 
        //校验参数
        if (ObjectUtils.isEmpty(queryBO.getPageSize())){
            throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR.getCode() ,"分页信息不能为空");
        }
        if (ObjectUtils.isEmpty(queryBO.getPageIndex())){
            throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR.getCode() ,"分页信息不能为空");
        }
        if (ObjectUtils.isEmpty(queryBO.getTag())){
            throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR.getCode() ,"查询报告类别参数缺失");
        }
        if (queryBO.getExperimentName() == ""){
            queryBO.setExperimentName(null);
        }
        UserInfoDomainDTO user = userDomainService.getUserById(currentUserId);
        if (ObjectUtils.isEmpty(user)){
            throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR.getCode() ,"用户不存在");
        }
        int roleTag = GetRoleTagUtils.GetRoleTagUtils(user);
 
        ReportQueryBO queryParam = BeanCopyUtils.copyBean(queryBO, ReportQueryBO.class);
        SearchResult searchResult = new SearchResult<>();
        searchResult.setPageIndex(queryParam.getPageIndex());
        searchResult.setPageSize(queryParam.getPageSize());
 
//        ExperimentInfoDTO experimentByName = experimentInfoService.getExperimentByName(queryBO.getExperimentName());
 
        //封装查询参数
        Specification<ReportRiskAssessInfo> specification = new Specification<ReportRiskAssessInfo>() {
            @Override
            public Predicate toPredicate(Root<ReportRiskAssessInfo> root, CriteriaQuery<?> query, CriteriaBuilder criteriaBuilder) {
                List<Predicate> predicateList = new ArrayList<>();
                if (queryParam.getAssessLevel() != null && !queryParam.getAssessLevel().equals("")){
                    predicateList.add(criteriaBuilder.equal(root.get("assessLevel"),queryParam.getAssessLevel()));
                }
                if (queryParam.getApprovePlanStatus() != null && !queryParam.getApprovePlanStatus().equals("")){
                    predicateList.add(criteriaBuilder.equal(root.get("approvePlanStatus"),
                            queryParam.getApprovePlanStatus()));
                }
                if (queryParam.getExperimentType() != null && !queryParam.getExperimentType().equals("")){
                    predicateList.add(criteriaBuilder.equal(root.get("experimentType"),queryParam.getExperimentType()));
                }
                if (!ObjectUtils.isEmpty(queryParam.getExperimentId())){
                    predicateList.add(criteriaBuilder.equal(root.get("experimentId"),queryParam.getExperimentId()));
                }
                if (!ObjectUtils.isEmpty(queryParam.getExperimentName())){
                    predicateList.add(criteriaBuilder.like(root.get("experimentName"),"%"+queryParam.getExperimentName()+"%"));
                }
                if (roleTag == UserTagEnum.USER_TAG_0.getCode()){
                    predicateList.add(criteriaBuilder.equal(root.get("personUserId"), currentUserId));
                }
                if (queryParam.getTag() == 1){
                    predicateList.add(criteriaBuilder.isNull(root.get("assessPerson")));
                }else if (queryParam.getTag() == 2){
                    predicateList.add(criteriaBuilder.isNotNull(root.get("assessPerson"))
                    );
                }
                //现在领导能查看所有的报告
//                if (roleTag == UserTagEnum.USER_TAG_2.getCode()){
//                    predicateList.add(criteriaBuilder.or(
//                                    criteriaBuilder.equal(root.get("approvePlanStatus"), StatusEnum.REPORT_APPROVED.getCode()),
//                                    criteriaBuilder.equal(root.get("approvePlanStatus"), StatusEnum.REPORT_NOT_APPROVED.getCode()),
//                                    criteriaBuilder.equal(root.get("approvePlanStatus"), StatusEnum.REPORT_APPROVED_LEAD.getCode())
//                            )
//                    );
//                }
 
                predicateList.add(criteriaBuilder.equal(root.get("deleteStatus"),StatusEnum.DELETE_NOT.getCode()));
                return criteriaBuilder.and(predicateList.toArray(new Predicate[0]));
            }
        };
 
        PageRequest pageParam = PageRequest.of(queryParam.getPageIndex() - 1, queryParam.getPageSize(), Sort.Direction.DESC, "updateTime");
        Page<ReportRiskAssessInfo> pageResult = reportRepository.findAll(specification, pageParam);
 
        List<ReportQueryDTO> reportQueryDTOS = BeanCopyUtils.copyBeanList(pageResult.getContent(), ReportQueryDTO.class);
 
        List<ReportAppQueryDTO> reportAppQueryDTOS = BeanCopyUtils.copyBeanList(reportQueryDTOS, ReportAppQueryDTO.class);
 
        List<UserInfoDomainDTO> userList = userDomainService.getUserList();
 
 
        for (ReportAppQueryDTO reportQueryDTO : reportAppQueryDTOS) {
            //获取审批人员
            List<ReportPersonQueryRespDTO> personByReportId = reportPersonService.listPersonByReportId(reportQueryDTO.getId());
            //获取实验风险源
            List<ReportRiskSourceQueryRespDTO> riskSourceByReportId = reportSourceService.getRiskSourceByReportId(reportQueryDTO.getId());
            //获取风险类型
            List<ReportSourceTypeQueryRespDTO> sourceTypeByReportId = reportSourceTypeService.getSourceTypeByReportId(reportQueryDTO.getId());
            //获取风险类型
            List<ReportExperimentSite> siteByReportId = reportExperimentSiteService.getSiteByReportId(reportQueryDTO.getId());
            //获取实验信息
            ExperimentInfoDTO experimentById = experimentInfoService.getExperimentById(reportQueryDTO.getExperimentId());
            //获取评估计划
            List<AssessPlanQueryDTO> assessPlanByExperimentId = assessPlanService.getAssessPlanByExperimentId(reportQueryDTO.getExperimentId());
            reportQueryDTO.setEvaluateTime(experimentById.getCreateTime());
            if (!ObjectUtils.isEmpty(experimentById.getProcess())){
                reportQueryDTO.setProcess(experimentById.getProcess());
            }
 
 
            if (!ObjectUtils.isEmpty(assessPlanByExperimentId)){
                for (AssessPlanQueryDTO assessPlan : assessPlanByExperimentId) {
                    if (assessPlan.getEvaluateTime() != null){
                        if (reportQueryDTO.getEvaluateTime().isBefore(assessPlan.getEvaluateTime())){
                            reportQueryDTO.setEvaluateTime(assessPlan.getEvaluateTime());
                        }
                    }
 
                }
            }
 
            if (!ObjectUtils.isEmpty(riskSourceByReportId)){
                reportQueryDTO.setRiskSource(riskSourceByReportId);
            }
            if (!ObjectUtils.isEmpty(sourceTypeByReportId)){
                reportQueryDTO.setRiskSourceType(sourceTypeByReportId);
            }
            if (!ObjectUtils.isEmpty(personByReportId)){
                reportQueryDTO.setPerson(personByReportId);
            }
            if (!ObjectUtils.isEmpty(siteByReportId)){
                reportQueryDTO.setExperimentSite(BeanCopyUtils.copyBeanList(siteByReportId, ReportExperimentSiteQueryRespDTO.class));
                if (queryBO.getExperimentId() != null){
                    List<ReportExperimentSiteQueryRespDTO> experimentSite = reportQueryDTO.getExperimentSite();
                    List<String> collect = experimentSite.stream().map(ReportExperimentSiteQueryRespDTO::getSiteName).collect(Collectors.toList());
                    List<OldRiskAssessResDTO> oldRiskAssessListByRegion = oldRiskAssessService.getOldRiskAssessListByRegion(collect);
                    if (!ObjectUtils.isEmpty(oldRiskAssessListByRegion)){
 
                        reportQueryDTO.setOldRiskAssess(oldRiskAssessListByRegion);
                    }
                    reportQueryDTO.setExperimentAndType(experimentAndTypeService.getByExperimentId(reportQueryDTO.getExperimentId()));
                }
            }
            reportQueryDTO.setExperimentCode(experimentById.getExperimentCode());
 
            for (UserInfoDomainDTO userInfo : userList) {
                if (userInfo.getId() == reportQueryDTO.getCreateByUserId()){
                    reportQueryDTO.setCreateByUserName(userInfo.getRealName());
                }
                if (userInfo.getId() == reportQueryDTO.getUpdateByUserId()){
                    reportQueryDTO.setUpdateByUserName(userInfo.getRealName());
                }
            }
 
 
 
        }
 
        searchResult.setData(reportAppQueryDTOS);
        searchResult.setTotal(pageResult.getTotalElements());
        return searchResult;
    }
 
    
    /**
     * 风险评估报告 - 生成报告信息
     */
    @Transactional
    @Override
    public ReportInsertDTO insertRiskReport(Long currentUserId, Long id) {
 
        if (currentUserId < 0){
            throw new BusinessException(this.getClass(), ResultCode.BUSINESS_ERROR_NOT_ALLOWED.getCode() ,"当前用户无效,请重新登陆");
        }
        UserInfoDomainDTO userInfoById = userDomainService.getUserInfoById(currentUserId);
        if (ObjectUtils.isEmpty(userInfoById)){
            throw new BusinessException(this.getClass(), ResultCode.BUSINESS_ERROR_NOT_ALLOWED.getCode() ,"当前用户不存在或已被删除");
        }
        int roleTag = GetRoleTagUtils.GetRoleTagUtils(userInfoById);
        if (ObjectUtils.isEmpty(id)){
            throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode() ,"实验id不能为空");
        }
        //获取实验id,查询实验
        ExperimentInfoDTO experimentById = experimentInfoService.getExperimentById(id);
        if (ObjectUtils.isEmpty(experimentById)){
            throw new BusinessException(this.getClass(), ResultCode.BUSINESS_ERROR.getCode(), "实验不存在");
        }
        if (roleTag == 0){
            throw new BusinessException(this.getClass(), ResultCode.BUSINESS_ERROR_NOT_ALLOWED.getCode() ,"不是管理员,无权生成报告");
        }
        if (experimentById.getStage() == StatusEnum.EXPERIMENT_STATUS_REPORT.getCode().byteValue()){
            throw new BusinessException(this.getClass(), ResultCode.BUSINESS_ERROR_NOT_ALLOWED.getCode() ,"该实验已经生成报告,无需重复操作");
        }
        //定义初始风险等级0级
        Byte level = 0;
        //获取该实验的所有计划信息
        List<AssessPlanQueryDTO> assessPlanList = assessPlanService.getAssessPlanByExperimentId(id);
        int tag = 0;
        StringBuilder info = new StringBuilder();
        List<Long>  assessPlanIds = new ArrayList<>();
        //如果有计划未评价完成,不可生成报告
        for (AssessPlanQueryDTO assessPlanQueryDTO : assessPlanList) {
            if (assessPlanQueryDTO.getPlanExecStatus() != StatusEnum.PLAN_EXEC_OVER.getCode().byteValue()){
                info.append(assessPlanQueryDTO.getAssessPlanName() + ";");
                tag = 1;
            }
            assessPlanIds.add(assessPlanQueryDTO.getId());
        }
 
        if (tag == 1){
            throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR.getCode() ,"该实验有未完成的评估计划" + info);
        }
 
        UserInfoDomainDTO liabilityUser = userDomainService.getUserInfoById(experimentById.getLiabilityUserId());
        if (ObjectUtils.isEmpty(liabilityUser)){
            throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR.getCode() ,"实验责任人信息不存在");
        }
 
 
        //检查该实验所有的评价结果,遍历评价结果等级
        int a = 1;
        StringBuilder analysis = new StringBuilder();
        List<RiskAssessPlanEvaluateLec> lecByIds = lecService.getLecByIds(assessPlanIds);
        List<RiskAssessPlanEvaluateLs> lsByIds = lsService.getLsByIds(assessPlanIds);
        List<RiskAssessPlanEvaluateMes> mesByIds = mesService.getMesByIds(assessPlanIds);
        List<RiskAssessPlanEvaluateRs> rsByIds = rsService.getRsByIds(assessPlanIds);
 
        if (lecByIds .size() > 0){
            for (RiskAssessPlanEvaluateLec lecById : lecByIds) {
                if (lecById.getRiskLevel() > level){
                    level = lecById.getRiskLevel();
                    analysis.append(a + lecById.getSafeRiskAnalysis() + ";");//todo 安全风险分析
                    a++;
                }
            }
        }
        if (lsByIds .size() > 0){
            for (RiskAssessPlanEvaluateLs lsById : lsByIds) {
                if (lsById.getRiskLevel() > level){
                    level = lsById.getRiskLevel();
                    analysis.append(a + lsById.getSafeRiskAnalysis() + ";");
                    a++;
                }
            }
        }
        if (mesByIds .size() > 0){
            for (RiskAssessPlanEvaluateMes mesById : mesByIds) {
                if (mesById.getRiskLevel() > level){
                    level = mesById.getRiskLevel();
                    analysis.append(a + mesById.getSafeRiskAnalysis() + ";");
                    a++;
                }
            }
        }
 
        if (rsByIds .size() > 0){
            for (RiskAssessPlanEvaluateRs rsById : rsByIds) {
                if (rsById.getRiskLevel() > level){
                    level = rsById.getRiskLevel();
                    analysis.append(a + rsById.getSafeRiskAnalysis() + ";");
                    a++;
                }
            }
        }
 
        //封装报告主体信息
        LocalDateTime date = LocalDateTime.now();
        ReportRiskAssessInfo reportInfo = new ReportRiskAssessInfo();
 
        reportInfo.setExperimentId(experimentById.getId());
        reportInfo.setExperimentName(experimentById.getExperimentName());
        reportInfo.setExperimentType(experimentById.getExperimentType());
        reportInfo.setExperimentDesc(experimentById.getNote());
        reportInfo.setPersonUserId(experimentById.getLiabilityUserId());//todo 确定实验负责人,安全负责人来源
        reportInfo.setPersonUser(experimentById.getLiabilityUser());
        reportInfo.setPersonUserPhone(Long.valueOf(experimentById.getLiabilityUserPhone()));  //从实验用户表查询
        reportInfo.setSafePersonUserId(experimentById.getSafeLiabilityUserId());
        reportInfo.setSafePersonUser(experimentById.getSafeLiabilityUser());
        reportInfo.setSafePersonUserPhone(Long.valueOf(experimentById.getSafeLiabilityUserPhone()));
        reportInfo.setEmergencyMeasure(experimentById.getMeasure());
        reportInfo.setDep(experimentById.getDep());
        reportInfo.setCreateTime(date);
        reportInfo.setUpdateTime(date);
        reportInfo.setCreateByUserId(userInfoById.getId());
        reportInfo.setUpdateByUserId(userInfoById.getId());
        reportInfo.setDeleteStatus(StatusEnum.DELETE_NOT.getCode().byteValue());
        reportInfo.setApprovePlanStatus(StatusEnum.REPORT_NOT_START.getCode().byteValue());
        reportInfo.setSafeRiskAnalysis(analysis.toString());
 
        reportInfo.setAssessPerson(null);
        reportInfo.setAssessLevel(null);
        reportInfo.setDepId(null); //todo 不确定是否需要部门
        reportInfo.setSafeRiskAnalysis(null); //todo 安全风险分析,暂时不知道数据来源,先设空
 
 
        //修改实验  4 生成报告,
        ExperimentInfoDTO experimentInfoDTO = experimentInfoService.updateExperimentStage(id, StatusEnum.EXPERIMENT_STATUS_REPORT.getCode().byteValue());
        if (ObjectUtils.isEmpty(experimentInfoDTO)){
            throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR.getCode() ,"实验状态修改失败");
        }
 
        //修改实验所有评估计划状态
        int result = assessPlanService.assessPlanSellStatus(id, StatusEnum.PLAN_EXEC_OVER.getCode().byteValue());
        if (result == 0){
            throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR.getCode() ,"评估计划状态修改失败");
        }
 
        //生成报告主体信息
        ReportRiskAssessInfo saveResult = reportRepository.save(reportInfo);
        if (ObjectUtils.isEmpty(saveResult)){
            throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR.getCode() ,"写入报告基本信息失败,请稍后尝试");
        }
 
        //封装实验场所信息
        List<ReportExperimentSite> reportSiteList = new ArrayList<>();
        List<ExperimentAndSite> experimentAndSiteList = experimentAndSiteService.getByExperimentId(id);
        for (ExperimentAndSite experimentAndSite : experimentAndSiteList) {
            SiteQueryDTO siteInfo = basicSiteService.getBasicExperimentSiteById(experimentAndSite.getSiteId());
            ReportExperimentSite reportSite = BeanCopyUtils.copyBean(siteInfo, ReportExperimentSite.class);
            reportSite.setReportId(saveResult.getId());
            reportSite.setDeleteStatus(StatusEnum.DELETE_NOT.getCode().byteValue());
            reportSite.setSiteId(siteInfo.getId());
            reportSiteList.add(reportSite);
        }
        List<ReportExperimentSite> reportExperimentSites = reportExperimentSiteService.insertAll(reportSiteList);
        if (reportExperimentSites.size() < reportSiteList.size()){
            throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR.getCode() ,"写入报告实验场所信息时失败,请稍后尝试");
        }
 
        //封装风险源类型信息
        List<ReportExperimentRiskSourceType> riskSourceTypeList = RiskSourceTypeUtils.RiskSourceType(currentUserId, saveResult.getId());
 
        //封装风
        List<RiskUnit> riskUnitList = riskUnitService.getRiskUnitByExperimentId(id);
        List<ReportExperimentRiskSource> riskSourceList = new ArrayList<>();
        int i = 1;
        for (RiskUnit riskUnit : riskUnitList) {
            //封装风险源信息  todo -- 需要确认 此处封装风险单元?辨识出的每一项结果
            ReportExperimentRiskSource riskSource = new ReportExperimentRiskSource();
            riskSource.setReportId(saveResult.getId());
            riskSource.setRiskSourceIndex(i);
            riskSource.setRiskSource(riskUnit.getRiskName());
            riskSource.setRiskCharacteristic(riskUnit.getDescription());
            riskSource.setDescription(riskUnit.getDescription());
            riskSource.setNumber(1);
            riskSource.setCreateByUserId(currentUserId);
            riskSource.setCreateTime(date);
            riskSource.setUpdateByUserId(currentUserId);
            riskSource.setUpdateTime(date);
            riskSource.setDeleteStatus(StatusEnum.DELETE_NOT.getCode().byteValue());
            riskSourceList.add(riskSource);
            i++;
 
            //检查风险源类型是否存在
            BasicRiskUnitType riskUnitTypeById = basicRiskUnitTypeService.getRiskUnitTypeById(riskUnit.getRiskUnitTypeId());
            for (ReportExperimentRiskSourceType riskSourceType : riskSourceTypeList) {
                if (riskSourceType.getRiskSourceType().equals(riskUnitTypeById.getRiskType())){
                    riskSourceType.setStatus((byte) 1);//1-存在;2-不存在
                }
            }
        }
        //todo 改为手写,----- 暂时弃用  写入风险源
//        List<ReportExperimentRiskSource> riskSources = reportSourceService.insertAllReportSource(riskSourceList);
//        if (riskSources.size() < riskSourceList.size()){
//            throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR.getCode() ,"写入报告风险源信息时失败,请稍后尝试");
//        }
 
        //写入风险源类型
        List<ReportExperimentRiskSourceType> riskSourceTypes = reportSourceTypeService.insertAllReportSource(riskSourceTypeList);
        if (riskSourceTypes.size() < riskSourceTypeList.size()){
            throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR.getCode() ,"写入报告风险源类型信息时失败,请稍后尝试");
        }
 
        return BeanCopyUtils.copyBean(saveResult, ReportInsertDTO.class);
 
    }
 
    /**
     * 风险评估报告 - 填报信息
     */
    @Override
    public ReportUpdateDTO updateReportInfo(Long currentUserId, ReportAppUpdateBO reportUpdateBO) {
 
        if (currentUserId < 0){
            throw new BusinessException(this.getClass(), ResultCode.BUSINESS_ERROR_NOT_ALLOWED.getCode() ,"当前用户无效,请重新登陆");
        }
        int roleTag = 0;
        UserInfoDomainDTO user = userDomainService.getUserById(currentUserId);
        for (SysUserRoleBindDomainDTO role : user.getRoles()) {
            if (role.getRoleId() == UserRoleEnum.USER_ROLE_4.getCode().byteValue()){
                roleTag = 1;
            }
        }
        if (ObjectUtils.isEmpty(user)){
            throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR.getCode() ,"用户不存在");
        }
        if (roleTag == 0){
            throw new BusinessException(this.getClass(), ResultCode.BUSINESS_ERROR_NOT_ALLOWED.getCode() ,"当前用户无权生成评估报告");
        }
        if (ObjectUtils.isEmpty(reportUpdateBO.getId())){
            throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode() ,"请选择正确的报告进行提交");
        }
        ReportRiskAssessInfo reportById = reportRepository.getReportById(reportUpdateBO.getId());
        if (ObjectUtils.isEmpty(reportById)){
            throw new BusinessException(this.getClass(), ResultCode.BUSINESS_ERROR.getCode() ,"选择的报告不存在");
        }
        if (!ObjectUtils.isEmpty(reportById.getAssessLevel())){
            throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode() ,"报告已经填写完成");
        }
        if (ObjectUtils.isEmpty(reportUpdateBO.getSafeRiskAnalysis())){
            throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode() ,"安全风险分析内容不能为空");
        }
        if (ObjectUtils.isEmpty(reportUpdateBO.getAssessLevel())){
            throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode() ,"项目风险评估等级不能为空");
        }
        if (!(reportUpdateBO.getAssessLevel() == 1 || reportUpdateBO.getAssessLevel() == 2 ||
                reportUpdateBO.getAssessLevel() == 3 || reportUpdateBO.getAssessLevel() == 4)){
            throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode() ,"项目风险评估等级不合法,请选择:低风险,一般风险,较大风险,重大风险");
        }
 
        reportById.setAssessPerson(reportUpdateBO.getAssessPerson());
        reportById.setAssessLevel(reportUpdateBO.getAssessLevel());
        reportById.setSafeRiskAnalysis(reportUpdateBO.getSafeRiskAnalysis());
        reportById.setDescription(reportUpdateBO.getDescription());
        reportById.setUpdateTime(LocalDateTime.now());
        reportById.setUpdateByUserId(currentUserId);
 
        ReportRiskAssessInfo updateResult = reportRepository.save(reportById);
        if (ObjectUtils.isEmpty(updateResult)){
            throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR.getCode() ,"评估报告信息写入失败");
        }
 
        return BeanCopyUtils.copyBean(updateResult, ReportUpdateDTO.class);
    }
 
    /**
     * 风险评估报告 - 修改填报信息
     */
    @Override
    public ReportUpdateDTO updateReportInfoById(Long currentUserId, ReportAppUpdateBO reportUpdateBO) {
 
        if (currentUserId < 0){
            throw new BusinessException(this.getClass(), ResultCode.BUSINESS_ERROR_NOT_ALLOWED.getCode() ,"当前用户无效,请重新登陆");
        }
        int roleTag = 0;
        UserInfoDomainDTO user = userDomainService.getUserById(currentUserId);
        for (SysUserRoleBindDomainDTO role : user.getRoles()) {
            if (role.getRoleId() == UserRoleEnum.USER_ROLE_4.getCode().byteValue()){
                roleTag = 1;
            }
        }
        if (ObjectUtils.isEmpty(user)){
            throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR.getCode() ,"用户不存在");
        }
        if (roleTag == 0){
            throw new BusinessException(this.getClass(), ResultCode.BUSINESS_ERROR_NOT_ALLOWED.getCode() ,"当前用户无权生成评估报告");
        }
        if (ObjectUtils.isEmpty(reportUpdateBO.getId())){
            throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode() ,"请选择正确的报告进行提交");
        }
        ReportRiskAssessInfo reportById = reportRepository.getReportById(reportUpdateBO.getId());
        if (ObjectUtils.isEmpty(reportById)){
            throw new BusinessException(this.getClass(), ResultCode.BUSINESS_ERROR.getCode() ,"选择的报告不存在");
        }
//        if (ObjectUtils.isEmpty(reportUpdateBO.getSafeRiskAnalysis())){
//            throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode() ,"安全风险分析内容不能为空");
//        }
        if (ObjectUtils.isEmpty(reportUpdateBO.getAssessLevel())){
            throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode() ,"项目风险评估等级不能为空");
        }
        if (!(reportUpdateBO.getAssessLevel() == 1 || reportUpdateBO.getAssessLevel() == 2 ||
                reportUpdateBO.getAssessLevel() == 3 || reportUpdateBO.getAssessLevel() == 4)){
            throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode() ,"项目风险评估等级不合法,请选择:低风险,一般风险,较大风险,重大风险");
        }
 
        reportById.setAssessPerson(reportUpdateBO.getAssessPerson());
        reportById.setAssessLevel(reportUpdateBO.getAssessLevel());
        reportById.setDescription(reportUpdateBO.getDescription());
        if(!ObjectUtils.isEmpty(reportUpdateBO.getSafeRiskAnalysis())){
            reportById.setSafeRiskAnalysis(reportUpdateBO.getSafeRiskAnalysis());
        }
        reportById.setUpdateTime(LocalDateTime.now());
        reportById.setUpdateByUserId(currentUserId);
 
        ReportRiskAssessInfo updateResult = reportRepository.save(reportById);
        if (ObjectUtils.isEmpty(updateResult)){
            throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR.getCode() ,"评估报告信息写入失败");
        }
 
        return BeanCopyUtils.copyBean(updateResult, ReportUpdateDTO.class);
    }
 
    /**
     * 风险评估报告 - 报告审核 - 旧 - 两层审核
     */
    @Transactional
    @Override
    public int report(Long currentUserId, ReportReqBO reportReqBO) {
 
        if (currentUserId < 0){
            throw new BusinessException(this.getClass(), ResultCode.BUSINESS_ERROR_NOT_ALLOWED.getCode() ,"当前用户无效,请重新登陆");
        }
        UserInfoDomainDTO user = userDomainService.getUserById(currentUserId);
        if (ObjectUtils.isEmpty(user)){
            throw new BusinessException(this.getClass(), ResultCode.BUSINESS_ERROR_NOT_ALLOWED.getCode() ,"当前用户不存在或已被删除");
        }
 
        int roleTag = GetRoleTagUtils.GetRoleTagUtils(user);
 
        if (roleTag == 0){
            throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode() ,"非管理人员,无权操作");
        }
        if (ObjectUtils.isEmpty(reportReqBO.getId())){
            throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode() ,"请选择正确的报告进行审核");
        }
        ReportRiskAssessInfo reportById = reportRepository.getReportById(reportReqBO.getId());
        if (ObjectUtils.isEmpty(reportById)){
            throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode() ,"报告不存在");
        }
        if (ObjectUtils.isEmpty(reportReqBO.getApproveDesc())){
            throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode() ,"审核意见不能为空");
        }
 
        /**
         * 方案
         * 1、管理部门审核报告后,领导可见
         * 2、管理部门-->领导,任意审核不通过,否决实验,改变报告、实验状态
         * 3、管理部门审核通过,改变报告状态(管理审核),不改变实验状态;
         * 4、领导审核通过,改变报告(领导审核)、实验状态;
        * */
        LocalDateTime  date = LocalDateTime.now();
 
        ReportRiskAssessPerson approvePerson = new ReportRiskAssessPerson();
        approvePerson.setReportId(reportReqBO.getId());
        approvePerson.setApprovePerson(user.getRealName());
        approvePerson.setApproveDesc(reportReqBO.getApproveDesc());
        approvePerson.setApproveTime(date);
        approvePerson.setCreateTime(date);
        approvePerson.setUpdateTime(date);
        approvePerson.setApprovePersonId(currentUserId);
        approvePerson.setCreateByUserId(currentUserId);
        approvePerson.setUpdateByUserId(currentUserId);
        approvePerson.setDeleteStatus(StatusEnum.DELETE_NOT.getCode().byteValue());
        //1、审核通过
        if (reportReqBO.getApproveStatus() == 2){
            approvePerson.setApproveStatus(StatusEnum.APPROVED_PASS.getCode().byteValue());
            if (roleTag == 1){
                List<ReportPersonInsertDTO> personByReportId = reportPersonService.getPersonByReportId(reportReqBO.getId());
                if (!ObjectUtils.isEmpty(personByReportId)){
                    for (ReportPersonInsertDTO person : personByReportId) {
                        if (person.getApproveIndex() == 1){
                            throw new BusinessException(this.getClass(), ResultCode.BUSINESS_ERROR_NOT_ALLOWED.getCode() ,"报告已被管理人员审核,无需重复操作");
                        }
                    }
                }
                //保存审核人员信息
                approvePerson.setApproveIndex(1);
                approvePerson.setApproveStage("管理人员审核");
                ReportRiskAssessPerson assessPerson = reportPersonService.insertOneReportPerson(approvePerson);
                if (ObjectUtils.isEmpty(assessPerson)){
                    throw new BusinessException(this.getClass(), ResultCode.BUSINESS_ERROR_NOT_ALLOWED.getCode() ,"审核信息保存失败");
                }
                //修改报告信息-管理审核
                reportById.setApprovePlanStatus(StatusEnum.REPORT_APPROVED.getCode().byteValue());
                ReportRiskAssessInfo reportReject = reportRepository.save(reportById);
                if (ObjectUtils.isEmpty(reportReject)){
                    throw new BusinessException(this.getClass(), ResultCode.BUSINESS_ERROR_NOT_ALLOWED.getCode() ,"报告状态修改失败");
                }
            }
            if (roleTag == 2){
                List<ReportPersonInsertDTO> personByReportId = reportPersonService.getPersonByReportId(reportReqBO.getId());
                if (!ObjectUtils.isEmpty(personByReportId)){
                    for (ReportPersonInsertDTO person : personByReportId) {
                        if (person.getApproveIndex() == 2){
                            throw new BusinessException(this.getClass(), ResultCode.BUSINESS_ERROR_NOT_ALLOWED.getCode() ,"报告已被领导审核,无需重复操作");
                        }
                    }
                }
                //保存审核人员信息
                approvePerson.setApproveIndex(2);
                approvePerson.setApproveStage("领导审核");
                ReportRiskAssessPerson assessPerson = reportPersonService.insertOneReportPerson(approvePerson);
                if (ObjectUtils.isEmpty(assessPerson)){
                    throw new BusinessException(this.getClass(), ResultCode.BUSINESS_ERROR_NOT_ALLOWED.getCode() ,"审核信息保存失败");
                }
                //修改报告状态-领导审核
                reportById.setApprovePlanStatus(StatusEnum.REPORT_APPROVED_LEAD.getCode().byteValue());
                ReportRiskAssessInfo reportReject = reportRepository.save(reportById);
                if (ObjectUtils.isEmpty(reportReject)){
                    throw new BusinessException(this.getClass(), ResultCode.BUSINESS_ERROR_NOT_ALLOWED.getCode() ,"报告状态修改失败");
                }
                //修改实验状态-通过实验
                UpdateExperimentInfoBO updateBO = new UpdateExperimentInfoBO();
                updateBO.setExperimentId(reportById.getExperimentId());
                updateBO.setApprovalStatus(ExperimentApprovalStatusEnum.APPROVAL_SUCCESS.getValue());
                updateBO.setRectifyStatus(ExperimentRectifyStatusEnum.NOT_RECTIFY.getValue());
                ExperimentInfo experimentInfo = experimentInfoService.updateExperimentStatus(updateBO);
                if (ObjectUtils.isEmpty(experimentInfo)){
                    throw new BusinessException(this.getClass(), ResultCode.BUSINESS_ERROR_NOT_ALLOWED.getCode() ,"实验信息状态修改失败");
                }
            }
        }
 
        //2、任意审核不通过
        if (reportReqBO.getApproveStatus() == 3){
            approvePerson.setApproveStatus(StatusEnum.APPROVED_NOT_PASS.getCode().byteValue());
            if (roleTag == 1){
                //保存审核人员信息
                approvePerson.setApproveIndex(1);
                approvePerson.setApproveStage("管理人员审核");
                ReportRiskAssessPerson assessPerson = reportPersonService.insertOneReportPerson(approvePerson);
                if (ObjectUtils.isEmpty(assessPerson)){
                    throw new BusinessException(this.getClass(), ResultCode.BUSINESS_ERROR_NOT_ALLOWED.getCode() ,"审核信息保存失败");
                }
            }
            if (roleTag == 2){
                //保存审核人员信息
                approvePerson.setApproveIndex(2);
                approvePerson.setApproveStage("领导审核");
                ReportRiskAssessPerson assessPerson = reportPersonService.insertOneReportPerson(approvePerson);
                if (ObjectUtils.isEmpty(assessPerson)){
                    throw new BusinessException(this.getClass(), ResultCode.BUSINESS_ERROR_NOT_ALLOWED.getCode() ,"审核信息保存失败");
                }
            }
            //修改报告状态
            reportById.setApprovePlanStatus(StatusEnum.REPORT_NOT_APPROVED.getCode().byteValue());
            ReportRiskAssessInfo reportReject = reportRepository.save(reportById);
            if (ObjectUtils.isEmpty(reportReject)){
                throw new BusinessException(this.getClass(), ResultCode.BUSINESS_ERROR_NOT_ALLOWED.getCode() ,"报告状态修改失败");
            }
            //修改实验状态,否决实验
            UpdateExperimentInfoBO updateBO = new UpdateExperimentInfoBO();
            updateBO.setExperimentId(reportById.getExperimentId());
            updateBO.setApprovalStatus(ExperimentApprovalStatusEnum.APPROVAL_FAIL.getValue());
            updateBO.setRectifyStatus(ExperimentRectifyStatusEnum.WAIT_RECTIFY.getValue());
            ExperimentInfo experimentInfo = experimentInfoService.updateExperimentStatus(updateBO);
            if (ObjectUtils.isEmpty(experimentInfo)){
                throw new BusinessException(this.getClass(), ResultCode.BUSINESS_ERROR_NOT_ALLOWED.getCode() ,"实验信息状态修改失败");
            }
        }
 
        return StatusEnum.SUCCESS.getCode();
    }
 
    /**
     * 风险评估报告 - 报告审核 - 新 - 单次审核
     */
    @Override
    @Transactional
    public int reportNew(Long currentUserId, ReportReqBO reportReqBO) {
 
        if (currentUserId < 0){
            throw new BusinessException(this.getClass(), ResultCode.BUSINESS_ERROR_NOT_ALLOWED.getCode() ,"当前用户无效,请重新登陆");
        }
        UserInfoDomainDTO user = userDomainService.getUserById(currentUserId);
        if (ObjectUtils.isEmpty(user)){
            throw new BusinessException(this.getClass(), ResultCode.BUSINESS_ERROR_NOT_ALLOWED.getCode() ,"当前用户不存在或已被删除");
        }
 
        int roleTag = GetRoleTagUtils.GetRoleTagUtils(user);
 
        if (roleTag != 2){
            throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode() ,"非综合办工作人员,无权操作");
        }
        if (ObjectUtils.isEmpty(reportReqBO.getId())){
            throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode() ,"请选择正确的报告进行审核");
        }
        ReportRiskAssessInfo reportById = reportRepository.getReportById(reportReqBO.getId());
        if (ObjectUtils.isEmpty(reportById)){
            throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode() ,"报告不存在");
        }
        if (ObjectUtils.isEmpty(reportReqBO.getApproveDesc())){
            throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode() ,"审核意见不能为空");
        }
 
        LocalDateTime  date = LocalDateTime.now();
 
        ReportRiskAssessPerson approvePerson = new ReportRiskAssessPerson();
        approvePerson.setReportId(reportReqBO.getId());
        approvePerson.setApprovePerson(user.getRealName());
        approvePerson.setApproveDesc(reportReqBO.getApproveDesc());
        approvePerson.setApproveTime(date);
        approvePerson.setCreateTime(date);
        approvePerson.setUpdateTime(date);
        approvePerson.setApprovePersonId(currentUserId);
        approvePerson.setCreateByUserId(currentUserId);
        approvePerson.setUpdateByUserId(currentUserId);
        approvePerson.setDeleteStatus(StatusEnum.DELETE_NOT.getCode().byteValue());
        //1、审核通过
        if (reportReqBO.getApproveStatus() == 2){
            approvePerson.setApproveStatus(StatusEnum.APPROVED_PASS.getCode().byteValue());
//            if (roleTag == 1){
//                List<ReportPersonInsertDTO> personByReportId = reportPersonService.getPersonByReportId(reportReqBO.getId());
//                if (!ObjectUtils.isEmpty(personByReportId)){
//                    for (ReportPersonInsertDTO person : personByReportId) {
//                        if (person.getApproveIndex() == 1){
//                            throw new BusinessException(this.getClass(), ResultCode.BUSINESS_ERROR_NOT_ALLOWED.getCode() ,"报告已被管理人员审核,无需重复操作");
//                        }
//                    }
//                }
//                //保存审核人员信息
//                approvePerson.setApproveIndex(1);
//                approvePerson.setApproveStage("管理人员审核");
//                ReportRiskAssessPerson assessPerson = reportPersonService.insertOneReportPerson(approvePerson);
//                if (ObjectUtils.isEmpty(assessPerson)){
//                    throw new BusinessException(this.getClass(), ResultCode.BUSINESS_ERROR_NOT_ALLOWED.getCode() ,"审核信息保存失败");
//                }
//                //修改报告信息-管理审核
//                reportById.setApprovePlanStatus(StatusEnum.REPORT_APPROVED.getCode().byteValue());
//                ReportRiskAssessInfo reportReject = reportRepository.save(reportById);
//                if (ObjectUtils.isEmpty(reportReject)){
//                    throw new BusinessException(this.getClass(), ResultCode.BUSINESS_ERROR_NOT_ALLOWED.getCode() ,"报告状态修改失败");
//                }
//            }
            if (roleTag == 2){
                List<ReportPersonInsertDTO> personByReportId = reportPersonService.getPersonByReportId(reportReqBO.getId());
                if (!ObjectUtils.isEmpty(personByReportId)){
                    for (ReportPersonInsertDTO person : personByReportId) {
                        if (person.getApproveIndex() == 2){
                            throw new BusinessException(this.getClass(), ResultCode.BUSINESS_ERROR_NOT_ALLOWED.getCode() ,"报告已被综合办审核,无需重复操作");
                        }
                    }
                }
                //保存审核人员信息
                approvePerson.setApproveIndex(2);
                approvePerson.setApproveStage("综合办审核");
                ReportRiskAssessPerson assessPerson = reportPersonService.insertOneReportPerson(approvePerson);
                if (ObjectUtils.isEmpty(assessPerson)){
                    throw new BusinessException(this.getClass(), ResultCode.BUSINESS_ERROR_NOT_ALLOWED.getCode() ,"审核信息保存失败");
                }
                //修改报告状态-领导审核
                reportById.setApprovePlanStatus(StatusEnum.REPORT_APPROVED_LEAD.getCode().byteValue());
                ReportRiskAssessInfo reportReject = reportRepository.save(reportById);
                if (ObjectUtils.isEmpty(reportReject)){
                    throw new BusinessException(this.getClass(), ResultCode.BUSINESS_ERROR_NOT_ALLOWED.getCode() ,"报告状态修改失败");
                }
                //修改实验状态-通过实验
                UpdateExperimentInfoBO updateBO = new UpdateExperimentInfoBO();
                updateBO.setExperimentId(reportById.getExperimentId());
                updateBO.setApprovalStatus(ExperimentApprovalStatusEnum.APPROVAL_SUCCESS.getValue());
                updateBO.setRectifyStatus(ExperimentRectifyStatusEnum.NOT_RECTIFY.getValue());
                ExperimentInfo experimentInfo = experimentInfoService.updateExperimentStatus(updateBO);
                if (ObjectUtils.isEmpty(experimentInfo)){
                    throw new BusinessException(this.getClass(), ResultCode.BUSINESS_ERROR_NOT_ALLOWED.getCode() ,"实验信息状态修改失败");
                }
 
                //添加评估记录  todo
                ExperimentAssessLog experimentAssessLog = new ExperimentAssessLog();
                experimentAssessLog.setExperimentCode(experimentInfo.getExperimentCode());
                experimentAssessLog.setAssessEndTime(date);
                experimentAssessLog.setAssessUser(user.getRealName());
                experimentAssessLog.setAssessResult(StatusEnum.APPROVED_PASS.getCode().byteValue());
                ExperimentAssessLog experimentAssessLogResult = experimentAssessLogService.saveExperimentAssessLog(experimentAssessLog);
                if (ObjectUtils.isEmpty(experimentAssessLogResult)){
                    throw new BusinessException(this.getClass(), ResultCode.BUSINESS_ERROR_NOT_ALLOWED.getCode() ,"实验信息评估记录写入失败");
                }
            }else {
                throw new BusinessException(this.getClass(), ResultCode.BUSINESS_ERROR_NOT_ALLOWED.getCode() ,"无操作权限");
            }
        }
 
        //2、任意审核不通过
        if (reportReqBO.getApproveStatus() == 3){
            approvePerson.setApproveStatus(StatusEnum.APPROVED_NOT_PASS.getCode().byteValue());
//            if (roleTag == 1){
//                //保存审核人员信息
//                approvePerson.setApproveIndex(1);
//                approvePerson.setApproveStage("管理人员审核");
//                ReportRiskAssessPerson assessPerson = reportPersonService.insertOneReportPerson(approvePerson);
//                if (ObjectUtils.isEmpty(assessPerson)){
//                    throw new BusinessException(this.getClass(), ResultCode.BUSINESS_ERROR_NOT_ALLOWED.getCode() ,"审核信息保存失败");
//                }
//            }
            if (roleTag == 2){
                //保存审核人员信息
                approvePerson.setApproveIndex(2);
                approvePerson.setApproveStage("综合办审核");
                ReportRiskAssessPerson assessPerson = reportPersonService.insertOneReportPerson(approvePerson);
                if (ObjectUtils.isEmpty(assessPerson)){
                    throw new BusinessException(this.getClass(), ResultCode.BUSINESS_ERROR_NOT_ALLOWED.getCode() ,"审核信息保存失败");
                }
            }else {
                throw new BusinessException(this.getClass(), ResultCode.BUSINESS_ERROR_NOT_ALLOWED.getCode() ,"无操作权限");
            }
            //修改报告状态
            reportById.setApprovePlanStatus(StatusEnum.REPORT_NOT_APPROVED.getCode().byteValue());
            ReportRiskAssessInfo reportReject = reportRepository.save(reportById);
            if (ObjectUtils.isEmpty(reportReject)){
                throw new BusinessException(this.getClass(), ResultCode.BUSINESS_ERROR_NOT_ALLOWED.getCode() ,"报告状态修改失败");
            }
 
            //修改实验状态,否决实验
            UpdateExperimentInfoBO updateBO = new UpdateExperimentInfoBO();
            updateBO.setExperimentId(reportById.getExperimentId());
            updateBO.setApprovalStatus(ExperimentApprovalStatusEnum.APPROVAL_FAIL.getValue());
            updateBO.setRectifyStatus(ExperimentRectifyStatusEnum.WAIT_RECTIFY.getValue());
            ExperimentInfo experimentInfo = experimentInfoService.updateExperimentStatus(updateBO);
            if (ObjectUtils.isEmpty(experimentInfo)){
                throw new BusinessException(this.getClass(), ResultCode.BUSINESS_ERROR_NOT_ALLOWED.getCode() ,"实验信息状态修改失败");
            }
 
 
            //添加评估记录 todo
            ExperimentAssessLog experimentAssessLog = new ExperimentAssessLog();
            experimentAssessLog.setExperimentCode(experimentInfo.getExperimentCode());
            experimentAssessLog.setAssessEndTime(date);
            experimentAssessLog.setAssessUser(user.getRealName());
            experimentAssessLog.setAssessResult(StatusEnum.APPROVED_NOT_PASS.getCode().byteValue());
            ExperimentAssessLog experimentAssessLogResult = experimentAssessLogService.saveExperimentAssessLog(experimentAssessLog);
            if (ObjectUtils.isEmpty(experimentAssessLogResult)){
                throw new BusinessException(this.getClass(), ResultCode.BUSINESS_ERROR_NOT_ALLOWED.getCode() ,"实验信息评估记录写入失败");
            }
        }
 
        return StatusEnum.SUCCESS.getCode();
    }
 
    /**
     * 风险评估报告 - list
     */
    @Override
    public List<ReportAppQueryDTO> listRiskReport(List<Long> idList) {
 
        List<ReportRiskAssessInfo> reportRiskAssessList = reportRepository.listRiskReport(idList);
        if (reportRiskAssessList.size() <= 0){
            return null;
        }
        return BeanCopyUtils.copyBeanList(reportRiskAssessList, ReportAppQueryDTO.class);
    }
 
    @Override
    public ReportRiskAssessInfo getByExperimentId(Long id) {
        return reportRepository.getByExperimentId(id);
    }
}