JavaFunctionJobHandler.java 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538
  1. package com.ruoyi;
  2. import cn.hutool.core.collection.CollUtil;
  3. import cn.hutool.core.date.DateTime;
  4. import cn.hutool.core.date.DateUtil;
  5. import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
  6. import com.ruoyi.quartz.handler.IJobHandler;
  7. import com.ruoyi.quartz.task.ChangedSave;
  8. import com.ruoyi.ucp.entity.*;
  9. import com.ruoyi.ucp.feign.AdapterApi;
  10. import com.ruoyi.ucp.service.*;
  11. import com.ruoyi.ucp.util.CalcCache;
  12. import org.springframework.data.redis.core.RedisTemplate;
  13. import javax.annotation.Resource;
  14. import java.net.URI;
  15. import java.util.*;
  16. import java.util.function.Function;
  17. import java.util.stream.Collectors;
  18. public class JavaFunctionJobHandler extends IJobHandler {
  19. @Resource
  20. private AdapterApi adapter;
  21. @Resource
  22. private IPointInfoService pointService;
  23. @Resource
  24. private IStationInfoHourService stationInfoHourService;
  25. @Resource
  26. private IStationInfoDayService stationInfoDayService;
  27. @Resource
  28. private ILineInfoDayService lineInfoDayService;
  29. @Resource
  30. private IStateAiService stateAiService;
  31. @Resource
  32. private RedisTemplate redisTemplate;
  33. @Resource
  34. private IEquipmentModelService equipmentModelService;
  35. @Resource
  36. private ITurbineInfoDayService turbineInfoDayService;
  37. @Override
  38. public void execute() throws Exception {
  39. }
  40. @Override
  41. public IJobHandler getFunctionHandler() {
  42. return null;
  43. }
  44. @Override
  45. public void setFunctionHandler(IJobHandler jobHandler) {
  46. }
  47. public void calcAQTS(Date date) {
  48. QueryWrapper<StationInfoDay> wrapper = new QueryWrapper<>();
  49. wrapper.select("min(record_date) record_date");
  50. StationInfoDay one = stationInfoDayService.getOne(wrapper);
  51. wrapper = new QueryWrapper<>();
  52. wrapper.eq("record_date", one.getRecordDate());
  53. //最早时间的列表
  54. List<StationInfoDay> list = stationInfoDayService.list(wrapper);
  55. List<StationInfoDay> today = getStationinfoByDate(date);
  56. if (today.isEmpty()) {
  57. for (StationInfoDay infoDay : list) {
  58. StationInfoDay day = new StationInfoDay();
  59. day.setStationId(infoDay.getStationId());
  60. day.setRecordDate(date);
  61. day.setAqts(infoDay.getAqts() + (int) DateUtil.betweenDay(infoDay.getRecordDate(), date, true));
  62. today.add(day);
  63. }
  64. } else {
  65. Map<String, StationInfoDay> collect = list.stream().collect(Collectors.toMap(StationInfoDay::getStationId, Function.identity()));
  66. for (StationInfoDay day : today) {
  67. StationInfoDay day1 = collect.get(day.getStationId());
  68. day.setAqts(day1.getAqts() + (int) DateUtil.betweenDay(day1.getRecordDate(), date, true));
  69. }
  70. }
  71. stationInfoDayService.saveOrUpdateBatch(today);
  72. }
  73. public List<StationInfoDay> getStationinfoByDate(Date date) {
  74. QueryWrapper<StationInfoDay> wrapper = new QueryWrapper<>();
  75. wrapper.eq("record_date", date);
  76. return stationInfoDayService.list(wrapper);
  77. }
  78. public URI taosGoldenUriTest() {
  79. return URI.create("http://127.0.0.1:8011/ts");
  80. }
  81. public URI taosUri() {
  82. return URI.create("http://172.16.12.101:8012/ts");
  83. }
  84. public void calcStationHourRFDL(Date hour) {
  85. PointInfo pointInfo = new PointInfo();
  86. pointInfo.setInstitutionType("station");
  87. pointInfo.setUniformCode("RFDLSYZ");
  88. List<PointInfo> entity = pointService.getByEntity(pointInfo);
  89. Map<String, PointData> section = adapter.getHistorySection(taosGoldenUriTest()
  90. , pointInfos2Keys(entity), hour.getTime());
  91. List<StationInfoHour> byHours = getStationinfoByHour(hour);
  92. if (byHours.isEmpty()) {
  93. for (PointInfo point : entity) {
  94. StationInfoHour info = new StationInfoHour();
  95. info.setStationId(point.getStationId());
  96. info.setRecordDate(DateUtil.beginOfHour(hour));
  97. info.setRfdl(section.get(point.getPointKey()).getDoubleValue());
  98. byHours.add(info);
  99. }
  100. } else {
  101. Map<String, String> collect = entity.stream().collect(Collectors.toMap(PointInfo::getStationId, PointInfo::getPointKey));
  102. for (StationInfoHour byHour : byHours) {
  103. byHour.setRfdl(section.get(collect.get(byHour.getStationId())).getDoubleValue());
  104. }
  105. }
  106. stationInfoHourService.saveOrUpdateBatch(byHours);
  107. }
  108. public List<StationInfoHour> getStationinfoByHour(Date hour) {
  109. QueryWrapper<StationInfoHour> wrapper = new QueryWrapper<>();
  110. wrapper.eq("record_date", DateUtil.beginOfHour(hour));
  111. return stationInfoHourService.list(wrapper);
  112. }
  113. public String pointInfos2Keys(List<PointInfo> entity) {
  114. return entity.stream().map(PointInfo::getPointKey).collect(Collectors.joining(","));
  115. }
  116. public void calcStationHourPJGL(Date hour) {
  117. PointInfo pointInfo = new PointInfo();
  118. pointInfo.setInstitutionType("station");
  119. pointInfo.setUniformCode("SSZGL");
  120. List<PointInfo> entity = pointService.getByEntity(pointInfo);
  121. List<StationInfoHour> byHours = getStationinfoByHour(hour);
  122. Map<String, StationInfoHour> collect = new HashMap<>();
  123. if (byHours.size() > 0) {
  124. collect = byHours.stream().collect(
  125. Collectors.toMap(StationInfoHour::getStationId, Function.identity()));
  126. }
  127. List<DoubleStatData> stat;
  128. List<StationInfoHour> byHours2 = new ArrayList<>();
  129. for (PointInfo point : entity) {
  130. stat = adapter.getHistoryStat(taosGoldenUriTest(),
  131. point.getPointKey(), DateUtil.offsetHour(hour, -1).getTime(), hour.getTime());
  132. if (byHours.isEmpty()) {
  133. StationInfoHour info = new StationInfoHour();
  134. info.setStationId(point.getStationId());
  135. info.setRecordDate(DateUtil.beginOfHour(hour));
  136. if (stat.isEmpty()) info.setPjgl(0.0);
  137. info.setPjgl(stat.get(0).getAvg().getDoubleValue());
  138. byHours2.add(info);
  139. } else {
  140. collect.get(point.getStationId()).setPjgl(stat.get(0).getAvg().getDoubleValue());
  141. }
  142. }
  143. stationInfoHourService.saveOrUpdateBatch(byHours.isEmpty() ? byHours2 : byHours);
  144. }
  145. public void calcLineDjlRfdl(Date date) {
  146. //date当天零点
  147. DateTime time = DateUtil.beginOfDay(date);
  148. //date昨天零点
  149. DateTime time0 = DateUtil.offsetDay(time, -1);
  150. //date当天零点加三分钟
  151. DateTime time2 = DateUtil.offsetMinute(time, 3);
  152. //date昨天零点加三分钟
  153. DateTime time1 = DateUtil.offsetMinute(time0, 3);
  154. PointInfo pi = new PointInfo();
  155. pi.setUniformCode("Z-ZXYG-JX");
  156. pi.setLineId("all");
  157. List<PointInfo> entity = pointService.getByEntity(pi);
  158. String keys = pointInfos2Keys(entity);
  159. Map<String, PointData> latest2 = adapter.getHistorySection(taosGoldenUriTest(), keys, time2.getTime());
  160. Map<String, PointData> latest1 = adapter.getHistorySection(taosGoldenUriTest(), keys, time1.getTime());
  161. List<LineInfoDay> byDate = getLineinfoByDate(time0.toJdkDate());
  162. Map<String, LineInfoDay> collect = new HashMap<>();
  163. if (byDate.size() > 0) {
  164. collect = byDate.stream().collect(Collectors.toMap(LineInfoDay::getLineId, Function.identity()));
  165. }
  166. List<LineInfoDay> list = new ArrayList<>();
  167. for (PointInfo info : entity) {
  168. LineInfoDay day;
  169. if (byDate.isEmpty()) {
  170. day = new LineInfoDay();
  171. day.setStationId(info.getStationId());
  172. day.setProjectId(info.getProjectId());
  173. day.setLineId(info.getLineId());
  174. day.setRecordDate(time0.toJdkDate());
  175. } else {
  176. day = collect.get(info.getLineId());
  177. }
  178. day.setRfdl((int) ((latest2.get(info.getPointKey()).getDoubleValue() -
  179. latest1.get(info.getPointKey()).getDoubleValue()) * info.getCoef()));
  180. list.add(day);
  181. }
  182. lineInfoDayService.saveOrUpdateBatch(list);
  183. }
  184. public List<LineInfoDay> getLineinfoByDate(Date date) {
  185. QueryWrapper<LineInfoDay> wrapper = new QueryWrapper<>();
  186. wrapper.eq("record_date", date);
  187. return lineInfoDayService.list(wrapper);
  188. }
  189. public void calcStationSwGwCyDl(Date date) {
  190. //date当天零点
  191. DateTime time = DateUtil.beginOfDay(date);
  192. //date昨天零点
  193. DateTime time0 = DateUtil.offsetDay(time, -1);
  194. //date当天零点加三分钟
  195. DateTime time2 = DateUtil.offsetMinute(time, 3);
  196. //date昨天零点加三分钟
  197. DateTime time1 = DateUtil.offsetMinute(time0, 3);
  198. PointInfo swdlPi = new PointInfo();
  199. swdlPi.setUniformCode("Z-ZXYG-CX");
  200. PointInfo gwdlPi = new PointInfo();
  201. gwdlPi.setUniformCode("Z-FXYG-CX");
  202. PointInfo cydlPi = new PointInfo();
  203. cydlPi.setUniformCode("Z-ZXYG-ZYB");
  204. List<PointInfo> swdlEt = pointService.getByEntity(swdlPi);
  205. List<PointInfo> gwdlEt = pointService.getByEntity(gwdlPi);
  206. Map<String, PointInfo> gwdlMap = gwdlEt.stream().collect(Collectors.toMap(PointInfo::getStationId, Function.identity()));
  207. List<PointInfo> cydlEt = pointService.getByEntity(cydlPi);
  208. Map<String, PointInfo> cydlMap = cydlEt.stream().collect(Collectors.toMap(PointInfo::getStationId, Function.identity()));
  209. String swdlK = pointInfos2Keys(swdlEt);
  210. String gwdlK = pointInfos2Keys(gwdlEt);
  211. String cydlK = pointInfos2Keys(cydlEt);
  212. Map<String, PointData> swdlL2 = adapter.getHistorySection(taosGoldenUriTest(), swdlK, time2.getTime());
  213. Map<String, PointData> swdlL1 = adapter.getHistorySection(taosGoldenUriTest(), swdlK, time1.getTime());
  214. Map<String, PointData> gwdlL2 = adapter.getHistorySection(taosGoldenUriTest(), gwdlK, time2.getTime());
  215. Map<String, PointData> gwdlL1 = adapter.getHistorySection(taosGoldenUriTest(), gwdlK, time1.getTime());
  216. Map<String, PointData> cydlL2 = adapter.getHistorySection(taosGoldenUriTest(), cydlK, time2.getTime());
  217. Map<String, PointData> cydlL1 = adapter.getHistorySection(taosGoldenUriTest(), cydlK, time1.getTime());
  218. List<StationInfoDay> byDate = getStationinfoByDate(time0.toJdkDate());
  219. Map<String, StationInfoDay> collect = new HashMap<>();
  220. if (byDate.size() > 0) {
  221. collect = byDate.stream().collect(Collectors.toMap(StationInfoDay::getStationId, Function.identity()));
  222. }
  223. StationInfoDay infoDay;
  224. String stationId;
  225. PointInfo gwdlKey, cydlKey;
  226. List<StationInfoDay> infoDays = new ArrayList<>();
  227. for (PointInfo info : swdlEt) {
  228. stationId = info.getStationId();
  229. if (byDate.isEmpty()) {
  230. infoDay = new StationInfoDay();
  231. infoDay.setStationId(stationId);
  232. infoDay.setRecordDate(time0.toJdkDate());
  233. } else {
  234. infoDay = collect.get(stationId);
  235. }
  236. infoDay.setSwdl((int) ((swdlL2.get(info.getPointKey()).getDoubleValue() -
  237. swdlL1.get(info.getPointKey()).getDoubleValue()) * info.getCoef()));
  238. gwdlKey = gwdlMap.get(stationId);
  239. infoDay.setGwdl((int) ((gwdlL2.get(gwdlKey.getPointKey()).getDoubleValue() -
  240. gwdlL1.get(gwdlKey.getPointKey()).getDoubleValue()) * gwdlKey.getCoef()));
  241. cydlKey = cydlMap.get(stationId);
  242. infoDay.setCydl((int) ((cydlL2.get(cydlKey.getPointKey()).getDoubleValue() -
  243. cydlL1.get(cydlKey.getPointKey()).getDoubleValue()) * cydlKey.getCoef()));
  244. infoDays.add(infoDay);
  245. }
  246. stationInfoDayService.saveOrUpdateBatch(infoDays);
  247. }
  248. public void calcStationZhcydl(Date date) {
  249. //date当天零点
  250. DateTime time = DateUtil.beginOfDay(date);
  251. //date昨天零点
  252. DateTime time0 = DateUtil.offsetDay(time, -1);
  253. QueryWrapper<LineInfoDay> wrapper = new QueryWrapper<>();
  254. wrapper.select("sum(rfdl) rfdl,station_id").eq("record_date", time0.toJdkDate())
  255. .groupBy("station_id");
  256. List<LineInfoDay> list = lineInfoDayService.list(wrapper);
  257. List<StationInfoDay> byDate = getStationinfoByDate(time0.toJdkDate());
  258. Map<String, StationInfoDay> collect = new HashMap<>();
  259. if (byDate.size() > 0) {
  260. collect = byDate.stream().collect(Collectors.toMap(StationInfoDay::getStationId, Function.identity()));
  261. }
  262. StationInfoDay infoDay;
  263. List<StationInfoDay> infoDays = new ArrayList<>();
  264. for (LineInfoDay day : list) {
  265. if (byDate.isEmpty()) {
  266. infoDay = new StationInfoDay();
  267. infoDay.setStationId(day.getStationId());
  268. infoDay.setRecordDate(time0.toJdkDate());
  269. } else {
  270. infoDay = collect.get(day.getStationId());
  271. }
  272. infoDay.setRfdl(day.getRfdl());
  273. infoDay.setZhcydl(infoDay.getRfdl() + infoDay.getGwdl() - infoDay.getSwdl());
  274. infoDays.add(infoDay);
  275. }
  276. stationInfoDayService.saveOrUpdateBatch(infoDays);
  277. }
  278. public void calcTurbine5s() {
  279. }
  280. //此处加公式
  281. public void calcTurbineSsztAi(Date date) {
  282. PointInfo pi = new PointInfo();
  283. pi.setUniformCode("AI422");
  284. pi.setInstitutionType("state");
  285. List<PointInfo> entity = pointService.getByEntity(pi);
  286. Map<String, PointInfo> collect = entity.stream().collect(Collectors.toMap(PointInfo::getTurbineId, Function.identity()));
  287. String keys = pointInfos2Keys(entity);
  288. PointInfo pimx = new PointInfo();
  289. pimx.setUniformCode("MXZT");
  290. pimx.setInstitutionType("turbine");
  291. List<PointInfo> entityMx = pointService.getByEntity(pimx);
  292. Map<String, PointInfo> collectMX = entityMx.stream().collect(Collectors.toMap(PointInfo::getTurbineId, Function.identity()));
  293. PointInfo pisb = new PointInfo();
  294. pisb.setUniformCode("SBZT");
  295. pisb.setInstitutionType("turbine");
  296. List<PointInfo> entitySB = pointService.getByEntity(pimx);
  297. Map<String, PointInfo> collectSB = entitySB.stream().collect(Collectors.toMap(PointInfo::getTurbineId, Function.identity()));
  298. Map<String, PointData> latest = adapter.getLatest(taosGoldenUriTest(), keys);
  299. List<StateAi> list = stateAiService.list();
  300. Map<String, Map<Integer, Integer>> collectAi = list.stream().collect(Collectors.groupingBy(StateAi::getModel, Collectors.toMap(StateAi::getOriginalState, StateAi::getMappingState)));
  301. List<PointData> pointDatas = new ArrayList<>();
  302. int i1;
  303. for (PointInfo info : entity) {
  304. PointData data = latest.get(info.getPointKey());
  305. data.setTagName(collectMX.get(info.getTurbineId()).getPointKey());
  306. i1 = (int) data.getDoubleValue();
  307. //缓存值
  308. Integer i2 = ChangedSave.map.get(info.getPointKey());
  309. if (i2 != null && i1 == i2) continue;
  310. ChangedSave.map.put(info.getPointKey(), i1);
  311. Integer i = collectAi.get(info.getSpare()).get(i1);
  312. data.setDoubleValue(i);
  313. pointDatas.add(data);
  314. }
  315. adapter.writeHistoryBatch(taosGoldenUriTest(), pointDatas);
  316. //redisTemplate.opsForHash().put("state_point",key,value);
  317. }
  318. public void calcStationXd(boolean priorRation) {
  319. //限电状态
  320. PointInfo piAgc = new PointInfo();
  321. //AGC
  322. piAgc.setUniformCode("AGC002");
  323. piAgc.setInstitutionType("booster");
  324. List<PointInfo> entityAgc = pointService.getByEntity(piAgc);
  325. Map<String, PointInfo> collectAgc = entityAgc.stream().collect(Collectors.toMap(PointInfo::getTurbineId, Function.identity()));
  326. String keysAgc = pointInfos2Keys(entityAgc);
  327. //出线
  328. PointInfo piCx = new PointInfo();
  329. piCx.setUniformCode("AGC001");
  330. piCx.setInstitutionType("booster");
  331. List<PointInfo> entityCx = pointService.getByEntity(piCx);
  332. Map<String, PointInfo> collectCx = entityCx.stream().collect(Collectors.toMap(PointInfo::getTurbineId, Function.identity()));
  333. String keysCx = pointInfos2Keys(entityCx);
  334. Map<String, PointData> statAgc = adapter.getLatest(goldenUri(), keysAgc);
  335. Map<String, PointData> statCx = adapter.getLatest(goldenUri(), keysCx);
  336. DateTime time5 = DateUtil.offsetMinute(DateUtil.date(), -5);
  337. List<DoubleStatData> statAgc5 = adapter.getHistoryStat(goldenUri(), keysAgc, time5.getTime(), DateUtil.date().getTime());
  338. List<DoubleStatData> statCx5 = adapter.getHistoryStat(goldenUri(), keysCx, time5.getTime(), DateUtil.date().getTime());
  339. //AI066
  340. for (PointInfo info : entityAgc) {
  341. //如果场站限电状态为0
  342. /*if (priorRation) {
  343. if (zsgl5 >= sub.getCapacity() * 0.4) {
  344. if (zsgl / agc > 1.15) {
  345. b = true;
  346. }
  347. if (agc5 <= cxgl5) {
  348. b = true;
  349. }
  350. if (zsgl > agc && agc5 - cxgl5 < 4) {
  351. b = true;
  352. }
  353. }
  354. } else {
  355. if (zsgl5 >= sub.getCapacity() * 0.4) {
  356. if (zsgl / agc >= 1.2 && agc - cxgl <= 2) {
  357. b = true;
  358. }
  359. if (agc5 <= cxgl5) {
  360. b = true;
  361. }
  362. } else {
  363. if (k) {
  364. if (agc5 <= cxgl5) {
  365. b = true;
  366. }
  367. if (zsgl / agc >= 1.1 && agc5 - cxgl5 <= 2) {
  368. b = true;
  369. }
  370. }
  371. }
  372. }*/
  373. }
  374. }
  375. public void calcNhglZs(boolean priorRation) {
  376. //拟合功率(自算)
  377. //实时风速
  378. PointInfo piFs = new PointInfo();
  379. piFs.setUniformCode("AI066");
  380. piFs.setInstitutionType("turbine");
  381. List<PointInfo> entityFs = pointService.getByEntity(piFs);
  382. Map<String, PointInfo> collectFs = entityFs.stream().collect(Collectors.toMap(PointInfo::getTurbineId, Function.identity()));
  383. Map<String, List<PointInfo>> collect = entityFs.stream().collect(Collectors.groupingBy(PointInfo::getStationId));
  384. String keysFs = pointInfos2Keys(entityFs);
  385. //设备拟合功率(自算)
  386. PointInfo piFjzsgl = new PointInfo();
  387. piFjzsgl.setUniformCode("ZSGL");
  388. piFjzsgl.setInstitutionType("turbine");
  389. List<PointInfo> entityFjzsgl = pointService.getByEntity(piFjzsgl);
  390. Map<String, String> collectFjzsgl = entityFjzsgl.stream().collect(Collectors.toMap(PointInfo::getTurbineId, PointInfo::getPointKey));
  391. String keysFjzsgl = pointInfos2Keys(entityFjzsgl);
  392. //场站自算功率
  393. PointInfo piCzzsgl = new PointInfo();
  394. piCzzsgl.setUniformCode("AGC010");
  395. piCzzsgl.setInstitutionType("booster");
  396. List<PointInfo> entityCzzsgl = pointService.getByEntity(piCzzsgl);
  397. Map<String, String> collectCzzsgl = entityCzzsgl.stream().collect(Collectors.toMap(PointInfo::getStationId, PointInfo::getPointKey));
  398. String keysCzzsgl = pointInfos2Keys(entityCzzsgl);
  399. DateTime time = DateUtil.beginOfMinute(DateUtil.date());
  400. DateTime time5 = DateUtil.offsetMinute(time, -5);
  401. List<DoubleStatData> statFs5;
  402. PointData avg;
  403. List<PointData> avgs = new ArrayList<>();
  404. double value, v;
  405. for (Map.Entry<String, List<PointInfo>> entry : collect.entrySet()) {
  406. double stV = 0;
  407. for (PointInfo info : entry.getValue()) {
  408. //todo
  409. statFs5 = adapter.getHistoryStat(goldenUri(), info.getPointKey(), time5.getTime(), time.getTime());
  410. if (CollUtil.isNotEmpty(statFs5)) {
  411. //todo
  412. value = statFs5.get(0).getAvg().getValue();
  413. avg = new PointData();
  414. v = CalcCache.wtMcfMap.get(info.getTurbineId()).get(value);
  415. stV += v;
  416. avg.setTs(time.getTime());
  417. avg.setDoubleValue(v);
  418. avg.setTagName(collectFjzsgl.get(info.getTurbineId()));
  419. avgs.add(avg);
  420. }
  421. }
  422. adapter.writeHistoryBatch(taosUri(), avgs);
  423. PointData data = new PointData();
  424. data.setTs(time.getTime());
  425. data.setDoubleValue(stV);
  426. data.setTagName(collectCzzsgl.get(entry.getKey()));
  427. adapter.writeHistory(taosUri(), data);
  428. }
  429. }
  430. public URI goldenUri() {
  431. return URI.create("http://172.16.12.103:8011/ts");
  432. }
  433. public void calcTurbineRFDL(Date date) {
  434. //date当天零点
  435. DateTime time = DateUtil.beginOfDay(date);
  436. //date昨天零点
  437. DateTime time0 = DateUtil.offsetDay(time, -1);
  438. //date当天零点加三分钟
  439. DateTime time2 = DateUtil.offsetMinute(time, 3);
  440. //date昨天零点加三分钟
  441. DateTime time1 = DateUtil.offsetMinute(time0, 3);
  442. PointInfo pi = new PointInfo();
  443. pi.setUniformCode("AI121");
  444. pi.setInstitutionType("turbine");
  445. List<PointInfo> entity = pointService.getByEntity(pi);
  446. Map<String, String> turMap = entity.stream().collect(Collectors.toMap(PointInfo::getTurbineId, PointInfo::getPointKey));
  447. String keys = pointInfos2Keys(entity);
  448. Map<String, PointData> swdlL2 = adapter.getHistorySection(goldenUri(), keys, time2.getTime());
  449. Map<String, PointData> swdlL1 = adapter.getHistorySection(goldenUri(), keys, time1.getTime());
  450. List<TurbineInfoDay> byDate = getTurbineinfoByDate(time0.toJdkDate());
  451. Map<String, TurbineInfoDay> collect = new HashMap<>();
  452. if (byDate.size() > 0) {
  453. collect = byDate.stream().collect(Collectors.toMap(TurbineInfoDay::getLineId, Function.identity()));
  454. }
  455. TurbineInfoDay infoDay;
  456. String turbineId, key;
  457. List<TurbineInfoDay> infoDays = new ArrayList<>();
  458. for (PointInfo info : entity) {
  459. turbineId = info.getTurbineId();
  460. if (byDate.isEmpty()) {
  461. infoDay = new TurbineInfoDay();
  462. infoDay.setStationId(info.getStationId());
  463. infoDay.setProjectId(info.getProjectId());
  464. infoDay.setLineId(info.getLineId());
  465. infoDay.setTurbineId(turbineId);
  466. infoDay.setRecordDate(time0.toJdkDate());
  467. } else {
  468. infoDay = collect.get(turbineId);
  469. }
  470. key = turMap.get(turbineId);
  471. double v = (swdlL2.get(key).getValue() - swdlL2.get(key).getValue()) * info.getCoef();
  472. if (v < 0 || v > 1000000) v = 0;
  473. infoDay.setRfdl(v);
  474. infoDays.add(infoDay);
  475. }
  476. turbineInfoDayService.saveOrUpdateBatch(infoDays);
  477. }
  478. public List<TurbineInfoDay> getTurbineinfoByDate(Date date) {
  479. QueryWrapper<TurbineInfoDay> wrapper = new QueryWrapper<>();
  480. wrapper.eq("record_date", date);
  481. return turbineInfoDayService.list(wrapper);
  482. }
  483. }