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 index 9d4b4a2..37bb17f 100644 --- 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 @@ -4,6 +4,7 @@ import com.fasterxml.jackson.annotation.JsonFormat; import com.hnac.hzims.fdp.entity.FdpTaskEntity; import io.swagger.annotations.ApiModelProperty; import lombok.Data; +import lombok.EqualsAndHashCode; import org.springframework.format.annotation.DateTimeFormat; import java.util.Date; @@ -13,8 +14,9 @@ import java.util.Date; * @created 2023-07-09 **/ @Data +@EqualsAndHashCode(callSuper = true) public class TaskStatisticsVo extends FdpTaskEntity { - + private static final long serialVersionUID = 1L; /** * 开始时间 */ @@ -43,7 +45,7 @@ public class TaskStatisticsVo extends FdpTaskEntity { @ApiModelProperty(value = "几级菜单") private Integer level; @ApiModelProperty(value = "菜单名称") - private String name; + private String memuName; diff --git a/hzims-service-api/middle-api/src/main/java/com/hnac/hzims/middle/process/fallback/ProcessDictFeignServiceFallback.java b/hzims-service-api/middle-api/src/main/java/com/hnac/hzims/middle/process/fallback/ProcessDictFeignServiceFallback.java index afe824b..e368bf7 100644 --- a/hzims-service-api/middle-api/src/main/java/com/hnac/hzims/middle/process/fallback/ProcessDictFeignServiceFallback.java +++ b/hzims-service-api/middle-api/src/main/java/com/hnac/hzims/middle/process/fallback/ProcessDictFeignServiceFallback.java @@ -21,11 +21,10 @@ public class ProcessDictFeignServiceFallback implements ProcessDictFeignService * * @param staff * @param typeInstrument - * @param createTime * @return */ @Override - public String getTicketByCode(String staff, String typeInstrument, LocalDateTime createTime) { + public String getTicketByCode(String staff, String typeInstrument) { log.error("获取工作票工作票唯一ID 熔断措施"); return null; } diff --git a/hzims-service-api/middle-api/src/main/java/com/hnac/hzims/middle/process/feign/ProcessDictFeignService.java b/hzims-service-api/middle-api/src/main/java/com/hnac/hzims/middle/process/feign/ProcessDictFeignService.java index 27bc415..70413dc 100644 --- a/hzims-service-api/middle-api/src/main/java/com/hnac/hzims/middle/process/feign/ProcessDictFeignService.java +++ b/hzims-service-api/middle-api/src/main/java/com/hnac/hzims/middle/process/feign/ProcessDictFeignService.java @@ -21,13 +21,11 @@ public interface ProcessDictFeignService { * * @param staff * @param typeInstrument - * @param createTime * @return */ @GetMapping("/process-dict/getTicketByCode") public String getTicketByCode(@RequestParam("staff") String staff, - @RequestParam("typeInstrument") String typeInstrument, - @RequestParam("createTime") LocalDateTime createTime); + @RequestParam("typeInstrument") String typeInstrument); /** 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 909ca71..2dd18d7 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 @@ -145,7 +145,7 @@ public class FdpTaskController extends BladeController { @PostMapping("/getTaskData") @ApiOperationSupport(order = 90) @ApiOperation(value = "获取统计详细数据") - public R getTaskData(TaskStatisticsVo statisticsVo){ - return service.getTaskData(statisticsVo); + public R getTaskData(TaskStatisticsVo statisticsVo,Query query){ + return service.getTaskData(statisticsVo,query); } } diff --git a/hzims-service/equipment/src/main/java/com/hnac/hzims/fdp/response/FaultStateResp.java b/hzims-service/equipment/src/main/java/com/hnac/hzims/fdp/response/FaultStateResp.java index a449dce..c10b35d 100644 --- a/hzims-service/equipment/src/main/java/com/hnac/hzims/fdp/response/FaultStateResp.java +++ b/hzims-service/equipment/src/main/java/com/hnac/hzims/fdp/response/FaultStateResp.java @@ -24,7 +24,7 @@ public class FaultStateResp { // @JSONField(name = "NAME") // private String name; @ApiModelProperty("数据时间") - @JSONField(name = "NAME") + @JSONField(name = "ts") private String ts; @ApiModelProperty("状态") @JSONField(name = "STATUS") diff --git a/hzims-service/equipment/src/main/java/com/hnac/hzims/fdp/scheduled/ThreadTask.java b/hzims-service/equipment/src/main/java/com/hnac/hzims/fdp/scheduled/ThreadTask.java index f70139a..32fd126 100644 --- a/hzims-service/equipment/src/main/java/com/hnac/hzims/fdp/scheduled/ThreadTask.java +++ b/hzims-service/equipment/src/main/java/com/hnac/hzims/fdp/scheduled/ThreadTask.java @@ -208,7 +208,7 @@ public class ThreadTask { diagnoseFaultReq.setTaskId(req.getId().toString()); diagnoseFaultReq.setFaultId(req.getFaultId()); diagnoseFaultReq.setConfidence(1.0); - diagnoseFaultReq.setLifeTime(1); + diagnoseFaultReq.setLifeTime(24*3);//设置有效期3天 diagnoseFaultReq.setPriority(2); diagnoseFaultReq.setTenantId(fdpFaultEntity.getStationId()); diagnoseFaultReq.setCreateUser(ObjectUtil.isEmpty(AuthUtil.getUser()) ? "告警推送" : AuthUtil.getUser().getUserName()); 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 3f18288..6282543 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 @@ -31,5 +31,5 @@ public interface IFdpTaskService extends BaseService { R getTaskStatistics(TaskStatisticsVo statisticsVo); - R getTaskData(TaskStatisticsVo statisticsVo); + R getTaskData(TaskStatisticsVo statisticsVo,Query query); } diff --git a/hzims-service/equipment/src/main/java/com/hnac/hzims/fdp/service/impl/FdpMonitorServiceImpl.java b/hzims-service/equipment/src/main/java/com/hnac/hzims/fdp/service/impl/FdpMonitorServiceImpl.java index 718e538..b97663e 100644 --- a/hzims-service/equipment/src/main/java/com/hnac/hzims/fdp/service/impl/FdpMonitorServiceImpl.java +++ b/hzims-service/equipment/src/main/java/com/hnac/hzims/fdp/service/impl/FdpMonitorServiceImpl.java @@ -76,6 +76,7 @@ import java.text.SimpleDateFormat; import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; import java.util.*; +import java.util.concurrent.TimeUnit; import java.util.stream.Collectors; /** @@ -85,174 +86,174 @@ import java.util.stream.Collectors; @Service @RequiredArgsConstructor public class FdpMonitorServiceImpl extends BaseServiceImpl implements IFdpMonitorService { - private final FdpDeviceMapper fdpDeviceMapper; - private final IEmInfoService emInfoService; - private final IAnalyseInstanceClient deviceInstanceClient; - private final IAnalyseInstanceClient analyseInstanceClient; - private final IRealDataSearchClient realDataSearchClient; - private final IAnalyseDataSearchClient deviceDataSearchClient; - private final IFdpTaskService fdpTaskService; - private final IDiagnoseProxy diagnoseProxy; - private final FdpMonitorNoScopeMapper fdpMonitorNoScopeMapper; - private final IStationClient stationClient; - private final IFdpFaultService fdpFaultService; - private final RedisTemplate redisTemplate; - - @Value("${url.listAll}") - public String atalsPath; - - @Value(value = "${url.getMonitorFault}") - private String getMonitorFaultUrl; - - @Value(value = "${fdp.monitor.rateRange}") - private float rateRange; - - @Value(value = "${fdp.tenantId}") - private String tenantId; - @Value("${url.updateFaultState_Auto}") - public String pushPath; - @Value("${url.updateFaultState_All}") - public String updateFaultStateAll; - - @Value("${url.getRealByFault}") - public String getRealByFault; - - @Value("${hzims.equipment.fdp.fdpReturnValuePath}") - public String fdpReturnValuePath; - - @Value("${url.getAutoFault}") - public String autoFaultPath; - - @Value("${url.updateFaultState}") - public String updateFaultState; - - private final static String JOINT_RELAY_SIGNAGE = "joint_relay";//合位继电器 - - - @Override - public List getMonitorBanding() { - return this.baseMapper.getMonitorBanding(); - } - - @Override - public R doSave(FdpMonitorDTO req) { - return R.status(super.save(req)); - } - - @Override - public R detail(Long id) { - FdpMonitorEntity detail = super.getById(id); - return R.data(FdpMonitorWrapper.build().entityVO(detail)); - } - - @Override - public R> list(FdpMonitorDTO req, Query query) { - Wrapper queryWrapper = new LambdaQueryWrapper() {{ - orderByDesc(FdpMonitorEntity::getId); - //name,fdpId,emId,monitorStyle,fdpDeviceId,fdpDeviceName,callbackType - if (StringUtil.isNotBlank(req.getName())) { - like(FdpMonitorEntity::getName, req.getName()); - } - if (StringUtil.isNotBlank(req.getFdpId())) { - eq(FdpMonitorEntity::getFdpId, req.getFdpId()); - } - if (StringUtil.isNotBlank(req.getEmCode())) { - eq(FdpMonitorEntity::getEmCode, req.getEmCode()); - } - if (StringUtil.isNotBlank(req.getMonitorStyle())) { - eq(FdpMonitorEntity::getMonitorStyle, req.getMonitorStyle()); - } - if (StringUtil.isNotBlank(req.getFdpDeviceId())) { - eq(FdpMonitorEntity::getFdpDeviceId, req.getFdpDeviceId()); - } - if (StringUtil.isNotBlank(req.getFdpDeviceName())) { - like(FdpMonitorEntity::getFdpDeviceName, req.getFdpDeviceName()); - } - if (StringUtil.isNotBlank(req.getCallbackType())) { - eq(FdpMonitorEntity::getCallbackType, req.getCallbackType()); - } - }}; - - IPage pages = super.page(Condition.getPage(query), queryWrapper); - pages.setRecords(FdpMonitorWrapper.build().listVO(pages.getRecords())); - return R.data(pages); - } - - @Override - public R> listTree(IPage page, FdpDeviceEntity entity) { - //List fdpDeviceEntityList = fdpDeviceMapper.selectAll();//查询智能诊断所以设备 - IPage fdpDeviceEntityIPage = fdpDeviceMapper.selectPage(page, new LambdaQueryWrapper() {{ - if (StringUtil.isNotBlank(entity.getEmCode())) { - eq(FdpDeviceEntity::getEmCode, entity.getEmCode()); - } - if (StringUtil.isNotBlank(entity.getFdpId())) { - eq(FdpDeviceEntity::getFdpId, entity.getFdpId()); - } - if (StringUtil.isNotBlank(entity.getName())) { - like(FdpDeviceEntity::getName, entity.getName()); - } - if (StringUtil.isNotBlank(entity.getOrd())) { - like(FdpDeviceEntity::getOrd, entity.getOrd()); - } - if (null != entity.getCreateDept()) { - eq(FdpDeviceEntity::getCreateDept, entity.getCreateDept()); - } - }}); - List fdpMonitorEntityList = this.baseMapper.selectListAll();//查询智能诊断所以监测点 - for (FdpDeviceEntity fdpDeviceEntity : fdpDeviceEntityIPage.getRecords()) { - List list = new ArrayList<>(); - List data = new ArrayList<>(); - - if (StringUtil.isNotBlank(fdpDeviceEntity.getEmCode())) { - try { - data = analyseInstanceClient.getInstanceFieldByAnalyseCode(fdpDeviceEntity.getEmCode(), 1, null).getData(); - } catch (Exception e) { - log.error(e.getMessage()); - } - } - for (FdpMonitorEntity fdpMonitorEntity : fdpMonitorEntityList) { - if (fdpDeviceEntity.getFdpId().equals(fdpMonitorEntity.getFdpDeviceId())) { - if (CollectionUtil.isNotEmpty(data) && StringUtil.isNotBlank(fdpMonitorEntity.getImsSignages())) { - String realNames = ""; - int count = 0; - for (String signage : fdpMonitorEntity.getImsSignages().split(",")) { - for (AnalyzeInstanceFieldVO datum : data) { - if (signage.equals(datum.getSignage())) { - if (count == 0) { - realNames = datum.getName(); - } else { - realNames += "," + datum.getName(); - } - count++; - } - } - } - fdpMonitorEntity.setRealNames(realNames); - } - list.add(fdpMonitorEntity); - } - } - fdpDeviceEntity.setMonitors(list); - } - - return R.data(fdpDeviceEntityIPage); - } - - @Override - public R> listPage(IPage page, FdpMonitorEntity entity) { - List fdpMonitorEntityList = this.baseMapper.selectListPage(page, entity); - if (fdpMonitorEntityList.size() > 0) { - fdpMonitorEntityList.forEach(o -> { - if ("bool".equals(o.getCallbackType())) { - o.setCallbackType("单点遥信"); - } else if ("bool[]".equals(o.getCallbackType())) { - o.setCallbackType("多点遥信"); - } else if ("float".equals(o.getCallbackType())) { - o.setCallbackType("单点遥测"); - } else if ("float[]".equals(o.getCallbackType())) { - o.setCallbackType("多点遥测"); - } - }); + private final FdpDeviceMapper fdpDeviceMapper; + private final IEmInfoService emInfoService; + private final IAnalyseInstanceClient deviceInstanceClient; + private final IAnalyseInstanceClient analyseInstanceClient; + private final IRealDataSearchClient realDataSearchClient; + private final IAnalyseDataSearchClient deviceDataSearchClient; + private final IFdpTaskService fdpTaskService; + private final IDiagnoseProxy diagnoseProxy; + private final FdpMonitorNoScopeMapper fdpMonitorNoScopeMapper; + private final IStationClient stationClient; + private final IFdpFaultService fdpFaultService; + private final RedisTemplate redisTemplate; + + @Value("${url.listAll}") + public String atalsPath; + + @Value(value = "${url.getMonitorFault}") + private String getMonitorFaultUrl; + + @Value(value = "${fdp.monitor.rateRange}") + private float rateRange; + + @Value(value = "${fdp.tenantId}") + private String tenantId; + @Value("${url.updateFaultState_Auto}") + public String pushPath; + @Value("${url.updateFaultState_All}") + public String updateFaultStateAll; + + @Value("${url.getRealByFault}") + public String getRealByFault; + + @Value("${hzims.equipment.fdp.fdpReturnValuePath}") + public String fdpReturnValuePath; + + @Value("${url.getAutoFault}") + public String autoFaultPath; + + @Value("${url.updateFaultState}") + public String updateFaultState; + + private final static String JOINT_RELAY_SIGNAGE = "joint_relay";//合位继电器 + private final static String KEY_FOR_FDP_TASK_ID = "fdp_task_id";//redis保存key + + @Override + public List getMonitorBanding() { + return this.baseMapper.getMonitorBanding(); + } + + @Override + public R doSave(FdpMonitorDTO req) { + return R.status(super.save(req)); + } + + @Override + public R detail(Long id) { + FdpMonitorEntity detail = super.getById(id); + return R.data(FdpMonitorWrapper.build().entityVO(detail)); + } + + @Override + public R> list(FdpMonitorDTO req, Query query) { + Wrapper queryWrapper = new LambdaQueryWrapper() {{ + orderByDesc(FdpMonitorEntity::getId); + //name,fdpId,emId,monitorStyle,fdpDeviceId,fdpDeviceName,callbackType + if (StringUtil.isNotBlank(req.getName())) { + like(FdpMonitorEntity::getName, req.getName()); + } + if (StringUtil.isNotBlank(req.getFdpId())) { + eq(FdpMonitorEntity::getFdpId, req.getFdpId()); + } + if (StringUtil.isNotBlank(req.getEmCode())) { + eq(FdpMonitorEntity::getEmCode, req.getEmCode()); + } + if (StringUtil.isNotBlank(req.getMonitorStyle())) { + eq(FdpMonitorEntity::getMonitorStyle, req.getMonitorStyle()); + } + if (StringUtil.isNotBlank(req.getFdpDeviceId())) { + eq(FdpMonitorEntity::getFdpDeviceId, req.getFdpDeviceId()); + } + if (StringUtil.isNotBlank(req.getFdpDeviceName())) { + like(FdpMonitorEntity::getFdpDeviceName, req.getFdpDeviceName()); + } + if (StringUtil.isNotBlank(req.getCallbackType())) { + eq(FdpMonitorEntity::getCallbackType, req.getCallbackType()); + } + }}; + + IPage pages = super.page(Condition.getPage(query), queryWrapper); + pages.setRecords(FdpMonitorWrapper.build().listVO(pages.getRecords())); + return R.data(pages); + } + + @Override + public R> listTree(IPage page, FdpDeviceEntity entity) { + //List fdpDeviceEntityList = fdpDeviceMapper.selectAll();//查询智能诊断所以设备 + IPage fdpDeviceEntityIPage = fdpDeviceMapper.selectPage(page, new LambdaQueryWrapper() {{ + if (StringUtil.isNotBlank(entity.getEmCode())) { + eq(FdpDeviceEntity::getEmCode, entity.getEmCode()); + } + if (StringUtil.isNotBlank(entity.getFdpId())) { + eq(FdpDeviceEntity::getFdpId, entity.getFdpId()); + } + if (StringUtil.isNotBlank(entity.getName())) { + like(FdpDeviceEntity::getName, entity.getName()); + } + if (StringUtil.isNotBlank(entity.getOrd())) { + like(FdpDeviceEntity::getOrd, entity.getOrd()); + } + if (null != entity.getCreateDept()) { + eq(FdpDeviceEntity::getCreateDept, entity.getCreateDept()); + } + }}); + List fdpMonitorEntityList = this.baseMapper.selectListAll();//查询智能诊断所以监测点 + for (FdpDeviceEntity fdpDeviceEntity : fdpDeviceEntityIPage.getRecords()) { + List list = new ArrayList<>(); + List data = new ArrayList<>(); + + if (StringUtil.isNotBlank(fdpDeviceEntity.getEmCode())) { + try { + data = analyseInstanceClient.getInstanceFieldByAnalyseCode(fdpDeviceEntity.getEmCode(), 1, null).getData(); + } catch (Exception e) { + log.error(e.getMessage()); + } + } + for (FdpMonitorEntity fdpMonitorEntity : fdpMonitorEntityList) { + if (fdpDeviceEntity.getFdpId().equals(fdpMonitorEntity.getFdpDeviceId())) { + if (CollectionUtil.isNotEmpty(data) && StringUtil.isNotBlank(fdpMonitorEntity.getImsSignages())) { + String realNames = ""; + int count = 0; + for (String signage : fdpMonitorEntity.getImsSignages().split(",")) { + for (AnalyzeInstanceFieldVO datum : data) { + if (signage.equals(datum.getSignage())) { + if (count == 0) { + realNames = datum.getName(); + } else { + realNames += "," + datum.getName(); + } + count++; + } + } + } + fdpMonitorEntity.setRealNames(realNames); + } + list.add(fdpMonitorEntity); + } + } + fdpDeviceEntity.setMonitors(list); + } + + return R.data(fdpDeviceEntityIPage); + } + + @Override + public R> listPage(IPage page, FdpMonitorEntity entity) { + List fdpMonitorEntityList = this.baseMapper.selectListPage(page, entity); + if (fdpMonitorEntityList.size() > 0) { + fdpMonitorEntityList.forEach(o -> { + if ("bool".equals(o.getCallbackType())) { + o.setCallbackType("单点遥信"); + } else if ("bool[]".equals(o.getCallbackType())) { + o.setCallbackType("多点遥信"); + } else if ("float".equals(o.getCallbackType())) { + o.setCallbackType("单点遥测"); + } else if ("float[]".equals(o.getCallbackType())) { + o.setCallbackType("多点遥测"); + } + }); // Set instanceDeviceCodeList = fdpMonitorEntityList.stream().filter(x -> x.getInstanceDeviceCode() != null).map(o -> o.getInstanceDeviceCode()).collect(Collectors.toSet()); // List data = new ArrayList<>(); @@ -279,9 +280,9 @@ public class FdpMonitorServiceImpl extends BaseServiceImpl list(FdpMonitorDTO req) { - LambdaQueryWrapper qw = Wrappers.lambdaQuery(); - if(CollectionUtil.isNotEmpty(req.getMonitorIds())) { - qw.in(FdpMonitorEntity::getFdpId,req.getMonitorIds()); - } - return this.list(qw); - } - - - /** - * 历史数据推送 - * - * @return - */ - @Override - public List getHistoryData(List fdpMonitorEntityList) { - List listMap = new ArrayList<>(); - List list = fdpMonitorEntityList.stream().filter(s -> s.getCallbackHistoryType() != null).collect(Collectors.toList()); - Date date = new Date(); - if (CollectionUtil.isNotEmpty(list)) { - Map> valueMap = new HashMap<>(); - Map> collectMap = list.stream().collect(Collectors.groupingBy(FdpMonitorEntity::getInstanceDeviceCode)); - for (String codeKey : collectMap.keySet()) { - List fdpMonitorEntityList1 = collectMap.get(codeKey); - fdpMonitorEntityList1.get(0).getInstanceDeviceCode(); - valueMap.putAll(this.getHisKeyValueDataPartition(fdpMonitorEntityList1, date, fdpMonitorEntityList1.get(0).getInstanceDeviceCode())); - } - for (FdpMonitorEntity fdpMonitorEntity : list) { - FdpHisDataVo vo = new FdpHisDataVo(); - vo.setId(fdpMonitorEntity.getFdpId()); - vo.setName(fdpMonitorEntity.getName()); - vo.setOrd(fdpMonitorEntity.getOrd()); - vo.setData(valueMap.get(fdpMonitorEntity.getFdpId())); - listMap.add(vo); - } - } - return listMap; - } - - /** - * 历史数据数据追溯 - * - * @return - */ - public List> getHistoryDataBack(List fdpMonitorEntityList, String faultId) { - List> listMap = new ArrayList<>(); - Date date = new Date(); - List list = fdpMonitorEntityList.stream().filter(o -> null != o.getCallbackHistoryType()).collect(Collectors.toList()); - if (CollectionUtil.isNotEmpty(list)) { - for (FdpMonitorEntity fdpMonitorEntity : list) { - Map map = new HashMap<>(); - map.put("id", fdpMonitorEntity.getFdpId()); - map.put("name", fdpMonitorEntity.getName()); - map.put("ord", fdpMonitorEntity.getOrd()); - map.put("data", this.getHisKeyValueDataBack(fdpMonitorEntity, date, faultId)); - listMap.add(map); - } - } - return listMap; - } - - /** - * 历史数据数据追溯 - * - * @return - */ - public List> getHistoryMonthlyDataBack(List fdpMonitorEntityList, String faultId, LocalDateTime beginTime, LocalDateTime endTime) { - List> listMap = new ArrayList<>(); - List list = fdpMonitorEntityList.stream().filter(o -> null != o.getCallbackHistoryType()).collect(Collectors.toList()); - if (CollectionUtil.isNotEmpty(list)) { - for (FdpMonitorEntity fdpMonitorEntity : list) { - Map map = new HashMap<>(); - map.put("id", fdpMonitorEntity.getFdpId()); - map.put("name", fdpMonitorEntity.getName()); - map.put("ord", fdpMonitorEntity.getOrd()); - map.put("data", this.getHisKeyValueMonthlyDataBack(fdpMonitorEntity, faultId, beginTime, endTime)); - listMap.add(map); - } - } - return listMap; - } - - - @Override - public List getFdpMonitorList(List stationIdList, List fdpDeviceCodeList) { - List fdpMonitorEntityRealTimeList = this.baseMapper.getFdpMonitorEntityRealTimeList(null, null, null, stationIdList, fdpDeviceCodeList); - return fdpMonitorEntityRealTimeList; - } - - @Override - public R updateFaultStateAll(FdpTaskDTO taskDTO) { - if (StringUtil.isEmpty(taskDTO.getFaultId())) { - return R.fail("未传入faultId参数"); - } - /**获取故障对象**/ - LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); - wrapper.eq(FdpFaultEntity::getFdpId, taskDTO.getFaultId()).last("limit 1"); - FdpFaultEntity fdpFaultEntity = fdpFaultService.getOne(wrapper); - if (ObjectUtil.isEmpty(fdpFaultEntity)) { - throw new ServiceException("获取对应故障对象失败"); - } - /**如果realId不为null 则为综合监控调用接口**/ - if (StringUtil.isNotBlank(taskDTO.getRealId())) { - String realId = taskDTO.getRealId(); - /**推送数据**/ - R mapR = this.dataPushByRealId(realId, null); - if (mapR.isSuccess() && ObjectUtil.isNotEmpty(mapR.getData())) { - /**更新故障状态**/ - DiagnoseFaultAllReq faultAllReq = new DiagnoseFaultAllReq(); - - faultAllReq.setAutoData(mapR.getData()); - return dianogse(taskDTO, faultAllReq, fdpFaultEntity, null); - } - return mapR; - } - /**如果realId为空 fdpId不为空 则为智能诊断手动调用接口**/ - else { - /**推送数据**/ - FdpRealTimeAndHisDataVo pushResp = this.dataPushByPartition(fdpFaultEntity.getFdpPartition(), fdpFaultEntity.getCreateDept()); - /**更新故障状态**/ - DiagnoseFaultAllReq faultAllReq = new DiagnoseFaultAllReq(); - faultAllReq.setAutoData(pushResp); - return dianogse(taskDTO, faultAllReq, fdpFaultEntity, "1"); - } - } + @Override + public List list(FdpMonitorDTO req) { + LambdaQueryWrapper qw = Wrappers.lambdaQuery(); + if (CollectionUtil.isNotEmpty(req.getMonitorIds())) { + qw.in(FdpMonitorEntity::getFdpId, req.getMonitorIds()); + } + return this.list(qw); + } + + + /** + * 历史数据推送 + * + * @return + */ + @Override + public List getHistoryData(List fdpMonitorEntityList) { + List listMap = new ArrayList<>(); + List list = fdpMonitorEntityList.stream().filter(s -> s.getCallbackHistoryType() != null).collect(Collectors.toList()); + Date date = new Date(); + if (CollectionUtil.isNotEmpty(list)) { + Map> valueMap = new HashMap<>(); + Map> collectMap = list.stream().collect(Collectors.groupingBy(FdpMonitorEntity::getInstanceDeviceCode)); + for (String codeKey : collectMap.keySet()) { + List fdpMonitorEntityList1 = collectMap.get(codeKey); + fdpMonitorEntityList1.get(0).getInstanceDeviceCode(); + valueMap.putAll(this.getHisKeyValueDataPartition(fdpMonitorEntityList1, date, fdpMonitorEntityList1.get(0).getInstanceDeviceCode())); + } + for (FdpMonitorEntity fdpMonitorEntity : list) { + FdpHisDataVo vo = new FdpHisDataVo(); + vo.setId(fdpMonitorEntity.getFdpId()); + vo.setName(fdpMonitorEntity.getName()); + vo.setOrd(fdpMonitorEntity.getOrd()); + vo.setData(valueMap.get(fdpMonitorEntity.getFdpId())); + listMap.add(vo); + } + } + return listMap; + } + + /** + * 历史数据数据追溯 + * + * @return + */ + public List> getHistoryDataBack(List fdpMonitorEntityList, String faultId) { + List> listMap = new ArrayList<>(); + Date date = new Date(); + List list = fdpMonitorEntityList.stream().filter(o -> null != o.getCallbackHistoryType()).collect(Collectors.toList()); + if (CollectionUtil.isNotEmpty(list)) { + for (FdpMonitorEntity fdpMonitorEntity : list) { + Map map = new HashMap<>(); + map.put("id", fdpMonitorEntity.getFdpId()); + map.put("name", fdpMonitorEntity.getName()); + map.put("ord", fdpMonitorEntity.getOrd()); + map.put("data", this.getHisKeyValueDataBack(fdpMonitorEntity, date, faultId)); + listMap.add(map); + } + } + return listMap; + } + + /** + * 历史数据数据追溯 + * + * @return + */ + public List> getHistoryMonthlyDataBack(List fdpMonitorEntityList, String faultId, LocalDateTime beginTime, LocalDateTime endTime) { + List> listMap = new ArrayList<>(); + List list = fdpMonitorEntityList.stream().filter(o -> null != o.getCallbackHistoryType()).collect(Collectors.toList()); + if (CollectionUtil.isNotEmpty(list)) { + for (FdpMonitorEntity fdpMonitorEntity : list) { + Map map = new HashMap<>(); + map.put("id", fdpMonitorEntity.getFdpId()); + map.put("name", fdpMonitorEntity.getName()); + map.put("ord", fdpMonitorEntity.getOrd()); + map.put("data", this.getHisKeyValueMonthlyDataBack(fdpMonitorEntity, faultId, beginTime, endTime)); + listMap.add(map); + } + } + return listMap; + } + + + @Override + public List getFdpMonitorList(List stationIdList, List fdpDeviceCodeList) { + List fdpMonitorEntityRealTimeList = this.baseMapper.getFdpMonitorEntityRealTimeList(null, null, null, stationIdList, fdpDeviceCodeList); + return fdpMonitorEntityRealTimeList; + } + + @Override + public R updateFaultStateAll(FdpTaskDTO taskDTO) { + if (StringUtil.isEmpty(taskDTO.getFaultId())) { + return R.fail("未传入faultId参数"); + } + /**获取故障对象**/ + LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); + wrapper.eq(FdpFaultEntity::getFdpId, taskDTO.getFaultId()).last("limit 1"); + FdpFaultEntity fdpFaultEntity = fdpFaultService.getOne(wrapper); + if (ObjectUtil.isEmpty(fdpFaultEntity)) { + throw new ServiceException("获取对应故障对象失败"); + } + /**如果realId不为null 则为综合监控调用接口**/ + if (StringUtil.isNotBlank(taskDTO.getRealId())) { + String realId = taskDTO.getRealId(); + /**推送数据**/ + R mapR = this.dataPushByRealId(realId, null); + if (mapR.isSuccess() && ObjectUtil.isNotEmpty(mapR.getData())) { + /**更新故障状态**/ + DiagnoseFaultAllReq faultAllReq = new DiagnoseFaultAllReq(); + + faultAllReq.setAutoData(mapR.getData()); + return dianogse(taskDTO, faultAllReq, fdpFaultEntity, null); + } + return mapR; + } + /**如果realId为空 fdpId不为空 则为智能诊断手动调用接口**/ + else { + /**推送数据**/ + FdpRealTimeAndHisDataVo pushResp = this.dataPushByPartition(fdpFaultEntity.getFdpPartition(), fdpFaultEntity.getCreateDept()); + /**更新故障状态**/ + DiagnoseFaultAllReq faultAllReq = new DiagnoseFaultAllReq(); + faultAllReq.setAutoData(pushResp); + return dianogse(taskDTO, faultAllReq, fdpFaultEntity, "1"); + } + } // @Override // public R getRealTimeHisData(FdpTaskDTO taskDTO) { @@ -449,1611 +450,1655 @@ public class FdpMonitorServiceImpl extends BaseServiceImpl wrapper = new LambdaQueryWrapper<>(); - wrapper.eq(FdpFaultEntity::getFdpId, taskDTO.getFaultId()).last("limit 1"); - FdpFaultEntity fdpFaultEntity = fdpFaultService.getOne(wrapper); - if (ObjectUtil.isEmpty(fdpFaultEntity)) { - throw new ServiceException("获取对应故障对象失败"); - } + @Override + public R getRealTimeHisDataNew(FdpTaskDTO taskDTO) { + /**获取故障对象**/ + LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); + wrapper.eq(FdpFaultEntity::getFdpId, taskDTO.getFaultId()).last("limit 1"); + FdpFaultEntity fdpFaultEntity = fdpFaultService.getOne(wrapper); + if (ObjectUtil.isEmpty(fdpFaultEntity)) { + throw new ServiceException("获取对应故障对象失败"); + } // /**获取实时、历史数据**/ // FdpRealTimeAndHisDataVo pushResp = this.dataPushByPartition(fdpFaultEntity.getFdpPartition(), fdpFaultEntity.getCreateDept()); // String key = UUID.randomUUID().toString(); - boolean flag = fdpTaskService.save(taskDTO); - if (!flag) { - return R.fail("诊断任务保存失败"); - } - String key = taskDTO.getId().toString(); + //拿到最近一次未完成的任务 + FdpTaskEntity fdpTaskEntity = fdpTaskService.getOne(new LambdaQueryWrapper() {{ + eq(FdpTaskEntity::getFaultId, taskDTO.getFaultId()); + eq(FdpTaskEntity::getIsDeleted, 0); + in(FdpTaskEntity::getStatus, 1, 2);//未开始或者未完成 + orderByDesc(FdpTaskEntity::getCreateTime); + last("limit 1"); + }}); + String key; + if (Func.isNotEmpty(fdpTaskEntity)) { + Boolean hasKey = redisTemplate.hasKey(KEY_FOR_FDP_TASK_ID + "_" + fdpTaskEntity.getId().toString()); + //Redis中存在,该任务没过期。用该任务Id + if (hasKey) { + key = fdpTaskEntity.getId().toString(); + } else { + //该任务过期,更改状态为过期,新增一个任务 + fdpTaskEntity.setStatus(4); + fdpTaskService.updateById(fdpTaskEntity); + boolean flag = fdpTaskService.save(taskDTO); + if (!flag) { + return R.fail("诊断任务保存失败"); + } + key = taskDTO.getId().toString(); + redisTemplate.opsForValue().set(KEY_FOR_FDP_TASK_ID + "_" + key, key); + Boolean expire = redisTemplate.expire(KEY_FOR_FDP_TASK_ID + "_" + key,3, TimeUnit.DAYS); + System.out.println(expire); + } + } else { + //没有未完成的任务,新增一个任务 + boolean flag = fdpTaskService.save(taskDTO); + if (!flag) { + return R.fail("诊断任务保存失败"); + } + key = taskDTO.getId().toString(); + redisTemplate.opsForValue().set(KEY_FOR_FDP_TASK_ID + "_" + key, key); + redisTemplate.expire(KEY_FOR_FDP_TASK_ID + "_" + key, 3, TimeUnit.DAYS); + } // //异步处理 20230426 此接口弃用 - ThreadTask.fdpTaskNew(taskDTO, fdpFaultEntity, key); - //获取数据成功-》 告知前端 - Map map = new HashMap<>(); - map.put("id", key); - return R.data(map); - } - - @Override - public R getNextstepData(String id) { - Object o = redisTemplate.opsForValue().get(fdpReturnValuePath + "_" + id); - if (ObjectUtil.isNotEmpty(o)) { - R r = JSONObject.parseObject(o.toString(), new TypeReference() {{}}); - return r; - } - return R.data("-1"); - } - - - @Override - public R updateFaultState(DiagnoseFaultReq diagnoseFaultReq) { - diagnoseFaultReq.setPriority(2); - /**获取故障对象**/ - LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); - wrapper.eq(FdpFaultEntity::getFdpId, diagnoseFaultReq.getFaultId()).last("limit 1"); - FdpFaultEntity fdpFaultEntity = fdpFaultService.getOne(wrapper); - if (ObjectUtil.isEmpty(fdpFaultEntity)) { - throw new ServiceException("获取对应故障对象失败"); - } - /**推送数据**/ - FdpRealTimeAndHisDataVo pushResp = this.dataPushByPartition(fdpFaultEntity.getFdpPartition(), fdpFaultEntity.getCreateDept()); - /**更新故障状态**/ - DiagnoseFaultAllReq faultAllReq = new DiagnoseFaultAllReq(); - faultAllReq.setAutoData(pushResp); - - faultAllReq.setStationId(fdpFaultEntity.getStationId()); - diagnoseFaultReq.setTenantId(fdpFaultEntity.getStationId()); - faultAllReq.setManualData(diagnoseFaultReq); - String jsonString = JSONObject.toJSONString(faultAllReq); - System.out.println(jsonString); - HttpResponse r = HttpClientUtils.post(updateFaultStateAll, JSONObject.toJSONString(faultAllReq)); - return JSONObject.parseObject(r.getData(), BaseResp.class).convert2R(); - } - - - @Override - public List getAll() { - return this.baseMapper.selectAll(); - } - - @Override - public List getRealIds() { - return this.baseMapper.getRealIds(); - } - - @Override - public String getFaultList() { - List list = this.baseMapper.selectStationIds(); - if(CollectionUtil.isEmpty(list)){ - return null; - } - Map paramMap = new HashMap<>(); - paramMap.put("stationIds", list.toArray(new String[0])); - String result = HttpRequestUtil.postCall(paramMap, autoFaultPath, "POST"); - if(StringUtil.isBlank(result)){ - return null; - } - return JSONObject.parseObject(result).get("data").toString(); - } - - @Override - public String updateFaultState(UpdateFaultStateVo state) { - Map paramMap = new HashMap<>(); - // 站点ID - paramMap.put("stationId", state.getStationId()); - // 故障ID - paramMap.put("faultId", state.getFaultId()); - // 故障的置信度 : 发生为1,不发生为0。 - paramMap.put("confidence", state.getConfidence()); - // 时间字符串 - paramMap.put("createTime", state.getCreateTime()); - // 创建人 - paramMap.put("createUser", state.getCreateUser()); - // 单位小时,默认值为1 - paramMap.put("lifeTime", state.getLifeTime()); - // 优先级 - paramMap.put("priority", state.getPriority()); - // 描述 - paramMap.put("info", state.getInfo()); - String result = HttpRequestUtil.postCall(paramMap, autoFaultPath, "POST"); - if(StringUtil.isBlank(result)){ - return null; - } - return JSONObject.parseObject(result).get("data").toString(); - } - - /*** - * - * @param req - * @param faultAllReq - * @param fdpFaultEntity - * @param type 1:推送;2:不推送 - * @return - */ - public R dianogse(FdpTaskDTO req, DiagnoseFaultAllReq faultAllReq, FdpFaultEntity fdpFaultEntity, String type) { - req.setFdpDeviceName(fdpFaultEntity.getFdpDeviceName()); - req.setFdpOrd(fdpFaultEntity.getOrd()); - req.setName(fdpFaultEntity.getName()); - boolean flag = fdpTaskService.save(req); - if (!flag) { - return R.fail("诊断任务保存失败"); - } - /**推送故障状态**/ - faultAllReq.setStationId(fdpFaultEntity.getStationId()); - - if ("1".equals(type)) { - DiagnoseFaultReq diagnoseFaultReq = new DiagnoseFaultReq(); - diagnoseFaultReq.setTaskId(req.getId().toString()); - log.info("存入taskId为:{}", req.getId().toString()); - diagnoseFaultReq.setFaultId(req.getFaultId()); - diagnoseFaultReq.setConfidence(1.0); - diagnoseFaultReq.setLifeTime(1); - diagnoseFaultReq.setPriority(2); - diagnoseFaultReq.setTenantId(fdpFaultEntity.getStationId()); - diagnoseFaultReq.setCreateUser(ObjectUtil.isEmpty(AuthUtil.getUser()) ? "告警推送" : AuthUtil.getUser().getUserName()); - faultAllReq.setManualData(diagnoseFaultReq); - } - - log.info("---智能诊断推送对象为:{}---", JSONObject.toJSONString(faultAllReq)); - HttpClientUtils.post(updateFaultStateAll, JSONObject.toJSONString(faultAllReq)); - //JSONObject.parseObject(r.getData(), BaseResp.class).convert2R(); - return R.data(req.getId()); - } - - /** - * 监测点绑定 - * - * @param req - * @return - */ - @Override - public R doSetCycle(FdpMonitorEntity req) { - FdpMonitorEntity entity = this.getOne(new LambdaQueryWrapper() {{ - eq(FdpMonitorEntity::getFdpId, req.getFdpId()).last(" LIMIT 1"); - }}); - if (req.getImsRealIds().split(",").length > 1 && ("bool".equals(entity.getCallbackType()) || "float".equals(entity.getCallbackType()))) { - String name = ""; - if ("bool".equals(entity.getCallbackType())) { - name = "单点遥信"; - } else if ("float".equals(entity.getCallbackType())) { - name = "单点遥测"; - } - return R.fail("该数据格式为:" + name + ",故该值最多绑定一个"); - } - return R.status(this.update(req, new LambdaQueryWrapper() {{ - eq(FdpMonitorEntity::getFdpId, req.getFdpId()); - }})); - } - - @Override - @Transactional - public R bindingBatch(List monitorBindingDTOList) { - /**监测点批量绑定**/ - List fdpMonitorEntityList = monitorBindingDTOList.stream().map(FdpMonitorBindingDTO::getMonitorEntity).collect(Collectors.toList()); - boolean flag = this.updateBatchById(fdpMonitorEntityList); - if (flag) { - throw new ServiceException("监测点批量绑定失败"); - } - /**数据平台接口批量更新接口调用**/ - List fieldVOList = monitorBindingDTOList.stream().map(FdpMonitorBindingDTO::getAnalyzeInstanceFieldVO).collect(Collectors.toList()); - - return R.success("绑定成功!"); - } - - /** - * 监测点绑定列表 - * - * @param entity - * @return - */ - @Override - public List doBindingList(FdpMonitorEntity entity) { - FdpMonitorEntity fdpMonitorEntity = this.baseMapper.selectOne(new LambdaQueryWrapper() {{ - eq(FdpMonitorEntity::getFdpId, entity.getFdpId()); - }}); - List list = new ArrayList<>(); - if (ObjectUtil.isNotEmpty(fdpMonitorEntity)) { - if (StringUtil.isNotBlank(fdpMonitorEntity.getImsSignages())) { - String[] signage = fdpMonitorEntity.getImsSignages().split(","); - EmInfoEntity emInfoEntity = emInfoService.getOne(new LambdaQueryWrapper() {{ - eq(EmInfoEntity::getNumber, entity.getEmCode()); - }}); - List data = analyseInstanceClient.getInstanceFieldByAnalyseCode(entity.getEmCode(), 1, null).getData(); - for (int i = 0; i < signage.length; i++) { - String realName = ""; - for (AnalyzeInstanceFieldVO analyzeInstanceFieldVO : data) { - if (analyzeInstanceFieldVO.getSignage().equals(signage[i])) { - realName = analyzeInstanceFieldVO.getName(); - continue; - } - } - FdpMonitorExtendDTO dto = new FdpMonitorExtendDTO(); - if (ObjectUtil.isNotEmpty(emInfoEntity)) { - dto.setEmName(emInfoEntity.getName()); - } - dto.setRealName(realName); - dto.setSignage(signage[i]); - dto.setEmCode(entity.getEmCode()); - dto.setFdpId(fdpMonitorEntity.getFdpId()); - list.add(dto); - } - } - } - return list; - } - - /** - * 根据设备编号查询点 - * - * @param instanceDeviceCode - * @return - */ - @Override - public R> getInstanceFieldByDeviceCode(Long id, String instanceDeviceCode, String instanceFieldName) { - String signages = ""; - FdpMonitorVO fdpMonitorVO = this.baseMapper.selectSignagesById(id, instanceDeviceCode); - if (ObjectUtil.isNotEmpty(fdpMonitorVO) && StringUtil.isNotBlank(fdpMonitorVO.getSignages())) { - signages = fdpMonitorVO.getSignages(); - } - R> deviceFieldByAnalyseCode = analyseInstanceClient.getDeviceFieldByAnalyseCode(instanceDeviceCode, instanceFieldName); - if (deviceFieldByAnalyseCode.isSuccess() && CollectionUtil.isNotEmpty(deviceFieldByAnalyseCode.getData())) { - List data = deviceFieldByAnalyseCode.getData(); - if (CollectionUtil.isNotEmpty(data) && StringUtil.isNotBlank(signages)) { - List list = Arrays.asList(signages.split(",")); - Set signage = new HashSet<>(list); - data = data.stream().filter(o -> !signage.contains(o.getSignage()) && null != o.getFieldName()).collect(Collectors.toList()); - } - return R.data(data); - } - return R.data(Lists.newArrayList()); - } - - /** - * 获取图谱 -- 专家知识库 - * - * @return - */ - @Override - public R getAtlas() { - String result = HttpRequestUtil.postCall(null, atalsPath, "POST"); - //数据转换成map - HashMap stringObjectHashMap = JSONObject.parseObject(result, new TypeReference>() { - }); - Map data = MapUtils.getMap(stringObjectHashMap, "data"); - if (ObjectUtil.isEmpty(data)) { - return R.data(null); - } - return R.data(data); - } - - @Override - public Integer updateByFdpId(String fdpId) { - return this.baseMapper.updateByFdpId(fdpId); - } - - /** - * 根据RealId进行数据获取 - * - * @param realId - * @param stationId - * @return - */ - @Override - public R dataPushByRealId(String realId, String stationId) { - List fdpMonitorEntityList = this.baseMapper.selectMonitorByRealId(realId, stationId); - FdpRealTimeAndHisDataVo vo = new FdpRealTimeAndHisDataVo(); - vo.setStationId(stationId); - if (CollectionUtil.isNotEmpty(fdpMonitorEntityList)) { - //实时数据 - List realTimeDataPush = this.getRealTimeData(fdpMonitorEntityList); - //历史数据 - List historyDataPush = this.getHistoryData(fdpMonitorEntityList); - vo.setRealTimeData(realTimeDataPush); - vo.setHistoryData(historyDataPush); - log.info("dataPushByRealId 结果集{}:......................" + JSONObject.toJSONString(realTimeDataPush)); - } - if (CollectionUtil.isEmpty(fdpMonitorEntityList)) { - return R.fail("该监测点在智能诊断功能未进行数据绑定!"); - } - return R.data(vo); - } - - /** - * 根据RealId进行数据推送 - * - * @param realId - * @param stationId - * @return - */ - @Override - public R dataByRealIdPush(String realId, String stationId) { - List fdpMonitorEntityList = this.baseMapper.selectMonitorByRealId(realId, stationId); - FdpRealTimeAndHisDataVo vo = new FdpRealTimeAndHisDataVo(); - vo.setStationId(stationId); - if (CollectionUtil.isNotEmpty(fdpMonitorEntityList)) { - //实时数据 - List realTimeDataPush = this.getRealTimeData(fdpMonitorEntityList); - vo.setRealTimeData(realTimeDataPush); - //历史数据 - List historyDataPush = this.getHistoryData(fdpMonitorEntityList); - vo.setHistoryData(historyDataPush); - log.info("dataByRealIdPush 结果集{}:......................" + JSONObject.toJSONString(vo)); - HttpRequestUtil.postCallObjectParam(vo, pushPath, "POST"); - } - if (CollectionUtil.isEmpty(fdpMonitorEntityList)) { - return R.fail("该监测点在智能诊断功能未进行数据绑定!"); - } - return R.data(vo); - } - - /** - * 根据分区号进行实时数据推送 - * - * @param fdpPartition - * @param dept - * @return - */ - @Override - public FdpRealTimeAndHisDataVo dataPushByPartition(Long fdpPartition, Long dept) { - List fdpMonitorEntityList = this.baseMapper.selectMonitorByPartition(fdpPartition, dept); - FdpRealTimeAndHisDataVo vo = new FdpRealTimeAndHisDataVo(); - if (CollectionUtil.isNotEmpty(fdpMonitorEntityList)) { - //实时数据 - List realTimeDataPush = this.getRealTimeData(fdpMonitorEntityList); - //历史数据 - List historyDataPush = this.getHistoryData(fdpMonitorEntityList); - vo.setRealTimeData(realTimeDataPush); - vo.setHistoryData(historyDataPush); - log.info("dataPushByPartition 结果集{}:......................" + JSONObject.toJSONString(vo)); - //HttpRequestUtil.postCall(resultMap, pushPath, "POST"); - } - return vo; - } - @Override - public R dataBackV2(String faultId) { - Map resultMap = new HashMap<>(); - resultMap.put("faultId", faultId); - String post = HttpRequestUtil.postCallObjectParam(resultMap, getRealByFault, "POST"); - FdpHttpResponseVo fdpHttpResponseVo = JSONObject.parseObject(post, new TypeReference() {}); - if (1==fdpHttpResponseVo.getSuccess()) { - if (Func.isNotEmpty(fdpHttpResponseVo.getData())) { - List list = JSONObject.parseObject(fdpHttpResponseVo.getData(), new TypeReference>() {}); - if (CollectionUtil.isEmpty(list)){ - return R.success("暂无数据,请稍后重试"); - } - List res =new ArrayList<>(); - for (FdpFaultRealDataDTO fdpFaultRealDataDTO : list) { - if (null!=fdpFaultRealDataDTO.getReal()){ - for (int i = 0; i < fdpFaultRealDataDTO.getReal().size(); i++ ) { - FdpFaultRealDataVO dataVO=new FdpFaultRealDataVO(); - BeanUtils.copyProperties(fdpFaultRealDataDTO,dataVO); - dataVO.setReal(fdpFaultRealDataDTO.getReal().get(i)); - dataVO.setRealTime(fdpFaultRealDataDTO.getRealTime().get(i)); - dataVO.setRealName(fdpFaultRealDataDTO.getRealName().get(i)); - dataVO.setRealIdentifier(fdpFaultRealDataDTO.getRealIdentifier().get(i)); - res.add(dataVO); - } - }else { - FdpFaultRealDataVO dataVO=new FdpFaultRealDataVO(); - BeanUtils.copyProperties(fdpFaultRealDataDTO,dataVO); - res.add(dataVO); - } - } - return R.data(res); - } - return R.success("暂无数据,请稍后重试"); - } - return R.fail("智能诊断接口异常,请联系管理员"); - } - - - //此接口已经弃用20230628 - @Deprecated - @Override - public Map dataBack(String faultId) { - //根据故障ID查询监测点列表 - List fdpMonitorEntityList = this.baseMapper.selectByFaultId(faultId); - Map resultMap = new HashMap<>(); - resultMap.put("realTimeData", null); - resultMap.put("historyData", null); - if (ObjectUtil.isNotEmpty(fdpMonitorEntityList)) { - //实时数据 - List> realTimeDataPush = this.getRealTimeDataBack(fdpMonitorEntityList); - //历史数据 - List> historyDataPush = this.getHistoryDataBack(fdpMonitorEntityList, faultId); - resultMap.put("realTimeData", realTimeDataPush); - resultMap.put("historyData", historyDataPush); - } - return resultMap; - } - - /** - * 统计月报-数据追溯 - * - * @param vo - * @return - */ - @Override - public Map monthlyDataBack(DataBackVo vo) { - //根据故障ID查询监测点列表 - List fdpMonitorEntityList = this.baseMapper.selectByFaultId(vo.getFaultId()); - DateTimeFormatter df = DateTimeFormatter.ofPattern(DateUtil.PATTERN_DATETIME); - LocalDateTime beginTime = LocalDateTime.parse(DateUtils.minutlDate(DateUtil.parse(vo.getDate(), DateUtil.PATTERN_DATETIME), -5, DateUtil.PATTERN_DATETIME), df); - LocalDateTime endTime = LocalDateTime.parse(DateUtils.minutlDate(DateUtil.parse(vo.getDate(), DateUtil.PATTERN_DATETIME), 5, DateUtil.PATTERN_DATETIME), df); - Map resultMap = new HashMap<>(); - resultMap.put("historyData", null); - if (ObjectUtil.isNotEmpty(fdpMonitorEntityList)) { - //历史数据 - List> historyDataPush = this.getHistoryMonthlyDataBack(fdpMonitorEntityList, vo.getFaultId(), beginTime, endTime); - resultMap.put("historyData", historyDataPush); - } - return resultMap; - } - - @Override - @Transactional - public R diagnosisByMonitorIdAndStation(String realId, String stationId) { - /**推送数据**/ - R pushResult = this.dataByRealIdPush(realId, stationId); - if (!pushResult.isSuccess()) { - return R.fail(pushResult.getMsg()); - } - /**根据realid获取monitor对象**/ - FdpMonitorEntity monitorEntity = new FdpMonitorEntity(); - monitorEntity.setImsRealIds(realId); - FdpMonitorEntity fdpMonitorEntity = fdpMonitorNoScopeMapper.selectOne(Condition.getQueryWrapper(monitorEntity, FdpMonitorEntity.class).last("limit 1")); - /**从智能诊断获取monitorId**/ - if (ObjectUtil.isEmpty(fdpMonitorEntity)) { - return R.fail("获取智能诊断监测点失败"); - } - /**开始诊断**/ - Map params = new HashMap<>(2); - params.put("stationId", stationId); - //fdpMonitorEntity.getFdpId() - params.put("monitorId", "90240008|1#机组上导|859e9dd658084d28b14402e1b3d6cf51"); - HttpResponse r = HttpClientUtils.post(getMonitorFaultUrl, JSONObject.toJSONString(params)); - R> monitorFaultRespListR = JSONObject.parseObject(r.getData(), new TypeReference>>() { - }).convert2R(); - if (!monitorFaultRespListR.isSuccess()) { - return R.fail(monitorFaultRespListR.getMsg()); - } - List monitorFaultRespList = monitorFaultRespListR.getData(); - /**排出list为空的情况 获取rate最大值**/ - monitorFaultRespList = CollectionUtil.isNotEmpty(monitorFaultRespList) ? monitorFaultRespList.stream().filter(m -> Func.isNotEmpty(m.getRate())).collect(Collectors.toList()) : null; - if (CollectionUtil.isEmpty(monitorFaultRespList)) { - return R.fail("获取检测点最有可能的故障ID失败,未返回相应记录"); - } - /**返回数据已排序,取第一条进行诊断(rate最高);根据rate进行相应诊断**/ - MonitorFaultResp monitorFaultResp = monitorFaultRespList.get(0); - if (Float.parseFloat(monitorFaultResp.getRate()) < 0) { - return R.fail("数据错误,请检查传感器或通信"); - } else if (Float.parseFloat(monitorFaultResp.getRate()) < rateRange) { - return R.success("数据正常"); - } else if (Float.parseFloat(monitorFaultResp.getRate()) >= rateRange) { - /**保存任务**/ - FdpTaskDTO fdpTaskDTO = new FdpTaskDTO(); - fdpTaskDTO.setFaultId(monitorFaultResp.getId()); - fdpTaskDTO.setName(monitorFaultResp.getName()); - fdpTaskDTO.setType(EquipmentConstants.TaskTypeEnum.AUTO.getType()); - fdpTaskDTO.setCreateTime(new Date()); - fdpTaskDTO.setCreateUser(1377143375838359553L); - fdpTaskDTO.setCreateDept(1123598813738675201L); - if (Func.isNotEmpty(realId)) { - fdpTaskDTO.setRealId(realId); - } - R saveTaskR = fdpTaskService.doSave(fdpTaskDTO); - if (!saveTaskR.isSuccess()) { - return R.fail("保存任务失败"); - } - /**获取根因等信息**/ - DiagnoseNextstepReq req = new DiagnoseNextstepReq(); - req.setExist(monitorFaultResp.getId()); - req.setTenantId(stationId); - R nextStepRespR = diagnoseProxy.nextstep(req); - if (nextStepRespR.isSuccess()) { - /**调用nextStep成功则更新任务**/ - fdpTaskService.update(Wrappers.lambdaUpdate() - .set(FdpTaskEntity::getReasonObject, JSONObject.toJSONString(nextStepRespR.getData())) - .eq(FdpTaskEntity::getId, fdpTaskDTO.getId())); - } else { - throw new ServiceException(nextStepRespR.getMsg()); - } - return nextStepRespR; - } else { - return R.fail("获取数据无法与rateRange比较"); - } - } - - @Override - @SuppressWarnings("uncheck") - @Transactional - public R getMonitorFault(String realId, String stationId) { - /**推送数据**/ - R pushResult = this.dataByRealIdPush(realId, stationId); - if (!pushResult.isSuccess()) { - return R.fail(pushResult.getMsg()); - } - /**根据realid获取monitor对象**/ - FdpMonitorEntity monitorEntity = new FdpMonitorEntity(); - monitorEntity.setImsRealIds(realId); - FdpMonitorEntity fdpMonitorEntity = fdpMonitorNoScopeMapper.selectOne(new LambdaQueryWrapper() {{ - like(FdpMonitorEntity::getImsRealIds, realId); - last("limit 1;"); - }}); - /**从智能诊断获取monitorId**/ - if (ObjectUtil.isEmpty(fdpMonitorEntity)) { - return R.fail("获取智能诊断监测点失败"); - } - /**获取站点ID**/ - R> stationListR = stationClient.getStationsByRefDept(fdpMonitorEntity.getCreateDept()); - if (!stationListR.isSuccess() || CollectionUtil.isEmpty(stationListR.getData())) { - return R.fail("获取监测点站点失败"); - } - /**开始诊断**/ - Map params = new HashMap<>(2); - params.put("stationId", stationListR.getData().get(0).getCode()); - //"90240008|1#机组上导|859e9dd658084d28b14402e1b3d6cf51" - params.put("monitorId", fdpMonitorEntity.getFdpId()); - HttpResponse r = HttpClientUtils.post(getMonitorFaultUrl, JSONObject.toJSONString(params)); - R> monitorFaultRespListR = JSONObject.parseObject(r.getData(), new TypeReference>>() { - }).convert2R(); - if (!monitorFaultRespListR.isSuccess()) { - return R.fail(monitorFaultRespListR.getMsg()); - } - List monitorFaultRespList = monitorFaultRespListR.getData(); - /**排出list为空的情况 获取rate最大值**/ - monitorFaultRespList = CollectionUtil.isNotEmpty(monitorFaultRespList) ? monitorFaultRespList.stream().filter(m -> Func.isNotEmpty(m.getRate())).collect(Collectors.toList()) : null; - if (CollectionUtil.isEmpty(monitorFaultRespList)) { - return R.fail("获取检测点最有可能的故障ID失败,未返回相应记录"); - } - /**返回数据已排序,取第一条进行诊断(rate最高);根据rate进行相应诊断**/ - MonitorFaultResp monitorFaultResp = monitorFaultRespList.get(0); - if (Float.parseFloat(monitorFaultResp.getRate()) < 0) { - return R.fail("数据错误,请检查传感器或通信"); - } else if (Float.parseFloat(monitorFaultResp.getRate()) < rateRange) { - return R.success("数据正常"); - } else if (Float.parseFloat(monitorFaultResp.getRate()) >= rateRange) { - return R.data(monitorFaultResp); - } else { - return R.fail("获取数据无法与rateRange比较"); - } - } - - - /** - * 根据站点获取开机的FDP实例Code - * - * @param stationIdList - * @return - */ - @Override - public List getFdpDeviceCodeByOff(List stationIdList) { - List fdpDeviceCodeList = new ArrayList<>(); - List list = this.baseMapper.selectFdpDeviceCodeByStation(stationIdList); - if (CollectionUtil.isNotEmpty(list)) { - for (String fdpDeviceCode : list) { - RealDataSearchPO realDataSearchPO = new RealDataSearchPO(); - realDataSearchPO.setAnalyzeCode(fdpDeviceCode); - realDataSearchPO.setSignages(Arrays.asList(JOINT_RELAY_SIGNAGE.split(","))); - R> realDataByAnalyzeCode = null; - try { - realDataByAnalyzeCode = realDataSearchClient.getRealDataByAnalyzeCode(realDataSearchPO); - } catch (Exception e) { - throw new RuntimeException(e.getMessage()); - } - XxlJobLogger.log(fdpDeviceCode+"实时数据返回:"+ JSON.toJSONString(realDataByAnalyzeCode)); - if (realDataByAnalyzeCode.isSuccess() && CollectionUtil.isNotEmpty(realDataByAnalyzeCode.getData())) { - FieldsData fieldsData = realDataByAnalyzeCode.getData().get(0); - if (0 == fieldsData.getQ() && "1".equals(fieldsData.getValue())) { - fdpDeviceCodeList.add(fdpDeviceCode); - } - } - } - } - return fdpDeviceCodeList; - } - - /*** - * 开始诊断 - * @param fdpTaskDTO 诊断任务 - * @param req 获取根因信息传参 - * @return - */ - @Override - @Transactional(rollbackFor = Exception.class) - public R diagnosisNextStep(FdpTaskDTO fdpTaskDTO, DiagnoseNextstepReq req) { - fdpTaskDTO.setType(EquipmentConstants.TaskTypeEnum.MANUAL.getType()); - boolean flag = fdpTaskService.save(fdpTaskDTO); - if (!flag) { - return R.fail("保存任务失败"); - } - /**根据fdpID获取站点ID**/ - FdpFaultEntity fdpFaultEntity = fdpFaultService.getOne(new LambdaQueryWrapper() {{ - eq(FdpFaultEntity::getFdpId, fdpTaskDTO.getFaultId()); - last("limit 1;"); - }}); - if (ObjectUtil.isEmpty(fdpFaultEntity)) { - throw new ServiceException("操作失败,获取相关故障对象失败!"); - } - req.setTenantId(fdpFaultEntity.getStationId()); - /**推送数据**/ - R pushResult = this.dataPushByRealId(fdpTaskDTO.getRealId(), null); - if (!pushResult.isSuccess()) { - throw new ServiceException(pushResult.getMsg()); - } - /**获取根因等信息**/ - R nextStepRespR = diagnoseProxy.nextstep(req); - if (nextStepRespR.isSuccess()) { - /**调用nextStep成功则更新任务**/ - fdpTaskService.update(Wrappers.lambdaUpdate() - .set(FdpTaskEntity::getReasonObject, JSONObject.toJSONString(nextStepRespR.getData())) - .eq(FdpTaskEntity::getId, fdpTaskDTO.getId())); - } else { - throw new ServiceException(nextStepRespR.getMsg()); - } - nextStepRespR.getData().setTaskId(fdpTaskDTO.getId()); - return nextStepRespR; - } - - - /*** - * 开始诊断 - * @param fdpTaskDTO 诊断任务 - * @param req 获取根因信息传参 - * @return - */ - @Override - @Transactional(rollbackFor = Exception.class) - public R diagnosisNextStepNew(FdpTaskDTO fdpTaskDTO, DiagnoseNextstepReq req) { - fdpTaskDTO.setType(EquipmentConstants.TaskTypeEnum.MANUAL.getType()); - /**根据fdpID获取站点ID**/ - FdpFaultEntity fdpFaultEntity = fdpFaultService.getOne(new LambdaQueryWrapper() {{ - eq(FdpFaultEntity::getFdpId, fdpTaskDTO.getFaultId()); - last("limit 1;"); - }}); - if (ObjectUtil.isEmpty(fdpFaultEntity)) { - throw new ServiceException("操作失败,获取相关故障对象失败!"); - } - fdpTaskDTO.setFdpOrd(fdpFaultEntity.getOrd()); - fdpTaskDTO.setFdpDeviceName(fdpFaultEntity.getFdpDeviceName()); - //boolean flag = fdpTaskService.save(fdpTaskDTO); + ThreadTask.fdpTaskNew(taskDTO, fdpFaultEntity, key); + //获取数据成功-》 告知前端 + Map map = new HashMap<>(); + map.put("id", key); + return R.data(map); + } + + @Override + public R getNextstepData(String id) { + Object o = redisTemplate.opsForValue().get(fdpReturnValuePath + "_" + id); + if (ObjectUtil.isNotEmpty(o)) { + R r = JSONObject.parseObject(o.toString(), new TypeReference() {{ + }}); + return r; + } + return R.data("-1"); + } + + + @Override + public R updateFaultState(DiagnoseFaultReq diagnoseFaultReq) { + diagnoseFaultReq.setPriority(2); + /**获取故障对象**/ + LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); + wrapper.eq(FdpFaultEntity::getFdpId, diagnoseFaultReq.getFaultId()).last("limit 1"); + FdpFaultEntity fdpFaultEntity = fdpFaultService.getOne(wrapper); + if (ObjectUtil.isEmpty(fdpFaultEntity)) { + throw new ServiceException("获取对应故障对象失败"); + } + Boolean hasKey = redisTemplate.hasKey(KEY_FOR_FDP_TASK_ID + "_" + diagnoseFaultReq.getTaskId().toString()); + //Redis中不存在,该任务过期 + if (!hasKey) { + return R.fail("该任务已过期,请重新生成任务"); + } + /**更新故障状态**/ + DiagnoseFaultAllReq faultAllReq = new DiagnoseFaultAllReq(); + /**推送数据**/ + //20230710取消实时数据推送 +// FdpRealTimeAndHisDataVo pushResp = this.dataPushByPartition(fdpFaultEntity.getFdpPartition(), fdpFaultEntity.getCreateDept()); +// faultAllReq.setAutoData(pushResp); + + faultAllReq.setStationId(fdpFaultEntity.getStationId()); + diagnoseFaultReq.setTenantId(fdpFaultEntity.getStationId()); + diagnoseFaultReq.setLifeTime(24*3);//一旦用户进行修改,智能诊断时效性刷新为3天 + faultAllReq.setManualData(diagnoseFaultReq); + String jsonString = JSONObject.toJSONString(faultAllReq); + System.out.println(jsonString); + HttpResponse r = HttpClientUtils.post(updateFaultStateAll, JSONObject.toJSONString(faultAllReq)); + redisTemplate.expire(KEY_FOR_FDP_TASK_ID + "_" + diagnoseFaultReq.getTaskId(), 3, TimeUnit.DAYS); + return JSONObject.parseObject(r.getData(), BaseResp.class).convert2R(); + } + + + @Override + public List getAll() { + return this.baseMapper.selectAll(); + } + + @Override + public List getRealIds() { + return this.baseMapper.getRealIds(); + } + + @Override + public String getFaultList() { + List list = this.baseMapper.selectStationIds(); + if (CollectionUtil.isEmpty(list)) { + return null; + } + Map paramMap = new HashMap<>(); + paramMap.put("stationIds", list.toArray(new String[0])); + String result = HttpRequestUtil.postCall(paramMap, autoFaultPath, "POST"); + if (StringUtil.isBlank(result)) { + return null; + } + return JSONObject.parseObject(result).get("data").toString(); + } + + @Override + public String updateFaultState(UpdateFaultStateVo state) { + Map paramMap = new HashMap<>(); + // 站点ID + paramMap.put("stationId", state.getStationId()); + // 故障ID + paramMap.put("faultId", state.getFaultId()); + // 故障的置信度 : 发生为1,不发生为0。 + paramMap.put("confidence", state.getConfidence()); + // 时间字符串 + paramMap.put("createTime", state.getCreateTime()); + // 创建人 + paramMap.put("createUser", state.getCreateUser()); + // 单位小时,默认值为1 + paramMap.put("lifeTime", state.getLifeTime()); + // 优先级 + paramMap.put("priority", state.getPriority()); + // 描述 + paramMap.put("info", state.getInfo()); + String result = HttpRequestUtil.postCall(paramMap, autoFaultPath, "POST"); + if (StringUtil.isBlank(result)) { + return null; + } + return JSONObject.parseObject(result).get("data").toString(); + } + + /*** + * + * @param req + * @param faultAllReq + * @param fdpFaultEntity + * @param type 1:推送;2:不推送 + * @return + */ + public R dianogse(FdpTaskDTO req, DiagnoseFaultAllReq faultAllReq, FdpFaultEntity fdpFaultEntity, String type) { + req.setFdpDeviceName(fdpFaultEntity.getFdpDeviceName()); + req.setFdpOrd(fdpFaultEntity.getOrd()); + req.setName(fdpFaultEntity.getName()); + boolean flag = fdpTaskService.save(req); + if (!flag) { + return R.fail("诊断任务保存失败"); + } + /**推送故障状态**/ + faultAllReq.setStationId(fdpFaultEntity.getStationId()); + + if ("1".equals(type)) { + DiagnoseFaultReq diagnoseFaultReq = new DiagnoseFaultReq(); + diagnoseFaultReq.setTaskId(req.getId().toString()); + log.info("存入taskId为:{}", req.getId().toString()); + diagnoseFaultReq.setFaultId(req.getFaultId()); + diagnoseFaultReq.setConfidence(1.0); + diagnoseFaultReq.setLifeTime(1); + diagnoseFaultReq.setPriority(2); + diagnoseFaultReq.setTenantId(fdpFaultEntity.getStationId()); + diagnoseFaultReq.setCreateUser(ObjectUtil.isEmpty(AuthUtil.getUser()) ? "告警推送" : AuthUtil.getUser().getUserName()); + faultAllReq.setManualData(diagnoseFaultReq); + } + + log.info("---智能诊断推送对象为:{}---", JSONObject.toJSONString(faultAllReq)); + HttpClientUtils.post(updateFaultStateAll, JSONObject.toJSONString(faultAllReq)); + //JSONObject.parseObject(r.getData(), BaseResp.class).convert2R(); + return R.data(req.getId()); + } + + /** + * 监测点绑定 + * + * @param req + * @return + */ + @Override + public R doSetCycle(FdpMonitorEntity req) { + FdpMonitorEntity entity = this.getOne(new LambdaQueryWrapper() {{ + eq(FdpMonitorEntity::getFdpId, req.getFdpId()).last(" LIMIT 1"); + }}); + if (req.getImsRealIds().split(",").length > 1 && ("bool".equals(entity.getCallbackType()) || "float".equals(entity.getCallbackType()))) { + String name = ""; + if ("bool".equals(entity.getCallbackType())) { + name = "单点遥信"; + } else if ("float".equals(entity.getCallbackType())) { + name = "单点遥测"; + } + return R.fail("该数据格式为:" + name + ",故该值最多绑定一个"); + } + return R.status(this.update(req, new LambdaQueryWrapper() {{ + eq(FdpMonitorEntity::getFdpId, req.getFdpId()); + }})); + } + + @Override + @Transactional + public R bindingBatch(List monitorBindingDTOList) { + /**监测点批量绑定**/ + List fdpMonitorEntityList = monitorBindingDTOList.stream().map(FdpMonitorBindingDTO::getMonitorEntity).collect(Collectors.toList()); + boolean flag = this.updateBatchById(fdpMonitorEntityList); + if (flag) { + throw new ServiceException("监测点批量绑定失败"); + } + /**数据平台接口批量更新接口调用**/ + List fieldVOList = monitorBindingDTOList.stream().map(FdpMonitorBindingDTO::getAnalyzeInstanceFieldVO).collect(Collectors.toList()); + + return R.success("绑定成功!"); + } + + /** + * 监测点绑定列表 + * + * @param entity + * @return + */ + @Override + public List doBindingList(FdpMonitorEntity entity) { + FdpMonitorEntity fdpMonitorEntity = this.baseMapper.selectOne(new LambdaQueryWrapper() {{ + eq(FdpMonitorEntity::getFdpId, entity.getFdpId()); + }}); + List list = new ArrayList<>(); + if (ObjectUtil.isNotEmpty(fdpMonitorEntity)) { + if (StringUtil.isNotBlank(fdpMonitorEntity.getImsSignages())) { + String[] signage = fdpMonitorEntity.getImsSignages().split(","); + EmInfoEntity emInfoEntity = emInfoService.getOne(new LambdaQueryWrapper() {{ + eq(EmInfoEntity::getNumber, entity.getEmCode()); + }}); + List data = analyseInstanceClient.getInstanceFieldByAnalyseCode(entity.getEmCode(), 1, null).getData(); + for (int i = 0; i < signage.length; i++) { + String realName = ""; + for (AnalyzeInstanceFieldVO analyzeInstanceFieldVO : data) { + if (analyzeInstanceFieldVO.getSignage().equals(signage[i])) { + realName = analyzeInstanceFieldVO.getName(); + continue; + } + } + FdpMonitorExtendDTO dto = new FdpMonitorExtendDTO(); + if (ObjectUtil.isNotEmpty(emInfoEntity)) { + dto.setEmName(emInfoEntity.getName()); + } + dto.setRealName(realName); + dto.setSignage(signage[i]); + dto.setEmCode(entity.getEmCode()); + dto.setFdpId(fdpMonitorEntity.getFdpId()); + list.add(dto); + } + } + } + return list; + } + + /** + * 根据设备编号查询点 + * + * @param instanceDeviceCode + * @return + */ + @Override + public R> getInstanceFieldByDeviceCode(Long id, String instanceDeviceCode, String instanceFieldName) { + String signages = ""; + FdpMonitorVO fdpMonitorVO = this.baseMapper.selectSignagesById(id, instanceDeviceCode); + if (ObjectUtil.isNotEmpty(fdpMonitorVO) && StringUtil.isNotBlank(fdpMonitorVO.getSignages())) { + signages = fdpMonitorVO.getSignages(); + } + R> deviceFieldByAnalyseCode = analyseInstanceClient.getDeviceFieldByAnalyseCode(instanceDeviceCode, instanceFieldName); + if (deviceFieldByAnalyseCode.isSuccess() && CollectionUtil.isNotEmpty(deviceFieldByAnalyseCode.getData())) { + List data = deviceFieldByAnalyseCode.getData(); + if (CollectionUtil.isNotEmpty(data) && StringUtil.isNotBlank(signages)) { + List list = Arrays.asList(signages.split(",")); + Set signage = new HashSet<>(list); + data = data.stream().filter(o -> !signage.contains(o.getSignage()) && null != o.getFieldName()).collect(Collectors.toList()); + } + return R.data(data); + } + return R.data(Lists.newArrayList()); + } + + /** + * 获取图谱 -- 专家知识库 + * + * @return + */ + @Override + public R getAtlas() { + String result = HttpRequestUtil.postCall(null, atalsPath, "POST"); + //数据转换成map + HashMap stringObjectHashMap = JSONObject.parseObject(result, new TypeReference>() { + }); + Map data = MapUtils.getMap(stringObjectHashMap, "data"); + if (ObjectUtil.isEmpty(data)) { + return R.data(null); + } + return R.data(data); + } + + @Override + public Integer updateByFdpId(String fdpId) { + return this.baseMapper.updateByFdpId(fdpId); + } + + /** + * 根据RealId进行数据获取 + * + * @param realId + * @param stationId + * @return + */ + @Override + public R dataPushByRealId(String realId, String stationId) { + List fdpMonitorEntityList = this.baseMapper.selectMonitorByRealId(realId, stationId); + FdpRealTimeAndHisDataVo vo = new FdpRealTimeAndHisDataVo(); + vo.setStationId(stationId); + if (CollectionUtil.isNotEmpty(fdpMonitorEntityList)) { + //实时数据 + List realTimeDataPush = this.getRealTimeData(fdpMonitorEntityList); + //历史数据 + List historyDataPush = this.getHistoryData(fdpMonitorEntityList); + vo.setRealTimeData(realTimeDataPush); + vo.setHistoryData(historyDataPush); + log.info("dataPushByRealId 结果集{}:......................" + JSONObject.toJSONString(realTimeDataPush)); + } + if (CollectionUtil.isEmpty(fdpMonitorEntityList)) { + return R.fail("该监测点在智能诊断功能未进行数据绑定!"); + } + return R.data(vo); + } + + /** + * 根据RealId进行数据推送 + * + * @param realId + * @param stationId + * @return + */ + @Override + public R dataByRealIdPush(String realId, String stationId) { + List fdpMonitorEntityList = this.baseMapper.selectMonitorByRealId(realId, stationId); + FdpRealTimeAndHisDataVo vo = new FdpRealTimeAndHisDataVo(); + vo.setStationId(stationId); + if (CollectionUtil.isNotEmpty(fdpMonitorEntityList)) { + //实时数据 + List realTimeDataPush = this.getRealTimeData(fdpMonitorEntityList); + vo.setRealTimeData(realTimeDataPush); + //历史数据 + List historyDataPush = this.getHistoryData(fdpMonitorEntityList); + vo.setHistoryData(historyDataPush); + log.info("dataByRealIdPush 结果集{}:......................" + JSONObject.toJSONString(vo)); + HttpRequestUtil.postCallObjectParam(vo, pushPath, "POST"); + } + if (CollectionUtil.isEmpty(fdpMonitorEntityList)) { + return R.fail("该监测点在智能诊断功能未进行数据绑定!"); + } + return R.data(vo); + } + + /** + * 根据分区号进行实时数据推送 + * + * @param fdpPartition + * @param dept + * @return + */ + @Override + public FdpRealTimeAndHisDataVo dataPushByPartition(Long fdpPartition, Long dept) { + List fdpMonitorEntityList = this.baseMapper.selectMonitorByPartition(fdpPartition, dept); + FdpRealTimeAndHisDataVo vo = new FdpRealTimeAndHisDataVo(); + if (CollectionUtil.isNotEmpty(fdpMonitorEntityList)) { + //实时数据 + List realTimeDataPush = this.getRealTimeData(fdpMonitorEntityList); + //历史数据 + List historyDataPush = this.getHistoryData(fdpMonitorEntityList); + vo.setRealTimeData(realTimeDataPush); + vo.setHistoryData(historyDataPush); + log.info("dataPushByPartition 结果集{}:......................" + JSONObject.toJSONString(vo)); + //HttpRequestUtil.postCall(resultMap, pushPath, "POST"); + } + return vo; + } + + @Override + public R dataBackV2(String faultId) { + Map resultMap = new HashMap<>(); + resultMap.put("faultId", faultId); + String post = HttpRequestUtil.postCallObjectParam(resultMap, getRealByFault, "POST"); + FdpHttpResponseVo fdpHttpResponseVo = JSONObject.parseObject(post, new TypeReference() { + }); + if (1 == fdpHttpResponseVo.getSuccess()) { + if (Func.isNotEmpty(fdpHttpResponseVo.getData())) { + List list = JSONObject.parseObject(fdpHttpResponseVo.getData(), new TypeReference>() { + }); + if (CollectionUtil.isEmpty(list)) { + return R.success("暂无数据,请稍后重试"); + } + List res = new ArrayList<>(); + for (FdpFaultRealDataDTO fdpFaultRealDataDTO : list) { + if (null != fdpFaultRealDataDTO.getReal()) { + for (int i = 0; i < fdpFaultRealDataDTO.getReal().size(); i++) { + FdpFaultRealDataVO dataVO = new FdpFaultRealDataVO(); + BeanUtils.copyProperties(fdpFaultRealDataDTO, dataVO); + dataVO.setReal(fdpFaultRealDataDTO.getReal().get(i)); + dataVO.setRealTime(fdpFaultRealDataDTO.getRealTime().get(i)); + dataVO.setRealName(fdpFaultRealDataDTO.getRealName().get(i)); + dataVO.setRealIdentifier(fdpFaultRealDataDTO.getRealIdentifier().get(i)); + res.add(dataVO); + } + } else { + FdpFaultRealDataVO dataVO = new FdpFaultRealDataVO(); + BeanUtils.copyProperties(fdpFaultRealDataDTO, dataVO); + res.add(dataVO); + } + } + return R.data(res); + } + return R.success("暂无数据,请稍后重试"); + } + return R.fail("智能诊断接口异常,请联系管理员"); + } + + + //此接口已经弃用20230628 + @Deprecated + @Override + public Map dataBack(String faultId) { + //根据故障ID查询监测点列表 + List fdpMonitorEntityList = this.baseMapper.selectByFaultId(faultId); + Map resultMap = new HashMap<>(); + resultMap.put("realTimeData", null); + resultMap.put("historyData", null); + if (ObjectUtil.isNotEmpty(fdpMonitorEntityList)) { + //实时数据 + List> realTimeDataPush = this.getRealTimeDataBack(fdpMonitorEntityList); + //历史数据 + List> historyDataPush = this.getHistoryDataBack(fdpMonitorEntityList, faultId); + resultMap.put("realTimeData", realTimeDataPush); + resultMap.put("historyData", historyDataPush); + } + return resultMap; + } + + /** + * 统计月报-数据追溯 + * + * @param vo + * @return + */ + @Override + public Map monthlyDataBack(DataBackVo vo) { + //根据故障ID查询监测点列表 + List fdpMonitorEntityList = this.baseMapper.selectByFaultId(vo.getFaultId()); + DateTimeFormatter df = DateTimeFormatter.ofPattern(DateUtil.PATTERN_DATETIME); + LocalDateTime beginTime = LocalDateTime.parse(DateUtils.minutlDate(DateUtil.parse(vo.getDate(), DateUtil.PATTERN_DATETIME), -5, DateUtil.PATTERN_DATETIME), df); + LocalDateTime endTime = LocalDateTime.parse(DateUtils.minutlDate(DateUtil.parse(vo.getDate(), DateUtil.PATTERN_DATETIME), 5, DateUtil.PATTERN_DATETIME), df); + Map resultMap = new HashMap<>(); + resultMap.put("historyData", null); + if (ObjectUtil.isNotEmpty(fdpMonitorEntityList)) { + //历史数据 + List> historyDataPush = this.getHistoryMonthlyDataBack(fdpMonitorEntityList, vo.getFaultId(), beginTime, endTime); + resultMap.put("historyData", historyDataPush); + } + return resultMap; + } + + @Override + @Transactional + public R diagnosisByMonitorIdAndStation(String realId, String stationId) { + /**推送数据**/ + R pushResult = this.dataByRealIdPush(realId, stationId); + if (!pushResult.isSuccess()) { + return R.fail(pushResult.getMsg()); + } + /**根据realid获取monitor对象**/ + FdpMonitorEntity monitorEntity = new FdpMonitorEntity(); + monitorEntity.setImsRealIds(realId); + FdpMonitorEntity fdpMonitorEntity = fdpMonitorNoScopeMapper.selectOne(Condition.getQueryWrapper(monitorEntity, FdpMonitorEntity.class).last("limit 1")); + /**从智能诊断获取monitorId**/ + if (ObjectUtil.isEmpty(fdpMonitorEntity)) { + return R.fail("获取智能诊断监测点失败"); + } + /**开始诊断**/ + Map params = new HashMap<>(2); + params.put("stationId", stationId); + //fdpMonitorEntity.getFdpId() + params.put("monitorId", "90240008|1#机组上导|859e9dd658084d28b14402e1b3d6cf51"); + HttpResponse r = HttpClientUtils.post(getMonitorFaultUrl, JSONObject.toJSONString(params)); + R> monitorFaultRespListR = JSONObject.parseObject(r.getData(), new TypeReference>>() { + }).convert2R(); + if (!monitorFaultRespListR.isSuccess()) { + return R.fail(monitorFaultRespListR.getMsg()); + } + List monitorFaultRespList = monitorFaultRespListR.getData(); + /**排出list为空的情况 获取rate最大值**/ + monitorFaultRespList = CollectionUtil.isNotEmpty(monitorFaultRespList) ? monitorFaultRespList.stream().filter(m -> Func.isNotEmpty(m.getRate())).collect(Collectors.toList()) : null; + if (CollectionUtil.isEmpty(monitorFaultRespList)) { + return R.fail("获取检测点最有可能的故障ID失败,未返回相应记录"); + } + /**返回数据已排序,取第一条进行诊断(rate最高);根据rate进行相应诊断**/ + MonitorFaultResp monitorFaultResp = monitorFaultRespList.get(0); + if (Float.parseFloat(monitorFaultResp.getRate()) < 0) { + return R.fail("数据错误,请检查传感器或通信"); + } else if (Float.parseFloat(monitorFaultResp.getRate()) < rateRange) { + return R.success("数据正常"); + } else if (Float.parseFloat(monitorFaultResp.getRate()) >= rateRange) { + /**保存任务**/ + FdpTaskDTO fdpTaskDTO = new FdpTaskDTO(); + fdpTaskDTO.setFaultId(monitorFaultResp.getId()); + fdpTaskDTO.setName(monitorFaultResp.getName()); + fdpTaskDTO.setType(EquipmentConstants.TaskTypeEnum.AUTO.getType()); + fdpTaskDTO.setCreateTime(new Date()); + fdpTaskDTO.setCreateUser(1377143375838359553L); + fdpTaskDTO.setCreateDept(1123598813738675201L); + if (Func.isNotEmpty(realId)) { + fdpTaskDTO.setRealId(realId); + } + R saveTaskR = fdpTaskService.doSave(fdpTaskDTO); + if (!saveTaskR.isSuccess()) { + return R.fail("保存任务失败"); + } + /**获取根因等信息**/ + DiagnoseNextstepReq req = new DiagnoseNextstepReq(); + req.setExist(monitorFaultResp.getId()); + req.setTenantId(stationId); + R nextStepRespR = diagnoseProxy.nextstep(req); + if (nextStepRespR.isSuccess()) { + /**调用nextStep成功则更新任务**/ + fdpTaskService.update(Wrappers.lambdaUpdate() + .set(FdpTaskEntity::getReasonObject, JSONObject.toJSONString(nextStepRespR.getData())) + .eq(FdpTaskEntity::getId, fdpTaskDTO.getId())); + } else { + throw new ServiceException(nextStepRespR.getMsg()); + } + return nextStepRespR; + } else { + return R.fail("获取数据无法与rateRange比较"); + } + } + + @Override + @SuppressWarnings("uncheck") + @Transactional + public R getMonitorFault(String realId, String stationId) { + /**推送数据**/ + R pushResult = this.dataByRealIdPush(realId, stationId); + if (!pushResult.isSuccess()) { + return R.fail(pushResult.getMsg()); + } + /**根据realid获取monitor对象**/ + FdpMonitorEntity monitorEntity = new FdpMonitorEntity(); + monitorEntity.setImsRealIds(realId); + FdpMonitorEntity fdpMonitorEntity = fdpMonitorNoScopeMapper.selectOne(new LambdaQueryWrapper() {{ + like(FdpMonitorEntity::getImsRealIds, realId); + last("limit 1;"); + }}); + /**从智能诊断获取monitorId**/ + if (ObjectUtil.isEmpty(fdpMonitorEntity)) { + return R.fail("获取智能诊断监测点失败"); + } + /**获取站点ID**/ + R> stationListR = stationClient.getStationsByRefDept(fdpMonitorEntity.getCreateDept()); + if (!stationListR.isSuccess() || CollectionUtil.isEmpty(stationListR.getData())) { + return R.fail("获取监测点站点失败"); + } + /**开始诊断**/ + Map params = new HashMap<>(2); + params.put("stationId", stationListR.getData().get(0).getCode()); + //"90240008|1#机组上导|859e9dd658084d28b14402e1b3d6cf51" + params.put("monitorId", fdpMonitorEntity.getFdpId()); + HttpResponse r = HttpClientUtils.post(getMonitorFaultUrl, JSONObject.toJSONString(params)); + R> monitorFaultRespListR = JSONObject.parseObject(r.getData(), new TypeReference>>() { + }).convert2R(); + if (!monitorFaultRespListR.isSuccess()) { + return R.fail(monitorFaultRespListR.getMsg()); + } + List monitorFaultRespList = monitorFaultRespListR.getData(); + /**排出list为空的情况 获取rate最大值**/ + monitorFaultRespList = CollectionUtil.isNotEmpty(monitorFaultRespList) ? monitorFaultRespList.stream().filter(m -> Func.isNotEmpty(m.getRate())).collect(Collectors.toList()) : null; + if (CollectionUtil.isEmpty(monitorFaultRespList)) { + return R.fail("获取检测点最有可能的故障ID失败,未返回相应记录"); + } + /**返回数据已排序,取第一条进行诊断(rate最高);根据rate进行相应诊断**/ + MonitorFaultResp monitorFaultResp = monitorFaultRespList.get(0); + if (Float.parseFloat(monitorFaultResp.getRate()) < 0) { + return R.fail("数据错误,请检查传感器或通信"); + } else if (Float.parseFloat(monitorFaultResp.getRate()) < rateRange) { + return R.success("数据正常"); + } else if (Float.parseFloat(monitorFaultResp.getRate()) >= rateRange) { + return R.data(monitorFaultResp); + } else { + return R.fail("获取数据无法与rateRange比较"); + } + } + + + /** + * 根据站点获取开机的FDP实例Code + * + * @param stationIdList + * @return + */ + @Override + public List getFdpDeviceCodeByOff(List stationIdList) { + List fdpDeviceCodeList = new ArrayList<>(); + List list = this.baseMapper.selectFdpDeviceCodeByStation(stationIdList); + if (CollectionUtil.isNotEmpty(list)) { + for (String fdpDeviceCode : list) { + RealDataSearchPO realDataSearchPO = new RealDataSearchPO(); + realDataSearchPO.setAnalyzeCode(fdpDeviceCode); + realDataSearchPO.setSignages(Arrays.asList(JOINT_RELAY_SIGNAGE.split(","))); + R> realDataByAnalyzeCode = null; + try { + realDataByAnalyzeCode = realDataSearchClient.getRealDataByAnalyzeCode(realDataSearchPO); + } catch (Exception e) { + throw new RuntimeException(e.getMessage()); + } + XxlJobLogger.log(fdpDeviceCode + "实时数据返回:" + JSON.toJSONString(realDataByAnalyzeCode)); + if (realDataByAnalyzeCode.isSuccess() && CollectionUtil.isNotEmpty(realDataByAnalyzeCode.getData())) { + FieldsData fieldsData = realDataByAnalyzeCode.getData().get(0); + if (0 == fieldsData.getQ() && "1".equals(fieldsData.getValue())) { + fdpDeviceCodeList.add(fdpDeviceCode); + } + } + } + } + return fdpDeviceCodeList; + } + + /*** + * 开始诊断 + * @param fdpTaskDTO 诊断任务 + * @param req 获取根因信息传参 + * @return + */ + @Override + @Transactional(rollbackFor = Exception.class) + public R diagnosisNextStep(FdpTaskDTO fdpTaskDTO, DiagnoseNextstepReq req) { + fdpTaskDTO.setType(EquipmentConstants.TaskTypeEnum.MANUAL.getType()); + boolean flag = fdpTaskService.save(fdpTaskDTO); + if (!flag) { + return R.fail("保存任务失败"); + } + /**根据fdpID获取站点ID**/ + FdpFaultEntity fdpFaultEntity = fdpFaultService.getOne(new LambdaQueryWrapper() {{ + eq(FdpFaultEntity::getFdpId, fdpTaskDTO.getFaultId()); + last("limit 1;"); + }}); + if (ObjectUtil.isEmpty(fdpFaultEntity)) { + throw new ServiceException("操作失败,获取相关故障对象失败!"); + } + req.setTenantId(fdpFaultEntity.getStationId()); + /**推送数据**/ + R pushResult = this.dataPushByRealId(fdpTaskDTO.getRealId(), null); + if (!pushResult.isSuccess()) { + throw new ServiceException(pushResult.getMsg()); + } + /**获取根因等信息**/ + R nextStepRespR = diagnoseProxy.nextstep(req); + if (nextStepRespR.isSuccess()) { + /**调用nextStep成功则更新任务**/ + fdpTaskService.update(Wrappers.lambdaUpdate() + .set(FdpTaskEntity::getReasonObject, JSONObject.toJSONString(nextStepRespR.getData())) + .eq(FdpTaskEntity::getId, fdpTaskDTO.getId())); + } else { + throw new ServiceException(nextStepRespR.getMsg()); + } + nextStepRespR.getData().setTaskId(fdpTaskDTO.getId()); + return nextStepRespR; + } + + + /*** + * 开始诊断 + * @param fdpTaskDTO 诊断任务 + * @param req 获取根因信息传参 + * @return + */ + @Override + @Transactional(rollbackFor = Exception.class) + public R diagnosisNextStepNew(FdpTaskDTO fdpTaskDTO, DiagnoseNextstepReq req) { + fdpTaskDTO.setType(EquipmentConstants.TaskTypeEnum.MANUAL.getType()); + /**根据fdpID获取站点ID**/ + FdpFaultEntity fdpFaultEntity = fdpFaultService.getOne(new LambdaQueryWrapper() {{ + eq(FdpFaultEntity::getFdpId, fdpTaskDTO.getFaultId()); + last("limit 1;"); + }}); + if (ObjectUtil.isEmpty(fdpFaultEntity)) { + throw new ServiceException("操作失败,获取相关故障对象失败!"); + } + fdpTaskDTO.setFdpOrd(fdpFaultEntity.getOrd()); + fdpTaskDTO.setFdpDeviceName(fdpFaultEntity.getFdpDeviceName()); + //boolean flag = fdpTaskService.save(fdpTaskDTO); // if (!flag) { // return R.fail("保存任务失败"); // } - req.setTenantId(fdpFaultEntity.getStationId()); - /**推送数据**/ - R pushResult = this.dataPushByRealId(fdpTaskDTO.getRealId(), null); - if (!pushResult.isSuccess()) { - throw new ServiceException(pushResult.getMsg()); - } - /**获取根因等信息**/ - R nextStepWithTree = fdpFaultService.getNextStepWithTree(fdpFaultEntity.getFdpId(), fdpFaultEntity.getStationId()); - if (nextStepWithTree.isSuccess()) { - /**调用nextStep成功则更新任务**/ + req.setTenantId(fdpFaultEntity.getStationId()); + /**推送数据**/ + R pushResult = this.dataPushByRealId(fdpTaskDTO.getRealId(), null); + if (!pushResult.isSuccess()) { + throw new ServiceException(pushResult.getMsg()); + } + /**获取根因等信息**/ + R nextStepWithTree = fdpFaultService.getNextStepWithTree(fdpFaultEntity.getFdpId(), fdpFaultEntity.getStationId()); + if (nextStepWithTree.isSuccess()) { + /**调用nextStep成功则更新任务**/ // fdpTaskService.update(Wrappers.lambdaUpdate() // .set(FdpTaskEntity::getReasonObject, JSONObject.toJSONString(nextStepWithTree.getData())) // .eq(FdpTaskEntity::getId, fdpTaskDTO.getId())); - } else { - throw new ServiceException(nextStepWithTree.getMsg()); - } - //nextStepRespR.getData().setTaskId(fdpTaskDTO.getId()); - return nextStepWithTree; - } - - - /** - * 获取实时数据 - * - * @param realDataList - * @return - */ - @Override - public List getRealTimeData(List realDataList) { - List listMap = new ArrayList<>(); - List list = realDataList.stream().filter(o -> null != o.getCallbackRealType()).collect(Collectors.toList()); - if (CollectionUtil.isNotEmpty(list)) { - Map> collectMap = list.stream().collect(Collectors.groupingBy(FdpMonitorEntity::getInstanceDeviceCode)); - for (String codeKey : collectMap.keySet()) { - List fdpMonitorEntityList = collectMap.get(codeKey); - String imsSignages = ""; - int count = 0; - for (FdpMonitorEntity fdpMonitorEntity : fdpMonitorEntityList) { - if (count == 0) { - imsSignages = fdpMonitorEntity.getImsSignages(); - } else { - imsSignages += "," + fdpMonitorEntity.getImsSignages(); - } - count++; - } - fdpMonitorEntityList.get(0).getInstanceDeviceCode(); - List valuePartition = this.getRealTimeDataValuePartition(fdpMonitorEntityList.get(0).getInstanceDeviceCode(), imsSignages); - if (CollectionUtil.isNotEmpty(valuePartition)) { - for (FdpMonitorEntity fdpMonitorEntity : fdpMonitorEntityList) { - List data = new ArrayList<>(); - for (String signage : fdpMonitorEntity.getImsSignages().split(",")) { - List collect = valuePartition.stream().filter(o -> o.getSignage().equals(signage)).collect(Collectors.toList()); - data.addAll(collect); - } - FdpRealTimeDataVo vo = this.getValuePartition(fdpMonitorEntity, data); - if (ObjectUtil.isNotEmpty(vo.getData())) { - vo.setId(fdpMonitorEntity.getFdpId()); - vo.setName(fdpMonitorEntity.getName()); - vo.setOrd(fdpMonitorEntity.getOrd()); - vo.setTime(DateUtil.format(new Date(), DateUtil.PATTERN_DATETIME)); - vo.setFaultIds(JSONObject.parseObject(fdpMonitorEntity.getCallbackRealType(), new TypeReference>>() { - })); - listMap.add(vo); - } - } - } - } - } - return listMap; - } - - public List> getRealTimeDataBack(List fdpMonitorEntityList) { - List list = fdpMonitorEntityList.stream().filter(o -> null != o.getCallbackRealType()).collect(Collectors.toList()); - List> listMap = new ArrayList<>(); - if (CollectionUtil.isNotEmpty(list)) { - if (CollectionUtil.isNotEmpty(list)) { - for (int i = 0; i < list.size(); i++) { - Map map = this.getValue(list.get(i)); - map.put("id", list.get(i).getFdpId()); - map.put("name", list.get(i).getName()); - map.put("ord", list.get(i).getOrd()); - map.put("time", DateUtil.format(new Date(), DateUtil.PATTERN_DATETIME)); - listMap.add(map); - } - } - } - return listMap; - } - - - public Map getValue(FdpMonitorEntity fdpMonitorEntity) { - Map maps = new HashMap(); - Map map = new HashMap<>(); - RealDataSearchPO realDataSearchPO = new RealDataSearchPO(); - String[] signages = fdpMonitorEntity.getImsSignages().split(","); - realDataSearchPO.setAnalyzeCode(fdpMonitorEntity.getInstanceDeviceCode()); - realDataSearchPO.setSignages(Arrays.asList(signages)); - R> realDataByDeviceCode = null; - try { - realDataByDeviceCode = realDataSearchClient.getRealDataByAnalyzeCode(realDataSearchPO); - } catch (Exception e) { - throw new RuntimeException(e.getMessage()); - } - if (realDataByDeviceCode.isSuccess() && CollectionUtil.isNotEmpty(realDataByDeviceCode.getData())) { - List data = realDataByDeviceCode.getData(); - this.setRealTimeDataFormatBack(map, fdpMonitorEntity, data); - } - maps.put("data", map); - return maps; - } - - public List getRealTimeDataValuePartition(String code, String signages) { - RealDataSearchPO realDataSearchPO = new RealDataSearchPO(); - String[] split = signages.split(","); - realDataSearchPO.setAnalyzeCode(code); - realDataSearchPO.setSignages(Arrays.asList(split)); - R> realDataByDeviceCode = null; - try { - realDataByDeviceCode = realDataSearchClient.getRealDataByAnalyzeCode(realDataSearchPO); - } catch (Exception e) { - throw new RuntimeException(e.getMessage()); - } - if (realDataByDeviceCode.isSuccess() && CollectionUtil.isNotEmpty(realDataByDeviceCode.getData())) { - return realDataByDeviceCode.getData(); - } - return null; - } - - public FdpRealTimeDataVo getValuePartition(FdpMonitorEntity fdpMonitorEntity, List data) { - Map map = new HashMap<>(); - FdpRealTimeDataVo vo = new FdpRealTimeDataVo(); - this.setRealTimeDataFormat(map, fdpMonitorEntity, data); - if (ObjectUtil.isNotEmpty(map.get("value_array")) || ObjectUtil.isNotEmpty(map.get("value")) - || ObjectUtil.isNotEmpty(map.get("state")) || ObjectUtil.isNotEmpty(map.get("state_array"))) { - vo.setData(map); - } - return vo; - } - - - private void setRealTimeDataFormatBack(Map map, FdpMonitorEntity fdpMonitorEntity, List data) { - Float flo[] = new Float[fdpMonitorEntity.getImsRealIds().split(",").length]; - int count = 0; - if ("float[]".equals(fdpMonitorEntity.getCallbackType())) { - for (int i = 0; i < data.size(); i++) { - FieldsData datum = data.get(i); - if (StringUtil.isNotBlank(datum.getValue())) { - flo[i] = Float.valueOf(datum.getValue()); - } else { - flo[i] = null; - count++; - } - } - if (data.size() == count) { - map.put("value_array", new ArrayList<>()); - } else { - map.put("value_array", flo); - } - } else if ("float".equals(fdpMonitorEntity.getCallbackType())) { - Float floValue = null; - for (FieldsData datum : data) { - if (StringUtil.isNotBlank(datum.getValue())) { - floValue = Float.valueOf(datum.getValue()); - } - } - map.put("value", floValue); - } else if ("bool".equals(fdpMonitorEntity.getCallbackType())) { - Boolean bool = null; - for (FieldsData datum : data) { - if (StringUtil.isNotBlank(datum.getValue())) { - if ("1".equals(datum.getValue())) { - bool = true; - } else if ("0".equals(datum.getValue())) { - bool = false; - } - } - } - map.put("state", bool); - } else if ("bool[]".equals(fdpMonitorEntity.getCallbackType())) { - Boolean booleans[] = new Boolean[fdpMonitorEntity.getImsRealIds().split(",").length]; - for (int i = 0; i < data.size(); i++) { - FieldsData datum = data.get(i); - if (StringUtil.isNotBlank(datum.getValue())) { - if ("1".equals(datum.getValue())) { - booleans[i] = true; - } else if ("0".equals(datum.getValue())) { - booleans[i] = false; - } - } else { - booleans[i] = null; - count++; - } - } - if (data.size() == count) { - map.put("state_array", new ArrayList<>()); - } else { - map.put("state_array", booleans); - } - } - } - - - private void setRealTimeDataFormat(Map map, FdpMonitorEntity fdpMonitorEntity, List data) { - List list = new ArrayList<>(); - int count = 0; - if ("float[]".equals(fdpMonitorEntity.getCallbackType())) { - for (int i = 0; i < data.size(); i++) { - FieldsData datum = data.get(i); - RealTimeDataFloVo vo = new RealTimeDataFloVo(); - if (StringUtil.isNotBlank(datum.getValue())) { - vo.setValue(Float.valueOf(datum.getValue())); - } else { - count++; - } - vo.setTime(datum.getTime()); - list.add(vo); - } - if (data.size() == count) { - map.put("value_array", null); - } else { - map.put("value_array", list); - } - } else if ("float".equals(fdpMonitorEntity.getCallbackType())) { - RealTimeDataFloVo vo = new RealTimeDataFloVo(); - for (FieldsData datum : data) { - if (StringUtil.isNotBlank(datum.getValue())) { - vo.setValue(Float.valueOf(datum.getValue())); - } - vo.setTime(datum.getTime()); - } - if (StringUtil.isNotBlank(vo.getTime())) { - map.put("value", vo); - } - } else if ("bool".equals(fdpMonitorEntity.getCallbackType())) { - RealTimeDataBoolVo vo = new RealTimeDataBoolVo(); - for (FieldsData datum : data) { - if (StringUtil.isNotBlank(datum.getValue())) { - if ("1".equals(datum.getValue())) { - vo.setValue(true); - } else if ("0".equals(datum.getValue())) { - vo.setValue(false); - } - } - vo.setTime(datum.getTime()); - } - if (StringUtil.isNotBlank(vo.getTime())) { - map.put("state", vo); - } - } else if ("bool[]".equals(fdpMonitorEntity.getCallbackType())) { - List voList = new ArrayList<>(); - for (int i = 0; i < data.size(); i++) { - FieldsData datum = data.get(i); - RealTimeDataBoolVo vo = new RealTimeDataBoolVo(); - if (StringUtil.isNotBlank(datum.getValue())) { - if ("1".equals(datum.getValue())) { - vo.setValue(true); - } else if ("0".equals(datum.getValue())) { - vo.setValue(false); - } - } else { - count++; - } - vo.setTime(datum.getTime()); - voList.add(vo); - } - if (data.size() == count) { - map.put("state_array", null); - } else { - map.put("state_array", voList); - } - } - } - - - public Map> getHisKeyValueDataPartition(List fdpMonitorEntityList, Date date, String code) { - List voList = new ArrayList<>(); - for (FdpMonitorEntity fdpMonitorEntity : fdpMonitorEntityList) { - List> hashMaps = JSONObject.parseObject(fdpMonitorEntity.getCallbackHistoryType(), new TypeReference>>() { - }); - List vos = transformFormatPartition(hashMaps, fdpMonitorEntity); - if (CollectionUtil.isEmpty(vos)) { - continue; - } - voList.addAll(vos); - } - //获取传递该数据点历史数据的数据格式 - Map> collect = voList.stream().collect(Collectors.groupingBy(join -> join.getInterval() + "_" + join.getNum() + "_" + join.getMode() + "_" + join.getUnit())); - //获取绑定的realId - return this.getRealIdHisValueMapPartition(collect, code, date); - } - - /** - * 数据追溯 - * - * @param fdpMonitorEntity - * @param date - * @return - */ - public Map getHisKeyValueDataBack(FdpMonitorEntity fdpMonitorEntity, Date date, String faultId) { - List> hashMaps = JSONObject.parseObject(fdpMonitorEntity.getCallbackHistoryType(), new TypeReference>>() { - }); - //获取传递该数据点历史数据的数据格式 - FdpCallbackHistoryTypeVo vo = transformFormatBack(hashMaps, faultId); - if (vo.getNum() <= 1) { - return null; - } - //获取绑定的realId - return getRealIdHisValueMapBack(vo, fdpMonitorEntity.getInstanceDeviceCode(), fdpMonitorEntity.getImsSignages(), date); - } - - /** - * 统计月报-数据追溯 - * - * @param fdpMonitorEntity - * @return - */ - public Map getHisKeyValueMonthlyDataBack(FdpMonitorEntity fdpMonitorEntity, String faultId, LocalDateTime beginTime, LocalDateTime endTime) { - List> hashMaps = JSONObject.parseObject(fdpMonitorEntity.getCallbackHistoryType(), new TypeReference>>() { - }); - //获取传递该数据点历史数据的数据格式 - FdpCallbackHistoryTypeVo vo = transformFormatBack(hashMaps, faultId); - if (vo.getNum() <= 1) { - return null; - } - Map maps = new HashMap<>(); - Object value = this.relevanceFaultObjectMonthlyBack(vo, fdpMonitorEntity.getInstanceDeviceCode(), fdpMonitorEntity.getImsSignages(), beginTime, endTime); - maps.put(vo.getFaultId(), value); - return maps; - } - - public Map> getRealIdHisValueMapPartition(Map> collect, String instanceDeviceCode, Date date) { - Map> resultMap = new HashMap<>(); - for (String key : collect.keySet()) { - List vos = collect.get(key); - String imsSignages = ""; - int count = 0; - for (FdpCallbackHistoryTypeVo vo : vos) { - if (count == 0) { - imsSignages = vo.getSignages(); - } else { - imsSignages += "," + vo.getSignages(); - } - count++; - } - List analyzeDataConditionVOS = this.dataParameterValues(instanceDeviceCode, imsSignages, getFdpTimeMap(vos.get(0), date, vos.get(0).getNum()), getCountingMode(vos.get(0).getMode()), vos.get(0).getInterval()); - if (CollectionUtil.isNotEmpty(analyzeDataConditionVOS)) { - for (FdpCallbackHistoryTypeVo vo : vos) { - List data = new ArrayList<>(); - for (String signage : vo.getSignages().split(",")) { - data.addAll(analyzeDataConditionVOS.stream().filter(o -> o.getSignage().equals(signage)).collect(Collectors.toList())); - } - vo.setData(data); - } - } - Map> collect1 = vos.stream().collect(Collectors.groupingBy(FdpCallbackHistoryTypeVo::getMonitorFdpIdId)); - for (String fdpIdKey : collect1.keySet()) { - Map maps = new HashMap<>(); - - List vos1 = collect1.get(fdpIdKey); - for (FdpCallbackHistoryTypeVo fdpCallbackHistoryTypeVo : vos1) { - Object value = this.relevanceFaultObjectPartition(fdpCallbackHistoryTypeVo); - String jsonString = JSONObject.toJSONString(value); - Object stringListMap = JSONObject.parseObject(jsonString, new TypeReference() { - }); - maps.put(fdpCallbackHistoryTypeVo.getFaultId(), stringListMap); - } - String jsonString = JSONObject.toJSONString(maps); - Map stringListMap = JSONObject.parseObject(jsonString, new TypeReference>() { - }); - resultMap.put(fdpIdKey, stringListMap); - } - } - return resultMap; - } - - /** - * 数据追溯 - * - * @param instanceDeviceCode - * @param signages - * @param date - * @return - */ - public Map getRealIdHisValueMapBack(FdpCallbackHistoryTypeVo vo, String instanceDeviceCode, String signages, Date date) { - Map maps = new HashMap<>(); - Object value = relevanceFaultObjectBack(vo, instanceDeviceCode, signages, date); - maps.put(vo.getFaultId(), value); - return maps; - } - - /** - * 关联故障 根据故障间隔类型 时间 采集方式 去数据库查询 - * - * @param vo - * @return - */ - private Object relevanceFaultObjectPartition(FdpCallbackHistoryTypeVo vo) { - List floList = new ArrayList<>(); - List boolList = new ArrayList<>(); - if (CollectionUtil.isNotEmpty(vo.getData())) { - if ("float[]".equals(vo.getType())) { - return floatValue(vo.getData(), floList, vo.getType()); - } else if ("float[][]".equals(vo.getType())) { - return floatValue(vo.getData(), floList, vo.getType()); - } else if ("bool[]".equals(vo.getType())) { - return bool(vo.getData(), boolList, vo.getType()); - } else if ("bool[][]".equals(vo.getType())) { - return bool(vo.getData(), boolList, vo.getType()); - } - - } else { - return new ArrayList<>(); - } - return null; - } - - /** - * 关联故障 根据故障间隔类型 时间 采集方式 去数据库查询 - * - * @param vo - * @return - */ - private Object relevanceFaultObjectBack(FdpCallbackHistoryTypeVo vo, String instanceDeviceCode, String signages, Date date) { - List> floList = new ArrayList<>(); - List> boolList = new ArrayList<>(); - List analyzeDataConditionVOS = dataParameterValues(instanceDeviceCode, signages, getFdpTimeMap(vo, date, vo.getNum()), getCountingMode(vo.getMode()), vo.getInterval()); - return getResultValue(vo, analyzeDataConditionVOS, floList, boolList); - } - - /** - * 统计月报 - 数据追溯 - * 关联故障 根据故障间隔类型 时间 采集方式 去数据库查询 - * - * @param vo - * @return - */ - private Object relevanceFaultObjectMonthlyBack(FdpCallbackHistoryTypeVo vo, String instanceDeviceCode, String signages, LocalDateTime beginTime, LocalDateTime endTime) { - List> floList = new ArrayList<>(); - List> boolList = new ArrayList<>(); - List analyzeDataConditionVOS = dataParameterValuesBack(instanceDeviceCode, signages, getCountingMode(vo.getMode()), vo.getInterval(), beginTime, endTime, getFdpTimeBack(vo)); - return getResultValue(vo, analyzeDataConditionVOS, floList, boolList); - } - - - private Object getResultValue(FdpCallbackHistoryTypeVo vo, List analyzeDataConditionVOS, List> floList, List> boolList) { - if (CollectionUtil.isNotEmpty(analyzeDataConditionVOS)) { - if ("float[]".equals(vo.getType())) { - return floatValueBack(analyzeDataConditionVOS, floList, vo.getType()); - } else if ("float[][]".equals(vo.getType())) { - return floatValueBack(analyzeDataConditionVOS, floList, vo.getType()); - } else if ("bool[]".equals(vo.getType())) { - return boolBack(analyzeDataConditionVOS, boolList, vo.getType()); - } else if ("bool[][]".equals(vo.getType())) { - return boolBack(analyzeDataConditionVOS, boolList, vo.getType()); - } - - } else { - return new ArrayList<>(); - } - return null; - } - - public Object floatValue(List analyzeDataConditionVOS, List floList, String type) { - int listCount = 0; - int count = 0; - for (AnalyzeDataConditionVO analyzeDataConditionVO : analyzeDataConditionVOS) { - List list = analyzeDataConditionVO.getList(); - listCount += list.size(); - Float[] floats = new Float[list.size()]; - for (int i = 0; i < list.size(); i++) { - AnalyseDataTaosVO analyseDataTaosVO = list.get(i); - if (StringUtil.isNotBlank(analyseDataTaosVO.getVal())) { - floats[i] = Float.valueOf(analyseDataTaosVO.getVal()); - } else { - floats[i] = null; - count++; - } - } - floList.add(floats); - } - if ("float[]".equals(type)) { - if (listCount == count) { - return new Float[0]; - } else { - return floList.get(0); - } - } else if ("float[][]".equals(type)) { - if (listCount == count) { - return new ArrayList<>(); - } else { - return floList; - } - } - return null; - } - - - public Object bool(List analyzeDataConditionVOS, List boolList, String type) { - int listCount = 0; - int count = 0; - for (AnalyzeDataConditionVO analyzeDataConditionVO : analyzeDataConditionVOS) { - List list = analyzeDataConditionVO.getList(); - listCount += list.size(); - Boolean[] booleans = new Boolean[list.size()]; - for (int i = 0; i < list.size(); i++) { - AnalyseDataTaosVO analyseDataTaosVO = list.get(i); - if (StringUtil.isNotBlank(analyseDataTaosVO.getVal())) { - if ("1".equals(analyseDataTaosVO.getVal())) { - booleans[i] = true; - } else if ("0".equals(analyseDataTaosVO.getVal())) { - booleans[i] = false; - } else { - booleans[i] = null; - count++; - } - } else { - booleans[i] = null; - count++; - } - } - boolList.add(booleans); - } - if ("bool[]".equals(type)) { - if (listCount == count) { - return new Boolean[0]; - } else { - return boolList.get(0); - } - } else if ("bool[][]".equals(type)) { - if (listCount == count) { - return new ArrayList<>(); - } else { - return boolList; - } - } - return null; - } - - - public Object floatValueBack(List analyzeDataConditionVOS, List> listList, String type) { - int listCount = 0; - int count = 0; - for (AnalyzeDataConditionVO analyzeDataConditionVO : analyzeDataConditionVOS) { - List list = analyzeDataConditionVO.getList(); - listCount += list.size(); - List list1 = new ArrayList<>(); - for (int i = 0; i < list.size(); i++) { - AnalyseDataTaosVO analyseDataTaosVO = list.get(i); - DataBackHisFloDataVo vo = new DataBackHisFloDataVo(); - if (StringUtil.isNotBlank(analyseDataTaosVO.getVal())) { - vo.setTime(analyseDataTaosVO.getTs()); - vo.setFloValue(Float.valueOf(analyseDataTaosVO.getVal())); - list1.add(vo); - } else { - vo.setFloValue(null); - count++; - } - } - listList.add(list1); - } - if ("float[][]".equals(type) || "float[]".equals(type)) { - if (listCount == count) { - return new ArrayList<>(); - } else { - return listList; - } - } - return null; - } - - public Object boolBack(List analyzeDataConditionVOS, List> boolList, String type) { - int listCount = 0; - int count = 0; - for (AnalyzeDataConditionVO analyzeDataConditionVO : analyzeDataConditionVOS) { - List list = analyzeDataConditionVO.getList(); - listCount += list.size(); - List list1 = new ArrayList<>(); - for (int i = 0; i < list.size(); i++) { - AnalyseDataTaosVO analyseDataTaosVO = list.get(i); - DataBackHisBoolDataVo vo = new DataBackHisBoolDataVo(); - vo.setTime(analyseDataTaosVO.getTs()); - if (StringUtil.isNotBlank(analyseDataTaosVO.getVal())) { - if ("1".equals(analyseDataTaosVO.getVal())) { - vo.setBoolValue(true); - list1.add(vo); - } else if ("0".equals(analyseDataTaosVO.getVal())) { - vo.setBoolValue(false); - list1.add(vo); - } else { - vo.setBoolValue(null); - count++; - } - } else { - vo.setBoolValue(null); - count++; - } - } - boolList.add(list1); - } - if ("bool[][]".equals(type) || "bool[]".equals(type)) { - if (listCount == count) { - return new ArrayList<>(); - } else { - return boolList; - } - } - return null; - } - - - /** - * 数据取值参数赋值 - * - * @param instanceDeviceCode 实例设备编号 - * @param signages 标识 多个以 “,” 隔开 - * @param map 计算间隔单位 及间隔时间 - * @param ptMode 计数模式 - * @param interval 间隔 - * @return - */ - public List dataParameterValues(String instanceDeviceCode, String signages, Map map, int ptMode, int interval) { - DateTimeFormatter df = DateTimeFormatter.ofPattern(DateUtil.PATTERN_DATETIME); - LocalDateTime beginTime = LocalDateTime.parse(MapUtils.getString(map, "start"), df); - LocalDateTime endTime = LocalDateTime.parse(MapUtils.getString(map, "end"), df); - AnalyseCodeByAnalyseDataPO po = new AnalyseCodeByAnalyseDataPO(); - po.setDeviceCode(instanceDeviceCode); - List list = new ArrayList<>(); - String[] split = signages.split(","); - for (String signage : split) { - AnalyzeDataConditionPO analyzeDataConditionPO = new AnalyzeDataConditionPO(); - analyzeDataConditionPO.setBeginTime(beginTime); - analyzeDataConditionPO.setEndTime(endTime); - analyzeDataConditionPO.setFull(1);//填充 null - analyzeDataConditionPO.setSignages(signage); - analyzeDataConditionPO.setAccessRules(ptMode);//取数规则 0=(整点值/最早值)、1=最大值、2=最小值、3=平均值、4=(累计值/和值)、5=(变化值/差值) 6=最新值 - analyzeDataConditionPO.setSaveTimeType(MapUtils.getInteger(map, "unit"));//【 //周期类型: 0-> s(秒) 1->、m(分)、2->h(小时)3->、d(天)4->、w(周)5->、n(自然月)、6->y(自然年) 】 - analyzeDataConditionPO.setTimeInterval(interval);//间隔 - list.add(analyzeDataConditionPO); - //log.info("-----------------------PT------历史数据参数ONE:" + analyzeDataConditionPO); - } - po.setSignboardConditions(list); - //log.info("-----------------------PT------历史数据参数TWO:" + po); - R> analyzeDataByDeviceCodeAndSignages = deviceDataSearchClient.getAnalyzeDataByAnalyzeCodeAndSignages(po); - if (analyzeDataByDeviceCodeAndSignages.isSuccess() && CollectionUtil.isNotEmpty(analyzeDataByDeviceCodeAndSignages.getData())) { - return analyzeDataByDeviceCodeAndSignages.getData(); - } - return null; - - } - - /** - * 数据取值参数赋值 - * - * @param instanceDeviceCode 实例设备编号 - * @param signages 标识 多个以 “,” 隔开 - * @param ptMode 计数模式 - * @param interval 间隔 - * @return - */ - public List dataParameterValuesBack(String instanceDeviceCode, String signages, int ptMode, int interval, LocalDateTime beginTime, LocalDateTime endTime, int unit) { - AnalyseCodeByAnalyseDataPO po = new AnalyseCodeByAnalyseDataPO(); - po.setDeviceCode(instanceDeviceCode); - List list = new ArrayList<>(); - String[] split = signages.split(","); - for (String signage : split) { - AnalyzeDataConditionPO analyzeDataConditionPO = new AnalyzeDataConditionPO(); - analyzeDataConditionPO.setBeginTime(beginTime); - analyzeDataConditionPO.setEndTime(endTime); - analyzeDataConditionPO.setFull(1);//填充 null - analyzeDataConditionPO.setSignages(signage); - analyzeDataConditionPO.setAccessRules(ptMode);//取数规则 0=(整点值/最早值)、1=最大值、2=最小值、3=平均值、4=(累计值/和值)、5=(变化值/差值) 6=最新值 - analyzeDataConditionPO.setSaveTimeType(unit);//【 //周期类型: 0-> s(秒) 1->、m(分)、2->h(小时)3->、d(天)4->、w(周)5->、n(自然月)、6->y(自然年) 】 - analyzeDataConditionPO.setTimeInterval(interval);//间隔 - list.add(analyzeDataConditionPO); - } - po.setSignboardConditions(list); - R> analyzeDataByDeviceCodeAndSignages = deviceDataSearchClient.getAnalyzeDataByAnalyzeCodeAndSignages(po); - if (analyzeDataByDeviceCodeAndSignages.isSuccess() && CollectionUtil.isNotEmpty(analyzeDataByDeviceCodeAndSignages.getData())) { - return analyzeDataByDeviceCodeAndSignages.getData(); - } - return null; - - } - - - /** - * 计算间隔单位 及间隔时间 - */ - private Map getFdpTimeMap(FdpCallbackHistoryTypeVo vo, Date date, int number) { - Map map = new HashMap<>(); - String start = ""; - String end = ""; - int unit = 0; - vo.getInterval();//采样间隔 - if (DeviceInstanceTypeConstant.FDP_POINT_INTERVAL_UNIT_SEC.equals(vo.getUnit())) { //单位秒 - start = secDate(date, number); - end = secDate(date, 0); - unit = 0; - } else if (DeviceInstanceTypeConstant.FDP_POINT_INTERVAL_UNIT_MIN.equals(vo.getUnit())) {//单位:分 - start = minutlDate(date, number); - end = minutlDate(date, 0); - unit = 1; - } else if (DeviceInstanceTypeConstant.FDP_POINT_INTERVAL_UNIT_HR.equals(vo.getUnit())) {//间隔:小时 - start = hrDate(date, number); - end = hrDate(date, 0); - unit = 2; - } else if (DeviceInstanceTypeConstant.FDP_POINT_INTERVAL_UNIT_DAY.equals(vo.getUnit())) {//间隔:天 - start = dayDate(date, number); - end = dayDate(date, 0); - unit = 3; - } else if (DeviceInstanceTypeConstant.FDP_POINT_INTERVAL_UNIT_MONTH.equals(vo.getUnit())) {//间隔:月 - start = monthDate(date, number); - end = monthDate(date, 0); - unit = 5; - } else if (DeviceInstanceTypeConstant.FDP_POINT_INTERVAL_UNIT_YEAR.equals(vo.getUnit())) {//间隔:年 - start = yearDate(date, number); - end = yearDate(date, 0); - unit = 6; - } - map.put("start", start); - map.put("end", end); - map.put("unit", unit); - return map; - } - - /** - * 计算间隔单位 及间隔时间 - */ - private int getFdpTimeBack(FdpCallbackHistoryTypeVo vo) { - int unit = 0; - if (DeviceInstanceTypeConstant.FDP_POINT_INTERVAL_UNIT_SEC.equals(vo.getUnit())) { //单位秒 - unit = 0; - } else if (DeviceInstanceTypeConstant.FDP_POINT_INTERVAL_UNIT_MIN.equals(vo.getUnit())) {//单位:分 - unit = 1; - } else if (DeviceInstanceTypeConstant.FDP_POINT_INTERVAL_UNIT_HR.equals(vo.getUnit())) {//间隔:小时 - unit = 2; - } else if (DeviceInstanceTypeConstant.FDP_POINT_INTERVAL_UNIT_DAY.equals(vo.getUnit())) {//间隔:天 - unit = 3; - } else if (DeviceInstanceTypeConstant.FDP_POINT_INTERVAL_UNIT_MONTH.equals(vo.getUnit())) {//间隔:月 - unit = 5; - } else if (DeviceInstanceTypeConstant.FDP_POINT_INTERVAL_UNIT_YEAR.equals(vo.getUnit())) {//间隔:年 - unit = 6; - } - - return unit; - } - - /** - * 获取计数模式 - * - * @param mode - * @return - */ - private int getCountingMode(String mode) { - int ptMode = 6; - if (DeviceInstanceTypeConstant.FDP_POINT_COUNTING_MODE_CURRENT.equals(mode)) {//采样时刻点的实际值 - ptMode = 6; - } else if (DeviceInstanceTypeConstant.FDP_POINT_COUNTING_MODE_AVG.equals(mode)) {//采样间隔内的均值 - ptMode = 3; - } else if (DeviceInstanceTypeConstant.FDP_POINT_COUNTING_MODE_MIN.equals(mode)) {//采样间隔内的最小值 - ptMode = 2; - } else if (DeviceInstanceTypeConstant.FDP_POINT_COUNTING_MODE_MAX.equals(mode)) {//采样间隔内的最大值 - ptMode = 1; - } else if (DeviceInstanceTypeConstant.FDP_POINT_COUNTING_MODE_SUM.equals(mode)) {//采样间隔内的所有值的累加 - ptMode = 4; - } - return ptMode; - } - - /** - * 年 - */ - private String yearDate(Date date, int i) {//减多少年 - String reStr = ""; - try { - SimpleDateFormat sdf = new SimpleDateFormat("yyyy-01-01 00:00:00");//"yyyy-MM-dd HH:mm:ss" - Calendar rightNow = Calendar.getInstance(); - rightNow.setTime(date); - rightNow.add(Calendar.YEAR, -i); - Date dt1 = rightNow.getTime(); - reStr = sdf.format(dt1); - } catch (Exception e) { - e.printStackTrace(); - } - return reStr; - } - - /** - * 月 - */ - private String monthDate(Date date, int i) {//减多少月 - String reStr = ""; - try { - SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-01 00:00:00");//"yyyy-MM-dd HH:mm:ss" - Calendar rightNow = Calendar.getInstance(); - rightNow.setTime(date); - rightNow.add(Calendar.MONTH, -i); - Date dt1 = rightNow.getTime(); - reStr = sdf.format(dt1); - } catch (Exception e) { - e.printStackTrace(); - } - return reStr; - } - - /** - * 天 - */ - private String dayDate(Date date, int i) {//天 - String reStr = ""; - try { - SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd 00:00:00");//"yyyy-MM-dd HH:mm:ss" - Calendar rightNow = Calendar.getInstance(); - rightNow.setTime(date); - rightNow.add(Calendar.DAY_OF_MONTH, -i); - Date dt1 = rightNow.getTime(); - reStr = sdf.format(dt1); - } catch (Exception e) { - e.printStackTrace(); - } - return reStr; - } - - /** - * 小时 - */ - private String hrDate(Date date, int i) {//减多少小时 - String reStr = ""; - try { - SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:00:00");//"yyyy-MM-dd HH:mm:ss" - Calendar rightNow = Calendar.getInstance(); - rightNow.setTime(date); - rightNow.add(Calendar.HOUR, -i); - Date dt1 = rightNow.getTime(); - reStr = sdf.format(dt1); - } catch (Exception e) { - e.printStackTrace(); - } - return reStr; - } - - - /** - * 分钟 - */ - private String minutlDate(Date date, int i) {//减多少分钟 - String reStr = ""; - try { - SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:00");//"yyyy-MM-dd HH:mm:ss" - Calendar rightNow = Calendar.getInstance(); - rightNow.setTime(date); - rightNow.add(Calendar.MINUTE, -i); - Date dt1 = rightNow.getTime(); - reStr = sdf.format(dt1); - } catch (Exception e) { - e.printStackTrace(); - } - return reStr; - } - - - /** - * 秒 - */ - private String secDate(Date date, int i) {//减多少秒 - String reStr = ""; - try { - SimpleDateFormat sdf = new SimpleDateFormat(DateUtil.PATTERN_DATETIME);//"yyyy-MM-dd HH:mm:ss" - Calendar rightNow = Calendar.getInstance(); - rightNow.setTime(date); - rightNow.add(Calendar.SECOND, -i); - Date dt1 = rightNow.getTime(); - reStr = sdf.format(dt1); - } catch (Exception e) { - e.printStackTrace(); - } - return reStr; - } - - /** - * 获取传递该数据点历史数据的数据格式 - * - * @param hashMaps - * @return - */ - private List transformFormatPartition(List> hashMaps, FdpMonitorEntity fdpMonitorEntity) { - List voList = new ArrayList<>(); - if (ObjectUtil.isNotEmpty(hashMaps)) { - for (HashMap hashMap : hashMaps) { - FdpCallbackHistoryTypeVo vo = new FdpCallbackHistoryTypeVo(); - if (ObjectUtil.isNotEmpty(hashMap.get("INTERVAL"))) { - vo.setFaultId(hashMap.get("FAULT_ID") + ""); - vo.setInterval(Integer.valueOf(hashMap.get("INTERVAL") + "")); - vo.setMode(hashMap.get("MODE").toString()); - vo.setNum(Integer.valueOf(hashMap.get("NUM") + "")); - vo.setType(hashMap.get("TYPE") + ""); - vo.setUnit(hashMap.get("UNIT") + ""); - vo.setCode(fdpMonitorEntity.getInstanceDeviceCode()); - vo.setSignages(fdpMonitorEntity.getImsSignages()); - vo.setMonitorFdpIdId(fdpMonitorEntity.getFdpId()); - voList.add(vo); - } - } - } - return voList; - } - - - /** - * 获取传递该数据点历史数据的数据格式 数据追溯 - * - * @param hashMaps - * @return - */ - private FdpCallbackHistoryTypeVo transformFormatBack(List> hashMaps, String faultId) { - FdpCallbackHistoryTypeVo vo = new FdpCallbackHistoryTypeVo(); - if (ObjectUtil.isNotEmpty(hashMaps)) { - for (HashMap hashMap : hashMaps) { - if (ObjectUtil.isNotEmpty(hashMap.get("INTERVAL"))) { - String faultid1 = hashMap.get("FAULT_ID").toString(); - if (faultid1.equals(faultId)) { - vo.setFaultId(hashMap.get("FAULT_ID") + ""); - vo.setInterval(Integer.valueOf(hashMap.get("INTERVAL") + "")); - vo.setMode(hashMap.get("MODE").toString()); - vo.setNum(Integer.valueOf(hashMap.get("NUM") + "")); - vo.setType(hashMap.get("TYPE") + ""); - vo.setUnit(hashMap.get("UNIT") + ""); - break; - } - } - } - } - return vo; - } + } else { + throw new ServiceException(nextStepWithTree.getMsg()); + } + //nextStepRespR.getData().setTaskId(fdpTaskDTO.getId()); + return nextStepWithTree; + } + + + /** + * 获取实时数据 + * + * @param realDataList + * @return + */ + @Override + public List getRealTimeData(List realDataList) { + List listMap = new ArrayList<>(); + List list = realDataList.stream().filter(o -> null != o.getCallbackRealType()).collect(Collectors.toList()); + if (CollectionUtil.isNotEmpty(list)) { + Map> collectMap = list.stream().collect(Collectors.groupingBy(FdpMonitorEntity::getInstanceDeviceCode)); + for (String codeKey : collectMap.keySet()) { + List fdpMonitorEntityList = collectMap.get(codeKey); + String imsSignages = ""; + int count = 0; + for (FdpMonitorEntity fdpMonitorEntity : fdpMonitorEntityList) { + if (count == 0) { + imsSignages = fdpMonitorEntity.getImsSignages(); + } else { + imsSignages += "," + fdpMonitorEntity.getImsSignages(); + } + count++; + } + fdpMonitorEntityList.get(0).getInstanceDeviceCode(); + List valuePartition = this.getRealTimeDataValuePartition(fdpMonitorEntityList.get(0).getInstanceDeviceCode(), imsSignages); + if (CollectionUtil.isNotEmpty(valuePartition)) { + for (FdpMonitorEntity fdpMonitorEntity : fdpMonitorEntityList) { + List data = new ArrayList<>(); + for (String signage : fdpMonitorEntity.getImsSignages().split(",")) { + List collect = valuePartition.stream().filter(o -> o.getSignage().equals(signage)).collect(Collectors.toList()); + data.addAll(collect); + } + FdpRealTimeDataVo vo = this.getValuePartition(fdpMonitorEntity, data); + if (ObjectUtil.isNotEmpty(vo.getData())) { + vo.setId(fdpMonitorEntity.getFdpId()); + vo.setName(fdpMonitorEntity.getName()); + vo.setOrd(fdpMonitorEntity.getOrd()); + vo.setTime(DateUtil.format(new Date(), DateUtil.PATTERN_DATETIME)); + vo.setFaultIds(JSONObject.parseObject(fdpMonitorEntity.getCallbackRealType(), new TypeReference>>() { + })); + listMap.add(vo); + } + } + } + } + } + return listMap; + } + + public List> getRealTimeDataBack(List fdpMonitorEntityList) { + List list = fdpMonitorEntityList.stream().filter(o -> null != o.getCallbackRealType()).collect(Collectors.toList()); + List> listMap = new ArrayList<>(); + if (CollectionUtil.isNotEmpty(list)) { + if (CollectionUtil.isNotEmpty(list)) { + for (int i = 0; i < list.size(); i++) { + Map map = this.getValue(list.get(i)); + map.put("id", list.get(i).getFdpId()); + map.put("name", list.get(i).getName()); + map.put("ord", list.get(i).getOrd()); + map.put("time", DateUtil.format(new Date(), DateUtil.PATTERN_DATETIME)); + listMap.add(map); + } + } + } + return listMap; + } + + + public Map getValue(FdpMonitorEntity fdpMonitorEntity) { + Map maps = new HashMap(); + Map map = new HashMap<>(); + RealDataSearchPO realDataSearchPO = new RealDataSearchPO(); + String[] signages = fdpMonitorEntity.getImsSignages().split(","); + realDataSearchPO.setAnalyzeCode(fdpMonitorEntity.getInstanceDeviceCode()); + realDataSearchPO.setSignages(Arrays.asList(signages)); + R> realDataByDeviceCode = null; + try { + realDataByDeviceCode = realDataSearchClient.getRealDataByAnalyzeCode(realDataSearchPO); + } catch (Exception e) { + throw new RuntimeException(e.getMessage()); + } + if (realDataByDeviceCode.isSuccess() && CollectionUtil.isNotEmpty(realDataByDeviceCode.getData())) { + List data = realDataByDeviceCode.getData(); + this.setRealTimeDataFormatBack(map, fdpMonitorEntity, data); + } + maps.put("data", map); + return maps; + } + + public List getRealTimeDataValuePartition(String code, String signages) { + RealDataSearchPO realDataSearchPO = new RealDataSearchPO(); + String[] split = signages.split(","); + realDataSearchPO.setAnalyzeCode(code); + realDataSearchPO.setSignages(Arrays.asList(split)); + R> realDataByDeviceCode = null; + try { + realDataByDeviceCode = realDataSearchClient.getRealDataByAnalyzeCode(realDataSearchPO); + } catch (Exception e) { + throw new RuntimeException(e.getMessage()); + } + if (realDataByDeviceCode.isSuccess() && CollectionUtil.isNotEmpty(realDataByDeviceCode.getData())) { + return realDataByDeviceCode.getData(); + } + return null; + } + + public FdpRealTimeDataVo getValuePartition(FdpMonitorEntity fdpMonitorEntity, List data) { + Map map = new HashMap<>(); + FdpRealTimeDataVo vo = new FdpRealTimeDataVo(); + this.setRealTimeDataFormat(map, fdpMonitorEntity, data); + if (ObjectUtil.isNotEmpty(map.get("value_array")) || ObjectUtil.isNotEmpty(map.get("value")) + || ObjectUtil.isNotEmpty(map.get("state")) || ObjectUtil.isNotEmpty(map.get("state_array"))) { + vo.setData(map); + } + return vo; + } + + + private void setRealTimeDataFormatBack(Map map, FdpMonitorEntity fdpMonitorEntity, List data) { + Float flo[] = new Float[fdpMonitorEntity.getImsRealIds().split(",").length]; + int count = 0; + if ("float[]".equals(fdpMonitorEntity.getCallbackType())) { + for (int i = 0; i < data.size(); i++) { + FieldsData datum = data.get(i); + if (StringUtil.isNotBlank(datum.getValue())) { + flo[i] = Float.valueOf(datum.getValue()); + } else { + flo[i] = null; + count++; + } + } + if (data.size() == count) { + map.put("value_array", new ArrayList<>()); + } else { + map.put("value_array", flo); + } + } else if ("float".equals(fdpMonitorEntity.getCallbackType())) { + Float floValue = null; + for (FieldsData datum : data) { + if (StringUtil.isNotBlank(datum.getValue())) { + floValue = Float.valueOf(datum.getValue()); + } + } + map.put("value", floValue); + } else if ("bool".equals(fdpMonitorEntity.getCallbackType())) { + Boolean bool = null; + for (FieldsData datum : data) { + if (StringUtil.isNotBlank(datum.getValue())) { + if ("1".equals(datum.getValue())) { + bool = true; + } else if ("0".equals(datum.getValue())) { + bool = false; + } + } + } + map.put("state", bool); + } else if ("bool[]".equals(fdpMonitorEntity.getCallbackType())) { + Boolean booleans[] = new Boolean[fdpMonitorEntity.getImsRealIds().split(",").length]; + for (int i = 0; i < data.size(); i++) { + FieldsData datum = data.get(i); + if (StringUtil.isNotBlank(datum.getValue())) { + if ("1".equals(datum.getValue())) { + booleans[i] = true; + } else if ("0".equals(datum.getValue())) { + booleans[i] = false; + } + } else { + booleans[i] = null; + count++; + } + } + if (data.size() == count) { + map.put("state_array", new ArrayList<>()); + } else { + map.put("state_array", booleans); + } + } + } + + + private void setRealTimeDataFormat(Map map, FdpMonitorEntity fdpMonitorEntity, List data) { + List list = new ArrayList<>(); + int count = 0; + if ("float[]".equals(fdpMonitorEntity.getCallbackType())) { + for (int i = 0; i < data.size(); i++) { + FieldsData datum = data.get(i); + RealTimeDataFloVo vo = new RealTimeDataFloVo(); + if (StringUtil.isNotBlank(datum.getValue())) { + vo.setValue(Float.valueOf(datum.getValue())); + } else { + count++; + } + vo.setTime(datum.getTime()); + list.add(vo); + } + if (data.size() == count) { + map.put("value_array", null); + } else { + map.put("value_array", list); + } + } else if ("float".equals(fdpMonitorEntity.getCallbackType())) { + RealTimeDataFloVo vo = new RealTimeDataFloVo(); + for (FieldsData datum : data) { + if (StringUtil.isNotBlank(datum.getValue())) { + vo.setValue(Float.valueOf(datum.getValue())); + } + vo.setTime(datum.getTime()); + } + if (StringUtil.isNotBlank(vo.getTime())) { + map.put("value", vo); + } + } else if ("bool".equals(fdpMonitorEntity.getCallbackType())) { + RealTimeDataBoolVo vo = new RealTimeDataBoolVo(); + for (FieldsData datum : data) { + if (StringUtil.isNotBlank(datum.getValue())) { + if ("1".equals(datum.getValue())) { + vo.setValue(true); + } else if ("0".equals(datum.getValue())) { + vo.setValue(false); + } + } + vo.setTime(datum.getTime()); + } + if (StringUtil.isNotBlank(vo.getTime())) { + map.put("state", vo); + } + } else if ("bool[]".equals(fdpMonitorEntity.getCallbackType())) { + List voList = new ArrayList<>(); + for (int i = 0; i < data.size(); i++) { + FieldsData datum = data.get(i); + RealTimeDataBoolVo vo = new RealTimeDataBoolVo(); + if (StringUtil.isNotBlank(datum.getValue())) { + if ("1".equals(datum.getValue())) { + vo.setValue(true); + } else if ("0".equals(datum.getValue())) { + vo.setValue(false); + } + } else { + count++; + } + vo.setTime(datum.getTime()); + voList.add(vo); + } + if (data.size() == count) { + map.put("state_array", null); + } else { + map.put("state_array", voList); + } + } + } + + + public Map> getHisKeyValueDataPartition(List fdpMonitorEntityList, Date date, String code) { + List voList = new ArrayList<>(); + for (FdpMonitorEntity fdpMonitorEntity : fdpMonitorEntityList) { + List> hashMaps = JSONObject.parseObject(fdpMonitorEntity.getCallbackHistoryType(), new TypeReference>>() { + }); + List vos = transformFormatPartition(hashMaps, fdpMonitorEntity); + if (CollectionUtil.isEmpty(vos)) { + continue; + } + voList.addAll(vos); + } + //获取传递该数据点历史数据的数据格式 + Map> collect = voList.stream().collect(Collectors.groupingBy(join -> join.getInterval() + "_" + join.getNum() + "_" + join.getMode() + "_" + join.getUnit())); + //获取绑定的realId + return this.getRealIdHisValueMapPartition(collect, code, date); + } + + /** + * 数据追溯 + * + * @param fdpMonitorEntity + * @param date + * @return + */ + public Map getHisKeyValueDataBack(FdpMonitorEntity fdpMonitorEntity, Date date, String faultId) { + List> hashMaps = JSONObject.parseObject(fdpMonitorEntity.getCallbackHistoryType(), new TypeReference>>() { + }); + //获取传递该数据点历史数据的数据格式 + FdpCallbackHistoryTypeVo vo = transformFormatBack(hashMaps, faultId); + if (vo.getNum() <= 1) { + return null; + } + //获取绑定的realId + return getRealIdHisValueMapBack(vo, fdpMonitorEntity.getInstanceDeviceCode(), fdpMonitorEntity.getImsSignages(), date); + } + + /** + * 统计月报-数据追溯 + * + * @param fdpMonitorEntity + * @return + */ + public Map getHisKeyValueMonthlyDataBack(FdpMonitorEntity fdpMonitorEntity, String faultId, LocalDateTime beginTime, LocalDateTime endTime) { + List> hashMaps = JSONObject.parseObject(fdpMonitorEntity.getCallbackHistoryType(), new TypeReference>>() { + }); + //获取传递该数据点历史数据的数据格式 + FdpCallbackHistoryTypeVo vo = transformFormatBack(hashMaps, faultId); + if (vo.getNum() <= 1) { + return null; + } + Map maps = new HashMap<>(); + Object value = this.relevanceFaultObjectMonthlyBack(vo, fdpMonitorEntity.getInstanceDeviceCode(), fdpMonitorEntity.getImsSignages(), beginTime, endTime); + maps.put(vo.getFaultId(), value); + return maps; + } + + public Map> getRealIdHisValueMapPartition(Map> collect, String instanceDeviceCode, Date date) { + Map> resultMap = new HashMap<>(); + for (String key : collect.keySet()) { + List vos = collect.get(key); + String imsSignages = ""; + int count = 0; + for (FdpCallbackHistoryTypeVo vo : vos) { + if (count == 0) { + imsSignages = vo.getSignages(); + } else { + imsSignages += "," + vo.getSignages(); + } + count++; + } + List analyzeDataConditionVOS = this.dataParameterValues(instanceDeviceCode, imsSignages, getFdpTimeMap(vos.get(0), date, vos.get(0).getNum()), getCountingMode(vos.get(0).getMode()), vos.get(0).getInterval()); + if (CollectionUtil.isNotEmpty(analyzeDataConditionVOS)) { + for (FdpCallbackHistoryTypeVo vo : vos) { + List data = new ArrayList<>(); + for (String signage : vo.getSignages().split(",")) { + data.addAll(analyzeDataConditionVOS.stream().filter(o -> o.getSignage().equals(signage)).collect(Collectors.toList())); + } + vo.setData(data); + } + } + Map> collect1 = vos.stream().collect(Collectors.groupingBy(FdpCallbackHistoryTypeVo::getMonitorFdpIdId)); + for (String fdpIdKey : collect1.keySet()) { + Map maps = new HashMap<>(); + + List vos1 = collect1.get(fdpIdKey); + for (FdpCallbackHistoryTypeVo fdpCallbackHistoryTypeVo : vos1) { + Object value = this.relevanceFaultObjectPartition(fdpCallbackHistoryTypeVo); + String jsonString = JSONObject.toJSONString(value); + Object stringListMap = JSONObject.parseObject(jsonString, new TypeReference() { + }); + maps.put(fdpCallbackHistoryTypeVo.getFaultId(), stringListMap); + } + String jsonString = JSONObject.toJSONString(maps); + Map stringListMap = JSONObject.parseObject(jsonString, new TypeReference>() { + }); + resultMap.put(fdpIdKey, stringListMap); + } + } + return resultMap; + } + + /** + * 数据追溯 + * + * @param instanceDeviceCode + * @param signages + * @param date + * @return + */ + public Map getRealIdHisValueMapBack(FdpCallbackHistoryTypeVo vo, String instanceDeviceCode, String signages, Date date) { + Map maps = new HashMap<>(); + Object value = relevanceFaultObjectBack(vo, instanceDeviceCode, signages, date); + maps.put(vo.getFaultId(), value); + return maps; + } + + /** + * 关联故障 根据故障间隔类型 时间 采集方式 去数据库查询 + * + * @param vo + * @return + */ + private Object relevanceFaultObjectPartition(FdpCallbackHistoryTypeVo vo) { + List floList = new ArrayList<>(); + List boolList = new ArrayList<>(); + if (CollectionUtil.isNotEmpty(vo.getData())) { + if ("float[]".equals(vo.getType())) { + return floatValue(vo.getData(), floList, vo.getType()); + } else if ("float[][]".equals(vo.getType())) { + return floatValue(vo.getData(), floList, vo.getType()); + } else if ("bool[]".equals(vo.getType())) { + return bool(vo.getData(), boolList, vo.getType()); + } else if ("bool[][]".equals(vo.getType())) { + return bool(vo.getData(), boolList, vo.getType()); + } + + } else { + return new ArrayList<>(); + } + return null; + } + + /** + * 关联故障 根据故障间隔类型 时间 采集方式 去数据库查询 + * + * @param vo + * @return + */ + private Object relevanceFaultObjectBack(FdpCallbackHistoryTypeVo vo, String instanceDeviceCode, String signages, Date date) { + List> floList = new ArrayList<>(); + List> boolList = new ArrayList<>(); + List analyzeDataConditionVOS = dataParameterValues(instanceDeviceCode, signages, getFdpTimeMap(vo, date, vo.getNum()), getCountingMode(vo.getMode()), vo.getInterval()); + return getResultValue(vo, analyzeDataConditionVOS, floList, boolList); + } + + /** + * 统计月报 - 数据追溯 + * 关联故障 根据故障间隔类型 时间 采集方式 去数据库查询 + * + * @param vo + * @return + */ + private Object relevanceFaultObjectMonthlyBack(FdpCallbackHistoryTypeVo vo, String instanceDeviceCode, String signages, LocalDateTime beginTime, LocalDateTime endTime) { + List> floList = new ArrayList<>(); + List> boolList = new ArrayList<>(); + List analyzeDataConditionVOS = dataParameterValuesBack(instanceDeviceCode, signages, getCountingMode(vo.getMode()), vo.getInterval(), beginTime, endTime, getFdpTimeBack(vo)); + return getResultValue(vo, analyzeDataConditionVOS, floList, boolList); + } + + + private Object getResultValue(FdpCallbackHistoryTypeVo vo, List analyzeDataConditionVOS, List> floList, List> boolList) { + if (CollectionUtil.isNotEmpty(analyzeDataConditionVOS)) { + if ("float[]".equals(vo.getType())) { + return floatValueBack(analyzeDataConditionVOS, floList, vo.getType()); + } else if ("float[][]".equals(vo.getType())) { + return floatValueBack(analyzeDataConditionVOS, floList, vo.getType()); + } else if ("bool[]".equals(vo.getType())) { + return boolBack(analyzeDataConditionVOS, boolList, vo.getType()); + } else if ("bool[][]".equals(vo.getType())) { + return boolBack(analyzeDataConditionVOS, boolList, vo.getType()); + } + + } else { + return new ArrayList<>(); + } + return null; + } + + public Object floatValue(List analyzeDataConditionVOS, List floList, String type) { + int listCount = 0; + int count = 0; + for (AnalyzeDataConditionVO analyzeDataConditionVO : analyzeDataConditionVOS) { + List list = analyzeDataConditionVO.getList(); + listCount += list.size(); + Float[] floats = new Float[list.size()]; + for (int i = 0; i < list.size(); i++) { + AnalyseDataTaosVO analyseDataTaosVO = list.get(i); + if (StringUtil.isNotBlank(analyseDataTaosVO.getVal())) { + floats[i] = Float.valueOf(analyseDataTaosVO.getVal()); + } else { + floats[i] = null; + count++; + } + } + floList.add(floats); + } + if ("float[]".equals(type)) { + if (listCount == count) { + return new Float[0]; + } else { + return floList.get(0); + } + } else if ("float[][]".equals(type)) { + if (listCount == count) { + return new ArrayList<>(); + } else { + return floList; + } + } + return null; + } + + + public Object bool(List analyzeDataConditionVOS, List boolList, String type) { + int listCount = 0; + int count = 0; + for (AnalyzeDataConditionVO analyzeDataConditionVO : analyzeDataConditionVOS) { + List list = analyzeDataConditionVO.getList(); + listCount += list.size(); + Boolean[] booleans = new Boolean[list.size()]; + for (int i = 0; i < list.size(); i++) { + AnalyseDataTaosVO analyseDataTaosVO = list.get(i); + if (StringUtil.isNotBlank(analyseDataTaosVO.getVal())) { + if ("1".equals(analyseDataTaosVO.getVal())) { + booleans[i] = true; + } else if ("0".equals(analyseDataTaosVO.getVal())) { + booleans[i] = false; + } else { + booleans[i] = null; + count++; + } + } else { + booleans[i] = null; + count++; + } + } + boolList.add(booleans); + } + if ("bool[]".equals(type)) { + if (listCount == count) { + return new Boolean[0]; + } else { + return boolList.get(0); + } + } else if ("bool[][]".equals(type)) { + if (listCount == count) { + return new ArrayList<>(); + } else { + return boolList; + } + } + return null; + } + + + public Object floatValueBack(List analyzeDataConditionVOS, List> listList, String type) { + int listCount = 0; + int count = 0; + for (AnalyzeDataConditionVO analyzeDataConditionVO : analyzeDataConditionVOS) { + List list = analyzeDataConditionVO.getList(); + listCount += list.size(); + List list1 = new ArrayList<>(); + for (int i = 0; i < list.size(); i++) { + AnalyseDataTaosVO analyseDataTaosVO = list.get(i); + DataBackHisFloDataVo vo = new DataBackHisFloDataVo(); + if (StringUtil.isNotBlank(analyseDataTaosVO.getVal())) { + vo.setTime(analyseDataTaosVO.getTs()); + vo.setFloValue(Float.valueOf(analyseDataTaosVO.getVal())); + list1.add(vo); + } else { + vo.setFloValue(null); + count++; + } + } + listList.add(list1); + } + if ("float[][]".equals(type) || "float[]".equals(type)) { + if (listCount == count) { + return new ArrayList<>(); + } else { + return listList; + } + } + return null; + } + + public Object boolBack(List analyzeDataConditionVOS, List> boolList, String type) { + int listCount = 0; + int count = 0; + for (AnalyzeDataConditionVO analyzeDataConditionVO : analyzeDataConditionVOS) { + List list = analyzeDataConditionVO.getList(); + listCount += list.size(); + List list1 = new ArrayList<>(); + for (int i = 0; i < list.size(); i++) { + AnalyseDataTaosVO analyseDataTaosVO = list.get(i); + DataBackHisBoolDataVo vo = new DataBackHisBoolDataVo(); + vo.setTime(analyseDataTaosVO.getTs()); + if (StringUtil.isNotBlank(analyseDataTaosVO.getVal())) { + if ("1".equals(analyseDataTaosVO.getVal())) { + vo.setBoolValue(true); + list1.add(vo); + } else if ("0".equals(analyseDataTaosVO.getVal())) { + vo.setBoolValue(false); + list1.add(vo); + } else { + vo.setBoolValue(null); + count++; + } + } else { + vo.setBoolValue(null); + count++; + } + } + boolList.add(list1); + } + if ("bool[][]".equals(type) || "bool[]".equals(type)) { + if (listCount == count) { + return new ArrayList<>(); + } else { + return boolList; + } + } + return null; + } + + + /** + * 数据取值参数赋值 + * + * @param instanceDeviceCode 实例设备编号 + * @param signages 标识 多个以 “,” 隔开 + * @param map 计算间隔单位 及间隔时间 + * @param ptMode 计数模式 + * @param interval 间隔 + * @return + */ + public List dataParameterValues(String instanceDeviceCode, String signages, Map map, int ptMode, int interval) { + DateTimeFormatter df = DateTimeFormatter.ofPattern(DateUtil.PATTERN_DATETIME); + LocalDateTime beginTime = LocalDateTime.parse(MapUtils.getString(map, "start"), df); + LocalDateTime endTime = LocalDateTime.parse(MapUtils.getString(map, "end"), df); + AnalyseCodeByAnalyseDataPO po = new AnalyseCodeByAnalyseDataPO(); + po.setDeviceCode(instanceDeviceCode); + List list = new ArrayList<>(); + String[] split = signages.split(","); + for (String signage : split) { + AnalyzeDataConditionPO analyzeDataConditionPO = new AnalyzeDataConditionPO(); + analyzeDataConditionPO.setBeginTime(beginTime); + analyzeDataConditionPO.setEndTime(endTime); + analyzeDataConditionPO.setFull(1);//填充 null + analyzeDataConditionPO.setSignages(signage); + analyzeDataConditionPO.setAccessRules(ptMode);//取数规则 0=(整点值/最早值)、1=最大值、2=最小值、3=平均值、4=(累计值/和值)、5=(变化值/差值) 6=最新值 + analyzeDataConditionPO.setSaveTimeType(MapUtils.getInteger(map, "unit"));//【 //周期类型: 0-> s(秒) 1->、m(分)、2->h(小时)3->、d(天)4->、w(周)5->、n(自然月)、6->y(自然年) 】 + analyzeDataConditionPO.setTimeInterval(interval);//间隔 + list.add(analyzeDataConditionPO); + //log.info("-----------------------PT------历史数据参数ONE:" + analyzeDataConditionPO); + } + po.setSignboardConditions(list); + //log.info("-----------------------PT------历史数据参数TWO:" + po); + R> analyzeDataByDeviceCodeAndSignages = deviceDataSearchClient.getAnalyzeDataByAnalyzeCodeAndSignages(po); + if (analyzeDataByDeviceCodeAndSignages.isSuccess() && CollectionUtil.isNotEmpty(analyzeDataByDeviceCodeAndSignages.getData())) { + return analyzeDataByDeviceCodeAndSignages.getData(); + } + return null; + + } + + /** + * 数据取值参数赋值 + * + * @param instanceDeviceCode 实例设备编号 + * @param signages 标识 多个以 “,” 隔开 + * @param ptMode 计数模式 + * @param interval 间隔 + * @return + */ + public List dataParameterValuesBack(String instanceDeviceCode, String signages, int ptMode, int interval, LocalDateTime beginTime, LocalDateTime endTime, int unit) { + AnalyseCodeByAnalyseDataPO po = new AnalyseCodeByAnalyseDataPO(); + po.setDeviceCode(instanceDeviceCode); + List list = new ArrayList<>(); + String[] split = signages.split(","); + for (String signage : split) { + AnalyzeDataConditionPO analyzeDataConditionPO = new AnalyzeDataConditionPO(); + analyzeDataConditionPO.setBeginTime(beginTime); + analyzeDataConditionPO.setEndTime(endTime); + analyzeDataConditionPO.setFull(1);//填充 null + analyzeDataConditionPO.setSignages(signage); + analyzeDataConditionPO.setAccessRules(ptMode);//取数规则 0=(整点值/最早值)、1=最大值、2=最小值、3=平均值、4=(累计值/和值)、5=(变化值/差值) 6=最新值 + analyzeDataConditionPO.setSaveTimeType(unit);//【 //周期类型: 0-> s(秒) 1->、m(分)、2->h(小时)3->、d(天)4->、w(周)5->、n(自然月)、6->y(自然年) 】 + analyzeDataConditionPO.setTimeInterval(interval);//间隔 + list.add(analyzeDataConditionPO); + } + po.setSignboardConditions(list); + R> analyzeDataByDeviceCodeAndSignages = deviceDataSearchClient.getAnalyzeDataByAnalyzeCodeAndSignages(po); + if (analyzeDataByDeviceCodeAndSignages.isSuccess() && CollectionUtil.isNotEmpty(analyzeDataByDeviceCodeAndSignages.getData())) { + return analyzeDataByDeviceCodeAndSignages.getData(); + } + return null; + + } + + + /** + * 计算间隔单位 及间隔时间 + */ + private Map getFdpTimeMap(FdpCallbackHistoryTypeVo vo, Date date, int number) { + Map map = new HashMap<>(); + String start = ""; + String end = ""; + int unit = 0; + vo.getInterval();//采样间隔 + if (DeviceInstanceTypeConstant.FDP_POINT_INTERVAL_UNIT_SEC.equals(vo.getUnit())) { //单位秒 + start = secDate(date, number); + end = secDate(date, 0); + unit = 0; + } else if (DeviceInstanceTypeConstant.FDP_POINT_INTERVAL_UNIT_MIN.equals(vo.getUnit())) {//单位:分 + start = minutlDate(date, number); + end = minutlDate(date, 0); + unit = 1; + } else if (DeviceInstanceTypeConstant.FDP_POINT_INTERVAL_UNIT_HR.equals(vo.getUnit())) {//间隔:小时 + start = hrDate(date, number); + end = hrDate(date, 0); + unit = 2; + } else if (DeviceInstanceTypeConstant.FDP_POINT_INTERVAL_UNIT_DAY.equals(vo.getUnit())) {//间隔:天 + start = dayDate(date, number); + end = dayDate(date, 0); + unit = 3; + } else if (DeviceInstanceTypeConstant.FDP_POINT_INTERVAL_UNIT_MONTH.equals(vo.getUnit())) {//间隔:月 + start = monthDate(date, number); + end = monthDate(date, 0); + unit = 5; + } else if (DeviceInstanceTypeConstant.FDP_POINT_INTERVAL_UNIT_YEAR.equals(vo.getUnit())) {//间隔:年 + start = yearDate(date, number); + end = yearDate(date, 0); + unit = 6; + } + map.put("start", start); + map.put("end", end); + map.put("unit", unit); + return map; + } + + /** + * 计算间隔单位 及间隔时间 + */ + private int getFdpTimeBack(FdpCallbackHistoryTypeVo vo) { + int unit = 0; + if (DeviceInstanceTypeConstant.FDP_POINT_INTERVAL_UNIT_SEC.equals(vo.getUnit())) { //单位秒 + unit = 0; + } else if (DeviceInstanceTypeConstant.FDP_POINT_INTERVAL_UNIT_MIN.equals(vo.getUnit())) {//单位:分 + unit = 1; + } else if (DeviceInstanceTypeConstant.FDP_POINT_INTERVAL_UNIT_HR.equals(vo.getUnit())) {//间隔:小时 + unit = 2; + } else if (DeviceInstanceTypeConstant.FDP_POINT_INTERVAL_UNIT_DAY.equals(vo.getUnit())) {//间隔:天 + unit = 3; + } else if (DeviceInstanceTypeConstant.FDP_POINT_INTERVAL_UNIT_MONTH.equals(vo.getUnit())) {//间隔:月 + unit = 5; + } else if (DeviceInstanceTypeConstant.FDP_POINT_INTERVAL_UNIT_YEAR.equals(vo.getUnit())) {//间隔:年 + unit = 6; + } + + return unit; + } + + /** + * 获取计数模式 + * + * @param mode + * @return + */ + private int getCountingMode(String mode) { + int ptMode = 6; + if (DeviceInstanceTypeConstant.FDP_POINT_COUNTING_MODE_CURRENT.equals(mode)) {//采样时刻点的实际值 + ptMode = 6; + } else if (DeviceInstanceTypeConstant.FDP_POINT_COUNTING_MODE_AVG.equals(mode)) {//采样间隔内的均值 + ptMode = 3; + } else if (DeviceInstanceTypeConstant.FDP_POINT_COUNTING_MODE_MIN.equals(mode)) {//采样间隔内的最小值 + ptMode = 2; + } else if (DeviceInstanceTypeConstant.FDP_POINT_COUNTING_MODE_MAX.equals(mode)) {//采样间隔内的最大值 + ptMode = 1; + } else if (DeviceInstanceTypeConstant.FDP_POINT_COUNTING_MODE_SUM.equals(mode)) {//采样间隔内的所有值的累加 + ptMode = 4; + } + return ptMode; + } + + /** + * 年 + */ + private String yearDate(Date date, int i) {//减多少年 + String reStr = ""; + try { + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-01-01 00:00:00");//"yyyy-MM-dd HH:mm:ss" + Calendar rightNow = Calendar.getInstance(); + rightNow.setTime(date); + rightNow.add(Calendar.YEAR, -i); + Date dt1 = rightNow.getTime(); + reStr = sdf.format(dt1); + } catch (Exception e) { + e.printStackTrace(); + } + return reStr; + } + + /** + * 月 + */ + private String monthDate(Date date, int i) {//减多少月 + String reStr = ""; + try { + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-01 00:00:00");//"yyyy-MM-dd HH:mm:ss" + Calendar rightNow = Calendar.getInstance(); + rightNow.setTime(date); + rightNow.add(Calendar.MONTH, -i); + Date dt1 = rightNow.getTime(); + reStr = sdf.format(dt1); + } catch (Exception e) { + e.printStackTrace(); + } + return reStr; + } + + /** + * 天 + */ + private String dayDate(Date date, int i) {//天 + String reStr = ""; + try { + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd 00:00:00");//"yyyy-MM-dd HH:mm:ss" + Calendar rightNow = Calendar.getInstance(); + rightNow.setTime(date); + rightNow.add(Calendar.DAY_OF_MONTH, -i); + Date dt1 = rightNow.getTime(); + reStr = sdf.format(dt1); + } catch (Exception e) { + e.printStackTrace(); + } + return reStr; + } + + /** + * 小时 + */ + private String hrDate(Date date, int i) {//减多少小时 + String reStr = ""; + try { + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:00:00");//"yyyy-MM-dd HH:mm:ss" + Calendar rightNow = Calendar.getInstance(); + rightNow.setTime(date); + rightNow.add(Calendar.HOUR, -i); + Date dt1 = rightNow.getTime(); + reStr = sdf.format(dt1); + } catch (Exception e) { + e.printStackTrace(); + } + return reStr; + } + + + /** + * 分钟 + */ + private String minutlDate(Date date, int i) {//减多少分钟 + String reStr = ""; + try { + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:00");//"yyyy-MM-dd HH:mm:ss" + Calendar rightNow = Calendar.getInstance(); + rightNow.setTime(date); + rightNow.add(Calendar.MINUTE, -i); + Date dt1 = rightNow.getTime(); + reStr = sdf.format(dt1); + } catch (Exception e) { + e.printStackTrace(); + } + return reStr; + } + + + /** + * 秒 + */ + private String secDate(Date date, int i) {//减多少秒 + String reStr = ""; + try { + SimpleDateFormat sdf = new SimpleDateFormat(DateUtil.PATTERN_DATETIME);//"yyyy-MM-dd HH:mm:ss" + Calendar rightNow = Calendar.getInstance(); + rightNow.setTime(date); + rightNow.add(Calendar.SECOND, -i); + Date dt1 = rightNow.getTime(); + reStr = sdf.format(dt1); + } catch (Exception e) { + e.printStackTrace(); + } + return reStr; + } + + /** + * 获取传递该数据点历史数据的数据格式 + * + * @param hashMaps + * @return + */ + private List transformFormatPartition(List> hashMaps, FdpMonitorEntity fdpMonitorEntity) { + List voList = new ArrayList<>(); + if (ObjectUtil.isNotEmpty(hashMaps)) { + for (HashMap hashMap : hashMaps) { + FdpCallbackHistoryTypeVo vo = new FdpCallbackHistoryTypeVo(); + if (ObjectUtil.isNotEmpty(hashMap.get("INTERVAL"))) { + vo.setFaultId(hashMap.get("FAULT_ID") + ""); + vo.setInterval(Integer.valueOf(hashMap.get("INTERVAL") + "")); + vo.setMode(hashMap.get("MODE").toString()); + vo.setNum(Integer.valueOf(hashMap.get("NUM") + "")); + vo.setType(hashMap.get("TYPE") + ""); + vo.setUnit(hashMap.get("UNIT") + ""); + vo.setCode(fdpMonitorEntity.getInstanceDeviceCode()); + vo.setSignages(fdpMonitorEntity.getImsSignages()); + vo.setMonitorFdpIdId(fdpMonitorEntity.getFdpId()); + voList.add(vo); + } + } + } + return voList; + } + + + /** + * 获取传递该数据点历史数据的数据格式 数据追溯 + * + * @param hashMaps + * @return + */ + private FdpCallbackHistoryTypeVo transformFormatBack(List> hashMaps, String faultId) { + FdpCallbackHistoryTypeVo vo = new FdpCallbackHistoryTypeVo(); + if (ObjectUtil.isNotEmpty(hashMaps)) { + for (HashMap hashMap : hashMaps) { + if (ObjectUtil.isNotEmpty(hashMap.get("INTERVAL"))) { + String faultid1 = hashMap.get("FAULT_ID").toString(); + if (faultid1.equals(faultId)) { + vo.setFaultId(hashMap.get("FAULT_ID") + ""); + vo.setInterval(Integer.valueOf(hashMap.get("INTERVAL") + "")); + vo.setMode(hashMap.get("MODE").toString()); + vo.setNum(Integer.valueOf(hashMap.get("NUM") + "")); + vo.setType(hashMap.get("TYPE") + ""); + vo.setUnit(hashMap.get("UNIT") + ""); + break; + } + } + } + } + return vo; + } } 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 9db05c1..ca9e8c3 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 @@ -128,46 +128,75 @@ public class FdpTaskServiceImpl extends BaseServiceImpl 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); + int size = fdpTaskEntities.size(); + //在第一层去掉为null值数据 + fdpTaskEntities=fdpTaskEntities.stream().filter(s->s.getFdpDeviceName()!=null).collect(Collectors.toList()); + extracted( res,0,"总计",size,size); + Map> collectByFdpDeviceName = fdpTaskEntities.stream().collect(Collectors.groupingBy(FdpTaskEntity::getFdpDeviceName)); + getCount("",collectByFdpDeviceName, fdpTaskEntities, res, 1); if (Func.isEmpty(statisticsVo.getName())) { - collectByCreateDept.entrySet().forEach(s->{ - Map> collectByName = s.getValue().stream().collect(Collectors.groupingBy(FdpTaskEntity::getName)); + collectByFdpDeviceName.entrySet().forEach(s->{ + List list=s.getValue().stream().filter(sig->sig.getName()!=null).collect(Collectors.toList()); + Map> collectByName = list.stream().collect(Collectors.groupingBy(FdpTaskEntity::getName)); 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.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.getCreateDept())){ + collectByFdpDeviceName.entrySet().forEach(s->{ + List list=s.getValue().stream().filter(sig->sig.getCreateDept()!=null).collect(Collectors.toList()); + Map> collectByName = list.stream().collect(Collectors.groupingBy(FdpTaskEntity::getCreateDept)); + 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())){ - collectByCreateDept.entrySet().forEach(s->{ - Map> collectByName = s.getValue().stream().collect(Collectors.groupingBy(FdpTaskEntity::getFdpOrd)); + collectByFdpDeviceName.entrySet().forEach(s->{ + List list=s.getValue().stream().filter(sig->sig.getFdpOrd()!=null).collect(Collectors.toList()); + Map> collectByName = list.stream().collect(Collectors.groupingBy(FdpTaskEntity::getFdpOrd)); 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())){ - collectByCreateDept.entrySet().forEach(s->{ - Map> collectByName = s.getValue().stream().collect(Collectors.groupingBy(FdpTaskEntity::getType)); + collectByFdpDeviceName.entrySet().forEach(s->{ + List list=s.getValue().stream().filter(sig->sig.getFdpOrd()!=null).collect(Collectors.toList()); + Map> collectByName = list.stream().collect(Collectors.groupingBy(FdpTaskEntity::getType)); 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); } + private static void extracted( ArrayList 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 - public R getTaskData(TaskStatisticsVo statisticsVo) { + public R getTaskData(TaskStatisticsVo statisticsVo,Query query) { Wrapper queryWrapper = getFdpTaskEntityWrapper(statisticsVo); - List fdpTaskEntities = super.baseMapper.selectList(queryWrapper); - if (CollectionUtil.isEmpty(fdpTaskEntities)){ + IPage pages = super.baseMapper.selectPage(Condition.getPage(query),queryWrapper); + if (CollectionUtil.isEmpty(pages.getRecords())){ return R.success("暂无数据,请稍后重试"); } - return R.data(fdpTaskEntities); + return R.data(pages); } private static Wrapper getFdpTaskEntityWrapper(TaskStatisticsVo statisticsVo) { @@ -179,7 +208,7 @@ public class FdpTaskServiceImpl extends BaseServiceImpl{ 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); + taskStatisticsVo.setPercentage(bigDecimal.toString()); + taskStatisticsVo.setLevel(level); + taskStatisticsVo.setMemuName(key+"-"+s.getKey().toString()); + res.add(taskStatisticsVo); + }); + } + //获取对应层级占比和数量 + //机构类型需要转换ID为名称 + private void getCount2(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()); + R deptNameCode = sysClient.getDeptName(s.getKey()); + String deptName; + if (deptNameCode.isSuccess()){ + deptName=deptNameCode.getData(); + }else { + deptName=""; + } + taskStatisticsVo.setMemuName(key+"-"+deptName); res.add(taskStatisticsVo); }); } diff --git a/hzims-service/hzims-middle/src/main/java/com/hnac/hzims/middle/processflow/controller/ProcessDictController.java b/hzims-service/hzims-middle/src/main/java/com/hnac/hzims/middle/processflow/controller/ProcessDictController.java index d34c813..fef5646 100644 --- a/hzims-service/hzims-middle/src/main/java/com/hnac/hzims/middle/processflow/controller/ProcessDictController.java +++ b/hzims-service/hzims-middle/src/main/java/com/hnac/hzims/middle/processflow/controller/ProcessDictController.java @@ -62,14 +62,12 @@ public class ProcessDictController { * * @param staff * @param typeInstrument - * @param createTime * @return */ @GetMapping("/getTicketByCode") public String getTicketByCode(@RequestParam("staff") String staff, - @RequestParam("typeInstrument") String typeInstrument, - @RequestParam("createTime") LocalDateTime createTime) { - return processIdWorker.getTicketByCode(staff, typeInstrument, createTime); + @RequestParam("typeInstrument") String typeInstrument) { + return processIdWorker.getTicketByCode(staff, typeInstrument, LocalDateTime.now()); } diff --git a/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/standardTicket/service/impl/OperationTicketServiceImpl.java b/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/standardTicket/service/impl/OperationTicketServiceImpl.java index 2e253a9..acfc197 100644 --- a/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/standardTicket/service/impl/OperationTicketServiceImpl.java +++ b/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/standardTicket/service/impl/OperationTicketServiceImpl.java @@ -126,7 +126,7 @@ public class OperationTicketServiceImpl implements OperationTicketService { standardTicketInfoVo.setSignage(signage); standardTicketInfoVo.setSignageCode(station.getCode()); //2. 获取编码 - String code = processDictFeignService.getTicketByCode(standardTicketInfoVo.getSignage(), this.getTicketWichCode(standardTicketInfoVo.getTicketType()), LocalDateTime.now()); + String code = processDictFeignService.getTicketByCode(standardTicketInfoVo.getSignage(), this.getTicketWichCode(standardTicketInfoVo.getTicketType())); log.info("获取编码: {}", code); if (StringUtils.isBlank(code)) { throw new ServiceException("服务器异常,请联系管理员"); diff --git a/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/twoTicket/service/impl/TicketProcessServiceImpl.java b/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/twoTicket/service/impl/TicketProcessServiceImpl.java index a7909aa..cb82cba 100644 --- a/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/twoTicket/service/impl/TicketProcessServiceImpl.java +++ b/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/twoTicket/service/impl/TicketProcessServiceImpl.java @@ -191,8 +191,7 @@ public class TicketProcessServiceImpl implements TicketProcessService { workTicketVo.getWorkTicket().setSignage(station.getSignage()); workTicketVo.getWorkTicket().setSignageCode(station.getCode()); //2. 获取编码 - String code = processDictFeignService.getTicketByCode(signage, this.getTicketWichCode(workTicketVo.getWorkTicket().getType()), - LocalDateTime.now()); + String code = processDictFeignService.getTicketByCode(signage, this.getTicketWichCode(workTicketVo.getWorkTicket().getType())); log.info("获取编码: {}", code); if (StringUtils.isBlank(code)) { throw new ServiceException("服务器异常,请联系管理员");