添加多个基础模板,修复细节问题。

This commit is contained in:
makejava 2018-07-19 14:14:54 +08:00
parent 7f11748d60
commit 5a19e37707
9 changed files with 172 additions and 13 deletions

View File

@ -100,6 +100,9 @@ public class ConfigInfo implements PersistentStateComponent<ConfigInfo> {
List<Template> templateList = new ArrayList<>();
templateList.add(new Template("entity", loadTemplate("entity")));
templateList.add(new Template("dao", loadTemplate("dao")));
templateList.add(new Template("service", loadTemplate("service")));
templateList.add(new Template("serviceImpl", loadTemplate("serviceImpl")));
templateList.add(new Template("controller", loadTemplate("controller")));
templateGroup.setName(DEFAULT_NAME);
templateGroup.setElementList(templateList);
this.templateGroupMap.put(DEFAULT_NAME, templateGroup);
@ -113,6 +116,7 @@ public class ConfigInfo implements PersistentStateComponent<ConfigInfo> {
typeMapperList.add(new TypeMapper("varchar(\\(\\d+\\))?", "java.lang.String"));
typeMapperList.add(new TypeMapper("decimal(\\(\\d+\\))?", "java.lang.Double"));
typeMapperList.add(new TypeMapper("integer", "java.lang.Integer"));
typeMapperList.add(new TypeMapper("int(\\(\\d+\\))?", "java.lang.Integer"));
typeMapperList.add(new TypeMapper("int4", "java.lang.Integer"));
typeMapperList.add(new TypeMapper("int8", "java.lang.Long"));
typeMapperList.add(new TypeMapper("bigint", "java.lang.Long"));
@ -130,7 +134,6 @@ public class ConfigInfo implements PersistentStateComponent<ConfigInfo> {
ColumnConfigGroup columnConfigGroup = new ColumnConfigGroup();
List<ColumnConfig> columnConfigList = new ArrayList<>();
columnConfigList.add(new ColumnConfig("disable", ColumnConfigType.BOOLEAN));
columnConfigList.add(new ColumnConfig("type", ColumnConfigType.SELECT, "ENUM,SELECT,RADIO,CHECKBOX"));
columnConfigGroup.setName(DEFAULT_NAME);
columnConfigGroup.setElementList(columnConfigList);
columnConfigGroupMap.put(DEFAULT_NAME, columnConfigGroup);

View File

@ -0,0 +1,54 @@
package com.sjhy.plugin.tool;
import java.text.SimpleDateFormat;
import java.util.Date;
/**
* 时间工具类
*
* @author makejava
* @version 1.0.0
* @since 2018/07/19 13:16
*/
public class TimeUtils {
private static volatile TimeUtils timeUtils;
/**
* 单例模式
*
* @return 实例对象
*/
public static TimeUtils getInstance() {
if (timeUtils == null) {
synchronized (TimeUtils.class) {
if (timeUtils == null) {
timeUtils = new TimeUtils();
}
}
}
return timeUtils;
}
private TimeUtils() {
}
/**
* 获取指定格式的时间字符串
*
* @param pattern 格式
* @return 时间字符串
*/
public String currTime(String pattern) {
return new SimpleDateFormat(pattern).format(new Date());
}
/**
* 获取默认格式的时间字符串yyyy-MM-dd HH:mm:ss
*
* @return 时间字符串
*/
public String currTime() {
return currTime("yyyy-MM-dd HH:mm:ss");
}
}

View File

@ -114,6 +114,7 @@ public class VelocityUtils {
map.put("author", author);
//工具类
map.put("tool", nameUtils);
map.put("time", TimeUtils.getInstance());
//设置的包名
map.put("packageName", cacheDataUtils.getPackageName());
if (selectModule != null) {
@ -240,21 +241,37 @@ public class VelocityUtils {
* @return 覆盖后的表配置信息
*/
private List<TableInfo> coverConfigInfo() {
// 选择的module名称
final String moduleName;
if (cacheDataUtils.getSelectModule()!=null) {
moduleName = cacheDataUtils.getSelectModule().getName();
} else {
moduleName = null;
}
AtomicBoolean isSave = new AtomicBoolean(false);
List<TableInfo> tableInfoList = tableInfoUtils.handler(cacheDataUtils.getDbTableList());
// 将选中表中的没有保存配置信息的表进行保存
tableInfoList.forEach(tableInfo -> {
// 只有所有项目都是空的才会进行覆盖保存
if (StringUtils.isEmpty(tableInfo.getSaveModelName()) && StringUtils.isEmpty(tableInfo.getSavePath()) && StringUtils.isEmpty(tableInfo.getSavePackageName())) {
tableInfo.setSavePath(cacheDataUtils.getSavePath());
tableInfo.setSavePackageName(cacheDataUtils.getPackageName());
if (cacheDataUtils.getSelectModule()!=null) {
tableInfo.setSaveModelName(cacheDataUtils.getSelectModule().getName());
// 输入当前表是选中表
if (tableInfo.getObj()==cacheDataUtils.getSelectDbTable()) {
// 只要所有保存信息都没修改就不进行覆盖保存
if (Objects.equals(tableInfo.getSavePath(), cacheDataUtils.getSavePath()) && Objects.equals(moduleName, tableInfo.getSaveModelName()) && Objects.equals(tableInfo.getSavePackageName(), cacheDataUtils.getPackageName())) {
return;
}
} else {
// 只要存在任意一项保存信息就不进行覆盖保存
if (!StringUtils.isEmpty(tableInfo.getSaveModelName()) || !StringUtils.isEmpty(tableInfo.getSavePath()) || !StringUtils.isEmpty(tableInfo.getSavePackageName())) {
return;
}
// 保存信息
tableInfoUtils.save(tableInfo);
isSave.set(true);
}
// 进行覆盖保存
tableInfo.setSavePath(cacheDataUtils.getSavePath());
tableInfo.setSavePackageName(cacheDataUtils.getPackageName());
tableInfo.setSaveModelName(moduleName);
// 保存信息
tableInfoUtils.save(tableInfo);
isSave.set(true);
});
// 保存完毕后需要重新获取数据
if (isSave.get()) {

View File

@ -6,5 +6,6 @@
#* @vtlvariable name="importList" type="java.util.List<java.lang.String>" *#
#* @vtlvariable name="callback" type="com.sjhy.plugin.entity.Callback" *#
#* @vtlvariable name="tool" type="com.sjhy.plugin.tool.NameUtils" *#
#* @vtlvariable name="time" type="com.sjhy.plugin.tool.TimeUtils" *#
#* @vtlvariable name="tableInfo" type="com.sjhy.plugin.entity.TableInfo" *#
#* @vtlvariable name="tableInfoList" type="java.util.List<com.sjhy.plugin.entity.TableInfo>" *#

View File

@ -0,0 +1,18 @@
##定义初始变量
#set($tableName = $tool.append($tableInfo.name, "Controller"))
##设置回调
$!callback.setFileName($tool.append($tableName, ".java"))
$!callback.setSavePath($tool.append($tableInfo.savePath, "/controller"))
#if($tableInfo.savePackageName)package $!{tableInfo.savePackageName}.#{end}controller;
/**
* $!{tableInfo.comment}($!{tableInfo.name})表控制层
*
* @author $!author
* @since $!time.currTime()
*/
public class $!{tableName} {
}

View File

@ -1 +1,18 @@
这里什么都没有
##定义初始变量
#set($tableName = $tool.append($tableInfo.name, "Dao"))
##设置回调
$!callback.setFileName($tool.append($tableName, ".java"))
$!callback.setSavePath($tool.append($tableInfo.savePath, "/dao"))
#if($tableInfo.savePackageName)package $!{tableInfo.savePackageName}.#{end}dao;
/**
* $!{tableInfo.comment}($!{tableInfo.name})表数据库访问层
*
* @author $!author
* @since $!time.currTime()
*/
public class $!{tableName} {
}

View File

@ -13,6 +13,9 @@ $tableInfo 表对象
fullColumn 所有列
pkColumn 主键列
otherColumn 其他列
savePackageName 保存的包名
savePath 保存路径
saveModelName 保存的model名称
columnInfo 列对象
obj 列原始对象
name 列名(首字母小写)
@ -30,12 +33,17 @@ $tool
firstUpperCase(String) 首字母大写方法
firstLowerCase(String) 首字母小写方法
getClsNameByFullName(String) 通过包全名获取类名
getJavaName(String) 将下划线分割字符串转驼峰命名
getJavaName(String) 将下划线分割字符串转驼峰命名(属性名)
getClassName(String) 将下划线分割字符串转驼峰命名(类名)
append(... Object) 多个数据进行拼接
$time
currTime(String) 获取当前时间指定时间格式默认yyyy-MM-dd HH:mm:ss
*#
##设置回调
$!callback.setFileName($tool.append($tableInfo.name, ".java"))
$!callback.setSavePath($tool.append($tableInfo.savePath, "/entity"))
package $!packageName;
#if($tableInfo.savePackageName)package $!{tableInfo.savePackageName}.#{end}entity;
#foreach($import in $importList)
import $!import;
@ -43,7 +51,9 @@ import $!import;
/**
* $!{tableInfo.comment}($!{tableInfo.name})表实体类
*
* @author $!author
* @since $!time.currTime()
*/
public class $!{tableInfo.name} {
#foreach($column in $tableInfo.fullColumn)
@ -53,9 +63,11 @@ public class $!{tableInfo.name} {
#end
#foreach($column in $tableInfo.fullColumn)
public $!{tool.getClsNameByFullName($column.type)} get$!{tool.firstUpperCase($column.name)}() {
return $!{column.name};
}
public void set$!{tool.firstUpperCase($column.name)}($!{tool.getClsNameByFullName($column.type)} $!{column.name}) {
this.$!{column.name} = $!{column.name};
}

View File

@ -0,0 +1,18 @@
##定义初始变量
#set($tableName = $tool.append($tableInfo.name, "Service"))
##设置回调
$!callback.setFileName($tool.append($tableName, ".java"))
$!callback.setSavePath($tool.append($tableInfo.savePath, "/service"))
#if($tableInfo.savePackageName)package $!{tableInfo.savePackageName}.#{end}service;
/**
* $!{tableInfo.comment}($!{tableInfo.name})表服务接口
*
* @author $!author
* @since $!time.currTime()
*/
public interface $!{tableName} {
}

View File

@ -0,0 +1,19 @@
##定义初始变量
#set($tableName = $tool.append($tableInfo.name, "ServiceImpl"))
##设置回调
$!callback.setFileName($tool.append($tableName, ".java"))
$!callback.setSavePath($tool.append($tableInfo.savePath, "/service/impl"))
#if($tableInfo.savePackageName)package $!{tableInfo.savePackageName}.#{end}service.impl;
import $!{tableInfo.savePackageName}.service.$!{tableInfo.name}Service;
/**
* $!{tableInfo.comment}($!{tableInfo.name})表服务实现类
*
* @author $!author
* @since $!time.currTime()
*/
public class $!{tableName} implements $!{tableInfo.name}Service {
}