Skip to content
This repository has been archived by the owner on Oct 5, 2023. It is now read-only.

Commit

Permalink
Merge pull request #10 from opendx/0.7.7
Browse files Browse the repository at this point in the history
0.7.7
  • Loading branch information
jiangyitao authored Sep 4, 2020
2 parents 54f020a + 77d1433 commit 1a9b84c
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 37 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>com.daxiang</groupId>
<artifactId>server</artifactId>
<version>0.7.6</version>
<version>0.7.7</version>
<packaging>jar</packaging>

<properties>
Expand Down
11 changes: 0 additions & 11 deletions src/main/java/com/daxiang/dao/UserDao.java

This file was deleted.

4 changes: 4 additions & 0 deletions src/main/java/com/daxiang/service/ProjectService.java
Original file line number Diff line number Diff line change
Expand Up @@ -130,4 +130,8 @@ private List<Project> selectByProject(Project project) {
public Project getProjectById(Integer id) {
return projectMapper.selectByPrimaryKey(id);
}

public List<Project> getAll() {
return projectMapper.selectByExample(null);
}
}
41 changes: 36 additions & 5 deletions src/main/java/com/daxiang/service/UserService.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.daxiang.service;

import com.daxiang.dao.UserDao;
import com.daxiang.exception.BusinessException;
import com.daxiang.mbg.mapper.UserMapper;
import com.daxiang.mbg.po.Project;
Expand Down Expand Up @@ -42,13 +41,13 @@ public class UserService {

@Autowired
private UserMapper userMapper;
@Autowired
private UserDao userDao;

@Autowired
private UserRoleService userRoleService;
@Autowired
private UserProjectService userProjectService;
@Autowired
private ProjectService projectService;

@Autowired
private AuthenticationManager authenticationManager;
Expand Down Expand Up @@ -248,8 +247,40 @@ private List<User> selectByUser(User user) {
return userMapper.selectByExample(example);
}

public UserDto getUserDtoByUsername(String useranme) {
return userDao.selectUserDtoByUsername(useranme);
private User getUserByUsername(String username) {
UserExample example = new UserExample();
example.createCriteria().andUsernameEqualTo(username);
List<User> users = userMapper.selectByExample(example);
if (!users.isEmpty()) {
return users.get(0);
}
return null;
}

public UserDto getUserDtoByUsername(String username) {
User user = getUserByUsername(username);
if (user == null) {
return null;
}

UserDto userDto = new UserDto();
BeanUtils.copyProperties(user, userDto);
List<Integer> singleUid = Collections.singletonList(user.getId());

List<Role> roles = userRoleService.getUserRoleDtosByUserIds(singleUid).stream()
.map(UserRoleDto::getRole).collect(Collectors.toList());
userDto.setRoles(roles);

boolean isAdmin = roles.stream().map(Role::getName).anyMatch("admin"::equals);
if (isAdmin) {
userDto.setProjects(projectService.getAll());
} else {
List<Project> projects = userProjectService.getUserProjectDtosByUserIds(singleUid).stream()
.map(UserProjectDto::getProject).collect(Collectors.toList());
userDto.setProjects(projects);
}

return userDto;
}

private List<User> getUsersByIds(List<Integer> userIds) {
Expand Down
20 changes: 0 additions & 20 deletions src/main/resources/com/daxiang/dao/UserDao.xml

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
delete from `user_project` where user_id = 1;

0 comments on commit 1a9b84c

Please sign in to comment.