<?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.project.shiftmgr.mapper.TShiftDailyInstDetailMapper">
    
    <resultMap type="TShiftDailyInstDetail" id="TShiftDailyInstDetailResult">
        <result property="id"    column="id"    />
        <result property="parentId"    column="parent_id"    />
        <result property="postWork"    column="post_work"    />
        <result property="postNote"    column="post_note"    />
        <result property="postTask"    column="post_task"    />
        <result property="delFlag"    column="del_flag"    />
        <result property="createrCode"    column="creater_code"    />
        <result property="createdate"    column="createdate"    />
        <result property="updaterCode"    column="updater_code"    />
        <result property="updatedate"    column="updatedate"    />
        <result property="deptId"    column="dept_id"    />
        <result property="deptName" column="dept_name" />
    </resultMap>

    <sql id="selectTShiftDailyInstDetailVo">
        select d.id, d.parent_id, d.post_work, d.post_note, d.post_task, d.del_flag, d.creater_code, d.createdate, d.updater_code, d.updatedate, d.dept_id ,s.dept_name from t_shift_daily_inst_detail d
      left join sys_dept s on s.dept_id = d.dept_id
    </sql>

    <select id="selectTShiftDailyInstDetailList" parameterType="TShiftDailyInstDetail" resultMap="TShiftDailyInstDetailResult">
        <include refid="selectTShiftDailyInstDetailVo"/>
        <where>  
            <if test="parentId != null "> and parent_id = #{parentId}</if>
            <if test="postWork != null  and postWork != ''"> and post_work = #{postWork}</if>
            <if test="postNote != null  and postNote != ''"> and post_note = #{postNote}</if>
            <if test="postTask != null  and postTask != ''"> and post_task = #{postTask}</if>
            <if test="createrCode != null "> and creater_code = #{createrCode}</if>
            <if test="createdate != null "> and createdate = #{createdate}</if>
            <if test="updaterCode != null "> and updater_code = #{updaterCode}</if>
            <if test="updatedate != null "> and updatedate = #{updatedate}</if>
            <if test="deptId != null "> and dept_id = #{deptId}</if>
            and d.del_flag = 0
        </where>
        <!-- 数据范围过滤 -->
        ${params.dataScope}
    </select>
    
    <select id="selectTShiftDailyInstDetailById" parameterType="Long" resultMap="TShiftDailyInstDetailResult">
        <include refid="selectTShiftDailyInstDetailVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertTShiftDailyInstDetail" parameterType="TShiftDailyInstDetail">
        <selectKey keyProperty="id" resultType="long" order="BEFORE">
            SELECT SEQ_T_SHIFT_DAILY_INST_DETAIL.NEXTVAL as id FROM DUAL
        </selectKey>
        insert into t_shift_daily_inst_detail
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="parentId != null">parent_id,</if>
            <if test="postWork != null">post_work,</if>
            <if test="postNote != null">post_note,</if>
            <if test="postTask != null">post_task,</if>
            <if test="delFlag != null">del_flag,</if>
            <if test="createrCode != null">creater_code,</if>
            <if test="createdate != null">createdate,</if>
            <if test="updaterCode != null">updater_code,</if>
            <if test="updatedate != null">updatedate,</if>
            <if test="deptId != null">dept_id,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id},</if>
            <if test="parentId != null">#{parentId},</if>
            <if test="postWork != null">#{postWork},</if>
            <if test="postNote != null">#{postNote},</if>
            <if test="postTask != null">#{postTask},</if>
            <if test="delFlag != null">#{delFlag},</if>
            <if test="createrCode != null">#{createrCode},</if>
            <if test="createdate != null">#{createdate},</if>
            <if test="updaterCode != null">#{updaterCode},</if>
            <if test="updatedate != null">#{updatedate},</if>
            <if test="deptId != null">#{deptId},</if>
         </trim>
    </insert>

    <update id="updateTShiftDailyInstDetail" parameterType="TShiftDailyInstDetail">
        update t_shift_daily_inst_detail
        <trim prefix="SET" suffixOverrides=",">
            <if test="parentId != null">parent_id = #{parentId},</if>
            <if test="postWork != null">post_work = #{postWork},</if>
            <if test="postNote != null">post_note = #{postNote},</if>
            <if test="postTask != null">post_task = #{postTask},</if>
            <if test="delFlag != null">del_flag = #{delFlag},</if>
            <if test="createrCode != null">creater_code = #{createrCode},</if>
            <if test="createdate != null">createdate = #{createdate},</if>
            <if test="updaterCode != null">updater_code = #{updaterCode},</if>
            <if test="updatedate != null">updatedate = #{updatedate},</if>
            <if test="deptId != null">dept_id = #{deptId},</if>
        </trim>
        where id = #{id}
    </update>

    <update id="deleteTShiftDailyInstDetailById" parameterType="Long">
        update t_shift_daily_inst_detail set del_flag = 2 where id = #{id}
    </update>

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