|
@@ -1,19 +1,19 @@
|
|
|
package com.xjrsoft.module.system.service.impl;
|
|
|
|
|
|
import cn.dev33.satoken.stp.StpUtil;
|
|
|
+import cn.hutool.core.bean.BeanUtil;
|
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.StringPool;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
import com.github.yulichang.base.MPJBaseServiceImpl;
|
|
|
import com.github.yulichang.toolkit.MPJWrappers;
|
|
|
import com.xjrsoft.common.constant.GlobalConstant;
|
|
|
-import com.xjrsoft.common.enums.AuthorizeType;
|
|
|
-import com.xjrsoft.common.enums.DeleteMark;
|
|
|
-import com.xjrsoft.common.enums.EnabledMark;
|
|
|
-import com.xjrsoft.common.enums.RoleEnum;
|
|
|
+import com.xjrsoft.common.enums.*;
|
|
|
+import com.xjrsoft.common.exception.MyException;
|
|
|
import com.xjrsoft.common.utils.VoToColumnUtil;
|
|
|
import com.xjrsoft.module.base.entity.WhitelistManagement;
|
|
|
import com.xjrsoft.module.base.service.IWhitelistManagementService;
|
|
@@ -21,16 +21,18 @@ import com.xjrsoft.module.organization.entity.UserRoleRelation;
|
|
|
import com.xjrsoft.module.organization.mapper.UserRoleRelationMapper;
|
|
|
import com.xjrsoft.module.system.dto.MenuTreeDto;
|
|
|
import com.xjrsoft.module.system.dto.RoleMenuServeListDto;
|
|
|
+import com.xjrsoft.module.system.dto.UpdateMenuDto;
|
|
|
+import com.xjrsoft.module.system.dto.UpdateMenuFormDto;
|
|
|
import com.xjrsoft.module.system.entity.*;
|
|
|
import com.xjrsoft.module.system.mapper.AuthorizeMapper;
|
|
|
import com.xjrsoft.module.system.mapper.MenuMapper;
|
|
|
import com.xjrsoft.module.system.mapper.XjrMenuDeptRelationMapper;
|
|
|
import com.xjrsoft.module.system.mapper.XjrMenuQuickMapper;
|
|
|
-import com.xjrsoft.module.system.service.IMenuService;
|
|
|
-import com.xjrsoft.module.system.service.IXjrMenuGroupSetService;
|
|
|
+import com.xjrsoft.module.system.service.*;
|
|
|
import com.xjrsoft.module.system.vo.*;
|
|
|
import lombok.AllArgsConstructor;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
import java.util.*;
|
|
|
import java.util.function.Function;
|
|
@@ -59,6 +61,110 @@ public class MenuServiceImpl extends MPJBaseServiceImpl<MenuMapper, Menu> implem
|
|
|
private final IXjrMenuGroupSetService xjrMenuGroupSetService;
|
|
|
private final IWhitelistManagementService whitelistManagementService;
|
|
|
|
|
|
+ private final MenuMapper menuMapper;
|
|
|
+
|
|
|
+ private final IMenuButtonService menuButtonService;
|
|
|
+
|
|
|
+ private final IMenuColumnService menuColumnService;
|
|
|
+
|
|
|
+ private final IMenuFormService menuFormService;
|
|
|
+
|
|
|
+ private final IXjrMenuDeptRelationService xjrMenuDeptRelationService;
|
|
|
+
|
|
|
+
|
|
|
+ * 修改菜单
|
|
|
+ */
|
|
|
+ @Transactional
|
|
|
+ public void edit(UpdateMenuDto dto) {
|
|
|
+ long count = this.count(Wrappers.<Menu>query().lambda()
|
|
|
+ .ne(Menu::getId, dto.getId()).and(wrapper ->
|
|
|
+ wrapper.eq(Menu::getCode, dto.getCode())
|
|
|
+ )
|
|
|
+ );
|
|
|
+
|
|
|
+ if (count > 0) {
|
|
|
+ throw new MyException("菜单编码已经存在!");
|
|
|
+ }
|
|
|
+ Menu menu = BeanUtil.toBean(dto, Menu.class);
|
|
|
+
|
|
|
+
|
|
|
+ if (menu.getMenuType() == YesOrNoEnum.NO.getCode()) {
|
|
|
+
|
|
|
+ if (!menu.getPath().startsWith(StringPool.SLASH)) {
|
|
|
+ menu.setPath(StringPool.SLASH + menu.getPath());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ if (menu.getOutLink() == YesOrNoEnum.YES.getCode()) {
|
|
|
+
|
|
|
+ menu.setComponent("IFrame");
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ if (menu.getParentId() == null) {
|
|
|
+ Menu obj = this.getById(dto.getId());
|
|
|
+ if (!obj.getSystemId().equals(dto.getSystemId())) {
|
|
|
+ List<Menu> chileAll = menuMapper.getChileAll(dto.getId());
|
|
|
+ List<Long> ids = chileAll.stream().map(Menu::getId).collect(Collectors.toList());
|
|
|
+ this.update(new Menu() {{
|
|
|
+ setSystemId(dto.getSystemId());
|
|
|
+ setComponentType(dto.getComponentType());
|
|
|
+ }}, Wrappers.<Menu>query().lambda().in(Menu::getId, ids));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ this.updateById(menu);
|
|
|
+
|
|
|
+
|
|
|
+ List<MenuButton> menuButtons = BeanUtil.copyToList(dto.getButtonList(), MenuButton.class);
|
|
|
+ menuButtons.forEach(menuButton -> menuButton.setMenuId(menu.getId()));
|
|
|
+
|
|
|
+ menuButtonService.remove(Wrappers.<MenuButton>query().lambda().eq(MenuButton::getMenuId, menu.getId()));
|
|
|
+
|
|
|
+
|
|
|
+ List<MenuColumn> columnList = BeanUtil.copyToList(dto.getColumnList(), MenuColumn.class);
|
|
|
+ columnList.forEach(menuColumn -> menuColumn.setMenuId(menu.getId()));
|
|
|
+ menuColumnService.remove(Wrappers.<MenuColumn>query().lambda().eq(MenuColumn::getMenuId, menu.getId()));
|
|
|
+
|
|
|
+
|
|
|
+ List<MenuForm> formList = new ArrayList<>();
|
|
|
+ for (UpdateMenuFormDto updateMenuFormDto : dto.getFormList()) {
|
|
|
+ formList.add(BeanUtil.toBean(updateMenuFormDto, MenuForm.class));
|
|
|
+ List<UpdateMenuFormDto> children = updateMenuFormDto.getChildren();
|
|
|
+ if (org.apache.commons.collections.CollectionUtils.isNotEmpty(children)) {
|
|
|
+ formList.addAll(BeanUtil.copyToList(children, MenuForm.class));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ formList.forEach(menuForm -> menuForm.setMenuId(menu.getId()));
|
|
|
+ menuFormService.remove(Wrappers.<MenuForm>query().lambda().eq(MenuForm::getMenuId, menu.getId()));
|
|
|
+
|
|
|
+ if (dto.getMenuDeptRelations() != null) {
|
|
|
+ List<XjrMenuDeptRelation> menuDeptRelations = BeanUtil.copyToList(dto.getMenuDeptRelations(), XjrMenuDeptRelation.class);
|
|
|
+ menuDeptRelations.forEach(XjrMenuDeptRelation -> XjrMenuDeptRelation.setMenuId(menu.getId()));
|
|
|
+ xjrMenuDeptRelationService.remove(Wrappers.<XjrMenuDeptRelation>query().lambda().eq(XjrMenuDeptRelation::getMenuId, menu.getId()));
|
|
|
+
|
|
|
+ if (CollectionUtils.isNotEmpty(menuDeptRelations)) {
|
|
|
+ xjrMenuDeptRelationService.saveBatch(menuDeptRelations);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (CollectionUtils.isNotEmpty(menuButtons)) {
|
|
|
+ menuButtonService.saveBatch(menuButtons);
|
|
|
+ }
|
|
|
+ if (CollectionUtils.isNotEmpty(columnList)) {
|
|
|
+ menuColumnService.saveBatch(columnList);
|
|
|
+ }
|
|
|
+ if (CollectionUtils.isNotEmpty(formList)) {
|
|
|
+ menuFormService.saveBatch(formList);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ * 获取用户角色id
|
|
|
+ *
|
|
|
+ * @return
|
|
|
+ */
|
|
|
@Override
|
|
|
public List<MenuVo> getAuthMenuList(MenuTreeDto dto) {
|
|
|
List<Long> roleIds = getUserRoleIds();
|
|
@@ -215,12 +321,8 @@ public class MenuServiceImpl extends MPJBaseServiceImpl<MenuMapper, Menu> implem
|
|
|
.select(Menu::getId)
|
|
|
.select("1 as authorized")
|
|
|
.selectAs(Subsystem::getName, MenuVo::getSystemName)
|
|
|
-
|
|
|
-
|
|
|
.select(Menu.class, x -> VoToColumnUtil.fieldsToColumns(MenuTreeVo.class).contains(x.getProperty()))
|
|
|
.leftJoin(Subsystem.class, Subsystem::getId, Menu::getSystemId)
|
|
|
-
|
|
|
-
|
|
|
.eq(Menu::getEnabledMark, EnabledMark.ENABLED.getCode())
|
|
|
.orderByAscStr(orderList)
|
|
|
);
|
|
@@ -312,10 +414,13 @@ public class MenuServiceImpl extends MPJBaseServiceImpl<MenuMapper, Menu> implem
|
|
|
* @return
|
|
|
*/
|
|
|
private List<MenuServeVo> getSubMenu(List<MenuVo> menuVos) {
|
|
|
- Map<Long, MenuServeVo> menuVoMap = new HashMap<>();
|
|
|
+ Map<Long, MenuServeVo> menuVoMap = new LinkedHashMap<>();
|
|
|
|
|
|
List<MenuVo> childMenus = new ArrayList<>();
|
|
|
|
|
|
+ Map<Long, MenuVo> menuMap = menuVos.stream()
|
|
|
+ .collect(Collectors.toMap(MenuVo::getId, menu -> menu));
|
|
|
+
|
|
|
menuVos.forEach((node) -> {
|
|
|
Long parentId = node.getParentId();
|
|
|
|
|
@@ -332,22 +437,49 @@ public class MenuServiceImpl extends MPJBaseServiceImpl<MenuMapper, Menu> implem
|
|
|
|
|
|
if (!StrUtil.isEmptyIfStr(parentId) || !StrUtil.equals(String.valueOf(parentId), String.valueOf(GlobalConstant.FIRST_NODE_VALUE))) {
|
|
|
|
|
|
- menuVos.stream().filter(x -> StrUtil.equals(x.getId().toString(), String.valueOf(parentId)))
|
|
|
- .findAny()
|
|
|
- .ifPresent(parentNode -> {
|
|
|
- node.setSystemId(parentNode.getSystemId());
|
|
|
- node.setSystemName(parentNode.getSystemName());
|
|
|
- });
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
Long number = menuVos.stream().filter(x -> x.getParentId().equals(node.getId())).count();
|
|
|
- if (number == 0) {
|
|
|
+ if (number == 0 && !Objects.equals(parentId, GlobalConstant.FIRST_NODE_VALUE)) {
|
|
|
+ MenuVo parentMenu = getParentMenu(parentId, menuMap);
|
|
|
+ node.setSystemId(parentMenu.getSystemId());
|
|
|
+ node.setSystemName(parentMenu.getSystemName());
|
|
|
+ node.setParentSortCode(parentMenu.getSortCode());
|
|
|
childMenus.add(node);
|
|
|
}
|
|
|
}
|
|
|
});
|
|
|
menuVoMap.values().forEach((node) -> {
|
|
|
- List<MenuVo> childMenu = childMenus.stream().filter(x -> x.getSystemId().equals(node.getId())).collect(Collectors.toList());
|
|
|
+ List<MenuVo> childMenu = childMenus.stream().
|
|
|
+ filter(x -> x.getSystemId().equals(node.getId())).
|
|
|
+ collect(Collectors.toList());
|
|
|
+ childMenu.sort(Comparator.comparingInt(MenuVo::getParentSortCode).thenComparingInt(MenuVo::getSortCode));
|
|
|
node.setMenuVoList(childMenu);
|
|
|
});
|
|
|
return new ArrayList<>(menuVoMap.values());
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+ * 找到顶级菜单
|
|
|
+ */
|
|
|
+ private MenuVo getParentMenu(Long parentId, Map<Long, MenuVo> menuMap) {
|
|
|
+ MenuVo menuVo = menuMap.get(parentId);
|
|
|
+ if (menuVo.getParentId().equals(GlobalConstant.FIRST_NODE_VALUE)) {
|
|
|
+ return menuVo;
|
|
|
+ }
|
|
|
+ return getParentMenu(menuVo.getParentId(), menuMap);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ * 获取所有子级菜单
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public List<Menu> getChileAll(Long id) {
|
|
|
+ return menuMapper.getChileAll(id);
|
|
|
+ }
|
|
|
}
|