ReportService.java
8.38 KB
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
package com.ruoyi.service;
import com.ruoyi.driver.domain.Driver;
import com.ruoyi.driver.mapper.DriverMapper;
import com.ruoyi.driver.mapper.DriverSchedulingMapper;
import com.ruoyi.eexception.domain.EquipmentException;
import com.ruoyi.eexception.mapper.EquipmentExceptionMapper;
import com.ruoyi.in.domain.SignIn;
import com.ruoyi.in.mapper.SignInMapper;
import com.ruoyi.pojo.entity.DriverScheduling;
import com.ruoyi.pojo.request.ReportViewRequestVo;
import com.ruoyi.pojo.request.ReportErrorRequestVo;
import com.ruoyi.pojo.response.*;
import com.ruoyi.utils.ConstDateUtil;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.NotBlank;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.YearMonth;
import java.time.format.DateTimeFormatter;
import java.util.*;
import java.util.stream.Collectors;
import static com.ruoyi.common.ConstDriverProperties.BC_TYPE_OUT;
import static com.ruoyi.common.ConstSignInConstSignInProperties.*;
import static com.ruoyi.common.ErrorTypeProperties.EQUIPMENT_ERROR;
import static com.ruoyi.common.ErrorTypeProperties.SIGN_IN_ERROR;
import static com.ruoyi.common.ReportProperties.DAY;
import static com.ruoyi.common.ReportProperties.MONTH;
/**
* @author 20412
*/
@Service
public class ReportService {
@Autowired
private SignInMapper signInMapper;
@Autowired
private EquipmentExceptionMapper exceptionMapper;
@Autowired
private DriverMapper driverMapper;
@Resource
private SchedulingService schedulingService;
@Autowired
private DriverSchedulingMapper schedulingMapper;
/**
* 查询报表信息
*/
public List<ReportViewResponseVo> getReportScrollViewTable(ReportViewRequestVo requestVo, HttpServletResponse response) {
List<ReportViewResponseVo> reportScrollViewTable = schedulingService.queryReportTableResponseVo(requestVo, response);
return reportScrollViewTable;
}
public List<ReportErrorResponseVo> getErrorReportList(ReportErrorRequestVo request) {
List<EquipmentExceptionResponseVo> list = exceptionMapper.selectEquipmentExceptionListByVo(request);
return list.stream().map(item -> {
ReportErrorResponseVo vo = new ReportErrorResponseVo();
vo.setRemark(item.getRemark());
vo.setName(item.getPersonnelName());
vo.setSiteName(item.getSiteName());
vo.setImage(item.getImage());
vo.setJobCode(item.getJobCode());
vo.setDeviceId(item.getDeviceId());
vo.setExType(item.getExType());
vo.setCreateTime(item.getCreateTime());
vo.setTitle(item.getTitle());
return vo;
}).collect(Collectors.toList());
}
public List<ExportReportViewResponseVo> exportReportList(ReportViewRequestVo requestVo, HttpServletResponse response) {
// 处理天
if (requestVo.getExportFlag().equals(DAY)) {
return getDayReportTableResponseVo(requestVo.getDate(), response);
}
// 处理月
else if (requestVo.getExportFlag().equals(MONTH)) {
return getMonthReportTableResponseVo(requestVo, response);
}
return null;
}
private List<ExportReportViewResponseVo> getDayReportTableResponseVo(String date, HttpServletResponse response) {
List<DriverScheduling> schedulingList = schedulingMapper.queryToDay(date, null, null, null);
Map<String, List<DriverScheduling>> resultMap = new HashMap<>(800);
List<ExportReportViewResponseVo> vo = new ArrayList<>(800);
handleResultMap(date, resultMap, schedulingList);
handleResultList(vo, resultMap);
return vo;
}
private void handleResultList(List<ExportReportViewResponseVo> vo, Map<String, List<DriverScheduling>> resultMap) {
for (String key : resultMap.keySet()) {
resultMap.get(key).sort(Comparator.comparing(DriverScheduling::getFcsjT));
vo.add(new ExportReportViewResponseVo(resultMap.get(key)));
}
}
private void handleResultMap(@NotBlank String date, Map<String, List<DriverScheduling>> resultMap, List<DriverScheduling> schedulingList) {
for (DriverScheduling item : schedulingList) {
String key = date + item.getJobCode();
if (Objects.isNull(resultMap.get(key))) {
resultMap.put(key, new ArrayList<>(Arrays.asList(item)));
} else {
resultMap.get(key).add(item);
}
}
}
private List<ExportReportViewResponseVo> getMonthReportTableResponseVo(ReportViewRequestVo requestVo, HttpServletResponse response) {
List<ExportReportViewResponseVo> responseVos = new ArrayList<>(10000);
List<String> days = getNowMonthAllDay(requestVo.getDate());
for (String day : days) {
List<ExportReportViewResponseVo> dayReportTableResponseVo = getDayReportTableResponseVo(day, response);
responseVos.addAll(dayReportTableResponseVo);
}
return responseVos;
}
private List<String> getNowMonthAllDay(@NotBlank String dateString) {
// 获取当前年月
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
LocalDate formatDate = LocalDate.parse(dateString, formatter);
int month = formatDate.getMonthValue();
int year = formatDate.getYear();
YearMonth yearMonth = YearMonth.of(year, month);
// 获取当前月份的第一天和最后一天日期
LocalDate firstDay = yearMonth.atDay(1);
LocalDate lastDay = yearMonth.atEndOfMonth();
// 获取当前月份的所有日期集合
List<String> datesInMonth = new ArrayList<>();
LocalDate date = firstDay;
while (!date.isAfter(lastDay)) {
datesInMonth.add(date.toString());
date = date.plusDays(1);
}
return datesInMonth;
}
public List<ReportDetailResponseVo> getReportDetail(ReportViewRequestVo vo, HttpServletResponse response) {
List<ReportDetailResponseVo> responseVos = new ArrayList<>();
List<DriverScheduling> toDay = schedulingMapper.queryToDay(vo.getDate(), vo.getName(), vo.getJobCode(), vo.getLineName());
for (DriverScheduling scheduling : toDay) {
ReportDetailResponseVo reportDetailResponseVo = new ReportDetailResponseVo();
handleReportDetail(reportDetailResponseVo, scheduling);
responseVos.add(reportDetailResponseVo);
}
responseVos.sort(Comparator.comparing(ReportDetailResponseVo::getPlanTime));
return responseVos;
}
private void handleReportDetail(ReportDetailResponseVo reportDetailResponseVo, DriverScheduling scheduling) {
BeanUtils.copyProperties(scheduling, reportDetailResponseVo);
reportDetailResponseVo.setPlanAction(scheduling.getBcType().equals(BC_TYPE_OUT) ? SIGN_IN_STRING : SIGN_IN_OUT_STRING);
reportDetailResponseVo.setPlanTime(scheduling.getBcType().equals(BC_TYPE_OUT) ? new Date(scheduling.getFcsjT()) : new Date(scheduling.getZdsjT()));
reportDetailResponseVo.setExString(SIGN_NO_EX_NUM.equals(scheduling.getExType()) ? NO_EX : HAVE_EX);
// 设置操作 当前有操作的
if (!Objects.isNull(scheduling.getSignInId())) {
reportDetailResponseVo.setActualTime(scheduling.getSignTime());
reportDetailResponseVo.setActualAction(scheduling.getSignType().equals(SIGN_IN) ? SIGN_IN_STRING : SIGN_IN_OUT_STRING);
reportDetailResponseVo.setRemark(scheduling.getRemark());
reportDetailResponseVo.setAlcoholString(ALCOHOL_FLAG_YES.equals(scheduling.getAlcoholFlag()) ? ALCOHOL_FLAG_YES_STRING : ALCOHOL_FLAG_NO_STRING);
}
// 当前无操作
else {
reportDetailResponseVo.setRemark(scheduling.getBcType().equals(BC_TYPE_OUT) ? "未签到" : "未签退");
reportDetailResponseVo.setAlcoholString(ALCOHOL_FLAG_NO_STRING);
}
}
public List<SignInResponseVo> getBigView(ReportViewRequestVo requestVo, HttpServletResponse response) {
SignInResponseVo vo = new SignInResponseVo();
vo.setDate(requestVo.getDate());
vo.setJobCode(requestVo.getJobCode());
List<SignInResponseVo> vos = signInMapper.selectSignInList(vo);
return vos;
}
}