From 5b237740ab4ef64bc95faa2ebd9af5f3671e4453 Mon Sep 17 00:00:00 2001 From: zepengdev <lzpsmith@outlook.com> Date: Wed, 30 Jul 2025 10:49:28 +0800 Subject: [PATCH] feat: 商户端的商品查询增加价格排序 --- oying-system/src/main/java/com/oying/modules/pc/product/domain/dto/ProductQueryCriteria.java | 4 ++++ oying-system/src/main/resources/mapper/pc/product/ProductMapper.xml | 19 +++++++++++++++---- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/oying-system/src/main/java/com/oying/modules/pc/product/domain/dto/ProductQueryCriteria.java b/oying-system/src/main/java/com/oying/modules/pc/product/domain/dto/ProductQueryCriteria.java index 860b8b4..9ea4244 100644 --- a/oying-system/src/main/java/com/oying/modules/pc/product/domain/dto/ProductQueryCriteria.java +++ b/oying-system/src/main/java/com/oying/modules/pc/product/domain/dto/ProductQueryCriteria.java @@ -37,4 +37,8 @@ private Integer limit; + private String sortColumn; + + private String sortDirection; + } diff --git a/oying-system/src/main/resources/mapper/pc/product/ProductMapper.xml b/oying-system/src/main/resources/mapper/pc/product/ProductMapper.xml index ee5bc4f..c9caf4c 100644 --- a/oying-system/src/main/resources/mapper/pc/product/ProductMapper.xml +++ b/oying-system/src/main/resources/mapper/pc/product/ProductMapper.xml @@ -38,9 +38,9 @@ </sql> <select id="findAll" resultMap="BaseResultMap"> - select + SELECT <include refid="Base_Column_List"/> - from pc_product + FROM pc_product <where> <if test="criteria.storeId != null"> and store_id = #{criteria.storeId} @@ -64,9 +64,20 @@ and active = #{criteria.active} </if> </where> - order by product_id desc + <!--<if test="criteria.sortColumn != null and criteria.sortColumn != ''"> + order by ${criteria.sortColumn} ${criteria.sortDirection} + </if>--> + ORDER BY + <choose> + <!-- 价格升序 --> + <when test="criteria.sortColumn == 'price' and criteria.sortDirection == 'asc'">price ASC</when> + <!-- 价格降序 --> + <when test="criteria.sortColumn == 'price' and criteria.sortDirection == 'desc'">price DESC</when> + <!-- 创建时间降序(默认) --> + <otherwise>create_time DESC</otherwise> + </choose> <if test="criteria.limit != null"> - limit #{criteria.limit} + LIMIT #{criteria.limit} </if> </select> -- Gitblit v1.9.3