<?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.TBranchPlanItemMapper">
    
    <resultMap type="TBranchPlanItem" id="TBranchPlanItemResult">
        <result property="itemId"    column="item_id"    />
        <result property="planId"    column="plan_id"    />
        <result property="itemContent"    column="item_content"    />
        <result property="planTime"    column="plan_time"    />
        <result property="itemStatus"    column="item_status"    />
        <result property="actualTime"    column="actual_time"    />
        <result property="personInCharge"    column="person_in_charge"    />
        <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="selectTBranchPlanItemVo">
        select u.item_id, u.plan_id, u.item_content, u.plan_time, u.item_status, u.actual_time, u.person_in_charge, u.del_flag, u.create_by, u.create_time, u.update_by, u.update_time, u.dept_id from t_branch_plan_item u left join sys_dept d on u.dept_id = d.dept_id
    </sql>

    <select id="selectTBranchPlanItemList" parameterType="TBranchPlanItem" resultMap="TBranchPlanItemResult">
        <include refid="selectTBranchPlanItemVo"/>
        <where>  
            <if test="itemId != null "> and u.item_id = #{itemId}</if>
            <if test="planId != null "> and u.plan_id = #{planId}</if>
            <if test="itemContent != null  and itemContent != ''"> and u.item_content like concat('%', #{itemContent}, '%')</if>
            <if test="planTime != null "> and u.plan_time = #{planTime}</if>
            <if test="planYear != null "> and extract(year from u.plan_time) = #{planYear}</if>
            <if test="itemStatus != null  and itemStatus != ''"> and u.item_status = #{itemStatus}</if>
            <if test="actualTime != null "> and u.actual_time = #{actualTime}</if>
            <if test="personInCharge != null  and personInCharge != ''"> and u.person_in_charge = #{personInCharge}</if>
            <if test="deptId != null "> and u.dept_id = #{deptId}</if>
            and u.del_flag = 0
        </where>
        order by u.plan_id asc
        <!-- 数据范围过滤 -->
        ${params.dataScope}
    </select>
    
    <select id="selectTBranchPlanItemByItemId" parameterType="Long" resultMap="TBranchPlanItemResult">
        <include refid="selectTBranchPlanItemVo"/>
        where u.item_id = #{itemId}
        and u.del_flag = 0
    </select>
        
    <insert id="insertTBranchPlanItem" parameterType="TBranchPlanItem">
        <selectKey keyProperty="itemId" resultType="long" order="BEFORE">
            SELECT seq_t_branch_plan_item.NEXTVAL as itemId FROM DUAL
        </selectKey>
        insert into t_branch_plan_item
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="itemId != null">item_id,</if>
            <if test="planId != null">plan_id,</if>
            <if test="itemContent != null">item_content,</if>
            <if test="planTime != null">plan_time,</if>
            <if test="itemStatus != null">item_status,</if>
            <if test="actualTime != null">actual_time,</if>
            <if test="personInCharge != null">person_in_charge,</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="itemId != null">#{itemId},</if>
            <if test="planId != null">#{planId},</if>
            <if test="itemContent != null">#{itemContent},</if>
            <if test="planTime != null">#{planTime},</if>
            <if test="itemStatus != null">#{itemStatus},</if>
            <if test="actualTime != null">#{actualTime},</if>
            <if test="personInCharge != null">#{personInCharge},</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="updateTBranchPlanItem" parameterType="TBranchPlanItem">
        update t_branch_plan_item
        <trim prefix="SET" suffixOverrides=",">
            <if test="planId != null">plan_id = #{planId},</if>
            <if test="itemContent != null">item_content = #{itemContent},</if>
            <if test="planTime != null">plan_time = #{planTime},</if>
            <if test="itemStatus != null">item_status = #{itemStatus},</if>
            <if test="actualTime != null">actual_time = #{actualTime},</if>
            <if test="personInCharge != null">person_in_charge = #{personInCharge},</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 item_id = #{itemId}
    </update>

    <update id="deleteTBranchPlanItemByItemId" parameterType="Long">
        update t_branch_plan_item set del_flag = 2 where item_id = #{itemId}
    </update>

    <update id="deleteTBranchPlanItemByItemIds" parameterType="String">
        update t_branch_plan_item set del_flag = 2 where item_id in
        <foreach item="itemId" collection="array" open="(" separator="," close=")">
            #{itemId}
        </foreach>
    </update>
</mapper>