|
@@ -11,6 +11,7 @@ import com.ruoyi.ucp.feign.AdapterApi;
|
|
|
import com.ruoyi.ucp.service.IHistoryPredictService;
|
|
|
import com.ruoyi.ucp.service.IPointInfoService;
|
|
|
import com.ruoyi.ucp.service.IRealtimePredictService;
|
|
|
+import com.ruoyi.ucp.service.IStationInfoMinService;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
@@ -22,7 +23,7 @@ import java.util.concurrent.ConcurrentHashMap;
|
|
|
import java.util.function.Function;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
-//@RestController
|
|
|
+@RestController
|
|
|
@RequestMapping("/predict")
|
|
|
public class PredictController {
|
|
|
|
|
@@ -36,6 +37,8 @@ public class PredictController {
|
|
|
private IRealtimePredictService realtimePredictService;
|
|
|
@Resource
|
|
|
private IHistoryPredictService historyPredictService;
|
|
|
+ @Resource
|
|
|
+ private IStationInfoMinService stationInfoMinService;
|
|
|
|
|
|
private Map<String, PointInfo> tbInfos = new ConcurrentHashMap<>();
|
|
|
|
|
@@ -299,6 +302,78 @@ public class PredictController {
|
|
|
});
|
|
|
return result;
|
|
|
}
|
|
|
+ @GetMapping("/snap/station/dq")
|
|
|
+ public List<StationInfoMin> latestStationDq(@RequestParam(value = "stationId",required = false) String stationId,
|
|
|
+ @RequestParam(value = "beginTime",required = false) String beginTime,
|
|
|
+ @RequestParam(value = "endTime",required = false) String endTime) {
|
|
|
+
|
|
|
+ DateTime begin = DateUtil.parse(beginTime);
|
|
|
+ DateTime middle = DateUtil.parse("2024-11-03");
|
|
|
+ DateTime end = DateUtil.parse(endTime);
|
|
|
+ QueryWrapper<StationInfoMin> minWrapper = new QueryWrapper<>();
|
|
|
+ minWrapper.lambda().eq(StationInfoMin::getStationId,stationId).between(StationInfoMin::getRecordDate,begin,middle)
|
|
|
+ .orderByAsc(StationInfoMin::getRecordDate);
|
|
|
+ List<StationInfoMin> list = stationInfoMinService.list(minWrapper);
|
|
|
+// List<StationInfoMin> min=new ArrayList<>();
|
|
|
+ int i = 1;
|
|
|
+ DateTime minBegin = middle, minEnd = DateUtil.offsetMinute(middle, 15);
|
|
|
+ while (minEnd.isBefore(end)) {
|
|
|
+ minEnd = DateUtil.offsetMinute(middle, i * 15);
|
|
|
+ StationInfoMin day = task.calcStationSjglAgcPjfsHjwdDlMin2(minBegin, minEnd, stationId);
|
|
|
+ System.out.println(minBegin.toString() + "," + minEnd.toString());
|
|
|
+ i++;
|
|
|
+ minBegin = minEnd;
|
|
|
+ list.add(day);
|
|
|
+ }
|
|
|
+
|
|
|
+ return list;
|
|
|
+ }
|
|
|
+ @GetMapping("/latest/station/dq")
|
|
|
+ public StationInfoMin latestStationDq(@RequestParam(value = "stationId",required = false) String stationId) {
|
|
|
+ DateTime date = DateUtil.beginOfMinute(DateUtil.date());
|
|
|
+ int i = Math.floorDiv(date.minute(), 15) * 15;
|
|
|
+ date.setMinutes(i);
|
|
|
+ DateTime minute = DateUtil.offsetMinute(date, -15);
|
|
|
+ return task.calcStationSjglAgcPjfsHjwdDlMin2(minute, date, stationId);
|
|
|
+ }
|
|
|
+ @GetMapping("/latest/station/dq2")
|
|
|
+ public StationInfoMin latestStationDq2(@RequestParam(value = "stationId",required = false) String stationId) {
|
|
|
+ DateTime date = DateUtil.beginOfMinute(DateUtil.date());
|
|
|
+ int i = Math.floorDiv(date.minute(), 15) * 15;
|
|
|
+ date.setMinutes(i);
|
|
|
+ DateTime minute = DateUtil.offsetMinute(date, -15);
|
|
|
+ //AGC
|
|
|
+ PointInfo entityAgc = getEntity("AGC002", "booster",stationId);
|
|
|
+ getLatestByEntity(entityAgc);
|
|
|
+ //出线
|
|
|
+ PointInfo entityCx = getEntity("AGC001", "booster",stationId);
|
|
|
+ getRawDataByEntity(entityCx,minute,date);
|
|
|
+ //风速
|
|
|
+ List<PointInfo> entityFs = getEntitys("AI066", "turbine",stationId);
|
|
|
+ getRawDataByEntity(entityFs,minute,date);
|
|
|
+ //环境温度
|
|
|
+ List<PointInfo> entityHjwd = getEntitys("AI072", "turbine",stationId);
|
|
|
+ getLatestByEntity(entityHjwd);
|
|
|
+ //日发电量
|
|
|
+ PointInfo entity = getEntity("Z-ZXYG-JX", "meter",stationId);
|
|
|
+ getSectionDataByEntity(entity,minute,date);
|
|
|
+
|
|
|
+ StationInfoMin day = new StationInfoMin();
|
|
|
+ day.setStationId(stationId);
|
|
|
+ day.setRecordDate(date);
|
|
|
+ double pjfs = entityFs.stream().mapToDouble(pi -> pi.getPointDatas().stream().mapToDouble(PointData::getValue).average().orElse(0.0)).average().orElse(0);
|
|
|
+ day.setPjfs(pjfs);
|
|
|
+ double cxgl = entityCx.getPointDatas().stream().mapToDouble(PointData::getValue).average().orElse(0.0);
|
|
|
+ cxgl = cxgl * entityCx.getCoef();
|
|
|
+ day.setPjgl(cxgl);
|
|
|
+ double agc = entityAgc.getPointDatas().get(0).getValue() * entityAgc.getCoef();
|
|
|
+ day.setAgc(agc);
|
|
|
+ double rfdl = (entity.getPointDatas().get(1).getValue() - entity.getPointDatas().get(0).getValue()) * entity.getCoef();
|
|
|
+ day.setRfdl(rfdl);
|
|
|
+ double hjwd = entityHjwd.stream().mapToDouble(pi -> pi.getPointDatas().stream().mapToDouble(PointData::getValue).average().orElse(0.0)).average().orElse(0);
|
|
|
+ day.setHjwd(hjwd);
|
|
|
+ return day;
|
|
|
+ }
|
|
|
@GetMapping("/haha2")
|
|
|
public Map<String, Collection<GlycSj>> haha2(@RequestParam(value = "stationId",required = false) String stationId,
|
|
|
@RequestParam(value = "beginTime",required = false) String beginTime,
|
|
@@ -489,7 +564,127 @@ public class PredictController {
|
|
|
}
|
|
|
return true;
|
|
|
}
|
|
|
+ @PostMapping("/write/station/dq")
|
|
|
+ public boolean writeStationDq(@RequestBody Map<String, List<GlycSj2>> data) {
|
|
|
+ try {
|
|
|
+ DateTime date = DateUtil.beginOfMinute(DateUtil.date());
|
|
|
+ int i = Math.floorDiv(date.minute(), 15) * 15;
|
|
|
+ date.setMinutes(i);
|
|
|
+ List<RealtimePredict> rpList = new ArrayList<>();
|
|
|
+ List<HistoryPredict> hpList = new ArrayList<>();
|
|
|
+ List<String> ids=new ArrayList<>();
|
|
|
+ data.forEach((tbId,glycsjs)->{
|
|
|
+ for (GlycSj2 glycsj : glycsjs) {
|
|
|
+ RealtimePredict rp = new RealtimePredict();
|
|
|
+ rp.setId(tbId+glycsj.getTime());
|
|
|
+ ids.add(rp.getId());
|
|
|
+ rp.setModelId("1");
|
|
|
+ rp.setPredictType("DQ");
|
|
|
+ rp.setDeviceType("station");
|
|
|
+ rp.setTime(DateUtil.parseDateTime(glycsj.getTime()));
|
|
|
+ rp.setSiteId(tbId);
|
|
|
+ rp.setPredictPower(glycsj.getPower());
|
|
|
+ rp.setPredictEnergy(glycsj.getEnergy());
|
|
|
+ rpList.add(rp);
|
|
|
+ HistoryPredict hp = new HistoryPredict();
|
|
|
+ hp.setModelId("1");
|
|
|
+ hp.setPredictType("DQ");
|
|
|
+ hp.setDeviceType("station");
|
|
|
+ hp.setDataTime(date);
|
|
|
+ hp.setPredictTime(DateUtil.parseDateTime(glycsj.getTime()));
|
|
|
+ hp.setSiteId(tbId);
|
|
|
+ hp.setPredictPower(glycsj.getPower());
|
|
|
+ hp.setPredictEnergy(glycsj.getEnergy());
|
|
|
+ hpList.add(hp);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ realtimePredictService.removeBatchByIds(ids);
|
|
|
+ realtimePredictService.saveBatch(rpList);
|
|
|
+ historyPredictService.saveBatch(hpList);
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ return true;
|
|
|
+ }
|
|
|
//2024-11-2 00:00:00 ---2024-11-2 00:15:00,2024-11-2 00:30:00,2024-11-2 00:45:00
|
|
|
//2024-11-2 00:15:00 ---2024-11-2 00:30:00,2024-11-2 00:45:00,2024-11-2 01:00:00
|
|
|
//2024-11-2 00:30:00 ---2024-11-2 00:45:00,2024-11-2 01:00:00,2024-11-2 01:15:00
|
|
|
+
|
|
|
+ public StationInfoMin getStationinfoByMin(Date date, String stId) {
|
|
|
+ QueryWrapper<StationInfoMin> wrapper = new QueryWrapper<>();
|
|
|
+ wrapper.eq("record_date", date).eq("station_id", stId);
|
|
|
+ List<StationInfoMin> list = stationInfoMinService.list(wrapper);
|
|
|
+ if (CollUtil.isEmpty(list)) {
|
|
|
+ StationInfoMin day = new StationInfoMin();
|
|
|
+ day.setStationId(stId);
|
|
|
+ day.setRecordDate(date);
|
|
|
+ list.add(day);
|
|
|
+ }
|
|
|
+ return list.get(0);
|
|
|
+ }
|
|
|
+ public PointInfo getEntity(String uniformCode, String institutionType,String stId) {
|
|
|
+ PointInfo pi = new PointInfo();
|
|
|
+ pi.setUniformCode(uniformCode);
|
|
|
+ pi.setInstitutionType(institutionType);
|
|
|
+ pi.setStationId(stId);
|
|
|
+ List<PointInfo> byEntity = pointInfoService.getByEntity(pi);
|
|
|
+ return byEntity.get(0);
|
|
|
+ }
|
|
|
+ public void getRawDataByEntity(List<PointInfo> entity, Date start, Date end) {
|
|
|
+ for (PointInfo info : entity) {
|
|
|
+ List<PointData> snap = adapterApi.getHistoryRaw(goldenUri(), info.getPointKey(), start.getTime(), end.getTime());
|
|
|
+ info.setPointDatas(snap);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ public void getRawDataByEntity(PointInfo entity, Date start, Date end) {
|
|
|
+ List<PointData> snap = adapterApi.getHistoryRaw(goldenUri(), entity.getPointKey(), start.getTime(), end.getTime());
|
|
|
+ entity.setPointDatas(snap);
|
|
|
+ }
|
|
|
+ public List<PointInfo> getEntitys(String uniformCode, String institutionType,String stId) {
|
|
|
+ PointInfo pi = new PointInfo();
|
|
|
+ pi.setUniformCode(uniformCode);
|
|
|
+ pi.setInstitutionType(institutionType);
|
|
|
+ pi.setStationId(stId);
|
|
|
+ return pointInfoService.getByEntity(pi);
|
|
|
+ }
|
|
|
+ public void getSectionDataByEntity(PointInfo entity, Date end) {
|
|
|
+ Map<String, PointData> section = adapterApi.getHistorySection(goldenUri(), entity.getPointKey(), end.getTime());
|
|
|
+ section.forEach((k,v)->{
|
|
|
+ entity.setPointDatas(Collections.singletonList(v));
|
|
|
+ });
|
|
|
+ }
|
|
|
+ public URI goldenUri() {
|
|
|
+ return URI.create("http://172.16.12.103:8011/ts");
|
|
|
+ }
|
|
|
+ public void getLatestByEntity(PointInfo entity) {
|
|
|
+ Map<String, PointData> latest = adapterApi.getLatest(goldenUri(), entity.getPointKey());
|
|
|
+ latest.forEach((k,v)->{
|
|
|
+ entity.setPointDatas(Collections.singletonList(v));
|
|
|
+ });
|
|
|
+ }
|
|
|
+ public void getSectionDataByEntity(List<PointInfo> entitys, Date start, Date end) {
|
|
|
+ String collect = entitys.stream().map(PointInfo::getPointKey).collect(Collectors.joining(","));
|
|
|
+ Map<String, PointData> section0 = adapterApi.getHistorySection(goldenUri(), collect, start.getTime());
|
|
|
+ Map<String, PointData> section1 = adapterApi.getHistorySection(goldenUri(), collect, end.getTime());
|
|
|
+ for (PointInfo entity : entitys) {
|
|
|
+ entity.setPointDatas(new ArrayList<>());
|
|
|
+ entity.getPointDatas().add(section0.get(entity.getPointKey()));
|
|
|
+ entity.getPointDatas().add(section1.get(entity.getPointKey()));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ public void getSectionDataByEntity(PointInfo entity, Date start, Date end) {
|
|
|
+ Map<String, PointData> section0 = adapterApi.getHistorySection(goldenUri(), entity.getPointKey(), start.getTime());
|
|
|
+ Map<String, PointData> section1 = adapterApi.getHistorySection(goldenUri(), entity.getPointKey(), end.getTime());
|
|
|
+ entity.setPointDatas(new ArrayList<>());
|
|
|
+ entity.getPointDatas().add(section0.get(entity.getPointKey()));
|
|
|
+ entity.getPointDatas().add(section1.get(entity.getPointKey()));
|
|
|
+ }
|
|
|
+ public void getLatestByEntity(List<PointInfo> entity) {
|
|
|
+ String collect = entity.stream().map(PointInfo::getPointKey).collect(Collectors.joining(","));
|
|
|
+ Map<String, PointData> latest = adapterApi.getLatest(goldenUri(), collect);
|
|
|
+ entity.forEach(e -> {
|
|
|
+ e.setPointDatas(Collections.singletonList(latest.get(e.getPointKey())));
|
|
|
+ });
|
|
|
+ }
|
|
|
}
|