|
@@ -0,0 +1,261 @@
|
|
|
+package com.gyee.impala;
|
|
|
+
|
|
|
+import com.alibaba.fastjson.JSONArray;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.gyee.impala.common.feign.IShardingService;
|
|
|
+import com.gyee.impala.common.util.DateUtil;
|
|
|
+import com.gyee.impala.model.custom.AlertHistory;
|
|
|
+import feign.Feign;
|
|
|
+import feign.Request;
|
|
|
+import feign.Retryer;
|
|
|
+import feign.jackson.JacksonDecoder;
|
|
|
+import feign.jackson.JacksonEncoder;
|
|
|
+import org.apache.poi.hssf.usermodel.HSSFRow;
|
|
|
+import org.apache.poi.hssf.usermodel.HSSFSheet;
|
|
|
+import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
|
|
+import org.apache.poi.ss.usermodel.Row;
|
|
|
+import org.apache.poi.ss.usermodel.Sheet;
|
|
|
+import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
|
|
+
|
|
|
+import java.io.FileOutputStream;
|
|
|
+import java.io.IOException;
|
|
|
+import java.sql.*;
|
|
|
+import java.util.*;
|
|
|
+import java.util.Date;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+public class FaultFilterMain {
|
|
|
+
|
|
|
+ private static String user = "nxfdprod";
|
|
|
+ private static String password = "gdnxfd123";
|
|
|
+ private static String driver = "oracle.jdbc.OracleDriver";
|
|
|
+ private static String url = "jdbc:oracle:thin:@192.168.1.105:1521:gdnxfd";
|
|
|
+
|
|
|
+ private static Connection conn;
|
|
|
+
|
|
|
+ public static void main(String[] args){
|
|
|
+ String station = "XS_FDC";
|
|
|
+ String model = "UP97";
|
|
|
+ String st = "2020-01-20 00:00:00";
|
|
|
+ String et = "2022-05-24 00:00:00";
|
|
|
+ long interval = 30 * 60 * 1000;
|
|
|
+
|
|
|
+ Calendar cal = Calendar.getInstance();
|
|
|
+
|
|
|
+ Map<String, String> typeMap = new HashMap<>();
|
|
|
+ typeMap.put("ZD", "振动故障");
|
|
|
+ typeMap.put("KZ", "控制系统故障");
|
|
|
+ typeMap.put("UPS", "UPS故障");
|
|
|
+ typeMap.put("TX", "通讯故障");
|
|
|
+ typeMap.put("CF", "测风类故障");
|
|
|
+ typeMap.put("LDBH", "防雷保护故障");
|
|
|
+ typeMap.put("JX", "机械故障");
|
|
|
+ typeMap.put("AQL", "安全链故障");
|
|
|
+ typeMap.put("LQ", "冷却类故障");
|
|
|
+ typeMap.put("JR", "加热类故障");
|
|
|
+ typeMap.put("ZS", "转速类故障");
|
|
|
+ typeMap.put("BPQ", "变频器故障");
|
|
|
+ typeMap.put("BPQ", "轴承故障");
|
|
|
+ typeMap.put("DC", "电池类故障");
|
|
|
+ typeMap.put("HH", "滑环故障");
|
|
|
+ typeMap.put("XB", "箱变故障");
|
|
|
+ typeMap.put("FDJ", "发电机故障");
|
|
|
+ typeMap.put("CLX", "齿轮箱故障");
|
|
|
+ typeMap.put("BJ", "变桨系统故障");
|
|
|
+ typeMap.put("PH", "偏航系统故障");
|
|
|
+ typeMap.put("YY", "液压系统故障");
|
|
|
+ typeMap.put("JC", "机舱类故障");
|
|
|
+ typeMap.put("ZKG", "控制柜故障");
|
|
|
+ typeMap.put("CGQ", "传感器异常");
|
|
|
+
|
|
|
+
|
|
|
+ IShardingService sharding = Feign.builder()
|
|
|
+ .encoder(new JacksonEncoder())
|
|
|
+ .decoder(new JacksonDecoder())
|
|
|
+ .options(new Request.Options(5000, 600000))
|
|
|
+ .retryer(new Retryer.Default(10000, 10000, 3))
|
|
|
+ .target(IShardingService.class, "http://192.168.1.14:8075");
|
|
|
+ String filename = "D:/" + station + "_" + model + ".xlsx";
|
|
|
+ //创建一个workbook对应一个excel文件
|
|
|
+ XSSFWorkbook workbook = new XSSFWorkbook();
|
|
|
+ //在workbook中创建一个sheet对应excel中的sheet
|
|
|
+ Sheet sheetw = workbook.createSheet(station + "_" + model);
|
|
|
+ Row row = sheetw.createRow(0);
|
|
|
+ row.createCell(0).setCellValue("id");
|
|
|
+ row.createCell(1).setCellValue("tag");
|
|
|
+ row.createCell(2).setCellValue("faultid");
|
|
|
+ row.createCell(3).setCellValue("stationcn");
|
|
|
+ row.createCell(4).setCellValue("windturbineid");
|
|
|
+ row.createCell(5).setCellValue("faulttype");
|
|
|
+ row.createCell(6).setCellValue("faultcode");
|
|
|
+ row.createCell(7).setCellValue("symptom");
|
|
|
+ row.createCell(8).setCellValue("symptomcode");
|
|
|
+ row.createCell(9).setCellValue("starttime");
|
|
|
+ row.createCell(10).setCellValue("endtime");
|
|
|
+ row.createCell(11).setCellValue("manufacturer");
|
|
|
+ row.createCell(12).setCellValue("model");
|
|
|
+ row.createCell(13).setCellValue("stationen");
|
|
|
+ row.createCell(14).setCellValue("remark");
|
|
|
+ row.createCell(15).setCellValue("category");
|
|
|
+
|
|
|
+ List<Object> list = query("select h.ID, s.STATIONID, s.STATIONNAME, s.WINDTURBINEID, w.MODELID, h.FAULTTIME, h.SNAPID from FAULTHISTORY h left join FAULTSNAP s on s.id = h.snapid left join windturbine w on w.id = s.windturbineid " +
|
|
|
+ "where w.modelid = '"+ model +"' and h.MESSAGETYPE = '1' and s.stationid = '"+ station +"' and s.CATEGORY2 = 'GZ' " +
|
|
|
+ "and h.FAULTTIME >= to_date('"+st+"','yyyy-mm-dd hh24:mi:ss') " +
|
|
|
+ "and h.FAULTTIME <= to_date('"+et+"','yyyy-mm-dd hh24:mi:ss')");
|
|
|
+ String key = "";
|
|
|
+ int count = 0;
|
|
|
+ try{
|
|
|
+ for (int i = 1; i < list.size(); i++) {
|
|
|
+ Map<String, Object> map = (Map<String, Object>) list.get(i - 1);
|
|
|
+ cal.setTime((Date) map.get("FAULTTIME"));
|
|
|
+ cal.add(Calendar.MINUTE, -30);
|
|
|
+ String stime = DateUtil.format(cal.getTime(), DateUtil.YYYY_MM_DD_HH_MM_SS);
|
|
|
+ cal.add(Calendar.MINUTE, 35);
|
|
|
+ String etime = DateUtil.format(cal.getTime(), DateUtil.YYYY_MM_DD_HH_MM_SS);
|
|
|
+ System.out.println((String) map.get("WINDTURBINEID"));
|
|
|
+ JSONObject json = sharding.getAlertHistory("windturbine", stime, etime, station, (String) map.get("WINDTURBINEID"), 1);
|
|
|
+ if (json == null)
|
|
|
+ continue;
|
|
|
+
|
|
|
+ JSONArray records = json.getJSONArray("records");
|
|
|
+ List<AlertHistory> array = JSONArray.parseArray(records.toString(), AlertHistory.class);
|
|
|
+ Map<String, List<AlertHistory>> collect = array.stream()
|
|
|
+ .filter(s -> !s.getAlertText().equals("总故障") && !s.getAlertText().equals("故障停机状态"))
|
|
|
+ .collect(Collectors.groupingBy(AlertHistory::getCategory2));
|
|
|
+
|
|
|
+ for (Map.Entry<String, List<AlertHistory>> entry : collect.entrySet()) {
|
|
|
+ String k = entry.getKey();
|
|
|
+ List<AlertHistory> v = entry.getValue();
|
|
|
+ if (!k.equals("other")) {
|
|
|
+ if (v.size() > count) {
|
|
|
+ key = k;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ Row row1 = sheetw.createRow(i);
|
|
|
+ row1.createCell(1).setCellValue("0");
|
|
|
+ row1.createCell(2).setCellValue(String.valueOf(map.get("ID")));
|
|
|
+ row1.createCell(3).setCellValue((String) map.get("STATIONNAME"));
|
|
|
+ row1.createCell(4).setCellValue((String) map.get("WINDTURBINEID"));
|
|
|
+ row1.createCell(5).setCellValue(typeMap.get(key.toUpperCase()));
|
|
|
+ row1.createCell(6).setCellValue(key.toUpperCase());
|
|
|
+ row1.createCell(7).setCellValue("");
|
|
|
+ row1.createCell(8).setCellValue("");
|
|
|
+ row1.createCell(9).setCellValue(DateUtil.format((Date) map.get("FAULTTIME"), DateUtil.YYYY_MM_DD_HH_MM_SS));
|
|
|
+ row1.createCell(10).setCellValue("");
|
|
|
+ row1.createCell(11).setCellValue("联合动力");
|
|
|
+ row1.createCell(12).setCellValue((String) map.get("MODELID"));
|
|
|
+ row1.createCell(13).setCellValue((String) map.get("STATIONID"));
|
|
|
+ row1.createCell(14).setCellValue("");
|
|
|
+ row1.createCell(15).setCellValue("");
|
|
|
+ }
|
|
|
+
|
|
|
+ //将文件保存到指定的位置
|
|
|
+ FileOutputStream out = null;
|
|
|
+ try {
|
|
|
+ out = new FileOutputStream(filename);
|
|
|
+ workbook.write(out);
|
|
|
+ out.flush();
|
|
|
+ System.out.println(filename + "-文件写入成功");
|
|
|
+ } catch (Exception e) {
|
|
|
+ System.out.println("文件写入失败" + e.getMessage());
|
|
|
+ } finally {
|
|
|
+ if (null != out) {
|
|
|
+ try {
|
|
|
+ out.close();
|
|
|
+ } catch (IOException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ Thread.sleep(5000);
|
|
|
+ }catch (Exception e){
|
|
|
+ e.getMessage();
|
|
|
+ e.getStackTrace();
|
|
|
+ }finally {
|
|
|
+ close();
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ private static void init() {
|
|
|
+ try {
|
|
|
+ Class.forName(driver);
|
|
|
+ conn = DriverManager.getConnection(url, user, password);
|
|
|
+ } catch (ClassNotFoundException e) {
|
|
|
+ System.out.println("===1: " + e.getMessage());
|
|
|
+ e.printStackTrace();
|
|
|
+ } catch (SQLException e) {
|
|
|
+ System.out.println("===2: " + e.getMessage());
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public static List<Object> query(String sql) {
|
|
|
+ List<Object> list = new ArrayList<>();
|
|
|
+ Statement stmt = null;
|
|
|
+ ResultSet rs = null;
|
|
|
+
|
|
|
+ if (conn == null)
|
|
|
+ init();
|
|
|
+
|
|
|
+ try {
|
|
|
+ stmt = conn.createStatement();
|
|
|
+ rs = stmt.executeQuery(sql);
|
|
|
+ list = toList(rs);
|
|
|
+ } catch (SQLException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ } finally {
|
|
|
+ if (rs != null) {
|
|
|
+ try {
|
|
|
+ rs.close();
|
|
|
+ } catch (SQLException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (stmt != null) {
|
|
|
+ try {
|
|
|
+ stmt.close();
|
|
|
+ } catch (SQLException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return list;
|
|
|
+ }
|
|
|
+
|
|
|
+ private static List toList(ResultSet rs) throws SQLException {
|
|
|
+ ResultSetMetaData md = rs.getMetaData();
|
|
|
+ int columnCount = md.getColumnCount();
|
|
|
+ List list = new ArrayList();
|
|
|
+ while (rs.next()) {
|
|
|
+ Map rowData = new HashMap(columnCount);
|
|
|
+ for (int i = 1; i <= columnCount; ++i) {
|
|
|
+ Object obFieldValue;
|
|
|
+ if (rs.getObject(i) == null) {
|
|
|
+ obFieldValue = "";
|
|
|
+ } else {
|
|
|
+ obFieldValue = rs.getObject(i);
|
|
|
+ }
|
|
|
+ rowData.put(md.getColumnName(i), obFieldValue);
|
|
|
+ }
|
|
|
+
|
|
|
+ list.add(rowData);
|
|
|
+ }
|
|
|
+
|
|
|
+ return list;
|
|
|
+ }
|
|
|
+
|
|
|
+ public static void close() {
|
|
|
+ if (conn != null) {
|
|
|
+ try {
|
|
|
+ conn.close();
|
|
|
+ } catch (SQLException throwables) {
|
|
|
+ throwables.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|