Commit e2b6a1ec071a4a62a2b79a5fb8b9e5bc850dc106
1 parent
9e37521a
update:订单列表排序
Showing
3 changed files
with
60 additions
and
1 deletions
etrade-order/src/main/java/com/diligrp/etrade/order/domain/OrderQueryDto.java
... | ... | @@ -87,6 +87,12 @@ public class OrderQueryDto extends BasePageQuery { |
87 | 87 | |
88 | 88 | private List<Integer> orderAchieveState; |
89 | 89 | |
90 | + private String sort; | |
91 | + /** | |
92 | + * 排序顺序 | |
93 | + */ | |
94 | + private String sortOrder; | |
95 | + | |
90 | 96 | public Integer getVerifyState() { |
91 | 97 | return verifyState; |
92 | 98 | } |
... | ... | @@ -294,4 +300,20 @@ public class OrderQueryDto extends BasePageQuery { |
294 | 300 | public void setOrderAchieveState(List<Integer> orderAchieveState) { |
295 | 301 | this.orderAchieveState = orderAchieveState; |
296 | 302 | } |
303 | + | |
304 | + public String getSort() { | |
305 | + return sort; | |
306 | + } | |
307 | + | |
308 | + public void setSort(String sort) { | |
309 | + this.sort = sort; | |
310 | + } | |
311 | + | |
312 | + public String getSortOrder() { | |
313 | + return sortOrder; | |
314 | + } | |
315 | + | |
316 | + public void setSortOrder(String sortOrder) { | |
317 | + this.sortOrder = sortOrder; | |
318 | + } | |
297 | 319 | } | ... | ... |
etrade-order/src/main/java/com/diligrp/etrade/order/service/impl/OrderQueryServiceImpl.java
... | ... | @@ -17,6 +17,7 @@ import com.github.pagehelper.PageHelper; |
17 | 17 | import com.github.pagehelper.PageInfo; |
18 | 18 | import jakarta.annotation.Resource; |
19 | 19 | import org.apache.commons.lang3.ObjectUtils; |
20 | +import org.apache.commons.lang3.StringUtils; | |
20 | 21 | import org.slf4j.Logger; |
21 | 22 | import org.slf4j.LoggerFactory; |
22 | 23 | import org.springframework.stereotype.Service; |
... | ... | @@ -74,6 +75,7 @@ public class OrderQueryServiceImpl implements OrderQueryService { |
74 | 75 | @Override |
75 | 76 | public OrderPageMessage<OrderDto> queryOrderPage(OrderQueryDto orderQueryDto) { |
76 | 77 | stateCheck(orderQueryDto.getStates()); |
78 | + checkSortAndOrder(orderQueryDto.getSort(),orderQueryDto.getSortOrder()); | |
77 | 79 | PageHelper.startPage(ObjectUtils.defaultIfNull(orderQueryDto.getPageNo(), 1), |
78 | 80 | ObjectUtils.defaultIfNull(orderQueryDto.getPageSize(), 10)); |
79 | 81 | Page<OrderDto> orderStateNumberDtoPage = orderQueryMapper.queryOrderPage(orderQueryDto); |
... | ... | @@ -92,6 +94,39 @@ public class OrderQueryServiceImpl implements OrderQueryService { |
92 | 94 | return success; |
93 | 95 | } |
94 | 96 | |
97 | + private void checkSortAndOrder(String sort, String sortOrder) { | |
98 | + if(StringUtils.isNotBlank(sort)){ | |
99 | + switch (sort){ | |
100 | + case "code": | |
101 | + sort = "ord.`code`"; | |
102 | + break; | |
103 | + case "createTime": | |
104 | + sort = "ord.created_time"; | |
105 | + break; | |
106 | + case "payTime": | |
107 | + sort = "ord.pay_time"; | |
108 | + break; | |
109 | + case "modifiedTime": | |
110 | + sort = "ord.modified_time"; | |
111 | + break; | |
112 | + default: | |
113 | + throw new OrderException(OrderErrorCode.PARAM_ERROR,"排序字段异常"); | |
114 | + } | |
115 | + } | |
116 | + if(StringUtils.isNotBlank(sort)){ | |
117 | + switch (StringUtils.lowerCase(sortOrder)){ | |
118 | + case "asc": | |
119 | + sortOrder = "asc"; | |
120 | + break; | |
121 | + case "desc": | |
122 | + sortOrder = "desc"; | |
123 | + break; | |
124 | + default: | |
125 | + throw new OrderException(OrderErrorCode.PARAM_ERROR,"排序方式异常"); | |
126 | + } | |
127 | + } | |
128 | + } | |
129 | + | |
95 | 130 | private void stateCheck(List<Integer> states) { |
96 | 131 | if(states == null||states.size()<1){ |
97 | 132 | return ; | ... | ... |
etrade-order/src/main/resources/com/diligrp/etrade/dao/mapper/order/OrderQueryMapper.xml
... | ... | @@ -298,7 +298,9 @@ |
298 | 298 | and ord.`order_status` = #{orderStatus} |
299 | 299 | </if> |
300 | 300 | </where> |
301 | - order by ord.id desc | |
301 | + <if test="sort != null and sort != '' and sortOrder != null and sortOrder != ''"> | |
302 | + ORDER BY ${sort} ${sortOrder} | |
303 | + </if> | |
302 | 304 | </select> |
303 | 305 | <select id="getOneOrderDetailById" resultType="com.diligrp.etrade.order.domain.OrderDto" |
304 | 306 | parameterType="com.diligrp.etrade.order.domain.OrderGetDto"> | ... | ... |