Newer
Older
newfiber-data-adapter / src / main / java / org / springnewfiber / dataadapter / xf / XfDataEnum.java
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", "分流井监测数据"),
    StSlwtRData("StSlwtRData","其他水体监测数据"),
    dhgx_szq("dhgx_szq","东湖高新-水质船"),
    WhjkSzqData("WhjkSzqData","公司水质船"),
    InwamntData("InwamntData","供水厂入水数据-水源地数据"),
    OutwamntData("OutwamntData","供水厂出水数据"),
    GwYsQData("GwYsQData","雨水管网流量监测数据"),
    GwYsLData("GwYsLData","雨水管网水位监测数据"),
    GwWsQData("GwWsQData","污水管网流量监测数据"),
    GwWsLData("GwWsLData"," 污水管网水位监测数据"),
    GwYsSZData("GwYsSZData"," 雨水管网水质监测数据"),
    GqYlData("GqYlData", "港渠实时监测数据"),
    GqSoilData("GqSoilData", "港渠墒情监测数据"),
    NyysData("NyysData", "农业用水监测数据"),
    NcjcyjData("NcjcyjData", "农村监测预警数据"),
    ;
    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());
        }else if (xfDataEnum == XfDataEnum.StSlwtRData) {
            result =(List<T>) JSONObject.parseArray(data, MonitorOtherData.class);
        }

        return result;
    }

}