ProductMapper.xml 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. <?xml version="1.0" encoding="UTF-8" ?>
  2. <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
  3. <mapper namespace="com.ylx.massage.mapper.ProductMapper">
  4. <!-- 分页查询商品列表(H5端)-支持排序 -->
  5. <select id="selectH5Page" resultType="com.ylx.massage.domain.vo.H5ProductVo">
  6. SELECT id, category_id, product_no,name,price_point, price_money, stock, sales,product_main_image,payment_type,sale_start_time
  7. FROM product
  8. WHERE deleted = 0 AND status = 1
  9. <if test="product.categoryId != null">
  10. AND category_id = #{product.categoryId}
  11. </if>
  12. <if test="name != null and name!='' ">
  13. and name like concat('%',#{name},'%')
  14. </if>
  15. <choose>
  16. <when test="sortField != null and sortField != '' and sortOrder != null and sortOrder != ''">
  17. ORDER BY
  18. <if test="sortField == 'price'">
  19. price_money ${sortOrder == 'asc' ? 'ASC' : 'DESC'}
  20. </if>
  21. <if test="sortField == 'sales'">
  22. sales ${sortOrder == 'asc' ? 'ASC' : 'DESC'}
  23. </if>
  24. <if test="sortField == 'comprehensive'">
  25. /* 综合排序:按销量降序(实际综合得分在Java层计算) */
  26. sales DESC
  27. </if>
  28. </when>
  29. <otherwise>
  30. ORDER BY sales DESC
  31. </otherwise>
  32. </choose>
  33. </select>
  34. <!-- 查询平台商品总销量(用于综合排序计算) -->
  35. <select id="selectPlatformStats" resultType="com.ylx.massage.domain.vo.PlatformProductStats">
  36. SELECT
  37. COALESCE(SUM(sales), 0) as totalSales
  38. FROM product
  39. WHERE deleted = 0 AND status = 1
  40. </select>
  41. </mapper>