AlarmDataParser.java 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. package com.gyee.runeconomy.dto;
  2. import com.fasterxml.jackson.core.type.TypeReference;
  3. import com.fasterxml.jackson.databind.DeserializationFeature;
  4. import com.fasterxml.jackson.databind.ObjectMapper;
  5. import java.util.List;
  6. import java.util.Map;
  7. public class AlarmDataParser {
  8. public static class AlarmData {
  9. private Long snapId;
  10. private String stationId;
  11. private String windturbineId;
  12. private String alertText;
  13. private int count;
  14. private String alarmid;
  15. private double time;
  16. private String relateParts;
  17. private String relatePartsText;
  18. // Getter 和 Setter 方法
  19. public Long getSnapId() {
  20. return snapId;
  21. }
  22. public void setSnapId(Long snapId) {
  23. this.snapId = snapId;
  24. }
  25. public String getStationId() {
  26. return stationId;
  27. }
  28. public void setStationId(String stationId) {
  29. this.stationId = stationId;
  30. }
  31. public String getWindturbineId() {
  32. return windturbineId;
  33. }
  34. public void setWindturbineId(String windturbineId) {
  35. this.windturbineId = windturbineId;
  36. }
  37. public String getAlertText() {
  38. return alertText;
  39. }
  40. public void setAlertText(String alertText) {
  41. this.alertText = alertText;
  42. }
  43. public int getCount() {
  44. return count;
  45. }
  46. public void setCount(int count) {
  47. this.count = count;
  48. }
  49. public String getAlarmid() {
  50. return alarmid;
  51. }
  52. public void setAlarmid(String alarmid) {
  53. this.alarmid = alarmid;
  54. }
  55. public double getTime() {
  56. return time;
  57. }
  58. public void setTime(double time) {
  59. this.time = time;
  60. }
  61. public String getRelateParts() {
  62. return relateParts;
  63. }
  64. public void setRelateParts(String relateParts) {
  65. this.relateParts = relateParts;
  66. }
  67. public String getRelatePartsText() {
  68. return relatePartsText;
  69. }
  70. public void setRelatePartsText(String relatePartsText) {
  71. this.relatePartsText = relatePartsText;
  72. }
  73. }
  74. public static List parseResponse(String jsonResponse) {
  75. ObjectMapper objectMapper = new ObjectMapper();
  76. objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); // 忽略未知字段
  77. List<AlarmData> dataList = null;
  78. try {
  79. List<Map<String, List<AlarmData>>> responseData = objectMapper.readValue(
  80. jsonResponse, new TypeReference<List<Map<String, List<AlarmData>>>>() {
  81. }
  82. );
  83. for (Map<String, List<AlarmData>> map : responseData) {
  84. for (Map.Entry<String, List<AlarmData>> entry : map.entrySet()) {
  85. String stationId = entry.getKey();
  86. dataList = entry.getValue();
  87. }
  88. }
  89. } catch (Exception e) {
  90. e.printStackTrace();
  91. }
  92. return dataList;
  93. }
  94. }