Commit 0f0392d7 authored by dqjdda's avatar dqjdda
Browse files

Merge branch '2.2DEV'

parents d0ffe1a8 f9bb8cf2
......@@ -15,4 +15,6 @@ public class MenuMetaVo implements Serializable {
private String title;
private String icon;
private Boolean noCache;
}
......@@ -19,6 +19,8 @@ public class MenuVo implements Serializable {
private String path;
private Boolean hidden;
private String redirect;
private String component;
......
......@@ -23,6 +23,13 @@ public interface MenuRepository extends JpaRepository<Menu, Long>, JpaSpecificat
*/
Menu findByName(String name);
/**
* findByName
* @param name
* @return
*/
Menu findByComponentName(String name);
/**
* findByPid
* @param pid
......
package me.zhengjie.modules.system.repository;
import me.zhengjie.modules.system.domain.Permission;
import me.zhengjie.modules.system.domain.Role;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import java.util.Collection;
import java.util.List;
import java.util.Set;
/**
* @author Zheng Jie
......
......@@ -3,6 +3,8 @@ package me.zhengjie.modules.system.repository;
import me.zhengjie.modules.system.domain.Role;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import java.util.Set;
......@@ -21,5 +23,11 @@ public interface RoleRepository extends JpaRepository<Role, Long>, JpaSpecificat
Set<Role> findByUsers_Id(Long id);
Set<Role> findByMenus_Id(Long id);
@Modifying
@Query(value = "delete from roles_permissions where permission_id = ?1",nativeQuery = true)
void untiedPermission(Long id);
@Modifying
@Query(value = "delete from roles_menus where menu_id = ?1",nativeQuery = true)
void untiedMenu(Long id);
}
package me.zhengjie.modules.system.repository;
import me.zhengjie.modules.system.domain.UserAvatar;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import java.util.Date;
/**
* @author Zheng Jie
* @date 2018-11-22
*/
public interface UserAvatarRepository extends JpaRepository<UserAvatar, Long>, JpaSpecificationExecutor {
}
......@@ -7,6 +7,7 @@ import me.zhengjie.modules.system.domain.Dept;
import me.zhengjie.modules.system.service.DeptService;
import me.zhengjie.modules.system.service.dto.DeptDTO;
import me.zhengjie.modules.system.service.dto.DeptQueryCriteria;
import me.zhengjie.utils.ThrowableUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
......@@ -63,7 +64,11 @@ public class DeptController {
@DeleteMapping(value = "/dept/{id}")
@PreAuthorize("hasAnyRole('ADMIN','DEPT_ALL','DEPT_DELETE')")
public ResponseEntity delete(@PathVariable Long id){
deptService.delete(id);
try {
deptService.delete(id);
}catch (Throwable e){
ThrowableUtil.throwForeignKeyException(e, "该部门存在岗位或者角色关联,请取消关联后再试");
}
return new ResponseEntity(HttpStatus.OK);
}
}
\ No newline at end of file
......@@ -4,7 +4,6 @@ import me.zhengjie.aop.log.Log;
import me.zhengjie.exception.BadRequestException;
import me.zhengjie.modules.system.domain.Dict;
import me.zhengjie.modules.system.service.DictService;
import me.zhengjie.modules.system.service.dto.DictDTO;
import me.zhengjie.modules.system.service.dto.DictQueryCriteria;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable;
......
......@@ -6,6 +6,7 @@ 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.dto.JobQueryCriteria;
import me.zhengjie.utils.ThrowableUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable;
import org.springframework.http.HttpStatus;
......@@ -64,7 +65,11 @@ public class JobController {
@DeleteMapping(value = "/job/{id}")
@PreAuthorize("hasAnyRole('ADMIN','USERJOB_ALL','USERJOB_DELETE')")
public ResponseEntity delete(@PathVariable Long id){
jobService.delete(id);
try {
jobService.delete(id);
}catch (Throwable e){
ThrowableUtil.throwForeignKeyException(e, "该岗位存在用户关联,请取消关联后再试");
}
return new ResponseEntity(HttpStatus.OK);
}
}
\ No newline at end of file
......@@ -16,7 +16,9 @@ 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.HashSet;
import java.util.List;
import java.util.Set;
/**
* @author Zheng Jie
......@@ -90,14 +92,10 @@ public class MenuController {
@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);
Set<Menu> menuSet = new HashSet<>();
menuSet.add(menuService.findOne(id));
menuSet = menuService.getDeleteMenus(menuList, menuSet);
menuService.delete(menuSet);
return new ResponseEntity(HttpStatus.OK);
}
}
......@@ -6,6 +6,7 @@ import me.zhengjie.exception.BadRequestException;
import me.zhengjie.modules.system.service.PermissionService;
import me.zhengjie.modules.system.service.dto.PermissionDTO;
import me.zhengjie.modules.system.service.dto.PermissionQueryCriteria;
import me.zhengjie.modules.system.service.mapper.PermissionMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
......@@ -13,7 +14,9 @@ import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
/**
* @author Zheng Jie
......@@ -26,6 +29,9 @@ public class PermissionController {
@Autowired
private PermissionService permissionService;
@Autowired
private PermissionMapper permissionMapper;
private static final String ENTITY_NAME = "permission";
/**
......@@ -68,7 +74,11 @@ public class PermissionController {
@DeleteMapping(value = "/permissions/{id}")
@PreAuthorize("hasAnyRole('ADMIN','PERMISSION_ALL','PERMISSION_DELETE')")
public ResponseEntity delete(@PathVariable Long id){
permissionService.delete(id);
List<Permission> permissions = permissionService.findByPid(id);
Set<Permission> permissionSet = new HashSet<>();
permissionSet.add(permissionMapper.toEntity(permissionService.findById(id)));
permissionSet = permissionService.getDeletePermission(permissions, permissionSet);
permissionService.delete(permissionSet);
return new ResponseEntity(HttpStatus.OK);
}
}
......@@ -5,10 +5,11 @@ import me.zhengjie.aop.log.Log;
import me.zhengjie.modules.system.domain.Role;
import me.zhengjie.exception.BadRequestException;
import me.zhengjie.modules.system.service.RoleService;
import me.zhengjie.modules.system.service.dto.MenuQueryCriteria;
import me.zhengjie.modules.system.service.dto.RoleQueryCriteria;
import me.zhengjie.modules.system.service.dto.RoleSmallDTO;
import me.zhengjie.utils.SecurityUtils;
import me.zhengjie.utils.ThrowableUtil;
import org.hibernate.exception.ConstraintViolationException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
......@@ -16,6 +17,7 @@ import org.springframework.data.web.PageableDefault;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.transaction.TransactionSystemException;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import java.util.Collections;
......@@ -107,7 +109,11 @@ public class RoleController {
@DeleteMapping(value = "/roles/{id}")
@PreAuthorize("hasAnyRole('ADMIN','ROLES_ALL','ROLES_DELETE')")
public ResponseEntity delete(@PathVariable Long id){
roleService.delete(id);
try {
roleService.delete(id);
}catch (Throwable e){
ThrowableUtil.throwForeignKeyException(e, "该角色存在用户关联,请取消关联后再试");
}
return new ResponseEntity(HttpStatus.OK);
}
}
......@@ -26,6 +26,8 @@ import org.springframework.util.ObjectUtils;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.*;
import java.util.stream.Collectors;
......@@ -55,6 +57,13 @@ public class UserController {
@Autowired
private VerificationCodeService verificationCodeService;
@Log("导出用户数据")
@GetMapping(value = "/users/download")
@PreAuthorize("hasAnyRole('ADMIN','USER_ALL','USER_SELECT')")
public void update(HttpServletResponse response, UserQueryCriteria criteria) throws IOException {
userService.download(userService.queryAll(criteria), response);
}
@Log("查询用户")
@GetMapping(value = "/users")
@PreAuthorize("hasAnyRole('ADMIN','USER_ALL','USER_SELECT')")
......@@ -147,8 +156,7 @@ public class UserController {
*/
@PostMapping(value = "/users/updateAvatar")
public ResponseEntity updateAvatar(@RequestParam MultipartFile file){
Picture picture = pictureService.upload(file, SecurityUtils.getUsername());
userService.updateAvatar(SecurityUtils.getUsername(),picture.getUrl());
userService.updateAvatar(file);
return new ResponseEntity(HttpStatus.OK);
}
......
......@@ -22,7 +22,7 @@ public interface DeptService {
* @param criteria
* @return
*/
@Cacheable(keyGenerator = "keyGenerator")
@Cacheable
List<DeptDTO> queryAll(DeptQueryCriteria criteria);
/**
......@@ -60,7 +60,7 @@ public interface DeptService {
* @param deptDTOS
* @return
*/
@Cacheable(keyGenerator = "keyGenerator")
@Cacheable
Object buildTree(List<DeptDTO> deptDTOS);
/**
......@@ -68,7 +68,7 @@ public interface DeptService {
* @param pid
* @return
*/
@Cacheable(keyGenerator = "keyGenerator")
@Cacheable
List<Dept> findByPid(long pid);
Set<Dept> findByRoleIds(Long id);
......
......@@ -47,6 +47,6 @@ public interface DictDetailService {
@CacheEvict(allEntries = true)
void delete(Long id);
@Cacheable(keyGenerator = "keyGenerator")
@Cacheable
Map queryAll(DictDetailQueryCriteria criteria, Pageable pageable);
}
\ No newline at end of file
......@@ -21,7 +21,7 @@ public interface DictService {
* @param pageable
* @return
*/
@Cacheable(keyGenerator = "keyGenerator")
@Cacheable
Object queryAll(DictQueryCriteria dict, Pageable pageable);
/**
......
......@@ -9,6 +9,7 @@ import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import java.util.List;
import java.util.Map;
import java.util.Set;
/**
* @author Zheng Jie
......@@ -22,7 +23,7 @@ public interface MenuService {
* @param criteria
* @return
*/
@Cacheable(keyGenerator = "keyGenerator")
@Cacheable
List<MenuDTO> queryAll(MenuQueryCriteria criteria);
/**
......@@ -49,11 +50,12 @@ public interface MenuService {
void update(Menu resources);
/**
* delete
* @param id
* getDeleteMenus
* @param menuList
* @param menuSet
* @return
*/
@CacheEvict(allEntries = true)
void delete(Long id);
Set<Menu> getDeleteMenus(List<Menu> menuList, Set<Menu> menuSet);
/**
* permission tree
......@@ -92,4 +94,11 @@ public interface MenuService {
Object buildMenus(List<MenuDTO> byRoles);
Menu findOne(Long id);
/**
* delete
* @param menuSet
*/
@CacheEvict(allEntries = true)
void delete(Set<Menu> menuSet);
}
......@@ -8,6 +8,7 @@ import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import java.util.List;
import java.util.Set;
/**
* @author Zheng Jie
......@@ -41,10 +42,10 @@ public interface PermissionService {
/**
* delete
* @param id
* @param permissions
*/
@CacheEvict(allEntries = true)
void delete(Long id);
void delete(Set<Permission> permissions);
/**
* permission tree
......@@ -66,7 +67,7 @@ public interface PermissionService {
* @param permissionDTOS
* @return
*/
@Cacheable(keyGenerator = "keyGenerator")
@Cacheable
Object buildTree(List<PermissionDTO> permissionDTOS);
/**
......@@ -74,6 +75,8 @@ public interface PermissionService {
* @param criteria
* @return
*/
@Cacheable(keyGenerator = "keyGenerator")
@Cacheable
List<PermissionDTO> queryAll(PermissionQueryCriteria criteria);
Set<Permission> getDeletePermission(List<Permission> permissions, Set<Permission> permissionSet);
}
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 me.zhengjie.modules.system.service.dto.RoleQueryCriteria;
......@@ -59,7 +58,7 @@ public interface RoleService {
@Cacheable(key = "'findByUsers_Id:' + #p0")
List<RoleSmallDTO> findByUsers_Id(Long id);
@Cacheable(keyGenerator = "keyGenerator")
@Cacheable
Integer findByRoles(Set<Role> roles);
/**
......@@ -79,13 +78,14 @@ public interface RoleService {
void updateMenu(Role resources, RoleDTO roleDTO);
@CacheEvict(allEntries = true)
void untiedMenu(Menu menu);
void untiedMenu(Long id);
/**
* queryAll
* @param pageable
* @return
*/
@Cacheable
Object queryAll(Pageable pageable);
/**
......@@ -94,5 +94,17 @@ public interface RoleService {
* @param criteria
* @return
*/
@Cacheable
Object queryAll(RoleQueryCriteria criteria, Pageable pageable);
/**
* queryAll
* @param criteria
* @return
*/
@Cacheable
List<RoleDTO> queryAll(RoleQueryCriteria criteria);
@CacheEvict(allEntries = true)
void untiedPermission(Long id);
}
......@@ -8,6 +8,11 @@ import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.data.domain.Pageable;
import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;
/**
* @author Zheng Jie
......@@ -64,11 +69,10 @@ public interface UserService {
/**
* 修改头像
* @param username
* @param url
* @param file
*/
@CacheEvict(allEntries = true)
void updateAvatar(String username, String url);
void updateAvatar(MultipartFile file);
/**
* 修改邮箱
......@@ -78,6 +82,11 @@ public interface UserService {
@CacheEvict(allEntries = true)
void updateEmail(String username, String email);
@Cacheable(keyGenerator = "keyGenerator")
@Cacheable
Object queryAll(UserQueryCriteria criteria, Pageable pageable);
@Cacheable
List<UserDTO> queryAll(UserQueryCriteria criteria);
void download(List<UserDTO> queryAll, HttpServletResponse response) throws IOException;
}
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