package com.ruoyi.web.controller.common;


import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.IdCardVo;
import com.ruoyi.common.utils.IdCardUtil;
import org.springframework.security.access.prepost.PreAuthorize;
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;

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

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

    /**
     * 营业执照识别
     *
     * @return
     */
    @PostMapping("/ocrBusinessLicense")
    @RepeatSubmit(interval = 1000, message = "请求过于频繁")
    @PreAuthorize("@ss.hasPermi('wuYe:ocr:ocrBusinessLicense')")
    public AjaxResult ocrBusinessLicense(@RequestBody IdCardVo idCardVo) {
        return IdCardUtil.businessLicense(idCardVo.getImage());
    }

    /**
     * 车牌照识别
     *
     * @return
     */
    @PostMapping("/licensePlate")
    @RepeatSubmit(interval = 1000, message = "请求过于频繁")
    @PreAuthorize("@ss.hasPermi('wuYe:ocr:licensePlate')")
    public AjaxResult licensePlate(@RequestBody IdCardVo idCardVo) {
        return IdCardUtil.licensePlate(idCardVo.getImage());
    }


    /**
     * 行驶证识别
     *
     * @return
     */
    @PostMapping("/vehicleLicense")
    @RepeatSubmit(interval = 1000, message = "请求过于频繁")
    @PreAuthorize("@ss.hasPermi('wuYe:ocr:vehicleLicense')")
    public AjaxResult vehicleLicense(@RequestBody IdCardVo idCardVo) {
        return IdCardUtil.vehicleLicense(idCardVo.getImage());
    }

    /**
     * 房产证识别
     *
     * @return
     */
    @PostMapping("/realEstateCertificate")
    @RepeatSubmit(interval = 1000, message = "请求过于频繁")
    @PreAuthorize("@ss.hasPermi('wuYe:ocr:realEstateCertificate')")
    public AjaxResult realEstateCertificate(@RequestBody IdCardVo idCardVo) {
        return IdCardUtil.realEstateCertificate(idCardVo.getImage());
    }
}
