Files
wuhan-saga/server/target/classes/mapper/NewsMapper.xml
王文昊 3daa0273a4 feat(news): 支持新闻中心多站点隔离功能
新增站点编码配置,支持新闻分类与文章按站点隔离。主要变更包括:
- 数据库表增加 site_code 字段及索引
- 后台管理界面支持按站点筛选
- 前台接口支持通过查询参数或请求头指定站点
- 新增站点配置与解析逻辑
2026-05-05 15:09:49 +08:00

131 lines
7.1 KiB
XML

<?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="com.wuhansaga.server.mapper.NewsMapper">
<resultMap id="newsResult" type="com.wuhansaga.server.entity.News">
<id property="newsId" column="news_id"/>
<result property="categoryId" column="category_id"/>
<result property="siteCode" column="site_code"/>
<result property="titleZh" column="title_zh"/>
<result property="titleEn" column="title_en"/>
<result property="excerptZh" column="excerpt_zh"/>
<result property="excerptEn" column="excerpt_en"/>
<result property="contentZh" column="content_zh"/>
<result property="contentEn" column="content_en"/>
<result property="coverImage" column="cover_image"/>
<result property="metaTitleZh" column="meta_title_zh"/>
<result property="metaTitleEn" column="meta_title_en"/>
<result property="metaDescriptionZh" column="meta_description_zh"/>
<result property="metaDescriptionEn" column="meta_description_en"/>
<result property="metaKeywords" column="meta_keywords"/>
<result property="isFeatured" column="is_featured"/>
<result property="isPublished" column="is_published"/>
<result property="viewCount" column="view_count"/>
<result property="sortOrder" column="sort_order"/>
<result property="createBy" column="create_by"/>
<result property="updateBy" column="update_by"/>
<result property="createTime" column="create_time"/>
<result property="updateTime" column="update_time"/>
<result property="remark" column="remark"/>
<result property="delFlag" column="del_flag"/>
<result property="categoryNameZh" column="category_name_zh"/>
<result property="categoryNameEn" column="category_name_en"/>
</resultMap>
<select id="selectList" resultMap="newsResult">
SELECT n.*, nc.name_zh AS category_name_zh, nc.name_en AS category_name_en
FROM f_news n
LEFT JOIN f_news_category nc ON n.category_id = nc.category_id
WHERE n.del_flag = 0
<if test="siteCode != null and siteCode != ''">AND n.site_code = #{siteCode}</if>
<if test="categoryId != null">AND n.category_id = #{categoryId}</if>
<if test="isFeatured != null">AND n.is_featured = #{isFeatured}</if>
<if test="isPublished != null">AND n.is_published = #{isPublished}</if>
<if test="keyword != null and keyword != ''">
AND (n.title_zh LIKE CONCAT('%',#{keyword},'%') OR n.title_en LIKE CONCAT('%',#{keyword},'%'))
</if>
ORDER BY n.sort_order ASC, n.create_time DESC
</select>
<select id="selectCount" resultType="long">
SELECT COUNT(*) FROM f_news n
WHERE n.del_flag = 0
<if test="siteCode != null and siteCode != ''">AND n.site_code = #{siteCode}</if>
<if test="categoryId != null">AND n.category_id = #{categoryId}</if>
<if test="isFeatured != null">AND n.is_featured = #{isFeatured}</if>
<if test="isPublished != null">AND n.is_published = #{isPublished}</if>
<if test="keyword != null and keyword != ''">
AND (n.title_zh LIKE CONCAT('%',#{keyword},'%') OR n.title_en LIKE CONCAT('%',#{keyword},'%'))
</if>
</select>
<select id="selectPublished" resultMap="newsResult">
SELECT n.*, nc.name_zh AS category_name_zh, nc.name_en AS category_name_en
FROM f_news n
LEFT JOIN f_news_category nc ON n.category_id = nc.category_id
WHERE n.del_flag = 0 AND n.is_published = 1
AND n.site_code = #{siteCode}
<if test="categoryId != null">AND n.category_id = #{categoryId}</if>
<if test="isFeatured != null">AND n.is_featured = #{isFeatured}</if>
ORDER BY n.sort_order ASC, n.create_time DESC
</select>
<select id="selectById" resultMap="newsResult">
SELECT n.*, nc.name_zh AS category_name_zh, nc.name_en AS category_name_en
FROM f_news n
LEFT JOIN f_news_category nc ON n.category_id = nc.category_id
WHERE n.news_id = #{id} AND n.del_flag = 0
</select>
<select id="selectPublishedById" resultMap="newsResult">
SELECT n.*, nc.name_zh AS category_name_zh, nc.name_en AS category_name_en
FROM f_news n
LEFT JOIN f_news_category nc ON n.category_id = nc.category_id
WHERE n.news_id = #{id} AND n.del_flag = 0 AND n.is_published = 1
AND n.site_code = #{siteCode}
</select>
<insert id="insert" useGeneratedKeys="true" keyProperty="newsId">
INSERT INTO f_news (category_id, site_code, title_zh, title_en, excerpt_zh, excerpt_en, content_zh, content_en,
cover_image, meta_title_zh, meta_title_en, meta_description_zh, meta_description_en,
meta_keywords, is_featured, is_published, sort_order, create_by, remark)
VALUES (#{categoryId}, #{siteCode}, #{titleZh}, #{titleEn}, #{excerptZh}, #{excerptEn}, #{contentZh}, #{contentEn},
#{coverImage}, #{metaTitleZh}, #{metaTitleEn}, #{metaDescriptionZh}, #{metaDescriptionEn},
#{metaKeywords}, #{isFeatured}, #{isPublished}, #{sortOrder}, #{createBy}, #{remark})
</insert>
<update id="update" parameterType="com.wuhansaga.server.entity.News">
UPDATE f_news
<set>
<if test="categoryId != null">category_id = #{categoryId},</if>
<if test="siteCode != null">site_code = #{siteCode},</if>
<if test="titleZh != null">title_zh = #{titleZh},</if>
<if test="titleEn != null">title_en = #{titleEn},</if>
<if test="excerptZh != null">excerpt_zh = #{excerptZh},</if>
<if test="excerptEn != null">excerpt_en = #{excerptEn},</if>
<if test="contentZh != null">content_zh = #{contentZh},</if>
<if test="contentEn != null">content_en = #{contentEn},</if>
<if test="coverImage != null">cover_image = #{coverImage},</if>
<if test="metaTitleZh != null">meta_title_zh = #{metaTitleZh},</if>
<if test="metaTitleEn != null">meta_title_en = #{metaTitleEn},</if>
<if test="metaDescriptionZh != null">meta_description_zh = #{metaDescriptionZh},</if>
<if test="metaDescriptionEn != null">meta_description_en = #{metaDescriptionEn},</if>
<if test="metaKeywords != null">meta_keywords = #{metaKeywords},</if>
<if test="isFeatured != null">is_featured = #{isFeatured},</if>
<if test="isPublished != null">is_published = #{isPublished},</if>
<if test="sortOrder != null">sort_order = #{sortOrder},</if>
<if test="updateBy != null">update_by = #{updateBy},</if>
<if test="remark != null">remark = #{remark},</if>
</set>
WHERE news_id = #{newsId} AND del_flag = 0
</update>
<update id="deleteById">
UPDATE f_news SET del_flag = 1 WHERE news_id = #{id}
</update>
<update id="incrementViewCount">
UPDATE f_news SET view_count = view_count + 1 WHERE news_id = #{id} AND del_flag = 0
</update>
</mapper>