diff --git a/hchyun/hchyun-generator/src/main/java/com/hchyun/generator/service/impl/GenTableServiceImpl.java b/hchyun/hchyun-generator/src/main/java/com/hchyun/generator/service/impl/GenTableServiceImpl.java index 78d1e02..16aac60 100644 --- a/hchyun/hchyun-generator/src/main/java/com/hchyun/generator/service/impl/GenTableServiceImpl.java +++ b/hchyun/hchyun-generator/src/main/java/com/hchyun/generator/service/impl/GenTableServiceImpl.java @@ -238,12 +238,12 @@ public class GenTableServiceImpl implements IGenTableService { // 获取模板列表 List templates = VelocityUtils.getTemplateList(table.getTplCategory()); for (String template : templates) { - if (!StringUtils.containsAny(template, "sql.vm" , "api.js.vm" , "index.vue.vm" , "index-tree.vue.vm")) { + if (!StringUtils.containsAny(template, "table.sql.vm" , "api.js.vm" , "index.vue.vm" , "index-tree.vue.vm")) { // 渲染模板 StringWriter sw = new StringWriter(); Template tpl = Velocity.getTemplate(template, Constants.UTF8); tpl.merge(context, sw); - if (template.equals("vm/sql/sql.vm")) { + if (template.equals("vm/sql/table.sql.vm")) { Boolean start = insertMenuItem(sw); if (start){ return false; @@ -352,7 +352,7 @@ public class GenTableServiceImpl implements IGenTableService { Template tpl = Velocity.getTemplate(template, Constants.UTF8); tpl.merge(context, sw); - if (template.equals("vm/sql/sql.vm")) { + if (template.equals("vm/sql/table.sql.vm")) { Boolean start = insertMenuItem(sw); if (start){ return null; diff --git a/hchyun/hchyun-generator/src/main/java/com/hchyun/generator/service/impl/InterTableServiceImpl.java b/hchyun/hchyun-generator/src/main/java/com/hchyun/generator/service/impl/InterTableServiceImpl.java index 8f7a05a..5355973 100644 --- a/hchyun/hchyun-generator/src/main/java/com/hchyun/generator/service/impl/InterTableServiceImpl.java +++ b/hchyun/hchyun-generator/src/main/java/com/hchyun/generator/service/impl/InterTableServiceImpl.java @@ -200,11 +200,16 @@ public class InterTableServiceImpl implements InterTableService { Apiclass apiclass = interTableDao.selectInterTableClass(cid); VelocityInitializer.initVelocity(); VelocityContext context = InterTableUtils.prepareClassContext(apiclass); - String templates = InterTableUtils.getTemplateList(2); + Map templates = InterTableUtils.getTemplateList(2); StringWriter sw = new StringWriter(); - Template template = Velocity.getTemplate(templates, Constants.UTF8); + Template template = Velocity.getTemplate(templates.get("java"), Constants.UTF8); template.merge(context,sw); dataMap.put(getJavaClassName(apiclass.getcName()),sw.toString()); + + sw = new StringWriter(); + template = Velocity.getTemplate(templates.get("sql"),Constants.UTF8); + template.merge(context,sw); + dataMap.put(getSqlName(apiclass.getcName()),sw.toString()); return new ServerResult>(true,dataMap); }catch (RuntimeException e){ logger.error(e.getMessage()); @@ -219,13 +224,17 @@ public class InterTableServiceImpl implements InterTableService { List interTableList = interTableDao.selectInterTableModule(mid); VelocityInitializer.initVelocity(); List contextList = InterTableUtils.prepareMoudleContext(interTableList); - String templates = InterTableUtils.getTemplateList(2); + Map templates = InterTableUtils.getTemplateList(2); + StringWriter sqlsw = new StringWriter(); + Template sqltemplate = Velocity.getTemplate(templates.get("sql"),Constants.UTF8); for (VelocityContext context : contextList){ StringWriter sw = new StringWriter(); - Template template = Velocity.getTemplate(templates, Constants.UTF8); + Template template = Velocity.getTemplate(templates.get("java"), Constants.UTF8); template.merge(context,sw); + sqltemplate.merge(context,sqlsw); dataMap.put(getJavaClassName((String) context.get("ClassName")),sw.toString()); } + dataMap.put(getSqlName("module"),sqlsw.toString()); return new ServerResult>(true,dataMap); }catch (RuntimeException e){ logger.error(e.getMessage()); @@ -236,4 +245,7 @@ public class InterTableServiceImpl implements InterTableService { public String getJavaClassName(String cName){ return InterTableUtils.getUpperCase(cName) + "Controller.java"; } + public String getSqlName(String cName){ + return InterTableUtils.getUpperCase(cName) + ".sql"; + } } \ No newline at end of file diff --git a/hchyun/hchyun-generator/src/main/java/com/hchyun/generator/util/InterTableUtils.java b/hchyun/hchyun-generator/src/main/java/com/hchyun/generator/util/InterTableUtils.java index bd294f3..f1b6766 100644 --- a/hchyun/hchyun-generator/src/main/java/com/hchyun/generator/util/InterTableUtils.java +++ b/hchyun/hchyun-generator/src/main/java/com/hchyun/generator/util/InterTableUtils.java @@ -1,12 +1,15 @@ package com.hchyun.generator.util; import com.hchyun.common.utils.DateUtils; +import com.hchyun.common.utils.SecurityUtils; import com.hchyun.generator.entity.Apiclass; import com.hchyun.generator.entity.InterTable; import org.apache.velocity.VelocityContext; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; +import java.util.Map; public class InterTableUtils { public static List prepareMoudleContext(List interTableList) { @@ -56,6 +59,7 @@ public class InterTableUtils { permission = true; } } + velocityContext.put("createBy", SecurityUtils.getUserId()); velocityContext.put("Permission", permission); velocityContext.put("packageName", "com.huhyun."+module); velocityContext.put("prefix",module+":"+getLowerCase(className)); @@ -80,6 +84,7 @@ public class InterTableUtils { permission = true; } } + velocityContext.put("createBy", SecurityUtils.getUserId()); velocityContext.put("Permission", permission); velocityContext.put("packageName", apiclass.getPackageName()); velocityContext.put("ClassName", getUpperCase(apiclass.getcName())); @@ -97,11 +102,10 @@ public class InterTableUtils { return "/" + getLowerCase(mname) + "/" + getLowerCase(cname); } - public static String getTemplateList(Integer type) { - String templates = "vm/java/class.java.vm"; - if (type == 1) { - templates = "vm/java/module.java.vm"; - } + public static Map getTemplateList(Integer type) { + Map templates = new HashMap(); + templates.put("java","vm/java/class.java.vm"); + templates.put("sql","vm/sql/class.sql.vm"); return templates; } @@ -110,6 +114,6 @@ public class InterTableUtils { } public static String getLowerCase(String str) { - return str.substring(0, 1).toLowerCase() + str.substring(1); + return str.toLowerCase(); } } diff --git a/hchyun/hchyun-generator/src/main/java/com/hchyun/generator/util/VelocityUtils.java b/hchyun/hchyun-generator/src/main/java/com/hchyun/generator/util/VelocityUtils.java index 3df2dae..cb00559 100644 --- a/hchyun/hchyun-generator/src/main/java/com/hchyun/generator/util/VelocityUtils.java +++ b/hchyun/hchyun-generator/src/main/java/com/hchyun/generator/util/VelocityUtils.java @@ -59,7 +59,6 @@ public class VelocityUtils { velocityContext.put("packageName", packageName); velocityContext.put("author", genTable.getFunctionAuthor()); velocityContext.put("datetime", DateUtils.getDate()); -// velocityContext.put("createTime", DateUtils.getTime()); velocityContext.put("createBy", SecurityUtils.getUserId()); velocityContext.put("pkColumn", genTable.getPkColumn()); velocityContext.put("importList", getImportList(genTable)); @@ -132,7 +131,7 @@ public class VelocityUtils { templates.add("vm/java/serviceImpl.java.vm"); templates.add("vm/java/controller.java.vm"); templates.add("vm/xml/mapper.xml.vm"); - templates.add("vm/sql/sql.vm"); + templates.add("vm/sql/table.sql.vm"); templates.add("vm/js/api.js.vm"); if (GenConstants.TPL_CRUD.equals(tplCategory)) { templates.add("vm/vue/index.vue.vm"); @@ -179,7 +178,7 @@ public class VelocityUtils { fileName = StringUtils.format("{}/controller/{}Controller.java", javaPath, className); } else if (template.contains("mapper.xml.vm")) { fileName = StringUtils.format("{}/{}Mapper.xml", mybatisPath, className); - } else if (template.contains("sql.vm")) { + } else if (template.contains("table.sql.vm")) { fileName = businessName + "Menu.sql"; } else if (template.contains("api.js.vm")) { fileName = StringUtils.format("{}/api/{}/{}.js", vuePath, moduleName, businessName); diff --git a/hchyun/hchyun-generator/src/main/resources/vm/sql/class.sql.vm b/hchyun/hchyun-generator/src/main/resources/vm/sql/class.sql.vm new file mode 100644 index 0000000..52471a8 --- /dev/null +++ b/hchyun/hchyun-generator/src/main/resources/vm/sql/class.sql.vm @@ -0,0 +1,18 @@ +-- ${functionName}Controller + +delete from sys_menu where perms= '${prefix}'; + +insert into sys_menu (menu_name, parent_id, order_num, path, component, is_frame, is_cache, menu_type, visible, status, perms, icon, create_by, create_time, update_by, update_time, remark) +values('${functionName}', 5, '1', '#','' ,1, 0, 'F', '0', '0', '${prefix}','#', ${createBy}, sysdate(), 0, null, '${functionName}接口管理'); + +SELECT @parentId := LAST_INSERT_ID(); +#foreach($column in $columns) +#if($column.isGenerate.equals("1")) + +delete from sys_menu where perms= '${prefix}:${column.requrl}'; + +insert into sys_menu (menu_name, parent_id, order_num, path, component, is_frame, is_cache, menu_type, visible, status, perms, icon, create_by, create_time, update_by, update_time, remark) +values('${column.itDescribe}', @parentId, '1', '#', '', 1, 0, 'F', '0', '0', '${prefix}:${column.requrl}', '#', ${createBy}, sysdate(), 0, null, ''); +#end +#end + diff --git a/hchyun/hchyun-generator/src/main/resources/vm/sql/sql.vm b/hchyun/hchyun-generator/src/main/resources/vm/sql/table.sql.vm similarity index 100% rename from hchyun/hchyun-generator/src/main/resources/vm/sql/sql.vm rename to hchyun/hchyun-generator/src/main/resources/vm/sql/table.sql.vm