package org.springnewfiber.dataadapter.xf; import com.alibaba.fastjson.JSONObject; import java.util.ArrayList; import java.util.List; import lombok.Getter; import org.apache.commons.lang3.StringUtils; import org.springnewfiber.dataadapter.xf.entity.BaseXfInterfaceEntity; import org.springnewfiber.dataadapter.xf.entity.MonitorChnlDataDto; import org.springnewfiber.dataadapter.xf.entity.MonitorLakeData; import org.springnewfiber.dataadapter.xf.entity.MonitorMeteorologicalData; import org.springnewfiber.dataadapter.xf.entity.MonitorPptnData; import org.springnewfiber.dataadapter.xf.entity.MonitorPumpData; import org.springnewfiber.dataadapter.xf.entity.MonitorRiverData; import org.springnewfiber.dataadapter.xf.entity.MonitorSoilData; import org.springnewfiber.dataadapter.xf.entity.MonitorWasData; import org.springnewfiber.dataadapter.xf.entity.MonitorWetlogData; @Getter public enum XfDataEnum { /** * */ ChnlData("ChnlData","港渠信息"), ForcastData("ForcastData","汉口水情"), LakeData("LakeData","湖泊监测数据"), Meteorological("Meteorological","气象站实时监测数据"), PptnData("PptnData","降雨量"), PumpData("PumpData","泵站信息"), RiverData("RiverData","河道信息"), SoilData("SoilData","土壤墒情"), WasData("WasData","涵闸监测数据"), WetlogData("WetlogData","渍水实时数据"), ; 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); } return result; } }