添加菜单下载
This commit is contained in:
@@ -16,7 +16,8 @@ public enum CodeGenType {
|
||||
|
||||
CONTROLLER(0, "controller"),
|
||||
MODULE_DATA_INFO(1, "module_data_info"),
|
||||
role_permission(2,"role_permission");
|
||||
ROLE_PERMISSION(2,"role_permission"),
|
||||
MENU_DATA_INFO(3, "menu_data_info");
|
||||
|
||||
private final int code;
|
||||
private final String desc;
|
||||
|
||||
@@ -25,7 +25,9 @@ public enum TemplateTypeEnum {
|
||||
RESPONSE_PARAM(2, "响应参数"),
|
||||
SERVICE(3, "服务接口"),
|
||||
SERVICE_IMPL(4, "服务实现"),
|
||||
MODULE_DATA_INFO(5, "模块功能操作数据生成");
|
||||
MODULE_DATA_INFO(5, "模块功能操作数据生成"),
|
||||
ROLE_DATA_INFO(6, "角色套餐权限数据生成"),
|
||||
MENU_DATA_INFO(7, "菜单数据生成");
|
||||
|
||||
private final int code;
|
||||
private final String desc;
|
||||
|
||||
@@ -0,0 +1,74 @@
|
||||
package com.cczsa.xinghe.codegen.service.flow.template;
|
||||
|
||||
import com.cczsa.xinghe.codegen.entity.MenuEntity;
|
||||
import com.cczsa.xinghe.codegen.entity.enums.TemplateTypeEnum;
|
||||
import com.cczsa.xinghe.codegen.mapper.MenuMapper;
|
||||
import com.cczsa.xinghe.codegen.service.TemplateService;
|
||||
import com.yomahub.liteflow.annotation.LiteflowComponent;
|
||||
import com.yomahub.liteflow.core.NodeComponent;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.stringtemplate.v4.ST;
|
||||
import org.stringtemplate.v4.STGroup;
|
||||
import org.stringtemplate.v4.STGroupString;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.zip.ZipEntry;
|
||||
import java.util.zip.ZipOutputStream;
|
||||
|
||||
/**
|
||||
* @author xia
|
||||
* @date 2026/1/23
|
||||
* @version 0.0.1
|
||||
*/
|
||||
@Slf4j
|
||||
@RequiredArgsConstructor
|
||||
@LiteflowComponent(id = "menuDataInfo", name = "菜单数据生成")
|
||||
public class MenuDataInfo extends NodeComponent {
|
||||
|
||||
private final TemplateService templateService;
|
||||
private final MenuMapper menuMapper;
|
||||
|
||||
// 压缩流
|
||||
private ZipOutputStream zos;
|
||||
|
||||
@Override
|
||||
public void process() throws Exception {
|
||||
// 获取 模版
|
||||
String template = templateService.getTemplateTypeContent(TemplateTypeEnum.MENU_DATA_INFO);
|
||||
if (template == null){
|
||||
return;
|
||||
}
|
||||
// 流
|
||||
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
||||
zos = new ZipOutputStream(outputStream);
|
||||
|
||||
// 平台角色
|
||||
STGroup group = new STGroupString("dbXml",template, '$', '$');
|
||||
// 平台角色 功能权限
|
||||
ST menuTemplate = group.getInstanceOf("menuTemplate"); // 使用正确的模板名称
|
||||
List<MenuEntity> menuEntities = menuMapper.selectAll();
|
||||
menuEntities.sort(Comparator.comparing(MenuEntity::getId));
|
||||
menuTemplate.add("menus",menuEntities);
|
||||
writeCodeToZip(menuTemplate);
|
||||
|
||||
// 确保 ZIP 流结束
|
||||
zos.finish();
|
||||
// 返回数据
|
||||
this.getSlot().setResponseData(outputStream.toByteArray());
|
||||
}
|
||||
|
||||
private void writeCodeToZip(ST st) throws IOException {
|
||||
// 生成代码
|
||||
String result = st.render();
|
||||
ZipEntry entry = new ZipEntry("insert-menus-data.xml");
|
||||
zos.putNextEntry(entry);
|
||||
zos.write(result.getBytes(StandardCharsets.UTF_8));
|
||||
zos.closeEntry();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,121 @@
|
||||
package com.cczsa.xinghe.codegen.service.flow.template;
|
||||
|
||||
import com.cczsa.xinghe.codegen.entity.FunOperationEntity;
|
||||
import com.cczsa.xinghe.codegen.entity.enums.ClientTypeEnum;
|
||||
import com.cczsa.xinghe.codegen.entity.enums.TemplateTypeEnum;
|
||||
import com.cczsa.xinghe.codegen.mapper.FunOperationMapper;
|
||||
import com.cczsa.xinghe.codegen.mapper.def.FunItemDef;
|
||||
import com.cczsa.xinghe.codegen.mapper.def.FunOperationDef;
|
||||
import com.cczsa.xinghe.codegen.service.TemplateService;
|
||||
import com.mybatisflex.core.query.QueryWrapper;
|
||||
import com.yomahub.liteflow.annotation.LiteflowComponent;
|
||||
import com.yomahub.liteflow.core.NodeComponent;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.stringtemplate.v4.ST;
|
||||
import org.stringtemplate.v4.STGroup;
|
||||
import org.stringtemplate.v4.STGroupString;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.zip.ZipEntry;
|
||||
import java.util.zip.ZipOutputStream;
|
||||
|
||||
/**
|
||||
* 角色 套餐权限相关数据生成
|
||||
* @author xia
|
||||
* @date 2026/1/23
|
||||
* @version 0.0.1
|
||||
*/
|
||||
@Slf4j
|
||||
@RequiredArgsConstructor
|
||||
@LiteflowComponent(id = "roleDataInfo", name = "角色 套餐权限相关数据生成")
|
||||
public class RoleDataInfo extends NodeComponent {
|
||||
|
||||
private final FunOperationMapper funOperationMapper;
|
||||
private final TemplateService templateService;
|
||||
|
||||
// 压缩流
|
||||
private ZipOutputStream zos;
|
||||
|
||||
|
||||
@Override
|
||||
public void process() throws Exception {
|
||||
// 获取 模版
|
||||
String template = templateService.getTemplateTypeContent(TemplateTypeEnum.ROLE_DATA_INFO);
|
||||
if (template == null){
|
||||
return;
|
||||
}
|
||||
// 流
|
||||
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
||||
zos = new ZipOutputStream(outputStream);
|
||||
|
||||
|
||||
// 平台角色
|
||||
STGroup group = new STGroupString("dbXml",template, '$', '$');
|
||||
|
||||
|
||||
// 功能数据生成
|
||||
FunOperationDef funOperationDef = FunOperationDef.FUN_OPERATION_ENTITY.as("o");
|
||||
FunItemDef funItemDef = FunItemDef.FUN_ITEM_ENTITY.as("i");
|
||||
QueryWrapper wrapper = QueryWrapper.create()
|
||||
.select(funOperationDef.ALL_COLUMNS)
|
||||
.from(funItemDef)
|
||||
.leftJoin(funOperationDef).on(funOperationDef.ITEM_ID.eq(funItemDef.ID))
|
||||
.where(funItemDef.IS_TENANT.eq(false))
|
||||
.and(funOperationDef.IS_GREEN_LIGHT.eq(false));
|
||||
List<FunOperationEntity> funOperationEntities = funOperationMapper.selectListByQuery(wrapper);
|
||||
|
||||
funOperationEntities.sort(Comparator.comparing(FunOperationEntity::getId));
|
||||
// 循环 ClientTypeEnum
|
||||
for (ClientTypeEnum clientTypeEnum : ClientTypeEnum.values()) {
|
||||
// 平台角色 功能权限
|
||||
ST roleBindFunTemplate = group.getInstanceOf("roleBindFunTemplate"); // 使用正确的模板名称
|
||||
roleBindFunTemplate.add("operations",funOperationEntities);
|
||||
roleBindFunTemplate.add("clientTypeCode",clientTypeEnum.getCode());
|
||||
roleBindFunTemplate.add("clientTypeDesc",clientTypeEnum.getDesc());
|
||||
writeCodeToZip(roleBindFunTemplate,"roleBindFun-"+clientTypeEnum.getDesc());
|
||||
}
|
||||
|
||||
|
||||
QueryWrapper wrapper2 = QueryWrapper.create()
|
||||
.select(funOperationDef.ALL_COLUMNS)
|
||||
.from(funItemDef)
|
||||
.leftJoin(funOperationDef).on(funOperationDef.ITEM_ID.eq(funItemDef.ID))
|
||||
.where(funItemDef.IS_TENANT.eq(true))
|
||||
.and(funOperationDef.IS_GREEN_LIGHT.eq(false));
|
||||
List<FunOperationEntity> mealsFun = funOperationMapper.selectListByQuery(wrapper2);
|
||||
mealsFun.sort(Comparator.comparing(FunOperationEntity::getId));
|
||||
// 功能数据生成
|
||||
for (ClientTypeEnum clientTypeEnum : ClientTypeEnum.values()) {
|
||||
// 平台套餐 功能权限
|
||||
ST mealBindFunTemplate = group.getInstanceOf("mealBindFunTemplate"); // 使用正确的模板名称
|
||||
mealBindFunTemplate.add("meals",mealsFun);
|
||||
mealBindFunTemplate.add("clientTypeCode",clientTypeEnum.getCode());
|
||||
mealBindFunTemplate.add("clientTypeDesc",clientTypeEnum.getDesc());
|
||||
writeCodeToZip(mealBindFunTemplate,"mealBindFun-"+clientTypeEnum.getDesc());
|
||||
}
|
||||
|
||||
|
||||
// 确保 ZIP 流结束
|
||||
zos.finish();
|
||||
// 返回数据
|
||||
this.getSlot().setResponseData(outputStream.toByteArray());
|
||||
}
|
||||
|
||||
|
||||
|
||||
private void writeCodeToZip(ST st,String fileName) throws IOException {
|
||||
// 生成代码
|
||||
String result = st.render();
|
||||
// insert-ms-fun-operation-data.xml
|
||||
ZipEntry entry = new ZipEntry("insert-"+ fileName +"-data.xml");
|
||||
zos.putNextEntry(entry);
|
||||
zos.write(result.getBytes(StandardCharsets.UTF_8));
|
||||
zos.closeEntry();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.cczsa.xinghe.codegen.service.impl;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.cczsa.xinghe.codegen.entity.FunItemEntity;
|
||||
import com.cczsa.xinghe.codegen.entity.FunOperationEntity;
|
||||
import com.cczsa.xinghe.codegen.entity.MenuEntity;
|
||||
@@ -11,11 +12,12 @@ import com.cczsa.xinghe.codegen.entity.res.menu.MenuQueryRes;
|
||||
import com.cczsa.xinghe.codegen.mapper.FunItemMapper;
|
||||
import com.cczsa.xinghe.codegen.mapper.FunOperationMapper;
|
||||
import com.cczsa.xinghe.codegen.mapper.MenuMapper;
|
||||
import com.cczsa.xinghe.codegen.mapper.RoleFunMapper;
|
||||
import com.cczsa.xinghe.codegen.mapper.def.FunOperationDef;
|
||||
import com.cczsa.xinghe.codegen.mapper.def.MenuDef;
|
||||
import com.cczsa.xinghe.codegen.mapper.def.RoleFunDef;
|
||||
import com.cczsa.xinghe.codegen.service.MenuService;
|
||||
import com.cczsa.xinghe.codegen.util.XResult;
|
||||
import com.github.xiaoymin.knife4j.core.util.StrUtil;
|
||||
import com.mybatisflex.core.query.QueryWrapper;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
@@ -40,6 +42,7 @@ public class MenuServiceImpl implements MenuService {
|
||||
private final MenuMapper menuMapper;
|
||||
private final FunOperationMapper funOperationMapper;
|
||||
private final FunItemMapper funItemMapper;
|
||||
private final RoleFunMapper roleFunMapper;
|
||||
|
||||
|
||||
/**
|
||||
@@ -198,9 +201,20 @@ public class MenuServiceImpl implements MenuService {
|
||||
if (count > 0) {
|
||||
return XResult.failed("请先删除子菜单");
|
||||
}
|
||||
QueryWrapper deleteMenu = new QueryWrapper();
|
||||
deleteMenu.eq(MenuEntity::getId, id);
|
||||
menuMapper.deleteByQuery(deleteMenu);
|
||||
// 获取菜单
|
||||
MenuEntity menuEntity = menuMapper.selectOneById(id);
|
||||
// 删除配置的角色
|
||||
if (menuEntity != null && menuEntity.getFunId() != null){
|
||||
// 删除角色的权限
|
||||
RoleFunDef roleFunDef = RoleFunDef.ROLE_FUN_ENTITY;
|
||||
QueryWrapper deleteRoleFun = new QueryWrapper();
|
||||
deleteRoleFun.from(roleFunDef);
|
||||
deleteRoleFun.where(roleFunDef.CLIENT_TYPE.eq(menuEntity.getClientType()));
|
||||
deleteRoleFun.and(roleFunDef.FUN_ID.eq(menuEntity.getFunId()));
|
||||
roleFunMapper.deleteByQuery(deleteRoleFun);
|
||||
}
|
||||
// 删除菜单
|
||||
menuMapper.deleteById(id);
|
||||
return XResult.ok();
|
||||
}
|
||||
|
||||
@@ -211,9 +225,7 @@ public class MenuServiceImpl implements MenuService {
|
||||
@Override
|
||||
public XResult<Void> bindFun(MenuBindFunReq req) {
|
||||
// 获取菜单
|
||||
QueryWrapper queryMenu = new QueryWrapper();
|
||||
queryMenu.eq(MenuEntity::getId, req.getMenuId());
|
||||
MenuEntity menuEntity = menuMapper.selectOneByQuery(queryMenu);
|
||||
MenuEntity menuEntity = menuMapper.selectOneById(req.getMenuId());
|
||||
if (menuEntity == null) {
|
||||
return XResult.failed("菜单不存在");
|
||||
}
|
||||
@@ -237,23 +249,47 @@ public class MenuServiceImpl implements MenuService {
|
||||
}
|
||||
menuEntity.setFunId(req.getFunId());
|
||||
menuMapper.update(menuEntity);
|
||||
|
||||
// 删除配置的角色操作权限
|
||||
RoleFunDef roleFunDef = RoleFunDef.ROLE_FUN_ENTITY;
|
||||
QueryWrapper wrapper = new QueryWrapper();
|
||||
wrapper.from(roleFunDef);
|
||||
wrapper.where(roleFunDef.CLIENT_TYPE.eq(menuEntity.getClientType()));
|
||||
wrapper.and(roleFunDef.FUN_ID.eq(req.getFunId()));
|
||||
|
||||
return XResult.ok();
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除菜单权限
|
||||
*/
|
||||
@Transactional
|
||||
@Override
|
||||
public XResult<Void> deleteFun(Long menuId) {
|
||||
// 获取菜单
|
||||
QueryWrapper queryMenu = new QueryWrapper();
|
||||
queryMenu.eq(MenuEntity::getId, menuId);
|
||||
MenuEntity menuEntity = menuMapper.selectOneByQuery(queryMenu);
|
||||
|
||||
if (menuEntity == null) {
|
||||
return XResult.failed("菜单不存在");
|
||||
}
|
||||
Long funId = menuEntity.getFunId();
|
||||
if (funId == null) {
|
||||
return XResult.failed("菜单未绑定权限");
|
||||
}
|
||||
|
||||
menuEntity.setFunId(null);
|
||||
menuMapper.update(menuEntity, false);
|
||||
|
||||
// 删除配置的 角色绑定操作权限
|
||||
RoleFunDef roleFunDef = RoleFunDef.ROLE_FUN_ENTITY;
|
||||
QueryWrapper wrapper = new QueryWrapper();
|
||||
wrapper.from(roleFunDef);
|
||||
wrapper.where(roleFunDef.CLIENT_TYPE.eq(menuEntity.getClientType()));
|
||||
wrapper.and(roleFunDef.FUN_ID.eq(funId));
|
||||
|
||||
roleFunMapper.deleteByQuery(wrapper);
|
||||
return XResult.ok();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user