123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105 |
- package com.gyee.runeconomy.dto;
- import com.fasterxml.jackson.core.type.TypeReference;
- import com.fasterxml.jackson.databind.DeserializationFeature;
- import com.fasterxml.jackson.databind.ObjectMapper;
- import java.util.List;
- import java.util.Map;
- public class AlarmDataParser {
- public static class AlarmData {
- private Long snapId;
- private String stationId;
- private String windturbineId;
- private String alertText;
- private int count;
- private String alarmid;
- private double time;
- private String relateParts;
- private String relatePartsText;
- // Getter 和 Setter 方法
- public Long getSnapId() {
- return snapId;
- }
- public void setSnapId(Long snapId) {
- this.snapId = snapId;
- }
- public String getStationId() {
- return stationId;
- }
- public void setStationId(String stationId) {
- this.stationId = stationId;
- }
- public String getWindturbineId() {
- return windturbineId;
- }
- public void setWindturbineId(String windturbineId) {
- this.windturbineId = windturbineId;
- }
- public String getAlertText() {
- return alertText;
- }
- public void setAlertText(String alertText) {
- this.alertText = alertText;
- }
- public int getCount() {
- return count;
- }
- public void setCount(int count) {
- this.count = count;
- }
- public String getAlarmid() {
- return alarmid;
- }
- public void setAlarmid(String alarmid) {
- this.alarmid = alarmid;
- }
- public double getTime() {
- return time;
- }
- public void setTime(double time) {
- this.time = time;
- }
- public String getRelateParts() {
- return relateParts;
- }
- public void setRelateParts(String relateParts) {
- this.relateParts = relateParts;
- }
- public String getRelatePartsText() {
- return relatePartsText;
- }
- public void setRelatePartsText(String relatePartsText) {
- this.relatePartsText = relatePartsText;
- }
- }
- public static List parseResponse(String jsonResponse) {
- ObjectMapper objectMapper = new ObjectMapper();
- objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); // 忽略未知字段
- List<AlarmData> dataList = null;
- try {
- List<Map<String, List<AlarmData>>> responseData = objectMapper.readValue(
- jsonResponse, new TypeReference<List<Map<String, List<AlarmData>>>>() {
- }
- );
- for (Map<String, List<AlarmData>> map : responseData) {
- for (Map.Entry<String, List<AlarmData>> entry : map.entrySet()) {
- String stationId = entry.getKey();
- dataList = entry.getValue();
- }
- }
- } catch (Exception e) {
- e.printStackTrace();
- }
- return dataList;
- }
- }
|