|
|
@@ -6,11 +6,14 @@ import com.github.microservice.dataConfig.IotTtlConfig;
|
|
|
import com.github.microservice.deviceTopicConfig.IotTopIcConfig;
|
|
|
import com.github.microservice.models.iotDeviceData.IotDeviceDataSimpleModel;
|
|
|
import com.github.microservice.net.ResultContent;
|
|
|
+import com.github.microservice.types.deviceUse.OnLineState;
|
|
|
import com.zhongshu.iot.server.core.dao.mqtt.DeviceInfoDao;
|
|
|
import com.zhongshu.iot.server.core.domain.iot.IotDeviceData;
|
|
|
import com.zhongshu.iot.server.core.domain.iot.IotMain;
|
|
|
+import com.zhongshu.iot.server.core.domain.iot.device.DeviceInfo;
|
|
|
import com.zhongshu.iot.server.core.domain.iot.message.OperationMessageResult;
|
|
|
import com.zhongshu.iot.server.core.service.device.GateWayManagerService;
|
|
|
+import com.zhongshu.iot.server.core.util.CommonUtil;
|
|
|
import com.zhongshu.iot.server.core.util.DateUtils;
|
|
|
import com.zhongshu.iot.server.core.util.mqtt.mqttConfig.client.MQClient;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
@@ -25,17 +28,11 @@ import org.springframework.stereotype.Service;
|
|
|
*/
|
|
|
@Slf4j
|
|
|
@Service
|
|
|
-public class IotFreshService {
|
|
|
+public class IotReFreshPageService {
|
|
|
|
|
|
@Autowired
|
|
|
private MQClient mqClient;
|
|
|
|
|
|
- @Autowired
|
|
|
- private DeviceInfoDao deviceInfoDao;
|
|
|
-
|
|
|
- @Autowired
|
|
|
- private GateWayManagerService gateWayManagerService;
|
|
|
-
|
|
|
@Autowired
|
|
|
private IotDeviceDataService iotDeviceDataService;
|
|
|
|
|
|
@@ -108,4 +105,28 @@ public class IotFreshService {
|
|
|
return ResultContent.buildSuccess();
|
|
|
}
|
|
|
|
|
|
+ public ResultContent sendDeviceOnLineChange(DeviceInfo deviceInfo, OnLineState onLineState) {
|
|
|
+ if (deviceInfo == null) {
|
|
|
+ return ResultContent.buildFail("设备信息为空");
|
|
|
+ }
|
|
|
+ String deviceId = deviceInfo.getDeviceId();
|
|
|
+ // 发送通知页面消息
|
|
|
+ String topicDevice = String.format(IotTopIcConfig.deviceOnLineChange, deviceId);
|
|
|
+
|
|
|
+ String messageId = CommonUtil.UUID();
|
|
|
+ JSONObject data = new JSONObject();
|
|
|
+ data.set("deviceId", deviceId);
|
|
|
+ data.set("onLineState", onLineState);
|
|
|
+
|
|
|
+ JSONObject jsonObject = new JSONObject();
|
|
|
+ jsonObject.set("id", messageId);
|
|
|
+ jsonObject.set("data", data);
|
|
|
+ jsonObject.set("timeStr", DateUtils.paresTime(System.currentTimeMillis(), DateUtils.patternyyyySSS));
|
|
|
+ jsonObject.set("time", System.currentTimeMillis());
|
|
|
+ jsonObject.set("ttl", IotTtlConfig.MQTT_TIME_OUT_TTL);
|
|
|
+ jsonObject.set("issued", Boolean.TRUE);
|
|
|
+ mqClient.sendObject(topicDevice, JSONUtil.toJsonStr(jsonObject), messageId);
|
|
|
+ return ResultContent.buildSuccess();
|
|
|
+ }
|
|
|
+
|
|
|
}
|