mirror of https://gitee.com/hnkaibin/RuoYi-cms.git
新增不替换原有已存在的代码生成
This commit is contained in:
parent
31e6a7b1a5
commit
66be01503e
|
@ -36,6 +36,7 @@
|
|||

|
||||
2. 新增多站点代码生成模板:单表、树表、多素材
|
||||

|
||||
3.新增不替换原有已存在的代码生成。
|
||||
|
||||
|
||||
## 功能优化
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成代码(自定义路径)
|
||||
*/
|
||||
|
|
|
@ -118,4 +118,6 @@ public interface IGenTableService
|
|||
* @param genTable 业务信息
|
||||
*/
|
||||
public void validateEdit(GenTable genTable);
|
||||
|
||||
void genCodeNotReplace(String tableName);
|
||||
}
|
||||
|
|
|
@ -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());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置主键列信息
|
||||
*
|
||||
|
|
|
@ -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() {
|
||||
|
|
Loading…
Reference in New Issue