zhangf
2024-05-08 0414ddb0b2b3a7199ae6181a770f97ac140dbd73
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
package com.gkhy.safePlatform.incidentManage.rpc.provider;
 
 
import com.gkhy.safePlatform.commons.enums.ResultCodes;
import com.gkhy.safePlatform.commons.exception.BusinessException;
import com.gkhy.safePlatform.commons.utils.BeanCopyUtils;
import com.gkhy.safePlatform.commons.vo.ResultVO;
import com.gkhy.safePlatform.commons.vo.SearchResultVO;
import com.gkhy.safePlatform.incidentManage.enums.AccidentResultCodes;
import com.gkhy.safePlatform.incidentManage.exception.AccidentException;
import com.gkhy.safePlatform.incidentManage.model.dto.resp.*;
import com.gkhy.safePlatform.incidentManage.query.IncidentManageCountQuery;
import com.gkhy.safePlatform.incidentManage.rpc.api.IncidentManageRpcAPi;
import com.gkhy.safePlatform.incidentManage.rpc.api.model.dto.req.IncidentManageCountRPCReq;
import com.gkhy.safePlatform.incidentManage.rpc.api.model.dto.resp.*;
import com.gkhy.safePlatform.incidentManage.service.AccidentCountService;
import org.apache.commons.collections.CollectionUtils;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
 
import java.util.ArrayList;
import java.util.List;
 
@DubboService
public class IncidentManageRpcProvider implements IncidentManageRpcAPi {
 
    @Autowired
    private AccidentCountService accidentCountService;
 
    @Override
    public SearchResultVO<IncidentManageRPCResp> getCountByDeptId(IncidentManageCountRPCReq query) {
        return accidentCountService.getCountByDeptId(query);
    }
 
    @Override
    public SearchResultVO<List<IncidentManageRPCResp>> getCountByDeptIds(IncidentManageCountRPCReq query) {
        return accidentCountService.getCountByDeptIds(query);
    }
 
    @Override
    public ResultVO<StatisticsDepLevelMonthAccidentRPCRespDTO> getAccidentCountByDeptIdAndMonth(IncidentManageCountRPCReq query) {
        ResultVO<StatisticsDepLevelMonthAccidentRPCRespDTO> result = new ResultVO<>(ResultCodes.OK);
        IncidentManageCountQuery countQuery = new IncidentManageCountQuery();
        countQuery.setDeptId(query.getDeptId());
        countQuery.setYear(query.getYear());
        countQuery.setMonth(query.getMonth());
        try{
            StatisticsDepLevelMonthAccidentRespDTO accidentRespDTO = accidentCountService.getCountByDeptIdAndMonth(countQuery);
            StatisticsDepLevelMonthAccidentRPCRespDTO accidentRPCRespDTO = new StatisticsDepLevelMonthAccidentRPCRespDTO();
            accidentRPCRespDTO.setMonth(accidentRespDTO.getMonth());
            accidentRPCRespDTO.setDepLevel(accidentRespDTO.getDepLevel());
            List<AccidentLevelResultCountRespDTO> accidentLevelList = accidentRespDTO.getAccidentLevelList();
            if(!CollectionUtils.isEmpty(accidentLevelList)){
                List<AccidentLevelResultCountRPCRespDTO> resultCountRPCRespDTOList = BeanCopyUtils.copyBeanList(accidentLevelList, AccidentLevelResultCountRPCRespDTO.class);
                accidentRPCRespDTO.setAccidentLevelList(resultCountRPCRespDTOList);
            }
            result.setData(accidentRPCRespDTO);
        }catch (AccidentException e){
            result.setCode(e.getCode());
            result.setMsg(e.getMessage());
        }catch (Exception e) {
            result.setCode(AccidentResultCodes.ERROR.getCode());
            result.setMsg(AccidentResultCodes.ERROR.getDesc());
        }
        return result;
    }
 
    @Override
    public ResultVO<StatisticsDeptLevelYearAccidentRPCRespDTO> getAccidentCountByDeptIdAndYear(IncidentManageCountRPCReq query) {
        ResultVO<StatisticsDeptLevelYearAccidentRPCRespDTO> result = new ResultVO<>(ResultCodes.OK);
        IncidentManageCountQuery countQuery = new IncidentManageCountQuery();
        countQuery.setDeptId(query.getDeptId());
        countQuery.setYear(query.getYear());
        countQuery.setMonth(query.getMonth());
        try{
            StatisticsDeptLevelYearAccidentRespDTO accidentRespDTO = accidentCountService.getCountByDeptIdAndYear(countQuery);
            StatisticsDeptLevelYearAccidentRPCRespDTO accidentRPCRespDTO = new StatisticsDeptLevelYearAccidentRPCRespDTO();
            accidentRPCRespDTO.setYear(accidentRespDTO.getYear());
            accidentRPCRespDTO.setDepLevel(accidentRespDTO.getDepLevel());
            List<StatisticsDepLevelMonthAccidentRespDTO> monthList = accidentRespDTO.getMonthList();
            List<StatisticsDepLevelMonthAccidentRPCRespDTO> monthAccidentRPCRespDTOList = new ArrayList<>();
            if(!CollectionUtils.isEmpty(monthList)){
                for(StatisticsDepLevelMonthAccidentRespDTO monthAccidentRespDTO : monthList){
                    StatisticsDepLevelMonthAccidentRPCRespDTO monthAccidentRPCRespDTO = new StatisticsDepLevelMonthAccidentRPCRespDTO();
                    monthAccidentRPCRespDTO.setMonth(monthAccidentRespDTO.getMonth());
                    monthAccidentRPCRespDTO.setDepLevel(monthAccidentRespDTO.getDepLevel());
                    List<AccidentLevelResultCountRespDTO> accidentLevelList = monthAccidentRespDTO.getAccidentLevelList();
                    if(!CollectionUtils.isEmpty(accidentLevelList)){
                        List<AccidentLevelResultCountRPCRespDTO> resultCountRPCRespDTOList = BeanCopyUtils.copyBeanList(accidentLevelList, AccidentLevelResultCountRPCRespDTO.class);
                        monthAccidentRPCRespDTO.setAccidentLevelList(resultCountRPCRespDTOList);
                    }
                    monthAccidentRPCRespDTOList.add(monthAccidentRPCRespDTO);
                }
            }
            accidentRPCRespDTO.setMonthList(monthAccidentRPCRespDTOList);
            result.setData(accidentRPCRespDTO);
        }catch (AccidentException e){
            result.setCode(e.getCode());
            result.setMsg(e.getMessage());
        }catch (Exception e) {
            result.setCode(AccidentResultCodes.ERROR.getCode());
            result.setMsg(AccidentResultCodes.ERROR.getDesc());
        }
        return result;
    }
 
    @Override
    public ResultVO<List<StatisticsDepLevelMonthAccidentRPCRespDTO>> getAccidentCountByDeptIdsAndMonth(IncidentManageCountRPCReq query) {
        ResultVO<List<StatisticsDepLevelMonthAccidentRPCRespDTO>> result = new ResultVO<>(ResultCodes.OK);
        IncidentManageCountQuery countQuery = new IncidentManageCountQuery();
        countQuery.setDeptId(query.getDeptId());
        countQuery.setYear(query.getYear());
        countQuery.setMonth(query.getMonth());
        try{
            List<StatisticsDepLevelMonthAccidentRespDTO> accidentRespDTOList = accidentCountService.getCountByDeptIdsAndMonth(countQuery);
            List<StatisticsDepLevelMonthAccidentRPCRespDTO> accidentRPCRespDTOList = new ArrayList<>();
            for(StatisticsDepLevelMonthAccidentRespDTO accidentRespDTO:accidentRespDTOList){
                StatisticsDepLevelMonthAccidentRPCRespDTO accidentRPCRespDTO = new StatisticsDepLevelMonthAccidentRPCRespDTO();
                accidentRPCRespDTO.setMonth(accidentRespDTO.getMonth());
                accidentRPCRespDTO.setDepLevel(accidentRespDTO.getDepLevel());
                List<AccidentLevelResultCountRespDTO> accidentLevelList = accidentRespDTO.getAccidentLevelList();
                if(!CollectionUtils.isEmpty(accidentLevelList)){
                    List<AccidentLevelResultCountRPCRespDTO> resultCountRPCRespDTOList = BeanCopyUtils.copyBeanList(accidentLevelList, AccidentLevelResultCountRPCRespDTO.class);
                    accidentRPCRespDTO.setAccidentLevelList(resultCountRPCRespDTOList);
                }
                accidentRPCRespDTOList.add(accidentRPCRespDTO);
            }
            result.setData(accidentRPCRespDTOList);
        }catch (AccidentException e){
            result.setCode(e.getCode());
            result.setMsg(e.getMessage());
        }catch (Exception e) {
            result.setCode(AccidentResultCodes.ERROR.getCode());
            result.setMsg(AccidentResultCodes.ERROR.getDesc());
        }
        return result;
    }
 
    @Override
    public ResultVO<List<StatisticsDeptLevelYearAccidentRPCRespDTO>> getAccidentCountByDeptIdsAndYear(IncidentManageCountRPCReq query) {
        ResultVO<List<StatisticsDeptLevelYearAccidentRPCRespDTO>> result = new ResultVO<>(ResultCodes.OK);
        IncidentManageCountQuery countQuery = new IncidentManageCountQuery();
        countQuery.setDeptId(query.getDeptId());
        countQuery.setYear(query.getYear());
        countQuery.setMonth(query.getMonth());
        try{
            List<StatisticsDeptLevelYearAccidentRespDTO> yearAccidentRespDTOList = accidentCountService.getCountByDeptIdsAndYear(countQuery);
            List<StatisticsDeptLevelYearAccidentRPCRespDTO> accidentRPCRespDTOList = new ArrayList<>();
            for(StatisticsDeptLevelYearAccidentRespDTO yearAccidentRespDTO:yearAccidentRespDTOList){
                StatisticsDeptLevelYearAccidentRPCRespDTO yearAccidentRPCRespDTO = new StatisticsDeptLevelYearAccidentRPCRespDTO();
                yearAccidentRPCRespDTO.setYear(yearAccidentRespDTO.getYear());
                yearAccidentRPCRespDTO.setDepLevel(yearAccidentRespDTO.getDepLevel());
                List<StatisticsDepLevelMonthAccidentRespDTO> monthList = yearAccidentRespDTO.getMonthList();
                List<StatisticsDepLevelMonthAccidentRPCRespDTO> monthAccidentRPCRespDTOList = new ArrayList<>();
                if(!CollectionUtils.isEmpty(monthList)){
                    for(StatisticsDepLevelMonthAccidentRespDTO monthAccidentRespDTO:monthList){
                        StatisticsDepLevelMonthAccidentRPCRespDTO monthAccidentRPCRespDTO = new StatisticsDepLevelMonthAccidentRPCRespDTO();
                        monthAccidentRPCRespDTO.setMonth(monthAccidentRespDTO.getMonth());
                        monthAccidentRPCRespDTO.setDepLevel(monthAccidentRespDTO.getDepLevel());
                        List<AccidentLevelResultCountRespDTO> accidentLevelList = monthAccidentRespDTO.getAccidentLevelList();
                        if (!CollectionUtils.isEmpty(accidentLevelList)) {
                            List<AccidentLevelResultCountRPCRespDTO> resultCountRPCRespDTOList = BeanCopyUtils.copyBeanList(accidentLevelList, AccidentLevelResultCountRPCRespDTO.class);
                            monthAccidentRPCRespDTO.setAccidentLevelList(resultCountRPCRespDTOList);
                        }
                        monthAccidentRPCRespDTOList.add(monthAccidentRPCRespDTO);
                    }
                }
                accidentRPCRespDTOList.add(yearAccidentRPCRespDTO);
 
            }
            result.setData(accidentRPCRespDTOList);
        }catch (AccidentException e){
            result.setCode(e.getCode());
            result.setMsg(e.getMessage());
        }catch (Exception e) {
            result.setCode(AccidentResultCodes.ERROR.getCode());
            result.setMsg(AccidentResultCodes.ERROR.getDesc());
        }
        return result;
    }
 
    @Override
    public ResultVO<List<IncidentStatisticCountRPCRespDTO>> getAccidentCountByGradeAndTime(IncidentManageCountRPCReq query){
        ResultVO<List<IncidentStatisticCountRPCRespDTO>> result = new ResultVO<>(ResultCodes.OK);
        try{
            List<AccidentStatisticDTO> countByAccidentGradeList = accidentCountService.getCountByAccidentGrade(query.getYear(), query.getMonth());
 
            List<IncidentStatisticCountRPCRespDTO> statisticCountRPCRespDTOList = new ArrayList<>();
            for(AccidentStatisticDTO accidentStatisticDTO:countByAccidentGradeList){
                IncidentStatisticCountRPCRespDTO accidentRPCRespDTO = new IncidentStatisticCountRPCRespDTO();
                accidentRPCRespDTO.setAccidentGrade(accidentStatisticDTO.getAccidentGrade());
                accidentRPCRespDTO.setCount(accidentStatisticDTO.getCount());
                statisticCountRPCRespDTOList.add(accidentRPCRespDTO);
            }
            result.setData(statisticCountRPCRespDTOList);
        }catch (AccidentException e){
            result.setCode(e.getCode());
            result.setMsg(e.getMessage());
        }catch (BusinessException e){
            result.setCode(e.getCode());
            result.setMsg(e.getMessage());
        }catch (Exception e) {
            result.setCode(AccidentResultCodes.ERROR.getCode());
            result.setMsg(AccidentResultCodes.ERROR.getDesc());
        }
        return result;
    }
    @Override
    public ResultVO<AccidentCountByGradeRPCRespDTO> getSpiAccidentCountByGradeAndTime(IncidentManageCountRPCReq query){
        ResultVO<AccidentCountByGradeRPCRespDTO> result = new ResultVO<>(ResultCodes.OK);
        try{
            AccidentCountByGradeRespDTO accidentCountByGradeRespDTO = accidentCountService.getSpiAccidentCountByAccidentGrade(query.getYear(), query.getMonth());
            AccidentCountByGradeRPCRespDTO accidentRPCRespDTO = new AccidentCountByGradeRPCRespDTO();
            BeanUtils.copyProperties(accidentCountByGradeRespDTO, accidentRPCRespDTO);
            result.setData(accidentRPCRespDTO);
        }catch (AccidentException e){
            result.setCode(e.getCode());
            result.setMsg(e.getMessage());
        }catch (BusinessException e){
            result.setCode(e.getCode());
            result.setMsg(e.getMessage());
        }catch (Exception e) {
            result.setCode(AccidentResultCodes.ERROR.getCode());
            result.setMsg(AccidentResultCodes.ERROR.getDesc());
        }
        return result;
    }
}