<?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.FlushDailyDao">
  <sql id="Base_Column_List">
    cfd.WELLNAME, RECORD_DATE, cfd.UNITCODE, RANGE_TIME, DISPLACEMENT, REASON, TYPE_ID, BEFORE_PT,
    BEFORE_PLAN_WATER, BEFORE_WATER, AFTER_PT, AFTER_PLAN_WATER, AFTER_WATER, AFTER_WATER_RATE, 
    EFFECTIVE, CREATED_ON, MODIFIED_ON, decode(EFFECTIVE, '1', '是', '0', '否', '') EFFECTIVE_NAME,
    (select flag_name from sys_flag where category_code = 'FLUSH_TYPE' and flag_code = cfd.TYPE_ID) TYPE_NAME
  </sql>
  <select id="selectList" parameterType="FlushDailyParam" resultType="FlushDaily">
    select
    <include refid="Base_Column_List" />
    , su.unitname, su.fullname
    from CON_FLUSH_DAILY cfd, sys_unitinfo su
    where cfd.unitcode = su.unitcode
    <if test="unitcode != null and unitcode != ''">
      and cfd.unitcode in (select unitcode from sys_unitinfo start with unitcode = #{unitcode} connect by prior unitcode = p_unitcode)
    </if>
    <if test="wellname != null and wellname != ''">
      and cfd.WELLNAME = #{wellname,jdbcType=VARCHAR}
    </if>
    <if test="typeId != null and typeId != ''">
      and cfd.TYPE_ID = #{typeId,jdbcType=VARCHAR}
    </if>
    and cfd.RECORD_DATE >= #{startDate}
    and cfd.RECORD_DATE &lt;= #{endDate}
    order by cfd.RECORD_DATE, cfd.WELLNAME
  </select>
  <select id="selectByPrimaryKey" parameterType="FlushDaily" resultType="FlushDaily">
    select 
    <include refid="Base_Column_List" />
    from CON_FLUSH_DAILY cfd
    where WELLNAME = #{wellname,jdbcType=VARCHAR}
      and RECORD_DATE = #{recordDate,jdbcType=TIMESTAMP}
  </select>
  <update id="updateByPrimaryKeySelective" parameterType="FlushDaily">
    update CON_FLUSH_DAILY
    <set>
      <if test="unitcode != null">
        UNITCODE = #{unitcode,jdbcType=VARCHAR},
      </if>
      <if test="rangeTime != null">
        RANGE_TIME = #{rangeTime,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>
</mapper>