<?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.TTrainingMatrixMapper">
    
    <resultMap type="TTrainingMatrix" id="TTrainingMatrixResult">
        <result property="id"    column="id"    />
        <result property="courseCode"    column="course_code"    />
        <result property="item"    column="item"    />
        <result property="actualpostId"    column="actualpost_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="deptId"    column="dept_id"    />
        <result property="lecturer"    column="lecturer"    />
        <result property="hour"    column="hour"    />
        <result property="designatedPosition"    column="designated_position"    />
        <result property="frequency"    column="frequency"    />
        <result property="responsDept"    column="respons_dept"    />
        <result property="involvedMoc"    column="involved_moc"    />
        <result property="designatedOther"    column="designated_other"    />
        <result property="trainingLevel"    column="training_level"    />
        <result property="deptName" column="dept_name" />
    </resultMap>

    <sql id="selectTTrainingMatrixVo">
        select d.id, d.course_code, d.item, d.actualpost_id, d.remarks, d.del_flag, d.creater_code, d.createdate, d.updater_code, d.updatedate, d.dept_id, d.lecturer, d.hour, d.designated_position, d.frequency, d.involved_moc, d.training_level, d.respons_dept, d.designated_other ,s.dept_name from t_training_matrix d
      left join sys_dept s on s.dept_id = d.dept_id
    </sql>

    <select id="selectTTrainingMatrixList" parameterType="TTrainingMatrix" resultMap="TTrainingMatrixResult">
        <include refid="selectTTrainingMatrixVo"/>
        <where>
            <if test="trainingLevel != null  and trainingLevel != ''"> and training_level = #{trainingLevel}</if>
            <if test="item != null  and item != ''"> and item like concat(concat('%', #{item}), '%')</if>
            and d.del_flag = 0
        </where>
        <!-- 数据范围过滤 -->
        ${params.dataScope}
        order by d.id asc
    </select>
    
    <select id="selectTTrainingMatrixById" parameterType="Long" resultMap="TTrainingMatrixResult">
        <include refid="selectTTrainingMatrixVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertTTrainingMatrix" parameterType="TTrainingMatrix">
        <selectKey keyProperty="id" resultType="long" order="BEFORE">
            SELECT seq_t_training_matrix.NEXTVAL as id FROM DUAL
        </selectKey>
        insert into t_training_matrix
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="courseCode != null">course_code,</if>
            <if test="item != null">item,</if>
            <if test="actualpostId != null">actualpost_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="deptId != null">dept_id,</if>
            <if test="lecturer != null">lecturer,</if>
            <if test="hour != null">hour,</if>
            <if test="designatedPosition != null">designated_position,</if>
            <if test="involvedMoc != null">involved_moc,</if>
            <if test="designatedOther != null">designated_other,</if>
            <if test="frequency != null">frequency,</if>
            <if test="responsDept != null">respons_dept,</if>
            <if test="trainingLevel != null">training_level,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id},</if>
            <if test="courseCode != null">#{courseCode},</if>
            <if test="item != null">#{item},</if>
            <if test="actualpostId != null">#{actualpostId},</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="deptId != null">#{deptId},</if>
            <if test="lecturer != null">#{lecturer},</if>
            <if test="hour != null">#{hour},</if>
            <if test="designatedPosition != null">#{designatedPosition},</if>
            <if test="involvedMoc != null">#{involvedMoc},</if>
            <if test="designatedOther != null">#{designatedOther},</if>
            <if test="frequency != null">#{frequency},</if>
            <if test="responsDept != null">#{responsDept},</if>
            <if test="trainingLevel != null">#{trainingLevel},</if>
         </trim>
    </insert>

    <update id="updateTTrainingMatrix" parameterType="TTrainingMatrix">
        update t_training_matrix
        <trim prefix="SET" suffixOverrides=",">
            <if test="courseCode != null">course_code = #{courseCode},</if>
            <if test="item != null">item = #{item},</if>
            <if test="actualpostId != null">actualpost_id = #{actualpostId},</if>
            <if test="actualpostId == null">actualpost_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="deptId != null">dept_id = #{deptId},</if>
            <if test="lecturer != null">lecturer = #{lecturer},</if>
            <if test="hour != null">hour = #{hour},</if>
            <if test="designatedPosition != null">designated_position = #{designatedPosition},</if>
            <if test="designatedPosition == null">designated_position = NULL,</if>
            <if test="involvedMoc != null">involved_moc = #{involvedMoc},</if>
            <if test="designatedOther != null">designated_other = #{designatedOther},</if>
            <if test="frequency != null">frequency = #{frequency},</if>
            <if test="responsDept != null">respons_dept = #{responsDept},</if>
            <if test="trainingLevel != null">training_level = #{trainingLevel},</if>
        </trim>
        where id = #{id}
    </update>

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

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