update 同步 ruoyi 对新业务进行修正

This commit is contained in:
疯狂的狮子li 2021-07-06 13:05:47 +08:00
parent aa14085746
commit 59114a14ff
8 changed files with 169 additions and 182 deletions

View File

@ -181,9 +181,7 @@ public class SysRoleController extends BaseController
@GetMapping("/authUser/allocatedList") @GetMapping("/authUser/allocatedList")
public TableDataInfo allocatedList(SysUser user) public TableDataInfo allocatedList(SysUser user)
{ {
startPage(); return userService.selectAllocatedList(user);
List<SysUser> list = userService.selectAllocatedList(user);
return getDataTable(list);
} }
/** /**
@ -193,9 +191,7 @@ public class SysRoleController extends BaseController
@GetMapping("/authUser/unallocatedList") @GetMapping("/authUser/unallocatedList")
public TableDataInfo unallocatedList(SysUser user) public TableDataInfo unallocatedList(SysUser user)
{ {
startPage(); return userService.selectUnallocatedList(user);
List<SysUser> list = userService.selectUnallocatedList(user);
return getDataTable(list);
} }
/** /**

View File

@ -204,12 +204,12 @@ public class SysUserController extends BaseController
@GetMapping("/authRole/{userId}") @GetMapping("/authRole/{userId}")
public AjaxResult authRole(@PathVariable("userId") Long userId) public AjaxResult authRole(@PathVariable("userId") Long userId)
{ {
AjaxResult ajax = AjaxResult.success();
SysUser user = userService.selectUserById(userId); SysUser user = userService.selectUserById(userId);
List<SysRole> roles = roleService.selectRolesByUserId(userId); List<SysRole> roles = roleService.selectRolesByUserId(userId);
Map<String, Object> ajax = new HashMap<>();
ajax.put("user", user); ajax.put("user", user);
ajax.put("roles", SysUser.isAdmin(userId) ? roles : roles.stream().filter(r -> !r.isAdmin()).collect(Collectors.toList())); ajax.put("roles", SysUser.isAdmin(userId) ? roles : roles.stream().filter(r -> !r.isAdmin()).collect(Collectors.toList()));
return ajax; return AjaxResult.success(ajax);
} }
/** /**

View File

@ -30,7 +30,7 @@ public interface SysUserMapper extends BaseMapperPlus<SysUser> {
* @param user 用户信息 * @param user 用户信息
* @return 用户信息集合信息 * @return 用户信息集合信息
*/ */
public List<SysUser> selectAllocatedList(SysUser user); public List<SysUser> selectAllocatedList(@Param("page") Page<SysUser> page, @Param("user") SysUser user);
/** /**
* 根据条件分页查询未分配用户角色列表 * 根据条件分页查询未分配用户角色列表
@ -38,7 +38,7 @@ public interface SysUserMapper extends BaseMapperPlus<SysUser> {
* @param user 用户信息 * @param user 用户信息
* @return 用户信息集合信息 * @return 用户信息集合信息
*/ */
public List<SysUser> selectUnallocatedList(SysUser user); public List<SysUser> selectUnallocatedList(@Param("page") Page<SysUser> page, @Param("user") SysUser user);
/** /**
* 通过用户名查询用户 * 通过用户名查询用户

View File

@ -30,7 +30,7 @@ public interface ISysUserService extends IServicePlus<SysUser> {
* @param user 用户信息 * @param user 用户信息
* @return 用户信息集合信息 * @return 用户信息集合信息
*/ */
public List<SysUser> selectAllocatedList(SysUser user); public TableDataInfo<SysUser> selectAllocatedList(SysUser user);
/** /**
* 根据条件分页查询未分配用户角色列表 * 根据条件分页查询未分配用户角色列表
@ -38,7 +38,7 @@ public interface ISysUserService extends IServicePlus<SysUser> {
* @param user 用户信息 * @param user 用户信息
* @return 用户信息集合信息 * @return 用户信息集合信息
*/ */
public List<SysUser> selectUnallocatedList(SysUser user); public TableDataInfo<SysUser> selectUnallocatedList(SysUser user);
/** /**
* 通过用户名查询用户 * 通过用户名查询用户

View File

@ -66,16 +66,12 @@ public class SysRoleServiceImpl extends ServicePlusImpl<SysRoleMapper, SysRole>
* @return 角色列表 * @return 角色列表
*/ */
@Override @Override
public List<SysRole> selectRolesByUserId(Long userId) public List<SysRole> selectRolesByUserId(Long userId) {
{ List<SysRole> userRoles = baseMapper.selectRolePermissionByUserId(userId);
List<SysRole> userRoles = roleMapper.selectRolePermissionByUserId(userId);
List<SysRole> roles = selectRoleAll(); List<SysRole> roles = selectRoleAll();
for (SysRole role : roles) for (SysRole role : roles) {
{ for (SysRole userRole : userRoles) {
for (SysRole userRole : userRoles) if (role.getRoleId().longValue() == userRole.getRoleId().longValue()) {
{
if (role.getRoleId().longValue() == userRole.getRoleId().longValue())
{
role.setFlag(true); role.setFlag(true);
break; break;
} }
@ -338,9 +334,10 @@ public class SysRoleServiceImpl extends ServicePlusImpl<SysRoleMapper, SysRole>
* @return 结果 * @return 结果
*/ */
@Override @Override
public int deleteAuthUser(SysUserRole userRole) public int deleteAuthUser(SysUserRole userRole) {
{ return userRoleMapper.delete(new LambdaQueryWrapper<SysUserRole>()
return userRoleMapper.deleteUserRoleInfo(userRole); .eq(SysUserRole::getRoleId, userRole.getRoleId())
.eq(SysUserRole::getUserId, userRole.getUserId()));
} }
/** /**
@ -351,9 +348,10 @@ public class SysRoleServiceImpl extends ServicePlusImpl<SysRoleMapper, SysRole>
* @return 结果 * @return 结果
*/ */
@Override @Override
public int deleteAuthUsers(Long roleId, Long[] userIds) public int deleteAuthUsers(Long roleId, Long[] userIds) {
{ return userRoleMapper.delete(new LambdaQueryWrapper<SysUserRole>()
return userRoleMapper.deleteUserRoleInfos(roleId, userIds); .eq(SysUserRole::getRoleId, roleId)
.in(SysUserRole::getUserId, Arrays.asList(userIds)));
} }
/** /**
@ -364,17 +362,15 @@ public class SysRoleServiceImpl extends ServicePlusImpl<SysRoleMapper, SysRole>
* @return 结果 * @return 结果
*/ */
@Override @Override
public int insertAuthUsers(Long roleId, Long[] userIds) public int insertAuthUsers(Long roleId, Long[] userIds) {
{
// 新增用户与角色管理 // 新增用户与角色管理
List<SysUserRole> list = new ArrayList<SysUserRole>(); List<SysUserRole> list = new ArrayList<SysUserRole>();
for (Long userId : userIds) for (Long userId : userIds) {
{
SysUserRole ur = new SysUserRole(); SysUserRole ur = new SysUserRole();
ur.setUserId(userId); ur.setUserId(userId);
ur.setRoleId(roleId); ur.setRoleId(roleId);
list.add(ur); list.add(ur);
} }
return userRoleMapper.batchUserRole(list); return userRoleMapper.insertAll(list);
} }
} }

View File

@ -76,10 +76,9 @@ public class SysUserServiceImpl extends ServicePlusImpl<SysUserMapper, SysUser>
* @return 用户信息集合信息 * @return 用户信息集合信息
*/ */
@Override @Override
@DataScope(deptAlias = "d", userAlias = "u") @DataScope(deptAlias = "d", userAlias = "u", isUser = true)
public List<SysUser> selectAllocatedList(SysUser user) public TableDataInfo<SysUser> selectAllocatedList(SysUser user) {
{ return PageUtils.buildDataInfo(baseMapper.selectAllocatedList(PageUtils.buildPage(), user));
return userMapper.selectAllocatedList(user);
} }
/** /**
@ -89,10 +88,9 @@ public class SysUserServiceImpl extends ServicePlusImpl<SysUserMapper, SysUser>
* @return 用户信息集合信息 * @return 用户信息集合信息
*/ */
@Override @Override
@DataScope(deptAlias = "d", userAlias = "u") @DataScope(deptAlias = "d", userAlias = "u", isUser = true)
public List<SysUser> selectUnallocatedList(SysUser user) public TableDataInfo<SysUser> selectUnallocatedList(SysUser user) {
{ return PageUtils.buildDataInfo(baseMapper.selectUnallocatedList(PageUtils.buildPage(), user));
return userMapper.selectUnallocatedList(user);
} }
/** /**
@ -266,7 +264,8 @@ public class SysUserServiceImpl extends ServicePlusImpl<SysUserMapper, SysUser>
@Override @Override
public void insertUserAuth(Long userId, Long[] roleIds) public void insertUserAuth(Long userId, Long[] roleIds)
{ {
userRoleMapper.deleteUserRoleByUserId(userId); userRoleMapper.delete(new LambdaQueryWrapper<SysUserRole>()
.eq(SysUserRole::getUserId, userId));
insertUserRole(userId, roleIds); insertUserRole(userId, roleIds);
} }
@ -383,22 +382,18 @@ public class SysUserServiceImpl extends ServicePlusImpl<SysUserMapper, SysUser>
* @param userId 用户ID * @param userId 用户ID
* @param roleIds 角色组 * @param roleIds 角色组
*/ */
public void insertUserRole(Long userId, Long[] roleIds) public void insertUserRole(Long userId, Long[] roleIds) {
{ if (Validator.isNotNull(roleIds)) {
if (StringUtils.isNotNull(roleIds))
{
// 新增用户与角色管理 // 新增用户与角色管理
List<SysUserRole> list = new ArrayList<SysUserRole>(); List<SysUserRole> list = new ArrayList<SysUserRole>();
for (Long roleId : roleIds) for (Long roleId : roleIds) {
{
SysUserRole ur = new SysUserRole(); SysUserRole ur = new SysUserRole();
ur.setUserId(userId); ur.setUserId(userId);
ur.setRoleId(roleId); ur.setRoleId(roleId);
list.add(ur); list.add(ur);
} }
if (list.size() > 0) if (list.size() > 0) {
{ userRoleMapper.insertAll(list);
userRoleMapper.batchUserRole(list);
} }
} }
} }

View File

@ -148,16 +148,16 @@
left join sys_dept d on u.dept_id = d.dept_id left join sys_dept d on u.dept_id = d.dept_id
left join sys_user_role ur on u.user_id = ur.user_id left join sys_user_role ur on u.user_id = ur.user_id
left join sys_role r on r.role_id = ur.role_id left join sys_role r on r.role_id = ur.role_id
where u.del_flag = '0' and r.role_id = #{roleId} where u.del_flag = '0' and r.role_id = #{user.roleId}
<if test="userName != null and userName != ''"> <if test="user.userName != null and user.userName != ''">
AND u.user_name like concat('%', #{userName}, '%') AND u.user_name like concat('%', #{user.userName}, '%')
</if> </if>
<if test="phonenumber != null and phonenumber != ''"> <if test="user.phonenumber != null and user.phonenumber != ''">
AND u.phonenumber like concat('%', #{phonenumber}, '%') AND u.phonenumber like concat('%', #{user.phonenumber}, '%')
</if> </if>
<!-- 数据范围过滤 --> <!-- 数据范围过滤 -->
<if test="params.dataScope != null and params.dataScope != ''"> <if test="user.params.dataScope != null and user.params.dataScope != ''">
AND ( ${params.dataScope} ) AND ( ${user.params.dataScope} )
</if> </if>
</select> </select>
@ -167,17 +167,17 @@
left join sys_dept d on u.dept_id = d.dept_id left join sys_dept d on u.dept_id = d.dept_id
left join sys_user_role ur on u.user_id = ur.user_id left join sys_user_role ur on u.user_id = ur.user_id
left join sys_role r on r.role_id = ur.role_id left join sys_role r on r.role_id = ur.role_id
where u.del_flag = '0' and (r.role_id != #{roleId} or r.role_id IS NULL) where u.del_flag = '0' and (r.role_id != #{user.roleId} or r.role_id IS NULL)
and u.user_id not in (select u.user_id from sys_user u inner join sys_user_role ur on u.user_id = ur.user_id and ur.role_id = #{roleId}) and u.user_id not in (select u.user_id from sys_user u inner join sys_user_role ur on u.user_id = ur.user_id and ur.role_id = #{user.roleId})
<if test="userName != null and userName != ''"> <if test="user.userName != null and user.userName != ''">
AND u.user_name like concat('%', #{userName}, '%') AND u.user_name like concat('%', #{user.userName}, '%')
</if> </if>
<if test="phonenumber != null and phonenumber != ''"> <if test="user.phonenumber != null and user.phonenumber != ''">
AND u.phonenumber like concat('%', #{phonenumber}, '%') AND u.phonenumber like concat('%', #{user.phonenumber}, '%')
</if> </if>
<!-- 数据范围过滤 --> <!-- 数据范围过滤 -->
<if test="params.dataScope != null and params.dataScope != ''"> <if test="user.params.dataScope != null and user.params.dataScope != ''">
AND ( ${params.dataScope} ) AND ( ${user.params.dataScope} )
</if> </if>
</select> </select>

View File

@ -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="phonenumber"> <el-form-item label="登录账号" prop="phonenumber">
<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.msgSuccess("授权成功"); this.msgSuccess("授权成功");
this.close(); this.close();
}); });
}, },
/** 关闭按钮 */ /** 关闭按钮 */
close() { close() {
this.$store.dispatch("tagsView/delView", this.$route); this.$store.dispatch("tagsView/delView", this.$route);
this.$router.push({ path: "/system/user" }); this.$router.push({ path: "/system/user" });
}, },
}, },
}; };
</script> </script>