|
@@ -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();
|
|
@@ -333,11 +439,11 @@ public class MenuServiceImpl extends MPJBaseServiceImpl<MenuMapper, Menu> implem
|
|
|
.ifPresent(parentNode -> {
|
|
|
node.setSystemId(parentNode.getSystemId());
|
|
|
node.setSystemName(parentNode.getSystemName());
|
|
|
- node.setSortCode(Integer.parseInt(parentNode.getSortCode() + "" + node.getSortCode()));
|
|
|
node.setParentSortCode(parentNode.getSortCode());
|
|
|
});
|
|
|
Long number = menuVos.stream().filter(x -> x.getParentId().equals(node.getId())).count();
|
|
|
if (number == 0) {
|
|
|
+ node.setParentSortCode(node.getParentSortCode() == null ? 0 : node.getParentSortCode());
|
|
|
childMenus.add(node);
|
|
|
}
|
|
|
}
|
|
@@ -346,9 +452,17 @@ public class MenuServiceImpl extends MPJBaseServiceImpl<MenuMapper, Menu> implem
|
|
|
List<MenuVo> childMenu = childMenus.stream().
|
|
|
filter(x -> x.getSystemId().equals(node.getId())).
|
|
|
collect(Collectors.toList());
|
|
|
- childMenu.sort(Comparator.comparingInt(MenuVo::getSortCode).thenComparingInt(MenuVo::getSortCode));
|
|
|
+ childMenu.sort(Comparator.comparingInt(MenuVo::getParentSortCode).thenComparingInt(MenuVo::getSortCode));
|
|
|
node.setMenuVoList(childMenu);
|
|
|
});
|
|
|
return new ArrayList<>(menuVoMap.values());
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+ * 获取所有子级菜单
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public List<Menu> getChileAll(Long id) {
|
|
|
+ return menuMapper.getChileAll(id);
|
|
|
+ }
|
|
|
}
|