<?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.TShiftDailyInstructionMapper">
    
    <resultMap type="TShiftDailyInstruction" id="TShiftDailyInstructionResult">
        <result property="id"    column="id"    />
        <result property="title"    column="title"    />
        <result property="publisher"    column="publisher"    />
        <result property="personInCharge"    column="person_in_charge"    />
        <result property="publishDate"    column="publish_date"    />
        <result property="priority"    column="priority"    />
        <result property="note"    column="note"    />
        <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="selectTShiftDailyInstructionVo">
        select d.id, d.title, d.publisher, d.person_in_charge, d.publish_date, d.priority, d.note, d.del_flag, d.creater_code, d.createdate, d.updater_code, d.updatedate, d.dept_id ,s.dept_name from t_shift_daily_instruction d
      left join sys_dept s on s.dept_id = d.dept_id
    </sql>

    <select id="selectTShiftDailyInstructionList" parameterType="TShiftDailyInstruction" resultMap="TShiftDailyInstructionResult">
        <include refid="selectTShiftDailyInstructionVo"/>
        <where>  
            <if test="title != null  and title != ''"> and title = #{title}</if>
            <if test="publisher != null  and publisher != ''"> and publisher = #{publisher}</if>
            <if test="personInCharge != null  and personInCharge != ''"> and person_in_charge = #{personInCharge}</if>
            <if test="publishDate != null "> and publish_date = #{publishDate}</if>
            <if test="priority != null "> and priority = #{priority}</if>
            <if test="note != null  and note != ''"> and note = #{note}</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="selectTShiftDailyInstructionById" parameterType="Long" resultMap="TShiftDailyInstructionResult">
        <include refid="selectTShiftDailyInstructionVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertTShiftDailyInstruction" parameterType="TShiftDailyInstruction">
        <selectKey keyProperty="id" resultType="long" order="BEFORE">
            SELECT SEQ_T_SHIFT_DAILY_INSTRUCTION.NEXTVAL as id FROM DUAL
        </selectKey>
        insert into t_shift_daily_instruction
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="title != null">title,</if>
            <if test="publisher != null">publisher,</if>
            <if test="personInCharge != null">person_in_charge,</if>
            <if test="publishDate != null">publish_date,</if>
            <if test="priority != null">priority,</if>
            <if test="note != null">note,</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="title != null">#{title},</if>
            <if test="publisher != null">#{publisher},</if>
            <if test="personInCharge != null">#{personInCharge},</if>
            <if test="publishDate != null">#{publishDate},</if>
            <if test="priority != null">#{priority},</if>
            <if test="note != null">#{note},</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="updateTShiftDailyInstruction" parameterType="TShiftDailyInstruction">
        update t_shift_daily_instruction
        <trim prefix="SET" suffixOverrides=",">
            <if test="title != null">title = #{title},</if>
            <if test="publisher != null">publisher = #{publisher},</if>
            <if test="personInCharge != null">person_in_charge = #{personInCharge},</if>
            <if test="publishDate != null">publish_date = #{publishDate},</if>
            <if test="priority != null">priority = #{priority},</if>
            <if test="note != null">note = #{note},</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="deleteTShiftDailyInstructionById" parameterType="Long">
        update t_shift_daily_instruction set del_flag = 2 where id = #{id}
    </update>

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