新增不替换原有已存在的代码生成

This commit is contained in:
china-bin 2020-09-16 11:38:17 +08:00
parent 31e6a7b1a5
commit 66be01503e
5 changed files with 68 additions and 1 deletions

View File

@ -36,6 +36,7 @@
![类型](doc/img/1.png)
2. 新增多站点代码生成模板:单表、树表、多素材
![模板](doc/img/2.png)
3.新增不替换原有已存在的代码生成。
## 功能优化

View File

@ -199,6 +199,19 @@ public class GenController extends BaseController
genCode(response, data);
}
/**
* 生成代码(不替换已有代码)自定义路径
*/
@RequiresPermissions("tool:gen:code")
@Log(title = "代码生成", businessType = BusinessType.GENCODE)
@GetMapping("/genCodeNotReplace/{tableName}")
@ResponseBody
public AjaxResult genCodeNotReplace(@PathVariable("tableName") String tableName)
{
genTableService.genCodeNotReplace(tableName);
return AjaxResult.success();
}
/**
* 生成代码自定义路径
*/

View File

@ -118,4 +118,6 @@ public interface IGenTableService
* @param genTable 业务信息
*/
public void validateEdit(GenTable genTable);
void genCodeNotReplace(String tableName);
}

View File

@ -409,6 +409,48 @@ public class GenTableServiceImpl implements IGenTableService
}
}
@Override
public void genCodeNotReplace(String tableName) {
// 查询表信息
GenTable table = genTableMapper.selectGenTableByName(tableName);
// 设置主子表信息
setSubTable(table);
// 设置主键列信息
setPkColumn(table);
VelocityInitializer.initVelocity();
VelocityContext context = VelocityUtils.prepareContext(table);
// 获取模板列表
List<String> templates = VelocityUtils.getTemplateList(table.getTplCategory());
for (String template : templates)
{
if (!StringUtils.contains(template, "sql.vm"))
{
// 渲染模板
StringWriter sw = new StringWriter();
Template tpl = Velocity.getTemplate(template, Constants.UTF8);
tpl.merge(context, sw);
try
{
String path = getGenPath(table, template);
File file = new File(path);
if (!file.exists()) {
// 不存在才生成
FileUtils.writeStringToFile(file, sw.toString(), CharsetKit.UTF_8);
}
}
catch (IOException e)
{
throw new BusinessException("渲染模板失败,表名:" + table.getTableName());
}
}
}
}
/**
* 设置主键列信息
*

View File

@ -127,6 +127,7 @@
actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.tableId + '\')"><i class="fa fa-remove"></i>删除</a> ');
actions.push('<a class="btn btn-warning btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="synchDb(\'' + row.tableName + '\')"><i class="fa fa-refresh"></i>同步</a> ');
actions.push('<a class="btn btn-primary btn-xs ' + codeFlag + '" href="javascript:void(0)" onclick="genCode(\'' + row.tableName + '\',\'' + row.genType + '\')"><i class="fa fa-bug"></i>生成代码</a> ');
actions.push('<a class="btn btn-primary btn-xs ' + codeFlag + '" href="javascript:void(0)" onclick="genCodeNotReplace(\'' + row.tableName + '\',\'' + row.genType + '\')"><i class="fa fa-bug"></i>生成代码(不替换已有代码)</a> ');
return actions.join('');
}
}]
@ -174,7 +175,15 @@
}
})
}
// 生成代码
function genCodeNotReplace(tableName, genType) {
$.modal.confirm("确定要生成" + tableName + "表代码吗?", function() {
$.operate.get(prefix + "/genCodeNotReplace/" + tableName);
})
}
// 同步数据库
function synchDb(tableName){
$.modal.confirm("确认要强制同步" + tableName + "表结构吗?", function() {