<?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.xxfc.platform.campsite.mapper.CampsiteShopTagMapper">

	<!-- 可根据自己的需求，是否要使用 -->
    <resultMap type="com.xxfc.platform.campsite.entity.CampsiteShopTag" id="campsiteShopTagMap">
        <result property="id" column="id"/>
        <result property="shopId" column="shop_id"/>
        <result property="tagId" column="tag_id"/>
        <result property="crtTime" column="crt_time"/>
        <result property="updTime" column="upd_time"/>
        <result property="isDel" column="is_del"/>
    </resultMap>

    <!--根据营地ids 查询全部-->
    <select id="findAllByCampsiteShopIds" resultType="com.xxfc.platform.campsite.dto.CampsiteShopTagDTO">
          select cst.shop_id as `shopId`,cst.tag_id as `tagId`,ct.name as `name` from `campsite_shop_tag` as `cst` inner join `campsite_tag` as `ct` on cst.tag_id=ct.id where cst.is_del=0
          and cst.shop_id in
          <foreach collection="cspIds" item="spid" separator="," open="(" close=")">
              #{spid}
          </foreach>
    </select>

    <!--根据营地id查询 全部-->
    <select id="findAllByCampsiteShopId" resultType="com.xxfc.platform.campsite.dto.CampsiteShopTagDTO">
        select ct.id as `id`,ct.name as `name` from campsite_shop_tag as `cst` left join campsite_tag as `ct` on cst.tag_id=ct.id where `shop_id`=#{shopId}
    </select>

    <!--根据营地类型id和营地id更新关系状态-->
    <update id="updateCampsiteTagStatusByIdsAndShopId">
        update `campsite_shop_tag` set `is_del`=#{status} where `shop_id`=#{shopId}
        <if test="ids != null and ids.size() != 0">
            and `id` not in <foreach collection="ids" item="id" open="(" close=")" separator=",">
            #{id}
        </foreach>
        </if>

    </update>

    <!--批量保存-->
    <insert id="saveBatch">
        insert into `campsite_shop_tag`(`shop_id`,`tag_id`,`crt_time`)values
        <foreach collection="stgdtos" item="stg" separator=",">
            (#{stg.shopId} ,#{stg.tagId} ,#{stg.crtTime} )
        </foreach>
    </insert>

    <!--根据营地id删除-->
    <delete id="deleteByShopId">
        delete  from `campsite_shop_tag` where `shop_id`=#{shopId} ;
    </delete>

</mapper>