|
@@ -0,0 +1,217 @@
|
|
|
+<?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.backendsys.modules.cms.article.dao.ArticleDao">
|
|
|
+
|
|
|
+ <sql id="includeArticle">
|
|
|
+ a.id id,
|
|
|
+ a.id article_id,
|
|
|
+ sf.user_id user_id,
|
|
|
+ COALESCE(sf.nickname, '') user_nickname,
|
|
|
+ ac.id category_id,
|
|
|
+ ac.category_name category_name,
|
|
|
+ at.title title,
|
|
|
+ COALESCE(at.description, '') description,
|
|
|
+ a.status status,
|
|
|
+ a.is_top is_top,
|
|
|
+ a.create_time create_time,
|
|
|
+ a.update_time update_time
|
|
|
+ </sql>
|
|
|
+
|
|
|
+ <sql id="includeArticleDetail">
|
|
|
+ a.id id,
|
|
|
+ a.id article_id,
|
|
|
+ sf.user_id user_id,
|
|
|
+ COALESCE(sf.nickname, '') user_nickname,
|
|
|
+ ac.id category_id,
|
|
|
+ ac.category_name category_name,
|
|
|
+ COALESCE(a.meta_keyword, '') meta_keyword,
|
|
|
+ COALESCE(a.meta_description, '') meta_description,
|
|
|
+ a.status status,
|
|
|
+ a.is_top is_top,
|
|
|
+ a.create_time create_time,
|
|
|
+ a.update_time update_time
|
|
|
+ </sql>
|
|
|
+ <sql id="includeArticleTranslation">
|
|
|
+ id, article_id, language, title, description, content
|
|
|
+ </sql>
|
|
|
+ <sql id="leftJoinCategory">
|
|
|
+ LEFT JOIN cms_article_category ac ON a.category_id = ac.id
|
|
|
+ </sql>
|
|
|
+ <sql id="leftJoinUser">
|
|
|
+ LEFT JOIN sys_user_info sf ON a.user_id = sf.user_id
|
|
|
+ </sql>
|
|
|
+ <sql id="leftJoinTranslations">
|
|
|
+ LEFT JOIN cms_article_translations at ON a.id = at.article_id
|
|
|
+ </sql>
|
|
|
+
|
|
|
+ <resultMap id="resultMapArticle" type="java.util.LinkedHashMap">
|
|
|
+ <id property="id" column="id" jdbcType="BIGINT" />
|
|
|
+ <result property="article_id" column="article_id" javaType="java.lang.Long" />
|
|
|
+ <result property="user_id" column="user_id" javaType="java.lang.Long" />
|
|
|
+ <result property="user_nickname" column="user_nickname" />
|
|
|
+ <result property="category_id" column="category_id" javaType="java.lang.Long" />
|
|
|
+ <result property="category_name" column="category_name" />
|
|
|
+ <result property="title" column="title" />
|
|
|
+ <result property="description" column="description" />
|
|
|
+ <result property="status" column="status" javaType="java.lang.Integer" />
|
|
|
+ <result property="is_top" column="is_top" javaType="java.lang.Integer" />
|
|
|
+ <result property="create_time" column="create_time" />
|
|
|
+ <result property="update_time" column="update_time" />
|
|
|
+ </resultMap>
|
|
|
+
|
|
|
+ <resultMap id="resultMapArticleDetail" type="java.util.LinkedHashMap">
|
|
|
+ <id property="id" column="id" jdbcType="BIGINT" />
|
|
|
+ <result property="article_id" column="article_id" javaType="java.lang.Long" />
|
|
|
+ <result property="user_id" column="user_id" javaType="java.lang.Long" />
|
|
|
+ <result property="user_nickname" column="user_nickname" />
|
|
|
+ <result property="category_id" column="category_id" javaType="java.lang.Long" />
|
|
|
+ <result property="category_name" column="category_name" />
|
|
|
+ <result property="meta_keyword" column="meta_keyword" />
|
|
|
+ <result property="meta_description" column="meta_description" />
|
|
|
+ <result property="status" column="status" javaType="java.lang.Integer" />
|
|
|
+ <result property="is_top" column="is_top" javaType="java.lang.Integer" />
|
|
|
+ <result property="create_time" column="create_time" />
|
|
|
+ <result property="update_time" column="update_time" />
|
|
|
+ <collection property="translations" javaType="java.util.List"
|
|
|
+ select="queryTranslationsById" column="id">
|
|
|
+ <id property="id" column="id" />
|
|
|
+ <result property="title" column="title" />
|
|
|
+ <result property="content" column="content" />
|
|
|
+ <result property="description" column="description" />
|
|
|
+ </collection>
|
|
|
+ </resultMap>
|
|
|
+
|
|
|
+
|
|
|
+ <!-- 查 列表 -->
|
|
|
+ <select id="selectArticleList" resultMap="resultMapArticle">
|
|
|
+ SELECT <include refid="includeArticle" /> FROM cms_article a
|
|
|
+ <include refid="leftJoinCategory" />
|
|
|
+ <include refid="leftJoinUser" />
|
|
|
+ <include refid="leftJoinTranslations" />
|
|
|
+ <where>
|
|
|
+ at.language = #{lang}
|
|
|
+ <if test="title != null and title != ''">
|
|
|
+ AND at.title LIKE CONCAT('%', #{title}, '%')
|
|
|
+ </if>
|
|
|
+ <if test="user_id != null and user_id != ''">
|
|
|
+ AND a.user_id = #{user_id}
|
|
|
+ </if>
|
|
|
+ <if test="category_id != null and category_id != ''">
|
|
|
+ AND a.category_id = #{category_id}
|
|
|
+ </if>
|
|
|
+ <if test="status != null and status != ''">
|
|
|
+ AND a.status = #{status}
|
|
|
+ </if>
|
|
|
+ <if test="create_time != null and create_time != ''">
|
|
|
+ AND a.create_time >= #{create_time}
|
|
|
+ </if>
|
|
|
+ </where>
|
|
|
+ ORDER BY a.is_top = 1 DESC, a.update_time DESC
|
|
|
+ </select>
|
|
|
+
|
|
|
+ <!-- 查 详情 (二次查询,带翻译) -->
|
|
|
+ <select id="selectArticleDetail" resultMap="resultMapArticleDetail">
|
|
|
+ SELECT <include refid="includeArticleDetail" />
|
|
|
+ FROM cms_article a
|
|
|
+ <include refid="leftJoinCategory" />
|
|
|
+ <include refid="leftJoinUser" />
|
|
|
+ WHERE a.id = #{article_id}
|
|
|
+ </select>
|
|
|
+ <!--<include refid="leftJoinTranslations" />-->
|
|
|
+ <!-- and at.language = #{lang} -->
|
|
|
+
|
|
|
+ <!-- 查 翻译集合 (子查询) -->
|
|
|
+ <select id="queryTranslationsById" resultType="java.util.LinkedHashMap">
|
|
|
+ SELECT <include refid="includeArticleTranslation" />
|
|
|
+ FROM cms_article_translations
|
|
|
+ WHERE article_id = #{id}
|
|
|
+ </select>
|
|
|
+
|
|
|
+
|
|
|
+ <!--<!– 查 详情 (公共) (带翻译 Object) (关联查询) –>-->
|
|
|
+ <!--<select id="queryArticleDetailPublic" resultMap="resultMapArticle">-->
|
|
|
+ <!-- SELECT <include refid="includeArticle" />, content-->
|
|
|
+ <!-- FROM cms_article a-->
|
|
|
+ <!-- <include refid="leftJoinCategory" />-->
|
|
|
+ <!-- <include refid="leftJoinUser" />-->
|
|
|
+ <!-- <include refid="leftJoinTranslations" />-->
|
|
|
+ <!-- WHERE a.id = #{article_id} AND at.language = #{lang}-->
|
|
|
+ <!--</select>-->
|
|
|
+
|
|
|
+
|
|
|
+ <!--<!– 审核功能,参考 /System/SysUserMapper.xml –>-->
|
|
|
+
|
|
|
+ <!--<insert id="insertArticle" parameterType="com.backendsys.entity.Cms.CmsArticleDTO"-->
|
|
|
+ <!-- useGeneratedKeys="true" keyProperty="article_id">-->
|
|
|
+ <!-- INSERT INTO cms_article (-->
|
|
|
+ <!-- user_id, category_id-->
|
|
|
+ <!-- <if test="meta_keyword != null and meta_keyword != ''">, meta_keyword</if>-->
|
|
|
+ <!-- <if test="meta_description != null and meta_description != ''">, meta_description</if>-->
|
|
|
+ <!-- <if test="status != null and status != ''">, status</if>-->
|
|
|
+ <!-- <if test="is_top != null and is_top != ''">, is_top</if>-->
|
|
|
+ <!-- )-->
|
|
|
+ <!-- VALUES (-->
|
|
|
+ <!-- #{user_id}, #{category_id}-->
|
|
|
+ <!-- <if test="meta_keyword != null and meta_keyword != ''">, #{meta_keyword}</if>-->
|
|
|
+ <!-- <if test="meta_description != null and meta_description != ''">, #{meta_description}</if>-->
|
|
|
+ <!-- <if test="status != null and status != ''">, #{status}</if>-->
|
|
|
+ <!-- <if test="is_top != null and is_top != ''">, #{is_top}</if>-->
|
|
|
+ <!-- );-->
|
|
|
+ <!--</insert>-->
|
|
|
+ <!--<insert id="insertArticleTranslations" parameterType="java.util.List">-->
|
|
|
+ <!-- INSERT INTO cms_article_translations (-->
|
|
|
+ <!-- article_id, language, title, content, description-->
|
|
|
+ <!-- )-->
|
|
|
+ <!-- VALUES-->
|
|
|
+ <!-- <foreach collection="translations" item="translation" separator=",">-->
|
|
|
+ <!-- (#{translation.article_id}, #{translation.language}, #{translation.title}, #{translation.content}, #{translation.description})-->
|
|
|
+ <!-- </foreach>-->
|
|
|
+ <!--</insert>-->
|
|
|
+
|
|
|
+
|
|
|
+ <!--<update id="updateArticle" parameterType="com.backendsys.entity.Cms.CmsArticleDTO"-->
|
|
|
+ <!-- useGeneratedKeys="true" keyProperty="article_id">-->
|
|
|
+ <!-- UPDATE cms_article-->
|
|
|
+ <!-- SET-->
|
|
|
+ <!-- category_id = #{category_id}-->
|
|
|
+ <!-- <if test="meta_keyword != null and meta_keyword != ''">, meta_keyword = #{meta_keyword}</if>-->
|
|
|
+ <!-- <if test="meta_description != null and meta_description != ''">, meta_description = #{meta_description}</if>-->
|
|
|
+ <!-- <if test="status != null and status != ''">, status = #{status}</if>-->
|
|
|
+ <!-- <if test="is_top != null and is_top != ''">, is_top = #{is_top}</if>-->
|
|
|
+ <!-- WHERE id = #{article_id};-->
|
|
|
+
|
|
|
+ <!-- <foreach collection="translations" item="translation" separator=";">-->
|
|
|
+ <!-- UPDATE cms_article_translations-->
|
|
|
+ <!-- <set>-->
|
|
|
+ <!-- title = #{translation.title},-->
|
|
|
+ <!-- content = #{translation.content},-->
|
|
|
+ <!-- <if test="translation.description != null and translation.description != ''">-->
|
|
|
+ <!-- description = #{translation.description}-->
|
|
|
+ <!-- </if>-->
|
|
|
+ <!-- </set>-->
|
|
|
+ <!-- WHERE article_id = ${article_id} AND language = #{translation.language}-->
|
|
|
+ <!-- </foreach>-->
|
|
|
+
|
|
|
+ <!--</update>-->
|
|
|
+ <!--<!– <if test="audit_status != null and audit_status != ''">, audit_status = #{audit_status}</if> –>-->
|
|
|
+
|
|
|
+ <!--<!– 删除 –>-->
|
|
|
+ <!--<delete id="deleteArticle" parameterType="java.lang.Long">-->
|
|
|
+ <!-- DELETE FROM cms_article WHERE id = #{article_id};-->
|
|
|
+ <!-- DELETE FROM cms_article_translations WHERE article_id = #{article_id};-->
|
|
|
+ <!--</delete>-->
|
|
|
+
|
|
|
+ <!--<!– 删除 (批量) –>-->
|
|
|
+ <!--<delete id="deleteArticleBatch" parameterType="java.lang.Long">-->
|
|
|
+ <!-- DELETE FROM cms_article WHERE id IN-->
|
|
|
+ <!-- <foreach collection="ids" item="id" open="(" separator="," close=")">-->
|
|
|
+ <!-- #{id}-->
|
|
|
+ <!-- </foreach>;-->
|
|
|
+
|
|
|
+ <!-- DELETE FROM cms_article_translations WHERE article_id IN-->
|
|
|
+ <!-- <foreach collection="ids" item="id" open="(" separator="," close=")">-->
|
|
|
+ <!-- #{id}-->
|
|
|
+ <!-- </foreach>;-->
|
|
|
+ <!--</delete>-->
|
|
|
+
|
|
|
+</mapper>
|