|
|
@@ -5,9 +5,6 @@ import com.github.microservice.models.gateDoor.use.GateDoorUseParam;
|
|
|
import com.github.microservice.models.gateDoor.use.GateDoorUseResult;
|
|
|
import com.github.microservice.net.ResultContent;
|
|
|
import com.zhongshu.card.client.model.devices.DeviceUseRecordModel;
|
|
|
-import com.zhongshu.card.client.type.DataState;
|
|
|
-import com.zhongshu.card.client.type.UserState;
|
|
|
-import com.zhongshu.card.client.type.school.CardState;
|
|
|
import com.zhongshu.card.client.utils.DateUtils;
|
|
|
import com.zhongshu.card.server.core.dao.devices.DeviceInfoDao;
|
|
|
import com.zhongshu.card.server.core.dao.devices.DevicePermissDao;
|
|
|
@@ -15,11 +12,12 @@ import com.zhongshu.card.server.core.dao.devices.DeviceUseRecordDao;
|
|
|
import com.zhongshu.card.server.core.dao.org.UserCountDao;
|
|
|
import com.zhongshu.card.server.core.dao.school.CardInfoDao;
|
|
|
import com.zhongshu.card.server.core.domain.devices.DeviceInfo;
|
|
|
-import com.zhongshu.card.server.core.domain.devices.DevicePermiss;
|
|
|
-import com.zhongshu.card.server.core.domain.devices.DeviceUseRecord;
|
|
|
+import com.zhongshu.card.server.core.domain.devices.DeviceUseRecords;
|
|
|
import com.zhongshu.card.server.core.domain.org.UserAccount;
|
|
|
import com.zhongshu.card.server.core.domain.school.CardInfo;
|
|
|
import com.zhongshu.card.server.core.service.base.SuperService;
|
|
|
+import com.zhongshu.card.server.core.service.projectAbout.CardInfoServiceImpl;
|
|
|
+import com.zhongshu.card.server.core.service.user.UserAccountServiceImpl;
|
|
|
import com.zhongshu.card.server.core.util.BeanUtils;
|
|
|
import com.zhongshu.card.server.core.util.TokenUtil;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
@@ -51,6 +49,15 @@ public class DeviceUseRecordService extends SuperService {
|
|
|
@Autowired
|
|
|
private UserCountDao userCountDao;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private UserAccountServiceImpl userAccountService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private CardInfoServiceImpl cardInfoService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private DeviceInfoServiceImpl deviceInfoService;
|
|
|
+
|
|
|
/**
|
|
|
* 设备使用日志 (物联网来的数据)
|
|
|
*
|
|
|
@@ -61,13 +68,15 @@ public class DeviceUseRecordService extends SuperService {
|
|
|
// 返回数据
|
|
|
GateDoorUseResult result = new GateDoorUseResult();
|
|
|
String mqttDataId = param.getMqttDataId();
|
|
|
+ log.info("saveDeviceUseRecord mqttDataId: {}", mqttDataId);
|
|
|
if (StringUtils.isNotEmpty(mqttDataId)) {
|
|
|
- DeviceUseRecord deviceUseRecord = init(mqttDataId);
|
|
|
+ DeviceUseRecords deviceUseRecord = init(mqttDataId);
|
|
|
if (ObjectUtils.isNotEmpty(deviceUseRecord)) {
|
|
|
BeanUtils.copyProperties(param, deviceUseRecord);
|
|
|
String deviceId = param.getDeviceId();
|
|
|
String cardNo = param.getCardNo();
|
|
|
String userId = param.getUserId();
|
|
|
+
|
|
|
String projectOid = "";
|
|
|
DeviceInfo deviceInfo = null;
|
|
|
if (StringUtils.isNotEmpty(deviceId)) {
|
|
|
@@ -79,11 +88,10 @@ public class DeviceUseRecordService extends SuperService {
|
|
|
deviceUseRecord.setDeviceId(deviceId);
|
|
|
if (ObjectUtils.isNotEmpty(deviceInfo)) {
|
|
|
// 设备信息
|
|
|
- deviceUseRecord.setDeviceInfo(deviceInfo);
|
|
|
+ deviceUseRecord.setDeviceInfo(deviceInfoService.toStoreModel(deviceInfo));
|
|
|
deviceUseRecord.setDeviceType(deviceInfo.getDeviceType());
|
|
|
deviceUseRecord.setGateWayId(deviceInfo.getGateWayId());
|
|
|
|
|
|
- deviceUseRecord.setBeLongOrganization(deviceInfo.getOrganization());
|
|
|
deviceUseRecord.setBeLongOid(deviceInfo.getBeLongOid());
|
|
|
deviceUseRecord.setBeLongName(deviceInfo.getBeLongName());
|
|
|
}
|
|
|
@@ -99,14 +107,15 @@ public class DeviceUseRecordService extends SuperService {
|
|
|
deviceUseRecord.setCardNo(cardNo);
|
|
|
if (ObjectUtils.isNotEmpty(cardInfo)) {
|
|
|
// 卡片信息
|
|
|
- deviceUseRecord.setCardInfo(cardInfo);
|
|
|
+ deviceUseRecord.setCardInfo(cardInfoService.toStoreModel(cardInfo));
|
|
|
}
|
|
|
+
|
|
|
UserAccount userAccount = null;
|
|
|
if (StringUtils.isNotEmpty(userId)) {
|
|
|
userAccount = userCountDao.findTopByUserId(userId);
|
|
|
}
|
|
|
deviceUseRecord.setUserId(userId);
|
|
|
- deviceUseRecord.setUserAccount(userAccount);
|
|
|
+ deviceUseRecord.setUserAccount(userAccountService.toSimpleModel(userAccount));
|
|
|
|
|
|
if (StringUtils.isNotEmpty(param.getTime())) {
|
|
|
deviceUseRecord.setTimestamp(DateUtils.timeToLong(param.getTime(), DateUtils.FORMAT_LONG));
|
|
|
@@ -154,10 +163,13 @@ public class DeviceUseRecordService extends SuperService {
|
|
|
return ResultContent.buildSuccess(JSONUtil.toJsonStr(result));
|
|
|
}
|
|
|
|
|
|
- public DeviceUseRecord init(String mqttDataId) {
|
|
|
- DeviceUseRecord entity = deviceUseRecordDao.init(mqttDataId, TokenUtil.create());
|
|
|
- entity.setCreateTimeStr(DateUtils.paresTime(System.currentTimeMillis(), DateUtils.FORMAT_LONG));
|
|
|
- return entity;
|
|
|
+ public DeviceUseRecords init(String mqttDataId) {
|
|
|
+ DeviceUseRecords entity = deviceUseRecordDao.init(mqttDataId, TokenUtil.create());
|
|
|
+ if (ObjectUtils.isNotEmpty(entity)) {
|
|
|
+ entity.setCreateTimeStr(DateUtils.paresTime(System.currentTimeMillis(), DateUtils.FORMAT_LONG));
|
|
|
+ return entity;
|
|
|
+ }
|
|
|
+ return null;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -165,76 +177,75 @@ public class DeviceUseRecordService extends SuperService {
|
|
|
*
|
|
|
* @param entity
|
|
|
*/
|
|
|
- public void checkUseDeviceData(DeviceUseRecord entity) {
|
|
|
- // 主要是从设备、卡片等的基础信息验证
|
|
|
- if (ObjectUtils.isNotEmpty(entity)) {
|
|
|
- // 1. 检查设备
|
|
|
- if (ObjectUtils.isEmpty(entity.getDeviceInfo())) {
|
|
|
- entity.setIsPassed(Boolean.FALSE);
|
|
|
- entity.setMsg("设备信息未找到");
|
|
|
- return;
|
|
|
- }
|
|
|
- DeviceInfo deviceInfo = entity.getDeviceInfo();
|
|
|
- if (deviceInfo.getState() == null || deviceInfo.getState() != DataState.Enable) {
|
|
|
- entity.setIsPassed(Boolean.FALSE);
|
|
|
- entity.setMsg("设备未启用");
|
|
|
- return;
|
|
|
- }
|
|
|
- //2. 验证用户信息
|
|
|
- UserAccount 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;
|
|
|
- }
|
|
|
- CardInfo 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 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;
|
|
|
+// }
|
|
|
+// }
|
|
|
+// }
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -243,7 +254,7 @@ public class DeviceUseRecordService extends SuperService {
|
|
|
* @param entity
|
|
|
* @return
|
|
|
*/
|
|
|
- public DeviceUseRecordModel toModel(DeviceUseRecord entity) {
|
|
|
+ public DeviceUseRecordModel toModel(DeviceUseRecords entity) {
|
|
|
DeviceUseRecordModel model = null;
|
|
|
if (ObjectUtils.isNotEmpty(entity)) {
|
|
|
model = new DeviceUseRecordModel();
|