🎨 用户管理列表接口修改

This commit is contained in:
ronger 2021-12-06 20:33:15 +08:00
parent b7585747d6
commit fa9d9dd92c
6 changed files with 28 additions and 11 deletions

View File

@ -3,6 +3,7 @@ package com.rymcu.forest.dto;
import com.alibaba.fastjson.annotation.JSONField;
import lombok.Data;
import javax.persistence.Column;
import java.io.Serializable;
import java.util.Date;
@ -40,4 +41,9 @@ public class UserInfoDTO implements Serializable {
@JSONField(format = "yyyy-MM-dd HH:mm")
private Date lastOnlineTime;
@JSONField(format = "yyyy-MM-dd HH:mm:ss")
private Date createdTime;
private Integer onlineStatus;
}

View File

@ -145,7 +145,7 @@ public interface UserMapper extends Mapper<User> {
* @param searchDTO
* @return
*/
List<User> selectUsers(@Param("searchDTO") UserSearchDTO searchDTO);
List<UserInfoDTO> selectUsers(@Param("searchDTO") UserSearchDTO searchDTO);
/**
* 更新用户最后在线时间

View File

@ -142,7 +142,7 @@ public interface UserService extends Service<User> {
* @param searchDTO
* @return
*/
List<User> findUsers(UserSearchDTO searchDTO);
List<UserInfoDTO> findUsers(UserSearchDTO searchDTO);
/**
* 通过邮箱查询用户信息

View File

@ -6,6 +6,7 @@ import com.rymcu.forest.dto.*;
import com.rymcu.forest.entity.Role;
import com.rymcu.forest.entity.User;
import com.rymcu.forest.entity.UserExtend;
import com.rymcu.forest.jwt.def.JwtConstants;
import com.rymcu.forest.jwt.service.TokenManager;
import com.rymcu.forest.lucene.model.UserLucene;
import com.rymcu.forest.lucene.util.UserIndexUtil;
@ -282,8 +283,20 @@ public class UserServiceImpl extends AbstractService<User> implements UserServic
}
@Override
public List<User> findUsers(UserSearchDTO searchDTO) {
return userMapper.selectUsers(searchDTO);
public List<UserInfoDTO> findUsers(UserSearchDTO searchDTO) {
List<UserInfoDTO> users = userMapper.selectUsers(searchDTO);
users.forEach(user -> {
user.setOnlineStatus(getUserOnlineStatus(user.getEmail()));
});
return users;
}
private Integer getUserOnlineStatus(String email) {
String lastOnlineTime = redisService.get(JwtConstants.LAST_ONLINE + email);
if (StringUtils.isBlank(lastOnlineTime)) {
return 0;
}
return 1;
}
@Override

View File

@ -4,10 +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.ArticleDTO;
import com.rymcu.forest.dto.ArticleSearchDTO;
import com.rymcu.forest.dto.CommentDTO;
import com.rymcu.forest.dto.UserSearchDTO;
import com.rymcu.forest.dto.*;
import com.rymcu.forest.dto.admin.TopicTagDTO;
import com.rymcu.forest.dto.admin.UserRoleDTO;
import com.rymcu.forest.entity.*;
@ -47,8 +44,8 @@ public class AdminController {
@GetMapping("/users")
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.findUsers(searchDTO);
PageInfo<User> pageInfo = new PageInfo<>(list);
List<UserInfoDTO> list = userService.findUsers(searchDTO);
PageInfo<UserInfoDTO> pageInfo = new PageInfo<>(list);
Map<String, Object> map = new HashMap<String, Object>(2);
map.put("users", pageInfo.getList());
Map pagination = Utils.getPagination(pageInfo);

View File

@ -33,6 +33,7 @@
<result column="status" property="status"/>
<result column="last_login_time" property="lastLoginTime"/>
<result column="last_online_time" property="lastOnlineTime"/>
<result column="created_time" property="createdTime"/>
<result column="signature" property="signature"/>
</resultMap>
<resultMap id="DTOResultMapper" type="com.rymcu.forest.dto.UserDTO">
@ -105,7 +106,7 @@
<select id="selectAuthor" resultMap="AuthorResultMap">
select * from forest_user where id = #{id}
</select>
<select id="selectUsers" resultMap="BaseResultMap">
<select id="selectUsers" resultMap="UserInfoResultMapper">
select id, nickname, sex, avatar_type, avatar_url, email, account, status, last_login_time, created_time, last_online_time from forest_user
<where>
<if test="searchDTO.nickname != null and searchDTO.nickname != ''">