<?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.bonus.material.repair.mapper.RepairPartDetailsMapper">
    <resultMap type="com.bonus.material.repair.domain.RepairPartDetails" id="RepairPartDetailsResult">
        <result property="id"    column="id"    />
        <result property="taskId"    column="task_id"    />
        <result property="maId"    column="ma_id"    />
        <result property="typeId"    column="type_id"    />
        <result property="partId"    column="part_id"    />
        <result property="partNum"    column="part_num"    />
        <result property="partCost"    column="part_cost"    />
        <result property="partType"    column="part_type"    />
        <result property="createBy"    column="create_by"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateBy"    column="update_by"    />
        <result property="updateTime"    column="update_time"    />
        <result property="remark"    column="remark"    />
        <result property="companyId"    column="company_id"    />
        <result property="repairContent"    column="repair_content"    />
    </resultMap>

    <sql id="selectRepairPartDetailsVo">
        select id, task_id, ma_id, type_id, part_id, part_num, part_cost, part_type, create_by, create_time, update_by, update_time, remark, company_id, repair_content from repair_part_details
    </sql>

    <select id="selectRepairPartDetailsList" parameterType="com.bonus.material.repair.domain.RepairPartDetails" resultMap="RepairPartDetailsResult">
        <include refid="selectRepairPartDetailsVo"/>
        <where>  
            <if test="taskId != null "> and task_id = #{taskId}</if>
            <if test="maId != null "> and ma_id = #{maId}</if>
            <if test="typeId != null "> and type_id = #{typeId}</if>
            <if test="partId != null "> and part_id = #{partId}</if>
            <if test="partNum != null "> and part_num = #{partNum}</if>
            <if test="partCost != null "> and part_cost = #{partCost}</if>
            <if test="partType != null  and partType != ''"> and part_type = #{partType}</if>
            <if test="companyId != null "> and company_id = #{companyId}</if>
            <if test="repairContent != null  and repairContent != ''"> and repair_content = #{repairContent}</if>
        </where>
    </select>
    
    <select id="selectRepairPartDetailsById" parameterType="Long" resultMap="RepairPartDetailsResult">
        <include refid="selectRepairPartDetailsVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertRepairPartDetails" parameterType="com.bonus.material.repair.domain.RepairPartDetails" useGeneratedKeys="true" keyProperty="id">
        insert into repair_part_details
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="taskId != null">task_id,</if>
            <if test="maId != null">ma_id,</if>
            <if test="typeId != null">type_id,</if>
            <if test="partId != null">part_id,</if>
            <if test="partNum != null">part_num,</if>
            <if test="partCost != null">part_cost,</if>
            <if test="partType != null">part_type,</if>
            <if test="createBy != null">create_by,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="remark != null">remark,</if>
            <if test="companyId != null">company_id,</if>
            <if test="repairContent != null">repair_content,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="taskId != null">#{taskId},</if>
            <if test="maId != null">#{maId},</if>
            <if test="typeId != null">#{typeId},</if>
            <if test="partId != null">#{partId},</if>
            <if test="partNum != null">#{partNum},</if>
            <if test="partCost != null">#{partCost},</if>
            <if test="partType != null">#{partType},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="remark != null">#{remark},</if>
            <if test="companyId != null">#{companyId},</if>
            <if test="repairContent != null">#{repairContent},</if>
         </trim>
    </insert>

    <update id="updateRepairPartDetails" parameterType="com.bonus.material.repair.domain.RepairPartDetails">
        update repair_part_details
        <trim prefix="SET" suffixOverrides=",">
            <if test="taskId != null">task_id = #{taskId},</if>
            <if test="maId != null">ma_id = #{maId},</if>
            <if test="typeId != null">type_id = #{typeId},</if>
            <if test="partId != null">part_id = #{partId},</if>
            <if test="partNum != null">part_num = #{partNum},</if>
            <if test="partCost != null">part_cost = #{partCost},</if>
            <if test="partType != null">part_type = #{partType},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="remark != null">remark = #{remark},</if>
            <if test="companyId != null">company_id = #{companyId},</if>
            <if test="repairContent != null">repair_content = #{repairContent},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteRepairPartDetailsById" parameterType="Long">
        delete from repair_part_details where id = #{id}
    </delete>

    <delete id="deleteRepairPartDetailsByIds" parameterType="String">
        delete from repair_part_details where id in 
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>

    <delete id="deleteRepairCostByTaskId">
        delete from repair_part_details where task_id = #{taskId}
        <if test="typeId != null">
            and type_id = #{typeId}
        </if>
        <if test="maId != null">
            and ma_id = #{maId}
        </if>
    </delete>
</mapper>