<?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.branch.mapper.TBranchDemocraticMapper">
    
    <resultMap type="TBranchDemocratic" id="TBranchDemocraticResult">
        <result property="democraticId"    column="democratic_id"    />
        <result property="meetingTime"    column="meeting_time"    />
        <result property="meetingVenue"    column="meeting_venue"    />
        <result property="host"    column="host"    />
        <result property="recorder"    column="recorder"    />
        <result property="participants"    column="participants"    />
        <result property="content"    column="content"    />
        <result property="records"    column="records"    />
        <result property="delFlag"    column="del_flag"    />
        <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="deptId"    column="dept_id"    />
    </resultMap>

    <sql id="selectTBranchDemocraticVo">
        select u.democratic_id, u.meeting_time, u.meeting_venue, u.host, u.recorder, u.participants, u.content, u.records, u.del_flag, u.create_by, u.create_time, u.update_by, u.update_time, u.dept_id from t_branch_democratic u left join sys_dept d on u.dept_id = d.dept_id
    </sql>

    <select id="selectTBranchDemocraticList" parameterType="TBranchDemocratic" resultMap="TBranchDemocraticResult">
        <include refid="selectTBranchDemocraticVo"/>
        <where>  
            <if test="democraticId != null "> and u.democratic_id = #{democraticId}</if>
            <if test="meetingTime != null "> and u.meeting_time = #{meetingTime}</if>
            <if test="meetingVenue != null  and meetingVenue != ''"> and u.meeting_venue like concat(concat('%', #{meetingVenue}), '%')</if>
            <if test="host != null  and host != ''"> and u.host = #{host}</if>
            <if test="recorder != null  and recorder != ''"> and u.recorder = #{recorder}</if>
            <if test="participants != null  and participants != ''"> and u.participants = #{participants})</if>
            <if test="content != null  and content != ''"> and u.content like concat(concat('%', #{content}), '%')</if>
            <if test="records != null  and records != ''"> and u.records like concat(concat('%', #{records}), '%')</if>
            <if test="deptId != null "> and u.dept_id = #{deptId}</if>
            and u.del_flag = 0
        </where>
        <!-- 数据范围过滤 -->
        ${params.dataScope}
    </select>
    
    <select id="selectTBranchDemocraticByDemocraticId" parameterType="Long" resultMap="TBranchDemocraticResult">
        <include refid="selectTBranchDemocraticVo"/>
        where u.democratic_id = #{democraticId}
        and u.del_flag = 0
    </select>
        
    <insert id="insertTBranchDemocratic" parameterType="TBranchDemocratic">
        <selectKey keyProperty="democraticId" resultType="long" order="BEFORE">
            SELECT seq_t_branch_democratic.NEXTVAL as democraticId FROM DUAL
        </selectKey>
        insert into t_branch_democratic
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="democraticId != null">democratic_id,</if>
            <if test="meetingTime != null">meeting_time,</if>
            <if test="meetingVenue != null">meeting_venue,</if>
            <if test="host != null">host,</if>
            <if test="recorder != null">recorder,</if>
            <if test="participants != null">participants,</if>
            <if test="content != null">content,</if>
            <if test="records != null">records,</if>
            <if test="delFlag != null">del_flag,</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="deptId != null">dept_id,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="democraticId != null">#{democraticId},</if>
            <if test="meetingTime != null">#{meetingTime},</if>
            <if test="meetingVenue != null">#{meetingVenue},</if>
            <if test="host != null">#{host},</if>
            <if test="recorder != null">#{recorder},</if>
            <if test="participants != null">#{participants},</if>
            <if test="content != null">#{content},</if>
            <if test="records != null">#{records},</if>
            <if test="delFlag != null">#{delFlag},</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="deptId != null">#{deptId},</if>
         </trim>
    </insert>

    <update id="updateTBranchDemocratic" parameterType="TBranchDemocratic">
        update t_branch_democratic
        <trim prefix="SET" suffixOverrides=",">
            <if test="meetingTime != null">meeting_time = #{meetingTime},</if>
            <if test="meetingVenue != null">meeting_venue = #{meetingVenue},</if>
            <if test="host != null">host = #{host},</if>
            <if test="recorder != null">recorder = #{recorder},</if>
            <if test="participants != null">participants = #{participants},</if>
            <if test="content != null">content = #{content},</if>
            <if test="records != null">records = #{records},</if>
            <if test="delFlag != null">del_flag = #{delFlag},</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="deptId != null">dept_id = #{deptId},</if>
        </trim>
        where democratic_id = #{democraticId}
    </update>

    <update id="deleteTBranchDemocraticByDemocraticId" parameterType="Long">
        update t_branch_democratic set del_flag = 2 where democratic_id = #{democraticId}
    </update>

    <update id="deleteTBranchDemocraticByDemocraticIds" parameterType="String">
        update t_branch_democratic set del_flag = 2 where democratic_id in
        <foreach item="democraticId" collection="array" open="(" separator="," close=")">
            #{democraticId}
        </foreach>
    </update>
</mapper>