package org.dromara.controller.common;


import cn.dev33.satoken.annotation.SaCheckPermission;
import org.dromara.common.core.domain.IdCardVo;
import org.dromara.common.core.domain.R;
import org.dromara.common.core.utils.IdCardUtil;
import org.dromara.common.idempotent.annotation.RepeatSubmit;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * @Author: tjf
 * @Date: 2024/4/22 14:24
 * @Describe:
 */
@RestController
@RequestMapping("/ocr")
public class OcrController {

    /**
     * 身份证识别
     *
     * @return
     */
    @PostMapping("/ocrIdCard")
    @RepeatSubmit(interval = 1000, message = "请求过于频繁")
    public R<Map<String, Object>> ocrIdCard(@RequestBody IdCardVo idCardVo) {
        return IdCardUtil.idCard(idCardVo.getImage(), idCardVo.getIdCardSide());
    }

    /**
     * 营业执照识别
     *
     * @return
     */
    @PostMapping("/ocrBusinessLicense")
    @RepeatSubmit(interval = 1000, message = "请求过于频繁")
    @SaCheckPermission("wuYe:ocr:ocrBusinessLicense")
    public R<Map<String, Object>> ocrBusinessLicense(@RequestBody IdCardVo idCardVo) {
        return IdCardUtil.businessLicense(idCardVo.getImage());
    }

    /**
     * 车牌照识别
     *
     * @return
     */
    @PostMapping("/licensePlate")
    @RepeatSubmit(interval = 1000, message = "请求过于频繁")
    @SaCheckPermission("wuYe:ocr:licensePlate")
    public R<String> licensePlate(@RequestBody IdCardVo idCardVo) {
        return IdCardUtil.licensePlate(idCardVo.getImage());
    }


    /**
     * 行驶证识别
     *
     * @return
     */
    @PostMapping("/vehicleLicense")
    @RepeatSubmit(interval = 1000, message = "请求过于频繁")
    @SaCheckPermission("wuYe:ocr:vehicleLicense")
    public R<Map<String, Object>> vehicleLicense(@RequestBody IdCardVo idCardVo) {
        return IdCardUtil.vehicleLicense(idCardVo.getImage());
    }

    /**
     * 房产证识别
     *
     * @return
     */
    @PostMapping("/realEstateCertificate")
    @RepeatSubmit(interval = 1000, message = "请求过于频繁")
    @SaCheckPermission("wuYe:ocr:realEstateCertificate")
    public R<Map<String, Object>> realEstateCertificate(@RequestBody IdCardVo idCardVo) {
        return IdCardUtil.realEstateCertificate(idCardVo.getImage());
    }
}
