package com.heyu.api.controller.financial;

import com.heyu.api.baidu.handle.financial.BTaxiReceiptHandle;
import com.heyu.api.baidu.request.financial.BTaxiReceiptRequest;
import com.heyu.api.baidu.response.financial.BTaxiReceiptResp;
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.financial.TaxiReceiptResp;
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>
 * https://console.bce.baidu.com/support/?_=1740575657628&timestamp=1740577722254#/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%2Ftaxi_receipt&method=post
 * <p>
 * <p>
 * 出租车票识别
 *
 *
 * 接口描述
 * 支持识别全国各大城市出租车票的 16 个关键字段，包括发票号码、代码、车号、日期、总金额、燃油附加费、叫车服务费、省、市、单价、里程、上车时间、下车时间等。
 */


@Slf4j
@RestController
@RequestMapping("/taxi/receipt")
@NotIntercept
public class TaxiReceiptController {


    @Autowired
    private BTaxiReceiptHandle bTaxiReceiptHandle;

    @RequestMapping("/recognize")
    @CacheResult
    public R recognize(BTaxiReceiptRequest req) {

        TaxiReceiptResp resp = new TaxiReceiptResp();


        ApiR<BTaxiReceiptResp> bR = bTaxiReceiptHandle.handle(req);
        if (bR.isSuccess()) {

            BTaxiReceiptResp bTaxiReceiptResp = bR.getData();
            BTaxiReceiptResp.WordsResultDTO wordsResultDTO = bTaxiReceiptResp.getWordsResult();


            resp.setDate(wordsResultDTO.getDate());                //	日期
            resp.setFare(wordsResultDTO.getFare());                //	金额
            resp.setLocation(wordsResultDTO.getLocation());                    //开票城市
            resp.setInvoiceCode(wordsResultDTO.getInvoiceCode());                 //	发票代码
            resp.setInvoiceNum(wordsResultDTO.getInvoiceNum());                      //发票号码
            resp.setTaxiNum(wordsResultDTO.getTaxiNum());                 //	车牌号
            resp.setTime(wordsResultDTO.getTime());                        //上下车时间
            resp.setPickupTime(wordsResultDTO.getPickupTime());                  //	上车时间
            resp.setDropoffTime(wordsResultDTO.getDropoffTime()); //下车时间
            resp.setFuelOilSurcharge(wordsResultDTO.getFuelOilSurcharge()); //燃油附加费
            resp.setCallServiceSurcharge(wordsResultDTO.getCallServiceSurcharge());                //叫车服务费
            resp.setTotalFare(wordsResultDTO.getTotalFare());                           //总金额
            resp.setProvince(wordsResultDTO.getProvince());                            //	省
            resp.setCity(wordsResultDTO.getCity());                            //	市
            resp.setPricePerkm(wordsResultDTO.getPricePerkm());                          //	单价
            resp.setDistance(wordsResultDTO.getDistance());                //里程
            return R.ok().setData(resp);
        }

        return R.error(bR.getErrorMsg());
    }


}
