|
|
@@ -0,0 +1,265 @@
|
|
|
1
|
+package com.sundot.airport.web.controller.system;
|
|
|
2
|
+
|
|
|
3
|
+import cn.hutool.core.collection.CollUtil;
|
|
|
4
|
+import cn.hutool.core.date.DatePattern;
|
|
|
5
|
+import cn.hutool.core.date.DateUtil;
|
|
|
6
|
+import cn.hutool.core.util.ObjectUtil;
|
|
|
7
|
+import cn.hutool.core.util.StrUtil;
|
|
|
8
|
+import com.sundot.airport.attendance.domain.AttendanceRecord;
|
|
|
9
|
+import com.sundot.airport.attendance.service.IAttendanceRecordService;
|
|
|
10
|
+import com.sundot.airport.check.service.ICheckLargeScreenService;
|
|
|
11
|
+import com.sundot.airport.common.core.controller.BaseController;
|
|
|
12
|
+import com.sundot.airport.common.core.domain.AjaxResult;
|
|
|
13
|
+import com.sundot.airport.common.core.domain.BaseLargeScreenQueryParamDto;
|
|
|
14
|
+import com.sundot.airport.common.core.domain.SysUsageReportDto;
|
|
|
15
|
+import com.sundot.airport.common.core.domain.entity.SysDept;
|
|
|
16
|
+import com.sundot.airport.common.core.domain.entity.SysUser;
|
|
|
17
|
+import com.sundot.airport.common.dto.BaseCommonDto;
|
|
|
18
|
+import com.sundot.airport.common.dto.QuizAccuracyAnalysisResultDto;
|
|
|
19
|
+import com.sundot.airport.common.enums.DeptTypeEnum;
|
|
|
20
|
+import com.sundot.airport.common.exception.ServiceException;
|
|
|
21
|
+import com.sundot.airport.common.utils.DeptUtils;
|
|
|
22
|
+import com.sundot.airport.exam.dto.DashboardOverviewDTO;
|
|
|
23
|
+import com.sundot.airport.exam.dto.DashboardQueryDTO;
|
|
|
24
|
+import com.sundot.airport.exam.dto.DashboardUserRankingDTO;
|
|
|
25
|
+import com.sundot.airport.exam.service.IAccuracyStatisticsService;
|
|
|
26
|
+import com.sundot.airport.exam.service.IDashboardService;
|
|
|
27
|
+import com.sundot.airport.item.service.ItemLargeScreenService;
|
|
|
28
|
+import com.sundot.airport.system.service.ISysDeptService;
|
|
|
29
|
+import com.sundot.airport.system.service.ISysUserService;
|
|
|
30
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
31
|
+import org.springframework.web.bind.annotation.GetMapping;
|
|
|
32
|
+import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
33
|
+import org.springframework.web.bind.annotation.RestController;
|
|
|
34
|
+
|
|
|
35
|
+import java.math.BigDecimal;
|
|
|
36
|
+import java.time.DayOfWeek;
|
|
|
37
|
+import java.time.LocalDate;
|
|
|
38
|
+import java.time.ZoneId;
|
|
|
39
|
+import java.util.ArrayList;
|
|
|
40
|
+import java.util.Date;
|
|
|
41
|
+import java.util.List;
|
|
|
42
|
+import java.util.stream.Collectors;
|
|
|
43
|
+
|
|
|
44
|
+/**
|
|
|
45
|
+ * 使用报告
|
|
|
46
|
+ *
|
|
|
47
|
+ * @author ruoyi
|
|
|
48
|
+ */
|
|
|
49
|
+@RestController
|
|
|
50
|
+@RequestMapping("/system/usageReport")
|
|
|
51
|
+public class SysUsageReportController extends BaseController {
|
|
|
52
|
+
|
|
|
53
|
+ @Autowired
|
|
|
54
|
+ private ISysDeptService sysDeptService;
|
|
|
55
|
+
|
|
|
56
|
+ @Autowired
|
|
|
57
|
+ private ISysUserService sysUserService;
|
|
|
58
|
+
|
|
|
59
|
+ @Autowired
|
|
|
60
|
+ private ICheckLargeScreenService checkLargeScreenService;
|
|
|
61
|
+
|
|
|
62
|
+ @Autowired
|
|
|
63
|
+ private ItemLargeScreenService itemLargeScreenService;
|
|
|
64
|
+
|
|
|
65
|
+ @Autowired
|
|
|
66
|
+ private IAttendanceRecordService attendanceRecordService;
|
|
|
67
|
+
|
|
|
68
|
+ @Autowired
|
|
|
69
|
+ private IDashboardService dashboardService;
|
|
|
70
|
+
|
|
|
71
|
+ @Autowired
|
|
|
72
|
+ private IAccuracyStatisticsService accuracyStatisticsService;
|
|
|
73
|
+
|
|
|
74
|
+ /**
|
|
|
75
|
+ * 使用报告
|
|
|
76
|
+ */
|
|
|
77
|
+ @GetMapping("/report")
|
|
|
78
|
+ public AjaxResult checkAnalysisReportCheckProblemDistributionDto(BaseLargeScreenQueryParamDto paramDto) {
|
|
|
79
|
+ SysUsageReportDto result = getSysUsageReportDto(paramDto);
|
|
|
80
|
+ return success(result);
|
|
|
81
|
+ }
|
|
|
82
|
+
|
|
|
83
|
+ /**
|
|
|
84
|
+ * 获取使用报告
|
|
|
85
|
+ */
|
|
|
86
|
+ private SysUsageReportDto getSysUsageReportDto(BaseLargeScreenQueryParamDto paramDto) {
|
|
|
87
|
+ if (ObjectUtil.isNull(paramDto.getStartDate()) || ObjectUtil.isNull(paramDto.getEndDate())) {
|
|
|
88
|
+ Date lastMonday = getLastWeekMonday();
|
|
|
89
|
+ Date lastSunday = getLastWeekSunday();
|
|
|
90
|
+ paramDto.setStartDate(lastMonday);
|
|
|
91
|
+ paramDto.setEndDate(lastSunday);
|
|
|
92
|
+ }
|
|
|
93
|
+ SysUsageReportDto result = new SysUsageReportDto();
|
|
|
94
|
+ result.setStartDate(paramDto.getStartDate());
|
|
|
95
|
+ result.setEndDate(paramDto.getEndDate());
|
|
|
96
|
+ result.setBasicSituation(getBasicSituation(paramDto));
|
|
|
97
|
+ result.setRunSituation(getRunSituation(paramDto));
|
|
|
98
|
+ return result;
|
|
|
99
|
+ }
|
|
|
100
|
+
|
|
|
101
|
+ /**
|
|
|
102
|
+ * 获取上周周一的日期 (java.util.Date)
|
|
|
103
|
+ */
|
|
|
104
|
+ public static Date getLastWeekMonday() {
|
|
|
105
|
+ LocalDate today = LocalDate.now();
|
|
|
106
|
+ // 计算本周周一(ISO标准:周一为1,周日为7)
|
|
|
107
|
+ LocalDate mondayThisWeek = today.with(DayOfWeek.MONDAY);
|
|
|
108
|
+ // 上周周一 = 本周周一 - 7天
|
|
|
109
|
+ LocalDate lastMonday = mondayThisWeek.minusWeeks(1);
|
|
|
110
|
+
|
|
|
111
|
+ return convertToUtilDate(lastMonday);
|
|
|
112
|
+ }
|
|
|
113
|
+
|
|
|
114
|
+ /**
|
|
|
115
|
+ * 获取上周周日的日期 (java.util.Date)
|
|
|
116
|
+ */
|
|
|
117
|
+ public static Date getLastWeekSunday() {
|
|
|
118
|
+ LocalDate today = LocalDate.now();
|
|
|
119
|
+ // 计算本周周一
|
|
|
120
|
+ LocalDate mondayThisWeek = today.with(DayOfWeek.MONDAY);
|
|
|
121
|
+ // 上周周日 = 本周周一 - 1天
|
|
|
122
|
+ LocalDate lastSunday = mondayThisWeek.minusDays(1);
|
|
|
123
|
+
|
|
|
124
|
+ return convertToUtilDate(lastSunday);
|
|
|
125
|
+ }
|
|
|
126
|
+
|
|
|
127
|
+ /**
|
|
|
128
|
+ * 将LocalDate转换为java.util.Date
|
|
|
129
|
+ */
|
|
|
130
|
+ private static Date convertToUtilDate(LocalDate localDate) {
|
|
|
131
|
+ return Date.from(localDate.atStartOfDay(ZoneId.systemDefault()).toInstant());
|
|
|
132
|
+ }
|
|
|
133
|
+
|
|
|
134
|
+ /**
|
|
|
135
|
+ * 获取基本情况
|
|
|
136
|
+ */
|
|
|
137
|
+ private SysUsageReportDto.BasicSituation getBasicSituation(BaseLargeScreenQueryParamDto paramDto) {
|
|
|
138
|
+ SysUsageReportDto.BasicSituation basicSituation = new SysUsageReportDto.BasicSituation();
|
|
|
139
|
+ List<SysUsageReportDto.SysDeptInfo> sysDeptInfoList = new ArrayList<>();
|
|
|
140
|
+ // 获取当前用户所在站点ID
|
|
|
141
|
+ Long topSiteId = DeptUtils.getTopSiteId(sysDeptService.selectDeptById(getDeptId()));
|
|
|
142
|
+ if (ObjectUtil.isNull(topSiteId)) {
|
|
|
143
|
+ throw new ServiceException("无法找到有效的站点信息");
|
|
|
144
|
+ }
|
|
|
145
|
+ List<SysDept> deptList = sysDeptService.selectChildrenDeptById(topSiteId);
|
|
|
146
|
+ deptList = deptList.stream().filter(item -> StrUtil.equals(DeptTypeEnum.BRIGADE.getCode(), item.getDeptType())).collect(Collectors.toList());
|
|
|
147
|
+ deptList.forEach(item -> {
|
|
|
148
|
+ SysUsageReportDto.SysDeptInfo sysDeptInfo = new SysUsageReportDto.SysDeptInfo();
|
|
|
149
|
+ List<SysUser> sysUserList = sysUserService.selectUserByDeptId(item.getDeptId());
|
|
|
150
|
+// List<SysUser> sysUserList = sysUserService.selectUserListByRoleKeyAndDeptId(Arrays.asList(RoleTypeEnum.banzuzhang.getCode(), RoleTypeEnum.SecurityCheck.getCode()), item.getId());
|
|
|
151
|
+ sysDeptInfo.setDeptId(item.getDeptId());
|
|
|
152
|
+ sysDeptInfo.setDeptName(item.getDeptName());
|
|
|
153
|
+ sysDeptInfo.setPeopleNumber(sysUserList.size());
|
|
|
154
|
+ sysDeptInfoList.add(sysDeptInfo);
|
|
|
155
|
+ });
|
|
|
156
|
+ basicSituation.setSysDeptInfoList(sysDeptInfoList);
|
|
|
157
|
+ basicSituation.setSysDeptInfoListDesc(sysDeptInfoList.stream().map(SysUsageReportDto.SysDeptInfo::getDeptName).collect(Collectors.joining("、")));
|
|
|
158
|
+ basicSituation.setTotalPeopleNumber(sysDeptInfoList.stream().mapToInt(SysUsageReportDto.SysDeptInfo::getPeopleNumber).sum());
|
|
|
159
|
+ return basicSituation;
|
|
|
160
|
+ }
|
|
|
161
|
+
|
|
|
162
|
+ /**
|
|
|
163
|
+ * 获取运行情况
|
|
|
164
|
+ */
|
|
|
165
|
+ private SysUsageReportDto.RunSituation getRunSituation(BaseLargeScreenQueryParamDto paramDto) {
|
|
|
166
|
+ SysUsageReportDto.RunSituation runSituation = new SysUsageReportDto.RunSituation();
|
|
|
167
|
+ runSituation.setAttendanceModule(getAttendanceModule(paramDto));
|
|
|
168
|
+ runSituation.setSeizureModule(getSeizureModule(paramDto));
|
|
|
169
|
+ runSituation.setExamModule(getExamModule(paramDto));
|
|
|
170
|
+ runSituation.setCheckModule(getCheckModule(paramDto));
|
|
|
171
|
+ return runSituation;
|
|
|
172
|
+ }
|
|
|
173
|
+
|
|
|
174
|
+ /**
|
|
|
175
|
+ * 获取勤务模块
|
|
|
176
|
+ */
|
|
|
177
|
+ private SysUsageReportDto.AttendanceModule getAttendanceModule(BaseLargeScreenQueryParamDto paramDto) {
|
|
|
178
|
+ SysUsageReportDto.AttendanceModule attendanceModule = new SysUsageReportDto.AttendanceModule();
|
|
|
179
|
+ AttendanceRecord attendanceRecordReq = new AttendanceRecord();
|
|
|
180
|
+ attendanceRecordReq.setAttendanceDateStart(paramDto.getStartDate());
|
|
|
181
|
+ attendanceRecordReq.setAttendanceDateEnd(paramDto.getEndDate());
|
|
|
182
|
+ List<AttendanceRecord> attendanceRecordList = attendanceRecordService.selectAttendanceRecordList(attendanceRecordReq);
|
|
|
183
|
+ attendanceRecordList = attendanceRecordList.stream().filter(item -> ObjectUtil.isNull(item.getCheckOutTime()) || "2000-01-01 00:00:00".equals(DateUtil.format(item.getCheckOutTime(), DatePattern.NORM_DATETIME_PATTERN))).collect(Collectors.toList());
|
|
|
184
|
+ if (CollUtil.isEmpty(attendanceRecordList)) {
|
|
|
185
|
+ return null;
|
|
|
186
|
+ }
|
|
|
187
|
+ List<SysUsageReportDto.SysDeptInfo> sysDeptInfoList = new ArrayList<>();
|
|
|
188
|
+ attendanceRecordList.stream().filter(item -> StrUtil.isNotBlank(item.getBrigadeCode())).collect(Collectors.groupingBy(item -> item.getBrigadeCode() + "_" + item.getBrigadeName())).forEach((key, value) -> {
|
|
|
189
|
+ SysUsageReportDto.SysDeptInfo sysDeptInfo = new SysUsageReportDto.SysDeptInfo();
|
|
|
190
|
+ sysDeptInfo.setDeptId(Long.valueOf(key.split("_")[0]));
|
|
|
191
|
+ sysDeptInfo.setDeptName(key.split("_")[1]);
|
|
|
192
|
+ sysDeptInfo.setPeopleNumber(value.size());
|
|
|
193
|
+ sysDeptInfoList.add(sysDeptInfo);
|
|
|
194
|
+ });
|
|
|
195
|
+ attendanceModule.setSysDeptInfoList(sysDeptInfoList);
|
|
|
196
|
+ attendanceModule.setSysDeptInfoListDesc(sysDeptInfoList.stream().map(item -> item.getDeptName() + item.getPeopleNumber() + "人").collect(Collectors.joining("、")));
|
|
|
197
|
+ attendanceModule.setTotalPeopleNumber(sysDeptInfoList.stream().mapToInt(SysUsageReportDto.SysDeptInfo::getPeopleNumber).sum());
|
|
|
198
|
+ return attendanceModule;
|
|
|
199
|
+ }
|
|
|
200
|
+
|
|
|
201
|
+ /**
|
|
|
202
|
+ * 获取查获模块
|
|
|
203
|
+ */
|
|
|
204
|
+ private SysUsageReportDto.SeizureModule getSeizureModule(BaseLargeScreenQueryParamDto paramDto) {
|
|
|
205
|
+ SysUsageReportDto.SeizureModule seizureModule = itemLargeScreenService.getSeizureModule(paramDto);
|
|
|
206
|
+ return seizureModule;
|
|
|
207
|
+ }
|
|
|
208
|
+
|
|
|
209
|
+ /**
|
|
|
210
|
+ * 获取抽问抽答模块
|
|
|
211
|
+ */
|
|
|
212
|
+ private SysUsageReportDto.ExamModule getExamModule(BaseLargeScreenQueryParamDto paramDto) {
|
|
|
213
|
+ SysUsageReportDto.ExamModule examModule = new SysUsageReportDto.ExamModule();
|
|
|
214
|
+
|
|
|
215
|
+ String startDateStr = DateUtil.format(paramDto.getStartDate(), DatePattern.NORM_DATE_PATTERN);
|
|
|
216
|
+ String endDateStr = DateUtil.format(paramDto.getEndDate(), DatePattern.NORM_DATE_PATTERN);
|
|
|
217
|
+
|
|
|
218
|
+ DashboardQueryDTO query = new DashboardQueryDTO();
|
|
|
219
|
+ query.setStartDate(startDateStr);
|
|
|
220
|
+ query.setEndDate(endDateStr);
|
|
|
221
|
+ query.setTimeRange("custom");
|
|
|
222
|
+
|
|
|
223
|
+ // 总项数、平均分
|
|
|
224
|
+ DashboardOverviewDTO overview = dashboardService.getOverview(query);
|
|
|
225
|
+ if (overview != null) {
|
|
|
226
|
+ examModule.setTotalItem(overview.getCompletedTasks() != null ? overview.getCompletedTasks().intValue() : 0);
|
|
|
227
|
+ examModule.setAverageScore(overview.getAvgScore() != null ? BigDecimal.valueOf(overview.getAvgScore()) : BigDecimal.ZERO);
|
|
|
228
|
+ }
|
|
|
229
|
+
|
|
|
230
|
+ // 参与人数(有完成任务的用户数)
|
|
|
231
|
+ List<DashboardUserRankingDTO> allUsers = dashboardService.getAllUsersRanking(query);
|
|
|
232
|
+ if (CollUtil.isNotEmpty(allUsers)) {
|
|
|
233
|
+ long participantCount = allUsers.stream()
|
|
|
234
|
+ .filter(user -> user.getCompletedTasks() != null && user.getCompletedTasks() > 0)
|
|
|
235
|
+ .count();
|
|
|
236
|
+ examModule.setTotalPeopleNumber((int) participantCount);
|
|
|
237
|
+ } else {
|
|
|
238
|
+ examModule.setTotalPeopleNumber(0);
|
|
|
239
|
+ }
|
|
|
240
|
+
|
|
|
241
|
+ // 各分类正确率列表
|
|
|
242
|
+ QuizAccuracyAnalysisResultDto accuracyAnalysis = accuracyStatisticsService.getQuizAccuracyAnalysis(startDateStr, endDateStr);
|
|
|
243
|
+ if (accuracyAnalysis != null && CollUtil.isNotEmpty(accuracyAnalysis.getCategoryList())) {
|
|
|
244
|
+ List<BaseCommonDto> typeList = accuracyAnalysis.getCategoryList().stream().map(item -> {
|
|
|
245
|
+ BaseCommonDto dto = new BaseCommonDto();
|
|
|
246
|
+ dto.setName(item.getCategoryName());
|
|
|
247
|
+ dto.setScale(item.getCorrectRate());
|
|
|
248
|
+ dto.setRemark(item.getLabel());
|
|
|
249
|
+ return dto;
|
|
|
250
|
+ }).collect(Collectors.toList());
|
|
|
251
|
+ examModule.setTypeList(typeList);
|
|
|
252
|
+ }
|
|
|
253
|
+
|
|
|
254
|
+ return examModule;
|
|
|
255
|
+ }
|
|
|
256
|
+
|
|
|
257
|
+ /**
|
|
|
258
|
+ * 获取巡检模块
|
|
|
259
|
+ */
|
|
|
260
|
+ private SysUsageReportDto.CheckModule getCheckModule(BaseLargeScreenQueryParamDto paramDto) {
|
|
|
261
|
+ SysUsageReportDto.CheckModule checkModule = checkLargeScreenService.getCheckModule(paramDto);
|
|
|
262
|
+ return checkModule;
|
|
|
263
|
+ }
|
|
|
264
|
+
|
|
|
265
|
+}
|