Browse Source

Merge remote-tracking branch 'origin/prod-20240506' into prod-5.1.3

# Conflicts:
#	hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/home/impl/RealTargetServiceImpl.java
#	pom.xml
zhongwei
yang_shj 4 months ago
parent
commit
ee40d4a132
  1. 2
      hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/main/constant/ScheduledConstant.java
  2. 14
      hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/scheduled/GenerationScheduledTask.java
  3. 4
      hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/home/ObtainGenerationService.java
  4. 73
      hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/home/impl/ObtainGenerationServiceImpl.java
  5. 5
      hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/mapper/CarMapper.xml

2
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";
}

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);
}

73
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<ThirtyGenerationEntity> saves = new CopyOnWriteArrayList<>();
for(List<StationEntity> item : limits){
try{
pool.submit(()->{
pool.submit(()->{
try{
item.forEach(station->{
// 站点设备集合
List<EminfoAndEmParamVo> 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<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);
}
}

5
hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/mapper/CarMapper.xml

@ -4,7 +4,7 @@
<select id="selectCarByYear" resultType="com.hnac.hzims.safeproduct.vo.CarMilesYearVO">
SELECT
DISTINCT t1.unit, t1.car_brand, t1.plate_number, t1.create_time
DISTINCT t1.unit, t1.car_brand, t1.plate_number, t1.create_time, t1.create_user, t1.create_dept
FROM
hzims_car t1
LEFT JOIN hzims_car_used_record t2 ON t1.id = t2.car_id
@ -22,7 +22,8 @@
<select id="selectMilesByCar" resultType="com.hnac.hzims.safeproduct.dto.CarMilesYearDTO">
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

Loading…
Cancel
Save