给租户管理增加角色切换的功能
This commit is contained in:
@@ -73,6 +73,12 @@ public class RoleController {
|
||||
return roleService.allList();
|
||||
}
|
||||
|
||||
@GetMapping(value = "/tenantRoleList")
|
||||
@ApiOperation(value = "查询租户角色列表")
|
||||
public List<Role> tenantRoleList(HttpServletRequest request)throws Exception {
|
||||
return roleService.tenantRoleList();
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量设置状态-启用或者禁用
|
||||
* @param jsonObject
|
||||
|
||||
@@ -1,36 +1,21 @@
|
||||
package com.jsh.erp.controller;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.jsh.erp.constants.BusinessConstants;
|
||||
import com.jsh.erp.constants.ExceptionConstants;
|
||||
import com.jsh.erp.datasource.entities.Tenant;
|
||||
import com.jsh.erp.datasource.entities.User;
|
||||
import com.jsh.erp.datasource.entities.UserEx;
|
||||
import com.jsh.erp.datasource.vo.TreeNodeEx;
|
||||
import com.jsh.erp.exception.BusinessParamCheckingException;
|
||||
import com.jsh.erp.service.log.LogService;
|
||||
import com.jsh.erp.service.redis.RedisService;
|
||||
import com.jsh.erp.service.tenant.TenantService;
|
||||
import com.jsh.erp.service.user.UserService;
|
||||
import com.jsh.erp.utils.*;
|
||||
import com.jsh.erp.utils.ErpInfo;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.context.request.RequestContextHolder;
|
||||
import org.springframework.web.context.request.ServletRequestAttributes;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
import static com.jsh.erp.utils.ResponseJsonUtil.returnJson;
|
||||
|
||||
|
||||
@@ -8,6 +8,10 @@ public class TenantEx extends Tenant{
|
||||
|
||||
private Integer userCount;
|
||||
|
||||
private Long roleId;
|
||||
|
||||
private String roleName;
|
||||
|
||||
public String getCreateTimeStr() {
|
||||
return createTimeStr;
|
||||
}
|
||||
@@ -31,4 +35,20 @@ public class TenantEx extends Tenant{
|
||||
public void setUserCount(Integer userCount) {
|
||||
this.userCount = userCount;
|
||||
}
|
||||
|
||||
public Long getRoleId() {
|
||||
return roleId;
|
||||
}
|
||||
|
||||
public void setRoleId(Long roleId) {
|
||||
this.roleId = roleId;
|
||||
}
|
||||
|
||||
public String getRoleName() {
|
||||
return roleName;
|
||||
}
|
||||
|
||||
public void setRoleName(String roleName) {
|
||||
this.roleName = roleName;
|
||||
}
|
||||
}
|
||||
@@ -19,4 +19,6 @@ public interface UserBusinessMapperEx {
|
||||
List<UserBusiness> getBasicDataByKeyIdAndType(
|
||||
@Param("keyId") String keyId,
|
||||
@Param("type") String type);
|
||||
|
||||
void updateValueByTypeAndKeyId(@Param("type") String type, @Param("keyId") String keyId, @Param("ubValue") String ubValue);
|
||||
}
|
||||
|
||||
@@ -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{
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user