diff --git a/on-visitor-web/.gitignore b/on-visitor-web/.gitignore new file mode 100644 index 0000000..7f628be --- /dev/null +++ b/on-visitor-web/.gitignore @@ -0,0 +1 @@ +src/main/webapp/ \ No newline at end of file diff --git a/on-visitor-web/pom.xml b/on-visitor-web/pom.xml index 800b00b..f9ded41 100644 --- a/on-visitor-web/pom.xml +++ b/on-visitor-web/pom.xml @@ -283,7 +283,7 @@ com.alibaba fastjson - 1.2.3 + 1.2.44 com.fasterxml.jackson.core @@ -300,6 +300,13 @@ spring-session-data-redis 2.0.1.RELEASE + + + + com.squareup.okhttp3 + okhttp + 3.14.9 + @@ -349,6 +356,7 @@ true + never false @@ -360,6 +368,7 @@ true + never false @@ -371,6 +380,7 @@ true + never false @@ -382,6 +392,7 @@ false + never true diff --git a/on-visitor-web/src/main/java/com/lecooai/visitor/web/config/BatchConfig.java b/on-visitor-web/src/main/java/com/lecooai/visitor/web/config/BatchConfig.java index 9ac39f3..6db71b5 100644 --- a/on-visitor-web/src/main/java/com/lecooai/visitor/web/config/BatchConfig.java +++ b/on-visitor-web/src/main/java/com/lecooai/visitor/web/config/BatchConfig.java @@ -59,21 +59,36 @@ public class BatchConfig { @Autowired private DataSource dataSource; - /*@Bean + + /** + * @Author yangkai + * @Description 重新计算人脸特征值,替换人脸 + * @Date 2024/5/8 + * @Param + * @return + **/ + @Bean public Job singleStepJob() { return jobBuilderFactory.get("singleStepJob") .listener(listener()) .start(itemReaderFromDBJobStep()) .build(); - }*/ + } - @Bean + /** + * @Author yangkai + * @Description 导入到新的saas系统中,注释不可删除 + * @Date 2024/5/8 + * @Param + * @return + **/ + /*@Bean public Job empStepJob() { return jobBuilderFactory.get("empStepJob") .listener(listener()) .start(empReaderFromDBJobStep()) .build(); - } + }*/ @Bean public Step uppercaseStep() { diff --git a/on-visitor-web/src/main/java/com/lecooai/visitor/web/sys/service/support/EmpServiceSupport.java b/on-visitor-web/src/main/java/com/lecooai/visitor/web/sys/service/support/EmpServiceSupport.java index 2651974..67b3fe6 100644 --- a/on-visitor-web/src/main/java/com/lecooai/visitor/web/sys/service/support/EmpServiceSupport.java +++ b/on-visitor-web/src/main/java/com/lecooai/visitor/web/sys/service/support/EmpServiceSupport.java @@ -395,7 +395,7 @@ public class EmpServiceSupport //移除掉第一次添加的管理员 String userCode = UserUtils.getUser().getUserCode(); if (!BusinessUtils.isSecAdmin(userCode)) { - userDataScopeService.deleteByOfficeCode(office.getOfficeCode()); +// userDataScopeService.deleteByOfficeCode(office.getOfficeCode()); } //调用新增 executeAddInfo(office, empIds, adminIds, flag); @@ -590,21 +590,18 @@ public class EmpServiceSupport return new ResponseInfo(ResponseCode.FACE_FETCH_FAIL, hasObj.getString("errMsg")); } - JSONObject obj = faceServiceSupport.hasface(token, id, base64Image); - JSONObject faceRectangle = obj.getJSONObject("data"); - int status = obj.getInteger("status"); + JSONObject obj = faceServiceSupport.getFaceExtraction(token, id, base64Image); - if (status != 0) { - return new ResponseInfo(ResponseCode.FACE_FETCH_FAIL, obj.getString("errMsg")); - } - if (!ObjectUtils.anyNotNull(faceRectangle) || faceRectangle.getJSONObject("faceRectangle").isEmpty()) { - return new ResponseInfo(ResponseCode.CW_FACE_IMG_NO_FACE, "no face"); + + if (!obj.containsKey("feature")) { + return new ResponseInfo(ResponseCode.FACE_FETCH_FAIL, obj.getString("errorMessage")); } + Date date = new Date(); emp.setUpdateTime(date); emp.setFaceImageName(newFileName); - JSONArray array = faceRectangle.getJSONArray("feature"); + JSONArray array = obj.getJSONArray("feature"); EmpFaceFeature empFaceFeature = new EmpFaceFeature(); empFaceFeature.setEmpId(id); @@ -632,8 +629,6 @@ public class EmpServiceSupport } this.updAuthMapping(emp); - - // } return new ResponseInfo(auditStatus); } catch (UnsupportedFormatException e){ @@ -641,6 +636,8 @@ public class EmpServiceSupport } catch (IOException e) { e.printStackTrace(); return new ResponseInfo(ResponseCode.FILE_UPLOAD_FAIL); + } catch (Exception e) { + throw new RuntimeException(e); } } @@ -1004,17 +1001,17 @@ public class EmpServiceSupport faceImage = faceImage.replaceAll("data:image/jpeg;base64,", ""); - JSONObject faceRectangle = faceServiceSupport.hasface("", emp.getId(), faceImage); - int status = faceRectangle.getInteger("status"); - faceRectangle = faceRectangle.getJSONObject("data"); + JSONObject faceRectangle = null; + try { + faceRectangle = faceServiceSupport.getFaceExtraction("", emp.getId(), faceImage); + } catch (Exception e) { + return e.getMessage(); + } String userName = emp.getRealName(); - if (status != 0) { - return "抱歉,您的账号 " + userName + " 注册失败,"+faceRectangle.getString("errMsg"); + if (!faceRectangle.containsKey("feature")) { + return "抱歉,您的账号 " + userName + " 注册失败,"+faceRectangle.getString("errorMessage"); } - if (!ObjectUtils.anyNotNull(faceRectangle) || faceRectangle.getJSONObject("faceRectangle").isEmpty()) { - return "抱歉,您的账号 " + userName + " 注册失败,上传的头像未找到人脸!"; - } JSONObject json = imageUtil.base64ToStorage(faceImage, true); @@ -1077,7 +1074,7 @@ public class EmpServiceSupport int status = getJson.getInteger("status"); String featureStr = ""; if (0 == status) { - featureStr = getJson.getString("feature"); + featureStr = getJson.getJSONArray("feature").toJSONString(); } else { return getJson; } diff --git a/on-visitor-web/src/main/java/com/lecooai/visitor/web/sys/service/support/FaceServiceSupport.java b/on-visitor-web/src/main/java/com/lecooai/visitor/web/sys/service/support/FaceServiceSupport.java index b2132e0..16f3ddb 100644 --- a/on-visitor-web/src/main/java/com/lecooai/visitor/web/sys/service/support/FaceServiceSupport.java +++ b/on-visitor-web/src/main/java/com/lecooai/visitor/web/sys/service/support/FaceServiceSupport.java @@ -4,27 +4,22 @@ package com.lecooai.visitor.web.sys.service.support; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; -import com.jeesite.common.config.Global; -import com.lecooai.visitor.web.sys.entity.EmpFaceFeature; +import com.jeesite.common.lang.StringUtils; import com.lecooai.visitor.web.sys.utils.ImageUtil; +import com.lecooai.visitor.web.utils.OkHttpUtil; import kong.unirest.HttpResponse; import kong.unirest.Unirest; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.ObjectUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; -import org.springframework.http.HttpEntity; -import org.springframework.http.HttpHeaders; -import org.springframework.http.MediaType; import org.springframework.stereotype.Component; -import org.springframework.util.LinkedMultiValueMap; -import org.springframework.util.MultiValueMap; import org.springframework.web.client.RestTemplate; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; -import java.util.Map; +import java.util.UUID; @Slf4j @Component @@ -36,9 +31,6 @@ public class FaceServiceSupport { @Value("${face.server}") private String faceServer; - @Value("${face.updServer}") - private String updFaceServer;//升级版本时测试用 - @Value("${face.authorizePath}") private String authorizePath; @@ -83,23 +75,6 @@ public class FaceServiceSupport { } public String getToken(){ - - - /********restTemplate 请求方式*************/ - /*HttpHeaders headers = new HttpHeaders(); - headers.setContentType(MediaType.APPLICATION_JSON); //OK - - MultiValueMap map = new LinkedMultiValueMap<>(); - map.add("name", uname); - map.add("password", password); - HttpEntity> entity = new HttpEntity<>(map.toSingleValueMap(), headers); - - String result = restTemplate.postForObject(faceServer + authorizePath, entity, String.class); - - log.info("Face Engine-authToken return >> " + result); - JSONObject resultJson = JSON.parseObject(result); - return resultJson.getJSONObject("result").getString("token");*/ - /*****Unirest 请求方式*****/ JSONObject paramJson = new JSONObject(); paramJson.put("name", user); @@ -112,207 +87,56 @@ public class FaceServiceSupport { String result = response.getBody(); JSONObject resultJson = JSON.parseObject(result); return resultJson.getJSONObject("result").getString("token"); - - - /********CURL 请求方式********/ - /*JSONObject paramJson = new JSONObject(); - paramJson.put("name", uname); - paramJson.put("password", password); - String content = paramJson.toJSONString(); - String[] cmds = {"curl", "--location", "--request", "POST", faceServer + authorizePath,"--data", content}; - log.info("------------"); - log.info(faceServer); - log.info("------------"); - String res = execCurl(cmds); - JSONObject json = JSONObject.parseObject(res); - JSONObject data = json.getJSONObject("result"); - String token = ""; - if(!data.isEmpty()){ - token = data.getString("token"); - } - return token;*/ } - public JSONObject getFaceExtraction(String token, String imageId, String imgBase64) { - - /********CURL 请求方式********/ - /*JSONObject paramJson = new JSONObject(); - paramJson.put("imageId", imageId); - paramJson.put("base64Data", imgBase64); - paramJson.put("detect", 1); - - String content = paramJson.toJSONString(); - String[] cmds = {"curl", "--location", "--request", "POST", faceServer + extractionPath, "--header", "Authorization: Bearer "+token, "--header", "Content-Type: application/json", "--data", content}; - String res = execCurl(cmds); - log.info("----------------"); - log.info(faceServer); - log.info("----------------"); - log.info("Face Engine-detectFace return >> " + res); - JSONObject json = JSONObject.parseObject(res); - JSONObject data = json.getJSONArray("result").getJSONObject(0); - return data;*/ - - - /********restTemplate 请求方式*************/ - HttpHeaders headers = new HttpHeaders(); - headers.setContentType(MediaType.APPLICATION_JSON); - headers.set("Authorization", "Bearer "+token); - MultiValueMap map = new LinkedMultiValueMap(); - - map.add("imageId", imageId); - map.add("base64Data", imgBase64); - map.add("detect", true); - map.add("quality", true); - HttpEntity> entity = new HttpEntity<>(map.toSingleValueMap(), headers); -// System.err.println(faceServer + extractionPath); - String emps = Global.getConfig("face.modeUpdEmps"); - - String path = faceServer; - System.err.println("emps==========1111"); - System.err.println(emps); - System.err.println(imageId); - - if (emps.contains(imageId)) { - System.err.println("---------------uuuuuuuuu"); - path = updFaceServer; - } - - System.err.println(faceServer); - System.err.println(updFaceServer); - System.err.println(path); - System.err.println("emps==========2222"); - String result = restTemplate.postForObject(path + extractionPath, entity, String.class, "face-detection"); + public JSONObject getFaceExtraction(String token, String imageId, String imgBase64) throws Exception { + imgBase64 = imgBase64.replace("data:image/jpeg;base64,", ""); + JSONObject j1 = new JSONObject().fluentPut("faceName","faceName").fluentPut("base64Data", imgBase64).fluentPut("detect", true).fluentPut("quality", true); + JSONArray jsonArray = new JSONArray().fluentAdd(j1); + System.out.println("获取特征值地址:"+faceServer + extractionPath); + System.out.println("获取特征值地址参数:"+jsonArray.toJSONString()); + String result = OkHttpUtil.postCvJson(faceServer+extractionPath, new JSONObject().fluentPut("images", jsonArray)); + System.err.println("获取特征值结果:"+result); -// log.info("Face Engine-detectFace return >> " + result); JSONObject resultJson = JSON.parseObject(result); + if (!resultJson.containsKey("errorCode") && 0==resultJson.getInteger("status")) { + return resultJson.getJSONArray("result").getJSONObject(0).getJSONArray("faces").getJSONObject(0); + } else { + return resultJson; + } -// System.err.println(resultJson.toJSONString()); - - return resultJson.getJSONArray("result").getJSONObject(0); - - - /*****Unirest 请求方式*****/ - /*JSONObject paramJson = new JSONObject(); - paramJson.put("imageId", imageId); - paramJson.put("base64Data", imgBase64); - paramJson.put("detect", 1); - - String content = paramJson.toJSONString(); - - HttpResponse response = Unirest.post(faceServer + extractionPath) - .header("Authorization", "Bearer "+token) - .header("Content-Type", "application/json") - .body(content) - .asString(); - String result = response.getBody(); - log.info("Face Engine-detectFace return >> " + result); - JSONObject resultJson = JSON.parseObject(result); - return resultJson.getJSONArray("result").getJSONObject(0);*/ } public JSONObject getFaceCheck(String token, String imageId, String imgBase64) throws Exception{ - - /********CURL 请求方式********/ - /*JSONObject paramJson = new JSONObject(); - paramJson.put("imageId", imageId); - paramJson.put("base64Data", imgBase64); - paramJson.put("detect", 1); - - String content = paramJson.toJSONString(); - String[] cmds = {"curl", "--location", "--request", "POST", faceServer + extractionPath, "--header", "Authorization: Bearer "+token, "--header", "Content-Type: application/json", "--data", content}; - String res = execCurl(cmds); - log.info("----------------"); - log.info(faceServer); - log.info("----------------"); - log.info("Face Engine-detectFace return >> " + res); - JSONObject json = JSONObject.parseObject(res); - JSONObject data = json.getJSONArray("result").getJSONObject(0); - return data;*/ - - - /********restTemplate 请求方式*************/ - try { - imgBase64 = imgBase64.replaceAll("data:image/jpeg;base64,", ""); - HttpHeaders headers = new HttpHeaders(); - headers.setContentType(MediaType.APPLICATION_JSON); - headers.set("Authorization", "Bearer "+token); - MultiValueMap map = new LinkedMultiValueMap(); - -// map.add("imageId", imageId); -// map.add("base64Data", imgBase64); - JSONArray jsonArray = new JSONArray(); - JSONObject jsonObject = new JSONObject(); - jsonObject.put("imageId",imageId); - jsonObject.put("base64Data",imgBase64); - jsonArray.add(jsonObject); - map.add("detect", true); - map.add("images", jsonArray); - HttpEntity> entity = new HttpEntity<>(map.toSingleValueMap(), headers); -// System.err.println(faceServer + extractionPath); - String result = restTemplate.postForObject(faceServer + qualityPath, entity, String.class, "face-detection"); - - -// log.info("Face Engine-detectFace return >> " + result); - JSONObject resultJson = JSON.parseObject(result); - - return resultJson.getJSONArray("result").getJSONObject(0); - } catch (Exception e) { - throw e; - } - - - - /*****Unirest 请求方式*****/ - /*JSONObject paramJson = new JSONObject(); - paramJson.put("imageId", imageId); - paramJson.put("base64Data", imgBase64); - paramJson.put("detect", 1); - - String content = paramJson.toJSONString(); - - HttpResponse response = Unirest.post(faceServer + extractionPath) - .header("Authorization", "Bearer "+token) - .header("Content-Type", "application/json") - .body(content) - .asString(); - String result = response.getBody(); - log.info("Face Engine-detectFace return >> " + result); + imgBase64 = imgBase64.replace("data:image/jpeg;base64,", ""); + JSONObject jsonObject = new JSONObject(); + jsonObject.put("imageId", StringUtils.isEmpty(imageId)? UUID.randomUUID().toString():imageId); + jsonObject.put("base64Data",imgBase64); + jsonObject.put("detect", true); + JSONArray jsonArray = new JSONArray().fluentAdd(jsonObject); + + System.out.println("获取特征值地址:"+faceServer + qualityPath); + String result = OkHttpUtil.postCvJson(faceServer+qualityPath, new JSONObject().fluentPut("images", jsonArray)); + System.err.println("人脸检测结果:"+result); JSONObject resultJson = JSON.parseObject(result); - return resultJson.getJSONArray("result").getJSONObject(0);*/ + return resultJson.getJSONArray("result").getJSONObject(0); } public JSONObject hasface(String token, String imageId, String imgBase64) { /********CURL 请求方式********/ - /*JSONObject paramJson = new JSONObject(); - paramJson.put("imageId", imageId); - paramJson.put("base64Data", imgBase64); - paramJson.put("detect", 1); - - String content = paramJson.toJSONString(); - String[] cmds = {"curl", "--location", "--request", "POST", faceServer + extractionPath, "--header", "Authorization: Bearer "+token, "--header", "Content-Type: application/json", "--data", content}; - String res = execCurl(cmds); - log.info("----------------"); - log.info(faceServer); - log.info("----------------"); - log.info("Face Engine-detectFace return >> " + res); - JSONObject json = JSONObject.parseObject(res); - JSONObject data = json.getJSONArray("result").getJSONObject(0); - return data;*/ JSONObject json = new JSONObject(); try { - imgBase64 = imgBase64.replaceAll("data:image/jpeg;base64,", ""); - JSONObject res = this.getFaceExtraction(token, imageId, imgBase64); - - JSONObject obj = res.getJSONArray("faces").getJSONObject(0); + imgBase64 = imgBase64.replace("data:image/jpeg;base64,", ""); + JSONObject res = this.getFaceCheck(token, imageId, imgBase64); - if (!obj.isEmpty()) { + if (res != null && res.getBoolean("passed")){ json.put("status", 0); - json.put("data", obj); + json.put("data", res); return json; } else { json.put("status", 500); @@ -330,62 +154,17 @@ public class FaceServiceSupport { } - - /*****Unirest 请求方式*****/ - /*JSONObject paramJson = new JSONObject(); - paramJson.put("imageId", imageId); - paramJson.put("base64Data", imgBase64); - paramJson.put("detect", 1); - - String content = paramJson.toJSONString(); - - HttpResponse response = Unirest.post(faceServer + extractionPath) - .header("Authorization", "Bearer "+token) - .header("Content-Type", "application/json") - .body(content) - .asString(); - String result = response.getBody(); - log.info("Face Engine-detectFace return >> " + result); - JSONObject resultJson = JSON.parseObject(result); - return resultJson.getJSONArray("result").getJSONObject(0);*/ } public JSONObject regCheckFace(String token, String imageId, String imgBase64) { - /********CURL 请求方式********/ - /*JSONObject paramJson = new JSONObject(); - paramJson.put("imageId", imageId); - paramJson.put("base64Data", imgBase64); - paramJson.put("detect", 1); - - String content = paramJson.toJSONString(); - String[] cmds = {"curl", "--location", "--request", "POST", faceServer + extractionPath, "--header", "Authorization: Bearer "+token, "--header", "Content-Type: application/json", "--data", content}; - String res = execCurl(cmds); - log.info("----------------"); - log.info(faceServer); - log.info("----------------"); - log.info("Face Engine-detectFace return >> " + res); - JSONObject json = JSONObject.parseObject(res); - JSONObject data = json.getJSONArray("result").getJSONObject(0); - return data;*/ JSONObject json = new JSONObject(); - try { - imgBase64 = imgBase64.replaceAll("data:image/jpeg;base64,", ""); + imgBase64 = imgBase64.replace("data:image/jpeg;base64,", ""); JSONObject res = this.getFaceCheck(token, imageId, imgBase64); - Boolean passed = res.getBoolean("passed"); - - if (!ObjectUtils.anyNotNull(passed)) { - json.put("status", 500); - json.put("data", null); - json.put("errMsg", "所拍摄的照片重人脸不存在"); - return json; - } - - if (!passed) { - json.put("status", 500); - json.put("data", res); + if (res == null || !res.getBoolean("passed")){ + json.fluentPut("status", 500).fluentPut("data", res); double blur = res.getDouble("blur"); double pose = res.getDouble("pose"); double occ = res.getDouble("occ"); @@ -402,17 +181,12 @@ public class FaceServiceSupport { errMsg = "人脸检测失败,光线太暗,请到明亮点的地方重新拍摄"; } - json.put("errMsg", errMsg); - json.put("data", res); + json.fluentPut("errMsg", errMsg).fluentPut("data", res); } else { - json.put("status", 0); - json.put("data", res); - json.put("errMsg", ""); + json.fluentPut("status", 0).fluentPut("data", res).fluentPut("errMsg", ""); } - return json; - } catch (Exception e) { e.printStackTrace(); json.put("status", 500); @@ -420,26 +194,6 @@ public class FaceServiceSupport { json.put("errMsg", e.getMessage()); return json; } - - - - /*****Unirest 请求方式*****/ - /*JSONObject paramJson = new JSONObject(); - paramJson.put("imageId", imageId); - paramJson.put("base64Data", imgBase64); - paramJson.put("detect", 1); - - String content = paramJson.toJSONString(); - - HttpResponse response = Unirest.post(faceServer + extractionPath) - .header("Authorization", "Bearer "+token) - .header("Content-Type", "application/json") - .body(content) - .asString(); - String result = response.getBody(); - log.info("Face Engine-detectFace return >> " + result); - JSONObject resultJson = JSON.parseObject(result); - return resultJson.getJSONArray("result").getJSONObject(0);*/ } @@ -454,17 +208,18 @@ public class FaceServiceSupport { json.put("errMsg", "imagePath不能为空"); return json; } - JSONObject faceRectangle = this.hasface("", empId, base64Image); - int status = faceRectangle.getInteger("status"); - faceRectangle = faceRectangle.getJSONObject("data"); - if (status != 0) { - json.put("status",status); - json.put("errMsg"," 特征值提取失败,"+faceRectangle.getString("errMsg")); + JSONObject faceRectangle = null; + try { + faceRectangle = this.getFaceExtraction("", empId, base64Image); + } catch (Exception e) { + json.put("status",504); + json.put("errMsg",e.getMessage()); return json; } - if (!ObjectUtils.anyNotNull(faceRectangle) || faceRectangle.getJSONObject("faceRectangle").isEmpty()) { - json.put("status",504); - json.put("errMsg"," 特征值提取失败,上传的头像未找到人脸!"); + + if (!faceRectangle.containsKey("feature")) { + json.put("status",500); + json.put("errMsg"," 特征值提取失败,"+faceRectangle.getString("errorMessage")); return json; } diff --git a/on-visitor-web/src/main/java/com/lecooai/visitor/web/sys/web/Account2Controller.java b/on-visitor-web/src/main/java/com/lecooai/visitor/web/sys/web/Account2Controller.java index 4716a2a..42b7bcb 100644 --- a/on-visitor-web/src/main/java/com/lecooai/visitor/web/sys/web/Account2Controller.java +++ b/on-visitor-web/src/main/java/com/lecooai/visitor/web/sys/web/Account2Controller.java @@ -22,7 +22,6 @@ import com.jeesite.modules.sys.dao.UserDataScopeDao; import com.jeesite.modules.sys.dao.UserRoleDao; import com.jeesite.modules.sys.entity.Office; import com.jeesite.modules.sys.entity.User; -import com.jeesite.modules.sys.entity.UserRole; import com.jeesite.modules.sys.service.OfficeService; import com.jeesite.modules.sys.service.UserService; import com.jeesite.modules.sys.utils.LogUtils; @@ -30,15 +29,22 @@ import com.jeesite.modules.sys.utils.PwdUtils; import com.jeesite.modules.sys.utils.UserUtils; import com.lecooai.visitor.web.controller.WxBaseController; import com.lecooai.visitor.web.sys.constant.ResponseCode; -import com.lecooai.visitor.web.sys.dao.*; +import com.lecooai.visitor.web.sys.dao.AuditRecordsDao; +import com.lecooai.visitor.web.sys.dao.AuthMappingDao; +import com.lecooai.visitor.web.sys.dao.EmpDao; +import com.lecooai.visitor.web.sys.dao.EmpFaceFeatureDao; +import com.lecooai.visitor.web.sys.dao.EmpUserRoleDao; +import com.lecooai.visitor.web.sys.dao.UserExtraDao; import com.lecooai.visitor.web.sys.entity.AuditRecords; import com.lecooai.visitor.web.sys.entity.Emp; import com.lecooai.visitor.web.sys.service.AdminService; import com.lecooai.visitor.web.sys.service.UserDataScopeService; import com.lecooai.visitor.web.sys.service.support.EmpServiceSupport; import com.lecooai.visitor.web.sys.service.support.FaceServiceSupport; -import com.lecooai.visitor.web.sys.utils.*; -import com.sun.org.apache.regexp.internal.RE; +import com.lecooai.visitor.web.sys.utils.ImageUtil; +import com.lecooai.visitor.web.sys.utils.OfficeEmpUtils; +import com.lecooai.visitor.web.sys.utils.RedisUtils; +import com.lecooai.visitor.web.sys.utils.SendUtil; import lombok.AllArgsConstructor; import me.chanjar.weixin.common.error.WxErrorException; import org.apache.shiro.SecurityUtils; @@ -51,7 +57,12 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.stereotype.Controller; import org.springframework.transaction.annotation.Transactional; import org.springframework.ui.Model; -import org.springframework.web.bind.annotation.*; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.ResponseBody; import javax.servlet.http.Cookie; import javax.servlet.http.HttpServletRequest; @@ -627,18 +638,18 @@ public class Account2Controller extends WxBaseController { } else { return output(ResponseCode.CW_FACE_IMG_NO_FACE); } - if (!ObjectUtils.anyNotNull(faceObject.getJSONObject("faceRectangle")) || faceObject.getJSONObject("faceRectangle").isEmpty()) { - return output(ResponseCode.CW_FACE_IMG_NO_FACE); - } JSONObject json = imageUtil.base64ToStorage(faceImage, true); String errMsg = ""; if (json.getBoolean("ok")) { String imgUrl = json.getString("imgUrl"); - JSONArray array = faceObject.getJSONArray("feature"); - empService.faceUpdate(emp, imgUrl, array.toJSONString()); -// empService.updAuthMapping(emp);//修改人脸无需修改mapping表 + JSONObject faceRectangle = null; try { + JSONObject faceJson = faceServiceSupport.getFaceExtraction("", emp.getId(), faceImage); + JSONArray array = faceJson.getJSONArray("feature"); + empService.faceUpdate(emp, imgUrl, array.toJSONString()); +// empService.updAuthMapping(emp);//修改人脸无需修改mapping表 + RedisUtils.setUserVariables(user.getWxOpenid(), user.getUserType().equals("estate")?"1":"0"); sendUtil.sendRegToUser(getOfficeMgrUser(emp),"贵司员工"+emp.getRealName()+"人脸照片已修改,需您审核", emp, SendUtil.TYPE_COMPANY_MGR); } catch (WxErrorException e) { @@ -649,8 +660,7 @@ public class Account2Controller extends WxBaseController { LogUtils.saveLog(user, null, user.getUserName()+"修改人脸照片", "update"); } - - JSONObject jsonObject = new JSONObject(); + JSONObject jsonObject = new JSONObject(); jsonObject.put("faceImage", faceImage); jsonObject.put("userCode", userCode); jsonObject.put("message", errMsg); diff --git a/on-visitor-web/src/main/java/com/lecooai/visitor/web/sys/web/api/CommonApiController.java b/on-visitor-web/src/main/java/com/lecooai/visitor/web/sys/web/api/CommonApiController.java index e520849..12643f3 100644 --- a/on-visitor-web/src/main/java/com/lecooai/visitor/web/sys/web/api/CommonApiController.java +++ b/on-visitor-web/src/main/java/com/lecooai/visitor/web/sys/web/api/CommonApiController.java @@ -272,14 +272,13 @@ public class CommonApiController extends BaseController { String nowTs = map.getString("now_ts"); int maxCnt = map.getInteger("max_cnt"); String sign = map.getString("sign"); - - MyResponse myResponse = commonCheck(deviceId, timestamp, sign); + NumberFormat nf = NumberFormat.getInstance(); + nf.setGroupingUsed(false); + MyResponse myResponse = commonCheck(deviceId, nf.format(Double.parseDouble(timestamp)), sign); if (myResponse.getStatus() != 0) { return myResponse; } - NumberFormat nf = NumberFormat.getInstance(); - nf.setGroupingUsed(false); String ts = nf.format(Double.parseDouble(nowTs)); List list = authMappingDao.getByDevAndTime(deviceId, ts, maxCnt); JSONObject ja = new JSONObject(); @@ -338,8 +337,10 @@ public class CommonApiController extends BaseController { String faceScore = map.containsKey("faceScore") ? map.getString("faceScore") : "0"; String imgbase64 = map.getString("imgbase64"); String sign = map.getString("sign"); + NumberFormat nf = NumberFormat.getInstance(); + nf.setGroupingUsed(false); - MyResponse myResponse = commonCheck(deviceId, timestamp, sign); + MyResponse myResponse = commonCheck(deviceId, nf.format(Double.parseDouble(timestamp)), sign); if (myResponse.getStatus() != 0) { return myResponse; } @@ -401,8 +402,10 @@ public class CommonApiController extends BaseController { if (myResponse.getStatus() != 0) { return myResponse; } + NumberFormat nf = NumberFormat.getInstance(); + nf.setGroupingUsed(false); - myResponse = commonCheck(devId, timestamp, sign); + myResponse = commonCheck(devId, nf.format(Double.parseDouble(timestamp)), sign); if (myResponse.getStatus() != 0) { return myResponse; } @@ -543,8 +546,7 @@ public class CommonApiController extends BaseController { JSONObject faceObject = faceServiceSupport.hasface("", "", faceImage); if (ObjectUtils.anyNotNull(faceObject.get("data"))) { faceObject = faceObject.getJSONObject("data"); - } - if (!ObjectUtils.anyNotNull(faceObject) || !ObjectUtils.anyNotNull(faceObject.getJSONObject("faceRectangle")) || faceObject.getJSONObject("faceRectangle").isEmpty()) { + } else { return output(ResponseCode.CW_FACE_IMG_NO_FACE); } diff --git a/on-visitor-web/src/main/java/com/lecooai/visitor/web/sys/web/api/FaceApiController.java b/on-visitor-web/src/main/java/com/lecooai/visitor/web/sys/web/api/FaceApiController.java index 80fd002..fce81a0 100644 --- a/on-visitor-web/src/main/java/com/lecooai/visitor/web/sys/web/api/FaceApiController.java +++ b/on-visitor-web/src/main/java/com/lecooai/visitor/web/sys/web/api/FaceApiController.java @@ -99,15 +99,13 @@ public class FaceApiController extends BaseController { token = faceServiceSupport.getToken(); logger.info(Global.getConfig("faceServerI.hasAuthorize")); } - - - json = faceServiceSupport.getFaceExtraction(token, empId, base64Image); - obj = json.getJSONArray("faces").getJSONObject(0).getJSONArray("feature"); - faceRectangle = json.getJSONArray("faces").getJSONObject(0).getJSONObject("faceRectangle"); - if (!faceRectangle.isEmpty()) { + if (json.containsKey("feature")) { + obj = json.getJSONArray("feature"); faceFlag = true; + } else { + return "人脸特征值提取失败!"; } } catch (Exception e) { e.printStackTrace(); diff --git a/on-visitor-web/src/main/java/com/lecooai/visitor/web/utils/OkHttpUtil.java b/on-visitor-web/src/main/java/com/lecooai/visitor/web/utils/OkHttpUtil.java new file mode 100644 index 0000000..8259386 --- /dev/null +++ b/on-visitor-web/src/main/java/com/lecooai/visitor/web/utils/OkHttpUtil.java @@ -0,0 +1,325 @@ +package com.lecooai.visitor.web.utils; + +/** + * @author yk + * @description + * @date 2024-05-07 18:08 + */ +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONObject; +import lombok.SneakyThrows; +import okhttp3.*; + +import javax.net.ssl.SSLContext; +import javax.net.ssl.SSLSocketFactory; +import javax.net.ssl.TrustManager; +import javax.net.ssl.X509TrustManager; +import java.io.IOException; +import java.net.URLEncoder; +import java.security.SecureRandom; +import java.security.cert.X509Certificate; +import java.util.LinkedHashMap; +import java.util.Map; +import java.util.concurrent.Semaphore; +import java.util.concurrent.TimeUnit; + +public class OkHttpUtil { + private static volatile OkHttpClient okHttpClient = null; + private static volatile Semaphore semaphore = null; + private Map headerMap; + private Map paramMap; + private String url; + private Request.Builder request; + + /** + * 初始化okHttpClient,并且允许https访问 + */ + private OkHttpUtil() { + if (okHttpClient == null) { + synchronized (OkHttpUtil.class) { + if (okHttpClient == null) { + TrustManager[] trustManagers = buildTrustManagers(); + okHttpClient = new OkHttpClient.Builder() + .connectTimeout(15, TimeUnit.SECONDS) + .writeTimeout(20, TimeUnit.SECONDS) + .readTimeout(20, TimeUnit.SECONDS) + .sslSocketFactory(createSSLSocketFactory(trustManagers), (X509TrustManager) trustManagers[0]) + .hostnameVerifier((hostName, session) -> true) + .retryOnConnectionFailure(true) + .build(); + addHeader("User-Agent", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36"); + } + } + } + } + + /** + * 用于异步请求时,控制访问线程数,返回结果 + * + * @return + */ + private static Semaphore getSemaphoreInstance() { + //只能1个线程同时访问 + synchronized (OkHttpUtil.class) { + if (semaphore == null) { + semaphore = new Semaphore(0); + } + } + return semaphore; + } + + /** + * 创建OkHttpUtil + * + * @return + */ + public static OkHttpUtil builder() { + return new OkHttpUtil(); + } + + /** + * 添加url + * + * @param url + * @return + */ + public OkHttpUtil url(String url) { + this.url = url; + return this; + } + + /** + * 添加参数 + * + * @param key 参数名 + * @param value 参数值 + * @return + */ + public OkHttpUtil addParam(String key, String value) { + if (paramMap == null) { + paramMap = new LinkedHashMap<>(16); + } + paramMap.put(key, value); + return this; + } + + /** + * 添加请求头 + * + * @param key 参数名 + * @param value 参数值 + * @return + */ + public OkHttpUtil addHeader(String key, String value) { + if (headerMap == null) { + headerMap = new LinkedHashMap<>(16); + } + headerMap.put(key, value); + return this; + } + + /** + * 初始化get方法 + * + * @return + */ + public OkHttpUtil get() { + request = new Request.Builder().get(); + StringBuilder urlBuilder = new StringBuilder(url); + if (paramMap != null) { + urlBuilder.append("?"); + try { + for (Map.Entry entry : paramMap.entrySet()) { + urlBuilder.append(URLEncoder.encode(entry.getKey(), "utf-8")). + append("="). + append(URLEncoder.encode(entry.getValue(), "utf-8")). + append("&"); + } + } catch (Exception e) { + e.printStackTrace(); + } + urlBuilder.deleteCharAt(urlBuilder.length() - 1); + } + request.url(urlBuilder.toString()); + return this; + } + + /** + * 初始化post方法 + * + * @param isJsonPost true等于json的方式提交数据,类似postman里post方法的raw + * false等于普通的表单提交 + * @return + */ + public OkHttpUtil post(boolean isJsonPost) { + RequestBody requestBody; + if (isJsonPost) { + String json = ""; + if (paramMap != null) { + json = JSON.toJSONString(paramMap); + } + requestBody = RequestBody.create(MediaType.parse("application/json; charset=utf-8"), json); + } else { + FormBody.Builder formBody = new FormBody.Builder(); + if (paramMap != null) { + paramMap.forEach(formBody::add); + } + requestBody = formBody.build(); + } + request = new Request.Builder().post(requestBody).url(url); + return this; + } + + /** + * 同步请求 + * + * @return + */ + public String sync() { + setHeader(request); + try { + Response response = okHttpClient.newCall(request.build()).execute(); + assert response.body() != null; + return response.body().string(); + } catch (IOException e) { + e.printStackTrace(); + return "请求失败:" + e.getMessage(); + } + } + + /** + * 异步请求,有返回值 + */ + public String async() { + StringBuilder buffer = new StringBuilder(""); + setHeader(request); + okHttpClient.newCall(request.build()).enqueue(new Callback() { + @Override + public void onFailure(Call call, IOException e) { + buffer.append("请求出错:").append(e.getMessage()); + } + + @Override + public void onResponse(Call call, Response response) throws IOException { + assert response.body() != null; + buffer.append(response.body().string()); + getSemaphoreInstance().release(); + } + }); + try { + getSemaphoreInstance().acquire(); + } catch (InterruptedException e) { + e.printStackTrace(); + } + return buffer.toString(); + } + + /** + * 异步请求,带有接口回调 + * + * @param callBack + */ + public void async(ICallBack callBack) { + setHeader(request); + okHttpClient.newCall(request.build()).enqueue(new Callback() { + @Override + public void onFailure(Call call, IOException e) { + callBack.onFailure(call, e.getMessage()); + } + + @Override + public void onResponse(Call call, Response response) throws IOException { + assert response.body() != null; + callBack.onSuccessful(call, response.body().string()); + } + }); + } + + /** + * 为request添加请求头 + * + * @param request + */ + private void setHeader(Request.Builder request) { + if (headerMap != null) { + try { + for (Map.Entry entry : headerMap.entrySet()) { + request.addHeader(entry.getKey(), entry.getValue()); + } + } catch (Exception e) { + e.printStackTrace(); + } + } + } + + + /** + * 生成安全套接字工厂,用于https请求的证书跳过 + * + * @return + */ + private static SSLSocketFactory createSSLSocketFactory(TrustManager[] trustAllCerts) { + SSLSocketFactory ssfFactory = null; + try { + SSLContext sc = SSLContext.getInstance("SSL"); + sc.init(null, trustAllCerts, new SecureRandom()); + ssfFactory = sc.getSocketFactory(); + } catch (Exception e) { + e.printStackTrace(); + } + return ssfFactory; + } + + private static TrustManager[] buildTrustManagers() { + return new TrustManager[]{ + new X509TrustManager() { + @Override + public void checkClientTrusted(X509Certificate[] chain, String authType) { + } + + @Override + public void checkServerTrusted(X509Certificate[] chain, String authType) { + } + + @Override + public X509Certificate[] getAcceptedIssuers() { + return new X509Certificate[]{}; + } + } + }; + } + + /** + * 自定义一个接口回调 + */ + public interface ICallBack { + + void onSuccessful(Call call, String data); + + void onFailure(Call call, String errorMsg); + + } + + /** + * @Author yangkai + * @Description 联想研究院新算法,请求模版 + * @Date 2024/5/8 + * @Param [url, json] + * @return java.lang.String + **/ + public static String postCvJson(String url, JSONObject json) throws Exception{ + OkHttpClient client = new OkHttpClient().newBuilder() + .build(); + MediaType mediaType = MediaType.parse("application/json"); + RequestBody body = RequestBody.create(mediaType, json.toJSONString()); + + Request request = new Request.Builder() + .url(url) + .method("POST", body) + .addHeader("Content-Type", "application/json") + .addHeader("Authorization", "Basic ZmFjZS1tYW5hZ2VtZW50OmZhY2UtbWFuYWdlbWVudA==") + .build(); + Response response = client.newCall(request).execute(); + return response.body().string(); + } +} \ No newline at end of file diff --git a/on-visitor-web/src/main/resources/config/application-dev.yml b/on-visitor-web/src/main/resources/config/application-dev.yml index 34343b2..708608d 100644 --- a/on-visitor-web/src/main/resources/config/application-dev.yml +++ b/on-visitor-web/src/main/resources/config/application-dev.yml @@ -188,8 +188,8 @@ mqttClient: serverPort: 1883 clientId: mqtt_clientid_dev_2002 faceServerI: - ip: 8.131.78.156 - port: 5000 + ip: 123.56.73.158 + port: 30306 user: lecooai_hw01 password: lecooai@2021 hasAuthorize: false diff --git a/on-visitor-web/src/main/resources/config/application.yml b/on-visitor-web/src/main/resources/config/application.yml index 79c9678..9256059 100644 --- a/on-visitor-web/src/main/resources/config/application.yml +++ b/on-visitor-web/src/main/resources/config/application.yml @@ -531,10 +531,11 @@ mqtt: face: server: http://${faceServerI.ip}:${faceServerI.port} updServer: http://${faceServerII.ip}:${faceServerII.port} - authorizePath: /authorize +# authorizePath: /authorize # extractionPath: /apps/v1/function/cv/face-extraction - extractionPath: /cv/feature-extraction-service/1.7 - qualityPath: /cv/quality/1.7 + authorizePath: /authorize + extractionPath: /apps/v1/solution/cv/face-extraction + qualityPath: /apps/v1/solution/cv/face-quality modeUpdate: true modeUpdEmps: "'beeefac44ef94daca475ff85a5c720cd','65f061754e204484a955aba8154eec14','a0a0f615ec374d9bb1e1ace496e586d7','e83e30d959144a65b83beb3b841c10b5','0601b9fc00204224a671bcd47040be30','7cabfde922354b41ae66841e3d0cc4d3'" diff --git a/on-visitor-web/src/main/webapp/.gitignore b/on-visitor-web/src/main/webapp/.gitignore deleted file mode 100644 index 0e80f3c..0000000 --- a/on-visitor-web/src/main/webapp/.gitignore +++ /dev/null @@ -1 +0,0 @@ -/WEB-INF/ \ No newline at end of file