Browse Source

#新版近3年发电量

zhongwei
yang_shj 6 months ago
parent
commit
c74dea48bc
  1. 14
      hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/scheduled/GenerationScheduledTask.java
  2. 4
      hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/home/ObtainGenerationService.java
  3. 56
      hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/home/impl/ObtainGenerationServiceImpl.java

14
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<String> 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");
}
}

4
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<Integer> types, Integer serveType,int year);
}

56
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;
@ -18,6 +19,7 @@ import com.hnac.hzims.scheduled.service.operation.home.ObtainGenerationService;
import com.hnac.hzims.scheduled.service.operation.plate.DataService;
import com.hnac.hzims.scheduled.service.operation.station.StationService;
import com.hnac.hzinfo.datasearch.analyse.vo.AnalyseDataTaosVO;
import io.undertow.util.CopyOnWriteMap;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springblade.core.tool.utils.CollectionUtil;
@ -59,6 +61,8 @@ 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());
/**
@ -437,4 +441,56 @@ 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<Integer> types, Integer serveType,int year) {
// 站点查询
List<StationEntity> stations = stationService.list(new LambdaQueryWrapper<StationEntity>() {{
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<ThreeGenerationEntity> generations = threeGenerateService.list(Wrappers.<ThreeGenerationEntity>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<String,List<ThreeGenerationEntity>> map = generations.stream().collect(Collectors.groupingBy(ThreeGenerationEntity::getStationId));
// 定义接收参数
Map<Long, Map<String, Float>> container = new HashMap<>();
map.forEach((key, value) -> {
Optional<StationEntity> optional = stations.stream().filter(o -> o.getCode().equals(key)).findFirst();
if (!optional.isPresent()) {
return;
}
// 根据月份分组
Map<String, List<ThreeGenerationEntity>> months = value.stream().collect(Collectors.groupingBy(ThreeGenerationEntity::getStrMonth));
// 接收月份发电量对象
Map<String, Float> 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);
}
}
Loading…
Cancel
Save