serv\web- 多租户修改
This commit is contained in:
@@ -5,6 +5,7 @@ import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.xyzh.common.core.page.PageParam;
|
||||
import org.xyzh.common.dto.resource.TbBanner;
|
||||
import org.xyzh.common.vo.UserDeptRoleVO;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -21,24 +22,26 @@ public interface BannerMapper extends BaseMapper<TbBanner> {
|
||||
/**
|
||||
* @description 查询Banner列表
|
||||
* @param filter 过滤条件
|
||||
* @param userDeptRoles 用户部门角色列表
|
||||
* @return List<TbBanner> Banner列表
|
||||
* @author yslg
|
||||
* @since 2025-10-15
|
||||
*/
|
||||
List<TbBanner> selectBanners(TbBanner filter);
|
||||
List<TbBanner> selectBanners(@Param("filter") TbBanner filter, @Param("userDeptRoles") List<UserDeptRoleVO> userDeptRoles);
|
||||
|
||||
List<TbBanner> selectBannersLimit(@Param("filter") TbBanner filter, @Param("limit") Integer limit);
|
||||
List<TbBanner> selectBannersLimit(@Param("filter") TbBanner filter, @Param("limit") Integer limit, @Param("userDeptRoles") List<UserDeptRoleVO> userDeptRoles);
|
||||
|
||||
|
||||
/**
|
||||
* @description 分页查询Banner
|
||||
* @param filter 过滤条件
|
||||
* @param pageParam 分页参数
|
||||
* @param userDeptRoles 用户部门角色列表
|
||||
* @return List<TbBanner> Banner列表
|
||||
* @author yslg
|
||||
* @since 2025-10-15
|
||||
*/
|
||||
List<TbBanner> selectBannersPage(@Param("filter") TbBanner filter, @Param("pageParam") PageParam pageParam);
|
||||
List<TbBanner> selectBannersPage(@Param("filter") TbBanner filter, @Param("pageParam") PageParam pageParam, @Param("userDeptRoles") List<UserDeptRoleVO> userDeptRoles);
|
||||
|
||||
/**
|
||||
* @description 根据Banner ID查询Banner信息
|
||||
@@ -133,9 +136,10 @@ public interface BannerMapper extends BaseMapper<TbBanner> {
|
||||
/**
|
||||
* @description 统计Banner总数
|
||||
* @param filter 过滤条件
|
||||
* @param userDeptRoles 用户部门角色列表
|
||||
* @return long 总数
|
||||
* @author yslg
|
||||
* @since 2025-10-15
|
||||
*/
|
||||
long countBanners(@Param("filter") TbBanner filter);
|
||||
long countBanners(@Param("filter") TbBanner filter, @Param("userDeptRoles") List<UserDeptRoleVO> userDeptRoles);
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.xyzh.common.core.page.PageParam;
|
||||
import org.xyzh.common.dto.resource.TbResource;
|
||||
import org.xyzh.common.vo.UserDeptRoleVO;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -21,11 +22,12 @@ public interface ResourceMapper extends BaseMapper<TbResource> {
|
||||
/**
|
||||
* @description 查询资源列表
|
||||
* @param filter 过滤条件
|
||||
* @param userDeptRoles 用户部门角色列表
|
||||
* @return List<TbResource> 资源列表
|
||||
* @author yslg
|
||||
* @since 2025-10-15
|
||||
*/
|
||||
List<TbResource> selectResources(TbResource filter);
|
||||
List<TbResource> selectResources(@Param("filter") TbResource filter, @Param("userDeptRoles") List<UserDeptRoleVO> userDeptRoles);
|
||||
|
||||
/**
|
||||
* @description 根据资源ID查询资源信息
|
||||
@@ -149,20 +151,22 @@ public interface ResourceMapper extends BaseMapper<TbResource> {
|
||||
* @description 分页查询资源
|
||||
* @param filter 过滤条件
|
||||
* @param pageParam 分页参数
|
||||
* @param userDeptRoles 用户部门角色列表
|
||||
* @return List<TbResource> 资源列表
|
||||
* @author yslg
|
||||
* @since 2025-10-15
|
||||
*/
|
||||
List<TbResource> selectResourcesPage(@Param("filter") TbResource filter, @Param("pageParam") PageParam pageParam);
|
||||
List<TbResource> selectResourcesPage(@Param("filter") TbResource filter, @Param("pageParam") PageParam pageParam, @Param("userDeptRoles") List<UserDeptRoleVO> userDeptRoles);
|
||||
|
||||
/**
|
||||
* @description 统计资源总数
|
||||
* @param filter 过滤条件
|
||||
* @param userDeptRoles 用户部门角色列表
|
||||
* @return long 总数
|
||||
* @author yslg
|
||||
* @since 2025-10-15
|
||||
*/
|
||||
long countResources(TbResource filter);
|
||||
long countResources(@Param("filter") TbResource filter, @Param("userDeptRoles") List<UserDeptRoleVO> userDeptRoles);
|
||||
|
||||
/**
|
||||
* @description 更新资源收藏次数
|
||||
|
||||
@@ -5,6 +5,7 @@ import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.xyzh.common.core.page.PageParam;
|
||||
import org.xyzh.common.dto.resource.TbTag;
|
||||
import org.xyzh.common.vo.UserDeptRoleVO;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -21,11 +22,12 @@ public interface TagMapper extends BaseMapper<TbTag> {
|
||||
/**
|
||||
* @description 查询标签列表
|
||||
* @param filter 过滤条件
|
||||
* @param userDeptRoles 用户部门角色列表
|
||||
* @return List<TbTag> 标签列表
|
||||
* @author yslg
|
||||
* @since 2025-10-15
|
||||
*/
|
||||
List<TbTag> selectTags(TbTag filter);
|
||||
List<TbTag> selectTags(@Param("filter") TbTag filter, @Param("userDeptRoles") List<UserDeptRoleVO> userDeptRoles);
|
||||
|
||||
/**
|
||||
* @description 根据标签ID查询标签信息
|
||||
|
||||
@@ -17,6 +17,11 @@ import org.xyzh.common.dto.resource.TbBanner;
|
||||
import org.xyzh.common.utils.IDUtils;
|
||||
import org.xyzh.news.mapper.BannerMapper;
|
||||
import org.xyzh.api.news.banner.BannerService;
|
||||
import org.xyzh.api.system.permission.ResourcePermissionService;
|
||||
import org.xyzh.common.dto.user.TbSysUser;
|
||||
import org.xyzh.common.vo.UserDeptRoleVO;
|
||||
import org.xyzh.common.core.enums.ResourceType;
|
||||
import org.xyzh.system.utils.LoginUtil;
|
||||
|
||||
/**
|
||||
* @description 横幅服务实现类
|
||||
@@ -33,11 +38,16 @@ public class NCBannerServiceImpl implements BannerService {
|
||||
@Autowired
|
||||
private BannerMapper bannerMapper;
|
||||
|
||||
@Autowired
|
||||
private ResourcePermissionService resourcePermissionService;
|
||||
|
||||
@Override
|
||||
public ResultDomain<TbBanner> getBannerList(TbBanner filter) {
|
||||
ResultDomain<TbBanner> resultDomain = new ResultDomain<>();
|
||||
|
||||
List<TbBanner> list = bannerMapper.selectBanners(filter);
|
||||
// 获取当前用户的部门角色
|
||||
List<UserDeptRoleVO> userDeptRoles = LoginUtil.getCurrentDeptRole();
|
||||
List<TbBanner> list = bannerMapper.selectBanners(filter, userDeptRoles);
|
||||
resultDomain.success("获取横幅列表成功", list);
|
||||
return resultDomain;
|
||||
}
|
||||
@@ -45,9 +55,11 @@ public class NCBannerServiceImpl implements BannerService {
|
||||
@Override
|
||||
public ResultDomain<TbBanner> getBannerPage(PageParam pageParam,TbBanner filter) {
|
||||
ResultDomain<TbBanner> resultDomain = new ResultDomain<>();
|
||||
List<TbBanner> list = bannerMapper.selectBannersPage(filter, pageParam);
|
||||
// 获取当前用户的部门角色
|
||||
List<UserDeptRoleVO> userDeptRoles = LoginUtil.getCurrentDeptRole();
|
||||
List<TbBanner> list = bannerMapper.selectBannersPage(filter, pageParam, userDeptRoles);
|
||||
PageDomain<TbBanner> pageDomain = new PageDomain<>();
|
||||
int total = (int)bannerMapper.countBanners(filter);
|
||||
int total = (int)bannerMapper.countBanners(filter, userDeptRoles);
|
||||
pageParam.setTotalElements(total);
|
||||
pageParam.setTotalPages( (int)Math.ceil((double)total / pageParam.getPageSize()));
|
||||
pageDomain.setDataList(list);
|
||||
@@ -100,6 +112,23 @@ public class NCBannerServiceImpl implements BannerService {
|
||||
int result = bannerMapper.insertBanner(banner);
|
||||
if (result > 0) {
|
||||
logger.info("创建横幅成功: {}", banner.getTitle());
|
||||
|
||||
// 创建横幅资源权限
|
||||
try {
|
||||
List<UserDeptRoleVO> userDeptRoles = LoginUtil.getCurrentDeptRole();
|
||||
if (userDeptRoles != null && !userDeptRoles.isEmpty()) {
|
||||
// 使用用户的第一个部门角色创建权限
|
||||
resourcePermissionService.createResourcePermission(
|
||||
ResourceType.BANNER.getCode(),
|
||||
banner.getBannerID(),
|
||||
userDeptRoles.get(0)
|
||||
);
|
||||
logger.info("创建横幅权限成功: {}", banner.getBannerID());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
logger.error("创建横幅权限异常,但不影响横幅创建: {}", e.getMessage(), e);
|
||||
}
|
||||
|
||||
resultDomain.success("创建横幅成功", banner);
|
||||
return resultDomain;
|
||||
} else {
|
||||
@@ -363,8 +392,9 @@ public class NCBannerServiceImpl implements BannerService {
|
||||
ResultDomain<TbBanner> resultDomain = new ResultDomain<>();
|
||||
TbBanner filter = new TbBanner();
|
||||
filter.setStatus(1);
|
||||
|
||||
List<TbBanner> list = bannerMapper.selectBannersLimit(filter, 5);
|
||||
// 获取当前用户的部门角色
|
||||
List<UserDeptRoleVO> userDeptRoles = LoginUtil.getCurrentDeptRole();
|
||||
List<TbBanner> list = bannerMapper.selectBannersLimit(filter, 5, userDeptRoles);
|
||||
resultDomain.success("获取首页横幅列表成功", list);
|
||||
return resultDomain;
|
||||
}
|
||||
|
||||
@@ -22,6 +22,9 @@ import org.xyzh.news.mapper.ResourceTagMapper;
|
||||
import org.xyzh.system.utils.LoginUtil;
|
||||
import org.xyzh.api.news.resource.ResourceService;
|
||||
import org.xyzh.api.usercenter.collection.UserCollectionService;
|
||||
import org.xyzh.api.system.permission.ResourcePermissionService;
|
||||
import org.xyzh.common.vo.UserDeptRoleVO;
|
||||
import org.xyzh.common.core.enums.ResourceType;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
@@ -49,6 +52,9 @@ public class NCResourceServiceImpl implements ResourceService {
|
||||
@Autowired
|
||||
private UserCollectionService userCollectionService;
|
||||
|
||||
@Autowired
|
||||
private ResourcePermissionService resourcePermissionService;
|
||||
|
||||
@Override
|
||||
public ResultDomain<TbResource> getResourceList(TbResource filter) {
|
||||
ResultDomain<TbResource> resultDomain = new ResultDomain<>();
|
||||
@@ -56,7 +62,9 @@ public class NCResourceServiceImpl implements ResourceService {
|
||||
if (filter == null) {
|
||||
filter = new TbResource();
|
||||
}
|
||||
List<TbResource> list = resourceMapper.selectResources(filter);
|
||||
// 获取当前用户的部门角色
|
||||
List<UserDeptRoleVO> userDeptRoles = LoginUtil.getCurrentDeptRole();
|
||||
List<TbResource> list = resourceMapper.selectResources(filter, userDeptRoles);
|
||||
resultDomain.success("获取资源列表成功", list);
|
||||
return resultDomain;
|
||||
} catch (Exception e) {
|
||||
@@ -74,8 +82,10 @@ public class NCResourceServiceImpl implements ResourceService {
|
||||
filter = new TbResource();
|
||||
}
|
||||
|
||||
List<TbResource> list = resourceMapper.selectResourcesPage(filter, pageParam);
|
||||
long total = resourceMapper.countResources(filter);
|
||||
// 获取当前用户的部门角色
|
||||
List<UserDeptRoleVO> userDeptRoles = LoginUtil.getCurrentDeptRole();
|
||||
List<TbResource> list = resourceMapper.selectResourcesPage(filter, pageParam, userDeptRoles);
|
||||
long total = resourceMapper.countResources(filter, userDeptRoles);
|
||||
pageParam.setTotalElements(total);
|
||||
pageParam.setTotalPages((int) Math.ceil((double) total / pageParam.getPageSize()));
|
||||
resultDomain.success("获取资源分页成功", new PageDomain<TbResource>(pageParam, list));
|
||||
@@ -192,6 +202,23 @@ public class NCResourceServiceImpl implements ResourceService {
|
||||
|
||||
if (result > 0) {
|
||||
logger.info("创建资源成功: {}", resourceVO.getResource().getTitle());
|
||||
|
||||
// 创建资源权限
|
||||
try {
|
||||
List<UserDeptRoleVO> userDeptRoles = LoginUtil.getCurrentDeptRole();
|
||||
if (userDeptRoles != null && !userDeptRoles.isEmpty()) {
|
||||
// 使用用户的第一个部门角色创建权限
|
||||
resourcePermissionService.createResourcePermission(
|
||||
ResourceType.NEWS.getCode(),
|
||||
resourceVO.getResource().getResourceID(),
|
||||
userDeptRoles.get(0)
|
||||
);
|
||||
logger.info("创建资源权限成功: {}", resourceVO.getResource().getResourceID());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
logger.error("创建资源权限异常,但不影响资源创建: {}", e.getMessage(), e);
|
||||
}
|
||||
|
||||
resultDomain.success("创建资源成功", resourceVO);
|
||||
return resultDomain;
|
||||
} else {
|
||||
@@ -679,7 +706,9 @@ public class NCResourceServiceImpl implements ResourceService {
|
||||
filter.setIsRecommend(true);
|
||||
filter.setStatus(1); // 只查询已发布的
|
||||
|
||||
List<TbResource> list = resourceMapper.selectResources(filter);
|
||||
// 获取当前用户的部门角色
|
||||
List<UserDeptRoleVO> userDeptRoles = LoginUtil.getCurrentDeptRole();
|
||||
List<TbResource> list = resourceMapper.selectResources(filter, userDeptRoles);
|
||||
|
||||
// 如果指定了limit,截取列表
|
||||
if (limit != null && limit > 0 && list != null && list.size() > limit) {
|
||||
@@ -704,7 +733,9 @@ public class NCResourceServiceImpl implements ResourceService {
|
||||
filter.setIsBanner(true);
|
||||
filter.setStatus(1); // 只查询已发布的
|
||||
|
||||
List<TbResource> list = resourceMapper.selectResources(filter);
|
||||
// 获取当前用户的部门角色
|
||||
List<UserDeptRoleVO> userDeptRoles = LoginUtil.getCurrentDeptRole();
|
||||
List<TbResource> list = resourceMapper.selectResources(filter, userDeptRoles);
|
||||
|
||||
// 如果指定了limit,截取列表
|
||||
if (limit != null && limit > 0 && list != null && list.size() > limit) {
|
||||
|
||||
@@ -19,6 +19,9 @@ import org.xyzh.news.mapper.ResourceTagMapper;
|
||||
import org.xyzh.news.mapper.TagMapper;
|
||||
import org.xyzh.system.utils.LoginUtil;
|
||||
import org.xyzh.api.news.tag.TagService;
|
||||
import org.xyzh.api.system.permission.ResourcePermissionService;
|
||||
import org.xyzh.common.vo.UserDeptRoleVO;
|
||||
import org.xyzh.common.core.enums.ResourceType;
|
||||
|
||||
/**
|
||||
* @description 标签服务实现类
|
||||
@@ -38,6 +41,9 @@ public class NCTagServiceImpl implements TagService {
|
||||
@Autowired
|
||||
private ResourceTagMapper resourceTagMapper;
|
||||
|
||||
@Autowired
|
||||
private ResourcePermissionService resourcePermissionService;
|
||||
|
||||
// ----------------标签管理相关--------------------------------
|
||||
|
||||
@Override
|
||||
@@ -74,6 +80,23 @@ public class NCTagServiceImpl implements TagService {
|
||||
int result = tagMapper.insertTag(tag);
|
||||
if (result > 0) {
|
||||
logger.info("创建标签成功: {}", tag.getName());
|
||||
|
||||
// 创建标签资源权限
|
||||
try {
|
||||
List<UserDeptRoleVO> userDeptRoles = LoginUtil.getCurrentDeptRole();
|
||||
if (userDeptRoles != null && !userDeptRoles.isEmpty()) {
|
||||
// 使用用户的第一个部门角色创建权限
|
||||
resourcePermissionService.createResourcePermission(
|
||||
ResourceType.TAG.getCode(),
|
||||
tag.getTagID(),
|
||||
userDeptRoles.get(0)
|
||||
);
|
||||
logger.info("创建标签权限成功: {}", tag.getTagID());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
logger.error("创建标签权限异常,但不影响标签创建: {}", e.getMessage(), e);
|
||||
}
|
||||
|
||||
resultDomain.success("创建标签成功", tag);
|
||||
return resultDomain;
|
||||
} else {
|
||||
@@ -195,7 +218,9 @@ public class NCTagServiceImpl implements TagService {
|
||||
public ResultDomain<TbTag> getAllTags() {
|
||||
ResultDomain<TbTag> resultDomain = new ResultDomain<>();
|
||||
try {
|
||||
List<TbTag> tags = tagMapper.selectTags(new TbTag());
|
||||
// 获取当前用户的部门角色
|
||||
List<UserDeptRoleVO> userDeptRoles = LoginUtil.getCurrentDeptRole();
|
||||
List<TbTag> tags = tagMapper.selectTags(new TbTag(), userDeptRoles);
|
||||
resultDomain.success("查询成功", tags);
|
||||
return resultDomain;
|
||||
} catch (Exception e) {
|
||||
@@ -216,7 +241,9 @@ public class NCTagServiceImpl implements TagService {
|
||||
|
||||
TbTag filter = new TbTag();
|
||||
filter.setName(name);
|
||||
List<TbTag> tags = tagMapper.selectTags(filter);
|
||||
// 获取当前用户的部门角色
|
||||
List<UserDeptRoleVO> userDeptRoles = LoginUtil.getCurrentDeptRole();
|
||||
List<TbTag> tags = tagMapper.selectTags(filter, userDeptRoles);
|
||||
|
||||
resultDomain.success("查询成功", tags);
|
||||
return resultDomain;
|
||||
|
||||
@@ -69,21 +69,83 @@
|
||||
</where>
|
||||
</sql>
|
||||
|
||||
<!-- selectBanners -->
|
||||
<!-- 权限过滤条件(基于dept_path的高效继承) -->
|
||||
<sql id="Permission_Filter">
|
||||
INNER JOIN tb_resource_permission rp ON b.banner_id = rp.resource_id
|
||||
AND rp.resource_type = 8
|
||||
AND rp.deleted = 0
|
||||
AND rp.can_read = 1
|
||||
AND (
|
||||
-- 全局权限:所有用户可访问
|
||||
(rp.dept_id IS NULL AND rp.role_id IS NULL)
|
||||
<if test="userDeptRoles != null and userDeptRoles.size() > 0">
|
||||
OR EXISTS (
|
||||
SELECT 1
|
||||
FROM (
|
||||
<foreach collection="userDeptRoles" item="udr" separator=" UNION ALL ">
|
||||
SELECT #{udr.deptID} AS dept_id, #{udr.deptPath} AS dept_path, #{udr.roleID} AS role_id
|
||||
</foreach>
|
||||
) user_roles
|
||||
LEFT JOIN tb_sys_dept perm_dept ON perm_dept.dept_id = rp.dept_id AND perm_dept.deleted = 0
|
||||
WHERE
|
||||
-- 部门级权限:当前部门或父部门(通过dept_path判断继承关系)
|
||||
(rp.role_id IS NULL AND rp.dept_id IS NOT NULL
|
||||
AND user_roles.dept_path LIKE CONCAT(perm_dept.dept_path, '%'))
|
||||
-- 角色级权限:跨部门的角色权限
|
||||
OR (rp.dept_id IS NULL AND rp.role_id = user_roles.role_id)
|
||||
-- 精确权限:特定部门的特定角色
|
||||
OR (rp.dept_id = user_roles.dept_id AND rp.role_id = user_roles.role_id)
|
||||
)
|
||||
</if>
|
||||
)
|
||||
</sql>
|
||||
|
||||
<!-- selectBanners - 添加权限过滤 -->
|
||||
<select id="selectBanners" resultMap="BaseResultMap">
|
||||
SELECT
|
||||
<include refid="Base_Column_List"/>
|
||||
FROM tb_banner
|
||||
<include refid="Where_Clause"/>
|
||||
ORDER BY order_num ASC, create_time DESC
|
||||
SELECT DISTINCT b.*
|
||||
FROM tb_banner b
|
||||
<include refid="Permission_Filter"/>
|
||||
WHERE b.deleted = 0
|
||||
<if test="filter.bannerID != null and filter.bannerID != ''">
|
||||
AND b.banner_id = #{filter.bannerID}
|
||||
</if>
|
||||
<if test="filter.title != null and filter.title != ''">
|
||||
AND b.title LIKE CONCAT('%', #{filter.title}, '%')
|
||||
</if>
|
||||
<if test="filter.linkType != null">
|
||||
AND b.link_type = #{filter.linkType}
|
||||
</if>
|
||||
<if test="filter.linkID != null and filter.linkID != ''">
|
||||
AND b.link_id = #{filter.linkID}
|
||||
</if>
|
||||
<if test="filter.status != null">
|
||||
AND b.status = #{filter.status}
|
||||
</if>
|
||||
ORDER BY b.order_num ASC, b.create_time DESC
|
||||
</select>
|
||||
|
||||
<!-- selectBannersLimit - 添加权限过滤 -->
|
||||
<select id="selectBannersLimit" resultMap="BaseResultMap">
|
||||
SELECT
|
||||
<include refid="Base_Column_List"/>
|
||||
FROM tb_banner
|
||||
<include refid="Filter_Clause"/>
|
||||
ORDER BY order_num ASC, create_time DESC
|
||||
SELECT DISTINCT b.*
|
||||
FROM tb_banner b
|
||||
<include refid="Permission_Filter"/>
|
||||
WHERE b.deleted = 0
|
||||
<if test="filter.bannerID != null and filter.bannerID != ''">
|
||||
AND b.banner_id = #{filter.bannerID}
|
||||
</if>
|
||||
<if test="filter.title != null and filter.title != ''">
|
||||
AND b.title LIKE CONCAT('%', #{filter.title}, '%')
|
||||
</if>
|
||||
<if test="filter.linkType != null">
|
||||
AND b.link_type = #{filter.linkType}
|
||||
</if>
|
||||
<if test="filter.linkID != null and filter.linkID != ''">
|
||||
AND b.link_id = #{filter.linkID}
|
||||
</if>
|
||||
<if test="filter.status != null">
|
||||
AND b.status = #{filter.status}
|
||||
</if>
|
||||
ORDER BY b.order_num ASC, b.create_time DESC
|
||||
LIMIT #{limit}
|
||||
</select>
|
||||
|
||||
@@ -218,20 +280,56 @@
|
||||
</delete>
|
||||
|
||||
<!-- 分页查询Banner -->
|
||||
<!-- selectBannersPage - 添加权限过滤 -->
|
||||
<select id="selectBannersPage" resultMap="BaseResultMap">
|
||||
SELECT
|
||||
<include refid="Base_Column_List" />
|
||||
FROM tb_banner
|
||||
<include refid="Filter_Clause" />
|
||||
ORDER BY order_num ASC, create_time DESC
|
||||
SELECT DISTINCT b.*
|
||||
FROM tb_banner b
|
||||
<include refid="Permission_Filter"/>
|
||||
WHERE b.deleted = 0
|
||||
<if test="filter != null">
|
||||
<if test="filter.bannerID != null and filter.bannerID != ''">
|
||||
AND b.banner_id = #{filter.bannerID}
|
||||
</if>
|
||||
<if test="filter.title != null and filter.title != ''">
|
||||
AND b.title LIKE CONCAT('%', #{filter.title}, '%')
|
||||
</if>
|
||||
<if test="filter.linkType != null">
|
||||
AND b.link_type = #{filter.linkType}
|
||||
</if>
|
||||
<if test="filter.linkID != null and filter.linkID != ''">
|
||||
AND b.link_id = #{filter.linkID}
|
||||
</if>
|
||||
<if test="filter.status != null">
|
||||
AND b.status = #{filter.status}
|
||||
</if>
|
||||
</if>
|
||||
ORDER BY b.order_num ASC, b.create_time DESC
|
||||
LIMIT #{pageParam.pageSize} OFFSET #{pageParam.offset}
|
||||
</select>
|
||||
|
||||
<!-- 统计Banner总数 -->
|
||||
<!-- 统计Banner总数 - 添加权限过滤 -->
|
||||
<select id="countBanners" resultType="long">
|
||||
SELECT COUNT(1)
|
||||
FROM tb_banner
|
||||
<include refid="Filter_Clause" />
|
||||
SELECT COUNT(DISTINCT b.id)
|
||||
FROM tb_banner b
|
||||
<include refid="Permission_Filter"/>
|
||||
WHERE b.deleted = 0
|
||||
<if test="filter != null">
|
||||
<if test="filter.bannerID != null and filter.bannerID != ''">
|
||||
AND b.banner_id = #{filter.bannerID}
|
||||
</if>
|
||||
<if test="filter.title != null and filter.title != ''">
|
||||
AND b.title LIKE CONCAT('%', #{filter.title}, '%')
|
||||
</if>
|
||||
<if test="filter.linkType != null">
|
||||
AND b.link_type = #{filter.linkType}
|
||||
</if>
|
||||
<if test="filter.linkID != null and filter.linkID != ''">
|
||||
AND b.link_id = #{filter.linkID}
|
||||
</if>
|
||||
<if test="filter.status != null">
|
||||
AND b.status = #{filter.status}
|
||||
</if>
|
||||
</if>
|
||||
</select>
|
||||
|
||||
</mapper>
|
||||
|
||||
@@ -62,13 +62,62 @@
|
||||
</where>
|
||||
</sql>
|
||||
|
||||
<!-- selectResources -->
|
||||
<!-- 权限过滤条件(基于dept_path的高效继承) -->
|
||||
<sql id="Permission_Filter">
|
||||
INNER JOIN tb_resource_permission rp ON r.resource_id = rp.resource_id
|
||||
AND rp.resource_type = 1
|
||||
AND rp.deleted = 0
|
||||
AND rp.can_read = 1
|
||||
AND (
|
||||
-- 全局权限:所有用户可访问
|
||||
(rp.dept_id IS NULL AND rp.role_id IS NULL)
|
||||
<if test="userDeptRoles != null and userDeptRoles.size() > 0">
|
||||
OR EXISTS (
|
||||
SELECT 1
|
||||
FROM (
|
||||
<foreach collection="userDeptRoles" item="udr" separator=" UNION ALL ">
|
||||
SELECT #{udr.deptID} AS dept_id, #{udr.deptPath} AS dept_path, #{udr.roleID} AS role_id
|
||||
</foreach>
|
||||
) user_roles
|
||||
LEFT JOIN tb_sys_dept perm_dept ON perm_dept.dept_id = rp.dept_id AND perm_dept.deleted = 0
|
||||
WHERE
|
||||
-- 部门级权限:当前部门或父部门(通过dept_path判断继承关系)
|
||||
(rp.role_id IS NULL AND rp.dept_id IS NOT NULL
|
||||
AND user_roles.dept_path LIKE CONCAT(perm_dept.dept_path, '%'))
|
||||
-- 角色级权限:跨部门的角色权限
|
||||
OR (rp.dept_id IS NULL AND rp.role_id = user_roles.role_id)
|
||||
-- 精确权限:特定部门的特定角色
|
||||
OR (rp.dept_id = user_roles.dept_id AND rp.role_id = user_roles.role_id)
|
||||
)
|
||||
</if>
|
||||
)
|
||||
</sql>
|
||||
|
||||
<!-- selectResources - 添加权限过滤 -->
|
||||
<select id="selectResources" resultMap="BaseResultMap">
|
||||
SELECT
|
||||
<include refid="Base_Column_List"/>
|
||||
FROM tb_resource
|
||||
<include refid="Where_Clause"/>
|
||||
ORDER BY publish_time DESC, create_time DESC
|
||||
SELECT DISTINCT r.*
|
||||
FROM tb_resource r
|
||||
<include refid="Permission_Filter"/>
|
||||
WHERE r.deleted = 0
|
||||
<if test="filter.title != null and filter.title != ''">
|
||||
AND r.title LIKE CONCAT('%', #{filter.title}, '%')
|
||||
</if>
|
||||
<if test="filter.tagID != null and filter.tagID != ''">
|
||||
AND r.tag_id = #{filter.tagID}
|
||||
</if>
|
||||
<if test="filter.author != null and filter.author != ''">
|
||||
AND r.author LIKE CONCAT('%', #{filter.author}, '%')
|
||||
</if>
|
||||
<if test="filter.status != null">
|
||||
AND r.status = #{filter.status}
|
||||
</if>
|
||||
<if test="filter.isRecommend != null">
|
||||
AND r.is_recommend = #{filter.isRecommend}
|
||||
</if>
|
||||
<if test="filter.isBanner != null">
|
||||
AND r.is_banner = #{filter.isBanner}
|
||||
</if>
|
||||
ORDER BY r.publish_time DESC, r.create_time DESC
|
||||
</select>
|
||||
|
||||
<!-- 根据资源ID查询资源信息 -->
|
||||
@@ -266,41 +315,58 @@
|
||||
</foreach>
|
||||
</delete>
|
||||
|
||||
<!-- 分页查询资源 -->
|
||||
<!-- 分页查询资源 - 添加权限过滤 -->
|
||||
<select id="selectResourcesPage" resultMap="BaseResultMap">
|
||||
SELECT
|
||||
<include refid="Base_Column_List" />
|
||||
FROM tb_resource
|
||||
<where>
|
||||
deleted = 0
|
||||
SELECT DISTINCT r.*
|
||||
FROM tb_resource r
|
||||
<include refid="Permission_Filter"/>
|
||||
WHERE r.deleted = 0
|
||||
<if test="filter.title != null and filter.title != ''">
|
||||
AND title LIKE CONCAT('%', #{filter.title}, '%')
|
||||
AND r.title LIKE CONCAT('%', #{filter.title}, '%')
|
||||
</if>
|
||||
<if test="filter.tagID != null and filter.tagID != ''">
|
||||
AND tag_id = #{filter.tagID}
|
||||
AND r.tag_id = #{filter.tagID}
|
||||
</if>
|
||||
<if test="filter.author != null and filter.author != ''">
|
||||
AND author LIKE CONCAT('%', #{filter.author}, '%')
|
||||
AND r.author LIKE CONCAT('%', #{filter.author}, '%')
|
||||
</if>
|
||||
<if test="filter.status != null">
|
||||
AND status = #{filter.status}
|
||||
AND r.status = #{filter.status}
|
||||
</if>
|
||||
<if test="filter.isRecommend != null">
|
||||
AND is_recommend = #{filter.isRecommend}
|
||||
AND r.is_recommend = #{filter.isRecommend}
|
||||
</if>
|
||||
<if test="filter.isBanner != null">
|
||||
AND is_banner = #{filter.isBanner}
|
||||
AND r.is_banner = #{filter.isBanner}
|
||||
</if>
|
||||
</where>
|
||||
ORDER BY publish_time DESC, create_time DESC
|
||||
ORDER BY r.publish_time DESC, r.create_time DESC
|
||||
LIMIT #{pageParam.pageSize} OFFSET #{pageParam.offset}
|
||||
</select>
|
||||
|
||||
<!-- 统计资源总数 -->
|
||||
<!-- 统计资源总数 - 添加权限过滤 -->
|
||||
<select id="countResources" resultType="long">
|
||||
SELECT COUNT(1)
|
||||
FROM tb_resource
|
||||
<include refid="Where_Clause" />
|
||||
SELECT COUNT(DISTINCT r.id)
|
||||
FROM tb_resource r
|
||||
<include refid="Permission_Filter"/>
|
||||
WHERE r.deleted = 0
|
||||
<if test="filter.title != null and filter.title != ''">
|
||||
AND r.title LIKE CONCAT('%', #{filter.title}, '%')
|
||||
</if>
|
||||
<if test="filter.tagID != null and filter.tagID != ''">
|
||||
AND r.tag_id = #{filter.tagID}
|
||||
</if>
|
||||
<if test="filter.author != null and filter.author != ''">
|
||||
AND r.author LIKE CONCAT('%', #{filter.author}, '%')
|
||||
</if>
|
||||
<if test="filter.status != null">
|
||||
AND r.status = #{filter.status}
|
||||
</if>
|
||||
<if test="filter.isRecommend != null">
|
||||
AND r.is_recommend = #{filter.isRecommend}
|
||||
</if>
|
||||
<if test="filter.isBanner != null">
|
||||
AND r.is_banner = #{filter.isBanner}
|
||||
</if>
|
||||
</select>
|
||||
|
||||
<!-- updateResourceCollectCount -->
|
||||
@@ -318,4 +384,6 @@
|
||||
SET view_count = view_count + 1
|
||||
WHERE resource_id = #{resourceID}
|
||||
</update>
|
||||
|
||||
|
||||
</mapper>
|
||||
|
||||
@@ -43,13 +43,56 @@
|
||||
</where>
|
||||
</sql>
|
||||
|
||||
<!-- selectTags -->
|
||||
<!-- 权限过滤条件(基于dept_path的高效继承) -->
|
||||
<sql id="Permission_Filter">
|
||||
INNER JOIN tb_resource_permission rp ON t.tag_id = rp.resource_id
|
||||
AND rp.resource_type = 9
|
||||
AND rp.deleted = 0
|
||||
AND rp.can_read = 1
|
||||
AND (
|
||||
-- 全局权限:所有用户可访问
|
||||
(rp.dept_id IS NULL AND rp.role_id IS NULL)
|
||||
<if test="userDeptRoles != null and userDeptRoles.size() > 0">
|
||||
OR EXISTS (
|
||||
SELECT 1
|
||||
FROM (
|
||||
<foreach collection="userDeptRoles" item="udr" separator=" UNION ALL ">
|
||||
SELECT #{udr.deptID} AS dept_id, #{udr.deptPath} AS dept_path, #{udr.roleID} AS role_id
|
||||
</foreach>
|
||||
) user_roles
|
||||
LEFT JOIN tb_sys_dept perm_dept ON perm_dept.dept_id = rp.dept_id AND perm_dept.deleted = 0
|
||||
WHERE
|
||||
-- 部门级权限:当前部门或父部门(通过dept_path判断继承关系)
|
||||
(rp.role_id IS NULL AND rp.dept_id IS NOT NULL
|
||||
AND user_roles.dept_path LIKE CONCAT(perm_dept.dept_path, '%'))
|
||||
-- 角色级权限:跨部门的角色权限
|
||||
OR (rp.dept_id IS NULL AND rp.role_id = user_roles.role_id)
|
||||
-- 精确权限:特定部门的特定角色
|
||||
OR (rp.dept_id = user_roles.dept_id AND rp.role_id = user_roles.role_id)
|
||||
)
|
||||
</if>
|
||||
)
|
||||
</sql>
|
||||
|
||||
<!-- selectTags - 添加权限过滤 -->
|
||||
<select id="selectTags" resultMap="BaseResultMap">
|
||||
SELECT
|
||||
<include refid="Base_Column_List"/>
|
||||
FROM tb_tag
|
||||
<include refid="Where_Clause"/>
|
||||
ORDER BY create_time DESC
|
||||
SELECT DISTINCT t.*
|
||||
FROM tb_tag t
|
||||
<include refid="Permission_Filter"/>
|
||||
WHERE t.deleted = 0
|
||||
<if test="filter.tagID != null and filter.tagID != ''">
|
||||
AND t.tag_id = #{filter.tagID}
|
||||
</if>
|
||||
<if test="filter.name != null and filter.name != ''">
|
||||
AND t.name LIKE CONCAT('%', #{filter.name}, '%')
|
||||
</if>
|
||||
<if test="filter.color != null and filter.color != ''">
|
||||
AND t.color = #{filter.color}
|
||||
</if>
|
||||
<if test="filter.tagType != null">
|
||||
AND t.tag_type = #{filter.tagType}
|
||||
</if>
|
||||
ORDER BY t.create_time DESC
|
||||
</select>
|
||||
|
||||
<!-- 根据标签ID查询标签信息 -->
|
||||
|
||||
Reference in New Issue
Block a user