RyTask_bak.java 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398
  1. //package com.slibra.quartz.task;
  2. //
  3. //import cn.hutool.core.date.DateUtil;
  4. //import cn.hutool.http.HttpRequest;
  5. //import com.alibaba.fastjson2.JSON;
  6. //import com.alibaba.fastjson2.JSONArray;
  7. //import com.slibra.business.domain.TXinyiIndustry;
  8. //import com.slibra.business.domain.TXinyiRobot;
  9. //import com.slibra.business.mapper.TXinyiIndustryMapper;
  10. //import com.slibra.business.mapper.TXinyiRobotMapper;
  11. //import com.slibra.common.enums.DataSourceType;
  12. //import com.slibra.common.utils.DateUtils;
  13. //import com.slibra.common.utils.StringUtils;
  14. //import com.slibra.framework.datasource.DynamicDataSourceContextHolder;
  15. //import lombok.extern.slf4j.Slf4j;
  16. //import org.springframework.beans.factory.annotation.Autowired;
  17. //import org.springframework.stereotype.Component;
  18. //import org.springframework.util.CollectionUtils;
  19. //
  20. //import java.math.BigDecimal;
  21. //import java.time.LocalDateTime;
  22. //import java.time.format.DateTimeFormatter;
  23. //import java.util.*;
  24. //
  25. ///**
  26. // * 定时任务调度测试
  27. // *
  28. // *
  29. // */
  30. //@Component("ryTask")
  31. //@Slf4j
  32. //public class RyTask_bak
  33. //{
  34. // public void ryMultipleParams(String s, Boolean b, Long l, Double d, Integer i)
  35. // {
  36. // System.out.println(StringUtils.format("执行多参方法: 字符串类型{},布尔类型{},长整型{},浮点型{},整形{}", s, b, l, d, i));
  37. // }
  38. //
  39. // public void ryParams(String params)
  40. // {
  41. // System.out.println("执行有参方法:" + params);
  42. // }
  43. //
  44. // public void ryNoParams()
  45. // {
  46. // System.out.println("执行无参方法");
  47. // }
  48. //
  49. // //----------------------------------------------下面是新增的方法----------------------------------------------
  50. //
  51. // @Autowired
  52. // private TXinyiIndustryMapper xinyiIndustryMapper;
  53. //
  54. // @Autowired
  55. // private TXinyiRobotMapper xinyiRobotMapper;
  56. //// public final static StopWatch watch = new StopWatch("task");
  57. // public static final String[] queryTags = {"信义污水厂JS_COD_Value","信义污水厂JS_PH_Value","信义污水厂JS_SS_Value","信义污水厂JS_ZL_Value","信义污水厂JS_ZA_Value","信义污水厂JS_AD_Value","信义污水厂JS_T_Value","信义污水厂进水泵房液位","信义污水厂出水瞬时流量","信义污水厂升级出水COD","信义污水厂升级出水PH","信义污水厂升级出水SS","信义污水厂升级出水TN","信义污水厂升级出水TP","信义污水厂升级出水氨氮","信义污水厂AIT202_Value","信义污水厂AIT203_Value","信义污水厂AIT207_Value","信义污水厂AIT206_Value","信义污水厂AIT209_Value","信义污水厂AIT210_Value","信义污水厂进水TDS","信义污水厂FT101_Value","信义污水厂SWCHHYHLB1_R_Value","信义污水厂SWCHHYHLB2_R_Value","信义污水厂SWCHHYHLB3_R_Value","信义污水厂SWCHHYHLB4_R_Value","信义污水厂SWCHHYHLB5_R_Value","信义污水厂SWCHHYHLB6_R_Value","信义污水厂SWCWNHLB1_R_Value","信义污水厂SWCWNHLB2_R_Value","信义污水厂SWCWNHLB3_R_Value","信义污水厂SWCWNHLB4_R_Value","信义污水厂SWCWNHLB5_R_Value","信义污水厂GFJ1_R_Value","信义污水厂GFJ2_R_Value","信义污水厂GFJ3_R_Value","信义污水厂GFJ4_R_Value","信义污水厂GFJ5_R_Value","信义污水厂GFJ6_R_Value","信义污水厂GFJ1_KQLL_Value","信义污水厂GFJ2_KQLL_Value","信义污水厂GFJ3_KQLL_Value","信义污水厂GFJ4_KQLL_Value","信义污水厂GFJ5_KQLL_Value","信义污水厂GFJ6_KQLL_Value","信义污水厂实际碳源加药量","信义污水厂除磷加药瞬时流量", "信义污水厂_除磷P04预测值_"};
  58. //
  59. // /**
  60. // * 定时从工业库获取数据
  61. // *
  62. // * 2024年4月17日17:44:15 调整逻辑:考虑到因断电等情况导致服务断电,所以不再同步最近一小时,而是同步从上次成功的最后一条数据开始。
  63. // */
  64. // public void getIndustryData(){
  65. // log.info("进入了定时同步工业库数据的任务");
  66. //
  67. // //耗时工具
  68. //// watch.start("parseJob");
  69. //
  70. //
  71. // // 给定时间段的起始时间和结束时间
  72. // LocalDateTime endTime = LocalDateTime.now();
  73. // //todo
  74. //// LocalDateTime startTime = endTime.plusMinutes(-60);
  75. // //获取上次最后一条同步的数据的日期到 分钟维度
  76. // String lastDateHour = this.xinyiIndustryMapper.getLastMinute();
  77. // log.info("获取上次同步工业库的最后一条记录的时间是{}", lastDateHour);
  78. // lastDateHour = lastDateHour + ":00";
  79. // //开始时间
  80. // LocalDateTime startTime = LocalDateTime.parse(lastDateHour.replaceAll("/", "-").replace(" ", "T"));
  81. // startTime = startTime.plusMinutes(1L);//加一分钟 从上次最后一条记录的下一分钟开始
  82. // /*LocalDateTime startTime = LocalDateTime.parse("2024-02-26T00:00:00");
  83. // LocalDateTime endTime = LocalDateTime.parse("2024-02-27T00:00:00");*/
  84. //
  85. // // 每个小时的时间格式
  86. // DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
  87. //
  88. // // 循环按小时分割
  89. // LocalDateTime currentHour = startTime;
  90. // while (currentHour.isBefore(endTime)) {
  91. // String begin = currentHour.format(formatter);
  92. // String end = currentHour.plusMinutes(5).format(formatter);
  93. // // 输出当前小时的起始时间和结束时间
  94. // System.out.println("起始时间:" + begin);
  95. // System.out.println("结束时间:" + end);
  96. //
  97. // // 当前小时加一小时,作为下一个小时的起始时间
  98. // currentHour = currentHour.plusMinutes(5);
  99. //
  100. // //每个小时查询一次数据
  101. // String url = "http://10.0.0.27:4568/api/v1/khquerydata";
  102. // HashMap<String, Object> req = new HashMap<>();
  103. // req.put("tagNames", queryTags);
  104. // req.put("startTime", begin);
  105. // req.put("endTime", end);
  106. // req.put("recordNumbers", 100000);
  107. // String body = HttpRequest.post(url).header("Authorization", "c2E6c2E=").header("clientName", "hongshan").body(JSON.toJSONString(req)).execute().body();
  108. //// System.out.println("body = " + body);
  109. // List<HashMap<String, String>> list = new ArrayList<>();
  110. //
  111. // //行转列数据处理
  112. // for (String queryTag : queryTags) {
  113. // JSONArray array = JSON.parseObject(body).getJSONArray(queryTag);
  114. // //特殊数据处理一
  115. // if(Objects.isNull(array) || array.isEmpty()){
  116. // System.out.println(queryTag + "查询到了空的数据,跳过本次循环");
  117. // continue;
  118. // }
  119. // int size = array.size();
  120. // //特殊数据处理二
  121. // if("0".equals(array.get(1) + "")){
  122. // System.out.println(queryTag + "查询到了数据,但是数据集合只有一条,且都是0");
  123. // continue;
  124. // }
  125. // //结合至少62个数据才满足条件(有可能获取不到)
  126. // /*if(size < 62){
  127. // System.out.println(queryTag + "查询到了不符合条件的数据,跳过本次循环");
  128. // continue;
  129. // }*/
  130. //
  131. // //存放的数据集
  132. // //利用map去重
  133. // HashMap<String, String> map = new LinkedHashMap<>();
  134. // for (int i = 2; i < size; i++) {
  135. //// System.out.println(i + "" + array.get(i));
  136. // JSONArray oneRecord = JSON.parseArray(JSON.toJSONString(array.get(i)));
  137. // //处理为空或者为0的数据
  138. // Object timeStampValue = oneRecord.get(2);
  139. // if(Objects.isNull(timeStampValue) || "0".equals(timeStampValue + ""))
  140. // continue;
  141. // BigDecimal value = Objects.isNull(oneRecord.get(0)) ? null : new BigDecimal(oneRecord.get(0) + "");
  142. // long timestamp = (long) timeStampValue;
  143. // String format = DateUtil.format(new Date(timestamp), DateUtils.YYYYMMDDHHMM_TS);
  144. // map.put(format, queryTag + "-" + value);
  145. // }
  146. // list.add(map);
  147. // }
  148. //
  149. // Set<String> recordTimeSet = new HashSet<>();
  150. // Map<String, TXinyiIndustry> recordMap = new HashMap<>();
  151. // for (int i = 0; i < list.size(); i++) {
  152. // HashMap<String, String> map = list.get(i);
  153. // int finalJ = i;
  154. // map.forEach((k, v) ->{
  155. // TXinyiIndustry industry = null;
  156. // if(!recordTimeSet.contains(k)){//第一次
  157. // industry = new TXinyiIndustry();
  158. // recordTimeSet.add(k);
  159. // recordMap.put(k, industry);
  160. // }else{
  161. // industry = recordMap.get(k);
  162. // }
  163. // industry.setTestTime(k);
  164. // //2024年4月15日11:19:52 额外增加2个字段
  165. // industry.setTestDate(k.substring(0,10));
  166. // industry.setTestHour(k.substring(0,13));
  167. // //解析值
  168. // String[] split = v.split("-");
  169. // String type = split[0];
  170. // BigDecimal value = new BigDecimal(split[1]);
  171. // if ("信义污水厂JS_COD_Value".equals(type)) {
  172. // industry.setJsCod(value);
  173. // } else if ("信义污水厂JS_PH_Value".equals(type)) {
  174. // industry.setJsPh(value);
  175. // } else if ("信义污水厂JS_SS_Value".equals(type)) {
  176. // industry.setJsSs(value);
  177. // } else if ("信义污水厂JS_ZL_Value".equals(type)) {
  178. // industry.setJsTp(value);
  179. // } else if ("信义污水厂JS_ZA_Value".equals(type)) {
  180. // industry.setJsTn(value);
  181. // } else if ("信义污水厂JS_AD_Value".equals(type)) {
  182. // industry.setJsNh3(value);
  183. // } else if ("信义污水厂JS_T_Value".equals(type)) {
  184. // industry.setJsSwPh(value);
  185. // } else if ("信义污水厂进水泵房液位".equals(type)) {
  186. // industry.setJsBfyw(value);
  187. // } else if ("信义污水厂出水瞬时流量".equals(type)) {
  188. // industry.setCsSlqc(value);
  189. // } else if ("信义污水厂升级出水COD".equals(type)) {
  190. // industry.setCsCod(value);
  191. // } else if ("信义污水厂升级出水PH".equals(type)) {
  192. // industry.setCsPh(value);
  193. // } else if ("信义污水厂升级出水SS".equals(type)) {
  194. // industry.setCsSs(value);
  195. // } else if ("信义污水厂升级出水TN".equals(type)) {
  196. // industry.setCsTn(value);
  197. // } else if ("信义污水厂升级出水TP".equals(type)) {
  198. // industry.setCsTp(value);
  199. // } else if ("信义污水厂升级出水氨氮".equals(type)) {
  200. // industry.setCsNh3(value);
  201. // } else if ("信义污水厂AIT202_Value".equals(type)) {
  202. // industry.setOneHyzdDo(value);
  203. // } else if ("信义污水厂AIT203_Value".equals(type)) {
  204. // industry.setOneHymdDo(value);
  205. // } else if ("信义污水厂AIT207_Value".equals(type)) {
  206. // industry.setTwoHyzdDo(value);
  207. // } else if ("信义污水厂AIT206_Value".equals(type)) {
  208. // industry.setTwoHymdDo(value);
  209. // } else if ("信义污水厂AIT209_Value".equals(type)) {
  210. // industry.setOneMlss(value);
  211. // } else if ("信义污水厂AIT210_Value".equals(type)) {
  212. // industry.setTwoMlss(value);
  213. // } else if ("信义污水厂进水TDS".equals(type)) {
  214. // industry.setJsTds(value);
  215. // } else if ("信义污水厂FT101_Value".equals(type)) {
  216. // industry.setJsSlq(value);
  217. // } else if ("信义污水厂SWCHHYHLB1_R_Value".equals(type)) {
  218. // industry.setNHlbOneGp(value);
  219. // } else if ("信义污水厂SWCHHYHLB2_R_Value".equals(type)) {
  220. // industry.setNHlbTwoGp(value);
  221. // } else if ("信义污水厂SWCHHYHLB3_R_Value".equals(type)) {
  222. // industry.setNHlbThreeGp(value);
  223. // } else if ("信义污水厂SWCHHYHLB4_R_Value".equals(type)) {
  224. // industry.setNHlbFourGp(value);
  225. // } else if ("信义污水厂SWCHHYHLB5_R_Value".equals(type)) {
  226. // industry.setNhlBFiveGp(value);
  227. // } else if ("信义污水厂SWCHHYHLB6_R_Value".equals(type)) {
  228. // industry.setNHlbSixGp(value);
  229. // } else if ("信义污水厂SWCWNHLB1_R_Value".equals(type)) {
  230. // industry.setWHlbOneGp(value);
  231. // } else if ("信义污水厂SWCWNHLB2_R_Value".equals(type)) {
  232. // industry.setWHlbTwoGp(value);
  233. // } else if ("信义污水厂SWCWNHLB3_R_Value".equals(type)) {
  234. // industry.setWHlbThreeGp(value);
  235. // } else if ("信义污水厂SWCWNHLB4_R_Value".equals(type)) {
  236. // industry.setWHlbFourGp(value);
  237. // } else if ("信义污水厂SWCWNHLB5_R_Value".equals(type)) {
  238. // industry.setWHlbFiveGp(value);
  239. // } else if ("信义污水厂GFJ1_R_Value".equals(type)) {
  240. // industry.setFjOne(value);
  241. // } else if ("信义污水厂GFJ2_R_Value".equals(type)) {
  242. // industry.setFjTwo(value);
  243. // } else if ("信义污水厂GFJ3_R_Value".equals(type)) {
  244. // industry.setFjThree(value);
  245. // } else if ("信义污水厂GFJ4_R_Value".equals(type)) {
  246. // industry.setFjFour(value);
  247. // } else if ("信义污水厂GFJ5_R_Value".equals(type)) {
  248. // industry.setFjFive(value);
  249. // } else if ("信义污水厂GFJ6_R_Value".equals(type)) {
  250. // industry.setFjSix(value);
  251. // } else if ("信义污水厂GFJ1_KQLL_Value".equals(type)) {
  252. // industry.setKqllOne(value);
  253. // } else if ("信义污水厂GFJ2_KQLL_Value".equals(type)) {
  254. // industry.setKqllTwo(value);
  255. // } else if ("信义污水厂GFJ3_KQLL_Value".equals(type)) {
  256. // industry.setKqllThree(value);
  257. // } else if ("信义污水厂GFJ4_KQLL_Value".equals(type)) {
  258. // industry.setKqllFour(value);
  259. // } else if ("信义污水厂GFJ5_KQLL_Value".equals(type)) {
  260. // industry.setKqllFive(value);
  261. // } else if ("信义污水厂GFJ6_KQLL_Value".equals(type)) {
  262. // industry.setKqllSix(value);
  263. // }else if ("信义污水厂实际碳源加药量".equals(type)) {
  264. // industry.setSJTYJLY(value);
  265. // }else if ("信义污水厂除磷加药瞬时流量".equals(type)) {
  266. // industry.setCLJYSSLL(value);
  267. // } else if ("信义污水厂_除磷P04预测值_".equals(type)) {
  268. // industry.setCLP04YCZ(value);
  269. // }
  270. // //只有最后一次才执行数据库添加
  271. // if(finalJ == list.size()-1){
  272. // //2024年4月22日15:45:24 额外保存两个字段 数组
  273. // List<BigDecimal> extraList = new ArrayList<>();
  274. // extraList.add(industry.getOneHymdDo());
  275. // extraList.add(industry.getTwoHymdDo());
  276. // industry.setHycRjyAll(JSON.toJSONString(extraList));
  277. // extraList.clear();
  278. // extraList.add(industry.getOneHyzdDo());
  279. // extraList.add(industry.getTwoHyzdDo());
  280. // industry.setHycRjyZdAll(JSON.toJSONString(extraList));
  281. // extraList.clear();
  282. // extraList.add(industry.getOneMlss());
  283. // extraList.add(industry.getTwoMlss());
  284. // industry.setHycWnndAll(JSON.toJSONString(extraList));
  285. // //插入数据库
  286. // xinyiIndustryMapper.insertTXinyiIndustry(industry);
  287. // }
  288. // });
  289. //
  290. // }
  291. //
  292. // }
  293. //
  294. // //执行完成 测试执行时间
  295. // //计时结束
  296. //// watch.stop();
  297. //// System.out.println(watch.getLastTaskName() + " 执行耗时:" + watch.getLastTaskTimeMillis() + " ms");
  298. // }
  299. //
  300. //
  301. // /**
  302. // * 定时从sqlserver获取数据
  303. // */
  304. // public void sqlserverData(){
  305. // log.info("进入了定时同步SqlServer的任务");
  306. // //主库获取上次最新的同步日期
  307. // String lastTime = this.xinyiRobotMapper.selectLastTime();
  308. // log.info("上次同步的日期是{}", lastTime);
  309. // //从
  310. // DynamicDataSourceContextHolder.setDataSourceType(DataSourceType.SLAVE.name());
  311. // List<TXinyiRobot> tXinyiRobots = xinyiRobotMapper.selectTXinyiRobotListByTime(lastTime);
  312. // DynamicDataSourceContextHolder.clearDataSourceType();
  313. //// System.out.println(JSON.toJSONString(tXinyiRobots));
  314. //// System.out.println("-------------");
  315. // //主
  316. // if(!CollectionUtils.isEmpty(tXinyiRobots)){
  317. // for (TXinyiRobot tXinyiRobot : tXinyiRobots) {
  318. // String date = handleDate(tXinyiRobot.getVDate().replaceAll(" ", ""));//有空格
  319. // String time = handleDate(tXinyiRobot.getVTime().replaceAll(" ", ""));//有空格
  320. // tXinyiRobot.setVDate(date);
  321. // tXinyiRobot.setVTime(time);
  322. // tXinyiRobot.setVDateTime(date + " " + time);
  323. // //处理给前端展示的字段
  324. // tXinyiRobot.setTestDate(date);//日期
  325. // tXinyiRobot.setTestHour(date + " " + time.substring(0, 2));//小时
  326. // tXinyiRobot.setTestTime(date + " " + time.substring(0, 5));//分钟
  327. // tXinyiRobot.setCreatedTime(new Date());
  328. // this.xinyiRobotMapper.insertTXinyiRobot(tXinyiRobot);
  329. // }
  330. // }
  331. //
  332. // }
  333. //
  334. //
  335. //
  336. // public static String handleDate(String str){
  337. // StringBuilder sb = new StringBuilder();
  338. // if(str.contains(" ")){//包含空格 就是年月日时分秒了
  339. // String[] split = str.split(" ");
  340. // addBeforeZero(sb, split[0], "/");
  341. // sb.append(" ");
  342. // addBeforeZero(sb, split[1], ":");
  343. // }else{
  344. // if(str.contains("/")){//年月日
  345. // addBeforeZero(sb, str, "/");
  346. // }else if(str.contains(":")){//时分秒
  347. // addBeforeZero(sb, str, ":");
  348. // }else {
  349. // sb.append(str);
  350. // }
  351. // }
  352. // return sb.toString();
  353. // }
  354. //
  355. // public static StringBuilder addBeforeZero(StringBuilder sb, String str, String tag){
  356. // String[] split = str.split(tag);
  357. // int length = split.length;
  358. // for (int i = 0; i < length; i++) {
  359. // String value = split[i];
  360. // Integer intValue = Integer.parseInt(value);
  361. // if(intValue < 10 && value.length() == 1){////防止有正确的情况 额外再补充字符串
  362. // sb.append(0).append(value);
  363. // }else{
  364. // sb.append(value);
  365. // }
  366. // if(i < length-1){
  367. // sb.append(tag);
  368. // }
  369. // }
  370. // return sb;
  371. // }
  372. //
  373. // public static void main(String[] args) {
  374. // /*LocalDateTime endTime = LocalDateTime.now();
  375. // System.out.println("endTime = " + endTime);
  376. // endTime = endTime.plusMinutes(60);
  377. // System.out.println("endTime = " + endTime);*/
  378. // /*String str = "2024/04/15 09:55";
  379. // System.out.println(str);
  380. // System.out.println(str.substring(0,10));
  381. // System.out.println(str.substring(0,13));*/
  382. //
  383. // /*String str = "2024/04/18 08:00";
  384. // str = str + ":00";
  385. // System.out.println(str);
  386. // LocalDateTime startTime = LocalDateTime.parse(str.replaceAll("/", "-").replace(" ", "T"));
  387. // System.out.println(startTime.plusMinutes(1L).format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));*/
  388. //
  389. // ArrayList<Integer> objects = new ArrayList<>();
  390. // objects.add(1);
  391. // objects.add(2);
  392. // objects.add(3);
  393. // System.out.println(objects);
  394. // objects.clear();
  395. // System.out.println(objects);
  396. //
  397. // }
  398. //}