songhuangfeng123
2022-08-17 8702c17288c16ec3d6760326e85cae37bbb10af8
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
package com.gkhy.safePlatform.incidentManage.service.impl;
 
import com.gkhy.safePlatform.commons.enums.ResultCodes;
import com.gkhy.safePlatform.commons.utils.BeanCopyUtils;
import com.gkhy.safePlatform.commons.vo.ResultVO;
import com.gkhy.safePlatform.incidentManage.entity.*;
import com.gkhy.safePlatform.incidentManage.model.dto.resp.*;
import com.gkhy.safePlatform.incidentManage.query.AccidentReportCountQuery;
import com.gkhy.safePlatform.incidentManage.query.db.AccidentReportRPCDBQuery;
import com.gkhy.safePlatform.incidentManage.service.AccidentCountService;
import com.gkhy.safePlatform.incidentManage.service.baseService.AccidentReportInfoService;
import com.gkhy.safePlatform.incidentManage.utils.TimeUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
 
import java.util.*;
 
@Service("accidentCountService")
public class AccidentCountServiceImpl implements AccidentCountService {
 
    @Autowired
    private AccidentReportInfoService accidentReportInfoService;
 
 
    @Override
    public ResultVO<List<AccidentReportCountRespDTO>> countAccidentReport(AccidentReportCountQuery query) {
 
        List<AccidentReportCount> list = new ArrayList<>();
        AccidentReportRPCDBQuery dbQuery = new AccidentReportRPCDBQuery();
        if (query.getType() == 1) {
            // 月
            int year = query.getYear();
            int month;
            if (query.getMonth() == 0) {
                Calendar date = Calendar.getInstance();
                month = date.get(Calendar.MONTH) + 1;
            } else {
                month = query.getMonth();
            }
            dbQuery.setStartTime(TimeUtils.getMonthFirst(year, month));
            dbQuery.setEndTime(TimeUtils.getMonthLast(year, month));
            list = accidentReportInfoService.selectByTimeAndType(dbQuery);
        }
        if (query.getType() == 2) {
            // 年
            int year = query.getYear();
            dbQuery.setStartTime(TimeUtils.getYearFirst(year));
            dbQuery.setEndTime(TimeUtils.getYearLast(year));
            list = accidentReportInfoService.selectByTimeAndType(dbQuery);
        }
 
        List<AccidentReportCountRespDTO> accidentReportCountRespDTOList = BeanCopyUtils.copyBeanList(list, AccidentReportCountRespDTO.class);
        return new ResultVO<>(ResultCodes.OK, accidentReportCountRespDTOList);
    }
 
}