<?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.ruoyi.tuya.mapper.TuyaArticleInfoMapper">

    <resultMap type="TuyaArticleInfo" id="TuyaArticleInfoResult">
        <result property="articleId"    column="article_id"    />
        <result property="siteId"    column="site_id"    />
        <result property="channelId"    column="channel_id"    />
        <result property="categoryId"    column="category_id"    />
        <result property="siteName"    column="site_name"    />
        <result property="channelName"    column="channel_name"    />
        <result property="categoryName"    column="category_name"    />
        <result property="articleTitle"    column="article_title"    />
        <result property="articleTitle2"    column="article_title2"    />
        <result property="articleDigest"    column="article_digest"    />
        <result property="articleContent"    column="article_content"    />
        <result property="articleLinkUrl"    column="article_link_url"    />
        <result property="articleImgUrl1"    column="article_img_url1"    />
        <result property="articleImgUrl2"    column="article_img_url2"    />
        <result property="articleImgUrl3"    column="article_img_url3"    />
        <result property="articleVideoUrl"    column="article_video_url"    />
        <result property="seoTitle"    column="seo_title"    />
        <result property="seoKeyword"    column="seo_keyword"    />
        <result property="seoDescription"    column="seo_description"    />
        <result property="sortId"    column="sort_id"    />
        <result property="isLock"    column="is_lock"    />
        <result property="createTime"    column="create_time"    />
        <result property="createBy"    column="create_by"    />
        <result property="updateTime"    column="update_time"    />
        <result property="updateBy"    column="update_by"    />
        <result property="flag"    column="flag"    />
        <result property="remark"    column="remark"    />
    </resultMap>

    <sql id="selectTuyaArticleInfoVo">
        select article_id, a.site_id, a.channel_id, a.category_id, d.site_name_cn site_name, c.channel_name, b.category_name,article_title,
               article_title2, article_digest,article_content, article_link_url, article_img_url1, article_img_url2,
               article_img_url3,article_video_url, a.seo_title, a.seo_keyword, a.seo_description, a.sort_id, a.is_lock,
               a.create_time,a.create_by, a.update_time, a.update_by, a.flag, a.remark
        from tuya_article_info a
            inner join tuya_category_info b on a.category_id = b.category_id
            inner join tuya_channel_info c on b.channel_id = c.channel_id
            inner join tuya_sites_info d on c.channel_site_id = d.site_id
    </sql>
    <select id="checkArticleTitleUnique" parameterType="TuyaArticleInfo" resultMap="TuyaArticleInfoResult">
        select TOP 1 article_id, a.site_id, a.channel_id, a.category_id, d.site_name_cn site_name, c.channel_name, b.category_name,article_title,
               article_title2, article_digest,article_content, article_link_url, article_img_url1, article_img_url2,
               article_img_url3,article_video_url, a.seo_title, a.seo_keyword, a.seo_description, a.sort_id, a.is_lock,
               a.create_time,a.create_by, a.update_time, a.update_by, a.flag, a.remark
        from tuya_article_info a
                 inner join tuya_category_info b on a.category_id = b.category_id
                 inner join tuya_channel_info c on b.channel_id = c.channel_id
                 inner join tuya_sites_info d on c.channel_site_id = d.site_id
        where d.site_id=#{siteId} and c.channel_id = #{channelId} and b.category_id = #{categoryId} and a.article_title = #{articleTitle}
    </select>
    <select id="selectTuyaArticleInfoList" parameterType="TuyaArticleInfo" resultMap="TuyaArticleInfoResult">
        <include refid="selectTuyaArticleInfoVo"/>
        <where>
            <if test="siteId != null "> and a.site_id = #{siteId}</if>
            <if test="channelId != null "> and a.channel_id = #{channelId}</if>
            <if test="categoryId != null "> and a.category_id = #{categoryId}</if>
            <if test="articleTitle != null  and articleTitle != ''"> and article_title like concat('%', #{articleTitle}, '%')</if>
            <if test="articleTitle2 != null  and articleTitle2 != ''"> and article_title2 = #{articleTitle2}</if>
            <if test="articleDigest != null  and articleDigest != ''"> and article_digest = #{articleDigest}</if>
            <if test="articleContent != null  and articleContent != ''"> and article_content = #{articleContent}</if>
            <if test="articleLinkUrl != null  and articleLinkUrl != ''"> and article_link_url = #{articleLinkUrl}</if>
            <if test="articleImgUrl1 != null  and articleImgUrl1 != ''"> and article_img_url1 = #{articleImgUrl1}</if>
            <if test="articleImgUrl2 != null  and articleImgUrl2 != ''"> and article_img_url2 = #{articleImgUrl2}</if>
            <if test="articleImgUrl3 != null  and articleImgUrl3 != ''"> and article_img_url3 = #{articleImgUrl3}</if>
            <if test="articleVideoUrl != null  and articleVideoUrl != ''"> and article_video_url = #{articleVideoUrl}</if>
            <if test="seoTitle != null  and seoTitle != ''"> and a.seo_title = #{seoTitle}</if>
            <if test="seoKeyword != null  and seoKeyword != ''"> and a.seo_keyword = #{seoKeyword}</if>
            <if test="seoDescription != null  and seoDescription != ''"> and a.seo_description = #{seoDescription}</if>
            <if test="sortId != null "> and a.sort_id = #{sortId}</if>
            <if test="isLock != null "> and a.is_lock = #{isLock}</if>
            <if test="flag != null "> and a.flag = #{flag}</if>
        </where>
    </select>

    <select id="selectTuyaArticleInfoByArticleId" parameterType="Long" resultMap="TuyaArticleInfoResult">
        <include refid="selectTuyaArticleInfoVo"/>
        where article_id = #{articleId}
    </select>

    <insert id="insertTuyaArticleInfo" parameterType="TuyaArticleInfo">
        insert into tuya_article_info
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="articleId != null">article_id,</if>
            <if test="siteId != null">site_id,</if>
            <if test="channelId != null">channel_id,</if>
            <if test="categoryId != null">category_id,</if>
            <if test="articleTitle != null">article_title,</if>
            <if test="articleTitle2 != null">article_title2,</if>
            <if test="articleDigest != null">article_digest,</if>
            <if test="articleContent != null">article_content,</if>
            <if test="articleLinkUrl != null">article_link_url,</if>
            <if test="articleImgUrl1 != null">article_img_url1,</if>
            <if test="articleImgUrl2 != null">article_img_url2,</if>
            <if test="articleImgUrl3 != null">article_img_url3,</if>
            <if test="articleVideoUrl != null">article_video_url,</if>
            <if test="seoTitle != null">seo_title,</if>
            <if test="seoKeyword != null">seo_keyword,</if>
            <if test="seoDescription != null">seo_description,</if>
            <if test="sortId != null">sort_id,</if>
            <if test="isLock != null">is_lock,</if>
            <if test="createTime != null">create_time,</if>
            <if test="createBy != null">create_by,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="flag != null">flag,</if>
            <if test="remark != null">remark,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="articleId != null">#{articleId},</if>
            <if test="siteId != null">#{siteId},</if>
            <if test="channelId != null">#{channelId},</if>
            <if test="categoryId != null">#{categoryId},</if>
            <if test="articleTitle != null">#{articleTitle},</if>
            <if test="articleTitle2 != null">#{articleTitle2},</if>
            <if test="articleDigest != null">#{articleDigest},</if>
            <if test="articleContent != null">#{articleContent},</if>
            <if test="articleLinkUrl != null">#{articleLinkUrl},</if>
            <if test="articleImgUrl1 != null">#{articleImgUrl1},</if>
            <if test="articleImgUrl2 != null">#{articleImgUrl2},</if>
            <if test="articleImgUrl3 != null">#{articleImgUrl3},</if>
            <if test="articleVideoUrl != null">#{articleVideoUrl},</if>
            <if test="seoTitle != null">#{seoTitle},</if>
            <if test="seoKeyword != null">#{seoKeyword},</if>
            <if test="seoDescription != null">#{seoDescription},</if>
            <if test="sortId != null">#{sortId},</if>
            <if test="isLock != null">#{isLock},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="flag != null">#{flag},</if>
            <if test="remark != null">#{remark},</if>
         </trim>
    </insert>

    <update id="updateTuyaArticleInfo" parameterType="TuyaArticleInfo">
        update tuya_article_info
        <trim prefix="SET" suffixOverrides=",">
            <if test="siteId != null">site_id = #{siteId},</if>
            <if test="channelId != null">channel_id = #{channelId},</if>
            <if test="categoryId != null">category_id = #{categoryId},</if>
            <if test="articleTitle != null">article_title = #{articleTitle},</if>
            <if test="articleTitle2 != null">article_title2 = #{articleTitle2},</if>
            <if test="articleDigest != null">article_digest = #{articleDigest},</if>
            <if test="articleContent != null">article_content = #{articleContent},</if>
            <if test="articleLinkUrl != null">article_link_url = #{articleLinkUrl},</if>
            <if test="articleImgUrl1 != null">article_img_url1 = #{articleImgUrl1},</if>
            <if test="articleImgUrl2 != null">article_img_url2 = #{articleImgUrl2},</if>
            <if test="articleImgUrl3 != null">article_img_url3 = #{articleImgUrl3},</if>
            <if test="articleVideoUrl != null">article_video_url = #{articleVideoUrl},</if>
            <if test="seoTitle != null">seo_title = #{seoTitle},</if>
            <if test="seoKeyword != null">seo_keyword = #{seoKeyword},</if>
            <if test="seoDescription != null">seo_description = #{seoDescription},</if>
            <if test="sortId != null">sort_id = #{sortId},</if>
            <if test="isLock != null">is_lock = #{isLock},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="flag != null">flag = #{flag},</if>
            <if test="remark != null">remark = #{remark},</if>
        </trim>
        where article_id = #{articleId}
    </update>

    <delete id="deleteTuyaArticleInfoByArticleId" parameterType="Long">
        delete from tuya_article_info where article_id = #{articleId}
    </delete>

    <delete id="deleteTuyaArticleInfoByArticleIds" parameterType="String">
        delete from tuya_article_info where article_id in
        <foreach item="articleId" collection="array" open="(" separator="," close=")">
            #{articleId}
        </foreach>
    </delete>
</mapper>
