<?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="cn.com.victorysoft.business.AbnormalUnitDao">
  <sql id="Base_Column_List">
    t.UNITCODE, t.RECORD_DATE, TOTAL_WELL, OPEN_WELL, DAILY_WATER, WATER_ABNORMAL, PRESSURE_ABNORMAL,
    OPEN_WELL_DIFF, DAILY_WATER_DIFF, WATER_ABNORMAL_DIFF, PRESSURE_ABNORMAL_DIFF, SUMMARY_DATE, PRESSURE,
    su.unitname,
    WATER_ABNORMAL + PRESSURE_ABNORMAL ABNORMAL,
    WATER_ABNORMAL_DIFF + PRESSURE_ABNORMAL_DIFF ABNORMAL_DIFF
  </sql>

  <select id="selectUnit" parameterType="UnitDatePageParam" resultType="AbnormalUnit">
    select
    <include refid="Base_Column_List" />
    from CON_ABNORMAL_UNIT t, V_SYS_UNITINFO su
    where t.RECORD_DATE = #{testdate}
    and t.UNITCODE = su.UNITCODE
    and su.unitcode= #{unitcode,jdbcType=VARCHAR}
  </select>

  <select id="selectChildren" parameterType="UnitDatePageParam" resultType="AbnormalUnit">
    select
    <include refid="Base_Column_List" />
    from CON_ABNORMAL_UNIT t, V_SYS_UNITINFO su
    where t.RECORD_DATE = #{testdate}
    and t.UNITCODE = su.UNITCODE
    and su.p_unitcode= #{unitcode,jdbcType=VARCHAR}
    order by su.unitorder
  </select>

  <delete id="deleteByPrimaryKey" parameterType="AbnormalUnit">
    delete from CON_ABNORMAL_UNIT
    where UNITCODE = #{unitcode,jdbcType=VARCHAR}
      and RECORD_DATE = #{recordDate,jdbcType=TIMESTAMP}
  </delete>
  <delete id="deleteByDate" parameterType="Date">
    delete from CON_ABNORMAL_UNIT
    where RECORD_DATE = #{value,jdbcType=TIMESTAMP}
  </delete>
  <insert id="insert" parameterType="AbnormalUnit">
    insert into CON_ABNORMAL_UNIT (UNITCODE, RECORD_DATE, TOTAL_WELL, 
      OPEN_WELL, DAILY_WATER, WATER_ABNORMAL, 
      PRESSURE_ABNORMAL, OPEN_WELL_DIFF, DAILY_WATER_DIFF, 
      WATER_ABNORMAL_DIFF, PRESSURE_ABNORMAL_DIFF, 
      SUMMARY_DATE, PRESSURE)
    values (#{unitcode,jdbcType=VARCHAR}, #{recordDate,jdbcType=TIMESTAMP}, #{totalWell,jdbcType=DECIMAL}, 
      #{openWell,jdbcType=DECIMAL}, #{dailyWater,jdbcType=DECIMAL}, #{waterAbnormal,jdbcType=DECIMAL}, 
      #{pressureAbnormal,jdbcType=DECIMAL}, #{openWellDiff,jdbcType=DECIMAL}, #{dailyWaterDiff,jdbcType=DECIMAL}, 
      #{waterAbnormalDiff,jdbcType=DECIMAL}, #{pressureAbnormalDiff,jdbcType=DECIMAL}, 
      #{summaryDate,jdbcType=TIMESTAMP}, #{pressure,jdbcType=DECIMAL})
  </insert>
  <update id="updateByPrimaryKeySelective" parameterType="AbnormalUnit">
    update CON_ABNORMAL_UNIT
    <set>
      <if test="totalWell != null">
        TOTAL_WELL = #{totalWell,jdbcType=DECIMAL},
      </if>
      <if test="openWell != null">
        OPEN_WELL = #{openWell,jdbcType=DECIMAL},
      </if>
      <if test="dailyWater != null">
        DAILY_WATER = #{dailyWater,jdbcType=DECIMAL},
      </if>
      <if test="waterAbnormal != null">
        WATER_ABNORMAL = #{waterAbnormal,jdbcType=DECIMAL},
      </if>
      <if test="pressureAbnormal != null">
        PRESSURE_ABNORMAL = #{pressureAbnormal,jdbcType=DECIMAL},
      </if>
      <if test="openWellDiff != null">
        OPEN_WELL_DIFF = #{openWellDiff,jdbcType=DECIMAL},
      </if>
      <if test="dailyWaterDiff != null">
        DAILY_WATER_DIFF = #{dailyWaterDiff,jdbcType=DECIMAL},
      </if>
      <if test="waterAbnormalDiff != null">
        WATER_ABNORMAL_DIFF = #{waterAbnormalDiff,jdbcType=DECIMAL},
      </if>
      <if test="pressureAbnormalDiff != null">
        PRESSURE_ABNORMAL_DIFF = #{pressureAbnormalDiff,jdbcType=DECIMAL},
      </if>
      <if test="summaryDate != null">
        SUMMARY_DATE = #{summaryDate,jdbcType=TIMESTAMP},
      </if>
      <if test="pressure != null">
        PRESSURE = #{pressure,jdbcType=DECIMAL},
      </if>
    </set>
    where UNITCODE = #{unitcode,jdbcType=VARCHAR}
      and RECORD_DATE = #{recordDate,jdbcType=TIMESTAMP}
  </update>
  <update id="updateByPrimaryKey" parameterType="AbnormalUnit">
    update CON_ABNORMAL_UNIT
    set TOTAL_WELL = #{totalWell,jdbcType=DECIMAL},
      OPEN_WELL = #{openWell,jdbcType=DECIMAL},
      DAILY_WATER = #{dailyWater,jdbcType=DECIMAL},
      WATER_ABNORMAL = #{waterAbnormal,jdbcType=DECIMAL},
      PRESSURE_ABNORMAL = #{pressureAbnormal,jdbcType=DECIMAL},
      OPEN_WELL_DIFF = #{openWellDiff,jdbcType=DECIMAL},
      DAILY_WATER_DIFF = #{dailyWaterDiff,jdbcType=DECIMAL},
      WATER_ABNORMAL_DIFF = #{waterAbnormalDiff,jdbcType=DECIMAL},
      PRESSURE_ABNORMAL_DIFF = #{pressureAbnormalDiff,jdbcType=DECIMAL},
      PRESSURE = #{pressure,jdbcType=DECIMAL},
      SUMMARY_DATE = #{summaryDate,jdbcType=TIMESTAMP}
    where UNITCODE = #{unitcode,jdbcType=VARCHAR}
      and RECORD_DATE = #{recordDate,jdbcType=TIMESTAMP}
  </update>
</mapper>