|
|
|
|
@ -1,18 +1,22 @@
|
|
|
|
|
package com.da.dangan.controller;
|
|
|
|
|
|
|
|
|
|
import cn.hutool.json.JSONObject;
|
|
|
|
|
import com.alibaba.fastjson2.JSONArray;
|
|
|
|
|
import com.da.common.config.RuoYiConfig;
|
|
|
|
|
import com.da.common.core.controller.BaseController;
|
|
|
|
|
import com.da.common.core.domain.AjaxResult;
|
|
|
|
|
import com.da.common.utils.file.FileUploadUtils;
|
|
|
|
|
import com.da.common.utils.file.FileUtils;
|
|
|
|
|
import com.da.dangan.domain.DaCzrkdj;
|
|
|
|
|
import com.da.dangan.domain.DaPicturesRecard;
|
|
|
|
|
import com.da.dangan.domain.vo.CzrkDatas;
|
|
|
|
|
import com.da.dangan.domain.vo.PicParams;
|
|
|
|
|
import com.da.dangan.service.IDaBirthDjService;
|
|
|
|
|
import com.da.dangan.service.IDaCzrkdjService;
|
|
|
|
|
import com.da.dangan.service.IDaPicturesRecardService;
|
|
|
|
|
import com.da.dangan.util.CallThirdInterface;
|
|
|
|
|
import com.da.framework.config.ServerConfig;
|
|
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
|
|
import org.springframework.http.ResponseEntity;
|
|
|
|
|
@ -111,11 +115,15 @@ public class DangAnCollectController extends BaseController {
|
|
|
|
|
*/
|
|
|
|
|
@PostMapping("/recongnize")
|
|
|
|
|
public AjaxResult recognize(@RequestBody List<DaPicturesRecard> picRecards) {
|
|
|
|
|
String code;
|
|
|
|
|
String msg;
|
|
|
|
|
int success;
|
|
|
|
|
int total;
|
|
|
|
|
try {
|
|
|
|
|
//取所有id的集合
|
|
|
|
|
List<Long> ids = picRecards.stream().map(DaPicturesRecard::getId).collect(Collectors.toList());
|
|
|
|
|
String ywType = picRecards.get(0).getYwType();
|
|
|
|
|
String singleOrDouble = picRecards.get(0).getSingelOrDouble();
|
|
|
|
|
// String singleOrDouble = picRecards.get(0).getSingelOrDouble();
|
|
|
|
|
//获取所有的文件
|
|
|
|
|
List<File> files = new ArrayList<>();
|
|
|
|
|
for (DaPicturesRecard picRecard : picRecards) {
|
|
|
|
|
@ -124,7 +132,7 @@ public class DangAnCollectController extends BaseController {
|
|
|
|
|
files.add(file);
|
|
|
|
|
}
|
|
|
|
|
// TODO————————多线程循环调用第三方接口
|
|
|
|
|
long start =System.currentTimeMillis();
|
|
|
|
|
long start = System.currentTimeMillis();
|
|
|
|
|
/*List<CompletableFuture<String>> futures = new ArrayList<>();
|
|
|
|
|
List<String> results = new ArrayList<>();
|
|
|
|
|
for(File file :files){
|
|
|
|
|
@ -140,21 +148,25 @@ public class DangAnCollectController extends BaseController {
|
|
|
|
|
long end =System.currentTimeMillis();
|
|
|
|
|
logger.info("CompletableFuture耗时--——————————————————》"+ (end-start)+"ms");*/
|
|
|
|
|
//不使用循环调用接口 直接传递数组
|
|
|
|
|
String result = CallThirdInterface.callThirdInterface(url, files, ywType,ids);
|
|
|
|
|
long end =System.currentTimeMillis();
|
|
|
|
|
logger.info("CompletableFuture耗时--——————————————————》"+ (end-start)+"ms");
|
|
|
|
|
//如果result中的code=0代表结果错误
|
|
|
|
|
// 解析JSON字符串
|
|
|
|
|
//! 获取键对应的值
|
|
|
|
|
String result = CallThirdInterface.callThirdInterface(url, files, ywType, ids);
|
|
|
|
|
long end = System.currentTimeMillis();
|
|
|
|
|
logger.info("CompletableFuture耗时--——————————————————》" + (end - start) + "ms");
|
|
|
|
|
//! 解析JSON字符串,获取键对应的值
|
|
|
|
|
JSONObject jsonobject = new JSONObject(result);
|
|
|
|
|
String code = jsonobject.getStr("code");
|
|
|
|
|
String msg = jsonobject.getStr("msg");
|
|
|
|
|
int success = jsonobject.getInt("success");
|
|
|
|
|
int total = jsonobject.getInt("total");
|
|
|
|
|
Long[] failPicids = (Long[])jsonobject.getJSONArray("failPicid").toArray();
|
|
|
|
|
String datas = jsonobject.getStr("datas");
|
|
|
|
|
|
|
|
|
|
// TODO 数据解析 根据业务类型存储识别后的信息
|
|
|
|
|
code = jsonobject.getStr("code");
|
|
|
|
|
msg = jsonobject.getStr("msg");
|
|
|
|
|
success = jsonobject.getInt("success");
|
|
|
|
|
total = jsonobject.getInt("total");
|
|
|
|
|
//如果code=0 识别失败,直接返回
|
|
|
|
|
if (code.equals("0")) {
|
|
|
|
|
return AjaxResult.error(msg + ", 成功:" + success + " , 总共:" + total);
|
|
|
|
|
} else {
|
|
|
|
|
//识别接口方说:多张识别,要么全识别成功,要么一张也识别不成功 ,所以---------failPicids暂时不用 失败则全失败
|
|
|
|
|
// String failPicid=jsonobject.getStr("msg");
|
|
|
|
|
|
|
|
|
|
String datas = jsonobject.getStr("datas");
|
|
|
|
|
|
|
|
|
|
// TODO 数据解析 根据业务类型存储识别后的信息
|
|
|
|
|
/*<option value="option1">常住人口登记表1</option> <option value="option2">常住卡</option>
|
|
|
|
|
<option value="option3">常住人口登记表2</option>
|
|
|
|
|
<option value="option4">出生医学证明</option>
|
|
|
|
|
@ -163,15 +175,43 @@ public class DangAnCollectController extends BaseController {
|
|
|
|
|
<option value="option7">转非农业人口批复存根</option>
|
|
|
|
|
<option value="option8">准迁证</option>
|
|
|
|
|
<option value="option9">常住人口登记表3</option>*/
|
|
|
|
|
Long dajlId=null;
|
|
|
|
|
switch(ywType){
|
|
|
|
|
case "option1" :
|
|
|
|
|
Long dajlId = null;
|
|
|
|
|
switch (ywType) {
|
|
|
|
|
case "option1":
|
|
|
|
|
|
|
|
|
|
//break;
|
|
|
|
|
case "option2":
|
|
|
|
|
|
|
|
|
|
// break;
|
|
|
|
|
case "option3":
|
|
|
|
|
|
|
|
|
|
//break;
|
|
|
|
|
case "option9":
|
|
|
|
|
//获取常住人口信息集合
|
|
|
|
|
List<CzrkDatas> czrkDatas = JSONArray.parseArray(datas, CzrkDatas.class);
|
|
|
|
|
for (CzrkDatas czrkData : czrkDatas) {
|
|
|
|
|
List<Long> picid = czrkData.getPicid();
|
|
|
|
|
// 将Long类型映射为String类型, 并将Stream转换为数组
|
|
|
|
|
String[] spicId = picid.stream().map(Object::toString).toArray(String[]::new);
|
|
|
|
|
String picIds = StringUtils.join(spicId, ",");//分号分割
|
|
|
|
|
//存储图片url
|
|
|
|
|
List<String> picUrls = picRecards.stream().map(DaPicturesRecard::getPicUrl).collect(Collectors.toList());
|
|
|
|
|
String[] pics = picUrls.stream().map(Object::toString).toArray(String[]::new);
|
|
|
|
|
String pictures = StringUtils.join(pics, ",");//分号分割
|
|
|
|
|
|
|
|
|
|
List<DaCzrkdj> info = czrkData.getInfo();
|
|
|
|
|
if(info!=null&&info.size()>0) {
|
|
|
|
|
for (DaCzrkdj daCzrkdj : info) {
|
|
|
|
|
daCzrkdj.setAllPicIds(picIds);
|
|
|
|
|
daCzrkdj.setAllPics(pictures);
|
|
|
|
|
daCzrkdj.setPicIds(picIds);
|
|
|
|
|
daCzrkdj.setPictures(pictures);
|
|
|
|
|
daCzrkdjService.insertDaCzrkdj(daCzrkdj);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
case "option2" :
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
case "option3" :
|
|
|
|
|
/*DaCzrkdj daCzrkdj = new DaCzrkdj();
|
|
|
|
|
daCzrkdj.setAllPicIds(picIds);
|
|
|
|
|
daCzrkdj.setAllPics();
|
|
|
|
|
@ -180,36 +220,34 @@ public class DangAnCollectController extends BaseController {
|
|
|
|
|
daCzrkdjService.insertDaCzrkdj();
|
|
|
|
|
//将插入后的id反写回来
|
|
|
|
|
dajlid=daCzrkdj.getId();*/
|
|
|
|
|
break;
|
|
|
|
|
case "option4" :
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
case "option5" :
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
case "option6" :
|
|
|
|
|
break;
|
|
|
|
|
case "option4":
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
case "option7" :
|
|
|
|
|
break;
|
|
|
|
|
case "option5":
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
case "option8" :
|
|
|
|
|
break;
|
|
|
|
|
case "option6":
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
case "option9" :
|
|
|
|
|
break;
|
|
|
|
|
case "option7":
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case "option8":
|
|
|
|
|
|
|
|
|
|
//识别成功的图片 ,修改图片信息记录表为已识别 可以用多线程
|
|
|
|
|
for (DaPicturesRecard picRecard : picRecards) {
|
|
|
|
|
picRecard.setRecognize("1");
|
|
|
|
|
daPicturesRecardService.updateDaPicturesRecard(picRecard);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
//识别成功的图片 ,修改图片信息记录表为已识别 可以用多线程
|
|
|
|
|
for (DaPicturesRecard picRecard : picRecards) {
|
|
|
|
|
picRecard.setRecognize("1");
|
|
|
|
|
daPicturesRecardService.updateDaPicturesRecard(picRecard);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
return AjaxResult.error(e.getMessage());
|
|
|
|
|
}
|
|
|
|
|
// return AjaxResult.success("成功:"+success+" , 总共:"+total);
|
|
|
|
|
return AjaxResult.success();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ -222,8 +260,8 @@ public class DangAnCollectController extends BaseController {
|
|
|
|
|
List<DaPicturesRecard> uncheked = params.getUnchecked();
|
|
|
|
|
String singleOrDouble = params.getSingeOrDouble();
|
|
|
|
|
//拼接所有的图片
|
|
|
|
|
List<DaPicturesRecard> listAll =checked;
|
|
|
|
|
if(uncheked!=null&&uncheked.size()>0){
|
|
|
|
|
List<DaPicturesRecard> listAll = checked;
|
|
|
|
|
if (uncheked != null && uncheked.size() > 0) {
|
|
|
|
|
listAll.addAll(uncheked);
|
|
|
|
|
}
|
|
|
|
|
//参数:checked id的集合
|
|
|
|
|
@ -235,7 +273,7 @@ public class DangAnCollectController extends BaseController {
|
|
|
|
|
|
|
|
|
|
System.out.println(allIds.toString());
|
|
|
|
|
|
|
|
|
|
if(checked!=null&&checked.size()>0){
|
|
|
|
|
if (checked != null && checked.size() > 0) {
|
|
|
|
|
try {
|
|
|
|
|
String ywType = checked.get(0).getYwType();
|
|
|
|
|
//获取所有的文件
|
|
|
|
|
@ -246,12 +284,12 @@ public class DangAnCollectController extends BaseController {
|
|
|
|
|
files.add(file);
|
|
|
|
|
}
|
|
|
|
|
// TODO————————多线程循环调用第三方接口
|
|
|
|
|
long start =System.currentTimeMillis();
|
|
|
|
|
long start = System.currentTimeMillis();
|
|
|
|
|
//参数:地址、文件、业务类型、单双面: 1单面 2双面
|
|
|
|
|
//String result = CallThirdInterface.callThirdInterface(url, files, ywType,singleOrDouble,ids);
|
|
|
|
|
String result = CallThirdInterface.callThirdInterface(url, files, ywType,ids);
|
|
|
|
|
long end =System.currentTimeMillis();
|
|
|
|
|
logger.info("CompletableFuture耗时--——————————————————》"+ (end-start)+"ms");
|
|
|
|
|
String result = CallThirdInterface.callThirdInterface(url, files, ywType, ids);
|
|
|
|
|
long end = System.currentTimeMillis();
|
|
|
|
|
logger.info("CompletableFuture耗时--——————————————————》" + (end - start) + "ms");
|
|
|
|
|
|
|
|
|
|
// TODO 根据业务类型存储识别后的信息
|
|
|
|
|
/*<option value="option1">常住人口登记表1</option>
|
|
|
|
|
@ -263,15 +301,15 @@ public class DangAnCollectController extends BaseController {
|
|
|
|
|
<option value="option7">转非农业人口批复存根</option>
|
|
|
|
|
<option value="option8">准迁证</option>
|
|
|
|
|
<option value="option9">常住人口登记表3</option>*/
|
|
|
|
|
Long dajlId=null;
|
|
|
|
|
switch(ywType){
|
|
|
|
|
case "option1" :
|
|
|
|
|
Long dajlId = null;
|
|
|
|
|
switch (ywType) {
|
|
|
|
|
case "option1":
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
case "option2" :
|
|
|
|
|
case "option2":
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
case "option3" :
|
|
|
|
|
case "option3":
|
|
|
|
|
/*DaCzrkdj daCzrkdj = new DaCzrkdj();
|
|
|
|
|
daCzrkdj.setAllPicIds(picIds);
|
|
|
|
|
daCzrkdj.setAllPics();
|
|
|
|
|
@ -281,31 +319,31 @@ public class DangAnCollectController extends BaseController {
|
|
|
|
|
//将插入后的id反写回来
|
|
|
|
|
dajlid=daCzrkdj.getId();*/
|
|
|
|
|
break;
|
|
|
|
|
case "option4" :
|
|
|
|
|
case "option4":
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
case "option5" :
|
|
|
|
|
case "option5":
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
case "option6" :
|
|
|
|
|
case "option6":
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
case "option7" :
|
|
|
|
|
case "option7":
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
case "option8" :
|
|
|
|
|
case "option8":
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
case "option9" :
|
|
|
|
|
case "option9":
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//识别成功的图片 ,修改图片信息记录表为已识别 可以用多线程
|
|
|
|
|
for (DaPicturesRecard picRecard : checked) {
|
|
|
|
|
picRecard.setRecognize("1");
|
|
|
|
|
daPicturesRecardService.updateDaPicturesRecard(picRecard);
|
|
|
|
|
}
|
|
|
|
|
for (DaPicturesRecard picRecard : checked) {
|
|
|
|
|
picRecard.setRecognize("1");
|
|
|
|
|
daPicturesRecardService.updateDaPicturesRecard(picRecard);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*if(uncheked!=null&&uncheked.size()>0){
|
|
|
|
|
for (DaPicturesRecard picRecard : uncheked) {
|
|
|
|
|
@ -320,7 +358,7 @@ public class DangAnCollectController extends BaseController {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
return AjaxResult.error(e.getMessage());
|
|
|
|
|
}
|
|
|
|
|
}else{
|
|
|
|
|
} else {
|
|
|
|
|
return AjaxResult.error("请选择需要识别的图片");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ -331,8 +369,23 @@ public class DangAnCollectController extends BaseController {
|
|
|
|
|
* test参数
|
|
|
|
|
*/
|
|
|
|
|
@PostMapping("/test3")
|
|
|
|
|
public String test(@RequestParam ("files")MultipartFile[] files,@RequestParam ("datas")Long[] datas){
|
|
|
|
|
return datas.toString();
|
|
|
|
|
public String test() {
|
|
|
|
|
String result = "{\"code\": 0, \"datas\": [{\"Picid\": [\"21\"], \"info\": [{\"name\":\"333\"},{\"name\":\"111\"}]}, {\"Picid\": [\"22\"], \"info\":[]]}]}";
|
|
|
|
|
JSONObject jsonobject = new JSONObject(result);
|
|
|
|
|
String code = jsonobject.getStr("code");
|
|
|
|
|
String msg = jsonobject.getStr("msg");
|
|
|
|
|
Integer success = jsonobject.getInt("success");
|
|
|
|
|
Integer total = jsonobject.getInt("total");
|
|
|
|
|
//识别接口方说:多张识别,要么全识别成功,要么一张也识别不成功 ,所以---------failPicids暂时不用 失败则全失败
|
|
|
|
|
// String failPicid=jsonobject.getStr("msg");
|
|
|
|
|
|
|
|
|
|
String datas = jsonobject.getStr("datas");
|
|
|
|
|
//获取常住人口信息集合
|
|
|
|
|
List<CzrkDatas> czrkDatas = JSONArray.parseArray(datas, CzrkDatas.class);
|
|
|
|
|
System.out.println(czrkDatas.get(1).getInfo()==null);
|
|
|
|
|
System.out.println(czrkDatas.get(1).getInfo().size());
|
|
|
|
|
System.out.println(czrkDatas.get(0).getInfo().get(0).getName());
|
|
|
|
|
return "datas.toString()";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
@ -409,7 +462,7 @@ public class DangAnCollectController extends BaseController {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 图片批量识别处理进度
|
|
|
|
|
* 图片批量识别处理进度
|
|
|
|
|
*/
|
|
|
|
|
@GetMapping("/progress")
|
|
|
|
|
public ResponseEntity<Double> getProgress() {
|
|
|
|
|
@ -432,7 +485,7 @@ public class DangAnCollectController extends BaseController {
|
|
|
|
|
multipartFile.transferTo(file);
|
|
|
|
|
fileList.add(file);
|
|
|
|
|
}
|
|
|
|
|
String result = CallThirdInterface.callThirdInterface(url, fileList, fileType,new ArrayList<>());
|
|
|
|
|
String result = CallThirdInterface.callThirdInterface(url, fileList, fileType, new ArrayList<>());
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|