use of com.hccake.ballcat.common.core.exception.BusinessException in project ballcat by ballcat-projects.
the class SysMenuServiceImpl method create.
@Override
@Transactional(rollbackFor = Exception.class)
public boolean create(SysMenuCreateDTO sysMenuCreateDTO) {
SysMenu sysMenu = SysMenuConverter.INSTANCE.createDtoToPo(sysMenuCreateDTO);
Integer menuId = sysMenu.getId();
SysMenu existingMenu = baseMapper.selectById(menuId);
if (existingMenu != null) {
String errorMessage = String.format("ID [%s] 已被菜单 [%s] 使用,请更换其他菜单ID", menuId, existingMenu.getTitle());
throw new BusinessException(BaseResultCode.LOGIC_CHECK_ERROR.getCode(), errorMessage);
}
boolean saveSuccess = SqlHelper.retBool(baseMapper.insert(sysMenu));
Assert.isTrue(saveSuccess, () -> {
log.error("[create] 创建菜单失败,sysMenuCreateDTO: {}", sysMenuCreateDTO);
return new BusinessException(BaseResultCode.UPDATE_DATABASE_ERROR.getCode(), "创建菜单失败");
});
// 多语言保存事件发布
List<I18nMessage> i18nMessages = sysMenuCreateDTO.getI18nMessages();
if (CollectionUtil.isNotEmpty(i18nMessages)) {
eventPublisher.publishEvent(new I18nMessageCreateEvent(i18nMessages));
}
return saveSuccess;
}
use of com.hccake.ballcat.common.core.exception.BusinessException 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));
}
use of com.hccake.ballcat.common.core.exception.BusinessException in project ballcat by ballcat-projects.
the class AnnouncementServiceImpl method uploadImages.
/**
* 批量上传公告图片
* @param files 图片文件
* @return 上传后的图片相对路径集合
*/
@Override
public List<String> uploadImages(List<MultipartFile> files) {
List<String> objectNames = new ArrayList<>();
for (MultipartFile file : files) {
String objectName = "announcement/" + LocalDate.now().format(DateTimeFormatter.BASIC_ISO_DATE) + StrUtil.SLASH + IdUtil.fastSimpleUUID() + StrUtil.DOT + FileUtil.extName(file.getOriginalFilename());
try {
objectName = fileService.upload(file.getInputStream(), objectName, file.getSize());
objectNames.add(objectName);
} catch (IOException e) {
// TODO 删除无效文件
throw new BusinessException(BaseResultCode.FILE_UPLOAD_ERROR.getCode(), "图片上传失败!", e);
}
}
return objectNames;
}
use of com.hccake.ballcat.common.core.exception.BusinessException in project ballcat by ballcat-projects.
the class SysMenuServiceImpl method save.
/**
* 插入一条记录(选择字段,策略插入)
* @param sysMenu 实体对象
*/
@Override
public boolean save(SysMenu sysMenu) {
Integer menuId = sysMenu.getId();
SysMenu existingMenu = baseMapper.selectById(menuId);
if (existingMenu != null) {
String errorMessage = String.format("ID [%s] 已被菜单 [%s] 使用,请更换其他菜单ID", menuId, existingMenu.getTitle());
throw new BusinessException(BaseResultCode.LOGIC_CHECK_ERROR.getCode(), errorMessage);
}
return SqlHelper.retBool(baseMapper.insert(sysMenu));
}
use of com.hccake.ballcat.common.core.exception.BusinessException in project ballcat by ballcat-projects.
the class SysMenuServiceImpl method update.
@Override
@Transactional(rollbackFor = Exception.class)
public void update(SysMenuUpdateDTO sysMenuUpdateDTO) {
// 原来的菜单 Id
Integer originalId = sysMenuUpdateDTO.getOriginalId();
SysMenu sysMenu = SysMenuConverter.INSTANCE.updateDtoToPo(sysMenuUpdateDTO);
// 更新菜单信息
boolean updateSuccess = baseMapper.updateMenuAndId(originalId, sysMenu);
Assert.isTrue(updateSuccess, () -> {
log.error("[update] 更新菜单权限时,sql 执行异常,originalId:{},sysMenu:{}", originalId, sysMenu);
return new BusinessException(BaseResultCode.UPDATE_DATABASE_ERROR.getCode(), "更新菜单权限时,sql 执行异常");
});
// 如果未修改过 菜单id 直接返回
Integer menuId = sysMenuUpdateDTO.getId();
if (originalId.equals(menuId)) {
return;
}
// 修改过菜单id,则需要对应修改角色菜单的关联表信息,这里不需要 check,因为可能没有授权过该菜单,所以返回值为 0
sysRoleMenuService.updateMenuId(originalId, menuId);
// 更新子菜单的 parentId
baseMapper.updateParentId(originalId, menuId);
}
Aggregations