TRX 1 年間 前
コミット
86d294ce57

+ 6 - 1
FullCardServer/src/main/java/com/zhongshu/card/server/core/controller/gateDoor/GateDoorController.java

@@ -4,7 +4,6 @@ package com.zhongshu.card.server.core.controller.gateDoor;
 import com.github.microservice.models.gateDoor.OnLineParam;
 import com.github.microservice.models.gateDoor.gateDoor.GateDoorIotParam;
 import com.github.microservice.net.ResultContent;
-import com.zhongshu.card.server.core.service.devices.DeviceUseRecordService;
 import com.zhongshu.card.server.core.service.gateDoor.GateDoorService;
 import io.swagger.v3.oas.annotations.Hidden;
 import io.swagger.v3.oas.annotations.Operation;
@@ -48,6 +47,12 @@ public class GateDoorController {
         return this.gateDoorService.gateDoorUseRecord(param);
     }
 
+    @Operation(summary = "陌生人在线验证", description = "陌生人在线验证")
+    @RequestMapping(value = "strSnapPush", method = {RequestMethod.POST})
+    public ResultContent strSnapPush(@RequestBody GateDoorIotParam param) {
+        return this.gateDoorService.gateDoorOnLineVerify(param);
+    }
+
     @Operation(summary = "门闸刷卡开门失败消息", description = "门闸刷卡开门失败消息")
     @RequestMapping(value = "cardPush", method = {RequestMethod.POST})
     public ResultContent cardPush(@RequestBody GateDoorIotParam param) {

+ 2 - 0
FullCardServer/src/main/java/com/zhongshu/card/server/core/domain/devices/permiss/DevicePermiss.java

@@ -49,6 +49,7 @@ public class DevicePermiss extends SuperMain {
 
     //------------------设备冗余数据 start-------------------
     @Schema(description = "设备ID")
+    @Indexed
     private String deviceId;
 
     @Schema(description = "设备名称")
@@ -83,6 +84,7 @@ public class DevicePermiss extends SuperMain {
     @Schema(description = "用户所属机构的类型")
     private AuthType authType;
 
+    @Indexed
     @Schema(description = "可使用用户userId")
     private String userId;
 

+ 94 - 0
FullCardServer/src/main/java/com/zhongshu/card/server/core/service/devices/permiss/DevicePermissVerifyService.java

@@ -0,0 +1,94 @@
+package com.zhongshu.card.server.core.service.devices.permiss;
+
+import com.github.microservice.net.ResultContent;
+import com.zhongshu.card.client.type.DataState;
+import com.zhongshu.card.client.type.UserState;
+import com.zhongshu.card.client.type.device.PermissDataType;
+import com.zhongshu.card.server.core.dao.devices.DeviceInfoDao;
+import com.zhongshu.card.server.core.dao.devices.DevicePermissDao;
+import com.zhongshu.card.server.core.dao.org.OrganizationUserDao;
+import com.zhongshu.card.server.core.dao.org.UserCountDao;
+import com.zhongshu.card.server.core.domain.devices.DeviceInfo;
+import com.zhongshu.card.server.core.domain.devices.permiss.DevicePermiss;
+import com.zhongshu.card.server.core.domain.org.UserAccount;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang3.ObjectUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+import org.springframework.util.StopWatch;
+
+/**
+ * 验证用户是否可以使用设备
+ *
+ * @author TRX
+ * @date 2024/12/24
+ */
+@Slf4j
+@Service
+public class DevicePermissVerifyService {
+
+    @Autowired
+    private DevicePermissDao devicePermissDao;
+
+    @Autowired
+    private UserCountDao userCountDao;
+
+    @Autowired
+    private OrganizationUserDao organizationUserDao;
+
+    @Autowired
+    private DeviceInfoDao deviceInfoDao;
+
+    /**
+     * 验证用户是否有设备的使用权限
+     *
+     * @param userId
+     * @param deviceId
+     * @return
+     */
+    public ResultContent<String> verifyDevice(String userId, String deviceId) {
+        StopWatch stopWatch = new StopWatch();
+        stopWatch.start("用户信息");
+        String msg = "";
+
+        // 验证用户基础信息
+        UserAccount userAccount = userCountDao.findTopByUserId(userId);
+        if (ObjectUtils.isEmpty(userAccount)) {
+            return ResultContent.buildFail("用户不存在");
+        }
+        msg = userAccount.getName();
+        if (userAccount.getState() != UserState.Normal) {
+            return ResultContent.buildFail("用户不可用");
+        }
+
+        // 验证设备
+        DeviceInfo deviceInfo = deviceInfoDao.findTopByDeviceId(deviceId);
+        if (ObjectUtils.isEmpty(deviceInfo)) {
+            return ResultContent.buildFail("设备不存在");
+        }
+        if (deviceInfo.getState() != DataState.Enable) {
+            return ResultContent.buildFail("设备不可用");
+        }
+
+        boolean hasPermission = false;
+        String projectOid = deviceInfo.getProjectOid();
+        DevicePermiss devicePermiss = devicePermissDao.findTopByUserIdAndDeviceIdAndProjectOid(userId, deviceId, projectOid);
+        if (ObjectUtils.isNotEmpty(devicePermiss) && devicePermiss.getPermissDataType() == PermissDataType.UserSetting) {
+            // 手动管理的设备权限
+            if (devicePermiss.getDataState() == DataState.Enable) {
+                hasPermission = true;
+            }
+        }
+
+        if (!hasPermission) {
+            // 查看权限规则 是否包含该设备
+
+        }
+
+        if (!hasPermission) {
+            return ResultContent.buildFail("验证失败");
+        }
+        log.info("用户设备权限验证:{}", stopWatch.prettyPrint());
+        return ResultContent.buildSuccess(msg);
+    }
+}

+ 48 - 76
FullCardServer/src/main/java/com/zhongshu/card/server/core/service/gateDoor/GateDoorService.java

@@ -1,15 +1,13 @@
 package com.zhongshu.card.server.core.service.gateDoor;
 
 import cn.hutool.json.JSONUtil;
+import com.github.microservice.auth.client.service.UserFaceService;
 import com.github.microservice.models.gateDoor.OnLineAckInfoModel;
 import com.github.microservice.models.gateDoor.OnLineInfoParam;
 import com.github.microservice.models.gateDoor.OnLineModel;
 import com.github.microservice.models.gateDoor.OnLineParam;
 import com.github.microservice.models.gateDoor.gateDoor.GateDoorIotParam;
-import com.github.microservice.models.gateDoor.use.GateDoorFailCardInfo;
-import com.github.microservice.models.gateDoor.use.GateDoorInfoParam;
-import com.github.microservice.models.gateDoor.use.GateDoorUseParam;
-import com.github.microservice.models.gateDoor.use.GateDoorUseResult;
+import com.github.microservice.models.gateDoor.use.*;
 import com.github.microservice.net.ResultContent;
 import com.github.microservice.types.deviceUse.OperateState;
 import com.github.microservice.types.deviceUse.OperateType;
@@ -17,6 +15,7 @@ import com.zhongshu.card.client.type.payment.RequestType;
 import com.zhongshu.card.server.core.domain.devices.DeviceUseRecords;
 import com.zhongshu.card.server.core.service.base.SuperService;
 import com.zhongshu.card.server.core.service.devices.DeviceUseRecordService;
+import com.zhongshu.card.server.core.service.devices.permiss.DevicePermissVerifyService;
 import com.zhongshu.card.server.core.service.payment.RequestInfoService;
 import com.zhongshu.card.server.core.util.CommonUtil;
 import lombok.extern.slf4j.Slf4j;
@@ -39,6 +38,12 @@ public class GateDoorService extends SuperService {
     @Autowired
     private DeviceUseRecordService deviceUseRecordService;
 
+    @Autowired
+    private DevicePermissVerifyService devicePermissVerifyService;
+
+    @Autowired
+    private UserFaceService userFaceService;
+
     /**
      * 闸机方法 onLine
      *
@@ -153,79 +158,46 @@ public class GateDoorService extends SuperService {
     }
 
     /**
-     * 检查设备使用的 参数验证
+     * 门闸人脸在线验证
      *
-     * @param entity
+     * @param param
+     * @return
      */
-    public void checkUseDeviceData(DeviceUseRecords entity) {
-//        // 主要是从设备、卡片等的基础信息验证
-//        if (ObjectUtils.isNotEmpty(entity)) {
-//            // 1. 检查设备
-//            if (ObjectUtils.isEmpty(entity.getDeviceInfo())) {
-//                entity.setIsPassed(Boolean.FALSE);
-//                entity.setMsg("设备信息未找到");
-//                return;
-//            }
-//            DeviceInfoStoreModel deviceInfo = entity.getDeviceInfo();
-//            if (deviceInfo.getState() == null || deviceInfo.getState() != DataState.Enable) {
-//                entity.setIsPassed(Boolean.FALSE);
-//                entity.setMsg("设备未启用");
-//                return;
-//            }
-//            //2. 验证用户信息
-//            UserCountSimpleModel userAccount = entity.getUserAccount();
-//            if (ObjectUtils.isEmpty(userAccount)) {
-//                entity.setIsPassed(Boolean.FALSE);
-//                entity.setMsg("用户信息未确定");
-//                return;
-//            }
-//            if (userAccount.getState() == null || userAccount.getState() != UserState.Normal) {
-//                entity.setIsPassed(Boolean.FALSE);
-//                entity.setMsg(String.format("用户已禁用"));
-//                return;
-//            }
-//            // 验证用户是否有设备申请权限
-//            if (deviceInfo.getIsOpenUse() == null || !deviceInfo.getIsOpenUse()) {
-//                DevicePermiss devicePermiss = devicePermissDao.findTopByUserIdAndDeviceIdAndProjectOid(entity.getUserId(), entity.getDeviceId(), entity.getProjectOid());
-//                if (ObjectUtils.isEmpty(devicePermiss)) {
-//                    entity.setIsPassed(Boolean.FALSE);
-//                    entity.setMsg("用户没有设备权限");
-//                    return;
-//                }
-//                if (devicePermiss.getDataState() == null || devicePermiss.getDataState() != DataState.Enable) {
-//                    entity.setIsPassed(Boolean.FALSE);
-//                    entity.setMsg("用户权限未启用");
-//                    return;
-//                }
-//            }
-//
-//            Integer mode = entity.getMode();
-//            if (mode == null) {
-//                entity.setIsPassed(Boolean.FALSE);
-//                entity.setMsg("使用模式未确定");
-//                return;
-//            }
-//            if (mode == 0) {
-//                // 刷卡
-//                if (ObjectUtils.isEmpty(entity.getCardInfo())) {
-//                    entity.setIsPassed(Boolean.FALSE);
-//                    entity.setMsg("卡片未找到");
-//                    return;
-//                }
-//                CardInfoStoreModel cardInfo = entity.getCardInfo();
-//                if (cardInfo.getIsCanceled() != null && cardInfo.getIsCanceled()) {
-//                    entity.setIsPassed(Boolean.FALSE);
-//                    entity.setMsg("卡片已作废");
-//                    return;
-//                }
-//
-//                if (cardInfo.getCardState() == null || cardInfo.getCardState() != CardState.Enable) {
-//                    entity.setIsPassed(Boolean.FALSE);
-//                    entity.setMsg(String.format("卡片%s", cardInfo.getCardState().getRemark()));
-//                    return;
-//                }
-//            }
-//        }
-    }
+    public ResultContent gateDoorOnLineVerify(GateDoorIotParam param) {
+        GateDoorOnLineUseResult result = new GateDoorOnLineUseResult();
+        GateDoorInfoParam info = param.getInfo();
+        log.info("闸机使用记录 gateDoorOnLineVerify...");
+        if (ObjectUtils.isNotEmpty(info)) {
+            String deviceId = param.getDeviceId();
+            String gateWayId = param.getGateWayId();
+            String mqttDataId = param.getMqttDataId();
+            result.setMqttDataId(mqttDataId);
+
+            GateDoorUseParam useParam = new GateDoorUseParam();
+            useParam.setMqttDataId(param.getMqttDataId());
+            useParam.setDeviceId(param.getDeviceId());
+            useParam.setGateWayId(param.getGateWayId());
+            String faceBase64Str = info.getPic();
+            // 根据人脸查找用户
+            com.github.microservice.auth.client.content.ResultContent<String> faceContent = userFaceService.matches(faceBase64Str);
+            String userId = "";
+            if (faceContent.isSuccess()) {
+                userId = faceContent.getContent();
+            } else {
+                result.setFailed(faceContent.getMsg());
+            }
 
+            if (StringUtils.isNotEmpty(userId)) {
+                // 验证用户对设备有误权限
+                ResultContent<String> resultContent = devicePermissVerifyService.verifyDevice(userId, deviceId);
+                if (resultContent.isSuccess()) {
+                    result.setSuccess();
+                    result.setMsg(resultContent.getContent());
+                } else {
+                    result.setFailed(resultContent.getMsg());
+                }
+            }
+        }
+        return ResultContent.buildSuccess(JSONUtil.toJsonStr(result));
+    }
 }