|
@@ -69,6 +69,9 @@ public class DevicePermissEventService {
|
|
|
@Autowired
|
|
@Autowired
|
|
|
private DevicePermissSendLogDao devicePermissSendLogDao;
|
|
private DevicePermissSendLogDao devicePermissSendLogDao;
|
|
|
|
|
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private DevicePermissSendLogService devicePermissSendLogService;
|
|
|
|
|
+
|
|
|
@Autowired
|
|
@Autowired
|
|
|
private void init(ApplicationContext applicationContext) {
|
|
private void init(ApplicationContext applicationContext) {
|
|
|
Runtime.getRuntime().addShutdownHook(new Thread(() -> {
|
|
Runtime.getRuntime().addShutdownHook(new Thread(() -> {
|
|
@@ -174,30 +177,17 @@ public class DevicePermissEventService {
|
|
|
// 网关 对应的设备
|
|
// 网关 对应的设备
|
|
|
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.setGroupId(groupId);
|
|
|
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);
|
|
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
});
|
|
});
|
|
@@ -260,6 +250,28 @@ public class DevicePermissEventService {
|
|
|
IotSendParam param = new IotSendParam();
|
|
IotSendParam param = new IotSendParam();
|
|
|
param.setGateWayId(gateWayId);
|
|
param.setGateWayId(gateWayId);
|
|
|
param.setIdentifier(IotIdentifierConfig.queryDeviceBindUsers);
|
|
param.setIdentifier(IotIdentifierConfig.queryDeviceBindUsers);
|
|
|
|
|
+
|
|
|
|
|
+ String groupId = gateWayPermissModel.getGroupId();
|
|
|
|
|
+ if (ObjectUtils.isNotEmpty(gateWayPermissModel.getDevices())
|
|
|
|
|
+ && StringUtils.isNotEmpty(groupId)) {
|
|
|
|
|
+ List<DevicePermissSendLog> list = new ArrayList<>();
|
|
|
|
|
+ for (DeviceAboutPermiss deviceAboutPermiss : gateWayPermissModel.getDevices()) {
|
|
|
|
|
+ deviceAboutPermiss.setDataId(CommonUtil.UUID());
|
|
|
|
|
+
|
|
|
|
|
+ DevicePermissSendLog sendLog = new DevicePermissSendLog();
|
|
|
|
|
+ sendLog.setDataId(deviceAboutPermiss.getDataId());
|
|
|
|
|
+ sendLog.setGateWayId(gateWayId);
|
|
|
|
|
+ sendLog.setDeviceId(deviceAboutPermiss.getDeviceId());
|
|
|
|
|
+ sendLog.setGroupId(groupId);
|
|
|
|
|
+ sendLog.setData(gateWayPermissModel);
|
|
|
|
|
+ sendLog.setSendTime(DateUtils.paresTime(System.currentTimeMillis(), DateUtils.FORMAT_LONG));
|
|
|
|
|
+ sendLog.setEvent(IotIdentifierConfig.queryDeviceBindUsers);
|
|
|
|
|
+ sendLog.setTtl(new Date(System.currentTimeMillis() + TtlConfig.permissLogTTl));
|
|
|
|
|
+ list.add(sendLog);
|
|
|
|
|
+ }
|
|
|
|
|
+ devicePermissSendLogDao.saveAll(list);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
// 组装消息内容
|
|
// 组装消息内容
|
|
|
JSONObject jsonObject = gateWayPermissModel.toJson();
|
|
JSONObject jsonObject = gateWayPermissModel.toJson();
|
|
|
param.setData(jsonObject);
|
|
param.setData(jsonObject);
|
|
@@ -269,6 +281,7 @@ public class DevicePermissEventService {
|
|
|
} else {
|
|
} else {
|
|
|
log.error("设备权限下发失败 网关ID:{} {}", gateWayId, resultContent.getMsg());
|
|
log.error("设备权限下发失败 网关ID:{} {}", gateWayId, resultContent.getMsg());
|
|
|
}
|
|
}
|
|
|
|
|
+ devicePermissSendLogService.markPermissSend(groupId, resultContent.isSuccess(), resultContent.getMsg());
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -297,6 +310,28 @@ public class DevicePermissEventService {
|
|
|
IotSendParam param = new IotSendParam();
|
|
IotSendParam param = new IotSendParam();
|
|
|
param.setGateWayId(gateWayId);
|
|
param.setGateWayId(gateWayId);
|
|
|
param.setIdentifier(IotIdentifierConfig.queryDeviceUsersInfo);
|
|
param.setIdentifier(IotIdentifierConfig.queryDeviceUsersInfo);
|
|
|
|
|
+
|
|
|
|
|
+ String groupId = deviceUsersInfo.getGroupId();
|
|
|
|
|
+ if (ObjectUtils.isNotEmpty(deviceUsersInfo.getUsers())
|
|
|
|
|
+ && StringUtils.isNotEmpty(groupId)) {
|
|
|
|
|
+ List<DevicePermissSendLog> list = new ArrayList<>();
|
|
|
|
|
+ for (ProjectUserPermiss projectUserPermiss : deviceUsersInfo.getUsers()) {
|
|
|
|
|
+ projectUserPermiss.setDataId(CommonUtil.UUID());
|
|
|
|
|
+ DevicePermissSendLog sendLog = new DevicePermissSendLog();
|
|
|
|
|
+ sendLog.setDataId(projectUserPermiss.getDataId());
|
|
|
|
|
+ sendLog.setGateWayId(gateWayId);
|
|
|
|
|
+ sendLog.setUserId(projectUserPermiss.getUid());
|
|
|
|
|
+ sendLog.setUserId(projectUserPermiss.getUn());
|
|
|
|
|
+ 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);
|
|
|
|
|
+ }
|
|
|
|
|
+ devicePermissSendLogDao.saveAll(list);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
// 组装消息内容
|
|
// 组装消息内容
|
|
|
JSONObject jsonObject = deviceUsersInfo.toJson();
|
|
JSONObject jsonObject = deviceUsersInfo.toJson();
|
|
|
param.setData(jsonObject);
|
|
param.setData(jsonObject);
|
|
@@ -306,6 +341,7 @@ public class DevicePermissEventService {
|
|
|
} else {
|
|
} else {
|
|
|
log.error("用户信息下发失败 网关ID:{} {}", gateWayId, resultContent.getMsg());
|
|
log.error("用户信息下发失败 网关ID:{} {}", gateWayId, resultContent.getMsg());
|
|
|
}
|
|
}
|
|
|
|
|
+ devicePermissSendLogService.markPermissSend(groupId, resultContent.isSuccess(), resultContent.getMsg());
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|