✨ Introducing new features. close #4544 代码预览 增加左侧结构树

This commit is contained in:
aeizzz committed 2022-11-29 16:57:43 +08:00
1 parent 871bdb1183
commit e80216eef0
5 files changed
+30 -21

No files matched your search

@@ -40,7 +40,7 @@ import java.util.zip.ZipOutputStream;
*/
public interface GenCodeService {
default Map<String, String> gen(GenConfig genConfig, Map<String, String> table, List<Map<String, String>> columns,
default Map<String, Map> gen(GenConfig genConfig, Map<String, String> table, List<Map<String, String>> columns,
ZipOutputStream zip, GenFormConf formConf) {
// 构建表实体
@@ -261,7 +261,7 @@ public interface GenCodeService {
* @return
*/
@SneakyThrows
default Map<String, String> renderData(GenConfig genConfig, ZipOutputStream zip, TableEntity tableEntity,
default Map<String, Map> renderData(GenConfig genConfig, ZipOutputStream zip, TableEntity tableEntity,
Map<String, Object> map, GenFormConf formConf) {
// 设置velocity资源加载器
Properties prop = new Properties();
@@ -274,9 +274,10 @@ public interface GenCodeService {
// 获取模板列表
List<String> templates = getTemplates(genConfig);
Map<String, String> resultMap = new LinkedHashMap<>(8);
Map<String, Map> resultMap = new LinkedHashMap<>(8);
for (String template : templates) {
Map<String,String> templatesData = new HashMap<>();
// 渲染模板
StringWriter sw = new StringWriter();
Template tpl = Velocity.getTemplate(template, CharsetUtil.UTF_8);
@@ -286,6 +287,9 @@ public interface GenCodeService {
String fileName = getFileName(template, tableEntity.getCaseClassName(), map.get("package").toString(),
map.get("moduleName").toString());
templatesData.put("codePath",fileName);
templatesData.put("code",sw.toString());
if (zip != null) {
try {
zip.putNextEntry(new ZipEntry(Objects.requireNonNull(fileName)));
@@ -296,7 +300,7 @@ public interface GenCodeService {
}
}
resultMap.put(template, sw.toString());
resultMap.put(template, templatesData);
}
return resultMap;
@@ -50,6 +50,6 @@ public interface GeneratorService {
* @param genConfig 生成信息
* @return
*/
Map<String, String> previewCode(GenConfig genConfig);
Map<String, Map> previewCode(GenConfig genConfig);
}
@@ -58,7 +58,7 @@ public class GenDynamicServiceImpl implements GenDynamicService {
}
@Override
public Map<String, String> run(GenConfig genConfig) {
public Map<String, Map> run(GenConfig genConfig) {
// 根据tableName 查询最新的表单配置
List<GenFormConf> formConfList = genFormConfMapper.selectList(Wrappers.<GenFormConf>lambdaQuery()
.eq(GenFormConf::getTableName, genConfig.getTableName()).orderByDesc(GenFormConf::getCreateTime));
@@ -68,7 +68,7 @@ public class GenDynamicServiceImpl implements GenDynamicService {
GeneratorMapper mapper = magic.getMapper(genConfig.getDsName());
Map<String, String> templates = new HashMap<>();
Map<String, Map> templates = new HashMap<>();
for (String tableName : StrUtil.split(tableNames, StrUtil.DASHED)) {
// 查询表信息
Map<String, String> table = mapper.queryTable(tableName, dsName);
@@ -95,8 +95,8 @@ public class GenDynamicServiceImpl implements GenDynamicService {
ApiInfo apiInfo = new ApiInfo();
apiInfo.setId(id + "_query");
String script = templates.get("template/magic/query.magic.vm");
apiInfo.setScript(script);
Map<String,String> script = templates.get("template/magic/query.magic.vm");
apiInfo.setScript(script.get("code"));
apiInfo.setName("分页");
apiInfo.setPath("/list");
apiInfo.setMethod("post");
@@ -105,8 +105,8 @@ public class GenDynamicServiceImpl implements GenDynamicService {
ApiInfo delApiInfo = new ApiInfo();
delApiInfo.setId(id + "_del");
String delScript = templates.get("template/magic/del.magic.vm");
delApiInfo.setScript(delScript);
Map<String,String> delScript = templates.get("template/magic/del.magic.vm");
delApiInfo.setScript(delScript.get("code"));
delApiInfo.setName("删除");
delApiInfo.setPath("/delete");
delApiInfo.setMethod("delete");
@@ -115,8 +115,8 @@ public class GenDynamicServiceImpl implements GenDynamicService {
ApiInfo addApiInfo = new ApiInfo();
addApiInfo.setId(id + "_add");
String addScript = templates.get("template/magic/add.magic.vm");
addApiInfo.setScript(addScript);
Map<String,String> addScript = templates.get("template/magic/add.magic.vm");
addApiInfo.setScript(addScript.get("code"));
addApiInfo.setName("添加");
addApiInfo.setPath("/save");
addApiInfo.setMethod("post");
@@ -125,8 +125,8 @@ public class GenDynamicServiceImpl implements GenDynamicService {
ApiInfo updateApiInfo = new ApiInfo();
updateApiInfo.setId(id + "_update");
String updateScript = templates.get("template/magic/update.magic.vm");
updateApiInfo.setScript(updateScript);
Map<String,String> updateScript = templates.get("template/magic/update.magic.vm");
updateApiInfo.setScript(updateScript.get("code"));
updateApiInfo.setName("修改");
updateApiInfo.setPath("/update");
updateApiInfo.setMethod("put");
@@ -135,8 +135,8 @@ public class GenDynamicServiceImpl implements GenDynamicService {
ApiInfo metadataApiInfo = new ApiInfo();
metadataApiInfo.setId(id + "metadata");
String metadataScript = templates.get("template/magic/metadata.magic.vm");
metadataApiInfo.setScript(metadataScript);
Map<String,String> metadataScript = templates.get("template/magic/metadata.magic.vm");
metadataApiInfo.setScript(metadataScript.get("code"));
metadataApiInfo.setName("元数据");
metadataApiInfo.setPath("/metadata");
metadataApiInfo.setMethod("get");
@@ -74,7 +74,7 @@ public class GeneratorServiceImpl implements GeneratorService {
}
@Override
public Map<String, String> previewCode(GenConfig genConfig) {
public Map<String, Map> previewCode(GenConfig genConfig) {
// 根据tableName 查询最新的表单配置
List<GenFormConf> formConfList = genFormConfMapper.selectList(Wrappers.<GenFormConf>lambdaQuery()
.eq(GenFormConf::getTableName, genConfig.getTableName()).orderByDesc(GenFormConf::getCreateTime));
@@ -81,24 +81,29 @@ public class AvueGenCodeServiceImpl implements GenCodeService {
* @return
*/
@SneakyThrows
public Map<String, String> renderData(GenConfig genConfig, ZipOutputStream zip, TableEntity tableEntity,
public Map<String, Map> renderData(GenConfig genConfig, ZipOutputStream zip, TableEntity tableEntity,
Map<String, Object> map, GenFormConf formConf) {
Map<String, String> resultMap = new HashMap<>();
Map<String, Map> resultMap = new HashMap<>();
if (Objects.nonNull(formConf)) {
Map<String,String> templatesData = new HashMap<>();
// 存在 curd 存在设计好的JSON 则使用Json 覆盖
String crudTempName = "template/avue/crud.js.vm";
String fileName = getFileName(crudTempName, tableEntity.getCaseClassName(), map.get("package").toString(),
map.get("moduleName").toString());
String contents = CRUD_PREFIX + formConf.getFormInfo();
templatesData.put("codePath",fileName);
templatesData.put("code",contents);
if (zip != null) {
zip.putNextEntry(new ZipEntry(Objects.requireNonNull(fileName)));
IoUtil.write(zip, StandardCharsets.UTF_8, false, contents);
}
resultMap.putAll(GenCodeService.super.renderData(genConfig, zip, tableEntity, map, formConf));
resultMap.put(crudTempName, contents);
resultMap.put(crudTempName, templatesData);
return resultMap;
}
return GenCodeService.super.renderData(genConfig, zip, tableEntity, map, formConf);