|
@@ -3,128 +3,118 @@ package cn.cslg.permission.service;
|
|
import cn.cslg.permission.common.model.vo.FunctionVO;
|
|
import cn.cslg.permission.common.model.vo.FunctionVO;
|
|
import cn.cslg.permission.domain.Function;
|
|
import cn.cslg.permission.domain.Function;
|
|
import cn.cslg.permission.mapper.FunctionMapper;
|
|
import cn.cslg.permission.mapper.FunctionMapper;
|
|
|
|
+import cn.hutool.core.collection.CollUtil;
|
|
|
|
+import cn.hutool.core.lang.tree.TreeNode;
|
|
|
|
+import cn.hutool.core.lang.tree.TreeNodeConfig;
|
|
|
|
+import cn.hutool.core.lang.tree.TreeUtil;
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
-import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
import lombok.RequiredArgsConstructor;
|
|
import lombok.RequiredArgsConstructor;
|
|
import org.springframework.context.annotation.Lazy;
|
|
import org.springframework.context.annotation.Lazy;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
|
+import org.springframework.transaction.interceptor.TransactionAspectSupport;
|
|
|
|
|
|
-import java.util.ArrayList;
|
|
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
|
|
|
/**
|
|
/**
|
|
* @author 沈永艺
|
|
* @author 沈永艺
|
|
- * @version 1.0
|
|
|
|
- * @date 2022-8-2 20:11:00
|
|
|
|
|
|
+ * @date 2022-8-2
|
|
* @description 功能类 Service 层
|
|
* @description 功能类 Service 层
|
|
*/
|
|
*/
|
|
|
|
|
|
@Service
|
|
@Service
|
|
@RequiredArgsConstructor(onConstructor_ = {@Lazy})
|
|
@RequiredArgsConstructor(onConstructor_ = {@Lazy})
|
|
public class FunctionService extends ServiceImpl<FunctionMapper, Function> {
|
|
public class FunctionService extends ServiceImpl<FunctionMapper, Function> {
|
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
public void addFunction(FunctionVO functionVO) {
|
|
public void addFunction(FunctionVO functionVO) {
|
|
- Function function = new Function();
|
|
|
|
- function.setFunctionUp(functionVO.getFunction())
|
|
|
|
- .setFunctionName(functionVO.getName())
|
|
|
|
- .setFunctionCorresponding(functionVO.getSign())
|
|
|
|
- .setApplicationId(functionVO.getApply())
|
|
|
|
- .setFunctionDescription(functionVO.getDescribe());
|
|
|
|
- function.insert();
|
|
|
|
|
|
+ try {
|
|
|
|
+ Function function = new Function();
|
|
|
|
+ function.setFunctionUp(functionVO.getFunction())
|
|
|
|
+ .setFunctionName(functionVO.getName())
|
|
|
|
+ .setFunctionPath(functionVO.getSign())
|
|
|
|
+ .setApplicationId(functionVO.getApply())
|
|
|
|
+ .setFunctionDescription(functionVO.getDescribe());
|
|
|
|
+ function.insert();
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
|
+ public void deleteFunction(FunctionVO functionVO) {
|
|
|
|
+ try {
|
|
|
|
+ Function function = new Function();
|
|
|
|
+ function.setFunctionUp(functionVO.getFunction())
|
|
|
|
+ .setFunctionName(functionVO.getName())
|
|
|
|
+ .setFunctionPath(functionVO.getSign())
|
|
|
|
+ .setApplicationId(functionVO.getApply())
|
|
|
|
+ .setFunctionDescription(functionVO.getDescribe());
|
|
|
|
+ function.updateById();
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
|
+ public void updateFunction(FunctionVO functionVO) {
|
|
|
|
+ try {
|
|
|
|
+ Function function = new Function();
|
|
|
|
+ function.setFunctionUp(functionVO.getFunction())
|
|
|
|
+ .setFunctionName(functionVO.getName())
|
|
|
|
+ .setFunctionPath(functionVO.getSign())
|
|
|
|
+ .setApplicationId(functionVO.getApply())
|
|
|
|
+ .setFunctionDescription(functionVO.getDescribe());
|
|
|
|
+ function.updateById();
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
public Object queryPageList(FunctionVO functionVO) {
|
|
public Object queryPageList(FunctionVO functionVO) {
|
|
LambdaQueryWrapper<Function> queryWrapper = new LambdaQueryWrapper<>();
|
|
LambdaQueryWrapper<Function> queryWrapper = new LambdaQueryWrapper<>();
|
|
if (functionVO.getSize() == null || functionVO.getCurrent() == null) {
|
|
if (functionVO.getSize() == null || functionVO.getCurrent() == null) {
|
|
- LambdaQueryWrapper<Function> lambdaQueryWrapper = new LambdaQueryWrapper();
|
|
|
|
-
|
|
|
|
queryWrapper.eq(Function::getIsDelete, 0);
|
|
queryWrapper.eq(Function::getIsDelete, 0);
|
|
- Function function = new Function();
|
|
|
|
-
|
|
|
|
- List<Function> lst = function.selectList(queryWrapper);
|
|
|
|
- List<FunctionVO> voList = new ArrayList<>();
|
|
|
|
- for (Function value : lst) {
|
|
|
|
- int id;
|
|
|
|
- if (value.getFunctionUp() == 0) {
|
|
|
|
-
|
|
|
|
- id = value.getId();
|
|
|
|
- LambdaQueryWrapper<Function> functionLambdaQueryWrapper = new LambdaQueryWrapper<>();
|
|
|
|
- functionLambdaQueryWrapper.eq(Function::getFunctionUp, id);
|
|
|
|
-
|
|
|
|
- Function function1 = new Function();
|
|
|
|
- List<Function> children = function1.selectList(functionLambdaQueryWrapper);
|
|
|
|
- List<FunctionVO> children1 = new ArrayList<>();
|
|
|
|
- for (Function child : children) {
|
|
|
|
- FunctionVO functionVO1 = new FunctionVO();
|
|
|
|
- functionVO1.setFunction(child.getFunctionUp())
|
|
|
|
- .setName(child.getFunctionName())
|
|
|
|
- .setSign(child.getFunctionCorresponding())
|
|
|
|
- .setDescribe(child.getFunctionDescription())
|
|
|
|
- .setApply(child.getApplicationId())
|
|
|
|
- .setId(child.getId());
|
|
|
|
- children1.add(functionVO1);
|
|
|
|
- }
|
|
|
|
|
|
+ List<Function> lst = this.list(queryWrapper);
|
|
|
|
|
|
- FunctionVO functionVO1 = new FunctionVO();
|
|
|
|
- functionVO1.setChildren(children1)
|
|
|
|
- .setFunction(value.getFunctionUp())
|
|
|
|
- .setApply(value.getApplicationId())
|
|
|
|
- .setName(value.getFunctionName())
|
|
|
|
- .setDescribe(value.getFunctionDescription())
|
|
|
|
- .setSign(value.getFunctionCorresponding())
|
|
|
|
- .setUpName("测试")
|
|
|
|
- .setId(value.getId());
|
|
|
|
- voList.add(functionVO1);
|
|
|
|
- }
|
|
|
|
|
|
+ TreeNodeConfig treeNodeConfig = new TreeNodeConfig();
|
|
|
|
+ treeNodeConfig.setWeightKey("order");
|
|
|
|
+ List<TreeNode<Integer>> nodeList = CollUtil.newArrayList();
|
|
|
|
+ for (Function data : lst) {
|
|
|
|
+ nodeList.add(new TreeNode<>(data.getId(), data.getFunctionUp(), data.getFunctionName(), data.getFunctionOrder()));
|
|
}
|
|
}
|
|
- return voList;
|
|
|
|
|
|
+ return TreeUtil.build(nodeList, 0, treeNodeConfig, (treeNode, tree) -> {
|
|
|
|
+ tree.setId(treeNode.getId());
|
|
|
|
+ tree.setParentId(treeNode.getParentId());
|
|
|
|
+ tree.setWeight(treeNode.getWeight());
|
|
|
|
+ tree.setName(treeNode.getName());
|
|
|
|
+ });
|
|
} else {
|
|
} else {
|
|
- queryWrapper.like(Function::getFunctionName, functionVO.getName());
|
|
|
|
- queryWrapper.or();
|
|
|
|
- queryWrapper.like(Function::getFunctionCorresponding, functionVO.getName());
|
|
|
|
- queryWrapper.or();
|
|
|
|
- queryWrapper.like(Function::getFunctionDescription, functionVO.getName());
|
|
|
|
- queryWrapper.eq(Function::getIsDelete, 0);
|
|
|
|
-
|
|
|
|
|
|
+ queryWrapper
|
|
|
|
+ .like(Function::getFunctionName, functionVO.getName())
|
|
|
|
+ .or()
|
|
|
|
+ .like(Function::getFunctionPath, functionVO.getName())
|
|
|
|
+ .or()
|
|
|
|
+ .like(Function::getFunctionDescription, functionVO.getName())
|
|
|
|
+ .eq(Function::getIsDelete, 0);
|
|
Function function = new Function();
|
|
Function function = new Function();
|
|
List<Function> lst = function.selectList(queryWrapper);
|
|
List<Function> lst = function.selectList(queryWrapper);
|
|
|
|
|
|
- List<FunctionVO> voList = new ArrayList<>();
|
|
|
|
- for (Function value : lst) {
|
|
|
|
- int id;
|
|
|
|
- if (value.getFunctionUp() == 0) {
|
|
|
|
-
|
|
|
|
- id = value.getId();
|
|
|
|
- LambdaQueryWrapper<Function> lambdaQueryWrapper = new LambdaQueryWrapper<>();
|
|
|
|
- lambdaQueryWrapper.eq(Function::getFunctionUp, id);
|
|
|
|
-
|
|
|
|
- Function function1 = new Function();
|
|
|
|
- List<Function> children = function1.selectList(lambdaQueryWrapper);
|
|
|
|
- List<FunctionVO> children1 = new ArrayList<>();
|
|
|
|
- for (Function child : children) {
|
|
|
|
- FunctionVO functionVO1 = new FunctionVO();
|
|
|
|
- functionVO1.setFunction(child.getFunctionUp())
|
|
|
|
- .setName(child.getFunctionName())
|
|
|
|
- .setSign(child.getFunctionCorresponding())
|
|
|
|
- .setDescribe(child.getFunctionDescription())
|
|
|
|
- .setApply(child.getApplicationId())
|
|
|
|
- .setId(child.getId());
|
|
|
|
- children1.add(functionVO1);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- FunctionVO functionVO1 = new FunctionVO();
|
|
|
|
- functionVO1.setChildren(children1)
|
|
|
|
- .setFunction(value.getFunctionUp())
|
|
|
|
- .setApply(value.getApplicationId())
|
|
|
|
- .setName(value.getFunctionName())
|
|
|
|
- .setDescribe(value.getFunctionDescription())
|
|
|
|
- .setSign(value.getFunctionCorresponding())
|
|
|
|
- .setUpName("测试")
|
|
|
|
- .setId(value.getId());
|
|
|
|
- voList.add(functionVO1);
|
|
|
|
- }
|
|
|
|
|
|
+ TreeNodeConfig treeNodeConfig = new TreeNodeConfig();
|
|
|
|
+ treeNodeConfig.setWeightKey("order");
|
|
|
|
+ List<TreeNode<Integer>> nodeList = CollUtil.newArrayList();
|
|
|
|
+ for (Function data : lst) {
|
|
|
|
+ nodeList.add(new TreeNode<>(data.getId(), data.getFunctionUp(), data.getFunctionName(), data.getFunctionOrder()));
|
|
}
|
|
}
|
|
- return voList;
|
|
|
|
|
|
+ return TreeUtil.build(nodeList, 0, treeNodeConfig, (treeNode, tree) -> {
|
|
|
|
+ tree.setId(treeNode.getId());
|
|
|
|
+ tree.setParentId(treeNode.getParentId());
|
|
|
|
+ tree.setWeight(treeNode.getWeight());
|
|
|
|
+ tree.setName(treeNode.getName());
|
|
|
|
+ });
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|