package com.heyu.api.controller.traffic;

import com.heyu.api.baidu.handle.traffic.BRoadTransportCertificateHandle;
import com.heyu.api.baidu.request.traffic.BRoadTransportCertificateRequest;
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.traffic.RoadTransportCertificateResp;
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/?_=1740411162437&timestamp=1740413029871#/api?product=AI&project=%E6%96%87%E5%AD%97%E8%AF%86%E5%88%AB&parent=%E4%BA%A4%E9%80%9A%E5%9C%BA%E6%99%AFOCR&api=rest%2F2.0%2Focr%2Fv1%2Froad_transport_certificate&method=post
 * <p>
 * <p>
 * 道路运输证识别
 *
 *接口描述
 * 结构化识别道路运输证的业户名称、地址、车辆号牌、经营许可证、经济类型、车辆类型、吨座位、车辆规格、经营范围、初领日期、备注、发证日期、道路运输证号等15个关键字段，支持识别横版及竖版两种道路运输证
 *
 */
@Slf4j
@RestController
@RequestMapping("/road/transport")
@NotIntercept
public class RoadTransportCertificateController extends BaseController {


    @Autowired
    private BRoadTransportCertificateHandle bRoadTransportCertificateHandle;


    @RequestMapping("/recognize")
    @CacheResult
    public R recognize(BRoadTransportCertificateRequest request) {

        RoadTransportCertificateResp resp = new RoadTransportCertificateResp();

        ApiR<Map> bR = bRoadTransportCertificateHandle.handle(request);

        if (bR.isSuccess()) {
            Map<String, Object> data = bR.getData();

            resp.setRoadTransportLicenseNumber(MapUtils.getByExpr(data, "words_result.道路运输证号.[0].word")); // 道路运输证号
            resp.setVehicleLicensePlate(MapUtils.getByExpr(data, "words_result.车辆号牌.[0].word"));  // 车辆号牌
            resp.setEconomicType(MapUtils.getByExpr(data, "words_result.经济类型.[0].word"));        //经济类型
            resp.setBusinessScope(MapUtils.getByExpr(data, "words_result.经营范围.[0].word")); // 经营范围
            resp.setVehicleType(MapUtils.getByExpr(data, "words_result.车辆类型.[0].word"));   //车辆类型
            resp.setTonsOfSeats(MapUtils.getByExpr(data, "words_result.吨座位.[0].word")); // 吨座位
            resp.setRemark(MapUtils.getByExpr(data, "words_result.备注.[0].word"));//备注
            resp.setBusinessLicense(MapUtils.getByExpr(data, "words_result.经营许可证.[0].word")); // 经营许可证
            resp.setVehicleMMH(MapUtils.getByExpr(data, "words_result.车辆毫米_高.[0].word")); // 车辆毫米_高
            resp.setVehicleMMWidth(MapUtils.getByExpr(data, "words_result.车辆毫米_宽.[0].word"));//车辆毫米_宽
            resp.setCertificateIssuanceDate(MapUtils.getByExpr(data, "words_result.发证日期.[0].word")); // 发证日期
            resp.setAddress(MapUtils.getByExpr(data, "words_result.地址.[0].word"));//地址
            resp.setVehicleMMLength(MapUtils.getByExpr(data, "words_result.车辆毫米_长.[0].word"));// 车辆毫米_长
            resp.setBusinessAccountName(MapUtils.getByExpr(data, "words_result.业户名称.[0].word")); // 业户名称
            resp.setFirstDate(MapUtils.getByExpr(data, "words_result.初领日期.[0].word")); // 初领日期

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

        }

        return R.error(bR.getErrorMsg());
    }


}
