fix 修复 用户绑定角色 与 角色绑定用户 异常 编写错误

dev
疯狂的狮子Li 4 years ago
parent 3ded50ca60
commit 487f18a930

@ -3,6 +3,8 @@ package com.ruoyi.system.mapper;
import com.ruoyi.common.mybatis.core.mapper.BaseMapperPlus; import com.ruoyi.common.mybatis.core.mapper.BaseMapperPlus;
import com.ruoyi.system.domain.SysUserRole; import com.ruoyi.system.domain.SysUserRole;
import java.util.List;
/** /**
* *
* *
@ -10,6 +12,6 @@ import com.ruoyi.system.domain.SysUserRole;
*/ */
public interface SysUserRoleMapper extends BaseMapperPlus<SysUserRoleMapper, SysUserRole, SysUserRole> { public interface SysUserRoleMapper extends BaseMapperPlus<SysUserRoleMapper, SysUserRole, SysUserRole> {
Long selectUserIdByRoleId(Long roleId); List<Long> selectUserIdsByRoleId(Long roleId);
} }

@ -115,11 +115,11 @@ public class SysUserServiceImpl implements ISysUserService {
*/ */
@Override @Override
public TableDataInfo<SysUser> selectUnallocatedList(SysUser user, PageQuery pageQuery) { public TableDataInfo<SysUser> selectUnallocatedList(SysUser user, PageQuery pageQuery) {
Long userId = userRoleMapper.selectUserIdByRoleId(user.getRoleId()); List<Long> userIds = userRoleMapper.selectUserIdsByRoleId(user.getRoleId());
QueryWrapper<SysUser> wrapper = Wrappers.query(); QueryWrapper<SysUser> wrapper = Wrappers.query();
wrapper.eq("u.del_flag", UserConstants.USER_NORMAL) wrapper.eq("u.del_flag", UserConstants.USER_NORMAL)
.and(w -> w.ne("r.role_id", user.getRoleId()).or().isNull("r.role_id")) .and(w -> w.ne("r.role_id", user.getRoleId()).or().isNull("r.role_id"))
.notIn("u.user_id", userId) .notIn("u.user_id", userIds)
.like(StringUtils.isNotBlank(user.getUserName()), "u.user_name", user.getUserName()) .like(StringUtils.isNotBlank(user.getUserName()), "u.user_name", user.getUserName())
.like(StringUtils.isNotBlank(user.getPhonenumber()), "u.phonenumber", user.getPhonenumber()); .like(StringUtils.isNotBlank(user.getPhonenumber()), "u.phonenumber", user.getPhonenumber());
Page<SysUser> page = baseMapper.selectUnallocatedList(pageQuery.build(), wrapper); Page<SysUser> page = baseMapper.selectUnallocatedList(pageQuery.build(), wrapper);

@ -9,7 +9,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<result property="roleId" column="role_id" /> <result property="roleId" column="role_id" />
</resultMap> </resultMap>
<select id="selectUserIdByRoleId" resultType="Long"> <select id="selectUserIdsByRoleId" resultType="Long">
select u.user_id from sys_user u select u.user_id from sys_user u
inner join sys_user_role ur inner join sys_user_role ur
on u.user_id = ur.user_id and ur.role_id = #{roleId} on u.user_id = ur.user_id and ur.role_id = #{roleId}

@ -1,117 +1,117 @@
<template> <template>
<div class="app-container"> <div class="app-container">
<h4 class="form-header h4">基本信息</h4> <h4 class="form-header h4">基本信息</h4>
<el-form ref="form" :model="form" label-width="80px"> <el-form ref="form" :model="form" label-width="80px">
<el-row> <el-row>
<el-col :span="8" :offset="2"> <el-col :span="8" :offset="2">
<el-form-item label="用户昵称" prop="nickName"> <el-form-item label="用户昵称" prop="nickName">
<el-input v-model="form.nickName" disabled /> <el-input v-model="form.nickName" disabled />
</el-form-item> </el-form-item>
</el-col> </el-col>
<el-col :span="8" :offset="2"> <el-col :span="8" :offset="2">
<el-form-item label="登录账号" prop="userName"> <el-form-item label="登录账号" prop="userName">
<el-input v-model="form.userName" disabled /> <el-input v-model="form.userName" disabled />
</el-form-item> </el-form-item>
</el-col> </el-col>
</el-row> </el-row>
</el-form> </el-form>
<h4 class="form-header h4">角色信息</h4> <h4 class="form-header h4">角色信息</h4>
<el-table v-loading="loading" :row-key="getRowKey" @row-click="clickRow" ref="table" @selection-change="handleSelectionChange" :data="roles.slice((pageNum-1)*pageSize,pageNum*pageSize)"> <el-table v-loading="loading" :row-key="getRowKey" @row-click="clickRow" ref="table" @selection-change="handleSelectionChange" :data="roles.slice((pageNum-1)*pageSize,pageNum*pageSize)">
<el-table-column label="序号" type="index" align="center"> <el-table-column label="序号" type="index" align="center">
<template slot-scope="scope"> <template slot-scope="scope">
<span>{{(pageNum - 1) * pageSize + scope.$index + 1}}</span> <span>{{(pageNum - 1) * pageSize + scope.$index + 1}}</span>
</template> </template>
</el-table-column> </el-table-column>
<el-table-column type="selection" :reserve-selection="true" width="55"></el-table-column> <el-table-column type="selection" :reserve-selection="true" width="55"></el-table-column>
<el-table-column label="角色编号" align="center" prop="roleId" /> <el-table-column label="角色编号" align="center" prop="roleId" />
<el-table-column label="角色名称" align="center" prop="roleName" /> <el-table-column label="角色名称" align="center" prop="roleName" />
<el-table-column label="权限字符" align="center" prop="roleKey" /> <el-table-column label="权限字符" align="center" prop="roleKey" />
<el-table-column label="创建时间" align="center" prop="createTime" width="180"> <el-table-column label="创建时间" align="center" prop="createTime" width="180">
<template slot-scope="scope"> <template slot-scope="scope">
<span>{{ parseTime(scope.row.createTime) }}</span> <span>{{ parseTime(scope.row.createTime) }}</span>
</template> </template>
</el-table-column> </el-table-column>
</el-table> </el-table>
<pagination v-show="total>0" :total="total" :page.sync="pageNum" :limit.sync="pageSize" /> <pagination v-show="total>0" :total="total" :page.sync="pageNum" :limit.sync="pageSize" />
<el-form label-width="100px"> <el-form label-width="100px">
<el-form-item style="text-align: center;margin-left:-120px;margin-top:30px;"> <el-form-item style="text-align: center;margin-left:-120px;margin-top:30px;">
<el-button type="primary" @click="submitForm()"></el-button> <el-button type="primary" @click="submitForm()"></el-button>
<el-button @click="close()"></el-button> <el-button @click="close()"></el-button>
</el-form-item> </el-form-item>
</el-form> </el-form>
</div> </div>
</template> </template>
<script> <script>
import { getAuthRole, updateAuthRole } from "@/api/system/user"; import { getAuthRole, updateAuthRole } from "@/api/system/user";
export default { export default {
name: "AuthRole", name: "AuthRole",
data() { data() {
return { return {
// //
loading: true, loading: true,
// //
total: 0, total: 0,
pageNum: 1, pageNum: 1,
pageSize: 10, pageSize: 10,
// //
roleIds:[], roleIds:[],
// //
roles: [], roles: [],
// //
form: {} form: {}
}; };
}, },
created() { created() {
const userId = this.$route.params && this.$route.params.userId; const userId = this.$route.params && this.$route.params.userId;
if (userId) { if (userId) {
this.loading = true; this.loading = true;
getAuthRole(userId).then((response) => { getAuthRole(userId).then((response) => {
this.form = response.user; this.form = response.data.user;
this.roles = response.roles; this.roles = response.data.roles;
this.total = this.roles.length; this.total = this.roles.length;
this.$nextTick(() => { this.$nextTick(() => {
this.roles.forEach((row) => { this.roles.forEach((row) => {
if (row.flag) { if (row.flag) {
this.$refs.table.toggleRowSelection(row); this.$refs.table.toggleRowSelection(row);
} }
}); });
}); });
this.loading = false; this.loading = false;
}); });
} }
}, },
methods: { methods: {
/** 单击选中行数据 */ /** 单击选中行数据 */
clickRow(row) { clickRow(row) {
this.$refs.table.toggleRowSelection(row); this.$refs.table.toggleRowSelection(row);
}, },
// //
handleSelectionChange(selection) { handleSelectionChange(selection) {
this.roleIds = selection.map((item) => item.roleId); this.roleIds = selection.map((item) => item.roleId);
}, },
// //
getRowKey(row) { getRowKey(row) {
return row.roleId; return row.roleId;
}, },
/** 提交按钮 */ /** 提交按钮 */
submitForm() { submitForm() {
const userId = this.form.userId; const userId = this.form.userId;
const roleIds = this.roleIds.join(","); const roleIds = this.roleIds.join(",");
updateAuthRole({ userId: userId, roleIds: roleIds }).then((response) => { updateAuthRole({ userId: userId, roleIds: roleIds }).then((response) => {
this.$modal.msgSuccess("授权成功"); this.$modal.msgSuccess("授权成功");
this.close(); this.close();
}); });
}, },
/** 关闭按钮 */ /** 关闭按钮 */
close() { close() {
const obj = { path: "/system/user" }; const obj = { path: "/system/user" };
this.$tab.closeOpenPage(obj); this.$tab.closeOpenPage(obj);
}, },
}, },
}; };
</script> </script>

Loading…
Cancel
Save