diff --git a/hzims-service/hzims-alarm/src/main/resources/dict/dict.sql b/hzims-service/hzims-alarm/src/main/resources/dict/dict.sql index 57e1dcf..7307bdd 100644 --- a/hzims-service/hzims-alarm/src/main/resources/dict/dict.sql +++ b/hzims-service/hzims-alarm/src/main/resources/dict/dict.sql @@ -48,3 +48,11 @@ INSERT INTO `BLADEX`.`BLADE_DICT`(`ID`, `PARENT_ID`, `CODE`, `DICT_KEY`, `DICT_V INSERT INTO `BLADEX`.`BLADE_DICT`(`ID`, `PARENT_ID`, `CODE`, `DICT_KEY`, `DICT_VALUE`, `SORT`, `REMARK`, `IS_SEALED`, `IS_DELETED`, `DICT_TYPE`, `APP_ID`, `APP_CODE`) VALUES (1331515358493851649, 1331514879315591270, 'FAULTDEALTYPE', '1', '误报', 1, '', 0, 0, 1, 1347090334530641921, 'HZIMS-ALARM'); + +INSERT INTO `BLADEX`.`BLADE_DICT` (`ID`, `PARENT_ID`, `CODE`, `DICT_KEY`, `DICT_VALUE`, `SORT`, `REMARK`, `IS_SEALED`, `IS_DELETED`, `DICT_TYPE`, `APP_ID`, `APP_CODE`) VALUES (1651149948657455106, 0, 'ALARM_HANDLE_TYPE', '-1', '告警处理类型', 100, '', 0, 0, 0, -1, 'HZIMS-ALARM'); +INSERT INTO `BLADEX`.`BLADE_DICT` (`ID`, `PARENT_ID`, `CODE`, `DICT_KEY`, `DICT_VALUE`, `SORT`, `REMARK`, `IS_SEALED`, `IS_DELETED`, `DICT_TYPE`, `APP_ID`, `APP_CODE`) VALUES (1651150040252665858, 1651149948657455106, 'ALARM_HANDLE_TYPE', '1', '延后', 1, '', 0, 0, 0, -1, 'HZIMS-ALARM'); +INSERT INTO `BLADEX`.`BLADE_DICT` (`ID`, `PARENT_ID`, `CODE`, `DICT_KEY`, `DICT_VALUE`, `SORT`, `REMARK`, `IS_SEALED`, `IS_DELETED`, `DICT_TYPE`, `APP_ID`, `APP_CODE`) VALUES (1651150074092310530, 1651149948657455106, 'ALARM_HANDLE_TYPE', '2', '误报', 2, '', 0, 0, 0, -1, 'HZIMS-ALARM'); +INSERT INTO `BLADEX`.`BLADE_DICT` (`ID`, `PARENT_ID`, `CODE`, `DICT_KEY`, `DICT_VALUE`, `SORT`, `REMARK`, `IS_SEALED`, `IS_DELETED`, `DICT_TYPE`, `APP_ID`, `APP_CODE`) VALUES (1651150112910594050, 1651149948657455106, 'ALARM_HANDLE_TYPE', '3', '缺陷', 3, '', 0, 0, 0, -1, 'HZIMS-ALARM'); +INSERT INTO `BLADEX`.`BLADE_DICT` (`ID`, `PARENT_ID`, `CODE`, `DICT_KEY`, `DICT_VALUE`, `SORT`, `REMARK`, `IS_SEALED`, `IS_DELETED`, `DICT_TYPE`, `APP_ID`, `APP_CODE`) VALUES (1651150146049789954, 1651149948657455106, 'ALARM_HANDLE_TYPE', '4', '检修', 4, '', 0, 0, 0, -1, 'HZIMS-ALARM'); +INSERT INTO `BLADEX`.`BLADE_DICT` (`ID`, `PARENT_ID`, `CODE`, `DICT_KEY`, `DICT_VALUE`, `SORT`, `REMARK`, `IS_SEALED`, `IS_DELETED`, `DICT_TYPE`, `APP_ID`, `APP_CODE`) VALUES (1651150182032723969, 1651149948657455106, 'ALARM_HANDLE_TYPE', '5', '处理', 5, '', 0, 0, 0, -1, 'HZIMS-ALARM'); +INSERT INTO `BLADEX`.`BLADE_DICT` (`ID`, `PARENT_ID`, `CODE`, `DICT_KEY`, `DICT_VALUE`, `SORT`, `REMARK`, `IS_SEALED`, `IS_DELETED`, `DICT_TYPE`, `APP_ID`, `APP_CODE`) VALUES (1651150182032756242, 1651149948657455106, 'ALARM_HANDLE_TYPE', '6', '处理完成', 5, '', 0, 0, 0, -1, 'HZIMS-ALARM'); \ No newline at end of file diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/controller/AppHomeController.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/controller/AppHomeController.java deleted file mode 100644 index ee111e7..0000000 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/controller/AppHomeController.java +++ /dev/null @@ -1,54 +0,0 @@ -package com.hnac.hzims.operational.main.controller; - -import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport; -import com.hnac.hzims.operational.main.service.IAppHomeService; -import com.hnac.hzims.operational.main.vo.AppStationAreaVo; -import com.hnac.hzims.operational.main.vo.AppAreaDutyVo; -import com.hnac.hzims.operational.main.vo.AppStationVo; -import io.swagger.annotations.Api; -import io.swagger.annotations.ApiOperation; -import io.swagger.annotations.ApiParam; -import lombok.AllArgsConstructor; -import org.springblade.core.boot.ctrl.BladeController; -import org.springblade.core.log.annotation.ApiLog; -import org.springblade.core.tool.api.R; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; - -import java.util.List; - -@RestController -@RequestMapping("/appHome") -@Api(value = "app首页", tags = "app-首页") -@AllArgsConstructor -public class AppHomeController extends BladeController { - - private final IAppHomeService appService; - - - - @ApiLog - @ApiOperation("app首页-站点") - @GetMapping("/appStation") - @ApiOperationSupport(order = 1) - public R> appStation(@ApiParam(value = "区域机构ID") Long deptId) { - return R.data(appService.appStation(deptId)); - } - - @ApiLog - @ApiOperation("app首页-站点列表数据") - @GetMapping("/appStationList") - @ApiOperationSupport(order = 2) - public R> appStationList(@ApiParam(value = "机构ID") Long deptId) { - return R.data(appService.appStationList(deptId)); - } - - @ApiLog - @ApiOperation("app首页-当班数据") - @GetMapping("/getDutyData") - @ApiOperationSupport(order = 3) - public R> getDutyData(@ApiParam(value = "区域机构ID") Long deptId) { - return R.data(appService.getDutyData(deptId)); - } -} diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/controller/HomePageController.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/controller/HomePageController.java deleted file mode 100644 index 97f87376..0000000 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/controller/HomePageController.java +++ /dev/null @@ -1,137 +0,0 @@ -package com.hnac.hzims.operational.main.controller; - -import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport; -import com.hnac.hzims.common.logs.annotation.OperationAnnotation; -import com.hnac.hzims.common.logs.enums.BusinessType; -import com.hnac.hzims.common.logs.enums.OperatorType; -import com.hnac.hzims.operational.main.service.IHomePageService; -import com.hnac.hzims.operational.main.vo.*; -import io.swagger.annotations.Api; -import io.swagger.annotations.ApiOperation; -import io.swagger.annotations.ApiParam; -import lombok.AllArgsConstructor; -import org.springblade.core.boot.ctrl.BladeController; -import org.springblade.core.log.annotation.ApiLog; -import org.springblade.core.tool.api.R; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; - -import javax.validation.constraints.NotNull; -import java.util.List; -import java.util.Map; - -/** - * @author ysj - */ -@RestController -@RequestMapping("/homePage") -@Api(value = "水电站-首页", tags = "水电站-首页") -@AllArgsConstructor -public class HomePageController extends BladeController { - - @NotNull - private final IHomePageService homePageService; - - @ApiLog - @ApiOperation("服务厂站统计") - @GetMapping("/stationCensus") - @ApiOperationSupport(order = 1) - public R> stationCount(@ApiParam(value = "站点服务类型:1、云服务站点; 2、代运维服务站点", required = true) Integer serveType, Long deptId) { - List stationList = homePageService.getStationCount(deptId,serveType); - return R.data(stationList); - } - - @ApiLog - @ApiOperation("关键指标:水电站、风电站、光伏站") - @GetMapping("/powerStation") - @ApiOperationSupport(order = 2) - public R> powerStation(@ApiParam(value = "站点服务类型:1、云服务站点; 2、代运维服务站点", required = true)Integer serveType,Long deptId) { - List powerTargetVoList = homePageService.powerTarget(serveType,deptId); - return R.data(powerTargetVoList); - } - - @ApiLog - @ApiOperation("关键指标:储能站、水利") - @GetMapping("/storageConservancy") - @ApiOperationSupport(order = 3) - public R> storageConservancy(@ApiParam(value = "站点服务类型:1、云服务站点; 2、代运维服务站点", required = true) Integer serveType,Long deptId) { - List crucialTargetVoList = homePageService.storageConservancy(serveType,deptId); - return R.data(crucialTargetVoList); - } - - @ApiLog - @ApiOperation("关键指标:暂定其他站") - @GetMapping("/waterAffairs") - @ApiOperationSupport(order = 4) - public R waterAffairs(@ApiParam(value = "站点服务类型:1、云服务站点; 2、代运维服务站点", required = true) Integer serveType,Long deptId) { - OtherStationVo waterAffairsVoList = homePageService.otherStation(serveType,deptId); - return R.data(waterAffairsVoList); - } - - @ApiLog - @ApiOperation("水电站数据获取") - @GetMapping("/getHydropowerData") - @ApiOperationSupport(order = 5) - public R> getHydropowerData(@ApiParam(value = "区域id", required = true) Long deptId) { - List hydropowerScoreVoList = homePageService.getHydropowerData(deptId); - return R.data(hydropowerScoreVoList); - } - - - @ApiLog - @ApiOperation("年计划发电完成趋势") - @GetMapping("/planAactualTrend") - // @OperationAnnotation(moduleName = "演示大屏",title = "演示大屏", operatorType = OperatorType.MOBILE, - // businessType = BusinessType.GENCODE,action = "年计划发电完成趋势") - @ApiOperationSupport(order = 6) - public R> planActualTrend(@ApiParam(value = "区域机构ID") Long deptId) { - return R.data(homePageService.planActualTrend(deptId)); - } - - - - @ApiLog - @ApiOperation("计划发电趋势") - @GetMapping("/planGenerationTrend") - @ApiOperationSupport(order = 7) - public R>> planGenerationTrend(@ApiParam(value = "区域机构ID") Long deptId) { - return homePageService.planGenerationTrend(deptId, 0, 2); - } - - @ApiLog - @ApiOperation("区域发电占比") - @GetMapping("/areaGenerationMakeUp") - @ApiOperationSupport(order = 9) - public R>> areaGenerationMakeUp(@ApiParam(value = "区域机构ID") Long deptId) { - return homePageService.areaGenerationMakeUp(deptId, 0, 2); - } - - - @ApiLog - @ApiOperation("统计") - @GetMapping("/getCount") - @ApiOperationSupport(order = 10) - public R>> getCount(@ApiParam(value = "区域机构ID") Long deptId) { - return homePageService.getCount(deptId, 0, 2); - } - - - @ApiLog - @ApiOperation("获取区域") - @GetMapping("/getArea") - @ApiOperationSupport(order = 11) - public R> getArea(@ApiParam(value = "区域机构ID") Long deptId) { - return homePageService.getArea(deptId); - } - - - @ApiLog - @ApiOperation("站点首页") - @GetMapping("/stationHome") - @ApiOperationSupport(order = 11) - public R> homeStation(@ApiParam(value = "区域机构ID") Long deptId) { - return R.data(homePageService.homeStation(deptId)); - } - -} diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/service/IAppHomeService.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/service/IAppHomeService.java deleted file mode 100644 index 582bd96..0000000 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/service/IAppHomeService.java +++ /dev/null @@ -1,34 +0,0 @@ -package com.hnac.hzims.operational.main.service; - -import com.hnac.hzims.operational.main.vo.AppStationAreaVo; -import com.hnac.hzims.operational.main.vo.AppAreaDutyVo; -import com.hnac.hzims.operational.main.vo.AppStationVo; - -import java.util.List; - -/** - * APP首页接口 - * @author ysj - */ -public interface IAppHomeService { - - /** - * 获取App首页站点列表 - * @param deptId - * @return - */ - List appStation(Long deptId); - - /** - * 获取app首页-站点列表数据 - * @param deptId - * @return - */ - List appStationList(Long deptId); - - /** - * app首页-当班数据 - * @return - */ - List getDutyData(Long deptId); -} diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/service/IHomePageService.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/service/IHomePageService.java deleted file mode 100644 index 82d6b10..0000000 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/service/IHomePageService.java +++ /dev/null @@ -1,50 +0,0 @@ -package com.hnac.hzims.operational.main.service; - -import com.hnac.hzims.operational.main.vo.*; -import org.springblade.core.tool.api.R; -import org.springblade.system.entity.Dept; - -import java.util.List; -import java.util.Map; - -public interface IHomePageService { - - // 水电站加载数据 - void loadHydropower(String param, Integer serveType); - - // 近年发电量数据 - void loadPowerData(String param,List types, Integer serveType, int yearCount); - - List getMonthList(int year, int endMoth,boolean nextMon); - - List getStationCount(Long deptId, Integer serveType); - - List powerTarget(Integer serveType,Long deptId); - - List storageConservancy(Integer serveType,Long deptId); - - OtherStationVo otherStation(Integer serveType,Long deptId); - - R>> planGenerationTrend(Long deptId,Integer stationType,Integer serveType); - - - R>> areaGenerationMakeUp(Long deptId,Integer stationType,Integer serveType); - - List getHydropowerData(Long deptId); - - R>> getCount(Long deptId,Integer stationType,Integer serveType); - - Map> getDepartMap(Long deptId); - - R> getArea(Long depeId); - - List getChildDept(List departList, Long deptId,List list); - - List getChildArea(List departList, Long deptId,List list); - - List planActualTrend(Long deptId); - - List homeStation(Long deptId); - - boolean compareDate(String date); -} diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/service/impl/AppHomeServiceImpl.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/service/impl/AppHomeServiceImpl.java deleted file mode 100644 index e9a531c..0000000 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/service/impl/AppHomeServiceImpl.java +++ /dev/null @@ -1,755 +0,0 @@ -package com.hnac.hzims.operational.main.service.impl; - -import com.alibaba.fastjson.JSONObject; -import com.alibaba.fastjson.TypeReference; -import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; -import com.baomidou.mybatisplus.core.toolkit.Wrappers; -import com.google.common.util.concurrent.ThreadFactoryBuilder; -import com.hnac.hzims.equipment.entity.PlanGenerationEntity; -import com.hnac.hzims.equipment.vo.EminfoAndEmParamVo; -import com.hnac.hzims.hzimsweather.response.weather.Daily; -import com.hnac.hzims.hzimsweather.response.weather.HeWeatherWeatherDailyResponse; -import com.hnac.hzims.operational.access.constants.AccessConstants; -import com.hnac.hzims.operational.access.entity.OperAccessTaskEntity; -import com.hnac.hzims.operational.access.service.IOperAccessTaskService; -import com.hnac.hzims.operational.defect.constants.TreatMethodConstant; -import com.hnac.hzims.operational.defect.entity.OperPhenomenonEntity; -import com.hnac.hzims.operational.defect.service.IOperPhenomenonService; -import com.hnac.hzims.operational.duty.service.IImsDutyMainService; -import com.hnac.hzims.operational.duty.vo.DutyMainInfoVo; -import com.hnac.hzims.operational.main.constant.HomePageConstant; -import com.hnac.hzims.operational.main.service.AreaService; -import com.hnac.hzims.operational.main.service.IAppHomeService; -import com.hnac.hzims.operational.main.service.IMainSystemMonitoringService; -import com.hnac.hzims.operational.main.service.IWeatherService; -import com.hnac.hzims.operational.main.vo.*; -import com.hnac.hzims.operational.maintenance.constants.MaintenanceConstant; -import com.hnac.hzims.operational.maintenance.entity.OperMaintenanceTaskEntity; -import com.hnac.hzims.operational.maintenance.service.IOperMaintenanceTaskService; -import com.hnac.hzims.operational.station.entity.StationEntity; -import com.hnac.hzims.operational.station.service.IStationAttributeService; -import com.hnac.hzims.operational.station.service.IStationService; -import com.hnac.hzinfo.datasearch.soe.domian.SoeData; -import com.hnac.hzinfo.inspect.task.feign.IInspectTaskReportClient; -import com.hnac.hzinfo.inspect.task.vo.DutyInspectTaskVO; -import lombok.RequiredArgsConstructor; -import org.apache.commons.collections4.MapUtils; -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.springblade.system.user.cache.UserCache; -import org.springblade.system.user.entity.User; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.data.redis.core.RedisTemplate; -import org.springframework.stereotype.Service; - -import java.math.BigDecimal; -import java.math.RoundingMode; -import java.time.Duration; -import java.time.LocalDateTime; -import java.time.ZoneId; -import java.time.format.DateTimeFormatter; -import java.util.*; -import java.util.concurrent.*; -import java.util.stream.Collectors; - -/** - * APP首页实现类 - * @author ysj - */ -@Service -@RequiredArgsConstructor -public class AppHomeServiceImpl implements IAppHomeService { - - private final AreaService areaService; - - private final IStationService stationService; - - private final IImsDutyMainService dutyMainService; - - private final IOperPhenomenonService phenomenonService; - - private final IOperAccessTaskService accessTaskService; - - private final IMainSystemMonitoringService mainService; - - private final IStationAttributeService attributeService; - - private final IOperMaintenanceTaskService maintenanceTaskService; - - private final IInspectTaskReportClient inspectTaskReportClient; - - private final ISysClient sysClient; - - private final IWeatherService weatherService; - - private final RedisTemplate redisTemplate; - - // 线程数量 - private final static int POOL_QUANTITY = 5; - - @Value("${hzims.operation.realIdKey}") - public String real_id_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"; - - private final static String KEY_INDICATORS_INFO = "hzims:operation:key:indicators:info"; - - /** - * app首页-站点 - * @param deptId - * @return - */ - @Override - public List appStation(Long deptId) { - // 用户权限机构 - R> R = sysClient.getDeptByCurrentUser(); - if(!R.isSuccess() && CollectionUtil.isEmpty(R.getData())){ - return null; - } - // 设备信息 - List emList = mainService.getEmInfoList(); - if(CollectionUtil.isEmpty(emList)){ - return null; - } - // 站点列表 - List list = stationService.getStationList(R.getData(),deptId,Collections.singletonList(HomePageConstant.HYDROPOWER),null,true); - if(CollectionUtil.isEmpty(list)){ - return null; - } - // 站点缓存列表 - KeyIndicatorsVo keyIndicatorsVo = (KeyIndicatorsVo) redisTemplate.opsForValue().get(KEY_INDICATORS_INFO); - // 监测点单位 - Map unitMap = this.attributeService.getPointUnit(); - // 站点遍历 - List result = new ArrayList<>(); - list.forEach(station -> { - if(null == station.getRefDept()){ - return; - } - AppStationVo vo = new AppStationVo(); - vo.setDeptId(station.getRefDept()); - vo.setDeptName(station.getName()); - vo.setDay(0L); - // 投运时间计算安全运行天数 - if (ObjectUtil.isNotEmpty(station.getCommissionTime())) { - Duration dur = Duration.between(station.getCommissionTime(), LocalDateTime.now()); - vo.setDay(dur.toDays()); - } - // 天气温度 - this.getWeather(station,vo); - // 站点告警列表 - List alertList = this.getStationAlert(station.getId(),keyIndicatorsVo); - if(CollectionUtil.isNotEmpty(alertList)){ - vo.setAlertList(alertList); - } - // 遍历监测点数据 - List stationEmList = getEmShowList(emList.stream().filter(o->station.getCreateDept().equals(o.getCreateDept())).collect(Collectors.toList()),unitMap); - if(CollectionUtil.isEmpty(stationEmList)){ - vo.setInstalledCapacity(0.0); - vo.setActivePower(0.0); - vo.setUsrRate(0.0); - result.add(vo); - return; - } - // 设备 - vo.setList(stationEmList); - // 总装机容量 - double installedCapacity = stationEmList.stream().filter(o-> null != o.getInstalledCapacity()).mapToDouble(EmShowVo::getInstalledCapacity).sum(); - vo.setInstalledCapacity(installedCapacity); - // 总有功功率 - double activePower = stationEmList.stream().filter(o->StringUtil.isNotBlank(o.getActivePower())).mapToDouble(o->Float.parseFloat(o.getActivePower())).sum(); - vo.setActivePower(activePower); - // 总有功率单位 - List unit = stationEmList.stream().filter(o->StringUtil.isNotBlank(o.getPowerUnit())).map(EmShowVo::getPowerUnit).collect(Collectors.toList()); - if(CollectionUtil.isNotEmpty(unit)){ - vo.setPowerUnit(unit.get(0)); - } else { - vo.setPowerUnit("kW"); - } - if(installedCapacity <= 0){ - vo.setUsrRate(0.0); - }else{ - double usrRate = BigDecimal.valueOf(activePower / installedCapacity * 100).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue(); - vo.setUsrRate(usrRate); - } - result.add(vo); - }); - return result; - } - - /** - * 获取展示设备列表 - * @param valid - * @return - */ - private List getEmShowList(List valid,Map unitMap) { - if(CollectionUtil.isEmpty(valid)){ - return null; - } - // readId,value - String json = (String) redisTemplate.opsForValue().get(real_id_key); - Map map = null; - if (StringUtil.isNotBlank(json)) { - map = JSONObject.parseObject(json, new TypeReference>() {}); - } - // 展示设备(有功功率) - List list = getActiveList(map,valid,unitMap); - // 设备监测点集合 - List onOffList = valid.stream().filter(o->MapUtils.isNotEmpty(o.getPoint()) && StringUtil.isNotBlank(o.getPoint().get(HomePageConstant.ACTIVE_POWER))). - map(o->o.getPoint().get(HomePageConstant.JOINT_RELAY)).collect(Collectors.toList()); - if(CollectionUtil.isEmpty(onOffList) || MapUtils.isEmpty(map)){ - return list; - } - // 展示设备(开关机状态) - for(EmShowVo em : list){ - em.setOnOff(false); - if (MapUtils.isEmpty(em.getPoint()) || StringUtil.isEmpty(em.getPoint().get(HomePageConstant.JOINT_RELAY))) { - continue; - } - String realId = em.getPoint().get(HomePageConstant.JOINT_RELAY); - String value = map.get(realId); - if(StringUtil.isBlank(value)){ - continue; - } - if (value.contains("1") || "1.0".equals(value)) { - em.setOnOff(true); - } - } - return list; - - } - - /** - * 获取有功功率展示设备 - * @param valid - * @return - */ - private List getActiveList(Map map,List valid,Map unitMap) { - List realIds = valid.stream().filter(o->MapUtils.isNotEmpty(o.getPoint()) && StringUtil.isNotBlank(o.getPoint().get(HomePageConstant.ACTIVE_POWER))). - map(o->o.getPoint().get(HomePageConstant.ACTIVE_POWER)).collect(Collectors.toList()); - if (CollectionUtil.isEmpty(realIds) || MapUtils.isEmpty(map)) { - return getEmShowVos(valid); - } - // 遍历设备 - List emShowVoList = new ArrayList<>(); - valid.forEach(em -> { - EmShowVo emShowVo = new EmShowVo(); - emShowVo.setDeptId(em.getCreateDept()); - emShowVo.setCode(em.getEmCode()); - emShowVo.setName(em.getName()); - emShowVo.setPoint(em.getPoint()); - emShowVo.setOnOff(false); - emShowVo.setOrd(em.getOrd()); - emShowVo.setInstalledCapacity(em.getInstalledCapacity()); - // 有功功率 - if (MapUtils.isEmpty(em.getPoint())) { - emShowVo.setActivePower("0"); - emShowVoList.add(emShowVo); - return; - } - String realId = em.getPoint().get(HomePageConstant.ACTIVE_POWER); - if(StringUtil.isEmpty(realId)){ - emShowVo.setActivePower("0"); - emShowVoList.add(emShowVo); - return; - } - // websocket 中取realId的value值 - String value = map.get(realId); - if(StringUtil.isEmpty(value)){ - emShowVo.setActivePower("0"); - emShowVoList.add(emShowVo); - return; - } - emShowVo.setActivePower(value); - // 单位设置 - if(MapUtils.isNotEmpty(unitMap)){ - String unit = unitMap.get(em.getId()+HomePageConstant.CONCAT_P); - if(StringUtil.isNotBlank(unit)) { - emShowVo.setPowerUnit(unit); - } else { - emShowVo.setPowerUnit("kW"); - } - } else { - emShowVo.setPowerUnit("kW"); - } - emShowVoList.add(emShowVo); - }); - return emShowVoList.stream().sorted(Comparator.comparing(EmShowVo::getOrd)).collect(Collectors.toList()); - } - - /** - * 默认设备展示信息 - * @param valid - * @return - */ - private List getEmShowVos(List valid) { - return valid.stream().map(o -> { - EmShowVo emShowVo = new EmShowVo(); - emShowVo.setDeptId(o.getCreateDept()); - emShowVo.setCode(o.getEmCode()); - emShowVo.setName(o.getName()); - emShowVo.setInstalledCapacity(o.getInstalledCapacity()); - emShowVo.setActivePower("0"); - emShowVo.setPoint(o.getPoint()); - emShowVo.setOnOff(false); - return emShowVo; - }).collect(Collectors.toList()); - } - - /** - * 获取温度 - * @param station - * @return - */ - private void getWeather(StationEntity station,AppStationVo vo) { - Map weekWeather = this.weatherService.getWeekWeather(Collections.singletonList(station.getCode())); - if(MapUtils.isEmpty(weekWeather)) { - return; - } - List list = weekWeather.get(station.getCode()).getDaily(); - if (CollectionUtil.isEmpty(list)) { - return; - - } - vo.setTempMin(list.get(0).getTempMin()); - vo.setTempMax(list.get(0).getTempMax()); - } - - - /** - * 获取站点告警列表 - * @param stationId - * @return - */ - public List getStationAlert(Long stationId,KeyIndicatorsVo keyIndicatorsVo) { - if(ObjectUtil.isEmpty(keyIndicatorsVo) || null == stationId){ - return null; - } - List powerStationTotalVoList = keyIndicatorsVo.getPowerStationTotalVoList(); - if(CollectionUtil.isEmpty(powerStationTotalVoList)){ - return null; - } - List stationAlertList = powerStationTotalVoList.stream().filter(o->stationId.equals(o.getStationId())).collect(Collectors.toList()); - if(CollectionUtil.isEmpty(stationAlertList)){ - return null; - } - return stationAlertList.get(0).getAlertList(); - } - - /** - * app首页-站点列表数据 - * @param deptId - * @return - */ - @Override - public List appStationList(Long deptId) { - // 获取区域或者站点map结构 - Map> map = areaService.areaOrStaion(deptId,Collections.singletonList(HomePageConstant.HYDROPOWER),true); - if(MapUtils.isEmpty(map)){ - return null; - } - // 获取站点计划发电量集合 - //List planPowerList = sideHustleService.getStaionPlanPower(map); - // 获取设备指标数据列表 - List targetList = (List) redisTemplate.opsForValue().get(LOAD_HYDROPOWER_UNIT_TARGET_KEY); - // 获取设备实时数据 - List realList = (List) redisTemplate.opsForValue().get(LOAD_HYDROPOWER_UNIT_REAL_KEY); - // 响应结果 - List result = new ArrayList<>(); - map.forEach((key,value)->{ - AppStationAreaVo vo = new AppStationAreaVo(); - List children = new ArrayList<>(); - value.forEach(item->{ - AppStationTargetVo response = new AppStationTargetVo(); - response.setDeptId(item.getRefDept()); - response.setDeptName(item.getName()); - // 站点年计划发电量 - //float planPowerYear = this.getPlanPowerYear(planPowerList,item.getCode()); - response.setPlanPowerYear(0f); - // 站点发电完成率 - double powerRate = this.getPowerRate(targetList,item.getCreateDept(),0f); - response.setPowerRate(powerRate); - // 设备总数 - int deviceSum = this.getDeviceSum(realList,item.getCreateDept(),false); - response.setDeviceSum(deviceSum); - // 设备开机数 - int deviceRunSum = this.getDeviceSum(realList,item.getCreateDept(),true); - response.setDeviceRunSum(deviceRunSum); - // 实时负荷 - float realPowerSum = this.getRealPowerSum(realList,item.getCreateDept()); - response.setRealPowerSum(realPowerSum); - // 负荷单位 - String unit = this.getPowerUnit(realList,item.getCreateDept()); - response.setRealPowerUnit(unit); - children.add(response); - }); - vo.setList(children); - vo.setDeptId(key.getId()); - vo.setDeptName(key.getDeptName()); - result.add(vo); - }); - return result; - } - - /** - * 获取站点年计划发电量 - * @param list - * @param code - * @return - */ - private float getPlanPowerYear(List list, String code) { - if(CollectionUtil.isEmpty(list)){ - return 0f; - } - return (float) list.stream().filter(o->code.equals(o.getStationId())).mapToDouble(PlanGenerationEntity::getPlanGeneration).sum(); - } - - /** - * 站点发电完成率 - * @param list - * @param createDept - * @return - */ - private double getPowerRate(List list, Long createDept ,float planPowerYear) { - if(CollectionUtil.isEmpty(list) || ObjectUtil.isEmpty(createDept)){ - return 0.0; - } - if(Math.abs(planPowerYear) <= 0){ - return 0.0; - } - double power = list.stream().filter(o->createDept.equals(o.getDeptId())).mapToDouble(HydropowerUnitTargetVo::getPowerYear).sum(); - if(Math.abs(power) <= 0){ - return 0.0; - } - return BigDecimal.valueOf((float) power / planPowerYear * 100).setScale(2, RoundingMode.HALF_UP).doubleValue(); - } - - /** - * 设备总数 - * @param list - * @param createDept - * @return - */ - private int getDeviceSum(List list, Long createDept,boolean isRun) { - if(CollectionUtil.isEmpty(list)){ - return 0; - } - if(isRun){ - return (int) list.stream().filter(o->createDept.equals(o.getDeptId()) && HomePageConstant.OFF.equals(o.getState())).count(); - } - return (int) list.stream().filter(o->createDept.equals(o.getDeptId())).count(); - } - - /** - * 实时负荷 - * @param list - * @param createDept - * @return - */ - private float getRealPowerSum(List list, Long createDept) { - if(CollectionUtil.isEmpty(list)){ - return 0; - } - return (float) list.stream().filter(o->createDept.equals(o.getDeptId())).mapToDouble(o->Double.valueOf(o.getActivePower())).sum(); - } - - /** - * 负荷单位 - * @param list - * @param createDept - * @return - */ - private String getPowerUnit(List list, Long createDept) { - if(CollectionUtil.isEmpty(list)){ - return "kW"; - } - List units = list.stream().filter(o->createDept.equals(o.getDeptId())).map(HydropowerUnitRealVo::getPowerUnit).collect(Collectors.toList()); - if(CollectionUtil.isEmpty(units)){ - return "kW"; - - } - return units.get(0); - } - - - /** - * app首页-当班数据 - * @return - */ - @Override - public List getDutyData(Long deptId) { - // 获取当班列表数据 - List list = this.dutyMainService.getDutyDataV2(deptId); - if(CollectionUtil.isEmpty(list)){ - return null; - } - // 响应数据 - return list.stream().map(duty->{ - AppAreaDutyVo item = new AppAreaDutyVo(); - // 班组基础数据设置 - this.settingBase(duty,item); - // 开始时间、结束时间 - LocalDateTime localDateTime = LocalDateTime.ofInstant(duty.getDutyDate().toInstant(), ZoneId.systemDefault()); - LocalDateTime startDate = localDateTime.withHour(duty.getStartTime().getHours()).withMinute(duty.getStartTime().getMinutes()).withSecond(00); - //LocalDateTime endDate = localDateTime.withHour(duty.getEndTime().getHours()).withMinute(duty.getEndTime().getMinutes()).withSecond(00); - DateTimeFormatter dtf = DateTimeFormatter.ofPattern(DateUtil.PATTERN_DATETIME); - String start = dtf.format(startDate); - String end = dtf.format(LocalDateTime.now()); - List deptList = Collections.singletonList(duty.getCreateDept()); - // 使用多线程处理数据 - ThreadFactory namedThreadFactory = new ThreadFactoryBuilder().setNameFormat("duty_data-pool-%d").build(); - ExecutorService pool = new ThreadPoolExecutor(5, 5, 0L, TimeUnit.MILLISECONDS, new LinkedBlockingQueue(1024), namedThreadFactory, new ThreadPoolExecutor.AbortPolicy()); - CountDownLatch countDownLatch = new CountDownLatch(POOL_QUANTITY); - // 下一班组 - pool.execute(()-> { - this.getNextDuty(item,duty.getId()); - countDownLatch.countDown(); - }); - // 缺陷 - pool.execute(()-> { - this.getDutyDefect(item,startDate,null); - countDownLatch.countDown(); - }); - // 巡检 - pool.execute(()-> { - this.getInspectionTask(item,start,end,deptList); - countDownLatch.countDown(); - }); - // 维护 - pool.execute(()-> { - this.getMaintenanceTask(item,start,end,deptList); - countDownLatch.countDown(); - }); - // 检修 - pool.execute(()-> { - this.getOverhaulTask(item,start,end,deptList); - countDownLatch.countDown(); - }); - // 等待所有线程执行完成 - try { - countDownLatch.await(); - } catch (InterruptedException e) { - e.printStackTrace(); - Thread.currentThread().interrupt(); - } - pool.shutdown(); - // 任务完成率 - int taskSum = item.getDefectSum() + item.getInspectionTaskCount() + item.getMaintenanceTaskCount() + item.getOverhaulTaskCount(); - int finishSum = item.getSolvedCount() + item.getInspectionTaskFinishCount() + item.getMaintenanceTaskFinishCount() + item.getOverhaulTaskFinishCount(); - if(Math.abs(taskSum) <= 0){ - item.setTaskRate(0.0); - }else{ - double taskRate = BigDecimal.valueOf((double)finishSum / (double)taskSum * 100).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue(); - item.setTaskRate(taskRate); - } - return item; - }).collect(Collectors.toList()); - } - - /** - * 班组基础数据设置 - * @param duty - * @param item - */ - private void settingBase(DutyMainInfoVo duty, AppAreaDutyVo item) { - item.setShift(duty.getClassName()); - item.setTeam(duty.getGroupName()); - // 班组负责人 - String managerName = this.getManagerName(duty.getManagerId()); - item.setTeamLeader(managerName); - // 班组成员 - String classMember = this.getClassMemberName(duty.getDutyPersonIds(),duty.getManagerId()); - item.setClassMember(classMember); - } - - - - /** - * 获取下一班组数据 - * @param item - * - * @param id - */ - private void getNextDuty(AppAreaDutyVo item, Long id) { - DutyMainInfoVo nextDuty = this.dutyMainService.getNextDutyDataV2(id); - if(ObjectUtil.isEmpty(nextDuty) || ObjectUtil.isEmpty(nextDuty.getId())){ - return; - } - item.setNextShift(nextDuty.getClassName()); - item.setNextTeam(nextDuty.getGroupName()); - // 下一班组负责人 - String managerName = this.getManagerName(nextDuty.getManagerId()); - item.setNextTeamLeader(managerName); - // 下一班组成员 - String classMember = this.getClassMemberName(nextDuty.getDutyPersonIds(),nextDuty.getManagerId()); - item.setNextClassMember(classMember); - } - - /** - * 获取巡检任务数量 - * @param item - * @param startDate - * @param endDate - */ - private void getInspectionTask(AppAreaDutyVo item, String startDate, String endDate, List deptList) { - item.setInspectionTaskCount(0); - item.setInspectionTaskFinishCount(0); - item.setNotInspectionTaskCount(0); - // 查询当班巡检任务 - Map params = new HashMap<>(); - params.put("startDate",startDate); - params.put("endDate",endDate); - params.put("deptList",deptList); - R response = inspectTaskReportClient.getDutyInspectTask(params); - if(!response.isSuccess() || ObjectUtil.isEmpty(response.getData())){ - return; - } - // 赋值 - item.setInspectionTaskCount(response.getData().getInspectTaskSum()); - item.setInspectionTaskFinishCount(response.getData().getInspectTaskFinish()); - item.setNotInspectionTaskCount(response.getData().getNotExecuteTaskCount()); - } - - /** - * 获取当班日常维护数据 - * @param item - * @param start - * @param end - * @param deptList - */ - private void getMaintenanceTask(AppAreaDutyVo item, String start, String end, List deptList) { - item.setMaintenanceTaskCount(0); - item.setMaintenanceTaskFinishCount(0); - item.setNotMaintenanceTaskCount(0); - // 查询当班日常维护任务 - List list = maintenanceTaskService.getMaintenanceTask(start, end, deptList); - if(CollectionUtil.isEmpty(list)){ - return; - } - // 总数 - item.setMaintenanceTaskCount(list.size()); - // 完成数 - int maintenanceTaskFinishCount = (int) list.stream().filter(o-> MaintenanceConstant.TASK_STATUS_5 == o.getStatus()).count(); - item.setMaintenanceTaskFinishCount(maintenanceTaskFinishCount); - // 未完成数 - int notMaintenanceTaskCount = list.size() - maintenanceTaskFinishCount; - item.setNotMaintenanceTaskCount(notMaintenanceTaskCount); - } - - /** - * 获取检修任务数量 - * @param item - * @param start - * @param end - * @param deptList - */ - private void getOverhaulTask(AppAreaDutyVo item, String start, String end, List deptList) { - item.setOverhaulTaskCount(0); - item.setNotOverhaulTaskCount(0); - item.setOverhaulTaskFinishCount(0); - // 查询当班检修任务 - List list = accessTaskService.getAccessTask(start, end, deptList); - if(CollectionUtil.isEmpty(list)){ - return; - } - // 总数 - item.setOverhaulTaskCount(list.size()); - // 完成数 - int overhaulTaskFinishCount = (int) list.stream().filter(o-> AccessConstants.ACCESS_TASK_STATUS_4 == o.getStatus()).count(); - item.setOverhaulTaskFinishCount(overhaulTaskFinishCount); - // 未开始数 - int notOverhaulTaskCount = (int) list.stream().filter(o-> AccessConstants.ACCESS_TASK_STATUS_0 == o.getStatus()).count(); - item.setNotOverhaulTaskCount(notOverhaulTaskCount); - } - - /** - * 获取当班缺陷数据 - * @param item - * @param startTime - * @param endTime - */ - private void getDutyDefect(AppAreaDutyVo item, LocalDateTime startTime, LocalDateTime endTime) { - LambdaQueryWrapper wrapper = Wrappers.lambdaQuery(); - wrapper.ge(OperPhenomenonEntity::getCreateTime,startTime); - //wrapper.le(OperPhenomenonEntity::getCreateTime,endTime); - wrapper.eq(OperPhenomenonEntity::getIsDefect, TreatMethodConstant.IS_DEFECT); - wrapper.eq(OperPhenomenonEntity::getDiscriminateStatus,TreatMethodConstant.AUTO_SCREENED); - // 查询现象 - List list = phenomenonService.list(wrapper); - if(CollectionUtil.isEmpty(list)){ - item.setUnsolvedCount(0); - item.setSolvedCount(0); - item.setDefectSum(0); - item.setSeriousCount(0); - item.setDefectRate(0.0); - return; - } - // 缺陷总数 - int defectSum = list.size(); - item.setDefectSum(defectSum); - // 缺陷已解决数量 - int solvedCount = (int) list.stream().filter(o->TreatMethodConstant.CONCLUSION_COMPLETED.equals(o.getConclusionStatus())).count(); - item.setSolvedCount(solvedCount); - // 缺陷未解决数量 - int unsolvedCount = list.size() - solvedCount; - item.setUnsolvedCount(unsolvedCount); - // 缺陷严重数量 - int seriousCount = (int) list.stream().filter(o-> TreatMethodConstant.CLASS_I_DEFECT.toString().equals(o.getDefectLevel())).count(); - item.setSeriousCount(seriousCount); - // 消缺率 - double defectRate = BigDecimal.valueOf((double) solvedCount / (double)list.size() * 100).setScale(2, RoundingMode.HALF_UP).doubleValue(); - item.setDefectRate(defectRate); - } - - /** - * 获取班组负责人 - * @param managerId - * @return - */ - private String getManagerName(String managerId) { - if(StringUtil.isBlank(managerId)){ - return ""; - } - User user = UserCache.getUser(Long.valueOf(managerId)); - if (ObjectUtil.isEmpty(user)) { - return ""; - } - return user.getName(); - } - - /** - * 获取班组成员 - * @param personIds - * @param managerId - * @return - */ - private String getClassMemberName(String personIds,String managerId) { - if(StringUtil.isBlank(personIds)){ - return ""; - } - StringBuilder builder = new StringBuilder(); - // 遍历成员 - for (String item : personIds.split("\\^")) { - if (item.equals(managerId)) { - continue; - } - User user = UserCache.getUser(Long.valueOf(item)); - if (ObjectUtil.isEmpty(user)) { - continue; - } - builder.append(user.getName()).append(","); - } - if(builder.length() <= 0){ - return ""; - } - return builder.substring(0,builder.toString().length() - 1); - } - -} diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/service/impl/HomePageServiceImpl.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/service/impl/HomePageServiceImpl.java deleted file mode 100644 index 2d5f9b3..0000000 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/service/impl/HomePageServiceImpl.java +++ /dev/null @@ -1,2200 +0,0 @@ -package com.hnac.hzims.operational.main.service.impl; - -import com.alibaba.fastjson.JSONObject; -import com.alibaba.fastjson.TypeReference; -import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; -import com.hnac.hzims.equipment.entity.PlanGenerationEntity; -import com.hnac.hzims.equipment.feign.IPlanGenertionClient; -import com.hnac.hzims.equipment.vo.EmInfoExtendVo; -import com.hnac.hzims.equipment.vo.EminfoAndEmParamVo; -import com.hnac.hzims.monitor.utils.DateUtils; -import com.hnac.hzims.operational.fill.entity.*; -import com.hnac.hzims.operational.fill.service.*; -import com.hnac.hzims.operational.main.constant.HomePageConstant; -import com.hnac.hzims.operational.main.service.IAnalyseDataService; -import com.hnac.hzims.operational.main.service.IHomePageService; -import com.hnac.hzims.operational.main.service.IMainSystemMonitoringService; -import com.hnac.hzims.operational.main.service.IMainTaskStatisticService; -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.ticket.allTicket.dto.TicketStatisticDTO; -import com.hnac.hzims.ticket.allTicket.fegin.ITicketInfoAllClient; -import com.hnac.hzims.ticket.allTicket.vo.DoublePassRateVO; -import com.hnac.hzims.ticket.allTicket.vo.DoublePassVO; -import com.hnac.hzinfo.datasearch.analyse.IAnalyseInstanceClient; -import com.hnac.hzinfo.datasearch.analyse.vo.AnalyseDataTaosVO; -import com.hnac.hzinfo.datasearch.soe.ISoeClient; -import com.hnac.hzinfo.datasearch.soe.domian.SoeData; -import com.hnac.hzinfo.sdk.core.response.Result; -import lombok.RequiredArgsConstructor; -import lombok.extern.slf4j.Slf4j; -import org.apache.commons.collections4.MapUtils; -import org.springblade.core.tool.api.R; -import org.springblade.core.tool.utils.*; -import org.springblade.system.cache.DictCache; -import org.springblade.system.entity.Dept; -import org.springblade.system.entity.Region; -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.io.BufferedReader; -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.math.BigDecimal; -import java.net.HttpURLConnection; -import java.net.URL; -import java.nio.charset.StandardCharsets; -import java.text.ParseException; -import java.text.SimpleDateFormat; -import java.time.LocalDate; -import java.time.LocalDateTime; -import java.time.LocalTime; -import java.time.format.DateTimeFormatter; -import java.util.*; -import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.CountDownLatch; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; -import java.util.stream.Collectors; - -@Service -@RequiredArgsConstructor -@Slf4j -public class HomePageServiceImpl implements IHomePageService { - - private final IStationService stationService; - - private final PowerService powerService; - - private final OverService overService; - - private final SolveService solveService; - - private final OtherService otherService; - - private final OverDetailsService overDetailsService; - - private final IAnalyseDataService analyseDataService; - - private final PowerService photovoltaicService; - - private final GenerateService hydropowerService; - - private final IMainSystemMonitoringService maintenanceTaskService; - - private final IMainTaskStatisticService mainTaskStatisticService; - - private final ISysClient sysClient; - - private final ISoeClient soeClient; - - private final IPlanGenertionClient planGenertionClient; - - private final ITicketInfoAllClient ticketInfoAllClient; - - private final IAnalyseInstanceClient analyseInstanceClient; - - private final RedisTemplate redisTemplate; - - private final static String KEY_INDICATORS_INFO = "hzims:operation:key:indicators:info"; - private final static String RECENT_YEAR_POWER_DATA = "hzims:operation:key:power:data"; - - private final static String CHARGE_SUM = "hzims:operation:key:charge_sum"; - //发电标识 - private final static String GENERATE_ELECTRICITY = "generation_capacity"; - //站点Code - private final static String STATION_TYPE = "stationType"; - //线程数量 - private final static int THREAD_QUANTITY = 4; - private final static int DISTRIBUTION_NETWORK_THREAD_QUANTITY = 3; - - @Value("${hzims.operation.homePage.charge.url}") - public String url; - - @Value("${hzims.operation.homePage.systemMonitoring.hydropowerStation.yearGeneration}") - public String yearGenerationData; - - @Value("${hzims.operation.homePage.activePowerKey}") - public String activePowerKey; - - @Value("${hzims.operation.homePage.jointRelayKey}") - public String jointRelayKey; - - /** - * 水电站数据加载 - * - * @param param - * @param serveType - */ - @Override - public void loadHydropower(String param, Integer serveType) { - KeyIndicatorsVo keyIndicatorsVo = new KeyIndicatorsVo(); - // 站点类型 - List storage = Arrays.asList(HomePageConstant.HYDROPOWER, HomePageConstant.WIND_POWER, HomePageConstant.WATER_CONSERVANCY,HomePageConstant.PUMPING,HomePageConstant.GATE, HomePageConstant.ENERGY_STORAGE, - HomePageConstant.DISTRIBUTION_NETWORK, HomePageConstant.PHOTOVOLTAIC, HomePageConstant.WATER_AFFAIRS, HomePageConstant.CHARGE); - // 站点查询 - List stationList = stationService.getStationType(serveType, storage, null,true); - // 站点根据type类型分组 - Map> stationGrpMap = stationList.stream().collect(Collectors.groupingBy(StationEntity::getType)); - // 遍历分组之后的站点信息 - stationGrpMap.forEach((key, value) -> { - switch (key) { - // 水电站 - case 0: - List powerStationTotalVoList = getLoadHydropower(value); - keyIndicatorsVo.setPowerStationTotalVoList(powerStationTotalVoList); - break; - // 风电站 - case 1: - List windPowerVoList = this.getWindPhotoPower(value, HomePageConstant.WIND_POWER_TYPE); - keyIndicatorsVo.setWindPowerVoList(windPowerVoList); - break; - // 水利 - case 2: - break; - // 储能站 - case 3: - break; - // 配网 - case 4: - break; - // 光伏站 - case 5: - List photovoltaicVoList = this.getWindPhotoPower(value, HomePageConstant.PHOTOVOLTAIC_TYPE); - keyIndicatorsVo.setPhotovoltaicVoList(photovoltaicVoList); - break; - // 水务 - case 6: - break; - // 充电桩 - case 7: - break; - default: - break; - } - }); - redisTemplate.opsForValue().set(KEY_INDICATORS_INFO, keyIndicatorsVo); - } - - /** - * 获取风电数据 - * - * @param value - * @return - */ - private List getWindPhotoPower(List value, Integer type) { - // 站点归属机构集合 - List deptList = value.stream().map(StationEntity::getRefDept).collect(Collectors.toList()); - List power = this.getPowerData(deptList, type); - if (CollectionUtil.isEmpty(power)) { - return null; - } - // 返回对象 - return power.stream().map(entity -> { - PowerStationTotalVo vo = new PowerStationTotalVo(); - List station = value.stream().filter(o -> o.getRefDept().equals(entity.getCreateDept())).collect(Collectors.toList()); - vo.setStationId(station.get(0).getId()); - vo.setInstalledCapacity(entity.getInstalledCapacity()); - vo.setCurrentYearPowerGeneration(Float.valueOf(entity.getPowerYear().toString())); - vo.setPlannedPowerGeneration(entity.getPlannedPowerYear()); - vo.setDoubleQualifyRate(Double.valueOf(entity.getDoubleQualifyRate())); - return vo; - }).collect(Collectors.toList()); - } - - /** - * 获取光伏、风电数据 - * - * @param deptList - * @param type - * @return - */ - private List getPowerData(List deptList, Integer type) { - // 查询机构最大月份记录 - String mon = DateUtil.format(new Date(),"yyyy"); - QueryWrapper queryWrapper = new QueryWrapper() {{ - in("create_dept", deptList); - eq("type", type); - ge("mon", mon + "-01"); - }}; - List list = powerService.list(queryWrapper); - if(CollectionUtil.isEmpty(list)){ - return null; - } - Map> map = list.stream().collect(Collectors.groupingBy(PowerEntity::getCreateDept)); - if(MapUtils.isEmpty(map)){ - return null; - } - return map.entrySet().stream().map(entry-> entry.getValue().stream().sorted(Comparator.comparing(PowerEntity::getMon).reversed()).collect(Collectors.toList()).get(0)).collect(Collectors.toList()); - } - /** - * 近年发电量数据 - * - * @param param 时间 - * @param serveType 站点类型 - * @param year 近几年 - */ - @Override - public void loadPowerData(String param,List types, Integer serveType, int year) { - // 站点查询 - List stationList = stationService.getStationType(serveType, types, null,true); - // 设备信息 - List devices = maintenanceTaskService.getEmInfoList(); - // 开始时间 - Calendar calendar = Calendar.getInstance(); - calendar.add(Calendar.MONTH, -calendar.get(Calendar.MONTH) + 12); - calendar.add(Calendar.DATE, -calendar.get(Calendar.DATE) + 1); - String end = DateUtil.format(calendar.getTime(),DateUtil.PATTERN_DATE) + " 00:00:00"; - // 结束日期 - calendar.set(Calendar.YEAR, calendar.get(Calendar.YEAR) - year); - calendar.add(Calendar.MONTH, -calendar.get(Calendar.MONTH)); - String start = DateUtil.format(calendar.getTime(),DateUtil.PATTERN_DATE) + " 00:00:00"; - // 存储数据map :<站点id,<月份,发电量>> - Map> powerMap = new HashMap<>(); - stationList.forEach(station -> { - // 站点设备集合 - List stationDevices = devices.stream().filter(device -> device.getCreateDept().equals(station.getRefDept())).collect(Collectors.toList()); - Map generateMap = this.getGenerateYear(station,stationDevices,start,end); - if(MapUtils.isEmpty(generateMap)){ - return; - } - powerMap.put(station.getId(),generateMap); - }); - redisTemplate.opsForValue().set(RECENT_YEAR_POWER_DATA, powerMap); - } - - /** - * 获取年发电量 - * @param devices - * @param start - * @param end - * @return - */ - private Map getGenerateYear(StationEntity station,List devices, String start, String end) { - List datas = new ArrayList<>(); - // 设备采集发电量 - if(CollectionUtil.isNotEmpty(devices)){ - devices.forEach(device->{ - List records = analyseDataService.periodTargetData(start,end,5,5,device.getEmCode(),HomePageConstant.HYDROPOWER_GENERATE_POWER); - if(CollectionUtil.isEmpty(records)){ - return; - } - datas.addAll(records.stream().map(record -> { - PowerMonthVo generate = new PowerMonthVo(); - Date time = DateUtil.parse(record.getTs(), "yyyy-MM-dd HH:mm:ss.s"); - generate.setStrMonth(DateUtil.format(time,DateUtil.PATTERN_DATE)); - generate.setPower(Float.parseFloat(Optional.ofNullable(record.getVal()).orElse("0")) * device.getRideCount()); - return generate; - }).collect(Collectors.toList())); - }); - } - // 补充填报数据 - datas.addAll(this.generateFill(station,start,end)); - if(CollectionUtil.isEmpty(datas)){ - return null; - } - return datas.stream().collect(Collectors.toMap(PowerMonthVo::getStrMonth, PowerMonthVo::getPower, Float::sum)); - } - - /** - * 补充填报数据 - * @param station - * @param start - * @param end - */ - private List generateFill(StationEntity station, String start, String end) { - start = DateUtil.format(DateUtil.parse(start,DateUtil.PATTERN_DATETIME),"yyyy-MM"); - end = DateUtil.format(DateUtil.parse(end,DateUtil.PATTERN_DATETIME),"yyyy-MM"); - // 光伏 - if(HomePageConstant.PHOTOVOLTAIC.equals(station.getType())){ - return photovoltaicService.generateThreeYear(start,end,station.getRefDept()); - // 水电 - } - return hydropowerService.generateThreeYear(start,end,station.getCode()); - } - - /** - * @param stationList - * @return - */ - private List getDoublePass(List stationList) { - Map stationMap = new HashMap<>(); - stationList.forEach(o -> { - if (null == o.getId() || null == o.getRefDept()) { - return; - } - stationMap.put(o.getId().toString(), o.getRefDept().toString()); - }); - // 当月首日 - LocalDate firstDay = LocalDate.now().withDayOfMonth(1); - LocalDateTime firstDateTime = LocalDateTime.of(firstDay, LocalTime.MIN); - TicketStatisticDTO ticketStatisticDTO=new TicketStatisticDTO(); - ticketStatisticDTO.setStationMap(stationMap); - ticketStatisticDTO.setStartTime(firstDateTime); - ticketStatisticDTO.setEndTime(LocalDateTime.now()); - return ticketInfoAllClient.getDoublePassQuantity(ticketStatisticDTO); - } - - /** - * 获取服务厂站统计 - * @param deptId - * @param serveType - * @return - */ - @Override - public List getStationCount(Long deptId, Integer serveType) { - //根据用户权限获取机构 - R> R = sysClient.getDeptByCurrentUser(); - if (!R.isSuccess() || ObjectUtil.isEmpty(R.getData())) { - return null; - } - // 站点类型 - List storage = Arrays.asList(HomePageConstant.HYDROPOWER, HomePageConstant.WIND_POWER, HomePageConstant.WATER_CONSERVANCY, HomePageConstant.PUMPING, HomePageConstant.GATE, HomePageConstant.ENERGY_STORAGE, - HomePageConstant.DISTRIBUTION_NETWORK, HomePageConstant.PHOTOVOLTAIC, HomePageConstant.WATER_AFFAIRS, HomePageConstant.CHARGE); - // 查询站点 - List stationEntityList = stationService.getStationList(R.getData(),deptId,storage,serveType,true); - List list = new ArrayList<>(); - storage.forEach(item->{ - if(HomePageConstant.PUMPING.equals(item) || HomePageConstant.GATE.equals(item)){ - return; - } - OldStationCountVo stationCountVo = new OldStationCountVo(); - stationCountVo.setStationType(item.toString()); - stationCountVo.setStationTypeName(DictCache.getValue("stationType", item)); - stationCountVo.setCount(0); - if(HomePageConstant.CHARGE.equals(item) && HomePageConstant.HYDROPOWER_SERVETYPE.equals(serveType)){ - ChargeVo charge = (ChargeVo) redisTemplate.opsForValue().get(CHARGE_SUM); - if(StringUtil.isEmpty(charge)){ - ChargeVo chargeVo = new ChargeVo(); - this.getCharge(chargeVo); - stationCountVo.setCount(chargeVo.getCount()); - }else{ - stationCountVo.setCount(charge.getCount()); - } - list.add(stationCountVo); - return; - } - if(CollectionUtil.isNotEmpty(stationEntityList)){ - long count; - if(HomePageConstant.WATER_CONSERVANCY.equals(item)){ - count = stationEntityList.stream().filter(o -> HomePageConstant.waterList.contains(o.getType())).count(); - } else { - count = stationEntityList.stream().filter(o -> o.getType().equals(item)).count(); - } - stationCountVo.setCount((int) count); - } - list.add(stationCountVo); - }); - return list; - } - - /** - * 获取水电站点信息 - * - * @param value - * @return List - */ - private List getLoadHydropower(List value) { - List powerStationTotalVoList = new ArrayList<>(); - // 获取设备信息、装机容量、ct、pt 、rideCount - List equipmentInfoList = maintenanceTaskService.getEmInfoList(); - // 站点Code集合 - List stationCodeList = value.stream().map(StationEntity::getCode).collect(Collectors.toList()); - // 根据站点Code查询发电计划 - List planGenerationList = planGenertionClient.getPlanGenerationByParam(stationCodeList, null, DateUtil.format(new Date(), "yyyy")); - value.forEach(item -> { - PowerStationTotalVo powerStationTotalVo = this.getHydropowerTarget(equipmentInfoList, planGenerationList, item); - powerStationTotalVoList.add(powerStationTotalVo); - }); - return powerStationTotalVoList; - } - - - /** - * 获取水电站点指标 - * - * @param equipmentInfoList - * @param planGenerationEntityList - * @param station - * @return - */ - private PowerStationTotalVo getHydropowerTarget(List equipmentInfoList, List planGenerationEntityList,StationEntity station) { - PowerStationTotalVo powerStationTotalVo = new PowerStationTotalVo(); - powerStationTotalVo.setStationId(station.getId()); - Long departId = station.getRefDept(); - powerStationTotalVo.setDeptId(departId); - // 获取对应站点设备 - List effEmInfoList = equipmentInfoList.stream().filter(o -> departId.equals(o.getCreateDept())).collect(Collectors.toList()); - // 装机容量 - double installedCapacity = getInstalledCapacity(equipmentInfoList, station); - powerStationTotalVo.setInstalledCapacity(installedCapacity); - // 当月发电量 - String start = DateUtil.format(new Date(),"yyyy-MM") + "-01 00:00:00"; - String end = DateUtil.format(new Date(),DateUtil.PATTERN_DATETIME); - float powerGeneration = this.generateByDevices(effEmInfoList, start, end,5); - powerStationTotalVo.setPowerGeneration((double)powerGeneration); - // 计划发电量 - double plannedPowerGeneration = this.getPlannedPowerGeneration(planGenerationEntityList, station); - powerStationTotalVo.setPlannedPowerGeneration(plannedPowerGeneration); - // 当年发电量 - end = DateUtil.format(new Date(),DateUtil.PATTERN_DATE); - Calendar calendar = Calendar.getInstance(); - calendar.add(Calendar.MINUTE,-calendar.get(Calendar.MINUTE)); - 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)); - start = DateUtil.format(calendar.getTime(),DateUtil.PATTERN_DATE); - float currentYearPowerGeneration = this.generateByDevices(effEmInfoList, start+ " 00:00:00", end + " 00:00:00",6); - powerStationTotalVo.setCurrentYearPowerGeneration(currentYearPowerGeneration); - // 当日发电量 - float currentDayPowerGeneration = this.generateByDevices(effEmInfoList, getCurrentTime() + " 00:00:00", getAddDayTime(1) + " 00:00:00",3); - powerStationTotalVo.setCurrentDayPowerGeneration(currentDayPowerGeneration); - // 告警列表 - Result> S = soeClient.getByLastLimitTime(null, station.getCode(), 1); - if(!S.isSuccess() || CollectionUtil.isEmpty(S.getData())){ - return powerStationTotalVo; - } - powerStationTotalVo.setAlertList(S.getData()); - return powerStationTotalVo; - } - - /** - * 获取设备发电量 - * @param devices - * @param start - * @param end - * @return - */ - private float generateByDevices(List devices, String start, String end,int accessRules) { - float generate = 0f; - if(CollectionUtil.isEmpty(devices)){ - return generate; - } - for(EminfoAndEmParamVo device : devices ){ - generate += analyseDataService.periodTargetFloat(start,end,5,accessRules,device.getEmCode(),device.getRideCount(),HomePageConstant.HYDROPOWER_GENERATE_POWER); - }; - return generate; - } - - /** - * 获取站点装机容量 - * - * @param equipmentInfoList - * @param station - * @return - */ - private double getInstalledCapacity(List equipmentInfoList, StationEntity station) { - // 装机容量 - if (CollectionUtil.isEmpty(equipmentInfoList)) { - return 0.0; - } - Long departId = station.getRefDept(); - // 获取对应站点设备 - List effEmInfoList = equipmentInfoList.stream().filter(o -> departId.equals(o.getCreateDept())).collect(Collectors.toList()); - // 过滤 非归属机构/装机容量 - if (CollectionUtil.isEmpty(effEmInfoList)) { - return 0.0; - } - return effEmInfoList.stream().filter(o -> null != o.getInstalledCapacity()).mapToDouble(EminfoAndEmParamVo::getInstalledCapacity).sum(); - } - - /** - * 站点首页 - * @param deptId - * @return - */ - @Override - public List homeStation(Long deptId) { - return null; - } - - - /** - * 年计划发电完成趋势 - * @param deptId - * @return - */ - @Override - public List planActualTrend(Long deptId) { - //根据用户权限获取机构 - R> R = sysClient.getDeptByCurrentUser(); - if (!R.isSuccess() || ObjectUtil.isEmpty(R.getData())) { - return null; - } - // 查询站点 - List stationList = stationService.getStationList(R.getData(),deptId,Collections.singletonList(HomePageConstant.HYDROPOWER),HomePageConstant.HYDROPOWER_SERVETYPE,true); - if(CollectionUtil.isEmpty(stationList)){ - return null; - } - // 站点cdoe集合 - List codeList = stationList.stream().map(StationEntity::getCode).collect(Collectors.toList()); - // 计划发电量 - Calendar calendar = Calendar.getInstance(); - calendar.setTime(new Date()); - String year = String.valueOf(calendar.get(Calendar.YEAR)); - List planPowerList = planGenertionClient.getPlanGenerationByParam(codeList,null,year); - // 实际发电量 - Map> powerMap = (Map>) redisTemplate.opsForValue().get(RECENT_YEAR_POWER_DATA); - List monList = this.getMonthList(0, 12,false); - Map floatMap = this.getStationFloatMap(stationList,powerMap,monList); - List list = new ArrayList<>(); - monList.forEach(mon -> { - PowerMonthVo vo = new PowerMonthVo(); - LocalDate localDate = LocalDate.parse(DateUtil.format(new Date(), mon), DateTimeFormatter.ofPattern(DateUtil.PATTERN_DATE)); - vo.setYear(localDate.getYear()); - vo.setMonth(localDate.getMonthValue()); - vo.setStrMonth(mon); - if(CollectionUtil.isEmpty(planPowerList)){ - vo.setPlanPower(0f); - }else { - vo.setPlanPower((float) planPowerList.stream().filter(o->mon.equals(o.getDateTime()+"-01")).mapToDouble(PlanGenerationEntity::getPlanGeneration).sum()); - } - if(MapUtils.isEmpty(floatMap)){ - vo.setPower(0f); - }else{ - vo.setPower(floatMap.get(mon)); - } - list.add(vo); - }); - return list; - } - - - /** - * 获取站点月份发电量map - * @param stationList - * @param powerMap - * @param monList - * @return - */ - private Map getStationFloatMap(List stationList, Map> powerMap, List monList) { - if(MapUtils.isEmpty(powerMap)){ - return null; - } - // 站点Id集合 - List stationIdList = stationList.stream().map(StationEntity::getId).collect(Collectors.toList()); - // 获取有效站点实际发电量 - List> valueList = powerMap.entrySet().stream().filter(e -> stationIdList.contains(e.getKey())).map(Map.Entry::getValue).collect(Collectors.toList()); - Map map = new HashMap<>(); - monList.forEach(mon->{ - float power = this.getStationFloat(mon,valueList); - map.put(mon,power); - }); - return map; - } - - /** - * 获取站点月份发电量 - * @param mon - * @param valueList - * @return - */ - private float getStationFloat(String mon, List> valueList) { - float power = 0f; - for (Map item : valueList){ - power += item.get(mon); - } - return power; - } - - /** - * 获取站点计划发电量 - * - * @param planGenerationEntityList - * @param station - * @return - */ - private double getPlannedPowerGeneration(List planGenerationEntityList, StationEntity station) { - if (CollectionUtil.isEmpty(planGenerationEntityList)) { - return 0.0; - } - double planFloat = planGenerationEntityList.stream().filter(o -> null != o.getPlanGeneration() && o.getStationId().equals(station.getCode())).mapToDouble(PlanGenerationEntity::getPlanGeneration).sum(); - if (Math.abs(planFloat) <= 0 ) { - return 0.0; - } - return planFloat; - } - - /** - * 关键指标 - 发电站 - * - * @param serveType - * @return List - */ - @Override - public List powerTarget(Integer serveType,Long deptId) { - //根据用户权限获取机构 - R> R = sysClient.getDeptByCurrentUser(); - if (!R.isSuccess() || ObjectUtil.isEmpty(R.getData())) { - return null; - } - List storage = Arrays.asList(HomePageConstant.HYDROPOWER, HomePageConstant.WIND_POWER, HomePageConstant.PHOTOVOLTAIC); - // 查询站点数据 - List stationEntityList = stationService.getStationList(R.getData(),deptId, storage,HomePageConstant.HYDROPOWER_SERVETYPE,true); - if(CollectionUtil.isEmpty(stationEntityList)){ - return null; - } - // 根据站点类型分组 - Map> stationMap = stationEntityList.stream().collect(Collectors.groupingBy(StationEntity::getType)); - // Redis数据获取 - KeyIndicatorsVo keyIndicatorsVo = (KeyIndicatorsVo) redisTemplate.opsForValue().get(KEY_INDICATORS_INFO); - if (!Optional.ofNullable(keyIndicatorsVo).isPresent()) { - return null; - } - List powerTargetVoList = new ArrayList<>(); - // 遍历发电站类型 - storage.forEach(type -> { - PowerTargetVo powerTargetVo = new PowerTargetVo(); - powerTargetVo.setTargetCode(type); - powerTargetVo.setTargetType(DictCache.getValue(STATION_TYPE, type)); - List grpStationList = stationMap.get(type); - List list; - switch (type) { - case 0: - list = keyIndicatorsVo.getPowerStationTotalVoList(); - this.powerHandle(list, grpStationList, powerTargetVo, type); - List deptIds = list.stream().map(PowerStationTotalVo::getDeptId).collect(Collectors.toList()); - if(CollectionUtil.isNotEmpty(deptIds)){ - List parentIds = R.getData().stream().filter(o->deptIds.contains(o.getId())).map(Dept::getParentId).distinct().collect(Collectors.toList()); - // 年双票合格率 - String doubleTicketPassRate = this.setDoubleTicketPassRate(parentIds); - powerTargetVo.setDoubleTicketPassRate(doubleTicketPassRate); - } - powerTargetVoList.add(powerTargetVo); - break; - case 1: - list = keyIndicatorsVo.getWindPowerVoList(); - this.powerHandle(list, grpStationList, powerTargetVo, type); - powerTargetVoList.add(powerTargetVo); - break; - case 5: - list = keyIndicatorsVo.getPhotovoltaicVoList(); - this.powerHandle(list, grpStationList, powerTargetVo, type); - powerTargetVoList.add(powerTargetVo); - break; - default: - list = new ArrayList<>(); - } - }); - return powerTargetVoList; - } - - /** - * 获取双票合格率 - * @param list - */ - private String setDoubleTicketPassRate(List list) { - if(CollectionUtil.isEmpty(list)){ - return "0.0"; - } - LocalDate firstDay = LocalDate.now().withDayOfYear(1); - LocalDateTime firstDateTime = LocalDateTime.of(firstDay, LocalTime.MIN); - TicketStatisticDTO ticketStatisticDTO=new TicketStatisticDTO(); - ticketStatisticDTO.setDepatList(list); - ticketStatisticDTO.setStartTime(firstDateTime); - ticketStatisticDTO.setEndTime(LocalDateTime.now()); - DoublePassRateVO doublePassRateVO = ticketInfoAllClient.getDoublePassRate(ticketStatisticDTO); - if(ObjectUtil.isEmpty(doublePassRateVO)){ - return "0.0"; - } - return doublePassRateVO.getDoublePassRate(); - } - - /** - * 关键指标 - 水电站数据处理 - * - * @param powerStationTotalVoList - * @param grpStationList - * @param powerTargetVo - */ - public void powerHandle(List powerStationTotalVoList, List grpStationList, PowerTargetVo powerTargetVo, int type) { - if (CollectionUtil.isEmpty(powerStationTotalVoList) || CollectionUtil.isEmpty(grpStationList)) { - powerTargetVo.setInstalledCapacity(0.0); - powerTargetVo.setPowerGeneration("0"); - powerTargetVo.setCompletionRate("0"); - powerTargetVo.setDoubleTicketPassRate("0"); - return; - } - List stationIdList = grpStationList.stream().map(StationEntity::getId).collect(Collectors.toList()); - // 装机容量 - double installedCapacity = powerStationTotalVoList.stream().filter(o -> stationIdList.contains(o.getStationId())).mapToDouble(PowerStationTotalVo::getInstalledCapacity).sum(); - powerTargetVo.setInstalledCapacity(installedCapacity); - // 实际发电量 - double powerGeneration = BigDecimal.valueOf(powerStationTotalVoList.stream().filter(o -> stationIdList.contains(o.getStationId())).mapToDouble(PowerStationTotalVo::getCurrentYearPowerGeneration).sum()).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue(); - powerTargetVo.setPowerGeneration(String.valueOf(powerGeneration)); - // 计划发电量 - double plannedPowerGeneration = powerStationTotalVoList.stream().filter(o -> stationIdList.contains(o.getStationId())).mapToDouble(PowerStationTotalVo::getPlannedPowerGeneration).sum(); - if (0 == powerGeneration || 0 == plannedPowerGeneration) { - powerTargetVo.setCompletionRate("0"); - } else { - double completionRate = new BigDecimal(powerGeneration / plannedPowerGeneration * 100).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();; - powerTargetVo.setCompletionRate(String.valueOf(completionRate)); - } - // 双票总数 - if (type == 0) { - return; - } - // 风电、光伏电站计算平均合格率 - double doubleTicketPassRate = powerStationTotalVoList.stream().filter(o -> stationIdList.contains(o.getStationId())).mapToDouble(PowerStationTotalVo::getDoubleQualifyRate).sum(); - if (Math.abs(doubleTicketPassRate) <= 0) { - powerTargetVo.setDoubleTicketPassRate("0"); - } else { - double doublePassRate = BigDecimal.valueOf(doubleTicketPassRate / powerStationTotalVoList.size()).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue(); - powerTargetVo.setDoubleTicketPassRate(String.valueOf(doublePassRate)); - } - } - - /** - * 关键指标 - 储能、水利 - * - * @param serveType - * @return List - */ - @Override - public List storageConservancy(Integer serveType,Long deptId) { - //根据用户权限获取机构 - R> result = sysClient.getDeptByCurrentUser(); - if (!result.isSuccess() || ObjectUtil.isEmpty(result.getData())) { - return null; - } - Map> storage = this.getStorageMap(result.getData(),serveType); - if(MapUtils.isEmpty(storage)){ - return null; - } - List storagList = new ArrayList<>(); - storage.entrySet().forEach(entry -> { - StorageConservancyVo storageConservancyVo = new StorageConservancyVo(); - storageConservancyVo.setTargetCode(entry.getKey()); - storageConservancyVo.setTargetType(DictCache.getValue(STATION_TYPE, entry.getKey())); - if (CollectionUtil.isEmpty(entry.getValue())) { - storageConservancyVo.setRoutineMaintenance(0); - storageConservancyVo.setMaintenanceTasks(0); - storageConservancyVo.setDeletionRate("0"); - storageConservancyVo.setPassRate("0"); - storagList.add(storageConservancyVo); - return; - } - // 线程池 - ExecutorService exe = Executors.newFixedThreadPool(THREAD_QUANTITY); - // 监控线程执行完后返回结果 - CountDownLatch countDownLatch = new CountDownLatch(THREAD_QUANTITY); - // 日常维护 - exe.execute(() -> { - Integer mTaskCount = mainTaskStatisticService.getRoutineMaintenanceCount(entry.getValue()); - storageConservancyVo.setRoutineMaintenance(mTaskCount); - countDownLatch.countDown(); - }); - // 检修任务 - exe.execute(() -> { - Integer aTaskCount = mainTaskStatisticService.getMaintenanceTasksCount(entry.getValue()); - storageConservancyVo.setMaintenanceTasks(aTaskCount); - countDownLatch.countDown(); - }); - // 消缺率 - exe.execute(() -> { - String deletionRate = mainTaskStatisticService.getDeletionRate(entry.getValue()); - storageConservancyVo.setDeletionRate(deletionRate); - countDownLatch.countDown(); - }); - // 双票合格率 - exe.execute(() -> { - LocalDate firstDay = LocalDate.now().withDayOfYear(1); - LocalDateTime firstDateTime = LocalDateTime.of(firstDay, LocalTime.MIN); - TicketStatisticDTO ticketStatisticDTO=new TicketStatisticDTO(); - ticketStatisticDTO.setDepatList(entry.getValue()); - ticketStatisticDTO.setStartTime(firstDateTime); - ticketStatisticDTO.setEndTime(LocalDateTime.now()); - DoublePassRateVO doublePassRateVO = ticketInfoAllClient.getDoublePassRate(ticketStatisticDTO); - if (ObjectUtil.isEmpty(doublePassRateVO)) { - storageConservancyVo.setPassRate("0"); - } else { - storageConservancyVo.setPassRate(doublePassRateVO.getDoublePassRate()); - } - countDownLatch.countDown(); - }); - - try { - countDownLatch.await(); - } catch (InterruptedException e) { - e.printStackTrace(); - Thread.currentThread().interrupt(); - } - exe.shutdown(); - storagList.add(storageConservancyVo); - }); - return storagList; - } - - /** - * 获取储能、水利区域机构map - * @param serveType - * @return - */ - private Map> getStorageMap(List all,Integer serveType) { - Map> map = new HashMap<>(); - // 储能 - List energy = this.stationService.getStationType(serveType,Collections.singletonList(HomePageConstant.ENERGY_STORAGE),null,true); - if(CollectionUtil.isNotEmpty(energy)){ - List refDeptList = energy.stream().map(StationEntity::getRefDept).collect(Collectors.toList()); - if(CollectionUtil.isNotEmpty(refDeptList)){ - map.put(HomePageConstant.ENERGY_STORAGE,all.stream().filter(o->refDeptList.contains(o.getId())).map(Dept::getParentId).distinct().collect(Collectors.toList())); - } - } - // 水利 - List water = this.stationService.getStationType(serveType,HomePageConstant.waterList,null,true); - if(CollectionUtil.isNotEmpty(water)){ - List refDeptList = water.stream().map(StationEntity::getRefDept).collect(Collectors.toList()); - if(CollectionUtil.isNotEmpty(refDeptList)){ - map.put(HomePageConstant.WATER_CONSERVANCY,all.stream().filter(o->refDeptList.contains(o.getId())).map(Dept::getParentId).distinct().collect(Collectors.toList())); - } - } - return map; - } - - /** - * 关键指标 - 水务 - * - * @param serveType - * @return List - */ - @Override - public OtherStationVo otherStation(Integer serveType,Long deptId) { - //根据用户权限获取机构 - R> R = sysClient.getDeptByCurrentUser(); - if (!R.isSuccess() || ObjectUtil.isEmpty(R.getData())) { - return null; - } - // 查询站点信息 - List storage = Arrays.asList(HomePageConstant.DISTRIBUTION_NETWORK, HomePageConstant.WATER_AFFAIRS, HomePageConstant.CHARGE); - // 查询站点数据 - OtherStationVo otherStationVo = new OtherStationVo(); - storage.forEach(type -> { - String stationType = DictCache.getValue(STATION_TYPE, type); - switch (type) { - // 配网 - case 4: - DistributionNetworkVo distributionNetworkVo = new DistributionNetworkVo(); - distributionNetworkVo.setTargetCode(type); - distributionNetworkVo.setTargetType(stationType); - this.distributionNetWortHandle(otherStationVo,distributionNetworkVo); - break; - // 水务 - case 6: - WaterAffairsVo waterAffairsVo = new WaterAffairsVo(); - waterAffairsVo.setTargetCode(type); - waterAffairsVo.setTargetType(stationType); - waterAffairsVo.setEquipmentAvailability("0"); - waterAffairsVo.setWorkOrderCompletionRate("0"); - waterAffairsVo.setInspectionTask(0); - otherStationVo.setWaterAffairsVo(waterAffairsVo); - break; - // 充电桩 - case 7: - ChargeVo chargeVo = new ChargeVo(); - chargeVo.setTargetCode(type); - chargeVo.setTargetType(stationType); - this.getCharge(chargeVo); - otherStationVo.setChargeVo(chargeVo); - break; - } - }); - return otherStationVo; - } - - /** - * 检修卡数据 - * @param otherStationVo - * @param distributionNetworkVo - */ - private void distributionNetWortHandle(OtherStationVo otherStationVo,DistributionNetworkVo distributionNetworkVo) { - // 线程池 - ExecutorService exe = Executors.newFixedThreadPool(DISTRIBUTION_NETWORK_THREAD_QUANTITY); - // 监控线程执行完后返回结果 - CountDownLatch countDownLatch = new CountDownLatch(DISTRIBUTION_NETWORK_THREAD_QUANTITY); - // 当月 - LocalDate firstDay = LocalDate.now().withDayOfYear(1); - LocalDateTime firstDateTime = LocalDateTime.of(firstDay, LocalTime.MIN); - // 检修卡 - exe.execute(()->{ - List overList = overService.list(new QueryWrapper() {{ - ge("create_time", firstDateTime); - le("create_time", LocalDateTime.now()); - }}); - if(CollectionUtil.isEmpty(overList)){ - distributionNetworkVo.setMaintenanceCard(0); - countDownLatch.countDown(); - return; - } - List countList = overDetailsService.list(new QueryWrapper() {{ - ge("create_time", firstDateTime); - le("create_time", LocalDateTime.now()); - in("over_id",overList.stream().map(OverEntity::getId).collect(Collectors.toList())); - }}); - if(CollectionUtil.isEmpty(countList)){ - distributionNetworkVo.setMaintenanceCard(0); - countDownLatch.countDown(); - return; - } - distributionNetworkVo.setMaintenanceCard(countList.stream().mapToInt(OverDetailsEntity::getQuantity).sum()); - countDownLatch.countDown(); - }); - // 消缺 - exe.execute(()->{ - List solveList = solveService.list(new QueryWrapper() {{ - ge("create_time", firstDateTime); - le("create_time", LocalDateTime.now()); - }}); - if(CollectionUtil.isEmpty(solveList)){ - distributionNetworkVo.setDefectElimination(0); - countDownLatch.countDown(); - return; - } - int defectElimination = solveList.stream().mapToInt(SolveEntity::getSolveQuantity).sum(); - distributionNetworkVo.setDefectElimination(defectElimination); - countDownLatch.countDown(); - }); - // 其他 - exe.execute(()->{ - List otherList = otherService.list(new QueryWrapper() {{ - ge("create_time", firstDateTime); - le("create_time", LocalDateTime.now()); - }}); - if(CollectionUtil.isEmpty(otherList)){ - distributionNetworkVo.setOnlineRate("0.0"); - distributionNetworkVo.setFaInvestment(0); - countDownLatch.countDown(); - return; - } - int faInvestment = otherList.stream().mapToInt(OtherEntity::getFaQuantity).sum(); - distributionNetworkVo.setFaInvestment(faInvestment); - double onlineRate = otherList.stream().mapToDouble(o-> Double.parseDouble(o.getOnlineRate())).average().getAsDouble(); - if(Math.abs(onlineRate) <= 0){ - distributionNetworkVo.setOnlineRate("0.0"); - countDownLatch.countDown(); - return; - } - distributionNetworkVo.setOnlineRate(String.valueOf(onlineRate)); - countDownLatch.countDown(); - }); - // 等待所有线程执行完成 - try { - countDownLatch.await(); - } catch (InterruptedException e) { - e.printStackTrace(); - Thread.currentThread().interrupt(); - } - exe.shutdown(); - otherStationVo.setDistributionNetworkVo(distributionNetworkVo); - } - - /** - * 获取充电站数据 - * - * @param chargeVo - */ - private void getCharge(ChargeVo chargeVo) { - try { - URL serverUrl = new URL(url); - HttpURLConnection conn = (HttpURLConnection) serverUrl.openConnection(); - conn.setRequestMethod("GET"); - conn.setRequestProperty("Content-type", "application/json"); - //必须设置false,否则会自动redirect到重定向后的地址 - conn.setInstanceFollowRedirects(false); - conn.connect(); - String result = getResponse(conn); - if (StringUtil.isBlank(result)) { - return; - } - JSONObject jsonObject = JSONObject.parseObject(result); - JSONObject data = JSONObject.parseObject(jsonObject.get("data").toString()); - chargeVo.setOrder(data.get("ordersCount").toString()); - chargeVo.setChargeDegrees(data.get("todayDegree").toString()); - chargeVo.setIncome(data.get("income").toString()); - chargeVo.setTotalChargeDegrees(data.get("kilowatt").toString()); - chargeVo.setCount(Integer.valueOf(data.get("stationNum").toString())); - redisTemplate.opsForValue().set(CHARGE_SUM,chargeVo); - } catch (Exception ex) { - chargeVo.setOrder("0"); - chargeVo.setChargeDegrees("0"); - chargeVo.setIncome("0"); - chargeVo.setTotalChargeDegrees("0"); - } - } - - /*** - * 获取返回的内容 - * @param connection - * @return - */ - private String getResponse(HttpURLConnection connection) { - StringBuilder stringBuilder = new StringBuilder(); - //将返回的输入流转换成字符串 - try ( - InputStream inputStream = connection.getInputStream(); - InputStreamReader inputStreamReader = new InputStreamReader(inputStream, StandardCharsets.UTF_8); - BufferedReader bufferedReader = new BufferedReader(inputStreamReader); - ) { - String str = null; - while ((str = bufferedReader.readLine()) != null) { - stringBuilder.append(str); - } - } catch (IOException e) { - return null; - } - return stringBuilder.toString(); - } - - /** - * 计划发电量趋势 - * - * @return - */ - @Override - public R>> planGenerationTrend(Long deptId, Integer stationType, Integer serveType) { - //根据站点类型及服务类型查询站点数据 - List stationByType = stationService.getStationIdByServeType(stationType, serveType); - if (null == deptId) { - return R.data(this.paramIsNull(stationByType)); - } - return R.data(this.paramIsNotNull(deptId, stationByType)); - } - - /** - * 区域发电占比 - * - * @param deptId - * @return - */ - @Override - public R>> areaGenerationMakeUp(Long deptId, Integer stationType, Integer serveType) { - //根据站点类型及服务类型查询站点数据 - List stationByType = stationService.getStationIdByServeType(stationType, serveType); - if (null == deptId) { - return R.data(this.areaGenerationMakeUpParamIsNull(stationByType)); - } - return R.data(this.stationGenerationMakeUpParamIsNtoNull(deptId, stationByType)); - } - - /** - * 计划发电量趋势 - * - * @return - */ - public List planGenerationTrendByDepts(List stationIds) { - - List planGenerationTrendVoList = new ArrayList<>(); - - //获取年度实际发电量及计划发电量 - Map> yearGenerationMap = new HashMap<>(); - Object yearGenerationDataObject = redisTemplate.opsForValue().get(yearGenerationData); - if (ObjectUtil.isNotEmpty(yearGenerationDataObject)) { - yearGenerationMap = JSONObject.parseObject(yearGenerationDataObject.toString(), new TypeReference>>() {{ - }}); - } - List yearGenerationList = new ArrayList<>(); - for (String stationId : stationIds) { - List yearGenerationVoList = yearGenerationMap.get(stationId); - if (CollectionUtil.isNotEmpty(yearGenerationVoList)) { - yearGenerationList.addAll(yearGenerationVoList); - } - } - //根据年月进行分组 - Map> map = yearGenerationList.stream().collect(Collectors.groupingBy(YearGenerationVo::getYearMonth)); - //获取当天年的所有月份 - List yearMonths = DateUtils.getYearMonths(DateUtil.format(new Date(), "yyyy")); - - yearMonths.forEach(iter -> { - PlanGenerationTrendVo vo = new PlanGenerationTrendVo(); - List yearGenerationVoList = map.get(iter); - vo.setYearMonth(iter); - if (CollectionUtil.isNotEmpty(yearGenerationVoList)) { - //计划发电量 - double planGenerationCount = yearGenerationVoList.stream().filter(s -> s.getPlannedGeneration() != null).mapToDouble(YearGenerationVo::getPlannedGeneration).sum(); - //实际发电量 - double practicalGenerationCount = yearGenerationVoList.stream().mapToDouble(YearGenerationVo::getPracticalGeneration).sum(); - if (planGenerationCount > 0) { - vo.setPlannedGeneration(Double.valueOf(String.format("%.2f", planGenerationCount))); - } - if (practicalGenerationCount > 0) { - vo.setPracticalGeneration(Double.valueOf(String.format("%.2f", practicalGenerationCount))); - } - } - planGenerationTrendVoList.add(vo); - }); - - return planGenerationTrendVoList; - } - - - /** - * 区域发电占比 - * - * @return - */ - public List areaGenerationMakeUpByDepts(List deptList, Map> finalYearGenerationMap, - List userDeptList, List stationByType) { - - List areaGenerationMakeUpVos = new ArrayList<>(); - deptList.forEach(iter -> { - List list = userDeptList.stream().filter(s -> "4".equals(s.getDeptCategory().toString()) && s.getParentId().toString().equals(iter.getId().toString())).collect(Collectors.toList()); - List deptList1 = new ArrayList<>(); - list.forEach(f -> { - if (stationByType.contains(f.getStationId())) { - deptList1.add(f); - } - }); - - if (deptList1.size() > 0) { - AreaGenerationMakeUpVo vo = getAreaGenerationMake(deptList1, finalYearGenerationMap); - vo.setName(iter.getDeptName()); - vo.setDeptId(iter.getId()); - areaGenerationMakeUpVos.add(vo); - } - - }); - if (areaGenerationMakeUpVos.size() < 1) { - return null; - } - //统计总发电量 - double sum = areaGenerationMakeUpVos.stream().mapToDouble(AreaGenerationMakeUpVo::getGeneration).sum(); - if (sum > 0) { - areaGenerationMakeUpVos.forEach(iter -> { - double makeUp = iter.getGeneration() / sum * 100; - if (makeUp > 0) { - iter.setMakeUp(Double.valueOf(String.format("%.2f", makeUp))); - } - }); - } - return areaGenerationMakeUpVos; - } - - private AreaGenerationMakeUpVo getAreaGenerationMake(List deptList, Map> finalYearGenerationMap) { - AreaGenerationMakeUpVo vo = new AreaGenerationMakeUpVo(); - - deptList.forEach(iter -> { - List yearGenerationVoList = finalYearGenerationMap.get(iter.getStationId()); - if (CollectionUtil.isNotEmpty(yearGenerationVoList)) { - double sum = yearGenerationVoList.stream().mapToDouble(YearGenerationVo::getPracticalGeneration).sum(); - double countSum = vo.getGeneration() + sum; - if (countSum > 0) { - vo.setGeneration(Double.valueOf(String.format("%.2f", countSum))); - } - } - }); - return vo; - } - - - /** - * 站点发电占比 - * - * @return - */ - public List stationGenerationMakeUpByDepts(List deptList) { - - List areaGenerationMakeUpVos = new ArrayList<>(); - - //获取年度实际发电量及计划发电量 - Map> yearGenerationMap = new HashMap<>(); - Object yearGenerationDataObject = redisTemplate.opsForValue().get(yearGenerationData); - if (ObjectUtil.isNotEmpty(yearGenerationDataObject)) { - yearGenerationMap = JSONObject.parseObject(yearGenerationDataObject.toString(), new TypeReference>>() {{ - }}); - } - - - Map> finalYearGenerationMap = yearGenerationMap; - deptList.forEach(iter -> { - AreaGenerationMakeUpVo vo = new AreaGenerationMakeUpVo(); - List yearGenerationVoList = finalYearGenerationMap.get(iter.getStationId()); - vo.setName(iter.getDeptName()); - vo.setDeptId(iter.getId()); - if (CollectionUtil.isNotEmpty(yearGenerationVoList)) { - //实际发电量 - double practicalGenerationCount = yearGenerationVoList.stream().mapToDouble(YearGenerationVo::getPracticalGeneration).sum(); - if (practicalGenerationCount > 0) { - vo.setGeneration(Double.valueOf(String.format("%.2f", practicalGenerationCount))); - } - } - areaGenerationMakeUpVos.add(vo); - }); - - - //统计总发电量 - double sum = areaGenerationMakeUpVos.stream().mapToDouble(AreaGenerationMakeUpVo::getGeneration).sum(); - if (sum > 0) { - areaGenerationMakeUpVos.forEach(iter -> { - double stationSum = iter.getGeneration() / sum * 100; - if (stationSum > 0) { - iter.setMakeUp(Double.valueOf(String.format("%.2f", stationSum))); - } - }); - } - return areaGenerationMakeUpVos; - } - - private Map> paramIsNull(List stationByType) { - //根据用户权限获取机构数据 - R> deptByCurrentUser = sysClient.getDeptByCurrentUser(); - Map> map = new HashMap<>(); - Optional min = deptByCurrentUser.getData().stream().min(Comparator.comparing(Dept::getDeptCategory)); - if(min.isPresent() && ObjectUtil.isNotEmpty(min.get())) { - Dept dept = min.get(); - switch (dept.getDeptCategory()) { - case 1: //集团 - List stationIdList = deptByCurrentUser.getData().stream().filter(s -> "4".equals(s.getDeptCategory().toString())).map(Dept::getStationId).collect(Collectors.toList()); - List stationList = new ArrayList<>(); - stationIdList.forEach(iter -> { - if (stationByType.contains(iter)) { - stationList.add(iter); - } - }); - if (stationList.size() > 0) { - map.put(dept.getId(), planGenerationTrendByDepts(stationList)); - } - break; - case 2: //省子公司 - List szgsStationIdList = deptByCurrentUser.getData().stream().filter(s -> s.getParentId().toString().equals(dept.getId().toString()) && "4".equals(s.getDeptCategory().toString())).map(Dept::getStationId).collect(Collectors.toList()); - List szgsStationList = new ArrayList<>(); - szgsStationIdList.forEach(iter -> { - if (stationByType.contains(iter)) { - szgsStationList.add(iter); - } - }); - if (szgsStationList.size() > 0) { - map.put(dept.getId(), planGenerationTrendByDepts(szgsStationList)); - } - break; - case 3: //区域 - List aeraDeptList = deptByCurrentUser.getData().stream().filter(s -> "3".equals(s.getDeptCategory().toString())).collect(Collectors.toList()); - aeraDeptList.forEach(iter -> { - List areaStationIdList = deptByCurrentUser.getData().stream().filter(s -> s.getParentId().toString().equals(iter.getId().toString()) && "4".equals(s.getDeptCategory().toString())).map(Dept::getStationId).collect(Collectors.toList()); - List areaStationList = new ArrayList<>(); - areaStationIdList.forEach(f -> { - if (stationByType.contains(f)) { - areaStationList.add(f); - } - }); - if (areaStationList.size() > 0) { - map.put(iter.getId(), planGenerationTrendByDepts(areaStationList)); - } - }); - break; - case 4: //站点 - break; - } - } - return map; - } - - - /** - * 参数不为空 - * - * @param deptId 机构ID - * @return - */ - private Map> paramIsNotNull(Long deptId, List stationByType) { - Map> map = new HashMap<>(); - //根据用户权限获取机构数据 - R> deptByCurrentUser = sysClient.getDeptByCurrentUser(); - - - List areaStationIdList = deptByCurrentUser.getData().stream().filter(s -> "4".equals(s.getDeptCategory().toString()) && - s.getParentId().toString().equals(deptId.toString())).map(Dept::getStationId).collect(Collectors.toList()); - if (CollectionUtil.isEmpty(stationByType)) { - map.put(deptId, planGenerationTrendByDepts(areaStationIdList)); - return map; - } - List stationList = new ArrayList<>(); - - areaStationIdList.forEach(iter -> { - if (stationByType.contains(iter)) { - stationList.add(iter); - } - }); - if (stationList.size() > 0) { - map.put(deptId, planGenerationTrendByDepts(stationList)); - } - return map; - } - - - /** - * 区域发电占比 - * 参数为空 - * - * @return - */ - private Map> areaGenerationMakeUpParamIsNull(List stationByType) { - //根据用户权限获取机构数据 - R> deptByCurrentUser = sysClient.getDeptByCurrentUser(); - Map> map = new HashMap<>(); - Optional min = deptByCurrentUser.getData().stream().min(Comparator.comparing(Dept::getDeptCategory)); - if(!min.isPresent() || ObjectUtil.isEmpty(min.get())) { - return map; - } - Dept dept = min.get(); - - //获取年度实际发电量及计划发电量 - Map> yearGenerationMap = new HashMap<>(); - Object yearGenerationDataObject = redisTemplate.opsForValue().get(yearGenerationData); - if (ObjectUtil.isNotEmpty(yearGenerationDataObject)) { - yearGenerationMap = JSONObject.parseObject(yearGenerationDataObject.toString(), new TypeReference>>() {{ - }}); - } - Map> finalYearGenerationMap = yearGenerationMap; - switch (dept.getDeptCategory()) { - case 1: //集团 - List jtDeptList = deptByCurrentUser.getData().stream().filter(s -> "3".equals(s.getDeptCategory().toString())).collect(Collectors.toList()); - List list = areaGenerationMakeUpByDepts(jtDeptList, finalYearGenerationMap, deptByCurrentUser.getData(), stationByType); - if (CollectionUtil.isNotEmpty(list)) { - List collect = list.stream().sorted(Comparator.comparing(AreaGenerationMakeUpVo::getGeneration).reversed()).collect(Collectors.toList()); - map.put(dept.getId(), collect); - } - break; - case 2: //省子公司 - List deptList = deptByCurrentUser.getData().stream().filter(s -> s.getId().toString().contains(dept.getId().toString()) && "3".equals(s.getDeptCategory().toString())).collect(Collectors.toList()); - List list1 = areaGenerationMakeUpByDepts(deptList, finalYearGenerationMap, deptByCurrentUser.getData(), stationByType); - if (CollectionUtil.isNotEmpty(list1)) { - List collect1 = list1.stream().sorted(Comparator.comparing(AreaGenerationMakeUpVo::getGeneration).reversed()).collect(Collectors.toList()); - map.put(dept.getId(), collect1); - } - break; - case 3: //区域 - List aeraDeptList = deptByCurrentUser.getData().stream().filter(s -> "3".equals(s.getDeptCategory().toString())).collect(Collectors.toList()); - aeraDeptList.forEach(iter -> { - List stationDeptList = deptByCurrentUser.getData().stream().filter(s -> s.getParentId().toString().equals(iter.getId().toString()) && "4".equals(s.getDeptCategory().toString())).collect(Collectors.toList()); - List depts = new ArrayList<>(); - stationDeptList.forEach(f -> { - if (stationByType.contains(f.getStationId())) { - depts.add(f); - } - }); - List list2 = stationGenerationMakeUpByDepts(depts); - if (CollectionUtil.isNotEmpty(list2)) { - List collect2 = list2.stream().sorted(Comparator.comparing(AreaGenerationMakeUpVo::getGeneration).reversed()).collect(Collectors.toList()); - map.put(iter.getId(), collect2); - } - }); - break; - case 4: //站点 - break; - } - - return map; - } - - - /** - * 站点发电占比 - * 参数不为空 - * - * @param deptId 机构ID - * @return - */ - private Map> stationGenerationMakeUpParamIsNtoNull(Long deptId, List stationByType) { - Map> map = new HashMap<>(); - //根据用户权限获取机构数据 - R> deptByCurrentUser = sysClient.getDeptByCurrentUser(); - List deptList = deptByCurrentUser.getData().stream().filter(s -> "4".equals(s.getDeptCategory().toString()) && - s.getParentId().toString().equals(deptId.toString())).collect(Collectors.toList()); - - List depts = new ArrayList<>(); - deptList.forEach(iter -> { - if (stationByType.contains(iter.getStationId())) { - depts.add(iter); - } - }); - if (depts.size() < 1) { - return map; - } - List list = stationGenerationMakeUpByDepts(depts); - if (CollectionUtil.isNotEmpty(list)) { - List collect = list.stream().sorted(Comparator.comparing(AreaGenerationMakeUpVo::getGeneration).reversed()).collect(Collectors.toList()); - map.put(deptId, collect); - } - return map; - } - - - /** - * 获取前后年份时间 - * - * @param year - * @return - */ - public static String getYearTime(int year) { - SimpleDateFormat sdf = new SimpleDateFormat(DateUtil.PATTERN_DATE); - Calendar cal = Calendar.getInstance(); - cal.setTime(new Date()); - cal.add(Calendar.YEAR, year); - cal.add(Calendar.MONTH, -cal.get(Calendar.MONTH)); - cal.add(Calendar.DATE, -cal.get(Calendar.DATE) + 1); - return sdf.format(cal.getTime()); - } - - /** - * 获取当前时间 - * - * @return - */ - public static String getCurrentTime() { - SimpleDateFormat sdf = new SimpleDateFormat(DateUtil.PATTERN_DATE); - Calendar cal = Calendar.getInstance(); - cal.setTime(new Date()); - return sdf.format(cal.getTime()); - } - - /** - * 获取前后天数时间 - * - * @return - */ - public static String getAddDayTime(int day) { - SimpleDateFormat sdf = new SimpleDateFormat(DateUtil.PATTERN_DATE); - Calendar cal = Calendar.getInstance(); - cal.setTime(new Date()); - cal.add(Calendar.DATE, day); - return sdf.format(cal.getTime()); - } - - - /** - * 获取近年月份集合 - * @param year - * @return - */ - @Override - public List getMonthList(int year, int endMoth, boolean nextMon) { - SimpleDateFormat sdf = new SimpleDateFormat(DateUtil.PATTERN_DATE); - 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(sdf.format(startCal.getTime())); - startCal.add(Calendar.MONTH, 1); - } - if(nextMon){ - list.add(sdf.format(endCal.getTime())); - } - return list; - } - - /** - * 时间比较 - * - * @param date - * @return - */ - @Override - public boolean compareDate(String date) { - SimpleDateFormat sdf = new SimpleDateFormat(DateUtil.PATTERN_DATE); - if (StringUtil.isBlank(date)) { - return false; - } - try { - Date strDate = sdf.parse(date); - if (strDate.compareTo(new Date()) > 0) { - return true; - } - ; - } catch (ParseException ignored) { - return false; - } - return false; - } - - /** - * 水电站统计数据 - * - * @return - */ - @Override - public List getHydropowerData(Long deptId) { - List hydropowerScoreVoList = new ArrayList<>(); - // 站点数据(水电站、风电站、光伏站) - KeyIndicatorsVo keyIndicatorsVo = (KeyIndicatorsVo) redisTemplate.opsForValue().get(KEY_INDICATORS_INFO); - // 水电站 - List powerStationTotalVoList = keyIndicatorsVo.getPowerStationTotalVoList(); - // 站点近年发电数据 - Map> powerMap = (Map>) redisTemplate.opsForValue().get(RECENT_YEAR_POWER_DATA); - // 站点有功功率 - Map activePowerMap = (Map) redisTemplate.opsForValue().get(activePowerKey); - // 部门信息 - Map> deptMap = getDepartMap(deptId); - if (MapUtils.isEmpty(deptMap)) { - return null; - } - deptMap.forEach((key, value) -> { - OldHydropowerScoreVo hydropowerScoreVo = new OldHydropowerScoreVo(); - hydropowerScoreVo.setDepartId(key); - // 站点查询 - List stationList = stationService.getStationType(HomePageConstant.HYDROPOWER_SERVETYPE, Collections.singletonList(HomePageConstant.HYDROPOWER), value,true); - if (CollectionUtil.isEmpty(stationList)) { - return; - } - // 站点Id集合 - List stationIdList = stationList.stream().map(StationEntity::getId).collect(Collectors.toList()); - List stationCodeList = stationList.stream().map(StationEntity::getCode).collect(Collectors.toList()); - // 站点数量 - hydropowerScoreVo.setStationCount(stationList.size()); - // 站点总装机容量、年总发电量、月总发电量、今日总发电量 - stationSumData(stationIdList, powerStationTotalVoList, hydropowerScoreVo); - // 近3年发电量 - recentYearPower(stationIdList, powerMap, hydropowerScoreVo); - // 年计划发电量/实际发电量 - planActualPower(stationCodeList, hydropowerScoreVo); - // 有功功率,容量利用率 - activePower(stationList, activePowerMap, hydropowerScoreVo); - - hydropowerScoreVoList.add(hydropowerScoreVo); - }); - return hydropowerScoreVoList; - } - - - /** - * 统计 - * - * @param deptId - * @return - */ - @Override - public R>> getCount(Long deptId, Integer stationType, Integer serveType) { - - //根据站点类型及服务类型查询站点数据 - List stationByType = stationService.getStationIdByServeType(stationType, serveType); - - //开关机 - Map jointRelayMap = (Map) redisTemplate.opsForValue().get(jointRelayKey); - //有功功率 - Map activePowerMap = (Map) redisTemplate.opsForValue().get(activePowerKey); - //装机容量 - Map installedCapacityMap = this.getInstalledCapacityMap(); - //根据用户权限获取机构 - R> deptByCurrentUser = sysClient.getDeptByCurrentUser(); - - //获取年度实际发电量及计划发电量 - Map> yearGenerationMap = new HashMap<>(); - Object yearGenerationDataObject = redisTemplate.opsForValue().get(yearGenerationData); - if (ObjectUtil.isNotEmpty(yearGenerationDataObject)) { - yearGenerationMap = JSONObject.parseObject(yearGenerationDataObject.toString(), new TypeReference>>() {{ - }}); - } - Map> finalYearGenerationMap = yearGenerationMap; - - if (null == deptId) { - return R.data(this.areaCountParamIsNull(deptByCurrentUser.getData(), jointRelayMap, activePowerMap, installedCapacityMap, finalYearGenerationMap, stationByType)); - } - List deptList = deptByCurrentUser.getData().stream().filter(s -> s.getParentId().toString().equals(deptId.toString()) && "4".equals(s.getDeptCategory().toString())).collect(Collectors.toList()); - Map> map = new HashMap<>(); - Map> stationMap = getStationMap(true); - List list = this.areaCountParamIsNotNull(stationMap, jointRelayMap, activePowerMap, deptList, installedCapacityMap, finalYearGenerationMap, stationByType); - if (CollectionUtil.isNotEmpty(list)) { - map.put(deptId, list); - } - return R.data(map); - } - - private Map> areaCountParamIsNull(List userDeptList, Map jointRelayMap, Map activePowerMap, Map installedCapacityMap, - Map> finalYearGenerationMap, List stationByType) { - Map> map = new HashMap<>(); - //根据机构类型获取最小机构 - Optional min = userDeptList.stream().min(Comparator.comparing(Dept::getDeptCategory)); - Dept dept = min.isPresent() ? min.get() : null; - if (ObjectUtil.isEmpty(dept)) { - return map; - } - switch (dept.getDeptCategory()) { - case 1: //集团 - case 2: //省子公司 - map.put(dept.getId(), getHomePageCountVoList(userDeptList, jointRelayMap, activePowerMap, installedCapacityMap, finalYearGenerationMap, stationByType)); - break; - case 3: //区域 - List areaDeptList = userDeptList.stream().filter(s -> s.getDeptCategory().toString().equals(dept.getDeptCategory().toString())).collect(Collectors.toList()); - - Map> stationMap = getStationMap(true); - - areaDeptList.forEach(iter -> { - List deptList = userDeptList.stream().filter(s -> s.getParentId().toString().equals(iter.getId().toString()) && "4".equals(s.getDeptCategory().toString())).collect(Collectors.toList()); - List list = this.areaCountParamIsNotNull(stationMap, jointRelayMap, activePowerMap, deptList, installedCapacityMap, finalYearGenerationMap, stationByType); - if (CollectionUtil.isNotEmpty(list)) { - map.put(iter.getId(), list); - } - }); - break; - case 4: //站点 - break; - } - return map; - } - - private List getHomePageCountVoList(List userDeptList, Map jointRelayMap, Map activePowerMap, Map installedCapacityMap, - Map> finalYearGenerationMap, List stationByType) { - List list = new ArrayList<>(); - - Map> stationMap = getStationMap(false); - List jtDeptList = userDeptList.stream().filter(s -> "3".equals(s.getDeptCategory().toString())).collect(Collectors.toList()); - jtDeptList.forEach(iter -> { - HomePageCountVo homePageCountVo = getHomePageCountVo(iter, userDeptList, jointRelayMap, activePowerMap, installedCapacityMap, finalYearGenerationMap, stationByType); - if (null != homePageCountVo) { - List stationEntityList = stationMap.get(iter.getId()); - if (CollectionUtil.isNotEmpty(stationEntityList)) { - homePageCountVo.setLgtd(stationEntityList.get(0).getLgtd()); - homePageCountVo.setLttd(stationEntityList.get(0).getLttd()); - if (StringUtil.isNotBlank(stationEntityList.get(0).getAreaCode())) { - homePageCountVo.setAreaCode(stationEntityList.get(0).getAreaCode()); - String[] areaCode = stationEntityList.get(0).getAreaCode().split(","); - R R = sysClient.getRegion(areaCode[1]); - if (R.isSuccess() && ObjectUtil.isNotEmpty(R.getData())) { - homePageCountVo.setAreaName(R.getData().getName()); - } - } - - } - list.add(homePageCountVo); - } - }); - if (list.size() < 1) { - return list; - } - double sum = list.stream().mapToDouble(HomePageCountVo::getGenerationCount).sum(); - if (sum > 0) { - list.forEach(iter -> { - double areaMakeUp = iter.getGenerationCount() / sum * 100; - iter.setAreaMakeUp(Double.valueOf(String.format("%.2f", areaMakeUp))); - }); - } - return list; - } - - private Map> getStationMap(Boolean isType) { - List stationList = stationService.getStationByServerTypeAndIsType(2, isType); - return stationList.stream().collect(Collectors.groupingBy(StationEntity::getRefDept)); - } - - - private HomePageCountVo getHomePageCountVo(Dept dept, List userDeptList, Map jointRelayMap, Map activePowerMap, Map installedCapacityMap, - Map> finalYearGenerationMap, List stationByType) { - HomePageCountVo vo = new HomePageCountVo(); - - List collect = userDeptList.stream().filter(s -> s.getParentId().toString().equals(dept.getId().toString()) && "4".equals(s.getDeptCategory().toString())).collect(Collectors.toList()); - - vo.setDeptId(dept.getId()); - vo.setStationName(dept.getDeptName()); - - if (CollectionUtil.isEmpty(collect)) { - return null; - } - List sdzDeptList = new ArrayList<>(); - collect.forEach(iter -> { - if (stationByType.contains(iter.getStationId())) { - sdzDeptList.add(iter); - } - }); - if (sdzDeptList.size() < 1) { - return null; - } - - //总开机数量 - double startingUp = 0; - //总数量 - double unitStartingUpSum = 0; - //装机容量 - double installedCapacity = 0; - //有功功率 - double activePower = 0; - //实际发电量 - double practicalGeneration = 0; - //计划发电量 - double planGenerationSum = 0; - - for (Dept iter : sdzDeptList) { - JointRelayVo jointRelayVo = jointRelayMap.get(iter.getStationId()); - if (null != jointRelayVo) { - startingUp += jointRelayVo.getStartingUpCount(); - unitStartingUpSum += jointRelayVo.getUnitSum(); - } - Double activePowerCount = activePowerMap.get(iter.getStationId()); - if (null != activePowerCount) { - activePower += activePowerCount; - } - Double installedCapacityCount = installedCapacityMap.get(iter.getId()); - if (null != installedCapacityCount) { - installedCapacity += installedCapacityCount; - } - List yearGenerationVoList = finalYearGenerationMap.get(iter.getStationId()); - if (CollectionUtil.isNotEmpty(yearGenerationVoList)) { - //计划发电量 - double planGenerationCount = yearGenerationVoList.stream().filter(s -> s.getPlannedGeneration() != null).mapToDouble(YearGenerationVo::getPlannedGeneration).sum(); - //实际发电量 - double practicalGenerationCount = yearGenerationVoList.stream().mapToDouble(YearGenerationVo::getPracticalGeneration).sum(); - - planGenerationSum += planGenerationCount; - practicalGeneration += practicalGenerationCount; - } - } - double capacityUse = activePower / installedCapacity * 100; - if (capacityUse > 0) { - vo.setCapacityUse(Double.valueOf(String.format("%.2f", capacityUse))); - } - if (startingUp > 0) { - double stationUse = startingUp / unitStartingUpSum * 100; - vo.setStationUse(Double.valueOf(String.format("%.2f", stationUse))); - } - if (practicalGeneration > 0 && planGenerationSum > 0) { - double generationPercentageComplete = practicalGeneration / planGenerationSum * 100; - vo.setGenerationPercentageComplete(Double.valueOf(String.format("%.2f", generationPercentageComplete))); - } - vo.setGenerationCount(practicalGeneration); - return vo; - - } - - /** - * 获取站点级 的发电完成率、区域/集团发电占比、电站利用率、容量利用率 - * - * @param jointRelayMap 开关机Map key:站点ID value:JointRelayVo 对象 - * @param activePowerMap 有功功率Map key:站点ID value: 一个站点总实时有功功率和 - * @param deptList 站点级机构List - * @param installedCapacityMap 装机容量 key:站点ID - * @param finalYearGenerationMap 年发电量 - * @return - */ - private List areaCountParamIsNotNull(Map> stationMap, Map jointRelayMap, Map activePowerMap, - List deptList, Map installedCapacityMap, - Map> finalYearGenerationMap, List stationByType) { - - List list = new ArrayList<>(); - - - List sdzDeptList = new ArrayList<>(); - deptList.forEach(iter -> { - if (stationByType.contains(iter.getStationId())) { - sdzDeptList.add(iter); - } - }); - if (CollectionUtil.isEmpty(sdzDeptList)) { - return null; - } - - sdzDeptList.forEach(iter -> { - HomePageCountVo vo = new HomePageCountVo(); - List yearGenerationVoList = finalYearGenerationMap.get(iter.getStationId()); - - List stationEntityList = stationMap.get(iter.getId()); - if (CollectionUtil.isNotEmpty(stationEntityList)) { - vo.setLgtd(stationEntityList.get(0).getLgtd()); - vo.setLttd(stationEntityList.get(0).getLttd()); - if (StringUtil.isNotBlank(stationEntityList.get(0).getAreaCode())) { - vo.setAreaCode(stationEntityList.get(0).getAreaCode()); - String[] areaCode = stationEntityList.get(0).getAreaCode().split(","); - R R = sysClient.getRegion(areaCode[1]); - if (R.isSuccess() && ObjectUtil.isNotEmpty(R.getData())) { - vo.setAreaName(R.getData().getName()); - } - } - } - vo.setDeptId(iter.getId()); - vo.setStationName(iter.getDeptName()); - if (CollectionUtil.isNotEmpty(yearGenerationVoList)) { - //计划发电量 - double planGenerationCount = yearGenerationVoList.stream().filter(s -> s.getPlannedGeneration() != null).mapToDouble(YearGenerationVo::getPlannedGeneration).sum(); - //实际发电量 - double practicalGenerationCount = yearGenerationVoList.stream().mapToDouble(YearGenerationVo::getPracticalGeneration).sum(); - - //发电完成率 - if (planGenerationCount > 0 && practicalGenerationCount > 0) { - double generationPercentageComplete = practicalGenerationCount / planGenerationCount * 100; - vo.setGenerationPercentageComplete(Double.valueOf(String.format("%.2f", generationPercentageComplete))); - } - //发电量统计 - vo.setGenerationCount(practicalGenerationCount); - } - JointRelayVo jointRelayVo = jointRelayMap.get(iter.getStationId()); - if (null != jointRelayVo && 0 != jointRelayVo.getStartingUpCount()) { - //电站利用率 - double startingUpCount = jointRelayVo.getStartingUpCount(); - double unitSum = jointRelayVo.getUnitSum(); - double stationUse = startingUpCount / unitSum * 100; - - vo.setStationUse(Double.valueOf(String.format("%.2f", stationUse))); - } - Double activePower = activePowerMap.get(iter.getStationId()); - Double installedCapacity = installedCapacityMap.get(iter.getId()); - if (null != activePower && null != installedCapacity) { - //容量利用率 - double capacityUse = activePower / installedCapacity * 100; - if (capacityUse > 0) { - vo.setCapacityUse(Double.valueOf(String.format("%.2f", capacityUse))); - } - } - list.add(vo); - }); - //总发电量 - double sum = list.stream().mapToDouble(HomePageCountVo::getGenerationCount).sum(); - if (sum > 0) { - list.forEach(iter -> { - double areaMakeUp = iter.getGenerationCount() / sum * 100; - iter.setAreaMakeUp(Double.valueOf(String.format("%.2f", areaMakeUp))); - - }); - } - return list; - } - - /** - * 获取装机容量 - * - * @return - */ - private Map getInstalledCapacityMap() { - List emInfoList = maintenanceTaskService.getEmInfoList(); - R> listAnalyseCode = analyseInstanceClient.getListAnalyseCode(emInfoList.stream().map(EmInfoExtendVo::getEmCode).collect(Collectors.toList())); - if (!listAnalyseCode.isSuccess() || CollectionUtil.isEmpty(listAnalyseCode.getData())) { - return null; - } - List emInfoEntityList = emInfoList.stream().filter(o -> listAnalyseCode.getData().stream().collect(Collectors.toList()).contains(o.getEmCode())).collect(Collectors.toList()); - - Map> map = emInfoEntityList.stream().collect(Collectors.groupingBy(EminfoAndEmParamVo::getCreateDept)); - Map doubleMap = new HashMap<>(); - map.forEach((key, value) -> { - doubleMap.put(key, value.stream().filter(s -> s.getInstalledCapacity() != null).mapToDouble(EminfoAndEmParamVo::getInstalledCapacity).sum()); - }); - return doubleMap; - } - - - /** - * 站点年总发电量 - * - * @param stationIdList - * @param powerStationTotalVoList - * @return - */ - private void stationSumData(List stationIdList, List powerStationTotalVoList, OldHydropowerScoreVo hydropowerScoreVo) { - if (CollectionUtil.isEmpty(powerStationTotalVoList)) { - hydropowerScoreVo.setInstalledCapacityMonth(0.0); - return; - } - // 总装机容量 - Double installedCapacityMonth = powerStationTotalVoList.stream().filter(o -> stationIdList.contains(o.getStationId())).mapToDouble(PowerStationTotalVo::getInstalledCapacity).sum(); - hydropowerScoreVo.setInstalledCapacityMonth(installedCapacityMonth); - hydropowerScoreVo.setInstalledCapacityYear(installedCapacityMonth); - - // 年总发电量 - double powerYear = powerStationTotalVoList.stream().filter(o -> stationIdList.contains(o.getStationId())).mapToDouble(PowerStationTotalVo::getCurrentYearPowerGeneration).sum(); - hydropowerScoreVo.setPowerYear(String.valueOf(new BigDecimal(powerYear).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue())); - - // 月总发电量 - double powerMon = powerStationTotalVoList.stream().filter(o -> stationIdList.contains(o.getStationId())).mapToDouble(PowerStationTotalVo::getPowerGeneration).sum(); - hydropowerScoreVo.setPowerMonth(String.valueOf(new BigDecimal(powerMon).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue())); - - // 日总发电量 - double powerDay = powerStationTotalVoList.stream().filter(o -> stationIdList.contains(o.getStationId())).mapToDouble(PowerStationTotalVo::getCurrentDayPowerGeneration).sum(); - hydropowerScoreVo.setPowerDay(String.valueOf(new BigDecimal(powerDay).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue())); - } - - /** - * 近3年发电量 - * - * @param stationIdList - * @param powerMap - * @param hydropowerScoreVo - */ - private void recentYearPower(List stationIdList, Map> powerMap, OldHydropowerScoreVo hydropowerScoreVo) { - List> valueList = powerMap.entrySet().stream().filter(e -> stationIdList.contains(e.getKey())).map(Map.Entry::getValue).collect(Collectors.toList()); - if (CollectionUtil.isEmpty(valueList) || MapUtils.isEmpty(powerMap)) { - return; - } - // 根据月份分组 - Map> monthMap = getMonthMap(valueList); - if (MapUtils.isEmpty(monthMap)) { - return; - } - // 总和所有相同月份的发电量 - List powerMonthVoList = new ArrayList<>(); - monthMap.forEach((key, value) -> { - PowerMonthVo powerMonthVo = new PowerMonthVo(); - powerMonthVo.setStrMonth(key); - LocalDate localDate = LocalDate.parse(DateUtil.format(new Date(), key), DateTimeFormatter.ofPattern(DateUtil.PATTERN_DATE)); - powerMonthVo.setYear(localDate.getYear()); - powerMonthVo.setMonth(localDate.getMonthValue()); - float power = (float) value.stream().mapToDouble(PowerMonthVo::getPower).sum(); - powerMonthVo.setPower(power); - powerMonthVoList.add(powerMonthVo); - }); - if (CollectionUtil.isEmpty(powerMonthVoList)) { - return; - } - // 根据年份分组 - Map> yearMap = powerMonthVoList.stream().collect(Collectors.groupingBy(PowerMonthVo::getYear)); - // 遍历为返回结构 - List powerYearVoList = new ArrayList<>(); - yearMap.forEach((key, value) -> { - PowerYearVo powerYearVo = new PowerYearVo(); - powerYearVo.setYear(key); - List sortValue = value.stream().sorted(Comparator.comparing(PowerMonthVo::getMonth)).collect(Collectors.toList()); - powerYearVo.setPowerMonthVoList(sortValue); - powerYearVoList.add(powerYearVo); - }); - hydropowerScoreVo.setPowerYearVoList(powerYearVoList); - } - - /** - * 根据月份分组 - * - * @param valueList - * @return - */ - private Map> getMonthMap(List> valueList) { - List powerMonthVos = new ArrayList<>(); - valueList.forEach(map -> { - map.forEach((key, value) -> { - PowerMonthVo powerMonthVo = new PowerMonthVo(); - powerMonthVo.setStrMonth(key); - powerMonthVo.setPower(value); - powerMonthVos.add(powerMonthVo); - }); - }); - return powerMonthVos.stream().collect(Collectors.groupingBy(PowerMonthVo::getStrMonth)); - } - - /** - * 年计划发电量/实际发电量 - * - * @param - * @param hydropowerScoreVo - */ - private void planActualPower(List stationCodeList, OldHydropowerScoreVo hydropowerScoreVo) { - if (CollectionUtil.isEmpty(stationCodeList)) { - hydropowerScoreVo.setPlanPowerYear("0"); - hydropowerScoreVo.setFinishPowerYear("0"); - return; - } - Calendar calendar = Calendar.getInstance(); - calendar.setTime(new Date()); - String year = String.valueOf(calendar.get(Calendar.YEAR)); - // 查询年计划发电情况 返回格式 : 计划发电量|完成发电量 - Double planActualPower = planGenertionClient.getPlanPowerYear(stationCodeList, year); - hydropowerScoreVo.setPlanPowerYear(String.valueOf(planActualPower)); - // 使用实时统计年发电量计算 - float finishPowerYear = Float.parseFloat(hydropowerScoreVo.getPowerYear()); - hydropowerScoreVo.setFinishPowerYear(String.valueOf(finishPowerYear)); - float planPowerYear = Float.parseFloat(String.valueOf(planActualPower)); - if (Math.abs(planPowerYear) <= 0) { - hydropowerScoreVo.setPlanCompletionRateYear("0.0"); - return; - } - double completionRate = BigDecimal.valueOf(finishPowerYear / planPowerYear * 100).setScale(1, BigDecimal.ROUND_HALF_UP).doubleValue(); - hydropowerScoreVo.setPlanCompletionRateYear(String.valueOf(completionRate)); - } - - /** - * 有功功率 - * - * @param stationList - * @param activePowerMap - * @param hydropowerScoreVo - */ - private void activePower(List stationList, Map activePowerMap, OldHydropowerScoreVo hydropowerScoreVo) { - if (MapUtils.isEmpty(activePowerMap)) { - hydropowerScoreVo.setActivePowerYear(0.0); - hydropowerScoreVo.setActivePowerMoth(0.0); - hydropowerScoreVo.setRateYear("0"); - return; - } - List stationCodeList = stationList.stream().map(StationEntity::getCode).collect(Collectors.toList()); - List doubleList = activePowerMap.entrySet().stream().filter(m -> stationCodeList.contains(m.getKey())).map(Map.Entry::getValue).collect(Collectors.toList()); - double sumPower = BigDecimal.valueOf(doubleList.stream().mapToDouble(Double::doubleValue).sum()).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue(); - hydropowerScoreVo.setActivePowerMoth(sumPower); - hydropowerScoreVo.setActivePowerYear(sumPower); - Double installedCapacity = hydropowerScoreVo.getInstalledCapacityMonth(); - if (installedCapacity.compareTo(0.0) <= 0) { - hydropowerScoreVo.setRateYear("0"); - return; - } - double rateYear = BigDecimal.valueOf(sumPower / installedCapacity * 100).setScale(1, BigDecimal.ROUND_HALF_UP).doubleValue(); - hydropowerScoreVo.setRateYear(String.valueOf(rateYear)); - } - - /** - * 把部门根据最大类型分组 - * - * @return - */ - @Override - public Map> getDepartMap(Long deptId) { - Map> departMap = new ConcurrentHashMap<>(); - //根据用户权限获取机构 - R> deptData = sysClient.getDeptByCurrentUser(); - if (ObjectUtil.isEmpty(deptData) || !deptData.isSuccess()) { - return null; - } - List departList = deptData.getData(); - if (null != deptId) { - // 根据传入机构查询 - List childDeptList = getChildDept(departList, deptId, new ArrayList<>()); - if (CollectionUtil.isEmpty(childDeptList)) { - return null; - } - departMap.put(deptId, childDeptList); - return departMap; - } - // 根据用户最大机构类型查询 - Optional min = departList.stream().min(Comparator.comparing(Dept::getDeptCategory)); - Integer deptCategory = min.isPresent() ? min.map(Dept::getDeptCategory).orElse(null) : null; - if(Func.isEmpty(deptCategory)) { - return departMap; - } - //departList.stream().min(Comparator.comparing(Dept::getDeptCategory)).get().getDeptCategory(); - List deptCategoryList = departList.stream().filter(d -> d.getDeptCategory().equals(deptCategory)).map(Dept::getId).collect(Collectors.toList()); - deptCategoryList.forEach(departId -> { - List dept = getChildDept(departList, departId, new ArrayList<>()); - departMap.put(departId, dept); - }); - return departMap; - } - - /** - * 递归取子机构 - * - * @param departList - * @param deptId - * @return - */ - @Override - public List getChildDept(List departList, Long deptId, List list) { - if (null == deptId || CollectionUtil.isEmpty(departList)) { - return null; - } - departList.forEach(dept -> { - if (dept.getParentId().equals(deptId)) { - // FIXME 是否只需要添加站点 - if (dept.getDeptCategory().equals(4)) { - list.add(dept.getId()); - } - getChildDept(departList, dept.getId(), list); - } - }); - List stationList = stationService.getStationType(HomePageConstant.HYDROPOWER_SERVETYPE, Collections.singletonList(HomePageConstant.HYDROPOWER), list,true); - if (CollectionUtil.isEmpty(stationList)) { - return null; - } - List refDeptList = stationList.stream().map(StationEntity::getRefDept).collect(Collectors.toList()); - return list.stream().filter(refDeptList::contains).collect(Collectors.toList()); - } - - /** - * 递归取子区域 - * @param departList - * @param deptId - * @param list - * @return - */ - @Override - public List getChildArea(List departList, Long deptId, List list) { - if (ObjectUtil.isEmpty(deptId) || CollectionUtil.isEmpty(departList)) { - return null; - } - departList.forEach(dept -> { - Integer type = dept.getDeptCategory(); - if(ObjectUtil.isEmpty(type) || type.equals(HomePageConstant.STATION)){ - return; - } - if(dept.getParentId().equals(deptId)){ - if (dept.getDeptCategory().equals(HomePageConstant.AREA)) { - list.add(dept); - } - getChildArea(departList, dept.getId(), list); - } - }); - return list; - } - - - /** - * 获取区域 - * - * @param depeId - * @return - */ - @Override - public R> getArea(Long depeId) { - R> deptByCurrentUser = sysClient.getDeptByCurrentUser(); - if (null != depeId) { - List collect = deptByCurrentUser.getData().stream().filter(s -> s.getId().toString().equals(depeId.toString())).collect(Collectors.toList()); - return R.data(getAreaVoList(collect)); - } - List collect = deptByCurrentUser.getData().stream().filter(s -> "3".equals(s.getDeptCategory().toString())).collect(Collectors.toList()); - return R.data(getAreaVoList(collect)); - } - - private List getAreaVoList(List listDept) { - List areaVoList = new ArrayList<>(); - List stationList = stationService.getStationByServerTypeAndIsType(2, false); - Map> stationMap = stationList.stream().collect(Collectors.groupingBy(StationEntity::getRefDept)); - listDept.forEach(iter -> { - AreaVo vo = BeanUtil.copy(iter, AreaVo.class); - List stationEntityList = stationMap.get(iter.getId()); - if (CollectionUtil.isNotEmpty(stationEntityList)) { - vo.setAreaCode(stationEntityList.get(0).getAreaCode()); - vo.setLgtd(stationEntityList.get(0).getLgtd()); - vo.setLttd(stationEntityList.get(0).getLttd()); - } - areaVoList.add(vo); - - }); - return areaVoList; - } - - /** - * 获取区域级地图 - * - * @return - */ - private List getAreaMap(List authList, Long deptId) { - // 获取区域 - List areaList = authList.stream().filter(o -> o.getId().equals(deptId) && o.getDeptCategory().equals(3)).collect(Collectors.toList()); - if (CollectionUtil.isEmpty(areaList)) { - return null; - } - List deptList = authList.stream().filter(o -> o.getParentId().equals(deptId) && o.getDeptCategory().equals(4)).map(Dept::getId).collect(Collectors.toList()); - if (CollectionUtil.isEmpty(deptList)) { - return null; - } - List stationList = stationService.getStationType(HomePageConstant.HYDROPOWER_SERVETYPE, Collections.singletonList(HomePageConstant.HYDROPOWER), deptList,true); - if (CollectionUtil.isEmpty(deptList)) { - return null; - } - // 获取站点地图标记 - List mapMarkerVos = new ArrayList<>(); - stationList.forEach(station -> { - MapMarkerVo mapMarkerVo = new MapMarkerVo(); - mapMarkerVo.setDeptId(station.getRefDept()); - mapMarkerVo.setStationName(station.getName()); - mapMarkerVo.setLgtd(station.getLgtd()); - mapMarkerVo.setLttd(station.getLttd()); - mapMarkerVo.setAreaCode(station.getAreaCode()); - mapMarkerVos.add(mapMarkerVo); - }); - return mapMarkerVos; - } -} diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/service/impl/SideHustleServiceImpl.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/service/impl/SideHustleServiceImpl.java index 487c78c..31b75b0 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/service/impl/SideHustleServiceImpl.java +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/service/impl/SideHustleServiceImpl.java @@ -31,7 +31,6 @@ import com.hnac.hzims.operational.main.vo.*; import com.hnac.hzims.operational.maintenance.constants.MaintenanceConstant; import com.hnac.hzims.operational.maintenance.entity.OperMaintenanceTaskEntity; import com.hnac.hzims.operational.maintenance.service.IOperMaintenanceTaskService; -import com.hnac.hzims.operational.main.vo.RegularWorkVO; import com.hnac.hzims.operational.report.vo.DutyDefectVO; import com.hnac.hzims.operational.station.entity.StationEntity; import com.hnac.hzims.operational.station.service.IStationService; @@ -70,8 +69,6 @@ import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.stream.Collectors; -import static org.springblade.system.user.UserConstants.UserDataScopeTypeEnum.dept; - /** * @author ysj */ @@ -83,8 +80,6 @@ public class SideHustleServiceImpl implements ISideHustleService { @NotNull private final IAnalyseDataService analyseDataService; @NotNull - private final IHomePageService homePageService; - @NotNull private final IStationService stationService; @NotNull private final UserDeptService userDeptService; @@ -851,7 +846,7 @@ public class SideHustleServiceImpl implements ISideHustleService { return null; } Map> powerMap = (Map>) redisTemplate.opsForValue().get(RECENT_YEAR_POWER_DATA); - List monList = homePageService.getMonthList(0,12,false); + List monList = this.getMonthList(0,12,false); // 获取总发电量 float sumPower = this.getSumPower(map.values(),powerMap,monList); List list = new ArrayList<>(); @@ -901,7 +896,7 @@ public class SideHustleServiceImpl implements ISideHustleService { // 设备开关机状态 Map deviceStateMap = (Map) redisTemplate.opsForValue().get(joint_relay_key); // 获取总发电量 - List monList = homePageService.getMonthList(0,12,false); + List monList = this.getMonthList(0,12,false); float sumPower = this.getSumPower(map.values(),powerMap,monList); List list = new ArrayList<>(); map.forEach((key,value)->{ @@ -1554,7 +1549,7 @@ public class SideHustleServiceImpl implements ISideHustleService { }}); } // 获取区域下站点级机构集合 - List stationDeprList = homePageService.getChildDept(depts, area.getId(), new ArrayList<>()); + List stationDeprList = this.getChildDept(depts, area.getId(), new ArrayList<>()); if (CollectionUtil.isEmpty(stationDeprList)) { return null; } @@ -1673,4 +1668,65 @@ public class SideHustleServiceImpl implements ISideHustleService { private List getStation(List singletonList, List childDeptIdList) { return stationService.getStationType(HomePageConstant.HYDROPOWER_SERVETYPE,singletonList,childDeptIdList,true); } + + /** + * 递归取子机构 + * + * @param departList + * @param deptId + * @return + */ + private List getChildDept(List departList, Long deptId, List list) { + if (null == deptId || CollectionUtil.isEmpty(departList)) { + return null; + } + departList.forEach(dept -> { + if (dept.getParentId().equals(deptId)) { + // FIXME 是否只需要添加站点 + if (dept.getDeptCategory().equals(4)) { + list.add(dept.getId()); + } + getChildDept(departList, dept.getId(), list); + } + }); + List stationList = stationService.getStationType(HomePageConstant.HYDROPOWER_SERVETYPE, Collections.singletonList(HomePageConstant.HYDROPOWER), list,true); + if (CollectionUtil.isEmpty(stationList)) { + return null; + } + List refDeptList = stationList.stream().map(StationEntity::getRefDept).collect(Collectors.toList()); + return list.stream().filter(refDeptList::contains).collect(Collectors.toList()); + } + + /** + * 获取近年月份集合 + * + * @param year + * @return + */ + private List getMonthList(int year, int endMoth, boolean nextMon) { + SimpleDateFormat sdf = new SimpleDateFormat(DateUtil.PATTERN_DATE); + 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(sdf.format(startCal.getTime())); + startCal.add(Calendar.MONTH, 1); + } + if(nextMon){ + list.add(sdf.format(endCal.getTime())); + } + return list; + } + }