"src/git@ustchcs.com:gujinli1118/MCMS.git" did not exist on "27867d4e8be822c4598dbda24cdada20b5c1e711"
Commit 784d670c authored by zhengjie's avatar zhengjie
Browse files

2.0 抢先版,主要更新了#71 | #IWYE2

parent 90c2bf90
package me.zhengjie.modules.security.service; package me.zhengjie.modules.security.service;
import me.zhengjie.modules.system.domain.Role; import me.zhengjie.modules.system.domain.Role;
import me.zhengjie.modules.system.domain.User;
import me.zhengjie.modules.system.repository.RoleRepository; import me.zhengjie.modules.system.repository.RoleRepository;
import me.zhengjie.modules.system.service.dto.UserDTO;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheConfig; import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.Cacheable; import org.springframework.cache.annotation.Cacheable;
...@@ -26,7 +26,7 @@ public class JwtPermissionService { ...@@ -26,7 +26,7 @@ public class JwtPermissionService {
* @return * @return
*/ */
@Cacheable(key = "'loadPermissionByUser:' + #p0.username") @Cacheable(key = "'loadPermissionByUser:' + #p0.username")
public Collection<GrantedAuthority> mapToGrantedAuthorities(User user) { public Collection<GrantedAuthority> mapToGrantedAuthorities(UserDTO user) {
System.out.println("--------------------loadPermissionByUser:" + user.getUsername() + "---------------------"); System.out.println("--------------------loadPermissionByUser:" + user.getUsername() + "---------------------");
......
...@@ -2,25 +2,18 @@ package me.zhengjie.modules.security.service; ...@@ -2,25 +2,18 @@ package me.zhengjie.modules.security.service;
import me.zhengjie.exception.BadRequestException; import me.zhengjie.exception.BadRequestException;
import me.zhengjie.modules.system.domain.*; import me.zhengjie.modules.system.domain.*;
import me.zhengjie.exception.EntityNotFoundException;
import me.zhengjie.modules.system.repository.PermissionRepository;
import me.zhengjie.modules.system.repository.RoleRepository;
import me.zhengjie.modules.security.security.JwtUser; import me.zhengjie.modules.security.security.JwtUser;
import me.zhengjie.modules.system.service.UserService; import me.zhengjie.modules.system.service.UserService;
import me.zhengjie.modules.system.service.dto.DeptDTO;
import me.zhengjie.modules.system.service.dto.JobDTO;
import me.zhengjie.modules.system.service.dto.UserDTO;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails; import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService; import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation; import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import java.util.HashSet;
import java.util.List;
import java.util.Optional; import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors;
/** /**
* @author jie * @author jie
...@@ -39,7 +32,7 @@ public class JwtUserDetailsService implements UserDetailsService { ...@@ -39,7 +32,7 @@ public class JwtUserDetailsService implements UserDetailsService {
@Override @Override
public UserDetails loadUserByUsername(String username){ public UserDetails loadUserByUsername(String username){
User user = userService.findByName(username); UserDTO user = userService.findByName(username);
if (user == null) { if (user == null) {
throw new BadRequestException("账号不存在"); throw new BadRequestException("账号不存在");
} else { } else {
...@@ -47,7 +40,7 @@ public class JwtUserDetailsService implements UserDetailsService { ...@@ -47,7 +40,7 @@ public class JwtUserDetailsService implements UserDetailsService {
} }
} }
public UserDetails createJwtUser(User user) { public UserDetails createJwtUser(UserDTO user) {
return new JwtUser( return new JwtUser(
user.getId(), user.getId(),
user.getUsername(), user.getUsername(),
...@@ -55,8 +48,8 @@ public class JwtUserDetailsService implements UserDetailsService { ...@@ -55,8 +48,8 @@ public class JwtUserDetailsService implements UserDetailsService {
user.getAvatar(), user.getAvatar(),
user.getEmail(), user.getEmail(),
user.getPhone(), user.getPhone(),
Optional.ofNullable(user.getDept()).map(Dept::getName).orElse(null), Optional.ofNullable(user.getDept()).map(DeptDTO::getName).orElse(null),
Optional.ofNullable(user.getJob()).map(Job::getName).orElse(null), Optional.ofNullable(user.getJob()).map(JobDTO::getName).orElse(null),
permissionService.mapToGrantedAuthorities(user), permissionService.mapToGrantedAuthorities(user),
user.getEnabled(), user.getEnabled(),
user.getCreateTime(), user.getCreateTime(),
......
...@@ -45,6 +45,10 @@ public class Dept implements Serializable { ...@@ -45,6 +45,10 @@ public class Dept implements Serializable {
@NotNull @NotNull
private Long pid; private Long pid;
@JsonIgnore
@ManyToMany(mappedBy = "depts")
private Set<Role> roles;
@Column(name = "create_time") @Column(name = "create_time")
@CreationTimestamp @CreationTimestamp
private Timestamp createTime; private Timestamp createTime;
......
package me.zhengjie.modules.system.domain; package me.zhengjie.modules.system.domain;
import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.Getter; import lombok.Getter;
import lombok.Setter; import lombok.Setter;
import org.hibernate.annotations.CreationTimestamp; import org.hibernate.annotations.CreationTimestamp;
......
...@@ -3,6 +3,7 @@ package me.zhengjie.modules.system.repository; ...@@ -3,6 +3,7 @@ package me.zhengjie.modules.system.repository;
import me.zhengjie.modules.system.domain.Dept; import me.zhengjie.modules.system.domain.Dept;
import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor; import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
...@@ -19,4 +20,9 @@ public interface DeptRepository extends JpaRepository<Dept, Long>, JpaSpecificat ...@@ -19,4 +20,9 @@ public interface DeptRepository extends JpaRepository<Dept, Long>, JpaSpecificat
* @return * @return
*/ */
List<Dept> findByPid(Long id); List<Dept> findByPid(Long id);
@Query(value = "select name from dept where id = ?1",nativeQuery = true)
String findNameById(Long id);
Set<Dept> findByRoles_Id(Long id);
} }
\ No newline at end of file
...@@ -8,6 +8,7 @@ import me.zhengjie.modules.system.service.MenuService; ...@@ -8,6 +8,7 @@ import me.zhengjie.modules.system.service.MenuService;
import me.zhengjie.modules.system.service.RoleService; import me.zhengjie.modules.system.service.RoleService;
import me.zhengjie.modules.system.service.UserService; import me.zhengjie.modules.system.service.UserService;
import me.zhengjie.modules.system.service.dto.MenuDTO; import me.zhengjie.modules.system.service.dto.MenuDTO;
import me.zhengjie.modules.system.service.dto.UserDTO;
import me.zhengjie.modules.system.service.mapper.MenuMapper; import me.zhengjie.modules.system.service.mapper.MenuMapper;
import me.zhengjie.modules.system.service.query.MenuQueryService; import me.zhengjie.modules.system.service.query.MenuQueryService;
import me.zhengjie.utils.SecurityUtils; import me.zhengjie.utils.SecurityUtils;
...@@ -50,7 +51,7 @@ public class MenuController { ...@@ -50,7 +51,7 @@ public class MenuController {
*/ */
@GetMapping(value = "/menus/build") @GetMapping(value = "/menus/build")
public ResponseEntity buildMenus(){ public ResponseEntity buildMenus(){
User user = userService.findByName(SecurityUtils.getUsername()); UserDTO user = userService.findByName(SecurityUtils.getUsername());
List<MenuDTO> menuDTOList = menuService.findByRoles(roleService.findByUsers_Id(user.getId())); List<MenuDTO> menuDTOList = menuService.findByRoles(roleService.findByUsers_Id(user.getId()));
List<MenuDTO> menuDTOTree = (List<MenuDTO>)menuService.buildTree(menuDTOList).get("content"); List<MenuDTO> menuDTOTree = (List<MenuDTO>)menuService.buildTree(menuDTOList).get("content");
return new ResponseEntity(menuService.buildMenus(menuDTOTree),HttpStatus.OK); return new ResponseEntity(menuService.buildMenus(menuDTOTree),HttpStatus.OK);
......
...@@ -7,6 +7,7 @@ import me.zhengjie.exception.BadRequestException; ...@@ -7,6 +7,7 @@ import me.zhengjie.exception.BadRequestException;
import me.zhengjie.modules.system.domain.User; import me.zhengjie.modules.system.domain.User;
import me.zhengjie.modules.system.service.RoleService; import me.zhengjie.modules.system.service.RoleService;
import me.zhengjie.modules.system.service.dto.RoleDTO; import me.zhengjie.modules.system.service.dto.RoleDTO;
import me.zhengjie.modules.system.service.dto.RoleSmallDTO;
import me.zhengjie.modules.system.service.query.RoleQueryService; import me.zhengjie.modules.system.service.query.RoleQueryService;
import me.zhengjie.utils.SecurityUtils; import me.zhengjie.utils.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
...@@ -71,7 +72,7 @@ public class RoleController { ...@@ -71,7 +72,7 @@ public class RoleController {
@GetMapping(value = "/roles/level") @GetMapping(value = "/roles/level")
public ResponseEntity getLevel(){ public ResponseEntity getLevel(){
List<Integer> levels = roleService.findByUsers_Id(SecurityUtils.getUserId()).stream().map(Role::getLevel).collect(Collectors.toList()); List<Integer> levels = roleService.findByUsers_Id(SecurityUtils.getUserId()).stream().map(RoleSmallDTO::getLevel).collect(Collectors.toList());
return new ResponseEntity(Dict.create().set("level", Collections.min(levels)),HttpStatus.OK); return new ResponseEntity(Dict.create().set("level", Collections.min(levels)),HttpStatus.OK);
} }
......
...@@ -9,6 +9,7 @@ import me.zhengjie.modules.system.domain.User; ...@@ -9,6 +9,7 @@ import me.zhengjie.modules.system.domain.User;
import me.zhengjie.exception.BadRequestException; import me.zhengjie.exception.BadRequestException;
import me.zhengjie.modules.system.service.DeptService; import me.zhengjie.modules.system.service.DeptService;
import me.zhengjie.modules.system.service.RoleService; import me.zhengjie.modules.system.service.RoleService;
import me.zhengjie.modules.system.service.dto.RoleSmallDTO;
import me.zhengjie.service.PictureService; import me.zhengjie.service.PictureService;
import me.zhengjie.service.VerificationCodeService; import me.zhengjie.service.VerificationCodeService;
import me.zhengjie.utils.*; import me.zhengjie.utils.*;
...@@ -119,8 +120,8 @@ public class UserController { ...@@ -119,8 +120,8 @@ public class UserController {
@DeleteMapping(value = "/users/{id}") @DeleteMapping(value = "/users/{id}")
@PreAuthorize("hasAnyRole('ADMIN','USER_ALL','USER_DELETE')") @PreAuthorize("hasAnyRole('ADMIN','USER_ALL','USER_DELETE')")
public ResponseEntity delete(@PathVariable Long id){ public ResponseEntity delete(@PathVariable Long id){
Integer currentLevel = Collections.min(roleService.findByUsers_Id(SecurityUtils.getUserId()).stream().map(Role::getLevel).collect(Collectors.toList())); Integer currentLevel = Collections.min(roleService.findByUsers_Id(SecurityUtils.getUserId()).stream().map(RoleSmallDTO::getLevel).collect(Collectors.toList()));
Integer optLevel = Collections.min(roleService.findByUsers_Id(id).stream().map(Role::getLevel).collect(Collectors.toList())); Integer optLevel = Collections.min(roleService.findByUsers_Id(id).stream().map(RoleSmallDTO::getLevel).collect(Collectors.toList()));
if (currentLevel > optLevel) { if (currentLevel > optLevel) {
throw new BadRequestException("角色权限不足"); throw new BadRequestException("角色权限不足");
...@@ -196,7 +197,7 @@ public class UserController { ...@@ -196,7 +197,7 @@ public class UserController {
* @param resources * @param resources
*/ */
private void checkLevel(User resources) { private void checkLevel(User resources) {
Integer currentLevel = Collections.min(roleService.findByUsers_Id(SecurityUtils.getUserId()).stream().map(Role::getLevel).collect(Collectors.toList())); Integer currentLevel = Collections.min(roleService.findByUsers_Id(SecurityUtils.getUserId()).stream().map(RoleSmallDTO::getLevel).collect(Collectors.toList()));
Integer optLevel = roleService.findByRoles(resources.getRoles()); Integer optLevel = roleService.findByRoles(resources.getRoles());
if (currentLevel > optLevel) { if (currentLevel > optLevel) {
throw new BadRequestException("角色权限不足"); throw new BadRequestException("角色权限不足");
......
...@@ -7,6 +7,7 @@ import org.springframework.cache.annotation.CacheEvict; ...@@ -7,6 +7,7 @@ import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable; import org.springframework.cache.annotation.Cacheable;
import java.util.List; import java.util.List;
import java.util.Set;
/** /**
* @author jie * @author jie
...@@ -60,4 +61,6 @@ public interface DeptService { ...@@ -60,4 +61,6 @@ public interface DeptService {
*/ */
@Cacheable(keyGenerator = "keyGenerator") @Cacheable(keyGenerator = "keyGenerator")
List<Dept> findByPid(long pid); List<Dept> findByPid(long pid);
Set<Dept> findByRoleIds(Long id);
} }
\ No newline at end of file
...@@ -3,6 +3,7 @@ package me.zhengjie.modules.system.service; ...@@ -3,6 +3,7 @@ package me.zhengjie.modules.system.service;
import me.zhengjie.modules.system.domain.Menu; import me.zhengjie.modules.system.domain.Menu;
import me.zhengjie.modules.system.domain.Role; import me.zhengjie.modules.system.domain.Role;
import me.zhengjie.modules.system.service.dto.MenuDTO; import me.zhengjie.modules.system.service.dto.MenuDTO;
import me.zhengjie.modules.system.service.dto.RoleSmallDTO;
import org.springframework.cache.annotation.CacheConfig; import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.CacheEvict; import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable; import org.springframework.cache.annotation.Cacheable;
...@@ -74,7 +75,7 @@ public interface MenuService { ...@@ -74,7 +75,7 @@ public interface MenuService {
* @param roles * @param roles
* @return * @return
*/ */
List<MenuDTO> findByRoles(List<Role> roles); List<MenuDTO> findByRoles(List<RoleSmallDTO> roles);
/** /**
* buildMenus * buildMenus
......
...@@ -3,6 +3,7 @@ package me.zhengjie.modules.system.service; ...@@ -3,6 +3,7 @@ package me.zhengjie.modules.system.service;
import me.zhengjie.modules.system.domain.Menu; import me.zhengjie.modules.system.domain.Menu;
import me.zhengjie.modules.system.domain.Role; import me.zhengjie.modules.system.domain.Role;
import me.zhengjie.modules.system.service.dto.RoleDTO; import me.zhengjie.modules.system.service.dto.RoleDTO;
import me.zhengjie.modules.system.service.dto.RoleSmallDTO;
import org.springframework.cache.annotation.CacheConfig; import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.CacheEvict; import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable; import org.springframework.cache.annotation.Cacheable;
...@@ -54,7 +55,7 @@ public interface RoleService { ...@@ -54,7 +55,7 @@ public interface RoleService {
* @return * @return
*/ */
@Cacheable(key = "'findByUsers_Id:' + #p0") @Cacheable(key = "'findByUsers_Id:' + #p0")
List<Role> findByUsers_Id(Long id); List<RoleSmallDTO> findByUsers_Id(Long id);
@Cacheable(keyGenerator = "keyGenerator") @Cacheable(keyGenerator = "keyGenerator")
Integer findByRoles(Set<Role> roles); Integer findByRoles(Set<Role> roles);
......
...@@ -50,7 +50,7 @@ public interface UserService { ...@@ -50,7 +50,7 @@ public interface UserService {
* @return * @return
*/ */
@Cacheable(key = "'loadUserByUsername:'+#p0") @Cacheable(key = "'loadUserByUsername:'+#p0")
User findByName(String userName); UserDTO findByName(String userName);
/** /**
* 修改密码 * 修改密码
......
...@@ -35,6 +35,11 @@ public class JobDTO implements Serializable { ...@@ -35,6 +35,11 @@ public class JobDTO implements Serializable {
private DeptDTO dept; private DeptDTO dept;
/**
* 如果分公司存在相同部门,则显示上级部门名称
*/
private String deptSuperiorName;
/** /**
* 创建日期 * 创建日期
*/ */
......
package me.zhengjie.modules.system.service.dto;
import lombok.Data;
import java.io.Serializable;
import java.sql.Timestamp;
import java.util.Set;
/**
* @author jie
* @date 2018-11-23
*/
@Data
public class RoleSmallDTO implements Serializable {
private Long id;
private String name;
private Integer level;
private String dataScope;
}
...@@ -36,7 +36,7 @@ public class UserDTO implements Serializable { ...@@ -36,7 +36,7 @@ public class UserDTO implements Serializable {
private Date lastPasswordResetTime; private Date lastPasswordResetTime;
@ApiModelProperty(hidden = true) @ApiModelProperty(hidden = true)
private Set<RoleDTO> roles; private Set<RoleSmallDTO> roles;
@ApiModelProperty(hidden = true) @ApiModelProperty(hidden = true)
private JobDTO job; private JobDTO job;
......
...@@ -42,10 +42,16 @@ public class DeptServiceImpl implements DeptService { ...@@ -42,10 +42,16 @@ public class DeptServiceImpl implements DeptService {
return deptRepository.findByPid(pid); return deptRepository.findByPid(pid);
} }
@Override
public Set<Dept> findByRoleIds(Long id) {
return deptRepository.findByRoles_Id(id);
}
@Override @Override
public Object buildTree(List<DeptDTO> deptDTOS) { public Object buildTree(List<DeptDTO> deptDTOS) {
Set<DeptDTO> trees = new LinkedHashSet<>(); Set<DeptDTO> trees = new LinkedHashSet<>();
Set<DeptDTO> depts= new LinkedHashSet<>(); Set<DeptDTO> depts= new LinkedHashSet<>();
List<String> deptNames = deptDTOS.stream().map(DeptDTO::getName).collect(Collectors.toList());
Boolean isChild; Boolean isChild;
for (DeptDTO deptDTO : deptDTOS) { for (DeptDTO deptDTO : deptDTOS) {
isChild = false; isChild = false;
...@@ -61,9 +67,10 @@ public class DeptServiceImpl implements DeptService { ...@@ -61,9 +67,10 @@ public class DeptServiceImpl implements DeptService {
deptDTO.getChildren().add(it); deptDTO.getChildren().add(it);
} }
} }
if(isChild) { if(isChild)
depts.add(deptDTO);
else if(!deptNames.contains(deptRepository.findNameById(deptDTO.getPid())))
depts.add(deptDTO); depts.add(deptDTO);
}
} }
if (CollectionUtils.isEmpty(trees)) { if (CollectionUtils.isEmpty(trees)) {
......
...@@ -2,7 +2,6 @@ package me.zhengjie.modules.system.service.impl; ...@@ -2,7 +2,6 @@ package me.zhengjie.modules.system.service.impl;
import cn.hutool.core.util.StrUtil; import cn.hutool.core.util.StrUtil;
import me.zhengjie.modules.system.domain.Menu; import me.zhengjie.modules.system.domain.Menu;
import me.zhengjie.modules.system.domain.Role;
import me.zhengjie.modules.system.domain.vo.MenuMetaVo; import me.zhengjie.modules.system.domain.vo.MenuMetaVo;
import me.zhengjie.modules.system.domain.vo.MenuVo; import me.zhengjie.modules.system.domain.vo.MenuVo;
import me.zhengjie.exception.BadRequestException; import me.zhengjie.exception.BadRequestException;
...@@ -10,6 +9,7 @@ import me.zhengjie.exception.EntityExistException; ...@@ -10,6 +9,7 @@ import me.zhengjie.exception.EntityExistException;
import me.zhengjie.modules.system.repository.MenuRepository; import me.zhengjie.modules.system.repository.MenuRepository;
import me.zhengjie.modules.system.service.MenuService; import me.zhengjie.modules.system.service.MenuService;
import me.zhengjie.modules.system.service.dto.MenuDTO; import me.zhengjie.modules.system.service.dto.MenuDTO;
import me.zhengjie.modules.system.service.dto.RoleSmallDTO;
import me.zhengjie.modules.system.service.mapper.MenuMapper; import me.zhengjie.modules.system.service.mapper.MenuMapper;
import me.zhengjie.utils.ValidationUtil; import me.zhengjie.utils.ValidationUtil;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
...@@ -37,9 +37,9 @@ public class MenuServiceImpl implements MenuService { ...@@ -37,9 +37,9 @@ public class MenuServiceImpl implements MenuService {
} }
@Override @Override
public List<MenuDTO> findByRoles(List<Role> roles) { public List<MenuDTO> findByRoles(List<RoleSmallDTO> roles) {
Set<Menu> menus = new LinkedHashSet<>(); Set<Menu> menus = new LinkedHashSet<>();
for (Role role : roles) { for (RoleSmallDTO role : roles) {
List<Menu> menus1 = menuRepository.findByRoles_IdOrderBySortAsc(role.getId()).stream().collect(Collectors.toList()); List<Menu> menus1 = menuRepository.findByRoles_IdOrderBySortAsc(role.getId()).stream().collect(Collectors.toList());
menus.addAll(menus1); menus.addAll(menus1);
} }
......
...@@ -7,7 +7,9 @@ import me.zhengjie.exception.EntityExistException; ...@@ -7,7 +7,9 @@ import me.zhengjie.exception.EntityExistException;
import me.zhengjie.modules.system.repository.RoleRepository; import me.zhengjie.modules.system.repository.RoleRepository;
import me.zhengjie.modules.system.service.RoleService; import me.zhengjie.modules.system.service.RoleService;
import me.zhengjie.modules.system.service.dto.RoleDTO; import me.zhengjie.modules.system.service.dto.RoleDTO;
import me.zhengjie.modules.system.service.dto.RoleSmallDTO;
import me.zhengjie.modules.system.service.mapper.RoleMapper; import me.zhengjie.modules.system.service.mapper.RoleMapper;
import me.zhengjie.modules.system.service.mapper.RoleSmallMapper;
import me.zhengjie.utils.ValidationUtil; import me.zhengjie.utils.ValidationUtil;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
...@@ -30,6 +32,9 @@ public class RoleServiceImpl implements RoleService { ...@@ -30,6 +32,9 @@ public class RoleServiceImpl implements RoleService {
@Autowired @Autowired
private RoleMapper roleMapper; private RoleMapper roleMapper;
@Autowired
private RoleSmallMapper roleSmallMapper;
@Override @Override
public RoleDTO findById(long id) { public RoleDTO findById(long id) {
Optional<Role> role = roleRepository.findById(id); Optional<Role> role = roleRepository.findById(id);
...@@ -100,8 +105,8 @@ public class RoleServiceImpl implements RoleService { ...@@ -100,8 +105,8 @@ public class RoleServiceImpl implements RoleService {
} }
@Override @Override
public List<Role> findByUsers_Id(Long id) { public List<RoleSmallDTO> findByUsers_Id(Long id) {
return roleRepository.findByUsers_Id(id).stream().collect(Collectors.toList()); return roleSmallMapper.toDto(roleRepository.findByUsers_Id(id).stream().collect(Collectors.toList()));
} }
@Override @Override
......
...@@ -102,18 +102,17 @@ public class UserServiceImpl implements UserService { ...@@ -102,18 +102,17 @@ public class UserServiceImpl implements UserService {
} }
@Override @Override
public User findByName(String userName) { public UserDTO findByName(String userName) {
User user = null; User user = null;
if(ValidationUtil.isEmail(userName)){ if(ValidationUtil.isEmail(userName)){
user = userRepository.findByEmail(userName); user = userRepository.findByEmail(userName);
} else { } else {
user = userRepository.findByUsername(userName); user = userRepository.findByUsername(userName);
} }
if (user == null) { if (user == null) {
throw new EntityNotFoundException(User.class, "name", userName); throw new EntityNotFoundException(User.class, "name", userName);
} else { } else {
return user; return userMapper.toDto(user);
} }
} }
......
...@@ -4,6 +4,7 @@ import me.zhengjie.mapper.EntityMapper; ...@@ -4,6 +4,7 @@ import me.zhengjie.mapper.EntityMapper;
import me.zhengjie.modules.system.domain.Job; import me.zhengjie.modules.system.domain.Job;
import me.zhengjie.modules.system.service.dto.JobDTO; import me.zhengjie.modules.system.service.dto.JobDTO;
import org.mapstruct.Mapper; import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.ReportingPolicy; import org.mapstruct.ReportingPolicy;
/** /**
...@@ -13,4 +14,6 @@ import org.mapstruct.ReportingPolicy; ...@@ -13,4 +14,6 @@ import org.mapstruct.ReportingPolicy;
@Mapper(componentModel = "spring",uses = {DeptMapper.class},unmappedTargetPolicy = ReportingPolicy.IGNORE) @Mapper(componentModel = "spring",uses = {DeptMapper.class},unmappedTargetPolicy = ReportingPolicy.IGNORE)
public interface JobMapper extends EntityMapper<JobDTO, Job> { public interface JobMapper extends EntityMapper<JobDTO, Job> {
@Mapping(source = "deptSuperiorName", target = "deptSuperiorName")
JobDTO toDto(Job job, String deptSuperiorName);
} }
\ No newline at end of file
Supports Markdown
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