<?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.roadm.mapper.SenstiveWordMapper">

    <resultMap type="SensitiveWord" id="senstiveWordResultMap">
        <id column="id" property="id" />
        <id column="content" property="content" />
        <id column="istelcom" property="isTelcom" />
        <id column="type" property="type" />
        <id column="strategy" property="strategy" />
        <result column="ismobile" property="isMobile" />
        <result column="isunicom" property="isUnicom" />
        <result column="create_time" property="createtime" />
         <result column="spid" property="spid" />
         <result column="marketing_sensitive_words" property="marketing_sensitive_words" />
        <result column="industry_sensitive_words" property="industry_sensitive_words" />
        <result column="verificationCode_sensitive_words" property="verificationCode_sensitive_words" />
        <result column="logistics_sensitive_words" property="logistics_sensitive_words" />
        <result column="remark" property="remark" />
        <association property="userInfo" column="createid"
            javaType="UserInfo">
            <id column="createid" property="user_id" />
            <result column="user_name" property="userName" />
        </association>
    </resultMap>

  <resultMap type="SensitiveWord" id="senstiveWordMap">
        <result column="content" property="content" />
    </resultMap>
    
    
    <resultMap type="SensitiveWord" id="exportWordResultMap">
        <id column="content" property="content" />
        <result column="create_time" property="createtime" />
            <result column="user_name" property="userName" />
    </resultMap>


<select id="exportSenstiveWord" parameterType="SensitiveWord"
        resultType="Map">
         select
        sw.content,date_format(sw.create_time,'%Y-%m-%d %H:%i:%S') create_time,
        us.user_name ,sw.type,sw.spid,sw.strategy from sms_sensitive_word sw 
        left join sms_user_info us on sw.createid=us.id
         where 1=1 
        <if test="content!=null and content!=''">
            and sw.content like CONCAT('%',#{content},'%') 
        </if>
        <if test="type!=null  and type!='-1'">
            and sw.type = #{type}
        </if>
        <if test="spid!=null  and spid!='-1'">
            and sw.spid = #{spid}
        </if>
        order by sw.id desc
</select>   


        
    <select id="listAllSensitiveWord" fetchSize="5000" parameterType="SensitiveWord"
        resultMap="senstiveWordMap"  useCache="true">
        select c.content from sms_sensitive_word  c where c.status=1
        <if test="type!=null and type>-1">
        	and type=#{type}
        </if>
    </select>



    <select id="listPageSensitiveWord" parameterType="SensitiveWord"
        resultMap="senstiveWordResultMap">
        select
        sw.id,sw.content,sw.create_time,sw.ismobile,sw.isunicom,sw.istelcom,sw.createid,
        us.user_name,sw.type,sw.spid,sw.strategy,sw.remark from sms_sensitive_word sw 
        left join sms_user_info us on sw.createid=us.id
         where 1=1 
        
        <if test="content!=null and content!=''">
            and sw.content like CONCAT('%',#{content},'%') 
        </if>
        <if test="type!=null  and type!='-1'">
            and sw.type = #{type}
        </if>
        <if test="spid!=null and spid!='-1' " >
            and sw.spid = #{spid}
        </if>
      order by sw.id desc
    </select>
    <select id="getSensitiveWordById" parameterType="int"
        resultMap="senstiveWordResultMap">
        select
        sw.id,sw.content,sw.create_time,sw.ismobile,sw.isunicom,sw.istelcom,sw.createid,
        us.user_name,sw.type,sw.spid,sw.strategy,sw.remark from sms_sensitive_word sw ,sms_user_info us where
        sw.createid=us.id
        and sw.id=#{word_id}
    </select>
    <select id="getWordCountByName" parameterType="SensitiveWord"
        resultType="int">
        select count(1) from sms_sensitive_word sw
        where
        sw.content=#{content, jdbcType=VARCHAR} and sw.type=#{type} and sw.spid=#{spid}
    </select>
    <update id="updateSensitiveWordById" parameterType="SensitiveWord">
        update
        sms_sensitive_word set
        content=#{content},
        ismobile=#{isMobile},
        istelcom=#{isTelcom},
        isunicom=#{isUnicom},
        spid=#{spid},
        type=#{type},
        strategy=#{strategy},
        remark=#{remark}
        where
        id=#{id}
    </update>


    <insert id="insertSensitiveWord" useGeneratedKeys="true" keyProperty="id" parameterType="SensitiveWord">
        insert into sms_sensitive_word
        (CONTENT,CREATEID,ISMOBILE,ISUNICOM,ISTELCOM,TYPE,SPID,create_time,strategy,remark) values
        (#{content,jdbcType=VARCHAR},#{createid},#{isMobile},#{isUnicom},#{isTelcom},#{type},#{spid},sysdate(),#{strategy},#{remark})
    </insert>
    
    <insert  id="addSenstiveWordBatch" useGeneratedKeys="true" keyProperty="id"  parameterType="java.util.List">
        insert into sms_sensitive_word (CONTENT,ISMOBILE,ISUNICOM,ISTELCOM,CREATEID,TYPE,STRATEGY,create_time,SPID,remark)
        VALUES
        <foreach collection="list" item="item"  index="index"  separator="," >
            (#{item.content,jdbcType=VARCHAR},#{item.isMobile},#{item.isUnicom},#{item.isTelcom},#{item.createid},#{item.type},#{item.strategy},sysdate(),#{item.spid},#{item.remark})
        </foreach>
</insert>
    
<!-- <insert id="addBlackMdnBatch"  parameterType="java.util.List">  
    <selectKey resultType="long" keyProperty="id" order="BEFORE">  
      select sms_black_object_id.nextval from dual
    </selectKey>  
    insert into sms_black_object (ID,MDN,SPID,DESCPTION)
    values  
    <foreach collection="list" item="item" index="index" separator="," >  
        (#{id},#{item.mdn},#{item.sp_id},#{item.descption,jdbcType=VARCHAR})  
    </foreach>  
</insert>   -->


    <delete id="deleteSensitiveWordById" parameterType="int">
        delete from sms_sensitive_word where id=#{word_id}
    </delete>
    
    <delete id="batchDelSensitiveWord">
        delete from sms_sensitive_word where id in
        <foreach collection="ids" item="id" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>
    
    <select id="listAllSensitiveWordType"  parameterType="DataDictionary"
        resultType="DataDictionary"  >
        select c.name,c.id,c.description,c.createtime,c.type,c.value,beginTime,endTime,isTongyin from sms_data_dictionary  c
        where 1=1
        <if test="type!=null  and type!=''">
            and c.type = #{type}
        </if>
        <if test="status!=null  and status!='-1'">
            and c.status = #{status}
        </if>
        order by c.id desc
    </select>
   <insert id="insertSensitiveWordType" useGeneratedKeys="true" keyProperty="id" parameterType="DataDictionary">
        insert into sms_data_dictionary
        (NAME,TYPE,DESCRIPTION,CREATETIME,STATUS,VALUE,beginTime,endTime,isTongyin) values
        (#{name,jdbcType=VARCHAR},#{type,jdbcType=VARCHAR},#{description,jdbcType=VARCHAR},sysdate(),#{status,jdbcType=INTEGER},#{value,jdbcType=VARCHAR},#{beginTime,jdbcType=VARCHAR},#{endTime,jdbcType=VARCHAR},#{isTongyin,jdbcType=INTEGER})
    </insert>

    <update id="updateSensitiveWordType" parameterType="DataDictionary">
        update
            sms_data_dictionary set
            description=#{description},
            beginTime=#{beginTime},
            endTime=#{endTime},
            isTongyin=#{isTongyin}
        where
            id=#{id}
    </update>

    <select id="getWordTypeCountByName" parameterType="DataDictionary"
        resultType="int">
        select count(1) from sms_data_dictionary sw
        where
        sw.name=#{name} and sw.type=#{type}
    </select>

    <select id="listPageSenstiveWordType" parameterType="DataDictionary"
            resultType="DataDictionary">
        select c.name,c.id,c.description,c.createtime,c.status,c.type,c.value,beginTime,endTime,isTongyin from sms_data_dictionary  c
        <where>
            <if test="name!=null  and name!=''">
                and c.name like CONCAT('%',#{name},'%')
            </if>
            <if test="type!=null  and type!=''">
                and c.type = #{type}
            </if>
            <if test="status!=null  and status!='-1'">
                and c.status = #{status}
            </if>
            <if test="id!=null  and id!='-1'">
                and c.id = #{id}
            </if>
        </where>
        order by c.id desc
    </select>

    <delete id="deleteSensitiveWordTypeById" parameterType="integer">
        delete from sms_data_dictionary where id=#{id}
    </delete>
</mapper>