From 5c9c836f4a72487d386b6e05fcd4b4a96eec4e72 Mon Sep 17 00:00:00 2001
From: 陶杰 <1378534974@qq.com>
Date: 星期五, 06 十二月 2024 21:12:39 +0800
Subject: [PATCH] 小程序菜单
---
src/main/java/com/mzl/flower/service/system/AppMenuService.java | 173 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 173 insertions(+), 0 deletions(-)
diff --git a/src/main/java/com/mzl/flower/service/system/AppMenuService.java b/src/main/java/com/mzl/flower/service/system/AppMenuService.java
new file mode 100644
index 0000000..670978a
--- /dev/null
+++ b/src/main/java/com/mzl/flower/service/system/AppMenuService.java
@@ -0,0 +1,173 @@
+package com.mzl.flower.service.system;
+
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.mzl.flower.config.exception.ValidationException;
+import com.mzl.flower.constant.Constants;
+import com.mzl.flower.dto.request.system.CreateAppMenuDTO;
+import com.mzl.flower.dto.request.system.UpdateAppMenuDTO;
+import com.mzl.flower.dto.response.system.AppMenuDTO;
+import com.mzl.flower.dto.response.system.AppMenuTreeDTO;
+import com.mzl.flower.entity.system.AppMenu;
+import com.mzl.flower.mapper.system.AppMenuMapper;
+import com.mzl.flower.service.BaseService;
+import com.mzl.flower.utils.TreeBuilderUtil;
+import com.mzl.flower.utils.UUIDGenerator;
+import org.springframework.beans.BeanUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+import org.springframework.util.CollectionUtils;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+@Service
+@Transactional
+public class AppMenuService extends BaseService {
+ @Autowired
+ private AppMenuMapper menuMapper;
+
+ public AppMenu getMenu(String id) {
+ return menuMapper.selectById(id);
+ }
+
+ public void addMenu(CreateAppMenuDTO dto) {
+ AppMenu menu = new AppMenu();
+ // 查找菜单名称是否已经存在
+ if (menuMapper.selectCount(new QueryWrapper<AppMenu>()
+ .lambda().eq(AppMenu::getMenuName, dto.getMenuName())
+ .eq(AppMenu::getStatus, Constants.STATUS_ACTIVE)
+ ) > 0) {
+ throw new ValidationException("菜单名称已经存在");
+ }
+ // 查找权限标识是否已经存在
+ if (menuMapper.selectCount(new QueryWrapper<AppMenu>().lambda().eq(AppMenu::getPermissionUq, dto.getPermissionUq()).eq(AppMenu::getStatus, Constants.STATUS_ACTIVE)) > 0) {
+ throw new ValidationException("权限标识已经存在");
+ }
+
+ BeanUtils.copyProperties(dto, menu);
+ menu.setId(UUIDGenerator.getUUID());
+ menu.setIsVisible(Constants.Y);
+ menu.setStatus(Constants.STATUS_ACTIVE);
+ menu.setSubaccountAccessFlag(Constants.CUSTOM01.ONE.getDesc());
+
+ menuMapper.insert(menu);
+ }
+
+ public List<AppMenuTreeDTO> searchOperationMenu() {
+ List<AppMenuTreeDTO> treeList = menuMapper.selectListOrderBySeq();
+ for (AppMenuTreeDTO appMenuTreeDTO : treeList) {
+ appMenuTreeDTO.setLabel(appMenuTreeDTO.getMenuName());
+ appMenuTreeDTO.setPath(appMenuTreeDTO.getMenuHref());
+ appMenuTreeDTO.setName(appMenuTreeDTO.getMenuName());
+ }
+ treeList = (List<AppMenuTreeDTO>) TreeBuilderUtil.buildListToTree(treeList);
+ return treeList;
+ }
+
+ public AppMenuDTO getMenuDetail(String id) {
+ AppMenu menu = getMenu(id);
+
+ //返回对象
+ AppMenuDTO menuDTO = new AppMenuDTO();
+ if (menu != null) {
+ BeanUtils.copyProperties(menu, menuDTO);
+ }
+ return menuDTO;
+ }
+
+ public void updateMenu(UpdateAppMenuDTO dto) {
+ AppMenu menu = getMenu(dto.getId());
+ if(null==menu){
+ throw new ValidationException("菜单不存在");
+ }
+ if (menuMapper.selectCount(new QueryWrapper<AppMenu>().lambda().eq(AppMenu::getMenuName, dto.getMenuName()).eq(AppMenu::getStatus, Constants.STATUS_ACTIVE).ne(AppMenu::getId, menu.getId())) > 0) {
+ throw new ValidationException("菜单名称已经存在");
+ }
+ // 查找权限标识是否已经存在
+ if (menuMapper.selectCount(new QueryWrapper<AppMenu>().lambda().eq(AppMenu::getPermissionUq, dto.getPermissionUq()).eq(AppMenu::getStatus, Constants.STATUS_ACTIVE).ne(AppMenu::getId, menu.getId())) > 0) {
+ throw new ValidationException("权限标识已经存在");
+ }
+ Integer subaccountAccessFlag = menu.getSubaccountAccessFlag();
+ BeanUtils.copyProperties(dto, menu);
+ menu.setSubaccountAccessFlag(subaccountAccessFlag);
+ menuMapper.updateById(menu);
+ }
+
+ public void deleteMenu(String id) {
+ AppMenu menu = getMenu(id);
+ menu.setStatus(Constants.STATUS_DELETED);
+ menuMapper.updateById(menu);
+
+ List<AppMenu> menus = menuMapper.selectList(new QueryWrapper<AppMenu>().eq("PARENT_ID", id));
+ if (menus != null && menus.size() > 0) {
+ for (AppMenu children : menus) {
+ deleteMenu(children.getId());
+ }
+ }
+ }
+
+ public void updateMenuShow(String id) {
+ // 更新当前菜单及所有子菜单都变为隐藏
+ List<String> menuIds = new ArrayList<>();
+ findAllChildMenuIds(id, menuIds);
+ menuMapper.updateMenuSubaccountAccessFlag(menuIds, Constants.CUSTOM01.ONE.getDesc());
+ }
+
+ public void updateMenuHidden(String id) {
+ // 递归查找所有子菜单
+ List<String> menuIds = new ArrayList<>();
+ findAllChildMenuIds(id, menuIds);
+ menuMapper.updateMenuSubaccountAccessFlag(menuIds, Constants.CUSTOM01.ZERO.getDesc());
+ }
+
+
+ /**
+ * 递归查找当前菜单及所有子菜单的 ID
+ *
+ * @param menuId 当前菜单 ID
+ * @param menuIds 存储菜单 ID 的列表
+ */
+ private void findAllChildMenuIds(String menuId, List<String> menuIds) {
+ // 首先将当前菜单 ID 加入菜单列表
+ menuIds.add(menuId);
+
+ // 查询当前菜单的所有子菜单
+ List<String> childMenuIds = menuMapper.findChildMenuIds(menuId);
+
+ // 如果有子菜单,递归查找
+ if (childMenuIds != null && !childMenuIds.isEmpty()) {
+ for (String childMenuId : childMenuIds) {
+ findAllChildMenuIds(childMenuId, menuIds); // 递归查找子菜单
+ }
+ }
+ }
+
+ // 获取供应商菜单信息
+ public List<AppMenu> getPermissionMenu() {
+
+ LambdaQueryWrapper<AppMenu> queryWrapper = new QueryWrapper<AppMenu>()
+ .lambda()
+ .eq(AppMenu::getStatus, Constants.STATUS_ACTIVE)
+ .eq(AppMenu::getSubaccountAccessFlag,Constants.CUSTOM01.ONE.getDesc())
+// .eq(AppMenu::getPermissionUq, Constants.APP_MENU_TYPE.SUPPLIER.getDesc())
+ ;
+ List<AppMenu> list = menuMapper.selectList(queryWrapper);
+
+ if (!CollectionUtils.isEmpty(list)) {
+
+ List<AppMenu> allMenuList = menuMapper.selectList(
+ new QueryWrapper<AppMenu>().lambda().eq(AppMenu::getStatus, Constants.STATUS_ACTIVE));
+
+ return allMenuList;
+ }
+
+ return null;
+ }
+
+
+
+}
--
Gitblit v1.9.3