|
@@ -3,6 +3,7 @@ package org.jeecg.modules.interlockUser.service.impl;
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
|
+import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import org.jeecg.common.api.vo.Result;
|
|
import org.jeecg.common.api.vo.Result;
|
|
import org.jeecg.common.util.oConvertUtils;
|
|
import org.jeecg.common.util.oConvertUtils;
|
|
@@ -110,46 +111,77 @@ public class InterlockUserServiceImpl extends ServiceImpl<InterlockUserMapper, I
|
|
SysUserRole userRole = new SysUserRole(userId, interlockUserAdd.getRoleId());
|
|
SysUserRole userRole = new SysUserRole(userId, interlockUserAdd.getRoleId());
|
|
sysUserRoleService.save(userRole);
|
|
sysUserRoleService.save(userRole);
|
|
|
|
|
|
- addSSOIoTEdgeUser(interlockUserAdd,interlockUser,eiToken);
|
|
|
|
|
|
+ int i = addSSOIoTEdgeUser(interlockUserAdd, interlockUser, eiToken);
|
|
|
|
+
|
|
|
|
+ if (i > 0){
|
|
|
|
+ this.removeById(interlockUser);
|
|
|
|
+ UpdateWrapper<InterlockSystemLimit> upQuery = new UpdateWrapper<>();
|
|
|
|
+ upQuery.eq("interlock_user_id",interlockUser.getId());
|
|
|
|
+ interlockSystemLimitService.remove(upQuery);
|
|
|
|
+ return Result.error("用户添加失败!");
|
|
|
|
+ }
|
|
|
|
|
|
|
|
|
|
return Result.OK("用户添加成功!");
|
|
return Result.OK("用户添加成功!");
|
|
}
|
|
}
|
|
|
|
|
|
- private void addSSOIoTEdgeUser(InterlockUserAdd interlockUserAdd, InterlockUser interlockUser, String eiToken) {
|
|
|
|
|
|
+ private int addSSOIoTEdgeUser(InterlockUserAdd interlockUserAdd, InterlockUser interlockUser, String eiToken) {
|
|
|
|
+ int count = 0;
|
|
try {
|
|
try {
|
|
restClientService.addSSOUser(interlockUserAdd.getUsername());
|
|
restClientService.addSSOUser(interlockUserAdd.getUsername());
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
log.info("SSO新增用户报错:{}",e.getMessage());
|
|
log.info("SSO新增用户报错:{}",e.getMessage());
|
|
} finally {
|
|
} finally {
|
|
- JSONObject jsonObject = restClientService.invitationSSOUserInIoTEdge(interlockUserAdd.getUsername(), eiToken);
|
|
|
|
- String code = (String) jsonObject.get("code");
|
|
|
|
- String iotUserId = (String) jsonObject.get("userId");
|
|
|
|
|
|
+ try {
|
|
|
|
+ JSONObject jsonObject = restClientService.invitationSSOUserInIoTEdge(interlockUserAdd.getUsername(), eiToken);
|
|
|
|
+ String code = (String) jsonObject.get("code");
|
|
|
|
+ String iotUserId = (String) jsonObject.get("userId");
|
|
|
|
|
|
- interlockUser.setIotUserid(iotUserId);
|
|
|
|
- this.updateById(interlockUser);
|
|
|
|
|
|
+ interlockUser.setIotUserid(iotUserId);
|
|
|
|
+ this.updateById(interlockUser);
|
|
|
|
|
|
- if (ObjectUtil.isNotNull(code)){
|
|
|
|
- log.info("IoTEdge邀请SSO用户失败: {}"+jsonObject.get("message").toString());
|
|
|
|
- }
|
|
|
|
- String rloe = "";
|
|
|
|
- if ("0".equals(interlockUserAdd.getRole())){
|
|
|
|
- rloe = "systemAdmin";
|
|
|
|
- restClientService.setUserRole(iotUserId,"",rloe,eiToken);
|
|
|
|
- }else {
|
|
|
|
- for (InterlockSystemLimit item : interlockUserAdd.getSystemLimitList()) {
|
|
|
|
- //InterlockBase base = baseService.getById(item.getId());
|
|
|
|
- if ("1".equals(interlockUserAdd.getRole()) && ObjectUtil.isNotNull(item.getLimitType()) && "0".equals(item.getLimitType())){
|
|
|
|
- rloe = "groupAdmin";
|
|
|
|
- restClientService.setUserRole(iotUserId,item.getIotedgeGroupId(),rloe,eiToken);
|
|
|
|
- }else if ("1".equals(interlockUserAdd.getRole()) && ObjectUtil.isNotNull(item.getLimitType()) && "1".equals(item.getLimitType())){
|
|
|
|
- rloe = "groupView";
|
|
|
|
- restClientService.setUserRole(iotUserId,item.getIotedgeGroupId(),rloe,eiToken);
|
|
|
|
|
|
+ if (ObjectUtil.isNotNull(code)){
|
|
|
|
+ log.info("IoTEdge邀请SSO用户失败: {}"+jsonObject.get("message").toString());
|
|
|
|
+ }
|
|
|
|
+ String rloe = "";
|
|
|
|
+ if ("0".equals(interlockUserAdd.getRole())){
|
|
|
|
+ rloe = "systemAdmin";
|
|
|
|
+ try {
|
|
|
|
+ restClientService.setUserRole(iotUserId,"",rloe,eiToken);
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ log.info("IoTEdge分配角色报错:{}",e.getMessage());
|
|
|
|
+ count++;
|
|
|
|
+ }
|
|
|
|
+ }else {
|
|
|
|
+ for (InterlockSystemLimit item : interlockUserAdd.getSystemLimitList()) {
|
|
|
|
+ //InterlockBase base = baseService.getById(item.getId());
|
|
|
|
+ if ("1".equals(interlockUserAdd.getRole()) && ObjectUtil.isNotNull(item.getLimitType()) && "0".equals(item.getLimitType())){
|
|
|
|
+ rloe = "groupAdmin";
|
|
|
|
+ try {
|
|
|
|
+ restClientService.setUserRole(iotUserId,item.getIotedgeGroupId(),rloe,eiToken);
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ log.info("IoTEdge分配角色报错:{}",e.getMessage());
|
|
|
|
+ count++;
|
|
|
|
+ }
|
|
|
|
+ }else if ("1".equals(interlockUserAdd.getRole()) && ObjectUtil.isNotNull(item.getLimitType()) && "1".equals(item.getLimitType())){
|
|
|
|
+ rloe = "groupView";
|
|
|
|
+ try {
|
|
|
|
+ restClientService.setUserRole(iotUserId,item.getIotedgeGroupId(),rloe,eiToken);
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ log.info("IoTEdge分配角色报错:{}",e.getMessage());
|
|
|
|
+ count++;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ log.info("IoTEdge邀请SSO用户报错:{}",e.getMessage());
|
|
|
|
+ count++;
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ return count;
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -348,4 +380,8 @@ public class InterlockUserServiceImpl extends ServiceImpl<InterlockUserMapper, I
|
|
return interlockUserMapper.getInterlockUserByUserName(wiseUser);
|
|
return interlockUserMapper.getInterlockUserByUserName(wiseUser);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ @Override
|
|
|
|
+ public int updateIotUserId(String userId, String iotUserId) {
|
|
|
|
+ return interlockUserMapper.updateIotUserId(userId, iotUserId);
|
|
|
|
+ }
|
|
}
|
|
}
|