|
|
@@ -7,6 +7,7 @@ import com.github.microservice.models.device.DevicePerQuery;
|
|
|
import com.github.microservice.models.devicePermiss.DeviceAboutPermiss;
|
|
|
import com.github.microservice.models.devicePermiss.DeviceUsersInfo;
|
|
|
import com.github.microservice.models.devicePermiss.GateWayPermissModel;
|
|
|
+import com.github.microservice.models.devicePermiss.ProjectUserPermiss;
|
|
|
import com.github.microservice.models.iot.IotSendParam;
|
|
|
import com.github.microservice.net.ResultContent;
|
|
|
import com.github.microservice.types.FunctionType;
|
|
|
@@ -32,6 +33,7 @@ import java.util.List;
|
|
|
import java.util.concurrent.ExecutorService;
|
|
|
import java.util.concurrent.Executors;
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
* 设备 用户 权限发生变化监听
|
|
|
@@ -145,33 +147,31 @@ public class DevicePermissEventService {
|
|
|
@EventListener(classes = UserInfoChangeSyncEvent.class)
|
|
|
@SneakyThrows
|
|
|
public void userInfoChange(UserInfoChangeSyncEvent event) {
|
|
|
+ // 用户信息发送变化
|
|
|
String projectOid = event.getProjectOid();
|
|
|
- List<String> userIds = event.getUserIds();
|
|
|
+ final List<String>[] userIds = new List[]{event.getUserIds()};
|
|
|
log.info("userInfoChange; {} {}", projectOid);
|
|
|
- if (StringUtils.isNotEmpty(projectOid) && ObjectUtils.isNotEmpty(userIds)) {
|
|
|
+ if (StringUtils.isNotEmpty(projectOid) && ObjectUtils.isNotEmpty(userIds[0])) {
|
|
|
executorService.execute(() -> {
|
|
|
- List<String> deviceIds = devicePermissService.getUserAllDeviceIds(projectOid, userIds);
|
|
|
- HashMap<String, List<String>> map = deviceGroupByGateWayId(deviceIds);
|
|
|
- if (!map.isEmpty()) {
|
|
|
- // 遍历发送
|
|
|
- map.keySet().stream().forEach(gateWayId -> {
|
|
|
- List<String> _deviceIds = map.get(gateWayId);
|
|
|
- try {
|
|
|
- while (_deviceIds.size() > 0) {
|
|
|
- // 统计网关管理的所有设备
|
|
|
- int index = Math.min(_deviceIds.size(), IotIdentifierConfig.maxNoticeSize);
|
|
|
- List<String> subList = _deviceIds.subList(0, index);
|
|
|
- _deviceIds = _deviceIds.subList(index, _deviceIds.size());
|
|
|
- // 下发用户信息
|
|
|
- sendDeviceAboutUserInfo(gateWayId, subList, projectOid);
|
|
|
- if (!_deviceIds.isEmpty()) {
|
|
|
- TimeUnit.SECONDS.sleep(10);
|
|
|
- }
|
|
|
- }
|
|
|
- } catch (Exception e) {
|
|
|
- throw new RuntimeException(e);
|
|
|
- }
|
|
|
- });
|
|
|
+ userIds[0] = userIds[0].stream().distinct().collect(Collectors.toList());
|
|
|
+ // 循环用户数据
|
|
|
+ for (String userId : userIds[0]) {
|
|
|
+ List<String> deviceIds = devicePermissService.getUserAllDeviceIds(
|
|
|
+ projectOid, List.of(userId));
|
|
|
+ HashMap<String, List<String>> map = deviceGroupByGateWayId(deviceIds);
|
|
|
+ if (!map.isEmpty()) {
|
|
|
+ // 遍历发送
|
|
|
+ map.keySet().stream().forEach(gateWayId -> {
|
|
|
+ DeviceUsersInfo deviceUsersInfo = new DeviceUsersInfo();
|
|
|
+ deviceUsersInfo.setGateWayId(gateWayId);
|
|
|
+ // 用户数据 (去重)
|
|
|
+ List<ProjectUserPermiss> userPermiss = devicePermissIotService.getUserPermiss(projectOid, userIds[0]);
|
|
|
+
|
|
|
+ deviceUsersInfo.setUsers(userPermiss);
|
|
|
+ // 下发用户数据
|
|
|
+ requestDevicesUsersData(deviceUsersInfo, projectOid);
|
|
|
+ });
|
|
|
+ }
|
|
|
}
|
|
|
});
|
|
|
}
|