|
@@ -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;
|
|
|
}
|