<?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="com.cool.store.mapper.HyIntendDevelopementMappingMapper">
  <resultMap id="BaseResultMap" type="com.cool.store.entity.HyIntendDevelopementMappingDO">
    <id column="id" jdbcType="BIGINT" property="id" />
    <result column="mapping_id" jdbcType="BIGINT" property="mappingId" />
    <result column="open_area_mapping_id" jdbcType="VARCHAR" property="openAreaMappingId" />
    <result column="type" jdbcType="VARCHAR" property="type" />
    <result column="create_time" jdbcType="TIMESTAMP" property="createTime" />
    <result column="update_time" jdbcType="TIMESTAMP" property="updateTime" />
  </resultMap>
  <sql id="Base_Column_List">
    id, mapping_id, open_area_mapping_id, type, create_time, update_time
  </sql>
  <insert id="insertSelective" keyColumn="id" keyProperty="record.id" useGeneratedKeys="true">
    insert into hy_intend_developement_mapping
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="record.mappingId != null">
        mapping_id,
      </if>
      <if test="record.openAreaMappingId != null">
        open_area_mapping_id,
      </if>
      <if test="record.type != null">
        type,
      </if>
      <if test="record.createTime != null">
        create_time,
      </if>
      <if test="record.updateTime != null">
        update_time,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides=",">
      <if test="record.mappingId != null">
        #{record.mappingId},
      </if>
      <if test="record.openAreaMappingId != null">
        #{record.openAreaMappingId},
      </if>
      <if test="record.type != null">
        #{record.type},
      </if>
      <if test="record.createTime != null">
        #{record.createTime},
      </if>
      <if test="record.updateTime != null">
        #{record.updateTime},
      </if>
    </trim>
  </insert>
  <update id="updateByPrimaryKeySelective">
    update hy_intend_developement_mapping
    <set>
      <if test="record.mappingId != null">
        mapping_id = #{record.mappingId},
      </if>
      <if test="record.openAreaMappingId != null">
        open_area_mapping_id = #{record.openAreaMappingId},
      </if>
      <if test="record.type != null">
        type = #{record.type},
      </if>
      <if test="record.createTime != null">
        create_time = #{record.createTime},
      </if>
      <if test="record.updateTime != null">
        update_time = #{record.updateTime},
      </if>
    </set>
    where id = #{record.id}
  </update>

  <delete id="deleteByOpenAreaIds">
    delete from hy_intend_developement_mapping
    <where>
      <if test="type!=null and type!=''">
        and type = #{type}
      </if>
      <if test="openAreaIdList!=null and openAreaIdList.size>0">
        <foreach collection="openAreaIdList" open="and open_area_mapping_id in (" close=")" separator="," item="openAreaId">
          #{openAreaId}
        </foreach>
      </if>
    </where>
  </delete>

  <delete id="deleteByMappingIds">
    delete from hy_intend_developement_mapping
    <where>
      <if test="type!=null and type!=''">
        and type = #{type}
      </if>
      <if test="mappingIds!=null and mappingIds.size>0">
        <foreach collection="mappingIds" open="and mapping_id in (" close=")" separator="," item="mappingId">
          #{mappingId}
        </foreach>
      </if>
    </where>
  </delete>


  <insert id="batchInsert">
    insert into
    hy_intend_developement_mapping
    (
    mapping_id,
    open_area_mapping_id,
    type
    )
    values
    <foreach collection="recordList" item="record" separator=",">
      (#{record.mappingId},
      #{record.openAreaMappingId},
      #{record.type})
    </foreach>
  </insert>


  <select id="selectByMappingIdList" resultType="com.cool.store.dto.partner.ZoneCheckDTO">
    select
    a.open_area_mapping_id  as openAreaMappingId,
    b.zone_name as zoneName
    from hy_intend_developement_mapping a inner join hy_intend_dev_zone_info b on a.mapping_id = b.id
    <where>
      <if test="mappingIdList!=null and mappingIdList.size>0">
        <foreach collection="mappingIdList" open="and a.mapping_id in (" close=")" separator="," item="mappingId">
          #{mappingId}
        </foreach>
      </if>
    </where>
  </select>


  <select id="selectByOpenAreaMappingIdList" resultType="com.cool.store.dto.partner.ZoneCheckDTO">
    select
    a.open_area_mapping_id  as openAreaMappingId,
    b.zone_name as zoneName,
    b.id as zoneId
    from hy_intend_developement_mapping a inner join hy_intend_dev_zone_info b on a.mapping_id = b.id
    <where>
      <if test="type!=null and type !=''">
        and a.type = #{type}
      </if>
      <if test="openAreaMappingIdList!=null and openAreaMappingIdList.size>0">
        <foreach collection="openAreaMappingIdList" open="and a.open_area_mapping_id in (" close=")" separator="," item="mappingId">
          #{mappingId}
        </foreach>
      </if>
      <if test="currentId!=null">
        and a.mapping_id != #{currentId}
      </if>
    </where>
  </select>

  <select id="selectByOpenAreaMappingId" resultMap="BaseResultMap">
    select
    *
    from hy_intend_developement_mapping a
    <where>
      <if test="type!=null and type !=''">
        and a.type = #{type}
      </if>
      <if test="openAreaMappingId!=null">
        and a.open_area_mapping_id = #{openAreaMappingId}
      </if>
    </where>
  </select>
</mapper>