|
@@ -4,11 +4,13 @@ import cn.hutool.json.JSONObject;
|
|
|
import com.github.microservice.core.util.os.SystemUtil;
|
|
import com.github.microservice.core.util.os.SystemUtil;
|
|
|
import com.github.microservice.dataConfig.IotIdentifierConfig;
|
|
import com.github.microservice.dataConfig.IotIdentifierConfig;
|
|
|
import com.github.microservice.models.device.DevicePerQuery;
|
|
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.DeviceUsersInfo;
|
|
|
import com.github.microservice.models.devicePermiss.GateWayPermissModel;
|
|
import com.github.microservice.models.devicePermiss.GateWayPermissModel;
|
|
|
import com.github.microservice.models.iot.IotSendParam;
|
|
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.zhongshu.card.server.core.dao.devices.DeviceInfoDao;
|
|
import com.zhongshu.card.server.core.dao.devices.DeviceInfoDao;
|
|
|
import com.zhongshu.card.server.core.domain.devices.DeviceInfo;
|
|
import com.zhongshu.card.server.core.domain.devices.DeviceInfo;
|
|
|
import com.zhongshu.card.server.core.event.DevicePermissChangeEvent;
|
|
import com.zhongshu.card.server.core.event.DevicePermissChangeEvent;
|
|
@@ -18,6 +20,7 @@ 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;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
|
|
+import org.apache.kafka.common.protocol.types.Field;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.context.ApplicationContext;
|
|
import org.springframework.context.ApplicationContext;
|
|
|
import org.springframework.context.event.EventListener;
|
|
import org.springframework.context.event.EventListener;
|
|
@@ -72,8 +75,7 @@ public class DevicePermissEventService {
|
|
|
* @param projectOid
|
|
* @param projectOid
|
|
|
*/
|
|
*/
|
|
|
public void sendUserInfoChangeEvent(String userId, String projectOid) {
|
|
public void sendUserInfoChangeEvent(String userId, String projectOid) {
|
|
|
- UserInfoChangeSyncEvent event = new UserInfoChangeSyncEvent(this,
|
|
|
|
|
- List.of(userId), projectOid);
|
|
|
|
|
|
|
+ UserInfoChangeSyncEvent event = new UserInfoChangeSyncEvent(this, List.of(userId), projectOid);
|
|
|
applicationContext.publishEvent(event);
|
|
applicationContext.publishEvent(event);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -84,8 +86,7 @@ public class DevicePermissEventService {
|
|
|
* @param projectOid
|
|
* @param projectOid
|
|
|
*/
|
|
*/
|
|
|
public void sendUserInfoChangeEvent(List<String> userIds, String projectOid) {
|
|
public void sendUserInfoChangeEvent(List<String> userIds, String projectOid) {
|
|
|
- UserInfoChangeSyncEvent event = new UserInfoChangeSyncEvent(this,
|
|
|
|
|
- userIds, projectOid);
|
|
|
|
|
|
|
+ UserInfoChangeSyncEvent event = new UserInfoChangeSyncEvent(this, userIds, projectOid);
|
|
|
applicationContext.publishEvent(event);
|
|
applicationContext.publishEvent(event);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -96,8 +97,7 @@ public class DevicePermissEventService {
|
|
|
* @param projectOid
|
|
* @param projectOid
|
|
|
*/
|
|
*/
|
|
|
public void sendDeviceChangeEvent(List<String> deviceIds, String projectOid) {
|
|
public void sendDeviceChangeEvent(List<String> deviceIds, String projectOid) {
|
|
|
- DevicePermissChangeEvent event = new DevicePermissChangeEvent(this,
|
|
|
|
|
- deviceIds, projectOid);
|
|
|
|
|
|
|
+ DevicePermissChangeEvent event = new DevicePermissChangeEvent(this, deviceIds, projectOid);
|
|
|
applicationContext.publishEvent(event);
|
|
applicationContext.publishEvent(event);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -122,24 +122,8 @@ public class DevicePermissEventService {
|
|
|
List<String> subList = _deviceIds.subList(0, index);
|
|
List<String> subList = _deviceIds.subList(0, index);
|
|
|
_deviceIds = _deviceIds.subList(index, _deviceIds.size());
|
|
_deviceIds = _deviceIds.subList(index, _deviceIds.size());
|
|
|
|
|
|
|
|
- sendDeviceAboutUserInfo(gateWayId, subList, projectOid);
|
|
|
|
|
sendDeviceAboutUsers(gateWayId, subList, projectOid);
|
|
sendDeviceAboutUsers(gateWayId, subList, projectOid);
|
|
|
-
|
|
|
|
|
-// DeviceInfo deviceInfo = deviceInfoDao.findTopByDeviceId(subList.get(0));
|
|
|
|
|
-// IotSendParam param = new IotSendParam();
|
|
|
|
|
-// param.setGateWayId(gateWayId);
|
|
|
|
|
-// param.setIdentifier(IotIdentifierConfig.permissionNotice);
|
|
|
|
|
-//
|
|
|
|
|
-// // 组装消息内容
|
|
|
|
|
-// JSONObject jsonObject = new JSONObject();
|
|
|
|
|
-// jsonObject.set("deviceIds", subList);
|
|
|
|
|
-// param.setData(jsonObject);
|
|
|
|
|
-// ResultContent resultContent = openApiRequestService.sendIotMessage(param, deviceInfo.getProjectOid());
|
|
|
|
|
-// if (resultContent.isSuccess()) {
|
|
|
|
|
-//
|
|
|
|
|
-// } else {
|
|
|
|
|
-// log.error("网关设备权限通知失败 {} {}", gateWayId, resultContent.getMsg());
|
|
|
|
|
-// }
|
|
|
|
|
|
|
+ sendDeviceAboutUserInfo(gateWayId, subList, projectOid);
|
|
|
if (!_deviceIds.isEmpty()) {
|
|
if (!_deviceIds.isEmpty()) {
|
|
|
TimeUnit.SECONDS.sleep(10);
|
|
TimeUnit.SECONDS.sleep(10);
|
|
|
}
|
|
}
|
|
@@ -193,6 +177,36 @@ public class DevicePermissEventService {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 清除所有所有数据
|
|
|
|
|
+ *
|
|
|
|
|
+ * @param deviceIds
|
|
|
|
|
+ * @param projectOid
|
|
|
|
|
+ */
|
|
|
|
|
+ public void clearDevicesAllBindUser(List<String> deviceIds, String projectOid) {
|
|
|
|
|
+ if (ObjectUtils.isNotEmpty(deviceIds) && StringUtils.isNotEmpty(projectOid)) {
|
|
|
|
|
+ executorService.execute(() -> {
|
|
|
|
|
+ HashMap<String, List<String>> map = deviceGroupByGateWayId(deviceIds);
|
|
|
|
|
+ map.keySet().stream().forEach(gateWayId -> {
|
|
|
|
|
+ GateWayPermissModel gateWayPermissModel = new GateWayPermissModel();
|
|
|
|
|
+ gateWayPermissModel.setGateWayId(gateWayId);
|
|
|
|
|
+ List<String> _deviceIds = map.get(gateWayId);
|
|
|
|
|
+
|
|
|
|
|
+ List<DeviceAboutPermiss> permisses = new ArrayList<DeviceAboutPermiss>();
|
|
|
|
|
+ for (String deviceId : _deviceIds) {
|
|
|
|
|
+ DeviceAboutPermiss permiss = new DeviceAboutPermiss();
|
|
|
|
|
+ permiss.setDeviceId(deviceId);
|
|
|
|
|
+ permiss.setMark(2);
|
|
|
|
|
+ permiss.setUserIds(Lists.newArrayList());
|
|
|
|
|
+ permisses.add(permiss);
|
|
|
|
|
+ }
|
|
|
|
|
+ gateWayPermissModel.setDevices(permisses);
|
|
|
|
|
+ requestDeviceBindData(gateWayPermissModel, projectOid);
|
|
|
|
|
+ });
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
* 发送设备关联的用户数据
|
|
* 发送设备关联的用户数据
|
|
|
*
|
|
*
|
|
@@ -205,7 +219,17 @@ public class DevicePermissEventService {
|
|
|
query.setDeviceIds(deviceIds);
|
|
query.setDeviceIds(deviceIds);
|
|
|
query.setGateWayId(gateWayId);
|
|
query.setGateWayId(gateWayId);
|
|
|
GateWayPermissModel gateWayPermissModel = devicePermissIotService.queryDevicePermissInfo(query);
|
|
GateWayPermissModel gateWayPermissModel = devicePermissIotService.queryDevicePermissInfo(query);
|
|
|
|
|
+ requestDeviceBindData(gateWayPermissModel, projectOid);
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 请求下发设备关联的用户
|
|
|
|
|
+ *
|
|
|
|
|
+ * @param gateWayPermissModel
|
|
|
|
|
+ * @param projectOid
|
|
|
|
|
+ */
|
|
|
|
|
+ public void requestDeviceBindData(GateWayPermissModel gateWayPermissModel, String projectOid) {
|
|
|
|
|
+ String gateWayId = gateWayPermissModel.getGateWayId();
|
|
|
IotSendParam param = new IotSendParam();
|
|
IotSendParam param = new IotSendParam();
|
|
|
param.setGateWayId(gateWayId);
|
|
param.setGateWayId(gateWayId);
|
|
|
param.setIdentifier(IotIdentifierConfig.queryDeviceBindUsers);
|
|
param.setIdentifier(IotIdentifierConfig.queryDeviceBindUsers);
|
|
@@ -232,7 +256,17 @@ public class DevicePermissEventService {
|
|
|
query.setDeviceIds(deviceIds);
|
|
query.setDeviceIds(deviceIds);
|
|
|
query.setGateWayId(gateWayId);
|
|
query.setGateWayId(gateWayId);
|
|
|
DeviceUsersInfo deviceUsersInfo = devicePermissIotService.queryDeviceAboutUsers(query);
|
|
DeviceUsersInfo deviceUsersInfo = devicePermissIotService.queryDeviceAboutUsers(query);
|
|
|
|
|
+ requestDevicesUsersData(deviceUsersInfo, projectOid);
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 请求下发用户信息发生变化
|
|
|
|
|
+ *
|
|
|
|
|
+ * @param deviceUsersInfo
|
|
|
|
|
+ * @param projectOid
|
|
|
|
|
+ */
|
|
|
|
|
+ public void requestDevicesUsersData(DeviceUsersInfo deviceUsersInfo, String projectOid) {
|
|
|
|
|
+ String gateWayId = deviceUsersInfo.getGateWayId();
|
|
|
IotSendParam param = new IotSendParam();
|
|
IotSendParam param = new IotSendParam();
|
|
|
param.setGateWayId(gateWayId);
|
|
param.setGateWayId(gateWayId);
|
|
|
param.setIdentifier(IotIdentifierConfig.queryDeviceUsersInfo);
|
|
param.setIdentifier(IotIdentifierConfig.queryDeviceUsersInfo);
|