<?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.system.mapper.OrderReworkMapper">
    
    <resultMap type="OrderRework" id="OrderReworkResult">
        <result property="id"    column="id"    />
        <result property="uid"    column="uid"    />
        <result property="oid"    column="oid"    />
        <result property="orderId"    column="order_id"    />
        <result property="phone"    column="phone"    />
        <result property="mark"    column="mark"    />
        <result property="status"    column="status"    />
        <result property="createdAt"    column="created_at"    />
        <result property="updatedAt"    column="updated_at"    />
    </resultMap>

    <sql id="selectOrderReworkVo">
        select id, uid, oid, order_id, phone, mark, status, created_at, updated_at from order_rework
    </sql>

    <select id="selectOrderReworkList" parameterType="OrderRework" resultMap="OrderReworkResult">
        <include refid="selectOrderReworkVo"/>
        <where>  
            <if test="uid != null "> and uid = #{uid}</if>
            <if test="oid != null "> and oid = #{oid}</if>
            <if test="orderId != null  and orderId != ''"> and order_id like concat('%',#{orderId},'%')</if>
            <if test="phone != null  and phone != ''"> and phone like concat('%',#{phone},'%')</if>
            <if test="mark != null  and mark != ''"> and mark = #{mark}</if>
            <if test="status != null "> and status = #{status}</if>
            <if test="createdAt != null "> and created_at = #{createdAt}</if>
            <if test="updatedAt != null "> and updated_at = #{updatedAt}</if>
        </where>
    </select>
    
    <select id="selectOrderReworkById" parameterType="Long" resultMap="OrderReworkResult">
        <include refid="selectOrderReworkVo"/>
        where id = #{id}
    </select>

    <insert id="insertOrderRework" parameterType="OrderRework" useGeneratedKeys="true" keyProperty="id">
        insert into order_rework
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="uid != null">uid,</if>
            <if test="oid != null">oid,</if>
            <if test="orderId != null and orderId != ''">order_id,</if>
            <if test="phone != null and phone != ''">phone,</if>
            <if test="mark != null and mark != ''">mark,</if>
            <if test="status != null">status,</if>
            <if test="createdAt != null">created_at,</if>
            <if test="updatedAt != null">updated_at,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="uid != null">#{uid},</if>
            <if test="oid != null">#{oid},</if>
            <if test="orderId != null and orderId != ''">#{orderId},</if>
            <if test="phone != null and phone != ''">#{phone},</if>
            <if test="mark != null and mark != ''">#{mark},</if>
            <if test="status != null">#{status},</if>
            <if test="createdAt != null">#{createdAt},</if>
            <if test="updatedAt != null">#{updatedAt},</if>
         </trim>
    </insert>

    <update id="updateOrderRework" parameterType="OrderRework">
        update order_rework
        <trim prefix="SET" suffixOverrides=",">
            <if test="uid != null">uid = #{uid},</if>
            <if test="oid != null">oid = #{oid},</if>
            <if test="orderId != null and orderId != ''">order_id = #{orderId},</if>
            <if test="phone != null and phone != ''">phone = #{phone},</if>
            <if test="mark != null and mark != ''">mark = #{mark},</if>
            <if test="status != null">status = #{status},</if>
            <if test="createdAt != null">created_at = #{createdAt},</if>
            <if test="updatedAt != null">updated_at = #{updatedAt},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteOrderReworkById" parameterType="Long">
        delete from order_rework where id = #{id}
    </delete>

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