|
|
@@ -7,6 +7,7 @@ import com.zhongshu.iot.client.model.mqtt.GateWayUserInfoNameParam;
|
|
|
import com.zhongshu.iot.client.model.mqtt.GateWayUserInfoSearchParam;
|
|
|
import com.zhongshu.iot.client.type.type.MqttUserState;
|
|
|
import com.zhongshu.iot.server.core.dao.mqtt.*;
|
|
|
+import com.zhongshu.iot.server.core.dataConfig.MqttConfig;
|
|
|
import com.zhongshu.iot.server.core.domain.iot.mqtt.*;
|
|
|
import com.zhongshu.iot.server.core.util.CommonUtil;
|
|
|
import com.zhongshu.iot.server.core.util.DateUtils;
|
|
|
@@ -56,9 +57,26 @@ public class GateWayUserInfoService {
|
|
|
|
|
|
@Autowired
|
|
|
private GateWayMqttSecurityDao gateWayMqttSecurityDao;
|
|
|
+
|
|
|
@Autowired
|
|
|
private GateWay2DeviceDao gateWay2DeviceDao;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private GateWayInfoDao gateWayInfoDao;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 刷新系统所有的用户 和 用户权限数据
|
|
|
+ */
|
|
|
+ public void initData() {
|
|
|
+ log.info("GateWayUserInfoService initData");
|
|
|
+
|
|
|
+ initDefaultUser();
|
|
|
+
|
|
|
+ refreshAllGateWayUser();
|
|
|
+
|
|
|
+ refreshAllGateWaySecurity();
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 初始mqtt连接账号信息
|
|
|
*
|
|
|
@@ -69,8 +87,9 @@ public class GateWayUserInfoService {
|
|
|
GateWayUserInfo entity = gateWayUserInfoDao.findTopByUserName(userName);
|
|
|
if (ObjectUtils.isEmpty(entity)) {
|
|
|
GateWayUserInfoAddParam param = new GateWayUserInfoAddParam();
|
|
|
- param.setUserName("admin");
|
|
|
+ param.setUserName(userName);
|
|
|
param.setPassWord("admin123");
|
|
|
+ param.setRoleName(MqttConfig.adminRoleName);
|
|
|
addGateWayUser(param);
|
|
|
log.info(String.format("gateWayUser [%s] 初始化成功", userName));
|
|
|
} else {
|
|
|
@@ -234,6 +253,18 @@ public class GateWayUserInfoService {
|
|
|
return ResultContent.buildSuccess();
|
|
|
}
|
|
|
|
|
|
+ public ResultContent syncUserToMQTTService(List<GateWayUserInfo> gateWayUserInfoList) {
|
|
|
+ //todo同步用户
|
|
|
+ List<MqttInfo> list = mqttInfoDao.findAll();
|
|
|
+ log.info("syncUserToMQTTService {}", list.size());
|
|
|
+ if (ObjectUtils.isNotEmpty(list)) {
|
|
|
+ list.parallelStream().forEach(mqttInfo -> {
|
|
|
+ syncMqttUsers(mqttInfo, gateWayUserInfoList);
|
|
|
+ });
|
|
|
+ }
|
|
|
+ return ResultContent.buildSuccess();
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 同步多个用户
|
|
|
*
|
|
|
@@ -338,6 +369,18 @@ public class GateWayUserInfoService {
|
|
|
return ResultContent.buildSuccess();
|
|
|
}
|
|
|
|
|
|
+ public ResultContent syncSecurityToMQTTService(List<GateWayInfo> gateWayInfos) {
|
|
|
+ //todo同步权限
|
|
|
+ List<MqttInfo> list = mqttInfoDao.findAll();
|
|
|
+ log.info("syncSecurityToMQTTService {}", list.size());
|
|
|
+ if (ObjectUtils.isNotEmpty(list)) {
|
|
|
+ list.parallelStream().forEach(mqttInfo -> {
|
|
|
+ syncMqttSecuritySettings(mqttInfo, gateWayInfos);
|
|
|
+ });
|
|
|
+ }
|
|
|
+ return ResultContent.buildSuccess();
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 同步网关可监听的权限
|
|
|
*
|
|
|
@@ -393,11 +436,11 @@ public class GateWayUserInfoService {
|
|
|
gateWayMqttSecurity.setGateWayId(gateWayInfo.getGateWayId());
|
|
|
gateWayMqttSecurity.setMqttInfo(mqttInfo);
|
|
|
gateWayMqttSecurity.setMqttName(mqttInfo.getName());
|
|
|
+ gateWayMqttSecurity.setAddressMatch(addressMatch);
|
|
|
try {
|
|
|
- addressControl.addSecuritySettings(
|
|
|
- addressMatch,
|
|
|
- roleName, roleName, roleName, roleName, roleName, roleName, roleName,
|
|
|
- roleName, roleName, roleName);
|
|
|
+ if (!roleName.equals(MqttConfig.adminRoleName)) {
|
|
|
+ addressControl.addSecuritySettings(addressMatch, roleName, roleName, roleName, roleName, roleName, roleName, roleName, roleName, roleName, roleName);
|
|
|
+ }
|
|
|
gateWayMqttSecurity.setIsSync(Boolean.TRUE);
|
|
|
gateWayMqttSecurity.setMsg("同步成功");
|
|
|
} catch (Exception e) {
|
|
|
@@ -417,6 +460,32 @@ public class GateWayUserInfoService {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 同步所有的用户
|
|
|
+ *
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public ResultContent refreshAllGateWayUser() {
|
|
|
+ List<GateWayUserInfo> gateWayUserInfoList = gateWayUserInfoDao.findAll();
|
|
|
+ if (ObjectUtils.isNotEmpty(gateWayUserInfoList)) {
|
|
|
+ syncUserToMQTTService(gateWayUserInfoList);
|
|
|
+ }
|
|
|
+ return ResultContent.buildSuccess();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 同步所有的数据
|
|
|
+ *
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public ResultContent refreshAllGateWaySecurity() {
|
|
|
+ List<GateWayInfo> gateWayInfos = gateWayInfoDao.findAll();
|
|
|
+ if (ObjectUtils.isNotEmpty(gateWayInfos)) {
|
|
|
+ syncSecurityToMQTTService(gateWayInfos);
|
|
|
+ }
|
|
|
+ return ResultContent.buildSuccess();
|
|
|
+ }
|
|
|
+
|
|
|
//-----------------------------同步权限数据 end----------------------
|
|
|
|
|
|
/**
|