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

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

@@ -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

View File

@@ -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;

View File

@@ -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;
}
}

View File

@@ -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);
}

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);

View File

@@ -3,11 +3,19 @@
<mapper namespace="com.jsh.erp.datasource.mappers.TenantMapperEx">
<resultMap extends="com.jsh.erp.datasource.mappers.LogMapper.BaseResultMap" id="ResultMapEx" type="com.jsh.erp.datasource.entities.TenantEx">
<result column="roleId" jdbcType="VARCHAR" property="roleId" />
<result column="roleName" jdbcType="VARCHAR" property="roleName" />
<result column="userCount" jdbcType="VARCHAR" property="userCount" />
</resultMap>
<select id="selectByConditionTenant" parameterType="com.jsh.erp.datasource.entities.TenantExample" resultMap="ResultMapEx">
select jsh_tenant.*,
(select r.id from jsh_user_business ub
left join jsh_role r on ub.value=concat("[",r.id,"]") and ifnull(r.delete_flag,'0') !='1'
where ub.type='UserRole' and ub.key_id=jsh_tenant.tenant_id limit 0,1) roleId,
(select r.name from jsh_user_business ub
left join jsh_role r on ub.value=concat("[",r.id,"]") and ifnull(r.delete_flag,'0') !='1'
where ub.type='UserRole' and ub.key_id=jsh_tenant.tenant_id limit 0,1) roleName,
(select count(jsh_user.id) from jsh_user where jsh_user.status='0' and jsh_user.delete_flag=0 and jsh_user.tenant_id=jsh_tenant.tenant_id) userCount
FROM jsh_tenant
where 1=1

View File

@@ -18,4 +18,9 @@
and ifnull(delete_flag,'0') !='1'
</select>
<update id="updateValueByTypeAndKeyId">
update jsh_user_business
set value= #{ubValue}
where type = #{type} and key_id = #{keyId}
</update>
</mapper>