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

    <resultMap type="WhiteCity" id="whiteObjectResultMap">
        <id column="id" property="id" />
        <id column="city" property="city" />
        <id column="spid" property="sp_id" />
        <result column="createtime" property="createtime" />
        <result column="descption" property="descption" />
    </resultMap>
    
    <resultMap type="WhiteCity" id="exportWordResultMap">
        <id column="id" property="id" />
        <id column="city" property="city" />
        <id column="spid" property="sp_id" />
        <result column="createtime" property="createtime" />
        <result column="descption" property="descption" />
    </resultMap>
    
    
    <select id="exportWord" parameterType="WhiteCity"
        resultType="Map">
        select ot.id,ot.city,ot.spid,IFNULL(ot.descption,' ')descption ,date_format(ot.createtime,'%Y-%m-%d %H:%i:%S') createtime  from sms_deduct_white_city ot where 1=1
        <if test="city!=null and city!=''">
            and ot.city like CONCAT('%',#{city},'%') 
        </if>
    </select>
    
    <select id="listPageWhiteObject" parameterType="WhiteCity"
        resultMap="whiteObjectResultMap">
        select ot.id,ot.city,ot.spid,ot.createtime,ot.descption  from sms_deduct_white_city ot where 1=1
        <if test="city!=null and city!=''">
            and ot.city like CONCAT('%',#{city},'%') 
        </if>
        order by ot.id desc
    </select>
    <select id="getWhiteObjectById" parameterType="int"
        resultMap="whiteObjectResultMap">
            select ot.id,ot.city,ot.spid,ot.createtime,ot.descption  from sms_deduct_white_city ot where 
         ot.id=#{id}
    </select>
    <select id="getWhiteObjectCountByName" parameterType="WhiteCity"
        resultType="int">
        select count(1) from sms_deduct_white_city sw
        where
        sw.city=#{city}
        <if test="sp_id!=null and sp_id!=''">
            and sw.spid =#{sp_id}
        </if>
    </select>
    <update id="updateWhiteObjectById" parameterType="WhiteCity">
        update
        sms_deduct_white_city
        <set>
            <if test="sp_ids !=null and sp_ids != '' ">
                spid=#{sp_ids},
            </if>
            <if test="city!=null and city!= ''">
                city=#{city},
            </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="WhiteCity">
        insert into sms_deduct_white_city
        (CITY,SPID,DESCPTION,CREATETIME) values
        (#{city,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_city (CITY,SPID,DESCPTION,CREATETIME)
     select A.* from(
    <foreach collection="list" item="white"  index="index"  separator="UNION"  >  
        SELECT #{white.city},#{white.sp_id},#{white.descption,jdbcType=VARCHAR},sysdate() FROM DUAL
    </foreach>  
      ) A
</insert>  


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