<?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.tmerclub.cloud.cuerecycle.mapper.CueOrderFlawMapper">

    <!-- 可根据自己的需求，是否要使用 -->
    <resultMap id="cueOrderFlawVOMap" type="com.tmerclub.cloud.cuerecycle.model.vo.CueOrderFlawVO">
        <result property="orderFlawId" column="order_flaw_id"/>
        <result property="orderId" column="order_id"/>
        <result property="flawId" column="flaw_id"/>
        <result property="flawName" column="flaw_name"/>
        <result property="isFlaw" column="is_flaw"/>
        <result property="flawPrice" column="flaw_price"/>
    </resultMap>

    <sql id="Vo_Column_List">
        order_flaw_id,order_id,flaw_id,flaw_name,is_flaw,flaw_price
    </sql>

    <select id="list" resultMap="cueOrderFlawVOMap">
        SELECT
            <include refid="Vo_Column_List" />
        FROM
            cue_order_flaw
        <where>
            <if test="dto.orderId != null">
                AND order_id = #{dto.orderId}
            </if>
        </where>
        ORDER BY
            order_flaw_id DESC
    </select>

    <insert id="save" useGeneratedKeys="true" keyProperty="orderFlawId">
        INSERT INTO cue_order_flaw
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="orderId != null">order_id,</if>
            <if test="flawId != null">flaw_id,</if>
            <if test="flawName != null">flaw_name,</if>
            <if test="isFlaw != null">is_flaw,</if>
            <if test="flawPrice != null">flaw_price,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="orderId != null">#{orderId},</if>
            <if test="flawId != null">#{flawId},</if>
            <if test="flawName != null">#{flawName},</if>
            <if test="isFlaw != null">#{isFlaw},</if>
            <if test="flawPrice != null">#{flawPrice},</if>
        </trim>
    </insert>

    <delete id="deleteByOrderId">
        DELETE FROM cue_order_flaw WHERE order_id = #{orderId}
    </delete>
</mapper>