<?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.meterwork.meterworkcomparespotscale.mapper.MeterWorkCompareSpotScaleMapper">
  <resultMap id="BaseResultMap" type="com.steerinfo.meterwork.meterworkcomparespotscale.model.MeterWorkCompareSpotScale">
    <id column="COMPARE_SPOT_SCALE_ID" jdbcType="VARCHAR" property="compareSpotScaleId" />
    <result column="VALUE_FLAG" jdbcType="VARCHAR" property="valueFlag" />
    <result column="CREATE_MAN_NAME" jdbcType="VARCHAR" property="createManName" />
    <result column="CREATE_TIME" jdbcType="TIMESTAMP" property="createTime" />
    <result column="UPDATE_MAN_NAME" jdbcType="VARCHAR" property="updateManName" />
    <result column="UPDATE_TIME" jdbcType="TIMESTAMP" property="updateTime" />
    <result column="CREATE_MAN_PHONE" jdbcType="VARCHAR" property="createManPhone" />
    <result column="UPDATE_MAN_PHONE" jdbcType="VARCHAR" property="updateManPhone" />
    <result column="CAR_NO" jdbcType="VARCHAR" property="carNo" />
    <result column="NUM" jdbcType="DECIMAL" property="num" />
    <result column="USED_NUM" jdbcType="DECIMAL" property="usedNum" />
  </resultMap>
  <sql id="columns">
    COMPARE_SPOT_SCALE_ID, VALUE_FLAG, CREATE_MAN_NAME, CREATE_TIME, UPDATE_MAN_NAME, 
    UPDATE_TIME, CREATE_MAN_PHONE, UPDATE_MAN_PHONE, CAR_NO, NUM, USED_NUM
  </sql>
  <sql id="columns_alias">
    t.COMPARE_SPOT_SCALE_ID, t.VALUE_FLAG, t.CREATE_MAN_NAME, t.CREATE_TIME, t.UPDATE_MAN_NAME, 
    t.UPDATE_TIME, t.CREATE_MAN_PHONE, t.UPDATE_MAN_PHONE, t.CAR_NO, t.NUM, t.USED_NUM
  </sql>
  <sql id="select">
    SELECT <include refid="columns" /> FROM METER_WORK_COMPARE_SPOT_SCALE
  </sql>
  <sql id="select_alias">
    SELECT <include refid="columns_alias" /> FROM METER_WORK_COMPARE_SPOT_SCALE t
  </sql>
  <sql id="where">
    <where> 
      <if test="compareSpotScaleId != null and compareSpotScaleId != ''">
        and COMPARE_SPOT_SCALE_ID = #{compareSpotScaleId}
      </if>
      <if test="valueFlag != null and valueFlag != ''">
        and VALUE_FLAG = #{valueFlag}
      </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>
      <if test="updateManName != null and updateManName != ''">
        and UPDATE_MAN_NAME = #{updateManName}
      </if>
      <if test="updateTime != null">
        and TO_CHAR(UPDATE_TIME,'yyyy-MM-dd') = #{updateTime}
      </if>
      <if test="createManPhone != null and createManPhone != ''">
        and CREATE_MAN_PHONE = #{createManPhone}
      </if>
      <if test="updateManPhone != null and updateManPhone != ''">
        and UPDATE_MAN_PHONE = #{updateManPhone}
      </if>
      <if test="carNo != null and carNo != ''">
        and CAR_NO = #{carNo}
      </if>
      <if test="num != null">
        and NUM = #{num}
      </if>
      <if test="usedNum != null">
        and USED_NUM = #{usedNum}
      </if>
    </where>
  </sql>
  <sql id="whereLike">
    <where> 
      <if test="compareSpotScaleId != null and compareSpotScaleId != ''">
        and COMPARE_SPOT_SCALE_ID LIKE '%${compareSpotScaleId}%'
      </if>
      <if test="valueFlag != null and valueFlag != ''">
        and VALUE_FLAG LIKE '%${valueFlag}%'
      </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>
      <if test="updateManName != null and updateManName != ''">
        and UPDATE_MAN_NAME LIKE '%${updateManName}%'
      </if>
      <if test="updateTime != null">
        and TO_CHAR(UPDATE_TIME,'yyyy-MM-dd') = #{updateTime}
      </if>
      <if test="createManPhone != null and createManPhone != ''">
        and CREATE_MAN_PHONE LIKE '%${createManPhone}%'
      </if>
      <if test="updateManPhone != null and updateManPhone != ''">
        and UPDATE_MAN_PHONE LIKE '%${updateManPhone}%'
      </if>
      <if test="carNo != null and carNo != ''">
        and CAR_NO LIKE '%${carNo}%'
      </if>
      <if test="num != null">
        and NUM = #{num}
      </if>
      <if test="usedNum != null">
        and USED_NUM = #{usedNum}
      </if>
    </where>
  </sql>
  <delete id="deleteByPrimaryKey" parameterType="java.lang.String">
    delete from METER_WORK_COMPARE_SPOT_SCALE
    where COMPARE_SPOT_SCALE_ID = #{compareSpotScaleId,jdbcType=VARCHAR}
  </delete>
  <delete id="deleteBySelectiveElement" parameterType="java.util.HashMap">
    delete from METER_WORK_COMPARE_SPOT_SCALE
    where 1!=1 
      <if test="valueFlag != null and valueFlag != ''">
        or VALUE_FLAG = #{valueFlag}
      </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>
      <if test="updateManName != null and updateManName != ''">
        or UPDATE_MAN_NAME = #{updateManName}
      </if>
      <if test="updateTime != null">
        or TO_CHAR(UPDATE_TIME,'yyyy-MM-dd') = '#{updateTime}'
      </if>
      <if test="createManPhone != null and createManPhone != ''">
        or CREATE_MAN_PHONE = #{createManPhone}
      </if>
      <if test="updateManPhone != null and updateManPhone != ''">
        or UPDATE_MAN_PHONE = #{updateManPhone}
      </if>
      <if test="carNo != null and carNo != ''">
        or CAR_NO = #{carNo}
      </if>
      <if test="num != null">
        or NUM = #{num}
      </if>
      <if test="usedNum != null">
        or USED_NUM = #{usedNum}
      </if>
  </delete>
  <insert id="insert" parameterType="com.steerinfo.meterwork.meterworkcomparespotscale.model.MeterWorkCompareSpotScale">
    insert into METER_WORK_COMPARE_SPOT_SCALE (COMPARE_SPOT_SCALE_ID, VALUE_FLAG, CREATE_MAN_NAME, 
      CREATE_TIME, UPDATE_MAN_NAME, UPDATE_TIME, 
      CREATE_MAN_PHONE, UPDATE_MAN_PHONE, CAR_NO, 
      NUM, USED_NUM)
    values (#{compareSpotScaleId,jdbcType=VARCHAR}, #{valueFlag,jdbcType=VARCHAR}, #{createManName,jdbcType=VARCHAR}, 
      #{createTime,jdbcType=TIMESTAMP}, #{updateManName,jdbcType=VARCHAR}, #{updateTime,jdbcType=TIMESTAMP}, 
      #{createManPhone,jdbcType=VARCHAR}, #{updateManPhone,jdbcType=VARCHAR}, #{carNo,jdbcType=VARCHAR}, 
      #{num,jdbcType=DECIMAL}, #{usedNum,jdbcType=DECIMAL})
  </insert>
  <insert id="insertSelective" parameterType="com.steerinfo.meterwork.meterworkcomparespotscale.model.MeterWorkCompareSpotScale">
    insert into METER_WORK_COMPARE_SPOT_SCALE
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="compareSpotScaleId != null">
        COMPARE_SPOT_SCALE_ID,
      </if>
      <if test="valueFlag != null">
        VALUE_FLAG,
      </if>
      <if test="createManName != null">
        CREATE_MAN_NAME,
      </if>
      <if test="createTime != null">
        CREATE_TIME,
      </if>
      <if test="updateManName != null">
        UPDATE_MAN_NAME,
      </if>
      <if test="updateTime != null">
        UPDATE_TIME,
      </if>
      <if test="createManPhone != null">
        CREATE_MAN_PHONE,
      </if>
      <if test="updateManPhone != null">
        UPDATE_MAN_PHONE,
      </if>
      <if test="carNo != null">
        CAR_NO,
      </if>
      <if test="num != null">
        NUM,
      </if>
      <if test="usedNum != null">
        USED_NUM,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides=",">
      <if test="compareSpotScaleId != null">
        #{compareSpotScaleId,jdbcType=VARCHAR},
      </if>
      <if test="valueFlag != null">
        #{valueFlag,jdbcType=VARCHAR},
      </if>
      <if test="createManName != null">
        #{createManName,jdbcType=VARCHAR},
      </if>
      <if test="createTime != null">
        #{createTime,jdbcType=TIMESTAMP},
      </if>
      <if test="updateManName != null">
        #{updateManName,jdbcType=VARCHAR},
      </if>
      <if test="updateTime != null">
        #{updateTime,jdbcType=TIMESTAMP},
      </if>
      <if test="createManPhone != null">
        #{createManPhone,jdbcType=VARCHAR},
      </if>
      <if test="updateManPhone != null">
        #{updateManPhone,jdbcType=VARCHAR},
      </if>
      <if test="carNo != null">
        #{carNo,jdbcType=VARCHAR},
      </if>
      <if test="num != null">
        #{num,jdbcType=DECIMAL},
      </if>
      <if test="usedNum != null">
        #{usedNum,jdbcType=DECIMAL},
      </if>
    </trim>
  </insert>
  <update id="updateByPrimaryKey" parameterType="com.steerinfo.meterwork.meterworkcomparespotscale.model.MeterWorkCompareSpotScale">
    update METER_WORK_COMPARE_SPOT_SCALE
    set VALUE_FLAG = #{valueFlag,jdbcType=VARCHAR},
      CREATE_MAN_NAME = #{createManName,jdbcType=VARCHAR},
      CREATE_TIME = #{createTime,jdbcType=TIMESTAMP},
      UPDATE_MAN_NAME = #{updateManName,jdbcType=VARCHAR},
      UPDATE_TIME = #{updateTime,jdbcType=TIMESTAMP},
      CREATE_MAN_PHONE = #{createManPhone,jdbcType=VARCHAR},
      UPDATE_MAN_PHONE = #{updateManPhone,jdbcType=VARCHAR},
      CAR_NO = #{carNo,jdbcType=VARCHAR},
      NUM = #{num,jdbcType=DECIMAL},
      USED_NUM = #{usedNum,jdbcType=DECIMAL}
    where COMPARE_SPOT_SCALE_ID = #{compareSpotScaleId,jdbcType=VARCHAR}
  </update>
  <update id="updateByPrimaryKeySelective" parameterType="com.steerinfo.meterwork.meterworkcomparespotscale.model.MeterWorkCompareSpotScale">
    update METER_WORK_COMPARE_SPOT_SCALE
    <set>
      <if test="valueFlag != null">
        VALUE_FLAG = #{valueFlag,jdbcType=VARCHAR},
      </if>
      <if test="createManName != null">
        CREATE_MAN_NAME = #{createManName,jdbcType=VARCHAR},
      </if>
      <if test="createTime != null">
        CREATE_TIME = #{createTime,jdbcType=TIMESTAMP},
      </if>
      <if test="updateManName != null">
        UPDATE_MAN_NAME = #{updateManName,jdbcType=VARCHAR},
      </if>
      <if test="updateTime != null">
        UPDATE_TIME = #{updateTime,jdbcType=TIMESTAMP},
      </if>
      <if test="createManPhone != null">
        CREATE_MAN_PHONE = #{createManPhone,jdbcType=VARCHAR},
      </if>
      <if test="updateManPhone != null">
        UPDATE_MAN_PHONE = #{updateManPhone,jdbcType=VARCHAR},
      </if>
      <if test="carNo != null">
        CAR_NO = #{carNo,jdbcType=VARCHAR},
      </if>
      <if test="num != null">
        NUM = #{num,jdbcType=DECIMAL},
      </if>
      <if test="usedNum != null">
        USED_NUM = #{usedNum,jdbcType=DECIMAL},
      </if>
    </set>
    where COMPARE_SPOT_SCALE_ID = #{compareSpotScaleId,jdbcType=VARCHAR}
  </update>
  <select id="selectByPrimaryKey" parameterType="java.lang.String" resultMap="BaseResultMap">
    <include refid="select" />
    where COMPARE_SPOT_SCALE_ID = #{compareSpotScaleId,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_WORK_COMPARE_SPOT_SCALE 
      (COMPARE_SPOT_SCALE_ID, 
      VALUE_FLAG, CREATE_MAN_NAME, CREATE_TIME, 
      UPDATE_MAN_NAME, UPDATE_TIME, 
      CREATE_MAN_PHONE, UPDATE_MAN_PHONE, 
      CAR_NO, NUM, USED_NUM
      )
    ( <foreach collection="list" item="item" separator="union all"> 
   select  
      #{item.compareSpotScaleId,jdbcType=VARCHAR}, 
      #{item.valueFlag,jdbcType=VARCHAR}, #{item.createManName,jdbcType=VARCHAR}, #{item.createTime,jdbcType=TIMESTAMP}, 
      #{item.updateManName,jdbcType=VARCHAR}, #{item.updateTime,jdbcType=TIMESTAMP}, 
      #{item.createManPhone,jdbcType=VARCHAR}, #{item.updateManPhone,jdbcType=VARCHAR}, 
      #{item.carNo,jdbcType=VARCHAR}, #{item.num,jdbcType=DECIMAL}, #{item.usedNum,jdbcType=DECIMAL}
       from dual  
   </foreach> )
  </insert>
  <update id="batchUpdate" parameterType="java.util.List">
     update METER_WORK_COMPARE_SPOT_SCALE
     set
       COMPARE_SPOT_SCALE_ID=
       <foreach close="end" collection="list" index="index" item="item" open="case COMPARE_SPOT_SCALE_ID" separator=" ">
          when #{item.compareSpotScaleId,jdbcType=VARCHAR} then #{item.compareSpotScaleId,jdbcType=VARCHAR}
       </foreach>
       ,VALUE_FLAG=
       <foreach close="end" collection="list" index="index" item="item" open="case COMPARE_SPOT_SCALE_ID" separator=" ">
          when #{item.compareSpotScaleId,jdbcType=VARCHAR} then #{item.valueFlag,jdbcType=VARCHAR}
       </foreach>
       ,CREATE_MAN_NAME=
       <foreach close="end" collection="list" index="index" item="item" open="case COMPARE_SPOT_SCALE_ID" separator=" ">
          when #{item.compareSpotScaleId,jdbcType=VARCHAR} then #{item.createManName,jdbcType=VARCHAR}
       </foreach>
       ,CREATE_TIME=
       <foreach close="end" collection="list" index="index" item="item" open="case COMPARE_SPOT_SCALE_ID" separator=" ">
          when #{item.compareSpotScaleId,jdbcType=VARCHAR} then #{item.createTime,jdbcType=TIMESTAMP}
       </foreach>
       ,UPDATE_MAN_NAME=
       <foreach close="end" collection="list" index="index" item="item" open="case COMPARE_SPOT_SCALE_ID" separator=" ">
          when #{item.compareSpotScaleId,jdbcType=VARCHAR} then #{item.updateManName,jdbcType=VARCHAR}
       </foreach>
       ,UPDATE_TIME=
       <foreach close="end" collection="list" index="index" item="item" open="case COMPARE_SPOT_SCALE_ID" separator=" ">
          when #{item.compareSpotScaleId,jdbcType=VARCHAR} then #{item.updateTime,jdbcType=TIMESTAMP}
       </foreach>
       ,CREATE_MAN_PHONE=
       <foreach close="end" collection="list" index="index" item="item" open="case COMPARE_SPOT_SCALE_ID" separator=" ">
          when #{item.compareSpotScaleId,jdbcType=VARCHAR} then #{item.createManPhone,jdbcType=VARCHAR}
       </foreach>
       ,UPDATE_MAN_PHONE=
       <foreach close="end" collection="list" index="index" item="item" open="case COMPARE_SPOT_SCALE_ID" separator=" ">
          when #{item.compareSpotScaleId,jdbcType=VARCHAR} then #{item.updateManPhone,jdbcType=VARCHAR}
       </foreach>
       ,CAR_NO=
       <foreach close="end" collection="list" index="index" item="item" open="case COMPARE_SPOT_SCALE_ID" separator=" ">
          when #{item.compareSpotScaleId,jdbcType=VARCHAR} then #{item.carNo,jdbcType=VARCHAR}
       </foreach>
       ,NUM=
       <foreach close="end" collection="list" index="index" item="item" open="case COMPARE_SPOT_SCALE_ID" separator=" ">
          when #{item.compareSpotScaleId,jdbcType=VARCHAR} then #{item.num,jdbcType=DECIMAL}
       </foreach>
       ,USED_NUM=
       <foreach close="end" collection="list" index="index" item="item" open="case COMPARE_SPOT_SCALE_ID" separator=" ">
          when #{item.compareSpotScaleId,jdbcType=VARCHAR} then #{item.usedNum,jdbcType=DECIMAL}
       </foreach>
     where COMPARE_SPOT_SCALE_ID in 
     <foreach close=")" collection="list" index="index" item="item" open="(" separator=",">
    #{item.compareSpotScaleId,jdbcType=VARCHAR}
     </foreach> 
  </update>
  <delete id="batchDelete" parameterType="java.util.List">
    delete from METER_WORK_COMPARE_SPOT_SCALE
    where COMPARE_SPOT_SCALE_ID 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(COMPARE_SPOT_ID, LENGTH(COMPARE_SPOT_ID) - 4))),0) + 1,5,'0') COMPARE_SPOT_ID
    FROM METER_WORK_COMPARE_SPOT
  </select>

  <select id="isExistWithinHour" resultType="java.lang.String">
    SELECT COMPARE_SPOT_SCALE_ID FROM (SELECT * FROM METER_WORK_COMPARE_SPOT_SCALE WHERE (CREATE_TIME BETWEEN SYSDATE-(#{time}/24) AND SYSDATE) AND CAR_NO = #{carNo} AND VALUE_FLAG = 1 ORDER BY CREATE_TIME DESC )  WHERE ROWNUM = 1
  </select>
  
  <select id="getAllScaleNo" resultMap="BaseResultMap">
    SELECT * FROM METER_WORK_COMPARE_SPOT_SCALE WHERE (CREATE_TIME BETWEEN SYSDATE-1 AND sysdate+(1/24*6)) AND VALUE_FLAG != 0 ORDER BY CREATE_TIME DESC
  </select>

</mapper>