|
|
@@ -3,17 +3,23 @@ package com.zhongshu.card.server.core.service.devices.permiss;
|
|
|
import com.zhongshu.card.client.model.devices.userCache.UserCacheModel;
|
|
|
import com.zhongshu.card.client.type.DataState;
|
|
|
import com.zhongshu.card.client.type.UserState;
|
|
|
+import com.zhongshu.card.server.core.dao.devices.DeviceGroupToDeviceDao;
|
|
|
+import com.zhongshu.card.server.core.dao.devices.DeviceInfoDao;
|
|
|
import com.zhongshu.card.server.core.dao.devices.UserPermissDataCacheDao;
|
|
|
import com.zhongshu.card.server.core.dao.org.OrganizationUserDao;
|
|
|
import com.zhongshu.card.server.core.dao.org.UserCountDao;
|
|
|
import com.zhongshu.card.server.core.dao.org.UserGroupDao;
|
|
|
import com.zhongshu.card.server.core.dao.org.UserGroupToUserDao;
|
|
|
import com.zhongshu.card.server.core.dataConfig.TtlConfig;
|
|
|
+import com.zhongshu.card.server.core.domain.devices.DeviceGroup;
|
|
|
+import com.zhongshu.card.server.core.domain.devices.DeviceGroupToDevice;
|
|
|
+import com.zhongshu.card.server.core.domain.devices.DeviceInfo;
|
|
|
import com.zhongshu.card.server.core.domain.devices.permiss.UserPermissDataCache;
|
|
|
import com.zhongshu.card.server.core.domain.org.OrganizationUser;
|
|
|
import com.zhongshu.card.server.core.domain.org.UserAccount;
|
|
|
import com.zhongshu.card.server.core.domain.org.UserGroup;
|
|
|
import com.zhongshu.card.server.core.domain.org.UserGroupToUser;
|
|
|
+import com.zhongshu.card.server.core.event.DevicePermissChangeEvent;
|
|
|
import com.zhongshu.card.server.core.event.UserInfoChangeSyncEvent;
|
|
|
import com.zhongshu.card.server.core.service.base.SuperService;
|
|
|
import com.zhongshu.card.server.core.service.org.OrganizationUserServiceImpl;
|
|
|
@@ -56,6 +62,12 @@ public class UserPermissDataCacheService extends SuperService {
|
|
|
@Autowired
|
|
|
private UserPermissDataCacheDao userPermissDataCacheDao;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private DeviceInfoDao deviceInfoDao;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private DeviceGroupToDeviceDao deviceGroupToDeviceDao;
|
|
|
+
|
|
|
@EventListener(classes = UserInfoChangeSyncEvent.class)
|
|
|
@SneakyThrows
|
|
|
public void userPermissDataChange(UserInfoChangeSyncEvent event) {
|
|
|
@@ -69,6 +81,19 @@ public class UserPermissDataCacheService extends SuperService {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ @EventListener(classes = DevicePermissChangeEvent.class)
|
|
|
+ @SneakyThrows
|
|
|
+ public void devicePermissDataChange(DevicePermissChangeEvent event) {
|
|
|
+ log.info("devicePermissDataChange: {}", event.getFrom());
|
|
|
+ String projectOid = event.getProjectOid();
|
|
|
+ List<String> deviceIds = event.getDeviceIds();
|
|
|
+ if (ObjectUtils.isNotEmpty(deviceIds) && StringUtils.isNotEmpty(projectOid)) {
|
|
|
+ for (String deviceId : deviceIds) {
|
|
|
+ updateDevicePermissAboutInfo(deviceId, projectOid);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 缓存用户
|
|
|
*
|
|
|
@@ -80,12 +105,15 @@ public class UserPermissDataCacheService extends SuperService {
|
|
|
if (ObjectUtils.isEmpty(dataCache)) {
|
|
|
dataCache = new UserPermissDataCache();
|
|
|
dataCache.setTTL(new Date(System.currentTimeMillis() + TtlConfig.userCacheTime));
|
|
|
+ dataCache.setDataId(userId);
|
|
|
+ dataCache.setProjectOid(projectOid);
|
|
|
}
|
|
|
|
|
|
// 影响范围:用户项目中:机构、角色、分户分组、性别
|
|
|
UserCacheModel model = new UserCacheModel();
|
|
|
UserAccount userAccount = userCountDao.findTopByUserId(userId);
|
|
|
if (ObjectUtils.isNotEmpty(userAccount)) {
|
|
|
+ dataCache.setDataName(userAccount.getName());
|
|
|
if (userAccount.getState() != UserState.Normal) {
|
|
|
model.setFailed("用户不可用");
|
|
|
} else {
|
|
|
@@ -124,9 +152,77 @@ public class UserPermissDataCacheService extends SuperService {
|
|
|
return dataCache;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 更新设备的权限数据
|
|
|
+ *
|
|
|
+ * @param deviceId
|
|
|
+ * @param projectOid
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private UserPermissDataCache updateDevicePermissAboutInfo(String deviceId, String projectOid) {
|
|
|
+ UserPermissDataCache dataCache = userPermissDataCacheDao.findTopByDataIdAndProjectOid(deviceId, projectOid);
|
|
|
+ if (ObjectUtils.isEmpty(dataCache)) {
|
|
|
+ dataCache = new UserPermissDataCache();
|
|
|
+ dataCache.setTTL(new Date(System.currentTimeMillis() + TtlConfig.userCacheTime));
|
|
|
+ dataCache.setDataId(deviceId);
|
|
|
+ dataCache.setProjectOid(projectOid);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 影响范围:用户项目中:机构、角色、分户分组、性别
|
|
|
+ UserCacheModel model = new UserCacheModel();
|
|
|
+
|
|
|
+ DeviceInfo deviceInfo = deviceInfoDao.findTopByDeviceId(deviceId);
|
|
|
+ if (ObjectUtils.isNotEmpty(deviceInfo)) {
|
|
|
+ dataCache.setDataName(deviceInfo.getDeviceName());
|
|
|
+
|
|
|
+ if (deviceInfo.getState() != DataState.Enable) {
|
|
|
+ model.setFailed("设备不可用");
|
|
|
+ } else {
|
|
|
+ model.add(deviceId);
|
|
|
+ model.setDeviceType(deviceInfo.getDeviceType());
|
|
|
+ if (StringUtils.isNotEmpty(deviceInfo.getAreaId())) {
|
|
|
+ // 区域的下级怎么办?
|
|
|
+ model.add(deviceInfo.getAreaId());
|
|
|
+ }
|
|
|
+
|
|
|
+ // 设备分组
|
|
|
+ List<DeviceGroupToDevice> deviceAbouts = deviceGroupToDeviceDao.findByProjectOidAndDeviceId(projectOid, deviceId);
|
|
|
+ if (ObjectUtils.isNotEmpty(deviceAbouts)) {
|
|
|
+ deviceAbouts.parallelStream().forEach(it -> {
|
|
|
+ DeviceGroup deviceGroup = it.getDeviceGroup();
|
|
|
+ if (ObjectUtils.isNotEmpty(deviceGroup) && deviceGroup.getState() == DataState.Enable) {
|
|
|
+ model.add(deviceGroup.getId());
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ model.setSuccess();
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ model.setFailed("设备不存在");
|
|
|
+ }
|
|
|
+ dataCache.setCacheData(model);
|
|
|
+ userPermissDataCacheDao.save(dataCache);
|
|
|
+ return dataCache;
|
|
|
+ }
|
|
|
+
|
|
|
public UserCacheModel getUserCacheModel(String userId, String projectOid) {
|
|
|
UserCacheModel model = null;
|
|
|
UserPermissDataCache dataCache = userPermissDataCacheDao.findTopByDataIdAndProjectOid(userId, projectOid);
|
|
|
+ if (ObjectUtils.isEmpty(dataCache)) {
|
|
|
+ dataCache = updateUserDevicePermissAboutInfo(userId, projectOid);
|
|
|
+ }
|
|
|
+ if (ObjectUtils.isNotEmpty(dataCache)) {
|
|
|
+ model = (UserCacheModel) dataCache.getCacheData();
|
|
|
+ }
|
|
|
+ return model;
|
|
|
+ }
|
|
|
+
|
|
|
+ public UserCacheModel getDeviceCacheModel(String deviceId, String projectOid) {
|
|
|
+ UserCacheModel model = null;
|
|
|
+ UserPermissDataCache dataCache = userPermissDataCacheDao.findTopByDataIdAndProjectOid(deviceId, projectOid);
|
|
|
+ if (ObjectUtils.isEmpty(dataCache)) {
|
|
|
+ dataCache = updateDevicePermissAboutInfo(deviceId, projectOid);
|
|
|
+ }
|
|
|
if (ObjectUtils.isNotEmpty(dataCache)) {
|
|
|
model = (UserCacheModel) dataCache.getCacheData();
|
|
|
}
|