<?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.reliability.mapper.TDeviceInventoryPartsMapper">
    
    <resultMap type="TDeviceInventoryParts" id="TDeviceInventoryPartsResult">
        <result property="id"    column="id"    />
        <result property="remarks"    column="remarks"    />
        <result property="delFlag"    column="del_flag"    />
        <result property="parts"    column="parts"    />
        <result property="area"    column="area"    />
        <result property="suitDevice"    column="suit_device"    />
        <result property="inventory"    column="inventory"    />
        <result property="inventoryStatus"    column="inventory_status"    />
        <result property="importance"    column="importance"    />
        <result property="useDateOne"    column="use_date_one"    />
        <result property="useDateTwo"    column="use_date_two"    />
        <result property="replaceReason"    column="replace_reason"    />
        <result property="replaceRequirement"    column="replace_requirement"    />
        <result property="replaceChargePerson"    column="replace_charge_person"    />

    </resultMap>

    <sql id="selectTDeviceInventoryPartsVo">
        select d.id, d.remarks, d.del_flag, d.parts, d.area, d.suit_device, d.inventory, d.inventory_status, d.importance, d.use_date_one, d.use_date_two, d.replace_reason, d.replace_requirement, d.replace_charge_person  from t_device_inventory_parts d

    </sql>

    <select id="selectTDeviceInventoryPartsList" parameterType="TDeviceInventoryParts" resultMap="TDeviceInventoryPartsResult">
        <include refid="selectTDeviceInventoryPartsVo"/>
        <where>  
            <if test="remarks != null  and remarks != ''"> and remarks = #{remarks}</if>
            <if test="parts != null  and parts != ''"> and parts = #{parts}</if>
            <if test="area != null  and area != ''"> and area = #{area}</if>
            <if test="suitDevice != null  and suitDevice != ''"> and suit_device = #{suitDevice}</if>
            <if test="inventory != null "> and inventory = #{inventory}</if>
            <if test="inventoryStatus != null "> and inventory_status = #{inventoryStatus}</if>
            <if test="importance != null  and importance != ''"> and importance = #{importance}</if>
            <if test="useDateOne != null "> and use_date_one = #{useDateOne}</if>
            <if test="useDateTwo != null "> and use_date_two = #{useDateTwo}</if>
            <if test="replaceReason != null  and replaceReason != ''"> and replace_reason = #{replaceReason}</if>
            <if test="replaceRequirement != null  and replaceRequirement != ''"> and replace_requirement = #{replaceRequirement}</if>
            <if test="replaceChargePerson != null  and replaceChargePerson != ''"> and replace_charge_person = #{replaceChargePerson}</if>
            and d.del_flag = 0
        </where>
        <!-- 数据范围过滤 -->
        ${params.dataScope}
    </select>
    
    <select id="selectTDeviceInventoryPartsById" parameterType="Long" resultMap="TDeviceInventoryPartsResult">
        <include refid="selectTDeviceInventoryPartsVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertTDeviceInventoryParts" parameterType="TDeviceInventoryParts">
        <selectKey keyProperty="id" resultType="long" order="BEFORE">
            SELECT seq_t_device_inventory_parts.NEXTVAL as id FROM DUAL
        </selectKey>
        insert into t_device_inventory_parts
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="remarks != null">remarks,</if>
            <if test="delFlag != null">del_flag,</if>
            <if test="parts != null">parts,</if>
            <if test="area != null">area,</if>
            <if test="suitDevice != null">suit_device,</if>
            <if test="inventory != null">inventory,</if>
            <if test="inventoryStatus != null">inventory_status,</if>
            <if test="importance != null">importance,</if>
            <if test="useDateOne != null">use_date_one,</if>
            <if test="useDateTwo != null">use_date_two,</if>
            <if test="replaceReason != null">replace_reason,</if>
            <if test="replaceRequirement != null">replace_requirement,</if>
            <if test="replaceChargePerson != null">replace_charge_person,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id},</if>
            <if test="remarks != null">#{remarks},</if>
            <if test="delFlag != null">#{delFlag},</if>
            <if test="parts != null">#{parts},</if>
            <if test="area != null">#{area},</if>
            <if test="suitDevice != null">#{suitDevice},</if>
            <if test="inventory != null">#{inventory},</if>
            <if test="inventoryStatus != null">#{inventoryStatus},</if>
            <if test="importance != null">#{importance},</if>
            <if test="useDateOne != null">#{useDateOne},</if>
            <if test="useDateTwo != null">#{useDateTwo},</if>
            <if test="replaceReason != null">#{replaceReason},</if>
            <if test="replaceRequirement != null">#{replaceRequirement},</if>
            <if test="replaceChargePerson != null">#{replaceChargePerson},</if>
         </trim>
    </insert>

    <update id="updateTDeviceInventoryParts" parameterType="TDeviceInventoryParts">
        update t_device_inventory_parts
        <trim prefix="SET" suffixOverrides=",">
            <if test="remarks != null">remarks = #{remarks},</if>
            <if test="delFlag != null">del_flag = #{delFlag},</if>
            <if test="parts != null">parts = #{parts},</if>
            <if test="area != null">area = #{area},</if>
            <if test="suitDevice != null">suit_device = #{suitDevice},</if>
            <if test="inventory != null">inventory = #{inventory},</if>
            <if test="inventoryStatus != null">inventory_status = #{inventoryStatus},</if>
            <if test="importance != null">importance = #{importance},</if>
            <if test="useDateOne != null">use_date_one = #{useDateOne},</if>
            <if test="useDateTwo != null">use_date_two = #{useDateTwo},</if>
            <if test="replaceReason != null">replace_reason = #{replaceReason},</if>
            <if test="replaceRequirement != null">replace_requirement = #{replaceRequirement},</if>
            <if test="replaceChargePerson != null">replace_charge_person = #{replaceChargePerson},</if>
        </trim>
        where id = #{id}
    </update>

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

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