package com.nmgs.service.impl;

import com.alibaba.fastjson.JSONArray;
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.math.BigDecimal;
import java.util.*;

@Service
public class ExcelDateImpl {

   /* @Autowired
    public Mapper mapperI;
    public List<DivPassidAllDto> getDivPassidAll(String classDate, String vecheType, String status, String vecheClass, Integer start, Integer end,
                                                 JSONArray whereParams) {
        List list=new ArrayList();
        List<DivPassidAllDto> listRet=new ArrayList<DivPassidAllDto>();
        String sql="";
        String resultSql="SELECT \n" +
                "  tt.rn,\n" +
                "\ttt.ID,\n" +
                "\ttt.PASSID,\n" +
                "\tto_char(tt.GPA_TOLLINTERVALID) as GPA_TOLLINTERVALID,\n" +
                "\t to_char(tt.GPA_FEEGROUP) as GPA_FEEGROUP,\n" +
                "\ttt.GPA_FEE /100 AS GPA_FEE,\n" +
                "\tto_char(tt.DIV_TOLLINTERVALID) as DIV_TOLLINTERVALID,\n" +
                "\tto_char(tt.DIV_FEEGROUP) as DIV_FEEGROUP,\n" +
                "\ttt.DIV_FEE/100 AS DIV_FEE,\n" +
                "\ttt.CLASSDATE,\n" +
                "\ttt.GPA_ENTIME,\n" +
                "\ttt.GPA_EXTIME,\n" +
                "\ttt.GPA_ENTOLLSTATIONNAME,\n" +
                "\ttt.GPA_EXTOLLSTATIONNAME,\n" +
                "\ttt.GPA_ENPOINTID,\n" +
                "\ttt.GPA_EXPOINTID,\n" +
                "\ttt.GPA_VEHICLEID,\n" +
                "\tttd.VALUE as GPA_VEHICLETYPE,\n" +
                "\ttt.STATUS,\n" +
                "\ttt.CHECKSTATUS,\n" +
                "\ttt.STATUSNAME,\n" +
                "\ttt.CHECKSTATUSNAME,\n" +
                "\tttd.text AS VEHICLENAME,\n" +
                "\tvt.text as VEHICLECLASSName,\n" +
                "\ta.TYPE,\n" +
                "\te.text AS KIND,\n" +
                "\t( a.incash + a.paycash )/100 AS FEE,\n" +
                "\t a.CASH/100 AS PAYFEE,\n" +
                "\tc.TEXT AS PAYTYPE,\n" +
                "\td.TEXT AS EXITFEETYPE,\n" +
                "\ta.FLAG AS FLAGVALUE,\n" +
                "\ttt.VEHICLECLASS" ;
        String startsql ="SELECT \n" +
                "\tss.rn,\n" +
                "\tss.ID,\n" +
                "\tss.PASSID,\n" +
                "\t ss.GPA_TOLLINTERVALID  AS GPA_TOLLINTERVALID,\n" +
                "\tss.GPA_FEEGROUP  AS GPA_FEEGROUP,\n" +
                "\tss.GPA_FEE,\n" +
                "\tss.DIV_TOLLINTERVALID  AS DIV_TOLLINTERVALID,\n" +
                "\tss.DIV_FEEGROUP AS DIV_FEEGROUP,\n" +
                "\tss.DIV_FEE,\n" +
                "\tss.CLASSDATE,\n" +
                "\tss.GPA_ENTIME,\n" +
                "\tss.GPA_EXTIME,\n" +
                "\tss.GPA_ENTOLLSTATIONNAME,\n" +
                "\tss.GPA_EXTOLLSTATIONNAME,\n" +
                "\tss.GPA_ENPOINTID,\n" +
                "\tss.GPA_EXPOINTID,\n" +
                "\tss.GPA_VEHICLEID ,\n" +
                "\tss.STATUS,\n" +
                "\tss.CHECKSTATUS,\n" +
                "\tss.STATUSNAME,\n" +
                "\tss.CHECKSTATUSNAME,\n" +
                "\tss.VEHICLECLASS,\n" +
                "\tss.VEHICLETYPE ";


        String startsqlPage ="SELECT ROWNUM AS\n" +
                "\trn,\n" +
                "\tt.ID,\n" +
                "\tt.PASSID,\n" +
                "\t t.GPA_TOLLINTERVALID  AS GPA_TOLLINTERVALID,\n" +
                "\tt.GPA_FEEGROUP  AS GPA_FEEGROUP,\n" +
                "\tt.GPA_FEE,\n" +
                "\tt.DIV_TOLLINTERVALID  AS DIV_TOLLINTERVALID,\n" +
                "\tt.DIV_FEEGROUP AS DIV_FEEGROUP,\n" +
                "\tt.DIV_FEE,\n" +
                "\tt.CLASSDATE,\n" +
                "\tt.GPA_ENTIME,\n" +
                "\tt.GPA_EXTIME,\n" +
                "\tt.GPA_ENTOLLSTATIONNAME,\n" +
                "\tt.GPA_EXTOLLSTATIONNAME,\n" +
                "\tt.GPA_ENPOINTID,\n" +
                "\tt.GPA_EXPOINTID,\n" +
                "\tCONCAT(substr( t.VEHICLEID, 1,instr(t.VEHICLEID,'_')-1) || '_',(select text from PLATECOLOR_TEXT where value=substr( t.VEHICLEID, instr(t.VEHICLEID,'_')+1)))  AS GPA_VEHICLEID,\n" +
                "\tt.VEHICLETYPE AS GPA_VEHICLETYPE,\n" +
                "\tt.STATUS,\n" +
                "\tt.CHECKSTATUS,\n" +
                "\t(\n" +
                "\tCASE\n" +
                "\t\t\tt.STATUS \n" +
                "\t\t\tWHEN 1 THEN\n" +
                "\t\t\t'拆分准确' \n" +
                "\t\t\tWHEN 2 THEN\n" +
                "\t\t\t'计费大于拆分' \n" +
                "\t\t\tWHEN 3 THEN\n" +
                "\t\t\t'计费小于拆分' \n" +
                "\t\t\tWHEN 4 THEN\n" +
                "\t\t\t'未计费' \n" +
                "\t\t\tWHEN 5 THEN\n" +
                "\t\t\t'未拆分' \n" +
                "\t\t\tWHEN 6 THEN\n" +
                "\t\t\t'拒付' \n" +
                "\t\t\tWHEN 7 THEN\n" +
                "\t\t\t'逾期' \n" +
                "\t\t\tWHEN 99 THEN\n" +
                "\t\t\t'U转' ELSE '未知' \n" +
                "\t\tEND \n" +
                "\t\t) STATUSNAME,\n" +
                "\t( CASE t.CHECKSTATUS WHEN 0 THEN '未稽核' WHEN 1 THEN '已稽核' ELSE '未知' END ) CHECKSTATUSNAME,\n" +
                "\tt.VEHICLECLASS,\n" +
                "\tt.VEHICLETYPE AS VEHICLETYPE";
        String endSql=" FROM\n" +
                "  div_passid_all t " +
                "WHERE\n" +
                "\t t.classdate = to_date( '"+classDate+"', 'yyyy-mm-dd' ) \n";
        try{
            if(!PubTools.isNull(vecheType)){
                endSql +=  " AND t.vehicletype = ( SELECT value FROM type_text WHERE text = '"+vecheType+"' )";
            }
            if(!PubTools.isNull(vecheClass) &&  ("8".equals(vecheClass) || "21".equals(vecheClass))){
                endSql += "\tAND t.VEHICLECLASS = "+vecheClass+"";
            }else{
                if(!PubTools.isNull(status)){
                    endSql += "\tAND t.STATUS = "+status+" and (t.VEHICLECLASS not in(8,21) or t.VEHICLECLASS is null) ";
                }
            }
            if(whereParams.size()>0){
                endSql +=  solveSearchJSOn(whereParams);
            }
            if(start >=0 && end >0){
                sql = resultSql+" from ("+startsql+" from ("+startsqlPage+endSql+ " and ROWNUM <= "+end+")ss where 1=1 AND ss.rn >= "+start+" )tt      " +
                        " LEFT JOIN VEHICLECLASS_TEXT vt ON ( tt.VEHICLECLASS = vt.value ) " +
                        " LEFT JOIN type_text ttd ON ( tt.VEHICLETYPE = ttd.value ) " +
                        " left join out_port a on(a.passId = tt.passId)  " +
                        " left join  paytype_text c on(a.paytype = c.value) " +
                        " left join exitfeetype_text d on(a.exitfeetype = d.value)" +
                        " left join  kind_text e on(a.kind = e.value) where 1=1 order by tt.rn "   ;
            }
            LogUtil.WriteLog_Info("getDivDataTableList===sql==="+sql,"ExcelDateImpl");
            LogUtil.WriteLog_Info("sql===执行开始"+PubTools.getCurrentDate(),"ExcelDateImpl");
            list= this.mapperI.selectforlist(sql);
            LogUtil.WriteLog_Info("sql===执行结束"+PubTools.getCurrentDate(),"ExcelDateImpl");
            if(list.size()>0){
                if(PubTools.isEmpty(list.get(0))){
                    list=new ArrayList();
                }else{
                    //解析特情值不是查询总数
                    if(start >=0 && end>0){
                        for(int i=0;i<list.size();i++){
                            Map map= (Map<String,Object>) list.get(i);
                            if(!PubTools.isEmpty(map.get("FLAGVALUE"))){
                                String flagType="";
                                if (!PubTools.isNull(map.get("FLAGVALUE").toString())) {
                                    String binaryString = Long.toBinaryString(Long.parseLong(map.get("FLAGVALUE").toString()));//转换为二进制字符串
                                    if ("0".equals(binaryString)) {
                                        flagType = "0";
                                    } else {
                                        char[] bytes = binaryString.toCharArray();
                                        int j = 1;
                                        for (int k = bytes.length - 1; k > -1; k--) {
                                            if (bytes[k] == '1') {
                                                if ("".equals(flagType)) {
                                                    flagType = j + "";
                                                } else {
                                                    flagType += "," + j;
                                                }
                                            }
                                            j++;
                                        }
                                    }
                                }
                                if(!PubTools.isNull(flagType)){
                                    String flagType1 = getFlagType(flagType);
                                    map.put("FLAG",flagType1);
                                }else{
                                    map.put("FLAG","");
                                }

                            }else{
                                map.put("FLAG","");
                            }
                               *//* ObjectMapper objectMapper= new ObjectMapper();
                                listRet.add(objectMapper.convertValue(map,DivPassidAllDto.class));*//*
                                DivPassidAllDto dto=new DivPassidAllDto();
                                dto.setRN(Integer.parseInt(map.get("RN").toString()));
                                dto.setPASSID((map.get("PASSID").toString()));
                                dto.setCLASSDATE((map.get("CLASSDATE").toString()));
                                if(!PubTools.isEmpty(map.get("DIV_FEE"))){
                                    dto.setDIV_FEE(new BigDecimal(map.get("DIV_FEE").toString()));
                                }
                                if(!PubTools.isEmpty(map.get("FEE"))){
                                    dto.setFEE(new BigDecimal(map.get("FEE").toString()));
                                }
                                dto.setCONTENT(!PubTools.isEmpty(map.get("CONTENT"))?map.get("CONTENT").toString():"");
                                dto.setFLAG(!PubTools.isEmpty(map.get("FLAG"))?map.get("FLAG").toString():"");
                                dto.setEXITFEETYPE(!PubTools.isEmpty(map.get("EXITFEETYPE"))?map.get("EXITFEETYPE").toString():"");
                                if(!PubTools.isEmpty(map.get("GPA_ENTIME"))){
                                    dto.setGPA_ENTIME((Date)(map.get("GPA_ENTIME")));
                                }
                                dto.setGPA_ENTOLLSTATIONNAME(!PubTools.isEmpty(map.get("GPA_ENTOLLSTATIONNAME"))?map.get("GPA_ENTOLLSTATIONNAME").toString():"");
                                if(!PubTools.isEmpty(map.get("GPA_EXTIME"))){
                                    dto.setGPA_EXTIME((Date)(map.get("GPA_EXTIME")));
                                }
                                dto.setGPA_EXTOLLSTATIONNAME(!PubTools.isEmpty(map.get("GPA_EXTOLLSTATIONNAME"))?map.get("GPA_EXTOLLSTATIONNAME").toString():"");
                                if(!PubTools.isEmpty(map.get("GPA_FEE"))){
                                    dto.setGPA_FEE(new BigDecimal(map.get("GPA_FEE").toString()));
                                }

                                dto.setGPA_VEHICLEID(!PubTools.isEmpty(map.get("GPA_VEHICLEID"))?map.get("GPA_VEHICLEID").toString():"");
                                if(!PubTools.isEmpty(map.get("PAYFEE"))){
                                    dto.setPAYFEE(new BigDecimal(map.get("PAYFEE").toString()));
                                }
                                dto.setPAYTYPE(!PubTools.isEmpty(map.get("PAYTYPE"))?map.get("PAYTYPE").toString():"");
                                dto.setSTATUSNAME(!PubTools.isEmpty(map.get("STATUSNAME"))?map.get("STATUSNAME").toString():"");
                                dto.setVEHICLECLASSNAME(!PubTools.isEmpty(map.get("VEHICLECLASSNAME"))?map.get("VEHICLECLASSNAME").toString():"");
                                dto.setVEHICLENAME(!PubTools.isEmpty(map.get("VEHICLENAME"))?map.get("VEHICLENAME").toString():"");
                                listRet.add(dto);

                            }

                        }
                }
            }
        }catch(Exception e){
            e.printStackTrace();
            LogUtil.WriteLog_Error("查询数据失败==="+e.getMessage(),"ExcelDateImpl");
            return new ArrayList();
        }
        return listRet;

    }
    public List<OutPortDivPassidDto> getOutPortDivPassid(String classDate, Integer start, Integer end, JSONArray whereParams) {
        List list=new ArrayList();
        List<OutPortDivPassidDto> listRet=new ArrayList<OutPortDivPassidDto>();
        String sql="";
        String resultSql="SELECT \n" +
                "tt.rn,\n" +
                "\ttt.ID,\n" +
                "\ttt.PASSID,\n" +
                "\tdnt.STANAME AS STANAME,\n" +
                "\tto_char(t.GPA_TOLLINTERVALID) as GPA_TOLLINTERVALID,\n" +
                "\t to_char(t.GPA_FEEGROUP) as GPA_FEEGROUP,\n" +
                "\tt.GPA_FEE /100 AS GPA_FEE,\n" +
                "\tto_char(t.DIV_TOLLINTERVALID) as DIV_TOLLINTERVALID,\n" +
                "\tto_char(t.DIV_FEEGROUP) as DIV_FEEGROUP,\n" +
                "\tt.DIV_FEE/100 AS DIV_FEE,\n" +
                "\ttt.CLASSDATE,\n" +
                "\tt.GPA_ENTIME,\n" +
                "\tt.GPA_EXTIME,\n" +
                "\tt.GPA_ENTOLLSTATIONNAME,\n" +
                "\tt.GPA_EXTOLLSTATIONNAME,\n" +
                "\tt.GPA_ENPOINTID,\n" +
                "\tt.GPA_EXPOINTID,\n" +
                "\ttt.ACARNO AS GPA_VEHICLEID,\n" +
                "\ttt.TYPE AS GPA_VEHICLETYPE,\n" +
                "\tt.STATUS,\n" +
                "\tt.CHECKSTATUS,\n" +
                "\t(\n" +
                "\tCASE\n" +
                "\t\t\tt.STATUS \n" +
                "\t\t\tWHEN 1 THEN\n" +
                "\t\t\t'拆分准确' \n" +
                "\t\t\tWHEN 2 THEN\n" +
                "\t\t\t'计费大于拆分' \n" +
                "\t\t\tWHEN 3 THEN\n" +
                "\t\t\t'计费小于拆分' \n" +
                "\t\t\tWHEN 4 THEN\n" +
                "\t\t\t'未计费' \n" +
                "\t\t\tWHEN 5 THEN\n" +
                "\t\t\t'未拆分' \n" +
                "\t\t\tWHEN 6 THEN\n" +
                "\t\t\t'拒付' \n" +
                "\t\t\tWHEN 7 THEN\n" +
                "\t\t\t'逾期' \n" +
                "\t\t\tWHEN 99 THEN\n" +
                "\t\t\t'U转' ELSE '未知' \n" +
                "\t\tEND \n" +
                "\t\t) STATUSNAME,\n" +
                "\t( CASE t.CHECKSTATUS WHEN 0 THEN '未稽核' WHEN 1 THEN '已稽核' ELSE '未知' END ) CHECKSTATUSNAME,\n" +
                "\ttt.VEHICLECLASS,\n" +
                "\tvt.text AS VEHICLECLASSNAME,\n" +
                "\ttt.TYPE AS TYPE,\n" +
                "\te.TEXT AS KIND,\n" +
                "\ttt.FEE/100 AS FEE,\n" +
                "\ttt.PAYFEE/100 AS PAYFEE,\n" +
                "\tc.TEXT AS PAYTYPE,\n" +
                "\td.TEXT AS EXITFEETYPE,\n" +
                "\ttt.FLAG AS FLAGVALUE,\n" +
                "\tttd.TEXT AS VEHICLENAME";

        String startsql ="SELECT " +
                "\tss.rn,\n" +
                "\tss.ID,\n" +
                "\tss.PASSID,\n" +
                "\tss.ACARNO,\n" +
                "\tss.STANO AS STANO,\n" +
                "\tss.CLASSDATE,\n" +
                "\tss.GPA_VEHICLEID AS GPA_VEHICLEID,\n" +
                "\tss.VEHICLECLASS,\n" +
                "\tss.TYPE AS TYPE,\n" +
                "\tss.KIND AS KIND,\n" +
                "\tss.FEE AS FEE,\n" +
                "\tss.PAYFEE AS PAYFEE,\n" +
                "\tss.paytype AS PAYTYPE,\n" +
                "\tss.exitfeetype AS EXITFEETYPE,\n" +
                "\tss.FLAG AS FLAG " ;
        String startPagesql ="SELECT ROWNUM AS\n" +
                "\trn,\n" +
                "\ta.ID,\n" +
                "\ta.PASSID,\n" +
                "\ta.ACARNO,\n" +
                "\ta.STANO AS STANO,\n" +
                "\ta.CLASSDATE,\n" +
                "\ta.ACARNO AS GPA_VEHICLEID,\n" +
                "\ta.VEHICLECLASS,\n" +
                "\ta.TYPE AS TYPE,\n" +
                "\ta.KIND AS KIND,\n" +
                "\t( a.incash + a.paycash ) AS FEE,\n" +
                "\ta.CASH AS PAYFEE,\n" +
                "\ta.paytype AS PAYTYPE,\n" +
                "\ta.exitfeetype AS EXITFEETYPE,\n" +
                "\ta.FLAG AS FLAG " ;
        String endSql=" FROM\n" +
                "  out_port  a" +
                " WHERE\n" +
                "\t a.flag <>1 and a.classdate = to_date( '"+classDate+"', 'yyyy-mm-dd' ) \n";
        try{
            *//*if(!PubTools.isNull(vecheType)){
                endSql +=  " AND t.vehicletype = ( SELECT value FROM type_text WHERE text = '"+vecheType+"' )";
            }
            if(!PubTools.isNull(vecheClass) &&  ("8".equals(vecheClass) || "21".equals(vecheClass))){
                endSql += "\tAND t.VEHICLECLASS = "+vecheClass+"";
            }else{
                if(!PubTools.isNull(status)){
                    endSql += "\tAND t.STATUS = "+status+" and (t.VEHICLECLASS not in(8,21) or t.VEHICLECLASS is null) ";
                }
            }*//*

            if(whereParams.size()>0){
                endSql +=  solveSearchJSOn(whereParams);
            }
            if(start >=0 && end >0){
                sql = resultSql+" from ("+ startsql + " FROM ("+ startPagesql +endSql+ " and ROWNUM <= "+end+" order by a.PASSID )ss where 1=1 AND ss.rn >= "+start+ ")tt"+
                        " left join  div_passid_all t on(tt.passId = t.passId) " +
                        " LEFT JOIN VEHICLECLASS_TEXT vt ON ( tt.VEHICLECLASS = vt.value ) " +
                        " LEFT JOIN type_text ttd ON ( tt.TYPE = ttd.value ) " +
                        " left join  paytype_text c on(tt.paytype = c.value) " +
                        " left join exitfeetype_text d on(tt.exitfeetype = d.value) " +
                        " left join  kind_text e on(tt.kind = e.value) " +
                        " left join  DIV_NAME_TABLE dnt on (dnt.STATYPE=1  and dnt.STANO = tt.STANO) where 1=1 order by tt.rn" ;
            }
            LogUtil.WriteLog_Info("getDivDataTableList===sql==="+sql,"ExcelDateImpl");
            LogUtil.WriteLog_Info("sql===执行开始"+PubTools.getCurrentDate(),"ExcelDateImpl");
            list= this.mapperI.selectforlist(sql);
            LogUtil.WriteLog_Info("sql===执行结束"+PubTools.getCurrentDate(),"ExcelDateImpl");
            if(list.size()>0){
                if(PubTools.isEmpty(list.get(0))){
                    list=new ArrayList();
                }else{
                    //解析特情值不是查询总数
                    if(start >=0 && end>0){
                        for(int i=0;i<list.size();i++){
                            Map map= (Map<String,Object>) list.get(i);
                            if(!PubTools.isEmpty(map.get("FLAGVALUE"))){
                                String flagType="";
                                    if (!PubTools.isNull(map.get("FLAGVALUE").toString())) {
                                        String binaryString = Long.toBinaryString(Long.parseLong(map.get("FLAGVALUE").toString()));//转换为二进制字符串
                                        if ("0".equals(binaryString)) {
                                            flagType = "0";
                                        } else {
                                            char[] bytes = binaryString.toCharArray();
                                            int j = 1;
                                            for (int k = bytes.length - 1; k > -1; k--) {
                                                if (bytes[k] == '1') {
                                                    if ("".equals(flagType)) {
                                                        flagType = j + "";
                                                    } else {
                                                        flagType += "," + j;
                                                    }
                                                }
                                                j++;
                                            }
                                        }
                                    }
                                    if(!PubTools.isNull(flagType)){
                                        String flagType1 = getFlagType(flagType);
                                        map.put("FLAG",flagType1);
                                    }else{
                                        map.put("FLAG","");
                                    }

                                }else{
                                    map.put("FLAG","");
                                }
                               *//* ObjectMapper objectMapper= new ObjectMapper();
                                listRet.add(objectMapper.convertValue(map,DivPassidAllDto.class));*//*
                                OutPortDivPassidDto dto=new OutPortDivPassidDto();
                                dto.setRN(Integer.parseInt(map.get("RN").toString()));
                                dto.setPASSID((map.get("PASSID").toString()));
                                dto.setSTANAME((map.get("STANAME").toString()));
                                dto.setCLASSDATE((map.get("CLASSDATE").toString()));
                                dto.setDIV_FEE(new BigDecimal(map.get("DIV_FEE").toString()));
                                dto.setFEE(new BigDecimal(map.get("FEE").toString()));
                                dto.setCONTENT(!PubTools.isEmpty(map.get("CONTENT"))?map.get("CONTENT").toString():"");
                                dto.setFLAG(!PubTools.isEmpty(map.get("FLAG"))?map.get("FLAG").toString():"");
                                dto.setEXITFEETYPE(map.get("EXITFEETYPE").toString());
                                dto.setGPA_ENTIME((Date)(map.get("GPA_ENTIME")));
                                dto.setGPA_ENTOLLSTATIONNAME(map.get("GPA_ENTOLLSTATIONNAME").toString());
                                dto.setGPA_EXTIME((Date)(map.get("GPA_EXTIME")));
                                dto.setGPA_EXTOLLSTATIONNAME(map.get("GPA_EXTOLLSTATIONNAME").toString());
                                dto.setGPA_FEE(new BigDecimal(map.get("DIV_FEE").toString()));
                                dto.setGPA_VEHICLEID(map.get("GPA_VEHICLEID").toString());
                                dto.setPAYFEE(new BigDecimal(map.get("PAYFEE").toString()));
                                dto.setPAYTYPE(map.get("PAYTYPE").toString());
                                dto.setSTATUSNAME(map.get("STATUSNAME").toString());
                                dto.setVEHICLECLASSNAME(map.get("VEHICLECLASSNAME").toString());
                                dto.setVEHICLENAME(map.get("VEHICLENAME").toString());
                                listRet.add(dto);

                            }

                        }
                }
            }
        }catch(Exception e){
            e.printStackTrace();
            LogUtil.WriteLog_Error("查询数据失败==="+e.getMessage(),"ExcelDateImpl");
            return new ArrayList();
        }
        return listRet;

    }

    public List<GantryPassDivDto> exportGantryPassDivList(String classDate, Integer start, Integer end, JSONArray whereParams) {
        List list=new ArrayList();
        List<GantryPassDivDto> listRet=new ArrayList<GantryPassDivDto>();
        String sql="";
        String resultSql="SELECT \n" +
                "   RN,\n" +
                "\t PASSID,\n" +
                "\t CLASSDATE,\n" +
                "\t PAYFEE,\n" +
                "\t FEE,\n" +
                "   VEHICALTYPENAME,\n" +
                "\t VEHICLEID,\n" +
                "\t ENPOINTNAME,\n" +
                "\t EXPOINTNAME,\n" +
                "\t ENTIME,\n" +
                "\t EXTIME";

        String startsql ="SELECT \n" +
                "\t\t\t\t ROWNUM as RN,\n" +
                "\t\t\t\t t.PASSID,\n" +
                "\t\t\t\t t.CLASSDATE,\n" +
                "\t\t\t\t t.PAYFEE/100 AS PAYFEE,\n" +
                "\t\t\t\t t.FEE/100 AS FEE,\n" +
                "\t\t\t\t ttd.TEXT AS VEHICALTYPENAME,\n" +
                "\t\t\t\t CONCAT(substr( t.VEHICLEID, 1,instr(t.VEHICLEID,'_')-1) || '_',(select text from PLATECOLOR_TEXT where value=substr( t.VEHICLEID, instr(t.VEHICLEID,'_')+1))) AS VEHICLEID,\n" +
                "\t\t\t\t gten.NAME AS ENPOINTNAME,\n" +
                "\t\t\t\t gtex.NAME AS EXPOINTNAME,\n" +
                "\t\t\t\t t.ENTIME,\n" +
                "\t\t\t\t t.EXTIME" ;
        String endSql=" FROM GANTRY_PASS_DIV t\n" +
                "\t\t\tLEFT JOIN type_text ttd ON ( t.VEHICLETYPE = ttd.value )\n" +
                "\t\t\tLEFT JOIN GANTRY_TABLE gten ON ( t.ENPOINTID = gten.GANTRYHEX)\n" +
                "\t\t\tLEFT JOIN GANTRY_TABLE gtex ON ( t.EXPOINTID = gtex.GANTRYHEX )" +
                "\t where t.classdate = to_date( '"+classDate+"', 'yyyy-mm-dd' ) \n";
        try{
            if(whereParams.size()>0){
                endSql +=  solveSearchJsonGantry(whereParams);
            }
            if(start >=0 && end >0){
                sql = resultSql+" from ("+ startsql  +endSql+ " and ROWNUM <= "+end+" )ss where 1=1 AND ss.rn >= "+start+ "" ;
            }
            list= this.mapperI.selectforlist(sql);
            if(list.size()>0){
                if(!PubTools.isEmpty(list.get(0))){
                    //解析特情值不是查询总数
                    if(start >=0 && end>0){
                        for(int i=0;i<list.size();i++){
                            Map map= (Map<String,Object>) list.get(i);
                            GantryPassDivDto dto=new GantryPassDivDto();
                            dto.setRN(Integer.parseInt(map.get("RN").toString()));
                            dto.setPASSID((map.get("PASSID").toString()));
                            dto.setCLASSDATE((map.get("CLASSDATE").toString()));
                            if(!PubTools.isEmpty(map.get("FEE"))){
                                dto.setFEE(new BigDecimal(map.get("FEE").toString()));
                            }
                            dto.setENTIME(PubTools.isEmpty(map.get("ENTIME"))?null:(Date)(map.get("ENTIME")));
                            dto.setENPOINTNAME(PubTools.isEmpty(map.get("ENPOINTNAME"))?"":map.get("ENPOINTNAME").toString());
                            dto.setEXTIME(PubTools.isEmpty(map.get("EXTIME"))?null:(Date)(map.get("EXTIME")));
                            dto.setEXPOINTNAME(PubTools.isEmpty(map.get("EXPOINTNAME"))?"":map.get("EXPOINTNAME").toString());
                            dto.setVEHICLEID(map.get("VEHICLEID").toString());
                            dto.setVEHICALTYPENAME(PubTools.isEmpty(map.get("VEHICALTYPENAME"))?"":map.get("VEHICALTYPENAME").toString());
                            listRet.add(dto);
                        }

                    }
                }
            }
        }catch(Exception e){
            e.printStackTrace();
            LogUtil.WriteLog_Error("查询数据失败==="+e.getMessage(),"ExcelDateImpl");
            return new ArrayList();
        }
        return listRet;

    }

    private String solveSearchJSOn(JSONArray params){
        String querySql="";
        if(params.size()>0){
            for(int  k=0;k<params.size();k++){
                JSONObject retO=(JSONObject) params.get(k);
                String colName=retO.get("colName").toString();
                String  val=retO.get("value").toString();
                if(!PubTools.isNull(val)){
                    if (colName.equals("vecheType")) {
                        querySql += "\tAND t.vehicletype = ( SELECT value FROM type_text WHERE text = '" + val + "' ) ";
                    } else if (colName.equals("sPassId")) {
                        querySql += "\t AND t.passid = '" + val + "' ";
                    }else if(colName.equals("enSTANAME")){
                        querySql += "\tAND t.GPA_ENTOLLSTATIONNAME like  '%"+val+"%'";
                    }else if(colName.equals("exSTANAME")){
                        querySql += "\tAND t.GPA_EXTOLLSTATIONNAME like  '%"+val+"%'";
                    }else if(colName.equals("sVEHICLEID")){
                        querySql += "\tAND t.VEHICLEID  = '" + val + "' ";
                    }else if(colName.equals("sVecheType")){
                        querySql += "\tAND t.vehicletype = '" + val + "' ";
                    }else if(colName.equals("sVecheClass")){
                        querySql += "\tAND t.VEHICLECLASS ='" + val + "' ";
                    }else if(colName.equals("sExitfeeType")){
                        querySql += "\tAND a.EXITFEETYPE ='"+val+"' ";
                    }else if(colName.equals("SENSTANAMEID")){
                        querySql += "\tAND t.GPA_ENPOINTID in (select GANTRYHEX from  GANTRY_TABLE WHERE STANO = '" + val + "') ";
                    }else if(colName.equals("SEXSTANAMEID")){
                        querySql += "\tAND t.GPA_EXPOINTID in (select GANTRYHEX from  GANTRY_TABLE WHERE STANO = '" + val + "') ";
                    }else if(colName.equals("sStatus")){
                        querySql += "\tAND t.STATUS ='"+val+"' ";
                    }
                }
            }
        }
        return querySql;
    }

    private String solveSearchJsonGantry(JSONArray params){
        String querySql="";
        if(params.size()>0){
            for(int  k=0;k<params.size();k++){
                JSONObject retO=(JSONObject) params.get(k);
                String colName=retO.get("colName").toString();
                String  val=retO.get("value").toString();
                if(!PubTools.isNull(val)){
                    if(colName.equals("sPassId")){
                        querySql += "\t AND t.passid = '"+val+"' ";
                    }else if(colName.equals("enSTANAME")){
                        querySql += "\tAND t.GPA_ENTOLLSTATIONNAME like  '%"+val+"%'";
                    }else if(colName.equals("sVEHICLEID")){
                        querySql += "\tAND t.VEHICLEID  like '%"+val+"%' ";
                    }else if(colName.equals("sVecheType")){
                        querySql += "\tAND t.VEHICLETYPE = '"+val+"' ";
                    }else if(colName.equals("sGANTRYHEX")){
                        querySql += "\tAND t.EXPOINTID = '"+val+"' ";
                    }else if(colName.equals("stano")){
                        querySql += "\tAND t.EXPOINTID in(SELECT GANTRYHEX FROM GANTRY_TABLE WHERE  stano="+val+") ";
                    }else if(colName.equals("roadno")){
                        querySql += "\tAND t.EXPOINTID in(SELECT GANTRYHEX FROM GANTRY_TABLE WHERE  stano in(" +
                                " SELECT DISTINCT STANO DIV_NAME_TABLE WHERE ROADNO ="+val+"))  ";
                    }else if(colName.equals("subcomno")){
                        querySql += "\tAND t.EXPOINTID in(SELECT GANTRYHEX FROM GANTRY_TABLE WHERE  stano in(" +
                                " SELECT DISTINCT STANO DIV_NAME_TABLE WHERE SUBCOMNO ="+val+"))  ";
                    }else if(colName.equals("sEACHGANTRY")){
                        querySql += "\tAND t.EXPOINTID in(SELECT GANTRYHEX FROM GANTRY_TABLE WHERE  ID in(" +
                                " SELECT DISTINCT GANTRY_ID FROM DIV_INTERFLOW_TABLE WHERE INTER_HEX ='"+val+"'))  ";
                    }
                }
            }
        }
        return querySql;
    }
    public String getFlagType(String value){
        String ret="";
        String sql="SELECT LISTAGG(TEXT, ',') WITHIN GROUP (ORDER BY VALUE) AS FLAGTEXT\n" +
                "FROM FLAG_TEXT where value in("+value+")";
        try{
            List temp = this.mapperI.selectforlist(sql);
            Map<String,Object> select1D=new HashMap<>();
            if(temp != null && temp.size()>0){
                Map<String,Object> select1=(Map<String,Object>)temp.get(0);
                ret= select1.get("FLAGTEXT").toString();
            }
        }catch(Exception e){
            e.printStackTrace();
            ret="";
        }

        return ret;
    }*/
}
