<?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.TBranchManageMapper">

    <resultMap type="TBranchManage" id="TBranchManageResult">
        <result property="manageId"    column="manage_id"    />
        <result property="monthly"    column="monthly"    />
        <result property="year"    column="year"    />
        <result property="describe"    column="describe"    />
        <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"    />
        <result property="filesId"    column="files_id"    />
    </resultMap>

    <sql id="selectTBranchManageVo">
        select u.manage_id, u.monthly, u.year, u.describe, u.remarks, u.del_flag, u.create_by, u.create_time, u.update_by, u.update_time, u.dept_id, u.files_id from t_branch_manage u left join sys_dept d on u.dept_id = d.dept_id
    </sql>

    <select id="selectTBranchManageList" parameterType="TBranchManage" resultMap="TBranchManageResult">
        <include refid="selectTBranchManageVo"/>
        <where>
            <if test="manageId != null "> and u.manage_id = #{manageId}</if>
            <if test="monthly != null "> and u.monthly = #{monthly}</if>
            <if test="year != null "> and u.year=#{year}</if>
            <if test="describe != null  and describe != ''"> and u.describe = #{describe}</if>
            <if test="remarks != null  and remarks != ''"> and u.remarks = #{remarks}</if>
            <if test="deptId != null "> and u.dept_id = #{deptId}</if>
            <if test="filesId != null  and filesId != ''"> and u.files_id = #{filesId}</if>
            and u.del_flag = 0
        </where>
        <!-- 数据范围过滤 -->
        ${params.dataScope}
    </select>

    <select id="selectTBranchManageByManageId" parameterType="Long" resultMap="TBranchManageResult">
        <include refid="selectTBranchManageVo"/>
        where u.manage_id = #{manageId}
        and u.del_flag = 0
    </select>

    <insert id="insertTBranchManage" parameterType="TBranchManage">
        <selectKey keyProperty="manageId" resultType="long" order="BEFORE">
            SELECT seq_t_branch_manage.NEXTVAL as id FROM DUAL
        </selectKey>
        insert into t_branch_manage
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="manageId != null">manage_id,</if>
            <if test="monthly != null">monthly,</if>
            <if test="year != null">year,</if>
            <if test="describe != null">describe,</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>
            <if test="filesId != null">files_id,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="manageId != null">#{manageId},</if>
            <if test="monthly != null">#{monthly},</if>
            <if test="year != null">#{year},</if>
            <if test="describe != null">#{describe},</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>
            <if test="filesId != null">#{filesId},</if>
         </trim>
    </insert>

    <update id="updateTBranchManage" parameterType="TBranchManage">
        update t_branch_manage
        <trim prefix="SET" suffixOverrides=",">
            <if test="monthly != null">monthly = #{monthly},</if>
            <if test="year != null">year = #{year},</if>
            <if test="describe != null">describe = #{describe},</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>
            <if test="filesId != null">files_id = #{filesId},</if>
        </trim>
        where manage_id = #{manageId}
    </update>

    <update id="deleteTBranchManageByManageId" parameterType="Long">
        update t_branch_manage set del_flag = 2 where manage_id = #{manageId}
    </update>

    <update id="deleteTBranchManageByManageIds" parameterType="String">
        update t_branch_manage set del_flag = 2 where manage_id in
        <foreach item="manageId" collection="array" open="(" separator="," close=")">
            #{manageId}
        </foreach>
    </update>
</mapper>
