<?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.xinelu.manage.mapper.goodsOrderDetails.GoodsOrderDetailsMapper">

    <resultMap type="GoodsOrderDetails" id="GoodsOrderDetailsResult">
        <result property="id" column="id"/>
        <result property="goodsOrderId" column="goods_order_id"/>
        <result property="orderNo" column="order_no"/>
        <result property="goodsName" column="goods_name"/>
        <result property="goodsCount" column="goods_count"/>
        <result property="goodsAttributeName" column="goods_attribute_name"/>
        <result property="goodsAttributeContent" column="goods_attribute_content"/>
        <result property="goodsPrice" column="goods_price"/>
        <result property="totalPrice" column="total_price"/>
        <result property="discountPrice" column="discount_price"/>
        <result property="transportPrice" column="transport_price"/>
        <result property="giveIntegral" column="give_integral"/>
        <result property="delFlag" column="del_flag"/>
        <result property="createBy" column="create_by"/>
        <result property="createTime" column="create_time"/>
        <result property="updateBy" column="update_by"/>
        <result property="updateTime" column="update_time"/>
        <result property="couponId" column="coupon_id"/>
        <result property="integralDeductionCount" column="integral_deduction_count"/>
        <result property="integralDeductionPrice" column="integral_deduction_price"/>
        <result property="couponTitle" column="coupon_title"/>
        <result property="integralExchangeSill" column="integral_exchange_sill"/>
        <result property="integralExchangeCount" column="integral_exchange_count"/>
    </resultMap>

    <sql id="selectGoodsOrderDetailsVo">
        select id,
               goods_order_id,
               order_no,
               goods_name,
               goods_count,
               goods_attribute_name,
               goods_attribute_content,
               goods_price,
               total_price,
               discount_price,
               transport_price,
               give_integral,
               del_flag,
               create_by,
               create_time,
               update_by,
               update_time,
               coupon_id,
               integral_deduction_count,
               integral_deduction_price,
               couponTitle,
               integral_exchange_sill,
               integral_exchange_count
        from goods_order_details
    </sql>

    <select id="selectGoodsOrderDetailsList" parameterType="GoodsOrderDetails" resultMap="GoodsOrderDetailsResult">
        <include refid="selectGoodsOrderDetailsVo"/>
        <where>
            <if test="goodsOrderId != null ">
                and goods_order_id = #{goodsOrderId}
            </if>
            <if test="orderNo != null  and orderNo != ''">
                and order_no = #{orderNo}
            </if>
            <if test="goodsName != null  and goodsName != ''">
                and goods_name like concat('%', #{goodsName}, '%')
            </if>
            <if test="goodsCount != null ">
                and goods_count = #{goodsCount}
            </if>
            <if test="goodsAttributeName != null  and goodsAttributeName != ''">
                and goods_attribute_name like concat('%', #{goodsAttributeName}, '%')
            </if>
            <if test="goodsAttributeContent != null  and goodsAttributeContent != ''">
                and goods_attribute_content = #{goodsAttributeContent}
            </if>
            <if test="goodsPrice != null ">
                and goods_price = #{goodsPrice}
            </if>
            <if test="totalPrice != null ">
                and total_price = #{totalPrice}
            </if>
            <if test="discountPrice != null ">
                and discount_price = #{discountPrice}
            </if>
            <if test="transportPrice != null ">
                and transport_price = #{transportPrice}
            </if>
            <if test="giveIntegral != null ">
                and give_integral = #{giveIntegral}
            </if>
            <if test="couponId != null ">
                and coupon_id = #{couponId}
            </if>
            <if test="integralDeductionCount != null ">
                and integral_deduction_count = #{integralDeductionCount}
            </if>
            <if test="integralDeductionPrice != null ">
                and integral_deduction_price = #{integralDeductionPrice}
            </if>
        </where>
    </select>

    <select id="selectGoodsOrderDetailsById" parameterType="Long"
            resultMap="GoodsOrderDetailsResult">
        <include refid="selectGoodsOrderDetailsVo"/>
        where id = #{id}
    </select>

    <insert id="insertGoodsOrderDetails" parameterType="GoodsOrderDetails" useGeneratedKeys="true"
            keyProperty="id">
        insert into goods_order_details
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="goodsOrderId != null">goods_order_id,
            </if>
            <if test="goodsAttributeId != null">goods_attribute_id,
            </if>
            <if test="goodsAttributeDetailsId != null">goods_attribute_details_id,
            </if>
            <if test="orderNo != null">order_no,
            </if>
            <if test="goodsName != null">goods_name,
            </if>
            <if test="goodsCount != null">goods_count,
            </if>
            <if test="goodsAttributeName != null">goods_attribute_name,
            </if>
            <if test="goodsAttributeContent != null">goods_attribute_content,
            </if>
            <if test="goodsPrice != null">goods_price,
            </if>
            <if test="totalPrice != null">total_price,
            </if>
            <if test="discountPrice != null">discount_price,
            </if>
            <if test="transportPrice != null">transport_price,
            </if>
            <if test="giveIntegral != null">give_integral,
            </if>
            <if test="delFlag != null">del_flag,
            </if>
            <if test="createBy != null">create_by,
            </if>
            <if test="createTime != null">create_time,
            </if>
            <if test="updateBy != null">update_by,
            </if>
            <if test="updateTime != null">update_time,
            </if>
            <if test="couponId != null">coupon_id,
            </if>
            <if test="integralDeductionCount != null">integral_deduction_count,
            </if>
            <if test="integralDeductionPrice != null">integral_deduction_price,
            </if>
            <if test="couponTitle != null">coupon_title,
            </if>
            <if test="integralExchangeSill != null">integral_exchange_sill,
            </if>
            <if test="integralExchangeCount != null">integral_exchange_count,
            </if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="goodsOrderId != null">#{goodsOrderId},
            </if>
            <if test="goodsAttributeId != null">#{goodsAttributeId},
            </if>
            <if test="goodsAttributeDetailsId != null">#{goodsAttributeDetailsId},
            </if>
            <if test="orderNo != null">#{orderNo},
            </if>
            <if test="goodsName != null">#{goodsName},
            </if>
            <if test="goodsCount != null">#{goodsCount},
            </if>
            <if test="goodsAttributeName != null">#{goodsAttributeName},
            </if>
            <if test="goodsAttributeContent != null">#{goodsAttributeContent},
            </if>
            <if test="goodsPrice != null">#{goodsPrice},
            </if>
            <if test="totalPrice != null">#{totalPrice},
            </if>
            <if test="discountPrice != null">#{discountPrice},
            </if>
            <if test="transportPrice != null">#{transportPrice},
            </if>
            <if test="giveIntegral != null">#{giveIntegral},
            </if>
            <if test="delFlag != null">#{delFlag},
            </if>
            <if test="createBy != null">#{createBy},
            </if>
            <if test="createTime != null">#{createTime},
            </if>
            <if test="updateBy != null">#{updateBy},
            </if>
            <if test="updateTime != null">#{updateTime},
            </if>
            <if test="couponId != null">#{couponId},
            </if>
            <if test="integralDeductionCount != null">#{integralDeductionCount},
            </if>
            <if test="integralDeductionPrice != null">#{integralDeductionPrice},
            </if>
            <if test="couponTitle != null">#{couponTitle},
            </if>
            <if test="integralExchangeSill != null">#{integralExchangeSill},
            </if>
            <if test="integralExchangeCount != null">#{integralExchangeCount},
            </if>
        </trim>
    </insert>

    <update id="updateGoodsOrderDetails" parameterType="GoodsOrderDetails">
        update goods_order_details
        <trim prefix="SET" suffixOverrides=",">
            <if test="goodsOrderId != null">goods_order_id =
                #{goodsOrderId},
            </if>
            <if test="orderNo != null">order_no =
                #{orderNo},
            </if>
            <if test="goodsName != null">goods_name =
                #{goodsName},
            </if>
            <if test="goodsCount != null">goods_count =
                #{goodsCount},
            </if>
            <if test="goodsAttributeName != null">goods_attribute_name =
                #{goodsAttributeName},
            </if>
            <if test="goodsAttributeContent != null">goods_attribute_content =
                #{goodsAttributeContent},
            </if>
            <if test="goodsPrice != null">goods_price =
                #{goodsPrice},
            </if>
            <if test="totalPrice != null">total_price =
                #{totalPrice},
            </if>
            <if test="discountPrice != null">discount_price =
                #{discountPrice},
            </if>
            <if test="transportPrice != null">transport_price =
                #{transportPrice},
            </if>
            <if test="giveIntegral != null">give_integral =
                #{giveIntegral},
            </if>
            <if test="delFlag != null">del_flag =
                #{delFlag},
            </if>
            <if test="createBy != null">create_by =
                #{createBy},
            </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="couponId != null">coupon_id =
                #{couponId},
            </if>
            <if test="integralDeductionCount != null">integral_deduction_count =
                #{integralDeductionCount},
            </if>
            <if test="integralDeductionPrice != null">integral_deduction_price =
                #{integralDeductionPrice},
            </if>
            <if test="couponTitle != null">coupon_title =
                #{couponTitle},
            </if>
            <if test="integralExchangeSill != null">integral_exchange_sill =
                #{integralExchangeSill},
            </if>
            <if test="integralExchangeCount != null">integral_exchange_count =
                #{integralExchangeCount},
            </if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteGoodsOrderDetailsById" parameterType="Long">
        delete
        from goods_order_details
        where id = #{id}
    </delete>

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

    <select id="getGoodsOrderDetailInfo" resultType="goodsOrderDetails">
        select order_no,  goods_attribute_details_id, goods_count
        FROM goods_order_details
        WHERE order_no = #{orderNo}
        AND goods_attribute_details_id = #{goodsOrderDetailId}
    </select>
</mapper>
