Files
schoolNews/schoolNewsServ/news/src/main/resources/mapper/BannerMapper.xml

336 lines
13 KiB
XML
Raw Normal View History

2025-10-15 13:11:19 +08:00
<?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">
<mapper namespace="org.xyzh.news.mapper.BannerMapper">
<!-- 基础结果映射 -->
<resultMap id="BaseResultMap" type="org.xyzh.common.dto.resource.TbBanner">
<id column="id" property="id" jdbcType="VARCHAR"/>
2025-10-28 19:04:35 +08:00
<result column="banner_id" property="bannerID" jdbcType="VARCHAR"/>
2025-10-15 13:11:19 +08:00
<result column="title" property="title" jdbcType="VARCHAR"/>
<result column="image_url" property="imageUrl" jdbcType="VARCHAR"/>
<result column="link_type" property="linkType" jdbcType="INTEGER"/>
<result column="link_id" property="linkID" jdbcType="VARCHAR"/>
<result column="link_url" property="linkUrl" jdbcType="VARCHAR"/>
<result column="order_num" property="orderNum" jdbcType="INTEGER"/>
<result column="status" property="status" jdbcType="INTEGER"/>
<result column="creator" property="creator" jdbcType="VARCHAR"/>
<result column="updater" property="updater" jdbcType="VARCHAR"/>
<result column="create_time" property="createTime" jdbcType="TIMESTAMP"/>
<result column="update_time" property="updateTime" jdbcType="TIMESTAMP"/>
<result column="delete_time" property="deleteTime" jdbcType="TIMESTAMP"/>
<result column="deleted" property="deleted" jdbcType="BOOLEAN"/>
</resultMap>
<!-- 基础字段 -->
<sql id="Base_Column_List">
2025-10-28 19:04:35 +08:00
id, banner_id, title, image_url, link_type, link_id, link_url, order_num, status,
2025-10-15 13:11:19 +08:00
creator, updater, create_time, update_time, delete_time, deleted
</sql>
<!-- 通用条件 -->
<sql id="Where_Clause">
<where>
deleted = 0
2025-10-28 19:04:35 +08:00
<if test="bannerID != null and bannerID != ''">
AND banner_id = #{bannerID}
</if>
2025-10-15 13:11:19 +08:00
<if test="title != null and title != ''">
AND title LIKE CONCAT('%', #{title}, '%')
</if>
<if test="linkType != null">
AND link_type = #{linkType}
</if>
<if test="linkID != null and linkID != ''">
AND link_id = #{linkID}
</if>
<if test="status != null">
AND status = #{status}
</if>
</where>
</sql>
2025-10-28 19:04:35 +08:00
<sql id="Filter_Clause">
<where>
deleted = 0
<if test="filter.bannerID != null and filter.bannerID != ''">
AND banner_id = #{filter.bannerID}
</if>
<if test="filter.title != null and filter.title != ''">
AND title LIKE CONCAT('%', #{filter.title}, '%')
</if>
<if test="filter.linkType != null">
AND link_type = #{filter.linkType}
</if>
<if test="filter.linkID != null and filter.linkID != ''">
AND link_id = #{filter.linkID}
</if>
<if test="filter.status != null">
AND status = #{filter.status}
</if>
</where>
</sql>
2025-10-15 13:11:19 +08:00
2025-10-29 19:08:22 +08:00
<!-- 权限过滤条件基于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 - 添加权限过滤 -->
2025-10-15 13:11:19 +08:00
<select id="selectBanners" resultMap="BaseResultMap">
2025-10-29 19:08:22 +08:00
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
2025-10-15 13:11:19 +08:00
</select>
2025-10-29 19:08:22 +08:00
<!-- selectBannersLimit - 添加权限过滤 -->
2025-10-28 19:04:35 +08:00
<select id="selectBannersLimit" resultMap="BaseResultMap">
2025-10-29 19:08:22 +08:00
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
2025-10-28 19:04:35 +08:00
LIMIT #{limit}
</select>
2025-10-16 14:31:56 +08:00
<!-- 根据Banner ID查询Banner信息 -->
<select id="selectByBannerId" resultMap="BaseResultMap">
SELECT
<include refid="Base_Column_List" />
FROM tb_banner
2025-10-28 19:04:35 +08:00
WHERE banner_id = #{bannerID} AND deleted = 0
2025-10-16 14:31:56 +08:00
</select>
<!-- 根据状态查询Banner列表 -->
<select id="selectByStatus" resultMap="BaseResultMap">
SELECT
<include refid="Base_Column_List" />
FROM tb_banner
WHERE status = #{status} AND deleted = 0
ORDER BY order_num ASC, create_time DESC
</select>
<!-- 根据位置查询Banner列表 -->
<select id="selectByPosition" resultMap="BaseResultMap">
SELECT
<include refid="Base_Column_List" />
FROM tb_banner
WHERE link_type = #{position} AND deleted = 0
ORDER BY order_num ASC, create_time DESC
</select>
<!-- 查询有效的Banner列表按排序 -->
<select id="selectActiveBanners" resultMap="BaseResultMap">
SELECT
<include refid="Base_Column_List" />
FROM tb_banner
WHERE status = 1 AND deleted = 0
ORDER BY order_num ASC, create_time DESC
</select>
<!-- 检查Banner标题是否存在 -->
<select id="countByTitle" resultType="int">
SELECT COUNT(1)
FROM tb_banner
WHERE title = #{title} AND deleted = 0
<if test="excludeId != null and excludeId != ''">
2025-10-28 19:04:35 +08:00
AND banner_id != #{excludeId}
2025-10-16 14:31:56 +08:00
</if>
</select>
<!-- 插入Banner -->
<insert id="insertBanner" parameterType="org.xyzh.common.dto.resource.TbBanner">
INSERT INTO tb_banner (
2025-10-28 19:04:35 +08:00
id, banner_id, title, image_url, link_type, link_id, link_url, order_num, status,
creator, create_time
2025-10-16 14:31:56 +08:00
) VALUES (
2025-10-28 19:04:35 +08:00
#{id}, #{bannerID}, #{title}, #{imageUrl}, #{linkType}, #{linkID}, #{linkUrl}, #{orderNum}, #{status},
#{creator}, #{createTime}
2025-10-16 14:31:56 +08:00
)
</insert>
<!-- 更新Banner -->
<update id="updateBanner" parameterType="org.xyzh.common.dto.resource.TbBanner">
UPDATE tb_banner
<set>
2025-10-28 19:04:35 +08:00
<if test="bannerID != null and bannerID != ''">
banner_id = #{bannerID},
</if>
2025-10-16 14:31:56 +08:00
<if test="title != null and title != ''">
title = #{title},
</if>
<if test="imageUrl != null and imageUrl != ''">
image_url = #{imageUrl},
</if>
<if test="linkType != null">
link_type = #{linkType},
</if>
<if test="linkID != null and linkID != ''">
link_id = #{linkID},
</if>
<if test="linkUrl != null and linkUrl != ''">
link_url = #{linkUrl},
</if>
<if test="orderNum != null">
order_num = #{orderNum},
</if>
<if test="status != null">
status = #{status},
</if>
<if test="updater != null and updater != ''">
updater = #{updater},
</if>
<if test="updateTime != null">
update_time = #{updateTime},
</if>
<if test="deleteTime != null">
delete_time = #{deleteTime},
</if>
<if test="deleted != null">
deleted = #{deleted},
</if>
</set>
2025-10-28 19:04:35 +08:00
WHERE banner_id = #{bannerID}
2025-10-16 14:31:56 +08:00
</update>
<!-- 删除Banner -->
<delete id="deleteBanner" parameterType="org.xyzh.common.dto.resource.TbBanner">
DELETE FROM tb_banner
2025-10-28 19:04:35 +08:00
WHERE banner_id = #{bannerID}
2025-10-16 14:31:56 +08:00
</delete>
<!-- 批量插入Banner -->
<insert id="batchInsertBanners" parameterType="java.util.List">
INSERT INTO tb_banner (
2025-10-28 19:04:35 +08:00
id, banner_id, title, image_url, link_type, link_id, link_url, order_num, status,
2025-10-16 14:31:56 +08:00
creator, updater, create_time, update_time, delete_time, deleted
) VALUES
<foreach collection="bannerList" item="item" separator=",">
(
2025-10-28 19:04:35 +08:00
#{item.id}, #{item.bannerID}, #{item.title}, #{item.imageUrl}, #{item.linkType}, #{item.linkID},
2025-10-16 14:31:56 +08:00
#{item.linkUrl}, #{item.orderNum}, #{item.status}, #{item.creator}, #{item.updater},
#{item.createTime}, #{item.updateTime}, #{item.deleteTime}, #{item.deleted}
)
</foreach>
</insert>
<!-- 批量删除Banner -->
<delete id="batchDeleteBanners">
DELETE FROM tb_banner
2025-10-28 19:04:35 +08:00
WHERE banner_id IN
<foreach collection="ids" item="bannerID" open="(" separator="," close=")">
#{bannerID}
2025-10-16 14:31:56 +08:00
</foreach>
</delete>
<!-- 分页查询Banner -->
2025-10-29 19:08:22 +08:00
<!-- selectBannersPage - 添加权限过滤 -->
2025-10-16 14:31:56 +08:00
<select id="selectBannersPage" resultMap="BaseResultMap">
2025-10-29 19:08:22 +08:00
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
2025-10-20 15:08:20 +08:00
LIMIT #{pageParam.pageSize} OFFSET #{pageParam.offset}
2025-10-16 14:31:56 +08:00
</select>
2025-10-29 19:08:22 +08:00
<!-- 统计Banner总数 - 添加权限过滤 -->
2025-10-16 14:31:56 +08:00
<select id="countBanners" resultType="long">
2025-10-29 19:08:22 +08:00
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>
2025-10-16 14:31:56 +08:00
</select>
2025-10-15 13:11:19 +08:00
</mapper>