diff --git a/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/main/constant/ScheduledConstant.java b/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/main/constant/ScheduledConstant.java index c5b9176..5dee662 100644 --- a/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/main/constant/ScheduledConstant.java +++ b/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/main/constant/ScheduledConstant.java @@ -11,4 +11,6 @@ public interface ScheduledConstant { String THIRTY_DAY_POWER_GENERATION = "thirtyDayPowerGeneration"; String THIS_DAY_POWER_GENERATION = "thisDayPowerGeneration"; + + String LOAD_THREE_YEAR_POWER_GENERATION = "loadThreeYearPowerGeneration"; } \ No newline at end of file diff --git a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/scheduled/GenerationScheduledTask.java b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/scheduled/GenerationScheduledTask.java index bd21b68..b574b22 100644 --- a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/scheduled/GenerationScheduledTask.java +++ b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/scheduled/GenerationScheduledTask.java @@ -69,4 +69,18 @@ public class GenerationScheduledTask { return new ReturnT<>("SUCCESS"); } + /** + * 新版-近3年发电量 + * @param param + * @return + */ + @XxlJob(LOAD_THREE_YEAR_POWER_GENERATION) + public ReturnT loadThreeYearPowerGeneration(String param) { + if (Func.isBlank(param)) { + param = DateUtil.format(new Date(), "yyyy-MM"); + } + service.loadThreeYearPowerGeneration(param,Arrays.asList(HomePageConstant.HYDROPOWER,HomePageConstant.PHOTOVOLTAIC),2,3); + return new ReturnT<>("SUCCESS"); + } + } \ No newline at end of file diff --git a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/home/ObtainGenerationService.java b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/home/ObtainGenerationService.java index 61c6fc7..50210c2 100644 --- a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/home/ObtainGenerationService.java +++ b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/home/ObtainGenerationService.java @@ -1,5 +1,7 @@ package com.hnac.hzims.scheduled.service.operation.home; +import java.util.List; + /** * @author ysj */ @@ -10,4 +12,6 @@ public interface ObtainGenerationService { void thirtyDayPowerGeneration(String param); void thisDayPowerGeneration(String param); + + void loadThreeYearPowerGeneration(String param, List types, Integer serveType,int year); } diff --git a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/home/impl/ObtainGenerationServiceImpl.java b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/home/impl/ObtainGenerationServiceImpl.java index 632c2f2..0259de2 100644 --- a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/home/impl/ObtainGenerationServiceImpl.java +++ b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/home/impl/ObtainGenerationServiceImpl.java @@ -2,6 +2,7 @@ package com.hnac.hzims.scheduled.service.operation.home.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.ThirtyGenerationEntity; @@ -59,8 +60,11 @@ public class ObtainGenerationServiceImpl implements ObtainGenerationService { @Value("${hzims.equipment.emInfo.emInfoList}") public String device_cache_cofig_final; + private final static String recent_year_power_data = "hzims:operation:key:power:data"; + private static final ExecutorService pool = new ThreadPoolExecutor(10, 10, 0L, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<>(1024), new ThreadFactoryBuilder().setNameFormat("obtain-generation-pool-%d").build() , new ThreadPoolExecutor.CallerRunsPolicy()); + /** * 设备近3年发电量数据 : 按月分割 * @param param @@ -131,8 +135,8 @@ public class ObtainGenerationServiceImpl implements ObtainGenerationService { CountDownLatch countDownLatch = new CountDownLatch(limits.size()); List saves = new CopyOnWriteArrayList<>(); for(List item : limits){ - try{ - pool.submit(()->{ + pool.submit(()->{ + try{ item.forEach(station->{ // 站点设备集合 List eminfos = devices.stream().filter(device -> device.getCreateDept().equals(station.getRefDept())).collect(Collectors.toList()); @@ -175,10 +179,11 @@ public class ObtainGenerationServiceImpl implements ObtainGenerationService { }); countDownLatch.countDown(); log.error("save_generation_execute_complete: {}" ,item.stream().map(StationEntity::getName).collect(Collectors.toList())); - }); - }catch (Exception e){ - log.error("save_generation_execute_complete_error : {}" ,e.getMessage()); - } + }catch (Exception e){ + countDownLatch.countDown(); + log.error("save_generation_execute_complete_error : {}" ,e.getMessage()); + } + }); } // 等待所有线程执行完成 try { @@ -216,9 +221,7 @@ public class ObtainGenerationServiceImpl implements ObtainGenerationService { calendar.set(Calendar.YEAR, calendar.get(Calendar.YEAR) - 3); calendar.add(Calendar.MONTH, -calendar.get(Calendar.MONTH)); String start = DateUtil.format(calendar.getTime(),DateUtil.PATTERN_DATE) + " 00:00:00"; - stations.forEach(station->{ - this.threeGenerateService.saveBatch(this.saveFillGenerate(station,start,end)); - }); + stations.forEach(station-> this.threeGenerateService.saveBatch(this.saveFillGenerate(station,start,end))); } /** @@ -306,6 +309,7 @@ public class ObtainGenerationServiceImpl implements ObtainGenerationService { log.error("save_generation_execute_complete: {}" ,item.stream().map(StationEntity::getName).collect(Collectors.toList())); }); }catch (Exception e){ + countDownLatch.countDown(); log.error("save_generation_execute_complete_error : {}" ,e.getMessage()); } } @@ -378,6 +382,7 @@ public class ObtainGenerationServiceImpl implements ObtainGenerationService { log.error("save_generation_execute_complete: {}" ,item.stream().map(StationEntity::getName).collect(Collectors.toList())); }); }catch (Exception e){ + countDownLatch.countDown(); log.error("save_generation_execute_complete_error : {}" ,e.getMessage()); } } @@ -437,4 +442,54 @@ public class ObtainGenerationServiceImpl implements ObtainGenerationService { private static Integer countStep(Integer size) { return (size + 3 - 1) / 3; } + + + /** + * 新版-近3年发电量 + * @param param + */ + @Override + public void loadThreeYearPowerGeneration(String param, List types, Integer serveType,int year) { + // 站点查询 + List stations = stationService.list(new LambdaQueryWrapper() {{ + if (CollectionUtil.isNotEmpty(types)) { + in(StationEntity::getType, types); + } + }}); + // 开始时间 + 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); + // 结束日期 + 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); + + List generations = threeGenerateService.list(Wrappers.lambdaQuery() + .in(ThreeGenerationEntity::getStationId,stations.stream().map(StationEntity::getCode).collect(Collectors.toList())) + .ge(ThreeGenerationEntity::getStrMonth,start) + .le(ThreeGenerationEntity::getStrMonth,end) + ); + if(CollectionUtil.isEmpty(generations)){ + return; + } + Map> map = generations.stream().collect(Collectors.groupingBy(ThreeGenerationEntity::getStationId)); + // 定义接收参数 + Map> container = new HashMap<>(); + map.forEach((key, value) -> { + Optional optional = stations.stream().filter(o -> o.getCode().equals(key)).findFirst(); + if (!optional.isPresent()) { + return; + } + // 根据月份分组 + Map> months = value.stream().collect(Collectors.groupingBy(ThreeGenerationEntity::getStrMonth)); + // 接收月份发电量对象 + Map son = new HashMap<>(); + // 遍历月份数据 + months.entrySet().stream().sorted(Map.Entry.comparingByKey()).forEach(iter -> son.put(iter.getKey(), (float) iter.getValue().stream().mapToDouble(o -> o.getGenerate().doubleValue()).sum())); + container.put(optional.get().getId(), son); + }); + redisTemplate.opsForValue().set(recent_year_power_data, container); + } } \ No newline at end of file diff --git a/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/mapper/CarMapper.xml b/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/mapper/CarMapper.xml index 61bea9f..82c6fae 100644 --- a/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/mapper/CarMapper.xml +++ b/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/mapper/CarMapper.xml @@ -4,7 +4,7 @@ SELECT - t1.unit, t1.car_brand, t1.plate_number, DATE_FORMAT(t2.end_time, '%m') as dateTime, sum(t2.miles) as miles + t1.unit, t1.car_brand, t1.plate_number, DATE_FORMAT(t2.end_time, '%m') as dateTime, sum(t2.miles) as miles, + t1.create_user, t1.create_dept FROM hzims_car t1 LEFT JOIN hzims_car_used_record t2 ON t1.id = t2.car_id