<?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.ruoyi.system.mapper.ZxConferenceMapper">
    
    <resultMap type="ZxConference" id="ZxConferenceResult">
        <result property="conferenceId"    column="conference_id"    />
        <result property="userId"    column="user_id"    />
        <result property="conferenceTitle"    column="conference_title"    />
        <result property="conferenceDate"    column="conference_date"    />
        <result property="conferenceTime"    column="conference_time"    />
        <result property="conferenceAddress"    column="conference_address"    />
        <result property="publishTime"    column="publish_time"    />
        <result property="conferenceType"    column="conference_type"    />
        <result property="conferenceQr"    column="conference_qr"    />
        <result property="createBy"    column="create_by"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateBy"    column="update_by"    />
        <result property="updateTime"    column="update_time"    />
        <result property="remark"    column="remark"    />
    </resultMap>

    <resultMap id="ZxConferenceZxConferenceUserResult" type="ZxConference" extends="ZxConferenceResult">
        <collection property="zxConferenceUserList" notNullColumn="sub_conference_id" javaType="java.util.List" resultMap="ZxConferenceUserResult" />
        <collection property="zxFjList" notNullColumn="fj_source_id" javaType="java.util.List" resultMap="ZxFjResult" />
    </resultMap>

    <resultMap type="ZxConferenceUser" id="ZxConferenceUserResult">
        <result property="conferenceId"    column="sub_conference_id"    />
        <result property="userId"    column="sub_user_id"    />
        <result property="userName"    column="sub_user_name"    />
        <result property="postName"    column="sub_post_name"    />
        <result property="userLevel"    column="sub_user_level"    />
        <result property="parentGrade"    column="sub_parent_grade"    />
        <result property="replyTime"    column="sub_reply_time"    />
        <result property="isJoin"    column="sub_is_join"    />
        <result property="leaveType"    column="sub_leave_type"    />
        <result property="leaveReason"    column="sub_leave_reason"    />
        <result property="signIn"    column="sub_sign_in"    />
        <result property="createBy"    column="sub_create_by"    />
        <result property="createTime"    column="sub_create_time"    />
        <result property="updateBy"    column="sub_update_by"    />
        <result property="updateTime"    column="sub_update_time"    />
        <result property="remark"    column="sub_remark"    />
    </resultMap>

    <resultMap type="ZxFj" id="ZxFjResult">
        <result property="id"    column="fj_id"    />
        <result property="mainId"    column="fj_main_id"    />
        <result property="sourceId"    column="fj_source_id"    />
        <result property="name"    column="fj_name"    />
        <result property="url"    column="fj_url"    />
        <result property="type"    column="fj_type"    />
        <result property="stytle"    column="fj_stytle"    />
        <result property="remark"    column="fj_remark"    />
    </resultMap>

    <sql id="selectZxConferenceVo">
        select conference_id, conference_title, conference_date,conference_type, conference_time, conference_address, publish_time,conference_qr, create_by, create_time, update_by, update_time, remark from zx_conference
    </sql>

    <select id="selectZxConferenceList" parameterType="ZxConference" resultMap="ZxConferenceZxConferenceUserResult">
        select a.conference_id, a.conference_title, a.conference_date,a.conference_type, a.conference_time, a.conference_address, a.publish_time,a.conference_qr, a.create_by, a.create_time, a.update_by, a.update_time, a.remark,
        b.conference_id as sub_conference_id, b.user_id as sub_user_id, b.user_name as sub_user_name, b.post_name as sub_post_name, b.user_level as sub_user_level, b.reply_time as sub_reply_time, b.is_join as sub_is_join, b.leave_type as sub_leave_type, b.parent_grade as sub_parent_grade,b.leave_reason as sub_leave_reason,b.sign_in as sub_sign_in, b.create_by as sub_create_by, b.create_time as sub_create_time, b.update_by as sub_update_by, b.update_time as sub_update_time, b.remark as sub_remark,
        f.id as fj_id,f.main_id as fj_main_id, f.source_id as fj_source_id, f.name as fj_name, f.url as fj_url, f.type as fj_type,f.stytle as fj_stytle
        from zx_conference a
        left join zx_conference_user b on b.conference_id = a.conference_id
        left join zx_fj f on f.source_id = a.conference_id
        <where>
            f.type = '4'
            <if test="conferenceTitle != null  and conferenceTitle != ''"> and a.conference_title like concat('%', #{conferenceTitle}, '%')</if>
            <if test="conferenceDate != null "> and a.conference_date = #{conferenceDate}</if>
            <if test="conferenceTime != null  and conferenceTime != ''"> and a.conference_time = #{conferenceTime}</if>
            <if test="conferenceAddress != null  and conferenceAddress != ''"> and a.conference_address = #{conferenceAddress}</if>
            <if test="publishTime != null "> and a.publish_time = #{publishTime}</if>
            <if test="userId != null "> and b.user_id = #{userId}</if>
            <if test="year != null and year != ''"><!-- 开始时间检索 -->
                AND date_format(a.publish_time,'%Y') = #{year}
            </if>
        </where>
        order  by a.publish_time DESC
    </select>
    
    <select id="selectZxConferenceByConferenceId" parameterType="Long" resultMap="ZxConferenceZxConferenceUserResult">
        select a.conference_id, a.conference_title,a.conference_qr,a.conference_type, a.conference_date, a.conference_time, a.conference_address, a.publish_time, a.create_by, a.create_time, a.update_by, a.update_time, a.remark,
 b.conference_id as sub_conference_id,b.parent_grade as sub_parent_grade, b.user_id as sub_user_id, b.user_name as sub_user_name, b.post_name as sub_post_name, b.user_level as sub_user_level, b.reply_time as sub_reply_time, b.is_join as sub_is_join, b.leave_type as sub_leave_type, b.leave_reason as sub_leave_reason,b.sign_in as sub_sign_in, b.create_by as sub_create_by, b.create_time as sub_create_time, b.update_by as sub_update_by, b.update_time as sub_update_time, b.remark as sub_remark,
        f.id as fj_id,f.main_id as fj_main_id, f.source_id as fj_source_id, f.name as fj_name, f.url as fj_url, f.type as fj_type,f.stytle as fj_stytle
        from zx_conference a
        left join zx_conference_user b on b.conference_id = a.conference_id
        left join zx_fj f on f.source_id = a.conference_id
        where a.conference_id = #{conferenceId} and f.type = '4'
    </select>
    <select id="selectZxConferenceUserByConferenceId" resultMap="ZxConferenceUserResult">
        select b.conference_id as sub_conference_id,b.parent_grade as sub_parent_grade, b.user_id as sub_user_id, b.user_name as sub_user_name, b.post_name as sub_post_name, b.user_level as sub_user_level, b.reply_time as sub_reply_time, b.is_join as sub_is_join, b.leave_type as sub_leave_type, b.leave_reason as sub_leave_reason,b.sign_in as sub_sign_in, b.create_by as sub_create_by, b.create_time as sub_create_time, b.update_by as sub_update_by, b.update_time as sub_update_time, b.remark as sub_remark
        from  zx_conference_user b
        where b.conference_id = #{conferenceId}
    </select>
    <select id="selectZxConferenceUser" parameterType = "zxConferenceUser" resultMap="ZxConferenceUserResult">
        select b.conference_id as sub_conference_id,b.parent_grade as sub_parent_grade, b.user_id as sub_user_id, b.user_name as sub_user_name, b.post_name as sub_post_name, b.user_level as sub_user_level, b.reply_time as sub_reply_time, b.is_join as sub_is_join, b.leave_type as sub_leave_type, b.leave_reason as sub_leave_reason,b.sign_in as sub_sign_in, b.create_by as sub_create_by, b.create_time as sub_create_time, b.update_by as sub_update_by, b.update_time as sub_update_time, b.remark as sub_remark
        from  zx_conference_user b
        <where>
            b.conference_id = #{conferenceId}
            <if test="userName != null  and userName != ''"> and b.user_name = #{userName}</if>
        </where>
    </select>
    <select id="selectZxConferenceInfo" parameterType="ZxConference" resultMap="ZxConferenceZxConferenceUserResult">
        select a.conference_id, a.conference_title,a.conference_qr,a.conference_type, a.conference_date, a.conference_time, a.conference_address, a.publish_time, a.create_by, a.create_time, a.update_by, a.update_time, a.remark,
               b.conference_id as sub_conference_id,b.parent_grade as sub_parent_grade, b.user_id as sub_user_id, b.user_name as sub_user_name, b.post_name as sub_post_name, b.user_level as sub_user_level, b.reply_time as sub_reply_time, b.is_join as sub_is_join, b.leave_type as sub_leave_type, b.leave_reason as sub_leave_reason,b.sign_in as sub_sign_in, b.create_by as sub_create_by, b.create_time as sub_create_time, b.update_by as sub_update_by, b.update_time as sub_update_time, b.remark as sub_remark,
               f.id as fj_id,f.main_id as fj_main_id, f.source_id as fj_source_id, f.name as fj_name, f.url as fj_url, f.type as fj_type,f.stytle as fj_stytle
        from zx_conference a
                 left join zx_conference_user b on b.conference_id = a.conference_id
                 left join zx_fj f on f.source_id = a.conference_id
        <where>
            f.type = '4'
           and a.conference_id = #{conferenceId}
            <if test="userId != null "> and b.user_id = #{userId}</if>
        </where>
    </select>

    <insert id="insertZxConference" parameterType="ZxConference" useGeneratedKeys="true" keyProperty="conferenceId">
        insert into zx_conference
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="conferenceTitle != null and conferenceTitle != ''">conference_title,</if>
            <if test="conferenceDate != null">conference_date,</if>
            <if test="conferenceTime != null">conference_time,</if>
            <if test="conferenceAddress != null and conferenceAddress != ''">conference_address,</if>
            <if test="publishTime != null">publish_time,</if>
            <if test="conferenceType != null">conference_type,</if>
            <if test="conferenceQr != null">conference_qr,</if>
            <if test="createBy != null">create_by,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="remark != null">remark,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="conferenceTitle != null and conferenceTitle != ''">#{conferenceTitle},</if>
            <if test="conferenceDate != null">#{conferenceDate},</if>
            <if test="conferenceTime != null">#{conferenceTime},</if>
            <if test="conferenceAddress != null and conferenceAddress != ''">#{conferenceAddress},</if>
            <if test="publishTime != null">#{publishTime},</if>
            <if test="conferenceType != null">#{conferenceType},</if>
            <if test="conferenceQr != null">#{conferenceQr},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="remark != null">#{remark},</if>
         </trim>
    </insert>

    <update id="updateZxConference" parameterType="ZxConference">
        update zx_conference
        <trim prefix="SET" suffixOverrides=",">
            <if test="conferenceTitle != null and conferenceTitle != ''">conference_title = #{conferenceTitle},</if>
            <if test="conferenceDate != null">conference_date = #{conferenceDate},</if>
            <if test="conferenceTime != null">conference_time = #{conferenceTime},</if>
            <if test="conferenceAddress != null and conferenceAddress != ''">conference_address = #{conferenceAddress},</if>
            <if test="publishTime != null">publish_time = #{publishTime},</if>
            <if test="conferenceType != null">conference_type = #{conferenceType},</if>
            <if test="conferenceQr != null">conference_qr = #{conferenceQr},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="remark != null">remark = #{remark},</if>
        </trim>
        where conference_id = #{conferenceId}
    </update>
    <update id="updateReply" parameterType="zxConferenceUser">
        update zx_conference_user
        <trim prefix="SET" suffixOverrides=",">
            <if test="replyTime != null">reply_time = #{replyTime},</if>
            <if test="isJoin != null and isJoin != ''">is_join = #{isJoin},</if>
            <if test="leaveType != null and leaveType != ''">leave_type = #{leaveType},</if>
            <if test="leaveReason != null and leaveReason != ''">leave_reason = #{leaveReason},</if>
            <if test="signIn != null and signIn != ''">sign_in = #{signIn},</if>
        </trim>
        where conference_id = #{conferenceId} and user_id = #{userId}
    </update>
    <update id="signIn">
        update zx_conference_user set sign_in = #{signIn}
        where conference_id = #{conferenceId} and user_id = #{userId}
    </update>

    <delete id="deleteZxConferenceByConferenceId" parameterType="Long">
        delete from zx_conference where conference_id = #{conferenceId}
    </delete>

    <delete id="deleteZxConferenceByConferenceIds" parameterType="String">
        delete from zx_conference where conference_id in 
        <foreach item="conferenceId" collection="array" open="(" separator="," close=")">
            #{conferenceId}
        </foreach>
    </delete>
    
    <delete id="deleteZxConferenceUserByConferenceIds" parameterType="String">
        delete from zx_conference_user where conference_id in 
        <foreach item="conferenceId" collection="array" open="(" separator="," close=")">
            #{conferenceId}
        </foreach>
    </delete>

    <delete id="deleteZxConferenceUserByConferenceId" parameterType="Long">
        delete from zx_conference_user where conference_id = #{conferenceId}
    </delete>

    <insert id="batchZxConferenceUser">
        insert into zx_conference_user( conference_id, user_id, user_name, post_name, user_level, reply_time, is_join, leave_type,parent_grade, leave_reason, sign_in ,create_by, create_time, update_by, update_time, remark) values
		<foreach item="item" index="index" collection="list" separator=",">
            ( #{item.conferenceId}, #{item.userId}, #{item.userName}, #{item.postName}, #{item.userLevel}, #{item.replyTime}, #{item.isJoin}, #{item.leaveType},#{item.parentGrade}, #{item.leaveReason},#{item.signIn}, #{item.createBy}, sysdate(), #{item.updateBy}, #{item.updateTime}, #{item.remark})
        </foreach>
    </insert>
</mapper>