<?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.TNewemployeeMapper">
    
    <resultMap type="TNewemployee" id="TNewemployeeResult">
        <result property="id"    column="id"    />
        <result property="plantCode"    column="plant_code"    />
        <result property="name"    column="name"    />
        <result property="newPostDepartment"    column="new_postdepartment"    />
        <result property="master"    column="master"    />
        <result property="masterPostDepartment"    column="master_postdepartment"    />
        <result property="agreement"    column="agreement"    />
        <result property="starttime"    column="starttime"    />
        <result property="endtime"    column="endtime"    />
        <result property="targetplan"    column="targetplan"    />
        <result property="evaluation"    column="evaluation"    />
        <result property="deptId"    column="dept_id"    />
        <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="deptName" column="dept_name" />
    </resultMap>

    <sql id="selectTNewemployeeVo">
        select d.id, d.plant_code, d.name, d.new_postdepartment, d.master, d.master_postdepartment, d.agreement, d.starttime, d.endtime, d.targetplan, d.evaluation, d.dept_id, d.del_flag, d.creater_code, d.createdate, d.updater_code, d.updatedate, d.remarks ,s.dept_name from t_newemployee d
      left join sys_dept s on s.dept_id = d.dept_id
    </sql>

    <select id="selectTNewemployeeList" parameterType="TNewemployee" resultMap="TNewemployeeResult">
        <include refid="selectTNewemployeeVo"/>
        <where>  
            <if test="name != null  and name != ''"> and name like concat(concat('%', #{name}), '%')</if>
            and d.del_flag = 0
        </where>
        <!-- 数据范围过滤 -->
        ${params.dataScope}
        order by d.id desc
    </select>
    
    <select id="selectTNewemployeeById" parameterType="Long" resultMap="TNewemployeeResult">
        <include refid="selectTNewemployeeVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertTNewemployee" parameterType="TNewemployee">
        <selectKey keyProperty="id" resultType="long" order="BEFORE">
            SELECT seq_t_newemployee.NEXTVAL as id FROM DUAL
        </selectKey>
        insert into t_newemployee
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="plantCode != null and plantCode != ''">plant_code,</if>
            <if test="name != null and name != ''">name,</if>
            <if test="newPostDepartment != null">new_postdepartment,</if>
            <if test="master != null">master,</if>
            <if test="masterPostDepartment != null">master_postdepartment,</if>
            <if test="agreement != null">agreement,</if>
            <if test="starttime != null">starttime,</if>
            <if test="endtime != null">endtime,</if>
            <if test="targetplan != null">targetplan,</if>
            <if test="evaluation != null">evaluation,</if>
            <if test="deptId != null">dept_id,</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>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id},</if>
            <if test="plantCode != null and plantCode != ''">#{plantCode},</if>
            <if test="name != null and name != ''">#{name},</if>
            <if test="newPostDepartment != null">#{newPostDepartment},</if>
            <if test="master != null">#{master},</if>
            <if test="masterPostDepartment != null">#{masterPostDepartment},</if>
            <if test="agreement != null">#{agreement},</if>
            <if test="starttime != null">#{starttime},</if>
            <if test="endtime != null">#{endtime},</if>
            <if test="targetplan != null">#{targetplan},</if>
            <if test="evaluation != null">#{evaluation},</if>
            <if test="deptId != null">#{deptId},</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>
         </trim>
    </insert>

    <update id="updateTNewemployee" parameterType="TNewemployee">
        update t_newemployee
        <trim prefix="SET" suffixOverrides=",">
            <if test="plantCode != null and plantCode != ''">plant_code = #{plantCode},</if>
            <if test="name != null and name != ''">name = #{name},</if>
            <if test="newPostDepartment != null">new_postdepartment = #{newPostDepartment},</if>
            <if test="master != null">master = #{master},</if>
            <if test="masterPostDepartment != null">master_postdepartment = #{masterPostDepartment},</if>
            <if test="agreement != null">agreement = #{agreement},</if>
            <if test="starttime != null">starttime = #{starttime},</if>
            <if test="endtime != null">endtime = #{endtime},</if>
            <if test="targetplan != null">targetplan = #{targetplan},</if>
            <if test="evaluation != null">evaluation = #{evaluation},</if>
            <if test="deptId != null">dept_id = #{deptId},</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>
        </trim>
        where id = #{id}
    </update>

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

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