|
|
@@ -3578,6 +3578,143 @@ public class IotRdDailyReportServiceImpl implements IotRdDailyReportService {
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public List<IotRdDailyReportSummaryYearRespVO> reportSummary(IotRdDailyReportPageReqVO pageReqVO) {
|
|
|
+ // 查询选择部门下面所有子部门
|
|
|
+ Set<Long> ids = new HashSet<>();
|
|
|
+ if (Objects.nonNull(pageReqVO.getDeptId())) {
|
|
|
+ ids = deptService.getChildDeptIdListFromCache(pageReqVO.getDeptId());
|
|
|
+ ids.add(pageReqVO.getDeptId());
|
|
|
+ pageReqVO.setDeptIds(ids);
|
|
|
+ }
|
|
|
+ // searchKey 兼容移动端查询的情况
|
|
|
+ if (StrUtil.isNotBlank(pageReqVO.getSearchKey())) {
|
|
|
+ if (CollUtil.isEmpty(pageReqVO.getProjectIds()) && CollUtil.isEmpty(pageReqVO.getTaskIds())) {
|
|
|
+ return new ArrayList<>();
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ // PC 端 AND 检查:各自条件必须匹配到对应 ID
|
|
|
+ if (StrUtil.isNotBlank(pageReqVO.getContractName()) && CollUtil.isEmpty(pageReqVO.getProjectIds())) {
|
|
|
+ return new ArrayList<>();
|
|
|
+ }
|
|
|
+ if (StrUtil.isNotBlank(pageReqVO.getTaskName()) && CollUtil.isEmpty(pageReqVO.getTaskIds())) {
|
|
|
+ return new ArrayList<>();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
|
|
|
+ PageResult<IotRdDailyReportDO> pageReports = iotRdDailyReportMapper.selectPage(pageReqVO);
|
|
|
+ List<IotRdDailyReportDO> dailyReports = pageReports.getList();
|
|
|
+ if (CollUtil.isEmpty(dailyReports)) {
|
|
|
+ return Collections.emptyList();
|
|
|
+ }
|
|
|
+ // 按照 年 月 日 汇总统计 日报数据
|
|
|
+ List<IotRdDailyReportSummaryYearRespVO> result = new ArrayList<>();
|
|
|
+ // 1. 按年 -> 月 -> 日 分组,过滤 createTime 为空的数据
|
|
|
+ Map<String, Map<String, Map<String, List<IotRdDailyReportDO>>>> grouped = dailyReports.stream()
|
|
|
+ .filter(r -> r.getCreateTime() != null)
|
|
|
+ .collect(Collectors.groupingBy(
|
|
|
+ r -> String.valueOf(r.getCreateTime().getYear()),
|
|
|
+ Collectors.groupingBy(
|
|
|
+ r -> String.valueOf(r.getCreateTime().getMonthValue()),
|
|
|
+ Collectors.groupingBy(
|
|
|
+ r -> String.valueOf(r.getCreateTime().getDayOfMonth())
|
|
|
+ )
|
|
|
+ )
|
|
|
+ ));
|
|
|
+ // 2. 遍历年份
|
|
|
+ for (Map.Entry<String, Map<String, Map<String, List<IotRdDailyReportDO>>>> yearEntry : grouped.entrySet()) {
|
|
|
+ String year = yearEntry.getKey();
|
|
|
+ Map<String, Map<String, List<IotRdDailyReportDO>>> monthMap = yearEntry.getValue();
|
|
|
+
|
|
|
+ IotRdDailyReportSummaryYearRespVO yearVO = new IotRdDailyReportSummaryYearRespVO();
|
|
|
+ yearVO.setYear(year);
|
|
|
+ yearVO.setLevel("year");
|
|
|
+ List<IotRdDailyReportSummaryMonthRespVO> monthVOList = new ArrayList<>();
|
|
|
+ int yearReportCount = 0;
|
|
|
+
|
|
|
+ // 3. 遍历月份
|
|
|
+ for (Map.Entry<String, Map<String, List<IotRdDailyReportDO>>> monthEntry : monthMap.entrySet()) {
|
|
|
+ String month = monthEntry.getKey();
|
|
|
+ Map<String, List<IotRdDailyReportDO>> dayMap = monthEntry.getValue();
|
|
|
+
|
|
|
+ IotRdDailyReportSummaryMonthRespVO monthVO = new IotRdDailyReportSummaryMonthRespVO();
|
|
|
+ monthVO.setMonth(month);
|
|
|
+ monthVO.setLevel("month");
|
|
|
+ List<IotRdDailyReportSummaryDayRespVO> dayVOList = new ArrayList<>();
|
|
|
+ int monthReportCount = 0;
|
|
|
+
|
|
|
+ // 4. 遍历日
|
|
|
+ for (Map.Entry<String, List<IotRdDailyReportDO>> dayEntry : dayMap.entrySet()) {
|
|
|
+ String day = dayEntry.getKey();
|
|
|
+ List<IotRdDailyReportDO> dayReports = dayEntry.getValue();
|
|
|
+
|
|
|
+ IotRdDailyReportSummaryDayRespVO dayVO = new IotRdDailyReportSummaryDayRespVO();
|
|
|
+ dayVO.setDay(day);
|
|
|
+ dayVO.setLevel("day");
|
|
|
+
|
|
|
+ // 统计已填报(status=1)和未填报(status=0)数量
|
|
|
+ long filled = dayReports.stream()
|
|
|
+ .filter(r -> r.getStatus() != null && r.getStatus() == 1)
|
|
|
+ .count();
|
|
|
+ long unfilled = dayReports.stream()
|
|
|
+ .filter(r -> r.getStatus() != null && r.getStatus() == 0)
|
|
|
+ .count();
|
|
|
+ dayVO.setFilledCount(String.valueOf(filled));
|
|
|
+ dayVO.setUnfilledCount(String.valueOf(unfilled));
|
|
|
+ dayVO.setReportCount(dayReports.size());
|
|
|
+
|
|
|
+ // 计算星期几(基于该天第一个日报的 createTime)
|
|
|
+ if (!dayReports.isEmpty()) {
|
|
|
+ LocalDateTime dateTime = dayReports.get(0).getCreateTime();
|
|
|
+ // 转换为中文星期几,如 "星期一"
|
|
|
+ String weekDay = dateTime.getDayOfWeek().getDisplayName(java.time.format.TextStyle.FULL, java.util.Locale.CHINESE);
|
|
|
+ dayVO.setWeekDay(weekDay);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 构建日报简要列表(仅 id 和 reportName)
|
|
|
+ List<IotRdDailyReportShortRespVO> reportVOList = dayReports.stream()
|
|
|
+ .map(r -> {
|
|
|
+ IotRdDailyReportShortRespVO respVO = new IotRdDailyReportShortRespVO();
|
|
|
+ respVO.setId(r.getId());
|
|
|
+ respVO.setReportName(r.getReportName());
|
|
|
+ return respVO;
|
|
|
+ })
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ dayVO.setReports(reportVOList);
|
|
|
+
|
|
|
+ dayVOList.add(dayVO);
|
|
|
+ monthReportCount += dayReports.size();
|
|
|
+ }
|
|
|
+
|
|
|
+ monthVO.setDays(dayVOList);
|
|
|
+ monthVO.setDayCount(dayVOList.size()); // 该月下有日报的天数
|
|
|
+ monthVO.setReportCount(monthReportCount); // 该月日报总数
|
|
|
+ monthVOList.add(monthVO);
|
|
|
+ yearReportCount += monthReportCount;
|
|
|
+ }
|
|
|
+
|
|
|
+ yearVO.setMonths(monthVOList);
|
|
|
+ yearVO.setMonthCount(monthVOList.size()); // 该年下有日报的月份数
|
|
|
+ yearVO.setReportCount(yearReportCount); // 该年日报总数
|
|
|
+ result.add(yearVO);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 5. 排序:年份降序、月份降序、日降序(最新在前)—— 使用数字比较
|
|
|
+ result.sort((y1, y2) -> Integer.compare(Integer.parseInt(y2.getYear()), Integer.parseInt(y1.getYear())));
|
|
|
+ for (IotRdDailyReportSummaryYearRespVO yearVO : result) {
|
|
|
+ if (CollUtil.isNotEmpty(yearVO.getMonths())) {
|
|
|
+ yearVO.getMonths().sort((m1, m2) -> Integer.compare(Integer.parseInt(m2.getMonth()), Integer.parseInt(m1.getMonth())));
|
|
|
+ for (IotRdDailyReportSummaryMonthRespVO monthVO : yearVO.getMonths()) {
|
|
|
+ if (CollUtil.isNotEmpty(monthVO.getDays())) {
|
|
|
+ // 日排序:降序,数字比较
|
|
|
+ monthVO.getDays().sort((d1, d2) -> Integer.compare(Integer.parseInt(d2.getDay()), Integer.parseInt(d1.getDay())));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 按项目部维度 汇总 统计数据
|
|
|
* @param dailyReports 日报数据列表
|