From 0f1262fbfa05bff677d1d04d54de094736888cc8 Mon Sep 17 00:00:00 2001 From: ronger Date: Wed, 24 Feb 2021 09:24:14 +0800 Subject: [PATCH] =?UTF-8?q?:art:=20=E7=94=A8=E6=88=B7=E5=88=97=E8=A1=A8?= =?UTF-8?q?=E6=8E=92=E5=BA=8F=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/rymcu/forest/dto/UserSearchDTO.java | 12 ++++++++++++ .../java/com/rymcu/forest/mapper/UserMapper.java | 10 ++++++++++ .../java/com/rymcu/forest/service/UserService.java | 8 ++++++++ .../rymcu/forest/service/impl/UserServiceImpl.java | 10 ++++++---- .../rymcu/forest/web/api/admin/AdminController.java | 9 +++------ src/main/java/mapper/UserMapper.xml | 9 +++++++++ 6 files changed, 48 insertions(+), 10 deletions(-) create mode 100644 src/main/java/com/rymcu/forest/dto/UserSearchDTO.java diff --git a/src/main/java/com/rymcu/forest/dto/UserSearchDTO.java b/src/main/java/com/rymcu/forest/dto/UserSearchDTO.java new file mode 100644 index 0000000..f645f60 --- /dev/null +++ b/src/main/java/com/rymcu/forest/dto/UserSearchDTO.java @@ -0,0 +1,12 @@ +package com.rymcu.forest.dto; + +import lombok.Data; + +/** + * @author ronger + */ +@Data +public class UserSearchDTO { + + private String nickname; +} diff --git a/src/main/java/com/rymcu/forest/mapper/UserMapper.java b/src/main/java/com/rymcu/forest/mapper/UserMapper.java index 901e765..2d61a58 100644 --- a/src/main/java/com/rymcu/forest/mapper/UserMapper.java +++ b/src/main/java/com/rymcu/forest/mapper/UserMapper.java @@ -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 { * @return */ Integer updatePasswordById(@Param("idUser") Integer idUser, @Param("password") String password); + + /** + * 查询用户数据 + * @param searchDTO + * @return + */ + List selectUsers(@Param("searchDTO") UserSearchDTO searchDTO); } \ No newline at end of file diff --git a/src/main/java/com/rymcu/forest/service/UserService.java b/src/main/java/com/rymcu/forest/service/UserService.java index 87530c4..7fcca8f 100644 --- a/src/main/java/com/rymcu/forest/service/UserService.java +++ b/src/main/java/com/rymcu/forest/service/UserService.java @@ -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 { * @return */ Map updatePassword(UpdatePasswordDTO updatePasswordDTO); + + /** + * 查询用户列表 + * @param searchDTO + * @return + */ + List findUsers(UserSearchDTO searchDTO); } diff --git a/src/main/java/com/rymcu/forest/service/impl/UserServiceImpl.java b/src/main/java/com/rymcu/forest/service/impl/UserServiceImpl.java index c416375..2ae4446 100644 --- a/src/main/java/com/rymcu/forest/service/impl/UserServiceImpl.java +++ b/src/main/java/com/rymcu/forest/service/impl/UserServiceImpl.java @@ -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 implements UserServic map.put("message", "更新成功!"); return map; } + + @Override + public List findUsers(UserSearchDTO searchDTO) { + return userMapper.selectUsers(searchDTO); + } } diff --git a/src/main/java/com/rymcu/forest/web/api/admin/AdminController.java b/src/main/java/com/rymcu/forest/web/api/admin/AdminController.java index 69cc224..f39b423 100644 --- a/src/main/java/com/rymcu/forest/web/api/admin/AdminController.java +++ b/src/main/java/com/rymcu/forest/web/api/admin/AdminController.java @@ -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> users(@RequestParam(defaultValue = "0") Integer page, @RequestParam(defaultValue = "10") Integer rows){ + public GlobalResult> users(@RequestParam(defaultValue = "0") Integer page, @RequestParam(defaultValue = "10") Integer rows, UserSearchDTO searchDTO){ PageHelper.startPage(page, rows); - List list = userService.findAll(); - // 按最后登录时间进行倒序排序 - list.sort(comparing(User::getLastLoginTime).reversed()); + List list = userService.findUsers(searchDTO); PageInfo pageInfo = new PageInfo<>(list); Map map = new HashMap(2); map.put("users", pageInfo.getList()); diff --git a/src/main/java/mapper/UserMapper.xml b/src/main/java/mapper/UserMapper.xml index c0d14f9..adaf741 100644 --- a/src/main/java/mapper/UserMapper.xml +++ b/src/main/java/mapper/UserMapper.xml @@ -99,5 +99,14 @@ + \ No newline at end of file