🎨 用户列表排序优化
This commit is contained in:
parent
8c85ff450d
commit
0f1262fbfa
12
src/main/java/com/rymcu/forest/dto/UserSearchDTO.java
Normal file
12
src/main/java/com/rymcu/forest/dto/UserSearchDTO.java
Normal file
@ -0,0 +1,12 @@
|
||||
package com.rymcu.forest.dto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* @author ronger
|
||||
*/
|
||||
@Data
|
||||
public class UserSearchDTO {
|
||||
|
||||
private String nickname;
|
||||
}
|
@ -4,9 +4,12 @@ import com.rymcu.forest.core.mapper.Mapper;
|
||||
import com.rymcu.forest.dto.Author;
|
||||
import com.rymcu.forest.dto.UserDTO;
|
||||
import com.rymcu.forest.dto.UserInfoDTO;
|
||||
import com.rymcu.forest.dto.UserSearchDTO;
|
||||
import com.rymcu.forest.entity.User;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author ronger
|
||||
*/
|
||||
@ -136,4 +139,11 @@ public interface UserMapper extends Mapper<User> {
|
||||
* @return
|
||||
*/
|
||||
Integer updatePasswordById(@Param("idUser") Integer idUser, @Param("password") String password);
|
||||
|
||||
/**
|
||||
* 查询用户数据
|
||||
* @param searchDTO
|
||||
* @return
|
||||
*/
|
||||
List<User> selectUsers(@Param("searchDTO") UserSearchDTO searchDTO);
|
||||
}
|
@ -6,6 +6,7 @@ import com.rymcu.forest.entity.User;
|
||||
import com.rymcu.forest.entity.UserExtend;
|
||||
import org.apache.ibatis.exceptions.TooManyResultsException;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
@ -135,4 +136,11 @@ public interface UserService extends Service<User> {
|
||||
* @return
|
||||
*/
|
||||
Map updatePassword(UpdatePasswordDTO updatePasswordDTO);
|
||||
|
||||
/**
|
||||
* 查询用户列表
|
||||
* @param searchDTO
|
||||
* @return
|
||||
*/
|
||||
List<User> findUsers(UserSearchDTO searchDTO);
|
||||
}
|
||||
|
@ -20,10 +20,7 @@ import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.*;
|
||||
|
||||
|
||||
/**
|
||||
@ -272,4 +269,9 @@ public class UserServiceImpl extends AbstractService<User> implements UserServic
|
||||
map.put("message", "更新成功!");
|
||||
return map;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<User> findUsers(UserSearchDTO searchDTO) {
|
||||
return userMapper.selectUsers(searchDTO);
|
||||
}
|
||||
}
|
||||
|
@ -4,6 +4,7 @@ import com.github.pagehelper.PageHelper;
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import com.rymcu.forest.core.result.GlobalResult;
|
||||
import com.rymcu.forest.core.result.GlobalResultGenerator;
|
||||
import com.rymcu.forest.dto.UserSearchDTO;
|
||||
import com.rymcu.forest.dto.admin.TopicTagDTO;
|
||||
import com.rymcu.forest.dto.admin.UserRoleDTO;
|
||||
import com.rymcu.forest.entity.*;
|
||||
@ -18,8 +19,6 @@ import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static java.util.Comparator.comparing;
|
||||
|
||||
/**
|
||||
* @author ronger
|
||||
* */
|
||||
@ -39,11 +38,9 @@ public class AdminController {
|
||||
private SpecialDayService specialDayService;
|
||||
|
||||
@GetMapping("/users")
|
||||
public GlobalResult<Map<String, Object>> users(@RequestParam(defaultValue = "0") Integer page, @RequestParam(defaultValue = "10") Integer rows){
|
||||
public GlobalResult<Map<String, Object>> users(@RequestParam(defaultValue = "0") Integer page, @RequestParam(defaultValue = "10") Integer rows, UserSearchDTO searchDTO){
|
||||
PageHelper.startPage(page, rows);
|
||||
List<User> list = userService.findAll();
|
||||
// 按最后登录时间进行倒序排序
|
||||
list.sort(comparing(User::getLastLoginTime).reversed());
|
||||
List<User> list = userService.findUsers(searchDTO);
|
||||
PageInfo<User> pageInfo = new PageInfo<>(list);
|
||||
Map<String, Object> map = new HashMap<String, Object>(2);
|
||||
map.put("users", pageInfo.getList());
|
||||
|
@ -99,5 +99,14 @@
|
||||
<select id="selectAuthor" resultMap="AuthorResultMap">
|
||||
select * from forest_user where id = #{id}
|
||||
</select>
|
||||
<select id="selectUsers" resultMap="BaseResultMap">
|
||||
select id, nickname, sex, avatar_type, avatar_url, email, account, status, last_login_time, created_time from forest_user
|
||||
<where>
|
||||
<if test="searchDTO.nickname != null and searchDTO.nickname != ''">
|
||||
and instr(nickname, #{searchDTO.nickname}) > 0
|
||||
</if>
|
||||
</where>
|
||||
order by last_login_time desc
|
||||
</select>
|
||||
|
||||
</mapper>
|
Loading…
Reference in New Issue
Block a user