mirror of
http://git.pig4cloud.com/pig/pigx.git
synced 2026-11-14 14:19:08 +08:00
✨ Introducing new features. close #4544 代码预览 增加左侧结构树
This commit is contained in:
1 parent
871bdb1183
commit
e80216eef0
5 files changed
+30
-21
No files matched your search
+8
-4
@@ -40,7 +40,7 @@ import java.util.zip.ZipOutputStream;
|
|||||||
*/
|
*/
|
||||||
public interface GenCodeService {
|
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) {
|
ZipOutputStream zip, GenFormConf formConf) {
|
||||||
|
|
||||||
// 构建表实体
|
// 构建表实体
|
||||||
@@ -261,7 +261,7 @@ public interface GenCodeService {
|
|||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
@SneakyThrows
|
@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) {
|
Map<String, Object> map, GenFormConf formConf) {
|
||||||
// 设置velocity资源加载器
|
// 设置velocity资源加载器
|
||||||
Properties prop = new Properties();
|
Properties prop = new Properties();
|
||||||
@@ -274,9 +274,10 @@ public interface GenCodeService {
|
|||||||
|
|
||||||
// 获取模板列表
|
// 获取模板列表
|
||||||
List<String> templates = getTemplates(genConfig);
|
List<String> templates = getTemplates(genConfig);
|
||||||
Map<String, String> resultMap = new LinkedHashMap<>(8);
|
Map<String, Map> resultMap = new LinkedHashMap<>(8);
|
||||||
|
|
||||||
for (String template : templates) {
|
for (String template : templates) {
|
||||||
|
Map<String,String> templatesData = new HashMap<>();
|
||||||
// 渲染模板
|
// 渲染模板
|
||||||
StringWriter sw = new StringWriter();
|
StringWriter sw = new StringWriter();
|
||||||
Template tpl = Velocity.getTemplate(template, CharsetUtil.UTF_8);
|
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(),
|
String fileName = getFileName(template, tableEntity.getCaseClassName(), map.get("package").toString(),
|
||||||
map.get("moduleName").toString());
|
map.get("moduleName").toString());
|
||||||
|
|
||||||
|
templatesData.put("codePath",fileName);
|
||||||
|
templatesData.put("code",sw.toString());
|
||||||
|
|
||||||
if (zip != null) {
|
if (zip != null) {
|
||||||
try {
|
try {
|
||||||
zip.putNextEntry(new ZipEntry(Objects.requireNonNull(fileName)));
|
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;
|
return resultMap;
|
||||||
|
|||||||
+1
-1
@@ -50,6 +50,6 @@ public interface GeneratorService {
|
|||||||
* @param genConfig 生成信息
|
* @param genConfig 生成信息
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
Map<String, String> previewCode(GenConfig genConfig);
|
Map<String, Map> previewCode(GenConfig genConfig);
|
||||||
|
|
||||||
}
|
}
|
||||||
+12
-12
@@ -58,7 +58,7 @@ public class GenDynamicServiceImpl implements GenDynamicService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Map<String, String> run(GenConfig genConfig) {
|
public Map<String, Map> run(GenConfig genConfig) {
|
||||||
// 根据tableName 查询最新的表单配置
|
// 根据tableName 查询最新的表单配置
|
||||||
List<GenFormConf> formConfList = genFormConfMapper.selectList(Wrappers.<GenFormConf>lambdaQuery()
|
List<GenFormConf> formConfList = genFormConfMapper.selectList(Wrappers.<GenFormConf>lambdaQuery()
|
||||||
.eq(GenFormConf::getTableName, genConfig.getTableName()).orderByDesc(GenFormConf::getCreateTime));
|
.eq(GenFormConf::getTableName, genConfig.getTableName()).orderByDesc(GenFormConf::getCreateTime));
|
||||||
@@ -68,7 +68,7 @@ public class GenDynamicServiceImpl implements GenDynamicService {
|
|||||||
|
|
||||||
GeneratorMapper mapper = magic.getMapper(genConfig.getDsName());
|
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)) {
|
for (String tableName : StrUtil.split(tableNames, StrUtil.DASHED)) {
|
||||||
// 查询表信息
|
// 查询表信息
|
||||||
Map<String, String> table = mapper.queryTable(tableName, dsName);
|
Map<String, String> table = mapper.queryTable(tableName, dsName);
|
||||||
@@ -95,8 +95,8 @@ public class GenDynamicServiceImpl implements GenDynamicService {
|
|||||||
|
|
||||||
ApiInfo apiInfo = new ApiInfo();
|
ApiInfo apiInfo = new ApiInfo();
|
||||||
apiInfo.setId(id + "_query");
|
apiInfo.setId(id + "_query");
|
||||||
String script = templates.get("template/magic/query.magic.vm");
|
Map<String,String> script = templates.get("template/magic/query.magic.vm");
|
||||||
apiInfo.setScript(script);
|
apiInfo.setScript(script.get("code"));
|
||||||
apiInfo.setName("分页");
|
apiInfo.setName("分页");
|
||||||
apiInfo.setPath("/list");
|
apiInfo.setPath("/list");
|
||||||
apiInfo.setMethod("post");
|
apiInfo.setMethod("post");
|
||||||
@@ -105,8 +105,8 @@ public class GenDynamicServiceImpl implements GenDynamicService {
|
|||||||
|
|
||||||
ApiInfo delApiInfo = new ApiInfo();
|
ApiInfo delApiInfo = new ApiInfo();
|
||||||
delApiInfo.setId(id + "_del");
|
delApiInfo.setId(id + "_del");
|
||||||
String delScript = templates.get("template/magic/del.magic.vm");
|
Map<String,String> delScript = templates.get("template/magic/del.magic.vm");
|
||||||
delApiInfo.setScript(delScript);
|
delApiInfo.setScript(delScript.get("code"));
|
||||||
delApiInfo.setName("删除");
|
delApiInfo.setName("删除");
|
||||||
delApiInfo.setPath("/delete");
|
delApiInfo.setPath("/delete");
|
||||||
delApiInfo.setMethod("delete");
|
delApiInfo.setMethod("delete");
|
||||||
@@ -115,8 +115,8 @@ public class GenDynamicServiceImpl implements GenDynamicService {
|
|||||||
|
|
||||||
ApiInfo addApiInfo = new ApiInfo();
|
ApiInfo addApiInfo = new ApiInfo();
|
||||||
addApiInfo.setId(id + "_add");
|
addApiInfo.setId(id + "_add");
|
||||||
String addScript = templates.get("template/magic/add.magic.vm");
|
Map<String,String> addScript = templates.get("template/magic/add.magic.vm");
|
||||||
addApiInfo.setScript(addScript);
|
addApiInfo.setScript(addScript.get("code"));
|
||||||
addApiInfo.setName("添加");
|
addApiInfo.setName("添加");
|
||||||
addApiInfo.setPath("/save");
|
addApiInfo.setPath("/save");
|
||||||
addApiInfo.setMethod("post");
|
addApiInfo.setMethod("post");
|
||||||
@@ -125,8 +125,8 @@ public class GenDynamicServiceImpl implements GenDynamicService {
|
|||||||
|
|
||||||
ApiInfo updateApiInfo = new ApiInfo();
|
ApiInfo updateApiInfo = new ApiInfo();
|
||||||
updateApiInfo.setId(id + "_update");
|
updateApiInfo.setId(id + "_update");
|
||||||
String updateScript = templates.get("template/magic/update.magic.vm");
|
Map<String,String> updateScript = templates.get("template/magic/update.magic.vm");
|
||||||
updateApiInfo.setScript(updateScript);
|
updateApiInfo.setScript(updateScript.get("code"));
|
||||||
updateApiInfo.setName("修改");
|
updateApiInfo.setName("修改");
|
||||||
updateApiInfo.setPath("/update");
|
updateApiInfo.setPath("/update");
|
||||||
updateApiInfo.setMethod("put");
|
updateApiInfo.setMethod("put");
|
||||||
@@ -135,8 +135,8 @@ public class GenDynamicServiceImpl implements GenDynamicService {
|
|||||||
|
|
||||||
ApiInfo metadataApiInfo = new ApiInfo();
|
ApiInfo metadataApiInfo = new ApiInfo();
|
||||||
metadataApiInfo.setId(id + "metadata");
|
metadataApiInfo.setId(id + "metadata");
|
||||||
String metadataScript = templates.get("template/magic/metadata.magic.vm");
|
Map<String,String> metadataScript = templates.get("template/magic/metadata.magic.vm");
|
||||||
metadataApiInfo.setScript(metadataScript);
|
metadataApiInfo.setScript(metadataScript.get("code"));
|
||||||
metadataApiInfo.setName("元数据");
|
metadataApiInfo.setName("元数据");
|
||||||
metadataApiInfo.setPath("/metadata");
|
metadataApiInfo.setPath("/metadata");
|
||||||
metadataApiInfo.setMethod("get");
|
metadataApiInfo.setMethod("get");
|
||||||
|
|||||||
+1
-1
@@ -74,7 +74,7 @@ public class GeneratorServiceImpl implements GeneratorService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Map<String, String> previewCode(GenConfig genConfig) {
|
public Map<String, Map> previewCode(GenConfig genConfig) {
|
||||||
// 根据tableName 查询最新的表单配置
|
// 根据tableName 查询最新的表单配置
|
||||||
List<GenFormConf> formConfList = genFormConfMapper.selectList(Wrappers.<GenFormConf>lambdaQuery()
|
List<GenFormConf> formConfList = genFormConfMapper.selectList(Wrappers.<GenFormConf>lambdaQuery()
|
||||||
.eq(GenFormConf::getTableName, genConfig.getTableName()).orderByDesc(GenFormConf::getCreateTime));
|
.eq(GenFormConf::getTableName, genConfig.getTableName()).orderByDesc(GenFormConf::getCreateTime));
|
||||||
|
|||||||
+8
-3
@@ -81,24 +81,29 @@ public class AvueGenCodeServiceImpl implements GenCodeService {
|
|||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
@SneakyThrows
|
@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, Object> map, GenFormConf formConf) {
|
||||||
|
|
||||||
Map<String, String> resultMap = new HashMap<>();
|
Map<String, Map> resultMap = new HashMap<>();
|
||||||
|
|
||||||
if (Objects.nonNull(formConf)) {
|
if (Objects.nonNull(formConf)) {
|
||||||
|
Map<String,String> templatesData = new HashMap<>();
|
||||||
// 存在 curd 存在设计好的JSON 则使用Json 覆盖
|
// 存在 curd 存在设计好的JSON 则使用Json 覆盖
|
||||||
String crudTempName = "template/avue/crud.js.vm";
|
String crudTempName = "template/avue/crud.js.vm";
|
||||||
String fileName = getFileName(crudTempName, tableEntity.getCaseClassName(), map.get("package").toString(),
|
String fileName = getFileName(crudTempName, tableEntity.getCaseClassName(), map.get("package").toString(),
|
||||||
map.get("moduleName").toString());
|
map.get("moduleName").toString());
|
||||||
String contents = CRUD_PREFIX + formConf.getFormInfo();
|
String contents = CRUD_PREFIX + formConf.getFormInfo();
|
||||||
|
|
||||||
|
templatesData.put("codePath",fileName);
|
||||||
|
templatesData.put("code",contents);
|
||||||
|
|
||||||
if (zip != null) {
|
if (zip != null) {
|
||||||
zip.putNextEntry(new ZipEntry(Objects.requireNonNull(fileName)));
|
zip.putNextEntry(new ZipEntry(Objects.requireNonNull(fileName)));
|
||||||
IoUtil.write(zip, StandardCharsets.UTF_8, false, contents);
|
IoUtil.write(zip, StandardCharsets.UTF_8, false, contents);
|
||||||
}
|
}
|
||||||
resultMap.putAll(GenCodeService.super.renderData(genConfig, zip, tableEntity, map, formConf));
|
resultMap.putAll(GenCodeService.super.renderData(genConfig, zip, tableEntity, map, formConf));
|
||||||
resultMap.put(crudTempName, contents);
|
|
||||||
|
resultMap.put(crudTempName, templatesData);
|
||||||
return resultMap;
|
return resultMap;
|
||||||
}
|
}
|
||||||
return GenCodeService.super.renderData(genConfig, zip, tableEntity, map, formConf);
|
return GenCodeService.super.renderData(genConfig, zip, tableEntity, map, formConf);
|
||||||
|
|||||||
Reference in new issue
Block a user