Browse Source

#水位调度任务执行

zhongwei
yang_shj 4 months ago
parent
commit
4abd5e9c81
  1. 1
      hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/scheduled/RealTargetScheduledTask.java
  2. 17
      hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/home/impl/ObtainGenerationServiceImpl.java
  3. 9
      hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/home/impl/RealTargetServiceImpl.java

1
hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/scheduled/RealTargetScheduledTask.java

@ -8,6 +8,7 @@ import lombok.extern.slf4j.Slf4j;
import org.springblade.core.tool.utils.DateUtil;
import org.springblade.core.tool.utils.Func;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import java.util.Arrays;

17
hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/home/impl/ObtainGenerationServiceImpl.java

@ -19,7 +19,6 @@ 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;
@ -65,6 +64,7 @@ public class ObtainGenerationServiceImpl implements ObtainGenerationService {
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
@ -135,8 +135,8 @@ public class ObtainGenerationServiceImpl implements ObtainGenerationService {
CountDownLatch countDownLatch = new CountDownLatch(limits.size());
List<ThirtyGenerationEntity> saves = new CopyOnWriteArrayList<>();
for(List<StationEntity> item : limits){
try{
pool.submit(()->{
try{
item.forEach(station->{
// 站点设备集合
List<EminfoAndEmParamVo> eminfos = devices.stream().filter(device -> device.getCreateDept().equals(station.getRefDept())).collect(Collectors.toList());
@ -179,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){
countDownLatch.countDown();
log.error("save_generation_execute_complete_error : {}" ,e.getMessage());
}
});
}
// 等待所有线程执行完成
try {
@ -220,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)));
}
/**
@ -310,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());
}
}
@ -382,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());
}
}
@ -486,9 +487,7 @@ public class ObtainGenerationServiceImpl implements ObtainGenerationService {
// 接收月份发电量对象
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());
});
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);

9
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(20, 20, 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) {
@ -573,19 +573,22 @@ public class RealTargetServiceImpl implements RealTargetService {
waterLevelVo.setRearCurveMap(rearCurveMap);
list.add(waterLevelVo);
}
log.error("load_water_level : 线程执行完成 {}", item.getInstanceCode());
countDownLatch.countDown();
} catch (Exception exception) {
log.error("load_water_level_error : {}",exception.getMessage());
log.error("load_water_level_error : 线程执行失败 {}", exception.getMessage());
countDownLatch.countDown();
}
});
}
try {
log.error("load_water_level :等待线程执行");
countDownLatch.await();
} catch (InterruptedException e) {
e.printStackTrace();
Thread.currentThread().interrupt();
}
log.error("load_water_level :线程执行完成");
redisTemplate.opsForValue().set(loadwater_level_key,list);
}
@ -1132,7 +1135,7 @@ public class RealTargetServiceImpl implements RealTargetService {
}
/**
* 获取水位当数据
* 获取水位当数据
* @param instanceCode
* @param signage
* @return

Loading…
Cancel
Save