Bladeren bron

压缩图片问题

qzy 11 maanden geleden
bovenliggende
commit
728c95aeb9

+ 1 - 1
sp-core/sp-base/src/main/java/com/pj/face/handler/IFaceHandler.java

@@ -34,7 +34,7 @@ public interface IFaceHandler {
      * @param baseImage
      * @return
      */
-    boolean verify(String faceId, String baseImage);
+    VerifyVO verify(String faceId, String baseImage);
 
     /**
      * 人脸搜索

+ 9 - 0
sp-core/sp-base/src/main/java/com/pj/face/handler/VerifyVO.java

@@ -0,0 +1,9 @@
+package com.pj.face.handler;
+
+import lombok.Data;
+
+@Data
+public class VerifyVO {
+    private String msg;
+    private boolean success;
+}

+ 13 - 4
sp-core/sp-base/src/main/java/com/pj/face/handler/impl/TencenFaceHandlerImpl.java

@@ -3,6 +3,7 @@ package com.pj.face.handler.impl;
 import cn.hutool.log.StaticLog;
 import com.pj.face.brand.FaceBrand;
 import com.pj.face.handler.IFaceHandler;
+import com.pj.face.handler.VerifyVO;
 import com.pj.face.properties.TencenProperties;
 import com.pj.utils.sg.AjaxError;
 import com.tencentcloudapi.common.Credential;
@@ -32,7 +33,9 @@ public class TencenFaceHandlerImpl implements IFaceHandler {
     private TencenProperties tencenProperties;
 
     @Override
-    public boolean verify(String personId, String baseImage) {
+    public VerifyVO verify(String personId, String baseImage) {
+        VerifyVO vo = new VerifyVO();
+        vo.setSuccess(false);
         IaiClient client = this.createClient();
         VerifyPersonRequest req = new VerifyPersonRequest();
         req.setImage(baseImage);
@@ -43,18 +46,24 @@ public class TencenFaceHandlerImpl implements IFaceHandler {
             resp = client.VerifyPerson(req);
         } catch (TencentCloudSDKException e) {
             log.error("verify person : {} fail,{}", personId, e.getMessage());
-            throw new AjaxError(e.getMessage());
+            StaticLog.info("verify person : {} fail,{}", personId, e.getMessage());
+            vo.setMsg(e.getMessage());
+            return vo;
         }
-        return resp != null && resp.getIsMatch();
+        boolean result=resp != null && resp.getIsMatch();
+        vo.setMsg(result?"成功":"不匹配");
+        vo.setSuccess(result);
+        return vo;
     }
 
     /**
      * 查找人脸库
+     *
      * @param baseImg
      * @return
      */
     public List<String> faceSearch(String baseImg) {
-        StaticLog.info("face:{}",baseImg);
+        StaticLog.info("face:{}", baseImg);
         IaiClient client = this.createClient();
         SearchFacesRequest request = new SearchFacesRequest();
         request.setImage(baseImg);

+ 59 - 1
sp-service/sp-admin/src/main/java/com/pj/project/app_user/AppUserApiController.java

@@ -1,11 +1,18 @@
 package com.pj.project.app_user;
 
+import cn.hutool.core.thread.ThreadUtil;
+import cn.hutool.core.util.RandomUtil;
+import cn.hutool.core.util.StrUtil;
+import cn.hutool.log.StaticLog;
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.pj.api.consts.FeignFactory;
 import com.pj.api.dto.AppUserCreateDTO;
 import com.pj.api.dto.AppUserDto;
 import com.pj.api.dto.PeopleDto;
 import com.pj.api.dto.UpdateAccountDTO;
 import com.pj.current.satoken.StpAPPUserUtil;
+import com.pj.face.factory.FaceFactory;
 import com.pj.project.app_user.dto.ForgetPasswordDto;
 import com.pj.project.app_user.dto.LoginDto;
 import com.pj.project.app_user.dto.RegisterDto;
@@ -13,6 +20,14 @@ import com.pj.project.app_user.vo.AppUserVo;
 import com.pj.project4sp.utils.ImageUtils;
 import com.pj.utils.sg.AjaxJson;
 import com.pj.utils.so.SoMap;
+import com.tencentcloudapi.common.Credential;
+import com.tencentcloudapi.common.exception.TencentCloudSDKException;
+import com.tencentcloudapi.common.profile.ClientProfile;
+import com.tencentcloudapi.common.profile.HttpProfile;
+import com.tencentcloudapi.iai.v20200303.IaiClient;
+import com.tencentcloudapi.iai.v20200303.models.VerifyPersonRequest;
+import com.tencentcloudapi.iai.v20200303.models.VerifyPersonResponse;
+import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.validation.annotation.Validated;
 import org.springframework.web.bind.annotation.*;
@@ -20,6 +35,7 @@ import org.springframework.web.multipart.MultipartFile;
 
 import java.util.Date;
 import java.util.HashMap;
+import java.util.List;
 import java.util.Map;
 
 
@@ -30,8 +46,10 @@ import java.util.Map;
  */
 @RestController
 @RequestMapping("/app/AppUser/")
+@Slf4j
 public class AppUserApiController {
-
+    @Autowired
+    private FaceFactory faceFactory;
     /**
      * 底层 Service 对象
      */
@@ -185,5 +203,45 @@ public class AppUserApiController {
         return appUserService.getByPhoneAndUserType(phone, userType);
     }
 
+    @RequestMapping("find")
+    public AjaxJson find(@RequestBody String img) {
+        img=ImageUtils.compressPic(img);
+//        LambdaQueryWrapper<AppUser>ew=new LambdaQueryWrapper<>();
+//        ew.isNotNull(AppUser::getFaceId);
+//        List<AppUser> appUserList = appUserService.list(ew);
+//        appUserList.stream().filter(appUser -> StrUtil.isNotEmpty(appUser.getFaceId()))
+//                .forEach(appUser -> {
+//                    String faceId = appUser.getFaceId();
+//                    Credential cred = new Credential("AKIDtmacfdOH97likhhaL971xywwhRH7saCt", "1DOSWWYcl2FWhw7BLOII6zz65ylOzTpS");
+//                    // 实例化一个http选项,可选的,没有特殊需求可以跳过
+//                    HttpProfile httpProfile = new HttpProfile();
+//                    httpProfile.setEndpoint("iai.tencentcloudapi.com");
+//                    // 实例化一个client选项,可选的,没有特殊需求可以跳过
+//                    ClientProfile clientProfile = new ClientProfile();
+//                    clientProfile.setHttpProfile(httpProfile);
+//                    // 实例化要请求产品的client对象,clientProfile是可选的
+//                    IaiClient client = new IaiClient(cred, "ap-chongqing", clientProfile);
+//                    VerifyPersonRequest req = new VerifyPersonRequest();
+//                    req.setImage(img);
+//                    req.setPersonId(faceId);
+//                    // 返回的resp是一个VerifyPersonResponse的实例,与请求对象对应
+//                    VerifyPersonResponse resp=null;
+//                    try {
+//                        resp = client.VerifyPerson(req);
+//                    } catch (TencentCloudSDKException e) {
+//                        if (e.getMessage().contains("人员ID不存在")){
+//                            appUser.setFaceId("1111");
+//                            appUserService.updateById(appUser);
+//                        }
+//                        log.error("VerifyPerson:{},{},{},{}",faceId,appUser.getName(),appUser.getId(),e.getMessage());
+//                    }
+//                    if (resp!= null) {
+//                        log.info("VerifyPerson:{},{},{},{},{}",faceId,appUser.getName(),appUser.getId(),resp.getIsMatch(),resp.getScore());
+//                    }
+//                    ThreadUtil.sleep(RandomUtil.randomLong(1000,2000));
+//                });
+        return AjaxJson.getSuccess();
+    }
+
 
 }

+ 26 - 4
sp-service/sp-admin/src/main/java/com/pj/project/app_user/AppUserService.java

@@ -25,6 +25,7 @@ import com.pj.enummj.DeleteStatus;
 import com.pj.enummj.IsLock;
 import com.pj.enummj.UserType;
 import com.pj.face.factory.FaceFactory;
+import com.pj.face.handler.VerifyVO;
 import com.pj.project.app_user.dto.*;
 import com.pj.project.app_user.vo.AppUserVo;
 import com.pj.project.app_user_login_log.AppUserLoginLog;
@@ -657,8 +658,13 @@ public class AppUserService extends ServiceImpl<AppUserMapper, AppUser> implemen
         img = ImageUtils.compressPic(img);
         if (type == 2) {
             AppUser db = getById(loginId);
-            boolean result = faceFactory.handler().verify(db.getFaceId(), img);
-            if (!result) {
+            VerifyVO result = faceFactory.handler().verify(db.getFaceId(), img);
+            if (!result.isSuccess()) {
+                if (result.getMsg().contains("人员ID不存在")){
+                    faceFactory.handler().createPersonByBase(db.getFaceId(), db.getName(), img);
+                    return;
+                }
+                log.info("Verification:{},{}", loginId, img);
                 throw new AjaxError("人脸不匹配");
             }
             return;
@@ -671,11 +677,27 @@ public class AppUserService extends ServiceImpl<AppUserMapper, AppUser> implemen
         faceFactory.handler().createPersonByBase(faceId, appUser.getName(), img);
     }
 
+    /**
+     * tencen:
+     * secret_id: 'AKIDtmacfdOH97likhhaL971xywwhRH7saCt'
+     * secret_key: '1DOSWWYcl2FWhw7BLOII6zz65ylOzTpS'
+     * groupId: 'gds4f56ds79w1g2d45'
+     * groupName: '天保物流'
+     *
+     * @param loginId
+     * @param img
+     * @param type
+     */
     public void authFace(Long loginId, String img, Integer type) {
         if (type == 2) {
             AppUser db = getById(loginId);
-            boolean result = faceFactory.handler().verify(db.getFaceId(), img);
-            if (!result) {
+            VerifyVO result = faceFactory.handler().verify(db.getFaceId(), img);
+            if (!result.isSuccess()) {
+                if (result.getMsg().contains("人员ID不存在")){
+                    faceFactory.handler().createPersonByBase(db.getFaceId(), db.getName(), img);
+                    return;
+                }
+                log.info("Verification:{},{}", loginId, img);
                 throw new AjaxError("人脸不匹配");
             }
             return;

File diff suppressed because it is too large
+ 1 - 2
sp-service/sp-admin/src/main/java/com/pj/project4sp/utils/ImageUtils.java


Some files were not shown because too many files changed in this diff