package com.heyu.api.controller.financial;

import com.heyu.api.baidu.handle.financial.BTollInvoiceHandle;
import com.heyu.api.baidu.request.financial.BTollInvoiceRequest;
import com.heyu.api.baidu.response.financial.BTollInvoiceResp;
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.financial.TollInvoiceResp;
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/?_=1740575657628&timestamp=1740578911257#/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%2Ftoll_invoice&method=post
 * <p>
 * 过路过桥费发票识别
 *
 * 接口描述
 * 支持对全国范围不同版式过路、过桥费发票的发票代码、发票号码、入口、出口、日期、时间、金额、省、市9个字段进行结构化识别。
 *
 *
 *
 *
 */
@Slf4j
@RestController
@RequestMapping("/toll/invoice")
@NotIntercept
public class TollInvoiceController extends BaseController {


    @Autowired
    private BTollInvoiceHandle bTollInvoiceHandle;


    @RequestMapping("/recognize")
    @CacheResult
    public R recognize(BTollInvoiceRequest req) {
        TollInvoiceResp resp = new TollInvoiceResp();

        ApiR<BTollInvoiceResp> bR = bTollInvoiceHandle.handle(req);
        if (bR.isSuccess()) {
            BTollInvoiceResp bTollInvoiceResp = bR.getData();

            BTollInvoiceResp.WordsResultDTO wordsResultDTO = bTollInvoiceResp.getWordsResult();
            resp.setEntrance(wordsResultDTO.getEntrance());                //	入口
            resp.setTime(wordsResultDTO.getTime());                    //时间
            resp.setInvoiceCode(wordsResultDTO.getInvoiceCode());             //发票代码
            resp.setDate(wordsResultDTO.getDate());                    //日期
            resp.setExit(wordsResultDTO.getExit());                        //	出口
            resp.setFare(wordsResultDTO.getFare());                //金额
            resp.setInvoiceNum(wordsResultDTO.getInvoiceNum());                  //发票号码
            resp.setCity(wordsResultDTO.getCity());                //	市
            resp.setProvince(wordsResultDTO.getProvince());            //省
            return R.ok().setData(resp);
        }
        return R.error();
    }

}
