package com.heyu.api.controller.financial;


import com.heyu.api.baidu.handle.financial.BBusTicketHandle;
import com.heyu.api.baidu.request.financial.BBusTicketRequest;
import com.heyu.api.baidu.response.financial.BBusTicketResp;
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.BusTicketResp;
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=1740578576329#/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%2Fbus_ticket&method=post
 * 汽车票识别
 *
 *
 * 接口描述
 * 支持对全国范围不同版式汽车票的发票代码、发票号码、到达站、出发站、日期、时间、金额、身份证号、姓名、开票日期10个字段进行结构化识别。
 *
 */

@Slf4j
@RestController
@RequestMapping("/bus/ticket")
@NotIntercept
public class BusTicketController extends BaseController {


    @Autowired
    private BBusTicketHandle bBusTicketHandle;


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

        BusTicketResp resp = new BusTicketResp();
        ApiR<BBusTicketResp> bR = bBusTicketHandle.handle(req);

        if (bR.isSuccess()) {
            BBusTicketResp bBusTicketResp = bR.getData();
            BBusTicketResp.WordsResultDTO wordsResultDTO = bBusTicketResp.getWordsResult();

            resp.setDestinationStation(wordsResultDTO.getDestinationStation()); // 	到达站
            resp.setIdNum(wordsResultDTO.getIdNum());// 身份证号
            resp.setTime(wordsResultDTO.getTime());        //时间
            resp.setInvoiceCode(wordsResultDTO.getInvoiceCode());     //发票代码
            resp.setInvoiceNum(wordsResultDTO.getInvoiceNum());      //	发票号码
            resp.setStartingStation(wordsResultDTO.getStartingStation());     //出发站
            resp.setDate(wordsResultDTO.getDate());            //日期
            resp.setName(wordsResultDTO.getName());            //姓名
            resp.setFare(wordsResultDTO.getFare());            //金额

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

}













