给租户管理增加角色切换的功能
This commit is contained in:
parent
6f294fad62
commit
bd1d96b58d
@ -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);
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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>
|
||||
@ -12,6 +12,7 @@ const addRole = (params)=>postAction("/role/add",params);
|
||||
const editRole = (params)=>putAction("/role/update",params);
|
||||
const checkRole = (params)=>getAction("/role/checkIsNameExist",params);
|
||||
const roleAllList = (params)=>getAction("/role/allList",params);
|
||||
const getTenantRoleList = (params)=>getAction("/role/tenantRoleList",params);
|
||||
//用户管理
|
||||
const registerUser = (params)=>postAction("/user/registerUser",params);
|
||||
const addUser = (params)=>postAction("/user/addUser",params);
|
||||
@ -124,6 +125,7 @@ export {
|
||||
editRole,
|
||||
checkRole,
|
||||
roleAllList,
|
||||
getTenantRoleList,
|
||||
registerUser,
|
||||
addUser,
|
||||
editUser,
|
||||
|
||||
@ -138,6 +138,7 @@
|
||||
{ title: '租户类型',dataIndex: 'type',width:60,align:"center",
|
||||
scopedSlots: { customRender: 'customRenderType' }
|
||||
},
|
||||
{ title: '租户角色', dataIndex: 'roleName', width: 80, align: "center"},
|
||||
{ title: '租户状态',dataIndex: 'enabled',width:60,align:"center",
|
||||
scopedSlots: { customRender: 'customRenderEnabled' }
|
||||
},
|
||||
|
||||
@ -30,6 +30,13 @@
|
||||
<a-select-option value="1">付费租户</a-select-option>
|
||||
</a-select>
|
||||
</a-form-item>
|
||||
<a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="租户角色" v-if="model.id">
|
||||
<a-select style="width:100%" placeholder="请选择租户角色" v-decorator.trim="[ 'roleId' ]">
|
||||
<a-select-option v-for="(item,index) in tenantRoleList" :key="index" :value="item.id">
|
||||
{{ item.name }}
|
||||
</a-select-option>
|
||||
</a-select>
|
||||
</a-form-item>
|
||||
<a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="到期时间">
|
||||
<j-date style="width:100%" placeholder="请选择到期时间" v-decorator.trim="[ 'expireTime' ]" :show-time="true"/>
|
||||
</a-form-item>
|
||||
@ -44,7 +51,7 @@
|
||||
<script>
|
||||
import pick from 'lodash.pick'
|
||||
import {mixinDevice} from '@/utils/mixin'
|
||||
import {addTenant,editTenant,checkTenant } from '@/api/api'
|
||||
import {addTenant,editTenant,checkTenant, getTenantRoleList } from '@/api/api'
|
||||
import JDate from '@/components/jeecg/JDate'
|
||||
import md5 from 'md5'
|
||||
export default {
|
||||
@ -58,6 +65,7 @@
|
||||
title:"操作",
|
||||
visible: false,
|
||||
model: {},
|
||||
tenantRoleList: [], //租户角色列表
|
||||
labelCol: {
|
||||
xs: { span: 24 },
|
||||
sm: { span: 5 },
|
||||
@ -91,8 +99,16 @@
|
||||
this.model.expireTime = this.model.expireTimeStr
|
||||
this.visible = true;
|
||||
this.$nextTick(() => {
|
||||
this.form.setFieldsValue(pick(this.model,'loginName', 'userNumLimit', 'type', 'expireTime', 'remark'))
|
||||
});
|
||||
this.form.setFieldsValue(pick(this.model,'loginName', 'userNumLimit', 'type', 'roleId', 'expireTime', 'remark'))
|
||||
})
|
||||
this.getTenantRoleList()
|
||||
},
|
||||
getTenantRoleList() {
|
||||
getTenantRoleList().then((res)=>{
|
||||
if(res) {
|
||||
this.tenantRoleList = res
|
||||
}
|
||||
})
|
||||
},
|
||||
close () {
|
||||
this.$emit('close');
|
||||
|
||||
@ -30,12 +30,12 @@
|
||||
<a-input placeholder="请输入用户姓名" v-decorator.trim="[ 'username', validatorRules.username]" />
|
||||
</a-form-item>
|
||||
<a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="角色">
|
||||
<a-select v-if="model.roleName!='租户'" placeholder="选择角色" v-decorator="[ 'roleId', validatorRules.roleId]" :dropdownMatchSelectWidth="false">
|
||||
<a-select v-if="model.id!==model.tenantId" placeholder="选择角色" v-decorator="[ 'roleId', validatorRules.roleId]" :dropdownMatchSelectWidth="false">
|
||||
<a-select-option v-for="(item,index) in roleList" :key="index" :value="item.id">
|
||||
{{ item.name }}
|
||||
</a-select-option>
|
||||
</a-select>
|
||||
<a-col v-if="model.roleName=='租户'"><a-row>租户</a-row></a-col>
|
||||
<a-col v-if="model.id===model.tenantId"><a-row>{{ tenantRoleName }}</a-row></a-col>
|
||||
</a-form-item>
|
||||
<a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="机构">
|
||||
<a-tree-select style="width:100%" :dropdownStyle="{maxHeight:'200px',overflow:'auto'}" allow-clear
|
||||
@ -95,6 +95,7 @@
|
||||
orgaTree: [],
|
||||
roleList: [],
|
||||
userId:"", //保存用户id
|
||||
tenantRoleName: '', //租户的角色名称
|
||||
isReadOnly: false,
|
||||
disableSubmit:false,
|
||||
dateFormat:"YYYY-MM-DD",
|
||||
@ -148,6 +149,7 @@
|
||||
this.$nextTick(() => {
|
||||
this.form.setFieldsValue(pick(this.model,'loginName','username','roleId','orgaId','position','leaderFlag',
|
||||
'phonenum','email','userBlngOrgaDsplSeq','description'))
|
||||
this.tenantRoleName = this.model.roleName
|
||||
autoJumpNextInput('userModal')
|
||||
});
|
||||
},
|
||||
|
||||
Loading…
Reference in New Issue
Block a user