use of com.hccake.ballcat.system.model.dto.OrganizationMoveChildParam 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.dto.OrganizationMoveChildParam in project ballcat by ballcat-projects.
the class SysOrganizationServiceImpl method getOrganizationMoveChildParam.
private OrganizationMoveChildParam getOrganizationMoveChildParam(SysOrganization newSysOrganization, SysOrganization originSysOrganization) {
// 父组织 id
Integer parentId = newSysOrganization.getId();
// 父节点原来的层级
String originParentHierarchy = originSysOrganization.getHierarchy();
// 修改后的父节点层级
String targetParentHierarchy = newSysOrganization.getHierarchy();
// 父节点移动后的深度差
int depthDiff = originSysOrganization.getDepth() - newSysOrganization.getDepth();
OrganizationMoveChildParam param = new OrganizationMoveChildParam();
param.setParentId(parentId);
param.setOriginParentHierarchy(originParentHierarchy);
param.setOriginParentHierarchyLengthPlusOne(originParentHierarchy.length() + 1);
param.setTargetParentHierarchy(targetParentHierarchy);
param.setDepthDiff(depthDiff);
param.setGrandsonConditionalStatement(originParentHierarchy + "-" + parentId + "-%");
return param;
}
Aggregations