新增超级管理员租户切换功能
This commit is contained in:
@@ -106,13 +106,15 @@ public class OnlineController extends BaseController{
|
|||||||
map.put("startTimestamp", DateUtils.formatDateTime(session.getStartTimestamp()));
|
map.put("startTimestamp", DateUtils.formatDateTime(session.getStartTimestamp()));
|
||||||
map.put("lastAccessTime", DateUtils.formatDateTime(session.getLastAccessTime()));
|
map.put("lastAccessTime", DateUtils.formatDateTime(session.getLastAccessTime()));
|
||||||
map.put("timeout", TimeUtils.formatDateAgo(session.getTimeout()-(currentTime-session.getLastAccessTime().getTime())));
|
map.put("timeout", TimeUtils.formatDateAgo(session.getTimeout()-(currentTime-session.getLastAccessTime().getTime())));
|
||||||
PrincipalCollection pc = (PrincipalCollection)session.getAttribute(DefaultSubjectContext.PRINCIPALS_SESSION_KEY);
|
Object pc = session.getAttribute(DefaultSubjectContext.PRINCIPALS_SESSION_KEY);
|
||||||
LoginInfo principal = (pc != null ? (LoginInfo)pc.getPrimaryPrincipal() : null);
|
if (pc != null && pc instanceof PrincipalCollection){
|
||||||
if (principal != null){
|
LoginInfo loginInfo = (LoginInfo)((PrincipalCollection)pc).getPrimaryPrincipal();
|
||||||
|
if (loginInfo != null){
|
||||||
map.put("userCode", session.getAttribute("userCode"));// principal.getId());
|
map.put("userCode", session.getAttribute("userCode"));// principal.getId());
|
||||||
map.put("userName", session.getAttribute("userName"));// principal.getName());
|
map.put("userName", session.getAttribute("userName"));// principal.getName());
|
||||||
map.put("userType", session.getAttribute("userType"));// ObjectUtils.toString(principal.getParam("userType")));
|
map.put("userType", session.getAttribute("userType"));// ObjectUtils.toString(principal.getParam("userType")));
|
||||||
map.put("deviceType", ObjectUtils.toString(principal.getParam("deviceType")));
|
map.put("deviceType", ObjectUtils.toString(loginInfo.getParam("deviceType")));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
map.put("host", session.getHost());
|
map.put("host", session.getHost());
|
||||||
list.add(map);
|
list.add(map);
|
||||||
|
|||||||
@@ -4,21 +4,26 @@
|
|||||||
package com.jeesite.modules.sys.web.user;
|
package com.jeesite.modules.sys.web.user;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
|
||||||
import org.apache.shiro.authz.annotation.RequiresPermissions;
|
import org.apache.shiro.authz.annotation.RequiresPermissions;
|
||||||
|
import org.apache.shiro.session.Session;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||||
import org.springframework.stereotype.Controller;
|
import org.springframework.stereotype.Controller;
|
||||||
import org.springframework.ui.Model;
|
import org.springframework.ui.Model;
|
||||||
import org.springframework.validation.annotation.Validated;
|
import org.springframework.validation.annotation.Validated;
|
||||||
import org.springframework.web.bind.annotation.ModelAttribute;
|
import org.springframework.web.bind.annotation.ModelAttribute;
|
||||||
|
import org.springframework.web.bind.annotation.PathVariable;
|
||||||
import org.springframework.web.bind.annotation.PostMapping;
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
import org.springframework.web.bind.annotation.ResponseBody;
|
import org.springframework.web.bind.annotation.ResponseBody;
|
||||||
|
|
||||||
|
import com.jeesite.common.collect.ListUtils;
|
||||||
|
import com.jeesite.common.collect.MapUtils;
|
||||||
import com.jeesite.common.config.Global;
|
import com.jeesite.common.config.Global;
|
||||||
import com.jeesite.common.entity.Page;
|
import com.jeesite.common.entity.Page;
|
||||||
import com.jeesite.common.lang.StringUtils;
|
import com.jeesite.common.lang.StringUtils;
|
||||||
@@ -217,4 +222,54 @@ public class CorpAdminController extends BaseController {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询租户数据树格式
|
||||||
|
* @param pId 父级编码,默认 -1
|
||||||
|
* @param isShowCode 是否显示编码(true or 1:显示在左侧;2:显示在右侧;false or null:不显示)
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@RequiresPermissions("user")
|
||||||
|
@RequestMapping(value = "treeData")
|
||||||
|
@ResponseBody
|
||||||
|
public List<Map<String, Object>> treeData(String pId, String isShowCode) {
|
||||||
|
List<Map<String, Object>> mapList = ListUtils.newArrayList();
|
||||||
|
User where = new User();
|
||||||
|
List<User> list = userService.findCorpList(where);
|
||||||
|
for (int i = 0; i < list.size(); i++) {
|
||||||
|
User e = list.get(i);
|
||||||
|
Map<String, Object> map = MapUtils.newHashMap();
|
||||||
|
map.put("id", e.getCorpCode_());
|
||||||
|
map.put("pId", StringUtils.defaultIfBlank(pId, "-1"));
|
||||||
|
map.put("name", StringUtils.getTreeNodeName(isShowCode, e.getCorpCode_(), e.getCorpName_()));
|
||||||
|
mapList.add(map);
|
||||||
|
}
|
||||||
|
return mapList;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 切换租户
|
||||||
|
* @param user
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@RequiresPermissions("sys:corpAdmin:edit")
|
||||||
|
@RequestMapping(value = "switch/{corpCode}")
|
||||||
|
@ResponseBody
|
||||||
|
public String switchCorp(@PathVariable String corpCode) {
|
||||||
|
if (UserUtils.getUser().isSuperAdmin()){
|
||||||
|
User where = new User();
|
||||||
|
where.setCorpCode_(corpCode);
|
||||||
|
List<User> list = userService.findCorpList(where);
|
||||||
|
if (list.size() > 0){
|
||||||
|
Session session = UserUtils.getSession();
|
||||||
|
User user = list.get(0);
|
||||||
|
session.setAttribute("corpCode", user.getCorpCode_());
|
||||||
|
session.setAttribute("corpName", user.getCorpName_());
|
||||||
|
return renderResult(Global.TRUE, "租户切换成功!");
|
||||||
|
}else{
|
||||||
|
return renderResult(Global.TRUE, "租户切换失败,没有这个租户!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return renderResult(Global.FALSE, "租户切换失败,只有超级管理员才可以操作!");
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,28 @@
|
|||||||
|
<% if(@Global.getConfigToBoolean('user.useCorpModel', 'false') && user.superAdmin){ %>
|
||||||
|
<li>
|
||||||
|
<a href="javascript:" id="switchCorp">
|
||||||
|
<i class="fa icon-home"></i> 当前租户:(${session.corpCode}) ${session.corpName}
|
||||||
|
</a>
|
||||||
|
<div class="hide"><#form:treeselect id="switchCorpSelect" title="${text('租户切换')}" allowClear="false"
|
||||||
|
url="${ctx}/sys/corpAdmin/treeData?isShowCode=true" callbackFuncName="switchCorpSelectCallback"/>
|
||||||
|
</div>
|
||||||
|
<script>
|
||||||
|
$('#switchCorp').click(function(){
|
||||||
|
$('#switchCorpSelectButton').click();
|
||||||
|
});
|
||||||
|
function switchCorpSelectCallback(id, act, index, layero, nodes){
|
||||||
|
if (act == 'ok'){
|
||||||
|
var corpCode = $('#switchCorpSelectCode').val();
|
||||||
|
if (corpCode != ''){
|
||||||
|
js.ajaxSubmit("${ctx}/sys/corpAdmin/switch/"+corpCode, function(data){
|
||||||
|
js.showMessage(data.message);
|
||||||
|
top.location.reload();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
</li>
|
||||||
|
<% }else if(__info_type == '0'){ %>
|
||||||
|
<li><a href="http://jeesite.com" target="_blank"><i class="fa fa-diamond"></i> 官方网站</a></li>
|
||||||
|
<% } %>
|
||||||
@@ -13,7 +13,7 @@ jdbc:
|
|||||||
# Mysql 数据库配置
|
# Mysql 数据库配置
|
||||||
type: mysql
|
type: mysql
|
||||||
driver: com.mysql.jdbc.Driver
|
driver: com.mysql.jdbc.Driver
|
||||||
url: jdbc:mysql://127.0.0.1:3306/jeesite?useSSL=true&useUnicode=true&characterEncoding=utf-8&zeroDateTimeBehavior=convertToNull
|
url: jdbc:mysql://127.0.0.1:3306/jeesite?useSSL=false&useUnicode=true&characterEncoding=utf-8&zeroDateTimeBehavior=convertToNull
|
||||||
username: root
|
username: root
|
||||||
password: 123456
|
password: 123456
|
||||||
testSql: SELECT 1
|
testSql: SELECT 1
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ jdbc:
|
|||||||
# Mysql 数据库配置
|
# Mysql 数据库配置
|
||||||
type: mysql
|
type: mysql
|
||||||
driver: com.mysql.jdbc.Driver
|
driver: com.mysql.jdbc.Driver
|
||||||
url: jdbc:mysql://127.0.0.1:3306/jeesite?useSSL=true&useUnicode=true&characterEncoding=utf-8&zeroDateTimeBehavior=convertToNull
|
url: jdbc:mysql://127.0.0.1:3306/jeesite?useSSL=false&useUnicode=true&characterEncoding=utf-8&zeroDateTimeBehavior=convertToNull
|
||||||
username: root
|
username: root
|
||||||
password: 123456
|
password: 123456
|
||||||
testSql: SELECT 1
|
testSql: SELECT 1
|
||||||
@@ -107,7 +107,7 @@ jdbc:
|
|||||||
# ds2:
|
# ds2:
|
||||||
# type: mysql
|
# type: mysql
|
||||||
# driver: com.mysql.jdbc.Driver
|
# driver: com.mysql.jdbc.Driver
|
||||||
# url: jdbc:mysql://127.0.0.1:3306/jeesite2?useSSL=true&useUnicode=true&characterEncoding=utf-8&zeroDateTimeBehavior=convertToNull
|
# url: jdbc:mysql://127.0.0.1:3306/jeesite2?useSSL=false&useUnicode=true&characterEncoding=utf-8&zeroDateTimeBehavior=convertToNull
|
||||||
# username: root
|
# username: root
|
||||||
# password: 123456
|
# password: 123456
|
||||||
# testSql: SELECT 1
|
# testSql: SELECT 1
|
||||||
@@ -173,10 +173,10 @@ spring:
|
|||||||
|
|
||||||
# 管理基础路径
|
# 管理基础路径
|
||||||
#adminPath: /a
|
#adminPath: /a
|
||||||
#
|
|
||||||
# 前端基础路径
|
# 前端基础路径
|
||||||
#frontPath: /f
|
#frontPath: /f
|
||||||
#
|
|
||||||
# 分页配置
|
# 分页配置
|
||||||
#page:
|
#page:
|
||||||
#
|
#
|
||||||
|
|||||||
Reference in New Issue
Block a user