use of com.hccake.ballcat.codegen.model.entity.TemplateEntry in project ballcat-codegen by ballcat-projects.
the class TemplateEntryServiceImpl method removeEntry.
/**
* 删除目录项
* @param entryId 目录项id
* @param mode 删除模式
* @return boolean 成功:true
*/
@Override
@Transactional(rollbackFor = Exception.class)
public boolean removeEntry(Integer entryId, Integer mode) {
TemplateEntry entry = baseMapper.selectById(entryId);
Integer groupId = entry.getGroupId();
Assert.notNull(entry, "This is a nonexistent directory entry!");
// 如果是文件夹类型,则根据删除模式进行子节点删除或上移操作
if (TemplateEntryTypeEnum.FOLDER.getType().equals(entry.getType())) {
if (TemplateEntryRemoveModeEnum.RESERVED_CHILD_NODE.getType().equals(mode)) {
// 子节点上移
baseMapper.updateParentId(groupId, entryId, entry.getParentId());
} else if (TemplateEntryRemoveModeEnum.REMOVE_CHILD_NODE.getType().equals(mode)) {
// ==========删除所有子节点=============
// 1. 获取所有目录项(目录项不会太多,一次查询比较方便)
List<TemplateEntry> entryList = baseMapper.listByTemplateGroupId(groupId);
// 2. 获取当前删除目录项的孩子节点列表
List<TemplateEntryTree> treeList = TreeUtils.buildTree(entryList, entryId, TemplateModelConverter.INSTANCE::entryPoToTree);
// 3. 获取当前删除目录项的孩子节点Id
List<Integer> treeNodeIds = TreeUtils.getTreeNodeIds(treeList);
// 4. 删除所有孩子节点
if (CollectionUtil.isNotEmpty(treeNodeIds)) {
baseMapper.deleteBatchIds(treeNodeIds);
}
} else {
throw new BusinessException(BaseResultCode.LOGIC_CHECK_ERROR.getCode(), "error delete mode");
}
}
// 删除自身
return SqlHelper.retBool(baseMapper.deleteById(entryId));
}
Aggregations