mirror of
https://gitee.com/xiaonuobase/snowy.git
synced 2026-03-22 10:47:16 +08:00
【底座】底座增强添加业务应用常用的支持功能
This commit is contained in:
@@ -13,6 +13,7 @@
|
||||
package vip.xiaonuo.sys.api;
|
||||
|
||||
import cn.hutool.core.lang.tree.Tree;
|
||||
import cn.hutool.json.JSONObject;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -39,4 +40,22 @@ public interface SysMenuApi {
|
||||
* @date 2024/9/6 01:24
|
||||
**/
|
||||
List<Tree<String>> menuTreeSelector(String module);
|
||||
|
||||
/**
|
||||
* 通过ID获得菜单详情
|
||||
*
|
||||
* @author yubaoshan
|
||||
* @date 2024/9/6 01:24
|
||||
**/
|
||||
JSONObject queryEntity(String id);
|
||||
|
||||
/**
|
||||
* 增加资源并授权于超管
|
||||
*
|
||||
* @author yubaoshan
|
||||
* @date 2025/5/5 04:30
|
||||
*/
|
||||
void addResourceGrantSuperAdmin(String moduleId, String id, String title, String parentId, String name, String code, String category,
|
||||
String menuType, String path, String component, String icon, String visible, Integer sortCode);
|
||||
|
||||
}
|
||||
|
||||
@@ -31,4 +31,20 @@ public interface SysModuleApi {
|
||||
* @date 2024/9/6 01:24
|
||||
**/
|
||||
List<JSONObject> moduleSelector();
|
||||
|
||||
/**
|
||||
* 增加模块
|
||||
*
|
||||
* @author yubaoshan
|
||||
* @date 2025/5/5 04:30
|
||||
*/
|
||||
void addModule(String id, String title, String code, String icon, String color);
|
||||
|
||||
/**
|
||||
* 删除模块以及所有的资源
|
||||
*
|
||||
* @author yubaoshan
|
||||
* @date 2025/5/5 04:30
|
||||
*/
|
||||
void deleteModuleByCode(String moduleCode, List<String> resourceIdList);
|
||||
}
|
||||
|
||||
@@ -28,6 +28,14 @@ import lombok.Setter;
|
||||
@Setter
|
||||
public class SysModuleAddParam {
|
||||
|
||||
/** 新增时可以自设id */
|
||||
@Schema(description = "id", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
private String id;
|
||||
|
||||
/** 新增时可以自设code */
|
||||
@Schema(description = "code")
|
||||
private String code;
|
||||
|
||||
/** 标题 */
|
||||
@Schema(description = "标题")
|
||||
@NotBlank(message = "title不能为空")
|
||||
|
||||
@@ -13,9 +13,13 @@
|
||||
package vip.xiaonuo.sys.modular.resource.provider;
|
||||
|
||||
import cn.hutool.core.lang.tree.Tree;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.json.JSONObject;
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.stereotype.Service;
|
||||
import vip.xiaonuo.sys.api.SysMenuApi;
|
||||
import vip.xiaonuo.sys.modular.resource.entity.SysMenu;
|
||||
import vip.xiaonuo.sys.modular.resource.param.menu.SysMenuSelectorMenuParam;
|
||||
import vip.xiaonuo.sys.modular.resource.service.SysMenuService;
|
||||
|
||||
@@ -44,4 +48,19 @@ public class SysMenuApiProvider implements SysMenuApi {
|
||||
param.setModule(module);
|
||||
return sysMenuService.menuTreeSelector(param);
|
||||
}
|
||||
|
||||
@Override
|
||||
public JSONObject queryEntity(String id) {
|
||||
SysMenu sysMenu = sysMenuService.getById(id);
|
||||
if(ObjectUtil.isNotEmpty(sysMenu)) {
|
||||
return JSONUtil.parseObj(sysMenu);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addResourceGrantSuperAdmin(String moduleId, String id, String title, String parentId, String name, String code, String category,
|
||||
String menuType, String path, String component, String icon, String visible, Integer sortCode) {
|
||||
sysMenuService.addResourceGrantSuperAdmin(moduleId, id, title, parentId, name, code, category, menuType, path, component, icon, visible, sortCode);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@ import cn.hutool.json.JSONObject;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.stereotype.Service;
|
||||
import vip.xiaonuo.sys.api.SysModuleApi;
|
||||
import vip.xiaonuo.sys.modular.resource.param.module.SysModuleAddParam;
|
||||
import vip.xiaonuo.sys.modular.resource.service.SysModuleService;
|
||||
|
||||
import java.util.List;
|
||||
@@ -36,4 +37,20 @@ public class SysModuleApiProvider implements SysModuleApi {
|
||||
public List<JSONObject> moduleSelector() {
|
||||
return sysModuleService.moduleSelector();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addModule(String id, String title, String code, String icon, String color) {
|
||||
SysModuleAddParam param = new SysModuleAddParam();
|
||||
param.setId(id);
|
||||
param.setTitle(title);
|
||||
param.setCode(code);
|
||||
param.setIcon(icon);
|
||||
param.setColor(color);
|
||||
sysModuleService.add(param);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteModuleByCode(String moduleCode, List<String> resourceIdList) {
|
||||
sysModuleService.deleteModuleByCode(moduleCode, resourceIdList);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -137,4 +137,14 @@ public interface SysMenuService extends IService<SysMenu> {
|
||||
* @date 2022/4/24 20:08
|
||||
*/
|
||||
List<Tree<String>> menuTreeSelector(SysMenuSelectorMenuParam sysMenuSelectorMenuParam);
|
||||
|
||||
/**
|
||||
* 增加资源并授权于超管
|
||||
*
|
||||
* @author yubaoshan
|
||||
* @date 2025/5/5 04:30
|
||||
*/
|
||||
void addResourceGrantSuperAdmin(String moduleId, String id, String title, String parentId, String name, String code, String category,
|
||||
String menuType, String path, String component, String icon, String visible, Integer sortCode);
|
||||
|
||||
}
|
||||
|
||||
@@ -86,4 +86,12 @@ public interface SysModuleService extends IService<SysModule> {
|
||||
* @date 2022/4/24 21:18
|
||||
*/
|
||||
SysModule queryEntity(String id);
|
||||
|
||||
/**
|
||||
* 删除模块以及所有的资源
|
||||
*
|
||||
* @author yubaoshan
|
||||
* @date 2025/5/5 04:30
|
||||
*/
|
||||
void deleteModuleByCode(String moduleCode, List<String> resourceIdList);
|
||||
}
|
||||
|
||||
@@ -48,6 +48,7 @@ import vip.xiaonuo.sys.modular.resource.param.module.SysModulePageParam;
|
||||
import vip.xiaonuo.sys.modular.resource.service.SysMenuService;
|
||||
import vip.xiaonuo.sys.modular.resource.service.SysModuleService;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@@ -176,4 +177,32 @@ public class SysModuleServiceImpl extends ServiceImpl<SysModuleMapper, SysModule
|
||||
}
|
||||
return sysModule;
|
||||
}
|
||||
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
@Override
|
||||
public void deleteModuleByCode(String moduleCode, List<String> resourceIdList) {
|
||||
SysModule module = this.getOne(new LambdaQueryWrapper<SysModule>().eq(SysModule::getCode, moduleCode));
|
||||
// 创建一个新的列表来存储所有需要删除的资源ID
|
||||
List<String> allDeleteResourceIds = new ArrayList<>(resourceIdList);
|
||||
|
||||
if (ObjectUtil.isNotEmpty(module)) {
|
||||
String moduleId = module.getId();
|
||||
// 执行删除模块
|
||||
this.removeById(moduleId);
|
||||
// 将模块ID添加到删除列表中
|
||||
allDeleteResourceIds.add(moduleId);
|
||||
}
|
||||
|
||||
// 删除资源
|
||||
sysMenuService.removeByIds(resourceIdList);
|
||||
// 清除对应的角色与资源信息
|
||||
sysRelationService.remove(new LambdaUpdateWrapper<SysRelation>().in(SysRelation::getTargetId, resourceIdList)
|
||||
.eq(SysRelation::getCategory, SysRelationCategoryEnum.SYS_ROLE_HAS_RESOURCE.getValue()));
|
||||
// 清除对应的用户与资源信息
|
||||
sysRelationService.remove(new LambdaUpdateWrapper<SysRelation>().in(SysRelation::getTargetId, resourceIdList)
|
||||
.eq(SysRelation::getCategory, SysRelationCategoryEnum.SYS_ROLE_HAS_RESOURCE.getValue()));
|
||||
|
||||
// 发布删除事件,使用合并后的ID列表
|
||||
CommonDataChangeEventCenter.doDeleteWithDataIdList(SysDataTypeEnum.RESOURCE.getValue(), allDeleteResourceIds);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user