heheng
2025-01-13 a27162cb82ef0cabf9b43cbfd1f3eb8c177d1e14
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
package com.gkhy.labRiskManage.application.riskReport.service.impl;
 
import com.gkhy.labRiskManage.api.controller.riskReport.dto.repDto.ReportInfoUpdateReqBO;
import com.gkhy.labRiskManage.api.controller.riskReport.dto.repDto.ReportQueryReqBO;
import com.gkhy.labRiskManage.api.controller.riskReport.dto.repDto.ReportReqBO;
import com.gkhy.labRiskManage.api.controller.riskReport.dto.repDto.ReportUpdateReqBO;
import com.gkhy.labRiskManage.api.controller.riskReport.dto.respDto.ReportQueryRespDTO;
import com.gkhy.labRiskManage.application.riskReport.dto.bo.*;
import com.gkhy.labRiskManage.application.riskReport.dto.dto.ReportAppQueryDTO;
import com.gkhy.labRiskManage.application.riskReport.dto.dto.RiskAssessPlanAppQueryDTO;
import com.gkhy.labRiskManage.application.riskReport.service.ReportAppService;
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.config.annotation.RepeatSubmit;
import com.gkhy.labRiskManage.domain.account.service.UserDomainService;
import com.gkhy.labRiskManage.domain.experiment.service.ExperimentInfoService;
import com.gkhy.labRiskManage.domain.riskReport.model.dto.*;
import com.gkhy.labRiskManage.domain.riskReport.service.ReportExperimentRiskSourceService;
import com.gkhy.labRiskManage.domain.riskReport.service.ReportExperimentRiskSourceTypeService;
import com.gkhy.labRiskManage.domain.riskReport.service.ReportRiskAssessInfoService;
import com.gkhy.labRiskManage.domain.riskReport.service.ReportRiskAssessPersonService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.ObjectUtils;
 
import java.util.List;
 
@Service
public class ReportAppServiceImpl implements ReportAppService {
 
    @Autowired
    private ReportRiskAssessInfoService reportInfoService;
    @Autowired
    private ReportRiskAssessPersonService reportPersonService;
    @Autowired
    private ReportExperimentRiskSourceTypeService reportSourceTypeService;
    @Autowired
    private ReportExperimentRiskSourceService reportSourceService;
    @Autowired
    private UserDomainService userDomainService;
    @Autowired
    private ExperimentInfoService experimentInfoService;
 
 
    /**
     * 风险评估报告 - 查询
     */
    @Override
    public SearchResult<ReportQueryRespDTO> selectRiskReportPage(Long currentUserId, ReportQueryReqBO queryReqBO) {
 
        SearchResult searchResult = new SearchResult<>();
 
        ReportAppQueryBO queryParam = BeanCopyUtils.copyBean(queryReqBO, ReportAppQueryBO.class);
 
        SearchResult<ReportAppQueryDTO> queryResult = reportInfoService.selectRiskReportPage(currentUserId, queryParam);
 
        searchResult.setPageIndex(queryResult.getPageIndex());
        searchResult.setPageSize(queryResult.getPageSize());
        searchResult.setTotal(queryResult.getTotal());
        searchResult.setData(BeanCopyUtils.copyRiskAssessPlanAppQueryList(queryResult.getData(), RiskAssessPlanAppQueryDTO.class));
 
        return searchResult;
    }
 
    /**
     * 风险评估报告 - 生成报告信息
     */
    @Override
    public int insertRiskReport(Long currentUserId, Long id) {
 
        ReportInsertDTO insertResult = reportInfoService.insertRiskReport(currentUserId, id);
 
        if (ObjectUtils.isEmpty(insertResult)){
            return StatusEnum.FAIL.getCode();
        }
        return StatusEnum.SUCCESS.getCode();
    }
 
    /**
     * 风险评估报告 - 填写信息
     */
    @Transactional
    @Override
    public int updateRiskReport(Long currentUserId, ReportUpdateReqBO updateReqBO) {
 
        int i = 0;
        //报告信息
        ReportAppUpdateBO reportUpdateBO = BeanCopyUtils.copyBean(updateReqBO, ReportAppUpdateBO.class);
        ReportUpdateDTO reportUpdateDTO = reportInfoService.updateReportInfoById(currentUserId,reportUpdateBO);
        if (ObjectUtils.isEmpty(reportUpdateDTO)){
            i = 1;
        }
//
//        //审核人信息
//        if (!ObjectUtils.isEmpty(updateReqBO.getPerson())){
//            List<ReportPersonAppInsertBO> personInsertBO = BeanCopyUtils.copyBeanList(updateReqBO.getPerson(), ReportPersonAppInsertBO.class);
//            List<ReportPersonInsertDTO> reportPersonInsertDTOS = reportPersonService.insertReportPerson(currentUserId,personInsertBO);
//            if (reportPersonInsertDTOS.size() != personInsertBO.size()){
//                i = 1;
//            }
//        }
//
//        //危险源类型信息
//        if (!ObjectUtils.isEmpty(updateReqBO.getRiskSourceType())){
//            List<ReportSourceTypeAppInsertBO> reportSourceTypeInsertBO = BeanCopyUtils.copyBeanList(updateReqBO.getRiskSourceType(), ReportSourceTypeAppInsertBO.class);
//            List<ReportSourceTypeInsertDTO> reportSourceTypeInsertDTOS = reportSourceTypeService.insertReportSourceType(currentUserId,reportSourceTypeInsertBO);
//            if (reportSourceTypeInsertDTOS.size() != reportSourceTypeInsertBO.size()){
//                i = 1;
//            }
//        }
//
        //危险源信
        if (!ObjectUtils.isEmpty(updateReqBO.getRiskSource())){
            List<ReportSourceAppInsertBO> riskSourceInsertBO = BeanCopyUtils.copyBeanList(updateReqBO.getRiskSource(), ReportSourceAppInsertBO.class);
            List<ReportRiskSourceDTO> reportRiskSourceDTOS = reportSourceService.insertReportSource(currentUserId,riskSourceInsertBO);
            if (reportRiskSourceDTOS.size() != riskSourceInsertBO.size()){
                i = 1;
            }
        }
 
        if (ObjectUtils.isEmpty(reportUpdateDTO)){
            throw new BusinessException(this.getClass(), ResultCode.BUSINESS_ERROR.getCode(), "风险评估报告写入失败");
        }
        return StatusEnum.SUCCESS.getCode();
    }
 
    /**
     * 风险评估报告 - 修改报告信息
     */
    @Transactional
    @Override
    public int updateReportInfo(Long currentUserId, ReportInfoUpdateReqBO updateReqBO) {
 
        int i = 0;
        //报告信息
        ReportAppUpdateBO reportUpdateBO = BeanCopyUtils.copyBean(updateReqBO, ReportAppUpdateBO.class);
        ReportUpdateDTO reportUpdateDTO = reportInfoService.updateReportInfoById(currentUserId,reportUpdateBO);
        if (ObjectUtils.isEmpty(reportUpdateDTO)){
            i = 1;
        }
 
        //审核人信息
//        if (!ObjectUtils.isEmpty(updateReqBO.getPerson())){
//            List<ReportPersonAppUpdateBO> personUpdateBO = BeanCopyUtils.copyBeanList(updateReqBO.getPerson(), ReportPersonAppUpdateBO.class);
//            List<ReportPersonInsertDTO> reportPersonUpdateDTOS = reportPersonService.updateReportPerson(currentUserId, personUpdateBO);
//            if (reportPersonUpdateDTOS.size() != personUpdateBO.size()){
//                i = 1;
//            }
//        }
 
        //危险源类型信息
//        if (!ObjectUtils.isEmpty(updateReqBO.getRiskSourceType())){
//            List<ReportSourceTypeAppUpdateBO> reportSourceTypeUpdateBO = BeanCopyUtils.copyBeanList(updateReqBO.getRiskSourceType(), ReportSourceTypeAppUpdateBO.class);
//            List<ReportSourceTypeInsertDTO> reportSourceTypeUpdateDTOS = reportSourceTypeService.updateReportSourceType(currentUserId, reportSourceTypeUpdateBO);
//            if (reportSourceTypeUpdateDTOS.size() != reportSourceTypeUpdateBO.size()){
//                i = 1;
//            }
//        }
 
//        if (!ObjectUtils.isEmpty(updateReqBO.getRiskSource())){
//            //危险源信息
//            List<ReportSourceAppUpdateBO> riskSourceUpdateBO = BeanCopyUtils.copyBeanList(updateReqBO.getRiskSource(), ReportSourceAppUpdateBO.class);
//            List<ReportRiskSourceDTO> reportRiskSourceUpdateDTOS = reportSourceService.updateReportSource(currentUserId, riskSourceUpdateBO);
//            if (reportRiskSourceUpdateDTOS.size() != riskSourceUpdateBO.size()){
//                i = 1;
//            }
//        }
 
        if (i == 1){
            throw new BusinessException(this.getClass(), ResultCode.BUSINESS_ERROR.getCode(), "风险评估报告修改失败");
        }
        return StatusEnum.SUCCESS.getCode();
    }
 
    /**
     * 风险评估报告 - 报告审核 - 旧 - 两层审核
     */
    @Override
    public int report(Long currentUserId, ReportReqBO reportReqBO) {
 
        int report = reportInfoService.report(currentUserId, reportReqBO);
 
        if (report == 0){
            return StatusEnum.FAIL.getCode();
        }
        return StatusEnum.SUCCESS.getCode();
    }
 
    /**
     * 风险评估报告 - 报告审核 - 新 - 单次审核
     */
    @Override
    public int reportNew(Long currentUserId, ReportReqBO reportReqBO) {
 
        int report = reportInfoService.reportNew(currentUserId, reportReqBO);
 
        if (report == 0){
            return StatusEnum.FAIL.getCode();
        }
        return StatusEnum.SUCCESS.getCode();
    }
}