Commit bb1edc18 authored by WeiWei's avatar WeiWei

Merge remote-tracking branch 'cash-loan-flow-boss/v1' into v1

parents 7a2fff6d 74e27a02
package cn.quantgroup.cashloanflowboss.api.test.controller;
import cn.quantgroup.cashloanflowboss.api.user.model.UserSessionInfo;
import cn.quantgroup.cashloanflowboss.core.base.Result;
import cn.quantgroup.cashloanflowboss.core.dictionary.ApplicationStatus;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
......@@ -12,12 +7,5 @@ import org.springframework.web.bind.annotation.RestController;
@RequestMapping("/test")
public class TestController {
// @Autowired
// private UserSessionService userSessionService;
//
// @GetMapping("/user/info")
// public Result findUserFromSession() {
// UserSessionInfo userSessionInfo = userSessionService.findUserSessionInfo();
// return new Result<>(ApplicationStatus.SUCCESS, userSessionInfo);
// }
}
......@@ -3,8 +3,10 @@ package cn.quantgroup.cashloanflowboss.api.user.controller;
import cn.quantgroup.cashloanflowboss.api.user.entity.User;
import cn.quantgroup.cashloanflowboss.api.user.model.Pagination;
import cn.quantgroup.cashloanflowboss.api.user.model.RegisterUserFormModel;
import cn.quantgroup.cashloanflowboss.api.user.model.UserDetailInfo;
import cn.quantgroup.cashloanflowboss.api.user.service.UserService;
import cn.quantgroup.cashloanflowboss.component.validator.constraints.NotEmpty;
import cn.quantgroup.cashloanflowboss.core.base.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.*;
......@@ -75,4 +77,13 @@ public class UserController {
return this.userService.removeUser(id);
}
/**
* 获取用户详情
* @return
*/
@GetMapping("/detail/info")
public Result<UserDetailInfo> userDetailInfo() {
return Result.buildSuccess(userService.getUserDetailInfo());
}
}
package cn.quantgroup.cashloanflowboss.api.user.model;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
@Data
@Builder
@AllArgsConstructor
public class RoleInfo {
private Long roleId;
private String roleName;
}
package cn.quantgroup.cashloanflowboss.api.user.model;
import cn.quantgroup.cashloanflowboss.api.log.model.Principal;
import cn.quantgroup.cashloanflowboss.api.role.entity.Role;
import cn.quantgroup.cashloanflowboss.core.asserts.Assert;
import cn.quantgroup.cashloanflowboss.core.dictionary.ApplicationStatus;
import com.google.common.collect.Lists;
import lombok.Data;
import java.util.List;
import java.util.Set;
@Data
public class UserDetailInfo {
private UserInfo userInfo;
private RoleInfo roleInfo;
private Long channelId;
private String rank;
@Data
static class RoleInfo {
List<roleView> roleInfos;
@Data
static class roleView {
private Long roleId;
private String roleName;
}
}
@Data
static class UserInfo {
private Long userId;
private String userName;
}
public static UserDetailInfo valueOf(Principal principal) {
Assert.isNull(principal, ApplicationStatus.INVALID_USER);
UserDetailInfo userDetailInfo = new UserDetailInfo();
Long userId = principal.getUserId();
userDetailInfo.setRank(principal.getRank().name());
userDetailInfo.setChannelId(principal.getChannelId());
Set<Role> roles = principal.getRoles();
if (null != roles && roles.size() > 0) {
RoleInfo roleInfo = new RoleInfo();
List<RoleInfo.roleView> roleInfos = Lists.newArrayList();
roles.forEach(role -> {
RoleInfo.roleView roleView = new RoleInfo.roleView();
roleView.setRoleId(role.getId());
roleView.setRoleName(role.getName());
roleInfos.add(roleView);
});
roleInfo.setRoleInfos(roleInfos);
userDetailInfo.setRoleInfo(roleInfo);
}
UserInfo userInfo = new UserInfo();
userInfo.setUserId(userId);
userDetailInfo.setUserInfo(userInfo);
return userDetailInfo;
}
}
package cn.quantgroup.cashloanflowboss.api.user.model;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
@Data
@Builder
@AllArgsConstructor
public class UserInfo {
private Long userId;
private String userName;
}
package cn.quantgroup.cashloanflowboss.api.user.model;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
@Data
@Builder
@AllArgsConstructor
public class UserSessionInfo {
private UserInfo userInfo;
private RoleInfo roleInfo;
private Long channelId;
}
package cn.quantgroup.cashloanflowboss.api.user.service;
import cn.quantgroup.cashloanflowboss.api.log.model.Principal;
import cn.quantgroup.cashloanflowboss.api.user.dictionary.UserStatus;
import cn.quantgroup.cashloanflowboss.api.user.entity.User;
import cn.quantgroup.cashloanflowboss.api.user.model.UserDetailInfo;
import cn.quantgroup.cashloanflowboss.api.user.repository.UserRepository;
import cn.quantgroup.cashloanflowboss.core.Application;
import cn.quantgroup.cashloanflowboss.core.asserts.Assert;
import cn.quantgroup.cashloanflowboss.core.dictionary.ApplicationStatus;
import cn.quantgroup.cashloanflowboss.utils.MD5Tools;
......@@ -130,4 +133,11 @@ public class UserService {
}
public UserDetailInfo getUserDetailInfo() {
Principal principal = Application.getPrincipal();
Assert.isNull(principal, ApplicationStatus.INVALID_USER);
return UserDetailInfo.valueOf(principal);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment