From 94014e38424537e2eff27423f2dc29d3016a8f17 Mon Sep 17 00:00:00 2001 From: xuhy <3313886187@qq.com> Date: 星期四, 03 七月 2025 13:56:47 +0800 Subject: [PATCH] bug修改 --- ruoyi-admin/src/main/java/com/ruoyi/web/controller/api/ReportController.java | 138 +++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 136 insertions(+), 2 deletions(-) diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/api/ReportController.java b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/api/ReportController.java index 9b5aceb..eb98463 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/api/ReportController.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/api/ReportController.java @@ -16,6 +16,7 @@ import com.ruoyi.system.model.*; import com.ruoyi.system.query.*; import com.ruoyi.system.service.*; +import com.ruoyi.system.utils.ExcelPoiUtils; import com.ruoyi.system.vo.system.*; import com.ruoyi.web.util.OssUploadUtil; import io.swagger.annotations.Api; @@ -479,7 +480,6 @@ locationTypeListByProjectVOS1.add(temp); } projectDeptDetailsChildVO.setLocationTypeList(locationTypeListByProjectVOS1); - projectDeptDetailsChildVO.setCleanerCount(0); } @@ -631,7 +631,6 @@ @ApiOperation(value = "巡检人员报表") @PostMapping(value = "/patrolInspectorList") - public R<List<PatrolInspectorVO>> patrolInspectorList(@RequestBody PatrolInspectorQuery query) { List<SysUser> sysUsers = sysUserService.selectAllList(); LambdaQueryWrapper<TLeave> tLeaveLambdaQueryWrapper = new LambdaQueryWrapper<>(); @@ -1075,5 +1074,140 @@ } } } + + + @ApiOperation(value = "任务报表导出模板") + @PostMapping(value = "/exportExcel") + public void exportExcel(@RequestBody TaskDetailsQuery query,HttpServletResponse response) throws Exception{ + // 动态标头名称字段 + final String headerName = "locationTypeName"; + // 动态标头值字段 + final String headerValue = "locationNum"; + List<TLocationType> locationTypeList = locationTypeService.list(); + List<TLocation> locations = locationService.list(); + LambdaQueryWrapper<TTask> tTaskLambdaQueryWrapper = new LambdaQueryWrapper<>(); + if (StringUtils.hasLength(query.getStartTime()) && StringUtils.hasLength(query.getEndTime())) { + tTaskLambdaQueryWrapper.ge(TTask::getImplementTime, query.getStartTime()); + tTaskLambdaQueryWrapper.le(TTask::getImplementTime, query.getEndTime()); + } + List<ProjectDeptDetailsVO> res = new ArrayList<>(); + List<TTask> tasks = taskCleanerService.list(tTaskLambdaQueryWrapper); + List<TTaskDetail> taskDetails = taskDetailService.lambdaQuery().orderByDesc(BaseModel::getCreateTime).list(); + List<String> collect = tasks.stream().map(TTask::getProjectId).distinct().collect(Collectors.toList()); + List<TProjectDept> projectDepts = projectDeptService.list(); + List<String> strings = new ArrayList<>(); + + // 片区ids 反查项目部 + List<TProjectDept> list1 = projectDeptService.lambdaQuery().in(TProjectDept::getId, collect).list(); + for (TProjectDept tProjectDept : list1) { + TProjectDept tProjectDept1 = projectDepts.stream().filter(e -> e.getId().equals(tProjectDept.getParentId())).findFirst().orElse(null); + if (tProjectDept1 != null && !strings.contains(tProjectDept1.getId())) { + ProjectDeptDetailsVO projectDeptDetailsVO = new ProjectDeptDetailsVO(); + projectDeptDetailsVO.setProjectName(tProjectDept1.getProjectName()); + List<TProjectDept> collect1 = list1.stream().filter(e -> e.getParentId().equals(tProjectDept1.getId())).collect(Collectors.toList()); + List<ProjectDeptDetailsChildVO> projectDeptDetailsChildVOS = new ArrayList<>(); + for (TProjectDept projectDept : collect1) { + ProjectDeptDetailsChildVO projectDeptDetailsChildVO = new ProjectDeptDetailsChildVO(); + projectDeptDetailsChildVO.setProjectChildName(projectDept.getProjectName()); + projectDeptDetailsChildVO.setProjectId(projectDept.getId()); + projectDeptDetailsChildVOS.add(projectDeptDetailsChildVO); + } + projectDeptDetailsVO.setProjectChild(projectDeptDetailsChildVOS); + res.add(projectDeptDetailsVO); + strings.add(tProjectDept1.getId()); + } + } + List<LocationTypeListByProjectVO> locationTypeListByProjectVOS = new ArrayList<>(); + for (TLocationType tLocationType : locationTypeList) { + LocationTypeListByProjectVO locationTypeListByProjectVO = new LocationTypeListByProjectVO(); + locationTypeListByProjectVO.setLocationTypeName(tLocationType.getLocationName()); + locationTypeListByProjectVO.setLocationNum(0); + locationTypeListByProjectVO.setId(tLocationType.getId()); + locationTypeListByProjectVOS.add(locationTypeListByProjectVO); + } + for (ProjectDeptDetailsVO re : res) { + List<ProjectDeptDetailsChildVO> projectChild = re.getProjectChild(); + for (ProjectDeptDetailsChildVO projectDeptDetailsChildVO : projectChild) { + int cleanerCount = cleanerService.lambdaQuery().eq(TCleaner::getProjectId, projectDeptDetailsChildVO.getProjectId()).list().size(); + projectDeptDetailsChildVO.setCleanerCount(cleanerCount); + for (LocationTypeListByProjectVO locationTypeListByProjectVO : locationTypeListByProjectVOS) { + List<TaskSummaryVO> taskSummaryVOS = new ArrayList<>(); + List<String> locationIds = locations.stream().filter(e -> e.getLocationType().equals(locationTypeListByProjectVO.getId())).map(TLocation::getId).collect(Collectors.toList()); + if (locationIds.isEmpty()) { + locationTypeListByProjectVO.setLocationNum(0); + } else { + List<TTask> taskList = tasks.stream().filter(e -> e.getProjectId().equals(projectDeptDetailsChildVO.getProjectId()) + && locationIds.contains(e.getLocationId())).collect(Collectors.toList()); + Integer count = taskList.size(); + locationTypeListByProjectVO.setLocationNum(count); + int total = taskList.size(); + int num1 = 0; + int num2 = 0; + int num3 = 0; + int num4 = 0; + int num5 = 0; + int num6 = 0; + int num7 = 0; + TaskSummaryVO taskSummaryVO = new TaskSummaryVO(); + for (TTask tTask : taskList) { + TTaskDetail tTaskDetail = taskDetails.stream().filter(e -> e.getTaskId().equals(tTask.getId()) && e.getClearStatus() != null).findFirst().orElse(null); + if (tTaskDetail!=null){ + switch (tTaskDetail.getClearStatus()) { + case 1: + num1++; + break; + case 2: + num2++; + break; + } + } + // 任务状态:1未执行、2超时、3待确认、4待整改、5整改完成、6已完成 + switch (tTask.getStatus()) { + case 1: + if (tTaskDetail == null) { + num3++; + } + break; + case 2: + num6++; + break; + case 3: + break; + case 4: + num4++; + break; + case 5: + num7++; + break; + case 6: + num5++; + break; + } + } + taskSummaryVO.setTotal(total); + taskSummaryVO.setNum1(num1); + taskSummaryVO.setNum2(num2); + taskSummaryVO.setNum3(num3); + taskSummaryVO.setNum4(num4); + taskSummaryVO.setNum5(num5); + taskSummaryVO.setNum6(num6); + taskSummaryVO.setNum7(num7); + taskSummaryVOS.add(taskSummaryVO); + } + projectDeptDetailsChildVO.setTaskSummaryVOS(taskSummaryVOS); + } + projectDeptDetailsChildVO.setLocationTypeList(locationTypeListByProjectVOS); + } + } + try { + String time = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy_MM_dd_HH_mm_ss")); + ExcelPoiUtils.exportExcel(response, "任务报表_"+time, "任务报表导出模板", + "sheet", res, headerName, headerValue); + } catch (Exception e) { + System.out.println("导出错误,"+e.getMessage()); + throw new RuntimeException(e.getMessage()); + } + } + } -- Gitblit v1.7.1