package com.heyu.api.controller.financial;


import com.heyu.api.baidu.handle.financial.BVatInvoiceVerificationHandle;
import com.heyu.api.baidu.request.financial.BVatInvoiceVerificationRequest;
import com.heyu.api.baidu.response.financial.BUsedCarVatInvoiceVerificationResp;
import com.heyu.api.baidu.response.financial.BVatInvoiceVerificationResp;
import com.heyu.api.controller.BaseController;
import com.heyu.api.data.annotation.CacheResult;
import com.heyu.api.data.annotation.NotIntercept;
import com.heyu.api.data.utils.ApiR;
import com.heyu.api.data.utils.R;
import com.heyu.api.request.financial.CommonVatInvoiceVerificationRequest;
import com.heyu.api.resp.financial.UsedCarVatInvoiceVerificationResp;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


/***
 *https://console.bce.baidu.com/support/?_=1740494347073&timestamp=1740500368284#/api?product=AI&project=%E6%96%87%E5%AD%97%E8%AF%86%E5%88%AB&parent=%E8%B4%A2%E5%8A%A1%E7%A5%A8%E6%8D%AEOCR&api=rest%2F2.0%2Focr%2Fv1%2Fvat_invoice_verification&method=post
 *
 *
 * 增值税发票验真
 *
 *
 *
 * 支持 14 种增值税发票的信息核验，包括增值税专票、电子专票、普票、电子普票、卷票、区块链发票（深圳地区）、全电发票（新版全国统一电子发票，专票/普票）、通行费增值税电子普通发票、货物运输业增值税专用发票、
 * 机动车销售发票、二手车销售发票、航空运输电子客票行程单（电子发票）、铁路电子客票（电子发票）等，支持返回票面的全部信息。同时可直接与同平台的发票识别能力对接，完成发票识别的同时进行自动化验真。
 *
 *
 * 视频教程请参见 智能财务票据识别+增值税发票验真使用教程
 *
 *
 */
@Slf4j
@RestController
@RequestMapping("/used/car/vat/Invoice")
@NotIntercept
public class UsedCarVatInvoiceVerificationController extends BaseController {


    @Autowired
    private BVatInvoiceVerificationHandle bVatInvoiceVerificationHandle;


    @RequestMapping("/verification")
    @CacheResult
    public R verification(CommonVatInvoiceVerificationRequest req) {

        BVatInvoiceVerificationRequest bVatInvoiceVerificationRequest = new BVatInvoiceVerificationRequest();
        bVatInvoiceVerificationRequest.setInvoiceCode(req.getInvoiceCode());
        bVatInvoiceVerificationRequest.setInvoiceNum(req.getInvoiceNum());
        bVatInvoiceVerificationRequest.setInvoiceDate(req.getInvoiceDate());
        bVatInvoiceVerificationRequest.setInvoiceType(req.getInvoiceType());
        bVatInvoiceVerificationRequest.setCheckCode(req.getCheckCode());
        bVatInvoiceVerificationRequest.setTotalAmount(req.getTotalAmount());

        UsedCarVatInvoiceVerificationResp resp = new UsedCarVatInvoiceVerificationResp();


        ApiR<BVatInvoiceVerificationResp> bR = bVatInvoiceVerificationHandle.handle(bVatInvoiceVerificationRequest, BUsedCarVatInvoiceVerificationResp.class);
        if (bR.isSuccess()) {

            BUsedCarVatInvoiceVerificationResp bUsedCarVatInvoiceVerificationResp =(BUsedCarVatInvoiceVerificationResp)  bR.getData();
            BUsedCarVatInvoiceVerificationResp.WordsResultDTO wordsResultDTO = bUsedCarVatInvoiceVerificationResp.getWordsResult();


            resp.setVerifyFrequency(wordsResultDTO.getVerifyFrequency());    // 查验次数。为历史查验次数
            resp.setVerifyMessage(wordsResultDTO.getVerifyMessage());      //查验结果信息。查验成功且发票为真返回“查验成功发票一致“，查验失败返回对应错误原因，详见末尾表格
            resp.setInvalidSign(wordsResultDTO.getInvalidSign());         // 是否作废（冲红）。Y：已作废；H：已冲红；N：未作废
            resp.setInvoiceType(wordsResultDTO.getInvoiceType());     //发票种类。即增值税专用发票、增值税电子专用发票、增值税普通发票、增值税普通发票（电子）、增值税普通发票（卷式）、通行费增值税电子普通发票、区块链电子发票、全电发票（专用发票）、全电发票（普通发票）、机动车销售发票、二手车销售发票、货物运输业增值税专用发票、航空运输电子客票行程单（电子发票）、铁路电子客票（电子发票）
            resp.setMachineCode(wordsResultDTO.getMachineCode());                 //机器编号
            resp.setCheckCode(wordsResultDTO.getCheckCode());           //校验码
            resp.setInvoiceCode(wordsResultDTO.getInvoiceCode());             //发票代码
            resp.setInvoiceDate(wordsResultDTO.getInvoiceDate());             //	开票日期
            resp.setVerifyResult(wordsResultDTO.getPurchaser());            //查验结果。查验成功返回“0001”，查验失败返回对应查验结果错误码，详见末尾表格
            resp.setInvoiceNum(wordsResultDTO.getInvoiceNum());              //发票号码
            resp.setOperator(wordsResultDTO.getOperator());                   //经营、拍卖单位
            resp.setTransferVehicleManagementOffice(wordsResultDTO.getTransferVehicleManagementOffice());     //	转入地车辆车管所名称
            resp.setManuModel(wordsResultDTO.getManuModel());               //厂牌型号
            resp.setRegistrationCode(wordsResultDTO.getRegistrationCode());                    //登记证号
            resp.setOperatorPhone(wordsResultDTO.getOperatorPhone());           //经营、拍卖单位电话
            resp.setPurchaserCode(wordsResultDTO.getPurchaserCode());                       //买方单位代码/身份证号
            resp.setSaler(wordsResultDTO.getSaler());                               //卖方单位/个人
            resp.setUsedCarMarketCode(wordsResultDTO.getUsedCarMarketCode());                   //二手车市场纳税人识别号
            resp.setPurchaser(wordsResultDTO.getPurchaser());                       //买方单位/个人
            resp.setOperatorCode(wordsResultDTO.getOperatorCode());                    //经营、拍卖单位纳税人识别号
            resp.setUsedCarMarketBank(wordsResultDTO.getUsedCarMarketBank());                   //	二手车市场开户银行及账号
            resp.setSalerAddress(wordsResultDTO.getSalerAddress());                    //	卖方单位/个人住址
            resp.setSalerCode(wordsResultDTO.getSalerCode());                       //卖方单位代码/身份证号
            resp.setPurchaserPhone(wordsResultDTO.getPurchaserPhone());                  //买方电话
            resp.setLicensePlateNum(wordsResultDTO.getLicensePlateNum());                     //车牌照号
            resp.setVehicleType(wordsResultDTO.getVehicleType());                 //车辆类型
            resp.setOperatorBank(wordsResultDTO.getOperatorBank());                //开户银行及账号
            resp.setOperatorAddress(wordsResultDTO.getOperatorAddress());                     //经营、拍卖单位地址
            resp.setVinNum(wordsResultDTO.getVinNum());                              //车辆识别代号/车架号码
            resp.setTotalCarPrice(wordsResultDTO.getTotalCarPrice());                       //车价合计
            resp.setSalerPhone(wordsResultDTO.getSalerPhone());                          //卖方电话
            resp.setPurchaserAddress(wordsResultDTO.getPurchaserAddress());                        //买方单位/个人住址
            resp.setUsedCarMarketPhone(wordsResultDTO.getUsedCarMarketPhone());              //二手车市场电话
            resp.setUsedCarMarketAddress(wordsResultDTO.getUsedCarMarketAddress());                        //二手车市地址
            resp.setUsedCarMarket(wordsResultDTO.getUsedCarMarket());                           //	二手车市场

            return  R.ok().setData(resp);




        }


        return R.ok();
    }


}
