|
@@ -12,11 +12,16 @@ import com.github.microservice.models.iot.IotSendParam;
|
|
|
import com.github.microservice.net.ResultContent;
|
|
import com.github.microservice.net.ResultContent;
|
|
|
import com.github.microservice.types.FunctionType;
|
|
import com.github.microservice.types.FunctionType;
|
|
|
import com.google.common.collect.Lists;
|
|
import com.google.common.collect.Lists;
|
|
|
|
|
+import com.zhongshu.card.client.utils.DateUtils;
|
|
|
import com.zhongshu.card.server.core.dao.devices.DeviceInfoDao;
|
|
import com.zhongshu.card.server.core.dao.devices.DeviceInfoDao;
|
|
|
|
|
+import com.zhongshu.card.server.core.dao.devices.DevicePermissSendLogDao;
|
|
|
|
|
+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.DeviceInfo;
|
|
|
|
|
+import com.zhongshu.card.server.core.domain.devices.DevicePermissSendLog;
|
|
|
import com.zhongshu.card.server.core.event.DevicePermissChangeEvent;
|
|
import com.zhongshu.card.server.core.event.DevicePermissChangeEvent;
|
|
|
import com.zhongshu.card.server.core.event.UserInfoChangeSyncEvent;
|
|
import com.zhongshu.card.server.core.event.UserInfoChangeSyncEvent;
|
|
|
import com.zhongshu.card.server.core.service.openAPI.OpenApiRequestService;
|
|
import com.zhongshu.card.server.core.service.openAPI.OpenApiRequestService;
|
|
|
|
|
+import com.zhongshu.card.server.core.util.CommonUtil;
|
|
|
import lombok.SneakyThrows;
|
|
import lombok.SneakyThrows;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.commons.lang3.ObjectUtils;
|
|
import org.apache.commons.lang3.ObjectUtils;
|
|
@@ -27,9 +32,7 @@ import org.springframework.context.ApplicationContext;
|
|
|
import org.springframework.context.event.EventListener;
|
|
import org.springframework.context.event.EventListener;
|
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
|
|
-import java.util.ArrayList;
|
|
|
|
|
-import java.util.HashMap;
|
|
|
|
|
-import java.util.List;
|
|
|
|
|
|
|
+import java.util.*;
|
|
|
import java.util.concurrent.ExecutorService;
|
|
import java.util.concurrent.ExecutorService;
|
|
|
import java.util.concurrent.Executors;
|
|
import java.util.concurrent.Executors;
|
|
|
import java.util.concurrent.TimeUnit;
|
|
import java.util.concurrent.TimeUnit;
|
|
@@ -63,6 +66,9 @@ public class DevicePermissEventService {
|
|
|
@Autowired
|
|
@Autowired
|
|
|
private ApplicationContext applicationContext;
|
|
private ApplicationContext applicationContext;
|
|
|
|
|
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private DevicePermissSendLogDao devicePermissSendLogDao;
|
|
|
|
|
+
|
|
|
@Autowired
|
|
@Autowired
|
|
|
private void init(ApplicationContext applicationContext) {
|
|
private void init(ApplicationContext applicationContext) {
|
|
|
Runtime.getRuntime().addShutdownHook(new Thread(() -> {
|
|
Runtime.getRuntime().addShutdownHook(new Thread(() -> {
|
|
@@ -81,6 +87,12 @@ public class DevicePermissEventService {
|
|
|
applicationContext.publishEvent(event);
|
|
applicationContext.publishEvent(event);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ public void sendUserInfoChangeEvent(String userId, String projectOid, Map<String, Object> map) {
|
|
|
|
|
+ UserInfoChangeSyncEvent event = new UserInfoChangeSyncEvent(
|
|
|
|
|
+ this, List.of(userId), projectOid, map);
|
|
|
|
|
+ applicationContext.publishEvent(event);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
* 通知用户关联信息发送变化
|
|
* 通知用户关联信息发送变化
|
|
|
*
|
|
*
|
|
@@ -153,24 +165,39 @@ public class DevicePermissEventService {
|
|
|
log.info("userInfoChange; {} {}", projectOid);
|
|
log.info("userInfoChange; {} {}", projectOid);
|
|
|
if (StringUtils.isNotEmpty(projectOid) && ObjectUtils.isNotEmpty(userIds[0])) {
|
|
if (StringUtils.isNotEmpty(projectOid) && ObjectUtils.isNotEmpty(userIds[0])) {
|
|
|
executorService.execute(() -> {
|
|
executorService.execute(() -> {
|
|
|
|
|
+ String groupId = event.getGroupId();
|
|
|
userIds[0] = userIds[0].stream().distinct().collect(Collectors.toList());
|
|
userIds[0] = userIds[0].stream().distinct().collect(Collectors.toList());
|
|
|
// 循环用户数据
|
|
// 循环用户数据
|
|
|
for (String userId : userIds[0]) {
|
|
for (String userId : userIds[0]) {
|
|
|
List<String> deviceIds = devicePermissService.getUserAllDeviceIds(
|
|
List<String> deviceIds = devicePermissService.getUserAllDeviceIds(
|
|
|
projectOid, List.of(userId));
|
|
projectOid, List.of(userId));
|
|
|
|
|
+ // 网关 对应的设备
|
|
|
HashMap<String, List<String>> map = deviceGroupByGateWayId(deviceIds);
|
|
HashMap<String, List<String>> map = deviceGroupByGateWayId(deviceIds);
|
|
|
if (!map.isEmpty()) {
|
|
if (!map.isEmpty()) {
|
|
|
|
|
+ List<DevicePermissSendLog> list = new ArrayList<>();
|
|
|
// 遍历发送
|
|
// 遍历发送
|
|
|
map.keySet().stream().forEach(gateWayId -> {
|
|
map.keySet().stream().forEach(gateWayId -> {
|
|
|
DeviceUsersInfo deviceUsersInfo = new DeviceUsersInfo();
|
|
DeviceUsersInfo deviceUsersInfo = new DeviceUsersInfo();
|
|
|
deviceUsersInfo.setGateWayId(gateWayId);
|
|
deviceUsersInfo.setGateWayId(gateWayId);
|
|
|
// 用户数据 (去重)
|
|
// 用户数据 (去重)
|
|
|
List<ProjectUserPermiss> userPermiss = devicePermissIotService.getUserPermiss(projectOid, userIds[0]);
|
|
List<ProjectUserPermiss> userPermiss = devicePermissIotService.getUserPermiss(projectOid, userIds[0]);
|
|
|
-
|
|
|
|
|
|
|
+ for (ProjectUserPermiss projectUserPermiss : userPermiss) {
|
|
|
|
|
+ projectUserPermiss.setDataId(CommonUtil.UUID());
|
|
|
|
|
+ DevicePermissSendLog sendLog = new DevicePermissSendLog();
|
|
|
|
|
+ sendLog.setGateWayId(gateWayId);
|
|
|
|
|
+ sendLog.setUserId(userId);
|
|
|
|
|
+ sendLog.setGroupId(groupId);
|
|
|
|
|
+ sendLog.setData(projectUserPermiss);
|
|
|
|
|
+ sendLog.setSendTime(DateUtils.paresTime(System.currentTimeMillis(), DateUtils.FORMAT_LONG));
|
|
|
|
|
+ sendLog.setEvent(IotIdentifierConfig.queryDeviceUsersInfo);
|
|
|
|
|
+ sendLog.setTtl(new Date(System.currentTimeMillis() + TtlConfig.permissLogTTl));
|
|
|
|
|
+ list.add(sendLog);
|
|
|
|
|
+ }
|
|
|
deviceUsersInfo.setUsers(userPermiss);
|
|
deviceUsersInfo.setUsers(userPermiss);
|
|
|
// 下发用户数据
|
|
// 下发用户数据
|
|
|
requestDevicesUsersData(deviceUsersInfo, projectOid);
|
|
requestDevicesUsersData(deviceUsersInfo, projectOid);
|
|
|
});
|
|
});
|
|
|
|
|
+ devicePermissSendLogDao.saveAll(list);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
});
|
|
});
|