package com.heyu.api.controller.financial;


import com.heyu.api.baidu.handle.financial.BQuotaInvoiceHandle;
import com.heyu.api.baidu.request.financial.BQuotaInvoiceRequest;
import com.heyu.api.baidu.response.financial.BQuotaInvoiceResp;
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.QuotaInvoiceResp;
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=1740576567910#/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%2Fquota_invoice&method=post
 *
 *
 * 定额发票识别
 *
 * 接口描述
 * 支持对各类定额发票的发票代码、发票号码、金额、发票所在地、发票金额小写、省、市7个关键字段进行结构化识别。
 *
 */

@Slf4j
@RestController
@RequestMapping("/v2/quota/invoice")
@NotIntercept
public class QuotaInvoiceController extends BaseController {


    @Autowired
    private BQuotaInvoiceHandle bQuotaInvoiceHandle;

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

        QuotaInvoiceResp resp = new QuotaInvoiceResp();


        ApiR<BQuotaInvoiceResp> bR = bQuotaInvoiceHandle.handle(req);
        if (bR.isSuccess()) {
            BQuotaInvoiceResp bQuotaInvoiceResp = bR.getData();

            BQuotaInvoiceResp.WordsResultDTO wordsResultDTO = bQuotaInvoiceResp.getWordsResult();


            resp.setInvoiceCode(wordsResultDTO.getInvoiceCode());
            resp.setInvoiceNumber(wordsResultDTO.getInvoiceNumber());
            resp.setInvoiceRate(wordsResultDTO.getInvoiceRate());
            resp.setInvoiceRateLowercase(wordsResultDTO.getInvoiceRateLowercase());
            resp.setProvince(wordsResultDTO.getProvince());


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


        }
        return R.error();
    }


}
