<?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.ma.mapper.PartRepairMapper">
    <resultMap type="com.bonus.material.ma.domain.PartRepair" id="PartRepairResult">
        <result property="partId"    column="part_id"    />
        <result property="userId"    column="user_id"    />
        <result property="companyId"    column="company_id"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateTime"    column="update_time"    />
    </resultMap>

    <sql id="selectPartRepairVo">
        select part_id, user_id, company_id, create_time, update_time from ma_part_repair
    </sql>

    <select id="selectPartRepairList" parameterType="com.bonus.material.ma.domain.PartRepair" resultMap="PartRepairResult">
        <include refid="selectPartRepairVo"/>
        <where>  
            <if test="userId != null "> and user_id = #{userId}</if>
            <if test="companyId != null  and companyId != ''"> and company_id = #{companyId}</if>
        </where>
    </select>
    
    <select id="selectPartRepairByPartId" parameterType="Long" resultMap="PartRepairResult">
        <include refid="selectPartRepairVo"/>
        where part_id = #{partId}
    </select>
        
    <insert id="insertPartRepair" parameterType="com.bonus.material.ma.domain.PartRepair" useGeneratedKeys="true" keyProperty="partId">
        insert into ma_part_repair
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="userId != null">user_id,</if>
            <if test="companyId != null">company_id,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateTime != null">update_time,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="userId != null">#{userId},</if>
            <if test="companyId != null">#{companyId},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateTime != null">#{updateTime},</if>
         </trim>
    </insert>

    <update id="updatePartRepair" parameterType="com.bonus.material.ma.domain.PartRepair">
        update ma_part_repair
        <trim prefix="SET" suffixOverrides=",">
            <if test="userId != null">user_id = #{userId},</if>
            <if test="companyId != null">company_id = #{companyId},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
        </trim>
        where part_id = #{partId}
    </update>

    <delete id="deletePartRepairByPartId" parameterType="Long">
        delete from ma_part_repair where part_id = #{partId}
    </delete>

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