<?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.supervision.grassrootsregistration.mapper.BdglEvenMapper">

    <resultMap type="BdglEven" id="BdglEvenResult">
        <result property="id"    column="id"    />
        <result property="convokeTime"    column="convoke_time"    />
        <result property="address"    column="address"    />
        <result property="compereId"    column="compere_id"    />
        <result property="joinId"    column="join_id"    />
        <result property="peopleId"    column="people_id"    />
        <result property="title"    column="title"    />
        <result property="contents"    column="contents"    />
        <result property="createtime"    column="createtime"    />
        <result property="updatetime"    column="updatetime"    />
        <result property="unitId"    column="unit_id"    />
        <result property="unitName"    column="unit_name"    />
        <result property="compereRen"    column="compere_ren"    />
        <result property="peopleJiLu"    column="people_ji_lu"    />
        <result property="fileUrl"    column="file_url"    />
        <result property="meetingForm"    column="meeting_form"    />
    </resultMap>

    <sql id="selectBdglEvenVo">
        select id, convoke_time, address, compere_id, join_id, people_id, title, contents, createtime, updatetime, unit_id,unit_name,compere_ren,people_ji_lu,file_url,meeting_form from bdgl_even
    </sql>

    <select id="selectBdglEvenList" parameterType="BdglEven" resultMap="BdglEvenResult">
        select id, convoke_time, address, compere_id, join_id, people_id, title, contents, createtime, updatetime, unit_id,unit_name,compere_ren,people_ji_lu,file_url,meeting_form
        from bdgl_even e left join sys_dept t
        on d.unit_id=t.dept_id
        <where>
            <if test="convokeTime != null "> and e.convoke_time = #{convokeTime}</if>
            <if test="address != null  and address != ''"> and e.address = #{address}</if>
            <if test="compereId != null "> and e.compere_id = #{compereId}</if>
            <if test="joinId != null  and joinId != ''"> and e.join_id = #{joinId}</if>
            <if test="peopleId != null "> and e.people_id = #{peopleId}</if>
            <if test="title != null  and title != ''"> and e.title = #{title}</if>
            <if test="contents != null  and contents != ''"> and e.contents = #{contents}</if>
            <if test="createtime != null  and createtime != ''"> and e.createtime = #{createtime}</if>
            <if test="updatetime != null  and updatetime != ''"> and e.updatetime = #{updatetime}</if>
            <if test="compereRen != null "> and e.compere_ren concat('%',#{compereRen}, '%')</if>
            <if test="peopleJiLu != null "> and e.people_ji_lu concat('%', #{peopleJiLu}, '%')</if>
            <if test="fileUrl != null "> and e.file_url concat('%', #{fileUrl}, '%')</if>
            <if test="meetingForm != null "> and e.meeting_form concat('%', #{meetingForm}, '%')</if>
            and(d.unit_id=#{unitId} or find_in_set(#{unitId}, t.ancestors))
        </where>
        order by e.id desc
    </select>


    <select id="selectBdglEvenLists" parameterType="BdglEven" resultMap="BdglEvenResult">
        select e.id, e.convoke_time, e.address, e.compere_id, e.join_id, e.people_id, e.title, e.contents, e.createtime, e.updatetime, e.unit_id ,e.compere_ren,e.people_ji_lu,e.file_url,e.meeting_form,d.dept_name unit_name   from
        bdgl_even e LEFT JOIN sys_dept d ON e.unit_id = d.dept_id
        <where>
            <if test="unitId!=null">
                and (e.unit_id=#{unitId} or find_in_set(#{unitId}, d.ancestors))
            </if>
            <if test="convokeTime != null "> and e.convoke_time = #{convokeTime}</if>
            <if test="address != null  and address != ''"> and e.address = #{address}</if>
            <if test="compereId != null "> and e.compere_id = #{compereId}</if>
            <if test="joinId != null  and joinId != ''"> and e.join_id = #{joinId}</if>
            <if test="peopleId != null "> and e. people_id = #{peopleId}</if>
            <if test="title != null  and title != ''"> and e.title = #{title}</if>
            <if test="contents != null  and contents != ''"> and e.contents = #{contents}</if>
            <if test="createtime != null  and createtime != ''"> and e.createtime = #{createtime}</if>
            <if test="updatetime != null  and updatetime != ''"> and e.updatetime = #{updatetime}</if>
            <if test="compereRen != null "> and e.compere_ren = #{compereRen}</if>
            <if test="peopleJiLu != null "> and e.people_ji_lu = #{peopleJiLu}</if>
            <if test="fileUrl != null "> and e.file_url = #{fileUrl}</if>
            <if test="meetingForm != null "> and e.meeting_form = #{meetingForm}</if>
            <if test="unitName != null "> and e.unit_name LIKE  concat('%', #{unitName}, '%')</if>

        </where>
        order by e.id desc
    </select>

    <select id="selectBdglEvenById" parameterType="Integer" resultMap="BdglEvenResult">
        <include refid="selectBdglEvenVo"/>
        where id = #{id}
    </select>

    <select id="selectlMeetRecordByunitId" resultType="java.lang.Integer">
        select count(*) from bdgl_even where unit_id = #{unitId} and YEAR(convoke_time)= #{year}
    </select>

    <select id="selectMeetRecordOnUnitList" parameterType="BdglEven" resultMap="BdglEvenResult">
        select id, convoke_time, address, compere_id, join_id, people_id, title, contents, createtime, updatetime, unit_id,unit_name,compere_ren,people_ji_lu,file_url,meeting_form
        from bdgl_even
        <where>
            <if test="unitId != null"> and unit_id = #{unitId}</if>
            <if test="year != null and year != ''"> and YEAR(convoke_time)= #{year}</if>
        </where>
        order by id desc
    </select>

    <insert id="insertBdglEven" parameterType="BdglEven" useGeneratedKeys="true" keyProperty="id">
        insert into bdgl_even
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="convokeTime != null">convoke_time,</if>
            <if test="address != null">address,</if>
            <if test="compereId != null">compere_id,</if>
            <if test="joinId != null">join_id,</if>
            <if test="peopleId != null">people_id,</if>
            <if test="title != null">title,</if>
            <if test="contents != null">contents,</if>
            <if test="createtime != null">createtime,</if>
            <if test="updatetime != null">updatetime,</if>
            <if test="unitId != null">unit_id,</if>
            <if test="unitName != null">unit_name,</if>
            <if test="compereRen != null">compere_ren,</if>
            <if test="peopleJiLu != null">people_ji_lu,</if>
            <if test="fileUrl != null">file_url,</if>
            <if test="meetingForm != null">meeting_form,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="convokeTime != null">#{convokeTime},</if>
            <if test="address != null">#{address},</if>
            <if test="compereId != null">#{compereId},</if>
            <if test="joinId != null">#{joinId},</if>
            <if test="peopleId != null">#{peopleId},</if>
            <if test="title != null">#{title},</if>
            <if test="contents != null">#{contents},</if>
            <if test="createtime != null">#{createtime},</if>
            <if test="updatetime != null">#{updatetime},</if>
            <if test="unitId != null">#{unitId},</if>
            <if test="unitName != null">#{unitName},</if>
            <if test="compereRen != null">#{compereRen},</if>
            <if test="peopleJiLu != null">#{peopleJiLu},</if>
            <if test="fileUrl != null">#{fileUrl},</if>
            <if test="meetingForm != null">#{meetingForm},</if>
         </trim>
    </insert>

    <update id="updateBdglEven" parameterType="BdglEven">
        update bdgl_even
        <trim prefix="SET" suffixOverrides=",">
            <if test="convokeTime != null">convoke_time = #{convokeTime},</if>
            <if test="address != null">address = #{address},</if>
            <if test="compereId != null">compere_id = #{compereId},</if>
            <if test="joinId != null">join_id = #{joinId},</if>
            <if test="peopleId != null">people_id = #{peopleId},</if>
            <if test="title != null">title = #{title},</if>
            <if test="contents != null">contents = #{contents},</if>
            <if test="createtime != null">createtime = #{createtime},</if>
            <if test="updatetime != null">updatetime = #{updatetime},</if>
            <if test="unitId != null">unit_id = #{unitId},</if>
            <if test="compereRen != null">compere_ren = #{compereRen},</if>
            <if test="peopleJiLu != null">people_ji_lu = #{peopleJiLu},</if>
            <if test="fileUrl != null">file_url = #{fileUrl},</if>
            <if test="meetingForm != null">meeting_form = #{meetingForm},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteBdglEvenById" parameterType="Integer">
        delete from bdgl_even where id = #{id}
    </delete>

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