|
@@ -0,0 +1,410 @@
|
|
|
+package com.gyee.frame.service.redar;
|
|
|
+
|
|
|
+import cn.hutool.core.date.DatePattern;
|
|
|
+import cn.hutool.core.date.DateUtil;
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
+import com.alibaba.fastjson.JSONArray;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
+import org.slf4j.Logger;
|
|
|
+import org.slf4j.LoggerFactory;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
+import java.io.*;
|
|
|
+import java.net.HttpURLConnection;
|
|
|
+import java.net.URL;
|
|
|
+import java.text.DecimalFormat;
|
|
|
+import java.util.*;
|
|
|
+
|
|
|
+@Service
|
|
|
+public class RedarService {
|
|
|
+ private static final Logger log = LoggerFactory.getLogger(RedarService.class);
|
|
|
+
|
|
|
+ public List<Map> hitch(String stId, String Date) {
|
|
|
+ String url = "http://192.168.1.18:8075/shutdown/list?stId=MHS_FDC&endDate=2021-11-21&startDate=2021-11-22";
|
|
|
+
|
|
|
+ String str = doGet(url);
|
|
|
+ List<Map> object = parseJSON(str);
|
|
|
+
|
|
|
+
|
|
|
+ String[] splitdata = Date.split("-");
|
|
|
+
|
|
|
+ Map<String, String> TimeMap = new HashMap<>();
|
|
|
+ //月份
|
|
|
+ TimeMap.put("monthstarttime", DateUtil.format(DateUtil.beginOfMonth(DateUtil.parseDate(Date)), DatePattern.NORM_DATETIME_MINUTE_PATTERN));
|
|
|
+ TimeMap.put("monthendtime", DateUtil.format(DateUtil.endOfMonth(DateUtil.parseDate(Date)), DatePattern.NORM_DATETIME_MINUTE_PATTERN));
|
|
|
+ //年份
|
|
|
+ TimeMap.put("yearstarttime", DateUtil.format(DateUtil.beginOfYear(DateUtil.parseDate(Date)), DatePattern.NORM_DATETIME_MINUTE_PATTERN));
|
|
|
+ TimeMap.put("yearendtime", DateUtil.format(DateUtil.endOfYear(DateUtil.parseDate(Date)), DatePattern.NORM_DATETIME_MINUTE_PATTERN));
|
|
|
+ //一天
|
|
|
+ TimeMap.put("daystarttime", DateUtil.format(DateUtil.beginOfDay(DateUtil.parseDate(Date)), DatePattern.NORM_DATETIME_MINUTE_PATTERN));
|
|
|
+ TimeMap.put("dayendtime", DateUtil.format(DateUtil.endOfDay(DateUtil.parseDate(Date)), DatePattern.NORM_DATETIME_MINUTE_PATTERN));
|
|
|
+
|
|
|
+ url = url.replaceAll("startDate=[0-9\\-]*", "startDate=" + TimeMap.get("yearstarttime"))
|
|
|
+ .replaceAll("endDate=[0-9\\-]*", "endDate=" + TimeMap.get("yearendtime"))
|
|
|
+ + "&startmonth=" + TimeMap.get("monthstarttime") + "&endmonth=" + TimeMap.get("monthendtime")
|
|
|
+ + "&beginday=" + TimeMap.get("daystarttime") + "&endday=" + TimeMap.get("dayendtime");
|
|
|
+
|
|
|
+ return object;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Http get请求
|
|
|
+ *
|
|
|
+ * @param httpUrl 连接
|
|
|
+ * @return 响应数据
|
|
|
+ */
|
|
|
+ public String doGet(String httpUrl) {
|
|
|
+ //链接
|
|
|
+ HttpURLConnection connection = null;
|
|
|
+ InputStream is = null;
|
|
|
+ BufferedReader br = null;
|
|
|
+ StringBuffer result = new StringBuffer();
|
|
|
+ try {
|
|
|
+ //创建连接
|
|
|
+ URL url = new URL(httpUrl);
|
|
|
+ connection = (HttpURLConnection) url.openConnection();
|
|
|
+ //设置请求方式
|
|
|
+ connection.setRequestMethod("GET");
|
|
|
+ //设置连接超时时间
|
|
|
+ connection.setReadTimeout(15000);
|
|
|
+ //开始连接
|
|
|
+ connection.connect();
|
|
|
+ //获取响应数据
|
|
|
+ if (connection.getResponseCode() == 200) {
|
|
|
+ //获取返回的数据
|
|
|
+ is = connection.getInputStream();
|
|
|
+ if (null != is) {
|
|
|
+ br = new BufferedReader(new InputStreamReader(is, "UTF-8"));
|
|
|
+ String temp = null;
|
|
|
+ while (null != (temp = br.readLine())) {
|
|
|
+ result.append(temp);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } catch (IOException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ } finally {
|
|
|
+ if (null != br) {
|
|
|
+ try {
|
|
|
+ br.close();
|
|
|
+ } catch (IOException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (null != is) {
|
|
|
+ try {
|
|
|
+ is.close();
|
|
|
+ } catch (IOException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //关闭远程连接
|
|
|
+ connection.disconnect();
|
|
|
+ }
|
|
|
+ return result.toString();
|
|
|
+ }
|
|
|
+
|
|
|
+ public List<Map> parseJSON(String jsonData) {
|
|
|
+ try {
|
|
|
+ JSONObject object = JSON.parseObject(jsonData);
|
|
|
+ JSONArray data1 = object.getJSONArray("data");
|
|
|
+
|
|
|
+ double count = 0;
|
|
|
+ int stationId = 0;
|
|
|
+ int windturbineId = 0;
|
|
|
+ int type = 0;
|
|
|
+ int typeID = 0;
|
|
|
+ int time = 0;
|
|
|
+
|
|
|
+ int bj = 0;
|
|
|
+ int fjqt = 0;
|
|
|
+ int fdj = 0;
|
|
|
+ int clx = 0;
|
|
|
+ int bpq = 0;
|
|
|
+ int zz = 0;
|
|
|
+ int hh = 0;
|
|
|
+ int ph = 0;
|
|
|
+ int yy = 0;
|
|
|
+ int lq = 0;
|
|
|
+ int rh = 0;
|
|
|
+ int kz = 0;
|
|
|
+ int jcjr = 0;
|
|
|
+
|
|
|
+ for (int i = 0; i < data1.size(); i++) {
|
|
|
+ JSONObject objecti = data1.getJSONObject(i);
|
|
|
+ Set<String> keys = objecti.keySet();
|
|
|
+ for (String key : keys) {
|
|
|
+ JSONArray array = objecti.getJSONArray(key);
|
|
|
+ for (int j = 0; j < array.size(); j++) {
|
|
|
+ JSONObject jsonObject = array.getJSONObject(j);
|
|
|
+
|
|
|
+ count += jsonObject.getInteger("count");
|
|
|
+ time += jsonObject.getInteger("time");
|
|
|
+
|
|
|
+ String c = jsonObject.getString("typeID");
|
|
|
+
|
|
|
+ if (c.equals("bj")) {
|
|
|
+ bj += jsonObject.getInteger("count");
|
|
|
+ } else if (c.equals("fjqt")) {
|
|
|
+ fjqt += jsonObject.getInteger("count");
|
|
|
+ } else if (c.equals("fdj")) {
|
|
|
+ fdj += jsonObject.getInteger("count");
|
|
|
+ } else if (c.equals("clx")) {
|
|
|
+ clx += jsonObject.getInteger("count");
|
|
|
+ } else if (c.equals("bpq")) {
|
|
|
+ bpq += jsonObject.getInteger("count");
|
|
|
+ } else if (c.equals("zz")) {
|
|
|
+ zz += jsonObject.getInteger("count");
|
|
|
+ } else if (c.equals("hh")) {
|
|
|
+ hh += jsonObject.getInteger("count");
|
|
|
+ } else if (c.equals("ph")) {
|
|
|
+ ph += jsonObject.getInteger("count");
|
|
|
+ } else if (c.equals("yy")) {
|
|
|
+ yy += jsonObject.getInteger("count");
|
|
|
+ } else if (c.equals("lq")) {
|
|
|
+ lq += jsonObject.getInteger("count");
|
|
|
+ } else if (c.equals("rh")) {
|
|
|
+ rh += jsonObject.getInteger("count");
|
|
|
+ } else if (c.equals("kz")) {
|
|
|
+ kz += jsonObject.getInteger("count");
|
|
|
+ } else if (c.equals("jcjr")) {
|
|
|
+ jcjr += jsonObject.getInteger("count");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ JSONObject jsonObject1 = new JSONObject();
|
|
|
+ jsonObject1.put("bj", bj);
|
|
|
+ jsonObject1.put("fjqt", fjqt);
|
|
|
+ jsonObject1.put("fdj", fdj);
|
|
|
+ jsonObject1.put("clx", clx);
|
|
|
+ jsonObject1.put("bpq", bpq);
|
|
|
+ jsonObject1.put("zz", zz);
|
|
|
+ jsonObject1.put("hh", hh);
|
|
|
+ jsonObject1.put("ph", ph);
|
|
|
+ jsonObject1.put("yy", yy);
|
|
|
+ jsonObject1.put("lq", lq);
|
|
|
+ jsonObject1.put("rh", rh);
|
|
|
+ jsonObject1.put("kz", kz);
|
|
|
+ jsonObject1.put("jcjr", jcjr);
|
|
|
+ jsonObject1.put("count", count);
|
|
|
+ jsonObject1.put("time", time);
|
|
|
+
|
|
|
+ List<Map> conver = new ArrayList<>();
|
|
|
+
|
|
|
+ DecimalFormat df = new DecimalFormat("0.00");
|
|
|
+
|
|
|
+ Map<String, String> year = new HashMap<>();
|
|
|
+ year.put("变桨", df.format(bj / count));
|
|
|
+ year.put("风机其它", df.format(fjqt / count));
|
|
|
+ year.put("齿轮箱", df.format(clx / count));
|
|
|
+ year.put("变频器", df.format(bpq / count));
|
|
|
+ year.put("主轴", df.format(zz / count));
|
|
|
+ year.put("滑环", df.format(hh / count));
|
|
|
+ year.put("偏航", df.format(ph / count));
|
|
|
+ year.put("液压", df.format(yy / count));
|
|
|
+ year.put("冷却", df.format(lq / count));
|
|
|
+ year.put("润滑", df.format(rh / count));
|
|
|
+ year.put("控制", df.format(kz / count));
|
|
|
+ year.put("机舱加热", df.format(jcjr / count));
|
|
|
+
|
|
|
+ JSONObject year1 = new JSONObject();
|
|
|
+ year1.put("year", year);
|
|
|
+ conver.add(year1);
|
|
|
+
|
|
|
+ Map<String, String> month = new HashMap<>();
|
|
|
+ month.put("变桨", df.format(bj / count));
|
|
|
+ month.put("风机其它", df.format(fjqt / count));
|
|
|
+ month.put("齿轮箱", df.format(clx / count));
|
|
|
+ month.put("变频器", df.format(bpq / count));
|
|
|
+ month.put("主轴", df.format(zz / count));
|
|
|
+ month.put("滑环", df.format(hh / count));
|
|
|
+ month.put("偏航", df.format(ph / count));
|
|
|
+ month.put("液压", df.format(yy / count));
|
|
|
+ month.put("冷却", df.format(lq / count));
|
|
|
+ month.put("润滑", df.format(rh / count));
|
|
|
+ month.put("控制", df.format(kz / count));
|
|
|
+ month.put("机舱加热", df.format(jcjr / count));
|
|
|
+ JSONObject month1 = new JSONObject();
|
|
|
+ month1.put("month", month);
|
|
|
+ conver.add(month1);
|
|
|
+
|
|
|
+ Map<String, String> day = new HashMap<>();
|
|
|
+ day.put("变桨", df.format(bj / count));
|
|
|
+ day.put("风机其它", df.format(fjqt / count));
|
|
|
+ day.put("齿轮箱", df.format(clx / count));
|
|
|
+ day.put("变频器", df.format(bpq / count));
|
|
|
+ day.put("主轴", df.format(zz / count));
|
|
|
+ day.put("滑环", df.format(hh / count));
|
|
|
+ day.put("偏航", df.format(ph / count));
|
|
|
+ day.put("液压", df.format(yy / count));
|
|
|
+ day.put("冷却", df.format(lq / count));
|
|
|
+ day.put("润滑", df.format(rh / count));
|
|
|
+ day.put("控制", df.format(kz / count));
|
|
|
+ day.put("机舱加热", df.format(jcjr / count));
|
|
|
+ JSONObject day1 = new JSONObject();
|
|
|
+ day1.put("day", day);
|
|
|
+ conver.add(day1);
|
|
|
+
|
|
|
+ return conver;
|
|
|
+
|
|
|
+ } catch (Exception e) {
|
|
|
+ System.out.println(e.getMessage());
|
|
|
+ }
|
|
|
+
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ public List<Map> warning(String stationid, String date) {
|
|
|
+ String url1 = "http://192.168.1.18:8075/alarm/count/query/new?stationid=MHS_FDC&startdate=2021-11-23&enddate=2021-11-24";
|
|
|
+ String st = doGet(url1);
|
|
|
+ List<Map> object = pron(st);
|
|
|
+
|
|
|
+ String[] splitdata = date.split("-");
|
|
|
+
|
|
|
+ Map<String, String> timeMap = new HashMap<>();
|
|
|
+ //月份
|
|
|
+ timeMap.put("monthstarttime", DateUtil.format(DateUtil.beginOfMonth(DateUtil.parseDate(date)), DatePattern.NORM_DATETIME_MINUTE_PATTERN));
|
|
|
+ timeMap.put("monthendtime", DateUtil.format(DateUtil.endOfMonth(DateUtil.parseDate(date)), DatePattern.NORM_DATETIME_MINUTE_PATTERN));
|
|
|
+ //年份
|
|
|
+ timeMap.put("yearstarttime", DateUtil.format(DateUtil.beginOfYear(DateUtil.parseDate(date)), DatePattern.NORM_DATETIME_MINUTE_PATTERN));
|
|
|
+ timeMap.put("yearendtime", DateUtil.format(DateUtil.endOfYear(DateUtil.parseDate(date)), DatePattern.NORM_DATETIME_MINUTE_PATTERN));
|
|
|
+ //一天
|
|
|
+ timeMap.put("daystarttime", DateUtil.format(DateUtil.beginOfDay(DateUtil.parseDate(date)), DatePattern.NORM_DATETIME_MINUTE_PATTERN));
|
|
|
+ timeMap.put("dayendtime", DateUtil.format(DateUtil.endOfDay(DateUtil.parseDate(date)), DatePattern.NORM_DATETIME_MINUTE_PATTERN));
|
|
|
+
|
|
|
+ url1 = url1.replaceAll("startdate=[0-9\\-]*", "startdate=" + timeMap.get("yearstarttime"))
|
|
|
+ .replaceAll("enddate=[0-9\\-]*", "enddate=" + timeMap.get("yearendtime"))
|
|
|
+ + "&startmonth=" + timeMap.get("monthstarttime") + "&endmonth=" + timeMap.get("monthendtime")
|
|
|
+ + "&beginday=" + timeMap.get("daystarttime") + "&endday=" + timeMap.get("dayendtime");
|
|
|
+
|
|
|
+ return object;
|
|
|
+ }
|
|
|
+
|
|
|
+ public List<Map> pron(String jsonData1) {
|
|
|
+ JSONObject object = JSON.parseObject(jsonData1);
|
|
|
+ JSONArray data2 = object.getJSONArray("data");
|
|
|
+
|
|
|
+ double count = 0;
|
|
|
+ int time = 0;
|
|
|
+
|
|
|
+ int CFXT = 0;
|
|
|
+ int CDL = 0;
|
|
|
+ int FDJ = 0;
|
|
|
+ int BJXT = 0;
|
|
|
+ int CLX = 0;
|
|
|
+ int YYXT = 0;
|
|
|
+ int PHXT = 0;
|
|
|
+ int JC = 0;
|
|
|
+ int QT = 0;
|
|
|
+ int TDG = 0;
|
|
|
+ for (int i = 0; i < data2.size(); i++) {
|
|
|
+ JSONObject objecti = data2.getJSONObject(i);
|
|
|
+ Set<String> keys = objecti.keySet();
|
|
|
+ for (String key : keys) {
|
|
|
+ JSONArray array = objecti.getJSONArray(key);
|
|
|
+ for (int j = 0; j < array.size(); j++) {
|
|
|
+ JSONObject jsonObject = array.getJSONObject(j);
|
|
|
+
|
|
|
+ count += jsonObject.getInteger("count");
|
|
|
+ time += jsonObject.getInteger("time");
|
|
|
+
|
|
|
+ String c = jsonObject.getString("relateParts");
|
|
|
+ if (StringUtils.isEmpty(c))
|
|
|
+ continue;
|
|
|
+
|
|
|
+ if (c.equals("CFXT")) {
|
|
|
+ CFXT += jsonObject.getInteger("count");
|
|
|
+ } else if (c.equals("CDL")) {
|
|
|
+ CDL += jsonObject.getInteger("count");
|
|
|
+ } else if (c.equals("FDJ")) {
|
|
|
+ FDJ += jsonObject.getInteger("count");
|
|
|
+ } else if (c.equals("BJXT")) {
|
|
|
+ BJXT += jsonObject.getInteger("count");
|
|
|
+ } else if (c.equals("CLX")) {
|
|
|
+ CLX += jsonObject.getInteger("count");
|
|
|
+ } else if (c.equals("YYXT")) {
|
|
|
+ YYXT += jsonObject.getInteger("count");
|
|
|
+ } else if (c.equals("PHXT")) {
|
|
|
+ PHXT += jsonObject.getInteger("count");
|
|
|
+ } else if (c.equals("JC")) {
|
|
|
+ JC += jsonObject.getInteger("count");
|
|
|
+ } else if (c.equals("QT")) {
|
|
|
+ QT += jsonObject.getInteger("count");
|
|
|
+ } else if (c.equals("TDG")) {
|
|
|
+ TDG += jsonObject.getInteger("count");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ JSONObject jsonObject2 = new JSONObject();
|
|
|
+ jsonObject2.put("CFXT", CFXT);
|
|
|
+ jsonObject2.put("CDL", CDL);
|
|
|
+ jsonObject2.put("FDJ", FDJ);
|
|
|
+ jsonObject2.put("BJXT", BJXT);
|
|
|
+ jsonObject2.put("CLX", CLX);
|
|
|
+ jsonObject2.put("YYXT", YYXT);
|
|
|
+ jsonObject2.put("PHXT", PHXT);
|
|
|
+ jsonObject2.put("JC", JC);
|
|
|
+ jsonObject2.put("QT", QT);
|
|
|
+ jsonObject2.put("TDG", TDG);
|
|
|
+ jsonObject2.put("count", count);
|
|
|
+ jsonObject2.put("time", time);
|
|
|
+
|
|
|
+ List<Map> conver = new ArrayList<>();
|
|
|
+
|
|
|
+ DecimalFormat df = new DecimalFormat("0.00");
|
|
|
+
|
|
|
+ Map<String, String> year = new HashMap<>();
|
|
|
+ year.put("测风系统", df.format(CFXT / count));
|
|
|
+ year.put("传动链", df.format(CDL / count));
|
|
|
+ year.put("发电机", df.format(FDJ / count));
|
|
|
+ year.put("变桨系统", df.format(BJXT / count));
|
|
|
+ year.put("齿轮箱", df.format(CLX / count));
|
|
|
+ year.put("液压系统", df.format(YYXT / count));
|
|
|
+ year.put("偏航系统", df.format(PHXT / count));
|
|
|
+ year.put("机舱", df.format(JC / count));
|
|
|
+ year.put("其它", df.format(QT / count));
|
|
|
+ year.put("塔底柜", df.format(TDG / count));
|
|
|
+
|
|
|
+ JSONObject year1 = new JSONObject();
|
|
|
+ year1.put("year", year);
|
|
|
+ conver.add(year1);
|
|
|
+
|
|
|
+ Map<String, String> month = new HashMap<>();
|
|
|
+ month.put("测风系统", df.format(CFXT / count));
|
|
|
+ month.put("传动链", df.format(CDL / count));
|
|
|
+ month.put("发电机", df.format(FDJ / count));
|
|
|
+ month.put("变桨系统", df.format(BJXT / count));
|
|
|
+ month.put("齿轮箱", df.format(CLX / count));
|
|
|
+ month.put("液压系统", df.format(YYXT / count));
|
|
|
+ month.put("偏航系统", df.format(PHXT / count));
|
|
|
+ month.put("机舱", df.format(JC / count));
|
|
|
+ month.put("其它", df.format(QT / count));
|
|
|
+ month.put("塔底柜", df.format(TDG / count));
|
|
|
+
|
|
|
+ JSONObject month1 = new JSONObject();
|
|
|
+ month1.put("month", month);
|
|
|
+ conver.add(month1);
|
|
|
+
|
|
|
+ Map<String, String> day = new HashMap<>();
|
|
|
+ day.put("测风系统", df.format(CFXT / count));
|
|
|
+ day.put("传动链", df.format(CDL / count));
|
|
|
+ day.put("发电机", df.format(FDJ / count));
|
|
|
+ day.put("变桨系统", df.format(BJXT / count));
|
|
|
+ day.put("齿轮箱", df.format(CLX / count));
|
|
|
+ day.put("液压系统", df.format(YYXT / count));
|
|
|
+ day.put("偏航系统", df.format(PHXT / count));
|
|
|
+ day.put("机舱", df.format(JC / count));
|
|
|
+ day.put("其它", df.format(QT / count));
|
|
|
+ day.put("塔底柜", df.format(TDG / count));
|
|
|
+ JSONObject day1 = new JSONObject();
|
|
|
+ day1.put("day", day);
|
|
|
+ conver.add(day1);
|
|
|
+
|
|
|
+ return conver;
|
|
|
+ }
|
|
|
+
|
|
|
+}
|