DataRecalculationImpl.java 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697
  1. package com.jiayue.biz.service.impl;
  2. import cn.hutool.core.util.ZipUtil;
  3. import cn.hutool.poi.excel.ExcelReader;
  4. import cn.hutool.poi.excel.ExcelUtil;
  5. import com.baomidou.mybatisplus.core.toolkit.Wrappers;
  6. import com.jiayue.biz.domain.*;
  7. import com.jiayue.biz.mapper.ProphaseAnemometryDataMapper;
  8. import com.jiayue.biz.mapper.ProphaseWeatherDataMapper;
  9. import com.jiayue.biz.service.DataRecalculationService;
  10. import com.jiayue.biz.service.EquipmentAttributeService;
  11. import com.jiayue.biz.service.WindTowerDataChildTableService;
  12. import com.jiayue.biz.util.DateTimeUtil;
  13. import com.jiayue.biz.util.FileUtil;
  14. import com.jiayue.common.core.domain.AjaxResult;
  15. import com.jiayue.common.utils.file.FileUtils;
  16. import lombok.AllArgsConstructor;
  17. import lombok.extern.slf4j.Slf4j;
  18. import org.apache.poi.xssf.streaming.SXSSFRow;
  19. import org.apache.poi.xssf.streaming.SXSSFSheet;
  20. import org.apache.poi.xssf.streaming.SXSSFWorkbook;
  21. import org.joda.time.DateTime;
  22. import org.springframework.beans.factory.annotation.Autowired;
  23. import org.springframework.stereotype.Service;
  24. import org.springframework.web.multipart.MultipartFile;
  25. import java.io.*;
  26. import java.sql.Timestamp;
  27. import java.text.SimpleDateFormat;
  28. import java.util.*;
  29. import java.util.stream.Collectors;
  30. /**
  31. * 上传文件or数据过滤
  32. *
  33. * @author whc
  34. * @Date 2022/06/23
  35. */
  36. @Slf4j
  37. @Service
  38. @AllArgsConstructor
  39. public class DataRecalculationImpl implements DataRecalculationService {
  40. private final WindTowerDataParentTableServiceImpl windTowerDataParentTableService;
  41. private final WindTowerDataChildTableService windTowerDataChildTableService;
  42. private final WindTowerInfoServiceImpl windTowerInfoService;
  43. private final WindTowerCalculationDataServiceImpl windTowerCalculationDataService;
  44. private final WindDirectionStatisticsDataServiceImpl windDirectionStatisticsDataService;
  45. private final EquipmentAttributeService equipmentAttributeService;
  46. private final StatisticsSituationServiceImpl statisticsSituationService;
  47. private AnalysisDataImpl analysisData;
  48. private final ProphaseWeatherDataMapper prophaseWeatherDataMapper;
  49. private final ProphaseAnemometryDataMapper prophaseAnemometryDataMapper;
  50. public void teset() {
  51. // File file1 = MultipartFileToFile(file);
  52. // //如果是压缩包
  53. // if(AnalysisDataImpl.isArchiveFile(file1)){
  54. //// String zipPath = file1.getPath();
  55. // //解压文件
  56. // ZipUtil.unzip(file1.getPath() + "\\");
  57. // //删除压缩包
  58. //// FileUtils.deleteFile(zipPath);
  59. // }
  60. }
  61. /**
  62. * 文件上传解析
  63. *
  64. * @param file 上传的文件
  65. * @param equipmentNo 设备编号
  66. * @param recorderNo 记录仪编号
  67. * @return
  68. */
  69. @Override
  70. public AjaxResult uploadFileAnalysis(MultipartFile file, String equipmentNo, String recorderNo) {
  71. try {
  72. //D:\\program\\uploadFile\\new
  73. String path = FileUtil.getFileUploadPath() + File.separator + "new";
  74. File filePath = new File(path);
  75. //判断目录是否存在
  76. if (!filePath.exists()) {
  77. filePath.mkdirs();
  78. }
  79. String originalFilename = file.getOriginalFilename();
  80. //如果是压缩文件
  81. if (originalFilename.contains(".zip")) {
  82. File file1 = MultipartFileToFile(file);
  83. //如果是压缩包
  84. if (AnalysisDataImpl.isArchiveFile(file1)) {
  85. //解压文件
  86. File unzip = ZipUtil.unzip(file1.getPath() + "\\");
  87. File[] files = unzip.listFiles();
  88. if (files != null) {
  89. for (File file2 : files) {
  90. if (file2.getName().contains("rld")) {
  91. String[] id = file2.getName().split("_");
  92. if (id[0].equals(equipmentNo)) {
  93. //文件保存到指定目录下
  94. FileUtil.move(file2.getPath(), path + File.separator);
  95. //如果文件名的后缀为.rld 则转换
  96. //调用系统命令转换
  97. this.systemCommand(equipmentNo, recorderNo);
  98. }
  99. } else if (file2.getName().contains(".RWD")) {
  100. path = "D:\\in\\";
  101. FileUtil.move(file2.getPath(), path);
  102. this.systemCommandRWD();
  103. } else {
  104. return AjaxResult.error("请检查数据文件是否正确");
  105. }
  106. }
  107. //删除压缩包
  108. FileUtils.deleteFile(file1.getPath());
  109. }
  110. return AjaxResult.success("上传完成");
  111. }
  112. }
  113. //如果不是压缩文件
  114. String[] names = file.getOriginalFilename().split("\\.");
  115. //如果不是rld文件则不解析
  116. if (names[names.length - 1].equals("rld")) {
  117. String[] id = file.getOriginalFilename().split("_");
  118. if (id[0].equals(equipmentNo)) {
  119. //文件保存到指定目录下
  120. file.transferTo(new File(path + File.separator + originalFilename));
  121. //如果文件名的后缀为.rld 则转换
  122. //调用系统命令转换
  123. this.systemCommand(equipmentNo, recorderNo);
  124. return AjaxResult.success("成功");
  125. } else {
  126. return AjaxResult.error("不是该测风塔的文件");
  127. }
  128. } else if (originalFilename.contains(".RWD")) {
  129. path = "D:\\in\\";
  130. file.transferTo(new File(path + File.separator + file.getOriginalFilename()));
  131. this.systemCommandRWD();
  132. return AjaxResult.success("成功");
  133. } else {
  134. return AjaxResult.error("请检查数据文件是否正确");
  135. }
  136. } catch (Exception ex) {
  137. log.error("上传失败" + ex);
  138. return AjaxResult.error(ex.getMessage());
  139. }
  140. }
  141. /**
  142. * 将MultipartFile转换为File
  143. *
  144. * @param multiFile
  145. * @return
  146. */
  147. public static File MultipartFileToFile(MultipartFile multiFile) {
  148. // 获取文件名
  149. String fileName = multiFile.getOriginalFilename();
  150. // 获取文件后缀
  151. String prefix = fileName.substring(fileName.lastIndexOf("."));
  152. // 若须要防止生成的临时文件重复,能够在文件名后添加随机码
  153. try {
  154. File file = File.createTempFile(fileName, prefix);
  155. multiFile.transferTo(file);
  156. return file;
  157. } catch (Exception e) {
  158. e.printStackTrace();
  159. }
  160. return null;
  161. }
  162. /**
  163. * rwd文件转换txt
  164. */
  165. public void systemCommandRWD() {
  166. try {
  167. Runtime runtime = Runtime.getRuntime();
  168. List<WindTowerInfo> windTowerInfoList = windTowerInfoService.list();
  169. File file = new File("D:\\in\\");
  170. //遍历所有文件
  171. File[] files = file.listFiles();
  172. for (File f : files) {
  173. for (WindTowerInfo w : windTowerInfoList) {
  174. String id = f.getName().substring(0, 4);
  175. String password = w.getPassword();
  176. //如果设备编号相等 则调用命令转换该文件
  177. if (id.equals(w.getEquipmentNo())) {
  178. String cmd = "\"D:\\NRG\\SymDR\\SDR.exe\"" + " /z " + password + " " + f.getPath();
  179. Process ipconfig = runtime.exec(cmd);
  180. ipconfig.waitFor();
  181. InputStream inputStream = ipconfig.getInputStream();
  182. byte[] bytes = new byte[1024];
  183. int len = 0;
  184. while ((len = inputStream.read(bytes)) != -1) {
  185. log.info(new String(bytes, 0, len, "GBK"));
  186. }
  187. }
  188. }
  189. //转换成txt的文件在D:\NRG\ScaledData\目录下 移动到 D:\out\下 转换文件后会有两个文件一个txt 一个log 删除log 移动txt
  190. File file1 = new File("D:\\NRG\\ScaledData\\");
  191. File[] files1 = file1.listFiles();
  192. for (File e : files1) {
  193. String[] name = e.getName().split("\\.");
  194. if (name[1].equals("txt")) {
  195. FileUtil.move(e.getPath(), "D:\\out\\new\\");
  196. } else {
  197. e.delete();
  198. }
  199. }
  200. //转成txt后把文件移动到系统文件备份目录下
  201. File file2 = new File("D:\\in\\");
  202. File[] files2 = file2.listFiles();
  203. //xls移动系统文件目录下
  204. for (File e : files2) {
  205. String[] str = e.getName().split("\\.");
  206. if (str[1].equals("RWD")) {
  207. FileUtil.move(e.getPath(), FileUtil.getSystemFilePath() + File.separator + str[0].substring(0, 4));
  208. } else {
  209. String[] strs = str[0].split("_");
  210. FileUtil.move(e.getPath(), FileUtil.getSystemFilePath() + File.separator + strs[0]);
  211. }
  212. }
  213. //把txt文件转成excel文件并解析
  214. String type = "RWD";
  215. analysisData.analysisData(type);
  216. }
  217. } catch (Exception e) {
  218. e.printStackTrace();
  219. }
  220. }
  221. /**
  222. * 执行命令通过软件解压rld文件到D:\out\new\下
  223. *
  224. * @param equipmentNo 设备编号
  225. * @param recorderNo 记录仪编号
  226. */
  227. public void systemCommand(String equipmentNo, String recorderNo) {
  228. try {
  229. Runtime runtime = Runtime.getRuntime();
  230. //D:\\program\\uploadFile\\new rld文件在这个目录下
  231. File file = new File(FileUtil.getFileUploadPath() + File.separator + "new");
  232. //D:\\program\\uploadFile\\file rld转换成txt文件在这个目录下
  233. File uploadFile = new File(FileUtil.getFileUploadPath() + File.separator + "txtFile");
  234. if (!uploadFile.exists()) {
  235. uploadFile.mkdirs();
  236. }
  237. //遍历所有文件
  238. File[] files = file.listFiles();
  239. for (File f : files) {
  240. //根据编号和记录仪号过滤
  241. List<WindTowerInfo> windTowerInfoList = windTowerInfoService.list().stream().filter(wind -> wind.getEquipmentNo().equals(equipmentNo)
  242. && wind.getRecorderNo().equals(recorderNo)).collect(Collectors.toList());
  243. //测风塔编号和记录仪编号两个条件 能确保塔的唯一性
  244. for (WindTowerInfo w : windTowerInfoList) {
  245. if ("".equals(w.getPassword())) {
  246. log.error(w.getEquipmentNo() + "测风塔没有配置数据密码");
  247. } else {
  248. String[] s = new String[]{
  249. "\"D:\\Program Files (x86)\\Renewable NRG Systems\\SymPRO Desktop\\SymPRODesktop.exe\"",
  250. "/cmd", "convert", "/file", f.getPath(),
  251. "/pass", w.getPassword(), "/type", "\"meas\"", "/outputdir", "\"D:\\program\\uploadFile\\txtFile\""
  252. };
  253. Process ipconfig = runtime.exec(s);
  254. ipconfig.waitFor();
  255. InputStream inputStream = ipconfig.getInputStream();
  256. byte[] bytes = new byte[1024];
  257. int len = 0;
  258. while ((len = inputStream.read(bytes)) != -1) {
  259. log.info(new String(bytes, 0, len, "GBK"));
  260. }
  261. }
  262. }
  263. }
  264. //转成txt后把上传路径 D:\\program\\uploadFile\\new 下的rld文件移动到系统文件里
  265. File file1 = new File(FileUtil.getFileUploadPath() + File.separator + "new");
  266. File[] files1 = file1.listFiles();
  267. //xls移动系统文件目录下
  268. for (File e : files1) {
  269. String[] str = e.getName().split("\\.");
  270. if (str[1].equals("RWD")) {
  271. FileUtil.move(e.getPath(), FileUtil.getSystemFilePath() + File.separator + str[0].substring(0, 4));
  272. } else {
  273. String[] strs = str[0].split("_");
  274. FileUtil.move(e.getPath(), FileUtil.getSystemFilePath() + File.separator + strs[0]);
  275. }
  276. }
  277. //解析数据
  278. this.analysisData();
  279. } catch (Exception e) {
  280. log.error("执行系统命令失败:" + e);
  281. }
  282. }
  283. /**
  284. * 解析数据
  285. */
  286. public void analysisData() {
  287. String txtPath = FileUtil.getFileUploadPath() + File.separator + "txtFile" + File.separator;
  288. String excelDir = FileUtil.getFileUploadPath() + File.separator + "excelFile" + File.separator;
  289. File file = new File(txtPath);
  290. if (!file.exists()) {
  291. file.mkdirs();
  292. }
  293. File excelFiles = new File(excelDir);
  294. if (!excelFiles.exists()) {
  295. excelFiles.mkdirs();
  296. }
  297. File[] files = file.listFiles();
  298. for (File f : files) {
  299. String[] xlsName = f.getName().split(".txt");
  300. String excelFile = excelDir + xlsName[0] + ".xls";
  301. //txt转xls
  302. analysisTXT(f.getPath(), excelFile);
  303. //xls文件解析入库
  304. analysisExcel(new File(excelFile));
  305. //转换成xls文件后删除txt文件
  306. f.delete();
  307. //解析完成后删除xls文件
  308. File exeFile = new File(excelFile);
  309. exeFile.delete();
  310. }
  311. }
  312. /**
  313. * 解析txt文件 输出成xls文件
  314. *
  315. * @param file_in 输入文件
  316. * @param file_out 输出文件
  317. */
  318. public void analysisTXT(String file_in, String file_out) {
  319. /*实例化输入、输出流*/
  320. //输入文件
  321. File f_in = new File(file_in);
  322. FileInputStream ips = null;
  323. InputStreamReader ipsr = null;
  324. //输出文件
  325. File f_out = new File(file_out);
  326. FileOutputStream ops = null;
  327. try {
  328. ips = new FileInputStream(f_in);
  329. ipsr = new InputStreamReader(ips);
  330. ops = new FileOutputStream(f_out);
  331. } catch (FileNotFoundException e) {
  332. // TODO Auto-generated catch block
  333. e.printStackTrace();
  334. }
  335. /*创建excel表格文件并输出*/
  336. //创建工作薄
  337. SXSSFWorkbook wb = new SXSSFWorkbook();
  338. try {
  339. //创建新的一页
  340. SXSSFSheet sheet = wb.createSheet("new sheet");
  341. BufferedReader br = new BufferedReader(ipsr);
  342. String valueString = null;
  343. //表格的有效行计数
  344. int count_line = 0;
  345. Boolean flag = false;
  346. StringBuilder dataName = new StringBuilder();
  347. //循环处理每一行
  348. while ((valueString = br.readLine()) != null) {
  349. if (flag) {//忽略开头代码
  350. //分解每一行有效行
  351. String[] strs_cell = valueString.split("\t");//用“|”切割每一行作为一个单元格数据
  352. SXSSFRow row = sheet.createRow((short) count_line);
  353. for (int i = 0; i < strs_cell.length; ++i) {//循环每个切割得到的数据,除了最后一个(,,,)和第一个(空)
  354. //创建要显示的内容,创建一个单元格,第一个参数为列坐标,第二个参数为行坐标,第三个参数为内容
  355. row.createCell((short) i).setCellValue(strs_cell[i]);
  356. //所有表头
  357. if (!dataName.toString().equals("")) {
  358. dataName.append(",");
  359. dataName.append(strs_cell[i]);
  360. } else {
  361. dataName.append(strs_cell[i]);
  362. }
  363. }
  364. count_line++;
  365. }
  366. if (valueString.equals("Data")) {
  367. flag = true;
  368. }
  369. }
  370. //根据数据表头分解出层高
  371. String[] names = dataName.toString().split(",");
  372. StringBuffer height = new StringBuffer();
  373. StringBuffer wdHeight = new StringBuffer();
  374. for (String name : names) {
  375. if (name.contains("Anem") || name.contains("Vane")) {
  376. String[] keys = name.split("_");
  377. String b = getWsOrWd(keys[1], keys[5]);
  378. String c = keys[2].substring(0, keys[2].length() - 4);
  379. if (b.equals("ws")) {
  380. if (!height.toString().equals("")) {
  381. if (!height.toString().contains(c)) {
  382. height.append(",");
  383. height.append(c);
  384. }
  385. } else {
  386. height.append(c);
  387. }
  388. } else if (b.equals("wd")) {
  389. if (!wdHeight.toString().equals("")) {
  390. if (!wdHeight.toString().contains(c)) {
  391. wdHeight.append(",");
  392. wdHeight.append(c);
  393. }
  394. } else {
  395. wdHeight.append(c);
  396. }
  397. }
  398. }
  399. }
  400. //把创建的表格写入到输出流中,并关闭输出流
  401. wb.write(ops);
  402. } catch (IOException e) {
  403. // TODO Auto-generated catch block
  404. e.printStackTrace();
  405. } finally {
  406. if (wb != null) {
  407. try {
  408. wb.close();
  409. } catch (IOException e) {
  410. // TODO Auto-generated catch block
  411. e.printStackTrace();
  412. }
  413. }
  414. if (ips != null) {
  415. try {
  416. ips.close();
  417. } catch (IOException e) {
  418. // TODO Auto-generated catch block
  419. e.printStackTrace();
  420. }
  421. }
  422. if (ops != null) {
  423. try {
  424. ops.close();
  425. } catch (IOException e) {
  426. // TODO Auto-generated catch block
  427. e.printStackTrace();
  428. }
  429. }
  430. }
  431. }
  432. /**
  433. * 解析excel文件
  434. *
  435. * @param file 文件
  436. */
  437. public void analysisExcel(File file) {
  438. String type = "rld";
  439. ExcelReader reader = ExcelUtil.getReader(file, 0);
  440. List<List<Object>> read = reader.read(0);
  441. List<Object> objects = read.get(0);
  442. Map<String, String> map = new HashMap<>();
  443. String[] fileNames = file.getName().split("_");
  444. CheckDataRecode.map.clear();
  445. //把表格里的数据转换成属性+层高方便解析入库
  446. for (Object object : objects) {
  447. //时间
  448. if (object.equals("Timestamp")) {
  449. reader.addHeaderAlias(object.toString(), "time");
  450. continue;
  451. }
  452. String[] keys = object.toString().split("_");
  453. //TODO改成传进去Ch1_Anem_140.00m_WNW_Avg_m/s 出来的是140风速的属性
  454. //a = 最大 最小 平均值 标差
  455. String a = getKeyStr(keys[4]);
  456. //b = 风速 风向 温 湿 压
  457. String b = getWsOrWd(keys[1], keys[5]);
  458. //c = 层高
  459. String c = keys[2].substring(0, keys[2].length() - 4);
  460. String value = b + a;
  461. if (null != map.get(value + "_" + c)) {
  462. value = value + "_" + Integer.parseInt(c) + "A";
  463. } else {
  464. if (!(b.equals("t") || b.equals("rh") || b.equals("pa"))) {
  465. value = value + "_" + Integer.parseInt(c);
  466. }
  467. }
  468. //判断该数据是否解析过
  469. map.put(value, "1");
  470. CheckDataRecode.map.put(value + "DeadDataStartTime", new DateTime(fileNames[1]));
  471. reader.addHeaderAlias(object.toString(), value);
  472. }
  473. List<Map<String, Object>> allData = reader.readAll();
  474. //数据筛选
  475. List<Map<String, Object>> filterData = new CheckDataRecode().checkValue(allData, type);
  476. String eqId = file.getName().split("_")[0];
  477. String eTime = file.getName().split("_")[1];
  478. windTowerDataParentTableService.packageData(filterData, eqId, eTime, type, "");
  479. reader.close();
  480. }
  481. //拼装实体
  482. private String getKeyStr(String key) {
  483. if (("Avg").equals(key)) {
  484. return "Ave";
  485. }
  486. if (("SD").equals(key)) {
  487. return "Sta";
  488. }
  489. return key;
  490. }
  491. //拼装实体
  492. private String getWsOrWd(String key, String key2) {
  493. if (("Anem").equals(key)) {
  494. return "ws";
  495. }
  496. if (("Vane").equals(key)) {
  497. return "wd";
  498. }
  499. if (("Analog").equals(key)) {
  500. if (key2.equals("C")) {
  501. return "t";
  502. }
  503. if (key2.equals("mb") || key2.equals("hPa") || key2.equals("kpa") || key2.equals("KPa")) {
  504. return "pa";
  505. }
  506. if (key2.equals("%RH")) {
  507. return "rh";
  508. }
  509. }
  510. return key;
  511. }
  512. /**
  513. * 数据筛选
  514. *
  515. * @param startTime 开始时间
  516. * @param endTime 结束时间
  517. * @param equipmentNo 设备编号
  518. * @return 成功/失败
  519. */
  520. public AjaxResult dataCheck(Date startTime, Date endTime, String equipmentNo) {
  521. SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
  522. //所有数据
  523. List<Map<String, Object>> maps = windTowerDataParentTableService.selectDataByBetweenTimeAndEquipmetId(startTime, endTime, equipmentNo);
  524. CheckDataRecode checkDataRecode = new CheckDataRecode();
  525. checkDataRecode.map.clear();
  526. List<String> parentIdList = new ArrayList<>();
  527. try {
  528. if (!maps.isEmpty()) {
  529. long startDate = Long.parseLong(maps.get(0).get("time").toString());
  530. long endDate = Long.parseLong(maps.get(0).get("time").toString());
  531. //设置属性死值开始时间
  532. maps.get(0).forEach((k, v) -> {
  533. checkDataRecode.map.put(k + "DeadDataStartTime", new DateTime(Long.parseLong(maps.get(0).get("time").toString())));
  534. });
  535. for (Map<String, Object> map : maps) {
  536. //获取时间
  537. if (startDate > Long.parseLong(map.get("time").toString())) {
  538. startDate = Long.parseLong(map.get("time").toString());
  539. }
  540. if (endDate < Long.parseLong(map.get("time").toString())) {
  541. endDate = Long.parseLong(map.get("time").toString());
  542. }
  543. }
  544. //如果存在数据先删除
  545. if (!maps.isEmpty()) {
  546. for (Map<String, Object> map : maps) {
  547. if (!map.get("id").toString().isEmpty()) {
  548. parentIdList.add(map.get("id").toString());
  549. }
  550. }
  551. windTowerDataChildTableService.deleteBetweenTimeAndEquipmentIdAndChild(parentIdList, equipmentNo);
  552. windTowerDataParentTableService.deleteBetweenTimeAndEquipmentIdAndParent(DateTimeUtil.getDayStartTime(startDate), DateTimeUtil.getDayLastTime(endDate), equipmentNo);
  553. }
  554. log.info("正在进行数据过滤");
  555. //重新走一遍数据过滤 然后存库
  556. List<Map<String, Object>> mapList = new CheckDataRecode().checkValue(maps, "rld");
  557. windTowerDataParentTableService.packageData(mapList, equipmentNo, sdf.format(new Date(startDate)), "rld", "DataRecalculation");
  558. return AjaxResult.success("数据筛选完成");
  559. } else {
  560. return AjaxResult.success("该时间范围内没有数据");
  561. }
  562. } catch (Exception e) {
  563. return AjaxResult.error("数据筛选失败");
  564. }
  565. }
  566. public AjaxResult statisticsCheck(Date startTime, Date endTime, String equipmentNo) {
  567. try {
  568. //获取到结束时间的当天最后时间
  569. endTime = DateTimeUtil.getDayLastTime(endTime.getTime());
  570. List<StatisticsSituation> statisticsSituations = statisticsSituationService.list();
  571. List<EquipmentAttribute> equipmentAttributeList = equipmentAttributeService.list();
  572. List<WindTowerCalculationData> windTowerCalculationDataList = windTowerCalculationDataService.getByBetweenTimeAndEquipmentId(startTime, endTime, equipmentNo);
  573. List<WindTowerInfo> windTowerInfoList = windTowerInfoService.getByEquipmentNo(equipmentNo);
  574. //风数据查询
  575. List<ProphaseAnemometryData> prophaseAnemometryDataList = prophaseAnemometryDataMapper.selectList(Wrappers.<ProphaseAnemometryData>lambdaQuery()
  576. .eq(ProphaseAnemometryData::getEquipmentId, equipmentNo)
  577. .le(ProphaseAnemometryData::getTs, new Timestamp(endTime.getTime()))
  578. .ge(ProphaseAnemometryData::getTs, new Timestamp(startTime.getTime())));
  579. //环境数据查询
  580. List<ProphaseWeatherData> prophaseWeatherDataList = prophaseWeatherDataMapper.selectPublicData(equipmentNo, new Timestamp(startTime.getTime()), new Timestamp(endTime.getTime()));
  581. //把传入的时间按照日或月分割
  582. log.info("开始重新计算统计数据");
  583. ArrayList<WindTowerCalculationData> allDataList = new ArrayList<>();
  584. //小时风功率密度和平均风速
  585. ArrayList<WindTowerCalculationData> dataList = windTowerCalculationDataService.calculateWindPowerDensity(startTime.getTime(), endTime.getTime(), equipmentNo, prophaseAnemometryDataList, prophaseWeatherDataList, equipmentAttributeList, windTowerCalculationDataList);
  586. allDataList.addAll(dataList);
  587. //小时风切变
  588. ArrayList<WindTowerCalculationData> calculationData = windTowerCalculationDataService.calculateWindPowerShear(startTime, endTime, equipmentNo, prophaseAnemometryDataList, windTowerCalculationDataList);
  589. allDataList.addAll(calculationData);
  590. //日平均温度
  591. ArrayList<WindTowerCalculationData> tDay = windTowerCalculationDataService.tDay(startTime, endTime, equipmentNo, prophaseWeatherDataList, equipmentAttributeList);
  592. allDataList.addAll(tDay);
  593. //日平均气压
  594. ArrayList<WindTowerCalculationData> paDay = windTowerCalculationDataService.paDay(startTime, endTime, equipmentNo, prophaseWeatherDataList, equipmentAttributeList);
  595. allDataList.addAll(paDay);
  596. //日平均风速
  597. ArrayList<WindTowerCalculationData> wsDay = windTowerCalculationDataService.wsDay(startTime, endTime, equipmentNo, windTowerCalculationDataList, equipmentAttributeList, windTowerInfoList);
  598. allDataList.addAll(wsDay);
  599. //日平均风速标差
  600. ArrayList<WindTowerCalculationData> calculationData1 = windTowerCalculationDataService.calculateStaDay(startTime, endTime, equipmentNo, prophaseAnemometryDataList, equipmentAttributeList, windTowerInfoList, windTowerCalculationDataList);
  601. allDataList.addAll(calculationData1);
  602. //日平均湍流
  603. ArrayList<WindTowerCalculationData> turbulenceDay = windTowerCalculationDataService.turbulenceDay(startTime, endTime, equipmentNo, equipmentAttributeList, windTowerInfoList, windTowerCalculationDataList);
  604. allDataList.addAll(turbulenceDay);
  605. //日平均空气密度
  606. ArrayList<WindTowerCalculationData> airDensityDay = windTowerCalculationDataService.airDensityDay(startTime, endTime, equipmentNo, prophaseWeatherDataList, equipmentAttributeList, windTowerCalculationDataList);
  607. allDataList.addAll(airDensityDay);
  608. //日平均风功率密度
  609. ArrayList<WindTowerCalculationData> wpdDay = windTowerCalculationDataService.wpdDay(startTime, endTime, equipmentNo, windTowerCalculationDataList, equipmentAttributeList, windTowerInfoList);
  610. allDataList.addAll(wpdDay);
  611. //日平均风切变
  612. ArrayList<WindTowerCalculationData> shearDay = windTowerCalculationDataService.shearDay(startTime, endTime, equipmentNo, windTowerCalculationDataList, equipmentAttributeList, windTowerInfoList);
  613. allDataList.addAll(shearDay);
  614. List<Long> dateTime = DateTimeUtil.getIntervalTimeByMonth(DateTimeUtil.beginOfMonth(startTime), DateTimeUtil.beginOfMonth(endTime));
  615. for (Long l : dateTime) {
  616. //月平均风速
  617. ArrayList<WindTowerCalculationData> wsMonth = windTowerCalculationDataService.wsMonth(DateTimeUtil.beginOfMonth(new Date(l)), DateTimeUtil.endOfMonth(new Date(l)), equipmentNo, windTowerCalculationDataList, equipmentAttributeList, windTowerInfoList);
  618. allDataList.addAll(wsMonth);
  619. //月平均风功率密度
  620. ArrayList<WindTowerCalculationData> wpdMonth = windTowerCalculationDataService.wpdMonth(DateTimeUtil.beginOfMonth(new Date(l)), DateTimeUtil.endOfMonth(new Date(l)), equipmentNo, windTowerCalculationDataList, equipmentAttributeList, windTowerInfoList);
  621. allDataList.addAll(wpdMonth);
  622. //月平均湍流
  623. ArrayList<WindTowerCalculationData> turbulenceMonth = windTowerCalculationDataService.turbulenceMonth(DateTimeUtil.beginOfMonth(new Date(l)), DateTimeUtil.endOfMonth(new Date(l)), equipmentNo, windTowerCalculationDataList, equipmentAttributeList, windTowerInfoList);
  624. allDataList.addAll(turbulenceMonth);
  625. //月平均空气密度
  626. ArrayList<WindTowerCalculationData> airDensityMonth = windTowerCalculationDataService.airDensityMonth(DateTimeUtil.beginOfMonth(new Date(l)), DateTimeUtil.endOfMonth(new Date(l)), equipmentNo, windTowerCalculationDataList, equipmentAttributeList);
  627. allDataList.addAll(airDensityMonth);
  628. //月最大风速
  629. ArrayList<WindTowerCalculationData> wsMaxMonth = windTowerCalculationDataService.wsMaxMonth(DateTimeUtil.beginOfMonth(new Date(l)), DateTimeUtil.endOfMonth(new Date(l)), equipmentNo, prophaseAnemometryDataList, equipmentAttributeList, windTowerInfoList);
  630. allDataList.addAll(wsMaxMonth);
  631. //月平均风切变
  632. ArrayList<WindTowerCalculationData> shearMonth = windTowerCalculationDataService.shearMonth(DateTimeUtil.beginOfMonth(new Date(l)), DateTimeUtil.endOfMonth(new Date(l)), equipmentNo, windTowerCalculationDataList, equipmentAttributeList, windTowerInfoList);
  633. allDataList.addAll(shearMonth);
  634. //月平均风速标差
  635. ArrayList<WindTowerCalculationData> staMonth = windTowerCalculationDataService.staMonth(DateTimeUtil.beginOfMonth(new Date(l)), DateTimeUtil.endOfMonth(new Date(l)), equipmentNo, prophaseAnemometryDataList, equipmentAttributeList, windTowerInfoList);
  636. allDataList.addAll(staMonth);
  637. //月玫瑰图
  638. windDirectionStatisticsDataService.roseMonth(DateTimeUtil.beginOfMonth(new Date(l)), DateTimeUtil.endOfMonth(new Date(l)), equipmentNo, prophaseAnemometryDataList,prophaseWeatherDataList, equipmentAttributeList);
  639. //月平均环境数据
  640. ArrayList<WindTowerCalculationData> environmentData = windTowerCalculationDataService.environmentData(DateTimeUtil.beginOfMonth(new Date(l)), DateTimeUtil.endOfMonth(new Date(l)), equipmentNo, prophaseWeatherDataList, equipmentAttributeList);
  641. allDataList.addAll(environmentData);
  642. //空气密度月逐时
  643. ArrayList<WindTowerCalculationData> airDensityMonth1 = windTowerCalculationDataService.airDensityMonth(equipmentNo, DateTimeUtil.beginOfMonth(new Date(l)), DateTimeUtil.endOfMonth(new Date(l)), prophaseWeatherDataList);
  644. allDataList.addAll(airDensityMonth1);
  645. //湍流月逐时
  646. ArrayList<WindTowerCalculationData> turbulenceHourForMonth = windTowerCalculationDataService.turbulenceHourForMonth(equipmentNo, DateTimeUtil.beginOfMonth(new Date(l)), DateTimeUtil.endOfMonth(new Date(l)), prophaseAnemometryDataList, equipmentAttributeList, windTowerInfoList);
  647. allDataList.addAll(turbulenceHourForMonth);
  648. }
  649. // 统计概述
  650. statisticsSituationService.statisticsSituation(windTowerInfoList.get(0), statisticsSituations, equipmentAttributeList);
  651. windTowerCalculationDataService.saveBatchByEquipmentId(allDataList,equipmentNo);
  652. log.info("计算统计数据执行完毕");
  653. return AjaxResult.success("数据已经重新统计");
  654. } catch (Exception e) {
  655. log.info("数据统计计算时异常");
  656. return AjaxResult.error("数据统计计算时异常");
  657. }
  658. }
  659. }