|
@@ -0,0 +1,378 @@
|
|
|
+package com.ruoyi;
|
|
|
+
|
|
|
+import cn.hutool.core.date.DateTime;
|
|
|
+import cn.hutool.core.date.DateUtil;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
+import com.ruoyi.quartz.handler.IJobHandler;
|
|
|
+import com.ruoyi.quartz.task.ChangedSave;
|
|
|
+import com.ruoyi.ucp.entity.*;
|
|
|
+import com.ruoyi.ucp.feign.AdapterApi;
|
|
|
+import com.ruoyi.ucp.service.*;
|
|
|
+import org.springframework.data.redis.core.RedisTemplate;
|
|
|
+
|
|
|
+import javax.annotation.Resource;
|
|
|
+import java.net.URI;
|
|
|
+import java.util.*;
|
|
|
+import java.util.function.Function;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+public class JavaFunctionJobHandler extends IJobHandler {
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private AdapterApi adapter;
|
|
|
+ @Resource
|
|
|
+ private IPointInfoService pointService;
|
|
|
+ @Resource
|
|
|
+ private IStationInfoHourService stationInfoHourService;
|
|
|
+ @Resource
|
|
|
+ private IStationInfoDayService stationInfoDayService;
|
|
|
+ @Resource
|
|
|
+ private ILineInfoDayService lineInfoDayService;
|
|
|
+ @Resource
|
|
|
+ private IStateAiService stateAiService;
|
|
|
+ @Resource
|
|
|
+ private RedisTemplate redisTemplate;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void execute() throws Exception {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public IJobHandler getFunctionHandler() {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void setFunctionHandler(IJobHandler jobHandler) {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ public void calcAQTS(Date date) {
|
|
|
+ QueryWrapper<StationInfoDay> wrapper = new QueryWrapper<>();
|
|
|
+ wrapper.select("min(record_date) record_date");
|
|
|
+ StationInfoDay one = stationInfoDayService.getOne(wrapper);
|
|
|
+ wrapper = new QueryWrapper<>();
|
|
|
+ wrapper.eq("record_date", one.getRecordDate());
|
|
|
+ //最早时间的列表
|
|
|
+ List<StationInfoDay> list = stationInfoDayService.list(wrapper);
|
|
|
+ List<StationInfoDay> today = getStationinfoByDate(date);
|
|
|
+ if (today.isEmpty()) {
|
|
|
+ for (StationInfoDay infoDay : list) {
|
|
|
+ StationInfoDay day = new StationInfoDay();
|
|
|
+ day.setStationId(infoDay.getStationId());
|
|
|
+ day.setRecordDate(date);
|
|
|
+ day.setAqts(infoDay.getAqts() + (int) DateUtil.betweenDay(infoDay.getRecordDate(), date, true));
|
|
|
+ today.add(day);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ Map<String, StationInfoDay> collect = list.stream().collect(Collectors.toMap(StationInfoDay::getStationId, Function.identity()));
|
|
|
+ for (StationInfoDay day : today) {
|
|
|
+ StationInfoDay day1 = collect.get(day.getStationId());
|
|
|
+ day.setAqts(day1.getAqts() + (int) DateUtil.betweenDay(day1.getRecordDate(), date, true));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ stationInfoDayService.saveOrUpdateBatch(today);
|
|
|
+ }
|
|
|
+
|
|
|
+ public List<StationInfoDay> getStationinfoByDate(Date date) {
|
|
|
+ QueryWrapper<StationInfoDay> wrapper = new QueryWrapper<>();
|
|
|
+ wrapper.eq("record_date", date);
|
|
|
+ return stationInfoDayService.list(wrapper);
|
|
|
+ }
|
|
|
+
|
|
|
+ public URI taosGoldenUriTest() {
|
|
|
+ return URI.create("http://127.0.0.1:8011/ts");
|
|
|
+ }
|
|
|
+
|
|
|
+ public URI taosUri() {
|
|
|
+ return URI.create("http://172.16.12.101:8012/ts");
|
|
|
+ }
|
|
|
+
|
|
|
+ public void calcStationHourRFDL(Date hour) {
|
|
|
+ PointInfo pointInfo = new PointInfo();
|
|
|
+ pointInfo.setInstitutionType("station");
|
|
|
+ pointInfo.setUniformCode("RFDLSYZ");
|
|
|
+ List<PointInfo> entity = pointService.getByEntity(pointInfo);
|
|
|
+ Map<String, PointData> section = adapter.getHistorySection(taosGoldenUriTest()
|
|
|
+ , pointInfos2Keys(entity), hour.getTime());
|
|
|
+ List<StationInfoHour> byHours = getStationinfoByHour(hour);
|
|
|
+ if (byHours.isEmpty()) {
|
|
|
+ for (PointInfo point : entity) {
|
|
|
+ StationInfoHour info = new StationInfoHour();
|
|
|
+ info.setStationId(point.getStationId());
|
|
|
+ info.setRecordDate(DateUtil.beginOfHour(hour));
|
|
|
+ info.setRfdl(section.get(point.getPointKey()).getDoubleValue());
|
|
|
+ byHours.add(info);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ Map<String, String> collect = entity.stream().collect(Collectors.toMap(PointInfo::getStationId, PointInfo::getPointKey));
|
|
|
+ for (StationInfoHour byHour : byHours) {
|
|
|
+ byHour.setRfdl(section.get(collect.get(byHour.getStationId())).getDoubleValue());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ stationInfoHourService.saveOrUpdateBatch(byHours);
|
|
|
+ }
|
|
|
+
|
|
|
+ public List<StationInfoHour> getStationinfoByHour(Date hour) {
|
|
|
+ QueryWrapper<StationInfoHour> wrapper = new QueryWrapper<>();
|
|
|
+ wrapper.eq("record_date", DateUtil.beginOfHour(hour));
|
|
|
+ return stationInfoHourService.list(wrapper);
|
|
|
+ }
|
|
|
+
|
|
|
+ public String pointInfos2Keys(List<PointInfo> entity) {
|
|
|
+ return entity.stream().map(PointInfo::getPointKey).collect(Collectors.joining(","));
|
|
|
+ }
|
|
|
+
|
|
|
+ public void calcStationHourPJGL(Date hour) {
|
|
|
+ PointInfo pointInfo = new PointInfo();
|
|
|
+ pointInfo.setInstitutionType("station");
|
|
|
+ pointInfo.setUniformCode("SSZGL");
|
|
|
+ List<PointInfo> entity = pointService.getByEntity(pointInfo);
|
|
|
+ List<StationInfoHour> byHours = getStationinfoByHour(hour);
|
|
|
+ Map<String, StationInfoHour> collect = new HashMap<>();
|
|
|
+ if (byHours.size() > 0) {
|
|
|
+ collect = byHours.stream().collect(
|
|
|
+ Collectors.toMap(StationInfoHour::getStationId, Function.identity()));
|
|
|
+ }
|
|
|
+ List<DoubleStatData> stat;
|
|
|
+ List<StationInfoHour> byHours2 = new ArrayList<>();
|
|
|
+ for (PointInfo point : entity) {
|
|
|
+ stat = adapter.getHistoryStat(taosGoldenUriTest(),
|
|
|
+ point.getPointKey(), DateUtil.offsetHour(hour, -1).getTime(), hour.getTime());
|
|
|
+ if (byHours.isEmpty()) {
|
|
|
+ StationInfoHour info = new StationInfoHour();
|
|
|
+ info.setStationId(point.getStationId());
|
|
|
+ info.setRecordDate(DateUtil.beginOfHour(hour));
|
|
|
+ if (stat.isEmpty()) info.setPjgl(0.0);
|
|
|
+ info.setPjgl(stat.get(0).getAvg().getDoubleValue());
|
|
|
+ byHours2.add(info);
|
|
|
+ } else {
|
|
|
+ collect.get(point.getStationId()).setPjgl(stat.get(0).getAvg().getDoubleValue());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ stationInfoHourService.saveOrUpdateBatch(byHours.isEmpty() ? byHours2 : byHours);
|
|
|
+ }
|
|
|
+
|
|
|
+ public void calcLineDjlRfdl(Date date) {
|
|
|
+ //date当天零点
|
|
|
+ DateTime time = DateUtil.beginOfDay(date);
|
|
|
+ //date昨天零点
|
|
|
+ DateTime time0 = DateUtil.offsetDay(time, -1);
|
|
|
+ //date当天零点加三分钟
|
|
|
+ DateTime time2 = DateUtil.offsetMinute(time, 3);
|
|
|
+ //date昨天零点加三分钟
|
|
|
+ DateTime time1 = DateUtil.offsetMinute(time0, 3);
|
|
|
+
|
|
|
+ PointInfo pi = new PointInfo();
|
|
|
+ pi.setUniformCode("Z-ZXYG-JX");
|
|
|
+ pi.setLineId("all");
|
|
|
+ List<PointInfo> entity = pointService.getByEntity(pi);
|
|
|
+ String keys = pointInfos2Keys(entity);
|
|
|
+ Map<String, PointData> latest2 = adapter.getHistorySection(taosGoldenUriTest(), keys, time2.getTime());
|
|
|
+ Map<String, PointData> latest1 = adapter.getHistorySection(taosGoldenUriTest(), keys, time1.getTime());
|
|
|
+
|
|
|
+ List<LineInfoDay> byDate = getLineinfoByDate(time0.toJdkDate());
|
|
|
+ Map<String, LineInfoDay> collect = new HashMap<>();
|
|
|
+ if (byDate.size() > 0) {
|
|
|
+ collect = byDate.stream().collect(Collectors.toMap(LineInfoDay::getLineId, Function.identity()));
|
|
|
+ }
|
|
|
+
|
|
|
+ List<LineInfoDay> list = new ArrayList<>();
|
|
|
+ for (PointInfo info : entity) {
|
|
|
+ LineInfoDay day;
|
|
|
+ if (byDate.isEmpty()) {
|
|
|
+ day = new LineInfoDay();
|
|
|
+ day.setStationId(info.getStationId());
|
|
|
+ day.setProjectId(info.getProjectId());
|
|
|
+ day.setLineId(info.getLineId());
|
|
|
+ day.setRecordDate(time0.toJdkDate());
|
|
|
+ } else {
|
|
|
+ day = collect.get(info.getLineId());
|
|
|
+ }
|
|
|
+ day.setRfdl((int) ((latest2.get(info.getPointKey()).getDoubleValue() -
|
|
|
+ latest1.get(info.getPointKey()).getDoubleValue()) * info.getCoef()));
|
|
|
+ list.add(day);
|
|
|
+ }
|
|
|
+ lineInfoDayService.saveOrUpdateBatch(list);
|
|
|
+ }
|
|
|
+
|
|
|
+ public List<LineInfoDay> getLineinfoByDate(Date date) {
|
|
|
+ QueryWrapper<LineInfoDay> wrapper = new QueryWrapper<>();
|
|
|
+ wrapper.eq("record_date", date);
|
|
|
+ return lineInfoDayService.list(wrapper);
|
|
|
+ }
|
|
|
+
|
|
|
+ public void calcStationSwGwCyDl(Date date) {
|
|
|
+ //date当天零点
|
|
|
+ DateTime time = DateUtil.beginOfDay(date);
|
|
|
+ //date昨天零点
|
|
|
+ DateTime time0 = DateUtil.offsetDay(time, -1);
|
|
|
+ //date当天零点加三分钟
|
|
|
+ DateTime time2 = DateUtil.offsetMinute(time, 3);
|
|
|
+ //date昨天零点加三分钟
|
|
|
+ DateTime time1 = DateUtil.offsetMinute(time0, 3);
|
|
|
+
|
|
|
+ PointInfo swdlPi = new PointInfo();
|
|
|
+ swdlPi.setUniformCode("Z-ZXYG-CX");
|
|
|
+ PointInfo gwdlPi = new PointInfo();
|
|
|
+ gwdlPi.setUniformCode("Z-FXYG-CX");
|
|
|
+ PointInfo cydlPi = new PointInfo();
|
|
|
+ cydlPi.setUniformCode("Z-ZXYG-ZYB");
|
|
|
+
|
|
|
+ List<PointInfo> swdlEt = pointService.getByEntity(swdlPi);
|
|
|
+ List<PointInfo> gwdlEt = pointService.getByEntity(gwdlPi);
|
|
|
+ Map<String, PointInfo> gwdlMap = gwdlEt.stream().collect(Collectors.toMap(PointInfo::getStationId, Function.identity()));
|
|
|
+ List<PointInfo> cydlEt = pointService.getByEntity(cydlPi);
|
|
|
+ Map<String, PointInfo> cydlMap = cydlEt.stream().collect(Collectors.toMap(PointInfo::getStationId, Function.identity()));
|
|
|
+
|
|
|
+ String swdlK = pointInfos2Keys(swdlEt);
|
|
|
+ String gwdlK = pointInfos2Keys(gwdlEt);
|
|
|
+ String cydlK = pointInfos2Keys(cydlEt);
|
|
|
+
|
|
|
+ Map<String, PointData> swdlL2 = adapter.getHistorySection(taosGoldenUriTest(), swdlK, time2.getTime());
|
|
|
+ Map<String, PointData> swdlL1 = adapter.getHistorySection(taosGoldenUriTest(), swdlK, time1.getTime());
|
|
|
+ Map<String, PointData> gwdlL2 = adapter.getHistorySection(taosGoldenUriTest(), gwdlK, time2.getTime());
|
|
|
+ Map<String, PointData> gwdlL1 = adapter.getHistorySection(taosGoldenUriTest(), gwdlK, time1.getTime());
|
|
|
+ Map<String, PointData> cydlL2 = adapter.getHistorySection(taosGoldenUriTest(), cydlK, time2.getTime());
|
|
|
+ Map<String, PointData> cydlL1 = adapter.getHistorySection(taosGoldenUriTest(), cydlK, time1.getTime());
|
|
|
+
|
|
|
+ List<StationInfoDay> byDate = getStationinfoByDate(time0.toJdkDate());
|
|
|
+ Map<String, StationInfoDay> collect = new HashMap<>();
|
|
|
+ if (byDate.size() > 0) {
|
|
|
+ collect = byDate.stream().collect(Collectors.toMap(StationInfoDay::getStationId, Function.identity()));
|
|
|
+ }
|
|
|
+ StationInfoDay infoDay;
|
|
|
+ String stationId;
|
|
|
+ PointInfo gwdlKey, cydlKey;
|
|
|
+ List<StationInfoDay> infoDays = new ArrayList<>();
|
|
|
+ for (PointInfo info : swdlEt) {
|
|
|
+ stationId = info.getStationId();
|
|
|
+ if (byDate.isEmpty()) {
|
|
|
+ infoDay = new StationInfoDay();
|
|
|
+ infoDay.setStationId(stationId);
|
|
|
+ infoDay.setRecordDate(time0.toJdkDate());
|
|
|
+ } else {
|
|
|
+ infoDay = collect.get(stationId);
|
|
|
+ }
|
|
|
+ infoDay.setSwdl((int) ((swdlL2.get(info.getPointKey()).getDoubleValue() -
|
|
|
+ swdlL1.get(info.getPointKey()).getDoubleValue()) * info.getCoef()));
|
|
|
+ gwdlKey = gwdlMap.get(stationId);
|
|
|
+ infoDay.setGwdl((int) ((gwdlL2.get(gwdlKey.getPointKey()).getDoubleValue() -
|
|
|
+ gwdlL1.get(gwdlKey.getPointKey()).getDoubleValue()) * gwdlKey.getCoef()));
|
|
|
+ cydlKey = cydlMap.get(stationId);
|
|
|
+ infoDay.setCydl((int) ((cydlL2.get(cydlKey.getPointKey()).getDoubleValue() -
|
|
|
+ cydlL1.get(cydlKey.getPointKey()).getDoubleValue()) * cydlKey.getCoef()));
|
|
|
+ infoDays.add(infoDay);
|
|
|
+ }
|
|
|
+ stationInfoDayService.saveOrUpdateBatch(infoDays);
|
|
|
+ }
|
|
|
+
|
|
|
+ public void calcStationZhcydl(Date date) {
|
|
|
+ //date当天零点
|
|
|
+ DateTime time = DateUtil.beginOfDay(date);
|
|
|
+ //date昨天零点
|
|
|
+ DateTime time0 = DateUtil.offsetDay(time, -1);
|
|
|
+
|
|
|
+ QueryWrapper<LineInfoDay> wrapper = new QueryWrapper<>();
|
|
|
+ wrapper.select("sum(rfdl) rfdl,station_id").eq("record_date", time0.toJdkDate())
|
|
|
+ .groupBy("station_id");
|
|
|
+ List<LineInfoDay> list = lineInfoDayService.list(wrapper);
|
|
|
+ List<StationInfoDay> byDate = getStationinfoByDate(time0.toJdkDate());
|
|
|
+
|
|
|
+ Map<String, StationInfoDay> collect = new HashMap<>();
|
|
|
+ if (byDate.size() > 0) {
|
|
|
+ collect = byDate.stream().collect(Collectors.toMap(StationInfoDay::getStationId, Function.identity()));
|
|
|
+ }
|
|
|
+
|
|
|
+ StationInfoDay infoDay;
|
|
|
+ List<StationInfoDay> infoDays = new ArrayList<>();
|
|
|
+ for (LineInfoDay day : list) {
|
|
|
+ if (byDate.isEmpty()) {
|
|
|
+ infoDay = new StationInfoDay();
|
|
|
+ infoDay.setStationId(day.getStationId());
|
|
|
+ infoDay.setRecordDate(time0.toJdkDate());
|
|
|
+ } else {
|
|
|
+ infoDay = collect.get(day.getStationId());
|
|
|
+ }
|
|
|
+ infoDay.setRfdl(day.getRfdl());
|
|
|
+ infoDay.setZhcydl(infoDay.getRfdl() + infoDay.getGwdl() - infoDay.getSwdl());
|
|
|
+ infoDays.add(infoDay);
|
|
|
+ }
|
|
|
+ stationInfoDayService.saveOrUpdateBatch(infoDays);
|
|
|
+ }
|
|
|
+
|
|
|
+ //此处加公式
|
|
|
+ public void calcTurbineSsztAi(Date date) {
|
|
|
+ PointInfo pi = new PointInfo();
|
|
|
+ pi.setUniformCode("AI422");
|
|
|
+ pi.setInstitutionType("state");
|
|
|
+ List<PointInfo> entity = pointService.getByEntity(pi);
|
|
|
+ Map<String, PointInfo> collect = entity.stream().collect(Collectors.toMap(PointInfo::getTurbineId, Function.identity()));
|
|
|
+ String keys = pointInfos2Keys(entity);
|
|
|
+
|
|
|
+ PointInfo pimx = new PointInfo();
|
|
|
+ pimx.setUniformCode("MXZT");
|
|
|
+ pimx.setInstitutionType("turbine");
|
|
|
+ List<PointInfo> entityMx = pointService.getByEntity(pimx);
|
|
|
+ Map<String, PointInfo> collectMX = entityMx.stream().collect(Collectors.toMap(PointInfo::getTurbineId, Function.identity()));
|
|
|
+ PointInfo pisb = new PointInfo();
|
|
|
+ pisb.setUniformCode("SBZT");
|
|
|
+ pisb.setInstitutionType("turbine");
|
|
|
+ List<PointInfo> entitySB = pointService.getByEntity(pimx);
|
|
|
+ Map<String, PointInfo> collectSB = entitySB.stream().collect(Collectors.toMap(PointInfo::getTurbineId, Function.identity()));
|
|
|
+
|
|
|
+ Map<String, PointData> latest = adapter.getLatest(taosGoldenUriTest(), keys);
|
|
|
+ List<StateAi> list = stateAiService.list();
|
|
|
+ Map<String, Map<Integer, Integer>> collectAi = list.stream().collect(Collectors.groupingBy(StateAi::getModel, Collectors.toMap(StateAi::getOriginalState, StateAi::getMappingState)));
|
|
|
+
|
|
|
+ List<PointData> pointDatas = new ArrayList<>();
|
|
|
+ int i1;
|
|
|
+ for (PointInfo info : entity) {
|
|
|
+ PointData data = latest.get(info.getPointKey());
|
|
|
+ data.setTagName(collectMX.get(info.getTurbineId()).getPointKey());
|
|
|
+ i1 = (int) data.getDoubleValue();
|
|
|
+ //缓存值
|
|
|
+ Integer i2 = ChangedSave.map.get(info.getPointKey());
|
|
|
+ if (i2 != null && i1 == i2) continue;
|
|
|
+ ChangedSave.map.put(info.getPointKey(), i1);
|
|
|
+ Integer i = collectAi.get(info.getSpare()).get(i1);
|
|
|
+ data.setDoubleValue(i);
|
|
|
+ pointDatas.add(data);
|
|
|
+ }
|
|
|
+ adapter.writeHistoryBatch(taosGoldenUriTest(), pointDatas);
|
|
|
+
|
|
|
+ //redisTemplate.opsForHash().put("state_point",key,value);
|
|
|
+
|
|
|
+ }
|
|
|
+ public void calcStationXd(){
|
|
|
+ DateTime time = DateUtil.date();
|
|
|
+ DateTime time5 = DateUtil.offsetMinute(DateUtil.date(), -5);
|
|
|
+ //限电状态
|
|
|
+ PointInfo pi = new PointInfo();
|
|
|
+ pi.setUniformCode("AGC009");
|
|
|
+ pi.setInstitutionType("booster");
|
|
|
+ List<PointInfo> entity = pointService.getByEntity(pi);
|
|
|
+ Map<String, PointInfo> collect = entity.stream().collect(Collectors.toMap(PointInfo::getTurbineId, Function.identity()));
|
|
|
+ String keys = pointInfos2Keys(entity);
|
|
|
+
|
|
|
+ //自算功率
|
|
|
+ PointInfo piZg = new PointInfo();
|
|
|
+ piZg.setUniformCode("AGC010");
|
|
|
+ piZg.setInstitutionType("booster");
|
|
|
+ List<PointInfo> entityZg = pointService.getByEntity(piZg);
|
|
|
+ Map<String, PointInfo> collectZg = entityZg.stream().collect(Collectors.toMap(PointInfo::getTurbineId, Function.identity()));
|
|
|
+ String keysZg = pointInfos2Keys(entityZg);
|
|
|
+
|
|
|
+ Map<String, PointData> latest = adapter.getLatest(taosGoldenUriTest(), keys);
|
|
|
+ List<DoubleStatData> statZg = adapter.getHistoryStat(taosGoldenUriTest(), keysZg, time5.getTime(), time.getTime());
|
|
|
+
|
|
|
+ for (PointInfo info : entity) {
|
|
|
+ PointData xdzt = latest.get(info.getPointKey());
|
|
|
+ //如果场站限电状态为0
|
|
|
+ if(xdzt==null||xdzt.getDoubleValue()==0.0){
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|