<?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.TBranchActivityMapper">
    
    <resultMap type="TBranchActivity" id="TBranchActivityResult">
        <result property="activityId"    column="activity_id"    />
        <result property="activityTheme"    column="activity_theme"    />
        <result property="activityGoal"    column="activity_goal"    />
        <result property="activityAttendees"    column="activity_attendees"    />
        <result property="activityDate"    column="activity_date"    />
        <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="selectTBranchActivityVo">
        select u.activity_id, u.activity_theme, u.activity_goal, u.activity_attendees, u.activity_date, u.remarks, u.del_flag, u.create_by, u.create_time, u.update_by, u.update_time, u.dept_id from t_branch_activity u left join sys_dept d on u.dept_id = d.dept_id
    </sql>

    <select id="selectTBranchActivityList" parameterType="TBranchActivity" resultMap="TBranchActivityResult">
        <include refid="selectTBranchActivityVo"/>
        <where>  
            <if test="activityId != null "> and u.activity_id = #{activityId}</if>
            <if test="activityTheme != null  and activityTheme != ''"> and u.activity_theme like concat(concat('%', #{activityTheme}), '%')</if>
            <if test="activityGoal != null  and activityGoal != ''"> and u.activity_goal like concat(concat('%', #{activityGoal}), '%')</if>
            <if test="activityAttendees != null  and activityAttendees != ''"> and u.activity_attendees = #{activityAttendees}</if>
            <if test="activityDate != null "> and u.activity_date = #{activityDate}</if>
            <if test="remarks != null  and remarks != ''"> and u.remarks = #{remarks}</if>
            <if test="deptId != null "> and u.dept_id = #{deptId}</if>
            and u.del_flag = 0
        </where>
        <!-- 数据范围过滤 -->
        ${params.dataScope}
    </select>
    
    <select id="selectTBranchActivityByActivityId" parameterType="Long" resultMap="TBranchActivityResult">
        <include refid="selectTBranchActivityVo"/>
        where u.activity_id = #{activityId}
        and u.del_flag = 0
    </select>
        
    <insert id="insertTBranchActivity" parameterType="TBranchActivity">
        <selectKey keyProperty="activityId" resultType="long" order="BEFORE">
            SELECT seq_t_branch_activity.NEXTVAL as activityId FROM DUAL
        </selectKey>
        insert into t_branch_activity
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="activityId != null">activity_id,</if>
            <if test="activityTheme != null and activityTheme != ''">activity_theme,</if>
            <if test="activityGoal != null and activityGoal != ''">activity_goal,</if>
            <if test="activityAttendees != null">activity_attendees,</if>
            <if test="activityDate != null">activity_date,</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="activityId != null">#{activityId},</if>
            <if test="activityTheme != null and activityTheme != ''">#{activityTheme},</if>
            <if test="activityGoal != null and activityGoal != ''">#{activityGoal},</if>
            <if test="activityAttendees != null">#{activityAttendees},</if>
            <if test="activityDate != null">#{activityDate},</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="updateTBranchActivity" parameterType="TBranchActivity">
        update t_branch_activity
        <trim prefix="SET" suffixOverrides=",">
            <if test="activityTheme != null and activityTheme != ''">activity_theme = #{activityTheme},</if>
            <if test="activityGoal != null and activityGoal != ''">activity_goal = #{activityGoal},</if>
            <if test="activityAttendees != null">activity_attendees = #{activityAttendees},</if>
            <if test="activityDate != null">activity_date = #{activityDate},</if>
            <if test="activityDate == null">activity_date = null,</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 activity_id = #{activityId}
    </update>

    <update id="deleteTBranchActivityByActivityId" parameterType="Long">
        update t_branch_activity set del_flag = 2 where activity_id = #{activityId}
    </update>

    <update id="deleteTBranchActivityByActivityIds" parameterType="String">
        update t_branch_activity set del_flag = 2 where activity_id in
        <foreach item="activityId" collection="array" open="(" separator="," close=")">
            #{activityId}
        </foreach>
    </update>
</mapper>