123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355 |
- package com.ruoyi;
- import cn.hutool.core.date.DateField;
- import cn.hutool.core.date.DateRange;
- import cn.hutool.core.date.DateTime;
- import cn.hutool.core.date.DateUtil;
- import cn.hutool.core.text.csv.CsvUtil;
- import cn.hutool.core.text.csv.CsvWriter;
- import cn.hutool.core.thread.ExecutorBuilder;
- import cn.hutool.core.thread.ThreadUtil;
- import cn.hutool.core.util.CharsetUtil;
- import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
- import com.ruoyi.ucp.entity.GlycSj;
- import com.ruoyi.ucp.entity.PointData;
- import com.ruoyi.ucp.entity.PointInfo;
- import com.ruoyi.ucp.feign.AdapterApi;
- import com.ruoyi.ucp.service.IPointInfoService;
- import com.ruoyi.web.controller.JavaFunctionJobHandler;
- import org.junit.Test;
- import org.junit.runner.RunWith;
- import org.springframework.boot.test.context.SpringBootTest;
- import org.springframework.test.context.junit4.SpringRunner;
- import javax.annotation.Resource;
- import java.net.URI;
- import java.util.*;
- import java.util.concurrent.ExecutionException;
- import java.util.concurrent.ExecutorService;
- import java.util.concurrent.Future;
- import java.util.function.Function;
- import java.util.stream.Collectors;
- @SpringBootTest
- @RunWith(SpringRunner.class)
- public class GetDataTest {
- @Resource
- private IPointInfoService pointInfoService;
- @Resource
- private AdapterApi adapterApi;
- @Resource
- private JavaFunctionJobHandler task;
- @Test
- public void test2() {
- DateTime begin = DateUtil.parse("2023-04-18");
- DateTime end = DateUtil.parse("2024-11-03");
-
- int i = 1;
- DateTime minBegin = begin, minEnd = DateUtil.offsetMinute(begin, 15);
- while (minEnd.isBefore(end)) {
- minEnd = DateUtil.offsetMinute(begin, i * 15);
- task.calcStationSjglAgcPjfsHjwdDlMin(minBegin, minEnd, "GJNY_SXGS_CSL_FDC_STA");
- System.out.println(minBegin.toString() + "," + minEnd.toString());
- i++;
- minBegin = minEnd;
- }
- }
- @Test
- public void test5() {
- task.getPoint();
- }
- @Test
- public void test6() {
- DateTime begin = DateUtil.parse("2023-04-18");
- DateTime end = DateUtil.parse("2024-11-03");
-
- int i = 1;
- DateTime minBegin = begin, minEnd = DateUtil.offsetMinute(begin, 15);
- while (minEnd.isBefore(end)) {
- minEnd = DateUtil.offsetMinute(begin, i * 15);
- task.calcStationMinZtts(minEnd, "GJNY_SXGS_JSL_FDC_STA");
- System.out.println(minBegin.toString() + "," + minEnd.toString());
- i++;
- minBegin = minEnd;
- }
- }
- @Test
- public void test3() {
- DateTime start = DateUtil.parse("2024-10-31");
- DateTime end = DateUtil.parse("2024-11-03");
- DateRange range = DateUtil.range(start, end, DateField.DAY_OF_YEAR);
- for (DateTime date : range) {
- task.calcPredictExamin(date);
- }
- }
- @Test
- public void test() {
- DateTime start = DateUtil.parse("2023-03-20");
- DateTime end = DateUtil.parse("2024-10-16");
-
-
- String[] names = {"AI114", "AI066", "AI060", "AI067", "AI082", "AI073", "AI004", "AI047", "AI072", "AI074"};
-
- QueryWrapper<PointInfo> wrapper = new QueryWrapper<>();
- wrapper.lambda().eq(PointInfo::getInstitutionType, "turbine")
-
- .in(PointInfo::getUniformCode, names);
- List<PointInfo> list = pointInfoService.list(wrapper);
-
-
- String a = "GJNY_SXGS_FSG_F_WT_0022_EQ\n" +
- "GJNY_SXGS_FSG_F_WT_0064_EQ\n";
-
- list = list.stream().filter(pi -> a.contains(pi.getTurbineId())).collect(Collectors.toList());
-
- Map<String, Map<String, List<PointInfo>>> collect = list.stream().collect(Collectors.groupingBy(PointInfo::getStationId, Collectors.groupingBy(PointInfo::getTurbineId)));
- ExecutorService executor = ExecutorBuilder.create()
- .setCorePoolSize(3)
- .setMaxPoolSize(3)
- .build();
- Vector<Future<String>> fts = new Vector<>();
- Vector<Future<String>> ftfs = new Vector<>();
- collect.forEach((stId, tbPiMap) -> {
- tbPiMap.forEach((tbId, Pis) -> {
- Future<String> future = executor.submit(() -> {
- List<PointData> zt = task.calcTurbineSimpleZt(start, end, 60 * 5, tbId);
- Map<String, GlycSj> map = new TreeMap<>();
- for (PointInfo info : Pis) {
- try {
- long j = start.getTime();
- List<PointData> s = adapterApi.getHistorySnap(URI.create("http://172.16.12.103:8017/ts"), info.getPointKey(),
- j, end.getTime(), 60 * 5);
- String dt = null;
- GlycSj glycSj = null;
-
-
- if (s == null || s.isEmpty()) {
- System.out.println(tbId + "," + info.getUniformCode());
- }
- switch (info.getUniformCode()) {
- case "AI114":
- for (int i = 0; i < s.size(); i++) {
- dt = DateUtil.formatDateTime(new Date(j));
- glycSj = map.get(dt);
- if (glycSj == null) {
- glycSj = new GlycSj();
- map.put(dt, glycSj);
- }
- glycSj.setGl(s.get(i).getValue());
- glycSj.setZt(zt.get(i) == null ? null : zt.get(i).getValue());
-
- j += 60 * 1000 * 5;
-
- glycSj.setTurbineId(info.getTurbineId().replaceFirst("GJNY_SXGS_.+_F_WT_", "").replaceFirst("_EQ", ""));
- }
- break;
- case "AI066":
- for (int i = 0; i < s.size(); i++) {
- dt = DateUtil.formatDateTime(new Date(j));
- glycSj = map.get(dt);
- if (glycSj == null) {
- glycSj = new GlycSj();
- map.put(dt, glycSj);
- }
- glycSj.setFs(s.get(i).getValue());
- j += 60 * 1000 * 5;
- }
- break;
- case "AI060":
- for (int i = 0; i < s.size(); i++) {
- dt = DateUtil.formatDateTime(new Date(j));
- glycSj = map.get(dt);
- if (glycSj == null) {
- glycSj = new GlycSj();
- map.put(dt, glycSj);
- }
- glycSj.setFdjzs(s.get(i).getValue());
- j += 60 * 1000 * 5;
- }
- break;
- case "AI065":
- for (int i = 0; i < s.size(); i++) {
- dt = DateUtil.formatDateTime(new Date(j));
- glycSj = map.get(dt);
- if (glycSj == null) {
- glycSj = new GlycSj();
- map.put(dt, glycSj);
- }
- glycSj.setZt(s.get(i).getValue());
- j += 60 * 1000 * 5;
- }
- break;
- case "AI067":
- for (int i = 0; i < s.size(); i++) {
- dt = DateUtil.formatDateTime(new Date(j));
- glycSj = map.get(dt);
- if (glycSj == null) {
- glycSj = new GlycSj();
- map.put(dt, glycSj);
- }
- glycSj.setFx(s.get(i).getValue());
- j += 60 * 1000 * 5;
- }
- break;
- case "AI082":
- for (int i = 0; i < s.size(); i++) {
- dt = DateUtil.formatDateTime(new Date(j));
- glycSj = map.get(dt);
- if (glycSj == null) {
- glycSj = new GlycSj();
- map.put(dt, glycSj);
- }
- glycSj.setJyjd(s.get(i).getValue());
- j += 60 * 1000 * 5;
- }
- break;
- case "AI073":
- for (int i = 0; i < s.size(); i++) {
- dt = DateUtil.formatDateTime(new Date(j));
- glycSj = map.get(dt);
- if (glycSj == null) {
- glycSj = new GlycSj();
- map.put(dt, glycSj);
- }
- glycSj.setDfjd(s.get(i).getValue());
- j += 60 * 1000 * 5;
- }
- break;
- case "AI004":
- for (int i = 0; i < s.size(); i++) {
- dt = DateUtil.formatDateTime(new Date(j));
- glycSj = map.get(dt);
- if (glycSj == null) {
- glycSj = new GlycSj();
- map.put(dt, glycSj);
- }
- glycSj.setNjwd(s.get(i).getValue());
- j += 60 * 1000 * 5;
- }
- break;
- case "AI047":
- for (int i = 0; i < s.size(); i++) {
- dt = DateUtil.formatDateTime(new Date(j));
- glycSj = map.get(dt);
- if (glycSj == null) {
- glycSj = new GlycSj();
- map.put(dt, glycSj);
- }
- glycSj.setDjwd(s.get(i).getValue());
- j += 60 * 1000 * 5;
- }
- break;
- case "AI072":
- for (int i = 0; i < s.size(); i++) {
- dt = DateUtil.formatDateTime(new Date(j));
- glycSj = map.get(dt);
- if (glycSj == null) {
- glycSj = new GlycSj();
- map.put(dt, glycSj);
- }
- glycSj.setHjwd(s.get(i).getValue());
- j += 60 * 1000 * 5;
- }
- break;
- case "AI074":
- for (int i = 0; i < s.size(); i++) {
- dt = DateUtil.formatDateTime(new Date(j));
- glycSj = map.get(dt);
- if (glycSj == null) {
- glycSj = new GlycSj();
- map.put(dt, glycSj);
- }
- glycSj.setJcwd(s.get(i).getValue());
- j += 60 * 1000 * 5;
- }
- break;
- }
- map.forEach((k, v) -> {
- v.setTime(k);
- });
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- Future<String> b = ThreadUtil.execAsync(() -> {
- writerData(map.values(), stId, tbId);
- return "ok";
- });
- ftfs.add(b);
- return "ok";
- });
- fts.add(future);
- });
- });
- for (Future<String> ft : fts) {
- try {
- ft.get();
- } catch (InterruptedException e) {
- throw new RuntimeException(e);
- } catch (ExecutionException e) {
- throw new RuntimeException(e);
- }
- }
- for (Future<String> ft : ftfs) {
- try {
- ft.get();
- } catch (InterruptedException e) {
- throw new RuntimeException(e);
- } catch (ExecutionException e) {
- throw new RuntimeException(e);
- }
- }
-
-
-
- }
-
- void writerData(Collection<GlycSj> values, String stId, String tbId) {
- CsvWriter writer = CsvUtil.getWriter("D:/数据/" + stId + "/" + tbId + ".csv", CharsetUtil.CHARSET_UTF_8);
- writer.writeBeans(values);
- writer.flush();
- }
- }
|