|
|
@@ -33,7 +33,8 @@ public class GenCodeService {
|
|
|
public void genController(GenCode model) throws IOException, TemplateException {
|
|
|
|
|
|
Path targetFile = StringUtils.isNotBlank(model.getGenPackage()) ?
|
|
|
- Paths.get(model.getJavaPath(), "web", model.getGenPackage(), model.getClassName() + "Controller.java").toAbsolutePath() :
|
|
|
+ Paths.get(model.getJavaPath(), "web", model.getGenPackage(), model.getClassName() + "Controller.java")
|
|
|
+ .toAbsolutePath() :
|
|
|
Paths.get(model.getJavaPath(), "web", model.getClassName() + "Controller.java").toAbsolutePath();
|
|
|
Map<String, Object> extra = new HashMap<>();
|
|
|
if (StringUtil.isNotEmpty(model.getGenPackage())) {
|
|
|
@@ -42,38 +43,38 @@ public class GenCodeService {
|
|
|
extra.put("imports", imports);
|
|
|
}
|
|
|
extra.put("subPackage", StringUtil.isNotEmpty(model.getGenPackage()));
|
|
|
+ extra.put("softDelete", canSoftDelete(model));
|
|
|
genFile("ControllerTemplate.ftl", model, extra, targetFile);
|
|
|
log.info("成功生成Controller:{}", targetFile.toString());
|
|
|
}
|
|
|
|
|
|
public void genService(GenCode model) throws IOException, TemplateException {
|
|
|
Path targetFile = StringUtils.isNotBlank(model.getGenPackage()) ?
|
|
|
- Paths.get(model.getJavaPath(), "service", model.getGenPackage(), model.getClassName() + "Service.java").toAbsolutePath() :
|
|
|
+ Paths.get(model.getJavaPath(), "service", model.getGenPackage(), model.getClassName() + "Service.java")
|
|
|
+ .toAbsolutePath() :
|
|
|
Paths.get(model.getJavaPath(), "service", model.getClassName() + "Service.java").toAbsolutePath();
|
|
|
- genFile("ServiceTemplate.ftl", model, null, targetFile);
|
|
|
+ Map<String, Object> extra = new HashMap<>();
|
|
|
+ extra.put("softDelete", canSoftDelete(model));
|
|
|
+ genFile("ServiceTemplate.ftl", model, extra, targetFile);
|
|
|
log.info("成功生成Service:{}", targetFile.toString());
|
|
|
}
|
|
|
|
|
|
public void genRepo(GenCode model) throws IOException, TemplateException, ClassNotFoundException {
|
|
|
Path targetFile = StringUtils.isNotBlank(model.getGenPackage()) ?
|
|
|
- Paths.get(model.getJavaPath(), "repo", model.getGenPackage(), model.getClassName() + "Repo.java").toAbsolutePath() :
|
|
|
+ Paths.get(model.getJavaPath(), "repo", model.getGenPackage(), model.getClassName() + "Repo.java")
|
|
|
+ .toAbsolutePath() :
|
|
|
Paths.get(model.getJavaPath(), "repo", model.getClassName() + "Repo.java").toAbsolutePath();
|
|
|
Map<String, Object> extra = new HashMap<>();
|
|
|
- extra.put("softDelete", false);
|
|
|
- try {
|
|
|
- Field field = Class.forName(model.getTablePackage()).getDeclaredField("enabled");
|
|
|
- if (field != null && field.getType().equals(Boolean.class)) {
|
|
|
- extra.put("softDelete", true);
|
|
|
- }
|
|
|
- } catch (NoSuchFieldException ignored) {
|
|
|
- }
|
|
|
+ extra.put("softDelete", canSoftDelete(model));
|
|
|
genFile("RepoTemplate.ftl", model, extra, targetFile);
|
|
|
log.info("成功生成Repo:{}", targetFile.toString());
|
|
|
}
|
|
|
|
|
|
public void genListView(GenCode model) throws IOException, TemplateException {
|
|
|
Path targetFile = Paths.get(model.getViewPath(), model.getClassName() + "List.vue").toAbsolutePath();
|
|
|
- genFile("ListViewTemplate.ftl", model, null, targetFile);
|
|
|
+ Map<String, Object> extra = new HashMap<>();
|
|
|
+ extra.put("softDelete", canSoftDelete(model));
|
|
|
+ genFile("ListViewTemplate.ftl", model, extra, targetFile);
|
|
|
log.info("成功生成ListView:{}", targetFile.toString());
|
|
|
}
|
|
|
|
|
|
@@ -89,6 +90,7 @@ public class GenCodeService {
|
|
|
}
|
|
|
}
|
|
|
map.put("labelWidth", maxLabelWidth + 25 + "px");
|
|
|
+ map.put("softDelete", canSoftDelete(model));
|
|
|
genFile("EditViewTemplate.ftl", model, map, targetFile);
|
|
|
log.info("成功生成EditView:{}", targetFile.toString());
|
|
|
}
|
|
|
@@ -112,7 +114,8 @@ public class GenCodeService {
|
|
|
private int measureText(String text, float fontSize) throws IOException, FontFormatException {
|
|
|
AffineTransform affinetransform = new AffineTransform();
|
|
|
FontRenderContext frc = new FontRenderContext(affinetransform, true, true);
|
|
|
- Font font = Font.createFont(Font.TRUETYPE_FONT, this.getClass().getResourceAsStream("/font/SourceHanSansCN-Normal.ttf"));
|
|
|
+ Font font = Font.createFont(Font.TRUETYPE_FONT, this.getClass()
|
|
|
+ .getResourceAsStream("/font/SourceHanSansCN-Normal.ttf"));
|
|
|
return (int) (font.deriveFont(fontSize).getStringBounds(text, frc).getWidth());
|
|
|
}
|
|
|
|
|
|
@@ -139,14 +142,14 @@ public class GenCodeService {
|
|
|
+ "Edit',\n component: () => import(/* webpackChunkName: \"" + routePath + "Edit\" */ '@/views/"
|
|
|
+ routeName
|
|
|
+ "Edit.vue'),\n meta: {\n title: '" + remark + "编辑',\n"
|
|
|
- +" },\n },\n {\n path: '/"
|
|
|
+ + " },\n },\n {\n path: '/"
|
|
|
+ routePath
|
|
|
+ "List',\n name: '"
|
|
|
+ routeName
|
|
|
+ "List',\n component: () => import(/* webpackChunkName: \"" + routePath + "List\" */ '@/views/"
|
|
|
+ routeName
|
|
|
+ "List.vue'),\n meta: {\n title: '" + remark + "',\n"
|
|
|
- +" },\n }\n ";
|
|
|
+ + " },\n }\n ";
|
|
|
boolean needComma = !routerJs.toString().substring(0, insertLocation).trim().endsWith(",");
|
|
|
if (needComma) {
|
|
|
routerJs.insert(routerJs.toString().substring(0, insertLocation).lastIndexOf("}") + 1, ",");
|
|
|
@@ -164,4 +167,15 @@ public class GenCodeService {
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ private boolean canSoftDelete(GenCode model) {
|
|
|
+ try {
|
|
|
+ Field field = Class.forName(model.getTablePackage()).getDeclaredField("enabled");
|
|
|
+ if (field != null && field.getType().equals(Boolean.class)) {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ } catch (NoSuchFieldException | ClassNotFoundException ignored) {
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+ }
|
|
|
}
|