Browse Source

修復錯誤

zyh
小久哥 3 years ago
parent
commit
f42644e836
  1. 44
      zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/statistical/StatisticalController.java

44
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<WorkHourDO> workList = workHourMapper.selectList(Wrappers.<WorkHourDO>lambdaQuery().ge(WorkHourDO::getCreateTime, time.getStartTime()).le(WorkHourDO::getCreateTime, time.getEndTime()));
//工时的userId
List<Long> workUserIdList = workList.stream().map(WorkHourDO::getUserId).collect(Collectors.toList());
//获取工时所有人信息
List<CpUserDO> userList = cpUserMapper.selectList(Wrappers.<CpUserDO>lambdaQuery().in(CpUserDO::getId, workUserIdList));
Map<Long, List<WorkHourDO>> workMap = workList.stream().collect(Collectors.groupingBy(WorkHourDO::getUserId));
Iterator<Map.Entry<Long, List<WorkHourDO>>> iterator = workMap.entrySet().iterator();
//工时统计 条形图
List<WorkMsg> workMsgList = new ArrayList<>();
while (iterator.hasNext()){
Entry<Long, List<WorkHourDO>> entry = iterator.next();
Long userId = entry.getKey();
Optional<CpUserDO> userDO = userList.stream().filter(user -> user.getId().equals(userId)).findFirst();
if (userDO.isPresent()){
List<WorkHourDO> 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<Long> workUserIdList = workList.stream().map(WorkHourDO::getUserId).collect(Collectors.toList());
//获取工时所有人信息
List<CpUserDO> userList = cpUserMapper.selectList(Wrappers.<CpUserDO>lambdaQuery().in(CpUserDO::getId, workUserIdList));
Map<Long, List<WorkHourDO>> workMap = workList.stream().collect(Collectors.groupingBy(WorkHourDO::getUserId));
Iterator<Map.Entry<Long, List<WorkHourDO>>> iterator = workMap.entrySet().iterator();
while (iterator.hasNext()){
Entry<Long, List<WorkHourDO>> entry = iterator.next();
Long userId = entry.getKey();
Optional<CpUserDO> userDO = userList.stream().filter(user -> user.getId().equals(userId)).findFirst();
if (userDO.isPresent()){
List<WorkHourDO> 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);
//任务数据

Loading…
Cancel
Save