<?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.production.mapper.TPpePersonMapper">

    <resultMap type="TPpePerson" id="TPpePersonResult">
        <result property="id"    column="id"    />
        <result property="plantCode"    column="plant_code"    />
        <result property="name"    column="name"    />
        <result property="employeeid"    column="employeeid"    />
        <result property="classes"    column="classes"    />
        <result property="sex"    column="sex"    />
        <result property="boiler"    column="boiler"    />
        <result property="cracking"    column="cracking"    />
        <result property="hotarea"    column="hotarea"    />
        <result property="coldarea"    column="coldarea"    />
        <result property="validity"    column="validity"    />
        <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="operator"    column="operator"    />
        <result property="deptName" column="dept_name" />
    </resultMap>

    <sql id="selectTPpePersonVo">
        select d.id, d.plant_code, d.name, d.employeeid, d.classes, d.sex, d.boiler, d.cracking, d.hotarea, d.coldarea, d.validity, d.del_flag, d.creater_code, d.createdate, d.updater_code, d.updatedate, d.remarks, d.dept_id, d.operator ,s.dept_name from t_ppe_person d
      left join sys_dept s on s.dept_id = d.dept_id
    </sql>

    <select id="selectTPpePersonList" parameterType="TPpePerson" resultMap="TPpePersonResult">
        <include refid="selectTPpePersonVo"/>
        <where>
            <if test="plantCode != null  and plantCode != ''">and plant_code = #{plantCode}</if>
            <if test="name != null  and name != ''">and name like concat(concat('%', #{name}), '%')</if>
            <if test="employeeid != null  and employeeid != ''">and employeeid = #{employeeid}</if>
            <if test="classes != null  and classes != ''">and classes = #{classes}</if>
            <if test="sex != null  and sex != ''">and sex = #{sex}</if>
            <if test="boiler =='true'">and boiler = '1'</if>
            <if test="cracking =='true'">and cracking = '1'</if>
            <if test="hotarea =='true'">and hotarea = '1'</if>
            <if test="coldarea =='true'">and coldarea = '1'</if>
            <if test="validity != null ">and validity = #{validity}</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>
            <if test="remarks != null  and remarks != ''">and remarks = #{remarks}</if>
            <if test="deptId != null ">and dept_id = #{deptId}</if>
            <if test="operator =='true'">and operator = '1'</if>
            and d.del_flag = 0
        </where>
        <!-- 数据范围过滤 -->
        ${params.dataScope}
        order by classes
    </select>

    <select id="selectTPpePersonById" parameterType="Long" resultMap="TPpePersonResult">
        <include refid="selectTPpePersonVo"/>
        where id = #{id}
    </select>

    <select id="selectTPpePersonByEmployeeid" parameterType="String" resultMap="TPpePersonResult">
        <include refid="selectTPpePersonVo"/>
        where employeeid = #{employeeid}
    </select>

    <delete id="deleteTPpePersonByShiftmgr">
        delete  from t_ppe_person where EMPLOYEEID in(SELECT a.EMPLOYEEID FROM T_PPE_PERSON a MINUS SELECT b.STAFFID FROM T_STAFFMGR b where b.del_flag = 0 and b.unit='10')
    </delete>

    <insert id="insertTPpePerson" parameterType="TPpePerson">
        <selectKey keyProperty="id" resultType="long" order="BEFORE">
            SELECT seq_t_ppe_person.NEXTVAL as id FROM DUAL
        </selectKey>
        insert into t_ppe_person
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="plantCode != null and plantCode != ''">plant_code,</if>
            <if test="name != null">name,</if>
            <if test="employeeid != null">employeeid,</if>
            <if test="classes != null">classes,</if>
            <if test="sex != null">sex,</if>
            <if test="boiler != null">boiler,</if>
            <if test="cracking != null">cracking,</if>
            <if test="hotarea != null">hotarea,</if>
            <if test="coldarea != null">coldarea,</if>
            <if test="validity != null">validity,</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="operator != null">operator,</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">#{name},</if>
            <if test="employeeid != null">#{employeeid},</if>
            <if test="classes != null">#{classes},</if>
            <if test="sex != null">#{sex},</if>
            <if test="boiler != null">#{boiler},</if>
            <if test="cracking != null">#{cracking},</if>
            <if test="hotarea != null">#{hotarea},</if>
            <if test="coldarea != null">#{coldarea},</if>
            <if test="validity != null">#{validity},</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="operator != null">#{operator},</if>
         </trim>
    </insert>

    <update id="updateTPpePerson" parameterType="TPpePerson">
        update t_ppe_person
        <trim prefix="SET" suffixOverrides=",">
            <if test="plantCode != null and plantCode != ''">plant_code = #{plantCode},</if>
            <if test="name != null">name = #{name},</if>
            <if test="employeeid != null">employeeid = #{employeeid},</if>
            <if test="classes != null">classes = #{classes},</if>
            <if test="sex != null">sex = #{sex},</if>
            <if test="boiler != null">boiler = #{boiler},</if>
            <if test="cracking != null">cracking = #{cracking},</if>
            <if test="hotarea != null">hotarea = #{hotarea},</if>
            <if test="coldarea != null">coldarea = #{coldarea},</if>
            <if test="validity != null">validity = #{validity},</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="operator != null">operator = #{operator},</if>
        </trim>
        where id = #{id}
    </update>

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

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

</mapper>
