郑永安
2023-09-19 69185134fcfaf913ea45f1255677225a2cc311a4
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
package com.gk.hotwork.doublePrevention.service.impl;
 
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.gk.hotwork.Domain.Vo.PageInfoExtension;
import com.gk.hotwork.doublePrevention.entity.PreventDangerCheckTaskRectifyDO;
import com.gk.hotwork.doublePrevention.entity.PreventProduceDevice;
import com.gk.hotwork.doublePrevention.entity.dto.req.StatisticsInspectionCompletedReqDTO;
import com.gk.hotwork.doublePrevention.entity.dto.req.StatisticsInspectionTaskReqDTO;
import com.gk.hotwork.doublePrevention.entity.dto.req.StatisticsInspectorReqDTO;
import com.gk.hotwork.doublePrevention.entity.dto.req.StatisticsPreventDangerPageReqDTO;
import com.gk.hotwork.doublePrevention.entity.dto.resp.PreventDangerCheckTaskRectifyRespDTO;
import com.gk.hotwork.doublePrevention.service.StatisticsService;
import com.gk.hotwork.doublePrevention.service.baseService.PreventDangerCheckTaskService;
import com.gk.hotwork.doublePrevention.service.baseService.PreventProduceDeviceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
 
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
import java.util.*;
 
 
@Service("statisticsService")
public class StatisticsServiceImpl implements StatisticsService {
 
    @Autowired
    private PreventDangerCheckTaskService preventDangerCheckTaskService;
    @Autowired
    private PreventProduceDeviceService preventProduceDeviceService;
 
    @Override
    public List<Map> selectInspectorsStatistics(StatisticsInspectorReqDTO reqDTO) {
        LocalDateTime startTime = null;
        LocalDateTime endTime = null;
        if (reqDTO.getStartTime() != null) {
            startTime = LocalDateTime.ofInstant(reqDTO.getStartTime().toInstant(), ZoneId.systemDefault());
        }
        if (reqDTO.getEndTime() != null) {
            endTime = LocalDateTime.ofInstant(reqDTO.getEndTime().toInstant(), ZoneId.systemDefault());
        }
        Long depId = reqDTO.getDepId();
        Calendar instance = Calendar.getInstance();
        instance.setTime(new Date());
        if (endTime == null) {
            endTime = LocalDate.now().atTime(23, 59, 59);
        }
        if (startTime == null) {
            startTime = LocalDate.now().minusDays(7).atStartOfDay();
        }
        List<String> list = new ArrayList<>();
        // 解析出每天
        LocalDateTime loopTime = startTime.plusDays(0);
        while(loopTime.isBefore(endTime)){//当明天不在结束时间之前是终止循环
            list.add(loopTime.format(DateTimeFormatter.ofPattern("yyyy-MM-dd")));
            loopTime = loopTime.plusDays(1L);
        }
 
        return preventDangerCheckTaskService.selectInspectorsStatistics(depId,list, startTime, endTime);
    }
 
    @Override
    public List<Map> selectInspectionCompleted(StatisticsInspectionCompletedReqDTO reqDTO) {
        LocalDateTime startTime = null;
        LocalDateTime endTime = null;
        if (reqDTO.getStartTime() != null) {
            startTime = LocalDateTime.ofInstant(reqDTO.getStartTime().toInstant(), ZoneId.systemDefault());
        }
        if (reqDTO.getEndTime() != null) {
            endTime = LocalDateTime.ofInstant(reqDTO.getEndTime().toInstant(), ZoneId.systemDefault());
        }
        Long depId = reqDTO.getDepId();
        Calendar instance = Calendar.getInstance();
        instance.setTime(new Date());
        if (endTime == null) {
            endTime = LocalDate.now().atTime(23, 59, 59);
        }
        if (startTime == null) {
            startTime = LocalDate.now().minusDays(7).atStartOfDay();
        }
        List<String> list = new ArrayList<>();
        // 解析出每天
        LocalDateTime loopTime = startTime.plusDays(0);
        while(loopTime.isBefore(endTime)){//当明天不在结束时间之前是终止循环
            list.add(loopTime.format(DateTimeFormatter.ofPattern("yyyy-MM-dd")));
            loopTime = loopTime.plusDays(1L);
        }
        return preventDangerCheckTaskService.selectInspectionCompleted(depId,reqDTO.getStatus(),list, startTime, endTime);
    }
 
    @Override
    public Map<String,List<Map>> selectInspectionTask(StatisticsInspectionTaskReqDTO reqDTO) {
        LocalDateTime startTime = null;
        LocalDateTime endTime = null;
        if (reqDTO.getStartTime() != null) {
            startTime = LocalDateTime.ofInstant(reqDTO.getStartTime().toInstant(), ZoneId.systemDefault());
        }
        if (reqDTO.getEndTime() != null) {
            endTime = LocalDateTime.ofInstant(reqDTO.getEndTime().toInstant(), ZoneId.systemDefault());
        }
        Long depId = reqDTO.getDepId();
        Calendar instance = Calendar.getInstance();
        instance.setTime(new Date());
        if (endTime == null) {
            endTime = LocalDate.now().atTime(23, 59, 59);
        }
        if (startTime == null) {
            startTime = LocalDate.now().minusDays(7).atStartOfDay();
        }
        List<String> list = new ArrayList<>();
        // 解析出每天
        LocalDateTime loopTime = startTime.plusDays(0);
        while(loopTime.isBefore(endTime)){//当明天不在结束时间之前是终止循环
            list.add(loopTime.format(DateTimeFormatter.ofPattern("yyyy-MM-dd")));
            loopTime = loopTime.plusDays(1L);
        }
        // 当日已认领
        List<Map> claimedData = preventDangerCheckTaskService.selectInspectionClaimedTask(depId, list, startTime, endTime);
        // 巡检完成数量
        List<Map> completedData = preventDangerCheckTaskService.selectInspectionCompletedTask(depId, list, startTime, endTime);
        // 巡检领取未完成数量
        List<Map> uncompletedData = preventDangerCheckTaskService.selectInspectionUnCompletedTask(depId, list, startTime, endTime);
        Map<String, List<Map>> result = new HashMap<>();
        result.put("claimed", claimedData);
        result.put("completed", completedData);
        result.put("uncompleted", uncompletedData);
        return result;
    }
 
    @Override
    public PageInfoExtension<Map> selectPreventDangerPage(StatisticsPreventDangerPageReqDTO reqDTO) {
 
        if (reqDTO.getPageIndex() == null) {
            reqDTO.setPageIndex(0);
        }
        if (reqDTO.getPageSize() == null || reqDTO.getPageSize() > 500) {
            reqDTO.setPageSize(500);
        }
        Page<PreventDangerCheckTaskRectifyDO> page = new Page<>(reqDTO.getPageIndex(), reqDTO.getPageSize());
 
        Map<String, Object> params = new HashMap<>();
        params.put("serialCode", reqDTO.getSerialCode());
        params.put("dangerLevel", reqDTO.getDangerLevel());
        params.put("dangerType", reqDTO.getDangerType());
        params.put("dangerSource", reqDTO.getDangerSource());
        params.put("dangerStatus", reqDTO.getDangerStatus());
        params.put("acceptPersonName", reqDTO.getAcceptPersonName());
        params.put("liablePersonName", reqDTO.getLiablePersonName());
        params.put("registantName", reqDTO.getRegistantName());
        List<PreventDangerCheckTaskRectifyDO> dbData = preventDangerCheckTaskService.selectPreventDangerPage(page, params);
        List<PreventDangerCheckTaskRectifyRespDTO> result = new ArrayList<>(dbData.size());
        if (dbData.size() > 0) {
            for (PreventDangerCheckTaskRectifyDO rectifyDO : dbData) {
                PreventDangerCheckTaskRectifyRespDTO respDTO = new PreventDangerCheckTaskRectifyRespDTO();
 
                respDTO.setManageId(rectifyDO.getManageId());
                respDTO.setManageUuid(rectifyDO.getManageUuid());
                respDTO.setRegisterTime(rectifyDO.getRegisterTime());
                respDTO.setDangerLevel(rectifyDO.getDangerLevel());
                respDTO.setDangerType(rectifyDO.getDangerType());
                respDTO.setDangerSource(rectifyDO.getDangerSource());
                respDTO.setDangerStatus(rectifyDO.getDangerStatus());
                respDTO.setRegistantId(rectifyDO.getRegistantId());
                respDTO.setProduceDeviceId(rectifyDO.getProduceDeviceId());
                respDTO.setDangerCode(rectifyDO.getDangerCode());
                respDTO.setRegistantName(rectifyDO.getRegistantName());
                respDTO.setDangerDesc(rectifyDO.getDangerDesc());
                respDTO.setDangerReason(rectifyDO.getDangerReason());
                respDTO.setDangerResult(rectifyDO.getDangerResult());
                respDTO.setDepId(rectifyDO.getDepId());
                respDTO.setRiskUnitId(rectifyDO.getRiskUnitId());
                respDTO.setDangerReview(rectifyDO.getDangerReview());
                respDTO.setDangerCloseReason(rectifyDO.getDangerCloseReason());
                respDTO.setRectifyId(rectifyDO.getRectifyId());
                respDTO.setRectifyType(rectifyDO.getRectifyType());
                respDTO.setRectifyTime(rectifyDO.getRectifyTime());
                respDTO.setLiablePersonId(rectifyDO.getLiablePersonId());
                respDTO.setCheckAcceptTime(rectifyDO.getCheckAcceptTime());
                respDTO.setCheckAcceptPersonId(rectifyDO.getCheckAcceptPersonId());
                respDTO.setLiablePerson(rectifyDO.getLiablePerson());
                respDTO.setCheckAcceptPerson(rectifyDO.getCheckAcceptPerson());
                respDTO.setRectifyDepId(rectifyDO.getRectifyDepId());
                respDTO.setRectifyDesc(rectifyDO.getRectifyDesc());
                respDTO.setCost(rectifyDO.getCost());
                respDTO.setRectifyApplyTime(rectifyDO.getRectifyApplyTime());
                respDTO.setTimeOutDesc(rectifyDO.getTimeOutDesc());
                respDTO.setRectifyInfo(rectifyDO.getRectifyInfo());
                result.add(respDTO);
 
            }
        }
        Page<PreventDangerCheckTaskRectifyRespDTO> resultPage = new Page<>();
        resultPage.setRecords(result);
        resultPage.setTotal(page.getTotal());
        resultPage.setSize(page.getSize());
        resultPage.setCurrent(page.getCurrent());
        resultPage.setPages(page.getPages());
        PageInfoExtension<Map> extension = new PageInfoExtension<>(resultPage);
 
        // 1. 待整改数量
        Map<String, Integer> extensionData = preventDangerCheckTaskService.selectRectifyNum();
        extension.setExtension(extensionData);
        return extension;
    }
 
    @Override
    public Map countDeviceEveryLevel() {
        return preventProduceDeviceService.countDeviceEveryLevel();
    }
}