<?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.TShiftRosterMapper">
    
    <resultMap type="TShiftRoster" id="TShiftRosterResult">
        <result property="id"    column="id"    />
        <result property="shiftDate"    column="shift_date"    />
        <result property="dclass"    column="dclass"    />
        <result property="nclass"    column="nclass"    />
        <result property="week"    column="week"    />
        <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="vacation"    column="vacation"    />
        <result property="deptName" column="dept_name" />
    </resultMap>

    <sql id="selectTShiftRosterVo">
        select d.id, d.shift_date, d.dclass, d.nclass, d.week, d.del_flag, d.creater_code, d.createdate, d.updater_code, d.updatedate, d.dept_id, d.vacation ,s.dept_name from t_shift_roster d
      left join sys_dept s on s.dept_id = d.dept_id
    </sql>

    <select id="selectTShiftRosterList" parameterType="TShiftRoster" resultMap="TShiftRosterResult">
        <include refid="selectTShiftRosterVo"/>
        <where>  
            <if test="shiftDate != null "> and shift_date = #{shiftDate}</if>
            <if test="dclass != null  and dclass != ''"> and dclass = #{dclass}</if>
            <if test="nclass != null  and nclass != ''"> and nclass = #{nclass}</if>
            <if test="week != null "> and week = #{week}</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>
            <if test="vacation != null "> and vacation = #{vacation}</if>
            and d.del_flag = 0
        </where>
        <!-- 数据范围过滤 -->
        ${params.dataScope}
    </select>
    
    <select id="selectTShiftRosterById" parameterType="TShiftRoster" resultMap="TShiftRosterResult">
        <include refid="selectTShiftRosterVo"/>
        where id = #{id}
    </select>

    <select id="selectTShiftRosterListByTrain" parameterType="Long" resultMap="TShiftRosterResult">
        <include refid="selectTShiftRosterVo"/>
        <where>
            <if test="shiftDate != null "> and shift_date >= #{shiftDate}</if>
            <if test="dclass != null  and dclass != '' and nclass != null  and nclass != ''"> and (dclass = #{dclass} or nclass = #{nclass})</if>
            <if test="vacation != null "> and vacation != #{vacation}</if>
            <if test="week != null "> and week != 0 and week != 6</if>
            and d.del_flag = 0
        </where>
    </select>
        
    <insert id="insertTShiftRoster" parameterType="TShiftRoster">
        <selectKey keyProperty="id" resultType="long" order="BEFORE">
            SELECT seq_t_shift_roster.NEXTVAL as id FROM DUAL
        </selectKey>
        insert into t_shift_roster
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="shiftDate != null">shift_date,</if>
            <if test="dclass != null and dclass != ''">dclass,</if>
            <if test="nclass != null and nclass != ''">nclass,</if>
            <if test="week != null">week,</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>
            <if test="vacation != null">vacation,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id},</if>
            <if test="shiftDate != null">#{shiftDate},</if>
            <if test="dclass != null and dclass != ''">#{dclass},</if>
            <if test="nclass != null and nclass != ''">#{nclass},</if>
            <if test="week != null">#{week},</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>
            <if test="vacation != null">#{vacation},</if>
         </trim>
    </insert>

    <update id="updateTShiftRoster" parameterType="TShiftRoster">
        update t_shift_roster
        <trim prefix="SET" suffixOverrides=",">
            <if test="shiftDate != null">shift_date = #{shiftDate},</if>
            <if test="dclass != null and dclass != ''">dclass = #{dclass},</if>
            <if test="nclass != null and nclass != ''">nclass = #{nclass},</if>
            <if test="week != null">week = #{week},</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>
            <if test="vacation != null">vacation = #{vacation},</if>
        </trim>
        where id = #{id}
    </update>

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

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