初始化v1

This commit is contained in:
2026-01-11 18:14:42 +08:00
commit 641b03e8e2
297 changed files with 28656 additions and 0 deletions

View File

@@ -0,0 +1,45 @@
<?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.nlshop.mapper.AnnouncementMapper">
<resultMap id="BaseResultMap" type="com.nlshop.entity.Announcement">
<id column="id" property="id"/>
<result column="merchant_id" property="merchantId"/>
<result column="title" property="title"/>
<result column="content" property="content"/>
<result column="type" property="type"/>
<result column="status" property="status"/>
<result column="create_time" property="createTime"/>
</resultMap>
<insert id="insert" parameterType="com.nlshop.entity.Announcement" useGeneratedKeys="true" keyProperty="id">
INSERT INTO announcement (merchant_id, title, content, type, status)
VALUES (#{merchantId}, #{title}, #{content}, #{type}, #{status})
</insert>
<select id="selectByMerchantId" resultMap="BaseResultMap">
SELECT * FROM announcement WHERE merchant_id = #{merchantId} ORDER BY create_time DESC
</select>
<select id="selectPublished" resultMap="BaseResultMap">
SELECT * FROM announcement WHERE status = 1 ORDER BY create_time DESC
</select>
<select id="selectById" resultMap="BaseResultMap">
SELECT * FROM announcement WHERE id = #{id}
</select>
<update id="update" parameterType="com.nlshop.entity.Announcement">
UPDATE announcement
<set>
<if test="title != null">title = #{title},</if>
<if test="content != null">content = #{content},</if>
<if test="type != null">type = #{type},</if>
<if test="status != null">status = #{status},</if>
</set>
WHERE id = #{id}
</update>
<delete id="delete">
DELETE FROM announcement WHERE id = #{id}
</delete>
</mapper>

View File

@@ -0,0 +1,95 @@
<?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.nlshop.mapper.CartMapper">
<resultMap id="BaseResultMap" type="com.nlshop.entity.CartItem">
<id column="id" property="id"/>
<result column="user_id" property="userId"/>
<result column="product_id" property="productId"/>
<result column="spec_id" property="specId"/>
<result column="quantity" property="quantity"/>
<result column="custom_sweetness" property="customSweetness"/>
<result column="custom_ice" property="customIce"/>
<result column="toppings" property="toppings"/>
<result column="create_time" property="createTime"/>
<association property="product" javaType="com.nlshop.entity.Product">
<id column="p_id" property="id"/>
<result column="p_name" property="name"/>
<result column="p_image" property="image"/>
<result column="p_base_price" property="basePrice"/>
<result column="p_merchant_id" property="merchantId"/>
</association>
<association property="spec" javaType="com.nlshop.entity.ProductSpec">
<id column="s_id" property="id"/>
<result column="s_spec_name" property="specName"/>
<result column="s_price_adjust" property="priceAdjust"/>
</association>
</resultMap>
<insert id="insert" parameterType="com.nlshop.entity.CartItem" useGeneratedKeys="true" keyProperty="id">
INSERT INTO cart (user_id, product_id, spec_id, quantity, custom_sweetness, custom_ice, toppings)
VALUES (#{userId}, #{productId}, #{specId}, #{quantity}, #{customSweetness}, #{customIce}, #{toppings})
</insert>
<select id="selectByUserId" resultMap="BaseResultMap">
SELECT c.*,
p.id as p_id, p.name as p_name, p.image as p_image, p.base_price as p_base_price, p.merchant_id as p_merchant_id,
s.id as s_id, s.spec_name as s_spec_name, s.price_adjust as s_price_adjust
FROM cart c
LEFT JOIN product p ON c.product_id = p.id
LEFT JOIN product_spec s ON c.spec_id = s.id
WHERE c.user_id = #{userId}
ORDER BY c.create_time DESC
</select>
<select id="selectById" resultMap="BaseResultMap">
SELECT c.*,
p.id as p_id, p.name as p_name, p.image as p_image, p.base_price as p_base_price, p.merchant_id as p_merchant_id,
s.id as s_id, s.spec_name as s_spec_name, s.price_adjust as s_price_adjust
FROM cart c
LEFT JOIN product p ON c.product_id = p.id
LEFT JOIN product_spec s ON c.spec_id = s.id
WHERE c.id = #{id}
</select>
<select id="selectByUserAndProduct" resultMap="BaseResultMap">
SELECT * FROM cart
WHERE user_id = #{userId} AND product_id = #{productId}
AND (spec_id = #{specId} OR (#{specId} IS NULL AND spec_id IS NULL))
AND (custom_sweetness = #{customSweetness} OR (#{customSweetness} IS NULL AND custom_sweetness IS NULL))
AND (custom_ice = #{customIce} OR (#{customIce} IS NULL AND custom_ice IS NULL))
AND (toppings = #{toppings} OR (#{toppings} IS NULL AND toppings IS NULL))
LIMIT 1
</select>
<update id="update" parameterType="com.nlshop.entity.CartItem">
UPDATE cart
<set>
<if test="quantity != null">quantity = #{quantity},</if>
<if test="customSweetness != null">custom_sweetness = #{customSweetness},</if>
<if test="customIce != null">custom_ice = #{customIce},</if>
<if test="toppings != null">toppings = #{toppings},</if>
</set>
WHERE id = #{id}
</update>
<update id="updateQuantity">
UPDATE cart SET quantity = #{quantity} WHERE id = #{id}
</update>
<delete id="delete">
DELETE FROM cart WHERE id = #{id}
</delete>
<delete id="deleteByUserId">
DELETE FROM cart WHERE user_id = #{userId}
</delete>
<delete id="deleteBatch">
DELETE FROM cart
WHERE id IN
<foreach collection="ids" item="id" open="(" separator="," close=")">
#{id}
</foreach>
AND user_id = #{userId}
</delete>
</mapper>

View File

@@ -0,0 +1,21 @@
<?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.nlshop.mapper.InventoryLogMapper">
<resultMap id="BaseResultMap" type="com.nlshop.entity.InventoryLog">
<id column="id" property="id"/>
<result column="inventory_id" property="inventoryId"/>
<result column="operation_type" property="operationType"/>
<result column="quantity" property="quantity"/>
<result column="operator" property="operator"/>
<result column="create_time" property="createTime"/>
</resultMap>
<insert id="insert" parameterType="com.nlshop.entity.InventoryLog" useGeneratedKeys="true" keyProperty="id">
INSERT INTO inventory_log (inventory_id, operation_type, quantity, operator)
VALUES (#{inventoryId}, #{operationType}, #{quantity}, #{operator})
</insert>
<select id="selectByInventoryId" resultMap="BaseResultMap">
SELECT * FROM inventory_log WHERE inventory_id = #{inventoryId} ORDER BY create_time DESC
</select>
</mapper>

View File

@@ -0,0 +1,55 @@
<?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.nlshop.mapper.InventoryMapper">
<resultMap id="BaseResultMap" type="com.nlshop.entity.Inventory">
<id column="id" property="id"/>
<result column="merchant_id" property="merchantId"/>
<result column="material_name" property="materialName"/>
<result column="quantity" property="quantity"/>
<result column="unit" property="unit"/>
<result column="min_threshold" property="minThreshold"/>
<result column="last_in_time" property="lastInTime"/>
<result column="last_out_time" property="lastOutTime"/>
</resultMap>
<insert id="insert" parameterType="com.nlshop.entity.Inventory" useGeneratedKeys="true" keyProperty="id">
INSERT INTO inventory (merchant_id, material_name, quantity, unit, min_threshold)
VALUES (#{merchantId}, #{materialName}, #{quantity}, #{unit}, #{minThreshold})
</insert>
<select id="selectByMerchantId" resultMap="BaseResultMap">
SELECT * FROM inventory WHERE merchant_id = #{merchantId} ORDER BY material_name
</select>
<select id="selectById" resultMap="BaseResultMap">
SELECT * FROM inventory WHERE id = #{id}
</select>
<select id="selectByMerchantAndMaterial" resultMap="BaseResultMap">
SELECT * FROM inventory
WHERE merchant_id = #{merchantId} AND material_name = #{materialName}
LIMIT 1
</select>
<select id="selectLowStock" resultMap="BaseResultMap">
SELECT * FROM inventory
WHERE merchant_id = #{merchantId} AND quantity &lt;= min_threshold
ORDER BY quantity ASC
</select>
<update id="update" parameterType="com.nlshop.entity.Inventory">
UPDATE inventory
<set>
<if test="quantity != null">quantity = #{quantity},</if>
<if test="unit != null">unit = #{unit},</if>
<if test="minThreshold != null">min_threshold = #{minThreshold},</if>
<if test="lastInTime != null">last_in_time = #{lastInTime},</if>
<if test="lastOutTime != null">last_out_time = #{lastOutTime},</if>
</set>
WHERE id = #{id}
</update>
<delete id="delete">
DELETE FROM inventory WHERE id = #{id}
</delete>
</mapper>

View File

@@ -0,0 +1,43 @@
<?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.nlshop.mapper.MerchantMapper">
<resultMap id="BaseResultMap" type="com.nlshop.entity.Merchant">
<id column="id" property="id"/>
<result column="username" property="username"/>
<result column="password" property="password"/>
<result column="store_name" property="storeName"/>
<result column="address" property="address"/>
<result column="phone" property="phone"/>
<result column="email" property="email"/>
<result column="manager_name" property="managerName"/>
<result column="avatar" property="avatar"/>
<result column="create_time" property="createTime"/>
<result column="update_time" property="updateTime"/>
</resultMap>
<insert id="insert" parameterType="com.nlshop.entity.Merchant" useGeneratedKeys="true" keyProperty="id">
INSERT INTO merchant (username, password, store_name, address, phone, email, manager_name, avatar)
VALUES (#{username}, #{password}, #{storeName}, #{address}, #{phone}, #{email}, #{managerName}, #{avatar})
</insert>
<select id="selectById" resultMap="BaseResultMap">
SELECT * FROM merchant WHERE id = #{id}
</select>
<select id="selectByUsername" resultMap="BaseResultMap">
SELECT * FROM merchant WHERE username = #{username}
</select>
<update id="update" parameterType="com.nlshop.entity.Merchant">
UPDATE merchant
<set>
<if test="storeName != null">store_name = #{storeName},</if>
<if test="address != null">address = #{address},</if>
<if test="phone != null">phone = #{phone},</if>
<if test="email != null">email = #{email},</if>
<if test="managerName != null">manager_name = #{managerName},</if>
<if test="avatar != null">avatar = #{avatar},</if>
</set>
WHERE id = #{id}
</update>
</mapper>

View File

@@ -0,0 +1,42 @@
<?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.nlshop.mapper.MessageMapper">
<resultMap id="BaseResultMap" type="com.nlshop.entity.Message">
<id column="id" property="id"/>
<result column="user_id" property="userId"/>
<result column="merchant_id" property="merchantId"/>
<result column="order_id" property="orderId"/>
<result column="content" property="content"/>
<result column="reply" property="reply"/>
<result column="status" property="status"/>
<result column="create_time" property="createTime"/>
<result column="reply_time" property="replyTime"/>
</resultMap>
<insert id="insert" parameterType="com.nlshop.entity.Message" useGeneratedKeys="true" keyProperty="id">
INSERT INTO message (user_id, merchant_id, order_id, content, status)
VALUES (#{userId}, #{merchantId}, #{orderId}, #{content}, #{status})
</insert>
<select id="selectByUserId" resultMap="BaseResultMap">
SELECT * FROM message WHERE user_id = #{userId} ORDER BY create_time DESC
</select>
<select id="selectByMerchantId" resultMap="BaseResultMap">
SELECT * FROM message WHERE merchant_id = #{merchantId} ORDER BY create_time DESC
</select>
<select id="selectById" resultMap="BaseResultMap">
SELECT * FROM message WHERE id = #{id}
</select>
<update id="update" parameterType="com.nlshop.entity.Message">
UPDATE message
<set>
<if test="reply != null">reply = #{reply},</if>
<if test="status != null">status = #{status},</if>
<if test="replyTime != null">reply_time = #{replyTime},</if>
</set>
WHERE id = #{id}
</update>
</mapper>

View File

@@ -0,0 +1,32 @@
<?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.nlshop.mapper.OrderItemMapper">
<resultMap id="BaseResultMap" type="com.nlshop.entity.OrderItem">
<id column="id" property="id"/>
<result column="order_id" property="orderId"/>
<result column="product_id" property="productId"/>
<result column="product_name" property="productName"/>
<result column="spec_name" property="specName"/>
<result column="quantity" property="quantity"/>
<result column="price" property="price"/>
<result column="custom_sweetness" property="customSweetness"/>
<result column="custom_ice" property="customIce"/>
<result column="toppings" property="toppings"/>
<result column="subtotal" property="subtotal"/>
</resultMap>
<insert id="insert" parameterType="com.nlshop.entity.OrderItem" useGeneratedKeys="true" keyProperty="id">
INSERT INTO order_item (order_id, product_id, product_name, spec_name, quantity, price,
custom_sweetness, custom_ice, toppings, subtotal)
VALUES (#{orderId}, #{productId}, #{productName}, #{specName}, #{quantity}, #{price},
#{customSweetness}, #{customIce}, #{toppings}, #{subtotal})
</insert>
<select id="selectByOrderId" resultMap="BaseResultMap">
SELECT * FROM order_item WHERE order_id = #{orderId}
</select>
<select id="selectById" resultMap="BaseResultMap">
SELECT * FROM order_item WHERE id = #{id}
</select>
</mapper>

View File

@@ -0,0 +1,107 @@
<?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.nlshop.mapper.OrderMapper">
<resultMap id="BaseResultMap" type="com.nlshop.entity.Order">
<id column="id" property="id"/>
<result column="order_no" property="orderNo"/>
<result column="user_id" property="userId"/>
<result column="merchant_id" property="merchantId"/>
<result column="total_amount" property="totalAmount"/>
<result column="payment_method" property="paymentMethod"/>
<result column="payment_status" property="paymentStatus"/>
<result column="order_status" property="orderStatus"/>
<result column="address" property="address"/>
<result column="contact_phone" property="contactPhone"/>
<result column="create_time" property="createTime"/>
<result column="pay_time" property="payTime"/>
<result column="complete_time" property="completeTime"/>
<association property="merchant" javaType="com.nlshop.entity.Merchant">
<id column="m_id" property="id"/>
<result column="m_store_name" property="storeName"/>
</association>
</resultMap>
<insert id="insert" parameterType="com.nlshop.entity.Order" useGeneratedKeys="true" keyProperty="id">
INSERT INTO `order` (order_no, user_id, merchant_id, total_amount, payment_method,
payment_status, order_status, address, contact_phone, pay_time, complete_time)
VALUES (#{orderNo}, #{userId}, #{merchantId}, #{totalAmount}, #{paymentMethod},
#{paymentStatus}, #{orderStatus}, #{address}, #{contactPhone}, #{payTime}, #{completeTime})
</insert>
<select id="selectById" resultMap="BaseResultMap">
SELECT o.*, m.id as m_id, m.store_name as m_store_name
FROM `order` o
LEFT JOIN merchant m ON o.merchant_id = m.id
WHERE o.id = #{id}
</select>
<select id="selectByOrderNo" resultMap="BaseResultMap">
SELECT * FROM `order` WHERE order_no = #{orderNo}
</select>
<select id="selectByUserId" resultMap="BaseResultMap">
SELECT o.*, m.id as m_id, m.store_name as m_store_name
FROM `order` o
LEFT JOIN merchant m ON o.merchant_id = m.id
WHERE o.user_id = #{userId}
<if test="status != null and status != ''">
AND o.order_status = #{status}
</if>
ORDER BY o.create_time DESC
</select>
<select id="selectByMerchantId" resultMap="BaseResultMap">
SELECT o.*, m.id as m_id, m.store_name as m_store_name
FROM `order` o
LEFT JOIN merchant m ON o.merchant_id = m.id
WHERE o.merchant_id = #{merchantId}
<if test="status != null and status != ''">
AND o.order_status = #{status}
</if>
ORDER BY o.create_time DESC
</select>
<update id="update" parameterType="com.nlshop.entity.Order">
UPDATE `order`
<set>
<if test="totalAmount != null">total_amount = #{totalAmount},</if>
<if test="paymentMethod != null">payment_method = #{paymentMethod},</if>
<if test="paymentStatus != null">payment_status = #{paymentStatus},</if>
<if test="orderStatus != null">order_status = #{orderStatus},</if>
<if test="address != null">address = #{address},</if>
<if test="contactPhone != null">contact_phone = #{contactPhone},</if>
<if test="payTime != null">pay_time = #{payTime},</if>
<if test="completeTime != null">complete_time = #{completeTime},</if>
</set>
WHERE id = #{id}
</update>
<update id="updateStatus">
UPDATE `order` SET order_status = #{status} WHERE id = #{id}
</update>
<update id="updatePayment">
UPDATE `order`
SET payment_status = #{paymentStatus},
payment_method = #{paymentMethod},
pay_time = NOW()
WHERE id = #{id}
</update>
<select id="selectStickyUsers" resultType="java.util.HashMap">
SELECT
u.id as userId,
u.username,
u.name,
COUNT(o.id) as orderCount,
SUM(o.total_amount) as totalAmount
FROM `order` o
INNER JOIN user u ON o.user_id = u.id
WHERE o.merchant_id = #{merchantId}
AND o.order_status = 'COMPLETED'
AND o.create_time >= DATE_SUB(NOW(), INTERVAL #{days} DAY)
GROUP BY u.id, u.username, u.name
HAVING COUNT(o.id) >= #{minOrders}
ORDER BY orderCount DESC, totalAmount DESC
</select>
</mapper>

View File

@@ -0,0 +1,20 @@
<?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.nlshop.mapper.OrderTrackMapper">
<resultMap id="BaseResultMap" type="com.nlshop.entity.OrderTrack">
<id column="id" property="id"/>
<result column="order_id" property="orderId"/>
<result column="status" property="status"/>
<result column="description" property="description"/>
<result column="create_time" property="createTime"/>
</resultMap>
<insert id="insert" parameterType="com.nlshop.entity.OrderTrack" useGeneratedKeys="true" keyProperty="id">
INSERT INTO order_track (order_id, status, description)
VALUES (#{orderId}, #{status}, #{description})
</insert>
<select id="selectByOrderId" resultMap="BaseResultMap">
SELECT * FROM order_track WHERE order_id = #{orderId} ORDER BY create_time ASC
</select>
</mapper>

View File

@@ -0,0 +1,38 @@
<?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.nlshop.mapper.ProductCustomMapper">
<resultMap id="BaseResultMap" type="com.nlshop.entity.ProductCustom">
<id column="id" property="id"/>
<result column="product_id" property="productId"/>
<result column="option_type" property="optionType"/>
<result column="option_value" property="optionValue"/>
<result column="price_adjust" property="priceAdjust"/>
</resultMap>
<insert id="insert" parameterType="com.nlshop.entity.ProductCustom" useGeneratedKeys="true" keyProperty="id">
INSERT INTO product_custom (product_id, option_type, option_value, price_adjust)
VALUES (#{productId}, #{optionType}, #{optionValue}, #{priceAdjust})
</insert>
<select id="selectByProductId" resultMap="BaseResultMap">
SELECT * FROM product_custom WHERE product_id = #{productId}
</select>
<select id="selectById" resultMap="BaseResultMap">
SELECT * FROM product_custom WHERE id = #{id}
</select>
<update id="update" parameterType="com.nlshop.entity.ProductCustom">
UPDATE product_custom
SET option_type = #{optionType}, option_value = #{optionValue}, price_adjust = #{priceAdjust}
WHERE id = #{id}
</update>
<delete id="delete">
DELETE FROM product_custom WHERE id = #{id}
</delete>
<delete id="deleteByProductId">
DELETE FROM product_custom WHERE product_id = #{productId}
</delete>
</mapper>

View File

@@ -0,0 +1,71 @@
<?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.nlshop.mapper.ProductMapper">
<resultMap id="BaseResultMap" type="com.nlshop.entity.Product">
<id column="id" property="id"/>
<result column="merchant_id" property="merchantId"/>
<result column="name" property="name"/>
<result column="category" property="category"/>
<result column="description" property="description"/>
<result column="base_price" property="basePrice"/>
<result column="image" property="image"/>
<result column="status" property="status"/>
<result column="create_time" property="createTime"/>
</resultMap>
<insert id="insert" parameterType="com.nlshop.entity.Product" useGeneratedKeys="true" keyProperty="id">
INSERT INTO product (merchant_id, name, category, description, base_price, image, status)
VALUES (#{merchantId}, #{name}, #{category}, #{description}, #{basePrice}, #{image}, #{status})
</insert>
<select id="selectById" resultMap="BaseResultMap">
SELECT * FROM product WHERE id = #{id}
</select>
<select id="selectByMerchantId" resultMap="BaseResultMap">
SELECT * FROM product WHERE merchant_id = #{merchantId}
<if test="status != null">
AND status = #{status}
</if>
ORDER BY create_time DESC
</select>
<select id="selectAll" resultMap="BaseResultMap">
SELECT * FROM product WHERE 1=1
<if test="category != null and category != ''">
AND category = #{category}
</if>
<if test="status != null">
AND status = #{status}
</if>
ORDER BY create_time DESC
</select>
<select id="selectHotProducts" resultMap="BaseResultMap">
SELECT p.*, SUM(oi.quantity) as sales
FROM product p
LEFT JOIN order_item oi ON p.id = oi.product_id
LEFT JOIN `order` o ON oi.order_id = o.id
WHERE o.order_status = 'COMPLETED' AND p.status = 1
GROUP BY p.id
ORDER BY sales DESC
LIMIT #{limit}
</select>
<update id="update" parameterType="com.nlshop.entity.Product">
UPDATE product
<set>
<if test="name != null">name = #{name},</if>
<if test="category != null">category = #{category},</if>
<if test="description != null">description = #{description},</if>
<if test="basePrice != null">base_price = #{basePrice},</if>
<if test="image != null">image = #{image},</if>
<if test="status != null">status = #{status},</if>
</set>
WHERE id = #{id}
</update>
<update id="updateStatus">
UPDATE product SET status = #{status} WHERE id = #{id}
</update>
</mapper>

View File

@@ -0,0 +1,37 @@
<?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.nlshop.mapper.ProductSpecMapper">
<resultMap id="BaseResultMap" type="com.nlshop.entity.ProductSpec">
<id column="id" property="id"/>
<result column="product_id" property="productId"/>
<result column="spec_name" property="specName"/>
<result column="price_adjust" property="priceAdjust"/>
</resultMap>
<insert id="insert" parameterType="com.nlshop.entity.ProductSpec" useGeneratedKeys="true" keyProperty="id">
INSERT INTO product_spec (product_id, spec_name, price_adjust)
VALUES (#{productId}, #{specName}, #{priceAdjust})
</insert>
<select id="selectByProductId" resultMap="BaseResultMap">
SELECT * FROM product_spec WHERE product_id = #{productId}
</select>
<select id="selectById" resultMap="BaseResultMap">
SELECT * FROM product_spec WHERE id = #{id}
</select>
<update id="update" parameterType="com.nlshop.entity.ProductSpec">
UPDATE product_spec
SET spec_name = #{specName}, price_adjust = #{priceAdjust}
WHERE id = #{id}
</update>
<delete id="delete">
DELETE FROM product_spec WHERE id = #{id}
</delete>
<delete id="deleteByProductId">
DELETE FROM product_spec WHERE product_id = #{productId}
</delete>
</mapper>

View File

@@ -0,0 +1,37 @@
<?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.nlshop.mapper.ProductToppingMapper">
<resultMap id="BaseResultMap" type="com.nlshop.entity.ProductTopping">
<id column="id" property="id"/>
<result column="product_id" property="productId"/>
<result column="topping_name" property="toppingName"/>
<result column="price" property="price"/>
</resultMap>
<insert id="insert" parameterType="com.nlshop.entity.ProductTopping" useGeneratedKeys="true" keyProperty="id">
INSERT INTO product_topping (product_id, topping_name, price)
VALUES (#{productId}, #{toppingName}, #{price})
</insert>
<select id="selectByProductId" resultMap="BaseResultMap">
SELECT * FROM product_topping WHERE product_id = #{productId}
</select>
<select id="selectById" resultMap="BaseResultMap">
SELECT * FROM product_topping WHERE id = #{id}
</select>
<update id="update" parameterType="com.nlshop.entity.ProductTopping">
UPDATE product_topping
SET topping_name = #{toppingName}, price = #{price}
WHERE id = #{id}
</update>
<delete id="delete">
DELETE FROM product_topping WHERE id = #{id}
</delete>
<delete id="deleteByProductId">
DELETE FROM product_topping WHERE product_id = #{productId}
</delete>
</mapper>

View File

@@ -0,0 +1,53 @@
<?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.nlshop.mapper.ReviewMapper">
<resultMap id="BaseResultMap" type="com.nlshop.entity.Review">
<id column="id" property="id"/>
<result column="user_id" property="userId"/>
<result column="order_id" property="orderId"/>
<result column="product_id" property="productId"/>
<result column="rating" property="rating"/>
<result column="content" property="content"/>
<result column="reply" property="reply"/>
<result column="create_time" property="createTime"/>
</resultMap>
<insert id="insert" parameterType="com.nlshop.entity.Review" useGeneratedKeys="true" keyProperty="id">
INSERT INTO review (user_id, order_id, product_id, rating, content)
VALUES (#{userId}, #{orderId}, #{productId}, #{rating}, #{content})
</insert>
<select id="selectByMerchantId" resultMap="BaseResultMap">
SELECT r.* FROM review r
INNER JOIN product p ON r.product_id = p.id
WHERE p.merchant_id = #{merchantId}
ORDER BY r.create_time DESC
</select>
<select id="selectByProductId" resultMap="BaseResultMap">
SELECT * FROM review WHERE product_id = #{productId} ORDER BY create_time DESC
</select>
<select id="selectById" resultMap="BaseResultMap">
SELECT * FROM review WHERE id = #{id}
</select>
<select id="selectByOrderId" resultMap="BaseResultMap">
SELECT * FROM review WHERE order_id = #{orderId} LIMIT 1
</select>
<select id="selectByOrderIdList" resultMap="BaseResultMap">
SELECT * FROM review WHERE order_id IN
<foreach collection="orderIds" item="orderId" open="(" separator="," close=")">
#{orderId}
</foreach>
</select>
<update id="update" parameterType="com.nlshop.entity.Review">
UPDATE review
<set>
<if test="reply != null">reply = #{reply},</if>
</set>
WHERE id = #{id}
</update>
</mapper>

View File

@@ -0,0 +1,45 @@
<?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.nlshop.mapper.UserAddressMapper">
<resultMap id="BaseResultMap" type="com.nlshop.entity.UserAddress">
<id column="id" property="id"/>
<result column="user_id" property="userId"/>
<result column="address" property="address"/>
<result column="contact_name" property="contactName"/>
<result column="contact_phone" property="contactPhone"/>
<result column="is_default" property="isDefault"/>
<result column="create_time" property="createTime"/>
</resultMap>
<insert id="insert" parameterType="com.nlshop.entity.UserAddress" useGeneratedKeys="true" keyProperty="id">
INSERT INTO user_address (user_id, address, contact_name, contact_phone, is_default)
VALUES (#{userId}, #{address}, #{contactName}, #{contactPhone}, #{isDefault})
</insert>
<select id="selectByUserId" resultMap="BaseResultMap">
SELECT * FROM user_address WHERE user_id = #{userId} ORDER BY is_default DESC, create_time DESC
</select>
<select id="selectById" resultMap="BaseResultMap">
SELECT * FROM user_address WHERE id = #{id}
</select>
<select id="selectDefaultByUserId" resultMap="BaseResultMap">
SELECT * FROM user_address WHERE user_id = #{userId} AND is_default = 1 LIMIT 1
</select>
<update id="update" parameterType="com.nlshop.entity.UserAddress">
UPDATE user_address
<set>
<if test="address != null">address = #{address},</if>
<if test="contactName != null">contact_name = #{contactName},</if>
<if test="contactPhone != null">contact_phone = #{contactPhone},</if>
<if test="isDefault != null">is_default = #{isDefault},</if>
</set>
WHERE id = #{id}
</update>
<delete id="delete">
DELETE FROM user_address WHERE id = #{id}
</delete>
</mapper>

View File

@@ -0,0 +1,62 @@
<?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.nlshop.mapper.UserBehaviorMapper">
<resultMap id="BaseResultMap" type="com.nlshop.entity.UserBehavior">
<id column="id" property="id"/>
<result column="user_id" property="userId"/>
<result column="product_id" property="productId"/>
<result column="behavior_type" property="behaviorType"/>
<result column="score" property="score"/>
<result column="create_time" property="createTime"/>
</resultMap>
<insert id="insert" parameterType="com.nlshop.entity.UserBehavior" useGeneratedKeys="true" keyProperty="id">
INSERT INTO user_behavior (user_id, product_id, behavior_type, score)
VALUES (#{userId}, #{productId}, #{behaviorType}, #{score})
</insert>
<select id="selectByUserId" resultMap="BaseResultMap">
SELECT * FROM user_behavior WHERE user_id = #{userId} ORDER BY create_time DESC
</select>
<select id="selectByProductId" resultMap="BaseResultMap">
SELECT * FROM user_behavior WHERE product_id = #{productId} ORDER BY create_time DESC
</select>
<select id="selectByUserAndProduct" resultMap="BaseResultMap">
SELECT * FROM user_behavior
WHERE user_id = #{userId} AND product_id = #{productId} AND behavior_type = #{behaviorType}
LIMIT 1
</select>
<update id="update" parameterType="com.nlshop.entity.UserBehavior">
UPDATE user_behavior
SET score = #{score}, create_time = NOW()
WHERE id = #{id}
</update>
<select id="selectProductIdsByUserId" resultType="java.lang.Long">
SELECT DISTINCT product_id FROM user_behavior WHERE user_id = #{userId}
</select>
<select id="selectUserIdsByProductId" resultType="java.lang.Long">
SELECT DISTINCT user_id FROM user_behavior WHERE product_id = #{productId}
</select>
<select id="selectActiveUsers" resultType="java.util.HashMap">
SELECT
u.id as userId,
u.username,
u.name,
COUNT(ub.id) as viewCount,
MAX(ub.create_time) as lastViewTime
FROM user_behavior ub
INNER JOIN user u ON ub.user_id = u.id
INNER JOIN product p ON ub.product_id = p.id
WHERE ub.behavior_type = 'VIEW'
AND p.merchant_id = #{merchantId}
AND ub.create_time >= DATE_SUB(NOW(), INTERVAL #{days} DAY)
GROUP BY u.id, u.username, u.name
ORDER BY lastViewTime DESC
</select>
</mapper>

View File

@@ -0,0 +1,51 @@
<?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.nlshop.mapper.UserMapper">
<resultMap id="BaseResultMap" type="com.nlshop.entity.User">
<id column="id" property="id"/>
<result column="username" property="username"/>
<result column="password" property="password"/>
<result column="name" property="name"/>
<result column="gender" property="gender"/>
<result column="phone" property="phone"/>
<result column="email" property="email"/>
<result column="avatar" property="avatar"/>
<result column="address" property="address"/>
<result column="create_time" property="createTime"/>
<result column="update_time" property="updateTime"/>
</resultMap>
<insert id="insert" parameterType="com.nlshop.entity.User" useGeneratedKeys="true" keyProperty="id">
INSERT INTO user (username, password, name, gender, phone, email, avatar, address)
VALUES (#{username}, #{password}, #{name}, #{gender}, #{phone}, #{email}, #{avatar}, #{address})
</insert>
<select id="selectById" resultMap="BaseResultMap">
SELECT * FROM user WHERE id = #{id}
</select>
<select id="selectByUsername" resultMap="BaseResultMap">
SELECT * FROM user WHERE username = #{username}
</select>
<update id="update" parameterType="com.nlshop.entity.User">
UPDATE user
<set>
<if test="name != null">name = #{name},</if>
<if test="gender != null">gender = #{gender},</if>
<if test="phone != null">phone = #{phone},</if>
<if test="email != null">email = #{email},</if>
<if test="avatar != null">avatar = #{avatar},</if>
<if test="address != null">address = #{address},</if>
</set>
WHERE id = #{id}
</update>
<update id="updatePassword">
UPDATE user SET password = #{password} WHERE id = #{id}
</update>
<select id="selectAll" resultMap="BaseResultMap">
SELECT * FROM user ORDER BY create_time DESC
</select>
</mapper>

View File

@@ -0,0 +1,31 @@
<?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.nlshop.mapper.UserSimilarityMapper">
<resultMap id="BaseResultMap" type="com.nlshop.entity.UserSimilarity">
<result column="user1_id" property="user1Id"/>
<result column="user2_id" property="user2Id"/>
<result column="similarity_score" property="similarityScore"/>
<result column="update_time" property="updateTime"/>
</resultMap>
<insert id="insertOrUpdate" parameterType="com.nlshop.entity.UserSimilarity">
INSERT INTO user_similarity (user1_id, user2_id, similarity_score)
VALUES (#{user1Id}, #{user2Id}, #{similarityScore})
ON DUPLICATE KEY UPDATE
similarity_score = #{similarityScore}, update_time = NOW()
</insert>
<select id="selectByUserIds" resultMap="BaseResultMap">
SELECT * FROM user_similarity
WHERE (user1_id = #{user1Id} AND user2_id = #{user2Id})
OR (user1_id = #{user2Id} AND user2_id = #{user1Id})
LIMIT 1
</select>
<select id="selectSimilarUsers" resultMap="BaseResultMap">
SELECT * FROM user_similarity
WHERE user1_id = #{userId} OR user2_id = #{userId}
ORDER BY similarity_score DESC
LIMIT #{limit}
</select>
</mapper>