package com.jkcredit.invoice.credit.custInterface;

import cn.com.taiji.sdk.model.comm.protocol.tts.trade.service.CardTradeModel;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.jkcredit.invoice.common.DataResult;
import com.jkcredit.invoice.mapper.customer.CustomerRecMapper;
import com.jkcredit.invoice.model.entity.customer.CustomerCarRec;
import com.jkcredit.invoice.model.entity.customer.CustomerRec;
import com.jkcredit.invoice.service.lowerService.SelfCarServiceL;
import com.jkcredit.invoice.service.lowerService.vo.*;
import com.jkcredit.invoice.service.selfCar.SelfCarService;
import com.jkcredit.invoice.util.DateUtil;
import com.jkcredit.invoice.util.RespR;
import com.mysql.cj.xdevapi.JsonArray;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;


@Slf4j
@Service("selfCarInterService")
public class SelfCarInterServiceImpl implements SelfCarInterService {


    @Autowired
    SelfCarServiceL selfCarService;

    @Autowired
    CustomerRecMapper customerRecMapper;

    /**
     * 自有车 用户卡列表查询接口
     * @param appKey
     * @param api
     * @param data
     * @return
     */
    @Override
    public DataResult customerETCQuery(String appKey, String api, String data,String requestid) {

        long costtimestart = System.currentTimeMillis();

        DataResult result = new DataResult();

        result.setData(3);
        result.setCode(200);
        result.setRequestid(requestid);
        result.setMsg("无法认证");

        try {
        log.info("[-SelfCarInterServiceImpl.customerETCQuery-] request appKey=" + appKey + " ,api=" + api + " ,data=" +data);
        JSONObject jsonObject = JSONObject.parseObject(data);
        String companyNum =  jsonObject.getString("companyNum");//企业编号 必输
        String cardId = jsonObject.getString("cardId");//卡号  非必输
        String plateNum = jsonObject.getString("plateNum");//车牌号 非必输
        Integer plateColor = jsonObject.getInteger("plateColor");//车牌颜色 非必输
        if(StringUtils.isEmpty(data)|| null == jsonObject || StringUtils.isEmpty(companyNum)){
            return  result;
        }

        CustomerRec customerRec = new CustomerRec();
        customerRec.setCustomerName(appKey);
        customerRec.setCompanyNum(companyNum);
        CustomerRec customerRec1 = customerRecMapper.selectByCustomerNameAndCompanyNum(customerRec);
            if (null == customerRec1){
                result.setMsg("该企业编号未注册企业!");
                return result;
            }

            EtcQueryVo etcQueryVo = new EtcQueryVo();
            etcQueryVo.setCustomerName(appKey);//客户名称
            etcQueryVo.setCompanyName(customerRec1.getCompanyName());//企业名称
            etcQueryVo.setPlateNum(plateNum);//车牌号 非必输
            etcQueryVo.setCardId(cardId);//卡号 非必输
            etcQueryVo.setPlateColor(plateColor);//车牌颜色 非必输
        RespR rs = selfCarService.getEtcInfo(etcQueryVo);
        long costtimeend = System.currentTimeMillis();
        log.info("[-SelfCarInterServiceImpl.customerETCQuery-] result is "
                    + rs.toString() + ", request is " + data + " ,costtime="
                    + (costtimeend - costtimestart));
        if(null != rs && rs.getCode() == 0){
           result.setData(1);
           result.setCode(200);
           result.setMsg(rs.getData().toString());
           return result;
        } else {
            result.setData(3);
            result.setCode(200);
            result.setMsg(rs.getMsg());
            return result;
        }
        } catch (Exception e) {
            log.error("[-SelfCarInterServiceImpl.customerETCQuery-] get httpclient exception is "
                            + e + ", request is " + data);
        }
        return result;
    }





    /**
     * 自有车 卡信息查询接口
     * @param appKey
     * @param api
     * @param data
     * @return
     */
    @Override
    public DataResult customerQueryEtcInfo(String appKey, String api, String data,String requestid) {

        long costtimestart = System.currentTimeMillis();

        DataResult result = new DataResult();

        result.setData(3);
        result.setCode(200);
        result.setRequestid(requestid);
        result.setMsg("无法认证");

        try {
            log.info("[-SelfCarInterServiceImpl.customerQueryEtcInfo-] request appKey=" + appKey + " ,api=" + api + " ,data=" +data);
            JSONObject jsonObject = JSONObject.parseObject(data);
            String companyNum =  jsonObject.getString("companyNum");//企业编号 必输
            JSONArray vehicleList = jsonObject.getJSONArray("vehicleList");//车牌的json字符串 必输
            //JSONObject jb = vehicleList.getJSONObject(0);
          //  String plateNum = jb.getString("plateNum");//车牌号
            //Integer plateColor = jb.getInteger("plateColor");//车牌颜色
            if(StringUtils.isEmpty(data)|| null == jsonObject || StringUtils.isEmpty(companyNum)
                    || null == vehicleList
                     ){
                return  result;
            }

            CustomerRec customerRec = new CustomerRec();
            customerRec.setCustomerName(appKey);
            customerRec.setCompanyNum(companyNum);
            CustomerRec customerRec1 = customerRecMapper.selectByCustomerNameAndCompanyNum(customerRec);

            if (null == customerRec1){
                result.setMsg("该企业编号未注册企业!");
                return result;
            }

            EtcBindVo etcQueryVo = new EtcBindVo();
            etcQueryVo.setCustomerName(appKey);//客户名称
            etcQueryVo.setCompanyName(customerRec1.getCompanyName());//企业名称

            List<CarVo> cards = new ArrayList<CarVo>();
            for(int i=0;i<vehicleList.size();i++) {
                JSONObject jb = vehicleList.getJSONObject(i);
                String plateNum = jb.getString("plateNum");//车牌号
                Integer plateColor = jb.getInteger("plateColor");//车牌颜色
                if(null == jb || StringUtils.isEmpty(plateNum)
                        || null == plateColor
                ){
                    return  result;
                }

                CarVo carVo = new CarVo();
                carVo.setNum(plateNum);
                carVo.setColor(plateColor);
                cards.add(carVo);
            }
            etcQueryVo.setCards(cards);
            RespR rs = selfCarService.queryEtcInfo(etcQueryVo);

            long costtimeend = System.currentTimeMillis();
            log.info("[-SelfCarInterServiceImpl.customerQueryEtcInfo-] result is "
                    + rs.toString() + ", request is " + data + " ,costtime="
                    + (costtimeend - costtimestart));
            if(null != rs && rs.getCode() == 0){
                result.setData(1);
                result.setCode(200);
                result.setMsg(rs.getData().toString());
                return result;
            } else {
                result.setData(3);
                result.setCode(200);
                result.setMsg(rs.getMsg());
                return result;
            }
        } catch (Exception e) {
            log.error("[-SelfCarInterServiceImpl.customerQueryEtcInfo-] get httpclient exception is "
                    + e + ", request is " + data);
        }
        return result;
    }





    /**
     * 自有车下发短信通知接口
     * @param appKey
     * @param api
     * @param data
     * @return
     */
    @Override
    public DataResult customerETCRec(String appKey, String api, String data,String requestid) {

        long costtimestart = System.currentTimeMillis();

        DataResult result = new DataResult();

        result.setData(3);
        result.setCode(200);
        result.setRequestid(requestid);
        result.setMsg("无法认证");

        try {
            log.info("[-SelfCarInterServiceImpl.customerETCRec-] request appKey=" + appKey + " ,api=" + api + " ,data=" +data);
            JSONObject jsonObject = JSONObject.parseObject(data);
            String companyNum =  jsonObject.getString("companyNum");//企业编号 必输
            String mobile =  jsonObject.getString("mobile");//企业预留手机号 必输
            JSONArray cardIdList = jsonObject.getJSONArray("cardIdList");//ETC卡编号列表 必输
            //JSONObject jb = cardIdList.getJSONObject(0);
           // String cardId = jb.getString("cardId");//用户卡Id
            if(StringUtils.isEmpty(data)|| null == jsonObject || StringUtils.isEmpty(companyNum)
                    || StringUtils.isEmpty(mobile)
                    || null == cardIdList

            ){
                return  result;
            }

            CustomerRec customerRec = new CustomerRec();
            customerRec.setCustomerName(appKey);
            customerRec.setCompanyNum(companyNum);
            CustomerRec customerRec1 = customerRecMapper.selectByCustomerNameAndCompanyNum(customerRec);
            if (null == customerRec1){
                result.setMsg("该企业编号未注册企业!");
                return result;
            }
            EtcBindVo etcQueryVo = new EtcBindVo();
            etcQueryVo.setCustomerName(appKey);//客户名称
            etcQueryVo.setCompanyName(customerRec1.getCompanyName());//企业名称
            etcQueryVo.setMobile(mobile);//企业预留手机号
            List<CarVo> cards = new ArrayList<CarVo>();
            for(int i=0;i<cardIdList.size();i++) {
                JSONObject jb = cardIdList.getJSONObject(i);
                String cardId = jb.getString("cardId");//用户卡Id

                if(null == jb || StringUtils.isEmpty(cardId)
                ){
                    return  result;
                }


                CarVo carVo = new CarVo();
                carVo.setEtcNum(cardId);
                cards.add(carVo);
            }
            etcQueryVo.setCards(cards);
            RespR rs = selfCarService.customerEtcRec(etcQueryVo);
            long costtimeend = System.currentTimeMillis();
            log.info("[-SelfCarInterServiceImpl.customerETCRec-] result is "
                    + rs.toString() + ", request is " + data + " ,costtime="
                    + (costtimeend - costtimestart));
            if(null != rs && rs.getCode() == 0){
                result.setData(1);
                result.setCode(200);
                result.setMsg(rs.getData().toString());
                return result;
            } else {
                result.setData(3);
                result.setCode(200);
                result.setMsg(rs.getMsg());
                return result;
            }
        } catch (Exception e) {
            log.error("[-SelfCarInterServiceImpl.customerETCRec-] get httpclient exception is "
                    + e + ", request is " + data);
        }
        return result;
    }




    /**
     * 自有车 卡绑定接口 渠道调用此接口，上传用户收到的短信验证码
     * @param appKey
     * @param api
     * @param data
     * @return
     */
    @Override
    public DataResult customerETCRecValid(String appKey, String api, String data,String requestid) {

        long costtimestart = System.currentTimeMillis();

        DataResult result = new DataResult();

        result.setData(3);
        result.setCode(200);
        result.setRequestid(requestid);
        result.setMsg("无法认证");

        try {
            log.info("[-SelfCarInterServiceImpl.customerETCRecValid-] request appKey=" + appKey + " ,api=" + api + " ,data=" +data);
            JSONObject jsonObject = JSONObject.parseObject(data);
            String companyNum =  jsonObject.getString("companyNum");//企业编号 必输
            String mobile =  jsonObject.getString("mobile");//企业预留手机号 必输
            String validCode =  jsonObject.getString("validCode");//验证码 必输
            if(StringUtils.isEmpty(data)|| null == jsonObject || StringUtils.isEmpty(companyNum)
                    || StringUtils.isEmpty(mobile)
                    || StringUtils.isEmpty(validCode)

            ){
                return  result;
            }

            CustomerRec customerRec = new CustomerRec();
            customerRec.setCustomerName(appKey);
            customerRec.setCompanyNum(companyNum);
            CustomerRec customerRec1 = customerRecMapper.selectByCustomerNameAndCompanyNum(customerRec);
            if (null == customerRec1){
                result.setMsg("该企业编号未注册企业!");
                return result;
            }
            EtcValidVo etcValidVo  = new EtcValidVo();
            etcValidVo.setCustomerName(appKey);
            etcValidVo.setCompanyName(customerRec1.getCompanyName());
            etcValidVo.setValidCode(validCode);
            etcValidVo.setMobile(mobile);
            etcValidVo.setInterType(0);//接口

            RespR rs = selfCarService.customerEtcRecValid(etcValidVo);
            long costtimeend = System.currentTimeMillis();
            log.info("[-SelfCarInterServiceImpl.customerETCRecValid-] result is "
                    + rs.toString() + ", request is " + data + " ,costtime="
                    + (costtimeend - costtimestart));
            if(null != rs && rs.getCode() == 0){
                result.setData(1);
                result.setCode(200);
                result.setMsg(rs.getData().toString());
                return result;
            } else {
                result.setData(3);
                result.setCode(200);
                result.setMsg(rs.getMsg());
                return result;
            }
        } catch (Exception e) {
            log.error("[-SelfCarInterServiceImpl.customerETCRecValid-] get httpclient exception is "
                    + e + ", request is " + data);
        }
        return result;
    }





    /**
     * 自有车 交易查询接口 渠道通过此接口可以查询单张卡连续90天内的交易（待开票、开票中、已开票）
     * @param appKey
     * @param api
     * @param data
     * @return
     */
    @Override
    public DataResult getTradeList(String appKey, String api, String data,String requestid) {

        long costtimestart = System.currentTimeMillis();

        DataResult result = new DataResult();

        result.setData(3);
        result.setCode(200);
        result.setRequestid(requestid);
        result.setMsg("无法认证");

        try {
            log.info("[-SelfCarInterServiceImpl.getTradeList-] request appKey=" + appKey + " ,api=" + api + " ,data=" +data);
            JSONObject jsonObject = JSONObject.parseObject(data);
            String companyNum =  jsonObject.getString("companyNum");//企业编号 必输
            String cardId =  jsonObject.getString("cardId");//卡号 必输
            Integer tradeStatus =  jsonObject.getInteger("tradeStatus");//交易状态 必输
            String startExTime =  jsonObject.getString("startExTime");//开始时间 必输
            String endExTime =  jsonObject.getString("endExTime");//结束时间 必输
            if(StringUtils.isEmpty(data)|| null == jsonObject || StringUtils.isEmpty(companyNum)
                    || StringUtils.isEmpty(cardId)
                    || null == tradeStatus
                    || StringUtils.isEmpty(startExTime)
                    || StringUtils.isEmpty(endExTime)

            ){
                return  result;
            }

            CustomerRec customerRec = new CustomerRec();
            customerRec.setCustomerName(appKey);
            customerRec.setCompanyNum(companyNum);
            CustomerRec customerRec1 = customerRecMapper.selectByCustomerNameAndCompanyNum(customerRec);
            if (null == customerRec1){
                result.setMsg("该企业编号未注册企业!");
                return result;
            }
            TradeRequestVo tradeRequestVo  = new TradeRequestVo();
            tradeRequestVo.setCustomerName(appKey);
            tradeRequestVo.setCompanyName(customerRec1.getCompanyName());
            tradeRequestVo.setStartTime(DateUtil.getDistanceHoursFormat(startExTime));
            tradeRequestVo.setEndTime(DateUtil.getDistanceHoursFormat(endExTime));
            tradeRequestVo.setEtcId(cardId);
            tradeRequestVo.setTradeStatus(tradeStatus);
            tradeRequestVo.setInterType(0);//0 接口

            if(tradeRequestVo.getTradeStatus() ==null){
                tradeRequestVo.setTradeStatus(1);
                RespR<List<CardTradeModel>> respRbefore = selfCarService.getTradeList(tradeRequestVo);
                tradeRequestVo.setTradeStatus(2);
                RespR<List<CardTradeModel>> respRUnder = selfCarService.getTradeList(tradeRequestVo);
                tradeRequestVo.setTradeStatus(3);
                RespR<List<CardTradeModel>> respRAfter = selfCarService.getTradeList(tradeRequestVo);
                //合并展示
                List<CardTradeModel> cardTradeModels = new ArrayList<>();
                if(respRbefore.getCode() == 0){
                    cardTradeModels.addAll(respRbefore.getData());
                }
                if(respRUnder.getCode() == 0){
                    cardTradeModels.addAll(respRUnder.getData());
                }
                if(respRAfter.getCode() == 0){
                    cardTradeModels.addAll(respRAfter.getData());
                }

                result.setData(1);
                result.setCode(200);
                result.setMsg(cardTradeModels.toString());
                return result;
            }
            RespR rs = selfCarService.getTradeList(tradeRequestVo);
            long costtimeend = System.currentTimeMillis();
            log.info("[-SelfCarInterServiceImpl.getTradeList-] result is "
                    + rs.toString() + ", request is " + data + " ,costtime="
                    + (costtimeend - costtimestart));
            if(null != rs && rs.getCode() == 0){
                result.setData(1);
                result.setCode(200);
                result.setMsg(rs.getData().toString());
                return result;
            } else {
                result.setData(3);
                result.setCode(200);
                result.setMsg(rs.getMsg());
                return result;
            }
        } catch (Exception e) {
            log.error("[-SelfCarInterServiceImpl.getTradeList-] get httpclient exception is "
                    + e + ", request is " + data);
        }
        return result;
    }




    /**
     * 自有车 交易查询接口 渠道通过此接口可以查询单张卡连续90天内的交易（待开票、开票中、已开票）
     * @param appKey
     * @param api
     * @param data
     * @return
     */
    @Override
    public DataResult applInvoice(String appKey, String api, String data,String requestid) {

        long costtimestart = System.currentTimeMillis();

        DataResult result = new DataResult();

        result.setData(3);
        result.setCode(200);
        result.setRequestid(requestid);
        result.setMsg("无法认证");

        try {
            log.info("[-SelfCarInterServiceImpl.applInvoice-] request appKey=" + appKey + " ,api=" + api + " ,data=" +data);
            JSONObject jsonObject = JSONObject.parseObject(data);
            String companyNum =  jsonObject.getString("companyNum");//企业编号 必输
            String cardId =  jsonObject.getString("cardId");//卡号 必输
            JSONArray tradeIdModel = jsonObject.getJSONArray("tradeIdModel");//交易ID集合 必输

            String startExTime =  jsonObject.getString("startExTime");//开始时间 必输
            String endExTime =  jsonObject.getString("endExTime");//结束时间 必输
            if(StringUtils.isEmpty(data)|| null == jsonObject || StringUtils.isEmpty(companyNum)
                    || StringUtils.isEmpty(cardId)
                    || null == tradeIdModel
                    || StringUtils.isEmpty(startExTime)
                    || StringUtils.isEmpty(endExTime)

            ){
                return  result;
            }

            CustomerRec customerRec = new CustomerRec();
            customerRec.setCustomerName(appKey);
            customerRec.setCompanyNum(companyNum);
            CustomerRec customerRec1 = customerRecMapper.selectByCustomerNameAndCompanyNum(customerRec);
            if (null == customerRec1){
                result.setMsg("该企业编号未注册企业!");
                return result;
            }
            InvoiceApplVo invoiceApplVo  = new InvoiceApplVo();
            invoiceApplVo.setCustomerName(appKey);
            invoiceApplVo.setCompanyName(customerRec1.getCompanyName());
            invoiceApplVo.setCardId(cardId);


            List<String> tradeIds = new ArrayList<String>();
            for(int i=0;i<tradeIdModel.size();i++) {
                JSONObject jb = tradeIdModel.getJSONObject(i);
                String tradeId = jb.getString("tradeId");//交易ID
                if(null == jb || StringUtils.isEmpty(tradeId)
                ){
                    return  result;
                }
                tradeIds.add(tradeId);
            }

            invoiceApplVo.setTradeIds(tradeIds);
            RespR rs = selfCarService.applInvoice(invoiceApplVo);
            long costtimeend = System.currentTimeMillis();
            log.info("[-SelfCarInterServiceImpl.applInvoice-] result is "
                    + rs.toString() + ", request is " + data + " ,costtime="
                    + (costtimeend - costtimestart));
            if(null != rs && rs.getCode() == 0){
                result.setData(1);
                result.setCode(200);
                result.setMsg(rs.getData().toString());
                return result;
            } else {
                result.setData(3);
                result.setCode(200);
                result.setMsg(rs.getMsg());
                return result;
            }
        } catch (Exception e) {
            log.error("[-SelfCarInterServiceImpl.applInvoice-] get httpclient exception is "
                    + e + ", request is " + data);
        }
        return result;
    }




    /**
     * 自有车 已开发票查询接口 渠道通过此接口可以根据该公司绑定的单张卡查询此卡在某个月开具的发票
     * @param appKey
     * @param api
     * @param data
     * @return
     */
    @Override
    public DataResult getSelfCarInvoicesByTime(String appKey, String api, String data,String requestid) {

        long costtimestart = System.currentTimeMillis();

        DataResult result = new DataResult();

        result.setData(3);
        result.setCode(200);
        result.setRequestid(requestid);
        result.setMsg("无法认证");

        try {
            log.info("[-SelfCarInterServiceImpl.getSelfCarInvoicesByTime-] request appKey=" + appKey + " ,api=" + api + " ,data=" +data);
            JSONObject jsonObject = JSONObject.parseObject(data);
            String companyNum =  jsonObject.getString("companyNum");//企业编号 必输
            String cardId =  jsonObject.getString("cardId");//卡号 必输
            String startInvoiceMakeTime =  jsonObject.getString("startInvoiceMakeTime");//开始时间 必输
            String endInvoiceMakeTime =  jsonObject.getString("endInvoiceMakeTime");//结束时间 必输
            if(StringUtils.isEmpty(data)|| null == jsonObject || StringUtils.isEmpty(companyNum)
                    || StringUtils.isEmpty(cardId)
                    || StringUtils.isEmpty(startInvoiceMakeTime)
                    || StringUtils.isEmpty(endInvoiceMakeTime)

            ){
                return  result;
            }

            CustomerRec customerRec = new CustomerRec();
            customerRec.setCustomerName(appKey);
            customerRec.setCompanyNum(companyNum);
            CustomerRec customerRec1 = customerRecMapper.selectByCustomerNameAndCompanyNum(customerRec);
            if (null == customerRec1){
                result.setMsg("该企业编号未注册企业!");
                return result;
            }
            SelfCarDueQueryVo selfCarDueQueryVo  = new SelfCarDueQueryVo();
            selfCarDueQueryVo.setCustomername(appKey);
            selfCarDueQueryVo.setCompanyName(customerRec1.getCompanyName());
            selfCarDueQueryVo.setCardId(cardId);
            selfCarDueQueryVo.setStartTime(startInvoiceMakeTime);
            selfCarDueQueryVo.setEndTime(endInvoiceMakeTime);

            RespR rs = selfCarService.getSelfCarInvoicesByTime(selfCarDueQueryVo);
            long costtimeend = System.currentTimeMillis();
            log.info("[-SelfCarInterServiceImpl.getSelfCarInvoicesByTime-] result is "
                    + rs.toString() + ", request is " + data + " ,costtime="
                    + (costtimeend - costtimestart));
            if(null != rs && rs.getCode() == 0){
                result.setData(1);
                result.setCode(200);
                result.setMsg(rs.getMsg());
                return result;
            } else {
                result.setData(3);
                result.setCode(200);
                result.setMsg(rs.getMsg());
                return result;
            }
        } catch (Exception e) {
            log.error("[-SelfCarInterServiceImpl.getSelfCarInvoicesByTime-] get httpclient exception is "
                    + e + ", request is " + data);
        }
        return result;
    }





    /**
     * 自有车 发票下载 渠道通过此接口可以下载某公司某个月份开具的发票。
     * @param appKey
     * @param api
     * @param data
     * @return
     */
    @Override
    public DataResult getSelfCarInvoicePackage(String appKey, String api, String data,String requestid) {

        long costtimestart = System.currentTimeMillis();

        DataResult result = new DataResult();

        result.setData(3);
        result.setCode(200);
        result.setRequestid(requestid);
        result.setMsg("无法认证");

        try {
            log.info("[-SelfCarInterServiceImpl.getSelfCarInvoicePackage-] request appKey=" + appKey + " ,api=" + api + " ,data=" +data);
            JSONObject jsonObject = JSONObject.parseObject(data);
            String companyNum =  jsonObject.getString("companyNum");//企业编号 必输
            String makeMonth =  jsonObject.getString("makeMonth");//发票开具月份 必输
            if(StringUtils.isEmpty(data)|| null == jsonObject || StringUtils.isEmpty(companyNum)
                    || StringUtils.isEmpty(makeMonth)

            ){
                return  result;
            }

            CustomerRec customerRec = new CustomerRec();
            customerRec.setCustomerName(appKey);
            customerRec.setCompanyNum(companyNum);
            CustomerRec customerRec1 = customerRecMapper.selectByCustomerNameAndCompanyNum(customerRec);
            if (null == customerRec1){
                result.setMsg("该企业编号未注册企业!");
                return result;
            }
            InvoicePackageVo invoicePackageVo  = new InvoicePackageVo();
            invoicePackageVo.setCustomerName(appKey);
            invoicePackageVo.setCompanyName(customerRec1.getCompanyName());
            invoicePackageVo.setMonth(makeMonth);

            RespR rs = selfCarService.getInvoicePackge(invoicePackageVo);
            long costtimeend = System.currentTimeMillis();
            log.info("[-SelfCarInterServiceImpl.getSelfCarInvoicePackage-] result is "
                    + rs.toString() + ", request is " + data + " ,costtime="
                    + (costtimeend - costtimestart));
            if(null != rs && rs.getCode() == 0){
                result.setData(1);
                result.setCode(200);
                result.setMsg(rs.getData().toString());
                return result;
            } else {
                result.setData(3);
                result.setCode(200);
                result.setMsg(rs.getMsg());
                return result;
            }
        } catch (Exception e) {
            log.error("[-SelfCarInterServiceImpl.getSelfCarInvoicePackage-] get httpclient exception is "
                    + e + ", request is " + data);
        }
        return result;
    }





    /**
     * 自有车 卡解绑接口
     * @param appKey
     * @param api
     * @param data
     * @return
     */
    @Override
    public DataResult customerCarUnRec(String appKey, String api, String data,String requestid) {

        long costtimestart = System.currentTimeMillis();

        DataResult result = new DataResult();

        result.setData(3);
        result.setCode(200);
        result.setRequestid(requestid);
        result.setMsg("无法认证");

        try {
            log.info("[-SelfCarInterServiceImpl.customerCarUnRec-] request appKey=" + appKey + " ,api=" + api + " ,data=" +data);
            JSONObject jsonObject = JSONObject.parseObject(data);
            String companyNum =  jsonObject.getString("companyNum");//企业编号 必输
            String cardId =  jsonObject.getString("cardId");//Etc卡号 必输
            if(StringUtils.isEmpty(data)|| null == jsonObject || StringUtils.isEmpty(companyNum)
                    || StringUtils.isEmpty(cardId)

            ){
                return  result;
            }

            CustomerRec customerRec = new CustomerRec();
            customerRec.setCustomerName(appKey);
            customerRec.setCompanyNum(companyNum);
            CustomerRec customerRec1 = customerRecMapper.selectByCustomerNameAndCompanyNum(customerRec);
            if (null == customerRec1){
                result.setMsg("该企业编号未注册企业!");
                return result;
            }
            List<CustomerCarRec> customerCarRecList = new ArrayList<CustomerCarRec>();

            CustomerCarRec customerCarRec  = new CustomerCarRec();
            customerCarRec.setCustomerName(appKey);
            customerCarRec.setCompanyName(customerRec1.getCompanyName());
            customerCarRec.setEtcNum(cardId);
            customerCarRecList.add(customerCarRec);

            RespR rs = selfCarService.customerCarUnRec(customerCarRecList);
            long costtimeend = System.currentTimeMillis();
            log.info("[-SelfCarInterServiceImpl.customerCarUnRec-] result is "
                    + rs.toString() + ", request is " + data + " ,costtime="
                    + (costtimeend - costtimestart));
            if(null != rs && rs.getCode() == 0){
                result.setData(1);
                result.setCode(200);
                result.setMsg(rs.getData().toString());
                return result;
            } else {
                result.setData(3);
                result.setCode(200);
                result.setMsg(rs.getMsg());
                return result;
            }
        } catch (Exception e) {
            log.error("[-SelfCarInterServiceImpl.customerCarUnRec-] get httpclient exception is "
                    + e + ", request is " + data);
        }
        return result;
    }
}
