<?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.metermonitor.metermonitorweight.mapper.MeterMonitorWeightMapper">
  <resultMap id="BaseResultMap" type="com.steerinfo.metermonitor.metermonitorweight.model.MeterMonitorWeight">
    <id column="WEIGHT_NO" jdbcType="VARCHAR" property="weightNo" />
    <result column="SCALE_POINT_NO" jdbcType="VARCHAR" property="scalePointNo" />
    <result column="SCALE_POINT_NAME" jdbcType="VARCHAR" property="scalePointName" />
    <result column="BASE_SPOT_NO" jdbcType="VARCHAR" property="baseSpotNo" />
    <result column="BASE_SPOT_NAME" jdbcType="VARCHAR" property="baseSpotName" />
    <result column="COLLECT_WEIGHT" jdbcType="VARCHAR" property="collectWeight" />
    <result column="COLLECT_START_TIME" jdbcType="TIMESTAMP" property="collectStartTime" />
    <result column="COLLECT_END_TIME" jdbcType="TIMESTAMP" property="collectEndTime" />
    <result column="COLLECT_TIME" jdbcType="DECIMAL" property="collectTime" />
    <result column="SPOT_TYPE_NO" jdbcType="VARCHAR" property="spotTypeNo" />
    <result column="SPOT_TYPE_NAME" jdbcType="VARCHAR" property="spotTypeName" />
    <result column="ACTUAL_FIRST_NO" jdbcType="VARCHAR" property="actualFirstNo" />
  </resultMap>
  <sql id="columns">
    WEIGHT_NO, SCALE_POINT_NO, SCALE_POINT_NAME, BASE_SPOT_NO, BASE_SPOT_NAME, COLLECT_WEIGHT,
    COLLECT_START_TIME, COLLECT_END_TIME, COLLECT_TIME, SPOT_TYPE_NO, SPOT_TYPE_NAME,
    ACTUAL_FIRST_NO
  </sql>
  <sql id="columns_alias">
    t.WEIGHT_NO, t.SCALE_POINT_NO, t.SCALE_POINT_NAME, t.BASE_SPOT_NO, t.BASE_SPOT_NAME,
    t.COLLECT_WEIGHT, t.COLLECT_START_TIME, t.COLLECT_END_TIME, t.COLLECT_TIME, t.SPOT_TYPE_NO,
    t.SPOT_TYPE_NAME, t.ACTUAL_FIRST_NO
  </sql>
  <sql id="select">
    SELECT <include refid="columns"/> FROM METER_MONITOR_WEIGHT
  </sql>
  <sql id="select_alias">
    SELECT <include refid="columns_alias"/> FROM METER_MONITOR_WEIGHT t
  </sql>
  <sql id="where">
    <where>
      <if test="scalePointNo != null and scalePointNo != ''">
        and SCALE_POINT_NO = #{scalePointNo}
      </if>
      <if test="scalePointName != null and scalePointName != ''">
        and SCALE_POINT_NAME = #{scalePointName}
      </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="collectWeight != null and collectWeight != ''">
        and COLLECT_WEIGHT = #{collectWeight}
      </if>
      <if test="collectStartTime != null">
        and TO_CHAR(COLLECT_START_TIME,'yyyy-MM-dd') = #{collectStartTime}
      </if>
      <if test="collectEndTime != null">
        and TO_CHAR(COLLECT_END_TIME,'yyyy-MM-dd') = #{collectEndTime}
      </if>
      <if test="collectTime != null">
        and COLLECT_TIME = #{collectTime}
      </if>
      <if test="spotTypeNo != null and spotTypeNo != ''">
        and SPOT_TYPE_NO = #{spotTypeNo}
      </if>
      <if test="spotTypeName != null and spotTypeName != ''">
        and SPOT_TYPE_NAME = #{spotTypeName}
      </if>
      <if test="actualFirstNo != null and actualFirstNo != ''">
        and ACTUAL_FIRST_NO = #{actualFirstNo}
      </if>
    </where>
  </sql>
  <sql id="whereLike">
    <where>
      <if test="scalePointNo != null and scalePointNo != ''">
        and SCALE_POINT_NO LIKE '%${scalePointNo}%'
      </if>
      <if test="scalePointName != null and scalePointName != ''">
        and SCALE_POINT_NAME LIKE '%${scalePointName}%'
      </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="collectWeight != null and collectWeight != ''">
        and COLLECT_WEIGHT LIKE '%${collectWeight}%'
      </if>
      <if test="collectStartTime != null">
        and TO_CHAR(COLLECT_START_TIME,'yyyy-MM-dd') = #{collectStartTime}
      </if>
      <if test="collectEndTime != null">
        and TO_CHAR(COLLECT_END_TIME,'yyyy-MM-dd') = #{collectEndTime}
      </if>
      <if test="collectTime != null">
        and COLLECT_TIME = #{collectTime}
      </if>
      <if test="spotTypeNo != null and spotTypeNo != ''">
        and SPOT_TYPE_NO LIKE '%${spotTypeNo}%'
      </if>
      <if test="spotTypeName != null and spotTypeName != ''">
        and SPOT_TYPE_NAME LIKE '%${spotTypeName}%'
      </if>
      <if test="actualFirstNo != null and actualFirstNo != ''">
        and ACTUAL_FIRST_NO LIKE '%${actualFirstNo}%'
      </if>
    </where>
  </sql>
  <delete id="deleteByPrimaryKey" parameterType="java.lang.String">
    delete from METER_MONITOR_WEIGHT
    where WEIGHT_NO = #{weightNo,jdbcType=VARCHAR}
  </delete>
  <delete id="deleteBySelectiveElement" parameterType="java.util.HashMap">
    delete from METER_MONITOR_WEIGHT
    where 1!=1
    <if test="scalePointNo != null and scalePointNo != ''">
      or SCALE_POINT_NO = #{scalePointNo}
    </if>
    <if test="scalePointName != null and scalePointName != ''">
      or SCALE_POINT_NAME = #{scalePointName}
    </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="collectWeight != null and collectWeight != ''">
      or COLLECT_WEIGHT = #{collectWeight}
    </if>
    <if test="collectStartTime != null">
      or TO_CHAR(COLLECT_START_TIME,'yyyy-MM-dd') = '#{collectStartTime}'
    </if>
    <if test="collectEndTime != null">
      or TO_CHAR(COLLECT_END_TIME,'yyyy-MM-dd') = '#{collectEndTime}'
    </if>
    <if test="collectTime != null">
      or COLLECT_TIME = #{collectTime}
    </if>
    <if test="spotTypeNo != null and spotTypeNo != ''">
      or SPOT_TYPE_NO = #{spotTypeNo}
    </if>
    <if test="spotTypeName != null and spotTypeName != ''">
      or SPOT_TYPE_NAME = #{spotTypeName}
    </if>
    <if test="actualFirstNo != null and actualFirstNo != ''">
      or ACTUAL_FIRST_NO = #{actualFirstNo}
    </if>
  </delete>
  <insert id="insert" parameterType="com.steerinfo.metermonitor.metermonitorweight.model.MeterMonitorWeight">
    insert into METER_MONITOR_WEIGHT (WEIGHT_NO, SCALE_POINT_NO, SCALE_POINT_NAME,
      BASE_SPOT_NO, BASE_SPOT_NAME, COLLECT_WEIGHT,
      COLLECT_START_TIME, COLLECT_END_TIME, COLLECT_TIME,
      SPOT_TYPE_NO, SPOT_TYPE_NAME, ACTUAL_FIRST_NO
      )
    values (#{weightNo,jdbcType=VARCHAR}, #{scalePointNo,jdbcType=VARCHAR}, #{scalePointName,jdbcType=VARCHAR},
      #{baseSpotNo,jdbcType=VARCHAR}, #{baseSpotName,jdbcType=VARCHAR}, #{collectWeight,jdbcType=VARCHAR},
      #{collectStartTime,jdbcType=TIMESTAMP}, #{collectEndTime,jdbcType=TIMESTAMP}, #{collectTime,jdbcType=DECIMAL},
      #{spotTypeNo,jdbcType=VARCHAR}, #{spotTypeName,jdbcType=VARCHAR}, #{actualFirstNo,jdbcType=VARCHAR}
      )
  </insert>
  <insert id="insertSelective" parameterType="com.steerinfo.metermonitor.metermonitorweight.model.MeterMonitorWeight">
    insert into METER_MONITOR_WEIGHT
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="weightNo != null">
        WEIGHT_NO,
      </if>
      <if test="scalePointNo != null">
        SCALE_POINT_NO,
      </if>
      <if test="scalePointName != null">
        SCALE_POINT_NAME,
      </if>
      <if test="baseSpotNo != null">
        BASE_SPOT_NO,
      </if>
      <if test="baseSpotName != null">
        BASE_SPOT_NAME,
      </if>
      <if test="collectWeight != null">
        COLLECT_WEIGHT,
      </if>
      <if test="collectStartTime != null">
        COLLECT_START_TIME,
      </if>
      <if test="collectEndTime != null">
        COLLECT_END_TIME,
      </if>
      <if test="collectTime != null">
        COLLECT_TIME,
      </if>
      <if test="spotTypeNo != null">
        SPOT_TYPE_NO,
      </if>
      <if test="spotTypeName != null">
        SPOT_TYPE_NAME,
      </if>
      <if test="actualFirstNo != null">
        ACTUAL_FIRST_NO,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides=",">
      <if test="weightNo != null">
        #{weightNo,jdbcType=VARCHAR},
      </if>
      <if test="scalePointNo != null">
        #{scalePointNo,jdbcType=VARCHAR},
      </if>
      <if test="scalePointName != null">
        #{scalePointName,jdbcType=VARCHAR},
      </if>
      <if test="baseSpotNo != null">
        #{baseSpotNo,jdbcType=VARCHAR},
      </if>
      <if test="baseSpotName != null">
        #{baseSpotName,jdbcType=VARCHAR},
      </if>
      <if test="collectWeight != null">
        #{collectWeight,jdbcType=VARCHAR},
      </if>
      <if test="collectStartTime != null">
        #{collectStartTime,jdbcType=TIMESTAMP},
      </if>
      <if test="collectEndTime != null">
        #{collectEndTime,jdbcType=TIMESTAMP},
      </if>
      <if test="collectTime != null">
        #{collectTime,jdbcType=DECIMAL},
      </if>
      <if test="spotTypeNo != null">
        #{spotTypeNo,jdbcType=VARCHAR},
      </if>
      <if test="spotTypeName != null">
        #{spotTypeName,jdbcType=VARCHAR},
      </if>
      <if test="actualFirstNo != null">
        #{actualFirstNo,jdbcType=VARCHAR},
      </if>
    </trim>
  </insert>
  <update id="updateByPrimaryKey" parameterType="com.steerinfo.metermonitor.metermonitorweight.model.MeterMonitorWeight">
    update METER_MONITOR_WEIGHT
    set SCALE_POINT_NO = #{scalePointNo,jdbcType=VARCHAR},
      SCALE_POINT_NAME = #{scalePointName,jdbcType=VARCHAR},
      BASE_SPOT_NO = #{baseSpotNo,jdbcType=VARCHAR},
      BASE_SPOT_NAME = #{baseSpotName,jdbcType=VARCHAR},
      COLLECT_WEIGHT = #{collectWeight,jdbcType=VARCHAR},
      COLLECT_START_TIME = #{collectStartTime,jdbcType=TIMESTAMP},
      COLLECT_END_TIME = #{collectEndTime,jdbcType=TIMESTAMP},
      COLLECT_TIME = #{collectTime,jdbcType=DECIMAL},
      SPOT_TYPE_NO = #{spotTypeNo,jdbcType=VARCHAR},
      SPOT_TYPE_NAME = #{spotTypeName,jdbcType=VARCHAR},
      ACTUAL_FIRST_NO = #{actualFirstNo,jdbcType=VARCHAR}
    where WEIGHT_NO = #{weightNo,jdbcType=VARCHAR}
  </update>
  <update id="updateByPrimaryKeySelective" parameterType="com.steerinfo.metermonitor.metermonitorweight.model.MeterMonitorWeight">
    update METER_MONITOR_WEIGHT
    <set>
      <if test="scalePointNo != null">
        SCALE_POINT_NO = #{scalePointNo,jdbcType=VARCHAR},
      </if>
      <if test="scalePointName != null">
        SCALE_POINT_NAME = #{scalePointName,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="collectWeight != null">
        COLLECT_WEIGHT = #{collectWeight,jdbcType=VARCHAR},
      </if>
      <if test="collectStartTime != null">
        COLLECT_START_TIME = #{collectStartTime,jdbcType=TIMESTAMP},
      </if>
      <if test="collectEndTime != null">
        COLLECT_END_TIME = #{collectEndTime,jdbcType=TIMESTAMP},
      </if>
      <if test="collectTime != null">
        COLLECT_TIME = #{collectTime,jdbcType=DECIMAL},
      </if>
      <if test="spotTypeNo != null">
        SPOT_TYPE_NO = #{spotTypeNo,jdbcType=VARCHAR},
      </if>
      <if test="spotTypeName != null">
        SPOT_TYPE_NAME = #{spotTypeName,jdbcType=VARCHAR},
      </if>
      <if test="actualFirstNo != null">
        ACTUAL_FIRST_NO = #{actualFirstNo,jdbcType=VARCHAR},
      </if>
    </set>
    where WEIGHT_NO = #{weightNo,jdbcType=VARCHAR}
  </update>
  <select id="selectByPrimaryKey" parameterType="java.lang.String" resultMap="BaseResultMap">
    <include refid="select"/>
    where WEIGHT_NO = #{weightNo,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_MONITOR_WEIGHT
    (WEIGHT_NO,
    SCALE_POINT_NO, SCALE_POINT_NAME,
    BASE_SPOT_NO, BASE_SPOT_NAME, COLLECT_WEIGHT,
    COLLECT_START_TIME, COLLECT_END_TIME,
    COLLECT_TIME, SPOT_TYPE_NO, SPOT_TYPE_NAME,
    ACTUAL_FIRST_NO)
    ( <foreach collection="list" item="item" separator="union all">
    select
    #{item.weightNo,jdbcType=VARCHAR},
    #{item.scalePointNo,jdbcType=VARCHAR}, #{item.scalePointName,jdbcType=VARCHAR},
    #{item.baseSpotNo,jdbcType=VARCHAR}, #{item.baseSpotName,jdbcType=VARCHAR}, #{item.collectWeight,jdbcType=VARCHAR},
    #{item.collectStartTime,jdbcType=TIMESTAMP}, #{item.collectEndTime,jdbcType=TIMESTAMP},
    #{item.collectTime,jdbcType=DECIMAL}, #{item.spotTypeNo,jdbcType=VARCHAR}, #{item.spotTypeName,jdbcType=VARCHAR},
    #{item.actualFirstNo,jdbcType=VARCHAR} from dual
  </foreach> )
  </insert>
  <update id="batchUpdate" parameterType="java.util.List">
    update METER_MONITOR_WEIGHT
    set
    WEIGHT_NO=
    <foreach collection="list" item="item" index="index" separator=" " open="case WEIGHT_NO" close="end">
      when #{item.weightNo,jdbcType=VARCHAR} then #{item.weightNo,jdbcType=VARCHAR}
    </foreach>
    ,SCALE_POINT_NO=
    <foreach collection="list" item="item" index="index" separator=" " open="case WEIGHT_NO" close="end">
      when #{item.weightNo,jdbcType=VARCHAR} then #{item.scalePointNo,jdbcType=VARCHAR}
    </foreach>
    ,SCALE_POINT_NAME=
    <foreach collection="list" item="item" index="index" separator=" " open="case WEIGHT_NO" close="end">
      when #{item.weightNo,jdbcType=VARCHAR} then #{item.scalePointName,jdbcType=VARCHAR}
    </foreach>
    ,BASE_SPOT_NO=
    <foreach collection="list" item="item" index="index" separator=" " open="case WEIGHT_NO" close="end">
      when #{item.weightNo,jdbcType=VARCHAR} then #{item.baseSpotNo,jdbcType=VARCHAR}
    </foreach>
    ,BASE_SPOT_NAME=
    <foreach collection="list" item="item" index="index" separator=" " open="case WEIGHT_NO" close="end">
      when #{item.weightNo,jdbcType=VARCHAR} then #{item.baseSpotName,jdbcType=VARCHAR}
    </foreach>
    ,COLLECT_WEIGHT=
    <foreach collection="list" item="item" index="index" separator=" " open="case WEIGHT_NO" close="end">
      when #{item.weightNo,jdbcType=VARCHAR} then #{item.collectWeight,jdbcType=VARCHAR}
    </foreach>
    ,COLLECT_START_TIME=
    <foreach collection="list" item="item" index="index" separator=" " open="case WEIGHT_NO" close="end">
      when #{item.weightNo,jdbcType=VARCHAR} then #{item.collectStartTime,jdbcType=TIMESTAMP}
    </foreach>
    ,COLLECT_END_TIME=
    <foreach collection="list" item="item" index="index" separator=" " open="case WEIGHT_NO" close="end">
      when #{item.weightNo,jdbcType=VARCHAR} then #{item.collectEndTime,jdbcType=TIMESTAMP}
    </foreach>
    ,COLLECT_TIME=
    <foreach collection="list" item="item" index="index" separator=" " open="case WEIGHT_NO" close="end">
      when #{item.weightNo,jdbcType=VARCHAR} then #{item.collectTime,jdbcType=DECIMAL}
    </foreach>
    ,SPOT_TYPE_NO=
    <foreach collection="list" item="item" index="index" separator=" " open="case WEIGHT_NO" close="end">
      when #{item.weightNo,jdbcType=VARCHAR} then #{item.spotTypeNo,jdbcType=VARCHAR}
    </foreach>
    ,SPOT_TYPE_NAME=
    <foreach collection="list" item="item" index="index" separator=" " open="case WEIGHT_NO" close="end">
      when #{item.weightNo,jdbcType=VARCHAR} then #{item.spotTypeName,jdbcType=VARCHAR}
    </foreach>
    ,ACTUAL_FIRST_NO=
    <foreach collection="list" item="item" index="index" separator=" " open="case WEIGHT_NO" close="end">
      when #{item.weightNo,jdbcType=VARCHAR} then #{item.actualFirstNo,jdbcType=VARCHAR}
    </foreach>
    where WEIGHT_NO in
    <foreach collection="list" index="index" item="item" separator="," open="(" close=")">
      #{item.weightNo,jdbcType=VARCHAR}
    </foreach>
  </update>
  <delete id="batchDelete" parameterType="java.util.List">
    delete from METER_MONITOR_WEIGHT
    where WEIGHT_NO in
    <foreach collection="list" item="id" open="(" close=")" separator=",">
      #{id}
    </foreach>
  </delete>
  <!-- 友情提示！！！-->
  <!-- 请将自己写的代码放在此标签之下，方便以后粘贴复制。-->
  <select id="selectTime" parameterType="java.util.HashMap" resultMap="BaseResultMap">
   select t.collect_start_time, t.collect_end_time
     from METER_MONITOR_WEIGHT t
    where t.collect_start_time =
        (select distinct (t.collect_start_time)
           from METER_MONITOR_WEIGHT t
          where t.actual_first_no = #{actualFirstNo}
            and t.base_spot_no = #{baseSpotNo})
  order by t.collect_end_time desc
  </select>

  <resultMap id="MeterMonitorWeightDto" type="com.steerinfo.metermonitor.dto.MeterMonitorWeightDto" extends="BaseResultMap">
    <result column="TIME_SPOT" jdbcType="VARCHAR" property="timeSpot" />
    <result column="WEIGHT" jdbcType="VARCHAR" property="weight" />
  </resultMap>
  <select id="selectByTime" parameterType="java.util.HashMap" resultMap="MeterMonitorWeightDto">
    select to_char(t1.times,'HH24:mi:ss') TIME_SPOT, t2.COLLECT_WEIGHT WEIGHT
      from (select (to_date(#{collectStartTime},'yyyy-mm-dd HH24:mi:ss')- 1/(24*60*60)) + 1 * rownum / 24 / 60 / 60  times
            from dual
          CONNECT BY rownum &lt;=
          (to_date(#{collectEndTime},'yyyy-mm-dd HH24:mi:ss') -(to_date(#{collectStartTime},'yyyy-mm-dd HH24:mi:ss') - 1/ (24*60*60) )) * 24 * 60 * 60 / 1)  t1,
        (select *
           from METER_MONITOR_WEIGHT
          where Collect_End_Time between to_date(#{collectStartTime},'yyyy-mm-dd HH24:mi:ss') and to_date(#{collectEndTime},'yyyy-mm-dd HH24:mi:ss')
            and BASE_SPOT_NO = #{baseSpotNo}) t2
    where t1.times = t2.Collect_End_Time(+)
    order by t1.times desc
  </select>

  <resultMap id="TimesDto" type="com.steerinfo.meterwork.dto.TimesDto" extends="BaseResultMap">
    <result column="TIMES" jdbcType="VARCHAR" property="times" />
    <result column="NUM" jdbcType="DECIMAL" property="num" />
  </resultMap>

  <select id="listFast" parameterType="java.util.HashMap" resultMap="TimesDto">
  select t2.month TIMES,nvl(t1.num,0) NUM
  from
  (select to_char(t2.collect_start_time, 'yyyy-MM') as month,
               min (t2.collect_time) num
          from (select max(t.collect_time) collect_time,
                       t.collect_start_time collect_start_time
                  from METER_MONITOR_WEIGHT t
                  <where>
                   t.collect_start_time in (select distinct (t.collect_start_time)
                    from METER_MONITOR_WEIGHT t
                    where t.actual_first_no is not null)
                    <if test="spotTypeNo != null and spotTypeNo != ''">
                      and t.SPOT_TYPE_NO = #{spotTypeNo}
                    </if>
                  </where>
                 group by t.collect_start_time
                 order by t.collect_start_time desc) t2
         group by to_char(t2.collect_start_time, 'yyyy-MM')
  )t1,
  (SELECT TO_CHAR(ADD_MONTHS(TO_DATE(substr(#{collectStartTime},1,7),'yyyy-MM'), ROWNUM - 1),'yyyy-MM') as month
  FROM DUAL
  CONNECT BY ROWNUM <![CDATA[ <= ]]>
  months_between(to_date(substr(#{collectEndTime},1,7),'yyyy-MM'),
  to_date(substr(#{collectStartTime},1,7),'yyyy-MM')) + 1
  )t2
  where t2.month = t1.month(+)
  order by t2.month asc
</select>


  <select id="listSlowly" parameterType="java.util.HashMap" resultMap="TimesDto">
    select t2.month TIMES,nvl(t1.num,0) NUM
    from
    (select to_char(t2.collect_start_time, 'yyyy-MM') as month,
    max(t2.collect_time) num
    from (select max(t.collect_time) collect_time,
    t.collect_start_time collect_start_time
    from METER_MONITOR_WEIGHT t
    <where>
       t.collect_start_time in (select distinct (t.collect_start_time)
      from METER_MONITOR_WEIGHT t
      where t.actual_first_no is not null)
      <if test="spotTypeNo != null and spotTypeNo != ''">
        and t.SPOT_TYPE_NO = #{spotTypeNo}
      </if>
    </where>
    group by t.collect_start_time
    order by t.collect_start_time desc) t2
    group by to_char(t2.collect_start_time, 'yyyy-MM')
    )t1,
    (
    SELECT TO_CHAR(ADD_MONTHS(TO_DATE(substr(#{collectStartTime},1,7),'yyyy-MM'), ROWNUM - 1),'yyyy-MM') as month
    FROM DUAL
    CONNECT BY ROWNUM <![CDATA[ <= ]]>
    months_between(to_date(substr(#{collectEndTime},1,7),'yyyy-MM'),
    to_date(substr(#{collectStartTime},1,7),'yyyy-MM')) + 1
    )t2
    where t2.month = t1.month(+)
    order by t2.month asc
  </select>

  <select id="listAvg" parameterType="java.util.HashMap" resultMap="TimesDto">
    select t2.month TIMES,nvl(t1.num,0) NUM
    from
    (select to_char(t2.collect_start_time, 'yyyy-MM') as month,
    trunc(avg(t2.collect_time),2) num
    from (select max(t.collect_time) collect_time,
    t.collect_start_time collect_start_time
    from METER_MONITOR_WEIGHT t
    <where>
      t.collect_start_time in (select distinct (t.collect_start_time)
      from METER_MONITOR_WEIGHT t
      where t.actual_first_no is not null)
      <if test="spotTypeNo != null and spotTypeNo != ''">
        and t.SPOT_TYPE_NO = #{spotTypeNo}
      </if>
    </where>
    group by t.collect_start_time
    order by t.collect_start_time desc) t2
    group by to_char(t2.collect_start_time, 'yyyy-MM')
    )t1,
    (
    SELECT TO_CHAR(ADD_MONTHS(TO_DATE(substr(#{collectStartTime},1,7),'yyyy-MM'), ROWNUM - 1),'yyyy-MM') as month
    FROM DUAL
    CONNECT BY ROWNUM <![CDATA[ <= ]]>
    months_between(to_date(substr(#{collectEndTime},1,7),'yyyy-MM'),
    to_date(substr(#{collectStartTime},1,7),'yyyy-MM')) + 1
    )t2
    where t2.month = t1.month(+)
    order by t2.month asc
  </select>
</mapper>