|
@@ -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;
|
|
|
}
|
|
|
|
|
|
|