<?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.TaLiveActivityMapper">

    <update id="addVisitNum" parameterType="java.lang.String">
        UPDATE ta_live_activity t
        SET t.visit_num = IFNULL( t.visit_num, 0 ) + 1
        WHERE
            t.live_activity_id = #{id}
    </update>

    <update id ="updateLiveActivityStatus" >
        UPDATE ta_live_activity t
            SET t.`status` = -1,
        t.update_date = CURRENT_TIME
        WHERE
        t.org_id = #{orgId}
	    AND t.live_activity_id in
        <foreach collection="taLiveActivityList" item="taLiveActivity" open="(" close=")" separator=",">
            #{taLiveActivity.liveActivityId}
        </foreach>
    </update>

    <select id="selectLiveListByCondition" resultType="com.huiju.estateagents.entity.TaLiveActivity">
     select
        a.building_name,
        b.name as city_name,
        c.user_name as createName,
        d.user_name as updateName,
        t.*
     From
        ta_live_activity t
         left join ta_building a on t.building_id = a.building_id
         LEFT JOIN td_city b on t.city_id = b.id
         left join ta_user c on t.create_user = c.user_id
         left join ta_user d on t.update_user = d.user_id
     where t.org_id = #{orgId} and t.status != -1
         <if test="status != null">
             and t.status = #{status}
         </if>
         <if test="liveActivityTitle != null and liveActivityTitle != ''">
             and t.live_Activity_Title like CONCAT('%', #{liveActivityTitle}, '%')
         </if>
         <if test="cityId != null and cityId != ''">
             and t.city_id = #{cityId}
         </if>
         <choose>
             <when test = 'source == 2'>
                 <if test="buildingId == null or buildingId == ''">
                     and t.building_id is null
                 </if>
             </when>
             <otherwise>
                 <if test="buildingId != null and buildingId != ''">
                     and t.building_id = #{buildingId}
                 </if>
             </otherwise>
         </choose>
        <if test="personBuildingList != null and personBuildingList.size > 0">
            AND (t.building_id in
            <foreach collection="personBuildingList" item="personBuilding" open="(" close=")" separator=",">
                #{personBuilding.buildingId}
            </foreach>
            or t.create_user = #{userId})
        </if>
            order by t.weight desc
    </select>
    <select id="getDetailById" resultType="com.huiju.estateagents.entity.TaLiveActivity">
        select t.*,a.live_plat_name as liveAppName From ta_live_activity t
        left join td_live_dict a on t.live_app = a.id
        where t.live_activity_id = #{id}
    </select>

</mapper>
