OcrController.java 1.38 KB
//package com.xly.ocr.web;
//
//import com.xly.ocr.service.OcrService;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.http.ResponseEntity;
//import org.springframework.web.bind.annotation.*;
//import org.springframework.web.multipart.MultipartFile;
//
//import java.util.HashMap;
//import java.util.List;
//import java.util.Map;
//
//@RestController
//@RequestMapping("/api/ocr")
//public class OcrController {
//
//    @Autowired
//    private OcrService ocrService;
//
//    @PostMapping("/extract")
//    public ResponseEntity<Map<String, Object>> extractText(
//            @RequestParam("file") MultipartFile file) {
//
//        Map<String, Object> response = new HashMap<>();
//        long startTime = System.currentTimeMillis();
//
//        String result = ocrService.extractTextFromMultipartFile(file);
//
//        response.put("text", result);
//        response.put("time", System.currentTimeMillis() - startTime);
//        response.put("success", !result.startsWith("错误") && !result.startsWith("失败"));
//
//        return ResponseEntity.ok(response);
//    }
//
//    @PostMapping("/batch")
//    public ResponseEntity<List<String>> batchExtract(
//            @RequestParam("files") List<MultipartFile> files) {
//        List<String> results = ocrService.batchExtractText(files);
//        return ResponseEntity.ok(results);
//    }
//}