From a0e3084978ed780932f29e95b64c210518cce57c Mon Sep 17 00:00:00 2001 From: haungxing <1203316822@qq.com> Date: Thu, 21 Mar 2024 20:20:51 +0800 Subject: [PATCH] =?UTF-8?q?#=20=E6=97=A5=E5=B8=B8=E7=BB=B4=E6=8A=A4?= =?UTF-8?q?=E4=BB=BB=E5=8A=A1=E6=9C=88=E5=BA=A6=E7=BB=9F=E8=AE=A1=E9=80=BB?= =?UTF-8?q?=E8=BE=91=E4=BF=AE=E6=94=B9=E3=80=81=E7=94=A8=E6=88=B7=E5=90=8D?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/com/hnac/hzims/vo/VoteChartVo.java | 15 ++- .../impl/OperMaintenanceTaskServiceImpl.java | 122 ++++++++++++++------- 2 files changed, 94 insertions(+), 43 deletions(-) diff --git a/hzims-service-api/common-api/src/main/java/com/hnac/hzims/vo/VoteChartVo.java b/hzims-service-api/common-api/src/main/java/com/hnac/hzims/vo/VoteChartVo.java index dcb909b..96d05be 100644 --- a/hzims-service-api/common-api/src/main/java/com/hnac/hzims/vo/VoteChartVo.java +++ b/hzims-service-api/common-api/src/main/java/com/hnac/hzims/vo/VoteChartVo.java @@ -16,12 +16,12 @@ import java.util.List; @ApiModel("各个票种统计表") public class VoteChartVo { @ApiModelProperty(value = "站点名称") - @ColumnWidth(value = 20) + @ColumnWidth(value = 25) @ExcelProperty(value = "站点名称", index = 0) private String name; @ApiModelProperty(value = "总数量") - @ExcelProperty(value = "总数量", index = 1) + @ExcelProperty(value = "总数量", index = 2) @ColumnWidth(value = 20) private int sumNum; @@ -30,7 +30,7 @@ public class VoteChartVo { private List sumIds; @ApiModelProperty(value = "未完成数量") - @ExcelProperty(value = "未完成数量", index = 2) + @ExcelProperty(value = "未完成数量", index = 3) @ColumnWidth(value = 20) private int undoneNum; @@ -40,7 +40,7 @@ public class VoteChartVo { @ApiModelProperty(value = "完成数量") @ColumnWidth(value = 20) - @ExcelProperty(value = "完成数量", index = 3) + @ExcelProperty(value = "完成数量", index = 4) private int finishNum; @ApiModelProperty(value = "完成id") @@ -48,7 +48,12 @@ public class VoteChartVo { private List finishIds; @ApiModelProperty(value = "完成率") - @ExcelProperty(value = "完成率", index = 4) + @ExcelProperty(value = "完成率", index = 5) @ColumnWidth(value = 20) private Double finishRate; + + @ApiModelProperty(value = "用戶名") + @ExcelProperty(value = "用戶名", index = 1) + @ColumnWidth(value = 20) + private String userName; } diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/maintenance/service/impl/OperMaintenanceTaskServiceImpl.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/maintenance/service/impl/OperMaintenanceTaskServiceImpl.java index 25fb744..ded403b 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/maintenance/service/impl/OperMaintenanceTaskServiceImpl.java +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/maintenance/service/impl/OperMaintenanceTaskServiceImpl.java @@ -491,46 +491,92 @@ public class OperMaintenanceTaskServiceImpl extends BaseServiceImpl getMaintenanceListStatistics(String startTime, String endTime,Long deptId) { - List maintenanceTaskEntities = new ArrayList<>(); - R> deptByCurrentUser = sysClient.getDeptByCurrentUser(); - List deptIds; - if (deptByCurrentUser.isSuccess() && CollectionUtil.isNotEmpty(deptByCurrentUser.getData())) { - deptIds = deptByCurrentUser.getData().stream().map(s -> s.getId()).collect(Collectors.toList()); - } else { - throw new ServiceException("暂无机构权限"); - } - QueryWrapper queryWrapper = new QueryWrapper<>(); - if (ObjectUtil.isNotEmpty(deptId)) { - if (deptIds.contains(deptId)) { - queryWrapper.in(ObjectUtils.isNotNull(deptIds), "CREATE_DEPT", deptId); - } else { - throw new ServiceException("暂无该机构权限"); - } - } else { - queryWrapper.in(ObjectUtils.isNotNull(deptIds), "CREATE_DEPT", deptIds); - } - queryWrapper.ge(ObjectUtils.isNotNull(startTime), "CREATE_TIME", startTime); - queryWrapper.le(ObjectUtils.isNotNull(endTime), "CREATE_TIME", endTime); - maintenanceTaskEntities = baseMapper.selectList(queryWrapper); - - List res = new ArrayList<>(); - if (CollectionUtil.isNotEmpty(maintenanceTaskEntities)) { - VoteChartVo all = getVoteChartVo(maintenanceTaskEntities); - all.setName("总计"); - res.add(all); - Map> collect = Optional.ofNullable(maintenanceTaskEntities).orElse(new ArrayList<>()).stream().collect(Collectors.groupingBy(OperMaintenanceTaskEntity::getCreateDept)); - for (Map.Entry> longListEntry : collect.entrySet()) { - VoteChartVo voteChartVo = getVoteChartVo(longListEntry.getValue()); - R deptName = sysClient.getDeptName(longListEntry.getKey()); - voteChartVo.setName(deptName.isSuccess() ? deptName.getData() : ""); - res.add(voteChartVo); + List result = Lists.newArrayList(); + LambdaQueryWrapper wq = Wrappers.lambdaQuery() + .like(Func.isNotEmpty(deptId),OperMaintenanceTaskEntity::getCreateDept, deptId) + .ge(StringUtils.isNotBlank(startTime), OperMaintenanceTaskEntity::getDisposeTime, startTime) + .le(StringUtils.isNotBlank(endTime), OperMaintenanceTaskEntity::getDisposeTime, endTime) + .orderByAsc(OperMaintenanceTaskEntity::getCreateDept); + List taskList = this.list(wq); + Map> taskMapList = taskList.stream().filter(t -> Func.isNotEmpty(t.getDisposer())) + .flatMap(t -> Func.toLongList(t.getDisposer()).stream().filter(Func::isNotEmpty).map(u -> { + OperMaintenanceTaskEntity task = BeanUtil.copy(t, OperMaintenanceTaskEntity.class); + task.setDisposer(u.toString()); + return task; + })) + .collect(Collectors.groupingBy(OperMaintenanceTaskEntity::getCreateDept)); + taskMapList.forEach((id,list) -> { + R deptR = sysClient.getDept(id); + if(deptR.isSuccess() && StringUtil.isNotBlank(deptR.getData().getDeptName())) { + Map> userTaskMap = list.stream().collect(Collectors.groupingBy(OperMaintenanceTaskEntity::getDisposer)); + userTaskMap.forEach((userId,mt) -> { + VoteChartVo chartVo = new VoteChartVo(); + chartVo.setName(deptR.getData().getDeptName()); + chartVo.setUserName(Optional.of(userId).map(Long::parseLong).map(UserCache::getUser).map(User::getName).orElse("-")); + List sumIds = mt.stream().map(OperMaintenanceTaskEntity::getId).distinct().collect(Collectors.toList()); + chartVo.setSumNum(sumIds.size()); + chartVo.setSumIds(sumIds); + List finishIds = mt.stream().filter(task -> "结束".equals(task.getFlowTaskName())).map(OperMaintenanceTaskEntity::getId).distinct().collect(Collectors.toList()); + chartVo.setFinishIds(finishIds); + chartVo.setFinishNum(finishIds.size()); + chartVo.setUndoneIds((List)org.apache.commons.collections4.CollectionUtils.subtract(sumIds, finishIds)); + chartVo.setUndoneNum(sumIds.size() - finishIds.size()); + chartVo.setFinishRate(new BigDecimal((double)finishIds.size() / (double)sumIds.size() * 100).setScale(2,RoundingMode.HALF_UP).doubleValue()); + result.add(chartVo); + }); } - } else { - VoteChartVo all = new VoteChartVo(); - all.setName("总计"); - res.add(all); + }); + // 合计 + if(CollectionUtil.isNotEmpty(result)) { + VoteChartVo chartVo = new VoteChartVo(); + chartVo.setName("合计"); + chartVo.setSumNum(result.stream().collect(Collectors.summingInt(VoteChartVo::getSumNum))); + chartVo.setFinishNum(result.stream().collect(Collectors.summingInt(VoteChartVo::getFinishNum))); + chartVo.setUndoneNum(result.stream().collect(Collectors.summingInt(VoteChartVo::getUndoneNum))); + chartVo.setFinishRate(new BigDecimal((double)chartVo.getFinishNum() / (double)chartVo.getSumNum() * 100).setScale(2,RoundingMode.HALF_UP).doubleValue()); + result.add(chartVo); } - return res; + return result; +// List maintenanceTaskEntities = new ArrayList<>(); +// R> deptByCurrentUser = sysClient.getDeptByCurrentUser(); +// List deptIds; +// if (deptByCurrentUser.isSuccess() && CollectionUtil.isNotEmpty(deptByCurrentUser.getData())) { +// deptIds = deptByCurrentUser.getData().stream().map(s -> s.getId()).collect(Collectors.toList()); +// } else { +// throw new ServiceException("暂无机构权限"); +// } +// QueryWrapper queryWrapper = new QueryWrapper<>(); +// if (ObjectUtil.isNotEmpty(deptId)) { +// if (deptIds.contains(deptId)) { +// queryWrapper.in(ObjectUtils.isNotNull(deptIds), "CREATE_DEPT", deptId); +// } else { +// throw new ServiceException("暂无该机构权限"); +// } +// } else { +// queryWrapper.in(ObjectUtils.isNotNull(deptIds), "CREATE_DEPT", deptIds); +// } +// queryWrapper.ge(ObjectUtils.isNotNull(startTime), "CREATE_TIME", startTime); +// queryWrapper.le(ObjectUtils.isNotNull(endTime), "CREATE_TIME", endTime); +// maintenanceTaskEntities = baseMapper.selectList(queryWrapper); +// +// List res = new ArrayList<>(); +// if (CollectionUtil.isNotEmpty(maintenanceTaskEntities)) { +// VoteChartVo all = getVoteChartVo(maintenanceTaskEntities); +// all.setName("总计"); +// res.add(all); +// Map> collect = Optional.ofNullable(maintenanceTaskEntities).orElse(new ArrayList<>()).stream().collect(Collectors.groupingBy(OperMaintenanceTaskEntity::getCreateDept)); +// for (Map.Entry> longListEntry : collect.entrySet()) { +// VoteChartVo voteChartVo = getVoteChartVo(longListEntry.getValue()); +// R deptName = sysClient.getDeptName(longListEntry.getKey()); +// voteChartVo.setName(deptName.isSuccess() ? deptName.getData() : ""); +// res.add(voteChartVo); +// } +// } else { +// VoteChartVo all = new VoteChartVo(); +// all.setName("总计"); +// res.add(all); +// } +// return res; } @Override