use of com.hccake.ballcat.system.model.entity.SysOrganization in project ballcat by ballcat-projects.
the class SysOrganizationServiceImpl method update.
/**
* 更新一个已有的组织机构
* @param sysOrganizationDTO 组织机构DTO
* @return boolean 更新成功/失败
*/
@Override
@Transactional(rollbackFor = Exception.class)
public boolean update(SysOrganizationDTO sysOrganizationDTO) {
// TODO 防止并发问题
SysOrganization newSysOrganization = SysOrganizationConverter.INSTANCE.dtoToPo(sysOrganizationDTO);
Integer organizationId = newSysOrganization.getId();
SysOrganization originSysOrganization = baseMapper.selectById(organizationId);
// 如果没有移动父节点,则直接更新
Integer targetParentId = sysOrganizationDTO.getParentId();
if (originSysOrganization.getParentId().equals(targetParentId)) {
return SqlHelper.retBool(baseMapper.updateById(newSysOrganization));
}
// 移动了父节点,先判断不是选择自己作为父节点
Assert.isFalse(targetParentId.equals(organizationId), "父节点不能是自己!");
// 再判断是否是自己的子节点,根节点跳过判断
if (!GlobalConstants.TREE_ROOT_ID.equals(targetParentId)) {
SysOrganization targetParentOrganization = baseMapper.selectById(targetParentId);
String[] targetParentHierarchy = targetParentOrganization.getHierarchy().split("-");
if (ArrayUtil.contains(targetParentHierarchy, String.valueOf(organizationId))) {
throw new BusinessException(BaseResultCode.LOGIC_CHECK_ERROR.getCode(), "父节点不能是自己的子节点!");
}
}
// 填充目标层级和深度
fillDepthAndHierarchy(newSysOrganization, targetParentId);
// 更新其子节点的数据
OrganizationMoveChildParam param = getOrganizationMoveChildParam(newSysOrganization, originSysOrganization);
baseMapper.followMoveChildNode(param);
// 更新组织节点信息
return SqlHelper.retBool(baseMapper.updateById(newSysOrganization));
}
use of com.hccake.ballcat.system.model.entity.SysOrganization in project ballcat by ballcat-projects.
the class SysOrganizationServiceImpl method fillDepthAndHierarchy.
/**
* 根据父级ID填充当前组织机构实体的深度和层级
* @param sysOrganization 组织机构实体
* @param parentId 父级ID
*/
private void fillDepthAndHierarchy(SysOrganization sysOrganization, Integer parentId) {
if (GlobalConstants.TREE_ROOT_ID.equals(parentId)) {
sysOrganization.setDepth(1);
sysOrganization.setHierarchy(GlobalConstants.TREE_ROOT_ID.toString());
} else {
SysOrganization parentSysOrganization = baseMapper.selectById(parentId);
Assert.notNull(parentSysOrganization, "不存在的父级组织机构!");
sysOrganization.setDepth(parentSysOrganization.getDepth() + 1);
sysOrganization.setHierarchy(parentSysOrganization.getHierarchy() + "-" + parentSysOrganization.getId());
}
}
use of com.hccake.ballcat.system.model.entity.SysOrganization in project ballcat by ballcat-projects.
the class SysOrganizationServiceImpl method updateChildHierarchyAndPath.
private void updateChildHierarchyAndPath(Map<Integer, List<SysOrganization>> map, Integer parentId, int depth, String hierarchy) {
// 获取对应 parentId 下的所有子节点
List<SysOrganization> sysOrganizations = map.get(parentId);
if (CollectionUtil.isEmpty(sysOrganizations)) {
return;
}
// 递归更新子节点数据
List<Integer> childrenIds = new ArrayList<>();
for (SysOrganization sysOrganization : sysOrganizations) {
Integer organizationId = sysOrganization.getId();
updateChildHierarchyAndPath(map, organizationId, depth + 1, hierarchy + "-" + organizationId);
childrenIds.add(organizationId);
}
baseMapper.updateHierarchyAndPathBatch(depth, hierarchy, childrenIds);
}
use of com.hccake.ballcat.system.model.entity.SysOrganization in project ballcat by ballcat-projects.
the class SysOrganizationServiceImpl method create.
/**
* 创建一个新的组织机构
* @param sysOrganizationDTO 组织机构DTO
* @return boolean 创建成功/失败
*/
@Override
public boolean create(SysOrganizationDTO sysOrganizationDTO) {
sysOrganizationDTO.setId(null);
SysOrganization sysOrganization = SysOrganizationConverter.INSTANCE.dtoToPo(sysOrganizationDTO);
// 如果父级为根节点则直接设置深度和层级,否则根据父节点数据动态设置
Integer parentId = sysOrganizationDTO.getParentId();
// 填充层级和深度
fillDepthAndHierarchy(sysOrganization, parentId);
return SqlHelper.retBool(baseMapper.insert(sysOrganization));
}
Aggregations