Commit bf7c1eeb authored by dqjdda's avatar dqjdda
Browse files

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

parent e3c3ebb1
...@@ -4,7 +4,6 @@ import me.zhengjie.exception.BadRequestException; ...@@ -4,7 +4,6 @@ import me.zhengjie.exception.BadRequestException;
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.*; import me.zhengjie.modules.system.service.dto.*;
import org.springframework.beans.factory.annotation.Autowired;
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;
...@@ -20,11 +19,14 @@ import java.util.Optional; ...@@ -20,11 +19,14 @@ import java.util.Optional;
@Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class) @Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class)
public class JwtUserDetailsService implements UserDetailsService { public class JwtUserDetailsService implements UserDetailsService {
@Autowired private final UserService userService;
private UserService userService;
@Autowired private final JwtPermissionService permissionService;
private JwtPermissionService permissionService;
public JwtUserDetailsService(UserService userService, JwtPermissionService permissionService) {
this.userService = userService;
this.permissionService = permissionService;
}
@Override @Override
public UserDetails loadUserByUsername(String username){ public UserDetails loadUserByUsername(String username){
......
...@@ -31,15 +31,15 @@ public class JwtTokenUtil implements Serializable { ...@@ -31,15 +31,15 @@ public class JwtTokenUtil implements Serializable {
return getClaimFromToken(token, Claims::getSubject); return getClaimFromToken(token, Claims::getSubject);
} }
public Date getIssuedAtDateFromToken(String token) { private Date getIssuedAtDateFromToken(String token) {
return getClaimFromToken(token, Claims::getIssuedAt); return getClaimFromToken(token, Claims::getIssuedAt);
} }
public Date getExpirationDateFromToken(String token) { private Date getExpirationDateFromToken(String token) {
return getClaimFromToken(token, Claims::getExpiration); return getClaimFromToken(token, Claims::getExpiration);
} }
public <T> T getClaimFromToken(String token, Function<Claims, T> claimsResolver) { private <T> T getClaimFromToken(String token, Function<Claims, T> claimsResolver) {
final Claims claims = getAllClaimsFromToken(token); final Claims claims = getAllClaimsFromToken(token);
return claimsResolver.apply(claims); return claimsResolver.apply(claims);
} }
......
package me.zhengjie.modules.security.utils; package me.zhengjie.modules.security.utils;
import me.zhengjie.utils.StringUtils;
import java.awt.Color; import java.awt.Color;
import java.awt.Font; import java.awt.Font;
import java.awt.Graphics; import java.awt.Graphics;
...@@ -20,26 +22,27 @@ import javax.imageio.ImageIO; ...@@ -20,26 +22,27 @@ import javax.imageio.ImageIO;
public class VerifyCodeUtils{ public class VerifyCodeUtils{
//使用到Algerian字体,系统里没有的话需要安装字体,字体只显示大写,去掉了1,0,i,o几个容易混淆的字符 //使用到Algerian字体,系统里没有的话需要安装字体,字体只显示大写,去掉了1,0,i,o几个容易混淆的字符
public static final String VERIFY_CODES = "23456789ABCDEFGHJKLMNPQRSTUVWXYZ"; private static final String VERIFY_CODES = "23456789ABCDEFGHJKLMNPQRSTUVWXYZ";
private static Random random = new Random(); private static Random random = new Random();
/** /**
* 使用系统默认字符源生成验证码 * 使用系统默认字符源生成验证码
* @param verifySize 验证码长度 * @param verifySize 验证码长度
* @return * @return 验证码
*/ */
public static String generateVerifyCode(int verifySize){ public static String generateVerifyCode(int verifySize){
return generateVerifyCode(verifySize, VERIFY_CODES); return generateVerifyCode(verifySize, VERIFY_CODES);
} }
/** /**
* 使用指定源生成验证码 * 使用指定源生成验证码
* @param verifySize 验证码长度 * @param verifySize 验证码长度
* @param sources 验证码字符源 * @param sources 验证码字符源
* @return * @return 验证码
*/ */
public static String generateVerifyCode(int verifySize, String sources){ private static String generateVerifyCode(int verifySize, String sources){
if(sources == null || sources.length() == 0){ if(StringUtils.isBlank(sources)){
sources = VERIFY_CODES; sources = VERIFY_CODES;
} }
int codesLen = sources.length(); int codesLen = sources.length();
...@@ -53,11 +56,11 @@ public class VerifyCodeUtils{ ...@@ -53,11 +56,11 @@ public class VerifyCodeUtils{
/** /**
* 输出指定验证码图片流 * 输出指定验证码图片流
* @param w * @param w /
* @param h * @param h /
* @param os * @param os /
* @param code * @param code /
* @throws IOException * @throws IOException /
*/ */
public static void outputImage(int w, int h, OutputStream os, String code) throws IOException{ public static void outputImage(int w, int h, OutputStream os, String code) throws IOException{
int verifySize = code.length(); int verifySize = code.length();
...@@ -157,33 +160,24 @@ public class VerifyCodeUtils{ ...@@ -157,33 +160,24 @@ public class VerifyCodeUtils{
} }
private static void shearX(Graphics g, int w1, int h1, Color color) { private static void shearX(Graphics g, int w1, int h1, Color color) {
int period = random.nextInt(2); int period = random.nextInt(2);
boolean borderGap = true;
int frames = 1; int frames = 1;
int phase = random.nextInt(2); int phase = random.nextInt(2);
for (int i = 0; i < h1; i++) { for (int i = 0; i < h1; i++) {
double d = (double) (period >> 1) double d = (double) (period >> 1)
* Math.sin((double) i / (double) period * Math.sin((double) i / (double) period
+ (6.2831853071795862D * (double) phase) + (6.2831853071795862D * (double) phase)
/ (double) frames); / (double) frames);
g.copyArea(0, i, w1, 1, (int) d, 0); g.copyArea(0, i, w1, 1, (int) d, 0);
if (borderGap) {
g.setColor(color); g.setColor(color);
g.drawLine((int) d, i, 0, i); g.drawLine((int) d, i, 0, i);
g.drawLine((int) d + w1, i, w1, i); g.drawLine((int) d + w1, i, w1, i);
} }
}
} }
private static void shearY(Graphics g, int w1, int h1, Color color) { private static void shearY(Graphics g, int w1, int h1, Color color) {
int period = random.nextInt(40) + 10; // 50; int period = random.nextInt(40) + 10; // 50;
boolean borderGap = true;
int frames = 20; int frames = 20;
int phase = 7; int phase = 7;
for (int i = 0; i < w1; i++) { for (int i = 0; i < w1; i++) {
...@@ -192,11 +186,9 @@ public class VerifyCodeUtils{ ...@@ -192,11 +186,9 @@ public class VerifyCodeUtils{
+ (6.2831853071795862D * (double) phase) + (6.2831853071795862D * (double) phase)
/ (double) frames); / (double) frames);
g.copyArea(i, 0, 1, h1, 0, (int) d); g.copyArea(i, 0, 1, h1, 0, (int) d);
if (borderGap) {
g.setColor(color); g.setColor(color);
g.drawLine(i, (int) d, i, 0); g.drawLine(i, (int) d, i, 0);
g.drawLine(i, (int) d + h1, i, h1); g.drawLine(i, (int) d + h1, i, h1);
}
} }
} }
......
...@@ -19,18 +19,12 @@ import java.util.Set; ...@@ -19,18 +19,12 @@ import java.util.Set;
@Table(name="dept") @Table(name="dept")
public class Dept implements Serializable { public class Dept implements Serializable {
/**
* ID
*/
@Id @Id
@GeneratedValue(strategy = GenerationType.IDENTITY) @GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id") @Column(name = "id")
@NotNull(groups = Update.class) @NotNull(groups = Update.class)
private Long id; private Long id;
/**
* 名称
*/
@Column(name = "name",nullable = false) @Column(name = "name",nullable = false)
@NotBlank @NotBlank
private String name; private String name;
...@@ -38,9 +32,6 @@ public class Dept implements Serializable { ...@@ -38,9 +32,6 @@ public class Dept implements Serializable {
@NotNull @NotNull
private Boolean enabled; private Boolean enabled;
/**
* 上级部门
*/
@Column(name = "pid",nullable = false) @Column(name = "pid",nullable = false)
@NotNull @NotNull
private Long pid; private Long pid;
......
...@@ -22,16 +22,10 @@ public class Dict implements Serializable { ...@@ -22,16 +22,10 @@ public class Dict implements Serializable {
@NotNull(groups = Update.class) @NotNull(groups = Update.class)
private Long id; private Long id;
/**
* 字典名称
*/
@Column(name = "name",nullable = false,unique = true) @Column(name = "name",nullable = false,unique = true)
@NotBlank @NotBlank
private String name; private String name;
/**
* 描述
*/
@Column(name = "remark") @Column(name = "remark")
private String remark; private String remark;
......
...@@ -20,27 +20,19 @@ public class DictDetail implements Serializable { ...@@ -20,27 +20,19 @@ public class DictDetail implements Serializable {
@NotNull(groups = Update.class) @NotNull(groups = Update.class)
private Long id; private Long id;
/** // 字典标签
* 字典标签
*/
@Column(name = "label",nullable = false) @Column(name = "label",nullable = false)
private String label; private String label;
/** // 字典值
* 字典值
*/
@Column(name = "value",nullable = false) @Column(name = "value",nullable = false)
private String value; private String value;
/** // 排序
* 排序
*/
@Column(name = "sort") @Column(name = "sort")
private String sort = "999"; private String sort = "999";
/** // 字典id
* 字典id
*/
@ManyToOne(fetch=FetchType.LAZY) @ManyToOne(fetch=FetchType.LAZY)
@JoinColumn(name = "dict_id") @JoinColumn(name = "dict_id")
private Dict dict; private Dict dict;
......
...@@ -19,18 +19,12 @@ import java.io.Serializable; ...@@ -19,18 +19,12 @@ import java.io.Serializable;
@Table(name="job") @Table(name="job")
public class Job implements Serializable { public class Job implements Serializable {
/**
* ID
*/
@Id @Id
@GeneratedValue(strategy = GenerationType.IDENTITY) @GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id") @Column(name = "id")
@NotNull(groups = Update.class) @NotNull(groups = Update.class)
private Long id; private Long id;
/**
* 名称
*/
@Column(name = "name",nullable = false) @Column(name = "name",nullable = false)
@NotBlank @NotBlank
private String name; private String name;
...@@ -39,9 +33,6 @@ public class Job implements Serializable { ...@@ -39,9 +33,6 @@ public class Job implements Serializable {
@NotNull @NotNull
private Long sort; private Long sort;
/**
* 状态
*/
@Column(name = "enabled",nullable = false) @Column(name = "enabled",nullable = false)
@NotNull @NotNull
private Boolean enabled; private Boolean enabled;
...@@ -50,9 +41,6 @@ public class Job implements Serializable { ...@@ -50,9 +41,6 @@ public class Job implements Serializable {
@JoinColumn(name = "dept_id") @JoinColumn(name = "dept_id")
private Dept dept; private Dept dept;
/**
* 创建日期
*/
@Column(name = "create_time") @Column(name = "create_time")
@CreationTimestamp @CreationTimestamp
private Timestamp createTime; private Timestamp createTime;
......
...@@ -51,15 +51,11 @@ public class Menu implements Serializable { ...@@ -51,15 +51,11 @@ public class Menu implements Serializable {
@Column(columnDefinition = "bit(1) default 0") @Column(columnDefinition = "bit(1) default 0")
private Boolean hidden; private Boolean hidden;
/** // 上级菜单ID
* 上级菜单ID
*/
@Column(name = "pid",nullable = false) @Column(name = "pid",nullable = false)
private Long pid; private Long pid;
/** // 是否为外链 true/false
* 是否为外链 true/false
*/
@Column(name = "i_frame") @Column(name = "i_frame")
private Boolean iFrame; private Boolean iFrame;
......
...@@ -29,9 +29,7 @@ public class Permission implements Serializable{ ...@@ -29,9 +29,7 @@ public class Permission implements Serializable{
@NotBlank @NotBlank
private String name; private String name;
/** // 上级类目
* 上级类目
*/
@NotNull @NotNull
@Column(name = "pid",nullable = false) @Column(name = "pid",nullable = false)
private Long pid; private Long pid;
......
...@@ -4,7 +4,6 @@ import me.zhengjie.modules.system.domain.Dept; ...@@ -4,7 +4,6 @@ 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 org.springframework.data.jpa.repository.Query;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
...@@ -12,13 +11,8 @@ import java.util.Set; ...@@ -12,13 +11,8 @@ import java.util.Set;
* @author Zheng Jie * @author Zheng Jie
* @date 2019-03-25 * @date 2019-03-25
*/ */
public interface DeptRepository extends JpaRepository<Dept, Long>, JpaSpecificationExecutor { public interface DeptRepository extends JpaRepository<Dept, Long>, JpaSpecificationExecutor<Dept> {
/**
* findByPid
* @param id
* @return
*/
List<Dept> findByPid(Long id); List<Dept> findByPid(Long id);
@Query(value = "select name from dept where id = ?1",nativeQuery = true) @Query(value = "select name from dept where id = ?1",nativeQuery = true)
......
...@@ -8,5 +8,5 @@ import org.springframework.data.jpa.repository.JpaSpecificationExecutor; ...@@ -8,5 +8,5 @@ import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
* @author Zheng Jie * @author Zheng Jie
* @date 2019-04-10 * @date 2019-04-10
*/ */
public interface DictDetailRepository extends JpaRepository<DictDetail, Long>, JpaSpecificationExecutor { public interface DictDetailRepository extends JpaRepository<DictDetail, Long>, JpaSpecificationExecutor<DictDetail> {
} }
\ No newline at end of file
...@@ -8,5 +8,5 @@ import org.springframework.data.jpa.repository.JpaSpecificationExecutor; ...@@ -8,5 +8,5 @@ import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
* @author Zheng Jie * @author Zheng Jie
* @date 2019-04-10 * @date 2019-04-10
*/ */
public interface DictRepository extends JpaRepository<Dict, Long>, JpaSpecificationExecutor { public interface DictRepository extends JpaRepository<Dict, Long>, JpaSpecificationExecutor<Dict> {
} }
\ No newline at end of file
...@@ -8,5 +8,5 @@ import org.springframework.data.jpa.repository.JpaSpecificationExecutor; ...@@ -8,5 +8,5 @@ import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
* @author Zheng Jie * @author Zheng Jie
* @date 2019-03-29 * @date 2019-03-29
*/ */
public interface JobRepository extends JpaRepository<Job, Long>, JpaSpecificationExecutor { public interface JobRepository extends JpaRepository<Job, Long>, JpaSpecificationExecutor<Job> {
} }
\ No newline at end of file
package me.zhengjie.modules.system.repository; package me.zhengjie.modules.system.repository;
import me.zhengjie.modules.system.domain.Menu; import me.zhengjie.modules.system.domain.Menu;
import me.zhengjie.modules.system.domain.Role;
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 java.util.Arrays;
import java.util.LinkedHashSet; import java.util.LinkedHashSet;
import java.util.List; import java.util.List;
import java.util.Set;
/** /**
* @author Zheng Jie * @author Zheng Jie
* @date 2018-12-17 * @date 2018-12-17
*/ */
public interface MenuRepository extends JpaRepository<Menu, Long>, JpaSpecificationExecutor { public interface MenuRepository extends JpaRepository<Menu, Long>, JpaSpecificationExecutor<Menu> {
/**
* findByName
* @param name
* @return
*/
Menu findByName(String name); Menu findByName(String name);
/**
* findByName
* @param name
* @return
*/
Menu findByComponentName(String name); Menu findByComponentName(String name);
/**
* findByPid
* @param pid
* @return
*/
List<Menu> findByPid(long pid); List<Menu> findByPid(long pid);
LinkedHashSet<Menu> findByRoles_IdOrderBySortAsc(Long id); LinkedHashSet<Menu> findByRoles_IdOrderBySortAsc(Long id);
......
...@@ -9,19 +9,9 @@ import java.util.List; ...@@ -9,19 +9,9 @@ import java.util.List;
* @author Zheng Jie * @author Zheng Jie
* @date 2018-12-03 * @date 2018-12-03
*/ */
public interface PermissionRepository extends JpaRepository<Permission, Long>, JpaSpecificationExecutor { public interface PermissionRepository extends JpaRepository<Permission, Long>, JpaSpecificationExecutor<Permission> {
/**
* findByName
* @param name
* @return
*/
Permission findByName(String name); Permission findByName(String name);
/**
* findByPid
* @param pid
* @return
*/
List<Permission> findByPid(long pid); List<Permission> findByPid(long pid);
} }
...@@ -5,20 +5,14 @@ import org.springframework.data.jpa.repository.JpaRepository; ...@@ -5,20 +5,14 @@ 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.Modifying; import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query; import org.springframework.data.jpa.repository.Query;
import java.util.Set; import java.util.Set;
/** /**
* @author Zheng Jie * @author Zheng Jie
* @date 2018-12-03 * @date 2018-12-03
*/ */
public interface RoleRepository extends JpaRepository<Role, Long>, JpaSpecificationExecutor { public interface RoleRepository extends JpaRepository<Role, Long>, JpaSpecificationExecutor<Role> {
/**
* findByName
* @param name
* @return
*/
Role findByName(String name); Role findByName(String name);
Set<Role> findByUsers_Id(Long id); Set<Role> findByUsers_Id(Long id);
......
...@@ -4,12 +4,10 @@ import me.zhengjie.modules.system.domain.UserAvatar; ...@@ -4,12 +4,10 @@ import me.zhengjie.modules.system.domain.UserAvatar;
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 java.util.Date;
/** /**
* @author Zheng Jie * @author Zheng Jie
* @date 2018-11-22 * @date 2018-11-22
*/ */
public interface UserAvatarRepository extends JpaRepository<UserAvatar, Long>, JpaSpecificationExecutor { public interface UserAvatarRepository extends JpaRepository<UserAvatar, Long>, JpaSpecificationExecutor<UserAvatar> {
} }
package me.zhengjie.modules.system.repository; package me.zhengjie.modules.system.repository;
import me.zhengjie.modules.system.domain.User; import me.zhengjie.modules.system.domain.User;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.domain.Specification;
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.Modifying; import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query; import org.springframework.data.jpa.repository.Query;
import java.util.Date; import java.util.Date;
import java.util.List;
/** /**
* @author Zheng Jie * @author Zheng Jie
* @date 2018-11-22 * @date 2018-11-22
*/ */
public interface UserRepository extends JpaRepository<User, Long>, JpaSpecificationExecutor { public interface UserRepository extends JpaRepository<User, Long>, JpaSpecificationExecutor<User> {
/**
* findByUsername
* @param username
* @return
*/
User findByUsername(String username); User findByUsername(String username);
/**
* findByEmail
* @param email
* @return
*/
User findByEmail(String email); User findByEmail(String email);
/**
* 修改密码
* @param username
* @param pass
*/
@Modifying @Modifying
@Query(value = "update user set password = ?2 , last_password_reset_time = ?3 where username = ?1",nativeQuery = true) @Query(value = "update user set password = ?2 , last_password_reset_time = ?3 where username = ?1",nativeQuery = true)
void updatePass(String username, String pass, Date lastPasswordResetTime); void updatePass(String username, String pass, Date lastPasswordResetTime);
/**
* 修改头像
* @param username
* @param url
*/
@Modifying
@Query(value = "update user set avatar = ?2 where username = ?1",nativeQuery = true)
void updateAvatar(String username, String url);
/**
* 修改邮箱
* @param username
* @param email
*/
@Modifying @Modifying
@Query(value = "update user set email = ?2 where username = ?1",nativeQuery = true) @Query(value = "update user set email = ?2 where username = ?1",nativeQuery = true)
void updateEmail(String username, String email); void updateEmail(String username, String email);
......
package me.zhengjie.modules.system.rest; 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.aop.log.Log;
import me.zhengjie.config.DataScope; import me.zhengjie.config.DataScope;
import me.zhengjie.exception.BadRequestException; import me.zhengjie.exception.BadRequestException;
...@@ -8,7 +10,6 @@ import me.zhengjie.modules.system.service.DeptService; ...@@ -8,7 +10,6 @@ import me.zhengjie.modules.system.service.DeptService;
import me.zhengjie.modules.system.service.dto.DeptDTO; import me.zhengjie.modules.system.service.dto.DeptDTO;
import me.zhengjie.modules.system.service.dto.DeptQueryCriteria; import me.zhengjie.modules.system.service.dto.DeptQueryCriteria;
import me.zhengjie.utils.ThrowableUtil; import me.zhengjie.utils.ThrowableUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.security.access.prepost.PreAuthorize;
...@@ -21,39 +22,46 @@ import java.util.List; ...@@ -21,39 +22,46 @@ import java.util.List;
* @date 2019-03-25 * @date 2019-03-25
*/ */
@RestController @RestController
@RequestMapping("api") @Api(tags = "系统:部门管理")
@RequestMapping("/api/dept")
public class DeptController { public class DeptController {
@Autowired private final DeptService deptService;
private DeptService deptService;
@Autowired private final DataScope dataScope;
private DataScope dataScope;
private static final String ENTITY_NAME = "dept"; private static final String ENTITY_NAME = "dept";
public DeptController(DeptService deptService, DataScope dataScope) {
this.deptService = deptService;
this.dataScope = dataScope;
}
@Log("查询部门") @Log("查询部门")
@GetMapping(value = "/dept") @ApiOperation("查询部门")
@GetMapping
@PreAuthorize("hasAnyRole('ADMIN','USER_ALL','USER_SELECT','DEPT_ALL','DEPT_SELECT')") @PreAuthorize("hasAnyRole('ADMIN','USER_ALL','USER_SELECT','DEPT_ALL','DEPT_SELECT')")
public ResponseEntity getDepts(DeptQueryCriteria criteria){ public ResponseEntity getDepts(DeptQueryCriteria criteria){
// 数据权限 // 数据权限
criteria.setIds(dataScope.getDeptIds()); criteria.setIds(dataScope.getDeptIds());
List<DeptDTO> deptDTOS = deptService.queryAll(criteria); List<DeptDTO> deptDTOS = deptService.queryAll(criteria);
return new ResponseEntity(deptService.buildTree(deptDTOS),HttpStatus.OK); return new ResponseEntity<>(deptService.buildTree(deptDTOS),HttpStatus.OK);
} }
@Log("新增部门") @Log("新增部门")
@PostMapping(value = "/dept") @ApiOperation("新增部门")
@PostMapping
@PreAuthorize("hasAnyRole('ADMIN','DEPT_ALL','DEPT_CREATE')") @PreAuthorize("hasAnyRole('ADMIN','DEPT_ALL','DEPT_CREATE')")
public ResponseEntity create(@Validated @RequestBody Dept resources){ public ResponseEntity create(@Validated @RequestBody Dept resources){
if (resources.getId() != null) { if (resources.getId() != null) {
throw new BadRequestException("A new "+ ENTITY_NAME +" cannot already have an ID"); throw new BadRequestException("A new "+ ENTITY_NAME +" cannot already have an ID");
} }
return new ResponseEntity(deptService.create(resources),HttpStatus.CREATED); return new ResponseEntity<>(deptService.create(resources),HttpStatus.CREATED);
} }
@Log("修改部门") @Log("修改部门")
@PutMapping(value = "/dept") @ApiOperation("修改部门")
@PutMapping
@PreAuthorize("hasAnyRole('ADMIN','DEPT_ALL','DEPT_EDIT')") @PreAuthorize("hasAnyRole('ADMIN','DEPT_ALL','DEPT_EDIT')")
public ResponseEntity update(@Validated(Dept.Update.class) @RequestBody Dept resources){ public ResponseEntity update(@Validated(Dept.Update.class) @RequestBody Dept resources){
deptService.update(resources); deptService.update(resources);
...@@ -61,7 +69,8 @@ public class DeptController { ...@@ -61,7 +69,8 @@ public class DeptController {
} }
@Log("删除部门") @Log("删除部门")
@DeleteMapping(value = "/dept/{id}") @ApiOperation("删除部门")
@DeleteMapping(value = "/{id}")
@PreAuthorize("hasAnyRole('ADMIN','DEPT_ALL','DEPT_DELETE')") @PreAuthorize("hasAnyRole('ADMIN','DEPT_ALL','DEPT_DELETE')")
public ResponseEntity delete(@PathVariable Long id){ public ResponseEntity delete(@PathVariable Long id){
try { try {
......
package me.zhengjie.modules.system.rest; 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.aop.log.Log;
import me.zhengjie.exception.BadRequestException; import me.zhengjie.exception.BadRequestException;
import me.zhengjie.modules.system.domain.Dict; import me.zhengjie.modules.system.domain.Dict;
...@@ -17,34 +19,41 @@ import org.springframework.web.bind.annotation.*; ...@@ -17,34 +19,41 @@ import org.springframework.web.bind.annotation.*;
* @author Zheng Jie * @author Zheng Jie
* @date 2019-04-10 * @date 2019-04-10
*/ */
@Api(tags = "系统:字典管理")
@RestController @RestController
@RequestMapping("api") @RequestMapping("/api/dict")
public class DictController { public class DictController {
@Autowired private final DictService dictService;
private DictService dictService;
private static final String ENTITY_NAME = "dict"; private static final String ENTITY_NAME = "dict";
public DictController(DictService dictService) {
this.dictService = dictService;
}
@Log("查询字典") @Log("查询字典")
@GetMapping(value = "/dict") @ApiOperation("查询字典")
@GetMapping
@PreAuthorize("hasAnyRole('ADMIN','DICT_ALL','DICT_SELECT')") @PreAuthorize("hasAnyRole('ADMIN','DICT_ALL','DICT_SELECT')")
public ResponseEntity getDicts(DictQueryCriteria resources, Pageable pageable){ public ResponseEntity getDicts(DictQueryCriteria resources, Pageable pageable){
return new ResponseEntity(dictService.queryAll(resources,pageable),HttpStatus.OK); return new ResponseEntity<>(dictService.queryAll(resources,pageable),HttpStatus.OK);
} }
@Log("新增字典") @Log("新增字典")
@PostMapping(value = "/dict") @ApiOperation("新增字典")
@PostMapping
@PreAuthorize("hasAnyRole('ADMIN','DICT_ALL','DICT_CREATE')") @PreAuthorize("hasAnyRole('ADMIN','DICT_ALL','DICT_CREATE')")
public ResponseEntity create(@Validated @RequestBody Dict resources){ public ResponseEntity create(@Validated @RequestBody Dict resources){
if (resources.getId() != null) { if (resources.getId() != null) {
throw new BadRequestException("A new "+ ENTITY_NAME +" cannot already have an ID"); throw new BadRequestException("A new "+ ENTITY_NAME +" cannot already have an ID");
} }
return new ResponseEntity(dictService.create(resources),HttpStatus.CREATED); return new ResponseEntity<>(dictService.create(resources),HttpStatus.CREATED);
} }
@Log("修改字典") @Log("修改字典")
@PutMapping(value = "/dict") @ApiOperation("修改字典")
@PutMapping
@PreAuthorize("hasAnyRole('ADMIN','DICT_ALL','DICT_EDIT')") @PreAuthorize("hasAnyRole('ADMIN','DICT_ALL','DICT_EDIT')")
public ResponseEntity update(@Validated(Dict.Update.class) @RequestBody Dict resources){ public ResponseEntity update(@Validated(Dict.Update.class) @RequestBody Dict resources){
dictService.update(resources); dictService.update(resources);
...@@ -52,7 +61,8 @@ public class DictController { ...@@ -52,7 +61,8 @@ public class DictController {
} }
@Log("删除字典") @Log("删除字典")
@DeleteMapping(value = "/dict/{id}") @ApiOperation("删除字典")
@DeleteMapping(value = "/{id}")
@PreAuthorize("hasAnyRole('ADMIN','DICT_ALL','DICT_DELETE')") @PreAuthorize("hasAnyRole('ADMIN','DICT_ALL','DICT_DELETE')")
public ResponseEntity delete(@PathVariable Long id){ public ResponseEntity delete(@PathVariable Long id){
dictService.delete(id); dictService.delete(id);
......
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