OrderItemMapper.xml 6.2 KB
Newer Older
1 2
<?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">
sin's avatar
sin committed
3
<mapper namespace="cn.iocoder.mall.order.biz.dao.OrderItemMapper">
4 5

    <sql id="FIELDS">
sin's avatar
sin committed
6
        id, order_id, order_no, sku_id, sku_name, sku_image, order_logistics_id,
7
        quantity, origin_price, buy_price, present_price, buy_total, discount_total, present_total,
sin's avatar
sin committed
8
        payment_time, delivery_time, receiver_time, closing_time,
sin's avatar
sin committed
9 10
        has_return_exchange, delivery_type, status,
        create_time, update_time, deleted
11 12 13 14 15
    </sql>

    <!--
        插入数据
    -->
16
    <insert id="insert" useGeneratedKeys="true" keyColumn="id" keyProperty="id">
17
        INSERT INTO `order_item` (
sin's avatar
sin committed
18
            order_id, order_no, sku_id, sku_name, sku_image, order_logistics_id,
19
            quantity, origin_price, buy_price, present_price, buy_total, discount_total, present_total,
sin's avatar
sin committed
20
            payment_time, delivery_time, receiver_time, closing_time,
sin's avatar
sin committed
21 22
            has_return_exchange, delivery_type, status,
            create_time, update_time, deleted
23
        ) VALUES
24 25 26
        <foreach collection="list" item="item" separator=",">
            (#{item.orderId}, #{item.orderNo}, #{item.skuId}, #{item.skuName}, #{item.skuImage}, #{item.orderLogisticsId},
            #{item.quantity}, #{item.originPrice}, #{item.buyPrice}, #{item.presentPrice}, #{item.buyTotal}, #{item.discountTotal}, #{item.presentTotal},
27 28
            #{item.paymentTime}, #{item.deliveryTime}, #{item.receiverTime}, #{item.closingTime},
            #{item.hasReturnExchange}, #{item.deliveryType}, #{item.status},
29
            #{item.createTime}, #{item.updateTime}, #{item.deleted})
30
        </foreach>
31 32
    </insert>

sin's avatar
sin committed
33 34 35 36 37
    <!--
        更新 - 可更新的字段
    -->
    <sql id="updateFieldSql" >
        <set>
sin's avatar
sin committed
38 39 40 41 42 43
            <if test="orderItemDO.orderId != null">
                , order_id = #{orderItemDO.orderId}
            </if>
            <if test="orderItemDO.orderNo != null">
                , order_no = #{orderItemDO.orderNo}
            </if>
sin's avatar
sin committed
44 45
            <if test="orderItemDO.orderLogisticsId != null">
                , order_logistics_id = #{orderItemDO.orderLogisticsId}
sin's avatar
sin committed
46
            </if>
sin's avatar
sin committed
47 48
            <if test="orderItemDO.skuId != null">
                , sku_id = #{orderItemDO.skuId}
sin's avatar
sin committed
49
            </if>
sin's avatar
sin committed
50 51
            <if test="orderItemDO.skuName != null">
                , sku_name = #{orderItemDO.skuName}
sin's avatar
sin committed
52
            </if>
sin's avatar
sin committed
53 54
            <if test="orderItemDO.skuImage != null">
                , sku_image = #{orderItemDO.skuImage}
sin's avatar
sin committed
55
            </if>
sin's avatar
sin committed
56 57
            <if test="orderItemDO.quantity != null">
                , quantity = #{orderItemDO.quantity}
sin's avatar
sin committed
58
            </if>
59 60 61 62 63 64 65
            <!-- TODO 芋艿 需要改 -->
<!--            <if test="orderItemDO.price != null">-->
<!--                , price = #{orderItemDO.price}-->
<!--            </if>-->
<!--            <if test="orderItemDO.payAmount != null">-->
<!--                , pay_amount = #{orderItemDO.payAmount}-->
<!--            </if>-->
sin's avatar
sin committed
66

sin's avatar
sin committed
67 68
            <if test="orderItemDO.paymentTime != null">
                , payment_time = #{orderItemDO.paymentTime}
sin's avatar
sin committed
69
            </if>
sin's avatar
sin committed
70 71
            <if test="orderItemDO.deliveryTime != null">
                , delivery_time = #{orderItemDO.deliveryTime}
sin's avatar
sin committed
72
            </if>
sin's avatar
sin committed
73 74
            <if test="orderItemDO.receiverTime != null">
                , receiver_time = #{orderItemDO.receiverTime}
sin's avatar
sin committed
75
            </if>
sin's avatar
sin committed
76 77
            <if test="orderItemDO.closingTime != null">
                , closing_time = #{orderItemDO.closingTime}
sin's avatar
sin committed
78
            </if>
sin's avatar
sin committed
79

sin's avatar
sin committed
80 81
            <if test="orderItemDO.hasReturnExchange != null">
                , has_return_exchange = #{orderItemDO.hasReturnExchange}
sin's avatar
sin committed
82
            </if>
sin's avatar
sin committed
83 84
            <if test="orderItemDO.status != null">
                , status = #{orderItemDO.status}
sin's avatar
sin committed
85
            </if>
sin's avatar
sin committed
86 87
            <if test="orderItemDO.deliveryType != null">
                , delivery_type = #{orderItemDO.deliveryType}
sin's avatar
sin committed
88
            </if>
sin's avatar
sin committed
89 90
            <if test="orderItemDO.deleted != null">
                , `deleted` = #{orderItemDO.deleted}
sin's avatar
sin committed
91
            </if>
sin's avatar
sin committed
92 93
            <if test="orderItemDO.createTime != null">
                , create_time = #{orderItemDO.createTime}
sin's avatar
sin committed
94
            </if>
sin's avatar
sin committed
95 96
            <if test="orderItemDO.updateTime != null">
                , update_time = #{orderItemDO.updateTime}
sin's avatar
sin committed
97 98 99 100 101 102 103 104 105 106
            </if>
        </set>
    </sql>

    <!--
        更新 - 根据 id 更新
    -->
    <update id="updateById" parameterType="OrderDO">
        UPDATE `order_item`
        <include refid="updateFieldSql" />
sin's avatar
sin committed
107
        WHERE id = #{orderItemDO.id}
sin's avatar
sin committed
108 109 110 111 112 113 114 115 116 117 118 119 120 121
    </update>

    <!--
       更新 - 根据 ids 更新
   -->
    <update id="updateByIds">
        UPDATE `order_item`
        <include refid="updateFieldSql" />
        WHERE id IN
        <foreach collection="ids" item="id" separator="," open="(" close=")">
          #{id}
        </foreach>
    </update>

sin's avatar
sin committed
122 123 124 125 126 127
    <!--
        更新 - 根据 orderId
    -->
    <update id="updateByOrderId">
        UPDATE `order_item`
        <include refid="updateFieldSql" />
sin's avatar
sin committed
128
        WHERE order_id = #{orderId}
sin's avatar
sin committed
129 130
    </update>

131 132 133 134 135 136 137 138 139 140 141 142 143
    <!--
        获取 - 根据 ids 查询
    -->
    <select id="selectByIds" resultType="cn.iocoder.mall.order.biz.dataobject.OrderItemDO">
        SELECT
        <include refid="FIELDS" />
        FROM order_item
        WHERE `id` IN
        <foreach collection="ids" item="id" separator="," open="(" close=")">
            #{id}
        </foreach>
    </select>

sin's avatar
sin committed
144 145 146
    <!--
        查询 - 根据 orderId 下的 item
    -->
sin's avatar
sin committed
147
    <select id="selectByDeletedAndOrderId" resultType="cn.iocoder.mall.order.biz.dataobject.OrderItemDO">
sin's avatar
sin committed
148 149
        SELECT * FROM `order_item`
        WHERE 1=1
sin's avatar
sin committed
150
        <if test="deleted != null">
sin's avatar
sin committed
151 152
            AND deleted = #{deleted}
        </if>
sin's avatar
sin committed
153
        <if test="orderId != null">
sin's avatar
sin committed
154 155 156
          AND order_id = #{orderId}
        </if>
    </select>
157 158 159 160

    <!--
        查询 - 根据 orderIds 和 status
    -->
sin's avatar
sin committed
161
    <select id="selectByDeletedAndOrderIds" resultType="cn.iocoder.mall.order.biz.dataobject.OrderItemDO">
sin's avatar
sin committed
162 163 164 165
        SELECT
        <include refid="FIELDS" />
        FROM `order_item`
        WHERE `deleted` = #{deleted}
166 167
        AND `order_id`
        IN
sin's avatar
sin committed
168
        <foreach collection="orderIds" item="orderId" open="(" close=")" separator=",">
169 170 171
          #{orderId}
        </foreach>
    </select>
sin's avatar
sin committed
172
</mapper>