package com.heyu.api.controller.financial;


import com.heyu.api.baidu.handle.financial.BBankReceiptNewHandle;
import com.heyu.api.baidu.request.financial.BBankReceiptNewRequest;
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.MapUtils;
import com.heyu.api.data.utils.R;
import com.heyu.api.resp.financial.BankReceiptNewResp;
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;

import java.util.Map;


/***
 * https://console.bce.baidu.com/support/?_=1740575657628&timestamp=1742739144533#/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%2Fbank_receipt_new&method=post
 *
 *银行回单识别
 *
 *接口描述
 * 支持对不同版式银行回单进行结构化识别，包括标题、付款人户名、付款人开户银行、付款人账号、收款人户名、收款人开户银行、收款人账号、大写金额、小写金额、流水号、回单编号、交易日期、摘要、用途 14个关键字段。
 *
 *
 */
@Slf4j
@RestController
@RequestMapping("/bankReceipt")
@NotIntercept
public class BankReceiptNewController extends BaseController {


    @Autowired
    private BBankReceiptNewHandle bankReceiptNewHandle;


    @RequestMapping("/recognize")
    @CacheResult
    public R recognize(BBankReceiptNewRequest req) {
        ApiR<Map> bR = bankReceiptNewHandle.handle(req);
        if (bR.isSuccess()) {
            Map<String, Object> data = bR.getData();
            BankReceiptNewResp resp = new BankReceiptNewResp();

            resp.setTitle(MapUtils.getByExpr(data, "words_result.标题.[0].word"));// 标题
            resp.setPayPersonName(MapUtils.getByExpr(data, "words_result.付款人户名.[0].word")); // 付款人户名
            resp.setPayBankName(MapUtils.getByExpr(data, "words_result.付款人开户银行.[0].word")); //付款人开户银行
            resp.setPayAcount(MapUtils.getByExpr(data, "words_result.付款人账号.[0].word"));//付款人账号
            resp.setPayeeAcount(MapUtils.getByExpr(data, "words_result.收款人户名.[0].word")); //付款人账号
            resp.setPayeeName(MapUtils.getByExpr(data, "words_result.付款人户名.[0].word"));       //收款人户名
            resp.setPayeeBankName(MapUtils.getByExpr(data, "words_result.收款人开户银行.[0].word"));//收款人开户银行
            resp.setPayeeBankAccount(MapUtils.getByExpr(data, "words_result.收款人账号.[0].word"));    // 收款人账号
            resp.setCapsAmount(MapUtils.getByExpr(data, "words_result.大写金额.[0].word"));  // 大写金额
            resp.setLowerCaseAmount(MapUtils.getByExpr(data, "words_result.小写金额.[0].word")); // 小写金额
            resp.setSerialNumber(MapUtils.getByExpr(data, "words_result.流水号.[0].word")); // 流水号
            resp.setReplyNumber(MapUtils.getByExpr(data, "words_result.回单编号.[0].word"));// 回单编号;
            resp.setTradeDate(MapUtils.getByExpr(data, "words_result.交易日期.[0].word")); // 交易日期
            resp.setSummary(MapUtils.getByExpr(data, "words_result.摘要.[0].word"));//  摘要
            resp.setUse(MapUtils.getByExpr(data, "words_result.用途.[0].word"));//用途

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

        return R.error();
    }


}
