Subversion Repositories SmartDukaan

Rev

Rev 5432 | Blame | Compare with Previous | Last modification | View Log | RSS feed

<?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="in.shop2020.user.persistence.CartMapper">
        
        <resultMap type="cartWithLine" id="cartWithLineResult">
                <id property="id" column="id"/>
                <collection property="lines" javaType="ArrayList" column="id" ofType="line" select="getLineByCartId"/>
        </resultMap>
        <resultMap type="cart" id="cartResult">
                <id property="id" column="id"/>
        </resultMap>
        <resultMap type="line" id="lineResult">
                <collection property="discounts" javaType="ArrayList" column="cart_id=cart_id, item_id=item_id" ofType="discount" select="getDiscounts"/>
        </resultMap>
        <resultMap type="discount" id="discountResult">
        </resultMap>
  
<insert id="createCart" parameterType="cart" useGeneratedKeys="true" keyProperty="id">
    INSERT INTO cart
    (cart_status, checked_out_on, created_on, updated_on, 
    total_price, discounted_price, coupon_code, pickupStoreId )
    VALUES
    (#{cart_status}, #{checked_out_on}, #{created_on}, #{updated_on},
    #{total_price}, #{discounted_price}, #{coupon_code}, #{pickupStoreId})
</insert>

<insert id="insertDiscount" parameterType="discount" useGeneratedKeys="true" keyProperty="id">
    INSERT INTO discount
    (line_cart_id, line_item_id, discount, quantity)
    VALUES
    (#{line_cart_id}, #{line_item_id}, #{discount}, #{quantity})
</insert>

<select id="getDiscounts" parameterType="map" resultType="discount">
        SELECT * 
        FROM discount
        <where>
        line_cart_id = #{cart_id}
        AND line_item_id = #{item_id}
        </where>
</select>

<insert id="insertLine" parameterType="line">
    INSERT INTO line
    (cart_id, item_id, quantity, line_status, estimate, created_on, updated_on, 
    actual_price)
    VALUES
    (#{cart_id}, #{item_id}, #{quantity}, #{line_status}, #{estimate}, #{created_on},
    #{updated_on}, #{actual_price})
</insert>

 <update id="updateLineQuantity" parameterType="map">
    UPDATE line
    SET quantity = #{quantity},
    updated_on = #{date}
    <where>
        cart_id = #{cartId}
        AND item_id = #{itemId}
        </where>
 </update>

<delete id="deleteDiscountForLine" parameterType="map">
    DELETE from discount
    <where>
        line_cart_id = #{cartId}
        AND line_item_id = #{itemId}
        </where>
 </delete>

<delete id="deleteLine" parameterType="map">
    DELETE from line
    <where>
        cart_id = #{cartId}
        AND item_id = #{itemId}
        </where>
 </delete>
  
  <update id="changeCartStatus" parameterType="map">
    UPDATE cart
    SET cart_status = #{status}
    <where>
        id = #{cartId}
        </where>
  </update>
  
<select id="getCart" parameterType="long" resultMap="cartWithLineResult">
    SELECT *
    FROM cart
    <where>
        id = #{id}
        </where>
</select>

<select id="getCartsByStatus" parameterType="int" resultMap="cartWithLineResult">
    SELECT *
    FROM cart
    <where>
        cart_status = #{status}
        </where>
</select>

<select id="getCartsByTime" parameterType="map" resultMap="cartWithLineResult">
    SELECT *
    FROM cart
    <where>
        cart_status = #{status}
        AND created_on &gt;= #{from_time}
        AND created_on &lt;= #{to_time}
        </where>
</select>

<select id="getCartsWithCouponCount" parameterType="String" resultType="long">
    SELECT id
    FROM cart
    <where>
        coupon_code = #{couponCode}
        </where>
</select>

<select id="getLine" parameterType="map" resultType="line">
    SELECT *
    FROM line
    <where>
        item_id = #{itemId}
        AND cart_id = #{cartId}
        <if test="status != -1">
        AND line_status = #{status}
        </if>
        </where>
        LIMIT 1
</select>

<select id="getLineByCartId" parameterType="int" resultMap="lineResult">
    SELECT *
    FROM line
    <where>
        cart_id = #{id}
        </where>
</select>


<update id="updateLine" parameterType="line">
        UPDATE line
        SET line_status = #{line_status},
        updated_on = #{updated_on},
        quantity = #{quantity},
        discounted_price = #{discounted_price},
        actual_price  = #{actual_price},
        estimate = #{estimate}
        <where>
        cart_id = #{cart_id}
        AND item_id = #{item_id}
        </where>
</update>

<update id="changeCartIdForLine" parameterType="map">
        UPDATE line
        SET cart_id = #{toCartId}
        <where>
        cart_id = #{fromCartId}
        AND item_id = #{itemId}
        </where>
</update>

<update id="updateCartUpdatedTime" parameterType="map">
        UPDATE cart
        SET updated_on = #{date}
        <where>
        id = #{cartId}
        </where>
</update>

<update id="removeLineDiscount" parameterType="map">
        UPDATE line
        SET discounted_price = NULL
        <where>
        cart_id = #{cartId}
        AND item_id = #{itemId}
        </where>
</update>

<update id="addAddressToCart" parameterType="map">
        UPDATE cart
        SET address_id = #{addressId}
        <where>
        id = #{cartId}
        </where>
</update>

<update id="updateCart" parameterType="cart">
        UPDATE cart
        SET total_price = #{total_price},
        discounted_price = #{discounted_price},
        coupon_code = #{coupon_code},
        updated_on = #{updated_on},
        checked_out_on = #{checked_out_on},
        total_price = #{total_price},
        discounted_price = #{discounted_price},
        coupon_code = #{coupon_code},
        pickupStoreId = #{pickupStoreId}
        <where>
        id = #{id}
        </where>
</update>

<update id="deActivateCart" parameterType="long">
        UPDATE cart
        SET cart_status = 1
        <where>
        id = #{id}
        </where>
</update>

</mapper>