修改--增加log相关
This commit is contained in:
parent
c4a8463e58
commit
d190f46ff2
|
|
@ -3,10 +3,10 @@ package com.bonus.ai.controller;
|
||||||
import com.bonus.ai.service.IOcrRecogService;
|
import com.bonus.ai.service.IOcrRecogService;
|
||||||
import com.bonus.ai.utils.FileTypeUtils;
|
import com.bonus.ai.utils.FileTypeUtils;
|
||||||
import com.bonus.common.core.web.domain.AjaxResult;
|
import com.bonus.common.core.web.domain.AjaxResult;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
import org.springframework.web.multipart.MultipartFile;
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
import static com.bonus.common.core.web.domain.AjaxResult.error;
|
import static com.bonus.common.core.web.domain.AjaxResult.error;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -16,6 +16,7 @@ import static com.bonus.common.core.web.domain.AjaxResult.error;
|
||||||
*/
|
*/
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping("/ocr")
|
@RequestMapping("/ocr")
|
||||||
|
@Slf4j
|
||||||
public class OcrRecogController
|
public class OcrRecogController
|
||||||
{
|
{
|
||||||
@Autowired
|
@Autowired
|
||||||
|
|
@ -40,6 +41,7 @@ public class OcrRecogController
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
log.error("数据上传失败:{}",e);
|
||||||
return error("数据上传失败!!!");
|
return error("数据上传失败!!!");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -20,6 +20,8 @@ import org.springframework.stereotype.Service;
|
||||||
import org.springframework.web.client.RestClientException;
|
import org.springframework.web.client.RestClientException;
|
||||||
import org.springframework.web.client.RestTemplate;
|
import org.springframework.web.client.RestTemplate;
|
||||||
import org.springframework.web.multipart.MultipartFile;
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
|
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
import java.nio.file.*;
|
import java.nio.file.*;
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
|
|
@ -59,8 +61,10 @@ public class OcrRecogServiceImpl implements IOcrRecogService {
|
||||||
try {
|
try {
|
||||||
getfilePath = convertFilesToBase64(files);
|
getfilePath = convertFilesToBase64(files);
|
||||||
idCardVo = processPythonResponse(getfilePath, recogurl);
|
idCardVo = processPythonResponse(getfilePath, recogurl);
|
||||||
|
log.info("获得data:{}",idCardVo);
|
||||||
ajax.put("data",idCardVo);
|
ajax.put("data",idCardVo);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
log.error("调用大模型失败:{}",e);
|
||||||
ajax.put("601", "调用大模型服务出错");
|
ajax.put("601", "调用大模型服务出错");
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
@ -73,7 +77,6 @@ public class OcrRecogServiceImpl implements IOcrRecogService {
|
||||||
String currentDate = System.currentTimeMillis()+"";
|
String currentDate = System.currentTimeMillis()+"";
|
||||||
String frontFileName = String.format(FRONT_FILE_NAME_TEMPLATE, idNumber, currentDate);
|
String frontFileName = String.format(FRONT_FILE_NAME_TEMPLATE, idNumber, currentDate);
|
||||||
String backFileName = String.format(BACK_FILE_NAME_TEMPLATE, idNumber, currentDate);
|
String backFileName = String.format(BACK_FILE_NAME_TEMPLATE, idNumber, currentDate);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
byte[] frontImageBytes = Base64.getDecoder().decode(getfilePath[0]);
|
byte[] frontImageBytes = Base64.getDecoder().decode(getfilePath[0]);
|
||||||
byte[] backImageBytes = Base64.getDecoder().decode(getfilePath[1]);
|
byte[] backImageBytes = Base64.getDecoder().decode(getfilePath[1]);
|
||||||
|
|
@ -82,12 +85,14 @@ public class OcrRecogServiceImpl implements IOcrRecogService {
|
||||||
Files.write(frontFilePath, frontImageBytes);
|
Files.write(frontFilePath, frontImageBytes);
|
||||||
Files.write(backFilePath, backImageBytes);
|
Files.write(backFilePath, backImageBytes);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
|
log.error("获取身份证信息出错:{}",e);
|
||||||
ajax.put("602", "获取身份证信息出错");
|
ajax.put("602", "获取身份证信息出错");
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
saveRecognitionResult(idCardVo, ifComplete, frontFileName, backFileName,startTime);
|
saveRecognitionResult(idCardVo, ifComplete, frontFileName, backFileName,startTime);
|
||||||
}
|
}
|
||||||
|
log.info("服务层返回给控制层的数据:{}",ajax);
|
||||||
return ajax;
|
return ajax;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -103,11 +108,13 @@ public class OcrRecogServiceImpl implements IOcrRecogService {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
log.info("base64格式的图片:{}",base64Strings);
|
||||||
return base64Strings;
|
return base64Strings;
|
||||||
}
|
}
|
||||||
|
|
||||||
private IdCardVo processPythonResponse(String[] strings, String recogurl) throws Exception {
|
private IdCardVo processPythonResponse(String[] strings, String recogurl) throws Exception {
|
||||||
if (strings.length != 2) {
|
if (strings.length != 2) {
|
||||||
|
log.info("Python响应数据不完整。");
|
||||||
throw new IllegalArgumentException("Python响应数据不完整。");
|
throw new IllegalArgumentException("Python响应数据不完整。");
|
||||||
}
|
}
|
||||||
ImageUpload imageUpload = new ImageUpload();
|
ImageUpload imageUpload = new ImageUpload();
|
||||||
|
|
@ -116,6 +123,7 @@ public class OcrRecogServiceImpl implements IOcrRecogService {
|
||||||
imageUpload.setType("1");
|
imageUpload.setType("1");
|
||||||
ResponseEntity<String> response = restTemplate.postForEntity(recogurl, imageUpload, String.class);
|
ResponseEntity<String> response = restTemplate.postForEntity(recogurl, imageUpload, String.class);
|
||||||
if (response.getStatusCodeValue() != 200) {
|
if (response.getStatusCodeValue() != 200) {
|
||||||
|
log.info("调用服务失败,状态码:{}",response.getStatusCodeValue());
|
||||||
throw new RestClientException("调用服务失败,状态码:" + response.getStatusCodeValue());
|
throw new RestClientException("调用服务失败,状态码:" + response.getStatusCodeValue());
|
||||||
}
|
}
|
||||||
String json = response.getBody();
|
String json = response.getBody();
|
||||||
|
|
@ -125,6 +133,7 @@ public class OcrRecogServiceImpl implements IOcrRecogService {
|
||||||
json = StringEscapeUtils.unescapeJava(json);
|
json = StringEscapeUtils.unescapeJava(json);
|
||||||
Gson gson = new Gson();
|
Gson gson = new Gson();
|
||||||
IdCardVo idCardVo = gson.fromJson(json, IdCardVo.class);//此方法 如果里面为空 错误 解决
|
IdCardVo idCardVo = gson.fromJson(json, IdCardVo.class);//此方法 如果里面为空 错误 解决
|
||||||
|
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) {
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<configuration scan="true" scanPeriod="60 seconds" debug="false">
|
<configuration scan="true" scanPeriod="60 seconds" debug="false">
|
||||||
<!-- 日志存放路径 -->
|
<!-- 日志存放路径 -->
|
||||||
<property name="log.path" value="logs/bonus-file" />
|
<property name="log.path" value="logs/bonus-ai" />
|
||||||
<!-- 日志输出格式 -->
|
<!-- 日志输出格式 -->
|
||||||
<property name="log.pattern" value="%d{HH:mm:ss.SSS} [%thread] %-5level %logger{20} - [%method,%line] - %msg%n" />
|
<property name="log.pattern" value="%d{HH:mm:ss.SSS} [%thread] %-5level %logger{20} - [%method,%line] - %msg%n" />
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue