Skip to content

Commit

Permalink
add: add last login date when user login
Browse files Browse the repository at this point in the history
  • Loading branch information
Jarrettluo committed Jul 5, 2023
1 parent 5ce6800 commit 6f8616e
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/main/java/com/jiaruiblog/controller/UserController.java
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,8 @@ public BaseApiResult deleteByIdBatch(@RequestBody BatchIdDTO batchIdDTO, HttpSer
@ApiOperation(value = "用户登录")
@PostMapping("/login")
public BaseApiResult login(@RequestBody RegistryUserDTO user) {


return userService.login(user);
}

Expand Down
2 changes: 2 additions & 0 deletions src/main/java/com/jiaruiblog/entity/User.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ public class User {

private PermissionEnum permissionEnum;

private Date lastLogin;

private Date createDate;

private Date updateDate;
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/com/jiaruiblog/entity/vo/UserVO.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ public class UserVO {

private PermissionEnum permissionEnum;

@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
private Date lastLogin;

@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
private Date createDate;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,13 @@ public BaseApiResult login(RegistryUserDTO userDTO) {
result.put(AVATAR, dbUser.getAvatar());
result.put(USERNAME, dbUser.getUsername());
result.put("type", dbUser.getPermissionEnum() != null ? dbUser.getPermissionEnum().toString() : null);

// 登录以后记录登录时间
Query query1 = new Query(Criteria.where("_id").is(dbUser.getId()));
Update update = new Update();
update.set("lastLogin", new Date());
mongoTemplate.updateFirst(query1, update, User.class, COLLECTION_NAME);

return BaseApiResult.success(result);

}
Expand Down

0 comments on commit 6f8616e

Please sign in to comment.