<?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.RepairApplyRecordMapper">
    <resultMap type="com.bonus.material.repair.domain.RepairApplyRecord" id="RepairApplyRecordResult">
        <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="repairNum"    column="repair_num"    />
        <result property="scrapNum"    column="scrap_num"    />
        <result property="createBy"    column="create_by"    />
        <result property="repairType"    column="repair_type"    />
        <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="scrapReason"    column="scrap_reason"    />
        <result property="scrapType"    column="scrap_type"    />
        <result property="supplierId"    column="supplier_id"    />
        <result property="partNum"    column="part_num"    />
        <result property="partPrice"    column="part_price"    />
        <result property="repairContent"    column="repair_content"    />
        <result property="partType"    column="part_type"    />
        <result property="partName"    column="part_name"    />
        <result property="fileIds"    column="file_ids"    />
        <result property="repairer"    column="repairer"    />
        <result property="partId"    column="part_id"    />
        <result property="status"    column="status"    />
        <result property="isSlt"    column="is_slt"    />
    </resultMap>

    <sql id="selectRepairApplyRecordVo">
        select id, task_id, ma_id, type_id, repair_num, scrap_num, create_by, repair_type, create_time, update_by, update_time, remark, company_id, scrap_reason, scrap_type, supplier_id, part_num, part_price, repair_content, part_type, part_name, file_ids, repairer, part_id, status, is_slt from repair_apply_record
    </sql>

    <select id="selectRepairApplyRecordList" parameterType="com.bonus.material.repair.domain.RepairApplyRecord" resultMap="RepairApplyRecordResult">
        <include refid="selectRepairApplyRecordVo"/>
        <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="repairNum != null "> and repair_num = #{repairNum}</if>
            <if test="scrapNum != null "> and scrap_num = #{scrapNum}</if>
            <if test="repairType != null  and repairType != ''"> and repair_type = #{repairType}</if>
            <if test="companyId != null "> and company_id = #{companyId}</if>
            <if test="scrapReason != null  and scrapReason != ''"> and scrap_reason = #{scrapReason}</if>
            <if test="scrapType != null  and scrapType != ''"> and scrap_type = #{scrapType}</if>
            <if test="supplierId != null "> and supplier_id = #{supplierId}</if>
            <if test="partNum != null "> and part_num = #{partNum}</if>
            <if test="partPrice != null "> and part_price = #{partPrice}</if>
            <if test="repairContent != null  and repairContent != ''"> and repair_content = #{repairContent}</if>
            <if test="partType != null  and partType != ''"> and part_type = #{partType}</if>
            <if test="partName != null  and partName != ''"> and part_name like concat('%', #{partName}, '%')</if>
            <if test="fileIds != null  and fileIds != ''"> and file_ids = #{fileIds}</if>
            <if test="repairer != null  and repairer != ''"> and repairer = #{repairer}</if>
            <if test="partId != null "> and part_id = #{partId}</if>
            <if test="status != null "> and status = #{status}</if>
            <if test="isSlt != null "> and is_slt = #{isSlt}</if>
        </where>
    </select>
    
    <select id="selectRepairApplyRecordById" parameterType="Long" resultMap="RepairApplyRecordResult">
        <include refid="selectRepairApplyRecordVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertRepairApplyRecord" parameterType="com.bonus.material.repair.domain.RepairApplyRecord" useGeneratedKeys="true" keyProperty="id">
        insert into repair_apply_record
        <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="repairNum != null">repair_num,</if>
            <if test="scrapNum != null">scrap_num,</if>
            <if test="createBy != null">create_by,</if>
            <if test="repairType != null">repair_type,</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="scrapReason != null">scrap_reason,</if>
            <if test="scrapType != null">scrap_type,</if>
            <if test="supplierId != null">supplier_id,</if>
            <if test="partNum != null">part_num,</if>
            <if test="partPrice != null">part_price,</if>
            <if test="repairContent != null">repair_content,</if>
            <if test="partType != null">part_type,</if>
            <if test="partName != null">part_name,</if>
            <if test="fileIds != null">file_ids,</if>
            <if test="repairer != null">repairer,</if>
            <if test="partId != null">part_id,</if>
            <if test="status != null">status,</if>
            <if test="isSlt != null">is_slt,</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="repairNum != null">#{repairNum},</if>
            <if test="scrapNum != null">#{scrapNum},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="repairType != null">#{repairType},</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="scrapReason != null">#{scrapReason},</if>
            <if test="scrapType != null">#{scrapType},</if>
            <if test="supplierId != null">#{supplierId},</if>
            <if test="partNum != null">#{partNum},</if>
            <if test="partPrice != null">#{partPrice},</if>
            <if test="repairContent != null">#{repairContent},</if>
            <if test="partType != null">#{partType},</if>
            <if test="partName != null">#{partName},</if>
            <if test="fileIds != null">#{fileIds},</if>
            <if test="repairer != null">#{repairer},</if>
            <if test="partId != null">#{partId},</if>
            <if test="status != null">#{status},</if>
            <if test="isSlt != null">#{isSlt},</if>
         </trim>
    </insert>

    <update id="updateRepairApplyRecord" parameterType="com.bonus.material.repair.domain.RepairApplyRecord">
        update repair_apply_record
        <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="repairNum != null">repair_num = #{repairNum},</if>
            <if test="scrapNum != null">scrap_num = #{scrapNum},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="repairType != null">repair_type = #{repairType},</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="scrapReason != null">scrap_reason = #{scrapReason},</if>
            <if test="scrapType != null">scrap_type = #{scrapType},</if>
            <if test="supplierId != null">supplier_id = #{supplierId},</if>
            <if test="partNum != null">part_num = #{partNum},</if>
            <if test="partPrice != null">part_price = #{partPrice},</if>
            <if test="repairContent != null">repair_content = #{repairContent},</if>
            <if test="partType != null">part_type = #{partType},</if>
            <if test="partName != null">part_name = #{partName},</if>
            <if test="fileIds != null">file_ids = #{fileIds},</if>
            <if test="repairer != null">repairer = #{repairer},</if>
            <if test="partId != null">part_id = #{partId},</if>
            <if test="status != null">status = #{status},</if>
            <if test="isSlt != null">is_slt = #{isSlt},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteRepairApplyRecordById" parameterType="Long">
        delete from repair_apply_record where id = #{id}
    </delete>

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