From f42644e8361d0da4c885033e5af3f719eed34355 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=8F=E4=B9=85=E5=93=A5?= <787952492@qq.com> Date: Sat, 11 Jun 2022 09:52:02 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=BE=A9=E9=8C=AF=E8=AA=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../statistical/StatisticalController.java | 44 +++++++++++-------- 1 file changed, 26 insertions(+), 18 deletions(-) diff --git a/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/statistical/StatisticalController.java b/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/statistical/StatisticalController.java index 4eb6aa85..d55ec3ab 100644 --- a/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/statistical/StatisticalController.java +++ b/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/statistical/StatisticalController.java @@ -4,6 +4,7 @@ import cn.hutool.core.date.DatePattern; import cn.hutool.core.date.DateTime; import cn.hutool.core.date.DateUtil; import cn.hutool.core.date.LocalDateTimeUtil; +import cn.hutool.core.util.ObjectUtil; import cn.iocoder.yudao.framework.common.pojo.CommonResult; import cn.iocoder.yudao.module.farm.controller.admin.statistical.dto.RequestDTO; import cn.iocoder.yudao.module.farm.controller.admin.statistical.vo.*; @@ -56,29 +57,36 @@ public class StatisticalController { StatisticalVo vo = new StatisticalVo(); //获取时间内的所有工时记录 List workList = workHourMapper.selectList(Wrappers.lambdaQuery().ge(WorkHourDO::getCreateTime, time.getStartTime()).le(WorkHourDO::getCreateTime, time.getEndTime())); - //工时的userId - List workUserIdList = workList.stream().map(WorkHourDO::getUserId).collect(Collectors.toList()); - //获取工时所有人信息 - List userList = cpUserMapper.selectList(Wrappers.lambdaQuery().in(CpUserDO::getId, workUserIdList)); - - Map> workMap = workList.stream().collect(Collectors.groupingBy(WorkHourDO::getUserId)); - Iterator>> iterator = workMap.entrySet().iterator(); //工时统计 条形图 List workMsgList = new ArrayList<>(); - while (iterator.hasNext()){ - Entry> entry = iterator.next(); - Long userId = entry.getKey(); - Optional userDO = userList.stream().filter(user -> user.getId().equals(userId)).findFirst(); - if (userDO.isPresent()){ - List oneUserWorkList = entry.getValue(); - Integer oneTotalHour = oneUserWorkList.stream().mapToInt(WorkHourDO::getHour).sum(); - WorkMsg workMsg = WorkMsg.builder().name(userDO.get().getName()).hour(oneTotalHour).build(); - workMsgList.add(workMsg); + if (ObjectUtil.isEmpty(workList)){ + vo.setWorkMsgList(workMsgList); + }else{ + //工时的userId + List workUserIdList = workList.stream().map(WorkHourDO::getUserId).collect(Collectors.toList()); + //获取工时所有人信息 + List userList = cpUserMapper.selectList(Wrappers.lambdaQuery().in(CpUserDO::getId, workUserIdList)); + + Map> workMap = workList.stream().collect(Collectors.groupingBy(WorkHourDO::getUserId)); + Iterator>> iterator = workMap.entrySet().iterator(); + + + while (iterator.hasNext()){ + Entry> entry = iterator.next(); + Long userId = entry.getKey(); + Optional userDO = userList.stream().filter(user -> user.getId().equals(userId)).findFirst(); + if (userDO.isPresent()){ + List oneUserWorkList = entry.getValue(); + Integer oneTotalHour = oneUserWorkList.stream().mapToInt(WorkHourDO::getHour).sum(); + WorkMsg workMsg = WorkMsg.builder().name(userDO.get().getName()).hour(oneTotalHour).build(); + workMsgList.add(workMsg); + } } + workMsgList = workMsgList.stream().sorted(Comparator.comparing(WorkMsg::getHour).reversed()).collect(Collectors.toList()); + vo.setWorkMsgList(workMsgList); } - workMsgList = workMsgList.stream().sorted(Comparator.comparing(WorkMsg::getHour).reversed()).collect(Collectors.toList()); - vo.setWorkMsgList(workMsgList); + //任务数据