<?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.decoration.TeamAreaMappingMapper">
  <resultMap id="BaseResultMap" type="com.cool.store.entity.decoration.TeamAreaMappingDO">
    <!--
      WARNING - @mbg.generated
    -->
    <id column="id" jdbcType="BIGINT" property="id" />
    <result column="team_id" jdbcType="BIGINT" property="teamId" />
    <result column="open_city_id" jdbcType="BIGINT" property="openCityId" />
    <result column="create_time" jdbcType="TIMESTAMP" property="createTime" />
  </resultMap>


  <!-- 批量插入 -->
  <insert id="batchInsert" parameterType="java.util.List">
    INSERT INTO zxjp_team_area_mapping (
    team_id,
    open_city_id
    ) VALUES
    <foreach collection="list" item="item" separator=",">
      (
      #{item.teamId},
      #{item.openCityId}
      )
    </foreach>
  </insert>

  <!-- 根据团队id删除 更新团队id时候删除 -->
  <delete id="deletedByTeamId" parameterType="java.lang.Long">
    DELETE FROM zxjp_team_area_mapping
    WHERE team_id = #{teamId}
  </delete>

  <!-- 根据ids删除 -->
  <delete id="deletedIds" parameterType="java.util.List">
    DELETE FROM zxjp_team_area_mapping
    WHERE id IN
    <foreach collection="ids" item="id" open="(" separator="," close=")">
      #{id}
    </foreach>
  </delete>

  <select id="getByCityId" parameterType="java.lang.Long" resultType="com.cool.store.entity.decoration.TeamAreaMappingDO">
    SELECT
    *
    FROM zxjp_team_area_mapping
    WHERE open_city_id = #{cityId}
    LIMIT 1
  </select>

  <select id="listByTeamIdList" parameterType="java.util.List" resultType="com.cool.store.dto.decoration.TeamAreaMappingDTO">
    SELECT
    a.team_id as teamId,
    a.open_city_id as openCityId,
    b.area_name as openCityName
    FROM zxjp_team_area_mapping a
    left join xfsg_open_area_info b on a.open_city_id = b.id
    WHERE a.team_id IN
    <foreach collection="teamIdList" item="teamId" open="(" separator="," close=")">
      #{teamId}
    </foreach>
  </select>


</mapper>