<?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.DeductWhiteObjectMapper">

    <resultMap type="WhiteObject" id="whiteObjectResultMap">
        <id column="id" property="id" />
        <id column="mdn" property="mdn" />
        <id column="spid" property="sp_id" />
        <result column="createtime" property="createtime" />
        <result column="descption" property="descption" />
    </resultMap>
    
    <resultMap type="WhiteObject" id="exportWordResultMap">
        <id column="id" property="id" />
        <id column="mdn" property="mdn" />
        <id column="spid" property="sp_id" />
        <result column="createtime" property="createtime" />
        <result column="descption" property="descption" />
    </resultMap>
    
    
    <select id="exportWord" parameterType="WhiteObject"
        resultType="Map">
        select ot.id,ot.mdn,ot.spid,IFNULL(ot.descption,' ')descption ,date_format(ot.createtime,'%Y-%m-%d %H:%i:%S') createtime  from sms_deduct_white_object ot where 1=1
        <if test="mdn!=null and mdn!=''">
            and ot.mdn like CONCAT('%',#{mdn},'%') 
        </if>
    </select>
    
    <select id="listPageWhiteObject" parameterType="WhiteObject"
        resultMap="whiteObjectResultMap">
        select ot.id,ot.mdn,ot.spid,ot.createtime,ot.descption  from sms_deduct_white_object ot where 1=1
        <if test="mdn!=null and mdn!=''">
            and ot.mdn like CONCAT('%',#{mdn},'%') 
        </if>
        order by ot.id desc
    </select>
    <select id="getWhiteObjectById" parameterType="int"
        resultMap="whiteObjectResultMap">
            select ot.id,ot.mdn,ot.spid,ot.createtime,ot.descption  from sms_deduct_white_object ot where 
         ot.id=#{id}
    </select>
    <select id="getWhiteObjectCountByName" parameterType="WhiteObject"
        resultType="int">
        select count(1) from sms_deduct_white_object sw
        where
        sw.mdn=#{mdn}
        <if test="sp_id!=null and sp_id!=''">
            and sw.spid =#{sp_id}
        </if>
    </select>
    <update id="updateWhiteObjectById" parameterType="WhiteObject">
        update
        sms_deduct_white_object
        <set>
            <if test="sp_ids !=null and sp_ids != '' ">
                spid=#{sp_ids},
            </if>
            <if test="mdn!=null and mdn!= ''">
                mdn=#{mdn},
            </if>
            <if test="descption!=null and descption!= ''">
                descption=#{descption},
            </if>
            createtime = now()
        </set>
        where
           id=#{id}
    </update>


    <insert id="insertWhiteObject"  useGeneratedKeys="true" keyProperty="id"  parameterType="WhiteObject">
        insert into sms_deduct_white_object
        (MDN,SPID,DESCPTION,CREATETIME) values
        (#{mdn,jdbcType=VARCHAR},#{sp_id},#{descption,jdbcType=VARCHAR},sysdate())
    </insert>

 <insert  id="addWhiteMdnBatch"  useGeneratedKeys="true" keyProperty="id" parameterType="ArrayList">  
    <!--  <selectKey resultType="int" order="BEFORE" keyProperty="id">
            select sms_white_object_id.nextval from dual
    </selectKey> -->
    insert into sms_deduct_white_object (MDN,SPID,DESCPTION,CREATETIME)
     select A.* from(
    <foreach collection="list" item="white"  index="index"  separator="UNION"  >  
        SELECT #{white.mdn},#{white.sp_id},#{white.descption,jdbcType=VARCHAR},sysdate() FROM DUAL
    </foreach>  
      ) A
</insert>  


    <delete id="deleteWhiteObjectById" parameterType="int">
        delete from sms_deduct_white_object where id=#{id}
    </delete>
</mapper>