<?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.fdkankan.scene.mapper.ISceneCooperationMapper">

  <select id="selectCooperationSceneListNew" parameterType="com.fdkankan.scene.vo.SceneParamVO" resultType="com.fdkankan.scene.vo.CooperationSceneVO">
    select * from
    t_scene_pro p
    left join t_scene_pro_ext px on p.id = px.scene_pro_id
    where and p.tb_status = 0
    and px.scene_source != 11
    and num in
    <foreach collection="numList" item="num" open="(" close=")" separator=",">
      #{num}
    </foreach>
    <if test="sceneSourceList != null and sceneSourceList.size() != 0">
      and px.scene_source in
      <foreach collection="sceneSourceList" item="sceneSource" open="(" close=")" separator=",">
        #{sceneSource}
      </foreach>
    </if>
    <if test="sceneType != null and sceneType !=''">
      and p.scene_type = #{sceneType}
    </if>
    <if test="startTime != null">
      and p.create_time >= #{startTime}
    </if>
    <if test="endTime != null">
      and p.create_time <![CDATA[ <= ]]> #{endTime}
    </if>
    <if test="folderId != null">
      AND EXISTS (SELECT 1 FROM t_folder_scene fs WHERE fs.scene_id = p.id AND fs.folder_id = #{folder_Id} AND fs.`tb_status` = 0)
    </if>

    <if test="folderId != null and sceneSource == null and sceneType == null and startTime == null and endTime == null">
      union
      select * from
      t_folder f
      where f.tb_status = 0
      and f.user_id = #{userId}
      and f.parent_id = #{folderId}
    </if>

  </select>

  <select id="getCooperationSceneNum" resultType="integer">
    SELECT count(0) FROM t_scene_cooperation a LEFT JOIN t_scene_plus b ON a.scene_num = b.num  WHERE a.tb_status = 0 AND b.tb_status = 0
            AND a.user_id = #{userId}  AND b.scene_source in
    <foreach collection="sceneSource" item="index" open="(" close=")" separator=",">
      #{index}
    </foreach>
  </select>


</mapper>
