package com.jianshui.invoice.service.impl.api;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.codec.Base64;
import cn.hutool.core.convert.Convert;
import cn.hutool.core.util.*;
import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpUtil;
import cn.hutool.json.JSON;
import cn.hutool.json.JSONUtil;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.jianshui.common.core.domain.AjaxResult;
import com.jianshui.common.core.domain.entity.Companyservice;
import com.jianshui.common.core.domain.entity.CompanyserviceDetail;
import com.jianshui.common.enums.ErrorCode;
import com.jianshui.common.exception.jianshui.JianshuiParamErrorException;
import com.jianshui.common.exception.jianshui.JianshuiServiceException;
import com.jianshui.common.utils.*;
import com.jianshui.common.utils.spring.SpringUtils;
import com.jianshui.common.utils.uuid.IdUtils;
import com.jianshui.framework.manager.AsyncManager;
import com.jianshui.invoice.constant.aisino.console.AisinoConsoleConstants;
import com.jianshui.invoice.domain.*;
import com.jianshui.invoice.domain.dto.*;
import com.jianshui.invoice.domain.dto.api.*;
import com.jianshui.invoice.domain.dto.api.aisino.console.*;
import com.jianshui.invoice.domain.dto.api.aisino.console.vehicle.TaxEquipmentInfo;
import com.jianshui.invoice.domain.dto.api.aisino.console.vehicle.VehicleInvoiceExpBo;
import com.jianshui.invoice.domain.ele.EleNewMessage;
import com.jianshui.invoice.domain.vo.RedinfoCopyAisinoVO;
import com.jianshui.invoice.domain.vo.RedinfodetailAisinoVO;
import com.jianshui.invoice.domain.vo.api.aisino.console.AisinoConsoleInvoiceAddVO;
import com.jianshui.invoice.domain.vo.api.aisino.console.DownloadJdcDetailItemVO;
import com.jianshui.invoice.domain.vo.api.aisino.console.DownloadJdcVO;
import com.jianshui.invoice.mapper.*;
import com.jianshui.invoice.service.IInvoiceApiService;
import com.jianshui.invoice.utils.BillInfoUtils;
import com.jianshui.invoice.utils.aisino.console.AisinoConsoleUtil;
import com.jianshui.system.domain.CompanyserviceProp;
import com.jianshui.system.service.ICompanyservicePropService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.io.IOUtils;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;


import javax.servlet.http.HttpServletRequest;
import java.io.*;
import java.math.BigDecimal;
import java.util.*;

/**
 * @author dxk
 * @date 2022年06月27日 11:18
 * 总部控制台-开票-重汽定制（订单号唯一、开票回调）
 */
@Component("aisinoZhongQi_console_invoice")
@Slf4j
public class AisinoConsoleInvoiceApiZhongQiServiceImpl implements IInvoiceApiService {

    @Autowired
    private BillInfoMapper billInfoMapper;
    @Autowired
    private InvoiceMapper invoiceMapper;

    @Autowired
    private SkDyjMapper skDyjMapper;

    @Autowired
    private RedinfoMapper redinfoMapper;

    @Autowired
    private InvoiceBackMapper invoiceBackMapper;

    static final String PREFIX = "stream2file";//前缀字符串定义文件名；必须至少三个字符
    static final String SUFFIX = ".tmp";//后缀字符串定义文件的扩展名；如果为null，则将使用后缀".tmp"


    /**
     * 1.发票开具 SID = 1
     *
     * @param billInfo
     * @param companyservice
     * @return com.jianshui.invoice.domain.dto.HXResponse
     * @author dxk
     * @date 2022/6/27 16:50
     */
    @Override
    public HXResponse addInvoice(BillInfo billInfo, Companyservice companyservice) throws IllegalAccessException, InstantiationException {


        // 1.订单唯一校验。新增历史订单部分（删除）。
        // 订单号唯一校验 start
        String outNO = billInfo.getOutTradeOrderno() != null ? billInfo.getOutTradeOrderno() : "";
        if (StrUtil.isEmpty(outNO)) {
            return new HXResponse("订单号为空，请检查报文！");
        }
        // update_by  0未删除 1已删除
        Invoice invoiceValidateTemp = new Invoice();
        List<Invoice> invoicesValidate = invoiceMapper.selectByOutTradeOrdernoList(companyservice.getCompanyid(), outNO, "0");

        // 开票回调失败防重复处理 start
        if (!CollectionUtils.isEmpty(invoicesValidate)) {
            for (Invoice invoice : invoicesValidate) {
                QueryWrapper<InvoiceBack> invoiceBackQueryWrapper = new QueryWrapper<>();
                invoiceBackQueryWrapper.eq("system_orderno", invoice.getOutTradeOrderno());
                InvoiceBack invoiceBackVali = invoiceBackMapper.selectOne(invoiceBackQueryWrapper);

                if (BeanUtil.isEmpty(invoiceBackVali)) {
                    invoiceBackVali = new InvoiceBack();
                    invoiceBackVali.setSystemOrderno(invoice.getOutTradeOrderno());
                    invoiceBackVali.setCreateTime(new Date());

                    invoiceBackVali.setId(IdUtils.randomUUID());
                    invoiceBackVali.setIdentity(companyservice.getIdentity());
                    invoiceBackVali.setBackUrl("");
                    invoiceBackVali.setStatus("0");
                    invoiceBackVali.setCreateTime(new Date());
                    invoiceBackVali.setSystemOrderno(invoice.getOutTradeOrderno());
                    invoiceBackVali.setBackMsg("");
                    invoiceBackVali.setResultCode("0000");
                    invoiceBackVali.setResultMsg("开票成功！");
                    invoiceBackVali.setUpdateTime(new Date());
                    invoiceBackMapper.insertInvoiceBack(invoiceBackVali);

                } else {
                    invoiceBackVali.setResultCode("0000");
                    invoiceBackVali.setResultMsg("开票成功！");
                    invoiceBackVali.setStatus("0");
                    invoiceBackVali.setUpdateTime(new Date());
                    invoiceBackMapper.updateInvoiceBack(invoiceBackVali);
                }

                // 再次推送
                try {
                    callBackAisino(invoiceBackVali, "", companyservice.getIdentity(), invoice.getId());
                } catch (Exception e) {
                    log.info("【重汽批量开票】发票回调失败！invoiceId={}", invoice.getId());
                }
            }
            return new HXResponse("0000", "重复订单已推送！");
        }
        // end

        // 2.预处理：处理billinfo，计算税额等
        try {
            billInfo = BillInfoUtils.processBillInfo(billInfo, companyservice);
        } catch (JianshuiParamErrorException e) {
            return new HXResponse(e.getMessage());
        } catch (Exception e) {
            log.error("【销项】【总部控制台发票】开票接口校验异常", e);
            return new HXResponse("格式校验失败，请检查报文！");
        }

        // 发票类型处理 必填
        Integer invoceTypeTemp = CovertInvoiceType(billInfo.getInvoiceType());
        if (invoceTypeTemp == -1) {
            return new HXResponse("发票类型不存在！");
        }

        billInfo.setInvoiceType(String.valueOf(invoceTypeTemp));

        // 转换报文为总部控制台请求报文
        AisinoConsoleInvoiceAddDTO aisinoConsoleInvoiceAddDTO = BeanUtil.copyProperties(billInfo, AisinoConsoleInvoiceAddDTO.class);

        List<BillDetail> billDetailList = billInfo.getBillDetailList();
        if (CollectionUtils.isEmpty(billDetailList)) {
            return new HXResponse("发票明细不存在，请检查报文！");
        }

        aisinoConsoleInvoiceAddDTO.setInvoiceType(invoceTypeTemp);

        //购方地址电话
        String buyerAddress = billInfo.getBuyerAddress() != null ? billInfo.getBuyerAddress() : "";
        String buyerTelPhone = billInfo.getBuyerTelephone() != null ? billInfo.getBuyerTelephone() : "";
        aisinoConsoleInvoiceAddDTO.setCustomerAddressTel(buyerAddress + buyerTelPhone);

        //购方银行账户
        String buyerBank = billInfo.getBuyerBank() != null ? billInfo.getBuyerBank() : "";
        String buyerAccount = billInfo.getBuyerAccount() != null ? billInfo.getBuyerAccount() : "";
        aisinoConsoleInvoiceAddDTO.setCustomerBankAccountNr(buyerBank + buyerAccount);

        //销方银行账户
        String sellerBank = billInfo.getSellerBank();
        String sellerAccount = billInfo.getSellerAccount();
        if (StrUtil.isEmpty(sellerBank) || StrUtil.isEmpty(sellerAccount)) {
            return new HXResponse("销方银行账户不存在！");
        }
        aisinoConsoleInvoiceAddDTO.setSellerBankAccountNr(sellerBank + sellerAccount);

        // 销方地址电话
        // 2022/12/21 中举说浪潮的地址和电话都放到 sellerAddress字段里了
        /*String sellerAddress = billInfo.getSellerAddress();
        String sellerTelephone = billInfo.getSellerTelephone();
        if (StrUtil.isEmpty(sellerAddress) || StrUtil.isEmpty(sellerTelephone)) {
            return new HXResponse("销方地址电话不存在！");
        }
        aisinoConsoleInvoiceAddDTO.setSellerAddressTel(sellerAddress + sellerTelephone);*/
        String sellerAddress = billInfo.getSellerAddress();
        if (StrUtil.isEmpty(sellerAddress)) {
            return new HXResponse("销方地址电话不存在！");
        }
        aisinoConsoleInvoiceAddDTO.setSellerAddressTel(sellerAddress);

        //清单标志
        String qdbz = billInfo.getQdbz();
        if (StrUtil.isEmpty(qdbz)) {
            return new HXResponse("清单标志不存在！");
        }
        boolean qdbzTemp = qdbz.equals("1") ? true : false;
        aisinoConsoleInvoiceAddDTO.setListed(qdbzTemp);

        // 销售单号 非必填
        //aisinoConsoleInvoiceAddDTO.setDocumentNr("");
        // 开票校验标识 问了下主任这里默认塞 0 标识开票
        aisinoConsoleInvoiceAddDTO.setCheckEWM(0);

        //税额
        BigDecimal tax = billInfo.getTax();
        aisinoConsoleInvoiceAddDTO.setTax(Convert.toDouble(tax));

        //数量 非必填
        //aisinoConsoleInvoiceAddDTO.setQuantity(0.0D);

        //专票必填
        if (invoceTypeTemp == 0) {
            if (StrUtil.isEmpty(aisinoConsoleInvoiceAddDTO.getCustomerTaxNr())) {
                return new HXResponse("购方税号不存在，专票！");
            }
            if (StrUtil.isEmpty(aisinoConsoleInvoiceAddDTO.getCustomerAddressTel())) {
                return new HXResponse("购方地址电话不存在，专票！");
            }
            if (StrUtil.isEmpty(aisinoConsoleInvoiceAddDTO.getCustomerBankAccountNr())) {
                return new HXResponse("购方银行账户不存在，专票！");
            }
        }

        //处理备注
        String kpType = billInfo.getKptype() == null ? "" : billInfo.getKptype();
        String redInvoiceCode = billInfo.getRedInvoiceInfoCode() == null ? "" : billInfo.getRedInvoiceInfoCode();
        if ("2".equals(kpType) && invoceTypeTemp == 0) {
            //专票：红字信息表编号 开具红字发票：备注中注明“开具红字增值税专用发票信息表编号 XXXXXXXXXXXXXXXX”
            aisinoConsoleInvoiceAddDTO.setMemo("开具红字增值税专用发票信息表编号" + redInvoiceCode);
        } else if ("2".equals(kpType) && invoceTypeTemp == 2) {
            //普票：开具负数发票（普通发票负数发票）：备注中注明“对应正数发票代码 XXXXXXXXXX 号 码 YYYYYYYY”字样，其中“X”为发票左上角 10 或是 12 位代码数字，“Y”为发票右上角 8位号码数字
            aisinoConsoleInvoiceAddDTO.setMemo("对应正数发票代码" + billInfo.getOriginFpdm() + "号码" + billInfo.getOriginFphm());
        }

        //明细处理前条件校验
        try {
            ValidateUtils.validate(aisinoConsoleInvoiceAddDTO, companyservice, null);
        } catch (RuntimeException e) {
            return new HXResponse("订单必填字段校验失败！{}", e.getMessage() != null ? e.getMessage().substring(0, 100) : "");
        }

        //发票明细处理
        List<AisinoConsoleInvoiceAddDetailDTO> invoiceItems = new ArrayList<>();
        List<Map<String, Object>> listMap = new ArrayList<>();
        for (BillDetail billDetail : billDetailList) {
            AisinoConsoleInvoiceAddDetailDTO addDetailDTO = BeanUtil.copyProperties(billDetail, AisinoConsoleInvoiceAddDetailDTO.class);
            //通过含税标志，区分含税单价不含税单价
            Integer hsbz = billDetail.getHsbz();
            if (hsbz == null) {
                return new HXResponse("含税标志不存在！");
            }
            addDetailDTO.setIncludeTax(hsbz == 1 ? true : false);
            //税率
            addDetailDTO.setTaxRate(Convert.toDouble(billDetail.getTaxrate()));
            //金额
            Double je = 0D;
            if (hsbz == 1) {
                je = Convert.toDouble(billDetail.getTaxamt());
            } else if (hsbz == 0) {
                je = Convert.toDouble(billDetail.getTaxfreeamt());
            } else {
                return new HXResponse("金额不存在！");
            }
            addDetailDTO.setValue(je);
            //单价
            addDetailDTO.setPrice(Convert.toDouble(billDetail.getPrice()));

            //是否享受优惠政策
            Integer yhzcbs = billDetail.getYhzcbs();
            if (yhzcbs == null) {
                return new HXResponse("优惠政策标识不存在！");
            } else if (yhzcbs == 1) {
                //享受优惠政策内容
                String zzstsgl = billDetail.getZzstsgl();
                if (StrUtil.isEmpty(zzstsgl)) {
                    return new HXResponse("优惠政策内容未填写！");
                }
                addDetailDTO.setTaxPreCon(billDetail.getZzstsgl());
            }
            addDetailDTO.setTaxPre(String.valueOf(yhzcbs));
            //企业自编码 非必填
            //addDetailDTO.setCropGoodsNo("");

            ValidateUtils.validate(addDetailDTO, companyservice, null);
            invoiceItems.add(addDetailDTO);
            Map<String, Object> mapDetail = BeanToMapUtils.fastJsonBean2Map(addDetailDTO);
            listMap.add(mapDetail);
        }
        aisinoConsoleInvoiceAddDTO.setInvoiceItems(invoiceItems);

        // 发起请求
        AjaxResult ajaxResult = null;
        try {
            // 控制台文档给的不对，反了
            String jdcbz = aisinoConsoleInvoiceAddDTO.getJDCBZ() != null ? aisinoConsoleInvoiceAddDTO.getJDCBZ() : "";
            log.info("机动车标志：{}", jdcbz);
            if ("1".equals(jdcbz)) {
                aisinoConsoleInvoiceAddDTO.setJDCBZ("2");
            } else if ("2".equals(jdcbz)) {
                aisinoConsoleInvoiceAddDTO.setJDCBZ("1");
            } else {
                aisinoConsoleInvoiceAddDTO.setJDCBZ("0");
            }

            //hutool的beancopy别名会与JSONUTIl冲突
            Map<String, Object> map = BeanToMapUtils.fastJsonBean2Map(aisinoConsoleInvoiceAddDTO);
            map.put("invoiceItems", listMap);
            ajaxResult = AisinoConsoleUtil.sendRequest(AisinoConsoleConstants.INVOICE_ADD, JSONUtil.parse(map), companyservice);
        } catch (Exception e) {
            log.error("【销项发票】【总部控制台接口】【发票开具】发票请求异常，请求报文{}，销方信息{}，错误信息{}"
                    , JSONUtil.parse(aisinoConsoleInvoiceAddDTO).toString(), JSONObject.toJSONString(companyservice),e.toString() );
//            throw new JianshuiServiceException("系统异常！");
            return new HXResponse("系统异常!");
        }
        log.info("【销项发票】【总部控制台发票】发票开具请求拉取结果{}", ajaxResult.toString());

        //返回报文解析
        if (ajaxResult.isError()) {
            return new HXResponse(ajaxResult.getMsg());
        }

        cn.hutool.json.JSONObject resultJSON = JSONUtil.parseObj(ajaxResult.get("data"));
        String retcode = resultJSON.get("retcode") != null ? resultJSON.get("retcode").toString() : "";
        String retmsg = resultJSON.get("retmsg") != null ? resultJSON.get("retmsg").toString() : "";
        if ("4011".equals(retcode)) {
            //回写发票代码、发票号码信息
            if (StrUtil.isEmpty(retmsg)) {
                return new HXResponse(retcode);
            }
            AisinoConsoleInvoiceAddVO aisinoConsoleInvoiceAddVO = BeanUtil.copyProperties(resultJSON, AisinoConsoleInvoiceAddVO.class);
            if (StrUtil.isEmpty(aisinoConsoleInvoiceAddVO.getInfoNumber())) {
                return new HXResponse("开具的发票号码不存在！");
            }
            //更新发票状态
            billInfo.setState(2);
            billInfoMapper.updateBillInfo(billInfo);

            //插入invoice
            Invoice invoice = BeanUtil.copyProperties(billInfo, Invoice.class);
            List<InvoiceDetail> invoiceDetailList = BeanUtil.copyToList(billInfo.getBillDetailList(), InvoiceDetail.class);
            invoice.setInvoiceDetailList(invoiceDetailList);

            //发票代码
            invoice.setFpdm(aisinoConsoleInvoiceAddVO.getInfoTypeCode());
            //发票号码
            invoice.setFphm(aisinoConsoleInvoiceAddVO.getInfoNumber());
            //上一张发票代码
            invoice.setOriginFpdm(aisinoConsoleInvoiceAddVO.getHisInfoTypeCode());
            //上一张发票号码
            invoice.setOriginFphm(aisinoConsoleInvoiceAddVO.getHisInfoNumber());
            //发票种类
            String hisInvoceTypeTemp = CovertInvoiceTypeReverse(String.valueOf(aisinoConsoleInvoiceAddDTO.getInvoiceType()));
            invoice.setInvoiceType(hisInvoceTypeTemp);
            invoice.setBillInfoId(billInfo.getId());
            invoice.setKprq(aisinoConsoleInvoiceAddVO.getInfoDate());
            invoice.setTaxfreeamt(BigDecimal.valueOf(aisinoConsoleInvoiceAddVO.getInfoAmount()));
            invoice.setTax(BigDecimal.valueOf(aisinoConsoleInvoiceAddVO.getInfoTaxAmount()));

            // 开票结果处理
//            Integer state = invoice.getState();

            long id = 0L;
            QueryWrapper<Invoice> invoiceQueryWrapper = new QueryWrapper<>();
            invoiceQueryWrapper.eq("fpdm", invoice.getFpdm()).eq("fphm", invoice.getFphm());
            List<Invoice> invoices = invoiceMapper.selectList(invoiceQueryWrapper);
            if (CollectionUtils.isEmpty(invoices)) {
                invoice.setUpdateBy("0");
                invoiceMapper.insertInvoice(invoice);
                invoices = invoiceMapper.selectList(invoiceQueryWrapper);
                id = invoices.get(0).getId();
            } else {
                Invoice invoiceT = invoices.get(0);
                invoiceT = BeanUtil.copyProperties(invoice, Invoice.class);
                invoiceT.setUpdateBy("0");
                invoiceMapper.updateInvoice(invoiceT);
                id = invoiceT.getId();
            }
            invoiceDetailList.forEach(i -> i.setInvoiceId(invoice.getId()));
            invoiceMapper.batchInvoiceDetail(invoiceDetailList);


            // 增加主动回调方式，可配置
            ICompanyservicePropService companyserviceProp = SpringUtils.getBean(ICompanyservicePropService.class);
            CompanyserviceProp secretIdProp = companyserviceProp.selectPropByKey(companyservice.getCompanyid(), "aisino_callback_url");
            if (BeanUtil.isNotEmpty(secretIdProp) && secretIdProp.getValue() != null && !"".equals(secretIdProp.getValue())) {

                String callBackUrl = secretIdProp.getValue();

                InvoiceBack queryInvoiceBack = new InvoiceBack();
                queryInvoiceBack.setSystemOrderno(billInfo.getOutTradeOrderno());
                List<InvoiceBack> invoiceBackList = invoiceBackMapper.selectInvoiceBackList(queryInvoiceBack);
                if (CollectionUtils.isEmpty(invoiceBackList)) {
                    queryInvoiceBack.setId(IdUtils.randomUUID());
                    queryInvoiceBack.setIdentity(companyservice.getIdentity());
                    queryInvoiceBack.setBackUrl(callBackUrl);
                    queryInvoiceBack.setStatus("0");
                    queryInvoiceBack.setCreateTime(new Date());
                    queryInvoiceBack.setSystemOrderno(billInfo.getOutTradeOrderno());
                    queryInvoiceBack.setBackMsg("");
                    queryInvoiceBack.setResultCode("0000");
                    queryInvoiceBack.setResultMsg("开票成功！");
                    queryInvoiceBack.setUpdateTime(new Date());
                    invoiceBackMapper.insertInvoiceBack(queryInvoiceBack);
                } else {
                    queryInvoiceBack = invoiceBackList.get(0);
                    queryInvoiceBack.setResultCode("0000");
                    queryInvoiceBack.setResultMsg("开票成功！");
                    queryInvoiceBack.setUpdateTime(new Date());
                }

                // 回调，失败的交给定时任务
                InvoiceBack finalQueryInvoiceBack = queryInvoiceBack;
                try {
                    callBackAisino(finalQueryInvoiceBack, callBackUrl, "", invoice.getId());
                } catch (Exception e) {
                    log.info("【重汽批量开票】发票回调失败！invoiceId={}", invoice.getId());
                }
            }

            HXResponse response = new HXResponse("0000", "同步成功");
            response.put("fpqqlsh", billInfo.getSystemOrderno());
            return response;
        } else {
            return new HXResponse(retmsg);
        }
    }


    /**
     * 开票接口回调-重汽
     * 2023-09-26
     *
     * @param callBackUrl
     * @param id
     */
    @Override
    public void callBackAisino(InvoiceBack invoiceBack, String callBackUrl, String identity, Long id) {

        // TODO: 2023/10/27  回调处理

        if (id == null) {
            log.info("【控制台】发票回调，id为空");
            return;
        }

        // 回调地址获取
        if (StrUtil.isEmpty(callBackUrl)) {
            ICompanyservicePropService companyserviceProp = SpringUtils.getBean(ICompanyservicePropService.class);
            CompanyserviceProp secretIdProp = companyserviceProp.selectPropByKey(Long.valueOf(identity), "aisino_callback_url");
            if (BeanUtil.isNotEmpty(secretIdProp) && secretIdProp.getValue() != null && !"".equals(secretIdProp.getValue())) {
                callBackUrl = secretIdProp.getValue();
            }
        }

        Invoice invoice = invoiceMapper.selectInvoiceById(id);
        if (invoice == null) {
            log.info("【控制台】发票信息未查询到，id={}", id);
            invoice = new Invoice();
            invoice.setOutTradeOrderno(invoiceBack.getSystemOrderno());
            invoice.setState(22);
            String resultMsg = invoiceBack.getResultMsg();
            String message = (resultMsg != null && resultMsg.length() > 200) ? resultMsg.substring(0, 200) : resultMsg;
            invoice.setMessage(message);
        }

        try {
            /*cn.hutool.json.JSONObject jsonResult = new cn.hutool.json.JSONObject();
            jsonResult.set("status", invoiceBack.getResultCode());
            jsonResult.set("message", invoiceBack.getResultMsg());
            jsonResult.set("data", invoice);*/

            log.info("【控制台】发票回调接口，发送数据开始，id={}，callBackUrl={}，param={}", id, callBackUrl, JSONUtil.toJsonStr(invoice));
            String result = HttpUtil.post(callBackUrl, JSONUtil.toJsonStr(invoice));
            log.info("【控制台】发票回调接口，发送数据结束，id={},接口返回信息={}", id, result);

            cn.hutool.json.JSONObject jsonObject = JSONUtil.parseObj(result);
            if (jsonObject != null) {
                String status = jsonObject.get("status") != null ? jsonObject.get("status").toString() : "";
                String message = jsonObject.get("message") != null ? jsonObject.get("message").toString() : "";

                if ("0000".equals(status)) {
                    invoiceBack.setStatus("1");
                    invoiceBack.setBackMsg(message != null ? message.substring(0, Math.min(message.length(), 200)) : "");
                    invoiceBack.setUpdateTime(new Date());
                    invoiceBackMapper.updateInvoiceBack(invoiceBack);
                } else if ("9999".equals(status)) {
                    invoiceBack.setStatus("3");
                    invoiceBack.setBackMsg(message != null ? message.substring(0, Math.min(message.length(), 200)) : "");
                    invoiceBack.setUpdateTime(new Date());
                    invoiceBackMapper.updateInvoiceBack(invoiceBack);
                } else {
                    invoiceBack.setStatus("2");
                    invoiceBack.setUpdateTime(new Date());
                    invoiceBack.setBackMsg(status + message != null ? message.substring(0, Math.min(message.length(), 200)) : "");
                    invoiceBackMapper.updateInvoiceBack(invoiceBack);
                }
            }
        } catch (Exception e) {
            log.info("【控制台】发票回调接口，发送数据异常，id={},e={}", id,e);
            invoiceBack.setStatus("2");
            invoiceBack.setBackMsg("发送数据异常！");
            invoiceBackMapper.updateInvoiceBack(invoiceBack);
        }

    }



    @Override
    public HXResponse mailDelivery(InvoiceMailDeliveryDTO mailDeliveryDTO, Companyservice companyservice) {
        return null;
    }


    /**
     * 发票打印
     *
     * @param invoice
     * @param companyservice
     * @return com.jianshui.common.core.domain.AjaxResult
     * @author dxk
     * @date 2022/6/29 13:48
     */
    @Override
    public AjaxResult printInvoice(Invoice invoice, Companyservice companyservice) {
        return null;
    }


    /**
     * 发票作废
     *
     * @param invoice
     * @param companyservice
     * @return com.jianshui.invoice.domain.dto.HXResponse
     * @author dxk
     * @date 2022/6/30 9:43
     */
    @Override
    public HXResponse deprecateInvoice(JSONObject invoice, Companyservice companyservice) {

        // kk: 2023/2/7  改为通用查询，流水号或发票代码发票号码
        // 查找原来的发票
        String fpqqlsh = invoice.getString("fpqqlsh");
        String fpdm = invoice.getString("fpdm");
        String fphm = invoice.getString("fphm");

        // 发票查询
        Invoice invoiceTemp = null;
        if (StringUtils.isNotEmpty(fpqqlsh)) {
            invoiceTemp = invoiceMapper.selectBySystemOrderNo(companyservice.getCompanyid(), fpqqlsh);
        } else if (StringUtils.isNotEmpty(fpdm) && StringUtils.isNotEmpty(fphm)) {
            invoiceTemp = invoiceMapper.selectByFpdmFphm(companyservice.getCompanyid(), fpdm, fphm);
        } else {
            throw new JianshuiParamErrorException(ErrorCode.EMPTY_FPQQLSH, companyservice, "invoice");
        }

        //发票不存在
        if (invoiceTemp == null) {
            throw new JianshuiParamErrorException(ErrorCode.INVOICE_NOT_EXISTS, companyservice, "invoice");
        }

        AisinoConsoleInvolidDTO consoleInvolidDTO = BeanUtil.copyProperties(invoiceTemp, AisinoConsoleInvolidDTO.class);

        //发票类型
        Integer invoceTypeTemp = CovertInvoiceType(invoiceTemp.getInvoiceType());
        if (invoceTypeTemp == -1) {
            throw new JianshuiParamErrorException(ErrorCode.ERROR_INVOICELINE, companyservice, "invoice");
        }
        consoleInvolidDTO.setInfoKind(invoceTypeTemp);

        ValidateUtils.validate(consoleInvolidDTO, companyservice, null);

        //发起请求
        AjaxResult ajaxResult = null;
        try {
            Map<String, Object> map = BeanToMapUtils.fastJsonBean2Map(consoleInvolidDTO);
            ajaxResult = AisinoConsoleUtil.sendRequest(AisinoConsoleConstants.INVOICE_INVOLID, JSONUtil.parse(map), companyservice);
        } catch (Exception e) {
            log.error("【销项发票】【总部控制台接口】【发票作废】发票请求异常，请求报文{}，销方信息{}", JSONUtil.parse(consoleInvolidDTO).toString(), JSONObject.toJSONString(companyservice));
            e.printStackTrace();
            throw new JianshuiServiceException("系统异常！");
        }

        //返回报文解析
        if (ajaxResult.isError()) {
            throw new JianshuiServiceException(ajaxResult.getMsg());
        }

        cn.hutool.json.JSONObject resultJSON = JSONUtil.parseObj(ajaxResult.get("data"));
        String retcode = resultJSON.get("retcode") != null ? resultJSON.get("retcode").toString() : "";
        String retmsg = resultJSON.get("retmsg") != null ? resultJSON.get("retmsg").toString() : "";
        if ("6011".equals(retcode)) {
            // 修改原有发票状态为已作废
            invoiceTemp.setState(3);
            invoiceMapper.updateInvoice(invoiceTemp);

            // 更新原有订单
            BillInfo originBillInfo = billInfoMapper.selectBySystemOrderNo(companyservice.getCompanyid(), invoiceTemp.getSystemOrderno());
            if (originBillInfo == null) {
                log.error("【销项】【总部控制台】作废发票，无法查找到原有发票{}", JSONObject.toJSONString(invoiceTemp));
            } else {
                originBillInfo.setState(3);
                billInfoMapper.updateBillInfo(originBillInfo);
            }
            return new HXResponse("0000", "作废完成", null, false);
        } else {
            return new HXResponse(retmsg);
        }

    }


    @Override
    public AjaxResult reInvoice(BillInfo billInfo, Companyservice companyservice) {
        return null;
    }

    /**
     * 单个发票查询
     *
     * @param billInfo
     * @param companyservice
     * @return
     */
    @Override
    public HXResponse queryInvoice(QueryBillInfoDTO billInfo, Companyservice companyservice) {

        Invoice invoiceQuery = new Invoice();
        invoiceQuery.setCompanyId(billInfo.getCompanyId());
        if (StringUtils.isNotEmpty(billInfo.getFpqqlsh())) {
            invoiceQuery.setFpqqlsh(billInfo.getFpqqlsh());
        } else if (StringUtils.isNotEmpty(billInfo.getOutTradeOrderno())) {
            invoiceQuery.setSystemOrderno(billInfo.getSystemOrderno());
        } else {
            HXResponse response = new HXResponse("9997", "订单号或流水号不能同时为空");
            return response;
        }

        Invoice invoice = invoiceMapper.selectInvoiceAllIn(invoiceQuery);
        if (invoice == null) {
            Invoice tempInvoice = new Invoice();
            tempInvoice.setInvoiceMsg("发票信息不存在");
            if (billInfo.getSystemOrderno() != null) {
                tempInvoice.setSystemOrderno(billInfo.getSystemOrderno());
            }
            if (billInfo.getOutTradeOrderno() != null) {
                tempInvoice.setOutTradeOrderno(billInfo.getOutTradeOrderno());
            }
            if (billInfo.getFpqqlsh() != null) {
                tempInvoice.setFpqqlsh(billInfo.getFpqqlsh());
            }
            HXResponse response = new HXResponse("9998", "发票信息不存在", tempInvoice);
            return response;
        } else {

        }

        HXResponse response = new HXResponse("0000", "查询成功", invoice);
        return response;
    }

    /**
     * 发票批量查询
     *
     * @param billInfo
     * @param byWhat
     * @param companyservice
     * @return
     */
    @Override
    public HXResponse batchQueryInvoices(BillInfo billInfo, String byWhat, Companyservice companyservice) {

        String fpqqlsh = billInfo.getFpqqlsh();
        String orderNo = billInfo.getOutTradeOrderno();
        List<Object> result = new ArrayList<>();
        List<BillInfo> queryBillInfo = new ArrayList<>();
        if (StringUtils.equals("fpqqlsh", byWhat)) {
            JSONArray fpqqlshs = JSONArray.parseArray(fpqqlsh);
            if (fpqqlshs == null) {
                fpqqlshs = new JSONArray();
                fpqqlshs.add(fpqqlsh);
            }
            fpqqlshs.forEach(i -> {
                BillInfo tempBillInfo = new BillInfo();
                tempBillInfo.setCompanyId(companyservice.getCompanyid());
                tempBillInfo.setFpqqlsh((String) i);
                queryBillInfo.add(tempBillInfo);
            });
        }

        if (StringUtils.equals("orderno", byWhat)) {
            JSONArray fpqqlshs = JSONArray.parseArray(orderNo);
            if (fpqqlshs == null) {
                fpqqlshs = new JSONArray();
                fpqqlshs.add(orderNo);
            }
            fpqqlshs.forEach(i -> {
                BillInfo tempBillInfo = new BillInfo();
                tempBillInfo.setCompanyId(companyservice.getCompanyid());
                tempBillInfo.setOutTradeOrderno((String) i);
                queryBillInfo.add(tempBillInfo);
            });
        }

        queryBillInfo.forEach(i -> {
            QueryBillInfoDTO queryBillInfoDTO = new QueryBillInfoDTO();
            BeanUtils.copyProperties(i, queryBillInfoDTO);
            HXResponse tempResult = this.queryInvoice(queryBillInfoDTO, companyservice);
            result.add(tempResult.getData());
        });

        return new HXResponse("0000", "查询成功", result);
    }

    @Override
    public HXResponse scopeQueryInvoices(JSONObject queryJson, Companyservice companyservice) {
        return null;
    }

    @Override
    public HXResponse queryRedConfirmationList(JSONObject decryptResult, Companyservice companyservice) {
        return null;
    }

    @Override
    public HXResponse queryRedConfirmationItemList(JSONObject decryptResult, Companyservice companyservice) {
        return null;
    }

    @Override
    public HXResponse redConfirmationApply(JSONObject decryptResult, Companyservice companyservice) {
        return null;
    }

    @Override
    public HXResponse redConfirmationConfirm(JSONObject decryptResult, Companyservice companyservice) {
        return null;
    }

    @Override
    public HXResponse rpaLogin(JSONObject decryptResult, Companyservice companyservice) {
        return null;
    }


    @Override
    public HXResponse getRpaAuthStatus(JSONObject decryptResult, Companyservice companyservice) {
        return null;
    }

    @Override
    public HXResponse queryRpaTaxAccount(JSONObject decryptResult, Companyservice companyservice) {
        return null;
    }

    /**
     * 红字信息表上传
     */
    @Override
    public HXResponse uploadRedInfo(Redinfo redinfo, Companyservice companyservice) {

        // 前置处理
        redinfo.setCompanyId(companyservice.getCompanyid());
        redinfo.setSystemOrderno(IdUtils.randomSystemOrderno());
        if (StringUtils.isEmpty(redinfo.getOutTradeOrderno())) {
            // 把 outTradeOrderno作为用户的申请单号
            throw new JianshuiParamErrorException(ErrorCode.EMPTY_REDINFO_NO, companyservice, "invoice");
        }
        redinfo.setOutTradeOrderno(redinfo.getOutTradeOrderno());
        redinfo.setFpqqlsh(redinfo.getSystemOrderno());
        redinfo.setRedInfoStatus("0");
        redinfo.setSellerName(companyservice.getSellername());
        redinfo.setSellerTaxnum(companyservice.getSellertax());
        redinfo.setBillInputTime(TimeUtil.dateFormat(new Date(), "yyyyMMddHHmmss"));
        List<Redinfodetail> redinfodetailList = redinfo.getRedinfodetailList();
        BigDecimal taxfreeamt = new BigDecimal(0); // 不含税金额
        BigDecimal tax = new BigDecimal(0); // 税额
        for (Redinfodetail detail : redinfodetailList) {
            taxfreeamt = taxfreeamt.add(detail.getTaxfreeamt());
            tax = tax.add(detail.getTax());
        }
        redinfo.setTax(tax);
        redinfo.setTaxfreeamt(taxfreeamt);
        redinfo.setTaxamt(tax.add(taxfreeamt));
        redinfoMapper.insertRedinfo(redinfo);
        int index = 0;

        String spbm = "";

        for (Redinfodetail detail : redinfodetailList) {
            detail.setBillno(redinfo.getRedInfoNo());
            detail.setRedinfoId(redinfo.getId());
            detail.setIndex(++index);
            detail.setBillno(redinfo.getRedInfoNo());
            taxfreeamt = taxfreeamt.add(detail.getTaxfreeamt());
            tax = tax.add(detail.getTax());

            // 商品编码
            spbm = detail.getSpbm();
        }

        // TODO: 2023/3/9 设备号是 jspbh 并非billNO？  申请方税号reqnsrsbh
        //
        redinfo.setJspbh("661024643068230218103524".substring(0, 12));
        redinfo.setReqnsrsbh("9113093067851155XY");
        redinfo.setFjh("123");
        redinfo.setMultTaxRate("0");
        redinfo.setBillInputTime("2022-11-11");
        redinfo.setBmbbh("2323232");
        redinfo.setTaxrate(new BigDecimal("0.03"));
        //

        redinfoMapper.batchRedinfodetail(redinfodetailList);

        // 参数校验及参数处理
        AisinoConsoleInvoiceRedUploadDTO redUploadDTO = BeanUtil.copyProperties(redinfo, AisinoConsoleInvoiceRedUploadDTO.class);
        // 填开日期
        redUploadDTO.setDate(redinfo.getBillInputTime());
        // 信息表类型
        redUploadDTO.setBillType("0");
        // TODO-dxk: 2023/2/27 含税、不含税金额  含税标志，这里需要确定
        // 合计金额计算
        redUploadDTO.setAmount(String.valueOf(taxfreeamt));
        // 含税税率标识
        redUploadDTO.setSLBZ("0");
        // 税种类别
        redUploadDTO.setSzlb("1");
        ValidateUtils.validate(redUploadDTO);


        if (redinfo.getRedinfodetailList() == null || redinfo.getRedinfodetailList().size() == 0) {
            return new HXResponse("格式校验失败，请上传明细信息！");
        }


        String paramChild = "";
        List<AisinoConsoleInvoiceRedUploadChildDTO> redUploadChildDTO = BeanUtil.copyToList(redinfo.getRedinfodetailList(), AisinoConsoleInvoiceRedUploadChildDTO.class);
        for (AisinoConsoleInvoiceRedUploadChildDTO childDTO : redUploadChildDTO) {

            // TODO-dxk: 2023/2/27 含税、不含税金额
            childDTO.setHS_BZ(childDTO.getHS_BZ().equals("false") ? "N" : "Y");

            paramChild = "<GoodsMx>" + JSONUtil.toXmlStr(JSONUtil.parse(childDTO)) + " </GoodsMx>";

            ValidateUtils.validate(childDTO);
        }

        // 组装xml报文
        String param = JSONUtil.toXmlStr(JSONUtil.parse(redUploadDTO));

//        param = "<?xml version=\"1.0\" encoding=\"GBK\"?>\n" +
        param = "" +
                "<FPXT>\n" +
                "    <INPUT>\n" +
                "        <RedInvReqBill>" + param;

        param = param + "<RedInvReqBillMx>";

        param = param + paramChild;

        param = param + "            </RedInvReqBillMx>\n" +
                "        </RedInvReqBill>\n" +
                "    </INPUT>\n" +
                "</FPXT>";


        //发起请求
        AjaxResult ajaxResult = null;
        try {
            ajaxResult = AisinoConsoleUtil.sendRequestXML(AisinoConsoleConstants.RED_UPLOAD, "0200", param, companyservice);
        } catch (Exception e) {
            log.error("【销项发票】【总部控制台接口】【发票作废】发票请求异常，请求报文{}，销方信息{}", "", JSONObject.toJSONString(companyservice));
            e.printStackTrace();
            throw new JianshuiServiceException("系统异常！");
        }

        //返回报文解析
        if (ajaxResult.isError()) {
            throw new JianshuiServiceException(ajaxResult.getMsg());
        }

        // todo-k: 返回报文解析这里还带看下具体的返回形式

        cn.hutool.json.JSONObject resultJSON = JSONUtil.parseObj(ajaxResult.get("data"));
        String retcode = resultJSON.get("retcode") != null ? resultJSON.get("retcode").toString() : "";
        String retmsg = resultJSON.get("retmsg") != null ? resultJSON.get("retmsg").toString() : "";


        if (!StringUtils.equals("0000", retcode)) {
            redinfo.setRedInfoStatus("2");
            redinfo.setRedInfoMessage(retmsg);
            redinfoMapper.updateRedinfo(redinfo);
            return new HXResponse(retmsg);
        }

        // TODO-dxk: 2023/2/27 看下 RedInfoStatus 0 1 2代表什么
        redinfo.setRedInfoStatus("1");
        redinfo.setRedInfoMessage(retmsg);
        redinfoMapper.updateRedinfo(redinfo);
        return new HXResponse(retmsg);
    }

    @Override
    public AjaxResult queryRedInfo(Redinfo redinfo, Companyservice companyservice) {
        return null;
    }

    /**
     * 红字信息表下载
     */
    @Override
    public HXResponse downloadRedInfo(DownloadRedInfoDTO downloadRedInfoDTO, Companyservice companyservice) {

        List<CompanyserviceDetail> companyserviceDetailList = companyservice.getCompanyserviceDetailList();
        if (CollectionUtils.isEmpty(companyserviceDetailList) || StrUtil.isEmpty(companyserviceDetailList.get(0).getGoldenTaxDiskNo())) {
//            throw new JianshuiServiceException("金税盘编号未配置，请联系管理员！");
            return new HXResponse("9999", "金税盘编号未配置，请联系管理员！");
        }
        String goldenTaxDiskNo = companyserviceDetailList.get(0).getGoldenTaxDiskNo();
        String fjh = companyserviceDetailList.get(0).getFjh();

        // 组装报文
        AisinoConsoleInvoiceRedDownloadDTO downloadDTO = BeanUtil.copyProperties(downloadRedInfoDTO, AisinoConsoleInvoiceRedDownloadDTO.class);
        downloadDTO.setYQZT("N");
        downloadDTO.setXXBFW("0");
        downloadDTO.setPAGENO("1");
        downloadDTO.setPAGESIZE("1000");
        downloadDTO.setNSRSBH(companyservice.getSellertax());
        downloadDTO.setSBBH(goldenTaxDiskNo);
        downloadDTO.setKPJH(fjh);
        downloadDTO.setXXBBH(downloadRedInfoDTO.getBillInfoNo());
        downloadDTO.setTKRQ_Q(downloadRedInfoDTO.getBillTimeBegin());
        downloadDTO.setTKRQ_Z(downloadRedInfoDTO.getBillTimeEnd());

        String param = JSONUtil.toXmlStr(JSONUtil.parse(downloadDTO));

        param = "" +
                "<FPXT>" +
                "<INPUT>" +
                "" + param + "</INPUT>" +
                "</FPXT>";

        //发起请求
        AjaxResult ajaxResult = null;
        try {
            ajaxResult = AisinoConsoleUtil.sendRequestXML(AisinoConsoleConstants.RED_DOWLOAD, "0201", param, companyservice);
        } catch (Exception e) {
            log.error("【销项发票】【总部控制台接口】【红字申请表下载】发票请求异常，请求报文{}，销方信息{}", "", JSONObject.toJSONString(companyservice));
            e.printStackTrace();
//            throw new JianshuiServiceException("系统异常！");
            return new HXResponse("9999", "系统异常！");
        }

        //返回报文解析
        if (ajaxResult.isError()) {
//            throw new JianshuiServiceException(ajaxResult.getMsg());
            return new HXResponse("9999", ajaxResult.getMsg());
        }

        /** 控制台和文档不一样*/
        String retdata = ajaxResult.get("data") != null ? ajaxResult.get("data").toString() : "";
        if (StrUtil.isEmpty(retdata)) {
            return new HXResponse("9999", "下载失败");
        }
        String FPXT_COM_OUTPUT = JSONUtil.parseObj(retdata).get("FPXT_COM_OUTPUT") != null ?
                JSONUtil.parseObj(retdata).get("FPXT_COM_OUTPUT").toString() : "";
        if (StrUtil.isEmpty(retdata)) {
            return new HXResponse("9999", "下载失败");
        }
        String data = JSONUtil.parseObj(FPXT_COM_OUTPUT).get("DATA") != null ?
                JSONUtil.parseObj(FPXT_COM_OUTPUT).get("DATA").toString() : "";

        if (StrUtil.isNotEmpty(data)) {
            System.out.println("存在");
            System.out.println(data);
            if (StrUtil.isNotEmpty(data)) {
                data = Base64.decodeStr(data, "GB2312");

                if (data.contains("<DATA>") && data.contains("</DATA>")) {
                    String dataChild = data.substring(data.indexOf("<DATA>") + 6, data.indexOf("</DATA>"));

                    cn.hutool.json.JSONObject dataChildJson = JSONUtil.parseObj(dataChild);
                    String RedInvReqBill = dataChildJson.get("RedInvReqBill").toString();

                    // TODO: 2023/11/4 多条明细的这里和单条的不一样，重汽只用多条的
//                    cn.hutool.json.JSONArray jsonArray = JSONUtil.parseArray(RedInvReqBill);

                    cn.hutool.json.JSONObject jsonObject = JSONUtil.parseObj(RedInvReqBill);
                    JSONArray jsonArray1 = new JSONArray();
                    jsonArray1.add(jsonObject);

                    // 拿到最终报文
                    List<DownloadJdcVO> downloadJdcVOList = BeanUtil.copyToList(jsonArray1, DownloadJdcVO.class);

                    // 解析
                    List<Redinfo> red = null;
                    try {
                        red = parseRedinfo(downloadJdcVOList);
                    } catch (Exception e) {
                        log.info("红字信息表税局解密错误：{}", e);
                        return new HXResponse("9999", "系统异常！！！");
                    }

                    return new HXResponse("0000", "查询成功！", red, true,"");

                }
            }

        }

        return new HXResponse("9999", "系统错误！");
    }

    /**
     * @author kk
     * @date 15:25
     * @param: [downloadJdcVOList]
     * @return: 红字信息表下载报文转换
     */
    private List<Redinfo> parseRedinfo(List<DownloadJdcVO> downloadJdcVOList) {

        List<Redinfo> redinfoList = new ArrayList<>();

        for (DownloadJdcVO downloadJdcVO : downloadJdcVOList) {
            RedinfoCopyAisinoVO redinfoCopyAisinoVO = BeanUtil.copyProperties(downloadJdcVO, RedinfoCopyAisinoVO.class);

            // 含税金额赋值
            if(StrUtil.isNotEmpty(downloadJdcVO.getAmount()) && StrUtil.isNotEmpty(downloadJdcVO.getTax())){
                redinfoCopyAisinoVO.setTaxamt(NumberUtil.add(downloadJdcVO.getAmount(),downloadJdcVO.getTax()));
            }

            // 明细处理
            if (!CollectionUtils.isEmpty(downloadJdcVO.getRedInvReqBillMx()) && !CollectionUtils.isEmpty(downloadJdcVO.getRedInvReqBillMx().get(0).getGoodsMx())) {
                List<DownloadJdcDetailItemVO> downloadJdcDetailItemVOS = downloadJdcVO.getRedInvReqBillMx().get(0).getGoodsMx();
                List<RedinfodetailAisinoVO> redinfodetailAisinoVOList = BeanUtil.copyToList(downloadJdcDetailItemVOS, RedinfodetailAisinoVO.class);
                redinfoCopyAisinoVO.setRedinfodetailList(redinfodetailAisinoVOList);
            }

            // 返回转换
            Redinfo redinfo = BeanUtil.copyProperties(BeanToMapUtils.fastJsonBean2Map(redinfoCopyAisinoVO), Redinfo.class);
            redinfoList.add(redinfo);
        }

        return redinfoList;
    }


    /**
     * 作废结果查询
     */
    @Override
    public HXResponse deprecateQueryInvoice(DeprecateQueryInvoiceDTO deprecateQueryInvoiceDTO, Companyservice companyservice) {

        Invoice invoice = new Invoice();
        invoice.setSellerTaxnum(companyservice.getSellertax());
        invoice.setFpdm(deprecateQueryInvoiceDTO.getFpdm());
        invoice.setFphm(deprecateQueryInvoiceDTO.getFphm());
        QueryWrapper<Invoice> queryWrapper = new QueryWrapper<>(invoice);
        queryWrapper.last(" limit 1 ");
        Invoice result = invoiceMapper.selectOne(queryWrapper);
        if (result == null) {
            return new HXResponse("9999", "发票不存在");
        }

        JSONObject status = new JSONObject();
        status.put("status", result.getState());
        return new HXResponse("0000", "操作完成", status);
    }


    /**
     * 打印机查询
     *
     * @param queryPrinterDTO
     * @param companyservice
     * @return
     */
    @Override
    public HXResponse queryPrinter(QueryPrinterDTO queryPrinterDTO, Companyservice companyservice) {
        List<SkDyj> skDyjList = new ArrayList<>();
        try {
            QueryWrapper<SkDyj> skDyjQueryWrapper = new QueryWrapper<>();
            if (StrUtil.isNotEmpty(companyservice.getSellertax())) {
                skDyjQueryWrapper.eq("NSRSBH", companyservice.getSellertax());
            }
            if (StrUtil.isNotEmpty(queryPrinterDTO.getPrinterName())) {
                skDyjQueryWrapper.eq("MC", queryPrinterDTO.getPrinterName());
            }
            skDyjList = skDyjMapper.selectList(skDyjQueryWrapper);
        } catch (Exception e) {
            log.error("【销项发票】【大象接口】【打印机查询】发票请求异常，请求报文{}，销方信息{}", "", JSONObject.toJSONString(companyservice));
            e.printStackTrace();
            throw new JianshuiServiceException("系统异常！");
        }
        log.info("【销项发票】【大象发票】打印机查询请求结果{}", skDyjList.toString());
        List<SkDyjVO> skDyjVO = BeanUtil.copyToList(skDyjList, SkDyjVO.class);
        return new HXResponse("0000", "操作完成", skDyjList);
    }

    @Override
    public HXResponse pushData(BillInfo billInfo, Companyservice companyservice) {
        return null;
    }

    /**
     * 发票打印
     *
     * @param printDTO
     * @param companyservice
     * @return
     */
    @Override
    public HXResponse batchPrint(PrintDTO printDTO, Companyservice companyservice) {

        if (BeanUtil.isEmpty(printDTO) || CollectionUtils.isEmpty(printDTO.getDetails())) {
            throw new JianshuiParamErrorException(ErrorCode.EMPTY_PARAMS, companyservice, "invoice");
        }
        if (StrUtil.isEmpty(printDTO.getFpbs())) {
            throw new JianshuiParamErrorException(ErrorCode.EMPTY_PARAMS, companyservice, "发票标识不存在！");
        }

        List<PrintDetailDTO> details = printDTO.getDetails();

        //返回信息处理
        for (PrintDetailDTO detail : details) {
            Map<String, String> result = new HashMap<>();
            //报文组装
            AisinoConsolePrintInvoiceDTO printInvoiceDTO = BeanUtil.copyProperties(detail, AisinoConsolePrintInvoiceDTO.class);

            if (!detail.getFpqh().equals(detail.getFpzh())) {
                result.put("9999", "发票打印失败，发票号码=" + printInvoiceDTO.getInfoNumber() + "，发票代码=" + printInvoiceDTO.getInfoTypeCode() + "，原因=发票号码传参错误");
                continue;
            }
            //发票类型
            Integer invoceTypeTemp = CovertInvoiceType(detail.getInvoiceType());
            if (invoceTypeTemp == -1) {
                result.put("9999", "发票打印失败，发票号码=" + printInvoiceDTO.getInfoNumber() + "，发票代码=" + printInvoiceDTO.getInfoTypeCode() + "，原因=发票类型未匹配");
                continue;
            }
            printInvoiceDTO.setInfoKind(invoceTypeTemp);

            //必填参数校验
            ValidateUtils.validate(printInvoiceDTO, companyservice, null);

            // 处理打印标识
            String fpbs = printDTO.getFpbs();
            if ("0".equals(fpbs)) {
                fpbs = "1";
            } else if ("1".equals(fpbs)) {
                fpbs = "0";
            } else {
                fpbs = "0";
            }

            printInvoiceDTO.setPrintKind(Integer.valueOf(fpbs));
            printInvoiceDTO.setShowPrintDlg(0);

            //发起请求
            AjaxResult ajaxResult = null;
            try {
                Map<String, Object> map = BeanToMapUtils.fastJsonBean2Map(printInvoiceDTO);
                ajaxResult = AisinoConsoleUtil.sendRequest(AisinoConsoleConstants.INVOICE_PRINT, JSONUtil.parse(map), companyservice);
            } catch (Exception e) {
                log.error("【销项发票】【总部控制台接口】【发票打印】发票请求异常，请求报文{}，销方信息{}", JSONUtil.parse(printInvoiceDTO).toString(), JSONObject.toJSONString(companyservice));
                result.put("9999", "发票打印失败，发票号码=" + printInvoiceDTO.getInfoNumber() + "，发票代码=" + printInvoiceDTO.getInfoTypeCode() + "，原因=系统原因");
            }

            //返回报文解析
            if (ajaxResult.isError()) {
                result.put("9999", "发票打印失败，发票号码=" + printInvoiceDTO.getInfoNumber() + "，发票代码=" + printInvoiceDTO.getInfoTypeCode() + "，原因=" + ajaxResult.getMsg());
                ;
            }

            cn.hutool.json.JSONObject resultJSON = JSONUtil.parseObj(ajaxResult.get("data"));
            String retcode = resultJSON.get("retcode") != null ? resultJSON.get("retcode").toString() : "";
            String retmsg = resultJSON.get("retmsg") != null ? resultJSON.get("retmsg").toString() : "";
            if ("5011".equals(retcode)) {
                return new HXResponse("0000", "发票打印成功，发票号码=" + printInvoiceDTO.getInfoNumber() + "，发票代码=" + printInvoiceDTO.getInfoTypeCode());
            } else {
                return new HXResponse("发票打印失败，发票号码=" + printInvoiceDTO.getInfoNumber() + "，发票代码=" + printInvoiceDTO.getInfoTypeCode() + "，原因=" + retmsg);
            }
        }

        return new HXResponse("0000", "操作完成");


    }

    /**
     * 机动车加密接口（控制台）
     */
    @Override
    public HXResponse exportVehicleInvoice(JSONObject decryptResult, Companyservice companyservice) {

        ExportVehicleDTO exportVehicleDTO = BeanUtil.copyProperties(decryptResult, ExportVehicleDTO.class);

        if (BeanUtil.isEmpty(exportVehicleDTO)) {
            return new HXResponse("9999", "请求参数为空！");
        }

        // 机动车加密导出路径配置
        exportVehicleDTO.setSavePath(AisinoConsoleConstants.SAVE_PATH);

        // 发起请求
        AjaxResult ajaxResult = null;

        JSON json = JSONUtil.parse(exportVehicleDTO);
        try {
            ajaxResult = AisinoConsoleUtil.sendRequest(AisinoConsoleConstants.VEHIC, json, companyservice);
        } catch (Exception e) {
            log.error("【销项发票】【总部控制台接口】【机动车加密】机动车加密文件导出请求异常，请求报文{}，销方信息{}", JSONUtil.parse(decryptResult).toString(), JSONObject.toJSONString(companyservice));
            e.printStackTrace();
            return new HXResponse("9999", "系统异常！");
        }
        log.info("【销项发票】【总部控制台发票】机动车加密文件导出结果{}", ajaxResult.toString());

        //返回报文解析
        if (ajaxResult.isError()) {
            return new HXResponse("9999", ajaxResult.getMsg());
        }

        cn.hutool.json.JSONObject resultJSON = JSONUtil.parseObj(ajaxResult.get("data"));
        String retcode = resultJSON.get("retcode") != null ? resultJSON.get("retcode").toString() : "";
        String retmsg = resultJSON.get("retmsg") != null ? resultJSON.get("retmsg").toString() : "";

        if ("0".equals(retcode)) {

            ICompanyservicePropService companyserviceProp = SpringUtils.getBean(ICompanyservicePropService.class);
            CompanyserviceProp secretIdProp = companyserviceProp.selectPropByKey(companyservice.getCompanyid(), "aisino_nginx_url");

            if (secretIdProp == null || StrUtil.isEmpty(secretIdProp.getValue())) {
                log.info("【销项发票】【总部控制台发票-机动车加密】推送nginx地址未配置！aisino_nginx_url");
                return new HXResponse("9999", "推送中间件地址未配置！");
            }

            String downloadUrl = secretIdProp.getValue();

            cn.hutool.json.JSONObject queryDto = JSONUtil.parseObj(json);
            if (queryDto == null) {
                log.info("【销项发票】【总部控制台发票-机动车加密】查询条件未获取到！");
                return new HXResponse("9999", "查询条件未获取到！");
            }

            String indexPage = null;
            try {
                indexPage = HttpUtil.get(downloadUrl);
            } catch (Exception e) {
                log.info("【销项发票】【总部控制台发票-机动车加密】{}", e);
                return new HXResponse("9999", "中间件读取失败！");
            }

            String startDate = queryDto.get("KSRQ") != null ? queryDto.get("KSRQ").toString().replace("-", ".") : "";
            String endDate = queryDto.get("JSRQ") != null ? queryDto.get("JSRQ").toString().replace("-", ".") : "";

            // 构建要匹配的日期范围字符串
            String dateRange = startDate + "-" + endDate;
            // 使用Jsoup解析HTML
            Document doc = Jsoup.parse(indexPage);

            // 获取带有动态日期范围的<a>标签
            Elements aTags = doc.select("a[href*='%28" + dateRange + "%29.dat']");

            String href = "";
            // 遍历<a>标签，提取href属性内容
            for (Element aTag : aTags) {
                href = aTag.attr("href");
                log.info("读取到的机动车加密文件名为" + href);
                continue;
            }

//            String fileStream = null;
            InputStream inputStream = null;
            File file = null;
            FileInputStream fileInputStream = null;
            try {
//                fileStream = HttpUtil.get(downloadUrl + href);
                CloseableHttpClient httpClient = HttpClients.createDefault();
                HttpGet httpGet = new HttpGet(downloadUrl + href);
                CloseableHttpResponse response = httpClient.execute(httpGet);
                inputStream = response.getEntity().getContent();
                file = stream2file(inputStream);
            } catch (Exception e) {
                log.info("读取到的机动车加密文件名为{},下载文件nginx接口失败", href);
                return new HXResponse("9999", "导出失败，未获取到下载文件！");
            }
//            InputStream is = new ByteArrayInputStream(fileStream.getBytes());

            CompanyserviceProp qyjc = companyserviceProp.selectPropByKey(companyservice.getCompanyid(), "aisino_qyjc");
            if (qyjc == null || StrUtil.isEmpty(qyjc.getValue())) {
                return new HXResponse("9999", "重汽推送企业简称未设置！");
            }
            CompanyserviceProp zdr = companyserviceProp.selectPropByKey(companyservice.getCompanyid(), "aisino_zdr");
            if (zdr == null || StrUtil.isEmpty(zdr.getValue())) {
                return new HXResponse("9999", "重汽推送制单人未设置！");
            }


            // 调用重汽的推送接口
            HashMap<String, Object> paramMap = new HashMap<>();
            paramMap.put("file", file);
            paramMap.put("qyjc", qyjc.getValue());
            paramMap.put("zdr", zdr.getValue());

            CompanyserviceProp pushUrl = companyserviceProp.selectPropByKey(companyservice.getCompanyid(), "aisino_upload_url");
            if (pushUrl == null || StrUtil.isEmpty(pushUrl.getValue())) {
                return new HXResponse("9999", "重汽推送机动车地址未设置！");
            }
            String retCode = null;
            String retMsg = null;
            try {
                log.info("【机动车加密接口推送】请求内容：{}", paramMap);
//                String result = HttpUtil.post(pushUrl.getValue(), paramMap);
                String result = HttpRequest.post(pushUrl.getValue())
                        .form(paramMap)//表单内容
                        .timeout(60000)//超时，毫秒
                        .execute().body();

//                log.info("【机动车加密接口推送】返回,{}", result);
                cn.hutool.json.JSONObject jsonObject = JSONUtil.parseObj(result);
                retCode = jsonObject.get("retCode") != null ? jsonObject.get("retCode").toString() : "";
                retMsg = jsonObject.get("retMsg") != null ? jsonObject.get("retMsg").toString() : "";
                log.info("【机动车加密接口推送】返回解析,retCode={},retMsg={}", retCode,retMsg);
            } catch (Exception e) {
                log.info("【机动车加密接口推送】异常,{}", e);
                return new HXResponse("9999", "推送接口异常！");
            }finally {
                file.delete();
            }
            try {
                fileInputStream.close();
            } catch (IOException e) {
                log.info("【机动车加密接口推送】文件流关闭失败,{}", e);
            }
            // 重汽返回接口信息
            return new HXResponse(retCode, retMsg);
        } else {
            return new HXResponse("9999", "导出失败、发票不存在！");
        }

    }

    @Override
    public HXResponse qrcodeResult(JSONObject decryptResult, Companyservice companyservice) {
        return null;
    }

    /**
     * @author kk
     * @date 17:42
     * @param: [in]
     * @return: 机动车加密导出-文件转化本地
     */
    public static File stream2file(InputStream in) throws IOException {
        final File tempFile = File.createTempFile(PREFIX, ".dat");
        tempFile.deleteOnExit();
        try (FileOutputStream out = new FileOutputStream(tempFile)) {
            IOUtils.copy(in, out);
        }
        return tempFile;
    }


    @Override
    public AjaxResult syncStockInfo(Companyservice companyservice) {
        return null;
    }

    @Override
    public HXResponse signInvoice(SignESealDTO signESealDTO, Companyservice companyservice) {
        return null;
    }

    @Override
    public HXResponse createESeal(CreateESealDTO createESealDTO, Companyservice companyservice) {
        return null;
    }

    @Override
    public HXResponse registerESeal(RegisterESealDTO createESealDTO, Companyservice companyservice) {
        return null;
    }

    @Override
    public AjaxResult SummaryReport(SummaryReportQueryDTO summaryReportQueryDTO, Companyservice companyservice) {
        return null;
    }

    @Override
    public Object callback(HttpServletRequest request) {
        return null;
    }


    /**
     * 简税转换总部控制台发票类型
     *
     * @param invoiceType
     * @return java.lang.Integer
     * @author dxk
     * @date 2022/6/28 20:17
     */
    public static Integer CovertInvoiceType(String invoiceType) {

        /** 控制台发票种类：
         专用发票 = 0,
         普通发票 = 2,
         货物运输业增值税专用发票 = 11,
         机动车销售统一发票 = 12,
         卷式普通发票 = 41,
         电子发票 = 51,
         农产品收购普通发票 = 20,
         农产品收购电子发票 = 21,
         电子专票 = 52*/
        /** 简税发票种类
         * 默认为普通电票p。
         卷票 r 只支持13 行明细；
         p:电子增值税普通发票，   2
         c:增值税普通发票(纸票)：普票  2
         s:增值税专用发票：专票、机动车专票  0
         j：机动车销售统一发票 12
         e: 收购发票(电子)， 21
         f:收购发票(纸质)， 20
         r:增值税普通发票(卷式)， 2
         b:增值税电子专用发票, 0
         82:数电普通，
         81：数电专票*/

        /**
         * 发票种类 invoice_type（ p电子增值税普通发票 c增值税普通发票 s 增值税专用发票 e 收购发票 f 收购发票 r增值税普通发票）
         */
        if (StrUtil.isEmpty(invoiceType)) {
            return -1;
        }
        if ("p".equals(invoiceType) || "c".equals(invoiceType) || "r".equals(invoiceType)) {
            return 2;
        } else if ("s".equals(invoiceType) || "b".equals(invoiceType)) {
            return 0;
        } else if ("j".equals(invoiceType)) {
            return 12;
        } else if ("e".equals(invoiceType)) {
            return 21;
        } else if ("f".equals(invoiceType)) {
            return 20;
        }

        return -1;
    }

    /**
     * 总部控制台转简税发票类型
     *
     * @param invoiceType
     * @return java.lang.String
     * @author dxk
     * @date 2022/6/29 17:12
     */
    public static String CovertInvoiceTypeReverse(String invoiceType) {

        if (invoiceType.equals("2")) {
            return "p";
        } else if (invoiceType.equals("0")) {
            return "s";
        }else if (invoiceType.equals("12")) {
            return "j";
        }else if (invoiceType.equals("21")) {
            return "e";
        }else if (invoiceType.equals("20")) {
            return "f";
        }
        return "";
    }


    @Override
    public Object addCallback(HttpServletRequest request) {
        return null;
    }

    @Override
    public Object decryptCallback(HttpServletRequest request) {
        return null;
    }

    @Override
    public HXResponse getFileUrl(InvoiceAllFileAcquisitionTWODTO invoiceAllFileAcquisitionTWODTO, Companyservice companyservice) {
        return null;
    }

    @Override
    public HXResponse getFileAcquisitionOn(InvoiceAllFileAcquisitionOnTWODTO invoiceAllFileAcquisitionOnTWODTO, Companyservice companyservice) {
        return null;
    }

    @Override
    public HXResponse qrcode(JSONObject decryptResult, Companyservice companyservice) {
        return null;
    }

    @Override
    public HXResponse query(InvoiceAllFileQueryTWODTO invoiceAllFileQueryTWODTO, Companyservice companyservice) {
        return null;
    }

    @Override
    public HXResponse getPrintXML(InvoiceAllPrintXMLTWODTO invoiceAllPrintXMLTWODTO, Companyservice companyservice) {
        return null;
    }

    @Override
    public HXResponse issueFastRedInvoice(InvoiceAllKshcJsonDataTWODTO invoiceAllKshcDTO, Companyservice companyservice) {
        return null;
    }

    @Override
    public HXResponse invoiceStatic(JSONObject decryptResult, Companyservice companyservice) {
        return null;
    }

    @Override
    public HXResponse auditRedInfo(InvoiceAllShhzJsonDataTWODTO invoiceAllShhzTWODTO, Companyservice companyservice) {
        return null;
    }

    @Override
    public HXResponse queryRedInfoDetail(InvoiceAllRedInvoiceDetailTWODTO invoiceAllRedInvoiceDetailDTO, Companyservice companyservice) {
        return null;
    }

    @Override
    public HXResponse queryResultInfo(InvoiceAllQueryTWODTO invoiceAllYhdjDTO, Companyservice companyservice) {
        return null;
    }

    @Override
    public EleNewMessage findRedInfo(FindRedInfo findRedInfo, Companyservice companyservice) {
        return null;
    }

    @Override
    public HXResponse generateDynamicCode(JSONObject decryptResult, Companyservice companyservice) {
        return null;
    }


    /**
     * 机动车加密接口（走的大象，重汽用控制台）
     *//*
    @Override
    public HXResponse exportVehicleInvoice(JSONObject decryptResult, Companyservice companyservice) {

        // 转换实体参数
        VehicleInvoiceExpBo vehicleInvoiceExpBo = BeanUtil.copyProperties(decryptResult, VehicleInvoiceExpBo.class);

        // TODO: 2023/10/8 迁移大象  迁移税控  找测试数据
        if (Objects.isNull(vehicleInvoiceExpBo)) {
            log.info("请求参数为空");
        }
        if (org.apache.commons.lang3.StringUtils.isBlank(vehicleInvoiceExpBo.getNsrsbh())) {
            log.info("纳税人识别号为空");
        }
        if (org.apache.commons.lang3.StringUtils.isBlank(vehicleInvoiceExpBo.getFjh())) {
            log.info("分机号为空");
        }
        if (org.apache.commons.lang3.StringUtils.isBlank(vehicleInvoiceExpBo.getQqsj())) {
            log.info("起始时间为空");
        }
        if (org.apache.commons.lang3.StringUtils.isBlank(vehicleInvoiceExpBo.getZzsj())) {
            log.info("终止时间为空");
        }

        String data = exportVehicleInvoice(vehicleInvoiceExpBo);
        if (org.apache.commons.lang3.StringUtils.isBlank(data)) {
            log.error("{}机动车加密数据导出，加密数据为空", "");
            data = "";
        }
        String fileName = "机动车专用发票明细" + "_" + vehicleInvoiceExpBo.getFjh()
                + (vehicleInvoiceExpBo.getQqsj() + "-" + vehicleInvoiceExpBo.getZzsj()) + ".dat";

        // TODO: 2023/10/8 输出到页面
        // 浏览器处理乱码问题
        *//*String userAgent = request.getHeader(HttpHeaders.USER_AGENT);
        try {
            //IE浏览器
            if (org.apache.commons.lang3.StringUtils.contains(userAgent, ConfigureConstant.REQUEST_HEAD_USER_AGENT_TYPE_MSIE)
                    || org.apache.commons.lang3.StringUtils.contains(userAgent, ConfigureConstant.REQUEST_HEAD_USER_AGENT_TYPE_TRIDENT)) {
                fileName = URLEncoder.encode(fileName, "UTF8");
                log.debug("{}IE浏览器下载", LOGGER_MSG);

            } else if (org.apache.commons.lang3.StringUtils.contains(userAgent, ConfigureConstant.REQUEST_HEAD_USER_AGENT_TYPE_MOZILLA)) {
                //google,火狐浏览器
                fileName = new String(fileName.getBytes(StandardCharsets.UTF_8), "ISO8859-1");
            } else {
                //其他浏览器
                fileName = URLEncoder.encode(fileName, "UTF8");
            }

            response.setContentType("application/octet-stream");
            response.setHeader("Content-Disposition", "attachment;filename=" + fileName);
            response.setHeader("fileName", fileName);
            response.getOutputStream().write(Base64Encoding.decode(data));
        } catch (IOException e) {
            log.error("{}机动车导出加密数据异常:{}", LOGGER_MSG, e);
        }*//*

        return null;
    }*/


    /**
     * 1.调用税控获取信息
     *
     * @param vehicleInvoiceExpBo
     * @return
     */
    public String exportVehicleInvoice(VehicleInvoiceExpBo vehicleInvoiceExpBo) {
        //1.调用税控获取终端代码(简税固定为 金税盘 )
        // `sksb_code`税控设备说明
        // (
        // 000:未配置;001:金税盘托管;002:金税盘A9托管;
        // 004:税控盘托管;005:百望服务器;006:本地税控盘;
        // 007:本地金税盘;008:百望服务器ActiveX;
        // 009:税控服务器;010:UKey托管;011:本地UKey;
        // 012:金税盘U180托管;013:UkeyU180托管;
        // 014:UT000/Q30;015:本地51云组件
        // )',
        String terminalCode = "007";

        // TODO: 2023/10/9 机动车加密大象


        /*try {
            InterfaceData interfaceData = InterfaceDataUtil.requestInterfaceData(req, apiVersion, true, minProtocolVersion);

            if (!StatusConstants.REQUEST_SUCCESS.getCODE().equals(interfaceData.getReturnCode())) {
                return interfaceData;
            }
            InterfaceData jg = taxInvoiceFactory.getQueryInfoHandler(TaxTypeEnum.getTaxType(interfaceData.getMachineType())).vehicleInvoiceExp(interfaceData);
            return ProtocolUtil.packageProtocol(InterfaceDataUtil.replaceInterfaceData(interfaceData, jg));

        } catch (JSONException jsonException) {
            log.error(jsonException.getMessage(), jsonException);
            return InterfaceDataUtil.error("9999", "参数解析异常");
        } catch (BadRequestException badReq) {
            log.error(badReq.getMessage(), badReq);
            return InterfaceDataUtil.error("9999", badReq.getMessage());
        } catch (ProtocolException protocolException) {
            log.error(protocolException.getMessage(), protocolException);
            return InterfaceDataUtil.error("9999", protocolException.getMessage());
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            return InterfaceDataUtil.error("9999", "验签失败发票查询发生异常");
        }


        return response.getVEHICLEINVOICEBUFF();*/


        return null;
    }

    /**
     * 调用税控获取终端代码
     *
     * @param nsrsbh
     * @param entId
     * @return
     */
    public String getTerminalCode(String nsrsbh, String entId) {
        TaxEquipmentInfo taxEquipmentInfo = queryTaxEquipment(nsrsbh, entId);
        if (ObjectUtil.isNotNull(taxEquipmentInfo)) {
            return taxEquipmentInfo.getSksbCode();
        } else {
            return "";
        }
    }

    /**
     * 调用基础服务获取税控设备
     *
     * @param nsrsbh
     * @param entId
     * @return
     */
    public TaxEquipmentInfo queryTaxEquipment(String nsrsbh, String entId) {
        TaxEquipmentInfo taxEquipmentInfo = null;

       /* try {
            //调用基础服务获取税控设备,基础服务封装了真实的entId
            String configQueryTaxEquipmentUrl = baseServiceConfig.configQueryTaxEquipmentUrl();
            PageQueryTaxEquipmentReq pageQueryTaxEquipmentReq = new PageQueryTaxEquipmentReq();
            pageQueryTaxEquipmentReq.setNsrsbh(nsrsbh);
            if (org.apache.commons.lang3.StringUtils.isNotBlank(entId)) {
                pageQueryTaxEquipmentReq.setEntId(entId);
            }

            PageQueryTaxEquipmentRsp pageQueryTaxEquipmentRsp = HttpInvoiceRequestUtilBase.queryTaxEquipment(configQueryTaxEquipmentUrl, pageQueryTaxEquipmentReq);
            if (ObjectUtil.isNotNull(pageQueryTaxEquipmentRsp) && ConfigureConstant.STRING_0000.equals(pageQueryTaxEquipmentRsp.getZTDM())) {
                if (ObjectUtil.isNotNull(pageQueryTaxEquipmentRsp.getTaxEquipmentInfo())) {
                    taxEquipmentInfo = pageQueryTaxEquipmentRsp.getTaxEquipmentInfo();
                }
            }

        } catch (Exception e) {
            log.error("{}调用基础服务获取税控设备接口异常:{}", LOGGER_MSG, e);
        }*/


        return taxEquipmentInfo;
    }


}
