seatonwan9
2025-08-28 1cda9be49d77c83bdab4cfea7e3558fd4064bdb1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
<?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.webmanage.mapper.CartMapper">
    
    <resultMap id="BaseResultMap" type="com.webmanage.entity.Cart">
        <id column="id" property="id" jdbcType="BIGINT"/>
        <result column="user_id" property="userId" jdbcType="VARCHAR"/>
        <result column="unit_id" property="unitId" jdbcType="VARCHAR"/>
        <result column="pricing_id" property="pricingId" jdbcType="BIGINT"/>
        <result column="product_id" property="productId" jdbcType="VARCHAR"/>
        <result column="product_name" property="productName" jdbcType="VARCHAR"/>
        <result column="suite_name" property="suiteName" jdbcType="VARCHAR"/>
        <result column="sales_form" property="salesForm" jdbcType="VARCHAR"/>
        <result column="customer_type" property="customerType" jdbcType="VARCHAR"/>
        <result column="account_limit" property="accountLimit" jdbcType="VARCHAR"/>
        <result column="concurrent_nodes" property="concurrentNodes" jdbcType="VARCHAR"/>
        <result column="price_type" property="priceType" jdbcType="VARCHAR"/>
        <result column="price_unit" property="priceUnit" jdbcType="VARCHAR"/>
        <result column="unit_price" property="unitPrice" jdbcType="DECIMAL"/>
        <result column="quantity" property="quantity" jdbcType="INTEGER"/>
        <result column="duration" property="duration" jdbcType="INTEGER"/>
        <result column="total_price" property="totalPrice" jdbcType="DECIMAL"/>
        <result column="provider_id" property="providerId" jdbcType="BIGINT"/>
        <result column="provider_name" property="providerName" jdbcType="VARCHAR"/>
        <result column="remarks" property="remarks" jdbcType="VARCHAR"/>
        <result column="add_time" property="addTime" jdbcType="TIMESTAMP"/>
        <result column="update_time" property="updateTime" jdbcType="TIMESTAMP"/>
        <result column="deleted" property="deleted" jdbcType="INTEGER"/>
    </resultMap>
    
    <sql id="Base_Column_List">
        id, user_id, unit_id, pricing_id, product_id, product_name, suite_name, sales_form, 
        customer_type, account_limit, concurrent_nodes, price_type, price_unit, unit_price, 
        quantity, duration, total_price, provider_id, provider_name, remarks, add_time, 
        update_time, deleted
    </sql>
    
    <select id="selectByUserIdAndUnitId" resultMap="BaseResultMap">
        SELECT <include refid="Base_Column_List"/>
        FROM tb_cart
        WHERE deleted = 0 
        AND user_id = #{userId}
        <if test="unitId !=null and unitId != ''">
            AND unit_id = #{unitId}
        </if>
        ORDER BY add_time DESC
    </select>
    
    <select id="selectByUserIdUnitIdAndPricingId" resultMap="BaseResultMap">
        SELECT <include refid="Base_Column_List"/>
        FROM tb_cart
        WHERE deleted = 0
        AND user_id = #{userId}
        <if test="unitId != '' and unitId != null">
            AND unit_id = #{unitId}
        </if>
        AND pricing_id = #{pricingId}
        LIMIT 1
    </select>
    
    <select id="countByUserIdAndUnitId" resultType="java.lang.Integer">
        SELECT COUNT(*)
        FROM tb_cart
        WHERE deleted = 0 
        AND user_id = #{userId}
        <if test="unitId != '' and unitId != null">
            AND unit_id = #{unitId}
        </if>
    </select>
    
    <select id="sumTotalAmountByUserIdAndUnitId" resultType="java.math.BigDecimal">
        SELECT COALESCE(SUM(total_price), 0)
        FROM tb_cart
        WHERE deleted = 0 
        AND user_id = #{userId}
        <if test="unitId != '' and unitId != null">
            AND unit_id = #{unitId}
        </if>
    </select>
    <delete id="deleteByCustomerCondition">
        delete from tb_cart where id = #{id}
    </delete>
    
</mapper>