修改--服务调用次数

This commit is contained in:
tjxt 2024-07-31 15:15:06 +08:00
parent af5adc61d5
commit 1f107df266
2 changed files with 43 additions and 19 deletions

View File

@ -19,4 +19,8 @@ public class IdCardVo {
private String idNumber; private String idNumber;
} }
public void setData(Data data) {
this.data = data;
}
} }

View File

@ -68,37 +68,56 @@ public class OcrRecogServiceImpl implements IOcrRecogService {
ajax.put("data",idCardVo); ajax.put("data",idCardVo);
} catch (Exception e) { } catch (Exception e) {
log.error("调用服务失败:{}",e); log.error("调用服务失败:{}",e);
AiIdcardrecognizeResult aiIdcardrecognizeResult = AiIdcardrecognizeResult.builder()
.serviceId(1L)
.resultStatus("1")
.updateTime(LocalDateTime.now())
.recognizeTime(LocalDateTime.now())
.build();
aiIdcardrecognizeMapper.insert(aiIdcardrecognizeResult);
ajax.put("601", "调用服务出错"); ajax.put("601", "调用服务出错");
} }
if (idCardVo.getData() != null) { if (idCardVo.getData() != null) {
char ifComplete = '否'; char ifComplete = '否';
if (idCardVo.getCode() == 20000) { if (idCardVo.getCode() == 20000) {
ifComplete = '是'; ifComplete = '是';
} }
String idNumber = idCardVo.getData().getIdNumber(); if (idCardVo.getCode() != 20000 && idCardVo.getCode() != 20001) {
String currentDate = System.currentTimeMillis()+""; AiIdcardrecognizeResult aiIdcardrecognizeResult = AiIdcardrecognizeResult.builder()
String frontFileName = String.format(FRONT_FILE_NAME_TEMPLATE, idNumber, currentDate); .serviceId(1L)
String backFileName = String.format(BACK_FILE_NAME_TEMPLATE, idNumber, currentDate); .resultStatus("1")
try { .updateTime(LocalDateTime.now())
byte[] frontImageBytes = Base64.getDecoder().decode(getfilePath[0]); .recognizeTime(LocalDateTime.now())
byte[] backImageBytes = Base64.getDecoder().decode(getfilePath[1]); .build();
Path frontFilePath = Paths.get(directoryPath, frontFileName); aiIdcardrecognizeMapper.insert(aiIdcardrecognizeResult);
Path backFilePath = Paths.get(directoryPath, backFileName); }
Files.write(frontFilePath, frontImageBytes); else {
Files.write(backFilePath, backImageBytes); String idNumber = idCardVo.getData().getIdNumber();
} catch (IOException e) { String currentDate = System.currentTimeMillis() + "";
log.error("获取身份证信息出错:{}",e); String frontFileName = String.format(FRONT_FILE_NAME_TEMPLATE, idNumber, currentDate);
ajax.put("602", "获取身份证信息出错"); String backFileName = String.format(BACK_FILE_NAME_TEMPLATE, idNumber, currentDate);
e.printStackTrace(); try {
byte[] frontImageBytes = Base64.getDecoder().decode(getfilePath[0]);
byte[] backImageBytes = Base64.getDecoder().decode(getfilePath[1]);
Path frontFilePath = Paths.get(directoryPath, frontFileName);
Path backFilePath = Paths.get(directoryPath, backFileName);
Files.write(frontFilePath, frontImageBytes);
Files.write(backFilePath, backImageBytes);
} catch (IOException e) {
log.error("获取身份证信息出错:{}", e);
ajax.put("602", "获取身份证信息出错");
e.printStackTrace();
}
String resultStatus = "0";
saveRecognitionResult(idCardVo, ifComplete, frontFileName, backFileName, startTime, resultStatus);
} }
saveRecognitionResult(idCardVo, ifComplete, frontFileName, backFileName,startTime);
} }
log.info("服务层返回给控制层的数据:{}",ajax); log.info("服务层返回给控制层的数据:{}",ajax);
return ajax; return ajax;
} }
public String[] convertFilesToBase64(MultipartFile[] files) { public String[] convertFilesToBase64(MultipartFile[] files) throws IOException {
String[] base64Strings = new String[files.length]; String[] base64Strings = new String[files.length];
for (int i = 0; i < files.length; i++) { for (int i = 0; i < files.length; i++) {
MultipartFile file = files[i]; MultipartFile file = files[i];
@ -138,7 +157,7 @@ public class OcrRecogServiceImpl implements IOcrRecogService {
log.info("获取python服务得到的数据{}",idCardVo); log.info("获取python服务得到的数据{}",idCardVo);
return idCardVo; return idCardVo;
} }
private void saveRecognitionResult(IdCardVo idCardVo, char ifComplete, String frontFileName, String backFileName,long startTime) { private void saveRecognitionResult(IdCardVo idCardVo, char ifComplete, String frontFileName, String backFileName,long startTime,String resultStatus) {
String idNumber = idCardVo.getData().getIdNumber(); String idNumber = idCardVo.getData().getIdNumber();
// 从SecurityUtils.getLoginUser()获取登录用户信息 // 从SecurityUtils.getLoginUser()获取登录用户信息
LoginUser loginUser = SecurityUtils.getLoginUser(); LoginUser loginUser = SecurityUtils.getLoginUser();
@ -165,6 +184,7 @@ public class OcrRecogServiceImpl implements IOcrRecogService {
.invokeIp(IpUtils.getIpAddr(ServletUtils.getRequest())) .invokeIp(IpUtils.getIpAddr(ServletUtils.getRequest()))
.updateBy(String.valueOf(loginUser.getUserid())) // 假设getUserid()已返回正确用户ID .updateBy(String.valueOf(loginUser.getUserid())) // 假设getUserid()已返回正确用户ID
.updateTime(LocalDateTime.now()) .updateTime(LocalDateTime.now())
.resultStatus(resultStatus)
.build(); .build();
aiIdcardrecognizeMapper.insert(aiIdcardrecognizeResult); aiIdcardrecognizeMapper.insert(aiIdcardrecognizeResult);
} }