|
@@ -3,6 +3,8 @@ package com.jpsoft.smart.modules.common.utils;
|
|
import cn.hutool.http.HttpRequest;
|
|
import cn.hutool.http.HttpRequest;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
import com.jpsoft.smart.config.TemperatureConfig;
|
|
import com.jpsoft.smart.config.TemperatureConfig;
|
|
|
|
+import com.jpsoft.smart.modules.base.entity.PersonInfo;
|
|
|
|
+import com.jpsoft.smart.modules.base.service.PersonInfoService;
|
|
import com.jpsoft.smart.modules.lapi.channel.LapiChannel;
|
|
import com.jpsoft.smart.modules.lapi.channel.LapiChannel;
|
|
import io.netty.handler.codec.http.DefaultHttpRequest;
|
|
import io.netty.handler.codec.http.DefaultHttpRequest;
|
|
import io.netty.handler.codec.http.HttpMethod;
|
|
import io.netty.handler.codec.http.HttpMethod;
|
|
@@ -11,6 +13,7 @@ import lombok.extern.slf4j.Slf4j;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.stereotype.Component;
|
|
import org.springframework.stereotype.Component;
|
|
|
|
+
|
|
import java.math.BigDecimal;
|
|
import java.math.BigDecimal;
|
|
import java.util.HashMap;
|
|
import java.util.HashMap;
|
|
import java.util.Map;
|
|
import java.util.Map;
|
|
@@ -23,10 +26,13 @@ import java.util.concurrent.TimeUnit;
|
|
@Slf4j
|
|
@Slf4j
|
|
@Component
|
|
@Component
|
|
public class LApiUtil {
|
|
public class LApiUtil {
|
|
- private final static int TIMEOUT = 10*1000;
|
|
|
|
|
|
+ private final static int TIMEOUT = 10 * 1000;
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ private PersonInfoService personInfoService;
|
|
|
|
|
|
|
|
|
|
- public static JSONObject postRequest(String url, HashMap map){
|
|
|
|
|
|
+ public static JSONObject postRequest(String url, HashMap map) {
|
|
String body = HttpRequest.post(url)
|
|
String body = HttpRequest.post(url)
|
|
.timeout(TIMEOUT)
|
|
.timeout(TIMEOUT)
|
|
.body(new JSONObject(map).toJSONString()).execute().body();
|
|
.body(new JSONObject(map).toJSONString()).execute().body();
|
|
@@ -34,7 +40,7 @@ public class LApiUtil {
|
|
return jsonbody;
|
|
return jsonbody;
|
|
}
|
|
}
|
|
|
|
|
|
- public static JSONObject getRequest(String url) throws Exception{
|
|
|
|
|
|
+ public static JSONObject getRequest(String url) throws Exception {
|
|
String body = HttpRequest.get(url)
|
|
String body = HttpRequest.get(url)
|
|
.timeout(TIMEOUT)
|
|
.timeout(TIMEOUT)
|
|
.execute().body();
|
|
.execute().body();
|
|
@@ -44,14 +50,14 @@ public class LApiUtil {
|
|
}
|
|
}
|
|
|
|
|
|
public static JSONObject deleteRequest(String url) {
|
|
public static JSONObject deleteRequest(String url) {
|
|
- String body = HttpRequest.delete(url)
|
|
|
|
- .timeout(TIMEOUT)
|
|
|
|
- .execute().body();
|
|
|
|
- JSONObject jsonbody = JSONObject.parseObject(body);
|
|
|
|
- return jsonbody;
|
|
|
|
|
|
+ String body = HttpRequest.delete(url)
|
|
|
|
+ .timeout(TIMEOUT)
|
|
|
|
+ .execute().body();
|
|
|
|
+ JSONObject jsonbody = JSONObject.parseObject(body);
|
|
|
|
+ return jsonbody;
|
|
}
|
|
}
|
|
|
|
|
|
- public static JSONObject putRequest(String url){
|
|
|
|
|
|
+ public static JSONObject putRequest(String url) {
|
|
String body = HttpRequest.put(url)
|
|
String body = HttpRequest.put(url)
|
|
.timeout(TIMEOUT)
|
|
.timeout(TIMEOUT)
|
|
.execute().body();
|
|
.execute().body();
|
|
@@ -60,7 +66,7 @@ public class LApiUtil {
|
|
return jsonbody;
|
|
return jsonbody;
|
|
}
|
|
}
|
|
|
|
|
|
- public static JSONObject putRequest(String url,HashMap map){
|
|
|
|
|
|
+ public static JSONObject putRequest(String url, HashMap map) {
|
|
String body = HttpRequest.put(url)
|
|
String body = HttpRequest.put(url)
|
|
.timeout(TIMEOUT)
|
|
.timeout(TIMEOUT)
|
|
.body(new JSONObject(map).toJSONString()).execute().body();
|
|
.body(new JSONObject(map).toJSONString()).execute().body();
|
|
@@ -69,152 +75,143 @@ public class LApiUtil {
|
|
return jsonbody;
|
|
return jsonbody;
|
|
}
|
|
}
|
|
|
|
|
|
- public static JSONObject getResponse(JSONObject dataJson) throws Exception{
|
|
|
|
- if (dataJson.getInteger("ResponseCode") == 1){
|
|
|
|
|
|
+ public static JSONObject getResponse(JSONObject dataJson) throws Exception {
|
|
|
|
+ if (dataJson.getInteger("ResponseCode") == 1) {
|
|
throw new Exception("通用错误");
|
|
throw new Exception("通用错误");
|
|
}
|
|
}
|
|
- if (dataJson.getInteger("ResponseCode") == 2){
|
|
|
|
|
|
+ if (dataJson.getInteger("ResponseCode") == 2) {
|
|
throw new Exception("参数非法");
|
|
throw new Exception("参数非法");
|
|
}
|
|
}
|
|
- if (dataJson.getInteger("ResponseCode") == 3){
|
|
|
|
|
|
+ if (dataJson.getInteger("ResponseCode") == 3) {
|
|
throw new Exception("用户无权限");
|
|
throw new Exception("用户无权限");
|
|
}
|
|
}
|
|
- if (dataJson.getInteger("ResponseCode") == 4){
|
|
|
|
|
|
+ if (dataJson.getInteger("ResponseCode") == 4) {
|
|
throw new Exception("设备不支持");
|
|
throw new Exception("设备不支持");
|
|
}
|
|
}
|
|
- if (dataJson.getInteger("ResponseCode") == 5){
|
|
|
|
|
|
+ if (dataJson.getInteger("ResponseCode") == 5) {
|
|
throw new Exception("用户状态异常");
|
|
throw new Exception("用户状态异常");
|
|
}
|
|
}
|
|
- if (dataJson.getInteger("StatusCode") == 1){
|
|
|
|
|
|
+ if (dataJson.getInteger("StatusCode") == 1) {
|
|
throw new Exception("执行失败");
|
|
throw new Exception("执行失败");
|
|
}
|
|
}
|
|
- if (dataJson.getInteger("StatusCode") == 2){
|
|
|
|
|
|
+ if (dataJson.getInteger("StatusCode") == 2) {
|
|
throw new Exception("输入参数非法");
|
|
throw new Exception("输入参数非法");
|
|
}
|
|
}
|
|
- if (dataJson.getInteger("StatusCode") == 3){
|
|
|
|
|
|
+ if (dataJson.getInteger("StatusCode") == 3) {
|
|
throw new Exception("系统内存不足");
|
|
throw new Exception("系统内存不足");
|
|
}
|
|
}
|
|
- if (dataJson.getInteger("StatusCode") == 8){
|
|
|
|
|
|
+ if (dataJson.getInteger("StatusCode") == 8) {
|
|
throw new Exception("功能不支持");
|
|
throw new Exception("功能不支持");
|
|
}
|
|
}
|
|
- if (dataJson.getInteger("StatusCode") == 10){
|
|
|
|
|
|
+ if (dataJson.getInteger("StatusCode") == 10) {
|
|
throw new Exception("序列化执行失败");
|
|
throw new Exception("序列化执行失败");
|
|
}
|
|
}
|
|
- if (dataJson.getInteger("StatusCode") == 11){
|
|
|
|
|
|
+ if (dataJson.getInteger("StatusCode") == 11) {
|
|
throw new Exception("Basic 鉴权失败");
|
|
throw new Exception("Basic 鉴权失败");
|
|
}
|
|
}
|
|
- if (dataJson.getInteger("StatusCode") == 12){
|
|
|
|
|
|
+ if (dataJson.getInteger("StatusCode") == 12) {
|
|
throw new Exception("Digest 鉴权失败");
|
|
throw new Exception("Digest 鉴权失败");
|
|
}
|
|
}
|
|
- if (dataJson.getInteger("StatusCode") == 13){
|
|
|
|
|
|
+ if (dataJson.getInteger("StatusCode") == 13) {
|
|
throw new Exception("订阅已满");
|
|
throw new Exception("订阅已满");
|
|
}
|
|
}
|
|
- if (dataJson.getInteger("StatusCode") == 14){
|
|
|
|
|
|
+ if (dataJson.getInteger("StatusCode") == 14) {
|
|
throw new Exception("重复订阅");
|
|
throw new Exception("重复订阅");
|
|
}
|
|
}
|
|
|
|
|
|
return dataJson.getJSONObject("Data");
|
|
return dataJson.getJSONObject("Data");
|
|
}
|
|
}
|
|
|
|
|
|
- public String getMatchMsg(Integer matchStatus,Integer maskFlag,BigDecimal temperature,TemperatureConfig temperatureConfig){
|
|
|
|
|
|
+ public String getMatchMsg(Integer matchStatus, Integer maskFlag, BigDecimal temperature, TemperatureConfig temperatureConfig) {
|
|
String matchMsg = "";
|
|
String matchMsg = "";
|
|
- if (matchStatus ==1){
|
|
|
|
|
|
+ if (matchStatus == 1) {
|
|
matchMsg = "核验成功";
|
|
matchMsg = "核验成功";
|
|
- }
|
|
|
|
- else if (matchStatus == 2){
|
|
|
|
|
|
+ } else if (matchStatus == 2) {
|
|
matchMsg = "对比失败";
|
|
matchMsg = "对比失败";
|
|
- }
|
|
|
|
- else if (matchStatus == 3){
|
|
|
|
|
|
+ } else if (matchStatus == 3) {
|
|
matchMsg = "对比成功,不在布控时间";
|
|
matchMsg = "对比成功,不在布控时间";
|
|
- }
|
|
|
|
- else if (matchStatus == 7){
|
|
|
|
|
|
+ } else if (matchStatus == 7) {
|
|
matchMsg = "刷脸开门模式下,刷脸成功";
|
|
matchMsg = "刷脸开门模式下,刷脸成功";
|
|
- }
|
|
|
|
-
|
|
|
|
- else if (matchStatus == 10){
|
|
|
|
- if (temperature.compareTo(new BigDecimal(temperatureConfig.getMax())) ==1){
|
|
|
|
|
|
+ } else if (matchStatus == 10) {
|
|
|
|
+ if (temperature.compareTo(new BigDecimal(temperatureConfig.getMax())) == 1) {
|
|
matchMsg = "对比成功,体温异常";
|
|
matchMsg = "对比成功,体温异常";
|
|
- }else if (maskFlag == 1){
|
|
|
|
|
|
+ } else if (maskFlag == 1) {
|
|
matchMsg = "对比成功,未戴口罩";
|
|
matchMsg = "对比成功,未戴口罩";
|
|
- }else {
|
|
|
|
|
|
+ } else {
|
|
matchMsg = "对比成功,人脸属性异常";
|
|
matchMsg = "对比成功,人脸属性异常";
|
|
}
|
|
}
|
|
|
|
|
|
- }
|
|
|
|
- else {
|
|
|
|
|
|
+ } else {
|
|
matchMsg = "未知匹配消息";
|
|
matchMsg = "未知匹配消息";
|
|
}
|
|
}
|
|
|
|
|
|
return matchMsg;
|
|
return matchMsg;
|
|
}
|
|
}
|
|
|
|
|
|
- public static Integer imageSize(String imageBase64Str){
|
|
|
|
|
|
+ public static Integer imageSize(String imageBase64Str) {
|
|
|
|
|
|
//1.找到等号,把等号也去掉(=用来填充base64字符串长度用)
|
|
//1.找到等号,把等号也去掉(=用来填充base64字符串长度用)
|
|
- Integer equalIndex= imageBase64Str.indexOf("=");
|
|
|
|
- if(imageBase64Str.indexOf("=")>0) {
|
|
|
|
- imageBase64Str=imageBase64Str.substring(0, equalIndex);
|
|
|
|
|
|
+ Integer equalIndex = imageBase64Str.indexOf("=");
|
|
|
|
+ if (imageBase64Str.indexOf("=") > 0) {
|
|
|
|
+ imageBase64Str = imageBase64Str.substring(0, equalIndex);
|
|
}
|
|
}
|
|
//2.原来的字符流大小,单位为字节
|
|
//2.原来的字符流大小,单位为字节
|
|
- Integer strLength=imageBase64Str.length();
|
|
|
|
- // System.out.println("imageBase64Str Length = "+strLength);
|
|
|
|
|
|
+ Integer strLength = imageBase64Str.length();
|
|
|
|
+ // System.out.println("imageBase64Str Length = "+strLength);
|
|
//3.计算后得到的文件流大小,单位为字节
|
|
//3.计算后得到的文件流大小,单位为字节
|
|
- Integer size=strLength-(strLength/8)*2;
|
|
|
|
|
|
+ Integer size = strLength - (strLength / 8) * 2;
|
|
return size;
|
|
return size;
|
|
}
|
|
}
|
|
|
|
|
|
- public static Integer getPersonCode(cn.hutool.json.JSONObject libMatInfoListJson, cn.hutool.json.JSONObject matchPersonInfo){
|
|
|
|
- if (org.apache.commons.lang.StringUtils.isNotBlank(libMatInfoListJson.getStr("MatchPersonID"))){
|
|
|
|
- if (!libMatInfoListJson.getStr("MatchPersonID").equals("0") && org.apache.commons.lang3.StringUtils.isNotBlank(matchPersonInfo.getStr("PersonCode"))){
|
|
|
|
- return matchPersonInfo.getInt("PersonCode");
|
|
|
|
-
|
|
|
|
- }else if (!libMatInfoListJson.getStr("MatchPersonID").equals("0") && org.apache.commons.lang3.StringUtils.isBlank(matchPersonInfo.getStr("PersonCode")) && StringUtils.isNotBlank(matchPersonInfo.getStr("PersonName"))){
|
|
|
|
- String personName = matchPersonInfo.getStr("PersonName");
|
|
|
|
- if (personName.contains("_")){
|
|
|
|
- log.warn(personName+"校验成功但未找到personCode");
|
|
|
|
- Integer personId =Integer.valueOf(personName.substring(personName.indexOf("_")+1)) ;
|
|
|
|
- return personId;
|
|
|
|
- }else {
|
|
|
|
- log.warn(personName+"校验成功但姓名中无personCode后缀");
|
|
|
|
- return 0;
|
|
|
|
- }
|
|
|
|
|
|
+ public static PersonInfo getPersonCode(cn.hutool.json.JSONObject libMatInfoListJson, cn.hutool.json.JSONObject matchPersonInfo) {
|
|
|
|
+ PersonInfo personInfo = new PersonInfo();
|
|
|
|
+ String personName = "";
|
|
|
|
+ Long personId = 0L;
|
|
|
|
+ String identityNo = "";
|
|
|
|
+ if (org.apache.commons.lang.StringUtils.isNotBlank(libMatInfoListJson.getStr("MatchPersonID"))) {
|
|
|
|
+ personName = matchPersonInfo.getStr("PersonName");
|
|
|
|
+ personId = libMatInfoListJson.getLong("MatchPersonID");
|
|
|
|
+ identityNo = matchPersonInfo.getStr("IdentityNo");
|
|
|
|
+ if (personName.contains("_")) {
|
|
|
|
+ personId = Long.valueOf(personName.substring(personName.indexOf("_") + 1));
|
|
|
|
+ personName = personName.substring(0, personName.indexOf("_"));
|
|
|
|
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
- else {
|
|
|
|
- return 0;
|
|
|
|
- }
|
|
|
|
- }else {
|
|
|
|
- return 0;
|
|
|
|
|
|
+
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
+ personInfo.setId(personId);
|
|
|
|
+ personInfo.setName(personName);
|
|
|
|
+ personInfo.setIdCard(identityNo);
|
|
|
|
+ return personInfo;
|
|
|
|
+
|
|
|
|
+
|
|
}
|
|
}
|
|
|
|
|
|
- public static boolean compareToInterval(BigDecimal bigDecimal, float min,float max){
|
|
|
|
- if (bigDecimal.compareTo(new BigDecimal(min))==-1 || bigDecimal.compareTo(new BigDecimal(max)) ==1){
|
|
|
|
|
|
+ public static boolean compareToInterval(BigDecimal bigDecimal, float min, float max) {
|
|
|
|
+ if (bigDecimal.compareTo(new BigDecimal(min)) == -1 || bigDecimal.compareTo(new BigDecimal(max)) == 1) {
|
|
return false;
|
|
return false;
|
|
- }
|
|
|
|
- else {
|
|
|
|
|
|
+ } else {
|
|
return true;
|
|
return true;
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
-
|
|
|
|
public static void main(String[] args) {
|
|
public static void main(String[] args) {
|
|
- // Date date = new Date(1584405803000L);
|
|
|
|
- // Date date = new
|
|
|
|
- // Date date = new Date();
|
|
|
|
- // long time = date.getTime();
|
|
|
|
- // System.out.println(date);
|
|
|
|
- // 192.168.11.13:80/V1.0/PeopleLibraries/1584409665/People/1111?LastChange=1584428390872
|
|
|
|
|
|
+ // Date date = new Date(1584405803000L);
|
|
|
|
+ // Date date = new
|
|
|
|
+ // Date date = new Date();
|
|
|
|
+ // long time = date.getTime();
|
|
|
|
+ // System.out.println(date);
|
|
|
|
+ // 192.168.11.13:80/V1.0/PeopleLibraries/1584409665/People/1111?LastChange=1584428390872
|
|
// cn.hutool.json.JSONObject jsonObject = new cn.hutool.json.JSONObject();
|
|
// cn.hutool.json.JSONObject jsonObject = new cn.hutool.json.JSONObject();
|
|
// Integer integer = getPersonCode(jsonObject,jsonObject);
|
|
// Integer integer = getPersonCode(jsonObject,jsonObject);
|
|
// System.out.println(integer);
|
|
// System.out.println(integer);
|
|
- Map<String,Object> map = new HashMap<>();
|
|
|
|
|
|
+ Map<String, Object> map = new HashMap<>();
|
|
|
|
|
|
// String requestStr = HttpRequest.post("http://www.baidu.com")
|
|
// String requestStr = HttpRequest.post("http://www.baidu.com")
|
|
// .timeout(TIMEOUT)
|
|
// .timeout(TIMEOUT)
|