Browse Source

#用户反馈更新sql

zhongwei
yang_shj 6 months ago
parent
commit
28668c8925
  1. 13
      hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/scheduled/RealTargetScheduledTask.java
  2. 2
      hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/home/RealTargetService.java
  3. 71
      hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/home/impl/RealTargetServiceImpl.java
  4. 35
      hzims-service/inspect/src/main/java/com/hnac/hzinfo/inspect/offline/service/impl/InspectOfflineServiceImpl.java
  5. 17
      hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/service/impl/HydropowerServiceImpl.java

13
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"); return new ReturnT<>("SUCCESS");
} }
/**
* 获取站点近3年发电量数据
*/
@XxlJob(LOAD_POWER_DATA_NEW)
//@Scheduled(cron = "0/40 * * * * ? ")
public ReturnT<String> 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) @XxlJob(WIND_POWER_GENERATION_RECENT_YEAR)
//@Scheduled(cron = "0/40 * * * * ? ") //@Scheduled(cron = "0/40 * * * * ? ")

2
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<Integer> types, Integer serveType, int year); void loadPowerData(String param, List<Integer> types, Integer serveType, int year);
void loadPowerDataNew(String param, List<Integer> types, Integer serveType, int year);
void loadPowerDataByWindEnergy(String param, List<Integer> types, Integer serveType, int year,String key); void loadPowerDataByWindEnergy(String param, List<Integer> types, Integer serveType, int year,String key);
} }

71
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 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 @Override
public void loadEmInfo(String param) { public void loadEmInfo(String param) {
@ -1250,9 +1250,8 @@ public class RealTargetServiceImpl implements RealTargetService {
// 将站点切割 // 将站点切割
int limit = countStep(stations.size()); int limit = countStep(stations.size());
List<List<StationEntity>> 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()); List<List<StationEntity>> 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<StationEntity> item : limits){ for(List<StationEntity> item : limits){
pool.submit(()->{ try{
item.forEach(station->{ item.forEach(station->{
// 站点设备集合 // 站点设备集合
List<EminfoAndEmParamVo> stationDevices = devices.stream().filter(device -> device.getCreateDept().equals(station.getRefDept())).collect(Collectors.toList()); List<EminfoAndEmParamVo> 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)){ if(MapUtils.isEmpty(generateMap)){
return; return;
} }
log.error("pool_item_execute_complete: {}" ,JSONObject.toJSONString(generateMap));
powerMap.put(station.getId(),generateMap); powerMap.put(station.getId(),generateMap);
}); });
countDownLatch.countDown(); }catch (Exception exception){
log.error("pool_item_execute_complete: {}" ,item.stream().map(StationEntity::getName).collect(Collectors.toList())); log.error("pool_item_execute_complete_error: {}" ,exception.getMessage());
}); }
}
//所有模板数据获取完成后释放锁
try {
countDownLatch.await();
} catch (InterruptedException e) {
e.printStackTrace();
Thread.currentThread().interrupt();
} }
redisTemplate.opsForValue().set(recent_year_power_data, powerMap); redisTemplate.opsForValue().set(recent_year_power_data, powerMap);
} }
@Override
public void loadPowerDataNew(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);
}
}});
// 设备信息
List<EminfoAndEmParamVo> devices = JSONObject.parseObject(redisTemplate.opsForValue().get(device_cache_cofig_final).toString(), new TypeReference<List<EminfoAndEmParamVo>>() {
});
// 开始时间
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<Long, Map<String, Float>> powerMap = new CopyOnWriteMap<>();
// 将站点切割
int limit = countStep(stations.size());
List<List<StationEntity>> 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<StationEntity> item : limits){
pool.submit(()->{
item.forEach(station->{
// 站点设备集合
List<EminfoAndEmParamVo> stationDevices = devices.stream().filter(device -> device.getCreateDept().equals(station.getRefDept())).collect(Collectors.toList());
Map<String, Float> 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<String, Float> lastReduceFirst(StationEntity station, List<EminfoAndEmParamVo> devices, String start, String end) { private Map<String, Float> lastReduceFirst(StationEntity station, List<EminfoAndEmParamVo> devices, String start, String end) {
List<PowerMonthVo> datas = new ArrayList<>(); List<PowerMonthVo> datas = new ArrayList<>();

35
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) @Transactional(rollbackFor = Exception.class)
public void updateData(BaseService service, List<? extends SyncBO> data) { public void updateData(BaseService service, List<? extends SyncBO> data) {
if (CollectionUtil.isEmpty(data)) { try{
return; if (CollectionUtil.isEmpty(data)) {
} return;
Map<Integer, List<SyncBO>> dataList = data.stream().collect(Collectors.groupingBy(o -> o.getOfflineFlag() != null ? o.getOfflineFlag() : 0)); }
//新增 Map<Integer, List<SyncBO>> 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(1))) {
} service.saveBatch(dataList.get(1));
//修改 }
if (CollectionUtil.isNotEmpty(dataList.get(2))) { //修改
service.updateBatchById(dataList.get(2)); 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())); 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());
} }
} }
/** /**

17
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)){ if(CollectionUtil.isEmpty(targetList)){
return; 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(); float powerYear = (float) targetList.stream().filter(o-> deptId.equals(o.getDeptId())).mapToDouble(HydropowerUnitTargetVo::getPowerYear).sum();
response.setPowerYear(powerYear); response.setPowerYear(powerYear);
@ -428,7 +431,10 @@ public class HydropowerServiceImpl implements HydropowerService {
return; return;
} }
String month = DateUtil.format(new Date(),"yyyy-MM") + "-01"; 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)) { if (MapUtils.isEmpty(map)) {
return kpi; 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)){ if(entry.getValue().containsKey(month)){
return Double.valueOf(entry.getValue().get(month)); return Double.valueOf(entry.getValue().get(month));
} }
return 0.0; return 0.0;
}).sum()); }).sum();
if(generateMon > 0){
kpi.setGenerateMon(generateMon);
}
// 今年发电趋势 // 今年发电趋势
kpi.setPowerMonthVoList(this.handlePowerFinish(stations,map)); kpi.setPowerMonthVoList(this.handlePowerFinish(stations,map));
// 近3年发电量 // 近3年发电量

Loading…
Cancel
Save