package com.heyu.api.controller.traffic;

import com.heyu.api.baidu.handle.traffic.BUsedVehicleInvoiceHandle;
import com.heyu.api.baidu.request.traffic.BUsedVehicleInvoiceRequest;
import com.heyu.api.baidu.response.traffic.BUsedVehicleInvoiceResp;
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.UsedVehicleInvoiceResp;
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/?_=1740411162437&timestamp=1740411735793#/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%2Fused_vehicle_invoice&method=post
 * 二手车销售发票识别
 *
 *接口描述
 * 支持对二手车销售发票的25个关键字段进行结构化识别，包括发票代码、发票号码、开票日期、买方、卖方、车牌号、车辆类型、二手车市场等。
 *
 *
 */
@Slf4j
@RestController
@RequestMapping("/used/vehicle/invoice")
@NotIntercept
public class UsedVehicleInvoiceController extends BaseController {


    @Autowired
    private BUsedVehicleInvoiceHandle bUsedVehicleInvoiceHandle;


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

        ApiR<BUsedVehicleInvoiceResp> bR = bUsedVehicleInvoiceHandle.handle(request);
        if (bR.isSuccess()) {
            BUsedVehicleInvoiceResp bUsedVehicleInvoiceResp = bR.getData();
            BUsedVehicleInvoiceResp.WordResultDTO wordResultDTO = bUsedVehicleInvoiceResp.getWordResult();

            if (wordResultDTO != null) {
                resp.setTransferVehicleManagementOffice(wordResultDTO.getTransferVehicleManagementOffice().getWord()); // 转入地车管所名称
                resp.setManuModel(wordResultDTO.getManuModel().getWord());                       //	厂牌型号
                resp.setRegistrationCode(wordResultDTO.getRegistrationCode().getWord());                     //登记证号
                resp.setTotalCarPriceLow(wordResultDTO.getTotalCarPriceLow().getWord());             //车价合计小写
                resp.setTaxAddress(wordResultDTO.getTaxAddress().getWord()); //纳税人地址
                resp.setPurchaserCode(wordResultDTO.getPurchaserCode().getWord()); // 买方身份证号
                resp.setSaler(wordResultDTO.getSaler().getWord());   //	卖方
                resp.setTaxCode(wordResultDTO.getTaxCode().getWord()); // 	税控码
                resp.setPurchaser(wordResultDTO.getPurchaser().getWord());               //买方
                resp.setInvoiceCode(wordResultDTO.getInvoiceCode().getWord());   //发票代码
                resp.setInvoiceDate(wordResultDTO.getInvoiceDate().getWord());       //开票日期
                resp.setSalerAddress(wordResultDTO.getSalerAddress().getWord()); //卖方地址
                resp.setSalerCode(wordResultDTO.getSalerCode().getWord()); //卖方身份证号
                resp.setTaxPhone(wordResultDTO.getTaxPhone().getWord()); //纳税人电话
                resp.setTaxNum(wordResultDTO.getTaxPhone().getWord()); //纳税人识别号
                resp.setPurchaserPhone(wordResultDTO.getPurchaserPhone().getWord()); //买方电话
                resp.setVehicleType(wordResultDTO.getVehicleType().getWord()); //	车辆类型
                resp.setLicensePlateNum(wordResultDTO.getLicensePlateNum().getWord());           //车牌号
                resp.setSheetNum(wordResultDTO.getSheetNum().getWord());//联次
                resp.setVinNum(wordResultDTO.getVinNum().getWord()); //车架号
                resp.setTotalCarPrice(wordResultDTO.getTotalCarPrice().getWord()); //车价合计大写
                resp.setPurchaserAddress(wordResultDTO.getPurchaserAddress().getWord());
                resp.setSalerPhone(wordResultDTO.getSalerPhone().getWord()); //卖方电话
                resp.setUsedCarMarket(wordResultDTO.getUsedCarMarket().getWord()); //二手车市场
                resp.setInvoiceNum(wordResultDTO.getInvoiceNum().getWord()); //发票号码
                return R.ok().setData(resp);
            }
        }
        return R.error(bR.getErrorMsg());
    }


}
