<?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.meterworkstockonline.mapper.MeterWorkStockOnlineMapper">
  <resultMap id="BaseResultMap" type="com.steerinfo.meterwork.meterworkstockonline.model.MeterWorkStockOnline">
    <id column="BASE_SPOT_NO" jdbcType="VARCHAR" property="baseSpotNo" />
    <result column="SPOT_TYPE_NO" jdbcType="VARCHAR" property="spotTypeNo" />
    <result column="WEIGHT_FLAG" jdbcType="VARCHAR" property="weightFlag" />
    <result column="WORK_FLAG" jdbcType="VARCHAR" property="workFlag" />
    <result column="USER_IP" jdbcType="VARCHAR" property="userIp" />
    <result column="USER_ID" jdbcType="VARCHAR" property="userId" />
    <result column="LAST_TIME" jdbcType="TIMESTAMP" property="lastTime" />
    <result column="WEIGHT_TIME" jdbcType="TIMESTAMP" property="weightTime" />
    <result column="BASE_SPOT_NAME" jdbcType="VARCHAR" property="baseSpotName" />
    <result column="POINT_NO" jdbcType="VARCHAR" property="pointNo" />
    <result column="VALID_FLAG" jdbcType="VARCHAR" property="validFlag" />
    <result column="WEIGHT_DIFF" jdbcType="VARCHAR" property="weightDiff" />
  </resultMap>
  <sql id="columns">
    BASE_SPOT_NO, SPOT_TYPE_NO, WEIGHT_FLAG, WORK_FLAG, USER_IP, USER_ID, LAST_TIME,
    WEIGHT_TIME, BASE_SPOT_NAME, POINT_NO, VALID_FLAG, WEIGHT_DIFF
  </sql>
  <sql id="columns_alias">
    t.BASE_SPOT_NO, t.SPOT_TYPE_NO, t.WEIGHT_FLAG, t.WORK_FLAG, t.USER_IP, t.USER_ID,
    t.LAST_TIME, t.WEIGHT_TIME, t.BASE_SPOT_NAME, t.POINT_NO, t.VALID_FLAG, t.WEIGHT_DIFF
  </sql>
  <sql id="select">
    SELECT <include refid="columns"/> FROM METER_WORK_STOCK_ONLINE
  </sql>
  <sql id="select_alias">
    SELECT <include refid="columns_alias"/> FROM METER_WORK_STOCK_ONLINE t
  </sql>
  <sql id="where">
    <where>
      <if test="baseSpotNo != null and baseSpotNo != ''">
        and BASE_SPOT_NO = #{baseSpotNo}
      </if>
      <if test="spotTypeNo != null and spotTypeNo != ''">
        and SPOT_TYPE_NO = #{spotTypeNo}
      </if>
      <if test="weightFlag != null and weightFlag != ''">
        and WEIGHT_FLAG = #{weightFlag}
      </if>
      <if test="workFlag != null and workFlag != ''">
        and WORK_FLAG = #{workFlag}
      </if>
      <if test="userIp != null and userIp != ''">
        and USER_IP = #{userIp}
      </if>
      <if test="userId != null and userId != ''">
        and USER_ID = #{userId}
      </if>
      <if test="lastTime != null">
        and TO_CHAR(LAST_TIME,'yyyy-MM-dd') = #{lastTime}
      </if>
      <if test="weightTime != null">
        and TO_CHAR(WEIGHT_TIME,'yyyy-MM-dd') = #{weightTime}
      </if>
      <if test="baseSpotName != null and baseSpotName != ''">
        and BASE_SPOT_NAME = #{baseSpotName}
      </if>
      <if test="pointNo != null and pointNo != ''">
        and POINT_NO = #{pointNo}
      </if>
      <if test="validFlag != null and validFlag != ''">
        and VALID_FLAG = #{validFlag}
      </if>
      <if test="weightDiff != null and weightDiff != ''">
        and WEIGHT_DIFF = #{weightDiff}
      </if>
    </where>
  </sql>
  <sql id="whereLike">
    <where>
      <if test="baseSpotNo != null and baseSpotNo != ''">
        and BASE_SPOT_NO LIKE '%${baseSpotNo}%'
      </if>
      <if test="spotTypeNo != null and spotTypeNo != ''">
        and SPOT_TYPE_NO LIKE '%${spotTypeNo}%'
      </if>
      <if test="weightFlag != null and weightFlag != ''">
        and WEIGHT_FLAG LIKE '%${weightFlag}%'
      </if>
      <if test="workFlag != null and workFlag != ''">
        and WORK_FLAG LIKE '%${workFlag}%'
      </if>
      <if test="userIp != null and userIp != ''">
        and USER_IP LIKE '%${userIp}%'
      </if>
      <if test="userId != null and userId != ''">
        and USER_ID LIKE '%${userId}%'
      </if>
      <if test="lastTime != null">
        and TO_CHAR(LAST_TIME,'yyyy-MM-dd') = #{lastTime}
      </if>
      <if test="weightTime != null">
        and TO_CHAR(WEIGHT_TIME,'yyyy-MM-dd') = #{weightTime}
      </if>
      <if test="baseSpotName != null and baseSpotName != ''">
        and BASE_SPOT_NAME LIKE '%${baseSpotName}%'
      </if>
      <if test="pointNo != null and pointNo != ''">
        and POINT_NO LIKE '%${pointNo}%'
      </if>
      <if test="validFlag != null and validFlag != ''">
        and VALID_FLAG LIKE '%${validFlag}%'
      </if>
      <if test="weightDiff != null and weightDiff != ''">
        and WEIGHT_DIFF LIKE '%${weightDiff}%'
      </if>
    </where>
  </sql>
  <delete id="deleteByPrimaryKey" parameterType="java.lang.String">
    delete from METER_WORK_STOCK_ONLINE
    where BASE_SPOT_NO = #{baseSpotNo,jdbcType=VARCHAR}
  </delete>
  <delete id="deleteBySelectiveElement" parameterType="java.util.HashMap">
    delete from METER_WORK_STOCK_ONLINE
    where 1!=1
    <if test="spotTypeNo != null and spotTypeNo != ''">
      or SPOT_TYPE_NO = #{spotTypeNo}
    </if>
    <if test="weightFlag != null and weightFlag != ''">
      or WEIGHT_FLAG = #{weightFlag}
    </if>
    <if test="workFlag != null and workFlag != ''">
      or WORK_FLAG = #{workFlag}
    </if>
    <if test="userIp != null and userIp != ''">
      or USER_IP = #{userIp}
    </if>
    <if test="userId != null and userId != ''">
      or USER_ID = #{userId}
    </if>
    <if test="lastTime != null">
      or TO_CHAR(LAST_TIME,'yyyy-MM-dd') = '#{lastTime}'
    </if>
    <if test="weightTime != null">
      or TO_CHAR(WEIGHT_TIME,'yyyy-MM-dd') = '#{weightTime}'
    </if>
    <if test="baseSpotName != null and baseSpotName != ''">
      or BASE_SPOT_NAME = #{baseSpotName}
    </if>
    <if test="pointNo != null and pointNo != ''">
      or POINT_NO = #{pointNo}
    </if>
    <if test="validFlag != null and validFlag != ''">
      or VALID_FLAG = #{validFlag}
    </if>
    <if test="weightDiff != null and weightDiff != ''">
      or WEIGHT_DIFF = #{weightDiff}
    </if>
  </delete>
  <insert id="insert" parameterType="com.steerinfo.meterwork.meterworkstockonline.model.MeterWorkStockOnline">
    insert into METER_WORK_STOCK_ONLINE (BASE_SPOT_NO, SPOT_TYPE_NO, WEIGHT_FLAG,
      WORK_FLAG, USER_IP, USER_ID,
      LAST_TIME, WEIGHT_TIME, BASE_SPOT_NAME,
      POINT_NO, VALID_FLAG, WEIGHT_DIFF
      )
    values (#{baseSpotNo,jdbcType=VARCHAR}, #{spotTypeNo,jdbcType=VARCHAR}, #{weightFlag,jdbcType=VARCHAR},
      #{workFlag,jdbcType=VARCHAR}, #{userIp,jdbcType=VARCHAR}, #{userId,jdbcType=VARCHAR},
      #{lastTime,jdbcType=TIMESTAMP}, #{weightTime,jdbcType=TIMESTAMP}, #{baseSpotName,jdbcType=VARCHAR},
      #{pointNo,jdbcType=VARCHAR}, #{validFlag,jdbcType=VARCHAR}, #{weightDiff,jdbcType=VARCHAR}
      )
  </insert>
  <insert id="insertSelective" parameterType="com.steerinfo.meterwork.meterworkstockonline.model.MeterWorkStockOnline">
    insert into METER_WORK_STOCK_ONLINE
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="baseSpotNo != null">
        BASE_SPOT_NO,
      </if>
      <if test="spotTypeNo != null">
        SPOT_TYPE_NO,
      </if>
      <if test="weightFlag != null">
        WEIGHT_FLAG,
      </if>
      <if test="workFlag != null">
        WORK_FLAG,
      </if>
      <if test="userIp != null">
        USER_IP,
      </if>
      <if test="userId != null">
        USER_ID,
      </if>
      <if test="lastTime != null">
        LAST_TIME,
      </if>
      <if test="weightTime != null">
        WEIGHT_TIME,
      </if>
      <if test="baseSpotName != null">
        BASE_SPOT_NAME,
      </if>
      <if test="pointNo != null">
        POINT_NO,
      </if>
      <if test="validFlag != null">
        VALID_FLAG,
      </if>
      <if test="weightDiff != null">
        WEIGHT_DIFF,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides=",">
      <if test="baseSpotNo != null">
        #{baseSpotNo,jdbcType=VARCHAR},
      </if>
      <if test="spotTypeNo != null">
        #{spotTypeNo,jdbcType=VARCHAR},
      </if>
      <if test="weightFlag != null">
        #{weightFlag,jdbcType=VARCHAR},
      </if>
      <if test="workFlag != null">
        #{workFlag,jdbcType=VARCHAR},
      </if>
      <if test="userIp != null">
        #{userIp,jdbcType=VARCHAR},
      </if>
      <if test="userId != null">
        #{userId,jdbcType=VARCHAR},
      </if>
      <if test="lastTime != null">
        #{lastTime,jdbcType=TIMESTAMP},
      </if>
      <if test="weightTime != null">
        #{weightTime,jdbcType=TIMESTAMP},
      </if>
      <if test="baseSpotName != null">
        #{baseSpotName,jdbcType=VARCHAR},
      </if>
      <if test="pointNo != null">
        #{pointNo,jdbcType=VARCHAR},
      </if>
      <if test="validFlag != null">
        #{validFlag,jdbcType=VARCHAR},
      </if>
      <if test="weightDiff != null">
        #{weightDiff,jdbcType=VARCHAR},
      </if>
    </trim>
  </insert>
  <update id="updateByPrimaryKey" parameterType="com.steerinfo.meterwork.meterworkstockonline.model.MeterWorkStockOnline">
    update METER_WORK_STOCK_ONLINE
    set SPOT_TYPE_NO = #{spotTypeNo,jdbcType=VARCHAR},
      WEIGHT_FLAG = #{weightFlag,jdbcType=VARCHAR},
      WORK_FLAG = #{workFlag,jdbcType=VARCHAR},
      USER_IP = #{userIp,jdbcType=VARCHAR},
      USER_ID = #{userId,jdbcType=VARCHAR},
      LAST_TIME = #{lastTime,jdbcType=TIMESTAMP},
      WEIGHT_TIME = #{weightTime,jdbcType=TIMESTAMP},
      BASE_SPOT_NAME = #{baseSpotName,jdbcType=VARCHAR},
      POINT_NO = #{pointNo,jdbcType=VARCHAR},
      VALID_FLAG = #{validFlag,jdbcType=VARCHAR},
      WEIGHT_DIFF = #{weightDiff,jdbcType=VARCHAR}
    where BASE_SPOT_NO = #{baseSpotNo,jdbcType=VARCHAR}
  </update>
  <update id="updateByPrimaryKeySelective" parameterType="com.steerinfo.meterwork.meterworkstockonline.model.MeterWorkStockOnline">
    update METER_WORK_STOCK_ONLINE
    <set>
      <if test="spotTypeNo != null">
        SPOT_TYPE_NO = #{spotTypeNo,jdbcType=VARCHAR},
      </if>
      <if test="weightFlag != null">
        WEIGHT_FLAG = #{weightFlag,jdbcType=VARCHAR},
      </if>
      <if test="workFlag != null">
        WORK_FLAG = #{workFlag,jdbcType=VARCHAR},
      </if>
      <if test="userIp != null">
        USER_IP = #{userIp,jdbcType=VARCHAR},
      </if>
      <if test="userId != null">
        USER_ID = #{userId,jdbcType=VARCHAR},
      </if>
      <if test="lastTime != null">
        LAST_TIME = #{lastTime,jdbcType=TIMESTAMP},
      </if>
      <if test="weightTime != null">
        WEIGHT_TIME = #{weightTime,jdbcType=TIMESTAMP},
      </if>
      <if test="baseSpotName != null">
        BASE_SPOT_NAME = #{baseSpotName,jdbcType=VARCHAR},
      </if>
      <if test="pointNo != null">
        POINT_NO = #{pointNo,jdbcType=VARCHAR},
      </if>
      <if test="validFlag != null">
        VALID_FLAG = #{validFlag,jdbcType=VARCHAR},
      </if>
      <if test="weightDiff != null">
        WEIGHT_DIFF = #{weightDiff,jdbcType=VARCHAR},
      </if>
    </set>
    where BASE_SPOT_NO = #{baseSpotNo,jdbcType=VARCHAR}
  </update>
  <select id="selectByPrimaryKey" parameterType="java.lang.String" resultMap="BaseResultMap">
    <include refid="select"/>
    where BASE_SPOT_NO = #{baseSpotNo,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_STOCK_ONLINE
    (BASE_SPOT_NO,
    SPOT_TYPE_NO, WEIGHT_FLAG, WORK_FLAG,
    USER_IP, USER_ID, LAST_TIME,
    WEIGHT_TIME, BASE_SPOT_NAME, POINT_NO,
    VALID_FLAG, WEIGHT_DIFF)
    ( <foreach collection="list" item="item" separator="union all">
    select
    #{item.baseSpotNo,jdbcType=VARCHAR},
    #{item.spotTypeNo,jdbcType=VARCHAR}, #{item.weightFlag,jdbcType=VARCHAR}, #{item.workFlag,jdbcType=VARCHAR},
    #{item.userIp,jdbcType=VARCHAR}, #{item.userId,jdbcType=VARCHAR}, #{item.lastTime,jdbcType=TIMESTAMP},
    #{item.weightTime,jdbcType=TIMESTAMP}, #{item.baseSpotName,jdbcType=VARCHAR}, #{item.pointNo,jdbcType=VARCHAR},
    #{item.validFlag,jdbcType=VARCHAR}, #{item.weightDiff,jdbcType=VARCHAR} from dual
  </foreach> )
  </insert>
  <update id="batchUpdate" parameterType="java.util.List">
    update METER_WORK_STOCK_ONLINE
    set
    BASE_SPOT_NO=
    <foreach collection="list" item="item" index="index" separator=" " open="case BASE_SPOT_NO" close="end">
      when #{item.baseSpotNo,jdbcType=VARCHAR} then #{item.baseSpotNo,jdbcType=VARCHAR}
    </foreach>
    ,SPOT_TYPE_NO=
    <foreach collection="list" item="item" index="index" separator=" " open="case BASE_SPOT_NO" close="end">
      when #{item.baseSpotNo,jdbcType=VARCHAR} then #{item.spotTypeNo,jdbcType=VARCHAR}
    </foreach>
    ,WEIGHT_FLAG=
    <foreach collection="list" item="item" index="index" separator=" " open="case BASE_SPOT_NO" close="end">
      when #{item.baseSpotNo,jdbcType=VARCHAR} then #{item.weightFlag,jdbcType=VARCHAR}
    </foreach>
    ,WORK_FLAG=
    <foreach collection="list" item="item" index="index" separator=" " open="case BASE_SPOT_NO" close="end">
      when #{item.baseSpotNo,jdbcType=VARCHAR} then #{item.workFlag,jdbcType=VARCHAR}
    </foreach>
    ,USER_IP=
    <foreach collection="list" item="item" index="index" separator=" " open="case BASE_SPOT_NO" close="end">
      when #{item.baseSpotNo,jdbcType=VARCHAR} then #{item.userIp,jdbcType=VARCHAR}
    </foreach>
    ,USER_ID=
    <foreach collection="list" item="item" index="index" separator=" " open="case BASE_SPOT_NO" close="end">
      when #{item.baseSpotNo,jdbcType=VARCHAR} then #{item.userId,jdbcType=VARCHAR}
    </foreach>
    ,LAST_TIME=
    <foreach collection="list" item="item" index="index" separator=" " open="case BASE_SPOT_NO" close="end">
      when #{item.baseSpotNo,jdbcType=VARCHAR} then #{item.lastTime,jdbcType=TIMESTAMP}
    </foreach>
    ,WEIGHT_TIME=
    <foreach collection="list" item="item" index="index" separator=" " open="case BASE_SPOT_NO" close="end">
      when #{item.baseSpotNo,jdbcType=VARCHAR} then #{item.weightTime,jdbcType=TIMESTAMP}
    </foreach>
    ,BASE_SPOT_NAME=
    <foreach collection="list" item="item" index="index" separator=" " open="case BASE_SPOT_NO" close="end">
      when #{item.baseSpotNo,jdbcType=VARCHAR} then #{item.baseSpotName,jdbcType=VARCHAR}
    </foreach>
    ,POINT_NO=
    <foreach collection="list" item="item" index="index" separator=" " open="case BASE_SPOT_NO" close="end">
      when #{item.baseSpotNo,jdbcType=VARCHAR} then #{item.pointNo,jdbcType=VARCHAR}
    </foreach>
    ,VALID_FLAG=
    <foreach collection="list" item="item" index="index" separator=" " open="case BASE_SPOT_NO" close="end">
      when #{item.baseSpotNo,jdbcType=VARCHAR} then #{item.validFlag,jdbcType=VARCHAR}
    </foreach>
    ,WEIGHT_DIFF=
    <foreach collection="list" item="item" index="index" separator=" " open="case BASE_SPOT_NO" close="end">
      when #{item.baseSpotNo,jdbcType=VARCHAR} then #{item.weightDiff,jdbcType=VARCHAR}
    </foreach>
    where BASE_SPOT_NO in
    <foreach collection="list" index="index" item="item" separator="," open="(" close=")">
      #{item.baseSpotNo,jdbcType=VARCHAR}
    </foreach>
  </update>
  <delete id="batchDelete" parameterType="java.util.List">
    delete from METER_WORK_STOCK_ONLINE
    where BASE_SPOT_NO in
    <foreach collection="list" item="id" open="(" close=")" separator=",">
      #{id}
    </foreach>
  </delete>
  <!-- 友情提示！！！-->
  <!-- 请将自己写的代码放在此标签之下，方便以后粘贴复制。-->
  <update id="updateByPrimaryKeySelectiveNotWeightTime" parameterType="com.steerinfo.meterwork.meterworkstockonline.model.MeterWorkStockOnline">
    update METER_WORK_STOCK_ONLINE
    <set>
      WEIGHT_TIME = #{weightTime,jdbcType=TIMESTAMP},
      <if test="spotTypeNo != null">
        SPOT_TYPE_NO = #{spotTypeNo,jdbcType=VARCHAR},
      </if>
      <if test="weightFlag != null">
        WEIGHT_FLAG = #{weightFlag,jdbcType=VARCHAR},
      </if>
      <if test="workFlag != null">
        WORK_FLAG = #{workFlag,jdbcType=VARCHAR},
      </if>
      <if test="userIp != null">
        USER_IP = #{userIp,jdbcType=VARCHAR},
      </if>
      <if test="userId != null">
        USER_ID = #{userId,jdbcType=VARCHAR},
      </if>
      <if test="lastTime != null">
        LAST_TIME = #{lastTime,jdbcType=TIMESTAMP},
      </if>
      <if test="baseSpotName != null">
        BASE_SPOT_NAME = #{baseSpotName,jdbcType=VARCHAR},
      </if>
    </set>
    where BASE_SPOT_NO = #{baseSpotNo,jdbcType=VARCHAR}
  </update>
  <select id="AutomaticUnlock" parameterType="java.util.HashMap" resultMap="BaseResultMap">
    SELECT <include refid="columns_alias"/> FROM METER_WORK_STOCK_ONLINE t
    where t.Work_Flag = '1' and
    CEIL((sysdate- t.last_time)  * 24*60*60  ) >= 60
  </select>

  <delete id="batchSelect" parameterType="java.util.List">
    delete from METER_WORK_STOCK_ONLINE
    where
    WORK_FLAG = '0' and  BASE_SPOT_NO in
    <foreach collection="list" item="id" open="(" close=")" separator=",">
      #{id}
    </foreach>
  </delete>

  <update id="batchUpdateSelective" parameterType="java.util.List">
    update METER_WORK_STOCK_ONLINE
    set
    <trim prefix="BASE_SPOT_NO = case BASE_SPOT_NO" suffix="end">
      <foreach collection="list" item="item" index="index" separator=" ">
        when #{item.baseSpotNo,jdbcType=VARCHAR} then #{item.baseSpotNo,jdbcType=VARCHAR}
      </foreach>
    </trim>
    <trim prefix=",USER_ID = case BASE_SPOT_NO" suffix="end">
      <foreach collection="list" item="item" index="index" separator=" ">
        <if test="item.userId != null and item.userId != ''">
          when #{item.baseSpotNo,jdbcType=VARCHAR} then #{item.userId,jdbcType=VARCHAR}
        </if>
      </foreach>
    </trim>
    <trim prefix=",WORK_FLAG = case BASE_SPOT_NO" suffix="end">
      <foreach collection="list" item="item" index="index" separator=" ">
          when #{item.baseSpotNo,jdbcType=VARCHAR} then '1'
      </foreach>
    </trim>
    where BASE_SPOT_NO in
    <foreach collection="list" index="index" item="item" separator="," open="(" close=")">
      #{item.baseSpotNo,jdbcType=VARCHAR}
    </foreach>
  </update>

  <update id="updateByPrimaryKeyForNull" parameterType="com.steerinfo.meterwork.meterworkstockonline.model.MeterWorkStockOnline">
    update METER_WORK_STOCK_ONLINE
    set
      USER_IP = #{userIp,jdbcType=VARCHAR},
      USER_ID = #{userId,jdbcType=VARCHAR},
    where BASE_SPOT_NO = #{baseSpotNo,jdbcType=VARCHAR}
  </update>
</mapper>