package com.cweb.controller;

import com.alibaba.fastjson.JSONObject;
import com.hfkj.common.exception.ErrorCode;
import com.hfkj.common.exception.ErrorHelp;
import com.hfkj.common.exception.SysCode;
import com.hfkj.common.security.*;
import com.hfkj.common.utils.MD5Util;
import com.hfkj.common.utils.ResponseMsgUtil;
import com.hfkj.entity.*;
import com.hfkj.model.MenuTreeModel;
import com.hfkj.model.ResponseData;
import com.hfkj.model.UserInfoModel;
import com.hfkj.ocr.AliYunOcrService;
import com.hfkj.service.*;
import com.hfkj.sysenum.AgentStatusEnum;
import com.hfkj.sysenum.SalesmanStatusEnum;
import com.hfkj.sysenum.SecUserTypeEnum;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.Objects;

@Controller
@RequestMapping(value = "/ocr")
@Api(value = "ocr识别")
public class OcrController {

    private static Logger log = LoggerFactory.getLogger(OcrController.class);

    @Resource
    private UserCenter userCenter;

    @RequestMapping(value="/recognizeIdCard",method = RequestMethod.GET)
    @ResponseBody
    @ApiOperation(value = "身份证识别")
    public ResponseData recognizeIdCard(@RequestParam(name = "url", required = true) String url) {
        try {
            return ResponseMsgUtil.success(AliYunOcrService.recognizeIdCard(url));
        } catch (Exception e) {
            log.error("recognizeIdCard error!",e);
            return ResponseMsgUtil.exception(e);
        }
    }

    @RequestMapping(value="/recognizeBankCard",method = RequestMethod.GET)
    @ResponseBody
    @ApiOperation(value = "银行卡识别")
    public ResponseData recognizeBankCard(@RequestParam(name = "url", required = true) String url) {
        try {
            return ResponseMsgUtil.success(AliYunOcrService.recognizeBankCard(url));
        } catch (Exception e) {
            log.error("recognizeBankCard error!",e);
            return ResponseMsgUtil.exception(e);
        }
    }

    @RequestMapping(value="/recognizeBankAccount",method = RequestMethod.GET)
    @ResponseBody
    @ApiOperation(value = "银行开户许可证识别")
    public ResponseData recognizeBankAccount(@RequestParam(name = "url", required = true) String url) {
        try {
            return ResponseMsgUtil.success(AliYunOcrService.recognizeBankAccount(url));
        } catch (Exception e) {
            log.error("recognizeBankCard error!",e);
            return ResponseMsgUtil.exception(e);
        }
    }

    @RequestMapping(value="/recognizeBusinessLicense",method = RequestMethod.GET)
    @ResponseBody
    @ApiOperation(value = "营业执照识别")
    public ResponseData recognizeBusinessLicense(@RequestParam(name = "url", required = true) String url) {
        try {
            return ResponseMsgUtil.success(AliYunOcrService.recognizeBusinessLicense(url));
        } catch (Exception e) {
            log.error("recognizeBusinessLicense error!",e);
            return ResponseMsgUtil.exception(e);
        }
    }
}
