/*
|
* Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
|
*
|
* Redistribution and use in source and binary forms, with or without
|
* modification, are permitted provided that the following conditions are met:
|
*
|
* Redistributions of source code must retain the above copyright notice,
|
* this list of conditions and the following disclaimer.
|
* Redistributions in binary form must reproduce the above copyright
|
* notice, this list of conditions and the following disclaimer in the
|
* documentation and/or other materials provided with the distribution.
|
* Neither the name of the dreamlu.net developer nor the names of its
|
* contributors may be used to endorse or promote products derived from
|
* this software without specific prior written permission.
|
* Author: Chill 庄骞 (smallchill@163.com)
|
*/
|
package org.springblade.modules.jurisdiction.service.impl;
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import org.springblade.core.log.exception.ServiceException;
|
import org.springblade.core.secure.utils.AuthUtil;
|
import org.springblade.core.tool.constant.BladeConstant;
|
import org.springblade.core.tool.node.ForestNodeMerger;
|
import org.springblade.core.tool.utils.Func;
|
import org.springblade.core.tool.utils.StringPool;
|
import org.springblade.modules.jurisdiction.entity.Jurisdiction;
|
import org.springblade.modules.jurisdiction.mapper.JurisdictionMapper;
|
import org.springblade.modules.jurisdiction.service.JurisdictionService;
|
import org.springblade.modules.jurisdiction.vo.JurisdictionVO;
|
import org.springblade.modules.system.node.TreeNode;
|
import org.springframework.stereotype.Service;
|
|
import java.util.ArrayList;
|
import java.util.List;
|
import java.util.Map;
|
|
/**
|
* 服务实现类
|
*
|
* @author Chill
|
*/
|
@Service
|
public class JurisdictionServiceImpl extends ServiceImpl<JurisdictionMapper, Jurisdiction> implements JurisdictionService {
|
private static final String TENANT_ID = "tenantId";
|
private static final String PARENT_ID = "parentId";
|
|
@Override
|
public List<JurisdictionVO> lazyList(String tenantId, Long parentId, Map<String, Object> param) {
|
// 设置租户ID
|
if (AuthUtil.isAdministrator()) {
|
tenantId = StringPool.EMPTY;
|
}
|
String paramTenantId = Func.toStr(param.get(TENANT_ID));
|
if (Func.isNotEmpty(paramTenantId) && AuthUtil.isAdministrator()) {
|
tenantId = paramTenantId;
|
}
|
// 判断点击搜索但是没有查询条件的情况
|
if (Func.isEmpty(param.get(PARENT_ID)) && param.size() == 1) {
|
parentId = 0L;
|
}
|
// 判断点击搜索带有查询条件的情况
|
if (Func.isEmpty(param.get(PARENT_ID)) && param.size() > 1 && Func.toLong(parentId) == 0L) {
|
parentId = null;
|
}
|
return baseMapper.lazyList(tenantId, parentId, param);
|
}
|
|
@Override
|
public List<JurisdictionVO> tree(String tenantId) {
|
return ForestNodeMerger.merge(baseMapper.tree(tenantId));
|
}
|
|
@Override
|
public List<JurisdictionVO> lazyTree(String tenantId, Long parentId) {
|
if (AuthUtil.isAdministrator()) {
|
tenantId = StringPool.EMPTY;
|
}
|
return ForestNodeMerger.merge(baseMapper.lazyTree(tenantId, parentId));
|
}
|
|
@Override
|
public List<JurisdictionVO> lazyTrees() {
|
return ForestNodeMerger.merge(baseMapper.lazyTrees());
|
}
|
|
|
@Override
|
public boolean removeDept(String ids) {
|
return removeByIds(Func.toLongList(ids));
|
}
|
|
@Override
|
public boolean submit(Jurisdiction dept) {
|
if (Func.isEmpty(dept.getParentId())) {
|
dept.setTenantId(AuthUtil.getTenantId());
|
dept.setParentId(BladeConstant.TOP_PARENT_ID);
|
dept.setAncestors(String.valueOf(BladeConstant.TOP_PARENT_ID));
|
}
|
if (dept.getParentId() > 0) {
|
Jurisdiction parent = getById(dept.getParentId());
|
if (Func.toLong(dept.getParentId()) == Func.toLong(dept.getId())) {
|
throw new ServiceException("父节点不可选择自身!");
|
}
|
dept.setTenantId(parent.getTenantId());
|
String ancestors = parent.getAncestors() + StringPool.COMMA + dept.getParentId();
|
dept.setAncestors(ancestors);
|
}
|
dept.setIsDeleted(BladeConstant.DB_NOT_DELETED);
|
return saveOrUpdate(dept);
|
}
|
|
@Override
|
public String selJur(String deptname) {
|
return baseMapper.selJur(deptname);
|
}
|
|
/**
|
* 查询tree 数据
|
* @return
|
*/
|
@Override
|
public List<TreeNode> jurisdictionLazyTree() {
|
Map<Long, TreeNode> map = baseMapper.jurisdictionLazyTree();
|
List<TreeNode> tree = new ArrayList<>();
|
map.forEach((id, treeNode) -> {
|
if (map.containsKey(treeNode.getParentId())) {
|
map.get(treeNode.getParentId()).getChildren().add(treeNode);
|
} else {
|
tree.add(treeNode);
|
}
|
});
|
return tree;
|
}
|
|
@Override
|
public String selectIn(String jurisdiction) {
|
return baseMapper.selectIn(jurisdiction);
|
}
|
}
|