<?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.TBranchActivityNoticeMapper">
    
    <resultMap type="TBranchActivityNotice" id="TBranchActivityNoticeResult">
        <result property="noticeId"    column="notice_id"    />
        <result property="contactLeader"    column="contact_leader"    />
        <result property="activityTime"    column="activity_time"    />
        <result property="activityVenue"    column="activity_venue"    />
        <result property="activityContent"    column="activity_content"    />
        <result property="leaderAttendance"    column="leader_attendance"    />
        <result property="remarks"    column="remarks"    />
        <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="selectTBranchActivityNoticeVo">
        select u.notice_id, u.contact_leader, u.activity_time, u.activity_venue, u.activity_content, u.leader_attendance, u.remarks, u.del_flag, u.create_by, u.create_time, u.update_by, u.update_time, u.dept_id from t_branch_activity_notice u left join sys_dept d on u.dept_id = d.dept_id
    </sql>

    <select id="selectTBranchActivityNoticeList" parameterType="TBranchActivityNotice" resultMap="TBranchActivityNoticeResult">
        <include refid="selectTBranchActivityNoticeVo"/>
        <where>  
            <if test="noticeId != null "> and u.notice_id = #{noticeId}</if>
            <if test="contactLeader != null  and contactLeader != ''"> and u.contact_leader = #{contactLeader}</if>
            <if test="activityTime != null "> and u.activity_time = #{activityTime}</if>
            <if test="activityVenue != null  and activityVenue != ''"> and u.activity_venue = #{activityVenue}</if>
            <if test="activityContent != null  and activityContent != ''"> and u.activity_content like concat(concat('%', #{activityContent}), '%')</if>
            <if test="leaderAttendance != null  and leaderAttendance != ''"> and u.leader_attendance like concat(concat('%', #{leaderAttendance}), '%')</if>
            <if test="remarks != null  and remarks != ''"> and u.remarks like concat(concat('%', #{remarks}), '%')</if>
            <if test="deptId != null "> and u.dept_id = #{deptId}</if>
            and u.del_flag = 0
        </where>
        <!-- 数据范围过滤 -->
        ${params.dataScope}
    </select>
    
    <select id="selectTBranchActivityNoticeByNoticeId" parameterType="Long" resultMap="TBranchActivityNoticeResult">
        <include refid="selectTBranchActivityNoticeVo"/>
        where u.notice_id = #{noticeId}
        and u.del_flag = 0
    </select>
        
    <insert id="insertTBranchActivityNotice" parameterType="TBranchActivityNotice" useGeneratedKeys="true" keyProperty="noticeId">
        <selectKey keyProperty="noticeId" resultType="long" order="BEFORE">
            SELECT seq_t_branch_activity_notice.NEXTVAL as noticeId FROM DUAL
        </selectKey>
        insert into t_branch_activity_notice
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="noticeId != null">notice_id,</if>
            <if test="contactLeader != null">contact_leader,</if>
            <if test="activityTime != null">activity_time,</if>
            <if test="activityVenue != null">activity_venue,</if>
            <if test="activityContent != null">activity_content,</if>
            <if test="leaderAttendance != null">leader_attendance,</if>
            <if test="remarks != null">remarks,</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="noticeId != null">#{noticeId},</if>
            <if test="contactLeader != null">#{contactLeader},</if>
            <if test="activityTime != null">#{activityTime},</if>
            <if test="activityVenue != null">#{activityVenue},</if>
            <if test="activityContent != null">#{activityContent},</if>
            <if test="leaderAttendance != null">#{leaderAttendance},</if>
            <if test="remarks != null">#{remarks},</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="updateTBranchActivityNotice" parameterType="TBranchActivityNotice">
        update t_branch_activity_notice
        <trim prefix="SET" suffixOverrides=",">
            <if test="contactLeader != null">contact_leader = #{contactLeader},</if>
            <if test="activityTime != null">activity_time = #{activityTime},</if>
            <if test="activityTime == null">activity_time = null,</if>
            <if test="activityVenue != null">activity_venue = #{activityVenue},</if>
            <if test="activityContent != null">activity_content = #{activityContent},</if>
            <if test="leaderAttendance != null">leader_attendance = #{leaderAttendance},</if>
            <if test="remarks != null">remarks = #{remarks},</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 notice_id = #{noticeId}
    </update>

    <update id="deleteTBranchActivityNoticeByNoticeId" parameterType="Long">
        update t_branch_activity_notice set del_flag = 2 where notice_id = #{noticeId}
    </update>

    <update id="deleteTBranchActivityNoticeByNoticeIds" parameterType="String">
        update t_branch_activity_notice set del_flag = 2 where notice_id in
        <foreach item="noticeId" collection="array" open="(" separator="," close=")">
            #{noticeId}
        </foreach>
    </update>
</mapper>