package com.by4cloud.platformx.device.service.impl;
|
|
import cn.hutool.core.lang.tree.Tree;
|
import cn.hutool.core.lang.tree.TreeNode;
|
import cn.hutool.core.lang.tree.TreeNodeConfig;
|
import cn.hutool.core.lang.tree.TreeUtil;
|
import cn.hutool.core.util.StrUtil;
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.by4cloud.platformx.admin.api.entity.SysDept;
|
import com.by4cloud.platformx.common.data.datascope.DataScope;
|
import com.by4cloud.platformx.device.entity.DeviceClass;
|
import com.by4cloud.platformx.device.mapper.DeviceClassMapper;
|
import com.by4cloud.platformx.device.service.DeviceClassService;
|
import lombok.AllArgsConstructor;
|
import org.springframework.beans.BeanUtils;
|
import org.springframework.stereotype.Service;
|
|
import java.util.Comparator;
|
import java.util.HashMap;
|
import java.util.List;
|
import java.util.Map;
|
import java.util.stream.Collectors;
|
|
/**
|
* 设备分类表
|
*
|
* @author pig
|
* @date 2025-03-05 10:46:29
|
*/
|
@Service
|
@AllArgsConstructor
|
public class DeviceClassServiceImpl extends ServiceImpl<DeviceClassMapper, DeviceClass> implements DeviceClassService {
|
private final DeviceClassMapper deviceClassMapper;
|
|
@Override
|
public List<Tree<String>> selectTree() {
|
// 查询全部部门
|
List<DeviceClass> taxList = list(Wrappers.emptyWrapper());
|
|
TreeNodeConfig treeNodeConfig = new TreeNodeConfig();
|
treeNodeConfig.setIdKey("id");
|
treeNodeConfig.setParentIdKey("pId");
|
treeNodeConfig.setNameKey("name");
|
// 第二个参数是根节点id
|
List<Tree<String>> treeList = TreeUtil.build(taxList, "0", treeNodeConfig, (taxCode, tree) -> {
|
tree.setId(taxCode.getId()+"");
|
tree.setName(taxCode.getName());
|
tree.setParentId(taxCode.getPId()+"");
|
tree.putExtra("beforeDate", taxCode.getBeforeDate());
|
tree.putExtra("depreciation", taxCode.getDepreciation());
|
tree.putExtra("remark", taxCode.getRemark());
|
tree.putExtra("number", taxCode.getNumber());
|
});
|
|
return treeList;
|
}
|
// @Override
|
// public List<Tree<Long>> selectTree(String name,Long pId) {
|
// // 查询全部部门
|
// QueryWrapper<DeviceClass> wrapper = new QueryWrapper<>();
|
// wrapper.lambda()
|
// .like(StrUtil.isNotBlank(name),DeviceClass::getName,name);
|
// List<DeviceClass> deviceClasses = deviceClassMapper.selectList(wrapper);
|
// // 权限内部门
|
// List<TreeNode<Long>> collect = deviceClasses.stream()
|
// .filter(dept -> dept.getId().intValue() != dept.getPId())
|
// .sorted(Comparator.comparingInt(DeviceClass::getSortOrder)).map(dept -> {
|
// TreeNode<Long> treeNode = new TreeNode<>();
|
// treeNode.setId(dept.getId());
|
// treeNode.setParentId(dept.getPId());
|
// treeNode.setName(dept.getName());
|
// treeNode.setWeight(dept.getSortOrder());
|
// // 有权限不返回标识
|
// Map<String, Object> extra = new HashMap<>(8);
|
// extra.put("createTime", dept.getCreateTime());
|
// treeNode.setExtra(extra);
|
// return treeNode;
|
// }).collect(Collectors.toList());
|
//
|
// // 模糊查询 不组装树结构 直接返回 表格方便编辑
|
// if (StrUtil.isNotBlank(name)) {
|
// return collect.stream().map(node -> {
|
// Tree<Long> tree = new Tree<>();
|
// tree.putAll(node.getExtra());
|
// BeanUtils.copyProperties(node, tree);
|
// return tree;
|
// }).collect(Collectors.toList());
|
// }
|
//
|
// return TreeUtil.build(collect, pId == null ? 0 : pId);
|
// }
|
}
|