【org】整理组织机构和职务代码

pull/3/head
fengshuonan 2021-02-08 20:48:39 +08:00
parent 66eed84d8a
commit a0b68f165c
20 changed files with 341 additions and 285 deletions

View File

@ -1,6 +1,6 @@
package cn.stylefeng.roses.kernel.system;
import cn.stylefeng.roses.kernel.system.pojo.organization.DataScopeResponse;
import cn.stylefeng.roses.kernel.system.pojo.organization.DataScopeDTO;
import cn.stylefeng.roses.kernel.system.pojo.role.response.SysRoleResponse;
import java.util.List;
@ -26,6 +26,6 @@ public interface DataScopeApi {
* @author majianguo
* @date 2020/11/5 11:44
*/
DataScopeResponse getDataScope(Long userId, List<SysRoleResponse> sysRoles);
DataScopeDTO getDataScope(Long userId, List<SysRoleResponse> sysRoles);
}

View File

@ -1,6 +1,6 @@
package cn.stylefeng.roses.kernel.system;
import cn.stylefeng.roses.kernel.system.pojo.organization.HrOrganizationResponse;
import cn.stylefeng.roses.kernel.system.pojo.organization.HrOrganizationDTO;
import java.util.List;
@ -19,5 +19,6 @@ public interface OrganizationServiceApi {
* @author liuhanqing
* @date 2021/1/15 10:41
*/
List<HrOrganizationResponse> orgList();
List<HrOrganizationDTO> orgList();
}

View File

@ -1,4 +1,4 @@
package cn.stylefeng.roses.kernel.system.exception.enums;
package cn.stylefeng.roses.kernel.system.exception.enums.organization;
import cn.stylefeng.roses.kernel.rule.constants.RuleConstants;
import cn.stylefeng.roses.kernel.rule.exception.AbstractExceptionEnum;

View File

@ -1,4 +1,4 @@
package cn.stylefeng.roses.kernel.system.exception.enums;
package cn.stylefeng.roses.kernel.system.exception.enums.organization;
import cn.stylefeng.roses.kernel.rule.constants.RuleConstants;
import cn.stylefeng.roses.kernel.rule.exception.AbstractExceptionEnum;

View File

@ -12,7 +12,7 @@ import java.util.Set;
* @date 2020/11/6 11:30
*/
@Data
public class DataScopeResponse {
public class DataScopeDTO {
/**
*

View File

@ -11,7 +11,7 @@ import java.math.BigDecimal;
* @date 2020/11/04 11:05
*/
@Data
public class HrOrganizationResponse {
public class HrOrganizationDTO {
/**
*

View File

@ -1,4 +1,4 @@
package cn.stylefeng.roses.kernel.system.pojo;
package cn.stylefeng.roses.kernel.system.pojo.organization;
import cn.stylefeng.roses.kernel.rule.pojo.request.BaseRequest;
import cn.stylefeng.roses.kernel.validator.validators.status.StatusValue;

View File

@ -6,7 +6,7 @@ import cn.stylefeng.roses.kernel.auth.api.enums.DataScopeTypeEnum;
import cn.stylefeng.roses.kernel.auth.api.exception.AuthException;
import cn.stylefeng.roses.kernel.auth.api.pojo.login.LoginUser;
import cn.stylefeng.roses.kernel.system.exception.SystemModularException;
import cn.stylefeng.roses.kernel.system.exception.enums.DataScopeExceptionEnum;
import cn.stylefeng.roses.kernel.system.exception.enums.organization.DataScopeExceptionEnum;
import java.util.Set;

View File

@ -40,18 +40,6 @@ public class HrOrganizationController {
return new SuccessResponseData();
}
/**
*
*
* @author fengshuonan
* @date 2020/11/04 11:05
*/
@PostResource(name = "编辑系统组织机构", path = "/hrOrganization/edit")
public ResponseData edit(@RequestBody @Validated(HrOrganizationRequest.edit.class) HrOrganizationRequest hrOrganizationRequest) {
hrOrganizationService.edit(hrOrganizationRequest);
return new SuccessResponseData();
}
/**
*
*
@ -64,6 +52,18 @@ public class HrOrganizationController {
return new SuccessResponseData();
}
/**
*
*
* @author fengshuonan
* @date 2020/11/04 11:05
*/
@PostResource(name = "编辑系统组织机构", path = "/hrOrganization/edit")
public ResponseData edit(@RequestBody @Validated(HrOrganizationRequest.edit.class) HrOrganizationRequest hrOrganizationRequest) {
hrOrganizationService.edit(hrOrganizationRequest);
return new SuccessResponseData();
}
/**
*
*
@ -110,18 +110,18 @@ public class HrOrganizationController {
}
/**
*
* antd vue
*
* @author chenjinlong
* @date 2021/01/05 15:55
*/
@GetResource(name = "获取全部系统组织机构树", path = "/hrOrganization/tree")
public ResponseData tree(HrOrganizationRequest hrOrganizationRequest) {
return new SuccessResponseData(hrOrganizationService.tree(hrOrganizationRequest));
return new SuccessResponseData(hrOrganizationService.treeAntdv(hrOrganizationRequest));
}
/**
*
* layui
*
* @author chenjinlong
* @date 2021/01/05 15:55
@ -132,7 +132,7 @@ public class HrOrganizationController {
}
/**
* zTreelayui
* layui
*
* @author fengshuonan
* @date 2021/1/9 18:37
@ -143,7 +143,7 @@ public class HrOrganizationController {
}
/**
* zTreeantd vue
* antd vue
*
* @author fengshuonan
* @date 2021/1/9 18:37
@ -154,5 +154,4 @@ public class HrOrganizationController {
return new SuccessResponseData(zTreeNodes);
}
}

View File

@ -7,7 +7,7 @@ import cn.stylefeng.roses.kernel.rule.pojo.request.BaseRequest;
import cn.stylefeng.roses.kernel.rule.pojo.response.ResponseData;
import cn.stylefeng.roses.kernel.rule.pojo.response.SuccessResponseData;
import cn.stylefeng.roses.kernel.system.modular.organization.service.HrPositionService;
import cn.stylefeng.roses.kernel.system.pojo.HrPositionRequest;
import cn.stylefeng.roses.kernel.system.pojo.organization.HrPositionRequest;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
@ -39,18 +39,6 @@ public class HrPositionController {
return new SuccessResponseData();
}
/**
*
*
* @author chenjinlong
* @date 2020/11/04 11:07
*/
@PostResource(name = "编辑系统职位", path = "/hrPosition/edit")
public ResponseData edit(@RequestBody @Validated(HrPositionRequest.edit.class) HrPositionRequest hrPositionRequest) {
hrPositionService.edit(hrPositionRequest);
return new SuccessResponseData();
}
/**
*
*
@ -63,6 +51,18 @@ public class HrPositionController {
return new SuccessResponseData();
}
/**
*
*
* @author chenjinlong
* @date 2020/11/04 11:07
*/
@PostResource(name = "编辑系统职位", path = "/hrPosition/edit")
public ResponseData edit(@RequestBody @Validated(HrPositionRequest.edit.class) HrPositionRequest hrPositionRequest) {
hrPositionService.edit(hrPositionRequest);
return new SuccessResponseData();
}
/**
*
*

View File

@ -0,0 +1,29 @@
package cn.stylefeng.roses.kernel.system.modular.organization.factory;
import cn.stylefeng.roses.kernel.rule.tree.factory.node.DefaultTreeNode;
import cn.stylefeng.roses.kernel.system.modular.organization.entity.HrOrganization;
/**
* Antdv
*
* @author fengshuonan
* @date 2021/2/8 20:32
*/
public class AntdvOrganizationFactory {
/**
*
*
* @author fengshuonan
* @date 2021/2/8 20:35
*/
public static DefaultTreeNode parseTreeNode(HrOrganization organizationList) {
DefaultTreeNode orgTreeNode = new DefaultTreeNode();
orgTreeNode.setId(String.valueOf(organizationList.getOrgId()));
orgTreeNode.setPId(String.valueOf(organizationList.getOrgParentId()));
orgTreeNode.setName(organizationList.getOrgName());
orgTreeNode.setSort(organizationList.getOrgSort());
return orgTreeNode;
}
}

View File

@ -7,8 +7,8 @@ import cn.stylefeng.roses.kernel.system.RoleServiceApi;
import cn.stylefeng.roses.kernel.system.UserOrgServiceApi;
import cn.stylefeng.roses.kernel.system.UserServiceApi;
import cn.stylefeng.roses.kernel.system.exception.SystemModularException;
import cn.stylefeng.roses.kernel.system.exception.enums.DataScopeExceptionEnum;
import cn.stylefeng.roses.kernel.system.pojo.organization.DataScopeResponse;
import cn.stylefeng.roses.kernel.system.exception.enums.organization.DataScopeExceptionEnum;
import cn.stylefeng.roses.kernel.system.pojo.organization.DataScopeDTO;
import cn.stylefeng.roses.kernel.system.pojo.role.response.SysRoleResponse;
import cn.stylefeng.roses.kernel.system.pojo.user.SysUserOrgResponse;
import org.springframework.stereotype.Service;
@ -41,10 +41,10 @@ public class DataScopeService implements DataScopeApi {
private DbOperatorApi dbOperatorApi;
@Override
public DataScopeResponse getDataScope(Long userId, List<SysRoleResponse> sysRoles) {
public DataScopeDTO getDataScope(Long userId, List<SysRoleResponse> sysRoles) {
// 初始化返回结果
DataScopeResponse dataScopeResponse = new DataScopeResponse();
DataScopeDTO dataScopeResponse = new DataScopeDTO();
Set<Long> userIds = new HashSet<>();
Set<Long> organizationIds = new HashSet<>();

View File

@ -29,15 +29,6 @@ public interface HrOrganizationService extends IService<HrOrganization>, Organiz
*/
void add(HrOrganizationRequest hrOrganizationRequest);
/**
*
*
* @param hrOrganizationRequest
* @author fengshuonan
* @date 2020/11/04 11:05
*/
void edit(HrOrganizationRequest hrOrganizationRequest);
/**
*
*
@ -47,6 +38,15 @@ public interface HrOrganizationService extends IService<HrOrganization>, Organiz
*/
void del(HrOrganizationRequest hrOrganizationRequest);
/**
*
*
* @param hrOrganizationRequest
* @author fengshuonan
* @date 2020/11/04 11:05
*/
void edit(HrOrganizationRequest hrOrganizationRequest);
/**
*
*
@ -86,19 +86,18 @@ public interface HrOrganizationService extends IService<HrOrganization>, Organiz
*/
List<HrOrganization> findList(HrOrganizationRequest hrOrganizationRequest);
/**
*
* antd vue
*
* @param hrOrganizationRequest
* @return
* @author fengshuonan
* @date 2020/11/6 13:41
*/
List<DefaultTreeNode> tree(HrOrganizationRequest hrOrganizationRequest);
List<DefaultTreeNode> treeAntdv(HrOrganizationRequest hrOrganizationRequest);
/**
*
* layui
*
* @param hrOrganizationRequest
* @return
@ -107,16 +106,6 @@ public interface HrOrganizationService extends IService<HrOrganization>, Organiz
*/
List<LayuiOrganizationTreeNode> treeLayui(HrOrganizationRequest hrOrganizationRequest);
/**
* idid
*
* @param organizationIds id
* @return idid
* @author fengshuonan
* @date 2020/11/6 14:24
*/
Set<Long> findAllLevelParentIdsByOrganizations(Set<Long> organizationIds);
/**
* ztreelayui
*
@ -128,4 +117,14 @@ public interface HrOrganizationService extends IService<HrOrganization>, Organiz
*/
List<ZTreeNode> orgZTree(HrOrganizationRequest hrOrganizationRequest, boolean buildTree);
/**
* idid
*
* @param organizationIds id
* @return idid
* @author fengshuonan
* @date 2020/11/6 14:24
*/
Set<Long> findAllLevelParentIdsByOrganizations(Set<Long> organizationIds);
}

View File

@ -2,7 +2,7 @@ package cn.stylefeng.roses.kernel.system.modular.organization.service;
import cn.stylefeng.roses.kernel.db.api.pojo.page.PageResult;
import cn.stylefeng.roses.kernel.system.modular.organization.entity.HrPosition;
import cn.stylefeng.roses.kernel.system.pojo.HrPositionRequest;
import cn.stylefeng.roses.kernel.system.pojo.organization.HrPositionRequest;
import com.baomidou.mybatisplus.extension.service.IService;
import java.util.List;
@ -81,4 +81,4 @@ public interface HrPositionService extends IService<HrPosition> {
*/
PageResult<HrPosition> findPage(HrPositionRequest hrPositionRequest);
}
}

View File

@ -24,13 +24,14 @@ import cn.stylefeng.roses.kernel.system.RoleServiceApi;
import cn.stylefeng.roses.kernel.system.UserOrgServiceApi;
import cn.stylefeng.roses.kernel.system.UserServiceApi;
import cn.stylefeng.roses.kernel.system.exception.SystemModularException;
import cn.stylefeng.roses.kernel.system.exception.enums.OrganizationExceptionEnum;
import cn.stylefeng.roses.kernel.system.exception.enums.organization.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.factory.AntdvOrganizationFactory;
import cn.stylefeng.roses.kernel.system.modular.organization.factory.LayuiOrganizationFactory;
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.HrOrganizationDTO;
import cn.stylefeng.roses.kernel.system.pojo.organization.HrOrganizationRequest;
import cn.stylefeng.roses.kernel.system.pojo.organization.HrOrganizationResponse;
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;
@ -87,27 +88,6 @@ public class HrOrganizationServiceImpl extends ServiceImpl<HrOrganizationMapper,
this.save(hrOrganization);
}
@Override
public void edit(HrOrganizationRequest hrOrganizationRequest) {
HrOrganization hrOrganization = this.queryOrganization(hrOrganizationRequest);
Long id = hrOrganization.getOrgId();
// 校验数据范围
DataScopeUtil.quickValidateDataScope(id);
BeanUtil.copyProperties(hrOrganizationRequest, hrOrganization);
// 填充parentIds
this.fillParentIds(hrOrganization);
// 不能修改状态,用修改状态接口修改状态
hrOrganization.setStatusFlag(null);
// 更新这条记录
this.updateById(hrOrganization);
}
@Override
@Transactional(rollbackFor = Exception.class)
public void del(HrOrganizationRequest hrOrganizationRequest) {
@ -139,6 +119,27 @@ public class HrOrganizationServiceImpl extends ServiceImpl<HrOrganizationMapper,
userServiceApi.deleteUserDataScopeListByOrgIdList(childIdList);
}
@Override
public void edit(HrOrganizationRequest hrOrganizationRequest) {
HrOrganization hrOrganization = this.queryOrganization(hrOrganizationRequest);
Long id = hrOrganization.getOrgId();
// 校验数据范围
DataScopeUtil.quickValidateDataScope(id);
BeanUtil.copyProperties(hrOrganizationRequest, hrOrganization);
// 填充parentIds
this.fillParentIds(hrOrganization);
// 不能修改状态,用修改状态接口修改状态
hrOrganization.setStatusFlag(null);
// 更新这条记录
this.updateById(hrOrganization);
}
@Override
public void updateStatus(HrOrganizationRequest hrOrganizationRequest) {
HrOrganization hrOrganization = this.queryOrganization(hrOrganizationRequest);
@ -165,8 +166,106 @@ public class HrOrganizationServiceImpl extends ServiceImpl<HrOrganizationMapper,
}
@Override
public List<HrOrganizationResponse> orgList() {
public List<DefaultTreeNode> treeAntdv(HrOrganizationRequest hrOrganizationRequest) {
// 定义返回结果
List<DefaultTreeNode> treeNodeList = CollectionUtil.newArrayList();
// 组装节点
List<HrOrganization> list = this.findListByDataScope(hrOrganizationRequest);
for (HrOrganization hrOrganization : list) {
DefaultTreeNode defaultTreeNode = AntdvOrganizationFactory.parseTreeNode(hrOrganization);
treeNodeList.add(defaultTreeNode);
}
// 构建树并返回
return new DefaultTreeBuildFactory<DefaultTreeNode>().doTreeBuild(treeNodeList);
}
@Override
public List<LayuiOrganizationTreeNode> treeLayui(HrOrganizationRequest hrOrganizationRequest) {
// 定义返回结果
List<LayuiOrganizationTreeNode> treeNodeList = CollectionUtil.newArrayList();
// 组装节点
List<HrOrganization> hrOrganizationList = this.findListByDataScope(hrOrganizationRequest);
for (HrOrganization hrOrganization : hrOrganizationList) {
LayuiOrganizationTreeNode treeNode = LayuiOrganizationFactory.parseOrganizationTreeNode(hrOrganization);
treeNodeList.add(treeNode);
}
// 构建树并返回
return new DefaultTreeBuildFactory<LayuiOrganizationTreeNode>().doTreeBuild(treeNodeList);
}
@Override
public List<ZTreeNode> orgZTree(HrOrganizationRequest hrOrganizationRequest, boolean buildTree) {
// 获取角色id
Long roleId = hrOrganizationRequest.getRoleId();
// 获取所有组织机构列表
LambdaQueryWrapper<HrOrganization> wrapper = createWrapper(hrOrganizationRequest);
List<HrOrganization> list = this.list(wrapper);
List<ZTreeNode> zTreeNodes = LayuiOrganizationFactory.parseZTree(list);
// 获取角色目前绑定的组织机构范围
List<Long> roleDataScopes = roleServiceApi.getRoleDataScopes(ListUtil.toList(roleId));
// 设置绑定的组织机构范围为已选则状态
for (ZTreeNode zTreeNode : zTreeNodes) {
if (roleDataScopes.contains(zTreeNode.getId())) {
zTreeNode.setChecked(true);
}
}
if (buildTree) {
return new DefaultTreeBuildFactory<ZTreeNode>().doTreeBuild(zTreeNodes);
} else {
return zTreeNodes;
}
}
@Override
public Set<Long> findAllLevelParentIdsByOrganizations(Set<Long> organizationIds) {
// 定义返回结果
Set<Long> allLevelParentIds = new HashSet<>(organizationIds);
// 查询出这些节点的pids字段
LambdaQueryWrapper<HrOrganization> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.in(HrOrganization::getOrgId, organizationIds);
queryWrapper.select(HrOrganization::getOrgPids);
List<HrOrganization> organizationList = this.list(queryWrapper);
if (organizationList == null || organizationList.isEmpty()) {
return allLevelParentIds;
}
// 把所有的pids分割并放入到set中
for (HrOrganization hrOrganization : organizationList) {
// 获取pids值
String pids = hrOrganization.getOrgPids();
// 去掉所有的左中括号
pids = StrUtil.removeAll(pids, SymbolConstant.LEFT_SQUARE_BRACKETS);
// 去掉所有的右中括号
pids = StrUtil.removeAll(pids, SymbolConstant.RIGHT_SQUARE_BRACKETS);
// 按逗号分割这个字符串得到pid的数组
String[] finalPidArray = pids.split(StrUtil.COMMA);
// 遍历这些值放入到最终的set
for (String pid : finalPidArray) {
allLevelParentIds.add(Convert.toLong(pid));
}
}
return allLevelParentIds;
}
@Override
public List<HrOrganizationDTO> orgList() {
LambdaQueryWrapper<HrOrganization> queryWrapper = new LambdaQueryWrapper<>();
@ -200,20 +299,109 @@ public class HrOrganizationServiceImpl extends ServiceImpl<HrOrganizationMapper,
// 根据排序升序排列,序号越小越在前
queryWrapper.orderByAsc(HrOrganization::getOrgSort);
// 先实例化出Function接口
Function<Object, HrOrganizationResponse> mapper = e -> {
HrOrganizationResponse org = new HrOrganizationResponse();
Function<Object, HrOrganizationDTO> mapper = e -> {
HrOrganizationDTO org = new HrOrganizationDTO();
HrOrganization hrOrg = (HrOrganization) e;
BeanUtil.copyProperties(hrOrg, org);
return org;
};
// 返回数据
List<HrOrganization> list = this.list(queryWrapper);
List<HrOrganizationResponse> resultList = list.stream().filter(Objects::nonNull).map(mapper).collect(Collectors.toList());
return resultList;
return list.stream().filter(Objects::nonNull).map(mapper).collect(Collectors.toList());
}
/**
* wrapper
*
* @author fengshuonan
* @date 2020/11/6 10:16
*/
private LambdaQueryWrapper<HrOrganization> createWrapper(HrOrganizationRequest hrOrganizationRequest) {
LambdaQueryWrapper<HrOrganization> queryWrapper = new LambdaQueryWrapper<>();
// 查询未删除状态的
queryWrapper.eq(HrOrganization::getDelFlag, YesOrNotEnum.N.getCode());
// 根据排序升序排列,序号越小越在前
queryWrapper.orderByAsc(HrOrganization::getOrgSort);
if (ObjectUtil.isEmpty(hrOrganizationRequest)) {
return queryWrapper;
}
String orgName = hrOrganizationRequest.getOrgName();
String orgCode = hrOrganizationRequest.getOrgCode();
Long orgParentId = hrOrganizationRequest.getOrgParentId();
Long orgId = hrOrganizationRequest.getOrgId();
// 拼接组织机构名称条件
queryWrapper.like(ObjectUtil.isNotEmpty(orgName), HrOrganization::getOrgName, orgName);
// 拼接组织机构编码条件
queryWrapper.eq(ObjectUtil.isNotEmpty(orgCode), HrOrganization::getOrgCode, orgCode);
// 拼接父机构id查询条件
if (ObjectUtil.isNotEmpty(orgParentId)) {
queryWrapper.and(qw -> {
qw.eq(HrOrganization::getOrgId, orgParentId).or().like(HrOrganization::getOrgPids, orgParentId);
});
}
// 拼接机构id查询条件
queryWrapper.eq(ObjectUtil.isNotEmpty(orgId), HrOrganization::getOrgId, orgId);
return queryWrapper;
}
/**
*
*
* @author fengshuonan
* @date 2020/11/04 11:05
*/
private HrOrganization queryOrganization(HrOrganizationRequest hrOrganizationRequest) {
HrOrganization hrOrganization = this.getById(hrOrganizationRequest.getOrgId());
if (ObjectUtil.isEmpty(hrOrganization)) {
throw new SystemModularException(OrganizationExceptionEnum.CANT_FIND_ORG, hrOrganizationRequest.getOrgId());
}
return hrOrganization;
}
/**
* pIds
* <p>
* pidpids [-1],
* <p>
* pidpidspids + [pid] + ,
*
* @author fengshuonan
* @date 2020/11/5 13:45
*/
private void fillParentIds(HrOrganization hrOrganization) {
if (TreeConstants.DEFAULT_PARENT_ID.equals(hrOrganization.getOrgParentId())) {
hrOrganization.setOrgPids(SymbolConstant.LEFT_SQUARE_BRACKETS + TreeConstants.DEFAULT_PARENT_ID + SymbolConstant.RIGHT_SQUARE_BRACKETS + SymbolConstant.COMMA);
} else {
// 获取父组织机构
HrOrganizationRequest hrOrganizationRequest = new HrOrganizationRequest();
hrOrganizationRequest.setOrgId(hrOrganization.getOrgId());
HrOrganization parentOrganization = this.queryOrganization(hrOrganizationRequest);
// 设置本节点的父ids为 (上一个节点的pids + (上级节点的id) )
hrOrganization.setOrgPids(
parentOrganization.getOrgPids() + SymbolConstant.LEFT_SQUARE_BRACKETS + parentOrganization.getOrgId() + SymbolConstant.RIGHT_SQUARE_BRACKETS + SymbolConstant.COMMA);
}
}
/**
*
*
* @author fengshuonan
* @date 2021/2/8 20:22
*/
private List<HrOrganization> findListByDataScope(HrOrganizationRequest hrOrganizationRequest) {
LambdaQueryWrapper<HrOrganization> queryWrapper = this.createWrapper(hrOrganizationRequest);
@ -238,169 +426,7 @@ public class HrOrganizationServiceImpl extends ServiceImpl<HrOrganizationMapper,
queryWrapper.in(HrOrganization::getOrgId, allLevelParentIdsByOrganizations);
}
return this.list(queryWrapper);
}
@Override
public List<DefaultTreeNode> tree(HrOrganizationRequest hrOrganizationRequest) {
// 定义返回结果
List<DefaultTreeNode> treeNodeList = CollectionUtil.newArrayList();
List<HrOrganization> list = this.findListByDataScope(hrOrganizationRequest);
// 组装节点
for (HrOrganization hrOrganization : list) {
DefaultTreeNode orgTreeNode = new DefaultTreeNode();
orgTreeNode.setId(String.valueOf(hrOrganization.getOrgId()));
orgTreeNode.setPId(String.valueOf(hrOrganization.getOrgParentId()));
orgTreeNode.setName(hrOrganization.getOrgName());
orgTreeNode.setSort(hrOrganization.getOrgSort());
treeNodeList.add(orgTreeNode);
}
// 构建树并返回
return new DefaultTreeBuildFactory<DefaultTreeNode>().doTreeBuild(treeNodeList);
}
@Override
public List<LayuiOrganizationTreeNode> treeLayui(HrOrganizationRequest hrOrganizationRequest) {
// 定义返回结果
List<LayuiOrganizationTreeNode> treeNodeList = CollectionUtil.newArrayList();
List<HrOrganization> hrOrganizationList = this.findListByDataScope(hrOrganizationRequest);
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) {
// 定义返回结果
Set<Long> allLevelParentIds = new HashSet<>(organizationIds);
// 查询出这些节点的pids字段
LambdaQueryWrapper<HrOrganization> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.in(HrOrganization::getOrgId, organizationIds);
queryWrapper.select(HrOrganization::getOrgPids);
List<HrOrganization> organizationList = this.list(queryWrapper);
if (organizationList == null || organizationList.isEmpty()) {
return allLevelParentIds;
}
// 把所有的pids分割并放入到set中
for (HrOrganization hrOrganization : organizationList) {
// 获取pids值
String pids = hrOrganization.getOrgPids();
// 去掉所有的左中括号
pids = StrUtil.removeAll(pids, SymbolConstant.LEFT_SQUARE_BRACKETS);
// 去掉所有的右中括号
pids = StrUtil.removeAll(pids, SymbolConstant.RIGHT_SQUARE_BRACKETS);
// 按逗号分割这个字符串得到pid的数组
String[] finalPidArray = pids.split(StrUtil.COMMA);
// 遍历这些值放入到最终的set
for (String pid : finalPidArray) {
allLevelParentIds.add(Convert.toLong(pid));
}
}
return allLevelParentIds;
}
@Override
public List<ZTreeNode> orgZTree(HrOrganizationRequest hrOrganizationRequest, boolean buildTree) {
// 获取角色id
Long roleId = hrOrganizationRequest.getRoleId();
// 获取所有组织机构列表
LambdaQueryWrapper<HrOrganization> wrapper = createWrapper(hrOrganizationRequest);
List<HrOrganization> list = this.list(wrapper);
List<ZTreeNode> zTreeNodes = OrganizationFactory.parseZTree(list);
// 获取角色目前绑定的组织机构范围
List<Long> roleDataScopes = roleServiceApi.getRoleDataScopes(ListUtil.toList(roleId));
// 设置绑定的组织机构范围为已选则状态
for (ZTreeNode zTreeNode : zTreeNodes) {
if (roleDataScopes.contains(zTreeNode.getId())) {
zTreeNode.setChecked(true);
}
}
if (buildTree) {
return new DefaultTreeBuildFactory<ZTreeNode>().doTreeBuild(zTreeNodes);
} else {
return zTreeNodes;
}
}
/**
* wrapper
*
* @author fengshuonan
* @date 2020/11/6 10:16
*/
private LambdaQueryWrapper<HrOrganization> createWrapper(HrOrganizationRequest hrOrganizationRequest) {
LambdaQueryWrapper<HrOrganization> queryWrapper = new LambdaQueryWrapper<>();
String orgName = hrOrganizationRequest.getOrgName();
String orgCode = hrOrganizationRequest.getOrgCode();
Long orgParentId = hrOrganizationRequest.getOrgParentId();
Long orgId = hrOrganizationRequest.getOrgId();
queryWrapper.like(ObjectUtil.isNotEmpty(orgName), HrOrganization::getOrgName, orgName);
queryWrapper.eq(ObjectUtil.isNotEmpty(orgCode), HrOrganization::getOrgCode, orgCode);
// 拼接机构id查询条件
queryWrapper.eq(ObjectUtil.isNotEmpty(orgId), HrOrganization::getOrgId, orgId);
// 拼接父机构id查询条件
if (ObjectUtil.isNotEmpty(orgParentId)) {
queryWrapper.and(qw -> {
qw.eq(HrOrganization::getOrgId, orgParentId).or().like(HrOrganization::getOrgPids, orgParentId);
});
}
// 查询未删除状态的
queryWrapper.eq(HrOrganization::getDelFlag, YesOrNotEnum.N.getCode());
// 根据排序升序排列,序号越小越在前
queryWrapper.orderByAsc(HrOrganization::getOrgSort);
return queryWrapper;
}
/**
*
*
* @author fengshuonan
* @date 2020/11/04 11:05
*/
private HrOrganization queryOrganization(HrOrganizationRequest hrOrganizationRequest) {
HrOrganization hrOrganization = this.getById(hrOrganizationRequest.getOrgId());
if (ObjectUtil.isEmpty(hrOrganization)) {
throw new SystemModularException(OrganizationExceptionEnum.CANT_FIND_ORG, hrOrganizationRequest.getOrgId());
}
return hrOrganization;
}
/**
* pIds
*
* @author fengshuonan
* @date 2020/11/5 13:45
*/
private void fillParentIds(HrOrganization hrOrganization) {
// 如果是一级节点一级节点的pid是0
if (hrOrganization.getOrgParentId().equals(TreeConstants.DEFAULT_PARENT_ID)) {
// 设置一级节点的pid为[0],
hrOrganization.setOrgPids(SymbolConstant.LEFT_SQUARE_BRACKETS + TreeConstants.DEFAULT_PARENT_ID + SymbolConstant.RIGHT_SQUARE_BRACKETS + SymbolConstant.COMMA);
} else {
// 获取父组织机构
HrOrganization parentOrganization = this.getById(hrOrganization.getOrgParentId());
// 设置本节点的父ids为 (上一个节点的pids + (上级节点的id) )
hrOrganization.setOrgPids(
parentOrganization.getOrgPids() + SymbolConstant.LEFT_SQUARE_BRACKETS + parentOrganization.getOrgId() + SymbolConstant.RIGHT_SQUARE_BRACKETS + SymbolConstant.COMMA);
}
}
}

View File

@ -14,7 +14,7 @@ import cn.stylefeng.roses.kernel.system.exception.enums.PositionExceptionEnum;
import cn.stylefeng.roses.kernel.system.modular.organization.entity.HrPosition;
import cn.stylefeng.roses.kernel.system.modular.organization.mapper.HrPositionMapper;
import cn.stylefeng.roses.kernel.system.modular.organization.service.HrPositionService;
import cn.stylefeng.roses.kernel.system.pojo.HrPositionRequest;
import cn.stylefeng.roses.kernel.system.pojo.organization.HrPositionRequest;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
@ -46,13 +46,6 @@ public class HrPositionServiceImpl extends ServiceImpl<HrPositionMapper, HrPosit
this.save(sysPosition);
}
@Override
public void edit(HrPositionRequest hrPositionRequest) {
HrPosition sysPosition = this.querySysPositionById(hrPositionRequest);
BeanUtil.copyProperties(hrPositionRequest, sysPosition);
this.updateById(sysPosition);
}
@Override
public void del(HrPositionRequest hrPositionRequest) {
HrPosition sysPosition = this.querySysPositionById(hrPositionRequest);
@ -68,6 +61,13 @@ public class HrPositionServiceImpl extends ServiceImpl<HrPositionMapper, HrPosit
this.updateById(sysPosition);
}
@Override
public void edit(HrPositionRequest hrPositionRequest) {
HrPosition sysPosition = this.querySysPositionById(hrPositionRequest);
BeanUtil.copyProperties(hrPositionRequest, sysPosition);
this.updateById(sysPosition);
}
@Override
public void updateStatus(HrPositionRequest hrPositionRequest) {
HrPosition sysPosition = this.querySysPositionById(hrPositionRequest);
@ -113,13 +113,22 @@ public class HrPositionServiceImpl extends ServiceImpl<HrPositionMapper, HrPosit
/**
* QueryWrapper
*
* @return
* @author chenjinlong
* @date 2021/2/2 10:17
*/
private LambdaQueryWrapper<HrPosition> createWrapper(HrPositionRequest hrPositionRequest) {
LambdaQueryWrapper<HrPosition> queryWrapper = new LambdaQueryWrapper<>();
// 查询未删除状态的
queryWrapper.eq(HrPosition::getDelFlag, YesOrNotEnum.N.getCode());
// 根据排序升序排列,序号越小越在前
queryWrapper.orderByAsc(HrPosition::getPositionSort);
if (ObjectUtil.isEmpty(hrPositionRequest)) {
return queryWrapper;
}
Long positionId = hrPositionRequest.getPositionId();
String positionName = hrPositionRequest.getPositionName();
String positionCode = hrPositionRequest.getPositionCode();
@ -129,13 +138,7 @@ public class HrPositionServiceImpl extends ServiceImpl<HrPositionMapper, HrPosit
queryWrapper.like(StrUtil.isNotEmpty(positionName), HrPosition::getPositionName, positionName);
queryWrapper.eq(StrUtil.isNotEmpty(positionCode), HrPosition::getPositionCode, positionCode);
// 查询未删除状态的
queryWrapper.eq(HrPosition::getDelFlag, YesOrNotEnum.N.getCode());
// 根据排序升序排列,序号越小越在前
queryWrapper.orderByAsc(HrPosition::getPositionSort);
return queryWrapper;
}
}

View File

@ -8,7 +8,7 @@ import cn.stylefeng.roses.kernel.auth.api.pojo.login.basic.SimpleUserInfo;
import cn.stylefeng.roses.kernel.auth.api.prop.LoginUserPropExpander;
import cn.stylefeng.roses.kernel.rule.enums.YesOrNotEnum;
import cn.stylefeng.roses.kernel.system.modular.user.entity.SysUser;
import cn.stylefeng.roses.kernel.system.pojo.organization.DataScopeResponse;
import cn.stylefeng.roses.kernel.system.pojo.organization.DataScopeDTO;
import cn.stylefeng.roses.kernel.system.pojo.role.response.SysRoleResponse;
import cn.stylefeng.roses.kernel.system.pojo.user.SysUserOrgResponse;
import cn.stylefeng.roses.kernel.system.pojo.user.UserLoginInfoDTO;
@ -37,7 +37,7 @@ public class UserLoginInfoFactory {
*/
public static UserLoginInfoDTO userLoginInfoDTO(SysUser sysUser,
List<SysRoleResponse> roleResponseList,
DataScopeResponse dataScopeResponse,
DataScopeDTO dataScopeResponse,
SysUserOrgResponse userOrgInfo,
Set<String> resourceUrlsListByCodes,
Set<String> roleButtonCodes) {

View File

@ -15,7 +15,6 @@ import java.util.List;
*/
public interface SysUserDataScopeService extends IService<SysUserDataScope> {
/**
*
*

View File

@ -39,8 +39,8 @@ import cn.stylefeng.roses.kernel.system.modular.user.service.SysUserDataScopeSer
import cn.stylefeng.roses.kernel.system.modular.user.service.SysUserOrgService;
import cn.stylefeng.roses.kernel.system.modular.user.service.SysUserRoleService;
import cn.stylefeng.roses.kernel.system.modular.user.service.SysUserService;
import cn.stylefeng.roses.kernel.system.pojo.organization.DataScopeResponse;
import cn.stylefeng.roses.kernel.system.pojo.organization.HrOrganizationResponse;
import cn.stylefeng.roses.kernel.system.pojo.organization.DataScopeDTO;
import cn.stylefeng.roses.kernel.system.pojo.organization.HrOrganizationDTO;
import cn.stylefeng.roses.kernel.system.pojo.role.response.SysRoleResponse;
import cn.stylefeng.roses.kernel.system.pojo.user.*;
import cn.stylefeng.roses.kernel.system.pojo.user.request.OnlineUserRequest;
@ -430,7 +430,7 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
List<SysRoleResponse> roleResponseList = roleServiceApi.getRolesByIds(roleIds);
// 3. 获取用户的数据范围
DataScopeResponse dataScopeResponse = dataScopeApi.getDataScope(userId, roleResponseList);
DataScopeDTO dataScopeResponse = dataScopeApi.getDataScope(userId, roleResponseList);
// 4. 获取用户的组织机构和职位信息
SysUserOrgResponse userOrgInfo = sysUserOrgService.getUserOrgInfo(userId);
@ -594,9 +594,9 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
public List<UserSelectTreeNode> userSelectTree(SysUserRequest sysUserRequest) {
// 定义返回结果
List<UserSelectTreeNode> treeNodeList = CollectionUtil.newArrayList();
List<HrOrganizationResponse> orgList = organizationServiceApi.orgList();
List<HrOrganizationDTO> orgList = organizationServiceApi.orgList();
UserSelectTreeNode orgTreeNode;
for (HrOrganizationResponse hrOrganization : orgList) {
for (HrOrganizationDTO hrOrganization : orgList) {
orgTreeNode = new UserSelectTreeNode();
orgTreeNode.setId(String.valueOf(hrOrganization.getOrgId()));
orgTreeNode.setPId(String.valueOf(hrOrganization.getOrgParentId()));