<?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.willalp.event.mapper.HsEventMapper">

    <resultMap type="com.willalp.event.domain.HsEvent" id="HsEventResult">
        <result property="id" column="id"/>
        <result property="eventNo" column="event_no"/>
        <result property="eventName" column="event_name"/>
        <result property="startTime" column="start_time"/>
        <result property="banCancelSubscribeTimeLimit" column="ban_cancel_subscribe_time_limit"/>
        <result property="eventTime" column="event_time"/>
        <result property="nowNum" column="now_num"/>
        <result property="limitNum" column="limit_num"/>
        <result property="eventType" column="event_type"/>
        <result property="endTime" column="end_time"/>
        <result property="howLongRemind" column="how_long_remind"/>
        <result property="eventPlace" column="event_place"/>
        <result property="eventStatus" column="event_status"/>
        <result property="eventDescribe" column="event_describe"/>
        <result property="eventStartTime" column="event_start_time"/>
        <result property="isDelete" column="is_delete"/>
        <result property="createBy" column="create_by"/>
        <result property="eventEndTime" column="event_end_time"/>
        <result property="createTime" column="create_time"/>
        <result property="updateBy" column="update_by"/>
        <result property="updateTime" column="update_time"/>
        <result property="activityTypeId" column="activity_type_id"/>
        <result property="remark" column="remark"/>
    </resultMap>

    <sql id="selectHsEventVo">
        select id,
               now_num,
               limit_num,
               event_start_time,
               event_end_time,
               how_long_remind,
               ban_cancel_subscribe_time_limit,
               event_no,
               event_name,
               start_time,
               event_time,
               event_type,
               event_place,
               end_time,
               event_describe,
               activity_type_id,
               event_status,
               is_delete,
               create_by,
               create_time,
               update_by,
               update_time,
               remark
        from hs_event
    </sql>
    <select id="selectHsEventList" parameterType="HsEvent" resultMap="HsEventResult">
        <include refid="selectHsEventVo"/>
        <where>
            is_delete = 0
            <if test="eventNo != null  and eventNo != ''">
                and event_no like concat('%', #{eventNo}, '%')
            </if>
            <if test="eventName != null  and eventName != ''">
                and event_name like concat('%', #{eventName}, '%')
            </if>
            <if test="eventTime != null ">
                and event_time like concat('%', #{eventTime}, '%')
            </if>
            <if test="eventType != null  and eventType != ''">
                and event_type = #{eventType}
            </if>
            <if test="eventPlace != null  and eventPlace != ''">
                and event_place = #{eventPlace}
            </if>
            <if test="eventDescribe != null  and eventDescribe != ''">
                and event_describe = #{eventDescribe}
            </if>
            <if test="eventStatus != null  and eventStatus != ''">
                and event_status = #{eventStatus}
            </if>
            <if test="isDelete != null ">
                and is_delete = #{isDelete}
            </if>
        </where>
    </select>

    <select id="getNowEventList" resultType="com.willalp.event.domain.HsEvent">
        <include refid="selectHsEventVo"/>
        WHERE
        is_delete = 0
        AND event_status = '2'
        AND event_start_time &lt; NOW()
        AND event_end_time &gt; NOW()
    </select>

    <select id="getFormerlyEventList" resultType="com.willalp.event.domain.HsEvent">
        <include refid="selectHsEventVo"/>
        WHERE
        is_delete = 0
        AND event_status = '3'
        AND event_end_time &lt; NOW()
    </select>
    <select id="appGetEvents" resultType="com.willalp.event.domain.HsEvent">
        SELECT he.id,
               limit_num,
               event_start_time,
               event_end_time,
               hcdp.place_name    event_place,
               hcdp.place_site    eventPlaceSite,
               hcdp.place_img_url eventImgUrl,
               he.now_num         alreadyHave
        FROM hs_event he
                 LEFT JOIN hs_canteen_dining_place hcdp ON he.event_place = hcdp.place_id
            AND hcdp.place_type = 4
            AND hcdp.is_delete = 0
        WHERE he.is_delete = 0
          AND he.activity_type_id = #{associationsInfoId}
          AND he.event_status = '2'
    </select>
    <select id="appGetMoreById" resultType="com.willalp.event.domain.vo.ClubActivityMoreVo">
        SELECT he.id,
               limit_num,
               event_name,
               event_start_time,
               event_end_time,
               hcdp.place_name       eventPlace,
               hcdp.place_site       eventPlaceSite,
               hcdp.details          placeMore,
               hai.project_name      eventType,
               hai.associations_name clubName,
               hai.mien
        FROM hs_event he
                 LEFT JOIN hs_canteen_dining_place hcdp ON he.event_place = hcdp.place_id
                 LEFT JOIN hs_associations_info hai ON hai.id = he.activity_type_id
        WHERE he.id = #{id}
          AND he.is_delete = 0
          AND hai.is_delete = 0
          AND hcdp.is_delete = 0
    </select>
    <update id="eventAppointOrder">
        update hs_event
        set now_num = now_num + 1
        WHERE is_delete = 0
          AND id = #{eventId}
          AND now_num &lt; limit_num
    </update>
    <update id="eventAppointBack">
        update hs_event
        set now_num = now_num - 1
        WHERE is_delete = 0
          AND id = #{eventId}
          AND now_num &gt; 0
    </update>
</mapper>

