Browse Source

#定时任务抽离

zhongwei
yang_shj 1 year ago
parent
commit
a30249d92e
  1. 39
      hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/ecology/vo/DeviceVo.java
  2. 30
      hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/ecology/vo/StationVo.java
  3. 22
      hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/ecology/vo/WaterVo.java
  4. 12
      hzims-service/operational/src/main/java/com/hnac/hzims/operational/ecology/controller/EcologyController.java
  5. 3
      hzims-service/operational/src/main/java/com/hnac/hzims/operational/ecology/service/EcologyFlowStationService.java
  6. 164
      hzims-service/operational/src/main/java/com/hnac/hzims/operational/ecology/service/impl/EcologyFlowStationServiceImpl.java

39
hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/ecology/vo/DeviceVo.java

@ -0,0 +1,39 @@
package com.hnac.hzims.operational.ecology.vo;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
/**
* @author ysj
*/
@Data
public class DeviceVo {
@ApiModelProperty(value = "设备编号")
private String deviceCode;
@ApiModelProperty(value = "设备名称")
private String deviceName;
@ApiModelProperty(value = "设备状态")
private Boolean state;
@ApiModelProperty(value = "有功功率")
private Double active;
@ApiModelProperty(value = "无功功率")
private Double reactive;
@ApiModelProperty(value = "生态流量")
private Double ecology;
@ApiModelProperty(value = "下泄流量")
private Double discharge;
@ApiModelProperty(value = "发电流量")
private Double generate;
@ApiModelProperty(value = "建议有功调整")
private Double adjust;
}

30
hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/ecology/vo/StationVo.java

@ -0,0 +1,30 @@
package com.hnac.hzims.operational.ecology.vo;
import com.hnac.hzims.operational.main.vo.WaterLevelVo;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.util.List;
/**
* @author ysj
*/
@Data
public class StationVo {
@ApiModelProperty(value = "站点编号")
private String stationId;
@ApiModelProperty(value = "站点名称")
private String stationName;
@ApiModelProperty(value = "水位")
private Double water;
@ApiModelProperty(value = "设备集合")
private List<DeviceVo> devices;
@ApiModelProperty(value = "设备集合")
private List<WaterVo> waters;
}

22
hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/ecology/vo/WaterVo.java

@ -0,0 +1,22 @@
package com.hnac.hzims.operational.ecology.vo;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
/**
* @author ysj
*/
@Data
public class WaterVo {
@ApiModelProperty(value = "时间")
private String time;
@ApiModelProperty(value = "水位")
private Double water;
@ApiModelProperty(value = "发电流量")
private Double generate;
}

12
hzims-service/operational/src/main/java/com/hnac/hzims/operational/ecology/controller/EcologyController.java

@ -71,6 +71,18 @@ public class EcologyController extends BladeController {
/** /**
* 接入站点数据
* @return
*/
@PostMapping("/station")
@ApiOperationSupport(order = 1)
@ApiOperation(value = "接入站点数据", notes = "接入站点数据")
public R station() {
return R.data(stationService.station());
}
/**
* 生态流量站点新增或修改 * 生态流量站点新增或修改
* @param entity * @param entity
* @return * @return

3
hzims-service/operational/src/main/java/com/hnac/hzims/operational/ecology/service/EcologyFlowStationService.java

@ -2,6 +2,7 @@ package com.hnac.hzims.operational.ecology.service;
import com.hnac.hzims.operational.ecology.entity.EcologyFlowStationEntity; import com.hnac.hzims.operational.ecology.entity.EcologyFlowStationEntity;
import com.hnac.hzims.operational.ecology.vo.EcologFlowStationVo; import com.hnac.hzims.operational.ecology.vo.EcologFlowStationVo;
import com.hnac.hzims.operational.ecology.vo.StationVo;
import com.hnac.hzims.operational.ecology.vo.TrendChartVo; import com.hnac.hzims.operational.ecology.vo.TrendChartVo;
import org.springblade.core.mp.base.BaseService; import org.springblade.core.mp.base.BaseService;
@ -19,4 +20,6 @@ public interface EcologyFlowStationService extends BaseService<EcologyFlowStatio
Boolean generate(Long mon,String year); Boolean generate(Long mon,String year);
List<TrendChartVo> trend_chart(String type); List<TrendChartVo> trend_chart(String type);
List<StationVo> station();
} }

164
hzims-service/operational/src/main/java/com/hnac/hzims/operational/ecology/service/impl/EcologyFlowStationServiceImpl.java

@ -2,19 +2,33 @@ package com.hnac.hzims.operational.ecology.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.hnac.hzims.EquipmentConstants;
import com.hnac.hzims.equipment.vo.EminfoAndEmParamVo;
import com.hnac.hzims.operational.ecology.entity.EcologyFlowDataEntity; import com.hnac.hzims.operational.ecology.entity.EcologyFlowDataEntity;
import com.hnac.hzims.operational.ecology.entity.EcologyFlowStationEntity; import com.hnac.hzims.operational.ecology.entity.EcologyFlowStationEntity;
import com.hnac.hzims.operational.ecology.mapper.EcologyFlowStationMapper; import com.hnac.hzims.operational.ecology.mapper.EcologyFlowStationMapper;
import com.hnac.hzims.operational.ecology.service.EcologyFlowDataService; import com.hnac.hzims.operational.ecology.service.EcologyFlowDataService;
import com.hnac.hzims.operational.ecology.service.EcologyFlowStationService; import com.hnac.hzims.operational.ecology.service.EcologyFlowStationService;
import com.hnac.hzims.operational.ecology.vo.DemonstrateTopVo; import com.hnac.hzims.operational.ecology.vo.*;
import com.hnac.hzims.operational.ecology.vo.EcologFlowStationVo; import com.hnac.hzims.operational.main.constant.HomePageConstant;
import com.hnac.hzims.operational.ecology.vo.TrendChartVo; import com.hnac.hzims.operational.main.service.IAnalyseDataService;
import com.hnac.hzims.operational.main.service.IMainSystemMonitoringService;
import com.hnac.hzims.operational.main.vo.GenerationPowerVo;
import com.hnac.hzims.operational.main.vo.HydropowerUnitRealVo;
import com.hnac.hzims.operational.main.vo.HydropowerUnitTargetVo;
import com.hnac.hzims.operational.main.vo.WaterLevelVo;
import com.hnac.hzims.operational.station.entity.HzimsAnalyzeModelStationEntity;
import com.hnac.hzims.operational.station.entity.StationEntity;
import com.hnac.hzims.operational.station.service.IHzimsAnalyzeModelStationService;
import com.hnac.hzims.operational.station.service.IStationService;
import com.hnac.hzinfo.datasearch.analyse.vo.AnalyseDataTaosVO;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springblade.core.mp.base.BaseServiceImpl; import org.springblade.core.mp.base.BaseServiceImpl;
import org.springblade.core.tool.utils.CollectionUtil; import org.springblade.core.tool.utils.CollectionUtil;
import org.springblade.core.tool.utils.DateUtil; import org.springblade.core.tool.utils.DateUtil;
import org.springblade.core.tool.utils.ObjectUtil;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.math.BigDecimal; import java.math.BigDecimal;
@ -30,8 +44,23 @@ import java.util.stream.Collectors;
@RequiredArgsConstructor @RequiredArgsConstructor
public class EcologyFlowStationServiceImpl extends BaseServiceImpl<EcologyFlowStationMapper, EcologyFlowStationEntity> implements EcologyFlowStationService { public class EcologyFlowStationServiceImpl extends BaseServiceImpl<EcologyFlowStationMapper, EcologyFlowStationEntity> implements EcologyFlowStationService {
private final IStationService stationService;
private final EcologyFlowDataService dataService; private final EcologyFlowDataService dataService;
private final IAnalyseDataService analyseDataService;
private final IMainSystemMonitoringService maintenanceTaskService;
private final IHzimsAnalyzeModelStationService modelStationService;
private final RedisTemplate redisTemplate;
private final static String loadwater_level_key = "hzims:operation:loadwater:level:key";
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";
/** /**
* 数据初始化 * 数据初始化
* @return * @return
@ -142,4 +171,133 @@ public class EcologyFlowStationServiceImpl extends BaseServiceImpl<EcologyFlowSt
} }
return charts.stream().sorted(Comparator.comparing(TrendChartVo::getTs)).collect(Collectors.toList()); return charts.stream().sorted(Comparator.comparing(TrendChartVo::getTs)).collect(Collectors.toList());
} }
/**
* 接入站点数据
* @return
*/
@Override
public List<StationVo> station() {
List<StationEntity> stations = stationService.list(Wrappers.<StationEntity>lambdaQuery()
.in(StationEntity::getCode,Arrays.asList("902400000054","902400052664")));
if(CollectionUtil.isEmpty(stations)){
return new ArrayList<>();
}
// 实时监测点数据
List<HydropowerUnitRealVo> realList = (List<HydropowerUnitRealVo>) redisTemplate.opsForValue().get(load_hydropower_unit_real_key);
// 获取站点机组指标数据
List<HydropowerUnitTargetVo> targetList = (List<HydropowerUnitTargetVo>) redisTemplate.opsForValue().get(load_hydropower_unit_target_key);
// 所有设备
List<EminfoAndEmParamVo> deviceList = maintenanceTaskService.getEmInfoList();
return stations.stream().map(item -> {
StationVo station = new StationVo();
station.setStationId(item.getCode());
station.setStationName(item.getName());
station.setDevices(this.devices(item,realList,targetList));
// 实时水位
this.handleWaterLeve(item.getCode(),station);
// 查询站点模型列表
HzimsAnalyzeModelStationEntity model = modelStationService.getOne(new LambdaQueryWrapper<HzimsAnalyzeModelStationEntity>() {{
eq(HzimsAnalyzeModelStationEntity::getStationId, item.getCode());
}});
// 水位曲线
if(ObjectUtil.isNotEmpty(model)){
station.setWaters(this. water(model.getInstanceCode()));
}
return station;
}).collect(Collectors.toList());
}
/**
* 获取站点设备信息
* @param station
* @return
*/
private List<DeviceVo> devices(StationEntity station, List<HydropowerUnitRealVo> realList, List<HydropowerUnitTargetVo> targetList) {
if(CollectionUtil.isEmpty(realList) || CollectionUtil.isEmpty(targetList)){
return null;
}
// 有效站点机组数据
List<HydropowerUnitRealVo> validRealList = realList.stream().filter(o-> null != station.getRefDept() && station.getRefDept().equals(o.getDeptId())).collect(Collectors.toList());
// 有效站点机组指标数据
List<HydropowerUnitTargetVo> validTargetList = targetList.stream().filter(o-> null != station.getRefDept() && station.getRefDept().equals(o.getDeptId())).collect(Collectors.toList());
List<DeviceVo> list = new ArrayList<>();
Random random = new Random();
for(HydropowerUnitRealVo real : validRealList){
DeviceVo device= new DeviceVo();
// 设备编号
device.setDeviceCode(real.getDeviceCode());
device.setDeviceName(real.getDeviceName());
device.setState(real.getState());
device.setActive(real.getActivePower());
device.setReactive(real.getReactivePower());
device.setEcology(random.nextDouble() * 20000);
device.setAdjust(random.nextDouble() * 20000);
device.setDischarge(random.nextDouble() * 20000);
device.setGenerate(random.nextDouble() * 20000);
list.add(device);
}
return list.stream().sorted(Comparator.comparing(DeviceVo::getDeviceCode)).collect(Collectors.toList());
}
/**
* 站点水位数据处理
* @param code
* @param station
*/
private void handleWaterLeve(String code, StationVo station) {
Random random = new Random();
station.setWater(random.nextDouble() * 100);
List<WaterLevelVo> levelList = (List<WaterLevelVo>) redisTemplate.opsForValue().get(loadwater_level_key);
if(CollectionUtil.isEmpty(levelList)){
return;
}
List<WaterLevelVo> validList = levelList.stream().filter(o-> code.equals(o.getStationCode())).collect(Collectors.toList());
if(CollectionUtil.isEmpty(validList)){
return;
}
WaterLevelVo level = validList.get(0);
station.setWater(level.getFrontWaterLevel());
}
/**
* 获取水位数据
* @param code
* @return
*/
private List<WaterVo> water(String code) {
Calendar calendar = Calendar.getInstance();
calendar.add(Calendar.DAY_OF_MONTH,-7);
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));
String start = DateUtil.format(calendar.getTime(), DateUtil.PATTERN_DATETIME);
String end = DateUtil.format(new Date(), DateUtil.PATTERN_DATETIME);
List<AnalyseDataTaosVO> records = analyseDataService.periodTargetData(start,end,3,3,code,HomePageConstant.FRONT_WATER_LEVEL);
Random random = new Random();
if(CollectionUtil.isEmpty(records)){
List<WaterVo> waters = new ArrayList<>();
while (calendar.getTime().compareTo(new Date()) <= 0){
WaterVo water = new WaterVo();
water.setTime(DateUtil.format(calendar.getTime(),DateUtil.PATTERN_DATE));
water.setWater(random.nextDouble() * 100);
water.setGenerate(random.nextDouble() * 50000);
waters.add(water);
calendar.add(Calendar.DAY_OF_MONTH,1);
}
return waters;
}
return records.stream().map(record -> {
WaterVo water = new WaterVo();
Date time = DateUtil.parse(record.getTs(), "yyyy-MM-dd HH:mm:ss.s");
water.setTime(DateUtil.format(time,DateUtil.PATTERN_DATE));
water.setWater(Double.valueOf(Optional.ofNullable(record.getVal()).orElse("0")));
if(Math.abs(water.getWater()) == 0){
water.setWater(random.nextDouble() * 100);
}
water.setGenerate(random.nextDouble() * 50000);
return water;
}).collect(Collectors.toList());
}
} }
Loading…
Cancel
Save