Quellcode durchsuchen

修改后台人脸核身逻辑

tongfeng vor 2 Jahren
Ursprung
Commit
ab5f090f38

+ 4 - 0
eladmin-system/src/main/java/me/zhengjie/dao/mybatis/entity/ContractOrderEntity.java

@@ -106,6 +106,8 @@ public class ContractOrderEntity implements Serializable {
 
     @TableField("other_upload")
     private String otherUpload;
+    @TableField("compare_img_id")
+    private Integer compareImgId;
 
     @TableField("joint_flag")
     private Integer jointFlag;
@@ -130,6 +132,8 @@ public class ContractOrderEntity implements Serializable {
 
     @TableField("joint_residence")
     private String jointResidence;
+    @TableField("joint_compare_img_id")
+    private Integer jointCompareImgId;
 
     @TableField("bank_id")
     private String bankId;

+ 0 - 3
eladmin-system/src/main/java/me/zhengjie/dao/mybatis/entity/UserAXQInfoEntity.java

@@ -45,7 +45,4 @@ public class UserAXQInfoEntity implements Serializable {
 
     @TableField("img_seal_id")
     private Integer imgSealId;
-
-    @TableField("face_compare_id")
-    private Long faceCompareId;
 }

+ 116 - 79
eladmin-system/src/main/java/me/zhengjie/domain/notary/impl/NotaryDomainImpl.java

@@ -55,48 +55,60 @@ public class NotaryDomainImpl implements NotaryDomain {
     private static final String LIBPATH = "/home/tom/nt-test/lib/so";
 
     //以下为本地测试
-/*    private static final String APPID = "H6Er8ksqAcKc7Dk4Yum9Rkz4g9Gm77ZXAEMgvenjkTQQ";
-    private static final String SDKKEY = "Abd9D8xZQUqG8vDtU2a1tEkdfThkK1tZppjXzydGwEd6";
-    private static final String LIBPATH = "D:\\arcsoft_lib";*/
+//    private static final String APPID = "H6Er8ksqAcKc7Dk4Yum9Rkz4g9Gm77ZXAEMgvenjkTQQ";
+//    private static final String SDKKEY = "Abd9D8xZQUqG8vDtU2a1tEkdfThkK1tZppjXzydGwEd6";
+//    private static final String LIBPATH = "D:\\arcsoft_lib";
 
 
     /**
      * 获取base64取消文件头
+     *
      * @param base64
      * @return
      */
-    public String getBase64(String base64){
+    public String getBase64(String base64) {
         String[] base64s = base64.split("base64");
-        if (base64s!=null && base64s.length>1){
+        if (base64s != null && base64s.length > 1) {
             base64 = base64s[1];
         }
         return base64;
     }
 
 
-
     /**
      * app端的人脸核身
+     *
      * @param compareImageDomain
      * @return
      */
-    public ResultCode appCompareFace(CompareImageDomain compareImageDomain){
+    public ResultCode appCompareFace(CompareImageDomain compareImageDomain) {
         String base64 = compareImageDomain.getBase64();
-        if (base64==null){
+        if (base64 == null) {
             return ResultCode.PARAM_IS_BLANK;
         }
         base64 = getBase64(base64);
         String idCard = compareImageDomain.getIdCard();
         String nickName = compareImageDomain.getName();
-        //当事人的人脸核身
-        QueryWrapper<UserAXQInfoEntity> userAXQInfoEntityQueryWrapper = new QueryWrapper<>();
-        userAXQInfoEntityQueryWrapper.eq("id_card",idCard).eq("nick_name",nickName);
-        UserAXQInfoEntity userAXQInfoEntity = userAXQInfoMapper.selectOne(userAXQInfoEntityQueryWrapper);
-        if (ObjectUtils.isEmpty(userAXQInfoEntity)){
-            return ResultCode.PARAM_IS_INVALID;
+        //根据业务编号获取订单 判断当事人名字
+        String businessNo = compareImageDomain.getBusinessNo();
+        QueryWrapper<ContractOrderEntity> contractOrderEntityQueryWrapper = new QueryWrapper<>();
+        contractOrderEntityQueryWrapper.eq("business_no", businessNo);
+        ContractOrderEntity contractOrderEntity = contractOrderMapper.selectOne(contractOrderEntityQueryWrapper);
+        Integer id = null;
+        //看是哪个当事人
+        if (nickName.equals(contractOrderEntity.getName())) {
+            id = contractOrderEntity.getCompareImgId();
+        } else if (nickName.equals(contractOrderEntity.getJointName())) {
+            id = contractOrderEntity.getJointCompareImgId();
+        }
+        //后面需要的三个参数 base64 身份证号 姓名
+        String redisCount = "idCard:" + idCard + ":COUNT:";
+        Integer count = null;
+        if (redis.hasKey(redisCount)) {
+            count = (Integer) redis.get(redisCount);
+            System.err.println("redis存入次数" + count);
         }
-        //做过安心签的用户 直接人脸核身 保存图片
-        ThirdPartyInterfaceEntity thirdPartyInterfaceEntity = JuheServiceUtil.URLPost(idCard, nickName, base64);
+
         File base = null;
         try {
             base = File.createTempFile("compare", ".jpeg");
@@ -110,19 +122,39 @@ public class NotaryDomainImpl implements NotaryDomain {
         }
         FileInfoEntity fileInfo = saveCompareImage(base);
         fileInfoMapper.insert(fileInfo);
-        thirdPartyInterfaceEntity.setFileId(fileInfo.getId()+"");
-        thirdPartyInterfaceEntity.setBusinessNo(compareImageDomain.getBusinessNo());
-        if (thirdPartyInterfaceEntity.getResult()==1){
-            UserAXQInfoEntity userAxq = new UserAXQInfoEntity();
-            userAxq.setId(userAXQInfoEntity.getId());
-            userAxq.setFaceCompareId(thirdPartyInterfaceEntity.getId());
-            userAXQInfoMapper.updateById(userAxq);
-            log.info("当事人人脸核身通过");
+
+        boolean redisFlag = (count != null && count >= 2);
+        if (ObjectUtils.isEmpty(id) || redisFlag) {
+            //要做人脸核身
+            ThirdPartyInterfaceEntity thirdPartyInterfaceEntity = JuheServiceUtil.URLPost(idCard, nickName, base64);
+            thirdPartyInterfaceEntity.setFileId(fileInfo.getId() + "");
+            thirdPartyInterfaceEntity.setBusinessNo(compareImageDomain.getBusinessNo());
             thirdPartyInterfaceRepository.insert(thirdPartyInterfaceEntity);
-            return ResultCode.SUCCESS;
+            if (thirdPartyInterfaceEntity.getResult() == 1) {
+                ContractOrderEntity orderEntity = new ContractOrderEntity();
+                orderEntity.setId(contractOrderEntity.getId());
+                //判断是共同责任人还是当事人
+                if (nickName.equals(contractOrderEntity.getName())) {
+                    orderEntity.setCompareImgId(fileInfo.getId());
+                }
+                if (nickName.equals(contractOrderEntity.getJointName())) {
+                    orderEntity.setJointCompareImgId(fileInfo.getId());
+                }
+                contractOrderMapper.updateById(orderEntity);
+                log.info("当事人人脸核身通过");
+                redis.del(redisCount);
+                return ResultCode.SUCCESS;
+            }
+            return ResultCode.LIVE_VIDEO_INVALID;
         }
-        thirdPartyInterfaceRepository.insert(thirdPartyInterfaceEntity);
-        return ResultCode.LIVE_VIDEO_INVALID;
+        //要做照片比对
+        if (!compareImage(base, id, redisCount, count)) {
+            return ResultCode.LIVE_VIDEO_INVALID;
+        }
+        if (count != null) {
+            redis.del(redisCount);
+        }
+        return ResultCode.SUCCESS;
     }
 
 
@@ -134,7 +166,7 @@ public class NotaryDomainImpl implements NotaryDomain {
      */
     public ResultCode compareFace(CompareImageDomain compareImageDomain) {
         String base64 = compareImageDomain.getBase64();
-        if (base64==null){
+        if (base64 == null) {
             return ResultCode.PARAM_IS_BLANK;
         }
         base64 = getBase64(base64);
@@ -144,13 +176,21 @@ public class NotaryDomainImpl implements NotaryDomain {
         UserAXQInfoEntity userAXQInfoEntity = null;
         String idCard = compareImageDomain.getIdCard();
         String nickName = compareImageDomain.getName();
+
+        QueryWrapper<ContractOrderEntity> orderEntityQueryWrapper = new QueryWrapper<>();
+        orderEntityQueryWrapper.eq("business_no", compareImageDomain.getBusinessNo());
+        ContractOrderEntity contractOrder = contractOrderMapper.selectOne(orderEntityQueryWrapper);
+        if (ObjectUtils.isEmpty(contractOrder)) {
+            return ResultCode.PARAM_IS_INVALID;
+        }
+        Integer compareImageId = null;
         boolean flag = "-1".equals(roleId);
         if (flag) {
             //说明是银行客户经理
             QueryWrapper<ContractOrderEntity> contractOrderEntityQueryWrapper = new QueryWrapper<>();
-            contractOrderEntityQueryWrapper.eq("business_no",compareImageDomain.getBusinessNo()).eq("customer_name",compareImageDomain.getName());
+            contractOrderEntityQueryWrapper.eq("business_no", compareImageDomain.getBusinessNo()).eq("customer_name", compareImageDomain.getName());
             ContractOrderEntity contractOrderEntity = contractOrderMapper.selectOne(contractOrderEntityQueryWrapper);
-            if (ObjectUtils.isEmpty(contractOrderEntity)){
+            if (ObjectUtils.isEmpty(contractOrderEntity)) {
                 return ResultCode.ACCOUNT_MANAGER_NO_ASSIGNED;
             }
             QueryWrapper<SysUserEntity> sysUserEntityQueryWrapper = new QueryWrapper<>();
@@ -158,11 +198,13 @@ public class NotaryDomainImpl implements NotaryDomain {
             sysUserEntity = userMapper.selectOne(sysUserEntityQueryWrapper);
         } else {
             //说明是当事人
-            QueryWrapper<UserAXQInfoEntity> userAXQInfoEntityQueryWrapper = new QueryWrapper<>();
-            userAXQInfoEntityQueryWrapper.eq("id_card", idCard).eq("user_name", nickName);
-            userAXQInfoEntity = userAXQInfoMapper.selectOne(userAXQInfoEntityQueryWrapper);
+            if (compareImageDomain.getName().equals(contractOrder.getName())) {
+                compareImageId = contractOrder.getCompareImgId();
+            } else if (compareImageDomain.getName().equals(contractOrder.getJointName())) {
+                compareImageId = contractOrder.getJointCompareImgId();
+            }
         }
-        if (ObjectUtils.isEmpty(sysUserEntity) && ObjectUtils.isEmpty(userAXQInfoEntity)) {
+        if (ObjectUtils.isEmpty(sysUserEntity) && ObjectUtils.isEmpty(compareImageId)) {
             return ResultCode.PARAM_IS_INVALID;
         }
         //后面需要的三个参数 base64 身份证号 姓名
@@ -184,19 +226,18 @@ public class NotaryDomainImpl implements NotaryDomain {
             log.info("base64转图片异常");
             return ResultCode.FACEAUTH_FAIL;
         }
-        FileInfoEntity fileInfo = saveCompareImage(base);
-        fileInfoMapper.insert(fileInfo);
 
-        ThirdPartyInterfaceEntity thirdParty = null;
         boolean redisFlag = (count != null && count >= 2);
         if (flag) {
             //说明是客户经理
             if (sysUserEntity.getCompareImgId() == null || redisFlag) {
                 //说明客户经理需要做人脸核身
+                FileInfoEntity fileInfo = saveCompareImage(base);
+                fileInfoMapper.insert(fileInfo);
                 ThirdPartyInterfaceEntity thirdPartyInterfaceEntity = JuheServiceUtil.URLPost(idCard, nickName, base64);
-                thirdPartyInterfaceEntity.setFileId(fileInfo.getId()+"");
+                thirdPartyInterfaceEntity.setFileId(fileInfo.getId() + "");
                 thirdPartyInterfaceEntity.setBusinessNo(compareImageDomain.getBusinessNo());
-                if (thirdPartyInterfaceEntity.getResult()==1){
+                if (thirdPartyInterfaceEntity.getResult() == 1) {
                     //上传图片到minio FileInfo
                     SysUserEntity bank = new SysUserEntity();
                     bank.setUserId(sysUserEntity.getUserId());
@@ -211,37 +252,33 @@ public class NotaryDomainImpl implements NotaryDomain {
                 thirdPartyInterfaceRepository.insert(thirdPartyInterfaceEntity);
                 return ResultCode.LIVE_VIDEO_INVALID;
             }
-        } else {
-            //说明是当事人
-            Long faceCompareId = userAXQInfoEntity.getFaceCompareId();
-            QueryWrapper<ThirdPartyInterfaceEntity> thirdPartyInterfaceEntityQueryWrapper = new QueryWrapper<>();
-            if (ObjectUtils.isEmpty(faceCompareId)){
-                thirdPartyInterfaceEntityQueryWrapper.eq("business_no",compareImageDomain.getBusinessNo()).eq("res","1");
-            }else {
-                thirdPartyInterfaceEntityQueryWrapper.eq("business_no",compareImageDomain.getBusinessNo()).eq("res","1").eq("id",faceCompareId);
-            }
-            thirdPartyInterfaceEntityQueryWrapper.eq("business",compareImageDomain.getBusinessNo()).eq("res","1");
-            thirdParty = thirdPartyInterfaceRepository.getOne(thirdPartyInterfaceEntityQueryWrapper);
-            if (ObjectUtils.isEmpty(thirdParty) || redisFlag) {
-                //说明当事人需要做人脸核身
-                ThirdPartyInterfaceEntity thirdPartyInterfaceEntity = JuheServiceUtil.URLPost(idCard, nickName, base64);
-                thirdPartyInterfaceEntity.setFileId(fileInfo.getId()+"");
-                thirdPartyInterfaceEntity.setBusinessNo(compareImageDomain.getBusinessNo());
-                if (thirdPartyInterfaceEntity.getResult()==1){
-                    //上传图片到minio FileInfo
-                    UserAXQInfoEntity userAxq = new UserAXQInfoEntity();
-                    userAxq.setId(userAXQInfoEntity.getId());
-                    userAxq.setFaceCompareId(thirdPartyInterfaceEntity.getId());
-                    userAXQInfoMapper.updateById(userAxq);
-                    log.info("当事人人脸核身通过");
-                    redis.del(redisCount);
-                    thirdPartyInterfaceRepository.insert(thirdPartyInterfaceEntity);
-                    return ResultCode.SUCCESS;
+        } else if (ObjectUtils.isEmpty(compareImageId) || redisFlag) {
+            //说明当事人需要做人脸核身
+            FileInfoEntity fileInfo = saveCompareImage(base);
+            fileInfoMapper.insert(fileInfo);
+            ThirdPartyInterfaceEntity thirdPartyInterfaceEntity = JuheServiceUtil.URLPost(idCard, nickName, base64);
+            thirdPartyInterfaceEntity.setFileId(fileInfo.getId() + "");
+            thirdPartyInterfaceEntity.setBusinessNo(compareImageDomain.getBusinessNo());
+            thirdPartyInterfaceRepository.insert(thirdPartyInterfaceEntity);
+            if (thirdPartyInterfaceEntity.getResult() == 1) {
+                //上传图片到minio FileInfo;
+                ContractOrderEntity orderEntity = new ContractOrderEntity();
+                orderEntity.setId(contractOrder.getId());
+                //判断是共同责任人还是当事人
+                if (nickName.equals(contractOrder.getName())) {
+                    orderEntity.setCompareImgId(fileInfo.getId());
                 }
-                log.info("当事人人脸核身失败");
-                thirdPartyInterfaceRepository.insert(thirdPartyInterfaceEntity);
-                return ResultCode.LIVE_VIDEO_INVALID;
+                if (nickName.equals(contractOrder.getJointName())) {
+                    orderEntity.setJointCompareImgId(fileInfo.getId());
+                }
+                redis.del(redisCount);
+                contractOrderMapper.updateById(orderEntity);
+                log.info("当事人人脸核身通过");
+
+                return ResultCode.SUCCESS;
             }
+            log.info("当事人人脸核身失败");
+            return ResultCode.LIVE_VIDEO_INVALID;
         }
         //如果不用做人脸核身 那么就去做照片比对
         //获取比较图片的id
@@ -249,13 +286,11 @@ public class NotaryDomainImpl implements NotaryDomain {
         if (!ObjectUtils.isEmpty(sysUserEntity)) {
             id = sysUserEntity.getCompareImgId();
         }
-        if (!ObjectUtils.isEmpty(userAXQInfoEntity)) {
-            if (!ObjectUtils.isEmpty(thirdParty)){
-                id = Integer.parseInt(thirdParty.getFileId());
-            }
+        if (!ObjectUtils.isEmpty(compareImageId)) {
+            id = compareImageId;
         }
-        if (!ObjectUtils.isEmpty(id)){
-            if (! compareImage(base, id,redisCount,count)) {
+        if (!ObjectUtils.isEmpty(id)) {
+            if (!compareImage(base, id, redisCount, count)) {
                 return ResultCode.LIVE_VIDEO_INVALID;
             }
         }
@@ -267,13 +302,14 @@ public class NotaryDomainImpl implements NotaryDomain {
 
     /**
      * 虹软的人脸照片比对
-     * @param base 照片
-     * @param id   文件库中照片的id
+     *
+     * @param base       照片
+     * @param id         文件库中照片的id
      * @param redisCount 数据库中的键
-     * @param count redis当中的次数
+     * @param count      redis当中的次数
      * @return
      */
-    public boolean compareImage(File base, Integer id,String redisCount,Integer count) {
+    public boolean compareImage(File base, Integer id, String redisCount, Integer count) {
         //从官网获取
         FaceEngine faceEngine = new FaceEngine(LIBPATH);
         //激活引擎
@@ -366,7 +402,8 @@ public class NotaryDomainImpl implements NotaryDomain {
         } else {
             redis.set(redisCount, count + 1, 30, TimeUnit.MINUTES);
         }
-        log.info("人脸照片比对未通过");;
+        log.info("人脸照片比对未通过");
+        ;
         return false;
     }