‘linchangsheng’ 7 months ago
parent
commit
b784336849

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

@@ -0,0 +1,22 @@
+package com.zfire.mall.manager.bean.admin;
+
+import com.zfire.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;
+
+}

+ 2 - 1
src/main/java/com/zfire/mall/manager/controller/admin/AdminModuleController.java

@@ -1,5 +1,6 @@
 package com.zfire.mall.manager.controller.admin;
 package com.zfire.mall.manager.controller.admin;
 
 
+import com.zfire.mall.manager.bean.admin.AdminModuleBean;
 import com.zfire.mall.manager.bean.admin.AdminModuleTree;
 import com.zfire.mall.manager.bean.admin.AdminModuleTree;
 import com.zfire.mall.manager.bean.admin.AdminModuleVO;
 import com.zfire.mall.manager.bean.admin.AdminModuleVO;
 import com.zfire.mall.manager.bean.admin.AdminWebsitTree;
 import com.zfire.mall.manager.bean.admin.AdminWebsitTree;
@@ -37,7 +38,7 @@ public class AdminModuleController {
 
 
     @PostMapping("/add")
     @PostMapping("/add")
     @ApiOperation("新增")
     @ApiOperation("新增")
-    public ResponseHelper add(@RequestBody AdminModule adminModule){
+    public ResponseHelper add(@RequestBody AdminModuleBean adminModule){
         adminModuleLogic.add(adminModule);
         adminModuleLogic.add(adminModule);
         return ResponseHelper.success();
         return ResponseHelper.success();
     }
     }

+ 20 - 31
src/main/java/com/zfire/mall/manager/logic/admin/AdminModuleLogic.java

@@ -1,6 +1,8 @@
 package com.zfire.mall.manager.logic.admin;
 package com.zfire.mall.manager.logic.admin;
 
 
 import cn.hutool.core.bean.BeanUtil;
 import cn.hutool.core.bean.BeanUtil;
+import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
+import com.zfire.mall.manager.bean.admin.AdminModuleBean;
 import com.zfire.mall.manager.bean.admin.AdminModuleTree;
 import com.zfire.mall.manager.bean.admin.AdminModuleTree;
 import com.zfire.mall.manager.bean.admin.AdminModuleVO;
 import com.zfire.mall.manager.bean.admin.AdminModuleVO;
 import com.zfire.mall.manager.bean.admin.AdminUserCom;
 import com.zfire.mall.manager.bean.admin.AdminUserCom;
@@ -35,7 +37,7 @@ public class AdminModuleLogic {
      * 新增模块
      * 新增模块
      * @param adminModule
      * @param adminModule
      */
      */
-    public void add(AdminModule adminModule){
+    public void add(AdminModuleBean adminModule){
         Integer level = 1;
         Integer level = 1;
         if(!adminModule.getParentId().equals("0")){
         if(!adminModule.getParentId().equals("0")){
             AdminModule parent = adminModuleService.getById(adminModule.getParentId());
             AdminModule parent = adminModuleService.getById(adminModule.getParentId());
@@ -43,62 +45,49 @@ public class AdminModuleLogic {
                 throw new RemoteServiceException("请选择正确的父级菜单");
                 throw new RemoteServiceException("请选择正确的父级菜单");
             }
             }
             level = parent.getLevel() + 1;
             level = parent.getLevel() + 1;
-//            parent.setType(1);
-//            parent.updateById();
+            parent.updateById();
         }
         }
         Integer count = adminModuleService.lambdaQuery()
         Integer count = adminModuleService.lambdaQuery()
-                .and(v -> v.eq(AdminModule::getFullUrl, adminModule.getFullUrl()).or().eq(AdminModule::getCode, adminModule.getCode()))
+                .eq(AdminModule::getCode,adminModule.getCode())
+                .eq(AdminModule::getParentId,adminModule.getParentId())
                 .count();
                 .count();
         if(count > 0){
         if(count > 0){
             throw new RemoteServiceException("code或者url重复");
             throw new RemoteServiceException("code或者url重复");
         }
         }
-//        adminModule.setUrl(adminModule.getUrl().replaceAll(" ",""));
-//        if(adminModule.getUrl().indexOf("http:") > -1 || adminModule.getUrl().indexOf("https:") > -1){
-//            adminModule.setType(4);
-//        }else{
-//            adminModule.setType(2);
-//        }
         adminModule.setLevel(level);
         adminModule.setLevel(level);
         adminModule.setCreateTime(new Date());
         adminModule.setCreateTime(new Date());
-        adminModule.setCurUrl(adminModule.getFullUrl());
         adminModule.insert();
         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){
     public void update(AdminModule adminModule){
         Integer level = 1;
         Integer level = 1;
-        if(!adminModule.getParentId().equals("0")){
+        if(adminModule.getParentId() != null && !adminModule.getParentId().equals("0")){
             AdminModule parent = adminModuleService.getById(adminModule.getParentId());
             AdminModule parent = adminModuleService.getById(adminModule.getParentId());
             if(parent == null){
             if(parent == null){
                 throw new RemoteServiceException("请选择正确的父级菜单");
                 throw new RemoteServiceException("请选择正确的父级菜单");
             }
             }
             level = parent.getLevel() + 1;
             level = parent.getLevel() + 1;
-            //parent.setType(1);
-            //parent.updateById();
         }
         }
         Integer count = adminModuleService.lambdaQuery()
         Integer count = adminModuleService.lambdaQuery()
-                .and(v -> v.eq(AdminModule::getFullUrl, adminModule.getFullUrl()).or().eq(AdminModule::getCode, adminModule.getCode()))
                 .ne(AdminModule::getModuleId,adminModule.getModuleId())
                 .ne(AdminModule::getModuleId,adminModule.getModuleId())
+                .eq(AdminModule::getCode,adminModule.getCode())
+                .eq(AdminModule::getParentId,adminModule.getParentId())
                 .count();
                 .count();
         if(count > 0){
         if(count > 0){
             throw new RemoteServiceException("code或者url重复");
             throw new RemoteServiceException("code或者url重复");
         }
         }
-        adminModule.setUrl(adminModule.getUrl().replaceAll(" ",""));
-//        if(adminModule.getUrl().indexOf("http:") > -1 || adminModule.getUrl().indexOf("https:") > -1){
-//            adminModule.setType(4);
-//        }else{
-//            //查询是否有子项
-//            Integer count1 = adminModuleService.lambdaQuery()
-//                    .eq(AdminModule::getParentId, adminModule.getModuleId())
-//                    .ne(AdminModule::getType,3)
-//                    .count();
-//            if(count1 > 0){
-//                adminModule.setType(1);
-//            }else {
-//                adminModule.setType(2);
-//            }
-//        }
-        adminModule.setLevel(level);
+        if(adminModule.getType() != 3) {
+            adminModule.setLevel(level);
+        }
         adminModule.updateById();
         adminModule.updateById();
     }
     }