16639036659
2023-08-28 7a9a4f4764b0a402e3d0b4a1dafc7ecf96cb1583
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
package com.gkhy.labRiskManage.domain.riskReport.service.impl;
 
 
import com.gkhy.labRiskManage.api.controller.riskReport.dto.repDto.ReportReqBO;
import com.gkhy.labRiskManage.api.controller.riskReport.dto.respDto.ReportPersonQueryRespDTO;
import com.gkhy.labRiskManage.application.riskReport.dto.bo.ReportPersonAppInsertBO;
import com.gkhy.labRiskManage.application.riskReport.dto.bo.ReportPersonAppUpdateBO;
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.basic.model.dto.PersonQueryDTO;
import com.gkhy.labRiskManage.domain.basic.service.BasicExperimentPersonService;
import com.gkhy.labRiskManage.domain.riskReport.entity.ReportRiskAssessPerson;
import com.gkhy.labRiskManage.domain.riskReport.model.dto.ReportPersonInsertDTO;
import com.gkhy.labRiskManage.domain.riskReport.repository.jpa.ReportRiskAssessPersonRepository;
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.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
 
 
/**
 * 风险评估报告-评估专家
 */
@Service
public class ReportRiskAssessPersonServiceImpl implements ReportRiskAssessPersonService {
 
    @Autowired
    private ReportRiskAssessPersonRepository personRepository;
    @Autowired
    private BasicExperimentPersonService basicPersonService;
 
    /**
     * 风险评估报告-评估专家 - 插入
     */
    @Override
    public List<ReportPersonInsertDTO> insertReportPerson(Long currentUserId, List<ReportPersonAppInsertBO> personInsertBO) {
 
        if (personInsertBO.size() < 1){
            List<ReportPersonInsertDTO> list= new ArrayList<>();
            return list;
        }
 
        List<ReportRiskAssessPerson> reportPeopleList = BeanCopyUtils.copyBeanList(personInsertBO, ReportRiskAssessPerson.class);
        List<ReportRiskAssessPerson> personList = new ArrayList<>();
 
        for (ReportRiskAssessPerson reportPerson : reportPeopleList) {
            if (ObjectUtils.isEmpty(reportPerson.getReportId())){
                throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode(), "用户信息不能为空");
            }
            if (ObjectUtils.isEmpty(reportPerson.getApproveStage())){
                throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode(), "审批阶段名称不能为空");
            }
            if (ObjectUtils.isEmpty(reportPerson.getApproveIndex())){
                throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode(), "审批阶段排序不能为空");
            }
            if (ObjectUtils.isEmpty(reportPerson.getApproveDesc())){
                throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode(), "审批意见说明不能为空");
            }
            if (ObjectUtils.isEmpty(reportPerson.getApprovePersonId())){
                throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode(), "审批人不能为空");
            }
            PersonQueryDTO personById = basicPersonService.getBasicExperimentPersonById(reportPerson.getApprovePersonId());
            if (ObjectUtils.isEmpty(personById)){
                throw new BusinessException(this.getClass(), ResultCode.BUSINESS_ERROR_DATA_NOT_EXISIST.getCode(), "审批人不能为空");
            }
            //补全数据
            LocalDateTime date = LocalDateTime.now();
 
            reportPerson.setApprovePerson(personById.getPersonName());
            reportPerson.setCreateTime(date);
            reportPerson.setUpdateTime(date);
            reportPerson.setCreateByUserId(currentUserId);
            reportPerson.setUpdateByUserId(currentUserId);
            reportPerson.setDeleteStatus(StatusEnum.DELETE_NOT.getCode().byteValue());
            reportPerson.setApproveStatus(StatusEnum.EXPERIMENT_STATUS_NOT_START.getCode().byteValue());
 
            personList.add(reportPerson);
        }
        List<ReportRiskAssessPerson> insertResult = personRepository.saveAll(personList);
        if (insertResult.size() != personInsertBO.size()){
            throw new BusinessException(this.getClass(), ResultCode.BUSINESS_ERROR.getCode(), "审批人写入失败");
        }
 
        return BeanCopyUtils.copyBeanList(insertResult, ReportPersonInsertDTO.class);
    }
 
    /**
     * 风险评估报告-评估专家 - 修改
     */
    @Override
    public List<ReportPersonInsertDTO> updateReportPerson(Long currentUserId, List<ReportPersonAppUpdateBO> personUpdateBO) {
 
        if (personUpdateBO.size() < 1){
            List<ReportPersonInsertDTO> list= new ArrayList<>();
            return list;
        }
 
        List<ReportRiskAssessPerson> reportPeopleList = BeanCopyUtils.copyBeanList(personUpdateBO, ReportRiskAssessPerson.class);
        List<ReportRiskAssessPerson> personList = new ArrayList<>();
 
        for (ReportRiskAssessPerson reportPerson : reportPeopleList) {
            if (ObjectUtils.isEmpty(reportPerson.getId())){
                throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode(), "审核人id不能为空");
            }
            if (ObjectUtils.isEmpty(reportPerson.getReportId())){
                throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode(), "用户信息不能为空");
            }
            if (ObjectUtils.isEmpty(reportPerson.getApproveStage())){
                throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode(), "审批阶段名称不能为空");
            }
            if (ObjectUtils.isEmpty(reportPerson.getApproveIndex())){
                throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode(), "审批阶段排序不能为空");
            }
            if (ObjectUtils.isEmpty(reportPerson.getApproveDesc())){
                throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode(), "审批意见说明不能为空");
            }
            if (ObjectUtils.isEmpty(reportPerson.getApprovePersonId())){
                throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode(), "审批人不能为空");
            }
            if (reportPerson.getApproveStatus() == StatusEnum.REPORT_APPROVED.getCode().byteValue()){
                throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode(), "审批人已经提交审核结果,无法修改信息");
            }
            PersonQueryDTO personById = basicPersonService.getBasicExperimentPersonById(reportPerson.getApprovePersonId());
            if (ObjectUtils.isEmpty(personById)){
                throw new BusinessException(this.getClass(), ResultCode.BUSINESS_ERROR_DATA_NOT_EXISIST.getCode(), "审批人不能为空");
            }
            ReportRiskAssessPerson person = personRepository.getPersonById(reportPerson.getId());
 
            //补全数据
            LocalDateTime date = LocalDateTime.now();
 
            person.setApprovePerson(personById.getPersonName());
            person.setUpdateTime(date);
            person.setUpdateByUserId(currentUserId);
            person.setApproveIndex(reportPerson.getApproveIndex());
            person.setApproveStage(reportPerson.getApproveStage());
            person.setApproveDesc(reportPerson.getApproveDesc());
            person.setApprovePersonId(reportPerson.getApprovePersonId());
 
            personList.add(person);
        }
 
        List<ReportRiskAssessPerson> updateResult = personRepository.saveAll(personList);
        if (updateResult.size() != personUpdateBO.size()){
            throw new BusinessException(this.getClass(), ResultCode.BUSINESS_ERROR.getCode(), "审批人写入失败");
        }
        
        return BeanCopyUtils.copyBeanList(updateResult, ReportPersonInsertDTO.class);
    }
 
    /**
     * 风险评估报告-评估专家 - 查询
     */
    @Override
    public ReportPersonInsertDTO getPersonById(Long id) {
        if (ObjectUtils.isEmpty(id)){
            throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode() ,"报告审核人不能为空");
        }
        ReportRiskAssessPerson personById = personRepository.getPersonById(id);
        if (ObjectUtils.isEmpty(personById)){
            throw new BusinessException(this.getClass(), ResultCode.BUSINESS_ERROR.getCode(), "审批人不存在或已被删除");
        }
        return BeanCopyUtils.copyBean(personById, ReportPersonInsertDTO.class);
    }
 
    /**
     * 风险评估报告-评估专家 - list
     */
    @Override
    public List<ReportPersonInsertDTO> getPersonByReportId(Long reportId) {
        if (ObjectUtils.isEmpty(reportId)){
            throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode() ,"报告id不能为空");
        }
 
        List<ReportRiskAssessPerson> personList = personRepository.getPersonByReportId(reportId);
        if (ObjectUtils.isEmpty(personList)){
            return null;
        }
 
        return BeanCopyUtils.copyBeanList(personList, ReportPersonInsertDTO.class);
    }
 
    /**
     * 风险评估报告-评估专家
     */
    @Override
    public List<ReportPersonQueryRespDTO> listPersonByReportId(Long id) {
        if (ObjectUtils.isEmpty(id)){
            throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode() ,"报告id不能为空");
        }
 
        List<ReportRiskAssessPerson> personList = personRepository.getPersonByReportId(id);
        if (ObjectUtils.isEmpty(personList)){
            return null;
        }
 
        return BeanCopyUtils.copyBeanList(personList, ReportPersonQueryRespDTO.class);
    }
 
    /**
     * 风险评估报告-评估专家 - 审核
     */
    @Transactional
    @Override
    public ReportPersonInsertDTO report(Long currentUserId, ReportReqBO reportReqBO) {
 
        if (ObjectUtils.isEmpty(reportReqBO.getId())){
            throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode() ,"报告id不能为空");
        }
        if (ObjectUtils.isEmpty(reportReqBO.getApproveStatus())){
            throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode() ,"审批状态不能为空");
        }
        //获取审核人信息
        ReportRiskAssessPerson personById = personRepository.getPersonById(reportReqBO.getId());
 
        LocalDateTime date = LocalDateTime.now();
 
        personById.setApproveDesc(reportReqBO.getApproveDesc());
        personById.setApproveTime(date);
        personById.setApproveStatus(reportReqBO.getApproveStatus());
        ReportRiskAssessPerson save = personRepository.save(personById);
        if (ObjectUtils.isEmpty(save)){
            throw new BusinessException(this.getClass(), ResultCode.BUSINESS_ERROR.getCode(), "审核失败");
        }
        return BeanCopyUtils.copyBean(save, ReportPersonInsertDTO.class);
    }
 
    @Override
    public ReportRiskAssessPerson insertOneReportPerson(ReportRiskAssessPerson approvePerson) {
        return personRepository.save(approvePerson);
    }
}