Browse Source

修改智能诊断统计代码

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

4
hzims-service-api/equipment-api/src/main/java/com/hnac/hzims/fdp/vo/TaskStatisticsVo.java

@ -4,6 +4,7 @@ import com.fasterxml.jackson.annotation.JsonFormat;
import com.hnac.hzims.fdp.entity.FdpTaskEntity; import com.hnac.hzims.fdp.entity.FdpTaskEntity;
import io.swagger.annotations.ApiModelProperty; import io.swagger.annotations.ApiModelProperty;
import lombok.Data; import lombok.Data;
import lombok.EqualsAndHashCode;
import org.springframework.format.annotation.DateTimeFormat; import org.springframework.format.annotation.DateTimeFormat;
import java.util.Date; import java.util.Date;
@ -13,8 +14,9 @@ import java.util.Date;
* @created 2023-07-09 * @created 2023-07-09
**/ **/
@Data @Data
@EqualsAndHashCode(callSuper = true)
public class TaskStatisticsVo extends FdpTaskEntity { public class TaskStatisticsVo extends FdpTaskEntity {
private static final long serialVersionUID = 1L;
/** /**
* 开始时间 * 开始时间
*/ */

4
hzims-service/equipment/src/main/java/com/hnac/hzims/fdp/controller/FdpTaskController.java

@ -145,7 +145,7 @@ public class FdpTaskController extends BladeController {
@PostMapping("/getTaskData") @PostMapping("/getTaskData")
@ApiOperationSupport(order = 90) @ApiOperationSupport(order = 90)
@ApiOperation(value = "获取统计详细数据") @ApiOperation(value = "获取统计详细数据")
public R getTaskData(TaskStatisticsVo statisticsVo){ public R getTaskData(TaskStatisticsVo statisticsVo,Query query){
return service.getTaskData(statisticsVo); return service.getTaskData(statisticsVo,query);
} }
} }

2
hzims-service/equipment/src/main/java/com/hnac/hzims/fdp/service/IFdpTaskService.java

@ -31,5 +31,5 @@ public interface IFdpTaskService extends BaseService<FdpTaskEntity> {
R getTaskStatistics(TaskStatisticsVo statisticsVo); R getTaskStatistics(TaskStatisticsVo statisticsVo);
R getTaskData(TaskStatisticsVo statisticsVo); R getTaskData(TaskStatisticsVo statisticsVo,Query query);
} }

64
hzims-service/equipment/src/main/java/com/hnac/hzims/fdp/service/impl/FdpTaskServiceImpl.java

@ -128,46 +128,75 @@ public class FdpTaskServiceImpl extends BaseServiceImpl<FdpTaskMapper, FdpTaskEn
return R.success("暂无数据,请稍后重试"); return R.success("暂无数据,请稍后重试");
} }
ArrayList<TaskStatisticsVo> res = new ArrayList<>(); ArrayList<TaskStatisticsVo> res = new ArrayList<>();
TaskStatisticsVo taskStatisticsVo = new TaskStatisticsVo(); int size = fdpTaskEntities.size();
taskStatisticsVo.setCount(fdpTaskEntities.size()); //在第一层去掉为null值数据
taskStatisticsVo.setPercentage("1"); fdpTaskEntities=fdpTaskEntities.stream().filter(s->s.getFdpDeviceName()!=null).collect(Collectors.toList());
taskStatisticsVo.setLevel(0); extracted( res,0,"总计",size,size);
taskStatisticsVo.setName("总计");
res.add(taskStatisticsVo);
Map<String, List<FdpTaskEntity>> collectByFdpDeviceName = fdpTaskEntities.stream().collect(Collectors.groupingBy(FdpTaskEntity::getFdpDeviceName)); Map<String, List<FdpTaskEntity>> collectByFdpDeviceName = fdpTaskEntities.stream().collect(Collectors.groupingBy(FdpTaskEntity::getFdpDeviceName));
getCount("",collectByFdpDeviceName, fdpTaskEntities, res, 1); getCount("",collectByFdpDeviceName, fdpTaskEntities, res, 1);
if (Func.isEmpty(statisticsVo.getName())) { if (Func.isEmpty(statisticsVo.getName())) {
collectByFdpDeviceName.entrySet().forEach(s->{ collectByFdpDeviceName.entrySet().forEach(s->{
Map<String, List<FdpTaskEntity>> collectByName = s.getValue().stream().collect(Collectors.groupingBy(FdpTaskEntity::getName)); List<FdpTaskEntity> list=s.getValue().stream().filter(sig->sig.getName()!=null).collect(Collectors.toList());
Map<String, List<FdpTaskEntity>> collectByName = list.stream().collect(Collectors.groupingBy(FdpTaskEntity::getName));
getCount(s.getKey(),collectByName, s.getValue(), res, 2); getCount(s.getKey(),collectByName, s.getValue(), res, 2);
if (list.size()!=s.getValue().size()) {
//值为空单独加进来
extracted( res,1,s.getKey()+"-空",s.getValue().size()-list.size(),s.getValue().size());
}
}); });
} else if (Func.isEmpty(statisticsVo.getCreateDept())){ } else if (Func.isEmpty(statisticsVo.getCreateDept())){
collectByFdpDeviceName.entrySet().forEach(s->{ collectByFdpDeviceName.entrySet().forEach(s->{
Map<Long, List<FdpTaskEntity>> collectByName = s.getValue().stream().collect(Collectors.groupingBy(FdpTaskEntity::getCreateDept)); List<FdpTaskEntity> list=s.getValue().stream().filter(sig->sig.getCreateDept()!=null).collect(Collectors.toList());
Map<Long, List<FdpTaskEntity>> collectByName = list.stream().collect(Collectors.groupingBy(FdpTaskEntity::getCreateDept));
getCount2(s.getKey(),collectByName, s.getValue(), res, 2); getCount2(s.getKey(),collectByName, s.getValue(), res, 2);
if (list.size()!=s.getValue().size()) {
//值为空单独加进来
extracted( res,1,s.getKey()+"-空",s.getValue().size()-list.size(),s.getValue().size());
}
}); });
}else if (Func.isEmpty(statisticsVo.getFdpOrd())){ }else if (Func.isEmpty(statisticsVo.getFdpOrd())){
collectByFdpDeviceName.entrySet().forEach(s->{ collectByFdpDeviceName.entrySet().forEach(s->{
Map<String, List<FdpTaskEntity>> collectByName = s.getValue().stream().collect(Collectors.groupingBy(FdpTaskEntity::getFdpOrd)); List<FdpTaskEntity> list=s.getValue().stream().filter(sig->sig.getFdpOrd()!=null).collect(Collectors.toList());
Map<String, List<FdpTaskEntity>> collectByName = list.stream().collect(Collectors.groupingBy(FdpTaskEntity::getFdpOrd));
getCount(s.getKey(),collectByName, s.getValue(), res, 2); getCount(s.getKey(),collectByName, s.getValue(), res, 2);
if (list.size()!=s.getValue().size()) {
//值为空单独加进来
extracted( res,1,s.getKey()+"-空",s.getValue().size()-list.size(),s.getValue().size());
}
}); });
}else if (Func.isEmpty(statisticsVo.getType())){ }else if (Func.isEmpty(statisticsVo.getType())){
collectByFdpDeviceName.entrySet().forEach(s->{ collectByFdpDeviceName.entrySet().forEach(s->{
Map<String, List<FdpTaskEntity>> collectByName = s.getValue().stream().collect(Collectors.groupingBy(FdpTaskEntity::getType)); List<FdpTaskEntity> list=s.getValue().stream().filter(sig->sig.getFdpOrd()!=null).collect(Collectors.toList());
Map<String, List<FdpTaskEntity>> collectByName = list.stream().collect(Collectors.groupingBy(FdpTaskEntity::getType));
getCount(s.getKey(),collectByName, s.getValue(), res, 2); getCount(s.getKey(),collectByName, s.getValue(), res, 2);
if (list.size()!=s.getValue().size()) {
//值为空单独加进来
extracted( res,1,s.getKey()+"-空",s.getValue().size()-list.size(),s.getValue().size());
}
}); });
} }
return R.data(res); return R.data(res);
} }
private static void extracted( ArrayList<TaskStatisticsVo> res,Integer level,String name,Integer size,Integer all) {
TaskStatisticsVo taskStatisticsByDeviceName = new TaskStatisticsVo();
taskStatisticsByDeviceName.setCount(size);
BigDecimal bigDecimal=BigDecimal.valueOf(all).divide(BigDecimal.valueOf(size),2,BigDecimal.ROUND_UP);
taskStatisticsByDeviceName.setPercentage(bigDecimal.toString());
taskStatisticsByDeviceName.setLevel(level);
taskStatisticsByDeviceName.setMemuName(name);
res.add(taskStatisticsByDeviceName);
}
@Override @Override
public R getTaskData(TaskStatisticsVo statisticsVo) { public R getTaskData(TaskStatisticsVo statisticsVo,Query query) {
Wrapper<FdpTaskEntity> queryWrapper = getFdpTaskEntityWrapper(statisticsVo); Wrapper<FdpTaskEntity> queryWrapper = getFdpTaskEntityWrapper(statisticsVo);
List<FdpTaskEntity> fdpTaskEntities = super.baseMapper.selectList(queryWrapper); IPage pages = super.baseMapper.selectPage(Condition.getPage(query),queryWrapper);
if (CollectionUtil.isEmpty(fdpTaskEntities)){ if (CollectionUtil.isEmpty(pages.getRecords())){
return R.success("暂无数据,请稍后重试"); return R.success("暂无数据,请稍后重试");
} }
return R.data(fdpTaskEntities); return R.data(pages);
} }
private static Wrapper<FdpTaskEntity> getFdpTaskEntityWrapper(TaskStatisticsVo statisticsVo) { private static Wrapper<FdpTaskEntity> getFdpTaskEntityWrapper(TaskStatisticsVo statisticsVo) {
@ -207,13 +236,14 @@ public class FdpTaskServiceImpl extends BaseServiceImpl<FdpTaskMapper, FdpTaskEn
collectByCreateDept.entrySet().forEach(s->{ collectByCreateDept.entrySet().forEach(s->{
TaskStatisticsVo taskStatisticsVo = new TaskStatisticsVo(); TaskStatisticsVo taskStatisticsVo = new TaskStatisticsVo();
taskStatisticsVo.setCount(s.getValue().size()); taskStatisticsVo.setCount(s.getValue().size());
BigDecimal bigDecimal=BigDecimal.valueOf(s.getValue().size()).divide(BigDecimal.valueOf(fdpTaskEntities.size())); BigDecimal bigDecimal=BigDecimal.valueOf(s.getValue().size()).divide(BigDecimal.valueOf(fdpTaskEntities.size()),2,BigDecimal.ROUND_UP);
taskStatisticsVo.setPercentage(bigDecimal.toString()); taskStatisticsVo.setPercentage(bigDecimal.toString());
taskStatisticsVo.setLevel(level); taskStatisticsVo.setLevel(level);
taskStatisticsVo.setName(key+"-"+s.getKey().toString()); taskStatisticsVo.setMemuName(key+"-"+s.getKey().toString());
res.add(taskStatisticsVo); res.add(taskStatisticsVo);
}); });
} }
//获取对应层级占比和数量
//机构类型需要转换ID为名称 //机构类型需要转换ID为名称
private void getCount2(String key,Map<Long, List<FdpTaskEntity>> collectByCreateDept, List<FdpTaskEntity> fdpTaskEntities, ArrayList<TaskStatisticsVo> res,Integer level) { private void getCount2(String key,Map<Long, List<FdpTaskEntity>> collectByCreateDept, List<FdpTaskEntity> fdpTaskEntities, ArrayList<TaskStatisticsVo> res,Integer level) {
collectByCreateDept.entrySet().forEach(s->{ collectByCreateDept.entrySet().forEach(s->{
@ -229,7 +259,7 @@ public class FdpTaskServiceImpl extends BaseServiceImpl<FdpTaskMapper, FdpTaskEn
}else { }else {
deptName=""; deptName="";
} }
taskStatisticsVo.setName(key+"-"+deptName); taskStatisticsVo.setMemuName(key+"-"+deptName);
res.add(taskStatisticsVo); res.add(taskStatisticsVo);
}); });
} }

Loading…
Cancel
Save