【7.1.1】【menu】更新菜单按钮的默认添加策略

pull/22/head
fengshuonan 2021-08-10 18:00:04 +08:00
parent 3b029cde30
commit 730d831596
2 changed files with 33 additions and 12 deletions

View File

@ -25,11 +25,13 @@
package cn.stylefeng.roses.kernel.system.modular.menu.factory;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.StrUtil;
import cn.stylefeng.roses.kernel.rule.enums.YesOrNotEnum;
import cn.stylefeng.roses.kernel.system.modular.menu.constants.MenuButtonConstant;
import cn.stylefeng.roses.kernel.system.modular.menu.entity.SysMenuButton;
import java.util.List;
import java.util.Locale;
/**
*
@ -47,40 +49,49 @@ public class MenuButtonFactory {
* @author chenjinlong
* @date 2021/1/27 15:36
*/
public static List<SysMenuButton> createSystemDefaultButton(Long menuId) {
public static List<SysMenuButton> createSystemDefaultButton(Long menuId, String menuName, String menuCode) {
List<SysMenuButton> sysMenuButtonList = CollUtil.newArrayList();
// 菜单编码加下划线
if (StrUtil.isNotBlank(menuCode)) {
menuCode = menuCode.toUpperCase(Locale.ROOT) + "_";
}
// 菜单名称添加下划线
if (StrUtil.isNotBlank(menuName)) {
menuName = menuName + "_";
}
// 新增按钮
SysMenuButton addButton = new SysMenuButton();
addButton.setMenuId(menuId);
addButton.setButtonCode(MenuButtonConstant.DEFAULT_ADD_BUTTON_CODE);
addButton.setButtonName(MenuButtonConstant.DEFAULT_ADD_BUTTON_NAME);
addButton.setButtonCode(menuCode + MenuButtonConstant.DEFAULT_ADD_BUTTON_CODE);
addButton.setButtonName(menuName + MenuButtonConstant.DEFAULT_ADD_BUTTON_NAME);
addButton.setDelFlag(YesOrNotEnum.N.getCode());
sysMenuButtonList.add(addButton);
// 删除按钮
SysMenuButton delButton = new SysMenuButton();
delButton.setMenuId(menuId);
delButton.setButtonCode(MenuButtonConstant.DEFAULT_DEL_BUTTON_CODE);
delButton.setButtonName(MenuButtonConstant.DEFAULT_DEL_BUTTON_NAME);
delButton.setButtonCode(menuCode + MenuButtonConstant.DEFAULT_DEL_BUTTON_CODE);
delButton.setButtonName(menuName + MenuButtonConstant.DEFAULT_DEL_BUTTON_NAME);
delButton.setDelFlag(YesOrNotEnum.N.getCode());
sysMenuButtonList.add(delButton);
// 修改按钮
SysMenuButton updateButton = new SysMenuButton();
updateButton.setMenuId(menuId);
updateButton.setButtonCode(MenuButtonConstant.DEFAULT_UPDATE_BUTTON_CODE);
updateButton.setButtonName(MenuButtonConstant.DEFAULT_UPDATE_BUTTON_NAME);
updateButton.setButtonCode(menuCode + MenuButtonConstant.DEFAULT_UPDATE_BUTTON_CODE);
updateButton.setButtonName(menuName + MenuButtonConstant.DEFAULT_UPDATE_BUTTON_NAME);
updateButton.setDelFlag(YesOrNotEnum.N.getCode());
sysMenuButtonList.add(updateButton);
// 查询按钮
SysMenuButton searchButton = new SysMenuButton();
searchButton.setMenuId(menuId);
searchButton.setButtonCode(MenuButtonConstant.DEFAULT_SEARCH_BUTTON_CODE);
searchButton.setButtonName(MenuButtonConstant.DEFAULT_SEARCH_BUTTON_NAME);
searchButton.setButtonCode(menuCode + MenuButtonConstant.DEFAULT_SEARCH_BUTTON_CODE);
searchButton.setButtonName(menuName + MenuButtonConstant.DEFAULT_SEARCH_BUTTON_NAME);
searchButton.setDelFlag(YesOrNotEnum.N.getCode());
sysMenuButtonList.add(searchButton);

View File

@ -33,16 +33,19 @@ import cn.stylefeng.roses.kernel.db.api.pojo.page.PageResult;
import cn.stylefeng.roses.kernel.rule.enums.YesOrNotEnum;
import cn.stylefeng.roses.kernel.system.api.exception.SystemModularException;
import cn.stylefeng.roses.kernel.system.api.exception.enums.menu.SysMenuButtonExceptionEnum;
import cn.stylefeng.roses.kernel.system.api.pojo.menu.SysMenuButtonRequest;
import cn.stylefeng.roses.kernel.system.modular.menu.entity.SysMenu;
import cn.stylefeng.roses.kernel.system.modular.menu.entity.SysMenuButton;
import cn.stylefeng.roses.kernel.system.modular.menu.factory.MenuButtonFactory;
import cn.stylefeng.roses.kernel.system.modular.menu.mapper.SysMenuButtonMapper;
import cn.stylefeng.roses.kernel.system.modular.menu.service.SysMenuButtonService;
import cn.stylefeng.roses.kernel.system.api.pojo.menu.SysMenuButtonRequest;
import cn.stylefeng.roses.kernel.system.modular.menu.service.SysMenuService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.List;
import java.util.Set;
@ -55,6 +58,9 @@ import java.util.Set;
@Service
public class SysMenuButtonServiceImpl extends ServiceImpl<SysMenuButtonMapper, SysMenuButton> implements SysMenuButtonService {
@Resource
private SysMenuService sysMenuService;
@Override
public void add(SysMenuButtonRequest sysMenuButtonRequest) {
SysMenuButton sysMenuButton = new SysMenuButton();
@ -65,8 +71,12 @@ public class SysMenuButtonServiceImpl extends ServiceImpl<SysMenuButtonMapper, S
@Override
public void addDefaultButtons(SysMenuButtonRequest sysMenuButtonRequest) {
Long menuId = sysMenuButtonRequest.getMenuId();
// 获取菜单的编码
SysMenu sysMenu = this.sysMenuService.getById(menuId);
// 构建菜单的系统默认按钮
List<SysMenuButton> sysMenuButtonList = MenuButtonFactory.createSystemDefaultButton(menuId);
List<SysMenuButton> sysMenuButtonList = MenuButtonFactory.createSystemDefaultButton(menuId, sysMenu.getMenuName(), sysMenu.getMenuCode());
this.saveBatch(sysMenuButtonList);
}