This commit is contained in:
parent
995476dc34
commit
6daa09abf3
|
|
@ -8,7 +8,6 @@ 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;
|
||||||
import static com.bonus.common.core.web.domain.AjaxResult.success;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 文件请求处理
|
* 文件请求处理
|
||||||
|
|
@ -27,14 +26,18 @@ public class OcrRecogController
|
||||||
public AjaxResult recognition(MultipartFile[] files, String type) {
|
public AjaxResult recognition(MultipartFile[] files, String type) {
|
||||||
AjaxResult ajax = AjaxResult.success();
|
AjaxResult ajax = AjaxResult.success();
|
||||||
try {
|
try {
|
||||||
|
if(files !=null) {
|
||||||
for (MultipartFile file : files) {
|
for (MultipartFile file : files) {
|
||||||
String contentType = file.getContentType();
|
String contentType = file.getContentType();
|
||||||
if (!FileTypeUtils.FILE_TYPE_PNG.equals(contentType) && !FileTypeUtils.FILE_TYPE_JPEG.equals(contentType) && !FileTypeUtils.FILE_TYPE_PDF.equals(contentType)) {
|
if (!FileTypeUtils.FILE_TYPE_PNG.equals(contentType) && !FileTypeUtils.FILE_TYPE_JPEG.equals(contentType) && !FileTypeUtils.FILE_TYPE_PDF.equals(contentType)) {
|
||||||
return error("仅允许导入doc、jpg、png格式文件");
|
return error("仅允许导入doc、jpg、png格式文件");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ajax = ocrRecogService.recognitionCheck(files,type);
|
ajax = ocrRecogService.recognitionCheck(files, type);
|
||||||
return success("数据上传成功!!!");
|
return ajax;
|
||||||
|
}else {
|
||||||
|
return error("规范上传文件类型");
|
||||||
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
return error("数据上传失败!!!");
|
return error("数据上传失败!!!");
|
||||||
|
|
|
||||||
|
|
@ -6,12 +6,10 @@ import com.bonus.ai.domain.vo.IdCardVo;
|
||||||
import com.bonus.ai.mapper.AiIdcardrecognizeMapper;
|
import com.bonus.ai.mapper.AiIdcardrecognizeMapper;
|
||||||
import com.bonus.ai.service.IOcrRecogService;
|
import com.bonus.ai.service.IOcrRecogService;
|
||||||
import com.bonus.common.core.utils.ServletUtils;
|
import com.bonus.common.core.utils.ServletUtils;
|
||||||
import com.bonus.common.core.utils.global.SystemGlobal;
|
|
||||||
import com.bonus.common.core.utils.ip.IpUtils;
|
import com.bonus.common.core.utils.ip.IpUtils;
|
||||||
import com.bonus.common.core.web.domain.AjaxResult;
|
import com.bonus.common.core.web.domain.AjaxResult;
|
||||||
import com.bonus.common.security.utils.SecurityUtils;
|
import com.bonus.common.security.utils.SecurityUtils;
|
||||||
import com.bonus.system.api.model.LoginUser;
|
import com.bonus.system.api.model.LoginUser;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
|
||||||
import org.apache.commons.lang3.StringEscapeUtils;
|
import org.apache.commons.lang3.StringEscapeUtils;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
|
|
@ -24,14 +22,13 @@ import java.io.*;
|
||||||
import java.nio.file.*;
|
import java.nio.file.*;
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@Slf4j
|
|
||||||
@Service
|
@Service
|
||||||
public class OcrRecogServiceImpl implements IOcrRecogService {
|
public class OcrRecogServiceImpl implements IOcrRecogService {
|
||||||
|
|
||||||
|
private static final Logger logger = LoggerFactory.getLogger(OcrRecogServiceImpl.class);
|
||||||
private static final String FRONT_FILE_NAME_TEMPLATE = "%s_%s_front.jpg";
|
private static final String FRONT_FILE_NAME_TEMPLATE = "%s_%s_front.jpg";
|
||||||
private static final String BACK_FILE_NAME_TEMPLATE = "%s_%s_back.jpg";
|
private static final String BACK_FILE_NAME_TEMPLATE = "%s_%s_back.jpg";
|
||||||
|
|
||||||
|
|
@ -50,7 +47,7 @@ public class OcrRecogServiceImpl implements IOcrRecogService {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public AjaxResult recognitionCheck(MultipartFile[] files, String type) {
|
public AjaxResult recognitionCheck(MultipartFile[] files, String type) {
|
||||||
AjaxResult ajax=null;
|
AjaxResult ajax = AjaxResult.success();
|
||||||
// 记录开始时间
|
// 记录开始时间
|
||||||
long startTime = System.currentTimeMillis();
|
long startTime = System.currentTimeMillis();
|
||||||
IdCardVo idCardVo = null;
|
IdCardVo idCardVo = null;
|
||||||
|
|
@ -59,20 +56,21 @@ public class OcrRecogServiceImpl implements IOcrRecogService {
|
||||||
try {
|
try {
|
||||||
getfilePath = convertFilesToBase64(files);
|
getfilePath = convertFilesToBase64(files);
|
||||||
idCardVo = processPythonResponse(getfilePath, recogurl);
|
idCardVo = processPythonResponse(getfilePath, recogurl);
|
||||||
|
ajax.put("result", idCardVo);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
ajax.put("601", "调用大模型服务出错");
|
logger.error("调用大模型服务出错", e);
|
||||||
e.printStackTrace();
|
ajax.error("调用大模型服务出错");
|
||||||
|
return ajax;
|
||||||
}
|
}
|
||||||
if (idCardVo != null) {
|
if (idCardVo.getData() != null) {
|
||||||
char ifComplete = '否';
|
char ifComplete = '否';
|
||||||
if (SystemGlobal.IDCARD_RECORD_SUCCESS.equals(idCardVo.getCode())) {
|
if ("20000".equals(idCardVo.getCode())) {
|
||||||
ifComplete = '是';
|
ifComplete = '是';
|
||||||
}
|
}
|
||||||
String idNumber = idCardVo.getData().getIdNumber();
|
String idNumber = idCardVo.getData().getIdNumber();
|
||||||
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]);
|
||||||
|
|
@ -81,8 +79,9 @@ 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) {
|
||||||
ajax.put("602", "获取身份证信息出错");
|
ajax.error("获取身份证信息出错");
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
return ajax;
|
||||||
}
|
}
|
||||||
|
|
||||||
saveRecognitionResult(idCardVo, ifComplete, frontFileName, backFileName,startTime);
|
saveRecognitionResult(idCardVo, ifComplete, frontFileName, backFileName,startTime);
|
||||||
|
|
|
||||||
|
|
@ -9,12 +9,12 @@
|
||||||
(service_id, name, sex, enthnic, birthday, address, idcard_number,
|
(service_id, name, sex, enthnic, birthday, address, idcard_number,
|
||||||
issuing_authority, idcard_validity, if_complete, frontImge_address,
|
issuing_authority, idcard_validity, if_complete, frontImge_address,
|
||||||
backImg_address, recognize_time, response_long, invoke_ip,
|
backImg_address, recognize_time, response_long, invoke_ip,
|
||||||
update_by, update_time, del_flag)
|
update_by, update_time)
|
||||||
VALUES
|
VALUES
|
||||||
(#{serviceId}, #{name}, #{sex}, #{enthnic}, #{birthday}, #{address}, #{idcardNumber},
|
(#{serviceId}, #{name}, #{sex}, #{enthnic}, #{birthday}, #{address}, #{idcardNumber},
|
||||||
#{issuingAuthority}, #{idcardValidity}, #{ifComplete}, #{frontImageAddress},
|
#{issuingAuthority}, #{idcardValidity}, #{ifComplete}, #{frontImageAddress},
|
||||||
#{backImageAddress}, #{recognizeTime}, #{responseLong}, #{invokeIp},
|
#{backImageAddress}, #{recognizeTime}, #{responseLong}, #{invokeIp},
|
||||||
#{updateBy}, #{updateTime}, #{delFlag})
|
#{updateBy}, #{updateTime})
|
||||||
</insert>
|
</insert>
|
||||||
|
|
||||||
</mapper>
|
</mapper>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue