<?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.FlushRecordDao">
  <sql id="Base_Column_List">
    cfr.WELLNAME, RECORD_DATE, cfr.UNITCODE, START_TIME, RANGE_TIME,
    START_TIME + to_char(RANGE_TIME, '99') / 24 + substr(trim(to_char(RANGE_TIME, '00.00')), 4) / 60 / 24 END_TIME,
    IN_WATER, OUT_WATER, REASON, DISPLACEMENT, TYPE_ID,
    EFFECTIVE, decode(EFFECTIVE, '1', '是', '0', '否', '') EFFECTIVE_NAME,
    CREATED_ON, MODIFIED_ON,
    (select flag_name from sys_flag where category_code = 'FLUSH_TYPE' and flag_code = cfr.TYPE_ID) TYPE_NAME
  </sql>
  <select id="selectList" parameterType="UnitDatePageParam" resultType="FlushRecord">
    select
    <include refid="Base_Column_List" />
    , su.unitname
    from CON_FLUSH_RECORD cfr, sys_unitinfo su
    where cfr.unitcode = su.unitcode
    and RECORD_DATE = #{testdate}
    <if test="unitcode != null and unitcode != ''">
      and cfr.unitcode in (select unitcode from sys_unitinfo start with unitcode = #{unitcode} connect by prior unitcode = p_unitcode)
    </if>
  </select>
  <select id="selectByPrimaryKey" parameterType="FlushRecord" resultType="FlushRecord">
    select 
    <include refid="Base_Column_List" />
    from CON_FLUSH_RECORD cfr
    where WELLNAME = #{wellname,jdbcType=VARCHAR}
      and RECORD_DATE = #{recordDate,jdbcType=TIMESTAMP}
  </select>
  <delete id="deleteByPrimaryKey" parameterType="FlushRecord">
    delete from CON_FLUSH_RECORD
    where WELLNAME = #{wellname,jdbcType=VARCHAR}
      and RECORD_DATE = #{recordDate,jdbcType=TIMESTAMP}
  </delete>
  <insert id="insert" parameterType="FlushRecord">
    insert into CON_FLUSH_RECORD (WELLNAME, RECORD_DATE, UNITCODE, 
      START_TIME, RANGE_TIME, IN_WATER,
      OUT_WATER, DISPLACEMENT, REASON, TYPE_ID,
      EFFECTIVE,
      CREATED_ON, MODIFIED_ON)
    values (#{wellname,jdbcType=VARCHAR}, #{recordDate,jdbcType=TIMESTAMP}, #{unitcode,jdbcType=VARCHAR}, 
      #{startTime,jdbcType=TIMESTAMP}, #{rangeTime,jdbcType=DECIMAL}, #{inWater,jdbcType=DECIMAL},
      #{outWater,jdbcType=DECIMAL}, #{displacement,jdbcType=DECIMAL}, #{reason,jdbcType=VARCHAR}, #{typeId,jdbcType=VARCHAR},
      #{effective,jdbcType=CHAR},
      #{createdOn,jdbcType=TIMESTAMP}, #{modifiedOn,jdbcType=TIMESTAMP})
  </insert>
  <update id="updateByPrimaryKeySelective" parameterType="FlushRecord">
    update CON_FLUSH_RECORD
    <set>
      <if test="unitcode != null">
        UNITCODE = #{unitcode,jdbcType=VARCHAR},
      </if>
      <if test="startTime != null">
        START_TIME = #{startTime,jdbcType=TIMESTAMP},
      </if>
      <if test="rangeTime != null">
        RANGE_TIME = #{rangeTime,jdbcType=DECIMAL},
      </if>
      <if test="inWater != null">
        IN_WATER = #{inWater,jdbcType=DECIMAL},
      </if>
      <if test="outWater != null">
        OUT_WATER = #{outWater,jdbcType=DECIMAL},
      </if>
      <if test="displacement != null">
        DISPLACEMENT = #{displacement,jdbcType=DECIMAL},
      </if>
      <if test="reason != null">
        REASON = #{reason,jdbcType=VARCHAR},
      </if>
      <if test="typeId != null">
        TYPE_ID = #{typeId,jdbcType=VARCHAR},
      </if>
      <if test="effective != null">
        EFFECTIVE = #{effective,jdbcType=CHAR},
      </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="FlushRecord">
    update CON_FLUSH_RECORD
    set UNITCODE = #{unitcode,jdbcType=VARCHAR},
      START_TIME = #{startTime,jdbcType=TIMESTAMP},
      RANGE_TIME = #{rangeTime,jdbcType=DECIMAL},
      IN_WATER = #{inWater,jdbcType=DECIMAL},
      OUT_WATER = #{outWater,jdbcType=DECIMAL},
      DISPLACEMENT = #{displacement,jdbcType=DECIMAL},
      REASON = #{reason,jdbcType=VARCHAR},
      TYPE_ID = #{typeId,jdbcType=VARCHAR},
      EFFECTIVE = #{effective,jdbcType=CHAR},
      CREATED_ON = #{createdOn,jdbcType=TIMESTAMP},
      MODIFIED_ON = #{modifiedOn,jdbcType=TIMESTAMP}
    where WELLNAME = #{wellname,jdbcType=VARCHAR}
      and RECORD_DATE = #{recordDate,jdbcType=TIMESTAMP}
  </update>
</mapper>