|
|
|
@ -1,9 +1,11 @@
|
|
|
|
|
package com.hnac.hzims.fdp.service.impl; |
|
|
|
|
|
|
|
|
|
import com.alibaba.fastjson.JSONObject; |
|
|
|
|
import com.aliyun.oss.ServiceException; |
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.Wrapper; |
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
|
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage; |
|
|
|
|
import com.hnac.hzims.fdp.dto.FdpSubmitResultDTO; |
|
|
|
|
import com.hnac.hzims.fdp.dto.FdpTaskDTO; |
|
|
|
|
import com.hnac.hzims.fdp.entity.FdpTaskEntity; |
|
|
|
|
import com.hnac.hzims.fdp.mapper.FdpTaskMapper; |
|
|
|
@ -16,6 +18,8 @@ import com.hnac.hzims.fdp.wrapper.FdpTaskWrapper;
|
|
|
|
|
import com.hnac.hzims.operational.defect.entity.OperPhenomenonEntity; |
|
|
|
|
import com.hnac.hzims.operational.defect.feign.IOperPhenomenonClient; |
|
|
|
|
import com.hnac.hzims.operational.defect.vo.OperPhenomenonVO; |
|
|
|
|
import com.hnac.hzims.util.HttpClientUtils; |
|
|
|
|
import com.hnac.hzims.util.pojo.HttpResponse; |
|
|
|
|
import lombok.AllArgsConstructor; |
|
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
|
import org.springblade.core.mp.base.BaseServiceImpl; |
|
|
|
@ -27,6 +31,7 @@ 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.beans.factory.annotation.Value; |
|
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
|
|
|
|
|
|
import java.math.BigDecimal; |
|
|
|
@ -47,13 +52,16 @@ public class FdpTaskServiceImpl extends BaseServiceImpl<FdpTaskMapper, FdpTaskEn
|
|
|
|
|
private final ISysClient sysClient; |
|
|
|
|
private IDiagnoseProxy diagnoseProxy; |
|
|
|
|
|
|
|
|
|
@Value("${url.submitResult}") |
|
|
|
|
public String submitResult; |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public R doSave(FdpTaskDTO req) { |
|
|
|
|
boolean flag = super.save(req); |
|
|
|
|
if(flag){ |
|
|
|
|
if (flag) { |
|
|
|
|
DiagnoseFaultReq diagnoseFaultReq = new DiagnoseFaultReq(); |
|
|
|
|
diagnoseFaultReq.setTaskId(req.getId().toString()); |
|
|
|
|
log.info("存入taskId为:{}",req.getId().toString()); |
|
|
|
|
log.info("存入taskId为:{}", req.getId().toString()); |
|
|
|
|
diagnoseFaultReq.setFaultId(req.getFaultId()); |
|
|
|
|
diagnoseFaultReq.setConfidence(1.0); |
|
|
|
|
diagnoseFaultReq.setLifeTime(1); |
|
|
|
@ -72,12 +80,11 @@ public class FdpTaskServiceImpl extends BaseServiceImpl<FdpTaskMapper, FdpTaskEn
|
|
|
|
|
@Override |
|
|
|
|
public boolean updateTaskStatus(Long id) { |
|
|
|
|
FdpTaskEntity detail = super.getById(id); |
|
|
|
|
try{ |
|
|
|
|
try { |
|
|
|
|
detail.setStatus(1); |
|
|
|
|
boolean flag = super.saveOrUpdate(detail); |
|
|
|
|
return flag; |
|
|
|
|
} |
|
|
|
|
catch (NullPointerException e){ |
|
|
|
|
} catch (NullPointerException e) { |
|
|
|
|
throw new ServiceException("该id无法获取到智能诊断任务记录!"); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
@ -102,11 +109,11 @@ public class FdpTaskServiceImpl extends BaseServiceImpl<FdpTaskMapper, FdpTaskEn
|
|
|
|
|
if (req.getSatisfaction() != null) { |
|
|
|
|
eq(FdpTaskEntity::getSatisfaction, req.getSatisfaction()); |
|
|
|
|
} |
|
|
|
|
if(ObjectUtil.isNotEmpty(req.getStatus())){ |
|
|
|
|
if (ObjectUtil.isNotEmpty(req.getStatus())) { |
|
|
|
|
eq(FdpTaskEntity::getStatus, req.getStatus()); |
|
|
|
|
} |
|
|
|
|
if(StringUtil.isNotBlank(req.getFdpDeviceName())){ |
|
|
|
|
like(FdpTaskEntity::getFdpDeviceName,req.getFdpDeviceName()); |
|
|
|
|
if (StringUtil.isNotBlank(req.getFdpDeviceName())) { |
|
|
|
|
like(FdpTaskEntity::getFdpDeviceName, req.getFdpDeviceName()); |
|
|
|
|
} |
|
|
|
|
}}; |
|
|
|
|
|
|
|
|
@ -124,65 +131,65 @@ public class FdpTaskServiceImpl extends BaseServiceImpl<FdpTaskMapper, FdpTaskEn
|
|
|
|
|
public R getTaskStatistics(TaskStatisticsVo statisticsVo) { |
|
|
|
|
Wrapper<FdpTaskEntity> queryWrapper = getFdpTaskEntityWrapper(statisticsVo); |
|
|
|
|
List<FdpTaskEntity> fdpTaskEntities = super.baseMapper.selectList(queryWrapper); |
|
|
|
|
if (CollectionUtil.isEmpty(fdpTaskEntities)){ |
|
|
|
|
if (CollectionUtil.isEmpty(fdpTaskEntities)) { |
|
|
|
|
return R.success("暂无数据,请稍后重试"); |
|
|
|
|
} |
|
|
|
|
ArrayList<TaskStatisticsVo> res = new ArrayList<>(); |
|
|
|
|
int size = fdpTaskEntities.size(); |
|
|
|
|
//在第一层去掉为null值数据
|
|
|
|
|
fdpTaskEntities=fdpTaskEntities.stream().filter(s->s.getFdpDeviceName()!=null).collect(Collectors.toList()); |
|
|
|
|
extracted( res,0,"总计",size,size); |
|
|
|
|
fdpTaskEntities = fdpTaskEntities.stream().filter(s -> s.getFdpDeviceName() != null).collect(Collectors.toList()); |
|
|
|
|
extracted(res, 0, "总计", size, size); |
|
|
|
|
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())) { |
|
|
|
|
collectByFdpDeviceName.entrySet().forEach(s->{ |
|
|
|
|
List<FdpTaskEntity> list=s.getValue().stream().filter(sig->sig.getName()!=null).collect(Collectors.toList()); |
|
|
|
|
collectByFdpDeviceName.entrySet().forEach(s -> { |
|
|
|
|
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); |
|
|
|
|
if (list.size()!=s.getValue().size()) { |
|
|
|
|
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()); |
|
|
|
|
extracted(res, 1, s.getKey() + "-空", s.getValue().size() - list.size(), s.getValue().size()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
}); |
|
|
|
|
} else if (Func.isEmpty(statisticsVo.getCreateDept())){ |
|
|
|
|
collectByFdpDeviceName.entrySet().forEach(s->{ |
|
|
|
|
List<FdpTaskEntity> list=s.getValue().stream().filter(sig->sig.getCreateDept()!=null).collect(Collectors.toList()); |
|
|
|
|
} else if (Func.isEmpty(statisticsVo.getCreateDept())) { |
|
|
|
|
collectByFdpDeviceName.entrySet().forEach(s -> { |
|
|
|
|
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); |
|
|
|
|
if (list.size()!=s.getValue().size()) { |
|
|
|
|
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()); |
|
|
|
|
extracted(res, 1, s.getKey() + "-空", s.getValue().size() - list.size(), s.getValue().size()); |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
}else if (Func.isEmpty(statisticsVo.getFdpOrd())){ |
|
|
|
|
collectByFdpDeviceName.entrySet().forEach(s->{ |
|
|
|
|
List<FdpTaskEntity> list=s.getValue().stream().filter(sig->sig.getFdpOrd()!=null).collect(Collectors.toList()); |
|
|
|
|
} else if (Func.isEmpty(statisticsVo.getFdpOrd())) { |
|
|
|
|
collectByFdpDeviceName.entrySet().forEach(s -> { |
|
|
|
|
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); |
|
|
|
|
if (list.size()!=s.getValue().size()) { |
|
|
|
|
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()); |
|
|
|
|
extracted(res, 1, s.getKey() + "-空", s.getValue().size() - list.size(), s.getValue().size()); |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
}else if (Func.isEmpty(statisticsVo.getType())){ |
|
|
|
|
collectByFdpDeviceName.entrySet().forEach(s->{ |
|
|
|
|
List<FdpTaskEntity> list=s.getValue().stream().filter(sig->sig.getFdpOrd()!=null).collect(Collectors.toList()); |
|
|
|
|
} else if (Func.isEmpty(statisticsVo.getType())) { |
|
|
|
|
collectByFdpDeviceName.entrySet().forEach(s -> { |
|
|
|
|
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); |
|
|
|
|
if (list.size()!=s.getValue().size()) { |
|
|
|
|
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()); |
|
|
|
|
extracted(res, 1, s.getKey() + "-空", s.getValue().size() - list.size(), s.getValue().size()); |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
return R.data(res); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private static void extracted( ArrayList<TaskStatisticsVo> res,Integer level,String name,Integer size,Integer all) { |
|
|
|
|
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); |
|
|
|
|
BigDecimal bigDecimal = BigDecimal.valueOf(all).divide(BigDecimal.valueOf(size), 2, BigDecimal.ROUND_UP); |
|
|
|
|
taskStatisticsByDeviceName.setPercentage(bigDecimal.toString()); |
|
|
|
|
taskStatisticsByDeviceName.setLevel(level); |
|
|
|
|
taskStatisticsByDeviceName.setMemuName(name); |
|
|
|
@ -190,15 +197,55 @@ public class FdpTaskServiceImpl extends BaseServiceImpl<FdpTaskMapper, FdpTaskEn
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public R getTaskData(TaskStatisticsVo statisticsVo,Query query) { |
|
|
|
|
public R getTaskData(TaskStatisticsVo statisticsVo, Query query) { |
|
|
|
|
Wrapper<FdpTaskEntity> queryWrapper = getFdpTaskEntityWrapper(statisticsVo); |
|
|
|
|
IPage pages = super.baseMapper.selectPage(Condition.getPage(query),queryWrapper); |
|
|
|
|
if (CollectionUtil.isEmpty(pages.getRecords())){ |
|
|
|
|
IPage pages = super.baseMapper.selectPage(Condition.getPage(query), queryWrapper); |
|
|
|
|
if (CollectionUtil.isEmpty(pages.getRecords())) { |
|
|
|
|
return R.success("暂无数据,请稍后重试"); |
|
|
|
|
} |
|
|
|
|
return R.data(pages); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public R submitResult(FdpTaskDTO req) { |
|
|
|
|
FdpSubmitResultDTO fdpSubmitResultDTO = new FdpSubmitResultDTO(); |
|
|
|
|
if (4 == req.getStatus()) { |
|
|
|
|
fdpSubmitResultDTO.setSuccess(0); |
|
|
|
|
} |
|
|
|
|
//诊断成功
|
|
|
|
|
if (3 == req.getStatus()) { |
|
|
|
|
fdpSubmitResultDTO.setSuccess(1); |
|
|
|
|
} else if (Func.isNotEmpty(req.getReasonId())) { |
|
|
|
|
fdpSubmitResultDTO.setRootCause(req.getReasonId()); |
|
|
|
|
} else { |
|
|
|
|
return R.fail("诊断传送状态异常"); |
|
|
|
|
} |
|
|
|
|
if (Func.isNotEmpty(req.getReasonId())) { |
|
|
|
|
fdpSubmitResultDTO.setRootCause(req.getReasonId()); |
|
|
|
|
} |
|
|
|
|
if (Func.isNotEmpty(req.getFaultId())) { |
|
|
|
|
fdpSubmitResultDTO.setFaultId(req.getFaultId()); |
|
|
|
|
} else { |
|
|
|
|
return R.fail("数据异常"); |
|
|
|
|
} |
|
|
|
|
if (Func.isNotEmpty(req.getComment())) { |
|
|
|
|
fdpSubmitResultDTO.setComment(req.getComment()); |
|
|
|
|
} |
|
|
|
|
if (Func.isNotEmpty(req.getStation())) { |
|
|
|
|
fdpSubmitResultDTO.setStationId(req.getStation()); |
|
|
|
|
} |
|
|
|
|
HttpResponse r = HttpClientUtils.post(submitResult, JSONObject.toJSONString(fdpSubmitResultDTO)); |
|
|
|
|
if (200 != r.getCode()) { |
|
|
|
|
throw new ServiceException("智能诊断回传失败"); |
|
|
|
|
} |
|
|
|
|
boolean b = this.updateById(req); |
|
|
|
|
if (b) { |
|
|
|
|
return R.success("保存成功"); |
|
|
|
|
} else { |
|
|
|
|
return R.fail("保存失败,请稍后重试"); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private static Wrapper<FdpTaskEntity> getFdpTaskEntityWrapper(TaskStatisticsVo statisticsVo) { |
|
|
|
|
Wrapper<FdpTaskEntity> queryWrapper = new LambdaQueryWrapper<FdpTaskEntity>() {{ |
|
|
|
|
if (Func.isNotEmpty(statisticsVo.getStartTime())) { |
|
|
|
@ -225,41 +272,42 @@ public class FdpTaskServiceImpl extends BaseServiceImpl<FdpTaskMapper, FdpTaskEn
|
|
|
|
|
if (Func.isNotEmpty(statisticsVo.getStatus())) { |
|
|
|
|
eq(FdpTaskEntity::getStatus, statisticsVo.getStatus()); |
|
|
|
|
} |
|
|
|
|
eq(FdpTaskEntity::getIsDeleted,0); |
|
|
|
|
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->{ |
|
|
|
|
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()),2,BigDecimal.ROUND_UP); |
|
|
|
|
BigDecimal bigDecimal = BigDecimal.valueOf(s.getValue().size()).divide(BigDecimal.valueOf(fdpTaskEntities.size()), 2, BigDecimal.ROUND_UP); |
|
|
|
|
taskStatisticsVo.setPercentage(bigDecimal.toString()); |
|
|
|
|
taskStatisticsVo.setLevel(level); |
|
|
|
|
taskStatisticsVo.setMemuName(key+"-"+s.getKey().toString()); |
|
|
|
|
taskStatisticsVo.setMemuName(key + "-" + s.getKey().toString()); |
|
|
|
|
res.add(taskStatisticsVo); |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
//获取对应层级占比和数量
|
|
|
|
|
//机构类型需要转换ID为名称
|
|
|
|
|
private void getCount2(String key,Map<Long, List<FdpTaskEntity>> collectByCreateDept, List<FdpTaskEntity> fdpTaskEntities, ArrayList<TaskStatisticsVo> res,Integer level) { |
|
|
|
|
collectByCreateDept.entrySet().forEach(s->{ |
|
|
|
|
private void getCount2(String key, Map<Long, 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())); |
|
|
|
|
BigDecimal bigDecimal = BigDecimal.valueOf(s.getValue().size()).divide(BigDecimal.valueOf(fdpTaskEntities.size())); |
|
|
|
|
taskStatisticsVo.setPercentage(bigDecimal.toString()); |
|
|
|
|
taskStatisticsVo.setLevel(level); |
|
|
|
|
R<String> deptNameCode = sysClient.getDeptName(s.getKey()); |
|
|
|
|
String deptName; |
|
|
|
|
if (deptNameCode.isSuccess()){ |
|
|
|
|
deptName=deptNameCode.getData(); |
|
|
|
|
}else { |
|
|
|
|
deptName=""; |
|
|
|
|
if (deptNameCode.isSuccess()) { |
|
|
|
|
deptName = deptNameCode.getData(); |
|
|
|
|
} else { |
|
|
|
|
deptName = ""; |
|
|
|
|
} |
|
|
|
|
taskStatisticsVo.setMemuName(key+"-"+deptName); |
|
|
|
|
taskStatisticsVo.setMemuName(key + "-" + deptName); |
|
|
|
|
res.add(taskStatisticsVo); |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|