Pārlūkot izejas kodu

菜单结构调整

FengChaoYu 1 mēnesi atpakaļ
vecāks
revīzija
c81d9ff149

+ 22 - 0
src/main/java/com/gree/mall/manager/bean/admin/AdminModuleBean.java

@@ -0,0 +1,22 @@
+package com.gree.mall.manager.bean.admin;
+
+import com.gree.mall.manager.plus.entity.AdminModule;
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+import java.util.List;
+
+/**
+ * @author :lijh
+ * @description:TODO
+ * @date :2024/1/13 15:19
+ */
+@ApiModel
+@Data
+public class AdminModuleBean extends AdminModule {
+
+    @ApiModelProperty("按钮子集")
+    private List<AdminModule> childList;
+
+}

+ 68 - 0
src/main/java/com/gree/mall/manager/bean/admin/AdminModuleVO.java

@@ -0,0 +1,68 @@
+package com.gree.mall.manager.bean.admin;
+
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+import java.util.Date;
+import java.util.List;
+
+/**
+ * @author qinrongjun
+ * @description
+ * @date 2023/8/12 14:55 星期六
+ */
+@Data
+public class AdminModuleVO {
+
+    @ApiModelProperty( "id")
+    private String moduleId;
+
+    @ApiModelProperty( "名称")
+    private String moduleName;
+
+    @ApiModelProperty( "模块路径")
+    private String modulePath;
+
+    @ApiModelProperty( "true=正常 false=作废")
+    private Boolean status;
+
+    @ApiModelProperty( "1=普通菜单 2=功能菜单 3=功能点  4=外部菜单")
+    private Integer type;
+
+    @ApiModelProperty( "编号")
+    private String code;
+
+    @ApiModelProperty( "层级")
+    private Integer level;
+
+    @ApiModelProperty( "url")
+    private String url;
+
+    @ApiModelProperty( "全url")
+    private String fullUrl;
+
+    @ApiModelProperty( "当前url")
+    private String curUrl;
+
+    @ApiModelProperty( "父id")
+    private String parentId;
+
+    @ApiModelProperty( "父级名称")
+    private String parentModule;
+
+    @ApiModelProperty( "排序号")
+    private Integer sortNum;
+
+    @ApiModelProperty( "创建时间")
+    private Date createTime;
+
+    @ApiModelProperty( "icon")
+    private String icon;
+
+    @ApiModelProperty( "更新时间")
+    private Date updateTime;
+
+    @ApiModelProperty( "type=2的功能点")
+    List<AdminModuleVO> childList;
+
+}

+ 6 - 4
src/main/java/com/gree/mall/manager/controller/admin/AdminModuleController.java

@@ -1,6 +1,8 @@
 package com.gree.mall.manager.controller.admin;
 
 import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.gree.mall.manager.bean.admin.AdminModuleBean;
+import com.gree.mall.manager.bean.admin.AdminModuleVO;
 import com.gree.mall.manager.helper.ResponseHelper;
 import com.gree.mall.manager.logic.admin.AdminModuleLogic;
 import com.gree.mall.manager.plus.entity.AdminModule;
@@ -22,14 +24,14 @@ public class AdminModuleController {
 
     @GetMapping("/detail")
     @ApiOperation("详情")
-    public ResponseHelper<AdminModule> detail(@RequestParam String moduleId){
-        AdminModule detail = adminModuleLogic.detail(moduleId);
+    public ResponseHelper<AdminModuleVO> detail(@RequestParam String moduleId){
+        AdminModuleVO detail = adminModuleLogic.detail(moduleId);
         return ResponseHelper.success(detail);
     }
 
     @PostMapping("/add")
     @ApiOperation("新增")
-    public ResponseHelper add(@RequestBody AdminModule adminModule){
+    public ResponseHelper add(@RequestBody AdminModuleBean adminModule){
         adminModuleLogic.add(adminModule);
         return ResponseHelper.success();
     }
@@ -37,7 +39,7 @@ public class AdminModuleController {
 
     @PostMapping("/update")
     @ApiOperation("修改")
-    public ResponseHelper update(@RequestBody AdminModule adminModule){
+    public ResponseHelper update(@RequestBody AdminModuleBean adminModule){
         adminModuleLogic.update(adminModule);
         return ResponseHelper.success();
     }

+ 31 - 9
src/main/java/com/gree/mall/manager/logic/admin/AdminModuleLogic.java

@@ -1,9 +1,13 @@
 package com.gree.mall.manager.logic.admin;
 
+import cn.hutool.core.bean.BeanUtil;
 import com.aliyuncs.utils.StringUtils;
 import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.gree.mall.manager.bean.admin.AdminModuleBean;
 import com.gree.mall.manager.bean.admin.AdminModuleTree;
+import com.gree.mall.manager.bean.admin.AdminModuleVO;
 import com.gree.mall.manager.exception.RemoteServiceException;
 import com.gree.mall.manager.plus.entity.AdminModule;
 import com.gree.mall.manager.plus.service.AdminModuleService;
@@ -22,7 +26,7 @@ public class AdminModuleLogic {
     AdminModuleService adminModuleService;
 
 
-    public void add(AdminModule adminModule){
+    public void add(AdminModuleBean adminModule){
         Integer level = 1;
         if(!adminModule.getParentId().equals("0")){
             AdminModule parent = adminModuleService.getById(adminModule.getParentId());
@@ -30,12 +34,11 @@ public class AdminModuleLogic {
                 throw new RemoteServiceException("请选择正确的父级菜单");
             }
             level = parent.getLevel() + 1;
-
-            parent.setType(1);
             parent.updateById();
         }
         Integer count = adminModuleService.lambdaQuery()
-                .and(v -> v.eq(AdminModule::getCode, adminModule.getCode()).or().eq(AdminModule::getUrl, adminModule.getUrl()))
+                .eq(AdminModule::getCode,adminModule.getCode())
+                .eq(AdminModule::getParentId,adminModule.getParentId())
                 .count();
         if(count > 0){
             throw new RemoteServiceException("code或者url重复");
@@ -43,12 +46,20 @@ public class AdminModuleLogic {
         adminModule.setLevel(level);
         adminModule.setCreateTime(new Date());
         adminModule.insert();
+        //添加子集
+        if(CollectionUtils.isNotEmpty(adminModule.getChildList())){
+            for (AdminModule module : adminModule.getChildList()) {
+                module.setLevel(adminModule.getLevel() + 1);
+                module.setParentId(adminModule.getModuleId());
+            }
+            adminModuleService.saveBatch(adminModule.getChildList());
+        }
     }
 
 
     public void update(AdminModule adminModule){
         Integer level = 1;
-        if(!adminModule.getParentId().equals("0")){
+        if(adminModule.getParentId() != null && !adminModule.getParentId().equals("0")){
             AdminModule parent = adminModuleService.getById(adminModule.getParentId());
             if(parent == null){
                 throw new RemoteServiceException("请选择正确的父级菜单");
@@ -56,13 +67,16 @@ public class AdminModuleLogic {
             level = parent.getLevel() + 1;
         }
         Integer count = adminModuleService.lambdaQuery()
-                .and(v -> v.eq(AdminModule::getCode, adminModule.getCode()).or().eq(AdminModule::getUrl, adminModule.getUrl()))
                 .ne(AdminModule::getModuleId,adminModule.getModuleId())
+                .eq(AdminModule::getCode,adminModule.getCode())
+                .eq(AdminModule::getParentId,adminModule.getParentId())
                 .count();
         if(count > 0){
             throw new RemoteServiceException("code或者url重复");
         }
-        adminModule.setLevel(level);
+        if(adminModule.getType() != 3) {
+            adminModule.setLevel(level);
+        }
         adminModule.updateById();
     }
 
@@ -72,8 +86,16 @@ public class AdminModuleLogic {
     }
 
 
-    public AdminModule detail(String id){
-        return adminModuleService.getById(id);
+    public AdminModuleVO detail(String id){
+        AdminModule adminModule = adminModuleService.getById(id);
+        AdminModuleVO adminModuleVO = BeanUtil.copyProperties(adminModule, AdminModuleVO.class);
+        //查询子集
+        if(adminModule.getType() == 2){
+            List<AdminModule> list = adminModuleService.lambdaQuery().eq(AdminModule::getParentId, adminModule.getModuleId()).list();
+            List<AdminModuleVO> adminModuleVOS = BeanUtil.copyToList(list, AdminModuleVO.class);
+            adminModuleVO.setChildList(adminModuleVOS);
+        }
+        return adminModuleVO;
     }