<?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.pine.admin.modules.business.dao.OrderSkuDao">

    <!-- 可根据自己的需求，是否要使用 -->
    <resultMap type="com.pine.admin.modules.business.entity.OrderSku" id="entityMap">
        <result property="id" column="id"/>
        <result property="orderId" column="order_id"/>
        <result property="skuId" column="sku_id"/>
        <result property="num" column="num"/>
        <result property="price" column="price"/>
        <result property="skuPrice" column="sku_price"/>
        <result property="skuName" column="sku_name"/>
        <result property="skuNo" column="sku_no"/>
        <result property="skuImage" column="sku_image"/>
        <result property="skuSpecs" column="sku_specs"/>
        <result property="priceDetail" column="price_detail"/>
        <result property="commissionRate" column="commission_rate"/>
        <result property="cateRate" column="cate_rate"/>
        <result property="oldPrice" column="old_price"/>
        <result property="supplyPrice" column="supply_price"/>
    </resultMap>

    <sql id="Base_Column_List">
                 id,
                     order_id,
                     sku_id,
                     num,
                     price,
                     sku_price,
                     sku_name,
                     sku_no,
                     sku_image,
                     sku_specs,
                     price_detail,
                     commission_rate,
                     cate_rate,
                     old_price,
                    supply_price         </sql>

    <!-- 根据Id查询-->
    <select id="selectByPrimaryKey" resultMap="entityMap" parameterType="java.lang.Integer">
        select
        <include refid="Base_Column_List"/>
        from ls_order_sku
        where id = #{id,jdbcType=INTEGER}
    </select>

    <!-- 根据Id删除-->
    <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer">
		delete from ls_order_sku
		where id = #{id,jdbcType=INTEGER}
	</delete>

    <!-- 插入数据-->
    <insert id="insertSelective" parameterType="com.pine.admin.modules.business.entity.OrderSku"
            useGeneratedKeys="true" keyProperty="id">
        insert into ls_order_sku
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="orderId != null">order_id,</if>
            <if test="skuId != null">sku_id,</if>
            <if test="num != null">num,</if>
            <if test="price != null">price,</if>
            <if test="skuPrice != null">sku_price,</if>
            <if test="skuName != null">sku_name,</if>
            <if test="skuNo != null">sku_no,</if>
            <if test="skuImage != null">sku_image,</if>
            <if test="skuSpecs != null">sku_specs,</if>
            <if test="priceDetail != null">price_detail,</if>
            <if test="commissionRate != null">commission_rate,</if>
            <if test="cateRate != null">cate_rate,</if>
            <if test="oldPrice != null">old_price,</if>
            <if test="supplyPrice != null">supply_price,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id},</if>
            <if test="orderId != null">#{orderId},</if>
            <if test="skuId != null">#{skuId},</if>
            <if test="num != null">#{num},</if>
            <if test="price != null">#{price},</if>
            <if test="skuPrice != null">#{skuPrice},</if>
            <if test="skuName != null">#{skuName},</if>
            <if test="skuNo != null">#{skuNo},</if>
            <if test="skuImage != null">#{skuImage},</if>
            <if test="skuSpecs != null">#{skuSpecs},</if>
            <if test="priceDetail != null">#{priceDetail},</if>
            <if test="commissionRate != null">#{commissionRate},</if>
            <if test="cateRate != null">#{cateRate},</if>
            <if test="oldPrice != null">#{oldPrice},</if>
            <if test="supplyPrice != null">#{supplyPrice},</if>
        </trim>
    </insert>

    <!-- 更新数据-->
    <update id="updateByPrimaryKeySelective" parameterType="com.pine.admin.modules.business.entity.OrderSku">
        update ls_order_sku
        <set>
            <if test="id != null">id = #{id},</if>
            <if test="orderId != null">order_id = #{orderId},</if>
            <if test="skuId != null">sku_id = #{skuId},</if>
            <if test="num != null">num = #{num},</if>
            <if test="price != null">price = #{price},</if>
            <if test="skuPrice != null">sku_price = #{skuPrice},</if>
            <if test="skuName != null">sku_name = #{skuName},</if>
            <if test="skuNo != null">sku_no = #{skuNo},</if>
            <if test="skuImage != null">sku_image = #{skuImage},</if>
            <if test="skuSpecs != null">sku_specs = #{skuSpecs},</if>
            <if test="priceDetail != null">price_detail = #{priceDetail},</if>
            <if test="commissionRate != null">commission_rate = #{commissionRate},</if>
            <if test="cateRate != null">cate_rate = #{cateRate},</if>
            <if test="oldPrice != null">old_price = #{oldPrice},</if>
            <if test="supplyPrice != null">supply_price = #{supplyPrice},</if>
        </set>
        where id = #{id,jdbcType=INTEGER}
    </update>

    <!-- 分页查询-->
    <select id="queryByPage" parameterType="java.util.Map"
            resultMap="entityMap">
        select
        <include refid="Base_Column_List"/>
        from ls_order_sku
        <where>
            and del_flag = 'N'
            <if test="record.id != null and !&quot;&quot;.equals(record.id)">
                and id = #{record.id}
            </if>
            <if test="record.orderId != null and !&quot;&quot;.equals(record.orderId)">
                and order_id = #{record.orderId}
            </if>
            <if test="record.skuId != null and !&quot;&quot;.equals(record.skuId)">
                and sku_id = #{record.skuId}
            </if>
            <if test="record.num != null and !&quot;&quot;.equals(record.num)">
                and num = #{record.num}
            </if>
            <if test="record.price != null and !&quot;&quot;.equals(record.price)">
                and price = #{record.price}
            </if>
            <if test="record.skuPrice != null and !&quot;&quot;.equals(record.skuPrice)">
                and sku_price = #{record.skuPrice}
            </if>
            <if test="record.skuName != null and !&quot;&quot;.equals(record.skuName)">
                and sku_name = #{record.skuName}
            </if>
            <if test="record.skuNo != null and !&quot;&quot;.equals(record.skuNo)">
                and sku_no = #{record.skuNo}
            </if>
            <if test="record.skuImage != null and !&quot;&quot;.equals(record.skuImage)">
                and sku_image = #{record.skuImage}
            </if>
            <if test="record.skuSpecs != null and !&quot;&quot;.equals(record.skuSpecs)">
                and sku_specs = #{record.skuSpecs}
            </if>
            <if test="record.priceDetail != null and !&quot;&quot;.equals(record.priceDetail)">
                and price_detail = #{record.priceDetail}
            </if>
            <if test="record.commissionRate != null and !&quot;&quot;.equals(record.commissionRate)">
                and commission_rate = #{record.commissionRate}
            </if>
            <if test="record.cateRate != null and !&quot;&quot;.equals(record.cateRate)">
                and cate_rate = #{record.cateRate}
            </if>
            <if test="record.oldPrice != null and !&quot;&quot;.equals(record.oldPrice)">
                and old_price = #{record.oldPrice}
            </if>
            <if test="record.supplyPrice != null and !&quot;&quot;.equals(record.supplyPrice)">
                and supply_price = #{record.supplyPrice}
            </if>
        </where>
        order by id desc
    </select>

    <!-- 全部查询 -->
    <select id="queryAll" parameterType="java.util.Map"
            resultMap="entityMap">
        select
        <include refid="Base_Column_List"/>
        from ls_order_sku
        <where>
            and del_flag = 'N'
            <if test="id != null and !&quot;&quot;.equals(id)">
                and id = #{id}
            </if>
            <if test="orderId != null and !&quot;&quot;.equals(orderId)">
                and order_id = #{orderId}
            </if>
            <if test="skuId != null and !&quot;&quot;.equals(skuId)">
                and sku_id = #{skuId}
            </if>
            <if test="num != null and !&quot;&quot;.equals(num)">
                and num = #{num}
            </if>
            <if test="price != null and !&quot;&quot;.equals(price)">
                and price = #{price}
            </if>
            <if test="skuPrice != null and !&quot;&quot;.equals(skuPrice)">
                and sku_price = #{skuPrice}
            </if>
            <if test="skuName != null and !&quot;&quot;.equals(skuName)">
                and sku_name = #{skuName}
            </if>
            <if test="skuNo != null and !&quot;&quot;.equals(skuNo)">
                and sku_no = #{skuNo}
            </if>
            <if test="skuImage != null and !&quot;&quot;.equals(skuImage)">
                and sku_image = #{skuImage}
            </if>
            <if test="skuSpecs != null and !&quot;&quot;.equals(skuSpecs)">
                and sku_specs = #{skuSpecs}
            </if>
            <if test="priceDetail != null and !&quot;&quot;.equals(priceDetail)">
                and price_detail = #{priceDetail}
            </if>
            <if test="commissionRate != null and !&quot;&quot;.equals(commissionRate)">
                and commission_rate = #{commissionRate}
            </if>
            <if test="cateRate != null and !&quot;&quot;.equals(cateRate)">
                and cate_rate = #{cateRate}
            </if>
            <if test="oldPrice != null and !&quot;&quot;.equals(oldPrice)">
                and old_price = #{oldPrice}
            </if>
            <if test="supplyPrice != null and !&quot;&quot;.equals(supplyPrice)">
                and supply_price = #{supplyPrice}
            </if>
        </where>
        order by id desc
    </select>

    <!-- 根据条件查询一个 -->
    <select id="queryOne" parameterType="java.util.Map"
            resultMap="entityMap">
        select
        <include refid="Base_Column_List"/>
        from ls_order_sku
        <where>
            and del_flag = 'N'
            <if test="id != null and !&quot;&quot;.equals(id)">
                and id = #{id}
            </if>
            <if test="orderId != null and !&quot;&quot;.equals(orderId)">
                and order_id = #{orderId}
            </if>
            <if test="skuId != null and !&quot;&quot;.equals(skuId)">
                and sku_id = #{skuId}
            </if>
            <if test="num != null and !&quot;&quot;.equals(num)">
                and num = #{num}
            </if>
            <if test="price != null and !&quot;&quot;.equals(price)">
                and price = #{price}
            </if>
            <if test="skuPrice != null and !&quot;&quot;.equals(skuPrice)">
                and sku_price = #{skuPrice}
            </if>
            <if test="skuName != null and !&quot;&quot;.equals(skuName)">
                and sku_name = #{skuName}
            </if>
            <if test="skuNo != null and !&quot;&quot;.equals(skuNo)">
                and sku_no = #{skuNo}
            </if>
            <if test="skuImage != null and !&quot;&quot;.equals(skuImage)">
                and sku_image = #{skuImage}
            </if>
            <if test="skuSpecs != null and !&quot;&quot;.equals(skuSpecs)">
                and sku_specs = #{skuSpecs}
            </if>
            <if test="priceDetail != null and !&quot;&quot;.equals(priceDetail)">
                and price_detail = #{priceDetail}
            </if>
            <if test="commissionRate != null and !&quot;&quot;.equals(commissionRate)">
                and commission_rate = #{commissionRate}
            </if>
            <if test="cateRate != null and !&quot;&quot;.equals(cateRate)">
                and cate_rate = #{cateRate}
            </if>
            <if test="oldPrice != null and !&quot;&quot;.equals(oldPrice)">
                and old_price = #{oldPrice}
            </if>
            <if test="supplyPrice != null and !&quot;&quot;.equals(supplyPrice)">
                and supply_price = #{supplyPrice}
            </if>
        </where>
        LIMIT 1
    </select>
    <select id="queryByOrderId" parameterType="java.lang.Long"  resultMap="entityMap">
        select   <include refid="Base_Column_List"/>  from ls_order_sku where order_id=#{orderId}
    </select>

    <update id="delete">
        UPDATE ls_order_sku SET del_flag = 'Y'
        <where>
            AND id = #{id}
        </where>
    </update>

    <update id="deleteIds" parameterType="java.util.ArrayList">
        UPDATE ls_order_sku SET del_flag = 'Y'
        WHERE id IN
        <foreach item='ids' collection="array" index="index" open="(" separator="," close=")">
            #{ids}
        </foreach>
    </update>

</mapper>
