<?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.huiju.estateagents.mapper.TaActivityDynamicEnlistMapper">
        <select id="signList" resultType="com.huiju.estateagents.entity.TaActivityDynamicEnlist">

            SELECT
            tade.*,
            IFNULL(tp.nickname,tu.user_name) AS sharePersonName,
            IFNULL(tp.company,tu.org_name)AS orgName
            FROM
            ta_activity_dynamic_enlist tade
            LEFT JOIN ta_share_person_from tspf ON tade.dynamic_id = tspf.target_id
            AND tspf.target_type = 'dynamic_share'
            AND tspf.STATUS = 1
            AND tade.person_id = tspf.person_id and tspf.is_first_time = 1
            LEFT JOIN ta_person tp ON tspf.share_person = tp.person_id AND tspf.share_person_type != 'Realty Consultant'
            LEFT JOIN ta_user tu ON tspf.share_person = tu.user_id AND tspf.share_person_type = 'Realty Consultant'
                <where>
                    tade.dynamic_id = #{dynamicId}
                    AND tade.org_id = #{orgId}

                    <if test="name != null and name !=''">
                        and tade.name like CONCAT('%',#{name}, '%')
                    </if>
                    <if test="isCheckin != null and isCheckin !=''">
                        and tade.is_checkin like CONCAT('%',#{isCheckin}, '%')
                    </if>
                    <if test="phone != null and phone !=''">
                        and tade.phone like CONCAT('%',#{phone}, '%')
                    </if>
                </where>
            group by tade.person_id

        </select>

        <select id="selectEnlistCount" resultType="Integer" >
            select ifnull(sum( attend_num ), 0) from ta_activity_dynamic_enlist where dynamic_id = #{dynamicId} and org_id = #{orgId}
        </select>

    <select id="getTaActivityDynamicEnlistExport" resultType="com.huiju.estateagents.excel.TaActivityDynamicEnlistExport">

        SELECT
        tade.*,
        (CASE tade.is_checkin WHEN 1 THEN '已签到' ELSE '未签到'END) as isCheckin,
        IFNULL(tp.nickname,tu.user_name) AS sharePersonName,
        IFNULL(tp.company,tu.org_name)AS orgName
        FROM
        ta_activity_dynamic_enlist tade
        LEFT JOIN ta_share_person_from tspf ON tade.dynamic_id = tspf.target_id AND tspf.target_type = 'dynamic_share' and tspf.status = 1 and tade.person_id = tspf.person_id and tspf.is_first_time = 1
        LEFT JOIN ta_person tp ON tspf.share_person = tp.person_id AND tspf.share_person_type != 'Realty Consultant'
        LEFT JOIN ta_user tu ON tspf.share_person = tu.user_id AND tspf.share_person_type = 'Realty Consultant'
        <where>
            tade.dynamic_id = #{dynamicId}
            AND tade.org_id = #{orgId}

            <if test="name != null and name !=''">
                and tade.name like CONCAT('%',#{name}, '%')
            </if>
            <if test="isCheckin != null and isCheckin !=''">
                and tade.is_checkin like CONCAT('%',#{isCheckin}, '%')
            </if>
            <if test="phone != null and phone !=''">
                and tade.phone like CONCAT('%',#{phone}, '%')
            </if>
        </where>
        group by tade.person_id
        limit #{pageCode}, #{pageSize}
    </select>
</mapper>
