<?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.ConditionWellDao">
  <sql id="Base_Column_List">
    t.WELLNAME, RECORD_DATE, t.UNITCODE, LAYER, TRUNK_PRESSURE, OIL_PRESSURE, CASING_PRESSURE,
    PLAN_DAILY_WATER, DAILY_WATER, TYPE_ID, CREATED_ON, MODIFIED_ON,
    (select flag_name from sys_flag where category_code = 'CONDITION_TYPE' and flag_code = t.TYPE_ID) TYPE_NAME
  </sql>
  <select id="selectList" parameterType="ConditionWellParam" resultType="ConditionWell">
    select
    <include refid="Base_Column_List" />
    , su.unitname, su.fullname,
    (select blockname from sys_blockinfo where blockcode = wb.blockcode) blockname,
    (select unitname from sys_unitinfo where unitcode = su.p_unitcode) areaname
    from CON_CONDITION_WELL t, water_well_basic wb, sys_unitinfo su
    where t.wellname = wb.wellname
    and wb.unitcode = su.unitcode
    and RECORD_DATE = #{testdate}
    <if test="unitcode != null and unitcode != ''">
      and su.unitcode in (select unitcode from sys_unitinfo start with unitcode = #{unitcode} connect by prior unitcode = p_unitcode)
    </if>
    <if test="blockcode != null and blockcode != ''">
      and wb.blockcode = #{blockcode}
    </if>
    <if test="wellname != null and wellname != ''">
      and wb.wellname = #{wellname}
    </if>
    <if test="typeId != null and typeId != ''">
      and t.TYPE_ID = #{typeId}
    </if>
    order by t.wellname
  </select>
  <select id="selectByPrimaryKey" parameterType="ConditionWell" resultType="ConditionWell">
    select 
    <include refid="Base_Column_List" />
    from CON_CONDITION_WELL t
    where WELLNAME = #{wellname,jdbcType=VARCHAR}
      and RECORD_DATE = #{recordDate,jdbcType=TIMESTAMP}
  </select>
  <delete id="deleteByPrimaryKey" parameterType="ConditionWell">
    delete from CON_CONDITION_WELL
    where WELLNAME = #{wellname,jdbcType=VARCHAR}
      and RECORD_DATE = #{recordDate,jdbcType=TIMESTAMP}
  </delete>
  <insert id="insert" parameterType="ConditionWell">
    insert into CON_CONDITION_WELL (WELLNAME, RECORD_DATE, UNITCODE, 
      LAYER, TRUNK_PRESSURE, OIL_PRESSURE, 
      CASING_PRESSURE, PLAN_DAILY_WATER, DAILY_WATER, 
      TYPE_ID, CREATED_ON, MODIFIED_ON
      )
    values (#{wellname,jdbcType=VARCHAR}, #{recordDate,jdbcType=TIMESTAMP}, #{unitcode,jdbcType=VARCHAR}, 
      #{layer,jdbcType=VARCHAR}, #{trunkPressure,jdbcType=DECIMAL}, #{oilPressure,jdbcType=DECIMAL}, 
      #{casingPressure,jdbcType=DECIMAL}, #{planDailyWater,jdbcType=DECIMAL}, #{dailyWater,jdbcType=DECIMAL}, 
      #{typeId,jdbcType=VARCHAR}, #{createdOn,jdbcType=TIMESTAMP}, #{modifiedOn,jdbcType=TIMESTAMP}
      )
  </insert>
  <update id="updateByPrimaryKeySelective" parameterType="ConditionWell">
    update CON_CONDITION_WELL
    <set>
      <if test="unitcode != null">
        UNITCODE = #{unitcode,jdbcType=VARCHAR},
      </if>
      <if test="layer != null">
        LAYER = #{layer,jdbcType=VARCHAR},
      </if>
      <if test="trunkPressure != null">
        TRUNK_PRESSURE = #{trunkPressure,jdbcType=DECIMAL},
      </if>
      <if test="oilPressure != null">
        OIL_PRESSURE = #{oilPressure,jdbcType=DECIMAL},
      </if>
      <if test="casingPressure != null">
        CASING_PRESSURE = #{casingPressure,jdbcType=DECIMAL},
      </if>
      <if test="planDailyWater != null">
        PLAN_DAILY_WATER = #{planDailyWater,jdbcType=DECIMAL},
      </if>
      <if test="dailyWater != null">
        DAILY_WATER = #{dailyWater,jdbcType=DECIMAL},
      </if>
      <if test="typeId != null">
        TYPE_ID = #{typeId,jdbcType=VARCHAR},
      </if>
      <if test="createdOn != null">
        CREATED_ON = #{createdOn,jdbcType=TIMESTAMP},
      </if>
      <if test="modifiedOn != null">
        MODIFIED_ON = #{modifiedOn,jdbcType=TIMESTAMP},
      </if>
    </set>
    where WELLNAME = #{wellname,jdbcType=VARCHAR}
      and RECORD_DATE = #{recordDate,jdbcType=TIMESTAMP}
  </update>
  <update id="updateByPrimaryKey" parameterType="ConditionWell">
    update CON_CONDITION_WELL
    set UNITCODE = #{unitcode,jdbcType=VARCHAR},
      LAYER = #{layer,jdbcType=VARCHAR},
      TRUNK_PRESSURE = #{trunkPressure,jdbcType=DECIMAL},
      OIL_PRESSURE = #{oilPressure,jdbcType=DECIMAL},
      CASING_PRESSURE = #{casingPressure,jdbcType=DECIMAL},
      PLAN_DAILY_WATER = #{planDailyWater,jdbcType=DECIMAL},
      DAILY_WATER = #{dailyWater,jdbcType=DECIMAL},
      TYPE_ID = #{typeId,jdbcType=VARCHAR},
      CREATED_ON = #{createdOn,jdbcType=TIMESTAMP},
      MODIFIED_ON = #{modifiedOn,jdbcType=TIMESTAMP}
    where WELLNAME = #{wellname,jdbcType=VARCHAR}
      and RECORD_DATE = #{recordDate,jdbcType=TIMESTAMP}
  </update>
</mapper>