<?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.TTrainingbccMapper">

    <resultMap type="TTrainingbcc" id="TTrainingbccResult">
        <result property="id"    column="id"    />
        <result property="plantCode"    column="plant_code"    />
        <result property="course"    column="course"    />
        <result property="courseid"    column="courseid"    />
        <result property="period"    column="period"    />
        <result property="duration"    column="duration"    />
        <result property="trainer"    column="trainer"    />
        <result property="position"    column="position"    />
        <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="remarks"    column="remarks"    />
        <result property="deptId"    column="dept_id"    />
        <result property="courseStartdate"    column="course_startdate"    />
        <result property="courseEnddate"    column="course_enddate"    />
        <result property="isfinish"    column="isfinish"    />
        <result property="confirmor"    column="confirmor"    />
        <result property="years"    column="years"    />
        <result property="content"    column="content"    />
        <result property="nonParticipants"    column="non_participants"    />
        <result property="unit"    column="unit"    />
        <result property="trainingType"    column="training_type"    />
        <result property="picUrl"    column="pic_url"    />
        <result property="regularId"    column="regular_id"    />
        <result property="designatedPosition"    column="designated_position"    />
        <result property="designatedStaff"    column="designated_staff"    />
        <result property="fileUrl"    column="file_url"    />
        <result property="fileName"    column="file_name"    />
        <result property="timerNeed"    column="timer_need"    />
        <result property="examId"    column="exam_id"    />
        <result property="deptName" column="dept_name" />
    </resultMap>

    <sql id="selectTTrainingbccVo">
        select d.id, d.plant_code, d.course, d.courseid, d.period, d.duration, d.trainer, d.position, d.del_flag, d.creater_code, d.createdate, d.updater_code, d.updatedate, d.remarks, d.dept_id, d.course_startdate, d.course_enddate, d.isfinish, d.confirmor, d.years, d.content, d.non_participants, d.unit, d.training_type, d.pic_url, d.regular_id, d.designated_position, d.designated_staff, d.file_url, d.file_name, d.timer_need, d.exam_id  from t_trainingbcc d

    </sql>

    <select id="selectTTrainingbccList" parameterType="TTrainingbcc" resultMap="TTrainingbccResult">
        <include refid="selectTTrainingbccVo"/>
        <where>
            <if test="years != null ">and years = #{years}</if>
            <if test="plantCode != null  and plantCode != ''"> and plant_code = #{plantCode}</if>
            <if test="course != null  and course != ''"> and course like concat(concat('%', #{course}), '%')</if>
            <if test="courseid != null  and courseid != ''"> and courseid = #{courseid}</if>
            <if test="period != null  and period != ''"> and period = #{period}</if>
            <if test="duration != null  and duration != ''"> and duration = #{duration}</if>
            <if test="trainer != null  and trainer != ''"> and trainer = #{trainer}</if>
            <if test="position != null  and position != ''"> and position = #{position}</if>
            <if test="trainingType != null and trainingType != ''">and training_type = #{trainingType}</if>
            and d.del_flag = 0
        </where>
        <!-- 数据范围过滤 -->
        order by d.years desc,d.course_startdate desc
        ${params.dataScope}
    </select>

    <select id="selectTTrainingbccById" parameterType="Long" resultMap="TTrainingbccResult">
        <include refid="selectTTrainingbccVo"/>
        where id = #{id}
    </select>

    <insert id="insertTTrainingbcc" parameterType="TTrainingbcc">
        <selectKey keyProperty="id" resultType="long" order="BEFORE">
            SELECT seq_t_training.NEXTVAL as id FROM DUAL
        </selectKey>
        insert into t_trainingbcc
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="plantCode != null">plant_code,</if>
            <if test="course != null and course != ''">course,</if>
            <if test="courseid != null">courseid,</if>
            <if test="period != null">period,</if>
            <if test="duration != null">duration,</if>
            <if test="trainer != null">trainer,</if>
            <if test="position != null">position,</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="remarks != null">remarks,</if>
            <if test="deptId != null">dept_id,</if>
            <if test="courseStartdate != null">course_startdate,</if>
            <if test="courseEnddate != null">course_enddate,</if>
            <if test="isfinish != null">isfinish,</if>
            <if test="confirmor != null">confirmor,</if>
            <if test="years != null">years,</if>
            <if test="content != null">content,</if>
            <if test="nonParticipants != null">non_participants,</if>
            <if test="unit != null">unit,</if>
            <if test="trainingType != null">training_type,</if>
            <if test="picUrl != null">pic_url,</if>
            <if test="regularId != null">regular_id,</if>
            <if test="designatedPosition != null">designated_position,</if>
            <if test="designatedStaff != null">designated_staff,</if>
            <if test="fileUrl != null">file_url,</if>
            <if test="fileName != null">file_name,</if>
            <if test="timerNeed != null">timer_need,</if>
            <if test="examId != null">exam_id,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id},</if>
            <if test="plantCode != null">#{plantCode},</if>
            <if test="course != null and course != ''">#{course},</if>
            <if test="courseid != null">#{courseid},</if>
            <if test="period != null">#{period},</if>
            <if test="duration != null">#{duration},</if>
            <if test="trainer != null">#{trainer},</if>
            <if test="position != null">#{position},</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="remarks != null">#{remarks},</if>
            <if test="deptId != null">#{deptId},</if>
            <if test="courseStartdate != null">#{courseStartdate},</if>
            <if test="courseEnddate != null">#{courseEnddate},</if>
            <if test="isfinish != null">#{isfinish},</if>
            <if test="confirmor != null">#{confirmor},</if>
            <if test="years != null">#{years},</if>
            <if test="content != null">#{content},</if>
            <if test="nonParticipants != null">#{nonParticipants},</if>
            <if test="unit != null">#{unit},</if>
            <if test="trainingType != null">#{trainingType},</if>
            <if test="picUrl != null">#{picUrl},</if>
            <if test="regularId != null">#{regularId},</if>
            <if test="designatedPosition != null">#{designatedPosition},</if>
            <if test="designatedStaff != null">#{designatedStaff},</if>
            <if test="fileUrl != null">#{fileUrl},</if>
            <if test="fileName != null">#{fileName},</if>
            <if test="timerNeed != null">#{timerNeed},</if>
            <if test="examId != null">#{examId},</if>
         </trim>
    </insert>

    <update id="updateTTrainingbcc" parameterType="TTrainingbcc">
        update t_trainingbcc
        <trim prefix="SET" suffixOverrides=",">
            <if test="plantCode != null">plant_code = #{plantCode},</if>
            <if test="course != null and course != ''">course = #{course},</if>
            <if test="courseid != null">courseid = #{courseid},</if>
            <if test="period != null">period = #{period},</if>
            <if test="duration != null">duration = #{duration},</if>
            <if test="trainer != null">trainer = #{trainer},</if>
            <if test="position != null">position = #{position},</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="remarks != null">remarks = #{remarks},</if>
            <if test="deptId != null">dept_id = #{deptId},</if>
            <if test="courseStartdate != null">course_startdate = #{courseStartdate},</if>
            <if test="courseEnddate != null">course_enddate = #{courseEnddate},</if>
            <if test="isfinish != null">isfinish = #{isfinish},</if>
            <if test="confirmor != null">confirmor = #{confirmor},</if>
            <if test="years != null">years = #{years},</if>
            <if test="content != null">content = #{content},</if>
            <if test="nonParticipants != null">non_participants = #{nonParticipants},</if>
            <if test="unit != null">unit = #{unit},</if>
            <if test="trainingType != null">training_type = #{trainingType},</if>
            <if test="picUrl != null">pic_url = #{picUrl},</if>
            <if test="regularId != null">regular_id = #{regularId},</if>
            <if test="designatedPosition != null">designated_position = #{designatedPosition},</if>
            <if test="designatedStaff != null">designated_staff = #{designatedStaff},</if>
            <if test="fileUrl != null">file_url = #{fileUrl},</if>
            <if test="fileName != null">file_name = #{fileName},</if>
            <if test="timerNeed != null">timer_need = #{timerNeed},</if>
            <if test="examId != null">exam_id = #{examId},</if>
        </trim>
        where id = #{id}
    </update>

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

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

</mapper>
