<?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.steerinfo.baseinfo.meterbasespecialunit.mapper.MeterBaseSpecialUnitMapper">
  <resultMap id="BaseResultMap" type="com.steerinfo.baseinfo.meterbasespecialunit.model.MeterBaseSpecialUnit">
    <id column="UNIT_NO" jdbcType="VARCHAR" property="unitNo" />
    <result column="UNIT_NAME" jdbcType="VARCHAR" property="unitName" />
    <result column="VALID_FLAG" jdbcType="VARCHAR" property="validFlag" />
    <result column="CREATE_MAN_NO" jdbcType="VARCHAR" property="createManNo" />
    <result column="CREATE_MAN_NAME" jdbcType="VARCHAR" property="createManName" />
    <result column="CREATE_TIME" jdbcType="TIMESTAMP" property="createTime" />
  </resultMap>
  <sql id="columns">
    UNIT_NO, UNIT_NAME, VALID_FLAG, CREATE_MAN_NO, CREATE_MAN_NAME, CREATE_TIME
  </sql>
  <sql id="columns_alias">
    t.UNIT_NO, t.UNIT_NAME, t.VALID_FLAG, t.CREATE_MAN_NO, t.CREATE_MAN_NAME, t.CREATE_TIME
  </sql>
  <sql id="select">
    SELECT <include refid="columns"/> FROM METER_BASE_SPECIAL_UNIT
  </sql>
  <sql id="select_alias">
    SELECT <include refid="columns_alias"/> FROM METER_BASE_SPECIAL_UNIT t
  </sql>
  <sql id="where">
    <where> 
      <if test="unitNo != null and unitNo != ''">
        and UNIT_NO = #{unitNo}
      </if>
      <if test="unitName != null and unitName != ''">
        and UNIT_NAME = #{unitName}
      </if>
      <if test="validFlag != null and validFlag != ''">
        and VALID_FLAG = #{validFlag}
      </if>
      <if test="createManNo != null and createManNo != ''">
        and CREATE_MAN_NO = #{createManNo}
      </if>
      <if test="createManName != null and createManName != ''">
        and CREATE_MAN_NAME = #{createManName}
      </if>
      <if test="createTime != null">
        and TO_CHAR(CREATE_TIME,'yyyy-MM-dd') = #{createTime}
      </if>
    </where>
  </sql>
  <sql id="whereLike">
    <where> 
      <if test="unitNo != null and unitNo != ''">
        and UNIT_NO LIKE '%${unitNo}%'
      </if>
      <if test="unitName != null and unitName != ''">
        and UNIT_NAME LIKE '%${unitName}%'
      </if>
      <if test="validFlag != null and validFlag != ''">
        and VALID_FLAG LIKE '%${validFlag}%'
      </if>
      <if test="createManNo != null and createManNo != ''">
        and CREATE_MAN_NO LIKE '%${createManNo}%'
      </if>
      <if test="createManName != null and createManName != ''">
        and CREATE_MAN_NAME LIKE '%${createManName}%'
      </if>
      <if test="createTime != null">
        and TO_CHAR(CREATE_TIME,'yyyy-MM-dd') = #{createTime}
      </if>
    </where>
  </sql>
  <delete id="deleteByPrimaryKey" parameterType="java.lang.String">
    delete from METER_BASE_SPECIAL_UNIT
    where UNIT_NO = #{unitNo,jdbcType=VARCHAR}
  </delete>
  <delete id="deleteBySelectiveElement" parameterType="java.util.HashMap">
    delete from METER_BASE_SPECIAL_UNIT
    where 1!=1 
      <if test="unitName != null and unitName != ''">
        or UNIT_NAME = #{unitName}
      </if>
      <if test="validFlag != null and validFlag != ''">
        or VALID_FLAG = #{validFlag}
      </if>
      <if test="createManNo != null and createManNo != ''">
        or CREATE_MAN_NO = #{createManNo}
      </if>
      <if test="createManName != null and createManName != ''">
        or CREATE_MAN_NAME = #{createManName}
      </if>
      <if test="createTime != null">
        or TO_CHAR(CREATE_TIME,'yyyy-MM-dd') = '#{createTime}'
      </if>
  </delete>
  <insert id="insert" parameterType="com.steerinfo.baseinfo.meterbasespecialunit.model.MeterBaseSpecialUnit">
    insert into METER_BASE_SPECIAL_UNIT (UNIT_NO, UNIT_NAME, VALID_FLAG, 
      CREATE_MAN_NO, CREATE_MAN_NAME, CREATE_TIME
      )
    values (#{unitNo,jdbcType=VARCHAR}, #{unitName,jdbcType=VARCHAR}, #{validFlag,jdbcType=VARCHAR}, 
      #{createManNo,jdbcType=VARCHAR}, #{createManName,jdbcType=VARCHAR}, #{createTime,jdbcType=TIMESTAMP}
      )
  </insert>
  <insert id="insertSelective" parameterType="com.steerinfo.baseinfo.meterbasespecialunit.model.MeterBaseSpecialUnit">
    insert into METER_BASE_SPECIAL_UNIT
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="unitNo != null">
        UNIT_NO,
      </if>
      <if test="unitName != null">
        UNIT_NAME,
      </if>
      <if test="validFlag != null">
        VALID_FLAG,
      </if>
      <if test="createManNo != null">
        CREATE_MAN_NO,
      </if>
      <if test="createManName != null">
        CREATE_MAN_NAME,
      </if>
      <if test="createTime != null">
        CREATE_TIME,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides=",">
      <if test="unitNo != null">
        #{unitNo,jdbcType=VARCHAR},
      </if>
      <if test="unitName != null">
        #{unitName,jdbcType=VARCHAR},
      </if>
      <if test="validFlag != null">
        #{validFlag,jdbcType=VARCHAR},
      </if>
      <if test="createManNo != null">
        #{createManNo,jdbcType=VARCHAR},
      </if>
      <if test="createManName != null">
        #{createManName,jdbcType=VARCHAR},
      </if>
      <if test="createTime != null">
        #{createTime,jdbcType=TIMESTAMP},
      </if>
    </trim>
  </insert>
  <update id="updateByPrimaryKey" parameterType="com.steerinfo.baseinfo.meterbasespecialunit.model.MeterBaseSpecialUnit">
    update METER_BASE_SPECIAL_UNIT
    set UNIT_NAME = #{unitName,jdbcType=VARCHAR},
      VALID_FLAG = #{validFlag,jdbcType=VARCHAR},
      CREATE_MAN_NO = #{createManNo,jdbcType=VARCHAR},
      CREATE_MAN_NAME = #{createManName,jdbcType=VARCHAR},
      CREATE_TIME = #{createTime,jdbcType=TIMESTAMP}
    where UNIT_NO = #{unitNo,jdbcType=VARCHAR}
  </update>
  <update id="updateByPrimaryKeySelective" parameterType="com.steerinfo.baseinfo.meterbasespecialunit.model.MeterBaseSpecialUnit">
    update METER_BASE_SPECIAL_UNIT
    <set>
      <if test="unitName != null">
        UNIT_NAME = #{unitName,jdbcType=VARCHAR},
      </if>
      <if test="validFlag != null">
        VALID_FLAG = #{validFlag,jdbcType=VARCHAR},
      </if>
      <if test="createManNo != null">
        CREATE_MAN_NO = #{createManNo,jdbcType=VARCHAR},
      </if>
      <if test="createManName != null">
        CREATE_MAN_NAME = #{createManName,jdbcType=VARCHAR},
      </if>
      <if test="createTime != null">
        CREATE_TIME = #{createTime,jdbcType=TIMESTAMP},
      </if>
    </set>
    where UNIT_NO = #{unitNo,jdbcType=VARCHAR}
  </update>
  <select id="selectByPrimaryKey" parameterType="java.lang.String" resultMap="BaseResultMap">
    <include refid="select"/>
    where UNIT_NO = #{unitNo,jdbcType=VARCHAR}
  </select>
  <select id="selectByParameters" parameterType="java.util.HashMap" resultMap="BaseResultMap">
    <include refid="select"/>
    <include refid="where"/>
  </select>
  <select id="selectLikeByParameters" parameterType="java.util.HashMap" resultMap="BaseResultMap">
    <include refid="select"/>
    <include refid="whereLike"/>
  </select>
  <insert id="batchInsert" parameterType="java.util.List">
    insert into METER_BASE_SPECIAL_UNIT 
      (UNIT_NO, 
      UNIT_NAME, VALID_FLAG, CREATE_MAN_NO, 
      CREATE_MAN_NAME, CREATE_TIME)
    ( <foreach collection="list" item="item" separator="union all"> 
   select  
      #{item.unitNo,jdbcType=VARCHAR}, 
      #{item.unitName,jdbcType=VARCHAR}, #{item.validFlag,jdbcType=VARCHAR}, #{item.createManNo,jdbcType=VARCHAR}, 
      #{item.createManName,jdbcType=VARCHAR}, #{item.createTime,jdbcType=TIMESTAMP} from dual  
   </foreach> )
  </insert>
  <update id="batchUpdate" parameterType="java.util.List">
     update METER_BASE_SPECIAL_UNIT
     set
       UNIT_NO=
       <foreach collection="list" item="item" index="index" separator=" " open="case UNIT_NO" close="end">
          when #{item.unitNo,jdbcType=VARCHAR} then #{item.unitNo,jdbcType=VARCHAR}
       </foreach>
       ,UNIT_NAME=
       <foreach collection="list" item="item" index="index" separator=" " open="case UNIT_NO" close="end">
          when #{item.unitNo,jdbcType=VARCHAR} then #{item.unitName,jdbcType=VARCHAR}
       </foreach>
       ,VALID_FLAG=
       <foreach collection="list" item="item" index="index" separator=" " open="case UNIT_NO" close="end">
          when #{item.unitNo,jdbcType=VARCHAR} then #{item.validFlag,jdbcType=VARCHAR}
       </foreach>
       ,CREATE_MAN_NO=
       <foreach collection="list" item="item" index="index" separator=" " open="case UNIT_NO" close="end">
          when #{item.unitNo,jdbcType=VARCHAR} then #{item.createManNo,jdbcType=VARCHAR}
       </foreach>
       ,CREATE_MAN_NAME=
       <foreach collection="list" item="item" index="index" separator=" " open="case UNIT_NO" close="end">
          when #{item.unitNo,jdbcType=VARCHAR} then #{item.createManName,jdbcType=VARCHAR}
       </foreach>
       ,CREATE_TIME=
       <foreach collection="list" item="item" index="index" separator=" " open="case UNIT_NO" close="end">
          when #{item.unitNo,jdbcType=VARCHAR} then #{item.createTime,jdbcType=TIMESTAMP}
       </foreach>
     where UNIT_NO in 
     <foreach collection="list" index="index" item="item" separator="," open="(" close=")">
    #{item.unitNo,jdbcType=VARCHAR}
     </foreach> 
  </update>
  <delete id="batchDelete" parameterType="java.util.List">
    delete from METER_BASE_SPECIAL_UNIT
    where UNIT_NO in 
    <foreach collection="list" item="id" open="(" close=")" separator=",">
      #{id}
    </foreach>
  </delete>
  <!-- 友情提示！！！-->
  <!-- 请将自己写的代码放在此标签之下，方便以后粘贴复制。-->
  <select id="likeByDesc" parameterType="java.util.HashMap" resultMap="BaseResultMap">
    <include refid="select"/>
    <include refid="whereLike"/>
    order By create_time desc
  </select>
</mapper>