新增--身份证识别结果统计相关接口
This commit is contained in:
parent
995476dc34
commit
466881654c
|
|
@ -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;
|
||||
|
||||
/**
|
||||
* 文件请求处理
|
||||
|
|
@ -23,24 +22,28 @@ public class OcrRecogController
|
|||
private IOcrRecogService ocrRecogService;
|
||||
|
||||
|
||||
@PostMapping("/recognition")
|
||||
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格式文件");
|
||||
@PostMapping("/recognition")
|
||||
public AjaxResult recognition(MultipartFile[] files, String type) {
|
||||
AjaxResult ajax = AjaxResult.success();
|
||||
try {
|
||||
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 AjaxResult.success(ajax);
|
||||
}else {
|
||||
return error("规范上传文件类型");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return error("数据上传失败!!!");
|
||||
}
|
||||
ajax = ocrRecogService.recognitionCheck(files,type);
|
||||
return success("数据上传成功!!!");
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return error("数据上传失败!!!");
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,54 @@
|
|||
package com.bonus.ai.controller;
|
||||
import com.bonus.ai.domain.po.AiIdcardrecognizeResult;
|
||||
import com.bonus.ai.domain.vo.ResultCountVo;
|
||||
import com.bonus.ai.service.IReportService;
|
||||
import com.bonus.common.core.web.domain.AjaxResult;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import java.util.List;
|
||||
import static com.bonus.common.core.web.domain.AjaxResult.error;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/report")
|
||||
@Slf4j
|
||||
public class ReportController {
|
||||
@Autowired
|
||||
private IReportService reportService;
|
||||
@GetMapping("getResultDetails/{serviceid}")
|
||||
public AjaxResult resultDetails(@PathVariable int serviceid) {
|
||||
try {
|
||||
List<AiIdcardrecognizeResult> data = reportService.getResultDetails(serviceid);
|
||||
return AjaxResult.success(data);
|
||||
}
|
||||
catch (Exception e){
|
||||
log.error(e.toString(),e);
|
||||
}
|
||||
return error("系统错误");
|
||||
}
|
||||
|
||||
@GetMapping("getResult/{serviceid}")
|
||||
public AjaxResult getResult(@PathVariable int serviceid) {
|
||||
try {
|
||||
ResultCountVo data = reportService.getResult(serviceid);
|
||||
return AjaxResult.success(data);
|
||||
}catch (Exception e) {
|
||||
log.error(e.toString(),e);
|
||||
}
|
||||
return error("系统错误");
|
||||
}
|
||||
|
||||
@GetMapping("getLast7Days/{serviceid}")
|
||||
public AjaxResult last7Days(@PathVariable int serviceid) {
|
||||
try {
|
||||
List<ResultCountVo> data = reportService. getLast7Days(serviceid);
|
||||
return AjaxResult.success(data);
|
||||
}catch (Exception e) {
|
||||
log.error(e.toString(),e);
|
||||
}
|
||||
return error("系统错误");
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
package com.bonus.ai.domain.vo;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class ResultCountVo {
|
||||
private String day;
|
||||
private int totalNu;
|
||||
private int correctNu;
|
||||
private int incorrectNu;
|
||||
}
|
||||
|
|
@ -1,9 +1,11 @@
|
|||
package com.bonus.ai.mapper;
|
||||
import com.bonus.ai.domain.po.AiIdcardrecognizeResult;
|
||||
import org.apache.ibatis.annotations.Insert;
|
||||
import com.bonus.ai.domain.vo.ResultCountVo;
|
||||
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author wubin
|
||||
*/
|
||||
|
|
@ -11,4 +13,10 @@ import org.springframework.stereotype.Repository;
|
|||
public interface AiIdcardrecognizeMapper {
|
||||
void insert(AiIdcardrecognizeResult aiIdcardrecognizeResult);
|
||||
|
||||
|
||||
List<AiIdcardrecognizeResult> ResultDetails();
|
||||
|
||||
ResultCountVo Result();
|
||||
|
||||
List<ResultCountVo> last7Days();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,4 +5,5 @@ import org.springframework.web.multipart.MultipartFile;
|
|||
public interface IOcrRecogService {
|
||||
|
||||
AjaxResult recognitionCheck(MultipartFile[] files, String type);
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,15 @@
|
|||
package com.bonus.ai.service;
|
||||
|
||||
import com.bonus.ai.domain.po.AiIdcardrecognizeResult;
|
||||
import com.bonus.ai.domain.vo.ResultCountVo;
|
||||
import com.bonus.common.core.web.domain.AjaxResult;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface IReportService {
|
||||
List<AiIdcardrecognizeResult> getResultDetails(int serviceid);
|
||||
|
||||
ResultCountVo getResult(int serviceid);
|
||||
|
||||
List<ResultCountVo> getLast7Days(int serviceid);
|
||||
}
|
||||
|
|
@ -50,7 +50,7 @@ public class OcrRecogServiceImpl implements IOcrRecogService {
|
|||
|
||||
@Override
|
||||
public AjaxResult recognitionCheck(MultipartFile[] files, String type) {
|
||||
AjaxResult ajax=null;
|
||||
AjaxResult ajax=new AjaxResult();
|
||||
// 记录开始时间
|
||||
long startTime = System.currentTimeMillis();
|
||||
IdCardVo idCardVo = null;
|
||||
|
|
@ -59,13 +59,14 @@ public class OcrRecogServiceImpl implements IOcrRecogService {
|
|||
try {
|
||||
getfilePath = convertFilesToBase64(files);
|
||||
idCardVo = processPythonResponse(getfilePath, recogurl);
|
||||
ajax.put("data",idCardVo);
|
||||
} catch (Exception e) {
|
||||
ajax.put("601", "调用大模型服务出错");
|
||||
e.printStackTrace();
|
||||
}
|
||||
if (idCardVo != null) {
|
||||
char ifComplete = '否';
|
||||
if (SystemGlobal.IDCARD_RECORD_SUCCESS.equals(idCardVo.getCode())) {
|
||||
if (idCardVo.getCode() == 20000) {
|
||||
ifComplete = '是';
|
||||
}
|
||||
String idNumber = idCardVo.getData().getIdNumber();
|
||||
|
|
@ -150,7 +151,7 @@ public class OcrRecogServiceImpl implements IOcrRecogService {
|
|||
.recognizeTime(LocalDateTime.now())
|
||||
.responseLong(responseTime)
|
||||
.invokeIp(IpUtils.getIpAddr(ServletUtils.getRequest()))
|
||||
// .updateBy(loginUser.getUserid()) // 假设getUserid()已返回正确用户ID
|
||||
// .updateBy(loginUser.getUserid()) // 假设getUserid()已返回正确用户ID
|
||||
.updateTime(LocalDateTime.now())
|
||||
.build();
|
||||
aiIdcardrecognizeMapper.insert(aiIdcardrecognizeResult);
|
||||
|
|
|
|||
|
|
@ -0,0 +1,85 @@
|
|||
package com.bonus.ai.service.impl;
|
||||
|
||||
import com.bonus.ai.domain.po.AiIdcardrecognizeResult;
|
||||
import com.bonus.ai.domain.vo.ResultCountVo;
|
||||
import com.bonus.ai.mapper.AiIdcardrecognizeMapper;
|
||||
import com.bonus.ai.service.IReportService;
|
||||
import com.bonus.common.core.web.domain.AjaxResult;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
public class ReportServiceImpl implements IReportService {
|
||||
|
||||
@Autowired
|
||||
private AiIdcardrecognizeMapper aiIdcardrecognizeMapper;
|
||||
@Override
|
||||
public List<AiIdcardrecognizeResult> getResultDetails(int serviceid) {
|
||||
switch (serviceid){
|
||||
//身份证识别
|
||||
case 1:
|
||||
return aiIdcardrecognizeMapper.ResultDetails();
|
||||
//发票识别
|
||||
case 2:
|
||||
return null;
|
||||
//文本识别
|
||||
case 3:
|
||||
return null;
|
||||
//人脸识别
|
||||
case 4:
|
||||
return null;
|
||||
//违章识别
|
||||
case 5:
|
||||
return null;
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResultCountVo getResult(int serviceid) {
|
||||
switch (serviceid){
|
||||
//身份证识别
|
||||
case 1:
|
||||
return aiIdcardrecognizeMapper.Result();
|
||||
//发票识别
|
||||
case 2:
|
||||
return null;
|
||||
//文本识别
|
||||
case 3:
|
||||
return null;
|
||||
//人脸识别
|
||||
case 4:
|
||||
return null;
|
||||
//违章识别
|
||||
case 5:
|
||||
return null;
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ResultCountVo> getLast7Days(int serviceid) {
|
||||
switch (serviceid){
|
||||
//身份证识别
|
||||
case 1:
|
||||
return aiIdcardrecognizeMapper.last7Days();
|
||||
//发票识别
|
||||
case 2:
|
||||
return null;
|
||||
//文本识别
|
||||
case 3:
|
||||
return null;
|
||||
//人脸识别
|
||||
case 4:
|
||||
return null;
|
||||
//违章识别
|
||||
case 5:
|
||||
return null;
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -4,17 +4,74 @@
|
|||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
|
||||
<mapper namespace="com.bonus.ai.mapper.AiIdcardrecognizeMapper">
|
||||
|
||||
<insert id="insert" parameterType="com.bonus.ai.domain.po.AiIdcardrecognizeResult">
|
||||
INSERT INTO ai_idcardrecognize_result
|
||||
(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>
|
||||
|
||||
|
||||
<select id="ResultDetails" resultType="com.bonus.ai.domain.po.AiIdcardrecognizeResult">
|
||||
select result_id, service_id, name, sex, enthnic, birthday, address,
|
||||
INSERT(idcard_number,7,8,'********')idcard_number,
|
||||
issuing_authority, idcard_validity, if_complete, frontImge_address,
|
||||
backImg_address, recognize_time, response_long, invoke_ip,
|
||||
update_by, update_time, del_flag
|
||||
from ai_idcardrecognize_result
|
||||
ORDER BY update_time DESC
|
||||
LIMIT 20
|
||||
</select>
|
||||
|
||||
<select id="Result" resultType="com.bonus.ai.domain.vo.ResultCountVo">
|
||||
SELECT
|
||||
COUNT(*) AS totalNu,
|
||||
SUM(CASE WHEN if_complete = '是' THEN 1 ELSE 0 END) AS correctNu,
|
||||
SUM(CASE WHEN if_complete = '否' THEN 1 ELSE 0 END) AS incorrectNU
|
||||
FROM
|
||||
ai_idcardrecognize_result
|
||||
</select>
|
||||
<select id="last7Days" resultType="com.bonus.ai.domain.vo.ResultCountVo">
|
||||
SELECT
|
||||
date_seq.day AS day,
|
||||
COALESCE(totalNu, 0) AS totalNu,
|
||||
COALESCE(correctNu, 0) AS correctNu,
|
||||
COALESCE(incorrectNu, 0) AS incorrectNu
|
||||
FROM
|
||||
(
|
||||
-- 生成日期序列,包括最近7天的日期
|
||||
SELECT CURDATE() - INTERVAL (a.a + (10 * b.a) + (100 * c.a)) DAY AS day
|
||||
FROM
|
||||
(SELECT 0 AS a UNION ALL SELECT 1 UNION ALL SELECT 2 UNION ALL SELECT 3 UNION ALL SELECT 4 UNION ALL SELECT 5 UNION ALL SELECT 6 UNION ALL SELECT 7 UNION ALL SELECT 8 UNION ALL SELECT 9) AS a
|
||||
CROSS JOIN
|
||||
(SELECT 0 AS a UNION ALL SELECT 1 UNION ALL SELECT 2 UNION ALL SELECT 3 UNION ALL SELECT 4 UNION ALL SELECT 5 UNION ALL SELECT 6 UNION ALL SELECT 7 UNION ALL SELECT 8 UNION ALL SELECT 9) AS b
|
||||
CROSS JOIN
|
||||
(SELECT 0 AS a UNION ALL SELECT 1 UNION ALL SELECT 2 UNION ALL SELECT 3 UNION ALL SELECT 4 UNION ALL SELECT 5 UNION ALL SELECT 6 UNION ALL SELECT 7 UNION ALL SELECT 8 UNION ALL SELECT 9) AS c
|
||||
) AS date_seq
|
||||
LEFT JOIN (
|
||||
SELECT
|
||||
DATE(update_time) AS day,
|
||||
COUNT(*) AS totalNu,
|
||||
SUM(CASE WHEN if_complete = '是' THEN 1 ELSE 0 END) AS correctNu,
|
||||
SUM(CASE WHEN if_complete = '否' THEN 1 ELSE 0 END) AS incorrectNu
|
||||
FROM
|
||||
ai_idcardrecognize_result
|
||||
WHERE
|
||||
update_time >= CURDATE() - INTERVAL 6 DAY
|
||||
GROUP BY
|
||||
DATE(update_time)
|
||||
) AS data ON date_seq.day = data.day
|
||||
WHERE
|
||||
date_seq.day >= CURDATE() - INTERVAL 6 DAY
|
||||
ORDER BY
|
||||
day DESC;
|
||||
</select>
|
||||
</mapper>
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue