| | |
| | | import cn.hutool.core.lang.Validator; |
| | | import cn.hutool.core.util.StrUtil; |
| | | import com.ruoyi.common.annotation.DataScope; |
| | | import com.ruoyi.common.core.domain.BaseEntity; |
| | | import com.ruoyi.common.core.domain.entity.SysRole; |
| | | import com.ruoyi.common.core.domain.entity.SysUser; |
| | | import com.ruoyi.common.core.domain.model.LoginUser; |
| | |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | import java.lang.reflect.Method; |
| | | import java.util.Map; |
| | | |
| | | /** |
| | | * 数据过滤处理 |
| | |
| | | if (StrUtil.isNotBlank(sqlString.toString())) |
| | | { |
| | | Object params = joinPoint.getArgs()[0]; |
| | | if (Validator.isNotNull(params) && params instanceof BaseEntity) |
| | | if (Validator.isNotNull(params)) |
| | | { |
| | | BaseEntity baseEntity = (BaseEntity) params; |
| | | baseEntity.getParams().put(DATA_SCOPE, " AND (" + sqlString.substring(4) + ")"); |
| | | try { |
| | | Method getParams = params.getClass().getDeclaredMethod("getParams", null); |
| | | Map<String, Object> invoke = (Map<String, Object>) getParams.invoke(params, null); |
| | | invoke.put(DATA_SCOPE, " AND (" + sqlString.substring(4) + ")"); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | } |
| | | } |
| | |
| | | public interface SysDeptMapper extends BaseMapper<SysDept> { |
| | | |
| | | /** |
| | | * 查询部门管理数据 |
| | | * |
| | | * @param dept 部门信息 |
| | | * @return 部门信息集合 |
| | | */ |
| | | public List<SysDept> selectDeptList(SysDept dept); |
| | | |
| | | /** |
| | | * 根据角色ID查询部门树信息 |
| | | * |
| | | * @param roleId 角色ID |
| | |
| | | */ |
| | | public interface SysRoleMapper extends BaseMapper<SysRole> { |
| | | |
| | | /** |
| | | * 根据条件分页查询角色数据 |
| | | * |
| | | * @param role 角色信息 |
| | | * @return 角色数据集合信息 |
| | | */ |
| | | public List<SysRole> selectRoleList(SysRole role); |
| | | |
| | | /** |
| | | * 根据用户ID查询角色 |
| | |
| | | @Override |
| | | @DataScope(deptAlias = "d") |
| | | public List<SysDept> selectDeptList(SysDept dept) { |
| | | Object dataScope = dept.getParams().get("dataScope"); |
| | | return list(new LambdaQueryWrapper<SysDept>() |
| | | .eq(dept.getParentId() != null && dept.getParentId() != 0, |
| | | SysDept::getParentId, dept.getParentId()) |
| | | .like(StrUtil.isNotBlank(dept.getDeptName()), SysDept::getDeptName, dept.getDeptName()) |
| | | .eq(StrUtil.isNotBlank(dept.getStatus()), SysDept::getStatus, dept.getStatus()) |
| | | .apply(dataScope != null, dataScope != null ? dataScope.toString() : null) |
| | | .orderByAsc(SysDept::getParentId) |
| | | .orderByAsc(SysDept::getOrderNum)); |
| | | return baseMapper.selectDeptList(dept); |
| | | } |
| | | |
| | | /** |
| | |
| | | @Override |
| | | @DataScope(deptAlias = "d") |
| | | public List<SysRole> selectRoleList(SysRole role) { |
| | | Map<String, Object> params = role.getParams(); |
| | | Object dataScope = params.get("dataScope"); |
| | | return list(new LambdaQueryWrapper<SysRole>() |
| | | .like(StrUtil.isNotBlank(role.getRoleName()), SysRole::getRoleName, role.getRoleName()) |
| | | .eq(StrUtil.isNotBlank(role.getStatus()), SysRole::getStatus, role.getStatus()) |
| | | .like(StrUtil.isNotBlank(role.getRoleKey()), SysRole::getRoleKey, role.getRoleKey()) |
| | | .apply(Validator.isNotEmpty(params.get("beginTime")), |
| | | "date_format(create_time,'%y%m%d') >= date_format({0},'%y%m%d')", |
| | | params.get("beginTime")) |
| | | .apply(Validator.isNotEmpty(params.get("endTime")), |
| | | "date_format(create_time,'%y%m%d') <= date_format({0},'%y%m%d')", |
| | | params.get("endTime")) |
| | | .apply(dataScope != null, dataScope != null ? dataScope.toString() : null) |
| | | .orderByAsc(SysRole::getRoleSort)); |
| | | return baseMapper.selectRoleList(role); |
| | | } |
| | | |
| | | /** |
| | |
| | | <result property="updateTime" column="update_time"/> |
| | | </resultMap> |
| | | |
| | | <sql id="selectDeptVo"> |
| | | select d.dept_id, d.parent_id, d.ancestors, d.dept_name, d.order_num, d.leader, d.phone, d.email, d.status, d.del_flag, d.create_by, d.create_time |
| | | from sys_dept d |
| | | </sql> |
| | | |
| | | <select id="selectDeptList" parameterType="SysDept" resultMap="SysDeptResult"> |
| | | <include refid="selectDeptVo"/> |
| | | where d.del_flag = '0' |
| | | <if test="parentId != null and parentId != 0"> |
| | | AND parent_id = #{parentId} |
| | | </if> |
| | | <if test="deptName != null and deptName != ''"> |
| | | AND dept_name like concat('%', #{deptName}, '%') |
| | | </if> |
| | | <if test="status != null and status != ''"> |
| | | AND status = #{status} |
| | | </if> |
| | | <!-- 数据范围过滤 --> |
| | | ${params.dataScope} |
| | | order by d.parent_id, d.order_num |
| | | </select> |
| | | |
| | | <select id="selectDeptListByRoleId" resultType="Integer"> |
| | | select d.dept_id |
| | | from sys_dept d |
| | |
| | | left join sys_dept d on u.dept_id = d.dept_id |
| | | </sql> |
| | | |
| | | <select id="selectRoleList" parameterType="SysRole" resultMap="SysRoleResult"> |
| | | <include refid="selectRoleVo"/> |
| | | where r.del_flag = '0' |
| | | <if test="roleName != null and roleName != ''"> |
| | | AND r.role_name like concat('%', #{roleName}, '%') |
| | | </if> |
| | | <if test="status != null and status != ''"> |
| | | AND r.status = #{status} |
| | | </if> |
| | | <if test="roleKey != null and roleKey != ''"> |
| | | AND r.role_key like concat('%', #{roleKey}, '%') |
| | | </if> |
| | | <if test="params.beginTime != null and params.beginTime != ''"><!-- 开始时间检索 --> |
| | | and date_format(r.create_time,'%y%m%d') >= date_format(#{params.beginTime},'%y%m%d') |
| | | </if> |
| | | <if test="params.endTime != null and params.endTime != ''"><!-- 结束时间检索 --> |
| | | and date_format(r.create_time,'%y%m%d') <= date_format(#{params.endTime},'%y%m%d') |
| | | </if> |
| | | <!-- 数据范围过滤 --> |
| | | ${params.dataScope} |
| | | order by r.role_sort |
| | | </select> |
| | | |
| | | <select id="selectRolePermissionByUserId" parameterType="Long" resultMap="SysRoleResult"> |
| | | <include refid="selectRoleVo"/> |
| | | WHERE r.del_flag = '0' and ur.user_id = #{userId} |