package com.nmgs.service.impl;

import com.alibaba.fastjson.JSONObject;
import com.nmgs.mapper.Mapper;
import com.nmgs.util.LogUtil;
import com.nmgs.util.PubTools;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * 下拉值查询
 */
@Service
public class SelectDataImpl {
    SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHH");
    @Autowired
    public Mapper mapperI;

    public List getDataByType(JSONObject paramsData) {
        List ret = new ArrayList();
        String sql="";
       String selectType=paramsData.get("selectType").toString();
       String serviceAreaName=PubTools.isEmpty(paramsData.get("serviceAreaName"))?"":paramsData.get("serviceAreaName").toString();
       String servicePosition=PubTools.isEmpty(paramsData.get("servicePosition"))?"":paramsData.get("servicePosition").toString();
       String subcomno="";
       String roadNo="";
       if(!PubTools.isEmpty(paramsData.get("subcomno"))){
           subcomno=paramsData.get("subcomno").toString();
       }
        if(!PubTools.isEmpty(paramsData.get("roadno"))){
            roadNo=paramsData.get("roadno").toString();
        }
        if("VECHECLASS".equals(selectType)){//车种下拉值查询
            sql="select a.value as VALUE,a.text as LABEL from VEHICLECLASS_TEXT a order by a.value";
        }else  if("VECHETYPE".equals(selectType)){//车型下拉值查询
            sql="select a.value as VALUE,a.text as LABEL from TYPE_TEXT a WHERE a.value in(11,12,13,14,15,16) order by a.value";
        }else  if("EXITFEETYPE".equals(selectType)){//出口计费方式
            sql="select a.value as VALUE,a.text as LABEL from EXITFEETYPE_TEXT a order by a.value";
        }else  if("STANAME".equals(selectType)){//站名称
            sql="select a.STANO as VALUE,a.STANAME as LABEL from DIV_NAME_TABLE a where a.STATYPE=1 order by a.STANAME";
        }else  if("SUBCOM".equals(selectType)){//分公司下拉值
             //sql="select subComNo value,subComName label from subcompany_table where  1=1 ";
            sql="select distinct t.SUBCOMNO as VALUE,t.SUBCOMNAME as LABEL from DIV_NAME_TABLE a,subcompany_table t where a.STATYPE=1 and a.SUBCOMNO=t.subComNo order by t.SUBCOMNAME";
        }else  if("ROAD".equals(selectType)){//路段
            sql="select distinct a.roadno value,a.roadname label from DIV_NAME_TABLE a where a.STATYPE=1 ";
            if(!PubTools.isNull(subcomno)){
                sql += " and a.subcomno ="+subcomno;
            }
            sql +=" order by a.roadname ";
        }else  if("STANO".equals(selectType)){//站名称
            sql="select distinct a.stano as value,a.staname as label from DIV_NAME_TABLE a where a.STATYPE=1  ";
            if(!PubTools.isNull(subcomno)){
                sql += " and a.subcomno ="+subcomno;
            }
            if(!PubTools.isNull(roadNo)){
                sql += " and a.roadno ="+roadNo;
            }
            sql +=" order by a.STANAME ";
        }else  if("GANTRY".equals(selectType)){//省界门架出口名称
            sql="select distinct a.gantryhex as value,a.name as label from GANTRY_TABLE a where a.boundarytype=2 group by a.name,a.gantryhex order by a.name  ";
        }else  if("INTERFLOW".equals(selectType)){//互通名称
            sql="select distinct a.INTER_HEX as value,a.INTER_NAME as label from DIV_INTERFLOW_TABLE a where a.IN_OUT='OUT' order by a.INTER_HEX  ";
        } else if ("PLATECOLOR".equals(selectType)) {//车牌颜色
            sql = "select a.value as VALUE,a.text as LABEL from INTEGRAL_PLATECOLOR_TEXT a order by a.value  ";
        }else if ("SERVICEAREA".equals(selectType)) {//服务区名称
            sql = "select a.ID as VALUE,a.AREANAME as LABEL from SERVICE_AREA_TABLE a where 1=1 ";
            if(!PubTools.isNull(serviceAreaName)){
                sql +=" AND a.AREANAME LIKE '%"+serviceAreaName+"%'";
            }
            if(!PubTools.isNull(servicePosition)){
                sql +=" AND a.POSITION = "+servicePosition+"";
            }
            sql +=" order by a.AREANAME ";
        } else if ("SERVICE_POSITION".equals(selectType)) {//服务区方位
            sql = "select a.value as VALUE,a.text as LABEL from SERVICE_AREA_POSITION_TEXT a order by a.value  ";
        }
        try {
                ret=mapperI.selectforlist(sql);
        } catch (Exception e) {
            LogUtil.WriteLog_Error("下拉数据"+selectType+"查询失败=====" + e.getMessage(), "SelectDataImpl");
            ret = new ArrayList();
        }
        return ret;

    }

}
