package com.heyu.api.controller.financial;


import com.heyu.api.baidu.handle.financial.BFerryTicketHandle;
import com.heyu.api.baidu.request.financial.BFerryTicketRequest;
import com.heyu.api.baidu.response.financial.BFerryTicketResp;
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.FerryTicketResp;
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=1740579219270#/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%2Fferry_ticket&method=post
 * <p>
 * <p>
 * 船票识别
 *
 * 接口描述
 * 对全国范围内不同版式的客运船票、货运船票进行结构化识别，包括发票代码、发票号码、发票日期、发票类型、总金额、出发地点、到达地点等7个字段。
 */
@Slf4j
@RestController
@RequestMapping("/ferry/ticket")
@NotIntercept
public class FerryTicketController extends BaseController {

    @Autowired
    private BFerryTicketHandle bFerryTicketHandle;

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

        FerryTicketResp resp = new FerryTicketResp();


        ApiR<BFerryTicketResp> bR = bFerryTicketHandle.handle(req);
        if (bR.isSuccess()) {
            BFerryTicketResp bFerryTicketResp = bR.getData();


            BFerryTicketResp.WordsResultDTO wordsResultDTO = bFerryTicketResp.getWordsResult();

            resp.setInvoiceType(wordsResultDTO.getInvoiceType());         //发票类型
            resp.setInvoiceCode(wordsResultDTO.getInvoiceCode());         // 	发票代码
            resp.setInvoiceNum(wordsResultDTO.getInvoiceNum());          //发票号码
            resp.setStartingStation(wordsResultDTO.getStartingStation());     // 	出发地点
            resp.setDestinationStation(wordsResultDTO.getDestinationStation());  //到达地点
            resp.setInvoiceDate(wordsResultDTO.getInvoiceDate());         // 开票日期
            resp.setFare(wordsResultDTO.getFare());                //	总金额


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


        return R.error();
    }


}
