package com.dxhy.core.job.utils;

import cn.hutool.core.util.ObjectUtil;
import com.dxhy.api.model.invoice.InvoiceDetailInfo;
import com.dxhy.api.model.invoice.TDxRecordInvoice;
import com.dxhy.api.model.invoice.TDxRecordInvoiceTdysMhxcd;
import com.dxhy.api.model.invoice.TDxRecordInvoiceTdysMhxcdItem;
import com.dxhy.common.enums.FpztEnum;
import com.dxhy.common.utils.CommonUtil;
import com.dxhy.core.job.entity.*;
import com.dxhy.core.job.pojo.*;
import org.apache.commons.lang3.StringUtils;
import org.springframework.util.CollectionUtils;

import java.math.BigDecimal;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;

/**
 * 功能描述
 *
 * @author 陈刚扬
 * @date 2020/10/28
 */
@SuppressWarnings({"AlibabaUndefineMagicConstant", "AlibabaMethodTooLong", "DuplicatedCode"})
public class TransitionUtils {

    /**
     * 实体转换
     *
     * @param info 大企业返回的报文
     * @param tdly    通道来源：0：大企业采集，1：大企业发票下载，2：数据平台，3：乐企采集，4：大企业增值税发票归集
     * @return 返回
     * @throws ParseException
     *             异常
     */
    public static TDxRecordInvoice getInvoiceInfo(InvoiceInfo info, String tdly) throws ParseException {
        TDxRecordInvoice invoice = new TDxRecordInvoice();
        // 发票代码
        invoice.setInvoiceCode(info.getInvoiceCode());
        // 发票号码
        invoice.setInvoiceNo(info.getInvoiceNo());
        //发票UUID
        invoice.setUuid(info.getInvoiceCode()+info.getInvoiceNo());
        // 全电发票号码
        if(StringUtils.isNotBlank(info.getElectronicInvoiceNo())){
            invoice.setEleInvoiceNo(info.getElectronicInvoiceNo());
        }
        //细分发票类型
        invoice.setLqTdyslxDm(info.getDetailType());
        //主信息扩展字段
        invoice.setInvoiceExt(info.getInvoiceExt());
        //明细扩展字段
        invoice.setDetailExt(info.getDetailExt());
        //附件
        invoice.setFileList(info.getFileList());

        // 当前税款所属期
        invoice.setDqskssq(info.getCurrentTaxPeriod());
        // 当前税款所属期勾选截止日
        invoice.setGxjzr(info.getLegalizeEndDate());
        // 当前税款所属期可勾选发票开票日期起
        invoice.setGxfwq(info.getLegalizeInvoiceDateBegin());
        // 当前税款所属期可勾选发票开票日期止
        invoice.setGxfwz(info.getLegalizeInvoiceDateEnd());
        // 发票类型
        invoice.setInvoiceType(info.getInvoiceType());
        // 购方名称
        invoice.setGfName(info.getBuyerName());
        // 购方税号
        invoice.setGfTaxNo(info.getBuyerTaxNo());
        // 购方地址、电话
        invoice.setGfAddressAndPhone(info.getBuyerAddressPhone());
        // 购方开户行及账号
        invoice.setGfBankAndNo(info.getBuyerAcount());
        // 销方名称
        invoice.setXfName(info.getSalerName());
        // 销方税号
        invoice.setXfTaxNo(info.getSalerTaxNo());
        // 销方地址、电话
        invoice.setXfAddressAndPhone(info.getSalerAddressPhone());
        // 销方开户行及账号
        invoice.setXfBankAndNo(info.getSalerAcount());
        // 开票日期
        invoice.setInvoiceDate(CommonUtil.dateConvert(info.getInvoiceDate()));
        // 发票金额
        invoice.setInvoiceAmount(StringUtils.isNotBlank(info.getInvoiceAmount())?new BigDecimal(info.getInvoiceAmount()):null);
        // 发票税额
        invoice.setTaxAmount(StringUtils.isNotBlank(info.getTaxAmount())?new BigDecimal(info.getTaxAmount()):null);
        // 价税合计
        invoice.setTotalAmount(StringUtils.isNotBlank(info.getTotalAmount())?new BigDecimal(info.getTotalAmount()):null);
        // 备注
        invoice.setRemark(info.getRemark());
        // 发票状态
        invoice.setInvoiceStatus(info.getInvoiceStatus());

        //设置红字锁定标识
        if(FpztEnum.HZDQR.getFpztDm().equals(info.getInvoiceStatus())){
            invoice.setLqHzsdbs("Y");
        }
        //以redlock为准。如果是Y，则同步更改发票状态为80
        if(StringUtils.isNotBlank(info.getRedLock())){
            invoice.setLqHzsdbs(info.getRedLock());
            if("Y".equals(info.getRedLock())){
                invoice.setInvoiceStatus("80");
            }
        }

        // 是否代办退税
        if (info.getSfdbts() == null || "".equals(info.getSfdbts())) {
            invoice.setSfdbts(null);
        } else {
            invoice.setSfdbts(info.getSfdbts());
        }
        // 认证类型
        if (info.getRzlx() == null || "".equals(info.getRzlx())) {
            invoice.setRzlx(null);
        } else {
            invoice.setRzlx(info.getRzlx());
        }
        // 认证方式
        if (info.getLegalizeType() == null || "".equals(info.getLegalizeType())) {
            invoice.setRzhType("");
        } else {
            invoice.setRzhType(info.getLegalizeType());
        }
        // 校验码
        if (info.getCheckCode() == null || "".equals(info.getCheckCode())) {
            invoice.setCheckCode("");
        } else {
            invoice.setCheckCode(info.getCheckCode());
        }
        // 通行费标志
        if (info.getTxfbz() == null || "".equals(info.getTxfbz())) {
            invoice.setTxfbz("");
        } else {
            invoice.setTxfbz(info.getTxfbz());
        }
        // 零税率标志
        if (info.getLslbz() == null || "".equals(info.getLslbz())) {
            invoice.setLslbz("");
        } else {
            invoice.setLslbz(info.getLslbz());
        }

        invoice.setSfygx(info.getLegalizeState());
        if ("1".equals(info.getLegalizeState()) && !"4".equals(info.getRzlx())) {
            // 认证状态
            invoice.setRzhYesorno(info.getLegalizeState());
            // 认证日期
            if (info.getLegalizeDate() == null || "".equals(info.getLegalizeDate())) {
                invoice.setRzhDate(null);
            } else {
                invoice.setRzhDate(new SimpleDateFormat("yyyyMMdd").parse(info.getLegalizeDate()));
            }
            // 认证归属期
            if (info.getLegalizeBlongDate() == null || "".equals(info.getLegalizeBlongDate())) {
                invoice.setRzhBelongDate(null);
            } else {
                invoice.setRzhBelongDate(info.getLegalizeBlongDate());
            }
            invoice.setAuthStatus("4");
            invoice.setBdkStatus("1");
        } else {

            invoice.setAuthStatus("0");
        }
        if ("1".equals(info.getLegalizeState()) && "4".equals(info.getRzlx())) {
            // 认证状态
            invoice.setRzhYesorno("2");
            // 认证日期
            if (info.getLegalizeDate() == null || "".equals(info.getLegalizeDate())) {
                invoice.setRzhDate(null);
            } else {
                invoice.setRzhDate(new SimpleDateFormat("yyyyMMdd").parse(info.getLegalizeDate()));
            }
            // 认证归属期
            if (info.getLegalizeBlongDate() == null || "".equals(info.getLegalizeBlongDate())) {
                invoice.setRzhBelongDate(null);
            } else {
                invoice.setRzhBelongDate(info.getLegalizeBlongDate());
            }
            invoice.setAuthStatus("4");
            invoice.setBdkStatus("2");
        }
        // 管理状态
        if (info.getGlzt() == null || "".equals(info.getGlzt())) {
            invoice.setGlzt(null);
        } else {
            invoice.setGlzt(info.getGlzt());
        }
        // 信息来源
        if (info.getXxly() == null || "".equals(info.getXxly())) {
            invoice.setXxly("");
        } else {
            invoice.setXxly(info.getXxly());
        }
        //抵扣税额
        if (info.getDkse() == null || "".equals(info.getDkse())) {
            invoice.setDkTaxAmount(invoice.getTaxAmount());
        } else {
            invoice.setDkTaxAmount(new BigDecimal(info.getYxse()));
        }
        // 异常类型
        if (info.getYclx() == null || "".equals(info.getYclx())) {
            invoice.setYclx("");
        } else {
            invoice.setYclx(info.getYclx());
        }
        // 逾期可勾选标志
        if (info.getYqkgxbz() == null || "".equals(info.getYqkgxbz())) {
            invoice.setYqkgxbz("");
        } else {
            invoice.setYqkgxbz(info.getYqkgxbz());
        }
        if(StringUtils.isNotBlank(info.getBdkMessage())){
            invoice.setBdkMessage(info.getBdkMessage());
        }
        if(StringUtils.isNotBlank(info.getInvoiceSources())){
            invoice.setInvoiceSource(info.getInvoiceSources());
        }
        invoice.setSourceSystem("0");
        invoice.setValid("1");
        invoice.setTdly(tdly);
        return invoice;
    }

    /**
     * 实体转换
     *
     * @param detailInfo
     *            明细信息
     * @return 返回
     */
    public static TDxRecordInvoiceDetailJobEntity getInvoiceDetailInfo(InvoiceDetailInfo detailInfo) {
        TDxRecordInvoiceDetailJobEntity detail = new TDxRecordInvoiceDetailJobEntity();
        detail.setDetailNo(detailInfo.getDetailNo());
        detail.setGoodsName(detailInfo.getGoodsName());
        if (isBlank(detailInfo.getSpecificationModel())) {
            detail.setModel(null);
        } else {
            detail.setModel(detailInfo.getSpecificationModel());
        }
        if (isBlank(detailInfo.getGoodsNum())) {
            detail.setGoodsNum(null);
        } else {
            detail.setGoodsNum(detailInfo.getGoodsNum());
        }
        if ("".equals(detailInfo.getNum())) {
            detail.setNum(null);
        } else {
            detail.setNum(detailInfo.getNum());
        }

        if ("".equals(detailInfo.getUnit())) {
            detail.setUnit(null);
        } else {
            detail.setUnit(detailInfo.getUnit());
        }

        if ("".equals(detailInfo.getUnitPrice())) {
            detail.setUnitPrice(null);
        } else {
            detail.setUnitPrice(detailInfo.getUnitPrice());
        }
        if ("".equals(detailInfo.getDetailAmount())) {
            detail.setDetailAmount(null);
        } else {
            detail.setDetailAmount(detailInfo.getDetailAmount());
        }
        if ("".equals(CommonUtil.processTaxRate(detailInfo.getTaxRate()))) {
            detail.setTaxRate(null);
        } else {
            detail.setTaxRate(CommonUtil.processTaxRate(detailInfo.getTaxRate()));
        }
        if ("".equals(detailInfo.getTaxAmount())) {
            detail.setTaxAmount(null);
        } else {
            detail.setTaxAmount(detailInfo.getTaxAmount());
        }
        if ("".equals(detailInfo.getCph())) {
            detail.setCph("");
        } else {
            detail.setCph(detailInfo.getCph());
        }
        if (isBlank(detailInfo.getLx())) {
            detail.setLx("");
        } else {
            detail.setLx(detailInfo.getLx());
        }
        if (isBlank(detailInfo.getTxrqq())) {
            detail.setTxrqq("");
        } else {
            detail.setTxrqq(detailInfo.getTxrqq());
        }
        if (isBlank(detailInfo.getTxrqz())) {
            detail.setTxrqz("");
        } else {
            detail.setTxrqz(detailInfo.getTxrqz());
        }
        return detail;
    }

    private static Boolean isBlank(String str) {
        return str == null || str.trim().length() == 0;

    }

    /**
     * 实体类转换
     *
     * @author X Yang
     * @date 2017年6月8日 下午6:41:27
     */
    public static State getStateInfo(StateInfo info) throws ParseException {
        State state = new State();
        state.setInvoiceCode(info.getInvoiceCode());
        state.setInvoiceNo(info.getInvoiceNo());
        state.setInvoiceStatus(info.getInvoiceStatus());
        if ("".equals(info.getLegalizeDate())) {
            state.setLegalizeDate(null);
        } else {
            state.setLegalizeDate(new SimpleDateFormat("yyyyMMdd").parse(info.getLegalizeDate()));
        }

        state.setLegalizeState(info.getLegalizeState());
        if ("1".equals(info.getLegalizeState())) {
            state.setAuthStatus("4");
        } else {
            state.setAuthStatus("0");
        }
        if ("".equals(info.getLegalizeBelongDate())) {
            state.setLegalizeBelongDate(null);
        } else {
            state.setLegalizeBelongDate(info.getLegalizeBelongDate());
        }
        if ("".equals(info.getLegalizeType())) {
            state.setLegalizeType(null);
        } else {
            state.setLegalizeType(info.getLegalizeType());
        }
        if (info.getRzlx() == null) {
            state.setLegalizeLx(null);
        } else {
            state.setLegalizeLx(Integer.parseInt(info.getRzlx()));
        }
        if (StringUtils.isNotBlank(info.getZztime())) {
            state.setZttime(new SimpleDateFormat("yyyy-MM-dd hh:mm:ss").parse(info.getZztime()));
        }
        if (StringUtils.isNotBlank(info.getYqkgxbz())) {
            state.setYqkgxbz(info.getYqkgxbz());
        }
//        if (StringUtils.isNotBlank(info.getYxse())) {
//            state.setYxse(info.getYxse());
//        }
        if(StringUtils.isNotBlank(info.getDkse())){
            state.setYxse(info.getDkse());
        }
        if (StringUtils.isNotBlank(info.getGlzt())) {
            state.setGlzt(info.getGlzt());
        }
        if (StringUtils.isNotBlank(info.getXxly())) {
            state.setXxly(info.getXxly());
        }
        //设置红字锁定标识
        if(FpztEnum.HZDQR.getFpztDm().equals(info.getInvoiceStatus())){
            state.setLqHzsdbs("Y");
        }
        //以redlock为准。如果是Y，则同步更改发票状态为80
        if(StringUtils.isNotBlank(info.getRedLock())){
            state.setLqHzsdbs(info.getRedLock());
            if("Y".equals(info.getRedLock())){
                state.setInvoiceStatus("80");
            }
        }
        return state;
    }

    public static Map<String, Object> getVehicleInfo(VehicleSaleInvoiceInfos info) throws ParseException {

        TDxVehicleSaleInvoice vehicleSaleInvoice = new TDxVehicleSaleInvoice();
        TDxRecordInvoice veinfo = new TDxRecordInvoice();
        veinfo.setInvoiceCode(info.getInvoiceCode());
        veinfo.setInvoiceNo(info.getInvoiceNo());
        veinfo.setEleInvoiceNo(info.getElectronicInvoiceNo());
        veinfo.setDqskssq(info.getCurrentTaxPeriod());
        veinfo.setGxjzr(info.getLegalizeEndDate());
        veinfo.setGxfwq(info.getLegalizeInvoiceDateBegin());
        veinfo.setGxfwz(info.getLegalizeInvoiceDateEnd());
        veinfo.setInvoiceType(info.getInvoiceType());
        veinfo.setGfName(info.getBuyerName());
        veinfo.setInvoiceDate(new SimpleDateFormat("yyyyMMdd").parse(info.getInvoiceDate()));

        if (!isBlank(info.getSalerName())) {
            veinfo.setXfName(info.getSalerName());
        }

        if (!isBlank(info.getSalerTaxno())) {
            veinfo.setXfTaxNo(info.getSalerTaxno());
        }

        veinfo.setXfBankAndNo(StringUtils.defaultString(info.getSalerBank())+StringUtils.defaultString(info.getSalerAcount()));

        veinfo.setXfAddressAndPhone(StringUtils.defaultString(info.getSalerAddress())+StringUtils.defaultString(info.getSalerPhone()));

        if (isBlank(info.getBuyerIdNum())) {
            vehicleSaleInvoice.setBuyerIdNum("");
        } else {
            vehicleSaleInvoice.setBuyerIdNum(info.getBuyerIdNum());
        }
        veinfo.setGfTaxNo(info.getBuyerTaxNo());
        if (isBlank(info.getVehicleType())) {
            vehicleSaleInvoice.setVehicleType("");
        } else {
            vehicleSaleInvoice.setVehicleType(info.getVehicleType());
        }
        if (isBlank(info.getFactoryModel())) {
            vehicleSaleInvoice.setFactoryModel("");
        } else {
            vehicleSaleInvoice.setFactoryModel(info.getFactoryModel());
        }
        if (isBlank(info.getProductPlace())) {
            vehicleSaleInvoice.setProductPlace("");
        } else {
            vehicleSaleInvoice.setProductPlace(info.getProductPlace());
        }
        if (isBlank(info.getCertificate())) {
            vehicleSaleInvoice.setCertificate("");
        } else {
            vehicleSaleInvoice.setCertificate(info.getCertificate());
        }
        if (isBlank(info.getCertificateImport())) {
            vehicleSaleInvoice.setCertificateImport("");
        } else {
            vehicleSaleInvoice.setCertificateImport(info.getCertificateImport());
        }
        if (isBlank(info.getInspectionNum())) {
            vehicleSaleInvoice.setInspectionNum("");
        } else {
            vehicleSaleInvoice.setInspectionNum(info.getInspectionNum());
        }
        if (isBlank(info.getEngineNo())) {
            vehicleSaleInvoice.setEngineNo("");
        } else {
            vehicleSaleInvoice.setEngineNo(info.getEngineNo());
        }
        if (isBlank(info.getVehicleNo())) {
            vehicleSaleInvoice.setVehicleNo("");
        } else {
            vehicleSaleInvoice.setVehicleNo(info.getVehicleNo());
        }
        if(StringUtils.isNotBlank(info.getTotalAmount())){
            veinfo.setTotalAmount(new BigDecimal(info.getTotalAmount()));
        }
        if (isBlank(info.getPhone())) {
            vehicleSaleInvoice.setPhone("");
        } else {
            vehicleSaleInvoice.setPhone(info.getPhone());
        }
        if (isBlank(info.getBuyerBank())) {
            vehicleSaleInvoice.setBuyerBank("");
        } else {
            vehicleSaleInvoice.setBuyerBank(info.getBuyerBank());
        }
        vehicleSaleInvoice.setTaxRate(info.getTaxRate());
        veinfo.setTaxAmount(new BigDecimal(info.getTaxAmount()));
        if (isBlank(info.getTaxBureauCode())) {
            vehicleSaleInvoice.setTaxBureauCode("");
        } else {
            vehicleSaleInvoice.setTaxBureauCode(info.getTaxBureauCode());
        }
        if (isBlank(info.getTaxBureauName())) {
            vehicleSaleInvoice.setTaxBureauName("");
        } else {
            vehicleSaleInvoice.setTaxBureauName(info.getTaxBureauName());
        }
        veinfo.setInvoiceAmount(new BigDecimal(info.getInvoiceAmount()));
        if (isBlank(info.getTaxRecords())) {
            vehicleSaleInvoice.setTaxRecords("");
        } else {
            vehicleSaleInvoice.setTaxRecords(info.getTaxRecords());
        }
        if (isBlank(info.getTonnage())) {
            vehicleSaleInvoice.setTonnage("");
        } else {
            vehicleSaleInvoice.setTonnage(info.getTonnage());
        }
        if (isBlank(info.getLimitPeople())) {
            vehicleSaleInvoice.setLimitPeople("");
        } else {
            vehicleSaleInvoice.setLimitPeople(info.getLimitPeople());
        }
        veinfo.setInvoiceStatus(info.getInvoiceStatus());
        //如果是80-红字发票待确认
        if(FpztEnum.HZDQR.getFpztDm().equals(info.getInvoiceStatus())){
            veinfo.setLqHzsdbs("Y");
        }
        //以redlock为准。如果是Y，则同步更改发票状态为80
        if(StringUtils.isNotBlank(info.getRedLock())){
            veinfo.setLqHzsdbs(info.getRedLock());
            if("Y".equals(info.getRedLock())){
                veinfo.setInvoiceStatus("80");
            }
        }
        veinfo.setRzhYesorno("0");
        if ("1".equals(info.getLegalizeState()) && !"4".equals(info.getRzlx())) {
            veinfo.setAuthStatus("4");
            veinfo.setSfygx(info.getCheckStatus());
            veinfo.setRzhYesorno(info.getLegalizeState());
            if ("".equals(info.getTaxPeriod())) {
                veinfo.setRzhBelongDate(null);
            } else {
                veinfo.setRzhBelongDate(info.getTaxPeriod());
            }
            if ("".equals(info.getLegalizeDate())) {
                veinfo.setRzhDate(null);
            } else {
                veinfo.setRzhDate(new SimpleDateFormat("yyyyMMdd").parse(info.getLegalizeDate()));
            }
            veinfo.setBdkStatus("1");
        } else {

            veinfo.setAuthStatus("0");
        }
        if ("1".equals(info.getLegalizeState()) && "4".equals(info.getRzlx())) {
            veinfo.setAuthStatus("4");
            veinfo.setSfygx(info.getCheckStatus());
            veinfo.setRzhYesorno("2");
            if ("".equals(info.getTaxPeriod())) {
                veinfo.setRzhBelongDate(null);
            } else {
                veinfo.setRzhBelongDate(info.getTaxPeriod());
            }
            if ("".equals(info.getLegalizeDate())) {
                veinfo.setRzhDate(null);
            } else {
                veinfo.setRzhDate(new SimpleDateFormat("yyyyMMdd").parse(info.getLegalizeDate()));
            }
            veinfo.setBdkStatus("2");
        }

        if ("".equals(info.getLegalizeType())) {
            veinfo.setRzhType(null);
        } else {
            veinfo.setRzhType(info.getLegalizeType());
        }
        if (info.getSfdbts() == null) {
            veinfo.setSfdbts(null);
        } else {
            veinfo.setSfdbts(info.getSfdbts());
        }
        if (info.getRzlx() == null) {
            veinfo.setRzlx(null);
        } else {
            veinfo.setRzlx(info.getRzlx());
        }
        if ("".equals(info.getYxse()) || info.getYxse() == null) {
            veinfo.setDkTaxAmount(new BigDecimal(info.getTaxAmount()));
        } else {
            veinfo.setDkTaxAmount(new BigDecimal(info.getYxse()));
        }
        if ("".equals(info.getXxly())) {
            veinfo.setXxly(null);
        } else {
            veinfo.setXxly(info.getXxly());
        }
        if ("".equals(info.getGlzt())) {
            veinfo.setGlzt(null);
        } else {
            veinfo.setGlzt(info.getGlzt());
        }
        if ("".equals(info.getYqkgxbz())) {
            veinfo.setYqkgxbz(null);
        } else {
            veinfo.setYqkgxbz(info.getYqkgxbz());
        }
        veinfo.setSourceSystem("0");
        Map<String, Object> map = new HashMap<>(2);
        map.put("vehicleSaleInvoice", vehicleSaleInvoice);
        map.put("veinfo", veinfo);
        return map;
    }

    public static InvoiceCheckVehicleDetailModel getVehicleDetaiModel(TDxVehicleSaleInvoice tDxVehicleSaleInvoice) {
        // Auto-generated method stub
        InvoiceCheckVehicleDetailModel model = new InvoiceCheckVehicleDetailModel();
        model.setBuyerBank(tDxVehicleSaleInvoice.getBuyerBank());
        model.setBuyerIdNum(tDxVehicleSaleInvoice.getBuyerIdNum());
        model.setCertificate(tDxVehicleSaleInvoice.getCertificate());
        model.setCertificateImport(tDxVehicleSaleInvoice.getCertificateImport());
        model.setCheckStatus(tDxVehicleSaleInvoice.getCheckStatus());
        model.setEngineNo(tDxVehicleSaleInvoice.getEngineNo());
        model.setFactoryModel(tDxVehicleSaleInvoice.getFactoryModel());
        model.setInspectionNum(tDxVehicleSaleInvoice.getInspectionNum());
        model.setLimitPeople(tDxVehicleSaleInvoice.getLimitPeople());
        model.setPhone(tDxVehicleSaleInvoice.getPhone());
        model.setProductPlace(tDxVehicleSaleInvoice.getProductPlace());
        model.setTaxBureauCode(tDxVehicleSaleInvoice.getTaxBureauCode());
        model.setTaxBureauName(tDxVehicleSaleInvoice.getTaxBureauName());
        model.setTaxRate(tDxVehicleSaleInvoice.getTaxRate());
        model.setTaxRecords(tDxVehicleSaleInvoice.getTaxRecords());
        model.setTonnage(tDxVehicleSaleInvoice.getTonnage());
        model.setUuid(tDxVehicleSaleInvoice.getUuid());
        model.setVehicleNo(tDxVehicleSaleInvoice.getVehicleNo());
        model.setVehicleType(tDxVehicleSaleInvoice.getVehicleType());
        model.setCreateDate(new Date());
        model.setPlateNo(tDxVehicleSaleInvoice.getPlateNo());
        model.setRegistrationNo(tDxVehicleSaleInvoice.getRegistrationNo());
        model.setVehicleAdminOffice(tDxVehicleSaleInvoice.getVehicleAdminOffice());
        model.setAuctionUnit(tDxVehicleSaleInvoice.getAuctionUnit());
        model.setAuctionAddress(tDxVehicleSaleInvoice.getAuctionAddress());
        model.setAuctionTaxNo(tDxVehicleSaleInvoice.getAuctionTaxNo());
        model.setAuctionBank(tDxVehicleSaleInvoice.getAuctionBank());
        model.setAuctionPhone(tDxVehicleSaleInvoice.getAuctionPhone());
        model.setCarMarket(tDxVehicleSaleInvoice.getCarMarket());
        model.setCarMarketTaxNo(tDxVehicleSaleInvoice.getCarMarketTaxNo());
        model.setCarMarketAddress(tDxVehicleSaleInvoice.getCarMarketAddress());
        model.setCarMarketBank(tDxVehicleSaleInvoice.getCarMarketBank());
        model.setCarMarketPhone(tDxVehicleSaleInvoice.getCarMarketPhone());
        return model;
    }

    public static InvoiceCheckVehicleDetailSalesModel
        getVehicleDetaiSalesModel(TDxVehicleSaleInvoice tDxVehicleSaleInvoice) {
        // Auto-generated method stub
        InvoiceCheckVehicleDetailSalesModel model = new InvoiceCheckVehicleDetailSalesModel();
        model.setBuyerBank(tDxVehicleSaleInvoice.getBuyerBank());
        model.setBuyerIdNum(tDxVehicleSaleInvoice.getBuyerIdNum());
        model.setCertificate(tDxVehicleSaleInvoice.getCertificate());
        model.setCertificateImport(tDxVehicleSaleInvoice.getCertificateImport());
        model.setCheckStatus(tDxVehicleSaleInvoice.getCheckStatus());
        model.setEngineNo(tDxVehicleSaleInvoice.getEngineNo());
        model.setFactoryModel(tDxVehicleSaleInvoice.getFactoryModel());
        model.setInspectionNum(tDxVehicleSaleInvoice.getInspectionNum());
        model.setLimitPeople(tDxVehicleSaleInvoice.getLimitPeople());
        model.setPhone(tDxVehicleSaleInvoice.getPhone());
        model.setProductPlace(tDxVehicleSaleInvoice.getProductPlace());
        model.setTaxBureauCode(tDxVehicleSaleInvoice.getTaxBureauCode());
        model.setTaxBureauName(tDxVehicleSaleInvoice.getTaxBureauName());
        model.setTaxRate(tDxVehicleSaleInvoice.getTaxRate());
        model.setTaxRecords(tDxVehicleSaleInvoice.getTaxRecords());
        model.setTonnage(tDxVehicleSaleInvoice.getTonnage());
        model.setUuid(tDxVehicleSaleInvoice.getUuid());
        model.setVehicleNo(tDxVehicleSaleInvoice.getVehicleNo());
        model.setVehicleType(tDxVehicleSaleInvoice.getVehicleType());
        model.setCreateDate(new Date());
        model.setPlateNo(tDxVehicleSaleInvoice.getPlateNo());
        model.setRegistrationNo(tDxVehicleSaleInvoice.getRegistrationNo());
        model.setVehicleAdminOffice(tDxVehicleSaleInvoice.getVehicleAdminOffice());
        model.setAuctionUnit(tDxVehicleSaleInvoice.getAuctionUnit());
        model.setAuctionAddress(tDxVehicleSaleInvoice.getAuctionAddress());
        model.setAuctionTaxNo(tDxVehicleSaleInvoice.getAuctionTaxNo());
        model.setAuctionBank(tDxVehicleSaleInvoice.getAuctionBank());
        model.setAuctionPhone(tDxVehicleSaleInvoice.getAuctionPhone());
        model.setCarMarket(tDxVehicleSaleInvoice.getCarMarket());
        model.setCarMarketTaxNo(tDxVehicleSaleInvoice.getCarMarketTaxNo());
        model.setCarMarketAddress(tDxVehicleSaleInvoice.getCarMarketAddress());
        model.setCarMarketBank(tDxVehicleSaleInvoice.getCarMarketBank());
        model.setCarMarketPhone(tDxVehicleSaleInvoice.getCarMarketPhone());
        return model;
    }

    /**
    * @Description 构建铁路信息主信息
    * @Author wangruwei
     * @param info 大企业返回的数据结构
    * @Date 2024/4/10 14:16
    **/
    public static TDxRecordInvoice getTlkpInvoiceInfo(InvoiceTlkpInfo info, String tdly) {
        TDxRecordInvoice invoice = new TDxRecordInvoice();
        // 发票代码
        invoice.setInvoiceCode(info.getInvoiceCode());
        // 发票号码
        invoice.setInvoiceNo(info.getInvoiceNo());
        //发票UUID
        invoice.setUuid(info.getInvoiceCode()+info.getInvoiceNo());
        // 全电发票号码
        if(StringUtils.isNotBlank(info.getElectronicInvoiceNo())){
            invoice.setEleInvoiceNo(info.getElectronicInvoiceNo());
        }
        //细分发票类型
        invoice.setLqTdyslxDm(info.getDetailType());
        //附件
        invoice.setFileList(info.getFileList());

        // 发票类型
        invoice.setInvoiceType(info.getInvoiceType());
        // 购方名称
        invoice.setGfName(info.getBuyerName());
        // 购方税号
        invoice.setGfTaxNo(info.getBuyerTaxNo());
        // 购方地址、电话
        invoice.setGfAddressAndPhone(info.getBuyerAddressPhone());
        // 购方开户行及账号
        invoice.setGfBankAndNo(info.getBuyerAcount());
        // 销方名称
        invoice.setXfName(info.getSalerName());
        // 销方税号
        invoice.setXfTaxNo(info.getSalerTaxNo());
        // 销方地址、电话
        invoice.setXfAddressAndPhone(info.getSalerAddressPhone());
        // 销方开户行及账号
        invoice.setXfBankAndNo(info.getSalerAcount());
        // 开票日期
        invoice.setInvoiceDate(CommonUtil.dateConvert(info.getInvoiceDate()));
        // 发票金额
        invoice.setInvoiceAmount(new BigDecimal(info.getInvoiceAmount()));
        // 发票税额
        invoice.setTaxAmount(new BigDecimal(info.getTaxAmount()));
        //抵扣税额
        if(ObjectUtil.isNotEmpty(info.getTaxAmount())){
            invoice.setDkTaxAmount(new BigDecimal(info.getTaxAmount()));
        }
        // 价税合计
        invoice.setTotalAmount(new BigDecimal(info.getTotalAmount()));
        // 备注
        invoice.setRemark(info.getRemark());
        // 发票状态
        invoice.setInvoiceStatus(info.getInvoiceStatus());
        //设置红字锁定标识
        if(FpztEnum.HZDQR.getFpztDm().equals(info.getInvoiceStatus())){
            invoice.setLqHzsdbs("Y");
        }

        invoice.setSourceSystem("0");
        invoice.setValid("1");
        invoice.setTdly(tdly);
        if(StringUtils.isNotBlank(info.getGlzt())){
            invoice.setGlzt(info.getGlzt());
        }

        //明细赋值
        invoice.setDetailList(info.getDetailList());
        return invoice;
    }

    /**
    * @Description 航空票构建
    * @param info 大企业返回的json对应实体
    * @param tdly
    * @Return com.dxhy.api.model.invoice.TDxRecordInvoice
    * @Author wangruwei
    * @Date 2024/4/10 15:50
    **/
    public static TDxRecordInvoice getHkysKpInvoiceInfo(InvoiceMhxcdInfo info, String tdly) {
        TDxRecordInvoice invoice = new TDxRecordInvoice();
        // 发票代码
        invoice.setInvoiceCode(info.getInvoiceCode());
        // 发票号码
        invoice.setInvoiceNo(info.getInvoiceNo());
        //发票UUID
        invoice.setUuid(info.getInvoiceCode()+info.getInvoiceNo());
        // 全电发票号码
        if(StringUtils.isNotBlank(info.getElectronicInvoiceNo())){
            invoice.setEleInvoiceNo(info.getElectronicInvoiceNo());
        }
        //细分发票类型
        invoice.setLqTdyslxDm(info.getDetailType());
        //附件
        invoice.setFileList(info.getFileList());

        //主信息扩展字段处理-明航行程单
        TDxRecordInvoiceTdysMhxcd mhxcd = new TDxRecordInvoiceTdysMhxcd();
        mhxcd.setDeductibleAmount(info.getDeductibleAmount());
        mhxcd.setInsuranceFee(info.getInsuranceFee());
        mhxcd.setAviationDevelopmentFund(info.getAviationDevelopmentFund());
        mhxcd.setOtherTaxes(info.getOtherTaxes());
        mhxcd.setPrompt(info.getPrompt());
        mhxcd.setOutletCode(info.getOutletCode());
        mhxcd.setVerificationCode(info.getVerificationCode());
        mhxcd.setVatRate(info.getVatRate());
        mhxcd.setEndorsement(info.getEndorsement());
        mhxcd.setTicketPrice(info.getTicketPrice());
        mhxcd.setTicketIssuanceStatus(info.getTicketIssuanceStatus());
        mhxcd.setFuelSurcharge(info.getFuelSurcharge());
        mhxcd.setIssuingEntity(info.getIssuingEntity());
        mhxcd.setIssuingDate(info.getIssuingDate());
        mhxcd.setValueAddedTaxAmount(info.getValueAddedTaxAmount());
        invoice.setTdysMhxcd(mhxcd);

        //主信息扩展字段处理-明航行程单明细
        List<InvoiceMhxcdInfoItem> detailList = info.getDetailList();
        if(!CollectionUtils.isEmpty(detailList)){
            List<TDxRecordInvoiceTdysMhxcdItem> list = new LinkedList();
            for (int i = 0; i < detailList.size(); i++) {
                InvoiceMhxcdInfoItem invoiceMhxcdInfoItem = detailList.get(i);
                TDxRecordInvoiceTdysMhxcdItem addItem = new TDxRecordInvoiceTdysMhxcdItem();
                addItem.setDetailNo(invoiceMhxcdInfoItem.getDetailNo());
                addItem.setCertificateNo(invoiceMhxcdInfoItem.getCertificateNo());
                addItem.setEleTicketNo(invoiceMhxcdInfoItem.getEleTicketNo());
                addItem.setFullName(invoiceMhxcdInfoItem.getFullName());
                addItem.setGp(invoiceMhxcdInfoItem.getGp());
                addItem.setInternationalLogo(invoiceMhxcdInfoItem.getInternationalLogo());
                addItem.setCarrier(invoiceMhxcdInfoItem.getCarrier());
                addItem.setCarrierDate(invoiceMhxcdInfoItem.getCarrierDate());
                addItem.setDepartureStation(invoiceMhxcdInfoItem.getDepartureStation());
                addItem.setDepartureTime(invoiceMhxcdInfoItem.getDepartureTime());
                addItem.setDestination(invoiceMhxcdInfoItem.getDestination());
                addItem.setFlightNo(invoiceMhxcdInfoItem.getFlightNo());
                addItem.setLeg(invoiceMhxcdInfoItem.getLeg());
                addItem.setSeatClass(invoiceMhxcdInfoItem.getSeatClass());
                addItem.setTicketType(invoiceMhxcdInfoItem.getTicketType());
                addItem.setBaggageWeight(invoiceMhxcdInfoItem.getBaggageWeight());
                addItem.setExpiryDate(invoiceMhxcdInfoItem.getExpiryDate());
                addItem.setTicketEffectiveDate(invoiceMhxcdInfoItem.getTicketEffectiveDate());
                list.add(addItem);
            }
            invoice.setTdysMhxcdDetailList(list);
        }

        // 发票类型
        invoice.setInvoiceType(info.getInvoiceType());
        // 购方名称
        invoice.setGfName(info.getBuyerName());
        // 购方税号
        invoice.setGfTaxNo(info.getBuyerTaxNo());
        // 购方地址、电话
        invoice.setGfAddressAndPhone(info.getBuyerAddressPhone());
        // 购方开户行及账号
        invoice.setGfBankAndNo(info.getBuyerAcount());
        // 销方名称
        invoice.setXfName(info.getSalerName());
        // 销方税号
        invoice.setXfTaxNo(info.getSalerTaxNo());
        // 销方地址、电话
        invoice.setXfAddressAndPhone(info.getSalerAddressPhone());
        // 销方开户行及账号
        invoice.setXfBankAndNo(info.getSalerAcount());
        // 开票日期
        invoice.setInvoiceDate(CommonUtil.dateConvert(info.getInvoiceDate()));
        // 发票金额
        invoice.setInvoiceAmount(new BigDecimal(info.getInvoiceAmount()));
        // 发票税额
        invoice.setTaxAmount(new BigDecimal(info.getTaxAmount()));
        if(ObjectUtil.isNotEmpty(info.getTaxAmount())){
            invoice.setDkTaxAmount(new BigDecimal(info.getTaxAmount()));
        }
        // 价税合计
        invoice.setTotalAmount(new BigDecimal(info.getTotalAmount()));
        // 备注
        invoice.setRemark(info.getRemark());
        // 发票状态
        invoice.setInvoiceStatus(info.getInvoiceStatus());
        //设置红字锁定标识
        if(FpztEnum.HZDQR.getFpztDm().equals(info.getInvoiceStatus())){
            invoice.setLqHzsdbs("Y");
        }

        invoice.setSourceSystem("0");
        invoice.setValid("1");
        invoice.setTdly(tdly);
        if(StringUtils.isNotBlank(info.getGlzt())){
            invoice.setGlzt(info.getGlzt());
        }
        return invoice;
    }
}
