|
@@ -1,5 +1,6 @@
|
|
|
package com.zhongshu.card.server.core.service.devices;
|
|
package com.zhongshu.card.server.core.service.devices;
|
|
|
|
|
|
|
|
|
|
+import cn.hutool.json.JSONObject;
|
|
|
import cn.hutool.json.JSONUtil;
|
|
import cn.hutool.json.JSONUtil;
|
|
|
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;
|
|
@@ -8,12 +9,10 @@ import com.github.microservice.models.devicePermiss.GateWayPermissModel;
|
|
|
import com.github.microservice.models.devicePermiss.GateWayQuery;
|
|
import com.github.microservice.models.devicePermiss.GateWayQuery;
|
|
|
import com.github.microservice.models.devicePermiss.UserPermiss;
|
|
import com.github.microservice.models.devicePermiss.UserPermiss;
|
|
|
import com.github.microservice.models.iot.IotSendParam;
|
|
import com.github.microservice.models.iot.IotSendParam;
|
|
|
-import com.github.microservice.models.iot.PermissionChange;
|
|
|
|
|
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.zhongshu.card.client.model.school.CardInfoModel;
|
|
import com.zhongshu.card.client.model.school.CardInfoModel;
|
|
|
import com.zhongshu.card.client.type.school.CardState;
|
|
import com.zhongshu.card.client.type.school.CardState;
|
|
|
-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.DevicePermissDao;
|
|
import com.zhongshu.card.server.core.dao.devices.DevicePermissDao;
|
|
|
import com.zhongshu.card.server.core.dao.org.OrganizationDao;
|
|
import com.zhongshu.card.server.core.dao.org.OrganizationDao;
|
|
@@ -23,7 +22,6 @@ import com.zhongshu.card.server.core.domain.devices.DevicePermiss;
|
|
|
import com.zhongshu.card.server.core.domain.org.Organization;
|
|
import com.zhongshu.card.server.core.domain.org.Organization;
|
|
|
import com.zhongshu.card.server.core.domain.org.UserAccount;
|
|
import com.zhongshu.card.server.core.domain.org.UserAccount;
|
|
|
import com.zhongshu.card.server.core.domain.projectAbout.OrgUserFace;
|
|
import com.zhongshu.card.server.core.domain.projectAbout.OrgUserFace;
|
|
|
-import com.zhongshu.card.server.core.domain.projectAbout.ProjectIotInfo;
|
|
|
|
|
import com.zhongshu.card.server.core.event.DevicePermissChangeEvent;
|
|
import com.zhongshu.card.server.core.event.DevicePermissChangeEvent;
|
|
|
import com.zhongshu.card.server.core.service.openAPI.OpenApiRequestService;
|
|
import com.zhongshu.card.server.core.service.openAPI.OpenApiRequestService;
|
|
|
import com.zhongshu.card.server.core.service.projectAbout.CardInfoServiceImpl;
|
|
import com.zhongshu.card.server.core.service.projectAbout.CardInfoServiceImpl;
|
|
@@ -38,7 +36,9 @@ import org.springframework.scheduling.annotation.Async;
|
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
import java.util.ArrayList;
|
|
|
|
|
+import java.util.HashMap;
|
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
|
|
+import java.util.concurrent.TimeUnit;
|
|
|
import java.util.stream.Collectors;
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -126,26 +126,61 @@ public class DevicePermissIotService {
|
|
|
// 通知物联网 设备权限发生变化
|
|
// 通知物联网 设备权限发生变化
|
|
|
List<String> deviceIds = event.getDeviceIds();
|
|
List<String> deviceIds = event.getDeviceIds();
|
|
|
if (ObjectUtils.isNotEmpty(deviceIds)) {
|
|
if (ObjectUtils.isNotEmpty(deviceIds)) {
|
|
|
- for (String deviceId : deviceIds) {
|
|
|
|
|
- DeviceInfo deviceInfo = deviceInfoDao.findTopByDeviceId(deviceId);
|
|
|
|
|
- if (ObjectUtils.isEmpty(deviceInfo)) {
|
|
|
|
|
- continue;
|
|
|
|
|
- }
|
|
|
|
|
- IotSendParam param = new IotSendParam();
|
|
|
|
|
- param.setDeviceId(deviceId);
|
|
|
|
|
- param.setIdentifier(IotIdentifierConfig.permissionNotice);
|
|
|
|
|
- param.setFunctionType(FunctionType.Server);
|
|
|
|
|
-
|
|
|
|
|
- PermissionChange change = new PermissionChange();
|
|
|
|
|
- change.setTime(DateUtils.paresTime(System.currentTimeMillis(), DateUtils.FORMAT_LONG));
|
|
|
|
|
- change.setDeviceId(deviceId);
|
|
|
|
|
- param.setData(JSONUtil.parseObj(change));
|
|
|
|
|
- ResultContent resultContent = openApiRequestService.sendIotSendMessage(param, deviceInfo.getProjectOid());
|
|
|
|
|
- if (resultContent.isSuccess()) {
|
|
|
|
|
-
|
|
|
|
|
- } else {
|
|
|
|
|
- log.error("设备权限通知失败 {} {}", deviceId, resultContent.getMsg());
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ List<DeviceInfo> deviceInfos = deviceInfoDao.findByDeviceIdIn(deviceIds);
|
|
|
|
|
+ if (ObjectUtils.isNotEmpty(deviceInfos)) {
|
|
|
|
|
+ // 按网关分组
|
|
|
|
|
+ HashMap<String, List<String>> map = new HashMap<>();
|
|
|
|
|
+ deviceInfos.stream().forEach(it -> {
|
|
|
|
|
+ String deviceId = it.getDeviceId();
|
|
|
|
|
+ String gateWayId = it.getGateWayId();
|
|
|
|
|
+ List<String> arr = List.of(gateWayId.split(","));
|
|
|
|
|
+ if (ObjectUtils.isNotEmpty(arr)) {
|
|
|
|
|
+ arr.stream().forEach(_gateWayId -> {
|
|
|
|
|
+ List<String> _list = map.get(_gateWayId);
|
|
|
|
|
+ if (ObjectUtils.isEmpty(_list)) {
|
|
|
|
|
+ _list = new ArrayList<>();
|
|
|
|
|
+ }
|
|
|
|
|
+ _list.add(deviceId);
|
|
|
|
|
+ map.put(_gateWayId, _list);
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ // 遍历发送
|
|
|
|
|
+ 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());
|
|
|
|
|
+
|
|
|
|
|
+ DeviceInfo deviceInfo = deviceInfoDao.findTopByDeviceId(subList.get(0));
|
|
|
|
|
+
|
|
|
|
|
+ IotSendParam param = new IotSendParam();
|
|
|
|
|
+ param.setGateWayId(gateWayId);
|
|
|
|
|
+ param.setFunctionType(FunctionType.Server);
|
|
|
|
|
+ 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());
|
|
|
|
|
+ }
|
|
|
|
|
+ if (!_deviceIds.isEmpty()) {
|
|
|
|
|
+ TimeUnit.SECONDS.sleep(10);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ throw new RuntimeException(e);
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|