Commit bf7c1eeb authored by dqjdda's avatar dqjdda
Browse files

代码优化完成,去除大量idea警告,代码生成器优化等

parent e3c3ebb1
package me.zhengjie.modules.system.rest;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import me.zhengjie.aop.log.Log;
import me.zhengjie.exception.BadRequestException;
import me.zhengjie.modules.system.domain.DictDetail;
......@@ -25,47 +27,55 @@ import java.util.stream.Collectors;
* @date 2019-04-10
*/
@RestController
@RequestMapping("api")
@Api(tags = "系统:字典详情管理")
@RequestMapping("/api/dictDetail")
public class DictDetailController {
@Autowired
private DictDetailService dictDetailService;
private final DictDetailService dictDetailService;
private static final String ENTITY_NAME = "dictDetail";
public DictDetailController(DictDetailService dictDetailService) {
this.dictDetailService = dictDetailService;
}
@Log("查询字典详情")
@GetMapping(value = "/dictDetail")
@ApiOperation("查询字典详情")
@GetMapping
public ResponseEntity getDictDetails(DictDetailQueryCriteria criteria,
@PageableDefault(value = 10, sort = {"sort"}, direction = Sort.Direction.ASC) Pageable pageable){
String[] names = criteria.getDictName().split(",");
return new ResponseEntity(dictDetailService.queryAll(criteria,pageable),HttpStatus.OK);
return new ResponseEntity<>(dictDetailService.queryAll(criteria,pageable),HttpStatus.OK);
}
@Log("查询多个字典详情")
@GetMapping(value = "/dictDetail/map")
@ApiOperation("查询多个字典详情")
@GetMapping(value = "/map")
public ResponseEntity getDictDetailMaps(DictDetailQueryCriteria criteria,
@PageableDefault(value = 10, sort = {"sort"}, direction = Sort.Direction.ASC) Pageable pageable){
String[] names = criteria.getDictName().split(",");
Map map = new HashMap(names.length);
Map<String,Object> map = new HashMap<>(names.length);
for (String name : names) {
criteria.setDictName(name);
map.put(name,dictDetailService.queryAll(criteria,pageable).get("content"));
}
return new ResponseEntity(map,HttpStatus.OK);
return new ResponseEntity<>(map,HttpStatus.OK);
}
@Log("新增字典详情")
@PostMapping(value = "/dictDetail")
@ApiOperation("新增字典详情")
@PostMapping
@PreAuthorize("hasAnyRole('ADMIN','DICT_ALL','DICT_CREATE')")
public ResponseEntity create(@Validated @RequestBody DictDetail resources){
if (resources.getId() != null) {
throw new BadRequestException("A new "+ ENTITY_NAME +" cannot already have an ID");
}
return new ResponseEntity(dictDetailService.create(resources),HttpStatus.CREATED);
return new ResponseEntity<>(dictDetailService.create(resources),HttpStatus.CREATED);
}
@Log("修改字典详情")
@PutMapping(value = "/dictDetail")
@ApiOperation("修改字典详情")
@PutMapping
@PreAuthorize("hasAnyRole('ADMIN','DICT_ALL','DICT_EDIT')")
public ResponseEntity update(@Validated(DictDetail.Update.class) @RequestBody DictDetail resources){
dictDetailService.update(resources);
......@@ -73,7 +83,8 @@ public class DictDetailController {
}
@Log("删除字典详情")
@DeleteMapping(value = "/dictDetail/{id}")
@ApiOperation("删除字典详情")
@DeleteMapping(value = "/{id}")
@PreAuthorize("hasAnyRole('ADMIN','DICT_ALL','DICT_DELETE')")
public ResponseEntity delete(@PathVariable Long id){
dictDetailService.delete(id);
......
package me.zhengjie.modules.system.rest;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import me.zhengjie.aop.log.Log;
import me.zhengjie.config.DataScope;
import me.zhengjie.exception.BadRequestException;
......@@ -21,40 +23,47 @@ import java.util.Set;
* @author Zheng Jie
* @date 2019-03-29
*/
@Api(tags = "系统:岗位管理")
@RestController
@RequestMapping("api")
@RequestMapping("/api/job")
public class JobController {
@Autowired
private JobService jobService;
private final JobService jobService;
@Autowired
private DataScope dataScope;
private final DataScope dataScope;
private static final String ENTITY_NAME = "job";
public JobController(JobService jobService, DataScope dataScope) {
this.jobService = jobService;
this.dataScope = dataScope;
}
@Log("查询岗位")
@GetMapping(value = "/job")
@ApiOperation("查询岗位")
@GetMapping
@PreAuthorize("hasAnyRole('ADMIN','USERJOB_ALL','USERJOB_SELECT','USER_ALL','USER_SELECT')")
public ResponseEntity getJobs(JobQueryCriteria criteria,
Pageable pageable){
// 数据权限
criteria.setDeptIds(dataScope.getDeptIds());
return new ResponseEntity(jobService.queryAll(criteria, pageable),HttpStatus.OK);
return new ResponseEntity<>(jobService.queryAll(criteria, pageable),HttpStatus.OK);
}
@Log("新增岗位")
@PostMapping(value = "/job")
@ApiOperation("新增岗位")
@PostMapping
@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);
return new ResponseEntity<>(jobService.create(resources),HttpStatus.CREATED);
}
@Log("修改岗位")
@PutMapping(value = "/job")
@ApiOperation("修改岗位")
@PutMapping
@PreAuthorize("hasAnyRole('ADMIN','USERJOB_ALL','USERJOB_EDIT')")
public ResponseEntity update(@Validated(Job.Update.class) @RequestBody Job resources){
jobService.update(resources);
......@@ -62,7 +71,8 @@ public class JobController {
}
@Log("删除岗位")
@DeleteMapping(value = "/job/{id}")
@ApiOperation("删除岗位")
@DeleteMapping(value = "/{id}")
@PreAuthorize("hasAnyRole('ADMIN','USERJOB_ALL','USERJOB_DELETE')")
public ResponseEntity delete(@PathVariable Long id){
try {
......
package me.zhengjie.modules.system.rest;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import me.zhengjie.aop.log.Log;
import me.zhengjie.modules.system.domain.Menu;
import me.zhengjie.exception.BadRequestException;
......@@ -10,7 +12,6 @@ import me.zhengjie.modules.system.service.dto.MenuDTO;
import me.zhengjie.modules.system.service.dto.MenuQueryCriteria;
import me.zhengjie.modules.system.service.dto.UserDTO;
import me.zhengjie.utils.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
......@@ -24,63 +25,63 @@ import java.util.Set;
* @author Zheng Jie
* @date 2018-12-03
*/
@Api(tags = "系统:菜单管理")
@RestController
@RequestMapping("api")
@RequestMapping("/api/menus")
public class MenuController {
@Autowired
private MenuService menuService;
private final MenuService menuService;
@Autowired
private UserService userService;
private final UserService userService;
@Autowired
private RoleService roleService;
private final RoleService roleService;
private static final String ENTITY_NAME = "menu";
/**
* 构建前端路由所需要的菜单
* @return
*/
@GetMapping(value = "/menus/build")
public MenuController(MenuService menuService, UserService userService, RoleService roleService) {
this.menuService = menuService;
this.userService = userService;
this.roleService = roleService;
}
@ApiOperation("获取菜单树")
@GetMapping(value = "/build")
public ResponseEntity buildMenus(){
UserDTO user = userService.findByName(SecurityUtils.getUsername());
List<MenuDTO> menuDTOList = menuService.findByRoles(roleService.findByUsers_Id(user.getId()));
List<MenuDTO> menuDTOTree = (List<MenuDTO>)menuService.buildTree(menuDTOList).get("content");
return new ResponseEntity(menuService.buildMenus(menuDTOTree),HttpStatus.OK);
return new ResponseEntity<>(menuService.buildMenus((List<MenuDTO>) menuService.buildTree(menuDTOList).get("content")),HttpStatus.OK);
}
/**
* 返回全部的菜单
* @return
*/
@GetMapping(value = "/menus/tree")
@ApiOperation("返回全部的菜单")
@GetMapping(value = "/tree")
@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);
return new ResponseEntity<>(menuService.getMenuTree(menuService.findByPid(0L)),HttpStatus.OK);
}
@Log("查询菜单")
@GetMapping(value = "/menus")
@ApiOperation("查询菜单")
@GetMapping
@PreAuthorize("hasAnyRole('ADMIN','MENU_ALL','MENU_SELECT')")
public ResponseEntity getMenus(MenuQueryCriteria criteria){
List<MenuDTO> menuDTOList = menuService.queryAll(criteria);
return new ResponseEntity(menuService.buildTree(menuDTOList),HttpStatus.OK);
return new ResponseEntity<>(menuService.buildTree(menuDTOList),HttpStatus.OK);
}
@Log("新增菜单")
@PostMapping(value = "/menus")
@ApiOperation("新增菜单")
@PostMapping
@PreAuthorize("hasAnyRole('ADMIN','MENU_ALL','MENU_CREATE')")
public ResponseEntity create(@Validated @RequestBody Menu resources){
if (resources.getId() != null) {
throw new BadRequestException("A new "+ ENTITY_NAME +" cannot already have an ID");
}
return new ResponseEntity(menuService.create(resources),HttpStatus.CREATED);
return new ResponseEntity<>(menuService.create(resources),HttpStatus.CREATED);
}
@Log("修改菜单")
@PutMapping(value = "/menus")
@ApiOperation("修改菜单")
@PutMapping
@PreAuthorize("hasAnyRole('ADMIN','MENU_ALL','MENU_EDIT')")
public ResponseEntity update(@Validated(Menu.Update.class) @RequestBody Menu resources){
menuService.update(resources);
......@@ -88,7 +89,8 @@ public class MenuController {
}
@Log("删除菜单")
@DeleteMapping(value = "/menus/{id}")
@ApiOperation("删除菜单")
@DeleteMapping(value = "/{id}")
@PreAuthorize("hasAnyRole('ADMIN','MENU_ALL','MENU_DELETE')")
public ResponseEntity delete(@PathVariable Long id){
List<Menu> menuList = menuService.findByPid(id);
......
package me.zhengjie.modules.system.rest;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import me.zhengjie.aop.log.Log;
import me.zhengjie.modules.system.domain.Permission;
import me.zhengjie.exception.BadRequestException;
......@@ -7,13 +9,11 @@ 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;
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;
......@@ -22,48 +22,52 @@ import java.util.Set;
* @author Zheng Jie
* @date 2018-12-03
*/
@Api(tags = "系统:权限管理")
@RestController
@RequestMapping("api")
@RequestMapping("/api/permissions")
public class PermissionController {
@Autowired
private PermissionService permissionService;
private final PermissionService permissionService;
@Autowired
private PermissionMapper permissionMapper;
private final PermissionMapper permissionMapper;
private static final String ENTITY_NAME = "permission";
/**
* 返回全部的权限,新增角色时下拉选择
* @return
*/
@GetMapping(value = "/permissions/tree")
public PermissionController(PermissionService permissionService, PermissionMapper permissionMapper) {
this.permissionService = permissionService;
this.permissionMapper = permissionMapper;
}
@ApiOperation("返回全部的权限,新增角色时下拉选择")
@GetMapping(value = "/tree")
@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);
return new ResponseEntity<>(permissionService.getPermissionTree(permissionService.findByPid(0L)),HttpStatus.OK);
}
@Log("查询权限")
@GetMapping(value = "/permissions")
@ApiOperation("查询权限")
@GetMapping
@PreAuthorize("hasAnyRole('ADMIN','PERMISSION_ALL','PERMISSION_SELECT')")
public ResponseEntity getPermissions(PermissionQueryCriteria criteria){
List<PermissionDTO> permissionDTOS = permissionService.queryAll(criteria);
return new ResponseEntity(permissionService.buildTree(permissionDTOS),HttpStatus.OK);
return new ResponseEntity<>(permissionService.buildTree(permissionDTOS),HttpStatus.OK);
}
@Log("新增权限")
@PostMapping(value = "/permissions")
@ApiOperation("新增权限")
@PostMapping
@PreAuthorize("hasAnyRole('ADMIN','PERMISSION_ALL','PERMISSION_CREATE')")
public ResponseEntity create(@Validated @RequestBody Permission resources){
if (resources.getId() != null) {
throw new BadRequestException("A new "+ ENTITY_NAME +" cannot already have an ID");
}
return new ResponseEntity(permissionService.create(resources),HttpStatus.CREATED);
return new ResponseEntity<>(permissionService.create(resources),HttpStatus.CREATED);
}
@Log("修改权限")
@PutMapping(value = "/permissions")
@ApiOperation("修改权限")
@PutMapping
@PreAuthorize("hasAnyRole('ADMIN','PERMISSION_ALL','PERMISSION_EDIT')")
public ResponseEntity update(@Validated(Permission.Update.class) @RequestBody Permission resources){
permissionService.update(resources);
......@@ -71,7 +75,8 @@ public class PermissionController {
}
@Log("删除权限")
@DeleteMapping(value = "/permissions/{id}")
@ApiOperation("删除权限")
@DeleteMapping(value = "/{id}")
@PreAuthorize("hasAnyRole('ADMIN','PERMISSION_ALL','PERMISSION_DELETE')")
public ResponseEntity delete(@PathVariable Long id){
List<Permission> permissions = permissionService.findByPid(id);
......
package me.zhengjie.modules.system.rest;
import cn.hutool.core.lang.Dict;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import me.zhengjie.aop.log.Log;
import me.zhengjie.modules.system.domain.Role;
import me.zhengjie.exception.BadRequestException;
......@@ -9,15 +11,12 @@ 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;
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;
......@@ -28,61 +27,62 @@ import java.util.stream.Collectors;
* @author Zheng Jie
* @date 2018-12-03
*/
@Api(tags = "系统:角色管理")
@RestController
@RequestMapping("api")
@RequestMapping("/api/roles")
public class RoleController {
@Autowired
private RoleService roleService;
private final RoleService roleService;
private static final String ENTITY_NAME = "role";
/**
* 获取单个role
* @param id
* @return
*/
@GetMapping(value = "/roles/{id}")
public RoleController(RoleService roleService) {
this.roleService = roleService;
}
@ApiOperation("获取单个role")
@GetMapping(value = "/{id}")
@PreAuthorize("hasAnyRole('ADMIN','ROLES_ALL','ROLES_SELECT')")
public ResponseEntity getRoles(@PathVariable Long id){
return new ResponseEntity(roleService.findById(id), HttpStatus.OK);
return new ResponseEntity<>(roleService.findById(id), HttpStatus.OK);
}
/**
* 返回全部的角色,新增用户时下拉选择
* @return
*/
@GetMapping(value = "/roles/all")
@ApiOperation("返回全部的角色")
@GetMapping(value = "/all")
@PreAuthorize("hasAnyRole('ADMIN','ROLES_ALL','USER_ALL','USER_CREATE','USER_EDIT')")
public ResponseEntity getAll(@PageableDefault(value = 2000, sort = {"level"}, direction = Sort.Direction.ASC) Pageable pageable){
return new ResponseEntity(roleService.queryAll(pageable),HttpStatus.OK);
return new ResponseEntity<>(roleService.queryAll(pageable),HttpStatus.OK);
}
@Log("查询角色")
@GetMapping(value = "/roles")
@ApiOperation("查询角色")
@GetMapping
@PreAuthorize("hasAnyRole('ADMIN','ROLES_ALL','ROLES_SELECT')")
public ResponseEntity getRoles(RoleQueryCriteria criteria, Pageable pageable){
return new ResponseEntity(roleService.queryAll(criteria,pageable),HttpStatus.OK);
return new ResponseEntity<>(roleService.queryAll(criteria,pageable),HttpStatus.OK);
}
@GetMapping(value = "/roles/level")
@ApiOperation("获取用户级别")
@GetMapping(value = "/level")
public ResponseEntity getLevel(){
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);
}
@Log("新增角色")
@PostMapping(value = "/roles")
@ApiOperation("新增角色")
@PostMapping
@PreAuthorize("hasAnyRole('ADMIN','ROLES_ALL','ROLES_CREATE')")
public ResponseEntity create(@Validated @RequestBody Role resources){
if (resources.getId() != null) {
throw new BadRequestException("A new "+ ENTITY_NAME +" cannot already have an ID");
}
return new ResponseEntity(roleService.create(resources),HttpStatus.CREATED);
return new ResponseEntity<>(roleService.create(resources),HttpStatus.CREATED);
}
@Log("修改角色")
@PutMapping(value = "/roles")
@ApiOperation("修改角色")
@PutMapping
@PreAuthorize("hasAnyRole('ADMIN','ROLES_ALL','ROLES_EDIT')")
public ResponseEntity update(@Validated(Role.Update.class) @RequestBody Role resources){
roleService.update(resources);
......@@ -90,7 +90,8 @@ public class RoleController {
}
@Log("修改角色权限")
@PutMapping(value = "/roles/permission")
@ApiOperation("修改角色权限")
@PutMapping(value = "/permission")
@PreAuthorize("hasAnyRole('ADMIN','ROLES_ALL','ROLES_EDIT')")
public ResponseEntity updatePermission(@RequestBody Role resources){
roleService.updatePermission(resources,roleService.findById(resources.getId()));
......@@ -98,7 +99,8 @@ public class RoleController {
}
@Log("修改角色菜单")
@PutMapping(value = "/roles/menu")
@ApiOperation("修改角色菜单")
@PutMapping(value = "/menu")
@PreAuthorize("hasAnyRole('ADMIN','ROLES_ALL','ROLES_EDIT')")
public ResponseEntity updateMenu(@RequestBody Role resources){
roleService.updateMenu(resources,roleService.findById(resources.getId()));
......@@ -106,7 +108,8 @@ public class RoleController {
}
@Log("删除角色")
@DeleteMapping(value = "/roles/{id}")
@ApiOperation("删除角色")
@DeleteMapping(value = "/{id}")
@PreAuthorize("hasAnyRole('ADMIN','ROLES_ALL','ROLES_DELETE')")
public ResponseEntity delete(@PathVariable Long id){
try {
......
package me.zhengjie.modules.system.rest;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
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;
......@@ -11,11 +12,9 @@ import me.zhengjie.modules.system.service.DeptService;
import me.zhengjie.modules.system.service.RoleService;
import me.zhengjie.modules.system.service.dto.RoleSmallDTO;
import me.zhengjie.modules.system.service.dto.UserQueryCriteria;
import me.zhengjie.service.PictureService;
import me.zhengjie.service.VerificationCodeService;
import me.zhengjie.utils.*;
import me.zhengjie.modules.system.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
......@@ -35,37 +34,40 @@ import java.util.stream.Collectors;
* @author Zheng Jie
* @date 2018-11-23
*/
@Api(tags = "系统:用户管理")
@RestController
@RequestMapping("api")
@RequestMapping("/api/users")
public class UserController {
@Autowired
private UserService userService;
private final UserService userService;
@Autowired
private PictureService pictureService;
private final DataScope dataScope;
@Autowired
private DataScope dataScope;
private final DeptService deptService;
@Autowired
private DeptService deptService;
private final RoleService roleService;
@Autowired
private RoleService roleService;
private final VerificationCodeService verificationCodeService;
@Autowired
private VerificationCodeService verificationCodeService;
public UserController(UserService userService, DataScope dataScope, DeptService deptService, RoleService roleService, VerificationCodeService verificationCodeService) {
this.userService = userService;
this.dataScope = dataScope;
this.deptService = deptService;
this.roleService = roleService;
this.verificationCodeService = verificationCodeService;
}
@Log("导出用户数据")
@GetMapping(value = "/users/download")
@ApiOperation("导出用户数据")
@GetMapping(value = "/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")
@ApiOperation("查询用户")
@GetMapping
@PreAuthorize("hasAnyRole('ADMIN','USER_ALL','USER_SELECT')")
public ResponseEntity getUsers(UserQueryCriteria criteria, Pageable pageable){
Set<Long> deptSet = new HashSet<>();
......@@ -89,27 +91,29 @@ public class UserController {
// 若无交集,则代表无数据权限
criteria.setDeptIds(result);
if(result.size() == 0){
return new ResponseEntity(PageUtil.toPage(null,0),HttpStatus.OK);
} else return new ResponseEntity(userService.queryAll(criteria,pageable),HttpStatus.OK);
return new ResponseEntity<>(PageUtil.toPage(null,0),HttpStatus.OK);
} else return new ResponseEntity<>(userService.queryAll(criteria,pageable),HttpStatus.OK);
// 否则取并集
} else {
result.addAll(deptSet);
result.addAll(deptIds);
criteria.setDeptIds(result);
return new ResponseEntity(userService.queryAll(criteria,pageable),HttpStatus.OK);
return new ResponseEntity<>(userService.queryAll(criteria,pageable),HttpStatus.OK);
}
}
@Log("新增用户")
@PostMapping(value = "/users")
@ApiOperation("新增用户")
@PostMapping
@PreAuthorize("hasAnyRole('ADMIN','USER_ALL','USER_CREATE')")
public ResponseEntity create(@Validated @RequestBody User resources){
checkLevel(resources);
return new ResponseEntity(userService.create(resources),HttpStatus.CREATED);
return new ResponseEntity<>(userService.create(resources),HttpStatus.CREATED);
}
@Log("修改用户")
@PutMapping(value = "/users")
@ApiOperation("修改用户")
@PutMapping
@PreAuthorize("hasAnyRole('ADMIN','USER_ALL','USER_EDIT')")
public ResponseEntity update(@Validated(User.Update.class) @RequestBody User resources){
checkLevel(resources);
......@@ -118,7 +122,8 @@ public class UserController {
}
@Log("删除用户")
@DeleteMapping(value = "/users/{id}")
@ApiOperation("删除用户")
@DeleteMapping(value = "/{id}")
@PreAuthorize("hasAnyRole('ADMIN','USER_ALL','USER_DELETE')")
public ResponseEntity delete(@PathVariable Long id){
Integer currentLevel = Collections.min(roleService.findByUsers_Id(SecurityUtils.getUserId()).stream().map(RoleSmallDTO::getLevel).collect(Collectors.toList()));
......@@ -131,12 +136,8 @@ public class UserController {
return new ResponseEntity(HttpStatus.OK);
}
/**
* 修改密码
* @param user
* @return
*/
@PostMapping(value = "/users/updatePass")
@ApiOperation("修改密码")
@PostMapping(value = "/updatePass")
public ResponseEntity updatePass(@RequestBody UserPassVo user){
UserDetails userDetails = SecurityUtils.getUserDetails();
if(!userDetails.getPassword().equals(EncryptUtils.encryptPassword(user.getOldPass()))){
......@@ -149,25 +150,16 @@ public class UserController {
return new ResponseEntity(HttpStatus.OK);
}
/**
* 修改头像
* @param file
* @return
*/
@PostMapping(value = "/users/updateAvatar")
@ApiOperation("修改头像")
@PostMapping(value = "/updateAvatar")
public ResponseEntity updateAvatar(@RequestParam MultipartFile file){
userService.updateAvatar(file);
return new ResponseEntity(HttpStatus.OK);
}
/**
* 修改邮箱
* @param user
* @param user
* @return
*/
@Log("修改邮箱")
@PostMapping(value = "/users/updateEmail/{code}")
@ApiOperation("修改邮箱")
@PostMapping(value = "/updateEmail/{code}")
public ResponseEntity updateEmail(@PathVariable String code,@RequestBody User user){
UserDetails userDetails = SecurityUtils.getUserDetails();
if(!userDetails.getPassword().equals(EncryptUtils.encryptPassword(user.getPassword()))){
......@@ -183,7 +175,7 @@ public class UserController {
/**
* 如果当前用户的角色级别低于创建用户的角色级别,则抛出权限不足的错误
* @param resources
* @param resources /
*/
private void checkLevel(User resources) {
Integer currentLevel = Collections.min(roleService.findByUsers_Id(SecurityUtils.getUserId()).stream().map(RoleSmallDTO::getLevel).collect(Collectors.toList()));
......
......@@ -3,10 +3,6 @@ package me.zhengjie.modules.system.service;
import me.zhengjie.modules.system.domain.Dept;
import me.zhengjie.modules.system.service.dto.DeptDTO;
import me.zhengjie.modules.system.service.dto.DeptQueryCriteria;
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;
......@@ -14,61 +10,20 @@ import java.util.Set;
* @author Zheng Jie
* @date 2019-03-25
*/
@CacheConfig(cacheNames = "dept")
public interface DeptService {
/**
* queryAll
* @param criteria
* @return
*/
@Cacheable
List<DeptDTO> queryAll(DeptQueryCriteria criteria);
/**
* 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
Object buildTree(List<DeptDTO> deptDTOS);
/**
* findByPid
* @param pid
* @return
*/
@Cacheable
List<Dept> findByPid(long pid);
Set<Dept> findByRoleIds(Long id);
......
......@@ -3,50 +3,22 @@ package me.zhengjie.modules.system.service;
import me.zhengjie.modules.system.domain.DictDetail;
import me.zhengjie.modules.system.service.dto.DictDetailDTO;
import me.zhengjie.modules.system.service.dto.DictDetailQueryCriteria;
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 java.util.Map;
/**
* @author Zheng 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);
@Cacheable
Map queryAll(DictDetailQueryCriteria criteria, Pageable pageable);
}
\ No newline at end of file
......@@ -3,54 +3,21 @@ package me.zhengjie.modules.system.service;
import me.zhengjie.modules.system.domain.Dict;
import me.zhengjie.modules.system.service.dto.DictDTO;
import me.zhengjie.modules.system.service.dto.DictQueryCriteria;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.data.domain.Pageable;
/**
* @author Zheng Jie
* @date 2019-04-10
*/
@CacheConfig(cacheNames = "dict")
public interface DictService {
/**
* 查询
* @param dict
* @param pageable
* @return
*/
@Cacheable
Object queryAll(DictQueryCriteria dict, Pageable pageable);
/**
* 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
......@@ -3,53 +3,21 @@ package me.zhengjie.modules.system.service;
import me.zhengjie.modules.system.domain.Job;
import me.zhengjie.modules.system.service.dto.JobDTO;
import me.zhengjie.modules.system.service.dto.JobQueryCriteria;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.data.domain.Pageable;
/**
* @author Zheng 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);
/**
* queryAll
* @param criteria
* @param pageable
* @return
*/
Object queryAll(JobQueryCriteria criteria, Pageable pageable);
}
\ No newline at end of file
......@@ -4,9 +4,6 @@ import me.zhengjie.modules.system.domain.Menu;
import me.zhengjie.modules.system.service.dto.MenuDTO;
import me.zhengjie.modules.system.service.dto.MenuQueryCriteria;
import me.zhengjie.modules.system.service.dto.RoleSmallDTO;
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.Map;
import java.util.Set;
......@@ -15,90 +12,29 @@ import java.util.Set;
* @author Zheng Jie
* @date 2018-12-17
*/
@CacheConfig(cacheNames = "menu")
public interface MenuService {
/**
* queryAll
* @param criteria
* @return
*/
@Cacheable
List<MenuDTO> queryAll(MenuQueryCriteria criteria);
/**
* get
* @param id
* @return
*/
@Cacheable(key = "#p0")
MenuDTO findById(long id);
/**
* create
* @param resources
* @return
*/
@CacheEvict(allEntries = true)
MenuDTO create(Menu resources);
/**
* update
* @param resources
*/
@CacheEvict(allEntries = true)
void update(Menu resources);
/**
* getDeleteMenus
* @param menuList
* @param menuSet
* @return
*/
Set<Menu> getDeleteMenus(List<Menu> menuList, Set<Menu> menuSet);
/**
* permission tree
* @return
*/
@Cacheable(key = "'tree'")
Object getMenuTree(List<Menu> menus);
/**
* findByPid
* @param pid
* @return
*/
@Cacheable(key = "'pid:'+#p0")
List<Menu> findByPid(long pid);
/**
* build Tree
* @param menuDTOS
* @return
*/
Map buildTree(List<MenuDTO> menuDTOS);
Map<String,Object> buildTree(List<MenuDTO> menuDTOS);
/**
* findByRoles
* @param roles
* @return
*/
List<MenuDTO> findByRoles(List<RoleSmallDTO> roles);
/**
* buildMenus
* @param byRoles
* @return
*/
Object buildMenus(List<MenuDTO> byRoles);
Menu findOne(Long id);
/**
* delete
* @param menuSet
*/
@CacheEvict(allEntries = true)
void delete(Set<Menu> menuSet);
}
......@@ -3,10 +3,6 @@ package me.zhengjie.modules.system.service;
import me.zhengjie.modules.system.domain.Permission;
import me.zhengjie.modules.system.service.dto.PermissionDTO;
import me.zhengjie.modules.system.service.dto.PermissionQueryCriteria;
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;
......@@ -14,68 +10,22 @@ import java.util.Set;
* @author Zheng Jie
* @date 2018-12-08
*/
@CacheConfig(cacheNames = "permission")
public interface PermissionService {
/**
* get
* @param id
* @return
*/
@Cacheable(key = "#p0")
PermissionDTO findById(long id);
/**
* create
* @param resources
* @return
*/
@CacheEvict(allEntries = true)
PermissionDTO create(Permission resources);
/**
* update
* @param resources
*/
@CacheEvict(allEntries = true)
void update(Permission resources);
/**
* delete
* @param permissions
*/
@CacheEvict(allEntries = true)
void delete(Set<Permission> permissions);
/**
* permission tree
* @return
*/
@Cacheable(key = "'tree'")
Object getPermissionTree(List<Permission> permissions);
/**
* findByPid
* @param pid
* @return
*/
@Cacheable(key = "'pid:'+#p0")
List<Permission> findByPid(long pid);
/**
* build Tree
* @param permissionDTOS
* @return
*/
@Cacheable
Object buildTree(List<PermissionDTO> permissionDTOS);
/**
* queryAll
* @param criteria
* @return
*/
@Cacheable
List<PermissionDTO> queryAll(PermissionQueryCriteria criteria);
Set<Permission> getDeletePermission(List<Permission> permissions, Set<Permission> permissionSet);
......
......@@ -4,11 +4,7 @@ import me.zhengjie.modules.system.domain.Role;
import me.zhengjie.modules.system.service.dto.RoleDTO;
import me.zhengjie.modules.system.service.dto.RoleQueryCriteria;
import me.zhengjie.modules.system.service.dto.RoleSmallDTO;
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 java.util.List;
import java.util.Set;
......@@ -16,95 +12,31 @@ import java.util.Set;
* @author Zheng Jie
* @date 2018-12-03
*/
@CacheConfig(cacheNames = "role")
public interface RoleService {
/**
* get
* @param id
* @return
*/
@Cacheable(key = "#p0")
RoleDTO findById(long id);
/**
* create
* @param resources
* @return
*/
@CacheEvict(allEntries = true)
RoleDTO create(Role resources);
/**
* update
* @param resources
*/
@CacheEvict(allEntries = true)
void update(Role resources);
/**
* delete
* @param id
*/
@CacheEvict(allEntries = true)
void delete(Long id);
/**
* key的名称如有修改,请同步修改 UserServiceImpl 中的 update 方法
* findByUsers_Id
* @param id
* @return
*/
@Cacheable(key = "'findByUsers_Id:' + #p0")
List<RoleSmallDTO> findByUsers_Id(Long id);
@Cacheable
Integer findByRoles(Set<Role> roles);
/**
* updatePermission
* @param resources
* @param roleDTO
*/
@CacheEvict(allEntries = true)
void updatePermission(Role resources, RoleDTO roleDTO);
/**
* updateMenu
* @param resources
* @param roleDTO
*/
@CacheEvict(allEntries = true)
void updateMenu(Role resources, RoleDTO roleDTO);
@CacheEvict(allEntries = true)
void untiedMenu(Long id);
/**
* queryAll
* @param pageable
* @return
*/
@Cacheable
Object queryAll(Pageable pageable);
/**
* queryAll
* @param pageable
* @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);
}
package me.zhengjie.modules.system.service;
import me.zhengjie.modules.system.domain.User;
import me.zhengjie.modules.security.security.JwtUser;
import me.zhengjie.modules.system.service.dto.UserDTO;
import me.zhengjie.modules.system.service.dto.UserQueryCriteria;
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;
......@@ -18,74 +13,26 @@ import java.util.List;
* @author Zheng Jie
* @date 2018-11-23
*/
@CacheConfig(cacheNames = "user")
public interface UserService {
/**
* get
* @param id
* @return
*/
@Cacheable(key = "#p0")
UserDTO findById(long id);
/**
* create
* @param resources
* @return
*/
@CacheEvict(allEntries = true)
UserDTO create(User resources);
/**
* update
* @param resources
*/
@CacheEvict(allEntries = true)
void update(User resources);
/**
* delete
* @param id
*/
@CacheEvict(allEntries = true)
void delete(Long id);
/**
* findByName
* @param userName
* @return
*/
@Cacheable(key = "'loadUserByUsername:'+#p0")
UserDTO findByName(String userName);
/**
* 修改密码
* @param username
* @param encryptPassword
*/
@CacheEvict(allEntries = true)
void updatePass(String username, String encryptPassword);
/**
* 修改头像
* @param file
*/
@CacheEvict(allEntries = true)
void updateAvatar(MultipartFile file);
/**
* 修改邮箱
* @param username
* @param email
*/
@CacheEvict(allEntries = true)
void updateEmail(String username, String email);
@Cacheable
Object queryAll(UserQueryCriteria criteria, Pageable pageable);
@Cacheable
List<UserDTO> queryAll(UserQueryCriteria criteria);
void download(List<UserDTO> queryAll, HttpServletResponse response) throws IOException;
......
......@@ -15,22 +15,16 @@ import java.util.List;
@Data
public class DeptDTO implements Serializable {
/**
* ID
*/
// ID
private Long id;
/**
* 名称
*/
// 名称
private String name;
@NotNull
private Boolean enabled;
/**
* 上级部门
*/
// 上级部门
private Long pid;
@JsonInclude(JsonInclude.Include.NON_EMPTY)
......
......@@ -10,13 +10,7 @@ import java.io.Serializable;
@Data
public class DeptSmallDTO implements Serializable {
/**
* ID
*/
private Long id;
/**
* 名称
*/
private String name;
}
\ No newline at end of file
......@@ -12,13 +12,7 @@ public class DictDTO implements Serializable {
private Long id;
/**
* 字典名称
*/
private String name;
/**
* 描述
*/
private String remark;
}
......@@ -12,18 +12,9 @@ public class DictDetailDTO implements Serializable {
private Long id;
/**
* 字典标签
*/
private String label;
/**
* 字典值
*/
private String value;
/**
* 排序
*/
private String sort;
}
\ No newline at end of file
......@@ -16,33 +16,18 @@ import java.io.Serializable;
@NoArgsConstructor
public class JobDTO implements Serializable {
/**
* ID
*/
private Long id;
private Long sort;
/**
* 名称
*/
private String name;
/**
* 状态
*/
private Boolean enabled;
private DeptDTO dept;
/**
* 如果分公司存在相同部门,则显示上级部门名称
*/
private String deptSuperiorName;
/**
* 创建日期
*/
private Timestamp createTime;
public JobDTO(String name, Boolean enabled) {
......
......@@ -12,13 +12,7 @@ import java.io.Serializable;
@NoArgsConstructor
public class JobSmallDTO implements Serializable {
/**
* ID
*/
private Long id;
/**
* 名称
*/
private String name;
}
\ 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