Commit 160b3a0a by 雷紫添

Merge remote-tracking branch 'remotes/origin/dev_QuanGuoTongYongJcxx' into dev_QuanGuoTongYongJcxx

parents 80e2f807 c80fbc85
...@@ -47,20 +47,7 @@ ...@@ -47,20 +47,7 @@
<artifactId>spring-boot-starter-data-redis</artifactId> <artifactId>spring-boot-starter-data-redis</artifactId>
<version>2.1.7.RELEASE</version> <version>2.1.7.RELEASE</version>
</dependency> </dependency>
<dependency>
<groupId>cn.com.winmage</groupId>
<artifactId>ocr-precision</artifactId>
<scope>system</scope>
<version>1.0</version>
<systemPath>${pom.basedir}/src/main/webapp/WEB-INF/lib/ocr-precision-1.0.jar</systemPath>
</dependency>
<dependency>
<groupId>com.sun.jna</groupId>
<artifactId>jna</artifactId>
<scope>system</scope>
<version>5.5.0</version>
<systemPath>${pom.basedir}/src/main/webapp/WEB-INF/lib/jna-5.5.0.jar</systemPath>
</dependency>
<dependency> <dependency>
<groupId>cn.hutool</groupId> <groupId>cn.hutool</groupId>
<artifactId>hutool-all</artifactId> <artifactId>hutool-all</artifactId>
...@@ -85,6 +72,7 @@ ...@@ -85,6 +72,7 @@
</dependency> </dependency>
<!-- 数据库驱动包 --> <!-- 数据库驱动包 -->
<dependency> <dependency>
<groupId>org.oracle</groupId> <groupId>org.oracle</groupId>
<artifactId>ojdbc6</artifactId> <artifactId>ojdbc6</artifactId>
......
package com.founder.config;
import com.founder.service.ResourceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;
import static org.springframework.core.Ordered.LOWEST_PRECEDENCE;
@Component
@Order(LOWEST_PRECEDENCE)
public class StartConfig implements CommandLineRunner {
@Autowired
private ResourceService resourceService;
@Override
public void run(String... args) throws Exception {
System.out.println("api项目启动完毕!");
resourceService.updateJjxx();
resourceService.updateCjxx();
}
}
package com.founder.controller;
import com.alibaba.fastjson.JSONObject;
import com.founder.common.CodeMsg;
import com.founder.model.Face;
import com.founder.model.Jccj;
import com.founder.service.AutoSeqService;
import com.founder.service.FaceService;
import com.founder.service.impl.JccjServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.util.Base64;
import java.util.List;
import java.util.Map;
@RestController
public class FaceController {
@Autowired
private FaceService faceService;
@ResponseBody
@RequestMapping("/query1")
public String query() {
System.out.println("1111111111111111111");
faceService.sync();;
System.out.println("33333333333333333");
/* List<Face> face = faceService.query();
for (Map<String, String> item : codeMsg.getStatus()) {
if (item.get("code").equals("001"))
System.out.println( item.get("name"));
}
codeMsg.getStatus().forEach(item->{
if("001".equals(item.get("code"))){
System.out.println(item.get("name"));
}
});*/
/* final Base64.Decoder decoder = Base64.getDecoder();
final Base64.Encoder encoder = Base64.getEncoder();
Jccj jccj =new Jccj();
try {
URL url = new URL("http://10.100.37.222/neimeng/FZXZ/201909/JCXX-R1100000500002014070008.zip");
InputStream inStream = null;
inStream = url.openStream();
ByteArrayOutputStream swapStream = new ByteArrayOutputStream();
byte[] buff = new byte[100]; //buff用于存放循环读取的临时数据
int rc = 0;
while ((rc = inStream.read(buff, 0, 100)) > 0) {
swapStream.write(buff, 0, rc);
}
byte[] in_b = swapStream.toByteArray(); //in_b为转换之后的结果
final String encodedText = encoder.encodeToString(in_b);
//编码
jccj.setXxsb_zip(encodedText);
jccj.setTaskid("JCXX-R1100000500002014070008");
jccj.setUser_id("142728188997588823");
jccj.setUser_dept("1400000000");
jccj.setVersion("1.00");
//发送,httpclient 包含zip包
JSONObject jsonResult= JccjServiceImpl.requestByPost("http://26.3.5.101:9061/jccj/xxbs",jccj);
System.out.println("返回的参数为::"+jsonResult.toJSONString());
} catch (IOException e) {
e.printStackTrace();
}*/
return "已执行";
}
}
package com.founder.controller;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.founder.common.*;
import com.founder.model.Face;
import com.founder.model.Jccj;
import com.founder.ratelimit.guava.annotation.RateLimiter;
import com.founder.service.AutoSeqService;
import com.founder.service.FaceService;
import com.founder.service.JccjService;
import com.founder.util.RequertUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.client.RestTemplate;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.Base64;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@RestController
@RequestMapping(value="/jccj",produces = "application/json; charset=utf-8")
public class JccjController {
@Autowired
private JccjService jccjService;
@Autowired
private RedisLock redisLock;
@Autowired
private IpADressLock ipADressLock;
@Autowired
private IdentityCardVerification identityCardVerification;
@Value(value = "${redistimeout}")
private int redistimeout;
@Value(value = "${ftpserverip}")
private String ftpserverip;
@Value(value = "${ftpfilePath}")
private String ftpfilePath;
@ResponseBody
@PostMapping("/xxbs")
@RateLimiter(value = 2.0)
public Object queryDatas( HttpServletRequest request, @RequestBody Jccj jccj) {
//1.验证是否非法调用()
Map<String, Object> res = new HashMap<>();
String idStr=identityCardVerification.IdentityCardVerification(jccj.getUser_id());
if( !jccj.getUser_id().equals(idStr)){
res.put("status_code", "010104");
res.put("message", idStr);
res.put("taskid", jccj.getTaskid());
return res;
}
if(!ipADressLock.getIpAddress(request)){
res.put("status_code", "010102");
res.put("message", "访问ip地址未授权");
res.put("taskid", jccj.getTaskid());
return res;
}
long time=System.currentTimeMillis()+redistimeout;
if(!redisLock.lock(jccj.getTaskid(),String.valueOf(time))){
res.put("status_code", "010103");
res.put("message", "请勿重复提交");
res.put("taskid", jccj.getTaskid());
return res;
}
res=jccjService.res(jccj);
// response.setCharacterEncoding("utf-8");
return res;
}
}
package com.founder.controller;
import com.alibaba.fastjson.JSONObject;
import com.founder.service.OcrService;
import com.founder.util.OcrFounder;
import org.apache.ibatis.annotations.Results;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.text.DateFormat;
import java.util.Base64;
import java.util.Date;
import sun.misc.BASE64Encoder;
@RestController
@RequestMapping(value="/ocr",produces = "application/json; charset=utf-8")
public class OcrController {
@Autowired
private OcrService ocrjService;
@Autowired
private OcrFounder ocrFounder;
@ResponseBody
@CrossOrigin
@PostMapping("/InvoiceOcr")
public JSONObject query(HttpServletRequest request, MultipartFile file) {
DateFormat df2 = DateFormat.getDateTimeInstance();//可以精确到时分秒
Date date = new Date();
System.out.println(df2.format(date)+"开始时间");
byte[] fileByte = null;
try {
fileByte = file.getBytes();
} catch (IOException e) {
}
BASE64Encoder encoder = new BASE64Encoder();
String voiceBase64= encoder.encode(fileByte);
JSONObject j = new JSONObject();
j.put("msg",ocrjService.getOcr(voiceBase64));
Date date1 = new Date();
DateFormat df3 = DateFormat.getDateTimeInstance();//可以精确到时分秒
System.out.println(df3.format(date1)+"结束时间");
return j;
}
@ResponseBody
@CrossOrigin
@PostMapping("/OcrFounder")
public JSONObject queryOcrFounder(HttpServletRequest request, MultipartFile file) {
DateFormat df2 = DateFormat.getDateTimeInstance();//可以精确到时分秒
Date date = new Date();
System.out.println(df2.format(date)+"开始时间");
String result="";
byte[] fileByte = null;
try {
fileByte = file.getBytes();
} catch (IOException e) {
}
String ocrRes="";
try {
ocrRes= ocrFounder.getOcrFounder(fileByte);
} catch (Exception e) {
e.printStackTrace();
}
//图片文字与简要案情比对
Float ocrCompJyaq=getSimilarityRatio(ocrRes,"立案");
//图片文字与嫌疑人比对
Float ocrCompZbfzxry=getSimilarityRatio(ocrRes,"王岩");
//图片文字与受害人人比对
Float ocrCompBhr=getSimilarityRatio(ocrRes,"大类");
//图片文字与受害人人比对
Float ocrCompws=getSimilarityRatio(ocrRes,"立案决定书");
if(ocrCompws<0.000001){
}else
if(ocrCompJyaq<0.000001&&ocrCompZbfzxry<0.000001&&ocrCompBhr<0.000001)
{
}
JSONObject j = new JSONObject();
j.put("msg",ocrRes);
Date date1 = new Date();
DateFormat df3 = DateFormat.getDateTimeInstance();//可以精确到时分秒
System.out.println(df3.format(date1)+"结束时间");
return j;
}
@ResponseBody
@CrossOrigin
@PostMapping("/OcrFounderByte")
public JSONObject queryOcrFounderFlws(@RequestBody String fileByte) {
final Base64.Decoder decoder = Base64.getMimeDecoder();
byte[] data=decoder.decode(fileByte);
DateFormat df2 = DateFormat.getDateTimeInstance();//可以精确到时分秒
String result="";
try {
result= ocrFounder.getOcrFounder(data);
} catch (Exception e) {
e.printStackTrace();
}
JSONObject j = new JSONObject();
j.put("msg",result);
Date date1 = new Date();
DateFormat df3 = DateFormat.getDateTimeInstance();//可以精确到时分秒
System.out.println(df3.format(date1)+"结束时间");
return j;
}
public static float getSimilarityRatio(String str, String target) {
int d[][]; // 矩阵
int n = str.length();
int m = target.length();
int i; // 遍历str的
int j; // 遍历target的
char ch1; // str的
char ch2; // target的
int temp; // 记录相同字符,在某个矩阵位置值的增量,不是0就是1
if (n == 0 || m == 0) {
return 0;
}
d = new int[n + 1][m + 1];
for (i = 0; i <= n; i++) { // 初始化第一列
d[i][0] = i;
}
for (j = 0; j <= m; j++) { // 初始化第一行
d[0][j] = j;
}
for (i = 1; i <= n; i++) { // 遍历str
ch1 = str.charAt(i - 1);
// 去匹配target
for (j = 1; j <= m; j++) {
ch2 = target.charAt(j - 1);
if (ch1 == ch2 || ch1 == ch2 + 32 || ch1 + 32 == ch2) {
temp = 0;
} else {
temp = 1;
}
// 左边+1,上边+1, 左上角+temp取最小
d[i][j] = Math.min(Math.min(d[i - 1][j] + 1, d[i][j - 1] + 1), d[i - 1][j - 1] + temp);
}
}
return (1 - (float) d[n][m] / Math.max(str.length(), target.length())) * 100F;
}
}
package com.founder.service;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.founder.dao.XxcxDao;
import com.founder.model.TbZhzxCjxx;
import com.founder.model.TbZhzxJjxx;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.utils.URIBuilder;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;
import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.apache.kafka.clients.consumer.ConsumerRecords;
import org.apache.kafka.clients.consumer.KafkaConsumer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
import java.io.IOException;
import java.net.URI;
import java.util.*;
@Service
public class ResourceService {
public Logger logger = LoggerFactory.getLogger(this.getClass());
@Value("${hnxjzd.getResource.url}")
private String getResourceUrl;
@Value("${hnxjzd.queryResource.url}")
private String queryResourceUrl;
@Value("${hnxjzd.pauseResource.url}")
private String pauseResourceUrl;
@Value("${hnxjzd.resource.jjxx}")
private String jjxxId;
@Value("${hnxjzd.resource.cjxx}")
private String cjxxId;
@Value("${hnxjzd.apiKey}")
private String apiKey;
@Value("${hnxjzd.kafka.server}")
private String kafkaServer;
@Value("${hnxjzd.kafka.groupId}")
private String groupId;
@Autowired
private XxcxDao xxcxDao;
@Async
public void updateJjxx(){
Map<String,Object> topicInfo = getJjxxTopic();
queryResource(topicInfo,"JJXX");
}
@Async
public void updateCjxx(){
Map<String,Object> topicInfo = getCjxxTopic();
queryResource(topicInfo,"CJXX");
}
private Map<String,Object> getJjxxTopic(){
return queryResourceTopicName(jjxxId);
}
private Map<String,Object> getCjxxTopic(){
return queryResourceTopicName(cjxxId);
}
private Map<String,Object> queryResourceTopicName(String resource){
Map<String,Object> result = new HashMap<>();
CloseableHttpClient httpClient = HttpClients.createDefault();
CloseableHttpResponse response = null;
String resultString = "";
try {
//添加参数
URIBuilder builder = new URIBuilder(getResourceUrl);
builder.addParameter("requestid", apiKey);
builder.addParameter("sourceid", resource);
URI uri = builder.build();
//logger.info(uri.toString());
// 创建Http Post请求
HttpPost httpPost = new HttpPost(uri);
//添加请求头
httpPost.addHeader("apikey",apiKey);
logger.info(httpPost.getURI().toString());
// 执行http请求
response = httpClient.execute(httpPost);
resultString = EntityUtils.toString(response.getEntity(), "utf-8");
//resultString = "{ \"code\": 200,\"code_message\": \"\",\"message\": \"成功\",\"data\": {\"topic\": \"AZNB46000000000000015_4699980060\",\"time\": 1615191601,\"status\": \"1\",\"isSuccess\": true},\"error_data\": null}";
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
if(response!=null){
response.close();
}
} catch (IOException e) {
e.printStackTrace();
}
}
if(!StringUtils.isEmpty(resultString)){
logger.info(resultString);
JSONObject jsonObject = JSON.parseObject(resultString);
String code = jsonObject.getString("code");
JSONObject data = jsonObject.getJSONObject("data");
if("200".equals(code)){
if(data!=null){
String topicName = data.getString("topic");
String status = data.getString("status");
result.put("topicName",topicName);
result.put("status",status);
}else{
logger.warn("["+resource+"]返回topic数据为空");
result.put("status",null);
}
}else{
logger.warn("请求资源返回状态码["+code+"],"+jsonObject.getString("code_message"));
result.put("status",null);
}
}else{
logger.warn("请求资源返回内容为空!");
result.put("status",null);
}
return result;
}
private void queryResource(Map<String,Object> resourceInfo,String type){
String status = (String)resourceInfo.get("status");
if(!StringUtils.isEmpty(status)){
String topicName = (String)resourceInfo.get("topicName");
Properties props = new Properties();
props.put("bootstrap.servers", kafkaServer); // 注意:kafka地址,根据现场配
props.put("key.deserializer", "org.apache.kafka.common.serialization.StringDeserializer");
props.put("value.deserializer", "org.apache.kafka.common.serialization.StringDeserializer");
props.put("group.id", groupId); // 注意:不同的厂商,使用不同的消费者组
props.put("auto.offset.reset", "earliest");
props.put("session.timeout.ms", "6000");
props.put("heartbeat.interval.ms", "2000");
@SuppressWarnings("resource")
KafkaConsumer<String, String> consumer = new KafkaConsumer<String, String>(props);
//kafka队列名 topicName
consumer.subscribe(Collections.singleton(topicName));
// 循环消费 任务进度 并更新前台界面
while (true) {
ConsumerRecords<String, String> records = null;//消费间隔单位:毫秒
try {
records = consumer.poll(10000);
} catch (Exception e) {
e.printStackTrace();
}
if(records!=null){
for (ConsumerRecord<String, String> consumerRecord : records) {
logger.info("消息队列返回内容:{"+consumerRecord.key()+":"+consumerRecord.value()+"}"); // 消息key:taskid的值// 消息value:消息的json字符串
try {
if("JJXX".equals(type)){
TbZhzxJjxx entity = parseJjxx(consumerRecord.value());
xxcxDao.insertJjxx(entity);
}else if("CJXX".equals(type)){
TbZhzxCjxx entity = parseCjxx(consumerRecord.value());
xxcxDao.insertCjxx(entity);
}
} catch (Exception e) {
e.printStackTrace();
}
}
}else{
logger.warn("消息队列没有内容返回。");
}
}
}
}
private TbZhzxJjxx parseJjxx(String value){
JSONObject jsonObject = JSON.parseObject(value);
TbZhzxJjxx tbZhzxJjxx = null;
if(jsonObject!=null){
Iterator<String> iterator = jsonObject.keySet().iterator();
JSONObject destJSON = new JSONObject();
while(iterator.hasNext()){
String key = iterator.next();
Object keyValue = jsonObject.get(key);
String humpKey = UnderlineToHump(key);
destJSON.put(humpKey,keyValue);
}
tbZhzxJjxx = destJSON.toJavaObject(TbZhzxJjxx.class);
}
return tbZhzxJjxx;
}
private TbZhzxCjxx parseCjxx(String value){
JSONObject jsonObject = JSON.parseObject(value);
TbZhzxCjxx tbZhzxCjxx = null;
if(jsonObject!=null){
Iterator<String> iterator = jsonObject.keySet().iterator();
JSONObject destJSON = new JSONObject();
while(iterator.hasNext()){
String key = iterator.next();
Object keyValue = jsonObject.get(key);
String humpKey = UnderlineToHump(key);
destJSON.put(humpKey,keyValue);
}
tbZhzxCjxx = destJSON.toJavaObject(TbZhzxCjxx.class);
}
return tbZhzxCjxx;
}
private String UnderlineToHump(String para){
StringBuilder result=new StringBuilder();
String a[]=para.split("_");
for(String s:a){
if (!para.contains("_")) {
result.append(s);
continue;
}
if(result.length()==0){
result.append(s.toLowerCase());
}else{
result.append(s.substring(0, 1).toUpperCase());
result.append(s.substring(1).toLowerCase());
}
}
return result.toString();
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment