This commit is contained in:
20932067@zju.edu.cn 2021-01-28 18:52:50 +08:00
parent 17358bf2cd
commit 59dd327214
6 changed files with 49 additions and 16 deletions

View File

@ -238,12 +238,12 @@ public class GenTableServiceImpl implements IGenTableService {
// 获取模板列表
List<String> 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;

View File

@ -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<String,String> 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<Map<String, String>>(true,dataMap);
}catch (RuntimeException e){
logger.error(e.getMessage());
@ -219,13 +224,17 @@ public class InterTableServiceImpl implements InterTableService {
List<InterTable> interTableList = interTableDao.selectInterTableModule(mid);
VelocityInitializer.initVelocity();
List<VelocityContext> contextList = InterTableUtils.prepareMoudleContext(interTableList);
String templates = InterTableUtils.getTemplateList(2);
Map<String,String> 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<Map<String,Object>>(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";
}
}

View File

@ -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<VelocityContext> prepareMoudleContext(List<InterTable> 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<String,String> getTemplateList(Integer type) {
Map<String,String> templates = new HashMap<String,String>();
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();
}
}

View File

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

View File

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