fix(菜单模块): 处理合并代码的报错
This commit is contained in:
parent
1eb01519ad
commit
5e508a5db2
6
pom.xml
6
pom.xml
@ -131,12 +131,6 @@
|
||||
<artifactId>commons-codec</artifactId>
|
||||
<version>1.17.1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>fastjson</artifactId>
|
||||
<version>2.0.21</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.apache.tika</groupId>
|
||||
<artifactId>tika-core</artifactId>
|
||||
|
@ -39,31 +39,31 @@ public class FirstTimeInitializer implements CommandLineRunner {
|
||||
|
||||
@Override
|
||||
public void run(String... args) {
|
||||
if (authorityService.count() == 0L) {
|
||||
Authority userPerm = new Authority(null, "用户模块", "用户管理", "SYSTEM:USER", true, null);
|
||||
Authority rolePerm = new Authority(null, "角色模块", "角色管理", "SYSTEM:ROLE", true, null);
|
||||
Authority deptPerm = new Authority(null, "部门模块", "部门管理", "SYSTEM:DEPT", true, null);
|
||||
Authority AuthorityPerm = new Authority(null, "权限模块", "权限管理", "SYSTEM:AUTHORITY", true, null);
|
||||
authorityService.saveBatch(List.of(userPerm, rolePerm, deptPerm, AuthorityPerm));
|
||||
List<Authority> authorities = new ArrayList<>();
|
||||
authorities.add(new Authority(userPerm.getId(), "用户管理", "用户列表", "SYSTEM:USER:QUERY", true, null));
|
||||
authorities.add(new Authority(userPerm.getId(), "用户管理", "用户新增", "SYSTEM:USER:CREATE",true, null));
|
||||
authorities.add(new Authority(userPerm.getId(), "用户管理", "用户修改", "SYSTEM:USER:UPDATE",true, null));
|
||||
authorities.add(new Authority(userPerm.getId(), "用户管理", "用户删除", "SYSTEM:USER:DELETE",true, null));
|
||||
authorities.add(new Authority(rolePerm.getId(), "角色管理", "角色列表", "SYSTEM:ROLE:QUERY", true, null));
|
||||
authorities.add(new Authority(rolePerm.getId(), "角色管理", "角色新增", "SYSTEM:ROLE:CREATE",true, null));
|
||||
authorities.add(new Authority(rolePerm.getId(), "角色管理", "角色修改", "SYSTEM:ROLE:UPDATE",true, null));
|
||||
authorities.add(new Authority(rolePerm.getId(), "角色管理", "角色删除", "SYSTEM:ROLE:DELETE",true, null));
|
||||
authorities.add(new Authority(deptPerm.getId(), "部门管理", "部门列表", "SYSTEM:DEPT:QUERY", true, null));
|
||||
authorities.add(new Authority(deptPerm.getId(), "部门管理", "部门新增", "SYSTEM:DEPT:CREATE",true, null));
|
||||
authorities.add(new Authority(deptPerm.getId(), "部门管理", "部门修改", "SYSTEM:DEPT:UPDATE",true, null));
|
||||
authorities.add(new Authority(deptPerm.getId(), "部门管理", "部门删除", "SYSTEM:DEPT:DELETE",true, null));
|
||||
authorities.add(new Authority(AuthorityPerm.getId(), "权限管理", "权限列表", "SYSTEM:AUTHORITY:QUERY", true, null));
|
||||
authorities.add(new Authority(AuthorityPerm.getId(), "权限管理", "权限新增", "SYSTEM:AUTHORITY:CREATE",true, null));
|
||||
authorities.add(new Authority(AuthorityPerm.getId(), "权限管理", "权限修改", "SYSTEM:AUTHORITY:UPDATE",true, null));
|
||||
authorities.add(new Authority(AuthorityPerm.getId(), "权限管理", "权限删除", "SYSTEM:AUTHORITY:DELETE",true, null));
|
||||
authorityService.saveBatch(authorities);
|
||||
}
|
||||
// if (authorityService.count() == 0L) {
|
||||
// Authority userPerm = new Authority(null, "用户模块", "用户管理", "SYSTEM:USER", true, null);
|
||||
// Authority rolePerm = new Authority(null, "角色模块", "角色管理", "SYSTEM:ROLE", true, null);
|
||||
// Authority deptPerm = new Authority(null, "部门模块", "部门管理", "SYSTEM:DEPT", true, null);
|
||||
// Authority AuthorityPerm = new Authority(null, "权限模块", "权限管理", "SYSTEM:AUTHORITY", true, null);
|
||||
// authorityService.saveBatch(List.of(userPerm, rolePerm, deptPerm, AuthorityPerm));
|
||||
// List<Authority> authorities = new ArrayList<>();
|
||||
// authorities.add(new Authority(userPerm.getId(), "用户管理", "用户列表", "SYSTEM:USER:QUERY", true, null));
|
||||
// authorities.add(new Authority(userPerm.getId(), "用户管理", "用户新增", "SYSTEM:USER:CREATE",true, null));
|
||||
// authorities.add(new Authority(userPerm.getId(), "用户管理", "用户修改", "SYSTEM:USER:UPDATE",true, null));
|
||||
// authorities.add(new Authority(userPerm.getId(), "用户管理", "用户删除", "SYSTEM:USER:DELETE",true, null));
|
||||
// authorities.add(new Authority(rolePerm.getId(), "角色管理", "角色列表", "SYSTEM:ROLE:QUERY", true, null));
|
||||
// authorities.add(new Authority(rolePerm.getId(), "角色管理", "角色新增", "SYSTEM:ROLE:CREATE",true, null));
|
||||
// authorities.add(new Authority(rolePerm.getId(), "角色管理", "角色修改", "SYSTEM:ROLE:UPDATE",true, null));
|
||||
// authorities.add(new Authority(rolePerm.getId(), "角色管理", "角色删除", "SYSTEM:ROLE:DELETE",true, null));
|
||||
// authorities.add(new Authority(deptPerm.getId(), "部门管理", "部门列表", "SYSTEM:DEPT:QUERY", true, null));
|
||||
// authorities.add(new Authority(deptPerm.getId(), "部门管理", "部门新增", "SYSTEM:DEPT:CREATE",true, null));
|
||||
// authorities.add(new Authority(deptPerm.getId(), "部门管理", "部门修改", "SYSTEM:DEPT:UPDATE",true, null));
|
||||
// authorities.add(new Authority(deptPerm.getId(), "部门管理", "部门删除", "SYSTEM:DEPT:DELETE",true, null));
|
||||
// authorities.add(new Authority(AuthorityPerm.getId(), "权限管理", "权限列表", "SYSTEM:AUTHORITY:QUERY", true, null));
|
||||
// authorities.add(new Authority(AuthorityPerm.getId(), "权限管理", "权限新增", "SYSTEM:AUTHORITY:CREATE",true, null));
|
||||
// authorities.add(new Authority(AuthorityPerm.getId(), "权限管理", "权限修改", "SYSTEM:AUTHORITY:UPDATE",true, null));
|
||||
// authorities.add(new Authority(AuthorityPerm.getId(), "权限管理", "权限删除", "SYSTEM:AUTHORITY:DELETE",true, null));
|
||||
// authorityService.saveBatch(authorities);
|
||||
// }
|
||||
if (roleService.count() == 0L) {
|
||||
Role admin = new Role();
|
||||
admin.setName("管理员");
|
||||
|
@ -1,7 +1,5 @@
|
||||
package com.zsc.edu.gateway.modules.iot.device.service.impl;
|
||||
|
||||
import com.alibaba.fastjson2.JSON;
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
@ -104,10 +102,6 @@ public class DeviceServiceImpl extends ServiceImpl<DeviceRepository, Device> imp
|
||||
throw new ConstraintException("deviceName", dto.getName(), "设备名称已存在");
|
||||
}
|
||||
mapper.convert(dto, device);
|
||||
String clientId = device.getClientId();
|
||||
if (redisUtils.hasKey("record:device:properties:" + clientId)) {
|
||||
redisUtils.set("record:device:properties:" + clientId, String.valueOf(JSONObject.parseObject(device.getProperties())));
|
||||
}
|
||||
updateById(device);
|
||||
return device;
|
||||
}
|
||||
@ -144,8 +138,6 @@ public class DeviceServiceImpl extends ServiceImpl<DeviceRepository, Device> imp
|
||||
public Boolean serve(DeviceServeDto dto) {
|
||||
Device device = baseMapper.findByClientIdAndStateAndOnline(dto.clientId, Device.Status.ACTIVATED, true);
|
||||
if (device != null) {
|
||||
JSONObject json = (JSONObject) JSON.toJSON(dto);
|
||||
json.put("type", "serve");
|
||||
// amqpTemplate.convertAndSend(exchange, "send", json);
|
||||
redisUtils.set("serve:sendTime:" + dto.serveName + ":" + dto.clientId, String.valueOf(new Date()));
|
||||
return true;
|
||||
|
@ -13,6 +13,8 @@ import lombok.AllArgsConstructor;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 部门Controller
|
||||
*
|
||||
@ -46,7 +48,7 @@ public class DeptController {
|
||||
*/
|
||||
@GetMapping("/tree")
|
||||
@PreAuthorize("hasAuthority('SYSTEM:DEPT:QUERY')")
|
||||
public Dept tree(@RequestParam Long id) {
|
||||
public List<Dept> tree(@RequestParam Long id) {
|
||||
return service.listTree(id);
|
||||
}
|
||||
|
||||
|
@ -5,6 +5,7 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Constants;
|
||||
import com.zsc.edu.gateway.modules.system.entity.Menu;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.apache.ibatis.annotations.Select;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@ -12,8 +13,10 @@ import java.util.List;
|
||||
* @author yao
|
||||
*/
|
||||
public interface MenuRepository extends BaseMapper<Menu> {
|
||||
|
||||
List<Menu> selectByRoleId(Long roleId);
|
||||
|
||||
|
||||
List<Menu> selectByUserId(Long userId, Menu.Type type);
|
||||
}
|
||||
|
||||
|
@ -4,6 +4,8 @@ import com.zsc.edu.gateway.modules.system.dto.DeptDto;
|
||||
import com.zsc.edu.gateway.modules.system.entity.Dept;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 部门 服务类
|
||||
@ -34,5 +36,5 @@ public interface DeptService extends IService<Dept> {
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
Dept listTree(Long id);
|
||||
List<Dept> listTree(Long id);
|
||||
}
|
||||
|
@ -10,6 +10,7 @@ import com.zsc.edu.gateway.modules.system.repo.DeptRepository;
|
||||
import com.zsc.edu.gateway.modules.system.service.DeptService;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@ -24,7 +25,7 @@ import java.util.Objects;
|
||||
* @author Yao
|
||||
* @since 2023-04-06
|
||||
*/
|
||||
@AllArgsConstructor
|
||||
@RequiredArgsConstructor
|
||||
@Service
|
||||
public class DeptServiceImpl extends ServiceImpl<DeptRepository, Dept> implements DeptService {
|
||||
|
||||
@ -59,7 +60,7 @@ public class DeptServiceImpl extends ServiceImpl<DeptRepository, Dept> implement
|
||||
|
||||
@Override
|
||||
public List<Dept> listTree(Long deptId) {
|
||||
List<Dept> deptTrees = repo.selectDeptTree();
|
||||
List<Dept> deptTrees = baseMapper.selectDeptTree();
|
||||
List<Dept> deptTree = TreeUtil.makeTree(
|
||||
deptTrees,
|
||||
department -> department.getPid() == null || department.getPid() == -1L,
|
||||
|
@ -1,96 +0,0 @@
|
||||
package com.zsc.edu.gateway.modules.system.utils;
|
||||
|
||||
|
||||
import com.zsc.edu.gateway.exception.NotExistException;
|
||||
import com.zsc.edu.gateway.modules.system.entity.Dept;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* @author Yao
|
||||
*/
|
||||
public class DeptTreeUtil {
|
||||
|
||||
public static Dept initTree(HashSet<Dept> list){
|
||||
Dept rootDept = list.stream()
|
||||
// .filter(dept -> dept.id.equals(deptId))
|
||||
.filter(dept -> dept.getPid() == null)
|
||||
.findFirst()
|
||||
.orElseThrow(NotExistException::new);
|
||||
rootDept.setChildren(DeptTreeUtil.getTree(list, rootDept.getId()));
|
||||
return rootDept;
|
||||
}
|
||||
|
||||
public static Set<Dept> initTrees(List<Dept> list){
|
||||
Map<Long, Dept> deptMap = list.stream().collect(Collectors.toMap(Dept::getId, dept -> dept));
|
||||
HashSet<Dept> result = new HashSet<>();
|
||||
list.forEach(dept -> {
|
||||
Dept parent = deptMap.get(dept.getPid());
|
||||
if (Objects.nonNull(parent)) {
|
||||
parent.getChildren().add(dept);
|
||||
} else {
|
||||
result.add(dept);
|
||||
}
|
||||
});
|
||||
return result;
|
||||
}
|
||||
|
||||
public static HashSet<Dept> getTree(HashSet<Dept> list, long parentId){
|
||||
//获取所有子节点
|
||||
HashSet<Dept> childTreeList = getChildTree(list, parentId);
|
||||
for (Dept dept:childTreeList) {
|
||||
dept.setChildren(getTree(list, dept.getId()));
|
||||
}
|
||||
return childTreeList;
|
||||
}
|
||||
|
||||
public static HashSet<Dept> getChildTree(HashSet<Dept> list, long id){
|
||||
HashSet<Dept> childTree = new HashSet<>();
|
||||
for (Dept dept: list) {
|
||||
if(dept.getPid() != null && dept.getPid() == id){
|
||||
childTree.add(dept);
|
||||
}
|
||||
}
|
||||
return childTree;
|
||||
}
|
||||
|
||||
/**
|
||||
* 从部门树中获取子树
|
||||
* @param list
|
||||
* @return
|
||||
*/
|
||||
public static Dept getChildNode(Set<Dept> list, long id) {
|
||||
for (Dept child: list) {
|
||||
if (child.getId() == id) {
|
||||
return child;
|
||||
} else if (child.getChildren() != null && !child.getChildren().isEmpty()) {
|
||||
return getChildNode(child.getChildren(), id);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 从部门获取本身及子部门的所有id
|
||||
* @param dept
|
||||
* @return
|
||||
*/
|
||||
public static HashSet<Long> getDeptPath(Dept dept) {
|
||||
HashSet<Long> result = new HashSet<>();
|
||||
result.add(dept.getId());
|
||||
Stack<Dept> deptStack = new Stack<>();
|
||||
Set<Dept> children = dept.getChildren();
|
||||
if (!children.isEmpty()) {
|
||||
deptStack.addAll(children);
|
||||
while (!deptStack.isEmpty()) {
|
||||
Dept child = deptStack.pop();
|
||||
result.add(child.getId());
|
||||
if (!child.getChildren().isEmpty()) {
|
||||
deptStack.addAll(child.getChildren());
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
@ -1,5 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.zsc.edu.gateway.modules.system.repo.RoleRepository">
|
||||
|
||||
</mapper>
|
Loading…
Reference in New Issue
Block a user