<?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.RepairCostMapper">
    <resultMap type="com.bonus.material.repair.domain.RepairCost" id="RepairCostResult">
        <result property="id"    column="id"    />
        <result property="taskId"    column="task_id"    />
        <result property="repairId"    column="repair_id"    />
        <result property="typeId"    column="type_id"    />
        <result property="maId"    column="ma_id"    />
        <result property="repairNum"    column="repair_num"    />
        <result property="costs"    column="costs"    />
        <result property="partType"    column="part_type"    />
        <result property="status"    column="status"    />
        <result property="companyId"    column="company_id"    />
        <result property="outSourceCosts"    column="out_source_costs"    />
        <result property="repairType"    column="repair_type"    />
    </resultMap>

    <sql id="selectRepairCostVo">
        select id, task_id, repair_id, type_id, ma_id, repair_num, costs, part_type, status, company_id, out_source_costs, repair_type from repair_cost
    </sql>

    <select id="selectRepairCostList" parameterType="com.bonus.material.repair.domain.RepairCost" resultMap="RepairCostResult">
        <include refid="selectRepairCostVo"/>
        <where>  
            <if test="taskId != null "> and task_id = #{taskId}</if>
            <if test="repairId != null "> and repair_id = #{repairId}</if>
            <if test="typeId != null "> and type_id = #{typeId}</if>
            <if test="maId != null "> and ma_id = #{maId}</if>
            <if test="repairNum != null "> and repair_num = #{repairNum}</if>
            <if test="costs != null "> and costs = #{costs}</if>
            <if test="partType != null  and partType != ''"> and part_type = #{partType}</if>
            <if test="status != null  and status != ''"> and status = #{status}</if>
            <if test="companyId != null "> and company_id = #{companyId}</if>
            <if test="outSourceCosts != null "> and out_source_costs = #{outSourceCosts}</if>
            <if test="repairType != null  and repairType != ''"> and repair_type = #{repairType}</if>
        </where>
    </select>
    
    <select id="selectRepairCostById" parameterType="Long" resultMap="RepairCostResult">
        <include refid="selectRepairCostVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertRepairCost" parameterType="com.bonus.material.repair.domain.RepairCost" useGeneratedKeys="true" keyProperty="id">
        insert into repair_cost
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="taskId != null">task_id,</if>
            <if test="repairId != null">repair_id,</if>
            <if test="typeId != null">type_id,</if>
            <if test="maId != null">ma_id,</if>
            <if test="repairNum != null">repair_num,</if>
            <if test="costs != null">costs,</if>
            <if test="partType != null">part_type,</if>
            <if test="status != null">status,</if>
            <if test="companyId != null">company_id,</if>
            <if test="outSourceCosts != null">out_source_costs,</if>
            <if test="repairType != null">repair_type,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="taskId != null">#{taskId},</if>
            <if test="repairId != null">#{repairId},</if>
            <if test="typeId != null">#{typeId},</if>
            <if test="maId != null">#{maId},</if>
            <if test="repairNum != null">#{repairNum},</if>
            <if test="costs != null">#{costs},</if>
            <if test="partType != null">#{partType},</if>
            <if test="status != null">#{status},</if>
            <if test="companyId != null">#{companyId},</if>
            <if test="outSourceCosts != null">#{outSourceCosts},</if>
            <if test="repairType != null">#{repairType},</if>
         </trim>
    </insert>

    <update id="updateRepairCost" parameterType="com.bonus.material.repair.domain.RepairCost">
        update repair_cost
        <trim prefix="SET" suffixOverrides=",">
            <if test="taskId != null">task_id = #{taskId},</if>
            <if test="repairId != null">repair_id = #{repairId},</if>
            <if test="typeId != null">type_id = #{typeId},</if>
            <if test="maId != null">ma_id = #{maId},</if>
            <if test="repairNum != null">repair_num = #{repairNum},</if>
            <if test="costs != null">costs = #{costs},</if>
            <if test="partType != null">part_type = #{partType},</if>
            <if test="status != null">status = #{status},</if>
            <if test="companyId != null">company_id = #{companyId},</if>
            <if test="outSourceCosts != null">out_source_costs = #{outSourceCosts},</if>
            <if test="repairType != null">repair_type = #{repairType},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteRepairCostById" parameterType="Long">
        delete from repair_cost where id = #{id}
    </delete>

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