|
|
@@ -3,7 +3,9 @@ package com.zhongshu.iot.server.core.service.mqtt;
|
|
|
import com.github.microservice.models.type.CommonState;
|
|
|
import com.zhongshu.iot.client.model.mqtt.MqttInfoAddParam;
|
|
|
import com.zhongshu.iot.client.model.mqtt.MqttInfoModel;
|
|
|
+import com.zhongshu.iot.client.model.mqtt.MqttInfoReturnModel;
|
|
|
import com.zhongshu.iot.client.model.mqtt.MqttInfoSimpleModel;
|
|
|
+import com.zhongshu.iot.client.type.type.AddressType;
|
|
|
import com.zhongshu.iot.server.core.dao.mqtt.Mqtt2UserDao;
|
|
|
import com.zhongshu.iot.server.core.dao.mqtt.MqttInfoDao;
|
|
|
import com.zhongshu.iot.server.core.domain.iot.mqtt.MqttInfo;
|
|
|
@@ -15,6 +17,7 @@ import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
+import javax.annotation.PostConstruct;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
|
import java.util.stream.Collectors;
|
|
|
@@ -26,11 +29,44 @@ import java.util.stream.Collectors;
|
|
|
@Service
|
|
|
@Slf4j
|
|
|
public class MqttInfoService {
|
|
|
+
|
|
|
@Autowired
|
|
|
- MqttInfoDao mqttInfoDao;
|
|
|
+ private MqttInfoDao mqttInfoDao;
|
|
|
|
|
|
@Autowired
|
|
|
- Mqtt2UserDao mqtt2UserDao;
|
|
|
+ private Mqtt2UserDao mqtt2UserDao;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 初始数据
|
|
|
+ */
|
|
|
+ @PostConstruct
|
|
|
+ public void initMqttInfo() {
|
|
|
+ log.info("PostConstruct initMqttInfo");
|
|
|
+ MqttInfo mqttInfo = mqttInfoDao.findTopByAddress(AddressType.Common);
|
|
|
+ if (ObjectUtils.isEmpty(mqttInfo)) {
|
|
|
+ mqttInfo = new MqttInfo();
|
|
|
+ mqttInfo.setName("默认MQTT服务");
|
|
|
+ mqttInfo.setBrokerHost("wss://mq.dev.zswllife.cn");
|
|
|
+ mqttInfo.setBrokerPort("443/mqtt");
|
|
|
+ mqttInfo.setUserName("admin");
|
|
|
+ mqttInfo.setPassword("admin123");
|
|
|
+ mqttInfo.setAddress(AddressType.Common);
|
|
|
+ mqttInfo.setState(CommonState.Enable);
|
|
|
+ mqttInfo.setBrokerName("broker1");
|
|
|
+ mqttInfoDao.save(mqttInfo);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public MqttInfoReturnModel getCommonMqttInfo() {
|
|
|
+ MqttInfoReturnModel mqttInfoSimpleModel = new MqttInfoReturnModel();
|
|
|
+ MqttInfo mqttInfo = mqttInfoDao.findTopByAddress(AddressType.Common);
|
|
|
+ if (ObjectUtils.isNotEmpty(mqttInfo)) {
|
|
|
+ mqttInfoSimpleModel.setBrokerAddress(String.format(":", mqttInfo.getBrokerHost(), mqttInfo.getBrokerPort()));
|
|
|
+ mqttInfoSimpleModel.setBrokerUsername(mqttInfo.getUserName());
|
|
|
+ mqttInfoSimpleModel.setBrokerPassword(mqttInfo.getPassword());
|
|
|
+ }
|
|
|
+ return mqttInfoSimpleModel;
|
|
|
+ }
|
|
|
|
|
|
/**
|
|
|
* 添加/编辑MQTT地址
|