|
|
@@ -6,10 +6,7 @@ import com.zhongshu.iot.client.model.mqtt.*;
|
|
|
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.GateWay2User;
|
|
|
-import com.zhongshu.iot.server.core.domain.iot.mqtt.GateWayInfo;
|
|
|
-import com.zhongshu.iot.server.core.domain.iot.mqtt.GateWayUserInfo;
|
|
|
-import com.zhongshu.iot.server.core.domain.iot.mqtt.ProjectInfo;
|
|
|
+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;
|
|
|
import com.zhongshu.iot.server.core.util.bean.BeanUtils;
|
|
|
@@ -22,6 +19,8 @@ import org.springframework.data.domain.Page;
|
|
|
import org.springframework.data.domain.Pageable;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
+import java.util.Date;
|
|
|
+
|
|
|
/**
|
|
|
* 账号管理
|
|
|
*
|
|
|
@@ -62,6 +61,9 @@ public class GateWayUserInfoService {
|
|
|
@Autowired
|
|
|
private DeviceInfoDao deviceInfoDao;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private GateWayUserInfoTempDao gateWayUserInfoTempDao;
|
|
|
+
|
|
|
/**
|
|
|
* 刷新系统所有的用户 和 用户权限数据
|
|
|
*/
|
|
|
@@ -151,8 +153,40 @@ public class GateWayUserInfoService {
|
|
|
userParam.setUserName(userName);
|
|
|
userParam.setPassWord(CommonUtil.generateRandomString(16));
|
|
|
userParam.setRoleName(roleName);
|
|
|
+ userParam.setRemark(param.getRemark());
|
|
|
+
|
|
|
+ // 最大连接数
|
|
|
+ userParam.setNumber(number);
|
|
|
+ userParam.setProjectCode(param.getProjectCode());
|
|
|
+ ResultContent<GateWayUserInfo> resultContent = addGateWayUser(userParam);
|
|
|
+ if (resultContent.isFailed()) {
|
|
|
+ return ResultContent.buildFail(resultContent.getMsg());
|
|
|
+ }
|
|
|
+ return ResultContent.buildSuccess();
|
|
|
+ }
|
|
|
+
|
|
|
+ public ResultContent createUserByTemp(GateWayUserInfoParam param) {
|
|
|
+ Long number = param.getNumber();
|
|
|
+ if (number == null || number == 0) {
|
|
|
+ return ResultContent.buildFail("number不符合要求");
|
|
|
+ }
|
|
|
+ if (StringUtils.isEmpty(param.getTempId())) {
|
|
|
+ return ResultContent.buildFail("tempId不能为空");
|
|
|
+ }
|
|
|
+ GateWayUserInfoTemp temp = gateWayUserInfoTempDao.findTopById(param.getTempId());
|
|
|
+ if (ObjectUtils.isEmpty(temp)) {
|
|
|
+ return ResultContent.buildFail("tempId数据不存在");
|
|
|
+ }
|
|
|
+
|
|
|
+ GateWayUserInfoAddParam userParam = new GateWayUserInfoAddParam();
|
|
|
+ userParam.setUserName(temp.getUserName());
|
|
|
+ userParam.setPassWord(temp.getPassWord());
|
|
|
+ userParam.setRoleName(temp.getRoleName());
|
|
|
+ // 最大连接数
|
|
|
userParam.setNumber(number);
|
|
|
userParam.setProjectCode(param.getProjectCode());
|
|
|
+ userParam.setRemark(param.getRemark());
|
|
|
+
|
|
|
ResultContent<GateWayUserInfo> resultContent = addGateWayUser(userParam);
|
|
|
if (resultContent.isFailed()) {
|
|
|
return ResultContent.buildFail(resultContent.getMsg());
|
|
|
@@ -160,6 +194,21 @@ public class GateWayUserInfoService {
|
|
|
return ResultContent.buildSuccess();
|
|
|
}
|
|
|
|
|
|
+ public ResultContent<GateWayUserInfoTempModel> createTempUserCount() {
|
|
|
+ GateWayUserInfoTemp temp = new GateWayUserInfoTemp();
|
|
|
+ String userName = CommonUtil.generateRandomString(8);
|
|
|
+ String roleName = userName;
|
|
|
+ temp.setUserName(userName);
|
|
|
+ temp.setPassWord(CommonUtil.generateRandomString(16));
|
|
|
+ temp.setRoleName(roleName);
|
|
|
+ temp.setTtl(new Date(System.currentTimeMillis() + 60 * 1000));
|
|
|
+ gateWayUserInfoTempDao.save(temp);
|
|
|
+
|
|
|
+ GateWayUserInfoTempModel model = new GateWayUserInfoTempModel();
|
|
|
+ BeanUtils.copyProperties(temp, model);
|
|
|
+ return ResultContent.buildSuccess(model);
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 编辑用户信息
|
|
|
*
|
|
|
@@ -252,20 +301,24 @@ public class GateWayUserInfoService {
|
|
|
*/
|
|
|
public ResultContent updateBindNumber(GateWayUserInfo entity) {
|
|
|
if (ObjectUtils.isNotEmpty(entity)) {
|
|
|
- entity.setBindNumber(countBindNumber(entity));
|
|
|
- }
|
|
|
- return ResultContent.buildSuccess();
|
|
|
- }
|
|
|
-
|
|
|
- public long countBindNumber(GateWayUserInfo entity) {
|
|
|
- if (ObjectUtils.isNotEmpty(entity) && StringUtils.isNotEmpty(entity.getUserName())) {
|
|
|
// 网关数量
|
|
|
long gatewayNumber = gateWayInfoDao.countByMqttUserName(entity.getUserName());
|
|
|
// 设备数量
|
|
|
long deviceNumber = deviceInfoDao.countByMqttUserName(entity.getUserName());
|
|
|
- return gatewayNumber + deviceNumber;
|
|
|
+ long bindNumber = gatewayNumber + deviceNumber;
|
|
|
+ entity.setGatewayNumber(gatewayNumber);
|
|
|
+ entity.setDeviceNumber(deviceNumber);
|
|
|
+ entity.setBindNumber(bindNumber);
|
|
|
}
|
|
|
- return 0;
|
|
|
+ return ResultContent.buildSuccess();
|
|
|
+ }
|
|
|
+
|
|
|
+ public ResultContent updateBindNumber(String userName) {
|
|
|
+ if (StringUtils.isNotEmpty(userName)) {
|
|
|
+ GateWayUserInfo entity = gateWayUserInfoDao.findTopByUserName(userName);
|
|
|
+ updateBindNumber(entity);
|
|
|
+ }
|
|
|
+ return ResultContent.buildSuccess();
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -320,14 +373,30 @@ public class GateWayUserInfoService {
|
|
|
if (StringUtils.isNotEmpty(topic)) {
|
|
|
String[] arr = topic.split("/");
|
|
|
if (arr.length >= 2) {
|
|
|
- userName = arr[1];
|
|
|
+ userName = arr[2];
|
|
|
}
|
|
|
}
|
|
|
if (StringUtils.isEmpty(userName)) {
|
|
|
return ResultContent.buildFail("连接账号为空");
|
|
|
}
|
|
|
GateWayUserInfo entity = gateWayUserInfoDao.findTopByUserName(userName);
|
|
|
-
|
|
|
+ if (ObjectUtils.isEmpty(entity)) {
|
|
|
+ return ResultContent.buildFail("账号不存在");
|
|
|
+ }
|
|
|
+ if (entity.getState() != MqttUserState.Enable) {
|
|
|
+ return ResultContent.buildFail("账号不可用");
|
|
|
+ }
|
|
|
+ Long number = entity.getNumber();
|
|
|
+ Long bindNumber = entity.getBindNumber();
|
|
|
+ if (number == null) {
|
|
|
+ return ResultContent.buildFail("未设置最大连接数");
|
|
|
+ }
|
|
|
+ if (bindNumber == null) {
|
|
|
+ bindNumber = 0L;
|
|
|
+ }
|
|
|
+ if (bindNumber >= number) {
|
|
|
+ return ResultContent.buildFail("设备连接数已达最大");
|
|
|
+ }
|
|
|
return ResultContent.buildSuccess(entity);
|
|
|
}
|
|
|
|