|
|
@@ -0,0 +1,144 @@
|
|
|
+package org.dromara.system;
|
|
|
+
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+public class MenuSqlGenerator {
|
|
|
+
|
|
|
+ // 内部类:模拟菜单数据结构
|
|
|
+ static class MenuItem {
|
|
|
+ String path;
|
|
|
+ String title;
|
|
|
+ String icon;
|
|
|
+ List<MenuItem> children;
|
|
|
+
|
|
|
+ public MenuItem(String path, String title, String icon) {
|
|
|
+ this.path = path;
|
|
|
+ this.title = title;
|
|
|
+ this.icon = icon;
|
|
|
+ this.children = new ArrayList<>();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public static void main(String[] args) {
|
|
|
+ // 1. 构建数据源 (模拟你提供的JSON数组)
|
|
|
+ List<MenuItem> menus = new ArrayList<>();
|
|
|
+
|
|
|
+ // --- 企业账户 ---
|
|
|
+ MenuItem enterprise = new MenuItem("/enterprise", "企业账户", "workbench1");
|
|
|
+ enterprise.children.add(new MenuItem("/enterprise/companyInfo", "企业信息", ""));
|
|
|
+ enterprise.children.add(new MenuItem("/enterprise/messageNotice", "消息通知", ""));
|
|
|
+ enterprise.children.add(new MenuItem("/easybuv", "地址管理", "")); // 注意:原数据path似乎不在enterprise下,这里按原样保留
|
|
|
+ enterprise.children.add(new MenuItem("/enterprise/invoiceManage", "发票抬头管理", ""));
|
|
|
+ enterprise.children.add(new MenuItem("/enterprise/purchasePlan", "专属采购方案", ""));
|
|
|
+ enterprise.children.add(new MenuItem("/enterprise/agreementSupply", "协议供货", ""));
|
|
|
+ enterprise.children.add(new MenuItem("/enterprise/myCollection", "我的收藏", ""));
|
|
|
+ enterprise.children.add(new MenuItem("/enterprise/purchaseHistory", "历史购买", ""));
|
|
|
+ enterprise.children.add(new MenuItem("/enterprise/myFootprint", "我的足迹", ""));
|
|
|
+ menus.add(enterprise);
|
|
|
+
|
|
|
+ // --- 交易管理 ---
|
|
|
+ MenuItem order = new MenuItem("/order", "交易管理", "workbench2");
|
|
|
+ order.children.add(new MenuItem("/order/orderManage", "订单管理", ""));
|
|
|
+ order.children.add(new MenuItem("/order/orderAudit", "审核订单", ""));
|
|
|
+ order.children.add(new MenuItem("/order/afterSale", "售后服务", ""));
|
|
|
+ order.children.add(new MenuItem("/order/batchOrder", "批量下单", ""));
|
|
|
+ order.children.add(new MenuItem("/order/orderEvaluation", "订单评价", ""));
|
|
|
+ menus.add(order);
|
|
|
+
|
|
|
+ // --- 组织管理 ---
|
|
|
+ MenuItem org = new MenuItem("/organization", "组织管理", "workbench3");
|
|
|
+ org.children.add(new MenuItem("/i", "个人信息", ""));
|
|
|
+ org.children.add(new MenuItem("/organization/deptManage", "部门管理", ""));
|
|
|
+ org.children.add(new MenuItem("/organization/staffManage", "人员管理", ""));
|
|
|
+ org.children.add(new MenuItem("/organization/roleManage", "角色管理", ""));
|
|
|
+ org.children.add(new MenuItem("/organization/approvalFlow", "审批流程", ""));
|
|
|
+ org.children.add(new MenuItem("/organization/groupEnterprise", "集团关联企业", ""));
|
|
|
+ menus.add(org);
|
|
|
+
|
|
|
+ // --- 成本管理 ---
|
|
|
+ MenuItem cost = new MenuItem("/cost", "成本管理", "workbench4");
|
|
|
+ cost.children.add(new MenuItem("/cost/itemExpense", "分项费用", ""));
|
|
|
+ cost.children.add(new MenuItem("/cost/quotaControl", "额度控制", ""));
|
|
|
+ menus.add(cost);
|
|
|
+
|
|
|
+ // --- 对账管理 ---
|
|
|
+ MenuItem recon = new MenuItem("/reconciliation", "对账管理", "workbench5");
|
|
|
+ recon.children.add(new MenuItem("/reconciliation/billManage", "对账单管理", ""));
|
|
|
+ recon.children.add(new MenuItem("/reconciliation/invoiceManage", "开票管理", ""));
|
|
|
+ menus.add(recon);
|
|
|
+
|
|
|
+ // --- 增值服务 ---
|
|
|
+ MenuItem valueAdded = new MenuItem("/valueAdded", "增值服务", "workbench6");
|
|
|
+ valueAdded.children.add(new MenuItem("/valueAdded/maintenance", "维保服务", ""));
|
|
|
+ valueAdded.children.add(new MenuItem("/valueAdded/complaint", "投诉与建议", ""));
|
|
|
+ menus.add(valueAdded);
|
|
|
+
|
|
|
+ // --- 采购分析 ---
|
|
|
+ MenuItem analysis = new MenuItem("/analysis", "采购分析", "workbench7");
|
|
|
+ analysis.children.add(new MenuItem("/analysis/orderAnalysis", "订单交易分析", ""));
|
|
|
+ analysis.children.add(new MenuItem("/analysis/purchaseDetail", "商品采购明细", ""));
|
|
|
+ analysis.children.add(new MenuItem("/analysis/orderStatus", "订单执行状态", ""));
|
|
|
+ analysis.children.add(new MenuItem("/analysis/settlementStatus", "对账结算状况", ""));
|
|
|
+ analysis.children.add(new MenuItem("/analysis/deptPurchase", "部门采购金额", ""));
|
|
|
+ menus.add(analysis);
|
|
|
+
|
|
|
+ // 2. 执行生成
|
|
|
+ generateSql(menus);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 生成SQL逻辑
|
|
|
+ */
|
|
|
+ public static void generateSql(List<MenuItem> menus) {
|
|
|
+ // 基础ID计数器,模拟数据库自增或雪花算法
|
|
|
+ long currentId = 2049013816429805570L;
|
|
|
+
|
|
|
+ StringBuilder sqlBuilder = new StringBuilder();
|
|
|
+ String tableName = "yoe_system_db.sys_menu";
|
|
|
+
|
|
|
+ // 公共字段常量
|
|
|
+ String component = "NULL"; // 根据你的参考SQL,component 都是 NULL
|
|
|
+ String queryParam = "NULL";
|
|
|
+ int isFrame = 1;
|
|
|
+ int isCache = 0;
|
|
|
+ int visible = 0;
|
|
|
+ int status = 0;
|
|
|
+ String perms = "NULL";
|
|
|
+ String createDept = "103";
|
|
|
+ String createBy = "1";
|
|
|
+ String createTime = "NOW()"; // 使用数据库函数或填入具体时间字符串
|
|
|
+ String updateBy = "1";
|
|
|
+ String updateTime = "NOW()";
|
|
|
+ String remark = "";
|
|
|
+ String platformCode = "home";
|
|
|
+
|
|
|
+ for (MenuItem menu : menus) {
|
|
|
+ // --- 生成父级菜单 SQL ---
|
|
|
+ long parentId = currentId++;
|
|
|
+ String parentPath = menu.path.replace("/", ""); // 去除斜杠作为path字段
|
|
|
+
|
|
|
+ sqlBuilder.append(String.format(
|
|
|
+ "INSERT INTO `%s` (`menu_id`, `menu_name`, `parent_id`, `order_num`, `path`, `component`, `query_param`, `is_frame`, `is_cache`, `menu_type`, `visible`, `status`, `perms`, `icon`, `create_dept`, `create_by`, `create_time`, `update_by`, `update_time`, `remark`, `platform_code`) VALUES (%d, '%s', 0, 1, '%s', %s, %s, %d, %d, 'M', '%d', '%d', %s, '%s', %s, %s, %s, %s, %s, '%s', '%s');\n",
|
|
|
+ tableName, parentId, menu.title, parentPath, component, queryParam, isFrame, isCache, visible, status, perms, menu.icon, createDept, createBy, createTime, updateBy, updateTime, remark, platformCode
|
|
|
+ ));
|
|
|
+
|
|
|
+ // --- 生成子级菜单 SQL ---
|
|
|
+ int childOrder = 1;
|
|
|
+ for (MenuItem child : menu.children) {
|
|
|
+ long childId = currentId++;
|
|
|
+ String childPath = child.path.startsWith("/") ? child.path.substring(1) : child.path;
|
|
|
+
|
|
|
+ sqlBuilder.append(String.format(
|
|
|
+ "INSERT INTO `%s` (`menu_id`, `menu_name`, `parent_id`, `order_num`, `path`, `component`, `query_param`, `is_frame`, `is_cache`, `menu_type`, `visible`, `status`, `perms`, `icon`, `create_dept`, `create_by`, `create_time`, `update_by`, `update_time`, `remark`, `platform_code`) VALUES (%d, '%s', %d, %d, '%s', %s, %s, %d, %d, 'C', '%d', '%d', %s, '%s', %s, %s, %s, %s, %s, '%s', '%s');\n",
|
|
|
+ tableName, childId, child.title, parentId, childOrder, childPath, component,
|
|
|
+ queryParam, isFrame, isCache, visible, status, perms, child.icon, createDept, createBy, createTime, updateBy, updateTime, remark, platformCode
|
|
|
+ ));
|
|
|
+ childOrder++;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 3. 输出结果
|
|
|
+ System.out.println(sqlBuilder.toString());
|
|
|
+ }
|
|
|
+}
|