mirror of https://gitee.com/stylefeng/roses
【HrOrganizationController】新增机构树
parent
0139e9b0e7
commit
7fce5793ac
|
@ -0,0 +1,59 @@
|
|||
package cn.stylefeng.roses.kernel.system.pojo.organization.layui;
|
||||
|
||||
import cn.stylefeng.roses.kernel.rule.abstracts.AbstractTreeNode;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Layui 机构树
|
||||
*
|
||||
* @author chenjinlong
|
||||
* @date 2020/12/27 18:36
|
||||
*/
|
||||
@Data
|
||||
public class LayuiOrganizationTreeNode implements AbstractTreeNode {
|
||||
|
||||
|
||||
/**
|
||||
* 父id,一级节点父id是0
|
||||
*/
|
||||
private Long parentId;
|
||||
|
||||
/**
|
||||
* 节点名称
|
||||
*/
|
||||
private String title;
|
||||
|
||||
/**
|
||||
* 节点值
|
||||
*/
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 是否展开状态 不展开-false 展开-true
|
||||
*/
|
||||
private boolean spread = true;
|
||||
|
||||
|
||||
/**
|
||||
* 子节点的集合
|
||||
*/
|
||||
private List<LayuiOrganizationTreeNode> children;
|
||||
|
||||
@Override
|
||||
public String getNodeId() {
|
||||
return this.id.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getNodeParentId() {
|
||||
return this.parentId.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setChildrenNodes(List childrenNodes) {
|
||||
this.children = childrenNodes;
|
||||
}
|
||||
|
||||
}
|
|
@ -107,5 +107,27 @@ public class HrOrganizationController {
|
|||
return new SuccessResponseData(hrOrganizationService.list(hrOrganizationRequest));
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取全部系统组织机构树,用于新增,编辑时选择上级节点
|
||||
*
|
||||
* @author chenjinlong
|
||||
* @date 2021/01/05 15:55
|
||||
*/
|
||||
@GetResource(name = "获取全部系统组织机构树", path = "/hrOrganization/tree")
|
||||
public ResponseData tree(HrOrganizationRequest hrOrganizationRequest) {
|
||||
return new SuccessResponseData(hrOrganizationService.tree(hrOrganizationRequest));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取全部系统组织机构树,用于新增,编辑时选择上级节点
|
||||
*
|
||||
* @author chenjinlong
|
||||
* @date 2021/01/05 15:55
|
||||
*/
|
||||
@GetResource(name = "获取全部系统组织机构树", path = "/hrOrganization/treeLayui")
|
||||
public ResponseData treeLayui(HrOrganizationRequest hrOrganizationRequest) {
|
||||
return new SuccessResponseData(hrOrganizationService.treeLayui(hrOrganizationRequest));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,23 @@
|
|||
package cn.stylefeng.roses.kernel.system.modular.organization.factory;
|
||||
|
||||
import cn.stylefeng.roses.kernel.system.modular.organization.entity.HrOrganization;
|
||||
import cn.stylefeng.roses.kernel.system.pojo.organization.layui.LayuiOrganizationTreeNode;
|
||||
|
||||
public class OrganizationFactory {
|
||||
|
||||
/**
|
||||
* 实体转换
|
||||
*
|
||||
* @param hrOrganization 机构
|
||||
* @return LayuiOrganizationTreeNode layui树实体对象
|
||||
* @author chenjinlong
|
||||
* @date 2021/1/5 21:07
|
||||
*/
|
||||
public static LayuiOrganizationTreeNode parseOrganizationTreeNode(HrOrganization hrOrganization) {
|
||||
LayuiOrganizationTreeNode treeNode = new LayuiOrganizationTreeNode();
|
||||
treeNode.setId(hrOrganization.getOrgId());
|
||||
treeNode.setParentId(hrOrganization.getOrgParentId());
|
||||
treeNode.setTitle(hrOrganization.getOrgName());
|
||||
return treeNode;
|
||||
}
|
||||
}
|
|
@ -4,6 +4,7 @@ import cn.stylefeng.roses.kernel.db.api.pojo.page.PageResult;
|
|||
import cn.stylefeng.roses.kernel.rule.pojo.tree.DefaultTreeNode;
|
||||
import cn.stylefeng.roses.kernel.system.modular.organization.entity.HrOrganization;
|
||||
import cn.stylefeng.roses.kernel.system.pojo.organization.HrOrganizationRequest;
|
||||
import cn.stylefeng.roses.kernel.system.pojo.organization.layui.LayuiOrganizationTreeNode;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
|
||||
import java.util.List;
|
||||
|
@ -93,6 +94,16 @@ public interface HrOrganizationService extends IService<HrOrganization> {
|
|||
*/
|
||||
List<DefaultTreeNode> tree(HrOrganizationRequest hrOrganizationRequest);
|
||||
|
||||
/**
|
||||
* 获取组织架构树
|
||||
*
|
||||
* @param hrOrganizationRequest 查询参数
|
||||
* @return 系统组织机构树
|
||||
* @author chenjinlong
|
||||
* @date 2020/11/6 13:41
|
||||
*/
|
||||
List<LayuiOrganizationTreeNode> treeLayui(HrOrganizationRequest hrOrganizationRequest);
|
||||
|
||||
/**
|
||||
* 查询所有参数组织架构id集合的所有层级的父id,包含父级的父级等
|
||||
*
|
||||
|
|
|
@ -22,9 +22,11 @@ import cn.stylefeng.roses.kernel.system.constants.SystemConstants;
|
|||
import cn.stylefeng.roses.kernel.system.exception.SystemModularException;
|
||||
import cn.stylefeng.roses.kernel.system.exception.enums.OrganizationExceptionEnum;
|
||||
import cn.stylefeng.roses.kernel.system.modular.organization.entity.HrOrganization;
|
||||
import cn.stylefeng.roses.kernel.system.modular.organization.factory.OrganizationFactory;
|
||||
import cn.stylefeng.roses.kernel.system.modular.organization.mapper.HrOrganizationMapper;
|
||||
import cn.stylefeng.roses.kernel.system.modular.organization.service.HrOrganizationService;
|
||||
import cn.stylefeng.roses.kernel.system.pojo.organization.HrOrganizationRequest;
|
||||
import cn.stylefeng.roses.kernel.system.pojo.organization.layui.LayuiOrganizationTreeNode;
|
||||
import cn.stylefeng.roses.kernel.system.util.DataScopeUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||
|
@ -131,14 +133,10 @@ public class HrOrganizationServiceImpl extends ServiceImpl<HrOrganizationMapper,
|
|||
|
||||
@Override
|
||||
public void updateStatus(HrOrganizationRequest hrOrganizationRequest) {
|
||||
|
||||
// 先查询有没有这条记录再更新
|
||||
// 先查询有没有这条记录,再更新
|
||||
HrOrganization hrOrganization = this.queryOrganization(hrOrganizationRequest);
|
||||
|
||||
LambdaUpdateWrapper<HrOrganization> updateWrapper = new LambdaUpdateWrapper<>();
|
||||
updateWrapper.eq(HrOrganization::getOrgId, hrOrganization.getOrgId());
|
||||
updateWrapper.set(HrOrganization::getStatusFlag, hrOrganizationRequest.getStatusFlag());
|
||||
this.update(updateWrapper);
|
||||
hrOrganization.setStatusFlag(hrOrganizationRequest.getStatusFlag());
|
||||
this.updateById(hrOrganization);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -222,6 +220,51 @@ public class HrOrganizationServiceImpl extends ServiceImpl<HrOrganizationMapper,
|
|||
return new DefaultTreeBuildFactory<DefaultTreeNode>().doTreeBuild(treeNodeList);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<LayuiOrganizationTreeNode> treeLayui(HrOrganizationRequest hrOrganizationRequest) {
|
||||
// 定义返回结果
|
||||
List<LayuiOrganizationTreeNode> treeNodeList = CollectionUtil.newArrayList();
|
||||
LambdaQueryWrapper<HrOrganization> queryWrapper = new LambdaQueryWrapper<>();
|
||||
|
||||
// 如果是超级管理员 或 数据范围是所有,则不过滤数据范围
|
||||
boolean needToDataScope = true;
|
||||
if (LoginContext.me().getSuperAdminFlag()) {
|
||||
Set<DataScopeTypeEnum> dataScopeTypes = LoginContext.me().getLoginUser().getDataScopeTypeEnums();
|
||||
if (dataScopeTypes != null && dataScopeTypes.contains(DataScopeTypeEnum.ALL)) {
|
||||
needToDataScope = false;
|
||||
}
|
||||
}
|
||||
|
||||
// 如果需要数据范围过滤,则获取用户的数据范围,拼接查询条件
|
||||
if (needToDataScope) {
|
||||
Set<Long> dataScope = LoginContext.me().getLoginUser().getDataScopeOrganizationIds();
|
||||
|
||||
// 数据范围没有,直接返回空
|
||||
if (ObjectUtil.isEmpty(dataScope)) {
|
||||
return treeNodeList;
|
||||
}
|
||||
|
||||
// 根据组织机构数据范围的上级组织,用于展示完整的树形结构
|
||||
Set<Long> allLevelParentIdsByOrganizations = this.findAllLevelParentIdsByOrganizations(dataScope);
|
||||
|
||||
// 拼接查询条件
|
||||
queryWrapper.in(HrOrganization::getOrgId, allLevelParentIdsByOrganizations);
|
||||
}
|
||||
|
||||
// 只查询未删除的
|
||||
queryWrapper.eq(HrOrganization::getDelFlag, YesOrNotEnum.N.getCode());
|
||||
|
||||
// 根据排序升序排列,序号越小越在前
|
||||
queryWrapper.orderByAsc(HrOrganization::getOrgSort);
|
||||
// 组装节点
|
||||
List<HrOrganization> hrOrganizationList = this.list(queryWrapper);
|
||||
hrOrganizationList.forEach(hrOrganization -> {
|
||||
LayuiOrganizationTreeNode treeNode = OrganizationFactory.parseOrganizationTreeNode(hrOrganization);
|
||||
treeNodeList.add(treeNode);
|
||||
});
|
||||
return new DefaultTreeBuildFactory<LayuiOrganizationTreeNode>().doTreeBuild(treeNodeList);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<Long> findAllLevelParentIdsByOrganizations(Set<Long> organizationIds) {
|
||||
|
||||
|
|
Loading…
Reference in New Issue