Commit 28ef1091 authored by ZhengJie's avatar ZhengJie
Browse files

[代码完善](v2.5): v2.5 beta 菜单管理、部门管理,列表和弹窗数据懒加载

1、菜单管理表格,弹窗数据懒加载
2、部门管理表格,弹窗数据懒加载
3、角色管理,菜单分配数据懒加载
4、用户管理,左侧部门数据懒加载
5、其他杂项优化,sql脚本更新

2.5 Beta 详情:https://www.ydyno.com/archives/1225.html
parent 5c4d0e46
......@@ -71,6 +71,8 @@ public @interface Query {
,BETWEEN
// 不为空
,NOT_NULL
// 为空
,IS_NULL
}
/**
......
......@@ -2,7 +2,10 @@ package me.zhengjie.base;
import lombok.Getter;
import lombok.Setter;
import org.apache.commons.lang3.builder.ToStringBuilder;
import java.io.Serializable;
import java.lang.reflect.Field;
import java.sql.Timestamp;
/**
......@@ -20,4 +23,19 @@ public class BaseDTO implements Serializable {
private Timestamp createTime;
private Timestamp updateTime;
@Override
public String toString() {
ToStringBuilder builder = new ToStringBuilder(this);
Field[] fields = this.getClass().getDeclaredFields();
try {
for (Field f : fields) {
f.setAccessible(true);
builder.append(f.getName(), f.get(this)).append("\n");
}
} catch (Exception e) {
builder.append("toString builder encounter an error");
}
return builder.toString();
}
}
......@@ -16,9 +16,13 @@
package me.zhengjie.config;
import lombok.Data;
import me.zhengjie.utils.ElAdminConstant;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;
/**
* @author Zheng Jie
*/
@Data
@Configuration
@ConfigurationProperties(prefix = "file")
......@@ -38,9 +42,9 @@ public class FileProperties {
public ElPath getPath(){
String os = System.getProperty("os.name");
if(os.toLowerCase().startsWith("win")) {
if(os.toLowerCase().startsWith(ElAdminConstant.WIN)) {
return windows;
} else if(os.toLowerCase().startsWith("mac")){
} else if(os.toLowerCase().startsWith(ElAdminConstant.MAC)){
return mac;
}
return linux;
......
......@@ -25,7 +25,17 @@ public class ElAdminConstant {
/**
* 用于IP定位转换
*/
static final String REGION = "内网IP|内网IP";
public static final String REGION = "内网IP|内网IP";
/**
* win 系统
*/
public static final String WIN = "win";
/**
* mac 系统
*/
public static final String MAC = "mac";
/**
* 常用接口
......
......@@ -27,13 +27,14 @@ import java.nio.charset.StandardCharsets;
* @author Zheng Jie
* @date 2018-11-23
*/
public class EncryptUtils {
private static final String strParam = "Passw0rd";
private static final String STR_PARAM = "Passw0rd";
private static Cipher cipher;
private static IvParameterSpec iv = new IvParameterSpec(strParam.getBytes(StandardCharsets.UTF_8));
private static final IvParameterSpec IV = new IvParameterSpec(STR_PARAM.getBytes(StandardCharsets.UTF_8));
private static DESKeySpec getDesKeySpec(String source) throws Exception {
if (source == null || source.length() == 0){
......@@ -51,7 +52,7 @@ public class EncryptUtils {
DESKeySpec desKeySpec = getDesKeySpec(source);
SecretKeyFactory keyFactory = SecretKeyFactory.getInstance("DES");
SecretKey secretKey = keyFactory.generateSecret(desKeySpec);
cipher.init(Cipher.ENCRYPT_MODE, secretKey, iv);
cipher.init(Cipher.ENCRYPT_MODE, secretKey, IV);
return byte2hex(
cipher.doFinal(source.getBytes(StandardCharsets.UTF_8))).toUpperCase();
}
......@@ -64,7 +65,7 @@ public class EncryptUtils {
DESKeySpec desKeySpec = getDesKeySpec(source);
SecretKeyFactory keyFactory = SecretKeyFactory.getInstance("DES");
SecretKey secretKey = keyFactory.generateSecret(desKeySpec);
cipher.init(Cipher.DECRYPT_MODE, secretKey, iv);
cipher.init(Cipher.DECRYPT_MODE, secretKey, IV);
byte[] retByte = cipher.doFinal(src);
return new String(retByte);
}
......
......@@ -56,6 +56,7 @@ public class QueryHelp {
List<Field> fields = getAllFields(query.getClass(), new ArrayList<>());
for (Field field : fields) {
boolean accessible = field.isAccessible();
// 设置对象的访问权限,保证对private的属性的访
field.setAccessible(true);
Query q = field.getAnnotation(Query.class);
if (q != null) {
......@@ -143,6 +144,9 @@ public class QueryHelp {
case NOT_NULL:
list.add(cb.isNotNull(getExpression(attributeName,join,root)));
break;
case IS_NULL:
list.add(cb.isNull(getExpression(attributeName,join,root)));
break;
case BETWEEN:
List<Object> between = new ArrayList<>((List<Object>)val);
list.add(cb.between(getExpression(attributeName, join, root).as((Class<? extends Comparable>) between.get(0).getClass()),
......@@ -182,7 +186,7 @@ public class QueryHelp {
return true;
}
private static List<Field> getAllFields(Class clazz, List<Field> fields) {
public static List<Field> getAllFields(Class clazz, List<Field> fields) {
if (clazz != null) {
fields.addAll(Arrays.asList(clazz.getDeclaredFields()));
getAllFields(clazz.getSuperclass(), fields);
......
......@@ -23,6 +23,7 @@ import lombok.Setter;
import me.zhengjie.base.BaseEntity;
import javax.persistence.*;
import java.io.Serializable;
import java.util.Objects;
/**
* @author zhanghouying
......@@ -58,4 +59,22 @@ public class ServerDeploy extends BaseEntity implements Serializable {
public void copy(ServerDeploy source){
BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(true));
}
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
ServerDeploy that = (ServerDeploy) o;
return Objects.equals(id, that.id) &&
Objects.equals(name, that.name);
}
@Override
public int hashCode() {
return Objects.hash(id, name);
}
}
......@@ -20,6 +20,7 @@ import lombok.Getter;
import lombok.Setter;
import me.zhengjie.base.BaseDTO;
import java.io.Serializable;
import java.util.Objects;
import java.util.Set;
import java.util.stream.Collectors;
......@@ -57,4 +58,21 @@ public class DeployDto extends BaseDTO implements Serializable {
}
return servers;
}
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
DeployDto deployDto = (DeployDto) o;
return Objects.equals(id, deployDto.id);
}
@Override
public int hashCode() {
return Objects.hash(id);
}
}
......@@ -19,6 +19,7 @@ import lombok.Getter;
import lombok.Setter;
import me.zhengjie.base.BaseDTO;
import java.io.Serializable;
import java.util.Objects;
/**
* @author zhanghouying
......@@ -39,4 +40,22 @@ public class ServerDeployDto extends BaseDTO implements Serializable {
private String account;
private String password;
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
ServerDeployDto that = (ServerDeployDto) o;
return Objects.equals(id, that.id) &&
Objects.equals(name, that.name);
}
@Override
public int hashCode() {
return Objects.hash(id, name);
}
}
......@@ -64,7 +64,9 @@ public class DeployServiceImpl implements DeployService {
private final DeployMapper deployMapper;
private final ServerDeployService serverDeployService;
private final DeployHistoryService deployHistoryService;
// 循环次数
/**
* 循环次数
*/
private final Integer count = 30;
......
......@@ -111,7 +111,7 @@ public class ExecutionJob extends QuartzJobBean {
private EmailVo taskAlarm(QuartzJob quartzJob, String msg) {
EmailVo emailVo = new EmailVo();
emailVo.setSubject("定时任务【"+ quartzJob.getJobName() +"】执行失败,请尽快处理!");
Map<String, Object> data = new HashMap<>();
Map<String, Object> data = new HashMap<>(16);
data.put("task", quartzJob);
data.put("msg", msg);
TemplateEngine engine = TemplateUtil.createEngine(new TemplateConfig("template", TemplateConfig.ResourceMode.CLASSPATH));
......
......@@ -99,7 +99,7 @@ public class TokenProvider implements InitializingBean {
long time = redisUtils.getExpire(properties.getOnlineKey() + token) * 1000;
Date expireDate = DateUtil.offset(new Date(), DateField.MILLISECOND, (int) time);
// 判断当前时间与过期时间的时间差
long differ = expireDate.getTime() - new Date().getTime();
long differ = expireDate.getTime() - System.currentTimeMillis();
// 如果在续期检查的范围内,则续期
if(differ <= properties.getDetect()){
long renew = time + properties.getRenew();
......
......@@ -49,6 +49,9 @@ public class Dept extends BaseEntity implements Serializable {
@ApiModelProperty(value = "角色")
private Set<Role> roles;
@ApiModelProperty(value = "排序")
private Integer deptSort;
@NotBlank
@ApiModelProperty(value = "部门名称")
private String name;
......@@ -57,7 +60,6 @@ public class Dept extends BaseEntity implements Serializable {
@ApiModelProperty(value = "是否启用")
private Boolean enabled;
@NotNull
@ApiModelProperty(value = "上级部门")
private Long pid;
......
......@@ -25,6 +25,7 @@ import javax.persistence.Table;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.io.Serializable;
import java.util.Objects;
/**
* @author Zheng Jie
......@@ -54,4 +55,21 @@ public class Job extends BaseEntity implements Serializable {
@NotNull
@ApiModelProperty(value = "是否启用")
private Boolean enabled;
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
Job job = (Job) o;
return Objects.equals(id, job.id);
}
@Override
public int hashCode() {
return Objects.hash(id);
}
}
\ No newline at end of file
......@@ -51,7 +51,6 @@ public class Menu extends BaseEntity implements Serializable {
@ApiModelProperty(value = "菜单角色")
private Set<Role> roles;
@NotBlank
@ApiModelProperty(value = "菜单标题")
private String title;
......
......@@ -36,6 +36,12 @@ public interface DeptRepository extends JpaRepository<Dept, Long>, JpaSpecificat
*/
List<Dept> findByPid(Long id);
/**
* 获取顶级部门
* @return
*/
List<Dept> findByPidIsNull();
/**
* 根据ID查询名称
* @param id ID
......@@ -50,4 +56,11 @@ public interface DeptRepository extends JpaRepository<Dept, Long>, JpaSpecificat
* @return /
*/
Set<Dept> findByRoles_Id(Long id);
/**
* 判断是否存在子节点
* @param pid /
* @return
*/
int countByPid(Long pid);
}
\ No newline at end of file
......@@ -50,6 +50,12 @@ public interface MenuRepository extends JpaRepository<Menu, Long>, JpaSpecificat
*/
List<Menu> findByPid(long pid);
/**
* 查询顶级菜单
* @return /
*/
List<Menu> findByPidIsNull();
/**
* 根据角色ID与菜单类型查询菜单
* @param roleIds roleIDs
......@@ -57,4 +63,11 @@ public interface MenuRepository extends JpaRepository<Menu, Long>, JpaSpecificat
* @return /
*/
LinkedHashSet<Menu> findByRoles_IdInAndTypeNotOrderByMenuSortAsc(Set<Long> roleIds, int type);
/**
* 获取节点数量
* @param id /
* @return
*/
int countByPid(Long id);
}
......@@ -25,6 +25,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.PageUtil;
import me.zhengjie.utils.ThrowableUtil;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
......@@ -32,10 +33,7 @@ import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.*;
/**
* @author Zheng Jie
......@@ -54,17 +52,31 @@ public class DeptController {
@ApiOperation("导出部门数据")
@GetMapping(value = "/download")
@PreAuthorize("@el.check('dept:list')")
public void download(HttpServletResponse response, DeptQueryCriteria criteria) throws IOException {
deptService.download(deptService.queryAll(criteria), response);
public void download(HttpServletResponse response, DeptQueryCriteria criteria) throws Exception {
deptService.download(deptService.queryAll(criteria, false), response);
}
@Log("查询部门")
@ApiOperation("查询部门")
@GetMapping
@PreAuthorize("@el.check('user:list','dept:list')")
public ResponseEntity<Object> getDepts(DeptQueryCriteria criteria){
List<DeptDto> deptDtos = deptService.queryAll(criteria);
return new ResponseEntity<>(deptService.buildTree(deptDtos),HttpStatus.OK);
public ResponseEntity<Object> getDepts(DeptQueryCriteria criteria) throws Exception {
List<DeptDto> deptDtos = deptService.queryAll(criteria, true);
return new ResponseEntity<>(PageUtil.toPage(deptDtos, deptDtos.size()),HttpStatus.OK);
}
@Log("查询部门")
@ApiOperation("查询部门:根据ID获取同级与上级数据")
@GetMapping("/superior")
@PreAuthorize("@el.check('user:list','dept:list')")
public ResponseEntity<Object> getSuperior(@RequestParam List<Long> ids) {
Set<DeptDto> deptDtos = new LinkedHashSet<>();
for (Long id : ids) {
DeptDto deptDto = deptService.findById(id);
List<DeptDto> depts = deptService.getSuperior(deptDto, new ArrayList<>());
deptDtos.addAll(depts);
}
return new ResponseEntity<>(deptService.buildTree(new ArrayList<>(deptDtos)),HttpStatus.OK);
}
@Log("新增部门")
......
......@@ -25,6 +25,7 @@ import me.zhengjie.modules.system.service.MenuService;
import me.zhengjie.modules.system.service.RoleService;
import me.zhengjie.modules.system.service.dto.MenuDto;
import me.zhengjie.modules.system.service.dto.MenuQueryCriteria;
import me.zhengjie.utils.PageUtil;
import me.zhengjie.utils.SecurityUtils;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
......@@ -33,6 +34,7 @@ import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
......@@ -57,8 +59,8 @@ public class MenuController {
@ApiOperation("导出菜单数据")
@GetMapping(value = "/download")
@PreAuthorize("@el.check('menu:list')")
public void download(HttpServletResponse response, MenuQueryCriteria criteria) throws IOException {
menuService.download(menuService.queryAll(criteria), response);
public void download(HttpServletResponse response, MenuQueryCriteria criteria) throws Exception {
menuService.download(menuService.queryAll(criteria, false), response);
}
@ApiOperation("获取前端所需菜单")
......@@ -70,19 +72,29 @@ public class MenuController {
}
@ApiOperation("返回全部的菜单")
@GetMapping(value = "/tree")
@GetMapping(value = "/lazy")
@PreAuthorize("@el.check('menu:list','roles:list')")
public ResponseEntity<Object> getMenuTree(){
return new ResponseEntity<>(menuService.getMenuTree(menuService.findByPid(0L)),HttpStatus.OK);
public ResponseEntity<Object> getMenus(@RequestParam Long pid){
return new ResponseEntity<>(menuService.getMenus(pid),HttpStatus.OK);
}
@Log("查询菜单")
@ApiOperation("查询菜单")
@GetMapping
@PreAuthorize("@el.check('menu:list')")
public ResponseEntity<Object> getMenus(MenuQueryCriteria criteria){
List<MenuDto> menuDtoList = menuService.queryAll(criteria);
return new ResponseEntity<>(menuService.buildTree(menuDtoList),HttpStatus.OK);
public ResponseEntity<Object> getMenus(MenuQueryCriteria criteria) throws Exception {
List<MenuDto> menuDtoList = menuService.queryAll(criteria, true);
return new ResponseEntity<>(PageUtil.toPage(menuDtoList, menuDtoList.size()),HttpStatus.OK);
}
@Log("查询菜单")
@ApiOperation("查询菜单:根据ID获取同级与上级数据")
@GetMapping("/superior")
@PreAuthorize("@el.check('menu:list')")
public ResponseEntity<Object> getSuperior(@RequestParam Long id) {
MenuDto menuDto = menuService.findById(id);
List<MenuDto> menuDtos = menuService.getSuperior(menuDto, new ArrayList<>());
return new ResponseEntity<>(menuService.buildTree(menuDtos),HttpStatus.OK);
}
@Log("新增菜单")
......
......@@ -68,6 +68,8 @@ public class VerifyController {
case TWO:
verificationCodeService.validated(CodeEnum.EMAIL_RESET_PWD_CODE.getKey() + email ,code);
break;
default:
break;
}
return new ResponseEntity<>(HttpStatus.OK);
}
......
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