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

    <resultMap type="TTrainingbccDevice" id="TTrainingbccDeviceResult">
        <result property="id"    column="id"    />
        <result property="staffId"    column="staff_id"    />
        <result property="regularId"    column="regular_id"    />
        <result property="startDate"    column="start_date"    />
        <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="supplementary"    column="supplementary"    />
        <result property="learnState"    column="learn_state"    />
        <result property="examState"    column="exam_state"    />
        <result property="examId"    column="exam_id"    />
        <result property="examNum"    column="exam_num"    />
        <result property="learnTime"    column="learn_time"    />
        <result property="deptName" column="dept_name" />
    </resultMap>

    <sql id="selectTTrainingbccDeviceVo">
        select d.id,s.name , d.staff_id, d.regular_id, d.start_date, d.remarks, d.del_flag, d.creater_code, d.createdate, d.updater_code, d.updatedate, d.supplementary, d.learn_state, d.exam_state, d.exam_id,d.exam_num, d.learn_time from t_trainingbcc_device d
       left join t_staffmgr s on s.staffid = d.staff_id

</sql>

    <select id="selectTTrainingbccDeviceList" parameterType="TTrainingbccDevice" resultMap="TTrainingbccDeviceResult">
        select d.id,s.name , d.staff_id, d.regular_id, d.start_date, d.remarks, d.del_flag, d.creater_code, d.createdate, d.updater_code, d.updatedate, d.supplementary, d.learn_state, d.exam_state, d.exam_id,d.exam_num, d.learn_time from t_trainingbcc_device d
        left join t_staffmgr s on s.staffid = d.staff_id
        left join t_trainingbcc t on t.id = d.regular_id and t.DEL_FLAG = 0
        <where>
            <if test="staffId != null  and staffId != ''"> and d.staff_id = #{staffId}</if>
            <if test="regularId != null "> and d.regular_id = #{regularId}</if>
            <if test="startDate != null "> and d.start_date = #{startDate}</if>
            <if test="remarks != null  and remarks != ''"> and d.remarks = #{remarks}</if>
            <if test="createrCode != null  and createrCode != ''"> and d.creater_code = #{createrCode}</if>
            <if test="createdate != null "> and d.createdate = #{createdate}</if>
            <if test="updaterCode != null  and updaterCode != ''"> and d.updater_code = #{updaterCode}</if>
            <if test="updatedate != null "> and d.updatedate = #{updatedate}</if>
            <if test="supplementary != null  and supplementary != ''"> and d.supplementary = #{supplementary}</if>
            <if test="learnState != null "> and d.learn_state = #{learnState}</if>
            <if test="examState != null "> and d.exam_state = #{examState}</if>
            <if test="examId != null "> and d.exam_id = #{examId}</if>
            <if test="learnTime != null "> and d.learn_time = #{learnTime}</if>
            <if test="trainingType != null and trainingType != ''">and t.training_type = #{trainingType}</if>
            and d.del_flag = 0
        </where>
        order by d.exam_state, d.start_date
    </select>

    <select id="selectTTrainingbccDeviceById" parameterType="Long" resultMap="TTrainingbccDeviceResult">
        <include refid="selectTTrainingbccDeviceVo"/>
        where d.id = #{id}
    </select>

    <insert id="insertTTrainingbccDevice" parameterType="TTrainingbccDevice">
        <selectKey keyProperty="id" resultType="long" order="BEFORE">
            SELECT seq_t_trainingbcc_device.NEXTVAL as id FROM DUAL
        </selectKey>
        insert into t_trainingbcc_device
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="staffId != null">staff_id,</if>
            <if test="regularId != null">regular_id,</if>
            <if test="startDate != null">start_date,</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="supplementary != null">supplementary,</if>
            <if test="learnState != null">learn_state,</if>
            <if test="examState != null">exam_state,</if>
            <if test="examId != null">exam_id,</if>
            <if test="learnTime != null">learn_time,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id},</if>
            <if test="staffId != null">#{staffId},</if>
            <if test="regularId != null">#{regularId},</if>
            <if test="startDate != null">#{startDate},</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="supplementary != null">#{supplementary},</if>
            <if test="learnState != null">#{learnState},</if>
            <if test="examState != null">#{examState},</if>
            <if test="examId != null">#{examId},</if>
            <if test="learnTime != null">#{learnTime},</if>
         </trim>
    </insert>

    <update id="updateTTrainingbccDevice" parameterType="TTrainingbccDevice">
        update t_trainingbcc_device
        <trim prefix="SET" suffixOverrides=",">
            <if test="staffId != null">staff_id = #{staffId},</if>
            <if test="regularId != null">regular_id = #{regularId},</if>
            <if test="startDate != null">start_date = #{startDate},</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="supplementary != null">supplementary = #{supplementary},</if>
            <if test="learnState != null">learn_state = #{learnState},</if>
            <if test="examState != null">exam_state = #{examState},</if>
            <if test="examId != null">exam_id = #{examId},</if>
            <if test="examNum != null">exam_num = #{examNum},</if>
            <if test="learnTime != null">learn_time = #{learnTime},</if>
        </trim>
        where id = #{id}
    </update>

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

    <update id="deleteTTrainingbccDeviceByStaff" parameterType="TTrainingbccDevice">
        update t_trainingbcc_device set del_flag = 2 where staff_id = #{staffId} and regular_id = #{regularId}
    </update>



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

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


    <select id="countTraining" parameterType="TTrainingbccDevice" resultType="int">
        select count(1) from t_trainingbcc_device
        <where>
            <if test="regularId != null "> and regular_id = #{regularId}</if>
            <if test="examState != null "> and exam_state = #{examState}</if>
            and del_flag = 0
        </where>

    </select>


</mapper>
