package com.heyu.api.controller.card;


import com.aliyun.ocr20191230.models.RecognizeCharacterResponse;
import com.heyu.api.alibaba.handle.common.text.ARecognizeCharacterHandle;
import com.heyu.api.alibaba.request.common.text.ARecognizeCharacterRequest;
import com.heyu.api.controller.BaseController;
import com.heyu.api.request.card.CharacterRecognizeRequest;
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.R;
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;


/**
 * https://next.api.aliyun.com/api/ocr/2019-12-30/RecognizeCharacter?tab=DEMO&lang=JAVA
 * 通用识别
 * <p>
 * RecognizeCharacter
 */
@Slf4j
@RestController
@RequestMapping("/character")
@NotIntercept
public class CharacterRecognizeController extends BaseController {

    @Autowired
    private ARecognizeCharacterHandle aRecognizeCharacterHandle;

    @RequestMapping("/recognize")
    @CacheResult
    public R recognize(CharacterRecognizeRequest request) {
        ARecognizeCharacterRequest arRecognizeCharacterRequest = new ARecognizeCharacterRequest();
        arRecognizeCharacterRequest.setImageUrl(request.getImageUrl());
        arRecognizeCharacterRequest.setImageBase64(request.getImageBase64());
        ApiR<RecognizeCharacterResponse> aR = aRecognizeCharacterHandle.handle(arRecognizeCharacterRequest);
        return R.ok().setData(aR.getData());
    }
}
