|
|
@ -197,7 +197,7 @@ public class OcrService implements IOcrService { |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
public List<QuestionOcrVo.CodeAndAnswer> discernWords(List<MultipartFile> param, Long userId,Long projectId) throws IOException, ParseException { |
|
|
|
public Map<String,Set<QuestionOcrVo.CodeAndAnswer>> discernWords(List<MultipartFile> param, Long userId,Long projectId) throws IOException, ParseException { |
|
|
|
// FirstAid firstAidInfo = firstAidDao.selectByPrimaryKey(firstAidId);
|
|
|
|
FirstAid firstAidInfo = firstAidDao.queryByProjectId(projectId); |
|
|
|
if (ObjectUtil.isNull(firstAidInfo)) { |
|
|
@ -208,7 +208,7 @@ public class OcrService implements IOcrService { |
|
|
|
List<OcrKeyword> ocrKeywordList = ocrKeywordDao.queryByHospital(firstAidInfo.getHospitalId()); |
|
|
|
log.info("规则:{}", ocrKeywordList); |
|
|
|
if (ObjectUtil.isNull(ocrKeywordList)) { |
|
|
|
return resultList; |
|
|
|
return new HashMap<>(); |
|
|
|
} |
|
|
|
SimpleDateFormat frontTime = new SimpleDateFormat("yy-MM-ddHH:mm"); |
|
|
|
String frontReg = "\\d{1,2}-\\d{1,2}-\\d{2,4}:\\d{1,2}"; |
|
|
@ -225,6 +225,14 @@ public class OcrService implements IOcrService { |
|
|
|
//识别图片,放入文字集合
|
|
|
|
List<String> strList = new ArrayList<>(); |
|
|
|
Long startOcr = System.currentTimeMillis(); |
|
|
|
log.info("接收到的文件{}",param); |
|
|
|
if (CollectionUtil.isNotEmpty(param)) { |
|
|
|
if (param.get(param.size()-1).getOriginalFilename().equals(param.get(param.size()-2).getOriginalFilename())) { |
|
|
|
log.info("已删除相同文件"); |
|
|
|
param.remove(param.size()-1); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
for (MultipartFile file : param) { |
|
|
|
ByteArrayOutputStream out = new ByteArrayOutputStream(); |
|
|
|
ImageUtil.scale(ImageIO.read(file.getInputStream()), out, 1); |
|
|
@ -254,7 +262,7 @@ public class OcrService implements IOcrService { |
|
|
|
Long ocrEnd = System.currentTimeMillis(); |
|
|
|
log.info("识图+保存文件花费时间{}",ocrEnd-startOcr); |
|
|
|
if (CollectionUtil.isEmpty(strList)) { |
|
|
|
return resultList; |
|
|
|
return new HashMap<>(); |
|
|
|
} |
|
|
|
//TODO 查询出院时间 (暂时没有根据医院id查询)
|
|
|
|
OcrKeyword dischargeTime = ocrKeywordDao.queryDischargeTime(firstAidInfo.getHospitalId()); |
|
|
@ -366,7 +374,8 @@ public class OcrService implements IOcrService { |
|
|
|
long endTimestamp = 0L; |
|
|
|
if (backMatcher.find()) { |
|
|
|
String endTime = backMatcher.group(); |
|
|
|
endTimestamp = backTime.parse(year + endTime).getTime(); |
|
|
|
String endTimeNew = endTime.replaceAll("[[\\s-:punct:]]", ""); |
|
|
|
endTimestamp = backTime.parse(year + endTimeNew).getTime(); |
|
|
|
} |
|
|
|
//将code与答案保存到结果集合
|
|
|
|
giveCodeAndAnswer(resultList,ocrKeyword.getId(),(byte)0,newStr,strList.get(i),endTimestamp,timeOfDischarge); |
|
|
@ -388,9 +397,19 @@ public class OcrService implements IOcrService { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
ArrayList<QuestionOcrVo.CodeAndAnswer> newList = resultList.stream().collect(Collectors |
|
|
|
.collectingAndThen(Collectors.toCollection(() -> new TreeSet<>(Comparator.comparing(QuestionOcrVo.CodeAndAnswer::getAnswer))), ArrayList::new)); |
|
|
|
return newList; |
|
|
|
|
|
|
|
Map<String, List<QuestionOcrVo.CodeAndAnswer>> resultGroup = resultList.stream().collect(Collectors.groupingBy(QuestionOcrVo.CodeAndAnswer::getCode)); |
|
|
|
Map<String,Set<QuestionOcrVo.CodeAndAnswer>> resultSet = new HashMap<>(); |
|
|
|
for (String key : resultGroup.keySet()) { |
|
|
|
resultSet.put(key,new HashSet<>(resultGroup.get(key))); |
|
|
|
} |
|
|
|
|
|
|
|
// ArrayList<QuestionOcrVo.CodeAndAnswer> newList = resultList.stream().collect(Collectors
|
|
|
|
// .collectingAndThen(Collectors.toCollection(() -> new TreeSet<>(Comparator.comparing(QuestionOcrVo.CodeAndAnswer::getAnswer))), ArrayList::new));
|
|
|
|
|
|
|
|
// Map<String, List<QuestionOcrVo.CodeAndAnswer>> collect = newList.stream().collect(Collectors.groupingBy(QuestionOcrVo.CodeAndAnswer::getCode));
|
|
|
|
return resultSet; |
|
|
|
// return newList;
|
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|