package com.heyu.api.controller.certificate;


import com.heyu.api.baidu.handle.certificate.BAccountOpeningHandle;
import com.heyu.api.baidu.request.certificate.BAccountOpeningRequest;
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.certificate.AccountOpeningResp;
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/?_=1740219852952&timestamp=1740322721909#/api?product=AI&project=%E6%96%87%E5%AD%97%E8%AF%86%E5%88%AB&parent=%E5%8D%A1%E8%AF%81OCR&api=rest%2F2.0%2Focr%2Fv1%2Faccount_opening&method=post
 * <p>
 * <p>
 * 开户许可证识别
 */


@Slf4j
@RestController
@RequestMapping("/account")
@NotIntercept
public class AccountOpeningController {


    @Autowired
    private BAccountOpeningHandle bAccountOpeningHandle;


    @RequestMapping("/opening")
    @CacheResult
    public R recognize(BAccountOpeningRequest request) {
        AccountOpeningResp accountOpeningResp = new AccountOpeningResp();
        ApiR<Map> bR = bAccountOpeningHandle.handle(request);
        if (bR.isSuccess()) {
            Map<String, Object> data = bR.getData();
            accountOpeningResp.setAccount(MapUtils.getByExpr(data, "words_result.账号.word.[0]"));
            accountOpeningResp.setCompanyName(MapUtils.getByExpr(data, "words_result.公司名称.word.[0]"));
            accountOpeningResp.setCheckNumber(MapUtils.getByExpr(data, "words_result.核准号.word.[0]"));
            accountOpeningResp.setLegalPerson(MapUtils.getByExpr(data, "words_result.法人.word.[0]"));
            accountOpeningResp.setSerialNumber(MapUtils.getByExpr(data, "words_result.编号.word.[0]"));
            accountOpeningResp.setOpenAccountBank(MapUtils.getByExpr(data, "words_result.开户银行.word.[0]"));
            return R.ok().setData(accountOpeningResp);
        }
        return R.error();
    }
}
