【HrOrganizationController】新增机构树

pull/3/head
chenjinlong 2021-01-05 22:38:38 +08:00 committed by fengshuonan
parent 0139e9b0e7
commit 7fce5793ac
5 changed files with 165 additions and 7 deletions

View File

@ -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 {
/**
* idid0
*/
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;
}
}

View File

@ -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));
}
}

View File

@ -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;
}
}

View File

@ -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);
/**
* idid
*

View File

@ -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) {