<?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.TTrainingrecordsMapper">
    
    <resultMap type="TTrainingrecords" id="TTrainingrecordsResult">
        <result property="id"    column="id"    />
        <result property="plantCode"    column="plant_code"    />
        <result property="year"    column="year"    />
        <result property="name"    column="name"    />
        <result property="employeeid"    column="employeeid"    />
        <result property="classes"    column="classes"    />
        <result property="companysafe"    column="companysafe"    />
        <result property="plantsafe"    column="plantsafe"    />
        <result property="teamsafe"    column="teamsafe"    />
        <result property="sub"    column="sub"    />
        <result property="cracking"    column="cracking"    />
        <result property="hotarea"    column="hotarea"    />
        <result property="coldarea"    column="coldarea"    />
        <result property="aeupgu"    column="aeupgu"    />
        <result property="upscore"    column="upscore"    />
        <result property="downscore"    column="downscore"    />
        <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="deptName" column="dept_name" />
        <result property="onboard"    column="onboard"    />
        <result property="tds"    column="tds"    />
        <result property="postCard"    column="post_card"    />
        <result property="craft"    column="craft"    />
        <result property="staffId"    column="staff_id"    />
        <result property="company"    column="company"    />
        <result property="device"    column="device"    />
    </resultMap>

    <sql id="selectTTrainingrecordsVo">
        select d.id, d.plant_code,d.onboard, d.company, d.device, d.staff_id, d.tds,d.post_card,d.craft, d.year, d.name, d.employeeid, d.classes, d.companysafe, d.plantsafe, d.teamsafe, d.sub, d.cracking, d.hotarea, d.coldarea, d.aeupgu, d.upscore, d.downscore, d.del_flag, d.creater_code, d.createdate, d.updater_code, d.updatedate, d.remarks, d.dept_id ,s.dept_name from t_trainingrecords d
      left join sys_dept s on s.dept_id = d.dept_id
    </sql>

    <select id="selectTTrainingrecordsList" parameterType="TTrainingrecords" resultMap="TTrainingrecordsResult">
        <include refid="selectTTrainingrecordsVo"/>
        <where>  
            <if test="year != null "> and year = #{year}</if>
            <if test="name != null  and name != ''"> and name like concat(concat('%', #{name}), '%')</if>
            <if test="employeeid != null  and employeeid != ''"> and employeeid like concat(concat('%', #{employeeid}), '%')</if>
            <if test="classes != null  and classes != ''"> and classes = #{classes}</if>
            <if test="onboard != null  and onboard != ''"> and onboard = #{onboard}</if>
            <if test="tds != null  and tds != ''"> and tds = #{tds}</if>
            <if test="postCard  != null  and postCard != ''"> and post_card  = #{postCard}</if>
            <if test="craft != null  and craft != ''"> and craft = #{craft}</if>
            <!-- 王子文 2022年8月15日 -->
            <!-- 新增检索条件：公司级培训、装置级培训 -->
            <if test="company != null  and company != ''"> and company = #{company}</if>
            <if test="device != null and device != ''"> and device = #{device}</if>
            and d.del_flag = 0
        </where>
        <!-- 数据范围过滤 -->
        ${params.dataScope}
        <if test="sortOrder == 'desc'">
            <if test="sortDate == 'companysafe'"> ORDER BY companysafe desc</if>
            <if test="sortDate == 'plantsafe'"> ORDER BY plantsafe desc</if>
            <if test="sortDate == 'teamsafe'"> ORDER BY teamsafe desc</if>
        </if>
        <if test="sortOrder == 'asc'">
            <if test="sortDate == 'companysafe'"> ORDER BY companysafe asc</if>
            <if test="sortDate == 'plantsafe'"> ORDER BY plantsafe asc</if>
            <if test="sortDate == 'teamsafe'"> ORDER BY teamsafe asc</if>
        </if>
    </select>

    <select id="selectList" parameterType="TTrainingrecords" resultMap="TTrainingrecordsResult">
        <include refid="selectTTrainingrecordsVo"/>
        <where>
            d.del_flag = 0
        </where>
        <!-- 数据范围过滤 -->
        ${params.dataScope}
    </select>
    
    <select id="selectTTrainingrecordsById" parameterType="Long" resultMap="TTrainingrecordsResult">
        <include refid="selectTTrainingrecordsVo"/>
        where id = #{id}
    </select>

    <select id="selectTTrainingrecordsBystaffId" parameterType="Long" resultMap="TTrainingrecordsResult">
        <include refid="selectTTrainingrecordsVo"/>
        where d.staff_id = #{id}
    </select>
        
    <insert id="insertTTrainingrecords" parameterType="TTrainingrecords">
        <selectKey keyProperty="id" resultType="long" order="BEFORE">
            SELECT seq_t_trainingrecords.NEXTVAL as id FROM DUAL
        </selectKey>
        insert into t_trainingrecords
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="plantCode != null and plantCode != ''">plant_code,</if>
            <if test="year != null">year,</if>
            <if test="name != null">name,</if>
            <if test="employeeid != null">employeeid,</if>
            <if test="classes != null">classes,</if>
            <if test="companysafe != null">companysafe,</if>
            <if test="plantsafe != null">plantsafe,</if>
            <if test="teamsafe != null">teamsafe,</if>
            <if test="sub == 'true'">boiler,</if>
            <if test="cracking == 'true'">cracking,</if>
            <if test="hotarea == 'true'">hotarea,</if>
            <if test="coldarea == 'true'">coldarea,</if>
            <if test="aeupgu == 'true'">aromatic,</if>
            <if test="upscore != null">upscore,</if>
            <if test="downscore != null">downscore,</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="onboard != null">onboard,</if>
            <if test="tds != null">tds,</if>
            <if test="postCard  != null">post_card ,</if>
            <if test="craft != null">craft,</if>
            <if test="company != null">company,</if>
            <if test="device != null">device,</if>
            <if test="staffId != null">staff_id,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id},</if>
            <if test="plantCode != null and plantCode != ''">#{plantCode},</if>
            <if test="year != null">#{year},</if>
            <if test="name != null">#{name},</if>
            <if test="employeeid != null">#{employeeid},</if>
            <if test="classes != null">#{classes},</if>
            <if test="companysafe != null">#{companysafe},</if>
            <if test="plantsafe != null">#{plantsafe},</if>
            <if test="teamsafe != null">#{teamsafe},</if>
            <if test="sub == 'true'">10,</if>
            <if test="cracking == 'true'">10,</if>
            <if test="hotarea == 'true'">10,</if>
            <if test="coldarea == 'true'">10,</if>
            <if test="aeupgu == 'true'">10,</if>
            <if test="upscore != null">#{upscore},</if>
            <if test="downscore != null">#{downscore},</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="onboard != null">#{onboard},</if>
            <if test="tds != null">#{tds},</if>
            <if test="postCard  != null">#{postCard },</if>
            <if test="craft != null">#{craft},</if>
            <if test="company != null">#{company},</if>
            <if test="device != null">#{device},</if>
            <if test="staffId != null">#{staffId},</if>
        </trim>
    </insert>

    <update id="updateTTrainingrecords" parameterType="TTrainingrecords">
        update t_trainingrecords
        <trim prefix="SET" suffixOverrides=",">
            <if test="plantCode != null and plantCode != ''">plant_code = #{plantCode},</if>
            <if test="year != null">year = #{year},</if>
            <if test="name != null">name = #{name},</if>
            <if test="employeeid != null">employeeid = #{employeeid},</if>
            <if test="classes != null">classes = #{classes},</if>
            <if test="companysafe != null">companysafe = #{companysafe},</if>
            <if test="plantsafe != null">plantsafe = #{plantsafe},</if>
            <if test="teamsafe != null">teamsafe = #{teamsafe},</if>
            <if test="sub == 'true'">sub = 10,</if>
            <if test="cracking == 'true'">cracking = 10,</if>
            <if test="hotarea == 'true'">hotarea = 10,</if>
            <if test="coldarea == 'true'">coldarea = 10,</if>
            <if test="aeupgu == 'true'">aeupgu = 10,</if>
            <if test="sub == 'false'">sub = NULL,</if>
            <if test="cracking == 'false'">cracking = NULL,</if>
            <if test="hotarea == 'false'">hotarea = NULL,</if>
            <if test="coldarea == 'false'">coldarea = NULL,</if>
            <if test="aeupgu == 'false'">aeupgu = NULL,</if>
            <if test="upscore != null">upscore = #{upscore},</if>
            <if test="downscore != null">downscore = #{downscore},</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="onboard != null">onboard = #{onboard},</if>
            <if test="tds != null">tds = #{tds},</if>
            <if test="postCard  != null">post_card  = #{postCard },</if>
            <if test="craft != null">craft = #{craft},</if>
            <if test="company != null">company = #{company},</if>
            <if test="device != null">device = #{device},</if>
            <if test="staffId != null">staff_id = #{staffId},</if>
        </trim>
        where id = #{id}
    </update>

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

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