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

    <resultMap type="TTrainingHisparticipants" id="TTrainingHisparticipantsResult">
        <result property="id"    column="id"    />
        <result property="staffId"    column="staff_id"    />
        <result property="companyId"    column="company_id"    />
        <result property="courseCode"    column="course_code"    />
        <result property="item"    column="item"    />
        <result property="startDate"    column="start_date"    />
        <result property="endDate"    column="end_date"    />
        <result property="score"    column="score"    />
        <result property="operationScore"    column="operation_score"    />
        <result property="trainingPlace"    column="training_place"    />
        <result property="trainingDuration"    column="training_duration"    />
        <result property="trainingCost"    column="training_cost"    />
        <result property="budget"    column="budget"    />
        <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="deptName" column="dept_name" />
    </resultMap>

    <sql id="selectTTrainingHisparticipantsVo">
        select d.id, d.staff_id, d.company_id,d.course_code, d.item,  d.start_date, d.end_date, d.score, d.operation_score, d.training_place, d.training_duration, d.training_cost, d.budget, d.remarks, d.del_flag, d.creater_code, d.createdate, d.updater_code, d.updatedate ,s.dept_name from t_training_hisparticipants d
      left join sys_dept s on s.dept_id = d.dept_id
    </sql>

    <select id="selectTTrainingHisparticipantsList" parameterType="TTrainingHisparticipants" resultMap="TTrainingHisparticipantsResult">
        <include refid="selectTTrainingHisparticipantsVo"/>
        <where>
            <if test="staffId != null "> and staff_id = #{staffId}</if>
            <if test="companyId != null "> and company_id = #{companyId}</if>
            <if test="startDate != null "> and start_date = #{startDate}</if>
            <if test="endDate != null "> and end_date = #{endDate}</if>
            <if test="score != null "> and score = #{score}</if>
            <if test="operationScore != null "> and operation_score = #{operationScore}</if>
            <if test="trainingPlace != null  and trainingPlace != ''"> and training_place = #{trainingPlace}</if>
            <if test="trainingDuration != null  and trainingDuration != ''"> and training_duration = #{trainingDuration}</if>
            <if test="trainingCost != null  and trainingCost != ''"> and training_cost = #{trainingCost}</if>
            <if test="budget != null  and budget != ''"> and budget = #{budget}</if>
            <if test="remarks != null  and remarks != ''"> and remarks = #{remarks}</if>
            <if test="createrCode != null  and createrCode != ''"> and creater_code = #{createrCode}</if>
            <if test="createdate != null "> and createdate = #{createdate}</if>
            <if test="updaterCode != null  and updaterCode != ''"> and updater_code = #{updaterCode}</if>
            <if test="updatedate != null "> and updatedate = #{updatedate}</if>
            and d.del_flag = 0
        </where>
        <!-- 数据范围过滤 -->
        ${params.dataScope}
    </select>

    <select id="selectTTrainingHisparticipantsListTask" parameterType="TTrainingHisparticipants" resultMap="TTrainingHisparticipantsResult">
        select d.id, d.staff_id, d.company_id, d.start_date, d.end_date, d.score, d.operation_score, d.training_place, d.training_duration, d.training_cost, d.budget, d.remarks, d.del_flag, d.creater_code, d.createdate, d.updater_code, d.updatedate from t_training_hisparticipants d
        <where>
            <if test="staffId != null and updaterCode != ''"> and staff_id like concat(concat('%', #{staffId}), '%')</if>
            <if test="companyId != null "> and company_id = #{companyId}</if>
            <if test="startDate != null "> and start_date = #{startDate}</if>
            <if test="endDate != null "> and end_date = #{endDate}</if>
            <if test="score != null "> and score = #{score}</if>
            <if test="operationScore != null "> and operation_score = #{operationScore}</if>
            <if test="trainingPlace != null  and trainingPlace != ''"> and training_place = #{trainingPlace}</if>
            <if test="trainingDuration != null  and trainingDuration != ''"> and training_duration = #{trainingDuration}</if>
            <if test="trainingCost != null  and trainingCost != ''"> and training_cost = #{trainingCost}</if>
            <if test="budget != null  and budget != ''"> and budget = #{budget}</if>
            <if test="remarks != null  and remarks != ''"> and remarks = #{remarks}</if>
            <if test="createrCode != null  and createrCode != ''"> and creater_code = #{createrCode}</if>
            <if test="createdate != null "> and createdate = #{createdate}</if>
            <if test="updaterCode != null  and updaterCode != ''"> and updater_code = #{updaterCode}</if>
            <if test="updatedate != null "> and updatedate = #{updatedate}</if>
            and d.del_flag = 0
        </where>
            order by start_date
    </select>

    <select id="selectTTrainingHisparticipantsById" parameterType="Long" resultMap="TTrainingHisparticipantsResult">
        <include refid="selectTTrainingHisparticipantsVo"/>
        where id = #{id}
    </select>

    <insert id="insertTTrainingHisparticipants" parameterType="TTrainingHisparticipants">
        <selectKey keyProperty="id" resultType="long" order="BEFORE">
            SELECT seq_t_training_hisparticipants.NEXTVAL as id FROM DUAL
        </selectKey>
        insert into t_training_hisparticipants
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="staffId != null">staff_id,</if>
            <if test="companyId != null">company_id,</if>
            <if test="startDate != null">start_date,</if>
            <if test="endDate != null">end_date,</if>
            <if test="score != null">score,</if>
            <if test="operationScore != null">operation_score,</if>
            <if test="trainingPlace != null">training_place,</if>
            <if test="trainingDuration != null">training_duration,</if>
            <if test="trainingCost != null">training_cost,</if>
            <if test="budget != null">budget,</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="courseCode != null">course_code,</if>
            <if test="item != null">item,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id},</if>
            <if test="staffId != null">#{staffId},</if>
            <if test="companyId != null">#{companyId},</if>
            <if test="startDate != null">#{startDate},</if>
            <if test="endDate != null">#{endDate},</if>
            <if test="score != null">#{score},</if>
            <if test="operationScore != null">#{operationScore},</if>
            <if test="trainingPlace != null">#{trainingPlace},</if>
            <if test="trainingDuration != null">#{trainingDuration},</if>
            <if test="trainingCost != null">#{trainingCost},</if>
            <if test="budget != null">#{budget},</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="courseCode != null">#{courseCode},</if>
            <if test="item != null">#{item},</if>
         </trim>
    </insert>

    <update id="updateTTrainingHisparticipants" parameterType="TTrainingHisparticipants">
        update t_training_hisparticipants
        <trim prefix="SET" suffixOverrides=",">
            <if test="staffId != null">staff_id = #{staffId},</if>
            <if test="companyId != null">company_id = #{companyId},</if>
            <if test="startDate != null">start_date = #{startDate},</if>
            <if test="endDate != null">end_date = #{endDate},</if>
            <if test="score != null">score = #{score},</if>
            <if test="operationScore != null">operation_score = #{operationScore},</if>
            <if test="trainingPlace != null">training_place = #{trainingPlace},</if>
            <if test="trainingDuration != null">training_duration = #{trainingDuration},</if>
            <if test="trainingCost != null">training_cost = #{trainingCost},</if>
            <if test="budget != null">budget = #{budget},</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="courseCode != null">course_code = #{courseCode},</if>
            <if test="item != null">item = #{item},</if>
        </trim>
        where id = #{id}
    </update>

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

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

    <delete id="duplicateHiParticipants">
        DELETE
        FROM T_TRAINING_HISPARTICIPANTS
        where rowid !=( select max(rowid)
        from T_TRAINING_HISPARTICIPANTS b
        where b.STAFF_ID = T_TRAINING_HISPARTICIPANTS.STAFF_ID
				and b.COURSE_CODE = T_TRAINING_HISPARTICIPANTS.COURSE_CODE
				and b.START_DATE = T_TRAINING_HISPARTICIPANTS.START_DATE
        )
    </delete>
</mapper>
