seatonwan9
2025-08-28 1cda9be49d77c83bdab4cfea7e3558fd4064bdb1
src/main/resources/mapper/CartMapper.xml
@@ -4,10 +4,10 @@
    
    <resultMap id="BaseResultMap" type="com.webmanage.entity.Cart">
        <id column="id" property="id" jdbcType="BIGINT"/>
        <result column="user_id" property="userId" jdbcType="BIGINT"/>
        <result column="unit_id" property="unitId" 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="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"/>
@@ -37,40 +37,48 @@
    
    <select id="selectByUserIdAndUnitId" resultMap="BaseResultMap">
        SELECT <include refid="Base_Column_List"/>
        FROM cart
        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 cart
        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 cart
        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 cart
        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 cart where id = #{id}
        delete from tb_cart where id = #{id}
    </delete>
    
</mapper>