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
|
|
|
|
|
|
|
|
|
|
<!-- 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>
|
|
|
|
|
|
|
2025-10-28 19:04:35 +08:00
|
|
|
|
<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
|
|
|
|
|
|
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 -->
|
|
|
|
|
|
<select id="selectBannersPage" resultMap="BaseResultMap">
|
|
|
|
|
|
SELECT
|
|
|
|
|
|
<include refid="Base_Column_List" />
|
|
|
|
|
|
FROM tb_banner
|
2025-10-28 19:04:35 +08:00
|
|
|
|
<include refid="Filter_Clause" />
|
2025-10-16 14:31:56 +08:00
|
|
|
|
ORDER BY order_num ASC, 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>
|
|
|
|
|
|
|
|
|
|
|
|
<!-- 统计Banner总数 -->
|
|
|
|
|
|
<select id="countBanners" resultType="long">
|
|
|
|
|
|
SELECT COUNT(1)
|
|
|
|
|
|
FROM tb_banner
|
2025-10-28 19:04:35 +08:00
|
|
|
|
<include refid="Filter_Clause" />
|
2025-10-16 14:31:56 +08:00
|
|
|
|
</select>
|
|
|
|
|
|
|
2025-10-15 13:11:19 +08:00
|
|
|
|
</mapper>
|