songhuangfeng123
2022-08-16 b98d1d16f81efb2a7795f1b8753e10a3fa98968f
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
package com.gkhy.safePlatform.emergency.service.impl;
 
import com.gkhy.safePlatform.account.rpc.apimodel.AccountDepartmentService;
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.emergency.entity.*;
import com.gkhy.safePlatform.emergency.model.dto.resp.*;
import com.gkhy.safePlatform.emergency.query.EmergencyDrillExecuteCountQuery;
import com.gkhy.safePlatform.emergency.service.EmergencyCountService;
import com.gkhy.safePlatform.emergency.service.baseService.EmergencyDrillExecuteInfoService;
import com.gkhy.safePlatform.emergency.utils.TimeUtils;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
 
import java.text.SimpleDateFormat;
import java.util.*;
 
@Service("emergencyCountService")
public class EmergencyCountServiceImpl implements EmergencyCountService {
 
    @Autowired
    private EmergencyDrillExecuteInfoService emergencyDrillExecuteInfoService;
 
    @DubboReference(check = false)
    private AccountDepartmentService accountDepartmentService;
 
 
    @Override
    public ResultVO<EmergencyDrillExecuteCountRespDTO> countEmergencyDrillExecute(EmergencyDrillExecuteCountQuery query) {
 
        EmergencyDrillExecuteCountRespDTO emergencyDrillExecuteCountRespDTO = new EmergencyDrillExecuteCountRespDTO();
 
        // 根据最新的应急演练实施的创建时间与当前时间  获取间隔天数
        Integer days = emergencyDrillExecuteInfoService.selectEmergencyDrillExecuteIntervalTime();
        emergencyDrillExecuteCountRespDTO.setDays(days);
 
        // 根据时间类型(年/月),部门id 获取统计结果
        List<EmergencyDrillExecuteCountData> list = new ArrayList<>();
        // 获取部门id集合
        List<Long> deptIds = new ArrayList<>();
 
        ResultVO<List<Long>> rpcResult = accountDepartmentService.listDepAndSubDepIds(query.getDeptId());
        if (rpcResult != null && rpcResult.getCode().equals(ResultCodes.OK.getCode())) {
            if (rpcResult.getData() != null) {
                deptIds = (List<Long>) rpcResult.getData();
            }
        }else{
            throw new BusinessException(ResultCodes.CLIENT_DEP_NOT_EXIST);
        }
        // 获取时间
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy");
        Date date = new Date();
        int year = Integer.parseInt(sdf.format(date));
        if (query.getType()==1){
            // 月
            String startTime = TimeUtils.getYearFirst(year);
            String endTime = TimeUtils.getYearLast(year);
            list = emergencyDrillExecuteInfoService.selectByMonthAndDept(startTime,endTime,deptIds);
        }
        if (query.getType()==2){
            // 年
            String startTime = TimeUtils.getYearFirst(year-10);
            String endTime = TimeUtils.getYearLast(year);
            list = emergencyDrillExecuteInfoService.selectByYearAndDept(startTime,endTime,deptIds);
        }
 
        if (!CollectionUtils.isEmpty(list)){
            List<EmergencyDrillExecuteCountDataRespDTO> dataList = BeanCopyUtils.copyBeanList(list,EmergencyDrillExecuteCountDataRespDTO.class);
            emergencyDrillExecuteCountRespDTO.setDataList(dataList);
        }else{
            emergencyDrillExecuteCountRespDTO.setDataList(new ArrayList<>());
        }
        return new ResultVO<>(ResultCodes.OK,emergencyDrillExecuteCountRespDTO);
    }
}