物资管理员,仓库管理员权限优化,用户必须先为物资管理员才可为仓库管理员

main
15036302109 7 months ago
parent 71a7347ea9
commit 750490c106

@ -1,18 +1,5 @@
package com.ruoyi.web.controller.system;
import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
@ -30,6 +17,16 @@ import com.ruoyi.system.domain.SysUserRole;
import com.ruoyi.system.service.ISysDeptService;
import com.ruoyi.system.service.ISysRoleService;
import com.ruoyi.system.service.ISysUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletResponse;
import java.util.Arrays;
import java.util.List;
import java.util.StringJoiner;
import java.util.stream.Collectors;
/**
*
@ -244,6 +241,23 @@ public class SysRoleController extends BaseController
public AjaxResult selectAuthUserAll(Long roleId, Long[] userIds)
{
roleService.checkRoleDataScope(roleId);
// 当授权成为仓库管理员前先判断此用户是否是物资管理员(必须先为物资管理员,才可成为仓库管理员)
StringJoiner joiner = new StringJoiner(",");
if (roleId == 102L) {
// 根据userIds查询用户信息
List<SysUser> userList = userService.listUser(Arrays.asList(userIds));
for (SysUser user : userList) {
List<Long> roleIds = user.getRoles().stream().map(SysRole::getRoleId).collect(Collectors.toList());
if (!roleIds.contains(107L)) {
// 如果不是物资管理员那么不能授权成为仓库管理员,记录一下不能成为仓库管理员的用户名
joiner.add(user.getNickName());
}
}
}
if (joiner.toString().length() != 0) {
return AjaxResult.error(joiner.toString() + "不是物资管理员,因此不能成为仓库管理员!");
}
return toAjax(roleService.insertAuthUsers(roleId, userIds));
}

@ -1,5 +1,6 @@
package com.ruoyi.web.controller.system;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
import javax.servlet.http.HttpServletResponse;
@ -138,6 +139,15 @@ public class SysUserController extends BaseController
}
user.setCreateBy(getUsername());
user.setPassword(SecurityUtils.encryptPassword(user.getPassword()));
List<Long> roleIdList = Arrays.asList(user.getRoleIds());
// 判断角色中是否仓库管理员
if (roleIdList.contains(102L)) {
// 如果包含了仓库管理员那么判断是否包含物资管理员
if (!roleIdList.contains(107L)) {
// 如果不包含物资管理员,那么返回错误提示,必须先为物资管理员,才可为仓库管理员
return AjaxResult.error("必须先为物资管理员,才可为仓库管理员!");
}
}
return toAjax(userService.insertUser(user));
}

@ -51,6 +51,13 @@ public interface SysUserMapper
*/
public SysUser selectUserById(Long userId);
/**
* id
* @param userIdList ID
* @return
*/
List<SysUser> listUser(List<Long> userIdList);
/**
*
*
@ -124,4 +131,5 @@ public interface SysUserMapper
* @return
*/
public SysUser checkEmailUnique(String email);
}

@ -50,6 +50,13 @@ public interface ISysUserService
*/
public SysUser selectUserById(Long userId);
/**
* id
* @param userIdList ID
* @return
*/
public List<SysUser> listUser(List<Long> userIdList);
/**
* ID
*
@ -203,4 +210,5 @@ public interface ISysUserService
* @return
*/
public String importUser(List<SysUser> userList, Boolean isUpdateSupport, String operName);
}

@ -124,6 +124,16 @@ public class SysUserServiceImpl implements ISysUserService
return userMapper.selectUserById(userId);
}
/**
* id
* @param userIdList ID
* @return
*/
@Override
public List<SysUser> listUser(List<Long> userIdList) {
return userMapper.listUser(userIdList);
}
/**
*
*

@ -147,7 +147,14 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<select id="checkEmailUnique" parameterType="String" resultMap="SysUserResult">
select user_id, email from sys_user where email = #{email} and del_flag = '0' limit 1
</select>
<select id="listUser" resultMap="SysUserResult">
<include refid="selectUserVo"/>
where u.user_id in
<foreach collection="list" open="(" close=")" separator="," item="item">
#{item}
</foreach>
</select>
<insert id="insertUser" parameterType="SysUser" useGeneratedKeys="true" keyProperty="userId">
insert into sys_user(
<if test="userId != null and userId != 0">user_id,</if>

Loading…
Cancel
Save