给租户管理增加角色切换的功能

This commit is contained in:
jishenghua
2024-12-23 00:34:03 +08:00
parent 6f294fad62
commit bd1d96b58d
12 changed files with 106 additions and 29 deletions

View File

@@ -39,6 +39,9 @@ public class RoleService {
@Resource
private UserService userService;
//超管的专用角色
private static Long MANAGE_ROLE_ID = 4L;
public Role getRole(long id)throws Exception {
Role result=null;
try{
@@ -75,6 +78,22 @@ public class RoleService {
return list;
}
public List<Role> tenantRoleList() {
List<Role> list=null;
try{
if(BusinessConstants.DEFAULT_MANAGER.equals(userService.getCurrentUser().getLoginName())) {
RoleExample example = new RoleExample();
example.createCriteria().andEnabledEqualTo(true).andTenantIdIsNull().andIdNotEqualTo(MANAGE_ROLE_ID)
.andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED);
example.setOrderByClause("sort asc, id asc");
list=roleMapper.selectByExample(example);
}
}catch(Exception e){
JshException.readFail(logger, e);
}
return list;
}
public List<RoleEx> select(String name, String description, int offset, int rows)throws Exception {
List<RoleEx> list=null;
try{

View File

@@ -2,12 +2,14 @@ package com.jsh.erp.service.tenant;
import com.alibaba.fastjson.JSONObject;
import com.jsh.erp.constants.BusinessConstants;
import com.jsh.erp.constants.ExceptionConstants;
import com.jsh.erp.datasource.entities.*;
import com.jsh.erp.datasource.entities.Tenant;
import com.jsh.erp.datasource.entities.TenantEx;
import com.jsh.erp.datasource.entities.TenantExample;
import com.jsh.erp.datasource.entities.UserEx;
import com.jsh.erp.datasource.mappers.TenantMapper;
import com.jsh.erp.datasource.mappers.TenantMapperEx;
import com.jsh.erp.datasource.mappers.UserBusinessMapperEx;
import com.jsh.erp.datasource.mappers.UserMapperEx;
import com.jsh.erp.exception.BusinessRunTimeException;
import com.jsh.erp.exception.JshException;
import com.jsh.erp.service.log.LogService;
import com.jsh.erp.service.user.UserService;
@@ -23,7 +25,8 @@ import org.springframework.web.context.request.ServletRequestAttributes;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.*;
import java.util.ArrayList;
import java.util.List;
@Service
public class TenantService {
@@ -38,6 +41,9 @@ public class TenantService {
@Resource
private UserMapperEx userMapperEx;
@Resource
private UserBusinessMapperEx userBusinessMapperEx;
@Resource
private UserService userService;
@@ -125,6 +131,11 @@ public class TenantService {
userMapperEx.disableUserByLimit(tenant.getTenantId());
}
result = tenantMapper.updateByPrimaryKeySelective(tenant);
//更新租户对应的角色
if(obj.get("roleId")!=null) {
String ubValue = "[" + obj.getString("roleId") + "]";
userBusinessMapperEx.updateValueByTypeAndKeyId("UserRole", tenant.getTenantId().toString(), ubValue);
}
}
}catch(Exception e){
JshException.writeFail(logger, e);