瀏覽代碼

更新!

TRX 1 年之前
父節點
當前提交
6d3dab6441

+ 2 - 0
FullCardServer/src/main/java/com/zhongshu/card/server/core/dataConfig/TtlConfig.java

@@ -12,4 +12,6 @@ public class TtlConfig {
     // 用户权限数据缓存的时间
     public static final Long userCacheTime = 30 * 24 * 60 * 60L * 1000;
 
+    // 设备使用记录的保存时间
+    public static final Long deviceUseRecordTime = 180 * 24 * 60 * 60L * 1000;
 }

+ 27 - 79
FullCardServer/src/main/java/com/zhongshu/card/server/core/service/devices/DeviceUseRecordService.java

@@ -1,6 +1,7 @@
 package com.zhongshu.card.server.core.service.devices;
 
 import com.github.microservice.components.data.base.util.PageEntityUtil;
+import com.github.microservice.core.util.os.SystemUtil;
 import com.github.microservice.models.gateDoor.use.GateDoorUseParam;
 import com.github.microservice.net.ResultContent;
 import com.zhongshu.card.client.model.devices.DeviceUseRecordModel;
@@ -12,6 +13,7 @@ import com.zhongshu.card.server.core.dao.devices.DeviceUseRecordDao;
 import com.zhongshu.card.server.core.dao.org.OrganizationDao;
 import com.zhongshu.card.server.core.dao.org.UserCountDao;
 import com.zhongshu.card.server.core.dao.school.CardInfoDao;
+import com.zhongshu.card.server.core.dataConfig.TtlConfig;
 import com.zhongshu.card.server.core.domain.devices.DeviceInfo;
 import com.zhongshu.card.server.core.domain.devices.DeviceUseRecords;
 import com.zhongshu.card.server.core.domain.org.Organization;
@@ -26,11 +28,14 @@ import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.lang3.ObjectUtils;
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.ApplicationContext;
 import org.springframework.data.domain.Page;
 import org.springframework.data.domain.Pageable;
 import org.springframework.stereotype.Service;
 
 import java.util.Date;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
 
 /**
  * @author TRX
@@ -67,8 +72,26 @@ public class DeviceUseRecordService extends SuperService {
     @Autowired
     private OrganizationDao organizationDao;
 
-    // 设备使用日志保存3个月
-    private static Long ttlTime = 90 * 24 * 60 * 60 * 1000L;
+    //线程池
+    private ExecutorService executorService = Executors.newFixedThreadPool(SystemUtil.getCpuCoreCount() * 2);
+
+    @Autowired
+    private void init(ApplicationContext applicationContext) {
+        Runtime.getRuntime().addShutdownHook(new Thread(() -> {
+            executorService.shutdownNow();
+        }));
+    }
+
+    /**
+     * 异步保存设备使用 日志
+     *
+     * @param param
+     */
+    public void asyncSaveRecord(GateDoorUseParam param) {
+        executorService.execute(() -> {
+            saveDeviceLogs(param);
+        });
+    }
 
     /**
      * 设备使用日志 (物联网来的数据)
@@ -146,7 +169,8 @@ public class DeviceUseRecordService extends SuperService {
                 if (ObjectUtils.isNotEmpty(organization)) {
                     deviceUseRecord.setProjectName(organization.getName());
                 }
-                deviceUseRecord.setTtl(new Date(System.currentTimeMillis() + ttlTime));
+                deviceUseRecord.setTtl(new Date(System.currentTimeMillis() + TtlConfig.deviceUseRecordTime));
+                deviceUseRecord.setMsg(param.getVerifyMsg());
                 deviceUseRecordDao.save(deviceUseRecord);
             } else {
                 return ResultContent.buildFail("数据初始失败");
@@ -166,82 +190,6 @@ public class DeviceUseRecordService extends SuperService {
         return null;
     }
 
-    /**
-     * 检查设备使用的 参数验证
-     *
-     * @param entity
-     */
-    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<Page<DeviceUseRecordModel>> page(DeviceUseRecordSearch param, Pageable pageable) {
         Page<DeviceUseRecords> page = deviceUseRecordDao.page(pageable, param);
         return ResultContent.buildSuccess(PageEntityUtil.concurrent2PageModel(page, this::toModel));

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

@@ -1,5 +1,6 @@
 package com.zhongshu.card.server.core.service.devices.permiss;
 
+import com.github.microservice.models.gateDoor.use.GateDoorUseParam;
 import com.github.microservice.net.ResultContent;
 import com.zhongshu.card.client.model.devices.permiss.PermissSettingListSearch;
 import com.zhongshu.card.client.model.devices.permiss.TimeSlotModel;
@@ -21,6 +22,7 @@ import com.zhongshu.card.server.core.domain.org.UserAccount;
 import com.zhongshu.card.server.core.service.org.OrganizationUserServiceImpl;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.lang3.ObjectUtils;
+import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.util.StopWatch;
@@ -77,7 +79,13 @@ public class DevicePermissVerifyService {
      * @param deviceId
      * @return
      */
-    public ResultContent<String> verifyDevice(String userId, String deviceId) {
+    public ResultContent<String> verifyDevice(String userId, String deviceId, GateDoorUseParam deviceUserParam) {
+        if (StringUtils.isEmpty(userId)) {
+            return ResultContent.buildFail("未包含用户信息");
+        }
+        deviceUserParam.setUserId(userId);
+        deviceUserParam.setDeviceId(deviceId);
+
         StopWatch stopWatch = new StopWatch();
         stopWatch.start("用户信息");
         String msg = "";
@@ -109,7 +117,6 @@ public class DevicePermissVerifyService {
 
         boolean hasPermission = false;
         String projectOid = deviceInfo.getProjectOid();
-
         stopWatch.start("查询绑定的设备权限");
         DevicePermiss devicePermiss = devicePermissDao.findTopByUserIdAndDeviceIdAndProjectOidAndDataState(userId, deviceId, projectOid, DataState.Enable);
         if (ObjectUtils.isNotEmpty(devicePermiss)) {

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

@@ -166,8 +166,9 @@ public class GateDoorService extends SuperService {
     public ResultContent gateDoorOnLineVerify(GateDoorIotParam param) {
         GateDoorOnLineUseResult result = new GateDoorOnLineUseResult();
         GateDoorInfoParam info = param.getInfo();
-        info = new GateDoorInfoParam();
-        info.setPic("1");
+        if (ObjectUtils.isEmpty(info)) {
+            info = new GateDoorInfoParam();
+        }
 
         log.info("闸机使用记录 gateDoorOnLineVerify...");
         if (ObjectUtils.isNotEmpty(info)) {
@@ -175,37 +176,30 @@ public class GateDoorService extends SuperService {
             String gateWayId = param.getGateWayId();
             String mqttDataId = param.getMqttDataId();
             result.setMqttDataId(mqttDataId);
+            String userId = info.getCustomId();
 
-            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 {
-//                String msg = faceContent.getMsg();
-//                if (StringUtils.isEmpty(msg)) {
-//                    msg = "人脸验证错误";
-//                }
-////                result.setFailed(msg);
-//            }
-            String userId = "665fc0389083d203896d3541";
-
-            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());
-                }
+            GateDoorUseParam deviceUserParam = new GateDoorUseParam();
+            ResultContent<String> resultContent = devicePermissVerifyService.verifyDevice(userId, deviceId, deviceUserParam);
+            deviceUserParam.setMqttDataId(mqttDataId);
+            deviceUserParam.setOperateType(OperateType.Face);
+            deviceUserParam.setGateWayId(gateWayId);
+            deviceUserParam.setData(info);
+            deviceUserParam.setIsOffLine(Boolean.FALSE);
+
+            if (resultContent.isSuccess()) {
+                result.setSuccess();
+                result.setMsg(resultContent.getContent());
+                deviceUserParam.setOperateState(OperateState.Success);
+                deviceUserParam.setIsPassed(Boolean.TRUE);
+                deviceUserParam.setVerifyMsg(resultContent.getContent());
+            } else {
+                result.setFailed(resultContent.getMsg());
+                deviceUserParam.setOperateState(OperateState.Failed);
+                deviceUserParam.setIsPassed(Boolean.FALSE);
+                deviceUserParam.setVerifyMsg(resultContent.getMsg());
             }
+            // 添加设备使用记录
+            deviceUseRecordService.asyncSaveRecord(deviceUserParam);
         } else {
             result.setFailed("参数错误");
         }