package org.springnewfiber.dataadapter.xf; import com.alibaba.fastjson.JSONObject; import lombok.Getter; import org.apache.commons.lang3.StringUtils; import org.springnewfiber.dataadapter.xf.entity.*; import java.util.ArrayList; import java.util.List; import java.util.stream.Collectors; @Getter public enum XfDataEnum { /** * */ ChnlData("ChnlData", "港渠信息"), ForcastData("ForcastData", "汉口水情"), LakeData("LakeData", "湖泊监测数据"), Meteorological("Meteorological", "气象站实时监测数据"), PptnData("PptnData", "降雨量"), PumpData("PumpData", "泵站信息"), RiverData("RiverData", "河道信息"), SoilData("SoilData", "土壤墒情"), WasData("WasData", "涵闸监测数据"), WetlogData("WetlogData", "渍水实时数据"), SewageData("SewageData", "污水厂实时监测数据"), WaterQualityData("WaterQualityData", "水质站实时监测数据"), SurgeTankData("SurgeTankData", "调蓄池监测数据"), DiverterWellData("DiverterWellData", "分流井监测数据"), ; private String code; private String remark; XfDataEnum(String code, String remark) { this.code = code; this.remark = remark; } public static XfDataEnum match(String code) { for (XfDataEnum value : XfDataEnum.values()) { if (StringUtils.equalsIgnoreCase(value.getCode(), code)) { return value; } } return null; } @SuppressWarnings("unchecked") public static <T extends BaseXfInterfaceEntity> List<T> parse(String data, XfDataEnum xfDataEnum) { List<T> result = new ArrayList<>(); if (xfDataEnum == XfDataEnum.ChnlData) { result = (List<T>) JSONObject.parseArray(data, MonitorChnlDataDto.class); // } else if (xfDataEnum == XfDataEnum.ForcastData) { // result = JSONObject.parseArray(data, MonitorForcastData.class); } else if (xfDataEnum == XfDataEnum.LakeData) { result = (List<T>) JSONObject.parseArray(data, MonitorLakeData.class); } else if (xfDataEnum == XfDataEnum.Meteorological) { result = (List<T>) JSONObject.parseArray(data, MonitorMeteorologicalData.class); } else if (xfDataEnum == XfDataEnum.PptnData) { result = (List<T>) JSONObject.parseArray(data, MonitorPptnData.class); } else if (xfDataEnum == XfDataEnum.PumpData) { result = (List<T>) JSONObject.parseArray(data, MonitorPumpData.class); } else if (xfDataEnum == XfDataEnum.RiverData) { result = (List<T>) JSONObject.parseArray(data, MonitorRiverData.class); } else if (xfDataEnum == XfDataEnum.SoilData) { result = (List<T>) JSONObject.parseArray(data, MonitorSoilData.class); } else if (xfDataEnum == XfDataEnum.WasData) { result = (List<T>) JSONObject.parseArray(data, MonitorWasData.class); } else if (xfDataEnum == XfDataEnum.WetlogData) { result = (List<T>) JSONObject.parseArray(data, MonitorWetlogData.class); } else if (xfDataEnum == XfDataEnum.SewageData) { result = (List<T>) JSONObject.parseArray(data, MonitorSewageData.class); } else if (xfDataEnum == XfDataEnum.WaterQualityData) { result = (List<T>)JSONObject.parseArray(data, WaterQualityData.class); }else if (xfDataEnum == XfDataEnum.DiverterWellData) { List<DiverterWellData> diverterWellDataList = JSONObject.parseArray(data, DiverterWellData.class); result = (List<T>)diverterWellDataList.stream().map(DiverterWellDataDto::dataToDto).collect(Collectors.toList()); } else if (xfDataEnum == XfDataEnum.SurgeTankData) { List<SurgeTankData> surgeTankDataList = JSONObject.parseArray(data, SurgeTankData.class); result = (List<T>)surgeTankDataList.stream().map(SurgeTankDataDto::dataToDto).collect(Collectors.toList()); } return result; } }