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

    <resultMap type="com.willalp.event.domain.HsActivityAppoint" id="HsActivityAppointResult">
        <result property="id" column="id"/>
        <result property="activityTime" column="activity_time"/>
        <result property="appointeeName" column="appointee_name"/>
        <result property="appointeePhone" column="appointee_phone"/>
        <result property="appointmentTime" column="appointment_time"/>
        <result property="activityId" column="activity_id"/>
        <result property="remark" column="remark"/>
        <result property="operation" column="operation"/>
        <result property="createTime" column="create_time"/>
        <result property="createBy" column="create_by"/>
        <result property="updateTime" column="update_time"/>
        <result property="updateBy" column="update_by"/>
        <result property="isDelete" column="is_delete"/>
    </resultMap>

    <sql id="selectHsActivityAppointVo">
        select haa.id,
               he.event_name,
               he.event_start_time,
               he.event_end_time,
               hai.project_name,
               haa.activity_time,
               haa.appointee_name,
               haa.appointee_phone,
               haa.appointment_time,
               haa.activity_id,
               haa.remark,
               haa.operation,
               haa.create_time,
               haa.create_by,
               haa.update_time,
               haa.update_by,
               haa.is_delete
        from hs_activity_appoint haa
                 left join hs_event he on haa.activity_id = he.id
                 left join hs_associations_info hai on hai.id = he.activity_type_id
    </sql>

    <select id="selectHsActivityAppointList" parameterType="HsActivityAppoint" resultMap="HsActivityAppointResult">
        <include refid="selectHsActivityAppointVo"/>
        <where>
            haa.is_delete = 0
            <if test="activityTime != null ">
                and activity_time = #{activityTime}
            </if>
            <if test="appointeeName != null  and appointeeName != ''">
                and appointee_name like concat('%', #{appointeeName}, '%')
            </if>
            <if test="appointeePhone != null  and appointeePhone != ''">
                and appointee_phone like concat('%', #{appointeePhone}, '%')
            </if>
            <if test="appointmentTime != null ">
                and SUBSTR( appointment_time, 1, 10 ) = SUBSTR(#{appointmentTime} , 1, 10 )
            </if>
            <if test="activityId != null ">
                and haa.activity_id = #{activityId}
            </if>
        </where>
    </select>
    <select id="appGetRecord" resultType="com.willalp.event.domain.vo.AppActivityAppointRecordVo">
        select haa.id              id,
               he.id               eventId,
               he.event_name       eventName,
               he.event_start_time eventTime,
               hai.project_name    eventType,
               haa.create_time
        from hs_activity_appoint haa
                 left join hs_event he on haa.activity_id = he.id
                 left join hs_associations_info hai on hai.id = he.activity_type_id
        WHERE haa.is_delete = 0
          AND haa.create_by = #{userCode}
    </select>
</mapper>
