diff --git a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/scheduled/RealTargetScheduledTask.java b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/scheduled/RealTargetScheduledTask.java index f71d9d3..9591c87 100644 --- a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/scheduled/RealTargetScheduledTask.java +++ b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/scheduled/RealTargetScheduledTask.java @@ -157,19 +157,6 @@ public class RealTargetScheduledTask { return new ReturnT<>("SUCCESS"); } - /** - * 获取站点近3年发电量数据 - */ - @XxlJob(LOAD_POWER_DATA_NEW) - //@Scheduled(cron = "0/40 * * * * ? ") - public ReturnT loadPowerDataNew(String param) { - if (Func.isBlank(param)) { - param = DateUtil.format(new Date(), "yyyy-MM"); - } - service.loadPowerDataNew(param, Arrays.asList(HomePageConstant.HYDROPOWER,HomePageConstant.PHOTOVOLTAIC),2,3); - return new ReturnT<>("SUCCESS"); - } - @XxlJob(WIND_POWER_GENERATION_RECENT_YEAR) //@Scheduled(cron = "0/40 * * * * ? ") diff --git a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/home/RealTargetService.java b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/home/RealTargetService.java index 7ea1a7d..485fe48 100644 --- a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/home/RealTargetService.java +++ b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/home/RealTargetService.java @@ -28,7 +28,5 @@ public interface RealTargetService { void loadPowerData(String param, List types, Integer serveType, int year); - void loadPowerDataNew(String param, List types, Integer serveType, int year); - void loadPowerDataByWindEnergy(String param, List types, Integer serveType, int year,String key); } diff --git a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/home/impl/RealTargetServiceImpl.java b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/home/impl/RealTargetServiceImpl.java index dfca1da..5536da7 100644 --- a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/home/impl/RealTargetServiceImpl.java +++ b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/home/impl/RealTargetServiceImpl.java @@ -127,7 +127,7 @@ public class RealTargetServiceImpl implements RealTargetService { private final static String load_photovoltaic_target_key = "hzims:operation:photovoltaic:target:key"; // 创建线程池 - private static final ExecutorService pool = new ThreadPoolExecutor(10, 10, 0L, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<>(1024), new ThreadFactoryBuilder().setNameFormat("load-power-data-pool-%d").build() , new ThreadPoolExecutor.CallerRunsPolicy()); + //private static final ExecutorService pool = new ThreadPoolExecutor(10, 10, 0L, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<>(1024), new ThreadFactoryBuilder().setNameFormat("load-power-data-pool-%d").build() , new ThreadPoolExecutor.CallerRunsPolicy()); @Override public void loadEmInfo(String param) { @@ -1250,9 +1250,8 @@ public class RealTargetServiceImpl implements RealTargetService { // 将站点切割 int limit = countStep(stations.size()); List> limits = Stream.iterate(0, n -> n + 1).limit(limit).parallel().map(a -> stations.stream().skip((long) a * 3).limit(3).parallel().collect(Collectors.toList())).collect(Collectors.toList()); - CountDownLatch countDownLatch = new CountDownLatch(limits.size()); for(List item : limits){ - pool.submit(()->{ + try{ item.forEach(station->{ // 站点设备集合 List stationDevices = devices.stream().filter(device -> device.getCreateDept().equals(station.getRefDept())).collect(Collectors.toList()); @@ -1260,74 +1259,16 @@ public class RealTargetServiceImpl implements RealTargetService { if(MapUtils.isEmpty(generateMap)){ return; } + log.error("pool_item_execute_complete: {}" ,JSONObject.toJSONString(generateMap)); powerMap.put(station.getId(),generateMap); }); - countDownLatch.countDown(); - log.error("pool_item_execute_complete: {}" ,item.stream().map(StationEntity::getName).collect(Collectors.toList())); - }); - - } - //所有模板数据获取完成后释放锁 - try { - countDownLatch.await(); - } catch (InterruptedException e) { - e.printStackTrace(); - Thread.currentThread().interrupt(); + }catch (Exception exception){ + log.error("pool_item_execute_complete_error: {}" ,exception.getMessage()); + } } redisTemplate.opsForValue().set(recent_year_power_data, powerMap); } - @Override - public void loadPowerDataNew(String param, List types, Integer serveType, int year) { - // 站点查询 - List stations = stationService.list(new LambdaQueryWrapper() {{ - if (CollectionUtil.isNotEmpty(types)) { - in(StationEntity::getType, types); - } - }}); - // 设备信息 - List devices = JSONObject.parseObject(redisTemplate.opsForValue().get(device_cache_cofig_final).toString(), new TypeReference>() { - }); - // 开始时间 - 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 CopyOnWriteMap<>(); - // 将站点切割 - int limit = countStep(stations.size()); - List> limits = Stream.iterate(0, n -> n + 1).limit(limit).parallel().map(a -> stations.stream().skip((long) a * 3).limit(3).parallel().collect(Collectors.toList())).collect(Collectors.toList()); - CountDownLatch countDownLatch = new CountDownLatch(limits.size()); - for(List item : limits){ - pool.submit(()->{ - item.forEach(station->{ - // 站点设备集合 - List stationDevices = devices.stream().filter(device -> device.getCreateDept().equals(station.getRefDept())).collect(Collectors.toList()); - Map generateMap = this.lastReduceFirst(station,stationDevices,start,end); - if(MapUtils.isEmpty(generateMap)){ - return; - } - powerMap.put(station.getId(),generateMap); - }); - countDownLatch.countDown(); - log.error("pool_item_execute_complete: {}" ,item.stream().map(StationEntity::getName).collect(Collectors.toList())); - }); - - } - //所有模板数据获取完成后释放锁 - try { - countDownLatch.await(); - } catch (InterruptedException e) { - e.printStackTrace(); - Thread.currentThread().interrupt(); - } - redisTemplate.opsForValue().set(recent_year_power_data_test, JSONObject.toJSONString(powerMap)); - } private Map lastReduceFirst(StationEntity station, List devices, String start, String end) { List datas = new ArrayList<>(); diff --git a/hzims-service/inspect/src/main/java/com/hnac/hzinfo/inspect/offline/service/impl/InspectOfflineServiceImpl.java b/hzims-service/inspect/src/main/java/com/hnac/hzinfo/inspect/offline/service/impl/InspectOfflineServiceImpl.java index 378ce44..959ac38 100644 --- a/hzims-service/inspect/src/main/java/com/hnac/hzinfo/inspect/offline/service/impl/InspectOfflineServiceImpl.java +++ b/hzims-service/inspect/src/main/java/com/hnac/hzinfo/inspect/offline/service/impl/InspectOfflineServiceImpl.java @@ -855,22 +855,27 @@ public class InspectOfflineServiceImpl implements IOfflineDataService { */ @Transactional(rollbackFor = Exception.class) public void updateData(BaseService service, List data) { - if (CollectionUtil.isEmpty(data)) { - return; - } - Map> dataList = data.stream().collect(Collectors.groupingBy(o -> o.getOfflineFlag() != null ? o.getOfflineFlag() : 0)); - //新增 - if (CollectionUtil.isNotEmpty(dataList.get(1))) { - service.saveBatch(dataList.get(1)); - } - //修改 - if (CollectionUtil.isNotEmpty(dataList.get(2))) { - service.updateBatchById(dataList.get(2)); - } - //删除 - if (CollectionUtil.isNotEmpty(dataList.get(3))) { - service.deleteLogic(dataList.get(3).stream().map(SyncBO::getPrimaryKey).collect(Collectors.toList())); + try{ + if (CollectionUtil.isEmpty(data)) { + return; + } + Map> dataList = data.stream().collect(Collectors.groupingBy(o -> o.getOfflineFlag() != null ? o.getOfflineFlag() : 0)); + //新增 + if (CollectionUtil.isNotEmpty(dataList.get(1))) { + service.saveBatch(dataList.get(1)); + } + //修改 + if (CollectionUtil.isNotEmpty(dataList.get(2))) { + service.updateBatchById(dataList.get(2)); + } + //删除 + if (CollectionUtil.isNotEmpty(dataList.get(3))) { + service.deleteLogic(dataList.get(3).stream().map(SyncBO::getPrimaryKey).collect(Collectors.toList())); + } + }catch (Exception exception){ + log.error("offline_update_data : {}",exception.getMessage()); } + } /** diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/service/impl/HydropowerServiceImpl.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/service/impl/HydropowerServiceImpl.java index cba31a3..1d72374 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/service/impl/HydropowerServiceImpl.java +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/service/impl/HydropowerServiceImpl.java @@ -403,6 +403,9 @@ public class HydropowerServiceImpl implements HydropowerService { if(CollectionUtil.isEmpty(targetList)){ return; } + // 月发电量 + float powerMon = (float) targetList.stream().filter(o-> deptId.equals(o.getDeptId())).mapToDouble(HydropowerUnitTargetVo::getPowerMon).sum(); + response.setPowerYear(powerMon); // 年发电量 float powerYear = (float) targetList.stream().filter(o-> deptId.equals(o.getDeptId())).mapToDouble(HydropowerUnitTargetVo::getPowerYear).sum(); response.setPowerYear(powerYear); @@ -428,7 +431,10 @@ public class HydropowerServiceImpl implements HydropowerService { return; } String month = DateUtil.format(new Date(),"yyyy-MM") + "-01"; - response.setPowerMon(map.get(id).getOrDefault(month, 0f)); + float powerMon = map.get(id).getOrDefault(month, 0f); + if(powerMon > 0){ + response.setPowerMon(powerMon); + } } @@ -650,14 +656,17 @@ public class HydropowerServiceImpl implements HydropowerService { if (MapUtils.isEmpty(map)) { return kpi; } - String month = DateUtil.format(new Date(),"yyyy-MM") + "-01"; // 当月发电量 - kpi.setGenerateMon(map.entrySet().stream().filter(o->stations.stream().map(StationEntity::getId).collect(Collectors.toList()).contains(o.getKey())).mapToDouble(entry->{ + String month = DateUtil.format(new Date(),"yyyy-MM") + "-01"; + double generateMon = map.entrySet().stream().filter(o->stations.stream().map(StationEntity::getId).collect(Collectors.toList()).contains(o.getKey())).mapToDouble(entry->{ if(entry.getValue().containsKey(month)){ return Double.valueOf(entry.getValue().get(month)); } return 0.0; - }).sum()); + }).sum(); + if(generateMon > 0){ + kpi.setGenerateMon(generateMon); + } // 今年发电趋势 kpi.setPowerMonthVoList(this.handlePowerFinish(stations,map)); // 近3年发电量