diff --git a/hzims-service-api/alarm-api/src/main/java/com/hnac/hzims/alarm/config/constants/AlarmConstants.java b/hzims-service-api/alarm-api/src/main/java/com/hnac/hzims/alarm/config/constants/AlarmConstants.java index d3e3789..b9483a3 100644 --- a/hzims-service-api/alarm-api/src/main/java/com/hnac/hzims/alarm/config/constants/AlarmConstants.java +++ b/hzims-service-api/alarm-api/src/main/java/com/hnac/hzims/alarm/config/constants/AlarmConstants.java @@ -42,7 +42,8 @@ public interface AlarmConstants { // 等级告警 : 21-一级告警 22-二级告警 23-三级告警 // 智能预警 : 30-智能预警 // 条件告警 : 40-条件告警 - // 开关机告警 : 50-开机告警 51-关机告警 + // AI告警 : 50-AI告警 + // 开关机告警 : 60-开机告警 61-停机告警 Integer WARNING = 2; Integer FAULT = 3; Integer OFFSIDE = 5; @@ -59,7 +60,6 @@ public interface AlarmConstants { Integer START = 60; Integer STOP = 61; List START_STOP_ALARAM = Arrays.asList(START,STOP); - String VIDEO_SCHEDULED_TASK= "VideoScheduledTask"; List HZ3000_TYPES = Arrays.asList("0","1","2","3","4","5","6","7","8","9","10","11","12"); diff --git a/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/report/entity/RunMonthEntity.java b/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/report/entity/RunMonthEntity.java index 4e29738..a88c68b 100644 --- a/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/report/entity/RunMonthEntity.java +++ b/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/report/entity/RunMonthEntity.java @@ -6,6 +6,7 @@ import io.swagger.annotations.ApiModelProperty; import lombok.Data; import lombok.EqualsAndHashCode; import org.springblade.core.mp.base.BaseEntity; +import org.springblade.core.tenant.mp.TenantEntity; /** * @author ysj @@ -14,7 +15,7 @@ import org.springblade.core.mp.base.BaseEntity; @EqualsAndHashCode(callSuper = true) @TableName("hzims_run_month_report") @ApiModel(value = "运行月报告表", description = "运行月报告实体类") -public class RunMonthEntity extends BaseEntity { +public class RunMonthEntity extends TenantEntity { @ApiModelProperty("站点编码") private String stationCode; diff --git a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/alarm/impl/AlarmServiceImpl.java b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/alarm/impl/AlarmServiceImpl.java index 331a697..cf46488 100644 --- a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/alarm/impl/AlarmServiceImpl.java +++ b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/alarm/impl/AlarmServiceImpl.java @@ -80,11 +80,11 @@ public class AlarmServiceImpl implements AlarmService { // 查询开关机默认告警配置 AlarmDefaultConfigEntity start = defaulConfigService.getOne(Wrappers.lambdaQuery() .eq(AlarmDefaultConfigEntity::getSource,5) - .eq(AlarmDefaultConfigEntity::getAlarmChiledType,50) + .eq(AlarmDefaultConfigEntity::getAlarmChiledType,60) ); AlarmDefaultConfigEntity stop = defaulConfigService.getOne(Wrappers.lambdaQuery() .eq(AlarmDefaultConfigEntity::getSource,5) - .eq(AlarmDefaultConfigEntity::getAlarmChiledType,51) + .eq(AlarmDefaultConfigEntity::getAlarmChiledType,61) ); // 获取站点设备实时数据 List reals = (List) redisTemplate.opsForValue().get(load_hydropower_unit_real_key); @@ -156,7 +156,7 @@ public class AlarmServiceImpl implements AlarmService { alarm.setDeviceCode(real.getDeviceCode()); alarm.setDeviceName(real.getDeviceName()); alarm.setAlarmId(station.getCode() + "_" + Func.randomUUID()); - alarm.setAlarmContext(station.getName() + "." + real.getDeviceName() + "_关机"); + alarm.setAlarmContext(station.getName() + "." + real.getDeviceName() + "_停机"); alarm.setAlarmSource(AlarmConstants.START_STOP_WARNING); alarm.setAlarmType(AlarmConstants.STOP); if(state == 1){ diff --git a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/home/impl/RealTargetServiceImpl.java b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/home/impl/RealTargetServiceImpl.java index bd0cf92..4ea3d60 100644 --- a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/home/impl/RealTargetServiceImpl.java +++ b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/home/impl/RealTargetServiceImpl.java @@ -4,11 +4,13 @@ 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.EquipmentConstants; import com.hnac.hzims.equipment.entity.EmParamEntity; import com.hnac.hzims.equipment.vo.EminfoAndEmParamVo; import com.hnac.hzims.hzimsweather.feign.IHeWeatherWeatherClient; import com.hnac.hzims.hzimsweather.vo.RainFallCountByMonthVo; +import com.hnac.hzims.operational.config.vo.StationRealVo; import com.hnac.hzims.operational.fill.entity.RainfallEntity; import com.hnac.hzims.operational.home.wind.RainMon; import com.hnac.hzims.operational.main.constant.HomePageConstant; @@ -111,6 +113,9 @@ public class RealTargetServiceImpl implements RealTargetService { @Value("${hzims.operation.realIdKey}") public String real_id_cofig_final; + // 创建线程池 + ExecutorService pool = new ThreadPoolExecutor(8, 8, 0L, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<>(1024), new ThreadFactoryBuilder().setNameFormat("load-power-data-pool-%d").build(), new ThreadPoolExecutor.AbortPolicy()); + private final static String recent_year_power_data = "hzims:operation:key:power:data"; private final static String load_hydropower_unit_real_key = "hzims:operation:loadhydropowerunit:real:key"; private final static String load_hydropower_unit_target_key = "hzims:operation:loadhydropowerunit:target:key"; @@ -1220,11 +1225,9 @@ public class RealTargetServiceImpl implements RealTargetService { */ @Override public void loadPowerData(String param, List types, Integer serveType, int year) { - Long time=System.currentTimeMillis(); - System.out.println("近年发电量接口耗时测试开始======================="); - log.info("近年发电量接口耗时测试开始======================="); // 站点查询 - List stationList = stationService.list(new LambdaQueryWrapper() {{ + List stations = stationService.list(new LambdaQueryWrapper() {{ + eq(StationEntity::getDataOrigin,HomePageConstant.DATA_ORIGIN); if (ObjectUtil.isNotEmpty(serveType)) { eq(StationEntity::getServeType, serveType); } @@ -1245,22 +1248,35 @@ public class RealTargetServiceImpl implements RealTargetService { calendar.add(Calendar.MONTH, -calendar.get(Calendar.MONTH)); String start = DateUtil.format(calendar.getTime(),DateUtil.PATTERN_DATE) + " 00:00:00"; // 存储数据map :<站点id,<月份,发电量>> - Map> powerMap = new HashMap<>(); - Long time2=System.currentTimeMillis(); - log.info("近年发电量接口,数据组装"+(time2-time)); - stationList.forEach(station -> { - // 站点设备集合 - List stationDevices = devices.stream().filter(device -> device.getCreateDept().equals(station.getRefDept())).collect(Collectors.toList()); - log.error("load_power_data station :" + station.getCode() + "==== device :" + stationDevices ); - Map generateMap = this.getGenerateYear(station,stationDevices,start,end); - if(MapUtils.isEmpty(generateMap)){ - return; + Map> powerMap = new ConcurrentHashMap<>(); + // 将站点切割 + int limit = countStep(stations.size()); + List> limits = Stream.iterate(0, n -> n + 1).limit(limit).parallel().map(a -> stations.stream().skip((long) a * 5).limit(5).parallel().collect(Collectors.toList())).collect(Collectors.toList()); + // 线程数量 + CountDownLatch countDownLatch = new CountDownLatch(limits.size()); + pool.execute(()->{ + for(List item : limits){ + item.forEach(station->{ + // 站点设备集合 + List stationDevices = devices.stream().filter(device -> device.getCreateDept().equals(station.getRefDept())).collect(Collectors.toList()); + Map generateMap = this.getGenerateYear(station,stationDevices,start,end); + if(MapUtils.isEmpty(generateMap)){ + return; + } + powerMap.put(station.getId(),generateMap); + }); + countDownLatch.countDown(); } - powerMap.put(station.getId(),generateMap); - }); + }); + // 等待所有线程执行完成 + try { + countDownLatch.await(); + } catch (InterruptedException e) { + e.printStackTrace(); + Thread.currentThread().interrupt(); + } + pool.shutdown(); redisTemplate.opsForValue().set(recent_year_power_data, powerMap); - Long time3=System.currentTimeMillis(); - log.info("近年发电量数据接口,总耗时:"+(time3-time)); } @Override diff --git a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/report/impl/ReportServiceImpl.java b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/report/impl/ReportServiceImpl.java index 771db81..994d944 100644 --- a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/report/impl/ReportServiceImpl.java +++ b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/report/impl/ReportServiceImpl.java @@ -624,14 +624,17 @@ public class ReportServiceImpl implements ReportService { List plans = planService.planGeneration(stations.stream().map(StationEntity::getCode).collect(Collectors.toList()), null ,DateUtil.format(new Date(),"yyyy")); // 查询站点设备 List devices = deviceService.rideDevices(stations.stream().map(StationEntity::getRefDept).collect(Collectors.toList())); - List runs = new ArrayList<>(); stations.forEach(station->{ RunMonthEntity run = new RunMonthEntity(); + run.setTenantId(station.getTenantId()); + run.setCreateDept(station.getRefDept()); + run.setCreateUser(station.getCreateUser()); + run.setUpdateUser(station.getUpdateUser()); run.setStationCode(station.getCode()); run.setStationName(station.getName()); Calendar calendar = Calendar.getInstance(); - calendar.setTime(DateUtil.parse("2024-04-01 00:00:00",DateUtil.PATTERN_DATETIME)); - //calendar.add(Calendar.DAY_OF_MONTH,-1); + calendar.setTime(new Date()); + calendar.add(Calendar.DAY_OF_MONTH,-1); run.setMonth(DateUtil.format(calendar.getTime(),"yyyy-MM")); List stationDevices = devices.stream().filter(device->device.getDepartment().equals(station.getRefDept())).collect(Collectors.toList()); if(CollectionUtil.isEmpty(stationDevices)){ @@ -645,9 +648,9 @@ public class ReportServiceImpl implements ReportService { run.setCurveData(this.curveData(stationDevices)); // TODO 运行数据分析 // TODO 运行建议及其他 - runs.add(run); + runMonService.save(run); }); - runMonService.saveBatch(runs); + } /** @@ -686,8 +689,7 @@ public class ReportServiceImpl implements ReportService { */ private Double generate(int type,String deviceCode,double ride) { Calendar calendar = Calendar.getInstance(); - calendar.setTime(DateUtil.parse("2024-04-01 00:00:00",DateUtil.PATTERN_DATETIME)); - //calendar.setTime(new Date()); + calendar.setTime(new Date()); String end = null,start = null; int cycleType = 5; switch (type){ @@ -723,8 +725,7 @@ public class ReportServiceImpl implements ReportService { */ private Double planGenerate(int type, String stationCode,List plans) { Calendar calendar = Calendar.getInstance(); - calendar.setTime(DateUtil.parse("2024-04-01 00:00:00",DateUtil.PATTERN_DATETIME)); - //calendar.setTime(new Date()); + calendar.setTime(new Date()); if(type == 0){ calendar.add(Calendar.DAY_OF_MONTH,-1); calendar.add(Calendar.HOUR_OF_DAY,-calendar.get(Calendar.HOUR_OF_DAY) + 1); @@ -761,8 +762,7 @@ public class ReportServiceImpl implements ReportService { // 确定查询时间范围: 年、月 Date startDate,endDate; Calendar calendar = Calendar.getInstance(); - calendar.setTime(DateUtil.parse("2024-04-01 00:00:00",DateUtil.PATTERN_DATETIME)); - //calendar.setTime(new Date()); + calendar.setTime(new Date()); endDate = calendar.getTime(); calendar.add(Calendar.MONTH, -calendar.get(Calendar.MONTH)); calendar.add(Calendar.DATE, -calendar.get(Calendar.DATE) + 1); @@ -835,8 +835,7 @@ public class ReportServiceImpl implements ReportService { */ private String alarmData(String code) { Calendar calendar = Calendar.getInstance(); - calendar.setTime(DateUtil.parse("2024-04-01 00:00:00",DateUtil.PATTERN_DATETIME)); - //calendar.setTime(new Date()); + calendar.setTime(new Date()); calendar.add(Calendar.DAY_OF_MONTH,-1); String end = DateUtil.format(calendar.getTime(),DateUtil.PATTERN_DATETIME); calendar.add(Calendar.MONTH,-1); @@ -943,12 +942,10 @@ public class ReportServiceImpl implements ReportService { */ private List curve(List attributes, String deviceCode) { Calendar calendar = Calendar.getInstance(); - calendar.setTime(DateUtil.parse("2024-04-01 23:59:59",DateUtil.PATTERN_DATETIME)); - //calendar.setTime(DateUtil.parse(DateUtil.format(new Date(),DateUtil.PATTERN_DATE) + " 23:59:59",DateUtil.PATTERN_DATETIME)); + calendar.setTime(DateUtil.parse(DateUtil.format(new Date(),DateUtil.PATTERN_DATE) + " 23:59:59",DateUtil.PATTERN_DATETIME)); calendar.add(Calendar.DAY_OF_MONTH,-1); String end = DateUtil.format(calendar.getTime(),DateUtil.PATTERN_DATETIME); calendar.add(Calendar.MONTH,-1); - calendar.add(Calendar.DAY_OF_MONTH,1); calendar.add(Calendar.HOUR_OF_DAY,-calendar.get(Calendar.HOUR_OF_DAY)); calendar.add(Calendar.MINUTE, -calendar.get(Calendar.MINUTE)); calendar.add(Calendar.SECOND, -calendar.get(Calendar.SECOND)); diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/report/service/impl/RunMonthServiceImpl.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/report/service/impl/RunMonthServiceImpl.java index c6d39e2..6e4a668 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/report/service/impl/RunMonthServiceImpl.java +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/report/service/impl/RunMonthServiceImpl.java @@ -342,7 +342,7 @@ public class RunMonthServiceImpl extends BaseServiceImpl