Selaa lähdekoodia

联调bug修改

xiaof 2 vuotta sitten
vanhempi
commit
7540f2d300

+ 1 - 1
paper-library-business/src/main/java/com/qmth/paper/library/business/mapper/PaperLibraryMapper.java

@@ -29,7 +29,7 @@ public interface PaperLibraryMapper extends BaseMapper<PaperLibrary> {
 
     List<PaperLibrary> selectBatchData(@Param("schoolId") Long schoolId, @Param("userId") Long userId);
 
-    List<TaskStudentResult> listByStudentCode(@Param("schoolId") Long schoolId, @Param("studentCode") String studentCode);
+    IPage<TaskStudentResult> listByStudentCode(@Param("page") Page<TaskStudentResult> page, @Param("schoolId") Long schoolId, @Param("studentCode") String studentCode);
 
     IPage<TaskStudentResult> pageStudent(@Param("objectPage") Page<Object> objectPage, @Param("schoolId") Long schoolId, @Param("paperScanTaskId") Long paperScanTaskId, @Param("param") String param);
 }

+ 1 - 1
paper-library-business/src/main/java/com/qmth/paper/library/business/service/PaperLibraryService.java

@@ -29,7 +29,7 @@ public interface PaperLibraryService extends IService<PaperLibrary> {
 
     List<PaperLibraryResult> toBindPaper();
 
-    List<TaskStudentResult> listByStudentCode(String studentCode);
+    IPage<TaskStudentResult> listByStudentCode(String studentCode, Integer pageNumber, Integer pageSize);
 
     int countScanCount(Long paperScanTaskId);
 

+ 8 - 3
paper-library-business/src/main/java/com/qmth/paper/library/business/service/impl/PaperLibraryCommonServiceImpl.java

@@ -1,5 +1,6 @@
 package com.qmth.paper.library.business.service.impl;
 
+import cn.hutool.core.io.IoUtil;
 import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
@@ -24,6 +25,7 @@ import com.qmth.paper.library.common.util.RedisUtil;
 import com.qmth.paper.library.common.util.ResultUtil;
 import com.qmth.paper.library.common.util.ServletUtil;
 import org.apache.commons.codec.digest.DigestUtils;
+import org.apache.commons.io.FileUtils;
 import org.apache.commons.io.IOUtils;
 import org.apache.commons.lang3.StringUtils;
 import org.slf4j.Logger;
@@ -34,7 +36,10 @@ import org.springframework.transaction.annotation.Transactional;
 import org.springframework.web.multipart.MultipartFile;
 
 import javax.annotation.Resource;
-import java.io.*;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
 import java.math.BigDecimal;
 import java.time.LocalDateTime;
 import java.util.*;
@@ -383,8 +388,8 @@ public class PaperLibraryCommonServiceImpl implements PaperLibraryCommonService
                     localFile.getParentFile().mkdirs(); //目标文件目录不存在的话需要创建目录
                     localFile.createNewFile();
                 }
-                IOUtils.copy(new FileInputStream(file), new FileOutputStream(localFile));
-                return file;
+                FileUtils.copyFile(file, localFile);
+                return localFile;
             } catch (IOException e) {
                 throw ExceptionResultEnum.ERROR.exception("本地复制文件失败");
             }

+ 18 - 16
paper-library-business/src/main/java/com/qmth/paper/library/business/service/impl/PaperLibraryServiceImpl.java

@@ -26,6 +26,7 @@ import com.qmth.paper.library.common.util.ImageUtil;
 import com.qmth.paper.library.common.util.OcrUtil;
 import com.qmth.paper.library.common.util.ServletUtil;
 import org.apache.commons.lang3.StringUtils;
+import org.json.JSONArray;
 import org.json.JSONException;
 import org.springframework.beans.BeanUtils;
 import org.springframework.stereotype.Service;
@@ -173,12 +174,12 @@ public class PaperLibraryServiceImpl extends ServiceImpl<PaperLibraryMapper, Pap
     }
 
     @Override
-    public List<TaskStudentResult> listByStudentCode(String studentCode) {
+    public IPage<TaskStudentResult> listByStudentCode(String studentCode, Integer pageNumber, Integer pageSize) {
         if (StringUtils.isBlank(studentCode)) {
             throw ExceptionResultEnum.ERROR.exception("请输入考号");
         }
         Long schoolId = Long.valueOf(ServletUtil.getRequestHeaderSchoolId().toString());
-        return this.baseMapper.listByStudentCode(schoolId, studentCode);
+        return this.baseMapper.listByStudentCode(new Page<>(pageNumber, pageSize), schoolId, studentCode);
     }
 
     @Override
@@ -225,25 +226,26 @@ public class PaperLibraryServiceImpl extends ServiceImpl<PaperLibraryMapper, Pap
         }
         try {
             org.json.JSONObject callHandwriting = ocrUtil.callHandwriting(subFile.getPath());
-            String wordsResult = callHandwriting.getString(SystemConstant.OCR_WORDS_RESULT);
-            if (StringUtils.isNotBlank(wordsResult)) {
-                List<JSONObject> wordsResultList = JSON.parseArray(wordsResult, JSONObject.class);
-                if (wordsResultList.isEmpty()) {
-                    throw ExceptionResultEnum.ERROR.exception("未正确识别出内容");
-                } else if (wordsResultList.size() != 1) {
-                    throw ExceptionResultEnum.ERROR.exception("检测出多条数据,请重新设置识别区");
-                } else {
-                    JSONObject object = wordsResultList.get(0);
-                    if (object.containsKey(SystemConstant.OCR_WORDS)) {
-                        return object.getString(SystemConstant.OCR_WORDS);
-                    }
+            JSONArray jsonArray = callHandwriting.getJSONArray(SystemConstant.OCR_WORDS_RESULT);
+            if (jsonArray.length() == 0) {
+                throw ExceptionResultEnum.ERROR.exception("未正确识别出内容");
+            } else if (jsonArray.length() != 1) {
+                throw ExceptionResultEnum.ERROR.exception("检测出多条数据,请重新设置识别区");
+            } else {
+                org.json.JSONObject object = jsonArray.getJSONObject(0);
+                if (object.has(SystemConstant.OCR_WORDS)) {
+                    // 保存识别数据
+                    UpdateWrapper<PaperLibrary> updateWrapper = new UpdateWrapper<>();
+                    updateWrapper.lambda().set(PaperLibrary::getWordsResult, jsonArray.toString()).eq(PaperLibrary::getId, paperLibraryId);
+                    this.updateById(paperLibrary);
+                    return object.getString(SystemConstant.OCR_WORDS);
                 }
             }
         } catch (JSONException e) {
             throw ExceptionResultEnum.ERROR.exception(e.getMessage());
         } finally {
-            file.deleteOnExit();
-            subFile.deleteOnExit();
+            file.delete();
+            subFile.delete();
         }
         return null;
     }

+ 1 - 0
paper-library-common/src/main/java/com/qmth/paper/library/common/contant/SystemConstant.java

@@ -90,6 +90,7 @@ public class SystemConstant {
     public static final String REGULAR_EXPRESSION_OF_PHONE = "((\\d{3,4})|(\\(\\d{3,4}\\)-))?\\d{7,8}";
     public static final String REGULAR_EXPRESSION_OF_CODE_PRIMARY_DIMENSION = "[A-Z]";
     public static final String REGULAR_EXPRESSION_OF_CODE_SECOND_DIMENSION = "[A-Z][1-9][0-9]*";
+    public static final String REGULAR_EXPRESSION_OF_NUMBER = "^\\d{n}$";
 
     /**
      * oss url过期时间

+ 5 - 3
paper-library/src/main/java/com/qmth/paper/library/api/PaperLibraryController.java

@@ -99,8 +99,10 @@ public class PaperLibraryController {
     @ApiOperation(value = "根据学号查询所有任务下考生信息")
     @PostMapping("/list_by_student_code")
     @ApiResponses({@ApiResponse(code = 200, message = "查询成功", response = Result.class)})
-    public Result listByStudentCode(@ApiParam(value = "学号") @RequestParam String studentCode) {
-        return ResultUtil.ok(paperLibraryService.listByStudentCode(studentCode));
+    public Result listByStudentCode(@ApiParam(value = "学号") @RequestParam String studentCode,
+                                    @ApiParam(value = "分页页码", required = true) @RequestParam @Min(SystemConstant.PAGE_NUMBER_MIN) Integer pageNumber,
+                                    @ApiParam(value = "分页数", required = true) @RequestParam @Min(SystemConstant.PAGE_SIZE_MIN) @Max(SystemConstant.PAGE_SIZE_MAX) Integer pageSize) {
+        return ResultUtil.ok(paperLibraryService.listByStudentCode(studentCode, pageNumber, pageSize));
     }
 
     @ApiOperation(value = "OCR识别")
@@ -112,6 +114,6 @@ public class PaperLibraryController {
                       @ApiParam(value = "y") @RequestParam Integer y,
                       @ApiParam(value = "width") @RequestParam Integer width,
                       @ApiParam(value = "height") @RequestParam Integer height){
-        return ResultUtil.ok(paperLibraryService.ocr(paperLibraryId, index, x, y, width, height));
+        return ResultUtil.ok(paperLibraryService.ocr(paperLibraryId, index, x, y, width, height), null);
     }
 }

+ 2 - 2
paper-library/src/main/resources/application-dev.properties

@@ -46,9 +46,9 @@ com.qmth.fss.public.server=https://oss-file.qmth.com.cn/teachcloud-print-dev-pub
 com.qmth.fss.private.config=oss://key:secret@teachcloud-print-dev-private.oss-api.qmth.com.cn
 com.qmth.fss.private.server=https://oss-file.qmth.com.cn/teachcloud-print-dev-private
 com.qmth.fss.localfile.config=/Users/king/Downloads/file-temp
-com.qmth.fss.localfile.server=http://127.0.0.1:7001
+com.qmth.fss.localfile.server=http://192.168.10.140:8001
 com.qmth.fss.localpdf.config=/Users/king/Downloads/pdf-temp
-com.qmth.fss.localpdf.server=http://127.0.0.1:7001
+com.qmth.fss.localpdf.server=http://192.168.10.140:8001
 
 #com.qmth.api.uri-prefix=/aaa
 #\u7EDF\u8BA1\u9875\u9762\u914D\u7F6E