<?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.affair.mapper.TPpeMapper">
    
    <resultMap type="TPpe" id="TPpeResult">
        <result property="id"    column="id"    />
        <result property="plantCode"    column="plant_code"    />
        <result property="name"    column="name"    />
        <result property="ppename"    column="ppename"    />
        <result property="specification"    column="specification"    />
        <result property="quantity"    column="quantity"    />
        <result property="servicetime"    column="servicetime"    />
        <result property="receiver"    column="receiver"    />
        <result property="receivedate"    column="receivedate"    />
        <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="deptId"    column="dept_id"    />
        <result property="remarks"    column="remarks"    />
        <result property="deptName" column="dept_name" />
    </resultMap>

    <sql id="selectTPpeVo">
        select d.id, d.plant_code, d.name, d.ppename, d.specification, d.quantity, d.servicetime, d.receiver, d.receivedate, d.del_flag, d.creater_code, d.createdate, d.updater_code, d.updatedate, d.dept_id, d.remarks ,s.dept_name from t_ppe d
      left join sys_dept s on s.dept_id = d.dept_id
    </sql>

    <select id="selectTPpeList" parameterType="TPpe" resultMap="TPpeResult">
        <include refid="selectTPpeVo"/>
        <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="ppename != null  and ppename != ''"> and ppename like concat(concat('%', #{ppename}), '%')</if>
            <if test="specification != null  and specification != ''"> and specification like concat(concat('%', #{specification}), '%')</if>
            <if test="quantity != null "> and quantity like concat(concat('%', #{quantity}), '%')</if>
            <if test="servicetime != null "> and servicetime = #{servicetime}</if>
            <if test="receivedate != null "> and receivedate = #{receivedate}</if>
            and d.del_flag = 0
        </where>
        <!-- 数据范围过滤 -->
        ${params.dataScope}
        order by d.id desc
    </select>

    <select id="selectList" parameterType="TPpe" resultMap="TPpeResult">
        <include refid="selectTPpeVo"/>
        <where>
            and d.del_flag = 0
        </where>
        <!-- 数据范围过滤 -->
        ${params.dataScope}
        order by d.id desc
    </select>
    
    <select id="selectTPpeById" parameterType="Long" resultMap="TPpeResult">
        <include refid="selectTPpeVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertTPpe" parameterType="TPpe">
        <selectKey keyProperty="id" resultType="long" order="BEFORE">
            SELECT seq_t_ppe.NEXTVAL as id FROM DUAL
        </selectKey>
        insert into t_ppe
        <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="ppename != null and ppename != ''">ppename,</if>
            <if test="specification != null">specification,</if>
            <if test="quantity != null">quantity,</if>
            <if test="servicetime != null">servicetime,</if>
            <if test="receiver != null">receiver,</if>
            <if test="receivedate != null">receivedate,</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="deptId != null">dept_id,</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="ppename != null and ppename != ''">#{ppename},</if>
            <if test="specification != null">#{specification},</if>
            <if test="quantity != null">#{quantity},</if>
            <if test="servicetime != null">#{servicetime},</if>
            <if test="receiver != null">#{receiver},</if>
            <if test="receivedate != null">#{receivedate},</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="deptId != null">#{deptId},</if>
            <if test="remarks != null">#{remarks},</if>
         </trim>
    </insert>

    <update id="updateTPpe" parameterType="TPpe">
        update t_ppe
        <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="ppename != null and ppename != ''">ppename = #{ppename},</if>
            <if test="specification != null">specification = #{specification},</if>
            <if test="quantity != null">quantity = #{quantity},</if>
            <if test="servicetime != null">servicetime = #{servicetime},</if>
            <if test="receiver != null">receiver = #{receiver},</if>
            <if test="receivedate != null">receivedate = #{receivedate},</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="deptId != null">dept_id = #{deptId},</if>
            <if test="remarks != null">remarks = #{remarks},</if>
        </trim>
        where id = #{id}
    </update>

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

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