WtAlysisDayService.java 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391
  1. package com.gyee.runeconomy.service;
  2. import cn.hutool.core.util.NumberUtil;
  3. import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
  4. import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
  5. import com.baomidou.mybatisplus.core.metadata.IPage;
  6. import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
  7. import com.gyee.runeconomy.model.auto.ProEconWtAlysisDay;
  8. import com.gyee.runeconomy.model.auto.TurbineInfoDay;
  9. import com.gyee.runeconomy.service.auto.IProEconWtAlysisDayService;
  10. import com.gyee.runeconomy.service.auto.ITurbineInfoDayService;
  11. import com.gyee.runeconomy.util.StringUtils;
  12. import org.springframework.stereotype.Service;
  13. import javax.annotation.Resource;
  14. import java.text.ParseException;
  15. import java.text.SimpleDateFormat;
  16. import java.time.LocalDate;
  17. import java.time.ZoneId;
  18. import java.util.Calendar;
  19. import java.util.Date;
  20. import java.util.List;
  21. import java.util.Map;
  22. import java.util.function.Function;
  23. import java.util.stream.Collectors;
  24. @Service
  25. public class WtAlysisDayService {
  26. @Resource
  27. private IProEconWtAlysisDayService proEconWtAlysisDayService;
  28. @Resource
  29. private ITurbineInfoDayService turbineInfoDayService;
  30. public Page<ProEconWtAlysisDay> wtAlysisDayList(Integer pageNum, Integer pageSize, String wtId, String beginDate, String endDate) {
  31. if (StringUtils.empty(pageNum)) {
  32. pageNum = 1;
  33. }
  34. if (StringUtils.empty(pageSize)) {
  35. pageSize = 10;
  36. }
  37. //构造分页构造器
  38. Page<ProEconWtAlysisDay> pageInfo = new Page<>(pageNum, pageSize);
  39. if (StringUtils.notEmp(wtId) && StringUtils.notEmp(beginDate) && StringUtils.notEmp(endDate)) {
  40. String format = "yyyy-MM-dd";
  41. SimpleDateFormat df = new SimpleDateFormat(format);
  42. Date begin = null;
  43. Date end = null;
  44. try {
  45. begin = df.parse(beginDate);
  46. end = df.parse(endDate);
  47. } catch (ParseException e) {
  48. e.printStackTrace();
  49. }
  50. //构造条件构造器
  51. LambdaQueryWrapper<ProEconWtAlysisDay> queryWrapper = new LambdaQueryWrapper<>();
  52. //添加过滤条件
  53. queryWrapper.eq(ProEconWtAlysisDay::getWindturbineId, wtId).
  54. ge(ProEconWtAlysisDay::getRecordDate, begin).
  55. le(ProEconWtAlysisDay::getRecordDate, end);
  56. queryWrapper.orderByAsc(ProEconWtAlysisDay::getRecordDate);
  57. //执行查询
  58. proEconWtAlysisDayService.page(pageInfo, queryWrapper);
  59. QueryWrapper<TurbineInfoDay> qw = new QueryWrapper<>();
  60. qw.lambda().eq(TurbineInfoDay::getTurbineId, wtId).between(TurbineInfoDay::getRecordDate, begin, end)
  61. .orderByAsc(TurbineInfoDay::getRecordDate);
  62. IPage<TurbineInfoDay> page01 = new Page<>(pageNum, pageSize);
  63. IPage<TurbineInfoDay> page1 = turbineInfoDayService.page(page01, qw);
  64. Map<Date, TurbineInfoDay> dayMap = page1.getRecords().stream().collect(Collectors.toMap(TurbineInfoDay::getRecordDate, Function.identity()));
  65. pageInfo.getRecords().forEach(rsl -> {
  66. TurbineInfoDay day = dayMap.get(rsl.getRecordDate());
  67. Calendar calendar = Calendar.getInstance();
  68. rsl.setRfdl(NumberUtil.round(day.getRfdl() / 1000, 2).doubleValue());
  69. double yfdl = calFdl(rsl.getWindturbineId(), "month", rsl.getRecordDate(), calendar);
  70. rsl.setYfdl(NumberUtil.round(yfdl / 1000, 2).doubleValue());
  71. double nfdl = calFdl(rsl.getWindturbineId(), "year", rsl.getRecordDate(), calendar);
  72. rsl.setNfdl(NumberUtil.round(nfdl / 1000, 2).doubleValue());
  73. rsl.setRpjfs(NumberUtil.round(day.getPjfs(), 2).doubleValue());
  74. double ypjfs = calPjfs(rsl.getWindturbineId(), "month", rsl.getRecordDate(), calendar);
  75. rsl.setYpjfs(NumberUtil.round(ypjfs, 2).doubleValue());
  76. double npjfs = calPjfs(rsl.getWindturbineId(), "year", rsl.getRecordDate(), calendar);
  77. rsl.setNpjfs(NumberUtil.round(npjfs, 2).doubleValue());
  78. double v = day.getGzss() + day.getJhjxss() + day.getXdss() + day.getXnss() + day.getSlss();
  79. rsl.setRssdl(NumberUtil.round(v / 1000, 2).doubleValue());
  80. double yssdl = calSsdl(rsl.getWindturbineId(), "month", rsl.getRecordDate(), calendar);
  81. rsl.setYssdl(NumberUtil.round(yssdl / 1000, 2).doubleValue());
  82. double nssdl = calSsdl(rsl.getWindturbineId(), "year", rsl.getRecordDate(), calendar);
  83. rsl.setNssdl(NumberUtil.round(nssdl / 1000, 2).doubleValue());
  84. rsl.setRgzxs(NumberUtil.round(day.getGzMin() / 60, 2).doubleValue());
  85. double ygzxs = calGzxs(rsl.getWindturbineId(), "month", rsl.getRecordDate(), calendar);
  86. rsl.setYgzxs(NumberUtil.round(ygzxs / 60, 2).doubleValue());
  87. double ngzxs = calGzxs(rsl.getWindturbineId(), "year", rsl.getRecordDate(), calendar);
  88. rsl.setNgzxs(NumberUtil.round(ngzxs / 60, 2).doubleValue());
  89. rsl.setRjxxs(NumberUtil.round(day.getJxMin() / 60, 2).doubleValue());
  90. double yjxxs = calJxxs(rsl.getWindturbineId(), "month", rsl.getRecordDate(), calendar);
  91. rsl.setYjxxs(NumberUtil.round(yjxxs / 60, 2).doubleValue());
  92. double njxxs = calJxxs(rsl.getWindturbineId(), "year", rsl.getRecordDate(), calendar);
  93. rsl.setNjxxs(NumberUtil.round(njxxs / 60, 2).doubleValue());
  94. rsl.setRyxxs(NumberUtil.round(day.getYxMin() / 60, 2).doubleValue());
  95. double yyxxs = calYxxs(rsl.getWindturbineId(), "month", rsl.getRecordDate(), calendar);
  96. rsl.setYyxxs(NumberUtil.round(yyxxs / 60, 2).doubleValue());
  97. double nyxxs = calYxxs(rsl.getWindturbineId(), "year", rsl.getRecordDate(), calendar);
  98. rsl.setNyxxs(NumberUtil.round(nyxxs / 60, 2).doubleValue());
  99. rsl.setRdjxs(NumberUtil.round(day.getDjMin() / 60, 2).doubleValue());
  100. double ydjxs = calDjxs(rsl.getWindturbineId(), "month", rsl.getRecordDate(), calendar);
  101. rsl.setYdjxs(NumberUtil.round(ydjxs / 60, 2).doubleValue());
  102. double ndjxs = calDjxs(rsl.getWindturbineId(), "year", rsl.getRecordDate(), calendar);
  103. rsl.setNdjxs(NumberUtil.round(ndjxs / 60, 2).doubleValue());
  104. rsl.setRtjcs(NumberUtil.round(day.getTjcs(), 2).doubleValue());
  105. double ytjcs = calTjcs(rsl.getWindturbineId(), "month", rsl.getRecordDate(), calendar);
  106. rsl.setYtjcs(NumberUtil.round(ytjcs, 2).doubleValue());
  107. double ntjcs = calTjcs(rsl.getWindturbineId(), "year", rsl.getRecordDate(), calendar);
  108. rsl.setNtjcs(NumberUtil.round(ntjcs, 2).doubleValue());
  109. rsl.setRsbklyl(NumberUtil.round(day.getKlyl(), 2).doubleValue());
  110. double ysbklyl = calSbklyl(rsl.getWindturbineId(), "month", rsl.getRecordDate(), calendar);
  111. rsl.setYsbklyl(NumberUtil.round(ysbklyl, 2).doubleValue());
  112. double nsbklyl = calSbklyl(rsl.getWindturbineId(), "year", rsl.getRecordDate(), calendar);
  113. rsl.setNsbklyl(NumberUtil.round(nsbklyl, 2).doubleValue());
  114. rsl.setRpjwd(NumberUtil.round(day.getHjwd(), 2).doubleValue());
  115. double ypjwd = calPjwd(rsl.getWindturbineId(), "month", rsl.getRecordDate(), calendar);
  116. rsl.setYpjwd(NumberUtil.round(ypjwd, 2).doubleValue());
  117. double npjwd = calPjwd(rsl.getWindturbineId(), "year", rsl.getRecordDate(), calendar);
  118. rsl.setNpjwd(NumberUtil.round(npjwd, 2).doubleValue());
  119. });
  120. }
  121. return pageInfo;
  122. }
  123. public double calSsdl(String windturbineId, String type, Date endDate, Calendar calendar) {
  124. calendar.setTime(endDate);
  125. Date firstDay = null;
  126. if ("month".equals(type)) {
  127. calendar.set(Calendar.DAY_OF_MONTH, 1);
  128. firstDay = calendar.getTime();
  129. } else if ("year".equals(type)) {
  130. calendar.set(Calendar.MONTH, 0);
  131. calendar.set(Calendar.DAY_OF_YEAR, 1);
  132. firstDay = calendar.getTime();
  133. }
  134. QueryWrapper<TurbineInfoDay> currentqw = new QueryWrapper<>();
  135. currentqw.select("station_id,MAX(record_date) AS record_date,SUM(gzss) AS gzss,SUM(jhjxss) AS jhjxss,SUM(xdss) AS xdss,SUM(xnss) AS xnss,SUM(slss) AS slss")
  136. .ge("record_date", firstDay)
  137. .le("record_date", endDate)
  138. .eq("turbine_id", windturbineId)
  139. .like("station_id", "_FDC_")
  140. .groupBy("station_id");
  141. List<TurbineInfoDay> monthData = turbineInfoDayService.list(currentqw);
  142. TurbineInfoDay tur = monthData.get(0);
  143. return tur.getGzss() + tur.getJhjxss() + tur.getXnss() + tur.getSlss() + tur.getXdss();
  144. }
  145. public double calPjwd(String windturbineId, String type, Date endDate, Calendar calendar) {
  146. calendar.setTime(endDate);
  147. Date firstDay = null;
  148. LocalDate localDate = endDate.toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
  149. int d = 0;
  150. if ("month".equals(type)) {
  151. calendar.set(Calendar.DAY_OF_MONTH, 1);
  152. firstDay = calendar.getTime();
  153. d = localDate.getDayOfMonth();
  154. } else if ("year".equals(type)) {
  155. calendar.set(Calendar.MONTH, 0);
  156. calendar.set(Calendar.DAY_OF_YEAR, 1);
  157. firstDay = calendar.getTime();
  158. d = localDate.getDayOfYear();
  159. }
  160. QueryWrapper<TurbineInfoDay> currentqw = new QueryWrapper<>();
  161. currentqw.select("station_id,MAX(record_date) AS record_date,SUM(hjwd) AS hjwd")
  162. .ge("record_date", firstDay)
  163. .le("record_date", endDate)
  164. .eq("turbine_id", windturbineId)
  165. .like("station_id", "_FDC_")
  166. .groupBy("station_id");
  167. List<TurbineInfoDay> monthData = turbineInfoDayService.list(currentqw);
  168. if (d != 0) {
  169. return monthData.get(0).getHjwd() / (d);
  170. } else {
  171. return monthData.get(0).getHjwd();
  172. }
  173. }
  174. public double calSbklyl(String windturbineId, String type, Date endDate, Calendar calendar) {
  175. calendar.setTime(endDate);
  176. Date firstDay = null;
  177. LocalDate localDate = endDate.toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
  178. int d = 0;
  179. if ("month".equals(type)) {
  180. calendar.set(Calendar.DAY_OF_MONTH, 1);
  181. firstDay = calendar.getTime();
  182. d = localDate.getDayOfMonth();
  183. } else if ("year".equals(type)) {
  184. calendar.set(Calendar.MONTH, 0);
  185. calendar.set(Calendar.DAY_OF_YEAR, 1);
  186. firstDay = calendar.getTime();
  187. d = localDate.getDayOfYear();
  188. }
  189. QueryWrapper<TurbineInfoDay> currentqw = new QueryWrapper<>();
  190. currentqw.select("station_id,MAX(record_date) AS record_date,SUM(klyl) AS klyl")
  191. .ge("record_date", firstDay)
  192. .le("record_date", endDate)
  193. .eq("turbine_id", windturbineId)
  194. .like("station_id", "_FDC_")
  195. .groupBy("station_id");
  196. List<TurbineInfoDay> monthData = turbineInfoDayService.list(currentqw);
  197. if (d != 0) {
  198. return monthData.get(0).getKlyl() / (d);
  199. } else {
  200. return monthData.get(0).getKlyl();
  201. }
  202. }
  203. public double calTjcs(String windturbineId, String type, Date endDate, Calendar calendar) {
  204. calendar.setTime(endDate);
  205. Date firstDay = null;
  206. if ("month".equals(type)) {
  207. calendar.set(Calendar.DAY_OF_MONTH, 1);
  208. firstDay = calendar.getTime();
  209. } else if ("year".equals(type)) {
  210. calendar.set(Calendar.MONTH, 0);
  211. calendar.set(Calendar.DAY_OF_YEAR, 1);
  212. firstDay = calendar.getTime();
  213. }
  214. QueryWrapper<TurbineInfoDay> currentqw = new QueryWrapper<>();
  215. currentqw.select("station_id,MAX(record_date) AS record_date,SUM(tjcs) AS tjcs")
  216. .ge("record_date", firstDay)
  217. .le("record_date", endDate)
  218. .eq("turbine_id", windturbineId)
  219. .like("station_id", "_FDC_")
  220. .groupBy("station_id");
  221. List<TurbineInfoDay> monthData = turbineInfoDayService.list(currentqw);
  222. return monthData.get(0).getTjcs();
  223. }
  224. public double calDjxs(String windturbineId, String type, Date endDate, Calendar calendar) {
  225. calendar.setTime(endDate);
  226. Date firstDay = null;
  227. if ("month".equals(type)) {
  228. calendar.set(Calendar.DAY_OF_MONTH, 1);
  229. firstDay = calendar.getTime();
  230. } else if ("year".equals(type)) {
  231. calendar.set(Calendar.MONTH, 0);
  232. calendar.set(Calendar.DAY_OF_YEAR, 1);
  233. firstDay = calendar.getTime();
  234. }
  235. QueryWrapper<TurbineInfoDay> currentqw = new QueryWrapper<>();
  236. currentqw.select("station_id,MAX(record_date) AS record_date,SUM(dj_min) AS dj_min")
  237. .ge("record_date", firstDay)
  238. .le("record_date", endDate)
  239. .eq("turbine_id", windturbineId)
  240. .like("station_id", "_FDC_")
  241. .groupBy("station_id");
  242. List<TurbineInfoDay> monthData = turbineInfoDayService.list(currentqw);
  243. return monthData.get(0).getDjMin();
  244. }
  245. public double calYxxs(String windturbineId, String type, Date endDate, Calendar calendar) {
  246. calendar.setTime(endDate);
  247. Date firstDay = null;
  248. if ("month".equals(type)) {
  249. calendar.set(Calendar.DAY_OF_MONTH, 1);
  250. firstDay = calendar.getTime();
  251. } else if ("year".equals(type)) {
  252. calendar.set(Calendar.MONTH, 0);
  253. calendar.set(Calendar.DAY_OF_YEAR, 1);
  254. firstDay = calendar.getTime();
  255. }
  256. QueryWrapper<TurbineInfoDay> currentqw = new QueryWrapper<>();
  257. currentqw.select("station_id,MAX(record_date) AS record_date,SUM(yx_min) AS yx_min")
  258. .ge("record_date", firstDay)
  259. .le("record_date", endDate)
  260. .eq("turbine_id", windturbineId)
  261. .like("station_id", "_FDC_")
  262. .groupBy("station_id");
  263. List<TurbineInfoDay> monthData = turbineInfoDayService.list(currentqw);
  264. return monthData.get(0).getYxMin();
  265. }
  266. public double calJxxs(String windturbineId, String type, Date endDate, Calendar calendar) {
  267. calendar.setTime(endDate);
  268. Date firstDay = null;
  269. if ("month".equals(type)) {
  270. calendar.set(Calendar.DAY_OF_MONTH, 1);
  271. firstDay = calendar.getTime();
  272. } else if ("year".equals(type)) {
  273. calendar.set(Calendar.MONTH, 0);
  274. calendar.set(Calendar.DAY_OF_YEAR, 1);
  275. firstDay = calendar.getTime();
  276. }
  277. QueryWrapper<TurbineInfoDay> currentqw = new QueryWrapper<>();
  278. currentqw.select("station_id,MAX(record_date) AS record_date,SUM(jx_min) AS jx_min")
  279. .ge("record_date", firstDay)
  280. .le("record_date", endDate)
  281. .eq("turbine_id", windturbineId)
  282. .like("station_id", "_FDC_")
  283. .groupBy("station_id");
  284. List<TurbineInfoDay> monthData = turbineInfoDayService.list(currentqw);
  285. return monthData.get(0).getJxMin();
  286. }
  287. public double calGzxs(String windturbineId, String type, Date endDate, Calendar calendar) {
  288. calendar.setTime(endDate);
  289. Date firstDay = null;
  290. if ("month".equals(type)) {
  291. calendar.set(Calendar.DAY_OF_MONTH, 1);
  292. firstDay = calendar.getTime();
  293. } else if ("year".equals(type)) {
  294. calendar.set(Calendar.MONTH, 0);
  295. calendar.set(Calendar.DAY_OF_YEAR, 1);
  296. firstDay = calendar.getTime();
  297. }
  298. QueryWrapper<TurbineInfoDay> currentqw = new QueryWrapper<>();
  299. currentqw.select("station_id,MAX(record_date) AS record_date,SUM(gz_min) AS gz_min")
  300. .ge("record_date", firstDay)
  301. .le("record_date", endDate)
  302. .eq("turbine_id", windturbineId)
  303. .like("station_id", "_FDC_")
  304. .groupBy("station_id");
  305. List<TurbineInfoDay> monthData = turbineInfoDayService.list(currentqw);
  306. return monthData.get(0).getGzMin();
  307. }
  308. public double calPjfs(String windturbineId, String type, Date endDate, Calendar calendar) {
  309. calendar.setTime(endDate);
  310. Date firstDay = null;
  311. LocalDate localDate = endDate.toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
  312. int d = 0;
  313. if ("month".equals(type)) {
  314. calendar.set(Calendar.DAY_OF_MONTH, 1);
  315. firstDay = calendar.getTime();
  316. d = localDate.getDayOfMonth();
  317. } else if ("year".equals(type)) {
  318. calendar.set(Calendar.MONTH, 0);
  319. calendar.set(Calendar.DAY_OF_YEAR, 1);
  320. firstDay = calendar.getTime();
  321. d = localDate.getDayOfYear();
  322. }
  323. QueryWrapper<TurbineInfoDay> currentqw = new QueryWrapper<>();
  324. currentqw.select("station_id,MAX(record_date) AS record_date,SUM(pjfs) AS pjfs")
  325. .ge("record_date", firstDay)
  326. .le("record_date", endDate)
  327. .eq("turbine_id", windturbineId)
  328. .like("station_id", "_FDC_")
  329. .groupBy("station_id");
  330. List<TurbineInfoDay> monthData = turbineInfoDayService.list(currentqw);
  331. if (d != 0) {
  332. return monthData.get(0).getPjfs() / (d);
  333. } else {
  334. return monthData.get(0).getPjfs();
  335. }
  336. }
  337. public double calFdl(String windturbineId, String type, Date endDate, Calendar calendar) {
  338. calendar.setTime(endDate);
  339. Date firstDay = null;
  340. if ("month".equals(type)) {
  341. calendar.set(Calendar.DAY_OF_MONTH, 1);
  342. firstDay = calendar.getTime();
  343. } else if ("year".equals(type)) {
  344. calendar.set(Calendar.MONTH, 0);
  345. calendar.set(Calendar.DAY_OF_YEAR, 1);
  346. firstDay = calendar.getTime();
  347. }
  348. QueryWrapper<TurbineInfoDay> currentqw = new QueryWrapper<>();
  349. currentqw.select("station_id,MAX(record_date) AS record_date,SUM(rfdl) AS rfdl")
  350. .ge("record_date", firstDay)
  351. .le("record_date", endDate)
  352. .eq("turbine_id", windturbineId)
  353. .like("station_id", "_FDC_")
  354. .groupBy("station_id");
  355. List<TurbineInfoDay> monthData = turbineInfoDayService.list(currentqw);
  356. return monthData.get(0).getRfdl();
  357. }
  358. }