<?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.sys.dao.WellSectionDailyDao">
  <sql id="Base_Column_List">
    WELLNAME, RECORD_DATE, "SECTION", UNITCODE, WELL_TYPE, NOZZLE, PP, PC, PT, PLAN_DAILY_WATER, 
    DAILY_WATER, WATER_WELL_CLASSIFY, INJECT_TYPE, OPEN_TIME, REMARK_CODE, REMARK_CODE1, LAYER, INJECT_TYPE_YS,
    REMARK, PLAN_SECTION
  </sql>

  <select id="selectByPrimaryKey" parameterType="WellSectionDaily" resultType="WellSectionDaily">
    select 
    <include refid="Base_Column_List" />
    from WELL_SECTION_DAILY
    where WELLNAME = #{wellname,jdbcType=VARCHAR}
      and RECORD_DATE = #{recordDate,jdbcType=TIMESTAMP}
      and "SECTION" = #{section,jdbcType=INTEGER}
  </select>

  <select id="selectByDate" parameterType="Date" resultType="WellSectionDaily">
    select
    <include refid="Base_Column_List" />
    from WELL_SECTION_DAILY
    where RECORD_DATE >= #{startDate,jdbcType=TIMESTAMP}
    and RECORD_DATE &lt;= #{endDate,jdbcType=TIMESTAMP}
    order by WELLNAME, "SECTION", RECORD_DATE
  </select>

  <delete id="deleteByDate">
    delete from WELL_SECTION_DAILY
    where RECORD_DATE >= #{startDate,jdbcType=TIMESTAMP}
    and RECORD_DATE &lt;= #{endDate,jdbcType=TIMESTAMP}
  </delete>

  <delete id="deleteByPrimaryKey" parameterType="WellSectionDaily">
    delete from WELL_SECTION_DAILY
    where WELLNAME = #{wellname,jdbcType=VARCHAR}
      and RECORD_DATE = #{recordDate,jdbcType=TIMESTAMP}
      and "SECTION" = #{section,jdbcType=INTEGER}
  </delete>

  <update id="updateInjectType">
    merge into WELL_SECTION_DAILY t
    using
    <foreach collection="list" item="item" open="(" close=")" index="index" separator="union all" >
      select
      #{item.wellname} WELLNAME, #{item.recordDate} RECORD_DATE,
      #{item.section} "SECTION", #{item.injectType} INJECT_TYPE
      from dual
    </foreach>
    tmp on (tmp.WELLNAME = t.WELLNAME and tmp.RECORD_DATE = t.RECORD_DATE and tmp."SECTION" = t."SECTION")
    when matched then
    update set t.INJECT_TYPE = tmp.INJECT_TYPE
  </update>

</mapper>