<?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.WellGroupDao">
  <sql id="Base_Column_List">
    ID, "NAME", UNITCODE, OIL_WELLS, WATER_WELLS,
    (select unitname from sys_unitinfo where unitcode = WELL_GROUP.unitcode) unitname
  </sql>
  <select id="selectByPrimaryKey" parameterType="java.lang.String" resultType="WellGroup">
    select
    <include refid="Base_Column_List" />
    from WELL_GROUP
    where ID = #{id,jdbcType=VARCHAR}
  </select>
  <delete id="deleteByPrimaryKey" parameterType="java.lang.String">
    delete from WELL_GROUP
    where ID = #{id,jdbcType=VARCHAR}
  </delete>
  <insert id="insert" parameterType="WellGroup">
    insert into WELL_GROUP (ID, "NAME", UNITCODE,
      OIL_WELLS, WATER_WELLS)
    values (#{id,jdbcType=VARCHAR}, #{name,jdbcType=VARCHAR}, #{unitcode,jdbcType=VARCHAR},
      #{oilWells,jdbcType=VARCHAR}, #{waterWells,jdbcType=VARCHAR})
  </insert>
  <update id="updateByPrimaryKeySelective" parameterType="WellGroup">
    update WELL_GROUP
    <set>
      <if test="name != null">
        "NAME" = #{name,jdbcType=VARCHAR},
      </if>
      <if test="unitcode != null">
        UNITCODE = #{unitcode,jdbcType=VARCHAR},
      </if>
      <if test="oilWells != null">
        OIL_WELLS = #{oilWells,jdbcType=VARCHAR},
      </if>
      <if test="waterWells != null">
        WATER_WELLS = #{waterWells,jdbcType=VARCHAR},
      </if>
    </set>
    where ID = #{id,jdbcType=VARCHAR}
  </update>
  <update id="updateByPrimaryKey" parameterType="WellGroup">
    update WELL_GROUP
    set "NAME" = #{name,jdbcType=VARCHAR},
      UNITCODE = #{unitcode,jdbcType=VARCHAR},
      OIL_WELLS = #{oilWells,jdbcType=VARCHAR},
      WATER_WELLS = #{waterWells,jdbcType=VARCHAR}
    where ID = #{id,jdbcType=VARCHAR}
  </update>

  <select id="selectWellGroupList" parameterType="UnitGroupWellParam" resultType="WellGroup">
    select
    <include refid="Base_Column_List" />
    from WELL_GROUP
    <where>
      <if test="unitcode != null and unitcode != ''">
        and unitcode = #{unitcode}
      </if>
      <if test="wellGroupName != null and wellGroupName != ''">
        and name like '%' || #{wellGroupName} || '%'
      </if>
      <if test="wellname != null and wellname != ''">
        and (',' || OIL_WELLS || ',' like '%,' || #{wellname} || ',%'
          or ',' || WATER_WELLS || ',' like '%,' || #{wellname} || ',%')
      </if>
    </where>
    order by name
  </select>

  <select id="selectByOilWellname" parameterType="String" resultType="WellGroup">
    select
    <include refid="Base_Column_List" />
    from WELL_GROUP
    where ',' || OIL_WELLS || ',' like '%,' || #{wellname} || ',%'
  </select>
</mapper>
