<!--<?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.mapper.Cms.CmsArticleMapper">-->

<!--    &lt;!&ndash;ac.user,&ndash;&gt;-->
<!--    &lt;!&ndash;ac.category,&ndash;&gt;-->
<!--    &lt;!&ndash; a.audit_status audit_status, &ndash;&gt;-->
<!--    <sql id="includeArticle">-->
<!--        a.id id,-->
<!--        a.id article_id,-->
<!--        uf.user_id user_id,-->
<!--        COALESCE(uf.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>-->

<!--    &lt;!&ndash; at.title title,-->
<!--    at.content content,-->
<!--    COALESCE(at.description, '') description, &ndash;&gt;-->
<!--    &lt;!&ndash; a.audit_status audit_status, &ndash;&gt;-->
<!--    <sql id="includeArticleDetail">-->
<!--        a.id id,-->
<!--        a.id article_id,-->
<!--        uf.user_id user_id,-->
<!--        COALESCE(uf.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>-->

<!--    <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="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"/>-->
<!--        &lt;!&ndash; <result property="audit_status" column="audit_status" javaType="java.lang.Integer"/> &ndash;&gt;-->
<!--        <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="category_id" column="category_id" javaType="java.lang.Long"/>-->
<!--        <result property="category_name" column="category_name" />-->
<!--        &lt;!&ndash; <result property="title" column="title" />-->
<!--        <result property="content" column="content" />-->
<!--        <result property="description" column="description" /> &ndash;&gt;-->
<!--        <result property="meta_keyword" column="meta_keyword" />-->
<!--        <result property="meta_description" column="meta_description" />-->
<!--        <result property="status" column="status" javaType="java.lang.Integer"/>-->
<!--        &lt;!&ndash; <result property="audit_status" column="audit_status" javaType="java.lang.Integer"/> &ndash;&gt;-->
<!--        <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>-->

<!--    <sql id="leftJoinCategory">-->
<!--        LEFT JOIN cms_article_category ac ON a.category_id = ac.id-->
<!--    </sql>-->
<!--    <sql id="leftJoinUser">-->
<!--        LEFT JOIN sys_user_info uf ON a.user_id = uf.user_id-->
<!--    </sql>-->
<!--    <sql id="leftJoinTranslations">-->
<!--        LEFT JOIN cms_article_i18n at ON a.id = at.article_id-->
<!--    </sql>-->

<!--    &lt;!&ndash; 查 列表 &ndash;&gt;-->
<!--    <select id="queryArticleList" 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>-->
<!--    &lt;!&ndash; <if test="audit_status != null and audit_status != ''">-->
<!--        AND a.audit_status = #{audit_status}-->
<!--    </if> &ndash;&gt;-->

<!--    &lt;!&ndash; 查 详情 (带翻译 Array) (二次查询) &ndash;&gt;-->
<!--    <select id="queryArticleDetail" resultMap="resultMapArticleDetail">-->
<!--        SELECT <include refid="includeArticleDetail" />-->
<!--        FROM cms_article a-->
<!--        <include refid="leftJoinCategory" />-->
<!--        <include refid="leftJoinUser" />-->
<!--        WHERE a.id = #{article_id}-->
<!--    </select>-->
<!--     &lt;!&ndash; and at.language = #{lang} &ndash;&gt;-->
<!--     &lt;!&ndash; 查 翻译集合 (子查询) &ndash;&gt;-->
<!--    <select id="queryTranslationsById" resultType="java.util.LinkedHashMap">-->
<!--        SELECT <include refid="includeArticleTranslation" />-->
<!--        FROM cms_article_i18n-->
<!--        WHERE article_id = #{id}-->
<!--    </select>-->


<!--    &lt;!&ndash; 查 详情 (公共) (带翻译 Object) (关联查询) &ndash;&gt;-->
<!--    <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>-->


<!--    &lt;!&ndash; 审核功能，参考 /System/SysUserMapper.xml &ndash;&gt;-->

<!--    <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_i18n (-->
<!--            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_i18n-->
<!--            <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>-->
<!--    &lt;!&ndash; <if test="audit_status != null and audit_status != ''">, audit_status = #{audit_status}</if> &ndash;&gt;-->

<!--    &lt;!&ndash; 删除 &ndash;&gt;-->
<!--    <delete id="deleteArticle" parameterType="java.lang.Long">-->
<!--        DELETE FROM cms_article WHERE id = #{article_id};-->
<!--        DELETE FROM cms_article_i18n WHERE article_id = #{article_id};-->
<!--    </delete>-->

<!--    &lt;!&ndash; 删除 (批量) &ndash;&gt;-->
<!--    <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_i18n WHERE article_id IN-->
<!--        <foreach collection="ids" item="id" open="(" separator="," close=")">-->
<!--            #{id}-->
<!--        </foreach>;-->
<!--    </delete>-->

<!--</mapper>-->