用户角色权限优化

This commit is contained in:
xd 2024-06-27 09:57:22 +08:00
parent 708ef3a735
commit acbf9e7876
13 changed files with 3790 additions and 311 deletions

View File

@ -1,12 +1,7 @@
package com.ruoyi.web.controller.monitor;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.Set;
import java.util.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisCallback;
import org.springframework.data.redis.core.RedisTemplate;
@ -87,7 +82,7 @@ public class CacheController
public AjaxResult getCacheKeys(@PathVariable String cacheName)
{
Set<String> cacheKeys = redisTemplate.keys(cacheName + "*");
return AjaxResult.success(cacheKeys);
return AjaxResult.success(new TreeSet<>(cacheKeys));
}
@PreAuthorize("@ss.hasPermi('monitor:cache:list')")

View File

@ -148,6 +148,8 @@ public class SysUserController extends BaseController
@PostMapping
public AjaxResult add(@Validated @RequestBody SysUser user)
{
deptService.checkDeptDataScope(user.getDeptId());
roleService.checkRoleDataScope(user.getRoleIds());
if (!userService.checkUserNameUnique(user))
{
return error("新增用户'" + user.getUserName() + "'失败,登录账号已存在");
@ -180,6 +182,8 @@ public class SysUserController extends BaseController
{
userService.checkUserAllowed(user);
userService.checkUserDataScope(user.getUserId());
deptService.checkDeptDataScope(user.getDeptId());
roleService.checkRoleDataScope(user.getRoleIds());
if (!userService.checkUserNameUnique(user))
{
return error("修改用户'" + user.getUserName() + "'失败,登录账号已存在");
@ -301,6 +305,7 @@ public class SysUserController extends BaseController
public AjaxResult insertAuthRole(Long userId, Long[] roleIds)
{
userService.checkUserDataScope(userId);
roleService.checkRoleDataScope(roleIds);
userService.insertUserAuth(userId, roleIds);
return success();
}

View File

@ -88,6 +88,11 @@ public @interface Excel
*/
public String[] combo() default {};
/**
* 是否从字典读数据到combo,默认不读取,如读取需要设置dictType注解.
*/
public boolean comboReadDict() default false;
/**
* 是否需要纵向合并单元格,应对需求:含有list集合单元格)
*/

View File

@ -92,11 +92,18 @@ public class DataScopeAspect
{
StringBuilder sqlString = new StringBuilder();
List<String> conditions = new ArrayList<String>();
List<String> scopeCustomIds = new ArrayList<String>();
user.getRoles().forEach(role -> {
if (DATA_SCOPE_CUSTOM.equals(role.getDataScope()) && StringUtils.isNotEmpty(permission) && StringUtils.isNotEmpty(role.getPermissions()) && StringUtils.containsAny(role.getPermissions(), Convert.toStrArray(permission)))
{
scopeCustomIds.add(Convert.toStr(role.getRoleId()));
}
});
for (SysRole role : user.getRoles())
{
String dataScope = role.getDataScope();
if (!DATA_SCOPE_CUSTOM.equals(dataScope) && conditions.contains(dataScope))
if (conditions.contains(dataScope))
{
continue;
}
@ -113,9 +120,15 @@ public class DataScopeAspect
}
else if (DATA_SCOPE_CUSTOM.equals(dataScope))
{
sqlString.append(StringUtils.format(
" OR {}.dept_id IN ( SELECT dept_id FROM sys_role_dept WHERE role_id = {} ) ", deptAlias,
role.getRoleId()));
if (scopeCustomIds.size() > 1)
{
// 多个自定数据权限使用in查询避免多次拼接
sqlString.append(StringUtils.format(" OR {}.dept_id IN ( SELECT dept_id FROM sys_role_dept WHERE role_id in ({}) ) ", deptAlias, String.join(",", scopeCustomIds)));
}
else
{
sqlString.append(StringUtils.format(" OR {}.dept_id IN ( SELECT dept_id FROM sys_role_dept WHERE role_id = {} ) ", deptAlias, role.getRoleId()));
}
}
else if (DATA_SCOPE_DEPT.equals(dataScope))
{
@ -142,7 +155,7 @@ public class DataScopeAspect
conditions.add(dataScope);
}
// 多角色情况下所有角色都不包含传递过来的权限字符这个时候sqlString也会为空所以要限制一下,不查询任何数据
// 角色都不包含传递过来的权限字符这个时候sqlString也会为空所以要限制一下,不查询任何数据
if (StringUtils.isEmpty(conditions))
{
sqlString.append(StringUtils.format(" OR {}.dept_id = 0 ", deptAlias));

View File

@ -1,6 +1,9 @@
package com.ruoyi.framework.web.exception;
import javax.servlet.http.HttpServletRequest;
import com.ruoyi.common.core.text.Convert;
import com.ruoyi.common.utils.html.EscapeUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.security.access.AccessDeniedException;
@ -19,7 +22,7 @@ import com.ruoyi.common.utils.StringUtils;
/**
* 全局异常处理器
*
*
* @author ruoyi
*/
@RestControllerAdvice
@ -79,8 +82,13 @@ public class GlobalExceptionHandler
public AjaxResult handleMethodArgumentTypeMismatchException(MethodArgumentTypeMismatchException e, HttpServletRequest request)
{
String requestURI = request.getRequestURI();
String value = Convert.toStr(e.getValue());
if (StringUtils.isNotEmpty(value))
{
value = EscapeUtil.clean(value);
}
log.error("请求参数类型不匹配'{}',发生系统异常.", requestURI, e);
return AjaxResult.error(String.format("请求参数类型不匹配,参数[%s]要求类型为:'%s',但输入值为:'%s'", e.getName(), e.getRequiredType().getName(), e.getValue()));
return AjaxResult.error(String.format("请求参数类型不匹配,参数[%s]要求类型为:'%s',但输入值为:'%s'", e.getName(), e.getRequiredType().getName(), value));
}
/**

View File

@ -131,12 +131,12 @@ public class SysLoginService
{
String verifyKey = CacheConstants.CAPTCHA_CODE_KEY + StringUtils.nvl(uuid, "");
String captcha = redisCache.getCacheObject(verifyKey);
redisCache.deleteObject(verifyKey);
if (captcha == null)
{
AsyncManager.me().execute(AsyncFactory.recordLogininfor(username, Constants.LOGIN_FAIL, MessageUtils.message("user.jcaptcha.expire")));
throw new CaptchaExpireException();
}
redisCache.deleteObject(verifyKey);
if (!code.equalsIgnoreCase(captcha))
{
AsyncManager.me().execute(AsyncFactory.recordLogininfor(username, Constants.LOGIN_FAIL, MessageUtils.message("user.jcaptcha.error")));

View File

@ -1,26 +1,26 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="${packageName}.mapper.${ClassName}Mapper">
<resultMap type="${ClassName}" id="${ClassName}Result">
#foreach ($column in $columns)
<result property="${column.javaField}" column="${column.columnName}" />
#end
#foreach ($column in $columns)
<result property="${column.javaField}" column="${column.columnName}" />
#end
</resultMap>
#if($table.sub)
#if($table.sub)
<resultMap id="${ClassName}${subClassName}Result" type="${ClassName}" extends="${ClassName}Result">
<collection property="${subclassName}List" notNullColumn="sub_${subTable.pkColumn.columnName}" javaType="java.util.List" resultMap="${subClassName}Result" />
</resultMap>
<resultMap id="${ClassName}${subClassName}Result" type="${ClassName}" extends="${ClassName}Result">
<collection property="${subclassName}List" ofType="${subClassName}" column="${pkColumn.columnName}" select="select${subClassName}List" />
</resultMap>
<resultMap type="${subClassName}" id="${subClassName}Result">
#foreach ($column in $subTable.columns)
<result property="${column.javaField}" column="sub_${column.columnName}" />
#end
</resultMap>
#end
<resultMap type="${subClassName}" id="${subClassName}Result">
#foreach ($column in $subTable.columns)
<result property="${column.javaField}" column="${column.columnName}" />
#end
</resultMap>
#end
<sql id="select${ClassName}Vo">
select#foreach($column in $columns) $column.columnName#if($foreach.count != $columns.size()),#end#end from ${tableName}
@ -28,76 +28,81 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<select id="select${ClassName}List" parameterType="${ClassName}" resultMap="${ClassName}Result">
<include refid="select${ClassName}Vo"/>
<where>
#foreach($column in $columns)
#set($queryType=$column.queryType)
#set($javaField=$column.javaField)
#set($javaType=$column.javaType)
#set($columnName=$column.columnName)
#set($AttrName=$column.javaField.substring(0,1).toUpperCase() + ${column.javaField.substring(1)})
#if($column.query)
#if($column.queryType == "EQ")
<if test="$javaField != null #if($javaType == 'String' ) and $javaField.trim() != ''#end"> and $columnName = #{$javaField}</if>
#elseif($queryType == "NE")
<if test="$javaField != null #if($javaType == 'String' ) and $javaField.trim() != ''#end"> and $columnName != #{$javaField}</if>
#elseif($queryType == "GT")
<if test="$javaField != null #if($javaType == 'String' ) and $javaField.trim() != ''#end"> and $columnName &gt; #{$javaField}</if>
#elseif($queryType == "GTE")
<if test="$javaField != null #if($javaType == 'String' ) and $javaField.trim() != ''#end"> and $columnName &gt;= #{$javaField}</if>
#elseif($queryType == "LT")
<if test="$javaField != null #if($javaType == 'String' ) and $javaField.trim() != ''#end"> and $columnName &lt; #{$javaField}</if>
#elseif($queryType == "LTE")
<if test="$javaField != null #if($javaType == 'String' ) and $javaField.trim() != ''#end"> and $columnName &lt;= #{$javaField}</if>
#elseif($queryType == "LIKE")
<if test="$javaField != null #if($javaType == 'String' ) and $javaField.trim() != ''#end"> and $columnName like concat('%', #{$javaField}, '%')</if>
#elseif($queryType == "BETWEEN")
<if test="params.begin$AttrName != null and params.begin$AttrName != '' and params.end$AttrName != null and params.end$AttrName != ''"> and $columnName between #{params.begin$AttrName} and #{params.end$AttrName}</if>
#end
#end
#end
<where>
#foreach($column in $columns)
#set($queryType=$column.queryType)
#set($javaField=$column.javaField)
#set($javaType=$column.javaType)
#set($columnName=$column.columnName)
#set($AttrName=$column.javaField.substring(0,1).toUpperCase() + ${column.javaField.substring(1)})
#if($column.query)
#if($column.queryType == "EQ")
<if test="$javaField != null #if($javaType == 'String' ) and $javaField.trim() != ''#end"> and $columnName = #{$javaField}</if>
#elseif($queryType == "NE")
<if test="$javaField != null #if($javaType == 'String' ) and $javaField.trim() != ''#end"> and $columnName != #{$javaField}</if>
#elseif($queryType == "GT")
<if test="$javaField != null #if($javaType == 'String' ) and $javaField.trim() != ''#end"> and $columnName &gt; #{$javaField}</if>
#elseif($queryType == "GTE")
<if test="$javaField != null #if($javaType == 'String' ) and $javaField.trim() != ''#end"> and $columnName &gt;= #{$javaField}</if>
#elseif($queryType == "LT")
<if test="$javaField != null #if($javaType == 'String' ) and $javaField.trim() != ''#end"> and $columnName &lt; #{$javaField}</if>
#elseif($queryType == "LTE")
<if test="$javaField != null #if($javaType == 'String' ) and $javaField.trim() != ''#end"> and $columnName &lt;= #{$javaField}</if>
#elseif($queryType == "LIKE")
<if test="$javaField != null #if($javaType == 'String' ) and $javaField.trim() != ''#end"> and $columnName like concat('%', #{$javaField}, '%')</if>
#elseif($queryType == "BETWEEN")
<if test="params.begin$AttrName != null and params.begin$AttrName != '' and params.end$AttrName != null and params.end$AttrName != ''"> and $columnName between #{params.begin$AttrName} and #{params.end$AttrName}</if>
#end
#end
#end
</where>
</select>
<select id="select${ClassName}By${pkColumn.capJavaField}" parameterType="${pkColumn.javaType}" resultMap="#if($table.sub)${ClassName}${subClassName}Result#else${ClassName}Result#end">
#if($table.crud || $table.tree)
<include refid="select${ClassName}Vo"/>
where ${pkColumn.columnName} = #{${pkColumn.javaField}}
#elseif($table.sub)
select#foreach($column in $columns) a.$column.columnName#if($foreach.count != $columns.size()),#end#end,
#foreach($column in $subTable.columns) b.$column.columnName as sub_$column.columnName#if($foreach.count != $subTable.columns.size()),#end#end
from ${tableName} a
left join ${subTableName} b on b.${subTableFkName} = a.${pkColumn.columnName}
where a.${pkColumn.columnName} = #{${pkColumn.javaField}}
#end
<select id="select${ClassName}By${pkColumn.capJavaField}" parameterType="${pkColumn.javaType}" resultMap="#if($table.sub)${ClassName}${subClassName}Result#else${ClassName}Result#end">
#if($table.crud || $table.tree)
<include refid="select${ClassName}Vo"/>
where ${pkColumn.columnName} = #{${pkColumn.javaField}}
#elseif($table.sub)
select#foreach($column in $columns) $column.columnName#if($foreach.count != $columns.size()),#end#end
from ${tableName}
where ${pkColumn.columnName} = #{${pkColumn.javaField}}
#end
</select>
#if($table.sub)
<select id="select${subClassName}List" resultType="${subClassName}" resultMap="${subClassName}Result">
select#foreach ($column in $subTable.columns) $column.columnName#if($foreach.count != $subTable.columns.size()),#end#end
from ${subTableName}
where ${subTableFkName} = #{${subTableFkName}}
</select>
#end
<insert id="insert${ClassName}" parameterType="${ClassName}"#if($pkColumn.increment) useGeneratedKeys="true" keyProperty="$pkColumn.javaField"#end>
insert into ${tableName}
<trim prefix="(" suffix=")" suffixOverrides=",">
#foreach($column in $columns)
#if($column.columnName != $pkColumn.columnName || !$pkColumn.increment)
<if test="$column.javaField != null#if($column.javaType == 'String' && $column.required) and $column.javaField != ''#end">$column.columnName,</if>
#end
#end
</trim>
#foreach($column in $columns)
#if($column.columnName != $pkColumn.columnName || !$pkColumn.increment)
<if test="$column.javaField != null#if($column.javaType == 'String' && $column.required) and $column.javaField != ''#end">$column.columnName,</if>
#end
#end
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
#foreach($column in $columns)
#if($column.columnName != $pkColumn.columnName || !$pkColumn.increment)
<if test="$column.javaField != null#if($column.javaType == 'String' && $column.required) and $column.javaField != ''#end">#{$column.javaField},</if>
#end
#end
</trim>
#foreach($column in $columns)
#if($column.columnName != $pkColumn.columnName || !$pkColumn.increment)
<if test="$column.javaField != null#if($column.javaType == 'String' && $column.required) and $column.javaField != ''#end">#{$column.javaField},</if>
#end
#end
</trim>
</insert>
<update id="update${ClassName}" parameterType="${ClassName}">
update ${tableName}
<trim prefix="SET" suffixOverrides=",">
#foreach($column in $columns)
#if($column.columnName != $pkColumn.columnName)
<if test="$column.javaField != null#if($column.javaType == 'String' && $column.required) and $column.javaField != ''#end">$column.columnName = #{$column.javaField},</if>
#end
#end
#foreach($column in $columns)
#if($column.columnName != $pkColumn.columnName)
<if test="$column.javaField != null#if($column.javaType == 'String' && $column.required) and $column.javaField != ''#end">$column.columnName = #{$column.javaField},</if>
#end
#end
</trim>
where ${pkColumn.columnName} = #{${pkColumn.javaField}}
</update>
@ -107,29 +112,29 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</delete>
<delete id="delete${ClassName}By${pkColumn.capJavaField}s" parameterType="String">
delete from ${tableName} where ${pkColumn.columnName} in
delete from ${tableName} where ${pkColumn.columnName} in
<foreach item="${pkColumn.javaField}" collection="array" open="(" separator="," close=")">
#{${pkColumn.javaField}}
</foreach>
</delete>
#if($table.sub)
<delete id="delete${subClassName}By${subTableFkClassName}s" parameterType="String">
delete from ${subTableName} where ${subTableFkName} in
<foreach item="${subTableFkclassName}" collection="array" open="(" separator="," close=")">
#{${subTableFkclassName}}
</foreach>
</delete>
#if($table.sub)
<delete id="delete${subClassName}By${subTableFkClassName}" parameterType="${pkColumn.javaType}">
delete from ${subTableName} where ${subTableFkName} = #{${subTableFkclassName}}
</delete>
<delete id="delete${subClassName}By${subTableFkClassName}s" parameterType="String">
delete from ${subTableName} where ${subTableFkName} in
<foreach item="${subTableFkclassName}" collection="array" open="(" separator="," close=")">
#{${subTableFkclassName}}
</foreach>
</delete>
<insert id="batch${subClassName}">
insert into ${subTableName}(#foreach($column in $subTable.columns) $column.columnName#if($foreach.count != $subTable.columns.size()),#end#end) values
<foreach item="item" index="index" collection="list" separator=",">
(#foreach($column in $subTable.columns) #{item.$column.javaField}#if($foreach.count != $subTable.columns.size()),#end#end)
</foreach>
</insert>
#end
</mapper>
<delete id="delete${subClassName}By${subTableFkClassName}" parameterType="${pkColumn.javaType}">
delete from ${subTableName} where ${subTableFkName} = #{${subTableFkclassName}}
</delete>
<insert id="batch${subClassName}">
insert into ${subTableName}(#foreach($column in $subTable.columns) $column.columnName#if($foreach.count != $subTable.columns.size()),#end#end) values
<foreach item="item" index="index" collection="list" separator=",">
(#foreach($column in $subTable.columns) #{item.$column.javaField}#if($foreach.count != $subTable.columns.size()),#end#end)
</foreach>
</insert>
#end
</mapper>

View File

@ -7,14 +7,14 @@ import com.ruoyi.system.domain.SysUserRole;
/**
* 角色业务层
*
*
* @author ruoyi
*/
public interface ISysRoleService
{
/**
* 根据条件分页查询角色数据
*
*
* @param role 角色信息
* @return 角色数据集合信息
*/
@ -22,7 +22,7 @@ public interface ISysRoleService
/**
* 根据用户ID查询角色列表
*
*
* @param userId 用户ID
* @return 角色列表
*/
@ -30,7 +30,7 @@ public interface ISysRoleService
/**
* 根据用户ID查询角色权限
*
*
* @param userId 用户ID
* @return 权限列表
*/
@ -38,14 +38,14 @@ public interface ISysRoleService
/**
* 查询所有角色
*
*
* @return 角色列表
*/
public List<SysRole> selectRoleAll();
/**
* 根据用户ID获取角色选择框列表
*
*
* @param userId 用户ID
* @return 选中角色ID列表
*/
@ -53,7 +53,7 @@ public interface ISysRoleService
/**
* 通过角色ID查询角色
*
*
* @param roleId 角色ID
* @return 角色对象信息
*/
@ -61,7 +61,7 @@ public interface ISysRoleService
/**
* 校验角色名称是否唯一
*
*
* @param role 角色信息
* @return 结果
*/
@ -69,7 +69,7 @@ public interface ISysRoleService
/**
* 校验角色权限是否唯一
*
*
* @param role 角色信息
* @return 结果
*/
@ -77,21 +77,21 @@ public interface ISysRoleService
/**
* 校验角色是否允许操作
*
*
* @param role 角色信息
*/
public void checkRoleAllowed(SysRole role);
/**
* 校验角色是否有数据权限
*
* @param roleId 角色id
*
* @param roleIds 角色id
*/
public void checkRoleDataScope(Long roleId);
public void checkRoleDataScope(Long... roleIds);
/**
* 通过角色ID查询角色使用数量
*
*
* @param roleId 角色ID
* @return 结果
*/
@ -99,7 +99,7 @@ public interface ISysRoleService
/**
* 新增保存角色信息
*
*
* @param role 角色信息
* @return 结果
*/
@ -107,7 +107,7 @@ public interface ISysRoleService
/**
* 修改保存角色信息
*
*
* @param role 角色信息
* @return 结果
*/
@ -115,7 +115,7 @@ public interface ISysRoleService
/**
* 修改角色状态
*
*
* @param role 角色信息
* @return 结果
*/
@ -123,7 +123,7 @@ public interface ISysRoleService
/**
* 修改数据权限信息
*
*
* @param role 角色信息
* @return 结果
*/
@ -131,7 +131,7 @@ public interface ISysRoleService
/**
* 通过角色ID删除角色
*
*
* @param roleId 角色ID
* @return 结果
*/
@ -139,7 +139,7 @@ public interface ISysRoleService
/**
* 批量删除角色信息
*
*
* @param roleIds 需要删除的角色ID
* @return 结果
*/
@ -147,7 +147,7 @@ public interface ISysRoleService
/**
* 取消授权用户角色
*
*
* @param userRole 用户和角色关联信息
* @return 结果
*/
@ -155,7 +155,7 @@ public interface ISysRoleService
/**
* 批量取消授权用户角色
*
*
* @param roleId 角色ID
* @param userIds 需要取消授权的用户数据ID
* @return 结果
@ -164,7 +164,7 @@ public interface ISysRoleService
/**
* 批量选择授权用户角色
*
*
* @param roleId 角色ID
* @param userIds 需要删除的用户数据ID
* @return 结果

View File

@ -23,7 +23,7 @@ import com.ruoyi.system.service.ISysDeptService;
/**
* 部门管理 服务实现
*
*
* @author ruoyi
*/
@Service
@ -37,7 +37,7 @@ public class SysDeptServiceImpl implements ISysDeptService
/**
* 查询部门管理数据
*
*
* @param dept 部门信息
* @return 部门信息集合
*/
@ -63,7 +63,7 @@ public class SysDeptServiceImpl implements ISysDeptService
/**
* 构建前端所需要树结构
*
*
* @param depts 部门列表
* @return 树结构列表
*/
@ -90,7 +90,7 @@ public class SysDeptServiceImpl implements ISysDeptService
/**
* 构建前端所需要下拉树结构
*
*
* @param depts 部门列表
* @return 下拉树结构列表
*/
@ -103,7 +103,7 @@ public class SysDeptServiceImpl implements ISysDeptService
/**
* 根据角色ID查询部门树信息
*
*
* @param roleId 角色ID
* @return 选中部门列表
*/
@ -116,7 +116,7 @@ public class SysDeptServiceImpl implements ISysDeptService
/**
* 根据部门ID查询信息
*
*
* @param deptId 部门ID
* @return 部门信息
*/
@ -128,7 +128,7 @@ public class SysDeptServiceImpl implements ISysDeptService
/**
* 根据ID查询所有子部门正常状态
*
*
* @param deptId 部门ID
* @return 子部门数
*/
@ -140,7 +140,7 @@ public class SysDeptServiceImpl implements ISysDeptService
/**
* 是否存在子节点
*
*
* @param deptId 部门ID
* @return 结果
*/
@ -153,7 +153,7 @@ public class SysDeptServiceImpl implements ISysDeptService
/**
* 查询部门是否存在用户
*
*
* @param deptId 部门ID
* @return 结果 true 存在 false 不存在
*/
@ -166,7 +166,7 @@ public class SysDeptServiceImpl implements ISysDeptService
/**
* 校验部门名称是否唯一
*
*
* @param dept 部门信息
* @return 结果
*/
@ -184,13 +184,13 @@ public class SysDeptServiceImpl implements ISysDeptService
/**
* 校验部门是否有数据权限
*
*
* @param deptId 部门id
*/
@Override
public void checkDeptDataScope(Long deptId)
{
if (!SysUser.isAdmin(SecurityUtils.getUserId()))
if (!SysUser.isAdmin(SecurityUtils.getUserId()) && StringUtils.isNotNull(deptId))
{
SysDept dept = new SysDept();
dept.setDeptId(deptId);
@ -204,7 +204,7 @@ public class SysDeptServiceImpl implements ISysDeptService
/**
* 新增保存部门信息
*
*
* @param dept 部门信息
* @return 结果
*/
@ -223,7 +223,7 @@ public class SysDeptServiceImpl implements ISysDeptService
/**
* 修改保存部门信息
*
*
* @param dept 部门信息
* @return 结果
*/
@ -251,7 +251,7 @@ public class SysDeptServiceImpl implements ISysDeptService
/**
* 修改该部门的父级部门状态
*
*
* @param dept 当前部门
*/
private void updateParentDeptStatusNormal(SysDept dept)
@ -263,7 +263,7 @@ public class SysDeptServiceImpl implements ISysDeptService
/**
* 修改子元素关系
*
*
* @param deptId 被修改的部门ID
* @param newAncestors 新的父ID集合
* @param oldAncestors 旧的父ID集合
@ -283,7 +283,7 @@ public class SysDeptServiceImpl implements ISysDeptService
/**
* 删除部门管理信息
*
*
* @param deptId 部门ID
* @return 结果
*/

View File

@ -27,7 +27,7 @@ import com.ruoyi.system.service.ISysRoleService;
/**
* 角色 业务层处理
*
*
* @author ruoyi
*/
@Service
@ -47,7 +47,7 @@ public class SysRoleServiceImpl implements ISysRoleService
/**
* 根据条件分页查询角色数据
*
*
* @param role 角色信息
* @return 角色数据集合信息
*/
@ -60,7 +60,7 @@ public class SysRoleServiceImpl implements ISysRoleService
/**
* 根据用户ID查询角色
*
*
* @param userId 用户ID
* @return 角色列表
*/
@ -85,7 +85,7 @@ public class SysRoleServiceImpl implements ISysRoleService
/**
* 根据用户ID查询权限
*
*
* @param userId 用户ID
* @return 权限列表
*/
@ -106,7 +106,7 @@ public class SysRoleServiceImpl implements ISysRoleService
/**
* 查询所有角色
*
*
* @return 角色列表
*/
@Override
@ -117,7 +117,7 @@ public class SysRoleServiceImpl implements ISysRoleService
/**
* 根据用户ID获取角色选择框列表
*
*
* @param userId 用户ID
* @return 选中角色ID列表
*/
@ -129,7 +129,7 @@ public class SysRoleServiceImpl implements ISysRoleService
/**
* 通过角色ID查询角色
*
*
* @param roleId 角色ID
* @return 角色对象信息
*/
@ -141,7 +141,7 @@ public class SysRoleServiceImpl implements ISysRoleService
/**
* 校验角色名称是否唯一
*
*
* @param role 角色信息
* @return 结果
*/
@ -159,7 +159,7 @@ public class SysRoleServiceImpl implements ISysRoleService
/**
* 校验角色权限是否唯一
*
*
* @param role 角色信息
* @return 结果
*/
@ -177,7 +177,7 @@ public class SysRoleServiceImpl implements ISysRoleService
/**
* 校验角色是否允许操作
*
*
* @param role 角色信息
*/
@Override
@ -191,27 +191,30 @@ public class SysRoleServiceImpl implements ISysRoleService
/**
* 校验角色是否有数据权限
*
* @param roleId 角色id
*
* @param roleIds 角色id
*/
@Override
public void checkRoleDataScope(Long roleId)
public void checkRoleDataScope(Long... roleIds)
{
if (!SysUser.isAdmin(SecurityUtils.getUserId()))
{
SysRole role = new SysRole();
role.setRoleId(roleId);
List<SysRole> roles = SpringUtils.getAopProxy(this).selectRoleList(role);
if (StringUtils.isEmpty(roles))
for (Long roleId : roleIds)
{
throw new ServiceException("没有权限访问角色数据!");
SysRole role = new SysRole();
role.setRoleId(roleId);
List<SysRole> roles = SpringUtils.getAopProxy(this).selectRoleList(role);
if (StringUtils.isEmpty(roles))
{
throw new ServiceException("没有权限访问角色数据!");
}
}
}
}
/**
* 通过角色ID查询角色使用数量
*
*
* @param roleId 角色ID
* @return 结果
*/
@ -223,7 +226,7 @@ public class SysRoleServiceImpl implements ISysRoleService
/**
* 新增保存角色信息
*
*
* @param role 角色信息
* @return 结果
*/
@ -238,7 +241,7 @@ public class SysRoleServiceImpl implements ISysRoleService
/**
* 修改保存角色信息
*
*
* @param role 角色信息
* @return 结果
*/
@ -255,7 +258,7 @@ public class SysRoleServiceImpl implements ISysRoleService
/**
* 修改角色状态
*
*
* @param role 角色信息
* @return 结果
*/
@ -267,7 +270,7 @@ public class SysRoleServiceImpl implements ISysRoleService
/**
* 修改数据权限信息
*
*
* @param role 角色信息
* @return 结果
*/
@ -285,7 +288,7 @@ public class SysRoleServiceImpl implements ISysRoleService
/**
* 新增角色菜单信息
*
*
* @param role 角色对象
*/
public int insertRoleMenu(SysRole role)
@ -333,7 +336,7 @@ public class SysRoleServiceImpl implements ISysRoleService
/**
* 通过角色ID删除角色
*
*
* @param roleId 角色ID
* @return 结果
*/
@ -350,7 +353,7 @@ public class SysRoleServiceImpl implements ISysRoleService
/**
* 批量删除角色信息
*
*
* @param roleIds 需要删除的角色ID
* @return 结果
*/
@ -377,7 +380,7 @@ public class SysRoleServiceImpl implements ISysRoleService
/**
* 取消授权用户角色
*
*
* @param userRole 用户和角色关联信息
* @return 结果
*/
@ -389,7 +392,7 @@ public class SysRoleServiceImpl implements ISysRoleService
/**
* 批量取消授权用户角色
*
*
* @param roleId 角色ID
* @param userIds 需要取消授权的用户数据ID
* @return 结果
@ -402,7 +405,7 @@ public class SysRoleServiceImpl implements ISysRoleService
/**
* 批量选择授权用户角色
*
*
* @param roleId 角色ID
* @param userIds 需要授权的用户数据ID
* @return 结果

View File

@ -4,6 +4,8 @@ import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
import javax.validation.Validator;
import com.ruoyi.system.service.ISysDeptService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
@ -32,7 +34,7 @@ import com.ruoyi.system.service.ISysUserService;
/**
* 用户 业务层处理
*
*
* @author ruoyi
*/
@Service
@ -58,12 +60,15 @@ public class SysUserServiceImpl implements ISysUserService
@Autowired
private ISysConfigService configService;
@Autowired
private ISysDeptService deptService;
@Autowired
protected Validator validator;
/**
* 根据条件分页查询用户列表
*
*
* @param user 用户信息
* @return 用户信息集合信息
*/
@ -76,7 +81,7 @@ public class SysUserServiceImpl implements ISysUserService
/**
* 根据条件分页查询已分配用户角色列表
*
*
* @param user 用户信息
* @return 用户信息集合信息
*/
@ -89,7 +94,7 @@ public class SysUserServiceImpl implements ISysUserService
/**
* 根据条件分页查询未分配用户角色列表
*
*
* @param user 用户信息
* @return 用户信息集合信息
*/
@ -102,7 +107,7 @@ public class SysUserServiceImpl implements ISysUserService
/**
* 通过用户名查询用户
*
*
* @param userName 用户名
* @return 用户对象信息
*/
@ -114,7 +119,7 @@ public class SysUserServiceImpl implements ISysUserService
/**
* 通过用户ID查询用户
*
*
* @param userId 用户ID
* @return 用户对象信息
*/
@ -126,7 +131,7 @@ public class SysUserServiceImpl implements ISysUserService
/**
* 查询用户所属角色组
*
*
* @param userName 用户名
* @return 结果
*/
@ -143,7 +148,7 @@ public class SysUserServiceImpl implements ISysUserService
/**
* 查询用户所属岗位组
*
*
* @param userName 用户名
* @return 结果
*/
@ -160,7 +165,7 @@ public class SysUserServiceImpl implements ISysUserService
/**
* 校验用户名称是否唯一
*
*
* @param user 用户信息
* @return 结果
*/
@ -214,7 +219,7 @@ public class SysUserServiceImpl implements ISysUserService
/**
* 校验用户是否允许操作
*
*
* @param user 用户信息
*/
@Override
@ -228,7 +233,7 @@ public class SysUserServiceImpl implements ISysUserService
/**
* 校验用户是否有数据权限
*
*
* @param userId 用户id
*/
@Override
@ -248,7 +253,7 @@ public class SysUserServiceImpl implements ISysUserService
/**
* 新增保存用户信息
*
*
* @param user 用户信息
* @return 结果
*/
@ -267,7 +272,7 @@ public class SysUserServiceImpl implements ISysUserService
/**
* 注册用户信息
*
*
* @param user 用户信息
* @return 结果
*/
@ -279,7 +284,7 @@ public class SysUserServiceImpl implements ISysUserService
/**
* 修改保存用户信息
*
*
* @param user 用户信息
* @return 结果
*/
@ -301,7 +306,7 @@ public class SysUserServiceImpl implements ISysUserService
/**
* 用户授权角色
*
*
* @param userId 用户ID
* @param roleIds 角色组
*/
@ -315,7 +320,7 @@ public class SysUserServiceImpl implements ISysUserService
/**
* 修改用户状态
*
*
* @param user 用户信息
* @return 结果
*/
@ -327,7 +332,7 @@ public class SysUserServiceImpl implements ISysUserService
/**
* 修改用户基本信息
*
*
* @param user 用户信息
* @return 结果
*/
@ -339,7 +344,7 @@ public class SysUserServiceImpl implements ISysUserService
/**
* 修改用户头像
*
*
* @param userName 用户名
* @param avatar 头像地址
* @return 结果
@ -352,7 +357,7 @@ public class SysUserServiceImpl implements ISysUserService
/**
* 重置用户密码
*
*
* @param user 用户信息
* @return 结果
*/
@ -364,7 +369,7 @@ public class SysUserServiceImpl implements ISysUserService
/**
* 重置用户密码
*
*
* @param userName 用户名
* @param password 密码
* @return 结果
@ -377,7 +382,7 @@ public class SysUserServiceImpl implements ISysUserService
/**
* 新增用户角色信息
*
*
* @param user 用户对象
*/
public void insertUserRole(SysUser user)
@ -387,7 +392,7 @@ public class SysUserServiceImpl implements ISysUserService
/**
* 新增用户岗位信息
*
*
* @param user 用户对象
*/
public void insertUserPost(SysUser user)
@ -410,7 +415,7 @@ public class SysUserServiceImpl implements ISysUserService
/**
* 新增用户角色信息
*
*
* @param userId 用户ID
* @param roleIds 角色组
*/
@ -433,7 +438,7 @@ public class SysUserServiceImpl implements ISysUserService
/**
* 通过用户ID删除用户
*
*
* @param userId 用户ID
* @return 结果
*/
@ -450,7 +455,7 @@ public class SysUserServiceImpl implements ISysUserService
/**
* 批量删除用户信息
*
*
* @param userIds 需要删除的用户ID
* @return 结果
*/
@ -472,7 +477,7 @@ public class SysUserServiceImpl implements ISysUserService
/**
* 导入用户数据
*
*
* @param userList 用户数据列表
* @param isUpdateSupport 是否更新支持如果已存在则进行更新数据
* @param operName 操作用户
@ -489,7 +494,6 @@ public class SysUserServiceImpl implements ISysUserService
int failureNum = 0;
StringBuilder successMsg = new StringBuilder();
StringBuilder failureMsg = new StringBuilder();
String password = configService.selectConfigByKey("sys.user.initPassword");
for (SysUser user : userList)
{
try
@ -499,6 +503,8 @@ public class SysUserServiceImpl implements ISysUserService
if (StringUtils.isNull(u))
{
BeanValidators.validateWithException(validator, user);
deptService.checkDeptDataScope(user.getDeptId());
String password = configService.selectConfigByKey("sys.user.initPassword");
user.setPassword(SecurityUtils.encryptPassword(password));
user.setCreateBy(operName);
userMapper.insertUser(user);
@ -510,6 +516,7 @@ public class SysUserServiceImpl implements ISysUserService
BeanValidators.validateWithException(validator, user);
checkUserAllowed(u);
checkUserDataScope(u.getUserId());
deptService.checkDeptDataScope(user.getDeptId());
user.setUserId(u.getUserId());
user.setUpdateBy(operName);
userMapper.updateUser(user);

View File

@ -1,114 +1,120 @@
<template>
<el-form size="small">
<el-form-item>
<el-radio v-model='radioValue' :label="1">
小时允许的通配符[, - * /]
</el-radio>
</el-form-item>
<el-form size="small">
<el-form-item>
<el-radio v-model='radioValue' :label="1">
小时允许的通配符[, - * /]
</el-radio>
</el-form-item>
<el-form-item>
<el-radio v-model='radioValue' :label="2">
周期从
<el-input-number v-model='cycle01' :min="0" :max="22" /> -
<el-input-number v-model='cycle02' :min="cycle01 ? cycle01 + 1 : 1" :max="23" /> 小时
</el-radio>
</el-form-item>
<el-form-item>
<el-radio v-model='radioValue' :label="2">
周期从
<el-input-number v-model='cycle01' :min="0" :max="22" /> -
<el-input-number v-model='cycle02' :min="cycle01 ? cycle01 + 1 : 1" :max="23" /> 小时
</el-radio>
</el-form-item>
<el-form-item>
<el-radio v-model='radioValue' :label="3">
<el-input-number v-model='average01' :min="0" :max="22" /> 小时开始
<el-input-number v-model='average02' :min="1" :max="23 - average01 || 0" /> 小时执行一次
</el-radio>
</el-form-item>
<el-form-item>
<el-radio v-model='radioValue' :label="3">
<el-input-number v-model='average01' :min="0" :max="22" /> 小时开始
<el-input-number v-model='average02' :min="1" :max="23 - average01 || 0" /> 小时执行一次
</el-radio>
</el-form-item>
<el-form-item>
<el-radio v-model='radioValue' :label="4">
指定
<el-select clearable v-model="checkboxList" placeholder="可多选" multiple style="width:100%">
<el-option v-for="item in 24" :key="item" :value="item-1">{{item-1}}</el-option>
</el-select>
</el-radio>
</el-form-item>
</el-form>
<el-form-item>
<el-radio v-model='radioValue' :label="4">
指定
<el-select clearable v-model="checkboxList" placeholder="可多选" multiple style="width:100%">
<el-option v-for="item in 24" :key="item" :value="item-1">{{item-1}}</el-option>
</el-select>
</el-radio>
</el-form-item>
</el-form>
</template>
<script>
export default {
data() {
return {
radioValue: 1,
cycle01: 0,
cycle02: 1,
average01: 0,
average02: 1,
checkboxList: [],
checkNum: this.$options.propsData.check
}
},
name: 'crontab-hour',
props: ['check', 'cron'],
methods: {
//
radioChange() {
switch (this.radioValue) {
case 1:
this.$emit('update', 'hour', '*')
break;
case 2:
this.$emit('update', 'hour', this.cycleTotal);
break;
case 3:
this.$emit('update', 'hour', this.averageTotal);
break;
case 4:
this.$emit('update', 'hour', this.checkboxString);
break;
}
},
//
cycleChange() {
if (this.radioValue == '2') {
this.$emit('update', 'hour', this.cycleTotal);
}
},
//
averageChange() {
if (this.radioValue == '3') {
this.$emit('update', 'hour', this.averageTotal);
}
},
// checkbox
checkboxChange() {
if (this.radioValue == '4') {
this.$emit('update', 'hour', this.checkboxString);
}
}
},
watch: {
'radioValue': 'radioChange',
'cycleTotal': 'cycleChange',
'averageTotal': 'averageChange',
'checkboxString': 'checkboxChange'
},
computed: {
//
cycleTotal: function () {
const cycle01 = this.checkNum(this.cycle01, 0, 22)
const cycle02 = this.checkNum(this.cycle02, cycle01 ? cycle01 + 1 : 1, 23)
return cycle01 + '-' + cycle02;
},
//
averageTotal: function () {
const average01 = this.checkNum(this.average01, 0, 22)
const average02 = this.checkNum(this.average02, 1, 23 - average01 || 0)
return average01 + '/' + average02;
},
// checkbox
checkboxString: function () {
let str = this.checkboxList.join();
return str == '' ? '*' : str;
}
}
}
export default {
data() {
return {
radioValue: 1,
cycle01: 0,
cycle02: 1,
average01: 0,
average02: 1,
checkboxList: [],
checkNum: this.$options.propsData.check
}
},
name: 'crontab-hour',
props: ['check', 'cron'],
methods: {
//
radioChange() {
if (this.cron.min === '*') {
this.$emit('update', 'min', '0', 'hour');
}
if (this.cron.second === '*') {
this.$emit('update', 'second', '0', 'hour');
}
switch (this.radioValue) {
case 1:
this.$emit('update', 'hour', '*')
break;
case 2:
this.$emit('update', 'hour', this.cycleTotal);
break;
case 3:
this.$emit('update', 'hour', this.averageTotal);
break;
case 4:
this.$emit('update', 'hour', this.checkboxString);
break;
}
},
//
cycleChange() {
if (this.radioValue == '2') {
this.$emit('update', 'hour', this.cycleTotal);
}
},
//
averageChange() {
if (this.radioValue == '3') {
this.$emit('update', 'hour', this.averageTotal);
}
},
// checkbox
checkboxChange() {
if (this.radioValue == '4') {
this.$emit('update', 'hour', this.checkboxString);
}
}
},
watch: {
'radioValue': 'radioChange',
'cycleTotal': 'cycleChange',
'averageTotal': 'averageChange',
'checkboxString': 'checkboxChange'
},
computed: {
//
cycleTotal: function () {
const cycle01 = this.checkNum(this.cycle01, 0, 22)
const cycle02 = this.checkNum(this.cycle02, cycle01 ? cycle01 + 1 : 1, 23)
return cycle01 + '-' + cycle02;
},
//
averageTotal: function () {
const average01 = this.checkNum(this.average01, 0, 22)
const average02 = this.checkNum(this.average02, 1, 23 - average01 || 0)
return average01 + '/' + average02;
},
// checkbox
checkboxString: function () {
let str = this.checkboxList.join();
return str == '' ? '*' : str;
}
}
}
</script>

File diff suppressed because it is too large Load Diff