From a9e8e5245d9725aedd712e04fc56cd4aa8dece14 Mon Sep 17 00:00:00 2001 From: yang_shj <1069818635@QQ.com> Date: Fri, 19 Jan 2024 15:11:57 +0800 Subject: [PATCH 1/6] =?UTF-8?q?#=E7=AB=99=E7=82=B9=E7=AD=9B=E9=80=89?= =?UTF-8?q?=E5=91=8A=E8=AD=A6=E6=97=A0=E6=95=88=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../alert/service/impl/HistoryAbnormalAlarmServiceImpl.java | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/alert/service/impl/HistoryAbnormalAlarmServiceImpl.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/alert/service/impl/HistoryAbnormalAlarmServiceImpl.java index e02cfe7..f6e34ea 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/alert/service/impl/HistoryAbnormalAlarmServiceImpl.java +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/alert/service/impl/HistoryAbnormalAlarmServiceImpl.java @@ -10,7 +10,10 @@ import com.hnac.hzims.operational.alert.entity.HistoryAbnormalAlarmEntity; import com.hnac.hzims.operational.alert.mapper.HistoryAbnormalAlarmMapper; import com.hnac.hzims.operational.alert.service.AlarmHandleService; import com.hnac.hzims.operational.alert.service.HistoryAbnormalAlarmService; -import com.hnac.hzims.operational.alert.vo.*; +import com.hnac.hzims.operational.alert.vo.AlarmDataVo; +import com.hnac.hzims.operational.alert.vo.AlarmParamVo; +import com.hnac.hzims.operational.alert.vo.AlarmReustVo; +import com.hnac.hzims.operational.alert.vo.HistoryAlarmVo; import com.hnac.hzims.operational.config.vo.AlarmDataPageVo; import com.hnac.hzims.operational.config.vo.AlarmVo; import com.hnac.hzims.operational.config.vo.IntelligentAlarmCountVo; @@ -38,7 +41,6 @@ import org.springblade.core.tool.utils.ObjectUtil; import org.springblade.system.entity.Dept; import org.springblade.system.feign.ISysClient; import org.springframework.beans.factory.annotation.Value; -import org.springframework.data.redis.core.RedisTemplate; import org.springframework.stereotype.Service; import java.lang.reflect.Field; @@ -46,7 +48,6 @@ import java.math.BigDecimal; import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; import java.util.*; -import java.util.concurrent.TimeUnit; import java.util.stream.Collectors; /** @@ -225,7 +226,9 @@ public class HistoryAbnormalAlarmServiceImpl extends BaseServiceImpl wrapper = Wrappers.lambdaQuery(); wrapper.eq(StationEntity::getServeType,HomePageConstant.HYDROPOWER_SERVETYPE); wrapper.in(StationEntity::getRefDept,result.getData().stream().map(Dept::getId).collect(Collectors.toList())); - + if(StringUtils.isNotEmpty(param.getCode())){ + wrapper.eq(StationEntity::getCode,param.getCode()); + } List stations = stationService.list(wrapper); if(CollectionUtil.isEmpty(stations)){ return new AlarmReustVo(); From d815997ffdbec902920d7c58be4b83144ae52712 Mon Sep 17 00:00:00 2001 From: yang_shj <1069818635@QQ.com> Date: Mon, 22 Jan 2024 10:10:47 +0800 Subject: [PATCH 2/6] =?UTF-8?q?#=E8=BF=90=E8=A1=8C=E6=9C=88=E6=8A=A5?= =?UTF-8?q?=E5=91=8A=E6=9B=B2=E7=BA=BF=E5=91=BD=E5=90=8Dbug=E4=BF=AE?= =?UTF-8?q?=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../hzims/operational/main/service/impl/RunMonthReportServiceImpl.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/service/impl/RunMonthReportServiceImpl.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/service/impl/RunMonthReportServiceImpl.java index d7add83..3a13109 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/service/impl/RunMonthReportServiceImpl.java +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/service/impl/RunMonthReportServiceImpl.java @@ -283,7 +283,7 @@ public class RunMonthReportServiceImpl extends ServiceImpl> statorMap = getHisData(emInfoExtendVo.getNumber(), map, df, statorSignages, signKeyMap, date); - runMonthReportUnitVoDZ.setName(emInfoExtendVo.getName() + "定子温度曲线"); + runMonthReportUnitVoDZ.setName(emInfoExtendVo.getName() + "定子电流/电压曲线"); runMonthReportUnitVoDZ.setDataMap(statorMap); unitYcDataList.add(runMonthReportUnitVoDZ); From 29abfb9009e990b493ac64d3f7e4ca7de9b7a3b0 Mon Sep 17 00:00:00 2001 From: yang_shj <1069818635@QQ.com> Date: Wed, 31 Jan 2024 14:09:25 +0800 Subject: [PATCH 3/6] =?UTF-8?q?#=E5=A2=9E=E5=8A=A0Json=E8=BD=AC=E6=8D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/operation/monitor/impl/MonitorServiceImpl.java | 2 +- .../operational/config/service/impl/CentralMonitorServiceImpl.java | 7 +++++-- .../operational/station/service/impl/RealMonitorServiceImpl.java | 6 +++++- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/monitor/impl/MonitorServiceImpl.java b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/monitor/impl/MonitorServiceImpl.java index 831dade..8f41d10 100644 --- a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/monitor/impl/MonitorServiceImpl.java +++ b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/monitor/impl/MonitorServiceImpl.java @@ -344,7 +344,7 @@ public class MonitorServiceImpl implements MonitorService { Thread.currentThread().interrupt(); } pool.shutdown(); - redisTemplate.opsForValue().set(moniter_station_cache_final, stationList); + redisTemplate.opsForValue().set(moniter_station_cache_final, JSONObject.toJSONString(stationList)); } /** diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/config/service/impl/CentralMonitorServiceImpl.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/config/service/impl/CentralMonitorServiceImpl.java index 6f92abc..3f8b367 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/config/service/impl/CentralMonitorServiceImpl.java +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/config/service/impl/CentralMonitorServiceImpl.java @@ -1,5 +1,7 @@ package com.hnac.hzims.operational.config.service.impl; +import cn.hutool.core.lang.TypeReference; +import com.alibaba.fastjson.JSONObject; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; @@ -75,10 +77,11 @@ public class CentralMonitorServiceImpl implements CentralMonitorService { if (CollectionUtil.isEmpty(codeList)) { return null; } - List result = (List) redisTemplate.opsForValue().get(moniter_station_key); - if (StringUtil.isEmpty(result)) { + Object json = redisTemplate.opsForValue().get(moniter_station_key); + if (StringUtil.isEmpty(json)) { return null; } + List result = JSONObject.parseObject(json.toString(), new TypeReference>() {}); return result.stream().filter(o -> codeList.contains(o.getStationCode())).collect(Collectors.toList()); } diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/service/impl/RealMonitorServiceImpl.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/service/impl/RealMonitorServiceImpl.java index 411588c..352d070 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/service/impl/RealMonitorServiceImpl.java +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/service/impl/RealMonitorServiceImpl.java @@ -851,8 +851,12 @@ public class RealMonitorServiceImpl implements IRealMonitorService { if(ObjectUtil.isEmpty(message) || CollectionUtil.isEmpty(message.getDeptIds())){ return null; } + Object json = redisTemplate.opsForValue().get(moniter_station_key); + if(ObjectUtil.isEmpty(json)){ + return null; + } // 获取所有监控缓存数据 - List realStationVoList = (List) redisTemplate.opsForValue().get(moniter_station_key); + List realStationVoList = JSONObject.parseObject(json.toString(),new TypeReference>() {}); if(CollectionUtil.isEmpty(realStationVoList)){ return null; } From 0152c5791c36fc63dbedfb4b687af68fb5435cdb Mon Sep 17 00:00:00 2001 From: yang_shj <1069818635@QQ.com> Date: Wed, 31 Jan 2024 14:36:43 +0800 Subject: [PATCH 4/6] =?UTF-8?q?#=E5=A2=9E=E5=8A=A0Json=E8=BD=AC=E6=8D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/operation/monitor/impl/MonitorServiceImpl.java | 2 +- .../operational/station/service/impl/RealMonitorServiceImpl.java | 8 +++----- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/monitor/impl/MonitorServiceImpl.java b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/monitor/impl/MonitorServiceImpl.java index 8f41d10..831dade 100644 --- a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/monitor/impl/MonitorServiceImpl.java +++ b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/monitor/impl/MonitorServiceImpl.java @@ -344,7 +344,7 @@ public class MonitorServiceImpl implements MonitorService { Thread.currentThread().interrupt(); } pool.shutdown(); - redisTemplate.opsForValue().set(moniter_station_cache_final, JSONObject.toJSONString(stationList)); + redisTemplate.opsForValue().set(moniter_station_cache_final, stationList); } /** diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/service/impl/RealMonitorServiceImpl.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/service/impl/RealMonitorServiceImpl.java index 352d070..1d7072e 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/service/impl/RealMonitorServiceImpl.java +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/service/impl/RealMonitorServiceImpl.java @@ -467,7 +467,7 @@ public class RealMonitorServiceImpl implements IRealMonitorService { } pool.shutdown(); log.info(thread.getName() + "步骤12所有线程完成 耗时 : {}",System.currentTimeMillis() - beginTime); - redisTemplate.opsForValue().set(moniter_station_key, stationList); + redisTemplate.opsForValue().set(moniter_station_key, JSONObject.toJSONString(stationList)); } /** @@ -851,12 +851,10 @@ public class RealMonitorServiceImpl implements IRealMonitorService { if(ObjectUtil.isEmpty(message) || CollectionUtil.isEmpty(message.getDeptIds())){ return null; } - Object json = redisTemplate.opsForValue().get(moniter_station_key); - if(ObjectUtil.isEmpty(json)){ + List realStationVoList = (List) redisTemplate.opsForValue().get(moniter_station_key); + if(ObjectUtil.isEmpty(realStationVoList)){ return null; } - // 获取所有监控缓存数据 - List realStationVoList = JSONObject.parseObject(json.toString(),new TypeReference>() {}); if(CollectionUtil.isEmpty(realStationVoList)){ return null; } From 2488de80e97d142a481fbc5ae2146afc102bbfbc Mon Sep 17 00:00:00 2001 From: yang_shj <1069818635@QQ.com> Date: Sun, 4 Feb 2024 15:05:22 +0800 Subject: [PATCH 5/6] =?UTF-8?q?#=E6=BC=94=E7=A4=BA=E5=B9=B3=E5=8F=B0?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../data/controller/HzimsDataController.java | 19 +- .../operational/data/service/HzimsDataService.java | 4 + .../data/service/impl/HzimsDataServiceImpl.java | 297 ++++++++++++++++++++- 3 files changed, 299 insertions(+), 21 deletions(-) diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/data/controller/HzimsDataController.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/data/controller/HzimsDataController.java index 25b89c9..a12dc75 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/data/controller/HzimsDataController.java +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/data/controller/HzimsDataController.java @@ -8,9 +8,10 @@ import lombok.AllArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springblade.core.log.annotation.ApiLog; import org.springblade.core.tool.api.R; -import org.springframework.web.bind.annotation.*; - -import java.util.Map; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; /** @@ -47,15 +48,11 @@ public class HzimsDataController { return R.data(service.saveStation()); } - /** - * 测试动作模板回调接口 - */ @ApiLog - @PostMapping("/test") + @GetMapping("/station") @ApiOperationSupport(order = 1) - @ApiOperation(value = "测试动作模板回调接口", notes = "map接收参数") - public R test(@RequestBody Map params) { - log.error("动作模板回调接口参数: {}",params.toString()); - return R.data(params); + @ApiOperation(value = "站点数据获取", notes = "传入站点code") + public R station(@RequestParam("stationCode") String stationCode) { + return R.data(service.station(stationCode)); } } diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/data/service/HzimsDataService.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/data/service/HzimsDataService.java index 906bad5..11c6878 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/data/service/HzimsDataService.java +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/data/service/HzimsDataService.java @@ -1,5 +1,7 @@ package com.hnac.hzims.operational.data.service; +import com.hnac.hzims.operational.main.vo.HydropowerStationVo; + import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.io.IOException; @@ -16,4 +18,6 @@ public interface HzimsDataService { boolean saveArea(); boolean saveStation(); + + HydropowerStationVo station(String stationCode); } diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/data/service/impl/HzimsDataServiceImpl.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/data/service/impl/HzimsDataServiceImpl.java index 986e74c..dac8435 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/data/service/impl/HzimsDataServiceImpl.java +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/data/service/impl/HzimsDataServiceImpl.java @@ -1,12 +1,16 @@ package com.hnac.hzims.operational.data.service.impl; import com.alibaba.fastjson.JSONObject; +import com.baomidou.mybatisplus.core.toolkit.Wrappers; +import com.hnac.hzims.equipment.entity.PlanGenerationEntity; +import com.hnac.hzims.equipment.feign.IPlanGenertionClient; import com.hnac.hzims.equipment.vo.EminfoAndEmParamVo; import com.hnac.hzims.operational.data.service.HzimsDataService; import com.hnac.hzims.operational.data.vo.AreaVo; +import com.hnac.hzims.operational.main.constant.HomePageConstant; import com.hnac.hzims.operational.main.service.AreaService; import com.hnac.hzims.operational.main.service.IMainSystemMonitoringService; -import com.hnac.hzims.operational.main.constant.HomePageConstant; +import com.hnac.hzims.operational.main.vo.*; import com.hnac.hzims.operational.station.entity.StationEntity; import com.hnac.hzims.operational.station.service.IStationService; import com.hnac.hzims.operational.station.vo.HzimsStationCountVo; @@ -16,19 +20,26 @@ import org.apache.commons.collections4.MapUtils; import org.springblade.core.log.exception.ServiceException; import org.springblade.core.tool.api.R; import org.springblade.core.tool.utils.CollectionUtil; +import org.springblade.core.tool.utils.DateUtil; +import org.springblade.core.tool.utils.ObjectUtil; +import org.springblade.core.tool.utils.StringUtil; import org.springblade.system.entity.Dept; import org.springblade.system.feign.ISysClient; import org.springframework.beans.factory.annotation.Value; +import org.springframework.data.redis.core.RedisTemplate; import org.springframework.stereotype.Service; -import javax.validation.constraints.NotNull; import java.io.InputStream; import java.io.OutputStream; +import java.math.BigDecimal; +import java.math.RoundingMode; import java.net.HttpURLConnection; import java.net.URL; -import java.util.Arrays; -import java.util.List; -import java.util.Map; +import java.time.Duration; +import java.time.LocalDate; +import java.time.LocalDateTime; +import java.time.format.DateTimeFormatter; +import java.util.*; import java.util.stream.Collectors; @@ -40,20 +51,33 @@ import java.util.stream.Collectors; @RequiredArgsConstructor public class HzimsDataServiceImpl implements HzimsDataService { - @NotNull private final AreaService areaService; - @NotNull + private final IMainSystemMonitoringService emService; - @NotNull - private final ISysClient sysClient; - @NotNull + private final IStationService stationService; + private final IMainSystemMonitoringService maintenanceTaskService; + + private final ISysClient sysClient; + + private final IPlanGenertionClient planGenertionClient; + + private final RedisTemplate redisTemplate; + @Value("${hzims.operation.save.area.url}") public String AREA_URL; @Value("${hzims.operation.save.station.url}") public String STATION_URL; + private final static String recent_year_power_data = "hzims:operation:key:power:data"; + + private final static String loadwater_level_key = "hzims:operation:loadwater:level:key"; + + private final static String load_hydropower_unit_real_key = "hzims:operation:loadhydropowerunit:real:key"; + + private final static String load_hydropower_unit_target_key = "hzims:operation:loadhydropowerunit:target:key"; + @Override public boolean saveArea() { R> result = sysClient.getDeptList(); @@ -103,6 +127,7 @@ public class HzimsDataServiceImpl implements HzimsDataService { return this.sendMessage(JSONObject.toJSONBytes(list),STATION_URL); } + /** * 发送请求 * @param params @@ -135,4 +160,256 @@ public class HzimsDataServiceImpl implements HzimsDataService { } return true; } + + /** + * 水电站-站点信息 + * @param stationCode + * @return + */ + @Override + public HydropowerStationVo station(String stationCode) { + if(StringUtil.isEmpty(stationCode)){ + return new HydropowerStationVo(); + } + // 站点 + StationEntity station = stationService.getOne(Wrappers.lambdaQuery() + .eq(StationEntity::getCode,stationCode) + .eq(StationEntity::getDataOrigin,"0") + .eq(StationEntity::getServeType,HomePageConstant.HYDROPOWER_SERVETYPE) + .eq(StationEntity::getType,HomePageConstant.HYDROPOWER) + ); + if(ObjectUtil.isEmpty(station)){ + return new HydropowerStationVo(); + } + // 实时监测点数据 + List realList = (List) redisTemplate.opsForValue().get(load_hydropower_unit_real_key); + // 获取站点机组指标数据 + List targetList = (List) redisTemplate.opsForValue().get(load_hydropower_unit_target_key); + // 所有设备 + List deviceList = maintenanceTaskService.getEmInfoList(); + HydropowerStationVo response = new HydropowerStationVo(); + // 近年发电量数据 + Map> map = (Map>) redisTemplate.opsForValue().get(recent_year_power_data); + response.setDeptId(station.getRefDept()); + response.setDeptName(station.getName()); + response.setStationCode(station.getCode()); + // 限制水位 + response.setLimitWaterLevel(station.getLimitWaterLevel()); + // 运行天数 + response.setRunDay(this.getRunDay(station)); + // 装机容量 + response.setInstalledCapacity(this.getInstalledCapacity(deviceList,station.getRefDept())); + // 总有功功率(总发电负荷) + response.setPowerSum(this.getPowerSum(realList,station.getRefDept())); + // 总有功单位 + response.setPowerUnit("kW"); + // 月计划发电量 + response.setPlanPowerMon(this.getPlanPowerrMon(station.getCode())); + // 年计划发电量 + response.setPlanPowerYear(this.getPlanPowerYear(station.getCode())); + // 月发电量、年发电量、年发电完成率 + this.handleStationInfo(station.getRefDept(),response); + // 水位、水位曲线 + this.handleWaterLeve(station.getCode(),response); + // 年发电量完成百分比 + response.setPowerYearMap(this.handlePowerFinish(Collections.singletonList(station),map)); + return response; + } + + /** + * 获取站点运行天数 + * @param station + * @return + */ + private int getRunDay(StationEntity station) { + if (ObjectUtil.isEmpty(station.getCommissionTime())) { + return 0; + } + // 计算投运时间与当前时间相隔天数 + Duration dur = Duration.between(station.getCommissionTime(), LocalDateTime.now()); + return (int) dur.toDays(); + } + + /** + * 获取设备装机容量 + * @param list + * @param refDept + * @return + */ + private double getInstalledCapacity(List list, Long refDept) { + if(CollectionUtil.isEmpty(list) || ObjectUtil.isEmpty(refDept)){ + return 0.0; + } + return list.stream().filter(o -> refDept.equals(o.getCreateDept())).mapToDouble(EminfoAndEmParamVo::getInstalledCapacity).sum(); + } + + + /** + * 获取总发电负荷 + * @param deptId + * @return + */ + private Double getPowerSum(List realList,Long deptId) { + if(ObjectUtil.isEmpty(deptId)){ + return 0.0; + } + // 获取站点机组实时数据 + if(CollectionUtil.isEmpty(realList)){ + return 0.0; + } + return realList.stream().filter(o->deptId.equals(o.getDeptId())).mapToDouble(o->{ + if("MW".equalsIgnoreCase(o.getPowerUnit())){ + return o.getActivePower() * 1000; + } + return o.getActivePower(); + }).sum(); + } + + /** + * 获取月计划发电量 + * @param code + * @return + */ + private float getPlanPowerrMon(String code) { + R R = planGenertionClient.planGenerationMonthCount(code, DateUtil.format(new Date(), "yyyy-MM")); + if(!R.isSuccess() || ObjectUtil.isEmpty(R.getData())){ + return 0f; + } + return R.getData(); + } + + /** + * 获取年计划发电量 + * @param code + * @return + */ + private float getPlanPowerYear(String code) { + R R = planGenertionClient.planGenerationYearCount(code); + if(!R.isSuccess() || ObjectUtil.isEmpty(R.getData())){ + return 0f; + } + // 查询年计划发电量 + return R.getData(); + } + + /** + * 站点信息处理 + * @param deptId + * @param response + */ + private void handleStationInfo(Long deptId, HydropowerStationVo response) { + response.setPowerMon(0f); + response.setPowerYear(0f); + response.setPowerRateYear(0.0); + List targetList = (List) redisTemplate.opsForValue().get(load_hydropower_unit_target_key); + if(CollectionUtil.isEmpty(targetList)){ + return; + } + // 月发电量 + float powerMont = (float) targetList.stream().filter(o-> deptId.equals(o.getDeptId())).mapToDouble(HydropowerUnitTargetVo::getPowerMon).sum(); + response.setPowerMon(powerMont); + // 年发电量 + float powerYear = (float) targetList.stream().filter(o-> deptId.equals(o.getDeptId())).mapToDouble(HydropowerUnitTargetVo::getPowerYear).sum(); + response.setPowerYear(powerYear); + // 年发电完成率 + float planPowerYear = response.getPlanPowerYear(); + if(Math.abs(planPowerYear) <= 0){ + response.setPowerRateYear(0.0); + } else { + double powerRateYear = BigDecimal.valueOf(powerYear / planPowerYear * 100).setScale(2, RoundingMode.HALF_UP).doubleValue(); + response.setPowerRateYear(powerRateYear); + } + } + + /** + * 站点水位数据处理 + * @param code + * @param response + */ + private void handleWaterLeve(String code, HydropowerStationVo response) { + response.setFrontWaterLevel(0.0); + List levelList = (List) redisTemplate.opsForValue().get(loadwater_level_key); + if(CollectionUtil.isEmpty(levelList)){ + return; + } + List validList = levelList.stream().filter(o-> code.equals(o.getStationCode())).collect(Collectors.toList()); + if(CollectionUtil.isEmpty(validList)){ + return; + } + WaterLevelVo level = validList.get(0); + // 前池水位、当日水位曲线 + response.setFrontWaterLevel(level.getFrontWaterLevel()); + response.setFrontCurveMap(level.getFrontCurveMap()); + } + + /** + * 年发电量完成百分比 + * @param stations + */ + private List handlePowerFinish(List stations, Map> map) { + if (CollectionUtil.isEmpty(stations)) { + return null; + } + // 查询计划发电量 + Calendar calendar = Calendar.getInstance(); + calendar.setTime(new Date()); + List plans = planGenertionClient.getPlanGenerationByParam(stations.stream().map(StationEntity::getCode).collect(Collectors.toList()), null, String.valueOf(calendar.get(Calendar.YEAR))); + // 获取月份集合 + List monList = this.mons(0, 12, false); + return monList.stream().map(o -> { + PowerMonthVo vo = new PowerMonthVo(); + LocalDate localDate = LocalDate.parse(DateUtil.format(new Date(), o), DateTimeFormatter.ofPattern(DateUtil.PATTERN_DATE)); + vo.setStrMonth(o); + vo.setYear(localDate.getYear()); + vo.setMonth(localDate.getMonthValue()); + // 实际发电量 + if (CollectionUtil.isEmpty(map)) { + vo.setPower(0f); + } else { + float generate = (float) map.entrySet().stream(). + filter(entry -> stations.stream().map(StationEntity::getId).collect(Collectors.toList()).contains(entry.getKey())). + mapToDouble(valueMap -> valueMap.getValue().entrySet().stream().filter(entry -> entry.getKey().equals(o)) + .mapToDouble(Map.Entry::getValue).sum()).sum(); + vo.setPower(generate); + } + // 计划发电量 + if (CollectionUtil.isEmpty(plans)) { + vo.setPlanPower(0f); + } else { + String mon = localDate.format(DateTimeFormatter.ofPattern("yyyy-MM")); + vo.setPlanPower((float) plans.stream().filter(plan -> mon.equals(plan.getDateTime())).mapToDouble(PlanGenerationEntity::getPlanGeneration).sum()); + } + return vo; + }).collect(Collectors.toList()); + } + + /** + * 获取近年月份集合 + * @param year + * @return + */ + public List mons(int year, int endMoth, boolean nextMon) { + List list = new ArrayList<>(); + // 开始日期 + Calendar endCal = Calendar.getInstance(); + endCal.setTime(new Date()); + endCal.add(Calendar.MONTH, -endCal.get(Calendar.MONTH) + endMoth); + endCal.add(Calendar.DATE, -endCal.get(Calendar.DATE) + 1); + + // 结束日期 + Calendar startCal = Calendar.getInstance(); + startCal.setTime(new Date()); + startCal.set(Calendar.YEAR, startCal.get(Calendar.YEAR) - year); + startCal.add(Calendar.MONTH, -startCal.get(Calendar.MONTH)); + startCal.add(Calendar.DATE, -startCal.get(Calendar.DATE) + 1); + // 获取日期之间的月份 + while (endCal.after(startCal)) { + list.add(DateUtil.format(startCal.getTime(),DateUtil.PATTERN_DATE)); + startCal.add(Calendar.MONTH, 1); + } + if(nextMon){ + list.add(DateUtil.format(endCal.getTime(),DateUtil.PATTERN_DATE)); + } + return list; + } } From a9c07883431ec611c3ad8d8c1b61bc5a42558a37 Mon Sep 17 00:00:00 2001 From: yang_shj <1069818635@QQ.com> Date: Tue, 6 Feb 2024 15:20:41 +0800 Subject: [PATCH 6/6] =?UTF-8?q?#=E6=BC=94=E7=A4=BA=E5=B9=B3=E5=8F=B0?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3=E3=80=8130=E5=A4=A9=E5=8F=91=E7=94=B5?= =?UTF-8?q?=E9=87=8F=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../operational/data/vo/ConverElectricityVo.java | 17 ++ .../operational/data/vo/LoadWaterLevelVo.java | 20 ++ .../hzims/operational/data/vo/PowerConvertVo.java | 22 +++ .../operational/main/vo/HydropowerStationVo.java | 3 + .../operation/home/impl/RealTargetServiceImpl.java | 2 +- .../data/controller/HzimsDataController.java | 19 +- .../operational/data/service/HzimsDataService.java | 3 + .../data/service/impl/HzimsDataServiceImpl.java | 211 ++++++++++++++++++++- .../main/service/IAnalyseDataService.java | 2 + .../main/service/impl/AnalyseDataServiceImpl.java | 39 ++++ .../main/service/impl/HydropowerServiceImpl.java | 6 +- 11 files changed, 332 insertions(+), 12 deletions(-) create mode 100644 hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/data/vo/ConverElectricityVo.java create mode 100644 hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/data/vo/LoadWaterLevelVo.java create mode 100644 hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/data/vo/PowerConvertVo.java diff --git a/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/data/vo/ConverElectricityVo.java b/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/data/vo/ConverElectricityVo.java new file mode 100644 index 0000000..dd7a7d5 --- /dev/null +++ b/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/data/vo/ConverElectricityVo.java @@ -0,0 +1,17 @@ +package com.hnac.hzims.operational.data.vo; + +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +/** + * @author ysj + */ +@Data +public class ConverElectricityVo { + + @ApiModelProperty("时间") + private String time; + + @ApiModelProperty("电量") + private Double electricity; +} \ No newline at end of file diff --git a/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/data/vo/LoadWaterLevelVo.java b/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/data/vo/LoadWaterLevelVo.java new file mode 100644 index 0000000..a7512e5 --- /dev/null +++ b/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/data/vo/LoadWaterLevelVo.java @@ -0,0 +1,20 @@ +package com.hnac.hzims.operational.data.vo; + +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +/** + * @author ysj + */ +@Data +public class LoadWaterLevelVo { + + @ApiModelProperty("时间") + private String time; + + @ApiModelProperty("水位") + private Double water; + + @ApiModelProperty("功率") + private Double load; +} \ No newline at end of file diff --git a/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/data/vo/PowerConvertVo.java b/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/data/vo/PowerConvertVo.java new file mode 100644 index 0000000..80b157e --- /dev/null +++ b/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/data/vo/PowerConvertVo.java @@ -0,0 +1,22 @@ +package com.hnac.hzims.operational.data.vo; + +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.util.List; + +/** + * @author ysj + */ +@Data +public class PowerConvertVo { + + @ApiModelProperty("站点名称") + private String stationName; + + @ApiModelProperty("功率/水位") + private List loadWaters; + + @ApiModelProperty("发电量") + private List electricitys; +} \ No newline at end of file diff --git a/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/main/vo/HydropowerStationVo.java b/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/main/vo/HydropowerStationVo.java index 86cb6ef..0bbcb8f 100644 --- a/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/main/vo/HydropowerStationVo.java +++ b/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/main/vo/HydropowerStationVo.java @@ -54,6 +54,9 @@ public class HydropowerStationVo { @ApiModelProperty(value = "月发电量") private Float powerMon; + @ApiModelProperty(value = "月发电量完成率") + private Double powerRateMon; + @ApiModelProperty(value = "年发电量") private Float powerYear; diff --git a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/home/impl/RealTargetServiceImpl.java b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/home/impl/RealTargetServiceImpl.java index 9bdfc9e..1706a4c 100644 --- a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/home/impl/RealTargetServiceImpl.java +++ b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/home/impl/RealTargetServiceImpl.java @@ -1006,7 +1006,7 @@ public class RealTargetServiceImpl implements RealTargetService { private List getModelStationList() { // 水利站点(All) List stations = stationService.list(new LambdaQueryWrapper() {{ - eq(StationEntity::getServeType, HomePageConstant.HYDROPOWER_SERVETYPE); + eq(StationEntity::getDataOrigin, "0"); }}); if(CollectionUtil.isEmpty(stations)){ return new ArrayList<>(); diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/data/controller/HzimsDataController.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/data/controller/HzimsDataController.java index a12dc75..03f730b 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/data/controller/HzimsDataController.java +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/data/controller/HzimsDataController.java @@ -26,9 +26,6 @@ public class HzimsDataController { private final HzimsDataService service; - /** - * 获取区域列表数据 - */ @ApiLog @GetMapping("/saveArea") @ApiOperationSupport(order = 1) @@ -37,12 +34,9 @@ public class HzimsDataController { return R.data(service.saveArea()); } - /** - * 获取区域列表数据 - */ @ApiLog @GetMapping("/saveStation") - @ApiOperationSupport(order = 1) + @ApiOperationSupport(order = 2) @ApiOperation(value = "获取站点统计数据", notes = "无需传入参数") public R saveStation() { return R.data(service.saveStation()); @@ -50,9 +44,18 @@ public class HzimsDataController { @ApiLog @GetMapping("/station") - @ApiOperationSupport(order = 1) + @ApiOperationSupport(order = 3) @ApiOperation(value = "站点数据获取", notes = "传入站点code") public R station(@RequestParam("stationCode") String stationCode) { return R.data(service.station(stationCode)); } + + @ApiLog + @GetMapping("/power") + @ApiOperationSupport(order = 4) + @ApiOperation(value = "站点功率换算电量", notes = "传入站点code") + public R power(@RequestParam("stationCode") String stationCode) { + return R.data(service.power(stationCode)); + } + } diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/data/service/HzimsDataService.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/data/service/HzimsDataService.java index 11c6878..a37e6fe 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/data/service/HzimsDataService.java +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/data/service/HzimsDataService.java @@ -1,5 +1,6 @@ package com.hnac.hzims.operational.data.service; +import com.hnac.hzims.operational.data.vo.PowerConvertVo; import com.hnac.hzims.operational.main.vo.HydropowerStationVo; import javax.servlet.http.HttpServletRequest; @@ -20,4 +21,6 @@ public interface HzimsDataService { boolean saveStation(); HydropowerStationVo station(String stationCode); + + PowerConvertVo power(String stationCode); } diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/data/service/impl/HzimsDataServiceImpl.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/data/service/impl/HzimsDataServiceImpl.java index dac8435..19332c2 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/data/service/impl/HzimsDataServiceImpl.java +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/data/service/impl/HzimsDataServiceImpl.java @@ -3,17 +3,26 @@ package com.hnac.hzims.operational.data.service.impl; import com.alibaba.fastjson.JSONObject; import com.baomidou.mybatisplus.core.toolkit.Wrappers; 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.EminfoAndEmParamVo; import com.hnac.hzims.operational.data.service.HzimsDataService; import com.hnac.hzims.operational.data.vo.AreaVo; +import com.hnac.hzims.operational.data.vo.ConverElectricityVo; +import com.hnac.hzims.operational.data.vo.LoadWaterLevelVo; +import com.hnac.hzims.operational.data.vo.PowerConvertVo; import com.hnac.hzims.operational.main.constant.HomePageConstant; import com.hnac.hzims.operational.main.service.AreaService; +import com.hnac.hzims.operational.main.service.IAnalyseDataService; import com.hnac.hzims.operational.main.service.IMainSystemMonitoringService; import com.hnac.hzims.operational.main.vo.*; +import com.hnac.hzims.operational.station.entity.HzimsAnalyzeModelStationEntity; import com.hnac.hzims.operational.station.entity.StationEntity; +import com.hnac.hzims.operational.station.service.IHzimsAnalyzeModelStationService; import com.hnac.hzims.operational.station.service.IStationService; import com.hnac.hzims.operational.station.vo.HzimsStationCountVo; +import com.hnac.hzinfo.datasearch.analyse.vo.AnalyseDataTaosVO; +import com.hnac.hzinfo.datasearch.analyse.vo.AnalyzeDataConditionVO; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.apache.commons.collections4.MapUtils; @@ -40,6 +49,7 @@ import java.time.LocalDate; import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; import java.util.*; +import java.util.concurrent.TimeUnit; import java.util.stream.Collectors; @@ -57,8 +67,14 @@ public class HzimsDataServiceImpl implements HzimsDataService { private final IStationService stationService; + private final IAnalyseDataService dataService; + + private final IHzimsAnalyzeModelStationService modelStationService; + private final IMainSystemMonitoringService maintenanceTaskService; + private final IEmInfoClient deviceClient; + private final ISysClient sysClient; private final IPlanGenertionClient planGenertionClient; @@ -70,6 +86,8 @@ public class HzimsDataServiceImpl implements HzimsDataService { @Value("${hzims.operation.save.station.url}") public String STATION_URL; + private final static String conver_power_key = "hzims:operation:conver:power:"; + private final static String recent_year_power_data = "hzims:operation:key:power:data"; private final static String loadwater_level_key = "hzims:operation:loadwater:level:key"; @@ -217,6 +235,189 @@ public class HzimsDataServiceImpl implements HzimsDataService { } /** + * 站点功率换算电量 + * @param stationCode + * @return + */ + @Override + public PowerConvertVo power(String stationCode) { + PowerConvertVo redisCache = (PowerConvertVo) redisTemplate.opsForValue().get(conver_power_key + stationCode); + if(!ObjectUtil.isEmpty(redisCache)){ + return redisCache; + } + // 查询站点 + StationEntity station = stationService.getOne(Wrappers.lambdaQuery(). + eq(StationEntity::getCode,stationCode) + ); + if(ObjectUtil.isEmpty(station)){ + return new PowerConvertVo(); + } + PowerConvertVo convert = new PowerConvertVo(); + convert.setStationName(station.getName()); + // 查询近30天发电量 + convert.setElectricitys(this.poweyBy30Day(station.getRefDept())); + // 查询24小时水位、功率 + convert.setLoadWaters(this.loadWaterBy24Hour(station.getRefDept(),station.getCode())); + redisTemplate.opsForValue().set(conver_power_key + stationCode,convert); + redisTemplate.expire(conver_power_key + stationCode,30, TimeUnit.MINUTES); + return convert; + } + + /** + * 查询近30天发电量 + * @param deptId + * @return + */ + private List poweyBy30Day(Long deptId) { + // 查询设备 + R> result = deviceClient.getEmCodeByDeptId(deptId); + if(!result.isSuccess() || CollectionUtil.isEmpty(result.getData())){ + return new ArrayList<>(); + } + Calendar calendar = Calendar.getInstance(); + String endTime = DateUtil.format(calendar.getTime(),DateUtil.PATTERN_DATETIME); + 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,-30); + String startTime = DateUtil.format(calendar.getTime(),DateUtil.PATTERN_DATETIME); + // 功率查询 + List datas = dataService.periodTargetDatas(startTime,endTime,3,2,result.getData(),HomePageConstant.ACTIVE_POWER); + if(CollectionUtil.isEmpty(datas)){ + return new ArrayList<>(); + } + List electricitys = new ArrayList<>(); + // 数据累计 + datas.forEach(item->{ + if(CollectionUtil.isEmpty(item.getList())){ + return; + } + item.getList().forEach(data->{ + ConverElectricityVo electricity = new ConverElectricityVo(); + Date date = DateUtil.parse(data.getTs(), "yyyy-MM-dd HH:mm:ss.s"); + electricity.setTime(DateUtil.format(date,DateUtil.PATTERN_DATE)); + if(StringUtil.isEmpty(data.getVal())){ + electricity.setElectricity(0.0); + }else{ + electricity.setElectricity(Double.parseDouble(data.getVal())); + } + electricitys.add(electricity); + }); + }); + if(CollectionUtil.isEmpty(electricitys)){ + return new ArrayList<>(); + } + // 进行time分组 + return electricitys.stream().collect(Collectors.groupingBy(ConverElectricityVo::getTime)).entrySet().stream().map(entry->{ + ConverElectricityVo electricity = new ConverElectricityVo(); + electricity.setTime(entry.getKey()); + electricity.setElectricity(entry.getValue().stream().mapToDouble(ConverElectricityVo::getElectricity).sum()); + return electricity; + }).sorted(Comparator.comparing(ConverElectricityVo::getTime)).collect(Collectors.toList()); + } + + /** + * 查询24小时水位、功率 + * @param stationCode + * @return + */ + private List loadWaterBy24Hour(Long deptId,String stationCode) { + Calendar calendar = Calendar.getInstance(); + String endTime = DateUtil.format(calendar.getTime(),DateUtil.PATTERN_DATETIME); + calendar.add(Calendar.HOUR_OF_DAY,-24); + String startTime = DateUtil.format(calendar.getTime(),DateUtil.PATTERN_DATETIME); + List hours = this.get24Hours(); + // 查询功率数据 + List loads = this.loads(startTime,endTime,deptId); + // 查询水位数据 + List waters = this.water(startTime,endTime,stationCode); + return hours.stream().map(hour ->{ + LoadWaterLevelVo loadWater = new LoadWaterLevelVo(); + Date time = DateUtil.parse(hour,"yyyy-MM-dd HH"); + loadWater.setTime(String.valueOf(time.getHours())); + if(CollectionUtil.isEmpty(loads)){ + loadWater.setLoad(0.0); + }else{ + loadWater.setLoad(loads.stream().filter(o->o.getTs().contains(hour)).mapToDouble(load->{ + if(StringUtil.isEmpty(load.getVal())){ + return 0.0; + } + return Double.parseDouble(load.getVal()); + }).sum()); + } + if(CollectionUtil.isEmpty(waters)){ + loadWater.setWater(0.0); + }else{ + loadWater.setWater(waters.stream().filter(o->o.getTs().contains(hour)).mapToDouble(load->{ + if(StringUtil.isEmpty(load.getVal())){ + return 0.0; + } + return Double.parseDouble(load.getVal()); + }).sum()); + } + return loadWater; + }).collect(Collectors.toList()); + } + + /** + * 查询24小时水位数据 + * @param startTime + * @param endTime + * @param stationCode + * @return + */ + private List water(String startTime, String endTime, String stationCode) { + // 查询模型站点 + HzimsAnalyzeModelStationEntity model = modelStationService.getOne(Wrappers.lambdaQuery() + .eq(HzimsAnalyzeModelStationEntity::getStationId,stationCode) + ); + if(ObjectUtil.isEmpty(model)){ + return new ArrayList<>(); + } + // 水位查询 + return dataService.periodTargetData(startTime,endTime,3,2,model.getInstanceCode(),HomePageConstant.FRONT_WATER_LEVEL); + + } + + /** + * 获取24小时功率 + * @param refDept + */ + private List loads(String start,String end,Long refDept) { + List datas = new ArrayList<>(); + R> result = deviceClient.getEmCodeByDeptId(refDept); + if(!result.isSuccess() || CollectionUtil.isEmpty(result.getData())){ + return datas; + } + // 功率查询 + List loads = dataService.periodTargetDatas(start,end,3,2,result.getData(),HomePageConstant.ACTIVE_POWER); + if(!CollectionUtil.isEmpty(loads)){ + loads.forEach(load->{ + datas.addAll(load.getList()); + }); + } + return datas; + } + + /** + * 获取24小时 + * @return + */ + private List get24Hours() { + Calendar calendar = Calendar.getInstance(); + Date end = calendar.getTime(); + calendar.add(Calendar.HOUR_OF_DAY,-24); + Date start = calendar.getTime(); + List times = new ArrayList<>(); + while (start.compareTo(end) < 0) { + times.add(DateUtil.format(calendar.getTime(),"yyyy-MM-dd HH")); + calendar.add(Calendar.HOUR_OF_DAY,1); + start = calendar.getTime(); + } + return times; + } + + /** * 获取站点运行天数 * @param station * @return @@ -308,6 +509,14 @@ public class HzimsDataServiceImpl implements HzimsDataService { // 月发电量 float powerMont = (float) targetList.stream().filter(o-> deptId.equals(o.getDeptId())).mapToDouble(HydropowerUnitTargetVo::getPowerMon).sum(); response.setPowerMon(powerMont); + // 月发电完成率 + float planPowerMon = response.getPlanPowerMon(); + if(Math.abs(planPowerMon) <= 0){ + response.setPowerRateMon(0.0); + } else { + double powerRateYear = BigDecimal.valueOf(powerMont / (double) planPowerMon * 100).setScale(2, RoundingMode.HALF_UP).doubleValue(); + response.setPowerRateMon(powerRateYear); + } // 年发电量 float powerYear = (float) targetList.stream().filter(o-> deptId.equals(o.getDeptId())).mapToDouble(HydropowerUnitTargetVo::getPowerYear).sum(); response.setPowerYear(powerYear); @@ -316,7 +525,7 @@ public class HzimsDataServiceImpl implements HzimsDataService { if(Math.abs(planPowerYear) <= 0){ response.setPowerRateYear(0.0); } else { - double powerRateYear = BigDecimal.valueOf(powerYear / planPowerYear * 100).setScale(2, RoundingMode.HALF_UP).doubleValue(); + double powerRateYear = BigDecimal.valueOf(powerYear / (double) planPowerYear * 100).setScale(2, RoundingMode.HALF_UP).doubleValue(); response.setPowerRateYear(powerRateYear); } } 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 421d09e..dbf502e 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 @@ -18,5 +18,7 @@ public interface IAnalyseDataService { 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); } 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 71fae0f..9e120ec 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 @@ -89,6 +89,45 @@ public class AnalyseDataServiceImpl implements IAnalyseDataService { * @param endTime 结束时间 * @param accessRules 取数规则 : 0=最早值 1=最大值 2=最小值 3=平均值 4=和值 5=差值 6=最新值 * @param cycleType 间隔周期 : 0-> 秒 1-> 分 2-> 小时 3->天 4-> 周 5-> 月 6-> 年 + * @param deviceCodes 设备编号集合 + * @param signages 指标 + * @return + */ + @Override + public List periodTargetDatas(String startTime, String endTime, Integer accessRules, Integer cycleType, List deviceCodes, String signages) { + AnalyseCodeByAnalyseDataPO po = new AnalyseCodeByAnalyseDataPO(); + List signboardConditions = new ArrayList<>(); + deviceCodes.forEach(deviceCode->{ + AnalyzeDataConditionPO analyzeDataConditionPO = new AnalyzeDataConditionPO(); + analyzeDataConditionPO.setFull(1); + po.setDeviceCode(deviceCode); + analyzeDataConditionPO.setSignages(signages); + analyzeDataConditionPO.setKeepFigures(2); + analyzeDataConditionPO.setAccessRules(accessRules); + analyzeDataConditionPO.setSaveTimeType(cycleType); + // 间隔 + 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_target_data_request {}",po); + R> result = analyseDataSearchClient.getAnalyzeDataByAnalyzeCodeAndSignages(po); + if (!result.isSuccess() || CollectionUtil.isEmpty(result.getData())) { + return new ArrayList<>(); + } + log.error("period_target_data_resp {}",result); + 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 ride 配电比 * @param signages 指标 diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/service/impl/HydropowerServiceImpl.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/service/impl/HydropowerServiceImpl.java index c4f94d0..d8edc2f 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/service/impl/HydropowerServiceImpl.java +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/service/impl/HydropowerServiceImpl.java @@ -528,8 +528,10 @@ public class HydropowerServiceImpl implements HydropowerService { * @return */ private List getGenerationPowerList(EminfoAndEmParamVo device) { - String start = DateUtil.format(new Date(), "yyyy-MM") + "-01 00:00:00"; - String end = DateUtil.format(new Date(), DateUtil.PATTERN_DATETIME); + Calendar calendar = Calendar.getInstance(); + String end = DateUtil.format(calendar.getTime(), DateUtil.PATTERN_DATETIME); + calendar.set(Calendar.DAY_OF_MONTH,-29); + String start = DateUtil.format(calendar.getTime(), DateUtil.PATTERN_DATETIME); List records = analyseDataService.periodTargetData(start,end,5,EquipmentConstants.CycleTypeEnum.DAY_CYCLE.getType(),device.getEmCode(),HomePageConstant.HYDROPOWER_GENERATE_POWER); if(CollectionUtil.isEmpty(records)){ return new ArrayList<>();