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
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
package com.gkhy.safePlatform.emergency.service.impl;
 
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.gkhy.safePlatform.account.rpc.apimodel.AccountDepartmentService;
import com.gkhy.safePlatform.commons.enums.E;
import com.gkhy.safePlatform.commons.enums.ResultCodes;
import com.gkhy.safePlatform.commons.exception.BusinessException;
import com.gkhy.safePlatform.commons.query.PageQuery;
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.emergency.entity.*;
import com.gkhy.safePlatform.emergency.model.dto.resp.*;
import com.gkhy.safePlatform.emergency.query.EmergencyDrillExecuteCountQuery;
import com.gkhy.safePlatform.emergency.query.EmergencySuppliesCountQuery;
import com.gkhy.safePlatform.emergency.service.EmergencyCountService;
import com.gkhy.safePlatform.emergency.service.EmergencySuppliesService;
import com.gkhy.safePlatform.emergency.service.baseService.EmergencyDrillExecuteInfoService;
import com.gkhy.safePlatform.emergency.service.baseService.EmergencySuppliesInfoService;
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;
 
    @Autowired
    private EmergencySuppliesInfoService emergencySuppliesInfoService;
 
 
 
    @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);
    }
 
    @Override
    public ResultVO<List<EmergencySuppliesCountRespDTO>> countEmergencySupplies(PageQuery<EmergencySuppliesCountQuery> pageQuery) {
        List<EmergencySuppliesCountRespDTO> respList = new ArrayList<>();
 
        Long pageIndex = pageQuery.getPageIndex();
        Long pageSize = pageQuery.getPageSize();
        Page<EmergencySuppliesInfoDetailDO> page = new Page<>(pageIndex,pageSize);
        List<EmergencySuppliesInfoDetailDO> emergencySuppliesInfoDetailDOList =  emergencySuppliesInfoService.countEmergencySupplies(page,pageQuery.getSearchParams());
 
        if (!CollectionUtils.isEmpty(emergencySuppliesInfoDetailDOList)){
            for (EmergencySuppliesInfoDetailDO emergencySuppliesInfoDetailDO :emergencySuppliesInfoDetailDOList){
                EmergencySuppliesCountRespDTO emergencySuppliesCountRespDTO = new EmergencySuppliesCountRespDTO();
                // 名称+数量
                emergencySuppliesCountRespDTO.setName(emergencySuppliesInfoDetailDO.getName());
                emergencySuppliesCountRespDTO.setTotalNum(emergencySuppliesInfoDetailDO.getCount());
//                // 保质期内数量
//                SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");//格式化一下
//                Date produceDate = emergencySuppliesInfoDetailDO.getProductionDate();
//                Integer usePeriod = emergencySuppliesInfoDetailDO.getUsePeriod();
//
//                String[] arr = sdf.format(produceDate).split("-");
//
//                Calendar calendar = Calendar.getInstance();//获取对日期操作的类对象
//                calendar.clear();
//                calendar.set(Calendar.YEAR, Integer.parseInt(arr[0]));
//                calendar.set(Calendar.MONTH, Integer.parseInt(arr[1]));
//                calendar.set(Calendar.DAY_OF_MONTH, Integer.parseInt(arr[2]));
//
//                calendar.set(Calendar.DAY_OF_YEAR,calendar.get(Calendar.DAY_OF_YEAR) +usePeriod);
//
//                Date qualityD = calendar.getTime();
//                String time= sdf.format(calendar.getTime());
//                System.out.println(time);
 
                respList.add(emergencySuppliesCountRespDTO);
            }
        }
        return new SearchResultVO<>(
                true,
                pageIndex,
                pageSize,page.getPages(),
                page.getTotal(),
                respList,
                ResultCodes.OK
        );
    }
 
    public static void main(String[] args) {
         Date date = new Date();//获取当前日期
         SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");//格式化一下
         Calendar calendar1 = Calendar.getInstance();//获取对日期操作的类对象
         //两种写法都可以获取到前三天的日期
          calendar1.set(Calendar.DAY_OF_YEAR,calendar1.get(Calendar.DAY_OF_YEAR) -40);
         //在当前时间的基础上获取前三天的日期
//         calendar1.add(Calendar.DATE, -40);
        //add方法 参数也可传入 月份,获取的是前几月或后几月的日期
        //calendar1.add(Calendar.MONTH, -3);
         Date today = calendar1.getTime();
         String time= sdf.format(today);
        System.out.println(time);
    }
}