Commit 9f43851e authored by zhengjie's avatar zhengjie
Browse files

1.7版本发布,详情查看版本说明

parent 1402e584
package me.zhengjie.modules.system.rest;
import me.zhengjie.aop.log.Log;
import me.zhengjie.config.DataScope;
import me.zhengjie.exception.BadRequestException;
import me.zhengjie.modules.system.domain.Job;
import me.zhengjie.modules.system.service.JobService;
import me.zhengjie.modules.system.service.query.JobQueryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import java.util.Set;
/**
* @author jie
* @date 2019-03-29
*/
@RestController
@RequestMapping("api")
public class JobController {
@Autowired
private JobService jobService;
@Autowired
private JobQueryService jobQueryService;
@Autowired
private DataScope dataScope;
private static final String ENTITY_NAME = "job";
@Log("查询岗位")
@GetMapping(value = "/job")
@PreAuthorize("hasAnyRole('ADMIN','USERJOB_ALL','USERJOB_SELECT','USER_ALL','USER_SELECT')")
public ResponseEntity getJobs(@RequestParam(required = false) String name,
@RequestParam(required = false) Long deptId,
@RequestParam(required = false) Boolean enabled,
Pageable pageable){
// 数据权限
Set<Long> deptIds = dataScope.getDeptIds();
return new ResponseEntity(jobQueryService.queryAll(name, enabled , deptIds, deptId, pageable),HttpStatus.OK);
}
@Log("新增岗位")
@PostMapping(value = "/job")
@PreAuthorize("hasAnyRole('ADMIN','USERJOB_ALL','USERJOB_CREATE')")
public ResponseEntity create(@Validated @RequestBody Job resources){
if (resources.getId() != null) {
throw new BadRequestException("A new "+ ENTITY_NAME +" cannot already have an ID");
}
return new ResponseEntity(jobService.create(resources),HttpStatus.CREATED);
}
@Log("修改岗位")
@PutMapping(value = "/job")
@PreAuthorize("hasAnyRole('ADMIN','USERJOB_ALL','USERJOB_EDIT')")
public ResponseEntity update(@Validated(Job.Update.class) @RequestBody Job resources){
jobService.update(resources);
return new ResponseEntity(HttpStatus.NO_CONTENT);
}
@Log("删除岗位")
@DeleteMapping(value = "/job/{id}")
@PreAuthorize("hasAnyRole('ADMIN','USERJOB_ALL','USERJOB_DELETE')")
public ResponseEntity delete(@PathVariable Long id){
jobService.delete(id);
return new ResponseEntity(HttpStatus.OK);
}
}
\ No newline at end of file
......@@ -8,6 +8,7 @@ import me.zhengjie.modules.system.service.MenuService;
import me.zhengjie.modules.system.service.RoleService;
import me.zhengjie.modules.system.service.UserService;
import me.zhengjie.modules.system.service.dto.MenuDTO;
import me.zhengjie.modules.system.service.mapper.MenuMapper;
import me.zhengjie.modules.system.service.query.MenuQueryService;
import me.zhengjie.utils.SecurityContextHolder;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -39,6 +40,9 @@ public class MenuController {
@Autowired
private RoleService roleService;
@Autowired
private MenuMapper menuMapper;
private static final String ENTITY_NAME = "menu";
/**
......@@ -59,7 +63,7 @@ public class MenuController {
* @return
*/
@GetMapping(value = "/menus/tree")
@PreAuthorize("hasAnyRole('ADMIN','MENU_ALL','MENU_SELECT','ROLES_SELECT','ROLES_ALL')")
@PreAuthorize("hasAnyRole('ADMIN','MENU_ALL','MENU_CREATE','MENU_EDIT','ROLES_SELECT','ROLES_ALL')")
public ResponseEntity getMenuTree(){
return new ResponseEntity(menuService.getMenuTree(menuService.findByPid(0L)),HttpStatus.OK);
}
......@@ -94,6 +98,14 @@ public class MenuController {
@DeleteMapping(value = "/menus/{id}")
@PreAuthorize("hasAnyRole('ADMIN','MENU_ALL','MENU_DELETE')")
public ResponseEntity delete(@PathVariable Long id){
List<Menu> menuList = menuService.findByPid(id);
// 特殊情况,对级联删除进行处理
for (Menu menu : menuList) {
roleService.untiedMenu(menu);
menuService.delete(menu.getId());
}
roleService.untiedMenu(menuService.findOne(id));
menuService.delete(id);
return new ResponseEntity(HttpStatus.OK);
}
......
......@@ -36,8 +36,8 @@ public class PermissionController {
* @return
*/
@GetMapping(value = "/permissions/tree")
@PreAuthorize("hasAnyRole('ADMIN','PERMISSION_ALL','PERMISSION_SELECT','ROLES_SELECT','ROLES_ALL')")
public ResponseEntity getRoleTree(){
@PreAuthorize("hasAnyRole('ADMIN','PERMISSION_ALL','PERMISSION_CREATE','PERMISSION_EDIT','ROLES_SELECT','ROLES_ALL')")
public ResponseEntity getTree(){
return new ResponseEntity(permissionService.getPermissionTree(permissionService.findByPid(0L)),HttpStatus.OK);
}
......
......@@ -40,10 +40,10 @@ public class RoleController {
* 返回全部的角色,新增用户时下拉选择
* @return
*/
@GetMapping(value = "/roles/tree")
@PreAuthorize("hasAnyRole('ADMIN','ROLES_ALL','USER_ALL','USER_SELECT')")
public ResponseEntity getRoleTree(){
return new ResponseEntity(roleService.getRoleTree(),HttpStatus.OK);
@GetMapping(value = "/roles/all")
@PreAuthorize("hasAnyRole('ADMIN','ROLES_ALL','USER_ALL','USER_CREATE','USER_EDIT')")
public ResponseEntity getAll(){
return new ResponseEntity(roleQueryService.queryAll(),HttpStatus.OK);
}
@Log("查询角色")
......
package me.zhengjie.modules.system.rest;
import me.zhengjie.aop.log.Log;
import me.zhengjie.config.DataScope;
import me.zhengjie.domain.Picture;
import me.zhengjie.domain.VerificationCode;
import me.zhengjie.modules.system.domain.User;
import me.zhengjie.exception.BadRequestException;
import me.zhengjie.modules.security.security.JwtUser;
import me.zhengjie.modules.system.service.DeptService;
import me.zhengjie.service.PictureService;
import me.zhengjie.service.VerificationCodeService;
import me.zhengjie.utils.ElAdminConstant;
import me.zhengjie.utils.EncryptUtils;
import me.zhengjie.modules.security.utils.JwtTokenUtil;
import me.zhengjie.utils.*;
import me.zhengjie.modules.system.service.UserService;
import me.zhengjie.modules.system.service.dto.UserDTO;
import me.zhengjie.modules.system.service.query.UserQueryService;
import me.zhengjie.utils.SecurityContextHolder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.data.domain.Pageable;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.util.CollectionUtils;
import org.springframework.util.ObjectUtils;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import java.util.HashMap;
import java.util.Map;
import java.util.*;
/**
* @author jie
......@@ -44,14 +41,13 @@ public class UserController {
private UserQueryService userQueryService;
@Autowired
private JwtTokenUtil jwtTokenUtil;
private PictureService pictureService;
@Autowired
@Qualifier("jwtUserDetailsService")
private UserDetailsService userDetailsService;
private DataScope dataScope;
@Autowired
private PictureService pictureService;
private DeptService deptService;
@Autowired
private VerificationCodeService verificationCodeService;
......@@ -63,7 +59,34 @@ public class UserController {
@GetMapping(value = "/users")
@PreAuthorize("hasAnyRole('ADMIN','USER_ALL','USER_SELECT')")
public ResponseEntity getUsers(UserDTO userDTO, Pageable pageable){
return new ResponseEntity(userQueryService.queryAll(userDTO,pageable),HttpStatus.OK);
Set<Long> deptSet = new HashSet<>();
Set<Long> result = new HashSet<>();
if (!ObjectUtils.isEmpty(userDTO.getDeptId())) {
deptSet.add(userDTO.getDeptId());
deptSet.addAll(dataScope.getDeptChildren(deptService.findByPid(userDTO.getDeptId())));
}
// 数据权限
Set<Long> deptIds = dataScope.getDeptIds();
// 查询条件不为空并且数据权限不为空则取交集
if (!CollectionUtils.isEmpty(deptIds) && !CollectionUtils.isEmpty(deptSet)){
// 取交集
result.addAll(deptSet);
result.retainAll(deptIds);
// 若无交集,则代表无数据权限
if(result.size() == 0){
return new ResponseEntity(PageUtil.toPage(null,0),HttpStatus.OK);
} else return new ResponseEntity(userQueryService.queryAll(userDTO,result,pageable),HttpStatus.OK);
// 否则取并集
} else {
result.addAll(deptSet);
result.addAll(deptIds);
return new ResponseEntity(userQueryService.queryAll(userDTO,result,pageable),HttpStatus.OK);
}
}
@Log("新增用户")
......@@ -100,10 +123,9 @@ public class UserController {
@GetMapping(value = "/users/validPass/{pass}")
public ResponseEntity validPass(@PathVariable String pass){
UserDetails userDetails = SecurityContextHolder.getUserDetails();
JwtUser jwtUser = (JwtUser)userDetailsService.loadUserByUsername(userDetails.getUsername());
Map map = new HashMap();
map.put("status",200);
if(!jwtUser.getPassword().equals(EncryptUtils.encryptPassword(pass))){
if(!userDetails.getPassword().equals(EncryptUtils.encryptPassword(pass))){
map.put("status",400);
}
return new ResponseEntity(map,HttpStatus.OK);
......@@ -117,11 +139,10 @@ public class UserController {
@GetMapping(value = "/users/updatePass/{pass}")
public ResponseEntity updatePass(@PathVariable String pass){
UserDetails userDetails = SecurityContextHolder.getUserDetails();
JwtUser jwtUser = (JwtUser)userDetailsService.loadUserByUsername(userDetails.getUsername());
if(jwtUser.getPassword().equals(EncryptUtils.encryptPassword(pass))){
if(userDetails.getPassword().equals(EncryptUtils.encryptPassword(pass))){
throw new BadRequestException("新密码不能与旧密码相同");
}
userService.updatePass(jwtUser,EncryptUtils.encryptPassword(pass));
userService.updatePass(userDetails.getUsername(),EncryptUtils.encryptPassword(pass));
return new ResponseEntity(HttpStatus.OK);
}
......@@ -133,9 +154,8 @@ public class UserController {
@PostMapping(value = "/users/updateAvatar")
public ResponseEntity updateAvatar(@RequestParam MultipartFile file){
UserDetails userDetails = SecurityContextHolder.getUserDetails();
JwtUser jwtUser = (JwtUser)userDetailsService.loadUserByUsername(userDetails.getUsername());
Picture picture = pictureService.upload(file,jwtUser.getUsername());
userService.updateAvatar(jwtUser,picture.getUrl());
Picture picture = pictureService.upload(file,userDetails.getUsername());
userService.updateAvatar(userDetails.getUsername(),picture.getUrl());
return new ResponseEntity(HttpStatus.OK);
}
......@@ -145,16 +165,16 @@ public class UserController {
* @param user
* @return
*/
@Log("修改邮箱")
@PostMapping(value = "/users/updateEmail/{code}")
public ResponseEntity updateEmail(@PathVariable String code,@RequestBody User user){
UserDetails userDetails = SecurityContextHolder.getUserDetails();
JwtUser jwtUser = (JwtUser)userDetailsService.loadUserByUsername(userDetails.getUsername());
if(!jwtUser.getPassword().equals(EncryptUtils.encryptPassword(user.getPassword()))){
if(!userDetails.getPassword().equals(EncryptUtils.encryptPassword(user.getPassword()))){
throw new BadRequestException("密码错误");
}
VerificationCode verificationCode = new VerificationCode(code, ElAdminConstant.RESET_MAIL,"email",user.getEmail());
verificationCodeService.validated(verificationCode);
userService.updateEmail(jwtUser,user.getEmail());
userService.updateEmail(userDetails.getUsername(),user.getEmail());
return new ResponseEntity(HttpStatus.OK);
}
}
package me.zhengjie.modules.system.service;
import me.zhengjie.modules.system.domain.Dept;
import me.zhengjie.modules.system.service.dto.DeptDTO;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import java.util.List;
/**
* @author jie
* @date 2019-03-25
*/
@CacheConfig(cacheNames = "dept")
public interface DeptService {
/**
* findById
* @param id
* @return
*/
@Cacheable(key = "#p0")
DeptDTO findById(Long id);
/**
* create
* @param resources
* @return
*/
@CacheEvict(allEntries = true)
DeptDTO create(Dept resources);
/**
* update
* @param resources
*/
@CacheEvict(allEntries = true)
void update(Dept resources);
/**
* delete
* @param id
*/
@CacheEvict(allEntries = true)
void delete(Long id);
/**
* buildTree
* @param deptDTOS
* @return
*/
@Cacheable(keyGenerator = "keyGenerator")
Object buildTree(List<DeptDTO> deptDTOS);
/**
* findByPid
* @param pid
* @return
*/
@Cacheable(keyGenerator = "keyGenerator")
List<Dept> findByPid(long pid);
}
\ No newline at end of file
package me.zhengjie.modules.system.service;
import me.zhengjie.modules.system.domain.DictDetail;
import me.zhengjie.modules.system.service.dto.DictDetailDTO;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
/**
* @author jie
* @date 2019-04-10
*/
@CacheConfig(cacheNames = "dictDetail")
public interface DictDetailService {
/**
* findById
* @param id
* @return
*/
@Cacheable(key = "#p0")
DictDetailDTO findById(Long id);
/**
* create
* @param resources
* @return
*/
@CacheEvict(allEntries = true)
DictDetailDTO create(DictDetail resources);
/**
* update
* @param resources
*/
@CacheEvict(allEntries = true)
void update(DictDetail resources);
/**
* delete
* @param id
*/
@CacheEvict(allEntries = true)
void delete(Long id);
}
\ No newline at end of file
package me.zhengjie.modules.system.service;
import me.zhengjie.modules.system.domain.Dict;
import me.zhengjie.modules.system.service.dto.DictDTO;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
/**
* @author jie
* @date 2019-04-10
*/
@CacheConfig(cacheNames = "dict")
public interface DictService {
/**
* findById
* @param id
* @return
*/
@Cacheable(key = "#p0")
DictDTO findById(Long id);
/**
* create
* @param resources
* @return
*/
@CacheEvict(allEntries = true)
DictDTO create(Dict resources);
/**
* update
* @param resources
*/
@CacheEvict(allEntries = true)
void update(Dict resources);
/**
* delete
* @param id
*/
@CacheEvict(allEntries = true)
void delete(Long id);
}
\ No newline at end of file
package me.zhengjie.modules.system.service;
import me.zhengjie.modules.system.domain.Job;
import me.zhengjie.modules.system.service.dto.JobDTO;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
/**
* @author jie
* @date 2019-03-29
*/
@CacheConfig(cacheNames = "job")
public interface JobService {
/**
* findById
* @param id
* @return
*/
@Cacheable(key = "#p0")
JobDTO findById(Long id);
/**
* create
* @param resources
* @return
*/
@CacheEvict(allEntries = true)
JobDTO create(Job resources);
/**
* update
* @param resources
*/
@CacheEvict(allEntries = true)
void update(Job resources);
/**
* delete
* @param id
*/
@CacheEvict(allEntries = true)
void delete(Long id);
}
\ No newline at end of file
......@@ -74,7 +74,7 @@ public interface MenuService {
* @param roles
* @return
*/
List<MenuDTO> findByRoles(Set<Role> roles);
List<MenuDTO> findByRoles(List<Role> roles);
/**
* buildMenus
......@@ -82,4 +82,6 @@ public interface MenuService {
* @return
*/
Object buildMenus(List<MenuDTO> byRoles);
Menu findOne(Long id);
}
......@@ -5,6 +5,8 @@ import me.zhengjie.modules.system.service.dto.PermissionDTO;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import java.util.Collection;
import java.util.List;
/**
......
package me.zhengjie.modules.system.service;
import me.zhengjie.modules.system.domain.Menu;
import me.zhengjie.modules.system.domain.Role;
import me.zhengjie.modules.system.service.dto.RoleDTO;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import java.util.List;
import java.util.Set;
/**
......@@ -45,19 +47,13 @@ public interface RoleService {
@CacheEvict(allEntries = true)
void delete(Long id);
/**
* role tree
* @return
*/
@Cacheable(key = "'tree'")
Object getRoleTree();
/**
* findByUsers_Id
* @param id
* @return
*/
Set<Role> findByUsers_Id(Long id);
@Cacheable(keyGenerator = "keyGenerator")
List<Role> findByUsers_Id(Long id);
/**
* updatePermission
......@@ -74,4 +70,7 @@ public interface RoleService {
*/
@CacheEvict(allEntries = true)
void updateMenu(Role resources, RoleDTO roleDTO);
@CacheEvict(allEntries = true)
void untiedMenu(Menu menu);
}
......@@ -49,30 +49,30 @@ public interface UserService {
* @param userName
* @return
*/
@Cacheable(keyGenerator = "keyGenerator")
@Cacheable(key = "'loadUserByUsername:'+#p0")
User findByName(String userName);
/**
* 修改密码
* @param jwtUser
* @param username
* @param encryptPassword
*/
@CacheEvict(allEntries = true)
void updatePass(JwtUser jwtUser, String encryptPassword);
void updatePass(String username, String encryptPassword);
/**
* 修改头像
* @param jwtUser
* @param username
* @param url
*/
@CacheEvict(allEntries = true)
void updateAvatar(JwtUser jwtUser, String url);
void updateAvatar(String username, String url);
/**
* 修改邮箱
* @param jwtUser
* @param username
* @param email
*/
@CacheEvict(allEntries = true)
void updateEmail(JwtUser jwtUser, String email);
void updateEmail(String username, String email);
}
package me.zhengjie.modules.system.service.dto;
import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.Data;
import javax.validation.constraints.NotNull;
import java.sql.Timestamp;
import java.io.Serializable;
import java.util.List;
/**
* @author jie
* @date 2019-03-25
*/
@Data
public class DeptDTO implements Serializable {
/**
* ID
*/
private Long id;
/**
* 名称
*/
private String name;
@NotNull
private Boolean enabled;
/**
* 上级部门
*/
private Long pid;
@JsonInclude(JsonInclude.Include.NON_EMPTY)
private List<DeptDTO> children;
private Timestamp createTime;
public String getLabel() {
return name;
}
}
\ No newline at end of file
package me.zhengjie.modules.system.service.dto;
import lombok.Data;
import java.sql.Timestamp;
import java.io.Serializable;
/**
* @author jie
* @date 2019-04-10
*/
@Data
public class DictDTO implements Serializable {
private Long id;
/**
* 字典名称
*/
private String name;
/**
* 描述
*/
private String remark;
}
\ No newline at end of file
package me.zhengjie.modules.system.service.dto;
import lombok.Data;
import java.io.Serializable;
/**
* @author jie
* @date 2019-04-10
*/
@Data
public class DictDetailDTO implements Serializable {
private Long id;
/**
* 字典标签
*/
private String label;
/**
* 字典值
*/
private String value;
/**
* 排序
*/
private String sort;
/**
* 字典id
*/
private String dictName;
}
\ No newline at end of file
package me.zhengjie.modules.system.service.dto;
import lombok.Data;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import java.sql.Timestamp;
import java.io.Serializable;
/**
* @author jie
* @date 2019-03-29
*/
@Data
@NoArgsConstructor
public class JobDTO implements Serializable {
/**
* ID
*/
private Long id;
private Long sort;
/**
* 名称
*/
private String name;
/**
* 状态
*/
private Boolean enabled;
private DeptDTO dept;
/**
* 创建日期
*/
private Timestamp createTime;
public JobDTO(String name, Boolean enabled) {
this.name = name;
this.enabled = enabled;
}
}
\ No newline at end of file
......@@ -16,11 +16,15 @@ public class RoleDTO implements Serializable {
private String name;
private String dataScope;
private String remark;
private Set<PermissionDTO> permissions;
private Set<MenuDTO> menus;
private Set<DeptDTO> depts;
private Timestamp createTime;
}
......@@ -24,6 +24,8 @@ public class UserDTO implements Serializable {
private String email;
private String phone;
private Boolean enabled;
@JsonIgnore
......@@ -35,4 +37,11 @@ public class UserDTO implements Serializable {
@ApiModelProperty(hidden = true)
private Set<RoleDTO> roles;
@ApiModelProperty(hidden = true)
private JobDTO job;
private DeptDTO dept;
private Long deptId;
}
package me.zhengjie.modules.system.service.impl;
import me.zhengjie.exception.BadRequestException;
import me.zhengjie.modules.system.domain.Dept;
import me.zhengjie.utils.ValidationUtil;
import me.zhengjie.modules.system.repository.DeptRepository;
import me.zhengjie.modules.system.service.DeptService;
import me.zhengjie.modules.system.service.dto.DeptDTO;
import me.zhengjie.modules.system.service.mapper.DeptMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
import java.util.*;
import java.util.stream.Collectors;
/**
* @author jie
* @date 2019-03-25
*/
@Service
@Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class)
public class DeptServiceImpl implements DeptService {
@Autowired
private DeptRepository deptRepository;
@Autowired
private DeptMapper deptMapper;
@Override
public DeptDTO findById(Long id) {
Optional<Dept> dept = deptRepository.findById(id);
ValidationUtil.isNull(dept,"Dept","id",id);
return deptMapper.toDto(dept.get());
}
@Override
public List<Dept> findByPid(long pid) {
return deptRepository.findByPid(pid);
}
@Override
public Object buildTree(List<DeptDTO> deptDTOS) {
Set<DeptDTO> trees = new LinkedHashSet<>();
Set<DeptDTO> depts= new LinkedHashSet<>();
Boolean isChild;
for (DeptDTO deptDTO : deptDTOS) {
isChild = false;
if ("0".equals(deptDTO.getPid().toString())) {
trees.add(deptDTO);
}
for (DeptDTO it : deptDTOS) {
if (it.getPid().equals(deptDTO.getId())) {
isChild = true;
if (deptDTO.getChildren() == null) {
deptDTO.setChildren(new ArrayList<DeptDTO>());
}
deptDTO.getChildren().add(it);
}
}
if(isChild) {
depts.add(deptDTO);
}
}
if (CollectionUtils.isEmpty(trees)) {
trees = depts;
}
Integer totalElements = deptDTOS!=null?deptDTOS.size():0;
Map map = new HashMap();
map.put("totalElements",totalElements);
map.put("content",CollectionUtils.isEmpty(trees)?deptDTOS:trees);
return map;
}
@Override
@Transactional(rollbackFor = Exception.class)
public DeptDTO create(Dept resources) {
return deptMapper.toDto(deptRepository.save(resources));
}
@Override
@Transactional(rollbackFor = Exception.class)
public void update(Dept resources) {
if(resources.getId().equals(resources.getPid())) {
throw new BadRequestException("上级不能为自己");
}
Optional<Dept> optionalDept = deptRepository.findById(resources.getId());
ValidationUtil.isNull( optionalDept,"Dept","id",resources.getId());
Dept dept = optionalDept.get();
// 此处需自己修改
resources.setId(dept.getId());
deptRepository.save(resources);
}
@Override
@Transactional(rollbackFor = Exception.class)
public void delete(Long id) {
deptRepository.deleteById(id);
}
}
\ 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