72 lines
2.8 KiB
XML
72 lines
2.8 KiB
XML
<?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>
|