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