package com.heyu.api.controller.traffic;

import com.heyu.api.baidu.handle.traffic.BVehicleInvoiceHandle;
import com.heyu.api.baidu.request.traffic.BVehicleInvoiceRequest;
import com.heyu.api.baidu.response.traffic.BVehicleInvoiceResp;
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.resp.traffic.VehicleInvoiceResp;
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;


/**
 * <p>
 * <p>
 * <p>
 * https://console.bce.baidu.com/support/?_=1740411162437&timestamp=1740411519148#/api?product=AI&project=%E6%96%87%E5%AD%97%E8%AF%86%E5%88%AB&parent=%E4%BA%A4%E9%80%9A%E5%9C%BA%E6%99%AFOCR&api=rest%2F2.0%2Focr%2Fv1%2Fvehicle_invoice&method=post
 * <p>
 * 机动车销售发票识别
 *
 *
 * 接口描述
 * 支持对机动车销售发票的26个关键字段进行结构化识别，包括发票代码、发票号码、开票日期、机器编号、购买方名称、购买方身份证号码/组织机构代码、车辆类型、
 * 厂牌型号、产地、合格证号、发动机号码、车架号码、价税合计、价税合计小写、销货单位名称、电话、纳税人识别号、账号、地址、开户银行、税率、税额、
 * 主管税务机关及代码、不含税价格、限乘人数。
 *
 *
 *
 */

@Slf4j
@RestController
@RequestMapping("/vehicle/invoice")
@NotIntercept
public class VehicleInvoiceController extends BaseController {


    @Autowired
    private BVehicleInvoiceHandle bVehicleInvoiceHandle;


    @RequestMapping("/recognize")
    @CacheResult
    public R recognize(BVehicleInvoiceRequest request) {
        VehicleInvoiceResp resp = new VehicleInvoiceResp();

        ApiR<BVehicleInvoiceResp> bR = bVehicleInvoiceHandle.handle(request);
        if (bR.isSuccess()) {
            BVehicleInvoiceResp bVehicleInvoiceResp = bR.getData();
            BVehicleInvoiceResp.WordsResultDTO wordsResultDTO = bVehicleInvoiceResp.getWordsResult();

            resp.setInvoiceNum(wordsResultDTO.getInvoiceNum());              //发票号码/机打号码
            resp.setSaler(wordsResultDTO.getSaler());                   //	销货单位名称
            resp.setLimitPassenger(wordsResultDTO.getLimitPassenger());          //限乘人数
            resp.setMachineCode(wordsResultDTO.getMachineCode());             // 	机器编号
            resp.setVinNum(wordsResultDTO.getVinNum());                  // 车架号码
            resp.setTaxRate(wordsResultDTO.getTaxRate());                 //税率
            resp.setPriceTaxLow(wordsResultDTO.getPriceTaxLow());             //价税合计小写
            resp.setInvoiceDate(wordsResultDTO.getInvoiceDate());             //开票日期
            resp.setPrice(wordsResultDTO.getPrice());                   //不含税价格
            resp.setSalerBank(wordsResultDTO.getSalerBank());               //销货单位开户银行
            resp.setTaxAuthor(wordsResultDTO.getTaxAuthor());               //主管税务机关
            resp.setManuModel(wordsResultDTO.getManuModel());               //厂牌型号
            resp.setCertificateNum(wordsResultDTO.getCertificateNum());          //合格证号
            resp.setPurchaser(wordsResultDTO.getPurchaser());               //购买方名称
            resp.setVehicleType(wordsResultDTO.getVehicleType());             //	车辆类型
            resp.setInvoiceCode(wordsResultDTO.getInvoiceCode());         //发票代码/机打代码
            resp.setPriceTax(wordsResultDTO.getPriceTax());                    //	价税合计
            resp.setSalerPhone(wordsResultDTO.getSalerPhone());                  //销货单位电话
            resp.setSalerAddress(wordsResultDTO.getSalerAddress());                    //	销货单位地址
            resp.setOrigin(wordsResultDTO.getOrigin());                      //产地
            resp.setEngineNum(wordsResultDTO.getEngineNum());               //发动机号码
            resp.setTax(wordsResultDTO.getTax());                         //税额
            resp.setPurchaserCode(wordsResultDTO.getPurchaserCode());                   //购买方身份证号码/组织机构代码
            resp.setTaxAuthorCode(wordsResultDTO.getTaxAuthorCode());                       //	主管税务机关代码
            resp.setSalerAccountNum(wordsResultDTO.getSalerAccountNum());                     //销货单位账号
            resp.setSalerCode(wordsResultDTO.getSalerCode());                       //销货单位纳税人识别号
            return R.ok().setData(resp);
        }
        return R.error(bR.getErrorMsg());
    }


}