Commit bf7c1eeb authored by dqjdda's avatar dqjdda
Browse files

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

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