<?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.srs.staff.mapper.SrsStaffOneStopCommunityActivitiesMapper">

    <resultMap type="SrsStaffOneStopCommunityActivities" id="SrsStaffOneStopCommunityActivitiesResult">
        <result property="activityId" column="activity_id"/>
        <result property="activityTheme" column="activity_theme"/>
        <result property="galleryful" column="galleryful"/>
        <result property="activityPlace" column="activity_place"/>
        <result property="publishStatus" column="publish_status"/>
        <result property="activityStatus" column="activity_status"/>
        <result property="signUpStartTime" column="sign_up_start_time"/>
        <result property="signUpEndTime" column="sign_up_end_time"/>
        <result property="activityStartTime" column="activity_start_time"/>
        <result property="activityEndTime" column="activity_end_time"/>
        <result property="specificRequirements" column="specific_requirements"/>
        <result property="signUpPrompt" column="sign_up_prompt"/>
        <result property="feedback" column="feedback"/>
        <result property="eventPromoter" column="event_promoter"/>
        <result property="feedbackImgs" column="feedback_imgs"/>
        <result property="activityImgs" column="activity_imgs"/>
        <result property="activePackage" column="active_package"/>
        <collection property="oneStopRegistrationRecords" column="{activityId=activity_id}"
                    javaType="java.util.ArrayList" select="selectSrsStaffOneStopRegistrationRecordByActivityId"/>
    </resultMap>

    <resultMap type="SrsStaffOneStopRegistrationRecord" id="SrsStaffOneStopRegistrationRecordResult">
        <result property="recordId" column="record_id"/>
        <result property="activityId" column="activity_id"/>
        <result property="activityTheme" column="activity_theme"/>
        <result property="initiator" column="initiator"/>
        <result property="applicant" column="applicant"/>
        <result property="registrationTime" column="registration_time"/>
        <result property="auditStatus" column="audit_status"/>
        <result property="jobNumber" column="job_number"/>
    </resultMap>

    <select id="selectSrsStaffOneStopRegistrationRecordByActivityId" resultMap="SrsStaffOneStopRegistrationRecordResult">
        select *
        from srs_staff_one_stop_registration_record
        <where>
            <if test="activityId != null">
                and activity_id = #{activityId}
            </if>
        </where>
    </select>

    <sql id="selectSrsStaffOneStopCommunityActivitiesVo">
        select activity_id,
               activity_theme,
               galleryful,
               activity_place,
               publish_status,
               activity_status,
               sign_up_start_time,
               sign_up_end_time,
               activity_start_time,
               activity_end_time,
               specific_requirements,
               sign_up_prompt,
               feedback,
               event_promoter,
               feedback_imgs,
               activity_imgs,
               active_package
        from srs_staff_one_stop_community_activities
    </sql>

    <select id="selectSrsStaffOneStopCommunityActivitiesList" parameterType="SrsStaffOneStopCommunityActivities"
            resultMap="SrsStaffOneStopCommunityActivitiesResult">
        <include refid="selectSrsStaffOneStopCommunityActivitiesVo"/>
        <where>
            <if test="activityTheme != null  and activityTheme != ''">
                and activity_theme like concat('%', #{activityTheme}, '%')
            </if>
            <if test="galleryful != null">
                and galleryful = #{galleryful}
            </if>
            <if test="signUpStartTime != null and signUpEndTime != null">
                and sign_up_start_time &gt;= #{signUpStartTime}
                and sign_up_end_time &lt;= #{signUpEndTime}
            </if>
            <if test="activityStartTime != null and activityEndTime != null">
                and activity_start_time &gt;= #{activityStartTime}
                and activity_end_time &lt;= #{activityEndTime}
            </if>
            <if test="activityPlace != null  and activityPlace != ''">
                and activity_place like concat('%', #{activityPlace}, '%')
            </if>
            <if test="publishStatus != null">
                and publish_status = #{publishStatus}
            </if>
            <if test="activityStatus != null">
                and activity_status = #{activityStatus}
            </if>
            <if test="specificRequirements != null  and specificRequirements != ''">
                and specific_requirements = #{specificRequirements}
            </if>
            <if test="signUpPrompt != null  and signUpPrompt != ''">
                and sign_up_prompt = #{signUpPrompt}
            </if>
            <if test="feedback != null  and feedback != ''">
                and feedback = #{feedback}
            </if>
            <if test="eventPromoter != null  and eventPromoter != ''">
                and event_promoter = #{eventPromoter}
            </if>
            <if test="feedbackImgs != null  and feedbackImgs != ''">
                and feedback_imgs = #{feedbackImgs}
            </if>
        </where>
        ORDER BY activity_id desc
    </select>


    <select id="selectSrsStaffOneStopCommunityActivitiesByActivityId" parameterType="Long"
            resultMap="SrsStaffOneStopCommunityActivitiesResult">
        <include refid="selectSrsStaffOneStopCommunityActivitiesVo"/>
        where activity_id = #{activityId}
    </select>

    <insert id="insertSrsStaffOneStopCommunityActivities" parameterType="SrsStaffOneStopCommunityActivities">
        insert into srs_staff_one_stop_community_activities
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="activityId != null">activity_id,</if>
            <if test="activityTheme != null and activityTheme != ''">activity_theme,</if>
            <if test="galleryful != null">galleryful,</if>
            <if test="activityPlace != null and activityPlace != ''">activity_place,</if>
            <if test="publishStatus != null">publish_status,</if>
            <if test="activityStatus != null">activity_status,</if>
            <if test="signUpStartTime != null">sign_up_start_time,</if>
            <if test="signUpEndTime != null">sign_up_end_time,</if>
            <if test="activityStartTime != null">activity_start_time,</if>
            <if test="activityEndTime != null">activity_end_time,</if>
            <if test="specificRequirements != null and specificRequirements != ''">specific_requirements,</if>
            <if test="signUpPrompt != null">sign_up_prompt,</if>
            <if test="feedback != null">feedback,</if>
            <if test="eventPromoter != null">event_promoter,</if>
            <if test="feedbackImgs != null">feedback_imgs,</if>
            <if test="activityImgs != null">activity_imgs,</if>
            <if test="activePackage != null">active_package,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="activityId != null">#{activityId},</if>
            <if test="activityTheme != null and activityTheme != ''">#{activityTheme},</if>
            <if test="galleryful != null">#{galleryful},</if>
            <if test="activityPlace != null and activityPlace != ''">#{activityPlace},</if>
            <if test="publishStatus != null">#{publishStatus},</if>
            <if test="activityStatus != null">#{activityStatus},</if>
            <if test="signUpStartTime != null">#{signUpStartTime},</if>
            <if test="signUpEndTime != null">#{signUpEndTime},</if>
            <if test="activityStartTime != null">#{activityStartTime},</if>
            <if test="activityEndTime != null">#{activityEndTime},</if>
            <if test="specificRequirements != null and specificRequirements != ''">#{specificRequirements},</if>
            <if test="signUpPrompt != null">#{signUpPrompt},</if>
            <if test="feedback != null">#{feedback},</if>
            <if test="eventPromoter != null">#{eventPromoter},</if>
            <if test="feedbackImgs != null">#{feedbackImgs},</if>
            <if test="activityImgs != null">#{activityImgs},</if>
            <if test="activePackage != null">#{activePackage},</if>
        </trim>
    </insert>

    <update id="updateSrsStaffOneStopCommunityActivities" parameterType="SrsStaffOneStopCommunityActivities">
        update srs_staff_one_stop_community_activities
        <trim prefix="SET" suffixOverrides=",">
            <if test="activityTheme != null and activityTheme != ''">activity_theme = #{activityTheme},</if>
            <if test="galleryful != null">galleryful = #{galleryful},</if>
            <if test="activityPlace != null and activityPlace != ''">activity_place = #{activityPlace},</if>
            <if test="publishStatus != null">publish_status = #{publishStatus},</if>
            <if test="activityStatus != null">activity_status = #{activityStatus},</if>
            <if test="signUpStartTime != null">sign_up_start_time = #{signUpStartTime},</if>
            <if test="signUpEndTime != null">sign_up_end_time = #{signUpEndTime},</if>
            <if test="activityStartTime != null">activity_start_time = #{activityStartTime},</if>
            <if test="activityEndTime != null">activity_end_time = #{activityEndTime},</if>
            <if test="specificRequirements != null and specificRequirements != ''">specific_requirements = #{specificRequirements},</if>
            <if test="signUpPrompt != null">sign_up_prompt = #{signUpPrompt},</if>
            <if test="feedback != null">feedback = #{feedback},</if>
            <if test="eventPromoter != null">event_promoter = #{eventPromoter},</if>
            <if test="feedbackImgs != null">feedback_imgs = #{feedbackImgs},</if>
            <if test="activityImgs != null">activity_imgs = #{activityImgs},</if>
            <if test="activePackage != null">active_package = #{activePackage},</if>
        </trim>
        where activity_id = #{activityId}
    </update>

    <delete id="deleteSrsStaffOneStopCommunityActivitiesByActivityId" parameterType="Long">
        delete
        from srs_staff_one_stop_community_activities
        where activity_id = #{activityId}
    </delete>

    <delete id="deleteSrsStaffOneStopCommunityActivitiesByActivityIds" parameterType="String">
        delete from srs_staff_one_stop_community_activities where activity_id in
        <foreach item="activityId" collection="array" open="(" separator="," close=")">
            #{activityId}
        </foreach>
    </delete>
</mapper>
