package com.heyu.api.controller.certificate;


import com.heyu.api.baidu.handle.certificate.BFoodBusinessLicenseHandle;
import com.heyu.api.baidu.request.certificate.BFoodBusinessLicenseRequest;
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.FoodBusinessLicenseResp;
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=1740323343124#/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%2Ffood_business_license&method=post
 * <p>
 * <p>
 * 食品经营许可证识别
 *
 *接口描述
 * 支持对食品经营许可证进行结构化识别，包括经营者名称、社会信用代码、法定代表人、住所、经营场所、主体业态、经营项目、有效期至、许可证编号、
 * 日常监督管理机构、日常监督管理人员、发证机关、签发人、签发日期，全部 14 个字段。
 *
 */
@Slf4j
@RestController
@RequestMapping("/foodBusinessLicense")
@NotIntercept
public class FoodBusinessLicenseController {


    @Autowired
    private BFoodBusinessLicenseHandle bFoodBusinessLicenseHandle;


    @RequestMapping("/recognize")
    @CacheResult
    public R recognize(BFoodBusinessLicenseRequest request) {
        FoodBusinessLicenseResp resp = new FoodBusinessLicenseResp();
        ApiR<Map> bR = bFoodBusinessLicenseHandle.handle(request);
        if (bR.isSuccess()) {
            Map<String, Object> data = bR.getData();

            resp.setBusinessName(MapUtils.getByExpr(data, "words_result.经营者名称.word"));
            resp.setBusinessSite(MapUtils.getByExpr(data, "words_result.经营场所.word"));
            resp.setDaySupervisionUnit(MapUtils.getByExpr(data, "words_result.日常监督管理机构.word"));
            resp.setDaySupervisionPerson(MapUtils.getByExpr(data, "words_result.日常监督管理人员.word"));
            resp.setIssuanceDate(MapUtils.getByExpr(data, "words_result.签发日期.word"));
            resp.setBusinessProject(MapUtils.getByExpr(data, "words_result.经营项目.word"));
            resp.setValidDateEnd(MapUtils.getByExpr(data, "words_result.有效期至.word"));
            resp.setLicenseNumber(MapUtils.getByExpr(data, "words_result.许可证编号.word"));
            resp.setLegalPerson(MapUtils.getByExpr(data, "words_result.法定代表人.word"));
            resp.setSocialCreditCode(MapUtils.getByExpr(data, "words_result.社会信用代码.word"));
            resp.setAddress(MapUtils.getByExpr(data, "words_result.住所.word"));
            resp.setIssuingAuthority(MapUtils.getByExpr(data, "words_result.发证机关.word"));
            resp.setMainBusiness(MapUtils.getByExpr(data, "words_result.主体业态.word"));
            resp.setIssuingPerson(MapUtils.getByExpr(data, "words_result.签发人.word"));
            return R.ok().setData(resp);

        }
        return R.error();
    }

}
