Commit 90a4a80a authored by ZhengJie's avatar ZhengJie
Browse files

[代码完善](v2.5): v2.5 beta 菜单部门优化,其他杂项优化

菜单和部门表加入 sub_count 字段,记录子节点数目,树形表格懒加载使用。
脚本同步更新

2.5 Beta 详情:https://www.ydyno.com/archives/1225.html
parent 48570fcb
......@@ -18,6 +18,7 @@ package me.zhengjie.modules.system.repository;
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.Modifying;
import org.springframework.data.jpa.repository.Query;
import java.util.List;
import java.util.Set;
......@@ -26,7 +27,6 @@ import java.util.Set;
* @author Zheng Jie
* @date 2019-03-25
*/
@SuppressWarnings("all")
public interface DeptRepository extends JpaRepository<Dept, Long>, JpaSpecificationExecutor<Dept> {
/**
......@@ -38,7 +38,7 @@ public interface DeptRepository extends JpaRepository<Dept, Long>, JpaSpecificat
/**
* 获取顶级部门
* @return
* @return /
*/
List<Dept> findByPidIsNull();
......@@ -60,7 +60,16 @@ public interface DeptRepository extends JpaRepository<Dept, Long>, JpaSpecificat
/**
* 判断是否存在子节点
* @param pid /
* @return
* @return /
*/
int countByPid(Long pid);
/**
* 根据ID更新sub_count
* @param count /
* @param id /
*/
@Modifying
@Query(value = " update sys_dept set sub_count = ?1 where dept_id = ?2 ",nativeQuery = true)
void updateSubCntById(Integer count, Long id);
}
\ No newline at end of file
......@@ -18,10 +18,17 @@ package me.zhengjie.modules.system.repository;
import me.zhengjie.modules.system.domain.Dict;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import java.util.Set;
/**
* @author Zheng Jie
* @date 2019-04-10
*/
public interface DictRepository extends JpaRepository<Dict, Long>, JpaSpecificationExecutor<Dict> {
/**
* 删除
* @param ids /
*/
void deleteByIdIn(Set<Long> ids);
}
\ No newline at end of file
......@@ -18,6 +18,8 @@ package me.zhengjie.modules.system.repository;
import me.zhengjie.modules.system.domain.Menu;
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.LinkedHashSet;
import java.util.List;
import java.util.Set;
......@@ -26,7 +28,6 @@ import java.util.Set;
* @author Zheng Jie
* @date 2018-12-17
*/
@SuppressWarnings("all")
public interface MenuRepository extends JpaRepository<Menu, Long>, JpaSpecificationExecutor<Menu> {
/**
......@@ -67,7 +68,16 @@ public interface MenuRepository extends JpaRepository<Menu, Long>, JpaSpecificat
/**
* 获取节点数量
* @param id /
* @return
* @return /
*/
int countByPid(Long id);
/**
* 更新节点数目
* @param count /
* @param menuId /
*/
@Modifying
@Query(value = " update sys_menu set sub_count = ?1 where menu_id = ?2 ",nativeQuery = true)
void updateSubCntById(int count, Long menuId);
}
......@@ -26,7 +26,6 @@ import java.util.Set;
* @author Zheng Jie
* @date 2018-12-03
*/
@SuppressWarnings("all")
public interface RoleRepository extends JpaRepository<Role, Long>, JpaSpecificationExecutor<Role> {
/**
......@@ -39,7 +38,7 @@ public interface RoleRepository extends JpaRepository<Role, Long>, JpaSpecificat
/**
* 根据用户ID查询
* @param id 用户ID
* @return
* @return /
*/
Set<Role> findByUsers_Id(Long id);
......
......@@ -87,7 +87,8 @@ public class DeptController {
if (resources.getId() != null) {
throw new BadRequestException("A new "+ ENTITY_NAME +" cannot already have an ID");
}
return new ResponseEntity<>(deptService.create(resources),HttpStatus.CREATED);
deptService.create(resources);
return new ResponseEntity<>(HttpStatus.CREATED);
}
@Log("修改部门")
......
......@@ -78,7 +78,8 @@ public class DictController {
if (resources.getId() != null) {
throw new BadRequestException("A new "+ ENTITY_NAME +" cannot already have an ID");
}
return new ResponseEntity<>(dictService.create(resources),HttpStatus.CREATED);
dictService.create(resources);
return new ResponseEntity<>(HttpStatus.CREATED);
}
@Log("修改字典")
......
......@@ -77,7 +77,8 @@ public class DictDetailController {
if (resources.getId() != null) {
throw new BadRequestException("A new "+ ENTITY_NAME +" cannot already have an ID");
}
return new ResponseEntity<>(dictDetailService.create(resources),HttpStatus.CREATED);
dictDetailService.create(resources);
return new ResponseEntity<>(HttpStatus.CREATED);
}
@Log("修改字典详情")
......
......@@ -71,7 +71,8 @@ public class JobController {
if (resources.getId() != null) {
throw new BadRequestException("A new "+ ENTITY_NAME +" cannot already have an ID");
}
return new ResponseEntity<>(jobService.create(resources),HttpStatus.CREATED);
jobService.create(resources);
return new ResponseEntity<>(HttpStatus.CREATED);
}
@Log("修改岗位")
......
......@@ -103,7 +103,8 @@ public class MenuController {
if (resources.getId() != null) {
throw new BadRequestException("A new "+ ENTITY_NAME +" cannot already have an ID");
}
return new ResponseEntity<>(menuService.create(resources),HttpStatus.CREATED);
menuService.create(resources);
return new ResponseEntity<>(HttpStatus.CREATED);
}
@Log("修改菜单")
......
......@@ -75,8 +75,8 @@ public class RoleController {
@ApiOperation("返回全部的角色")
@GetMapping(value = "/all")
@PreAuthorize("@el.check('roles:list','user:add','user:edit')")
public ResponseEntity<Object> query(@PageableDefault(value = 2000, sort = {"level"}, direction = Sort.Direction.ASC) Pageable pageable){
return new ResponseEntity<>(roleService.queryAll(pageable),HttpStatus.OK);
public ResponseEntity<Object> query(){
return new ResponseEntity<>(roleService.queryAll(),HttpStatus.OK);
}
@Log("查询角色")
......@@ -102,7 +102,8 @@ public class RoleController {
throw new BadRequestException("A new "+ ENTITY_NAME +" cannot already have an ID");
}
getLevels(resources.getLevel());
return new ResponseEntity<>(roleService.create(resources),HttpStatus.CREATED);
roleService.create(resources);
return new ResponseEntity<>(HttpStatus.CREATED);
}
@Log("修改角色")
......
......@@ -88,7 +88,7 @@ public class UserController {
criteria.getDeptIds().addAll(dataService.getDeptChildren(deptService.findByPid(criteria.getDeptId())));
}
// 数据权限
List<Long> dataScopes = dataService.getDeptIds(userService.findById(SecurityUtils.getCurrentUserId()));
List<Long> dataScopes = dataService.getDeptIds(userService.findByName(SecurityUtils.getCurrentUsername()));
// criteria.getDeptIds() 不为空并且数据权限不为空则取交集
if (!CollectionUtils.isEmpty(criteria.getDeptIds()) && !CollectionUtils.isEmpty(dataScopes)){
// 取交集
......@@ -112,7 +112,8 @@ public class UserController {
checkLevel(resources);
// 默认密码 123456
resources.setPassword(passwordEncoder.encode("123456"));
return new ResponseEntity<>(userService.create(resources),HttpStatus.CREATED);
userService.create(resources);
return new ResponseEntity<>(HttpStatus.CREATED);
}
@Log("修改用户")
......
......@@ -48,9 +48,8 @@ public interface DeptService {
/**
* 创建
* @param resources /
* @return /
*/
DeptDto create(Dept resources);
void create(Dept resources);
/**
* 编辑
......
......@@ -37,9 +37,8 @@ public interface DictDetailService {
/**
* 创建
* @param resources /
* @return /
*/
DictDetailDto create(DictDetail resources);
void create(DictDetail resources);
/**
* 编辑
......
......@@ -59,7 +59,7 @@ public interface DictService {
* @param resources /
* @return /
*/
DictDto create(Dict resources);
void create(Dict resources);
/**
* 编辑
......
......@@ -44,7 +44,7 @@ public interface JobService {
* @param resources /
* @return /
*/
JobDto create(Job resources);
void create(Job resources);
/**
* 编辑
......
......@@ -49,9 +49,8 @@ public interface MenuService {
/**
* 创建
* @param resources /
* @return /
*/
MenuDto create(Menu resources);
void create(Menu resources);
/**
* 编辑
......
......@@ -33,6 +33,12 @@ import java.util.Set;
*/
public interface RoleService {
/**
* 查询全部数据
* @return /
*/
List<RoleDto> queryAll();
/**
* 根据ID查询
* @param id /
......@@ -43,9 +49,8 @@ public interface RoleService {
/**
* 创建
* @param resources /
* @return /
*/
RoleDto create(Role resources);
void create(Role resources);
/**
* 编辑
......@@ -86,13 +91,6 @@ public interface RoleService {
*/
void untiedMenu(Long id);
/**
* 不带条件分页查询
* @param pageable 分页参数
* @return /
*/
Object queryAll(Pageable pageable);
/**
* 待条件分页查询
* @param criteria 条件
......
......@@ -41,9 +41,8 @@ public interface UserService {
/**
* 新增用户
* @param resources /
* @return /
*/
UserDto create(User resources);
void create(User resources);
/**
* 编辑用户
......
......@@ -44,9 +44,15 @@ public class DeptDto extends BaseDTO implements Serializable {
private Long pid;
private Boolean hasChildren = false;
private Integer subCount;
private Boolean leaf = true;
public Boolean getHasChildren() {
return subCount > 0;
}
public Boolean getLeaf() {
return subCount <= 0;
}
public String getLabel() {
return name;
......
......@@ -48,6 +48,8 @@ public class MenuDto extends BaseDTO implements Serializable {
private Long pid;
private Integer subCount;
private Boolean iFrame;
private Boolean cache;
......@@ -58,9 +60,13 @@ public class MenuDto extends BaseDTO implements Serializable {
private String icon;
private Boolean leaf = true;
public Boolean getHasChildren() {
return subCount > 0;
}
private Boolean hasChildren = false;
public Boolean getLeaf() {
return subCount <= 0;
}
public String getLabel() {
return title;
......
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