修改--服务调用次数
This commit is contained in:
parent
af5adc61d5
commit
1f107df266
|
|
@ -19,4 +19,8 @@ public class IdCardVo {
|
|||
private String idNumber;
|
||||
|
||||
}
|
||||
|
||||
public void setData(Data data) {
|
||||
this.data = data;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -68,37 +68,56 @@ public class OcrRecogServiceImpl implements IOcrRecogService {
|
|||
ajax.put("data",idCardVo);
|
||||
} catch (Exception 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", "调用服务出错");
|
||||
|
||||
}
|
||||
if (idCardVo.getData() != null) {
|
||||
char ifComplete = '否';
|
||||
if (idCardVo.getCode() == 20000) {
|
||||
ifComplete = '是';
|
||||
}
|
||||
String idNumber = idCardVo.getData().getIdNumber();
|
||||
String currentDate = System.currentTimeMillis()+"";
|
||||
String frontFileName = String.format(FRONT_FILE_NAME_TEMPLATE, idNumber, currentDate);
|
||||
String backFileName = String.format(BACK_FILE_NAME_TEMPLATE, idNumber, currentDate);
|
||||
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();
|
||||
if (idCardVo.getCode() != 20000 && idCardVo.getCode() != 20001) {
|
||||
AiIdcardrecognizeResult aiIdcardrecognizeResult = AiIdcardrecognizeResult.builder()
|
||||
.serviceId(1L)
|
||||
.resultStatus("1")
|
||||
.updateTime(LocalDateTime.now())
|
||||
.recognizeTime(LocalDateTime.now())
|
||||
.build();
|
||||
aiIdcardrecognizeMapper.insert(aiIdcardrecognizeResult);
|
||||
}
|
||||
else {
|
||||
String idNumber = idCardVo.getData().getIdNumber();
|
||||
String currentDate = System.currentTimeMillis() + "";
|
||||
String frontFileName = String.format(FRONT_FILE_NAME_TEMPLATE, idNumber, currentDate);
|
||||
String backFileName = String.format(BACK_FILE_NAME_TEMPLATE, idNumber, currentDate);
|
||||
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);
|
||||
return ajax;
|
||||
}
|
||||
|
||||
public String[] convertFilesToBase64(MultipartFile[] files) {
|
||||
public String[] convertFilesToBase64(MultipartFile[] files) throws IOException {
|
||||
String[] base64Strings = new String[files.length];
|
||||
for (int i = 0; i < files.length; i++) {
|
||||
MultipartFile file = files[i];
|
||||
|
|
@ -138,7 +157,7 @@ public class OcrRecogServiceImpl implements IOcrRecogService {
|
|||
log.info("获取python服务得到的数据:{}",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();
|
||||
// 从SecurityUtils.getLoginUser()获取登录用户信息
|
||||
LoginUser loginUser = SecurityUtils.getLoginUser();
|
||||
|
|
@ -165,6 +184,7 @@ public class OcrRecogServiceImpl implements IOcrRecogService {
|
|||
.invokeIp(IpUtils.getIpAddr(ServletUtils.getRequest()))
|
||||
.updateBy(String.valueOf(loginUser.getUserid())) // 假设getUserid()已返回正确用户ID
|
||||
.updateTime(LocalDateTime.now())
|
||||
.resultStatus(resultStatus)
|
||||
.build();
|
||||
aiIdcardrecognizeMapper.insert(aiIdcardrecognizeResult);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue