<?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.pcloud.book.skill.dao.impl.PcloudGroupActivityDaoImpl" >
    <resultMap id="BaseResultMap" type="com.pcloud.book.skill.entity.PcloudGroupActivity" >
        <id column="id" property="id" jdbcType="INTEGER" />
        <result column="number" property="number" jdbcType="VARCHAR" />
        <result column="group_extLink" property="groupExtLink" jdbcType="VARCHAR" />
        <result column="group_type" property="groupType" jdbcType="INTEGER" />
        <result column="name" property="name" jdbcType="VARCHAR" />
        <result column="description" property="desc" jdbcType="VARCHAR" />
        <result column="join_type" property="joinType" jdbcType="INTEGER" />
        <result column="group_pic" property="groupPic" jdbcType="VARCHAR" />
        <result column="pro_label_id" property="proLabelId" jdbcType="INTEGER" />
        <result column="dep_label_id" property="depLabelId" jdbcType="INTEGER" />
        <result column="pur_label_id" property="purLabelId" jdbcType="INTEGER" />
        <result column="book_group_classify_id" property="bookGroupClassifyId" jdbcType="INTEGER" />
        <result column="group_name" property="groupName" jdbcType="VARCHAR" />
        <result column="create_time" property="createTime" jdbcType="TIMESTAMP" />
        <result column="create_user" property="createUser" jdbcType="INTEGER" />
        <result column="update_time" property="updateTime" jdbcType="TIMESTAMP" />
        <result column="update_user" property="updateUser" jdbcType="INTEGER" />
        <result column="is_delete" property="isDelete" jdbcType="BIT" />
        <result column="first_classify" property="firstClassify" jdbcType="BIGINT" />
        <result column="second_classify" property="secondClassify" jdbcType="BIGINT" />
        <result column="third_classify" property="thirdClassify" jdbcType="BIGINT" />
        <result column="grade_label_id" property="gradeLabelId" jdbcType="BIGINT" />
        <result column="subject_label_id" property="subjectLabelId" jdbcType="BIGINT" />
        <result column="media_id" property="mediaId" jdbcType="VARCHAR"/>
        <result column="agent_id" property="agentId" jdbcType="BIGINT" />
        <result column="brand_name" property="brandName" jdbcType="VARCHAR"/>
    </resultMap>
    <sql id="Base_Column_List" >
    id, name, description, join_type, group_pic, pro_label_id, dep_label_id,
    pur_label_id, book_group_classify_id,
    create_time, create_user, update_time, update_user, is_delete,
    first_classify, second_classify, third_classify, grade_label_id, subject_label_id,media_id, agent_id, brand_name
  </sql>

    <update id="batchUpdateClassify" parameterType="map">
        UPDATE pcloud_group_activity
        SET
        first_classify = #{firstClassify,jdbcType=BIGINT},
        second_classify = #{secondClassify,jdbcType=BIGINT},
         third_classify = #{thirdClassify},
        grade_label_id = #{gradeLabelId,jdbcType=BIGINT},
        subject_label_id = #{subjectLabelId,jdbcType=BIGINT},
        update_time=NOW()
        WHERE id IN
        <foreach collection="ids" item="item" separator="," open="(" close=")" >
            ${item}
        </foreach>
    </update>

    <select id="getCountByNumber" parameterType="String" resultType="integer">
        select count(1)
        from pcloud_group_activity
        where number=#{number}
        <choose>
            <when test="agentId != null">
                and agent_id = #{agentId}
            </when>
            <otherwise>
                and agent_id = 0
            </otherwise>
        </choose>
        and is_delete = 0
    </select>


    <update id="batchUpdateShowState" parameterType="map">
        UPDATE pcloud_group_activity
        SET
        is_show = #{showState},
        update_time=NOW()
        WHERE id IN
        <foreach collection="ids" item="item" separator="," open="(" close=")" >
            ${item}
        </foreach>
    </update>

    <update id="deleteByIds" parameterType="long">
        update pcloud_group_activity set is_delete = 1 where id in
        <foreach collection="list" item="item" index="index" open="(" separator="," close=")">
            ${item}
        </foreach>
    </update>


    <update id="deleteById" parameterType="long">
    update pcloud_group_activity set is_delete = 1 where id = #{id}
  </update>

    <select id="getGroupClassifyIds" resultType="long" parameterType="map">
        select book_group_classify_id from pcloud_group_activity
        where
            is_delete = 0 and is_show = 1
            <if test="firstClassify != null">
                and first_classify = #{firstClassify}
            </if>
            <if test="secondClassify != null">
                and second_classify = #{secondClassify}
            </if>
            <if test="thirdClassify != null">
                and third_classify = #{thirdClassify}
            </if>
            <if test="gradeLabelId != null">
                and grade_label_id = #{gradeLabelId}
            </if>
            <if test="subjectLabelId != null">
                and subject_label_id = #{subjectLabelId}
            </if>
            <choose>
                <when test="agentId != null">
                    and agent_id = #{agentId}
                </when>
                <otherwise>
                    and agent_id = 0
                </otherwise>
            </choose>
        order by id desc
    </select>

    <select id="queryGroupActivity" resultType="com.pcloud.book.skill.facade.response.QueryGroupActivityResponseVO" parameterType="map" >
        SELECT
        a.id,
        a.`name`,
        a.description as `desc`,
        a.join_type AS joinType,
        b.id AS bookGroupClassifyId,
        a.pro_label_id AS proLabelId,
        a.dep_label_id AS depLabelId,
        a.pur_label_id AS purLabelId,
        b.classify AS classifyName,
        a.first_classify AS firstClassify,
        a.second_classify AS secondClassify,
        a.third_classify AS thirdClassify,
        a.grade_label_id AS gradeLabelId,
        a.subject_label_id AS subjectLabelId,
        a.number,
        a.group_extLink as groupExtLink,
        a.group_type as groupType,
        is_show AS isShow,
        b.city_code cityCode,
        a.brand_name brandName
        FROM
        pcloud_group_activity a left join book_group_classify b on a.book_group_classify_id = b.id
        WHERE
        a.is_delete = 0
        <if test='isChoose == "1"'>
            and
            ifnull(b.is_delete, 0) = 0
            and a.is_Show = 1
        </if>
        <if test="proLabelId != null">
            and a.pro_label_id = #{proLabelId}
        </if>
        <if test="depLabelId != null">
            and a.dep_label_id = #{depLabelId}
        </if>
        <if test="purLabelId != null">
            and a.pur_label_id = #{purLabelId}
        </if>
        <if test="name != null">
            and (a.name like CONCAT('%', #{name},'%') or a.number like CONCAT('%', #{name},'%') )
        </if>
        <if test="joinType != null">
            and a.join_type = #{joinType}
        </if>
        <if test="firstClassify != null">
            and a.first_classify = #{firstClassify}
        </if>
        <if test="secondClassify != null">
            and a.second_classify = #{secondClassify}
        </if>
        <if test="thirdClassify != null">
            and a.third_classify = #{thirdClassify}
        </if>
        <if test="gradeLabelId != null">
            and a.grade_label_id = #{gradeLabelId}
        </if>
        <if test="subjectLabelId != null">
            and a.subject_label_id = #{subjectLabelId}
        </if>
        <if test="cityCode != null">
            and b.city_code = #{cityCode}
            and a.group_type != 1
        </if>
        <if test="groupType != null">
            and a.group_type = #{groupType}
        </if>
        <if test="brandName != null">
            and a.brand_name like CONCAT('%', #{brandName},'%')
        </if>
        <choose>
            <when test="agentId != null">
                and a.agent_id = #{agentId}
            </when>
            <otherwise>
                and a.agent_id = 0
            </otherwise>
        </choose>
        order by a.id desc
    </select>

    <select id="listGroupActivity" resultType="com.pcloud.book.skill.facade.response.ListGroupActivityResponseVO" parameterType="map" >
        SELECT
        a.id,
        a.name,
        a.description,
        a.number,
        a.group_type groupType,
        a.group_extLink groupExtLink,
        b.id classifyId,
        b.classify classifyName,
        b.classify_introduce AS classifyIntroduce,
        b.book_group_id bookGroupId,
        b.price,
        count(c.classify_id) AS groupCount
        FROM
        pcloud_group_activity a
        LEFT JOIN book_group_classify b ON a.book_group_classify_id = b.id
        LEFT JOIN book_group_qrcode c ON b.id = c.classify_id
        LEFT JOIN book_group d ON b.book_group_id = d.id
        <where>
            <if test="name!=null or bookIds != null and bookIds.size()>0">
                <trim prefix="(" suffix=")" prefixOverrides="OR">
                    <if test="name!=null">
                        a.name LIKE CONCAT("%",#{name},"%")
                    </if>
                    <if test="bookIds.size()>0">
                        OR b.book_id IN
                        <foreach collection="bookIds" open="(" separator="," close=")" index="index" item="item">
                            ${item}
                        </foreach>
                    </if>
                </trim>
            </if>
            <if test="proLabelId!=null">
                AND c.pro_label_id = #{proLabelId}
            </if>
            <if test="depLabelId!=null">
                AND c.dep_label_id = #{depLabelId}
            </if>
            <if test="joinType != null">
                AND a.join_type = #{joinType}
            </if>
            AND a.is_delete = 0  and   ifnull(b.is_delete, 0) = 0  and a.is_show = 1
            <choose>
                <when test="agentId != null">
                    and a.agent_id = #{agentId}
                </when>
                <otherwise>
                    and a.agent_id = 0
                </otherwise>
            </choose>
        </where>
        GROUP BY a.id
        ORDER BY a.create_time DESC
    </select>

    <select id="getTishBookSchoolList" resultType="com.pcloud.book.applet.dto.GroupActivity4AppletDTO" parameterType="map" >
        SELECT
        a.id,
        a.id groupActivityId,
        a.`name`,
        a.description as `desc`,
        a.join_type AS joinType,
        c.classify AS classifyName,
        a.book_group_classify_id classifyId,
        c.book_group_id bookGroupId,
        a.first_classify AS firstClassify,
        a.second_classify AS secondClassify,
        a.third_classify as thirdClassify,
        a.grade_label_id AS gradeLabelId,
        a.subject_label_id AS subjectLabelId,
        d.related_book_group_id AS relatedBookGroupId,
        c.id AS classifyId,
        c.book_group_id AS bookGroupId,
        d.related_book_group_id AS relatedBookGroupId,
        c.price AS price,
        a.group_type as groupType,
        group_extLink as groupLink
        FROM
        pcloud_group_activity a
        LEFT JOIN book_group_classify c ON a.book_group_classify_id = c.id AND c.is_delete = 0
        LEFT JOIN book_group_qrcode b ON b.classify_id = c.id
        LEFT JOIN book_group d ON c.book_group_id = d.id
        WHERE
        a.is_delete = 0 AND a.is_show = 1  AND IFNULL(b.is_delete,0) = 0
        and !(c.id is null and a.group_type!=1)
        <if test="firstClassify != null">
            and a.first_classify = #{firstClassify}
        </if>
        <if test="secondClassify != null">
            and a.second_classify = #{secondClassify}
        </if>
        <if test="thirdClassify != null">
            and a.third_classify = #{thirdClassify}
        </if>
        <if test="gradeLabelId != null">
            and a.grade_label_id = #{gradeLabelId}
        </if>
        <if test="subjectLabelId != null">
            and a.subject_label_id = #{subjectLabelId}
        </if>
        <choose>
            <when test="agentId >0">
                and a.agent_id in (#{agentId} ,0)
            </when>
            <otherwise>
                and a.agent_id = 0
            </otherwise>
        </choose>
        GROUP BY a.id
        ORDER BY a.agent_id desc, a.id DESC
        LIMIT #{limit}
    </select>

  <select id="getById" resultMap="BaseResultMap" parameterType="long" >
    SELECT
        a.id,
        a.`name`,
        a.description,
        a.join_type,
        a.pro_label_id,
        a.dep_label_id,
        a.pur_label_id,
        a.book_group_classify_id,
        a.create_time,
        a.create_user,
        a.update_time,
        a.update_user,
        a.is_delete,
        b.classify AS groupName,
        a.first_classify,
        a.second_classify,
        a.third_classify,
        a.grade_label_id,
        a.subject_label_id,
        a.is_show,
        a.number,
        a.group_extLink,
        a.group_type,
        a.media_id,
        a.agent_id
    FROM pcloud_group_activity a LEFT JOIN book_group_classify b ON a.book_group_classify_id = b.id
    WHERE a.id = #{id,jdbcType=INTEGER} and a.is_delete = 0
  </select>

    <!-- 立享权益加入 编辑端群 add by pansy  2020/7/2 -->
    <select id="getGroupClassifyByIds" resultType="com.pcloud.book.applet.dto.GroupActivity4AppletDTO">
        SELECT
        c.id,
        c.classify as `name`,
        c.classify_introduce AS `desc`,
        c.price AS price,
        a.join_type AS joinType,
        c.classify AS groupName,
        b.user_number userNumber,
        b.classify_id classifyId,
        c.book_group_id bookGroupId,
        a.first_classify AS firstClassify,
        a.second_classify AS secondClassify,
        a.third_classify as thirdClassify,
        a.grade_label_id AS gradeLabelId,
        a.subject_label_id AS subjectLabelId,
        'GROUP' as serveType,
        '2' as groupType,
        c.id as serveId
        FROM
        book_group_classify c
        LEFT JOIN pcloud_group_activity a ON a.book_group_classify_id = c.id
        LEFT JOIN book_group_qrcode b on b.classify_id = c.id
        where
        IFNULL(b.is_delete,0) = 0
        and
        c.id IN
        <foreach collection="list" item="item" open="(" close=")" separator=",">
            ${item}
        </foreach>
        GROUP BY c.id
        ORDER BY c.id DESC
    </select>

    <select id="getByIds" resultType="com.pcloud.book.applet.dto.GroupActivity4AppletDTO">
        SELECT
        a.id,
        a.id groupActivityId,
        a.`name`,
        a.description as `desc`,
        a.join_type AS joinType,
        c.classify AS groupName,
        c.price AS price,
        b.user_number userNumber,
        b.classify_id classifyId,
        c.book_group_id bookGroupId,
        a.first_classify AS firstClassify,
        a.second_classify AS secondClassify,
        a.third_classify as thirdClassify,
        a.grade_label_id AS gradeLabelId,
        a.subject_label_id AS subjectLabelId,
        IFNULL(case c.price when a.group_type = 1 then 0 else c.price END, 0) price,
        d.related_book_group_id relatedBookGroupId,
        a.group_type as groupType,
        a.group_extLink groupLink,
        'GROUP' as serveType
        FROM
        pcloud_group_activity a
        left JOIN book_group_classify c ON a.book_group_classify_id = c.id
        left JOIN book_group_qrcode b on b.classify_id = c.id
        left JOIN book_group d ON c.book_group_id = d.id
        WHERE
        a.is_delete = 0 AND IFNULL(b.is_delete,0) = 0
        AND IFNULL(c.is_delete, 0) = 0
        <if test="isShow != null">
            AND a.is_show = #{isShow}
        </if>
        AND a.id IN
        <foreach collection="list" item="item" open="(" close=")" separator=",">
            ${item}
        </foreach>
        GROUP BY a.id
        ORDER BY a.id DESC
    </select>

    <!--根据id获取第三方群信息 -->
    <select id="getThirdPartByIds" resultType="com.pcloud.book.applet.dto.GroupActivity4AppletDTO">
        SELECT
        a.id,
        a.id groupActivityId,
        a.`name`,
        a.description as `desc`,
        a.join_type AS joinType,
        a.`name` AS groupName,
        null userNumber,
        null bookGroupId,
        a.first_classify AS firstClassify,
        a.second_classify AS secondClassify,
        a.third_classify as thirdClassify,
        a.grade_label_id AS gradeLabelId,
        a.subject_label_id AS subjectLabelId,
        c.price AS price,
        null relatedBookGroupId,
        a.group_type as groupType,
        a.group_extLink as groupLink,
        a.book_group_classify_id classifyId
        FROM
        pcloud_group_activity a
        left join book_group_classify c on a.book_group_classify_id =  c.id
        WHERE
        a.is_delete = 0 AND a.is_show = 1
        AND a.id IN
        <foreach collection="list" item="item" open="(" close=")" separator=",">
            ${item}
        </foreach>
        GROUP BY a.id
        ORDER BY a.id DESC
    </select>

    <select id="getGroupActivity4Applet" resultType="com.pcloud.book.applet.dto.GroupActivity4AppletDTO" parameterType="map">
        SELECT
        a.id,
        a.id groupActivityId,
        a.`name`,
        a.description as `desc`,
        a.join_type AS joinType,
        a.group_pic AS groupPic,
        b.group_name AS groupName,
        b.user_number userNumber,
        b.classify_id classifyId,
        c.book_group_id bookGroupId,
        a.first_classify AS firstClassify,
        a.second_classify AS secondClassify,
        a.third_classify as thirdClassify,
        a.grade_label_id AS gradeLabelId,
        a.subject_label_id AS subjectLabelId
        FROM
        pcloud_group_activity a
        INNER JOIN book_group_classify c ON a.book_group_classify_id = c.id AND c.is_delete = 0
        INNER JOIN book_group_qrcode b on c.id = b.classify_id
        WHERE
        a.is_delete = 0 AND a.is_show = 1 AND IFNULL(b.is_delete,0) = 0
        <if test="firstClassify != null">
            and a.first_classify = #{firstClassify}
        </if>
        <if test="secondClassify != null">
            and a.second_classify = #{secondClassify}
        </if>
        <if test="thirdClassify != null">
            and a.third_classify = #{thirdClassify}
        </if>
        <if test="gradeLabelId != null">
            and a.grade_label_id = #{gradeLabelId}
        </if>
        <if test="subjectLabelId != null">
            and a.subject_label_id = #{subjectLabelId}
        </if>
        GROUP BY a.id
        ORDER BY a.id DESC
        LIMIT 1
    </select>

    <insert id="insert" parameterType="com.pcloud.book.skill.entity.PcloudGroupActivity" >
    insert into pcloud_group_activity (id, name,
      description, join_type, group_pic, pro_label_id, dep_label_id,
      pur_label_id, book_group_classify_id, create_time,
      create_user, update_time, update_user,
      is_delete, first_classify, second_classify, third_classify, grade_label_id, subject_label_id,number,
      group_type,group_extLink, agent_id, brand_name)
    values (#{id,jdbcType=INTEGER}, #{name,jdbcType=VARCHAR},
      #{desc,jdbcType=VARCHAR}, #{joinType,jdbcType=INTEGER}, #{groupPic,jdbcType=VARCHAR}, #{proLabelId,jdbcType=INTEGER}, #{depLabelId,jdbcType=INTEGER},
      #{purLabelId,jdbcType=INTEGER}, #{bookGroupClassifyId,jdbcType=INTEGER}, #{createTime,jdbcType=TIMESTAMP},
      #{createUser,jdbcType=INTEGER}, #{updateTime,jdbcType=TIMESTAMP}, #{updateUser,jdbcType=INTEGER},
      #{isDelete,jdbcType=BIT}, #{firstClassify,jdbcType=BIGINT}, #{secondClassify,jdbcType=BIGINT}, #{thirdClassify},
      #{gradeLabelId,jdbcType=BIGINT}, #{subjectLabelId,jdbcType=BIGINT}, #{number,jdbcType=BIGINT},
      #{groupType,jdbcType=BIGINT}, #{groupExtLink,jdbcType=VARCHAR}, #{agentId}, #{brandName})
  </insert>
    <update id="updateByPrimaryKeySelective" parameterType="com.pcloud.book.skill.entity.PcloudGroupActivity" >
        update pcloud_group_activity
        <set >
            <if test="name != null" >
                name = #{name,jdbcType=VARCHAR},
            </if>
            <if test="desc != null" >
                description = #{desc,jdbcType=VARCHAR},
            </if>
            <if test="joinType != null" >
                join_type = #{joinType,jdbcType=INTEGER},
            </if>
            <if test="groupPic != null" >
                group_pic = #{groupPic,jdbcType=VARCHAR},
            </if>
            <if test="proLabelId != null" >
                pro_label_id = #{proLabelId,jdbcType=INTEGER},
            </if>
            <if test="depLabelId != null" >
                dep_label_id = #{depLabelId,jdbcType=INTEGER},
            </if>
            <if test="purLabelId != null" >
                pur_label_id = #{purLabelId,jdbcType=INTEGER},
            </if>
            <if test="bookGroupClassifyId != null" >
                book_group_classify_id = #{bookGroupClassifyId,jdbcType=INTEGER},
            </if>
            <if test="createTime != null" >
                create_time = #{createTime,jdbcType=TIMESTAMP},
            </if>
            <if test="createUser != null" >
                create_user = #{createUser,jdbcType=INTEGER},
            </if>
            <if test="updateTime != null" >
                update_time = #{updateTime,jdbcType=TIMESTAMP},
            </if>
            <if test="updateUser != null" >
                update_user = #{updateUser,jdbcType=INTEGER},
            </if>
            <if test="isDelete != null" >
                is_delete = #{isDelete,jdbcType=BIT},
            </if>
            <if test="isShow != null" >
                is_show = #{isShow,jdbcType=BIT},
            </if>
            <if test="number !=null">
                number = #{number,jdbcType=VARCHAR},
            </if>
            <if test="groupExtLink !=null">
                group_extLink = #{groupExtLink,jdbcType=VARCHAR},
            </if>
            <if test="groupType !=null">
                group_type = #{groupType,jdbcType=BIT},
            </if>
            <if test="mediaId !=null">
                media_id = #{mediaId,jdbcType=VARCHAR},
            </if>
            first_classify = #{firstClassify,jdbcType=BIGINT},
            second_classify = #{secondClassify,jdbcType=BIGINT},
            third_classify = #{thirdClassify},
            grade_label_id = #{gradeLabelId,jdbcType=BIGINT},
            subject_label_id = #{subjectLabelId,jdbcType=BIGINT},
            <if test="brandName != null">
                brand_name = #{brandName},
            </if>
        </set>
        where id = #{id,jdbcType=INTEGER}
    </update>
    <update id="update" parameterType="com.pcloud.book.skill.entity.PcloudGroupActivity" >
    update pcloud_group_activity
    set name = #{name,jdbcType=VARCHAR},
      description = #{desc,jdbcType=VARCHAR},
      join_type = #{joinType,jdbcType=INTEGER},
      group_pic = #{groupPic,jdbcType=VARCHAR},
      pro_label_id = #{proLabelId,jdbcType=INTEGER},
      dep_label_id = #{depLabelId,jdbcType=INTEGER},
      pur_label_id = #{purLabelId,jdbcType=INTEGER},
      book_group_classify_id = #{bookGroupClassifyId,jdbcType=INTEGER},
      create_time = #{createTime,jdbcType=TIMESTAMP},
      create_user = #{createUser,jdbcType=INTEGER},
      update_time = #{updateTime,jdbcType=TIMESTAMP},
      update_user = #{updateUser,jdbcType=INTEGER},
      is_delete = #{isDelete,jdbcType=BIT},
      first_classify = #{firstClassify,jdbcType=BIGINT},
      second_classify = #{secondClassify,jdbcType=BIGINT},
      third_classify = #{thirdClassify},
      grade_label_id = #{gradeLabelId,jdbcType=BIGINT},
      subject_label_id = #{subjectLabelId,jdbcType=BIGINT},
      is_show = #{isShow,jdbcType=BIT},
      group_type = #{groupType},
      group_extLink = #{groupExtLink},
      number = #{number},
      media_Id = #{mediaId}
    where id = #{id,jdbcType=INTEGER}
  </update>

    <select id="mayByIds" parameterType="long" resultMap="BaseResultMap">
        select <include refid="Base_Column_List"/>
        from pcloud_group_activity
        where id in
        <foreach collection="list" index="i" item="item" open="(" separator="," close=")">
            ${item}
        </foreach>
    </select>

    <select id="getGroupListByBookTemplet" parameterType="map" resultType="com.pcloud.book.applet.dto.AppletGroupManageDTO">
        SELECT
        a.id,
        a.id groupActivityId,
        a.`name`,
        a.description as `desc`,
        a.join_type AS joinType,
        a.group_pic AS groupPic,
        c.classify AS classifyName,
        b.user_number userNumber,
        a.book_group_classify_id classifyId,
        c.book_group_id bookGroupId,
        a.first_classify AS firstClassify,
        a.second_classify AS secondClassify,
        a.third_classify as thirdClassify,
        a.grade_label_id AS gradeLabelId,
        a.subject_label_id AS subjectLabelId,
        c.price,
        g.related_book_group_id relatedBookGroupId,
        a.group_type as groupType,
        a.group_extLink groupLink
        FROM
        pcloud_group_activity a
        LEFT JOIN book_group_classify c ON a.book_group_classify_id = c.id AND c.is_delete = 0
        LEFT JOIN book_group_qrcode b on c.id = b.classify_id
        LEFT JOIN book_group g ON g.id = c.book_group_id
        WHERE
        a.is_delete = 0 AND a.is_show = 1 AND IFNULL(b.is_delete,0) = 0
        and !(c.id is null and a.group_type!=1)
        <if test="firstClassify != null">
            and a.first_classify = #{firstClassify}
        </if>
        <if test="secondClassify != null">
            and a.second_classify = #{secondClassify}
        </if>
        <if test="thirdClassify != null">
            and a.third_classify = #{thirdClassify}
        </if>
        <if test="gradeLabelId != null">
            and a.grade_label_id = #{gradeLabelId}
        </if>
        <if test="subjectLabelId != null">
            and a.subject_label_id = #{subjectLabelId}
        </if>
        <choose>
            <when test="agentId != null">
                and a.agent_id = #{agentId}
            </when>
            <otherwise>
                and a.agent_id = 0
            </otherwise>
        </choose>
        GROUP BY a.id
        ORDER BY a.id DESC
    </select>



  <select id="getLocalGroup" parameterType="map" resultType="com.pcloud.book.applet.dto.AppletGroupManageDTO">
  SELECT
  a.id,
  a.id groupActivityId,
  a.`name`,
  a.description as `desc`,
  a.join_type AS joinType,
  a.group_pic AS groupPic,
  c.classify AS classifyName,
  b.user_number userNumber,
  b.classify_id classifyId,
  c.book_group_id bookGroupId,
  a.first_classify AS firstClassify,
  a.second_classify AS secondClassify,
  a.third_classify as thirdClassify,
  a.grade_label_id AS gradeLabelId,
  a.subject_label_id AS subjectLabelId,
  c.price,
  g.related_book_group_id relatedBookGroupId
  FROM
  pcloud_group_activity a
  INNER JOIN book_group_classify c ON a.book_group_classify_id = c.id AND c.is_delete = 0
  INNER JOIN book_group_qrcode b on c.id = b.classify_id
  LEFT JOIN book_group g ON g.id = c.book_group_id
  WHERE
  a.is_delete = 0 AND a.is_show = 1 AND IFNULL(b.is_delete,0) = 0
  and c.city_code = #{cityCode}
  and a.group_type != 1
      <choose>
          <when test="agentId != null">
              and a.agent_id = #{agentId}
          </when>
          <otherwise>
              and a.agent_id = 0
          </otherwise>
      </choose>
  GROUP BY a.id
  ORDER BY a.id DESC
  </select>

    <select id="getByActivityId" resultType="com.pcloud.book.skill.facade.response.QueryGroupActivityResponseVO" parameterType="long" >
    SELECT
    a.id,
    a.`name`,
    a.description as `desc`,
    a.join_type AS joinType,
    a.book_group_classify_id AS bookGroupClassifyId,
    a.pro_label_id AS proLabelId,
    a.dep_label_id AS depLabelId,
    a.pur_label_id AS purLabelId,
    b.classify AS classifyName,
    a.first_classify AS firstClassify,
    a.second_classify AS secondClassify,
    a.third_classify as thirdClassify,
    a.grade_label_id AS gradeLabelId,
    a.subject_label_id AS subjectLabelId,
    a.number,
    a.group_extLink as groupExtLink,
    a.group_type as groupType,
    is_show AS isShow
    FROM
    pcloud_group_activity a left join book_group_classify b on a.book_group_classify_id = b.id
    WHERE
    a.id = #{id}
    </select>

    <select id="getGroupClassifyByIds4Record" resultType="com.pcloud.book.applet.dto.GroupActivity4AppletDTO">
    SELECT
    c.id,
    c.classify as `name`,
    c.classify_introduce AS `desc`,
    c.price AS price,
    c.classify AS groupName,
    b.user_number userNumber,
    b.classify_id classifyId,
    c.book_group_id bookGroupId,
    'GROUP' as serveType,
    '2' as groupType,
    c.id as serveId
    FROM
    book_group_classify c
    LEFT JOIN pcloud_group_activity a ON a.book_group_classify_id = c.id
    LEFT JOIN book_group_qrcode b on b.classify_id = c.id
    where
    IFNULL(b.is_delete,0) = 0
    and
    c.id IN
    <foreach collection="list" item="item" open="(" close=")" separator=",">
        ${item}
    </foreach>
    GROUP BY c.id
    ORDER BY c.id DESC
    </select>

    <select id="getByActivityNumber" parameterType="string" resultMap="BaseResultMap">
        select <include refid="Base_Column_List"/>
        from pcloud_group_activity
        where number = #{number}
        limit 1
    </select>

</mapper>
