From defac355fde06725916088de8e3b7faf70f4879b Mon Sep 17 00:00:00 2001 From: tyty Date: Sun, 9 Jul 2023 23:21:23 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E6=99=BA=E8=83=BD=E8=AF=8A?= =?UTF-8?q?=E6=96=AD=E7=BB=9F=E8=AE=A1=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/hnac/hzims/fdp/vo/TaskStatisticsVo.java | 50 ++++++++++ .../hzims/fdp/controller/FdpTaskController.java | 16 +++- .../hnac/hzims/fdp/service/IFdpTaskService.java | 6 +- .../hzims/fdp/service/impl/FdpTaskServiceImpl.java | 104 +++++++++++++++++++++ 4 files changed, 173 insertions(+), 3 deletions(-) create mode 100644 hzims-service-api/equipment-api/src/main/java/com/hnac/hzims/fdp/vo/TaskStatisticsVo.java diff --git a/hzims-service-api/equipment-api/src/main/java/com/hnac/hzims/fdp/vo/TaskStatisticsVo.java b/hzims-service-api/equipment-api/src/main/java/com/hnac/hzims/fdp/vo/TaskStatisticsVo.java new file mode 100644 index 0000000..9d4b4a2 --- /dev/null +++ b/hzims-service-api/equipment-api/src/main/java/com/hnac/hzims/fdp/vo/TaskStatisticsVo.java @@ -0,0 +1,50 @@ +package com.hnac.hzims.fdp.vo; + +import com.fasterxml.jackson.annotation.JsonFormat; +import com.hnac.hzims.fdp.entity.FdpTaskEntity; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import org.springframework.format.annotation.DateTimeFormat; + +import java.util.Date; + +/** + * @author tangyu + * @created 2023-07-09 + **/ +@Data +public class TaskStatisticsVo extends FdpTaskEntity { + + /** + * 开始时间 + */ + @DateTimeFormat( + pattern = "yyyy-MM-dd HH:mm:ss" + ) + @JsonFormat( + pattern = "yyyy-MM-dd HH:mm:ss" + ) + @ApiModelProperty(value = "发现时间") + private Date startTime; /** + * 结束时间 + */ + @DateTimeFormat( + pattern = "yyyy-MM-dd HH:mm:ss" + ) + @JsonFormat( + pattern = "yyyy-MM-dd HH:mm:ss" + ) + @ApiModelProperty(value = "发现时间") + private Date endTime; + @ApiModelProperty(value = "占比") + private String percentage; + @ApiModelProperty(value = "数量") + private Integer count; + @ApiModelProperty(value = "几级菜单") + private Integer level; + @ApiModelProperty(value = "菜单名称") + private String name; + + + +} diff --git a/hzims-service/equipment/src/main/java/com/hnac/hzims/fdp/controller/FdpTaskController.java b/hzims-service/equipment/src/main/java/com/hnac/hzims/fdp/controller/FdpTaskController.java index c9fec01..909ca71 100644 --- a/hzims-service/equipment/src/main/java/com/hnac/hzims/fdp/controller/FdpTaskController.java +++ b/hzims-service/equipment/src/main/java/com/hnac/hzims/fdp/controller/FdpTaskController.java @@ -2,7 +2,6 @@ package com.hnac.hzims.fdp.controller; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; -import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport; import com.hnac.hzims.common.logs.annotation.OperationAnnotation; import com.hnac.hzims.common.logs.enums.BusinessType; @@ -11,6 +10,7 @@ import com.hnac.hzims.fdp.dto.FdpTaskDTO; import com.hnac.hzims.fdp.entity.FdpTaskEntity; import com.hnac.hzims.fdp.service.IFdpTaskService; import com.hnac.hzims.fdp.vo.FdpTaskVO; +import com.hnac.hzims.fdp.vo.TaskStatisticsVo; import com.hnac.hzims.fdp.wrapper.FdpTaskWrapper; import com.hnac.hzims.operational.defect.entity.OperPhenomenonEntity; import com.hnac.hzims.operational.defect.vo.OperPhenomenonVO; @@ -29,7 +29,6 @@ import org.springblade.core.tool.utils.StringUtil; import org.springframework.web.bind.annotation.*; import javax.validation.Valid; -import java.util.List; /** * 故障诊断任务表 @@ -136,4 +135,17 @@ public class FdpTaskController extends BladeController { IPage pages = service.page(Condition.getPage(query),queryWrapper); return R.data(pages.setRecords(FdpTaskWrapper.build().listVO(pages.getRecords()))); } + + @PostMapping("/getTaskStatistics") + @ApiOperationSupport(order = 90) + @ApiOperation(value = "获取统计表格") + public R getTaskStatistics(TaskStatisticsVo statisticsVo){ + return service.getTaskStatistics(statisticsVo); + } + @PostMapping("/getTaskData") + @ApiOperationSupport(order = 90) + @ApiOperation(value = "获取统计详细数据") + public R getTaskData(TaskStatisticsVo statisticsVo){ + return service.getTaskData(statisticsVo); + } } diff --git a/hzims-service/equipment/src/main/java/com/hnac/hzims/fdp/service/IFdpTaskService.java b/hzims-service/equipment/src/main/java/com/hnac/hzims/fdp/service/IFdpTaskService.java index 51eac9e..3f18288 100644 --- a/hzims-service/equipment/src/main/java/com/hnac/hzims/fdp/service/IFdpTaskService.java +++ b/hzims-service/equipment/src/main/java/com/hnac/hzims/fdp/service/IFdpTaskService.java @@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.core.metadata.IPage; import com.hnac.hzims.fdp.dto.FdpTaskDTO; import com.hnac.hzims.fdp.entity.FdpTaskEntity; import com.hnac.hzims.fdp.vo.FdpTaskVO; +import com.hnac.hzims.fdp.vo.TaskStatisticsVo; import com.hnac.hzims.operational.defect.entity.OperPhenomenonEntity; import com.hnac.hzims.operational.defect.vo.OperPhenomenonVO; import org.springblade.core.mp.base.BaseService; @@ -28,4 +29,7 @@ public interface IFdpTaskService extends BaseService { R getOperPhenomenon(OperPhenomenonEntity phenomenon); -} + R getTaskStatistics(TaskStatisticsVo statisticsVo); + + R getTaskData(TaskStatisticsVo statisticsVo); + } diff --git a/hzims-service/equipment/src/main/java/com/hnac/hzims/fdp/service/impl/FdpTaskServiceImpl.java b/hzims-service/equipment/src/main/java/com/hnac/hzims/fdp/service/impl/FdpTaskServiceImpl.java index 5f26d88..9db05c1 100644 --- a/hzims-service/equipment/src/main/java/com/hnac/hzims/fdp/service/impl/FdpTaskServiceImpl.java +++ b/hzims-service/equipment/src/main/java/com/hnac/hzims/fdp/service/impl/FdpTaskServiceImpl.java @@ -11,6 +11,7 @@ import com.hnac.hzims.fdp.proxy.IDiagnoseProxy; import com.hnac.hzims.fdp.request.DiagnoseFaultReq; import com.hnac.hzims.fdp.service.IFdpTaskService; import com.hnac.hzims.fdp.vo.FdpTaskVO; +import com.hnac.hzims.fdp.vo.TaskStatisticsVo; import com.hnac.hzims.fdp.wrapper.FdpTaskWrapper; import com.hnac.hzims.operational.defect.entity.OperPhenomenonEntity; import com.hnac.hzims.operational.defect.feign.IOperPhenomenonClient; @@ -21,11 +22,19 @@ import org.springblade.core.mp.base.BaseServiceImpl; import org.springblade.core.mp.support.Condition; import org.springblade.core.mp.support.Query; import org.springblade.core.tool.api.R; +import org.springblade.core.tool.utils.CollectionUtil; +import org.springblade.core.tool.utils.Func; import org.springblade.core.tool.utils.ObjectUtil; import org.springblade.core.tool.utils.StringUtil; import org.springblade.system.feign.ISysClient; import org.springframework.stereotype.Service; +import java.math.BigDecimal; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; + /** * @author xiashandong * @created 2021-05-25 17:32 @@ -110,4 +119,99 @@ public class FdpTaskServiceImpl extends BaseServiceImpl getOperPhenomenon(OperPhenomenonEntity phenomenon) { return operPhenomenonClient.detail(phenomenon); } + + @Override + public R getTaskStatistics(TaskStatisticsVo statisticsVo) { + Wrapper queryWrapper = getFdpTaskEntityWrapper(statisticsVo); + List fdpTaskEntities = super.baseMapper.selectList(queryWrapper); + if (CollectionUtil.isEmpty(fdpTaskEntities)){ + return R.success("暂无数据,请稍后重试"); + } + ArrayList res = new ArrayList<>(); + TaskStatisticsVo taskStatisticsVo = new TaskStatisticsVo(); + taskStatisticsVo.setCount(fdpTaskEntities.size()); + taskStatisticsVo.setPercentage("1"); + taskStatisticsVo.setLevel(0); + taskStatisticsVo.setName("总计"); + res.add(taskStatisticsVo); + Map> collectByCreateDept = fdpTaskEntities.stream().collect(Collectors.groupingBy(FdpTaskEntity::getFdpDeviceName)); + getCount("",collectByCreateDept, fdpTaskEntities, res, 1); + if (Func.isEmpty(statisticsVo.getName())) { + collectByCreateDept.entrySet().forEach(s->{ + Map> collectByName = s.getValue().stream().collect(Collectors.groupingBy(FdpTaskEntity::getName)); + getCount(s.getKey(),collectByName, s.getValue(), res, 2); + }); + } else if (Func.isEmpty(statisticsVo.getFdpDeviceName())){ + collectByCreateDept.entrySet().forEach(s->{ + Map> collectByName = s.getValue().stream().collect(Collectors.groupingBy(FdpTaskEntity::getFdpDeviceName)); + getCount(s.getKey(),collectByName, s.getValue(), res, 2); + }); + }else if (Func.isEmpty(statisticsVo.getFdpOrd())){ + collectByCreateDept.entrySet().forEach(s->{ + Map> collectByName = s.getValue().stream().collect(Collectors.groupingBy(FdpTaskEntity::getFdpOrd)); + getCount(s.getKey(),collectByName, s.getValue(), res, 2); + }); + }else if (Func.isEmpty(statisticsVo.getType())){ + collectByCreateDept.entrySet().forEach(s->{ + Map> collectByName = s.getValue().stream().collect(Collectors.groupingBy(FdpTaskEntity::getType)); + getCount(s.getKey(),collectByName, s.getValue(), res, 2); + }); + } + return R.data(res); + } + + @Override + public R getTaskData(TaskStatisticsVo statisticsVo) { + Wrapper queryWrapper = getFdpTaskEntityWrapper(statisticsVo); + List fdpTaskEntities = super.baseMapper.selectList(queryWrapper); + if (CollectionUtil.isEmpty(fdpTaskEntities)){ + return R.success("暂无数据,请稍后重试"); + } + return R.data(fdpTaskEntities); + } + + private static Wrapper getFdpTaskEntityWrapper(TaskStatisticsVo statisticsVo) { + Wrapper queryWrapper = new LambdaQueryWrapper() {{ + if (Func.isNotEmpty(statisticsVo.getStartTime())) { + ge(FdpTaskEntity::getCreateTime, statisticsVo.getStartTime()); + } + if (Func.isNotEmpty(statisticsVo.getEndTime())) { + le(FdpTaskEntity::getCreateTime, statisticsVo.getEndTime()); + } + if (Func.isNotEmpty(statisticsVo.getCreateDept())) { + in(FdpTaskEntity::getCreateDept, statisticsVo.getCreateDept()); + } + if (Func.isNotEmpty(statisticsVo.getName())) { + like(FdpTaskEntity::getName, statisticsVo.getName()); + } + if (Func.isNotEmpty(statisticsVo.getFdpDeviceName())) { + like(FdpTaskEntity::getFdpDeviceName, statisticsVo.getFdpDeviceName()); + } + if (Func.isNotEmpty(statisticsVo.getFdpOrd())) { + like(FdpTaskEntity::getFdpOrd, statisticsVo.getFdpOrd()); + } + if (Func.isNotEmpty(statisticsVo.getType())) { + eq(FdpTaskEntity::getType, statisticsVo.getType()); + } + if (Func.isNotEmpty(statisticsVo.getStatus())) { + eq(FdpTaskEntity::getStatus, statisticsVo.getStatus()); + } + eq(FdpTaskEntity::getIsDeleted,0); + orderByDesc(FdpTaskEntity::getCreateTime); + }}; + return queryWrapper; + } + + //获取对应层级占比和数量 + private static void getCount(String key,Map> collectByCreateDept, List fdpTaskEntities, ArrayList res,Integer level) { + collectByCreateDept.entrySet().forEach(s->{ + TaskStatisticsVo taskStatisticsVo = new TaskStatisticsVo(); + taskStatisticsVo.setCount(s.getValue().size()); + BigDecimal bigDecimal=BigDecimal.valueOf(s.getValue().size()).divide(BigDecimal.valueOf(fdpTaskEntities.size())); + taskStatisticsVo.setPercentage(bigDecimal.toString()); + taskStatisticsVo.setLevel(level); + taskStatisticsVo.setName(key+"-"+s.getKey().toString()); + res.add(taskStatisticsVo); + }); + } }