<?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.training.mapper.TTrainingCompanylevelMapper">
    
    <resultMap type="TTrainingCompanylevel" id="TTrainingCompanylevelResult">
        <result property="id"    column="id"    />
        <result property="serialNum"    column="serial_num"    />
        <result property="courseCode"    column="course_code"    />
        <result property="item"    column="item"    />
        <result property="staffId"    column="staff_id"    />
        <result property="remarks"    column="remarks"    />
        <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="frequency"    column="frequency"    />
        <result property="deptId"    column="dept_id"    />
        <result property="deptName" column="dept_name" />
    </resultMap>

    <sql id="selectTTrainingCompanylevelVo">
        select d.id, d.serial_num, d.course_code, d.item, d.staff_id, d.remarks, d.del_flag, d.creater_code, d.createdate, d.updater_code, d.updatedate, d.dept_id, d.frequency ,s.dept_name from t_training_companylevel d
      left join sys_dept s on s.dept_id = d.dept_id
    </sql>

    <select id="selectTTrainingCompanylevelList" parameterType="TTrainingCompanylevel" resultMap="TTrainingCompanylevelResult">
        <include refid="selectTTrainingCompanylevelVo"/>
        <where>  
            <if test="serialNum != null "> and serial_num = #{serialNum}</if>
            <if test="courseCode != null  and courseCode != ''"> and course_code like concat(concat('%', #{courseCode}), '%')</if>
            <if test="item != null  and item != ''"> and item like concat(concat('%', #{item}), '%')</if>
            <if test="staffId!=null and staffId!= ''"> and staff_id like concat(concat('%', #{staffId}), '%')   </if>
            <if test="remarks != null  and remarks != ''"> and remarks = #{remarks}</if>
            and d.del_flag = 0
        </where>
        <!-- 数据范围过滤 -->
        ${params.dataScope}
        order by d.serial_num asc
    </select>
    
    <select id="selectTTrainingCompanylevelById" parameterType="Long" resultMap="TTrainingCompanylevelResult">
        <include refid="selectTTrainingCompanylevelVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertTTrainingCompanylevel" parameterType="TTrainingCompanylevel">
        <selectKey keyProperty="id" resultType="long" order="BEFORE">
            SELECT seq_t_training_companylevel.NEXTVAL as id FROM DUAL
        </selectKey>
        insert into t_training_companylevel
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="serialNum != null">serial_num,</if>
            <if test="courseCode != null">course_code,</if>
            <if test="item != null">item,</if>
            <if test="staffId != null">staff_id,</if>
            <if test="remarks != null">remarks,</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="frequency != null">frequency,</if>
            <if test="deptId != null">dept_id,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id},</if>
            <if test="serialNum != null">#{serialNum},</if>
            <if test="courseCode != null">#{courseCode},</if>
            <if test="item != null">#{item},</if>
            <if test="staffId != null">#{staffId},</if>
            <if test="remarks != null">#{remarks},</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="frequency != null">#{frequency},</if>
            <if test="deptId != null">#{deptId},</if>
         </trim>
    </insert>

    <update id="updateTTrainingCompanylevel" parameterType="TTrainingCompanylevel">
        update t_training_companylevel
        <trim prefix="SET" suffixOverrides=",">
            <if test="serialNum != null">serial_num = #{serialNum},</if>
            <if test="courseCode != null">course_code = #{courseCode},</if>
            <if test="item != null">item = #{item},</if>
            <if test="staffId != null">staff_id = #{staffId},</if>
            <if test="staffId == null">staff_id = NULL,</if>
            <if test="remarks != null">remarks = #{remarks},</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="frequency != null">frequency = #{frequency},</if>
            <if test="frequency == null">frequency = NULL,</if>
            <if test="deptId != null">dept_id = #{deptId},</if>
        </trim>
        where id = #{id}
    </update>

    <update id="resetTTrainingCompanylevel">
        update t_training_companylevel set staff_id = NULL where staff_id IS NOT NULL and del_flag = 0
    </update>

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

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