Browse Source

新增智能诊断统计接口

zhongwei
tyty 1 year ago
parent
commit
defac355fd
  1. 50
      hzims-service-api/equipment-api/src/main/java/com/hnac/hzims/fdp/vo/TaskStatisticsVo.java
  2. 16
      hzims-service/equipment/src/main/java/com/hnac/hzims/fdp/controller/FdpTaskController.java
  3. 6
      hzims-service/equipment/src/main/java/com/hnac/hzims/fdp/service/IFdpTaskService.java
  4. 104
      hzims-service/equipment/src/main/java/com/hnac/hzims/fdp/service/impl/FdpTaskServiceImpl.java

50
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;
}

16
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);
}
}

6
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<FdpTaskEntity> {
R<OperPhenomenonVO> getOperPhenomenon(OperPhenomenonEntity phenomenon);
}
R getTaskStatistics(TaskStatisticsVo statisticsVo);
R getTaskData(TaskStatisticsVo statisticsVo);
}

104
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<FdpTaskMapper, FdpTaskEn
public R<OperPhenomenonVO> getOperPhenomenon(OperPhenomenonEntity phenomenon) {
return operPhenomenonClient.detail(phenomenon);
}
@Override
public R getTaskStatistics(TaskStatisticsVo statisticsVo) {
Wrapper<FdpTaskEntity> queryWrapper = getFdpTaskEntityWrapper(statisticsVo);
List<FdpTaskEntity> fdpTaskEntities = super.baseMapper.selectList(queryWrapper);
if (CollectionUtil.isEmpty(fdpTaskEntities)){
return R.success("暂无数据,请稍后重试");
}
ArrayList<TaskStatisticsVo> res = new ArrayList<>();
TaskStatisticsVo taskStatisticsVo = new TaskStatisticsVo();
taskStatisticsVo.setCount(fdpTaskEntities.size());
taskStatisticsVo.setPercentage("1");
taskStatisticsVo.setLevel(0);
taskStatisticsVo.setName("总计");
res.add(taskStatisticsVo);
Map<String, List<FdpTaskEntity>> collectByCreateDept = fdpTaskEntities.stream().collect(Collectors.groupingBy(FdpTaskEntity::getFdpDeviceName));
getCount("",collectByCreateDept, fdpTaskEntities, res, 1);
if (Func.isEmpty(statisticsVo.getName())) {
collectByCreateDept.entrySet().forEach(s->{
Map<String, List<FdpTaskEntity>> 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<String, List<FdpTaskEntity>> 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<String, List<FdpTaskEntity>> 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<String, List<FdpTaskEntity>> 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<FdpTaskEntity> queryWrapper = getFdpTaskEntityWrapper(statisticsVo);
List<FdpTaskEntity> fdpTaskEntities = super.baseMapper.selectList(queryWrapper);
if (CollectionUtil.isEmpty(fdpTaskEntities)){
return R.success("暂无数据,请稍后重试");
}
return R.data(fdpTaskEntities);
}
private static Wrapper<FdpTaskEntity> getFdpTaskEntityWrapper(TaskStatisticsVo statisticsVo) {
Wrapper<FdpTaskEntity> queryWrapper = new LambdaQueryWrapper<FdpTaskEntity>() {{
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<String, List<FdpTaskEntity>> collectByCreateDept, List<FdpTaskEntity> fdpTaskEntities, ArrayList<TaskStatisticsVo> 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);
});
}
}

Loading…
Cancel
Save