|
|
@@ -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));
|