<?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="cn.com.tenlion.configcontent.dao.contentantistop.IContentAntistopDao">

    <resultMap id="contentAntistopDTO" type="cn.com.tenlion.configcontent.pojo.dtos.contentantistop.ContentAntistopDTO">
        <id column="content_antistop_id" property="contentAntistopId"/>
        <result column="content_antistop_name" property="contentAntistopName"/>
        <result column="content_antistop_pinyin" property="contentAntistopPinyin"/>
        <result column="content_antistop_type" property="contentAntistopType"/>
        <result column="content_antistop_type_dictionary_name" property="contentAntistopTypeDictionaryName"/>
        <result column="content_antistop_remark" property="contentAntistopRemark"/>
    </resultMap>

    <select id="getContentAntistopByName" parameterType="map" resultMap="contentAntistopDTO">
        SELECT
            content_antistop_id,
            content_antistop_name
        FROM
            m_content_antistop
        WHERE
            is_delete = 0 AND content_antistop_name = #{contentAntistopName}
    </select>

    <!-- 新增新闻评论敏感词库 -->
    <insert id="saveContentAntistop" parameterType="map">
        INSERT INTO m_content_antistop(
            content_antistop_id,
            content_antistop_name,
            content_antistop_pinyin,
            content_antistop_type,
            content_antistop_remark,
            creator,
            gmt_create,
            modifier,
            gmt_modified,
            is_delete
        ) VALUES(
            #{contentAntistopId},
            #{contentAntistopName},
            #{contentAntistopPinyin},
            #{contentAntistopType},
            #{contentAntistopRemark},
            #{creator},
            #{gmtCreate},
            #{modifier},
            #{gmtModified},
            #{isDelete}
        )
    </insert>

    <!-- 删除新闻评论敏感词库 -->
    <update id="removeContentAntistop" parameterType="map">
        UPDATE
            m_content_antistop
        SET
            is_delete = 1,
            modifier = #{modifier},
            gmt_modified = #{gmtModified}
        WHERE
            content_antistop_id IN
        <foreach collection="contentAntistopIds" index="index" open="(" separator="," close=")">
            #{contentAntistopIds[${index}]}
        </foreach>
    </update>

    <!-- 修改新闻评论敏感词库 -->
    <update id="updateContentAntistop" parameterType="map">
        UPDATE
            m_content_antistop
        SET
        <if test="contentAntistopName != null and contentAntistopName != ''">
            content_antistop_name = #{contentAntistopName},
        </if>
        <if test="contentAntistopPinyin != null and contentAntistopPinyin != ''">
            content_antistop_pinyin = #{contentAntistopPinyin},
        </if>
        <if test="contentAntistopType != null and contentAntistopType != ''">
            content_antistop_type = #{contentAntistopType},
        </if>
        <if test="contentAntistopRemark != null and contentAntistopRemark != ''">
            content_antistop_remark = #{contentAntistopRemark},
        </if>
            modifier = #{modifier},
            gmt_modified = #{gmtModified}
        WHERE
            content_antistop_id = #{contentAntistopId}
    </update>

    <!-- 新闻评论敏感词库详情 -->
    <select id="getContentAntistop" parameterType="map" resultMap="contentAntistopDTO">
        SELECT
            t1.content_antistop_name,
            t1.content_antistop_pinyin,
            t1.content_antistop_type,
            t1.content_antistop_remark,
            t1.content_antistop_id
        FROM
            m_content_antistop t1
        WHERE
            t1.is_delete = 0
        <if test="contentAntistopId != null and contentAntistopId != ''">
        AND
            t1.content_antistop_id = #{contentAntistopId}
        </if>
    </select>

    <!-- 新闻评论敏感词库列表 -->
    <select id="listContentAntistop" parameterType="map" resultMap="contentAntistopDTO">
        SELECT
            t1.content_antistop_name,
            t1.content_antistop_pinyin,
            t1.content_antistop_type,
            t1.content_antistop_remark,
            t1.content_antistop_id
        FROM
            m_content_antistop t1
        WHERE
            t1.is_delete = 0
        <if test="keywords != null and keywords != ''">
            AND
            (
            t1.content_antistop_name LIKE CONCAT('%', #{keywords}, '%')
            OR
            t1.content_antistop_remark LIKE CONCAT('%', #{keywords}, '%')
            )
        </if>
        <if test="startTime != null and startTime != ''">
        AND
            LEFT(t1.gmt_create, 10) <![CDATA[ >= ]]> #{startTime}
        </if>
        <if test="endTime != null and endTime != ''">
        AND
            LEFT(t1.gmt_create, 10) <![CDATA[ <= ]]> #{endTime}
        </if>
        <if test="contentAntistopIds != null and contentAntistopIds.size > 0">
        AND
            t1.content_antistop_id IN
            <foreach collection="contentAntistopIds" index="index" open="(" separator="," close=")">
            #{contentAntistopIds[${index}]}
            </foreach>
        </if>
       ORDER BY t1.content_antistop_type
    </select>

</mapper>