数据bug修改
This commit is contained in:
parent
eefb05f733
commit
60c21e3ad0
|
|
@ -1,5 +1,6 @@
|
|||
package com.bonus.common.core.utils.http;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.http.*;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
|
||||
|
|
@ -8,6 +9,7 @@ import org.springframework.web.client.RestTemplate;
|
|||
* @data 2023/1/5 15:14
|
||||
* @description 工具类
|
||||
*/
|
||||
@Slf4j
|
||||
public class HttpUtils {
|
||||
static RestTemplate client = new RestTemplate();
|
||||
/**
|
||||
|
|
@ -19,17 +21,21 @@ public class HttpUtils {
|
|||
* @return 数据
|
||||
*/
|
||||
public static String sendRequest(String url, Object params, boolean type) {
|
||||
//新建Http头,add方法可以添加参数
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
//设置请求发送方式
|
||||
HttpMethod method = type ? HttpMethod.POST : HttpMethod.GET;
|
||||
//以表单的方式提交
|
||||
headers.setContentType(MediaType.APPLICATION_JSON);
|
||||
//将请求头部和参数合成一个请求
|
||||
HttpEntity<Object> requestEntity = new HttpEntity<>(params, headers);
|
||||
//执行HTTP请求,将返回的结构使用String类格式化(可以设置为对应返回值格式的类)
|
||||
ResponseEntity<String> response = client.exchange(url, method, requestEntity, String.class);
|
||||
|
||||
return response.getBody();
|
||||
try{
|
||||
//新建Http头,add方法可以添加参数
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
//设置请求发送方式
|
||||
HttpMethod method = type ? HttpMethod.POST : HttpMethod.GET;
|
||||
//以表单的方式提交
|
||||
headers.setContentType(MediaType.APPLICATION_JSON);
|
||||
//将请求头部和参数合成一个请求
|
||||
HttpEntity<Object> requestEntity = new HttpEntity<>(params, headers);
|
||||
//执行HTTP请求,将返回的结构使用String类格式化(可以设置为对应返回值格式的类)
|
||||
ResponseEntity<String> response = client.exchange(url, method, requestEntity, String.class);
|
||||
return response.getBody();
|
||||
}catch (Exception e){
|
||||
log.error(e.toString(),e);
|
||||
return "";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -141,5 +141,5 @@ public class StayPersonEntity {
|
|||
/**
|
||||
* 人脸验证信息
|
||||
*/
|
||||
private int faceStatus;
|
||||
private Integer faceStatus;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -41,7 +41,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||
</if>
|
||||
</select>
|
||||
<select id="getBoxInfo" resultType="com.bonus.app.entity.BraceletEntity">
|
||||
select blt.sh_code shCode,blt.id devId,peopel_type userType, blt.bid_id userId,blt.sh_name,shName,
|
||||
select blt.sh_code shCode,blt.id devId,peopel_type userType, blt.bid_id userId,blt.sh_name shName,
|
||||
tpp.lat sgLat ,tpp.lon sgLon,team.team_name teamName,blt.face_status faceStatus,
|
||||
case
|
||||
WHEN peopel_type=0 then tpe.name
|
||||
|
|
@ -85,7 +85,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||
</if>
|
||||
</select>
|
||||
<select id="getBoxInfoBid" resultType="com.bonus.app.entity.BraceletEntity">
|
||||
select blt.sh_code shCode,blt.id devId,peopel_type userType, blt.bid_id userId,blt.sh_name,shName,
|
||||
select blt.sh_code shCode,blt.id devId,peopel_type userType, blt.bid_id userId,blt.sh_name shName,
|
||||
tpp.lat sgLat ,tpp.lon sgLon,blt.face_status faceStatus,
|
||||
case
|
||||
WHEN peopel_type=0 then tpe.name
|
||||
|
|
|
|||
|
|
@ -38,20 +38,63 @@ public class FaceInterUtilService2 {
|
|||
*/
|
||||
public final static String sbface="facerecognition";
|
||||
|
||||
/**
|
||||
* 识别人脸库
|
||||
*/
|
||||
public final static String getBlob="featuredetect";
|
||||
|
||||
public static void main(String[] args) {
|
||||
// 指定要转换的图片路径
|
||||
String imagePath = "C:\\Users\\86157\\Pictures\\Camera Roll\\1e3875a83e0f77fb29ceb0ad42adb68.jpg"; // 替换为实际图片路径
|
||||
String imagePath2 = "C:\\Users\\86157\\Pictures\\Camera Roll\\72186adbf4800e94256e7b8b126da33.jpg"; // 替换为实际图片路径
|
||||
try {
|
||||
String base64String = convertImageToBase64(imagePath);
|
||||
addFace2(base64String,FaceCodeUtil.DEL,"342622199312096833");
|
||||
String base64String = convertImageToBase64(imagePath2);
|
||||
String base64String2= convertImageToBase64(imagePath);
|
||||
Map<String,Object> map=getBlob2(base64String);
|
||||
Map<String,Object> map2=getBlob2(base64String2);
|
||||
Integer code= (Integer) map.get("code");
|
||||
if(200== (Integer) map.get("code")){
|
||||
String data= (String) map.get("data");
|
||||
String data2= (String) map2.get("data");
|
||||
double DB=calculateEuclideanDistance(data,data2);
|
||||
System.err.println(DB);
|
||||
}
|
||||
|
||||
|
||||
|
||||
// addFace2(base64String,FaceCodeUtil.DEL,"bz-94");
|
||||
} catch (IOException e) {
|
||||
System.err.println("Error converting image to Base64: " + e.getMessage());
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 识别代码
|
||||
* @param str1
|
||||
* @param str2
|
||||
* @return
|
||||
*/
|
||||
public static double calculateEuclideanDistance(String str1, String str2) {
|
||||
JSONArray features1=JSON.parseArray(str1);
|
||||
JSONArray features2=JSON.parseArray(str2);
|
||||
JSONArray features3=null;
|
||||
if(features1.size()>features2.size()){
|
||||
features3=features2;
|
||||
features2=features1;
|
||||
features1=features3;
|
||||
}
|
||||
|
||||
// if (features1.size() != features2.size()) {
|
||||
// return 0;
|
||||
// }
|
||||
double sum = 0;
|
||||
for (int i = 0; i < features1.size(); i++) {
|
||||
sum += Float.parseFloat(features1.get(i).toString()) * Float.parseFloat(features2.get(i).toString());
|
||||
}
|
||||
return sum;
|
||||
}
|
||||
|
||||
|
||||
public static void addFace2(String image, String type, String id) {
|
||||
Map<String,Object> result= Maps.newHashMap();
|
||||
try{
|
||||
|
|
@ -83,6 +126,65 @@ public class FaceInterUtilService2 {
|
|||
// return AjaxResult.error("人脸识别接口异常!请检查人脸服务!");
|
||||
|
||||
}
|
||||
public static Map<String,Object> getBlob2(String image) {
|
||||
Map<String,Object> result= Maps.newHashMap();
|
||||
try{
|
||||
Map<String,Object> map= Maps.newHashMap();
|
||||
map.put("img",image);
|
||||
String msg= HttpUtils.sendRequest("http://192.168.0.14:18017/"+"featuredetect",JSON.toJSONString(map),true);
|
||||
if(StringUtils.isNotEmpty(msg)){
|
||||
JSONObject json=JSON.parseObject(msg);
|
||||
JSONArray jsonArray = json.getJSONArray("data");
|
||||
System.err.println(jsonArray);
|
||||
String data=json.getString("data");
|
||||
String code=json.getString("code");
|
||||
String eMsg=json.getString("msg");
|
||||
JSONArray array=JSON.parseArray(data);
|
||||
String object= array.get(0).toString();
|
||||
result.put("data",object);
|
||||
if("30002".equals(code)){
|
||||
result.put("code",200);
|
||||
}else {
|
||||
result.put("code",201);
|
||||
}
|
||||
String msgCN= FaceCodeUtil.getCodeString(code);
|
||||
result.put("msg",msgCN);
|
||||
result.put("eMsg",eMsg);
|
||||
}else{
|
||||
result.put("code",201);
|
||||
result.put("msg","人脸识别接口异常!请检查人脸服务!");
|
||||
}
|
||||
|
||||
}catch (Exception e){
|
||||
result.put("code",201);
|
||||
result.put("msg","图片未检测到人人脸");
|
||||
log.error(e.toString(),e);
|
||||
}
|
||||
return result;
|
||||
|
||||
}
|
||||
|
||||
// 将String转换回float数组
|
||||
public static float[] stringToArray(String floatArrayString) {
|
||||
JSONArray array=JSON.parseArray(floatArrayString);
|
||||
for (int i = 0; i < array.size(); i++) {
|
||||
// String json=array.get(0);
|
||||
|
||||
|
||||
|
||||
}
|
||||
// 移除外围的方括号
|
||||
floatArrayString = floatArrayString.substring(1, floatArrayString.length() - 1);
|
||||
// 根据逗号分割字符串
|
||||
String[] stringElements = floatArrayString.split(", ");
|
||||
// 将字符串数组转换为float数组
|
||||
float[] floatArray = new float[stringElements.length];
|
||||
for (int i = 0; i < stringElements.length; i++) {
|
||||
floatArray[i] = Float.parseFloat(stringElements[i]);
|
||||
}
|
||||
return floatArray;
|
||||
}
|
||||
|
||||
/**
|
||||
* 人脸信进行修改
|
||||
* @param image
|
||||
|
|
@ -98,6 +200,37 @@ public class FaceInterUtilService2 {
|
|||
map.put("img",image);
|
||||
map.put("optMode",type);
|
||||
map.put("uniqueKey",id);
|
||||
String msg=HttpUtils.sendRequest(faceUrl+getBlob,JSON.toJSONString(map),true);
|
||||
if(StringUtils.isNotEmpty(msg)){
|
||||
JSONObject json=JSON.parseObject(msg);
|
||||
String code=json.getString("code");
|
||||
String eMsg=json.getString("msg");
|
||||
if("30002".equals(code)){
|
||||
result.put("code",200);
|
||||
}else {
|
||||
result.put("code",201);
|
||||
}
|
||||
String msgCN= FaceCodeUtil.getCodeString(code);
|
||||
result.put("msg",msgCN);
|
||||
result.put("eMsg",eMsg);
|
||||
}else{
|
||||
result.put("code",201);
|
||||
result.put("msg","人脸识别接口异常!请检查人脸服务!");
|
||||
}
|
||||
return AjaxResult.success(result);
|
||||
}catch (Exception e){
|
||||
log.error(e.toString(),e);
|
||||
}
|
||||
return AjaxResult.error("人脸识别接口异常!请检查人脸服务!");
|
||||
|
||||
}
|
||||
|
||||
public AjaxResult getBlob(String image) {
|
||||
Map<String,Object> result= Maps.newHashMap();
|
||||
try{
|
||||
Map<String,Object> map= Maps.newHashMap();
|
||||
map.put("img",image);
|
||||
|
||||
String msg=HttpUtils.sendRequest(faceUrl+addFace,JSON.toJSONString(map),true);
|
||||
if(StringUtils.isNotEmpty(msg)){
|
||||
JSONObject json=JSON.parseObject(msg);
|
||||
|
|
@ -185,6 +318,8 @@ public class FaceInterUtilService2 {
|
|||
result.put("msg","人脸识别接口异常!请检查人脸服务!");
|
||||
}
|
||||
}catch (Exception e){
|
||||
result.put("code",201);
|
||||
result.put("msg","未检测到人脸!");
|
||||
log.error(e.toString(),e);
|
||||
}
|
||||
return result;
|
||||
|
|
|
|||
|
|
@ -230,10 +230,10 @@ public class BraceletImageServiceImpl implements BraceletImageService {
|
|||
Map<String,Object> ajaxResult=faceInterUtilService2.verifyFace(vo.getImage());
|
||||
Integer code= (Integer) ajaxResult.get("code");
|
||||
if(code==200){
|
||||
//校验人id 去实际人员校验
|
||||
String userId= (String) ajaxResult.get("userId");
|
||||
userId=userId.split("-")[1];
|
||||
String bidId=mapper.getDevBindUser(vo);
|
||||
//校验人id 去实际人员校验
|
||||
String userId= (String) ajaxResult.get("userId");
|
||||
userId=userId.split("-")[1];
|
||||
String bidId=mapper.getDevBindUser(vo);
|
||||
if(userId.equals(bidId)){
|
||||
mapper.updateVerdateStatus(vo.getDevCode(),"1");
|
||||
return AjaxResult.success("校验成功");
|
||||
|
|
|
|||
Loading…
Reference in New Issue