<?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.meterbasehistaredetail.mapper.MeterBaseHisTareDetailMapper">
  <resultMap id="BaseResultMap" type="com.steerinfo.baseinfo.meterbasehistaredetail.model.MeterBaseHisTareDetail">
    <id column="DETAIL_NO" jdbcType="VARCHAR" property="detailNo" />
    <result column="ACTUAL_FIRST_NO" jdbcType="VARCHAR" property="actualFirstNo" />
    <result column="BASE_SPOT_NO" jdbcType="VARCHAR" property="baseSpotNo" />
    <result column="BASE_SPOT_NAME" jdbcType="VARCHAR" property="baseSpotName" />
    <result column="CAR_NO" jdbcType="VARCHAR" property="carNo" />
    <result column="METER_WEIGHT" jdbcType="DECIMAL" property="meterWeight" />
    <result column="METER_NAME" jdbcType="VARCHAR" property="meterName" />
    <result column="METER_TIME" jdbcType="TIMESTAMP" property="meterTime" />
    <result column="METER_ORDER" jdbcType="VARCHAR" property="meterOrder" />
    <result column="VALUE_FLAG" jdbcType="VARCHAR" property="valueFlag" />
  </resultMap>
  <sql id="columns">
    DETAIL_NO, ACTUAL_FIRST_NO, BASE_SPOT_NO, BASE_SPOT_NAME, CAR_NO, METER_WEIGHT, METER_NAME, 
    METER_TIME, METER_ORDER, VALUE_FLAG
  </sql>
  <sql id="columns_alias">
    t.DETAIL_NO, t.ACTUAL_FIRST_NO, t.BASE_SPOT_NO, t.BASE_SPOT_NAME, t.CAR_NO, t.METER_WEIGHT, 
    t.METER_NAME, t.METER_TIME, t.METER_ORDER, t.VALUE_FLAG
  </sql>
  <sql id="select">
    SELECT <include refid="columns" /> FROM METER_BASE_HIS_TARE_DETAIL
  </sql>
  <sql id="select_alias">
    SELECT <include refid="columns_alias" /> FROM METER_BASE_HIS_TARE_DETAIL t
  </sql>
  <sql id="where">
    <where> 
      <if test="detailNo != null and detailNo != ''">
        and DETAIL_NO = #{detailNo}
      </if>
      <if test="actualFirstNo != null and actualFirstNo != ''">
        and ACTUAL_FIRST_NO = #{actualFirstNo}
      </if>
      <if test="baseSpotNo != null and baseSpotNo != ''">
        and BASE_SPOT_NO = #{baseSpotNo}
      </if>
      <if test="baseSpotName != null and baseSpotName != ''">
        and BASE_SPOT_NAME = #{baseSpotName}
      </if>
      <if test="carNo != null and carNo != ''">
        and CAR_NO = #{carNo}
      </if>
      <if test="meterWeight != null">
        and METER_WEIGHT = #{meterWeight}
      </if>
      <if test="meterName != null and meterName != ''">
        and METER_NAME = #{meterName}
      </if>
      <if test="meterTime != null">
        and TO_CHAR(METER_TIME,'yyyy-MM-dd') = #{meterTime}
      </if>
      <if test="meterOrder != null and meterOrder != ''">
        and METER_ORDER = #{meterOrder}
      </if>
      <if test="valueFlag != null and valueFlag != ''">
        and VALUE_FLAG = #{valueFlag}
      </if>
    </where>
  </sql>
  <sql id="whereLike">
    <where> 
      <if test="detailNo != null and detailNo != ''">
        and DETAIL_NO LIKE '%${detailNo}%'
      </if>
      <if test="actualFirstNo != null and actualFirstNo != ''">
        and ACTUAL_FIRST_NO LIKE '%${actualFirstNo}%'
      </if>
      <if test="baseSpotNo != null and baseSpotNo != ''">
        and BASE_SPOT_NO LIKE '%${baseSpotNo}%'
      </if>
      <if test="baseSpotName != null and baseSpotName != ''">
        and BASE_SPOT_NAME LIKE '%${baseSpotName}%'
      </if>
      <if test="carNo != null and carNo != ''">
        and CAR_NO LIKE '%${carNo}%'
      </if>
      <if test="meterWeight != null">
        and METER_WEIGHT = #{meterWeight}
      </if>
      <if test="meterName != null and meterName != ''">
        and METER_NAME LIKE '%${meterName}%'
      </if>
      <if test="meterTime != null">
        and TO_CHAR(METER_TIME,'yyyy-MM-dd') = #{meterTime}
      </if>
      <if test="meterOrder != null and meterOrder != ''">
        and METER_ORDER LIKE '%${meterOrder}%'
      </if>
      <if test="valueFlag != null and valueFlag != ''">
        and VALUE_FLAG LIKE '%${valueFlag}%'
      </if>
    </where>
  </sql>
  <delete id="deleteByPrimaryKey" parameterType="java.lang.String">
    delete from METER_BASE_HIS_TARE_DETAIL
    where DETAIL_NO = #{detailNo,jdbcType=VARCHAR}
  </delete>
  <delete id="deleteBySelectiveElement" parameterType="java.util.HashMap">
    delete from METER_BASE_HIS_TARE_DETAIL
    where 1!=1 
      <if test="actualFirstNo != null and actualFirstNo != ''">
        or ACTUAL_FIRST_NO = #{actualFirstNo}
      </if>
      <if test="baseSpotNo != null and baseSpotNo != ''">
        or BASE_SPOT_NO = #{baseSpotNo}
      </if>
      <if test="baseSpotName != null and baseSpotName != ''">
        or BASE_SPOT_NAME = #{baseSpotName}
      </if>
      <if test="carNo != null and carNo != ''">
        or CAR_NO = #{carNo}
      </if>
      <if test="meterWeight != null">
        or METER_WEIGHT = #{meterWeight}
      </if>
      <if test="meterName != null and meterName != ''">
        or METER_NAME = #{meterName}
      </if>
      <if test="meterTime != null">
        or TO_CHAR(METER_TIME,'yyyy-MM-dd') = '#{meterTime}'
      </if>
      <if test="meterOrder != null and meterOrder != ''">
        or METER_ORDER = #{meterOrder}
      </if>
      <if test="valueFlag != null and valueFlag != ''">
        or VALUE_FLAG = #{valueFlag}
      </if>
  </delete>
  <insert id="insert" parameterType="com.steerinfo.baseinfo.meterbasehistaredetail.model.MeterBaseHisTareDetail">
    insert into METER_BASE_HIS_TARE_DETAIL (DETAIL_NO, ACTUAL_FIRST_NO, BASE_SPOT_NO, 
      BASE_SPOT_NAME, CAR_NO, METER_WEIGHT, 
      METER_NAME, METER_TIME, METER_ORDER, 
      VALUE_FLAG)
    values (#{detailNo,jdbcType=VARCHAR}, #{actualFirstNo,jdbcType=VARCHAR}, #{baseSpotNo,jdbcType=VARCHAR}, 
      #{baseSpotName,jdbcType=VARCHAR}, #{carNo,jdbcType=VARCHAR}, #{meterWeight,jdbcType=DECIMAL}, 
      #{meterName,jdbcType=VARCHAR}, #{meterTime,jdbcType=TIMESTAMP}, #{meterOrder,jdbcType=VARCHAR}, 
      #{valueFlag,jdbcType=VARCHAR})
  </insert>
  <insert id="insertSelective" parameterType="com.steerinfo.baseinfo.meterbasehistaredetail.model.MeterBaseHisTareDetail">
    insert into METER_BASE_HIS_TARE_DETAIL
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="detailNo != null">
        DETAIL_NO,
      </if>
      <if test="actualFirstNo != null">
        ACTUAL_FIRST_NO,
      </if>
      <if test="baseSpotNo != null">
        BASE_SPOT_NO,
      </if>
      <if test="baseSpotName != null">
        BASE_SPOT_NAME,
      </if>
      <if test="carNo != null">
        CAR_NO,
      </if>
      <if test="meterWeight != null">
        METER_WEIGHT,
      </if>
      <if test="meterName != null">
        METER_NAME,
      </if>
      <if test="meterTime != null">
        METER_TIME,
      </if>
      <if test="meterOrder != null">
        METER_ORDER,
      </if>
      <if test="valueFlag != null">
        VALUE_FLAG,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides=",">
      <if test="detailNo != null">
        #{detailNo,jdbcType=VARCHAR},
      </if>
      <if test="actualFirstNo != null">
        #{actualFirstNo,jdbcType=VARCHAR},
      </if>
      <if test="baseSpotNo != null">
        #{baseSpotNo,jdbcType=VARCHAR},
      </if>
      <if test="baseSpotName != null">
        #{baseSpotName,jdbcType=VARCHAR},
      </if>
      <if test="carNo != null">
        #{carNo,jdbcType=VARCHAR},
      </if>
      <if test="meterWeight != null">
        #{meterWeight,jdbcType=DECIMAL},
      </if>
      <if test="meterName != null">
        #{meterName,jdbcType=VARCHAR},
      </if>
      <if test="meterTime != null">
        #{meterTime,jdbcType=TIMESTAMP},
      </if>
      <if test="meterOrder != null">
        #{meterOrder,jdbcType=VARCHAR},
      </if>
      <if test="valueFlag != null">
        #{valueFlag,jdbcType=VARCHAR},
      </if>
    </trim>
  </insert>
  <update id="updateByPrimaryKey" parameterType="com.steerinfo.baseinfo.meterbasehistaredetail.model.MeterBaseHisTareDetail">
    update METER_BASE_HIS_TARE_DETAIL
    set ACTUAL_FIRST_NO = #{actualFirstNo,jdbcType=VARCHAR},
      BASE_SPOT_NO = #{baseSpotNo,jdbcType=VARCHAR},
      BASE_SPOT_NAME = #{baseSpotName,jdbcType=VARCHAR},
      CAR_NO = #{carNo,jdbcType=VARCHAR},
      METER_WEIGHT = #{meterWeight,jdbcType=DECIMAL},
      METER_NAME = #{meterName,jdbcType=VARCHAR},
      METER_TIME = #{meterTime,jdbcType=TIMESTAMP},
      METER_ORDER = #{meterOrder,jdbcType=VARCHAR},
      VALUE_FLAG = #{valueFlag,jdbcType=VARCHAR}
    where DETAIL_NO = #{detailNo,jdbcType=VARCHAR}
  </update>
  <update id="updateByPrimaryKeySelective" parameterType="com.steerinfo.baseinfo.meterbasehistaredetail.model.MeterBaseHisTareDetail">
    update METER_BASE_HIS_TARE_DETAIL
    <set>
      <if test="actualFirstNo != null">
        ACTUAL_FIRST_NO = #{actualFirstNo,jdbcType=VARCHAR},
      </if>
      <if test="baseSpotNo != null">
        BASE_SPOT_NO = #{baseSpotNo,jdbcType=VARCHAR},
      </if>
      <if test="baseSpotName != null">
        BASE_SPOT_NAME = #{baseSpotName,jdbcType=VARCHAR},
      </if>
      <if test="carNo != null">
        CAR_NO = #{carNo,jdbcType=VARCHAR},
      </if>
      <if test="meterWeight != null">
        METER_WEIGHT = #{meterWeight,jdbcType=DECIMAL},
      </if>
      <if test="meterName != null">
        METER_NAME = #{meterName,jdbcType=VARCHAR},
      </if>
      <if test="meterTime != null">
        METER_TIME = #{meterTime,jdbcType=TIMESTAMP},
      </if>
      <if test="meterOrder != null">
        METER_ORDER = #{meterOrder,jdbcType=VARCHAR},
      </if>
      <if test="valueFlag != null">
        VALUE_FLAG = #{valueFlag,jdbcType=VARCHAR},
      </if>
    </set>
    where DETAIL_NO = #{detailNo,jdbcType=VARCHAR}
  </update>
  <select id="selectByPrimaryKey" parameterType="java.lang.String" resultMap="BaseResultMap">
    <include refid="select" />
    where DETAIL_NO = #{detailNo,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_HIS_TARE_DETAIL 
      (DETAIL_NO, 
      ACTUAL_FIRST_NO, BASE_SPOT_NO, BASE_SPOT_NAME, 
      CAR_NO, METER_WEIGHT, METER_NAME, 
      METER_TIME, METER_ORDER, VALUE_FLAG
      )
    ( <foreach collection="list" item="item" separator="union all"> 
   select  
      #{item.detailNo,jdbcType=VARCHAR}, 
      #{item.actualFirstNo,jdbcType=VARCHAR}, #{item.baseSpotNo,jdbcType=VARCHAR}, #{item.baseSpotName,jdbcType=VARCHAR}, 
      #{item.carNo,jdbcType=VARCHAR}, #{item.meterWeight,jdbcType=DECIMAL}, #{item.meterName,jdbcType=VARCHAR}, 
      #{item.meterTime,jdbcType=TIMESTAMP}, #{item.meterOrder,jdbcType=VARCHAR}, #{item.valueFlag,jdbcType=VARCHAR}
       from dual  
   </foreach> )
  </insert>
  <update id="batchUpdate" parameterType="java.util.List">
     update METER_BASE_HIS_TARE_DETAIL
     set
       DETAIL_NO=
       <foreach close="end" collection="list" index="index" item="item" open="case DETAIL_NO" separator=" ">
          when #{item.detailNo,jdbcType=VARCHAR} then #{item.detailNo,jdbcType=VARCHAR}
       </foreach>
       ,ACTUAL_FIRST_NO=
       <foreach close="end" collection="list" index="index" item="item" open="case DETAIL_NO" separator=" ">
          when #{item.detailNo,jdbcType=VARCHAR} then #{item.actualFirstNo,jdbcType=VARCHAR}
       </foreach>
       ,BASE_SPOT_NO=
       <foreach close="end" collection="list" index="index" item="item" open="case DETAIL_NO" separator=" ">
          when #{item.detailNo,jdbcType=VARCHAR} then #{item.baseSpotNo,jdbcType=VARCHAR}
       </foreach>
       ,BASE_SPOT_NAME=
       <foreach close="end" collection="list" index="index" item="item" open="case DETAIL_NO" separator=" ">
          when #{item.detailNo,jdbcType=VARCHAR} then #{item.baseSpotName,jdbcType=VARCHAR}
       </foreach>
       ,CAR_NO=
       <foreach close="end" collection="list" index="index" item="item" open="case DETAIL_NO" separator=" ">
          when #{item.detailNo,jdbcType=VARCHAR} then #{item.carNo,jdbcType=VARCHAR}
       </foreach>
       ,METER_WEIGHT=
       <foreach close="end" collection="list" index="index" item="item" open="case DETAIL_NO" separator=" ">
          when #{item.detailNo,jdbcType=VARCHAR} then #{item.meterWeight,jdbcType=DECIMAL}
       </foreach>
       ,METER_NAME=
       <foreach close="end" collection="list" index="index" item="item" open="case DETAIL_NO" separator=" ">
          when #{item.detailNo,jdbcType=VARCHAR} then #{item.meterName,jdbcType=VARCHAR}
       </foreach>
       ,METER_TIME=
       <foreach close="end" collection="list" index="index" item="item" open="case DETAIL_NO" separator=" ">
          when #{item.detailNo,jdbcType=VARCHAR} then #{item.meterTime,jdbcType=TIMESTAMP}
       </foreach>
       ,METER_ORDER=
       <foreach close="end" collection="list" index="index" item="item" open="case DETAIL_NO" separator=" ">
          when #{item.detailNo,jdbcType=VARCHAR} then #{item.meterOrder,jdbcType=VARCHAR}
       </foreach>
       ,VALUE_FLAG=
       <foreach close="end" collection="list" index="index" item="item" open="case DETAIL_NO" separator=" ">
          when #{item.detailNo,jdbcType=VARCHAR} then #{item.valueFlag,jdbcType=VARCHAR}
       </foreach>
     where DETAIL_NO in 
     <foreach close=")" collection="list" index="index" item="item" open="(" separator=",">
    #{item.detailNo,jdbcType=VARCHAR}
     </foreach> 
  </update>
  <delete id="batchDelete" parameterType="java.util.List">
    delete from METER_BASE_HIS_TARE_DETAIL
    where DETAIL_NO in 
    <foreach close=")" collection="list" item="id" open="(" separator=",">
      #{id}
    </foreach>
  </delete>
  <!-- 友情提示！！！-->
  <!-- 请将自己写的代码放在此标签之下，方便以后粘贴复制。-->
  <select id="getNewID" parameterType="java.lang.String" resultType="java.lang.String">
    SELECT LPAD(NVL(MAX(TO_NUMBER(SUBSTR(DETAIL_NO, LENGTH(DETAIL_NO) - 3))),0) + 1,4,'0') DETAIL_NO
    FROM METER_BASE_HIS_TARE_DETAIL where instr(DETAIL_NO,#{afl,jdbcType=VARCHAR})>0
  </select>
  
</mapper>