use of com.hccake.ballcat.common.i18n.I18nMessageCreateEvent 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;
}
Aggregations