diff --git a/hzims-service-api/equipment-api/src/main/java/com/hnac/hzims/equipment/feign/IEmInfoClient.java b/hzims-service-api/equipment-api/src/main/java/com/hnac/hzims/equipment/feign/IEmInfoClient.java index 6e6dec3..df356ed 100644 --- a/hzims-service-api/equipment-api/src/main/java/com/hnac/hzims/equipment/feign/IEmInfoClient.java +++ b/hzims-service-api/equipment-api/src/main/java/com/hnac/hzims/equipment/feign/IEmInfoClient.java @@ -19,6 +19,7 @@ package com.hnac.hzims.equipment.feign; import com.hnac.hzims.EquipmentConstants; import com.hnac.hzims.equipment.entity.EmInfoEntity; import com.hnac.hzims.equipment.vo.DeviceVO; +import com.hnac.hzims.equipment.vo.RideDeviceVo; import org.springblade.core.tool.api.R; import org.springblade.system.vo.CreateTableVO; import org.springframework.cloud.openfeign.FeignClient; @@ -84,6 +85,9 @@ public interface IEmInfoClient { String DEVICE_BY_PATH = API_PREFIX + "/deviceByPath"; String EM_INFO_LIST = API_PREFIX + "/emInfoList"; + String RIDE_DEVICES = API_PREFIX + "/rideDevices"; + + @PostMapping(DETAIL) EmInfoEntity getByCode(@RequestParam("code") String id); @@ -169,4 +173,7 @@ public interface IEmInfoClient { @GetMapping(EM_INFO_LIST) R> emInfoList(EmInfoEntity req); + + @GetMapping(RIDE_DEVICES) + List rideDevices(List longs); } diff --git a/hzims-service-api/equipment-api/src/main/java/com/hnac/hzims/equipment/feign/IEmInfoClientBack.java b/hzims-service-api/equipment-api/src/main/java/com/hnac/hzims/equipment/feign/IEmInfoClientBack.java index c411e7e..104d494 100644 --- a/hzims-service-api/equipment-api/src/main/java/com/hnac/hzims/equipment/feign/IEmInfoClientBack.java +++ b/hzims-service-api/equipment-api/src/main/java/com/hnac/hzims/equipment/feign/IEmInfoClientBack.java @@ -2,6 +2,7 @@ package com.hnac.hzims.equipment.feign; import com.hnac.hzims.equipment.entity.EmInfoEntity; import com.hnac.hzims.equipment.vo.DeviceVO; +import com.hnac.hzims.equipment.vo.RideDeviceVo; import lombok.extern.slf4j.Slf4j; import org.springblade.core.tool.api.R; import org.springblade.system.vo.CreateTableVO; @@ -114,4 +115,9 @@ public class IEmInfoClientBack implements IEmInfoClient { public R> emInfoList(EmInfoEntity req) { return R.fail("远程调用失败"); } + + @Override + public List rideDevices(List longs) { + return new ArrayList<>(); + } } diff --git a/hzims-service/equipment/src/main/java/com/hnac/hzims/equipment/feign/EmInfoClient.java b/hzims-service/equipment/src/main/java/com/hnac/hzims/equipment/feign/EmInfoClient.java index 637da20..444b59c 100644 --- a/hzims-service/equipment/src/main/java/com/hnac/hzims/equipment/feign/EmInfoClient.java +++ b/hzims-service/equipment/src/main/java/com/hnac/hzims/equipment/feign/EmInfoClient.java @@ -9,6 +9,7 @@ import com.hnac.hzims.common.utils.Condition; import com.hnac.hzims.equipment.entity.EmInfoEntity; import com.hnac.hzims.equipment.service.IEmInfoService; import com.hnac.hzims.equipment.vo.DeviceVO; +import com.hnac.hzims.equipment.vo.RideDeviceVo; import org.springblade.core.tool.api.R; import org.springblade.core.tool.utils.CollectionUtil; import org.springblade.core.tool.utils.ObjectUtil; @@ -155,6 +156,11 @@ public class EmInfoClient implements IEmInfoClient { return R.data(service.list(queryWrapper)); } + @Override + public List rideDevices(List deptIds) { + return service.rideDevices(deptIds); + } + @PostMapping(GET_EM_CREATE_TABLE) @Override public List getEmCreateTable(List tableNames) { diff --git a/hzims-service/equipment/src/main/java/com/hnac/hzims/equipment/mapper/EmParamMapper.java b/hzims-service/equipment/src/main/java/com/hnac/hzims/equipment/mapper/EmParamMapper.java index a2cb335..0e83b71 100644 --- a/hzims-service/equipment/src/main/java/com/hnac/hzims/equipment/mapper/EmParamMapper.java +++ b/hzims-service/equipment/src/main/java/com/hnac/hzims/equipment/mapper/EmParamMapper.java @@ -19,4 +19,5 @@ public interface EmParamMapper extends UserDataScopeBaseMapper { List selectRideCountGroupEmIdByDepts(@Param("list") List list); + List rides(List deviceIds); } diff --git a/hzims-service/equipment/src/main/java/com/hnac/hzims/equipment/mapper/EmParamMapper.xml b/hzims-service/equipment/src/main/java/com/hnac/hzims/equipment/mapper/EmParamMapper.xml index bf699b0..09861ea 100644 --- a/hzims-service/equipment/src/main/java/com/hnac/hzims/equipment/mapper/EmParamMapper.xml +++ b/hzims-service/equipment/src/main/java/com/hnac/hzims/equipment/mapper/EmParamMapper.xml @@ -53,4 +53,13 @@ 'installedCapacity') + diff --git a/hzims-service/equipment/src/main/java/com/hnac/hzims/equipment/service/IEmInfoService.java b/hzims-service/equipment/src/main/java/com/hnac/hzims/equipment/service/IEmInfoService.java index ead9dee..5632b61 100644 --- a/hzims-service/equipment/src/main/java/com/hnac/hzims/equipment/service/IEmInfoService.java +++ b/hzims-service/equipment/src/main/java/com/hnac/hzims/equipment/service/IEmInfoService.java @@ -98,4 +98,6 @@ public interface IEmInfoService extends BaseService { List select(Long deptId); List getEmInfoTree(EmInfoEntity req); + + List rideDevices(List deptIds); } diff --git a/hzims-service/equipment/src/main/java/com/hnac/hzims/equipment/service/IEmParamService.java b/hzims-service/equipment/src/main/java/com/hnac/hzims/equipment/service/IEmParamService.java index 9284338..ca087ff 100644 --- a/hzims-service/equipment/src/main/java/com/hnac/hzims/equipment/service/IEmParamService.java +++ b/hzims-service/equipment/src/main/java/com/hnac/hzims/equipment/service/IEmParamService.java @@ -19,4 +19,5 @@ public interface IEmParamService extends BaseService { Map> getRideCountGroupEmIdByDepts(List emIds); + List rides(List deviceIds); } diff --git a/hzims-service/equipment/src/main/java/com/hnac/hzims/equipment/service/impl/EmInfoServiceImpl.java b/hzims-service/equipment/src/main/java/com/hnac/hzims/equipment/service/impl/EmInfoServiceImpl.java index fb6fb04..75d0db5 100644 --- a/hzims-service/equipment/src/main/java/com/hnac/hzims/equipment/service/impl/EmInfoServiceImpl.java +++ b/hzims-service/equipment/src/main/java/com/hnac/hzims/equipment/service/impl/EmInfoServiceImpl.java @@ -949,4 +949,51 @@ public class EmInfoServiceImpl extends BaseServiceImpl rideDevices(List deptIds) { + // 查询设备 + List devices = this.list(Wrappers.lambdaQuery() + .in(EmInfoEntity::getDepartment,deptIds) + .eq(EmInfoEntity::getHomePageDisplay,"1") + .eq(EmInfoEntity::getEmType,"2") + ); + if(CollectionUtil.isEmpty(devices)){ + return new ArrayList<>(); + } + List paramList = paramService.rides(devices.stream().map(EmInfoEntity::getId).collect(Collectors.toList())); + return devices.stream().map(device->{ + RideDeviceVo rideDevice = new RideDeviceVo(); + BeanUtil.copyProperties(device,rideDevice); + // 寻找设备配置参数 + List itemParamList = paramList.stream().filter(o->device.getId().equals(o.getInfoId())).collect(Collectors.toList()); + if(CollectionUtil.isNotEmpty(itemParamList)) { + // 遍历设备配置参数 + for (EmParamEntity paramEntity : itemParamList) { + String paramName = paramEntity.getParamName(); + switch (paramName) { + case "ct": + case "CT": + rideDevice.setCt(Double.parseDouble(paramEntity.getParamValue())); + break; + case "pt": + case "PT": + rideDevice.setPt(Double.parseDouble(paramEntity.getParamValue())); + break; + default: + break; + } + } + // 设置ct * pt + if (null != rideDevice.getCt() && null != rideDevice.getPt()) { + rideDevice.setRide(rideDevice.getCt() * rideDevice.getPt()); + }else{ + rideDevice.setRide(1.0); + } + }else{ + rideDevice.setRide(1.0); + } + return rideDevice; + }).collect(Collectors.toList()); + } + } diff --git a/hzims-service/equipment/src/main/java/com/hnac/hzims/equipment/service/impl/EmParamServiceImpl.java b/hzims-service/equipment/src/main/java/com/hnac/hzims/equipment/service/impl/EmParamServiceImpl.java index 394189f..cd4f0c6 100644 --- a/hzims-service/equipment/src/main/java/com/hnac/hzims/equipment/service/impl/EmParamServiceImpl.java +++ b/hzims-service/equipment/src/main/java/com/hnac/hzims/equipment/service/impl/EmParamServiceImpl.java @@ -69,4 +69,9 @@ public class EmParamServiceImpl extends BaseServiceImpl rides(List deviceIds) { + return this.baseMapper.rides(deviceIds); + } } diff --git a/hzims-service/operational/pom.xml b/hzims-service/operational/pom.xml index 7f60701..688077c 100644 --- a/hzims-service/operational/pom.xml +++ b/hzims-service/operational/pom.xml @@ -240,6 +240,10 @@ com.hnac.hzinfo.data hzinfo-data-sdk + + com.hnac.hzims + alarm-api + @@ -255,6 +259,12 @@ 3.9.1 compile + + com.hnac.hzims + alarm-api + 4.0.0-SNAPSHOT + compile + diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/service/IAnalyseDataService.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/service/IAnalyseDataService.java index 14d1292..fe2130f 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/service/IAnalyseDataService.java +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/service/IAnalyseDataService.java @@ -15,10 +15,13 @@ public interface IAnalyseDataService { List getAnalyzeCodeBySignages(Function convert, T resource); + List analyzeCodeBySignages(List list); + + List periodTargetSignages(String startTime, String endTime, Integer accessRules, Integer cycleType, String deviceCode, List signages); List periodTargetData(String startTime, String endTime, Integer accessRules, Integer cycleType, String deviceCode, String signages); List periodTargetDatas(String startTime, String endTime, Integer accessRules, Integer cycleType, List deviceCodes, String signages); - Float periodTargetFloat(String startTime, String endTime, Integer accessRules, Integer cycleType, String deviceCode, Integer ride ,String signages); + Float periodTargetFloat(String startTime, String endTime, Integer accessRules, Integer cycleType, String deviceCode, Double ride ,String signages); } diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/service/impl/AnalyseDataServiceImpl.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/service/impl/AnalyseDataServiceImpl.java index 927d6d2..c66d6ff 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/service/impl/AnalyseDataServiceImpl.java +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/service/impl/AnalyseDataServiceImpl.java @@ -1,8 +1,6 @@ package com.hnac.hzims.operational.main.service.impl; import com.google.common.collect.Lists; -import com.hnac.hzims.EquipmentConstants; -import com.hnac.hzims.equipment.vo.EminfoAndEmParamVo; import com.hnac.hzims.operational.main.service.IAnalyseDataService; import com.hnac.hzinfo.datasearch.analyse.IAnalyseDataSearchClient; import com.hnac.hzinfo.datasearch.analyse.po.AnalyseCodeByAnalyseDataPO; @@ -22,7 +20,10 @@ import org.springframework.stereotype.Service; import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; -import java.util.*; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Date; +import java.util.List; import java.util.function.Function; import java.util.stream.Collectors; @@ -47,6 +48,58 @@ public class AnalyseDataServiceImpl implements IAnalyseDataService { return result; } + /** + * 查询设备实例属性标识 + * @param list + * @return + */ + @Override + public List analyzeCodeBySignages(List list) { + R> result = analyseDataSearchClient.getAnalyzeCodeBySignages(list); + if(!result.isSuccess() || CollectionUtil.isEmpty(result.getData())){ + return new ArrayList<>(); + } + return result.getData(); + } + + /*** + * 指标数据列表查询 + * @param startTime 开始时间 + * @param endTime 结束时间 + * @param accessRules 取数规则 : 0=最早值 1=最大值 2=最小值 3=平均值 4=和值 5=差值 6=最新值 + * @param cycleType 间隔周期 : 0-> 秒 1-> 分 2-> 小时 3->天 4-> 周 5-> 月 6-> 年 + * @param deviceCode 设备编号 + * @param signages 指标集合 + * @return + */ + @Override + public List periodTargetSignages(String startTime, String endTime, Integer accessRules, Integer cycleType, String deviceCode, List signages) { + AnalyseCodeByAnalyseDataPO po = new AnalyseCodeByAnalyseDataPO(); + List signboardConditions = new ArrayList<>(); + signages.forEach(signage->{ + AnalyzeDataConditionPO analyzeDataConditionPO = new AnalyzeDataConditionPO(); + analyzeDataConditionPO.setFull(1); + po.setDeviceCode(deviceCode); + analyzeDataConditionPO.setKeepFigures(2); + analyzeDataConditionPO.setAccessRules(accessRules); + analyzeDataConditionPO.setSaveTimeType(cycleType); + analyzeDataConditionPO.setSignages(signage); + // 间隔 + analyzeDataConditionPO.setTimeInterval(1); + analyzeDataConditionPO.setBeginTime(LocalDateTime.parse(DateUtil.format(new Date(), startTime), DateTimeFormatter.ofPattern(DateUtil.PATTERN_DATETIME))); + analyzeDataConditionPO.setEndTime(LocalDateTime.parse(DateUtil.format(new Date(), endTime), DateTimeFormatter.ofPattern(DateUtil.PATTERN_DATETIME))); + signboardConditions.add(analyzeDataConditionPO); + }); + po.setSignboardConditions(signboardConditions); + log.error("period_targets_data_request {}",po); + R> result = analyseDataSearchClient.getAnalyzeDataByAnalyzeCodeAndSignages(po); + if (!result.isSuccess() || CollectionUtil.isEmpty(result.getData())) { + return new ArrayList<>(); + } + log.error("period_targets_data_resp {}",result); + return result.getData(); + } + /*** * 指标数据列表查询 * @param startTime 开始时间 @@ -134,7 +187,7 @@ public class AnalyseDataServiceImpl implements IAnalyseDataService { * @return */ @Override - public Float periodTargetFloat(String startTime, String endTime, Integer accessRules, Integer cycleType, String deviceCode,Integer ride,String signages) { + public Float periodTargetFloat(String startTime, String endTime, Integer accessRules, Integer cycleType, String deviceCode,Double ride,String signages) { AnalyseCodeByAnalyseDataPO po = new AnalyseCodeByAnalyseDataPO(); List signboardConditions = new ArrayList<>(); AnalyzeDataConditionPO analyzeDataConditionPO = new AnalyzeDataConditionPO(); @@ -170,7 +223,7 @@ public class AnalyseDataServiceImpl implements IAnalyseDataService { if (ObjectUtil.isEmpty(analyseDataTaosVO) || StringUtil.isBlank(analyseDataTaosVO.getVal())) { return 0f; } - return Float.parseFloat(Optional.ofNullable(analyseDataTaosVO.getVal()).orElse("0")) * ride; + return Float.parseFloat(String.valueOf(Double.parseDouble(analyseDataTaosVO.getVal()) * ride)) ; } diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/report/controller/RunMonthController.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/report/controller/RunMonthController.java index 17b18ec..a5872ce 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/report/controller/RunMonthController.java +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/report/controller/RunMonthController.java @@ -23,6 +23,22 @@ public class RunMonthController { private final RunMonthService runMonthService; + + @GetMapping("/generate") + @ApiOperation(value = "生成站点月报",notes = "生成站点月报") + @ApiOperationSupport(order = 1) + public R generate(@RequestParam("mon") String mon, + @RequestParam("stationCode") String stationCode){ + return R.data(runMonthService.generate(mon,stationCode)); + } + + @GetMapping("/check") + @ApiOperation(value = "查询站点月报数据",notes = "查询站点月报数据") + @ApiOperationSupport(order = 2) + public R check(@RequestParam("stationCode") String stationCode){ + return R.data(runMonthService.check(stationCode)); + } + @GetMapping("/data") @ApiOperation(value = "查询站点月报数据",notes = "查询站点月报数据") @ApiOperationSupport(order = 3) @@ -33,7 +49,7 @@ public class RunMonthController { @GetMapping("/export") @ApiOperation(value = "导出站点运行月报",notes = "导出站点运行月报") - @ApiOperationSupport(order = 3) + @ApiOperationSupport(order = 4) public void export(@RequestParam("mon") String mon, @RequestParam("stationCode") String stationCode){ runMonthService.export(mon,stationCode); diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/report/service/RunMonthService.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/report/service/RunMonthService.java index aa172f4..bed8fde 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/report/service/RunMonthService.java +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/report/service/RunMonthService.java @@ -11,4 +11,8 @@ public interface RunMonthService extends BaseService { RunMonthEntity data(String mon, String stationCode); void export(String mon, String stationCode); + + Boolean generate(String mon, String stationCode); + + Boolean check(String stationCode); } diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/report/service/impl/RunMonthServiceImpl.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/report/service/impl/RunMonthServiceImpl.java index 6e4a668..6d278d2 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/report/service/impl/RunMonthServiceImpl.java +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/report/service/impl/RunMonthServiceImpl.java @@ -3,10 +3,38 @@ package com.hnac.hzims.operational.report.service.impl; import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.TypeReference; import com.baomidou.mybatisplus.core.toolkit.Wrappers; +import com.hnac.hzims.alarm.config.constants.AlarmConstants; +import com.hnac.hzims.alarm.config.constants.AlarmHandleConstant; +import com.hnac.hzims.common.logs.utils.StringUtils; +import com.hnac.hzims.equipment.entity.EmInfoEntity; +import com.hnac.hzims.equipment.entity.PlanGenerationEntity; +import com.hnac.hzims.equipment.feign.IEmInfoClient; +import com.hnac.hzims.equipment.feign.IPlanGenertionClient; +import com.hnac.hzims.equipment.vo.RideDeviceVo; +import com.hnac.hzims.operational.main.constant.HomePageConstant; +import com.hnac.hzims.operational.main.service.IAnalyseDataService; import com.hnac.hzims.operational.report.entity.RunMonthEntity; import com.hnac.hzims.operational.report.mapper.RunMonthMapper; import com.hnac.hzims.operational.report.service.RunMonthService; import com.hnac.hzims.operational.report.vo.*; +import com.hnac.hzims.operational.station.entity.StationEntity; +import com.hnac.hzims.operational.station.service.IStationService; +import com.hnac.hzims.operational.station.vo.StationVO; +import com.hnac.hzinfo.datasearch.PointData; +import com.hnac.hzinfo.datasearch.analyse.vo.AnalyseDataTaosVO; +import com.hnac.hzinfo.datasearch.analyse.vo.AnalyzeCodeBySignagesVO; +import com.hnac.hzinfo.datasearch.analyse.vo.AnalyzeDataConditionVO; +import com.hnac.hzinfo.datasearch.history.IHistoryDataSearchClient; +import com.hnac.hzinfo.datasearch.history.OriginalDataQuery; +import com.hnac.hzinfo.datasearch.soe.ISoeClient; +import com.hnac.hzinfo.datasearch.soe.domian.SoeData; +import com.hnac.hzinfo.datasearch.soe.domian.SoeQueryConditionByStation; +import com.hnac.hzinfo.sdk.analyse.po.MultiAnalyzeCodePO; +import com.hnac.hzinfo.sdk.core.response.HzPage; +import com.hnac.hzinfo.sdk.core.response.Result; +import com.hnac.hzinfo.sdk.v5.soe.SoeDataClient; +import com.hnac.hzinfo.sdk.v5.soe.dto.StbAnalysisDTO; +import com.hnac.hzinfo.sdk.v5.soe.vo.StbAnalysisVO; import lombok.AllArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.apache.poi.hssf.usermodel.HSSFFont; @@ -17,10 +45,9 @@ import org.apache.poi.ss.util.CellRangeAddress; import org.apache.poi.xssf.usermodel.XSSFWorkbook; import org.springblade.core.log.exception.ServiceException; import org.springblade.core.mp.base.BaseServiceImpl; -import org.springblade.core.tool.utils.BeanUtil; -import org.springblade.core.tool.utils.CollectionUtil; -import org.springblade.core.tool.utils.ObjectUtil; -import org.springblade.core.tool.utils.StringUtil; +import org.springblade.core.tool.api.R; +import org.springblade.core.tool.utils.DateUtil; +import org.springblade.core.tool.utils.*; import org.springframework.stereotype.Service; import org.springframework.web.context.request.RequestContextHolder; import org.springframework.web.context.request.ServletRequestAttributes; @@ -31,19 +58,33 @@ import java.io.IOException; import java.math.BigDecimal; import java.math.RoundingMode; import java.net.URLEncoder; -import java.util.ArrayList; -import java.util.Comparator; -import java.util.List; +import java.time.LocalDateTime; +import java.util.*; import java.util.stream.Collectors; /** * @author ysj */ +@SuppressWarnings("ALL") @Service @AllArgsConstructor @Slf4j public class RunMonthServiceImpl extends BaseServiceImpl implements RunMonthService { + private final IStationService stationService; + + private final IAnalyseDataService dataService; + + private final ISoeClient soeClient; + + private final IEmInfoClient deivceClient; + + private final SoeDataClient soeDataClient; + + private final IPlanGenertionClient planClient; + + private final IHistoryDataSearchClient historyDataSearchClient; + /** * 查询站点月报运行数据 * @param mon @@ -124,6 +165,488 @@ public class RunMonthServiceImpl extends BaseServiceImpllambdaQuery() + .eq(StationEntity::getDataOrigin, HomePageConstant.DATA_ORIGIN) + .eq(StationEntity::getType,HomePageConstant.HYDROPOWER) + .eq(StationEntity::getCode,stationCode) + ); + if(ObjectUtil.isEmpty(station)){ + throw new ServiceException("未查询到站点信息!"); + } + // 查询站点设备 + List devices = deivceClient.rideDevices(Collections.singletonList(station.getRefDept())); + if(CollectionUtil.isEmpty(devices)){ + throw new ServiceException("站点未配置机组设备信息、请先为站点添加设备,绑定设备实例,再进行月报查询!"); + } + // 计划发电量 + List plans = planClient.getPlanGenerationByParam(Collections.singletonList(stationCode), null , DateUtil.format(new Date(),"yyyy")); + RunMonthEntity run = new RunMonthEntity(); + run.setTenantId(station.getTenantId()); + run.setCreateDept(station.getRefDept()); + run.setCreateUser(station.getCreateUser()); + run.setUpdateUser(station.getUpdateUser()); + run.setStationCode(station.getCode()); + run.setStationName(station.getName()); + Calendar calendar = Calendar.getInstance(); + calendar.setTime(org.springblade.core.tool.utils.DateUtil.parse("2024-05-01 00:00:00", org.springblade.core.tool.utils.DateUtil.PATTERN_DATETIME)); + calendar.add(Calendar.DAY_OF_MONTH,-1); + run.setMonth(DateUtil.format(calendar.getTime(),"yyyy-MM")); + List stationDevices = devices.stream().filter(device->device.getDepartment().equals(station.getRefDept())).collect(Collectors.toList()); + // 运行数据 + run.setRunData(this.runData(station.getCode(),stationDevices,plans)); + // 告警数据 + run.setAlarmData(this.alarmData(station.getCode())); + // 月度运行曲线 + run.setCurveData(this.curveData(stationDevices)); + // TODO 运行数据分析 + // TODO 运行建议及其他 + // TODO 保存生成月报数据 + // runMonService.save(run); + return true; + } + + /** + * 运行数据 + * @param devices + * @return + */ + private String runData(String stationCode,List devices,List plans) { + List runs = new ArrayList<>(); + devices.forEach(device->{ + RunDataVo run = new RunDataVo(); + run.setDeviceCode(device.getNumber()); + run.setDeviceName(device.getName()); + // 运行时长 + run.setRunHours(this.runHours(device)); + // 月发电量 + Double day = this.generates(0,device.getNumber(),device.getRide()); + if(ObjectUtil.isEmpty(day)){ + run.setGenerate(0.0); + }else{ + run.setGenerate(day/10000); + } + // 年发电量 + Double year = this.generates(1,device.getNumber(),device.getRide()); + if(ObjectUtil.isEmpty(day)){ + run.setGenerateYear(0.0); + }else{ + run.setGenerateYear(year/10000); + } + // 计划发电量 + run.setPlan(this.planGenerate(0,stationCode,plans)/10000); + // 年计划发电量 + run.setPlanYear(this.planGenerate(1,stationCode,plans)/10000); + runs.add(run); + }); + return JSONObject.toJSONString(runs); + } + + /** + * 实际发电量 + * @param type + * @param deviceCode + * @param ride + * @return + */ + private Double generates(int type,String deviceCode,double ride) { + Calendar calendar = Calendar.getInstance(); + calendar.setTime(DateUtil.parse("2024-05-01 00:00:00",DateUtil.PATTERN_DATETIME)); + String end = null,start = null; + int cycleType = 5; + switch (type){ + case 0 : + calendar.add(Calendar.DAY_OF_MONTH,-1); + calendar.add(Calendar.HOUR_OF_DAY,-calendar.get(Calendar.HOUR_OF_DAY)); + calendar.add(Calendar.MINUTE, -calendar.get(Calendar.MINUTE)); + calendar.add(Calendar.SECOND, -calendar.get(Calendar.SECOND)); + end = DateUtil.format(calendar.getTime(),DateUtil.PATTERN_DATETIME); + calendar.add(Calendar.DATE, -calendar.get(Calendar.DATE) + 1); + start = DateUtil.format(calendar.getTime(),DateUtil.PATTERN_DATETIME); + break; + case 1 : + cycleType = 6; + end = DateUtil.format(calendar.getTime(),DateUtil.PATTERN_DATETIME); + calendar.add(Calendar.MONTH,-calendar.get(Calendar.MONTH)); + calendar.add(Calendar.DAY_OF_MONTH,-calendar.get(Calendar.DAY_OF_MONTH)); + calendar.add(Calendar.HOUR_OF_DAY,-calendar.get(Calendar.HOUR_OF_DAY)); + calendar.add(Calendar.MINUTE, -calendar.get(Calendar.MINUTE)); + calendar.add(Calendar.SECOND, -calendar.get(Calendar.SECOND)); + calendar.add(Calendar.DAY_OF_MONTH,1); + start = DateUtil.format(calendar.getTime(),DateUtil.PATTERN_DATETIME); + break; + } + return Double.valueOf(dataService.periodTargetFloat(start,end,5,cycleType,deviceCode,ride,HomePageConstant.HYDROPOWER_GENERATE_POWER)); + } + + /** + * 计划发电量 + * @param type + * @param stationCode + * @param plans + * @return + */ + private Double planGenerate(int type, String stationCode,List plans) { + Calendar calendar = Calendar.getInstance(); + calendar.setTime(DateUtil.parse("2024-05-01 00:00:00",DateUtil.PATTERN_DATETIME)); + if(type == 0){ + calendar.add(Calendar.DAY_OF_MONTH,-1); + calendar.add(Calendar.HOUR_OF_DAY,-calendar.get(Calendar.HOUR_OF_DAY) + 1); + calendar.add(Calendar.MINUTE, -calendar.get(Calendar.MINUTE)); + calendar.add(Calendar.SECOND, -calendar.get(Calendar.SECOND)); + String time = DateUtil.format(calendar.getTime(),"yyyy-MM"); + return plans.stream().filter(plan -> plan.getStationId().equals(stationCode) && plan.getDateTime().contains(time)) + .mapToDouble(PlanGenerationEntity::getPlanGeneration).sum(); + } + String time = DateUtil.format(calendar.getTime(),"yyyy"); + return plans.stream().filter(plan -> plan.getStationId().equals(stationCode) && plan.getDateTime().contains(time)) + .mapToDouble(PlanGenerationEntity::getPlanGeneration).sum(); + } + + /** + * 获取运行数据 + * @param device + * @return + */ + private Double runHours(EmInfoEntity device) { + MultiAnalyzeCodePO analyze = new MultiAnalyzeCodePO(); + analyze.setDeviceCode(device.getNumber()); + analyze.setSignages(Collections.singletonList(HomePageConstant.ACTIVE_POWER)); + List signages = dataService.analyzeCodeBySignages(Collections.singletonList(analyze)); + if(CollectionUtil.isEmpty(signages)){ + return 0.0; + } + // 监测点 + String realId = signages.get(0).getRealId(); + if(StringUtils.isEmpty(realId)){ + return 0.0; + } + // 确定查询时间范围: 年、月 + Date startDate,endDate; + Calendar calendar = Calendar.getInstance(); + calendar.setTime(DateUtil.parse("2024-05-01 00:00:00",DateUtil.PATTERN_DATETIME)); + endDate = calendar.getTime(); + calendar.add(Calendar.MONTH, -calendar.get(Calendar.MONTH)); + calendar.add(Calendar.DATE, -calendar.get(Calendar.DATE) + 1); + startDate = calendar.getTime(); + return this.getRunConvertData(realId,startDate,endDate); + } + + /** + * 获取时间范围内运行时长 + * @param realId + * @param startDate + * @param endDate + * @return + */ + private Double getRunConvertData(String realId, Date startDate, Date endDate) { + OriginalDataQuery originalDataQuery = new OriginalDataQuery(); + originalDataQuery.setRealId(realId); + originalDataQuery.setBeginTime(startDate); + originalDataQuery.setEndTime(endDate); + originalDataQuery.setLimit(100000); + originalDataQuery.setPage(1); + // 查询时间范围开关机监测点历史数据 + Result> result = historyDataSearchClient.getOriginalDataByRealIds(originalDataQuery); + if(!result.isSuccess() || ObjectUtil.isEmpty(result.getData())){ + return 0.0; + } + // 开机运行时长 + long time = this.getRunTime(result.getData().getRecords(),startDate,endDate); + return BigDecimal.valueOf(time / (1000 * 60 * 60.00)).setScale(2, RoundingMode.HALF_UP).doubleValue(); + } + + /** + * 获取运行时长 + * @param result + * @return + */ + private long getRunTime(List result,Date startDate,Date endDate) { + if(result.size() == 1){ + // 一直开机 + if(Double.parseDouble(result.get(0).getValue()) > 0){ + return endDate.getTime() - startDate.getTime(); + } + // 一直关机 + return 0; + } + long time=0; + // 遍历累计开机时长 + for(int i = 0; i< result.size() ; i++){ + // 记录为开机状态 就计算到下次关机的时间差 + if(Double.parseDouble(result.get(i).getValue()) <= 0){ + continue; + } + Date endTime,startTime = DateUtil.parse(result.get(i).getTime(), DateUtil.PATTERN_DATETIME); + // 遍历至最后一条数据,累计至当前时间 + if(i == result.size() - 1){ + endTime = endDate; + }else { + endTime = DateUtil.parse(result.get(i+1).getTime(), DateUtil.PATTERN_DATETIME); + } + time += endTime.getTime() - startTime.getTime(); + } + return time; + } + + /** + * 告警数据 + * @param code + * @return + */ + private String alarmData(String code) { + Calendar calendar = Calendar.getInstance(); + calendar.setTime(DateUtil.parse("2024-05-01 00:00:00",DateUtil.PATTERN_DATETIME)); + calendar.add(Calendar.DAY_OF_MONTH,-1); + String end = DateUtil.format(calendar.getTime(),DateUtil.PATTERN_DATETIME); + calendar.add(Calendar.MONTH,-1); + calendar.add(Calendar.DAY_OF_MONTH,1); + calendar.add(Calendar.HOUR_OF_DAY,-calendar.get(Calendar.HOUR_OF_DAY)); + calendar.add(Calendar.MINUTE, -calendar.get(Calendar.MINUTE)); + calendar.add(Calendar.SECOND, -calendar.get(Calendar.SECOND)); + String start = DateUtil.format(calendar.getTime(),DateUtil.PATTERN_DATETIME); + // HZ3000:故障告警 + List alarms = this.hz3000Alarm(code,start,end); + // FIXME 设备实例:一级告警 + // FDP智能预警 + alarms.addAll(this.intelligentEarly(code,start,end)); + return JSONObject.toJSONString(alarms); + } + + /** + * 查询hz3000告警 + * @param code + */ + private List hz3000Alarm(String code,String start,String end) { + SoeQueryConditionByStation query = new SoeQueryConditionByStation(); + query.setStationIds(Collections.singletonList(code)); + query.setTypes(Collections.singletonList(AlarmHandleConstant.FAULT)); + query.setBeginTime(LocalDateTime.parse(start,DateUtil.DATETIME_FORMATTER)); + query.setEndTime(LocalDateTime.parse(end,DateUtil.DATETIME_FORMATTER)); + query.setNeedPage(false); + Result> result = soeClient.getByStationsAndTime(query); + if(!result.isSuccess() || ObjectUtil.isEmpty(result.getData()) || CollectionUtil.isEmpty(result.getData().getRecords())){ + return new ArrayList<>(); + } + return result.getData().getRecords().stream().collect(Collectors.groupingBy(SoeData::getSoeExplain)).entrySet().stream().map(entry->{ + RunAlarmVo alarm = new RunAlarmVo(); + alarm.setAlarmTime(DateUtil.format(entry.getValue().stream().sorted(Comparator.comparing(SoeData::getTs)).collect(Collectors.toList()).get(0).getTs(),DateUtil.PATTERN_DATETIME)); + alarm.setDeviceName(entry.getValue().get(0).getDeviceName()); + alarm.setContent(entry.getKey()); + alarm.setType(String.valueOf(AlarmConstants.FAULT)); + alarm.setTypeName("故障"); + alarm.setCount(Math.max(entry.getValue().stream().filter(o->StringUtil.isNotBlank(o.getTraceCount())).mapToInt(soe->Integer.parseInt(soe.getTraceCount())).sum(), 1)); + return alarm; + }).collect(Collectors.toList()); + } + + /** + * 智能预警 + * @param code + * @param start + * @param end + * @return + */ + private List intelligentEarly(String code, String start, String end) { + StbAnalysisDTO param = new StbAnalysisDTO(); + param.setStartTime(LocalDateTime.parse(start,DateUtil.DATETIME_FORMATTER)); + param.setEndTime(LocalDateTime.parse(end, DateUtil.DATETIME_FORMATTER)); + param.setStations(Collections.singletonList(code)); + param.setNeedPage(false); + Result> result = soeDataClient.pageStbAnalysis(param); + if(!result.isSuccess() || ObjectUtil.isEmpty(result.getData()) || CollectionUtil.isEmpty(result.getData().getRecords())){ + return new ArrayList<>(); + } + return result.getData().getRecords().stream().collect(Collectors.groupingBy(StbAnalysisVO::getName)).entrySet().stream().map(entry->{ + RunAlarmVo alarm = new RunAlarmVo(); + alarm.setAlarmTime(entry.getValue().stream().sorted(Comparator.comparing(StbAnalysisVO::getTs)).collect(Collectors.toList()).get(0).getTs()); + alarm.setDeviceName(entry.getValue().get(0).getOrd()); + alarm.setContent(entry.getKey()); + alarm.setType(String.valueOf(AlarmConstants.EARLY)); + alarm.setTypeName("智能预警"); + alarm.setReason(entry.getValue().get(0).getFinfo()); + alarm.setMemo(entry.getValue().get(0).getInfo()); + alarm.setCount(entry.getValue().size()); + return alarm; + }).collect(Collectors.toList()); + } + + /** + * 运行曲线 + * @param devices + * @return + */ + private String curveData(List devices) { + List curveDatas = devices.stream().map(device -> { + CurveEchartVo curveData = new CurveEchartVo(); + curveData.setDeviceCode(device.getNumber()); + curveData.setDeviceName(device.getName()); + // 负荷曲线 + curveData.setLoadCurve(this.curve(this.attribute(0), device.getNumber())); + // 轴承温度曲线 + curveData.setBearingTempCurve(this.curve(this.attribute(1), device.getNumber())); + // 定子温度曲线 + curveData.setStatorTempCurve(this.curve(this.attribute(2), device.getNumber())); + return curveData; + }).collect(Collectors.toList()); + return JSONObject.toJSONString(curveDatas); + } + + /** + * 获取曲线数据 + * @param attributes + * @param deviceCode + * @return + * + * + */ + private List curve(List attributes, String deviceCode) { + Calendar calendar = Calendar.getInstance(); + calendar.setTime(DateUtil.parse("2024-05-01 00:00:00",DateUtil.PATTERN_DATETIME)); + //calendar.setTime(DateUtil.parse(DateUtil.format(new Date(),DateUtil.PATTERN_DATE) + " 23:59:59",DateUtil.PATTERN_DATETIME)); + calendar.add(Calendar.DAY_OF_MONTH,-1); + String end = DateUtil.format(calendar.getTime(),DateUtil.PATTERN_DATETIME); + calendar.add(Calendar.MONTH,-1); + calendar.add(Calendar.HOUR_OF_DAY,-calendar.get(Calendar.HOUR_OF_DAY)); + calendar.add(Calendar.MINUTE, -calendar.get(Calendar.MINUTE)); + calendar.add(Calendar.SECOND, -calendar.get(Calendar.SECOND)); + String start = DateUtil.format(calendar.getTime(),DateUtil.PATTERN_DATETIME); + List datas = dataService.periodTargetSignages(start,end,3,3,deviceCode,attributes.stream().map(AttributeVo::getSignage).collect(Collectors.toList())); + if(CollectionUtil.isEmpty(datas)){ + return new ArrayList<>(); + } + List analyseDatas = new ArrayList<>(); + Calendar day = Calendar.getInstance(); + datas.forEach(data->{ + if(CollectionUtil.isEmpty(data.getList())){ + return; + } + analyseDatas.addAll(data.getList().stream().peek(item->{ + item.setSignage(data.getSignage()); + Date date = DateUtil.parse(item.getTs(), "yyyy-MM-dd HH:mm:ss.s"); + day.setTime(date); + item.setTs(String.valueOf(day.get(Calendar.DAY_OF_MONTH))); + }).collect(Collectors.toList())); + }); + if(CollectionUtil.isEmpty(analyseDatas)){ + return new ArrayList<>(); + } + Map> map = analyseDatas.stream().collect(Collectors.groupingBy(AnalyseDataTaosVO::getTs)); + return map.entrySet().stream().map(entry->{ + EchartVo echart = new EchartVo(); + echart.setTime(Integer.valueOf(entry.getKey())); + echart.setValues(entry.getValue().stream().map(value->{ + EchartValueVo echartValue = new EchartValueVo(); + echartValue.setAttribute(value.getSignage()); + echartValue.setAttributeName(attributes.stream().filter(o->o.getSignage().equals(value.getSignage())).collect(Collectors.toList()).get(0).getSignageName()); + if(StringUtil.isEmpty(value.getVal())){ + echartValue.setValue(0.0); + }else{ + echartValue.setValue(Double.parseDouble(value.getVal())); + } + return echartValue; + }).collect(Collectors.toList())); + return echart; + }).sorted(Comparator.comparing(EchartVo::getTime)).collect(Collectors.toList()); + } + + /** + * 曲线属性获取 + * @param attributeType + * @return + */ + private List attribute(int attributeType) { + List attributes = new ArrayList<>(); + switch (attributeType){ + case 0: + AttributeVo attribute = new AttributeVo(); + attribute.setSignage(HomePageConstant.ACTIVE_POWER); + attribute.setSignageName("负荷"); + attributes.add(attribute); + break; + case 1: + + AttributeVo upper_temp = new AttributeVo(); + upper_temp.setSignage(HomePageConstant.UPPER_GUIDE_BEARING_TEMP); + upper_temp.setSignageName("上导轴承瓦温1"); + attributes.add(upper_temp); + AttributeVo oil_tem = new AttributeVo(); + oil_tem.setSignage(HomePageConstant.UPPER_GUIDE_BEARING_OIL_GROOVE_TEMP); + oil_tem.setSignageName("上导轴承油槽温度"); + attributes.add(oil_tem); + AttributeVo thrust_tem = new AttributeVo(); + thrust_tem.setSignage(HomePageConstant.THRUST_BEARING_TEMP); + thrust_tem.setSignageName("推力轴瓦温度1"); + attributes.add(thrust_tem); + AttributeVo lower_tem = new AttributeVo(); + lower_tem.setSignage(HomePageConstant.LOWER_GUIDE_BEARING_TEMP); + lower_tem.setSignageName("下导轴承瓦温1"); + attributes.add(lower_tem); + AttributeVo tank_tem = new AttributeVo(); + tank_tem.setSignage(HomePageConstant.LOWER_GUIDE_OIL_TANK_TEMP); + tank_tem.setSignageName("下导油槽温度"); + attributes.add(tank_tem); + AttributeVo tile_tem = new AttributeVo(); + tile_tem.setSignage(HomePageConstant.WATER_GUIDE_TILE_TEMP); + tile_tem.setSignageName("水导瓦温"); + attributes.add(tile_tem); + AttributeVo water_tem = new AttributeVo(); + water_tem.setSignage(HomePageConstant.WATER_GUIDE_OIL_TANK_TEMP); + water_tem.setSignageName("水导油槽温度"); + attributes.add(water_tem); + break; + case 2: + AttributeVo A_tem = new AttributeVo(); + A_tem.setSignage(HomePageConstant.A_PHASE_IRON_CORE_TEMP); + A_tem.setSignageName("A相铁芯温度1"); + attributes.add(A_tem); + + AttributeVo B_tem = new AttributeVo(); + B_tem.setSignage(HomePageConstant.B_PHASE_IRON_CORE_TEMP); + B_tem.setSignageName("B相铁芯温度1"); + attributes.add(B_tem); + + AttributeVo C_tem = new AttributeVo(); + C_tem.setSignage(HomePageConstant.C_PHASE_IRON_CORE_TEMP); + C_tem.setSignageName("C相铁芯温度1"); + attributes.add(C_tem); + break; + } + return attributes; + } + + /** + * 检查站点是否存在设备信息 + * @param stationCode + * @return + */ + @Override + public Boolean check(String stationCode) { + // 查询站点 + StationVO station = stationService.getStationByCode(stationCode); + if(ObjectUtil.isEmpty(station)){ + throw new ServiceException("未查询到站点信息!"); + } + // 查询设备 + R> emInfos = deivceClient.getEmInfoByDept(Collections.singletonList(station.getRefDept())); + if(!emInfos.isSuccess() || CollectionUtil.isEmpty(emInfos.getData())){ + throw new ServiceException("站点未配置机组设备信息、请先为站点添加设备,绑定设备实例,再进行月报查询!"); + } + List devices = emInfos.getData().stream().filter(o->"2".equals(o.getEmType())).collect(Collectors.toList()); + if(CollectionUtil.isEmpty(devices)){ + throw new ServiceException("站点未配置机组设备信息、请先为站点添加设备,绑定设备实例,再进行月报查询!"); + } + return true; + } + + /** * 手绘运行数据表格 * @return */ @@ -280,16 +803,14 @@ public class RunMonthServiceImpl extends BaseServiceImpl curveToArray(List curves) { List attrValues = new ArrayList<>(); - curves.forEach(curve->{ - attrValues.addAll(curve.getValues().stream().map(value->{ - CurveAttrValueVo attrValue = new CurveAttrValueVo(); - attrValue.setAttribute(value.getAttribute()); - attrValue.setAttributeName(value.getAttributeName()); - attrValue.setTime(curve.getTime()); - attrValue.setValue(value.getValue()); - return attrValue; - }).collect(Collectors.toList())); - }); + curves.forEach(curve-> attrValues.addAll(curve.getValues().stream().map(value->{ + CurveAttrValueVo attrValue = new CurveAttrValueVo(); + attrValue.setAttribute(value.getAttribute()); + attrValue.setAttributeName(value.getAttributeName()); + attrValue.setTime(curve.getTime()); + attrValue.setValue(value.getValue()); + return attrValue; + }).collect(Collectors.toList()))); return attrValues.stream().collect(Collectors.groupingBy(CurveAttrValueVo::getAttribute)).entrySet().stream().map(entry->{ CurveYArrayVo yArray = new CurveYArrayVo(); yArray.setAttribute(entry.getKey());