优化店员查询接口:在线店员优先显示
- 在 /wx/clerk/user/queryByPage 接口中添加排序逻辑 - 在线状态(onlineState=1)的店员优先显示在列表前面 - 离线状态(onlineState=0)的店员排在后面 - 正确处理空值情况,将 null 视为离线状态 - 在控制器层实现排序,保持服务层代码简洁
This commit is contained in:
67364
backend.txt
Normal file
67364
backend.txt
Normal file
File diff suppressed because it is too large
Load Diff
@@ -347,6 +347,27 @@ public class WxClerkController {
|
|||||||
public R queryByPage(@RequestBody PlayClerkUserInfoQueryVo vo) {
|
public R queryByPage(@RequestBody PlayClerkUserInfoQueryVo vo) {
|
||||||
IPage<PlayClerkUserInfoResultVo> page = playClerkUserInfoService.selectByPage(vo,
|
IPage<PlayClerkUserInfoResultVo> page = playClerkUserInfoService.selectByPage(vo,
|
||||||
customUserService.getLoginUserId());
|
customUserService.getLoginUserId());
|
||||||
|
// 对记录进行排序,优先显示在线店员
|
||||||
|
if (page.getRecords() != null && !page.getRecords().isEmpty()) {
|
||||||
|
page.getRecords().sort((clerk1, clerk2) -> {
|
||||||
|
// 在线状态优先级:"1"(在线)排在"0"(离线)之前
|
||||||
|
String onlineState1 = clerk1.getOnlineState();
|
||||||
|
String onlineState2 = clerk2.getOnlineState();
|
||||||
|
// 如果两者在线状态相同,保持原有顺序
|
||||||
|
if (onlineState1 != null && onlineState2 != null) {
|
||||||
|
// 反向比较,使"1"排在"0"之前
|
||||||
|
return onlineState2.compareTo(onlineState1);
|
||||||
|
}
|
||||||
|
// 处理空值情况:将null视为离线状态("0")
|
||||||
|
if (onlineState1 == null && onlineState2 == null)
|
||||||
|
return 0;
|
||||||
|
if (onlineState1 == null)
|
||||||
|
return 1; // null视为离线,排在在线之后
|
||||||
|
if (onlineState2 == null)
|
||||||
|
return -1; // null视为离线,排在在线之后
|
||||||
|
return onlineState2.compareTo(onlineState1);
|
||||||
|
});
|
||||||
|
}
|
||||||
return R.ok(page);
|
return R.ok(page);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user