提交 4be084b0 编写于 作者: sq3536's avatar sq3536

便捷操作

上级 4cca4e4d
......@@ -113,6 +113,7 @@ public class CodegenConfig {
additionalProperties.put("lowercase", new LowercaseLambda().generator(this));
additionalProperties.put("uppercase", new UppercaseLambda());
additionalProperties.put("snakecase", new SnakecaseLambda());
additionalProperties.put("spinalcase", new SpinalcaseLambda());
additionalProperties.put("titlecase", new TitlecaseLambda());
additionalProperties.put("camelcase", new CamelCaseLambda(true).generator(this));
additionalProperties.put("pascalcase", new CamelCaseLambda(false).generator(this));
......
......@@ -12,7 +12,7 @@ public class BaseModel {
public String getId() {
if(StringUtils.isEmpty(id)&&(!StringUtils.isEmpty(getCodeName())))
id=this.getCodeName();
id=this.getCodeName().toString();
return id;
}
......@@ -22,17 +22,20 @@ public class BaseModel {
return (T)this;
}
public String getCodeName() {
return codeName;
public LabelExt getCodeName() {
return new LabelExt(codeName);
}
public <T> T setCodeName(String codeName) {
this.codeName = codeName;
return (T)this;
}
public String getName() {
return name;
public LabelExt getName() {
return new LabelExt(name);
}
public <T> T setName(String name) {
......@@ -74,4 +77,5 @@ public class BaseModel {
return (T)this;
}
}
......@@ -21,9 +21,9 @@ public class CtrlModel extends BaseModel{
this.setName(psControl.getName());
if(psControl.getPSAppDataEntity()!=null)
folder=psControl.getPSAppDataEntity().getCodeName();
folder=new LabelExt(psControl.getPSAppDataEntity().getCodeName());
else
folder="app";
folder=new LabelExt("app");
this.setId(String.format("%1$s-%2$s-%3$s",app.getCodeName(),folder,psControl.getCodeName()));
}
......@@ -32,7 +32,7 @@ public class CtrlModel extends BaseModel{
private AppEntityModel appEntity;
private String folder;
private LabelExt folder;
public IPSControl getControl()
{
......
......@@ -102,7 +102,7 @@ public class EntityModel extends BaseModel {
{
references.forEach(ship->{
if(!StringUtils.isEmpty(ship.getCodeName()))
refMaps.put(ship.getCodeName(),ship);
refMaps.put(ship.getCodeName().toString(),ship);
String fkname= DataObject.getStringValue(ship.getName(),"");
if(!StringUtils.isEmpty(fkname))
refMaps.put(fkname, ship);
......@@ -134,7 +134,7 @@ public class EntityModel extends BaseModel {
fieldMap=new LinkedHashMap<>();
fields.forEach(field->{
fieldMap.put(field.getFieldName(),field);
fieldMap.put(field.getCodeName(),field);
fieldMap.put(field.getCodeName().toString(),field);
});
}
return fieldMap;
......
......@@ -29,9 +29,6 @@ public class FieldModel extends BaseModel {
this.setId(String.format("%1$s-%2$s",entity.getCodeName(),deField.getCodeName()));
}
public String getCodeName() {
return getDataEntityField().getCodeName();
}
public String getFieldName() {
return getDataEntityField().getName();
......
package cn.ibizlab.codegen.model;
import cn.ibizlab.codegen.utils.StringAdvUtils;
import org.springframework.util.StringUtils;
import java.util.stream.IntStream;
public class LabelExt implements java.io.Serializable, Comparable<String>, CharSequence {
private String label="";
public LabelExt(String label)
{
if(!StringUtils.isEmpty(label))
this.label=label;
}
public String toLowerCase()
{
return label.toLowerCase();
}
public String toUpperCase()
{
return label.toUpperCase();
}
public String toPascalCase() {
return StringAdvUtils.pascalcase(label);
}
public String toCapFirst() {
return StringAdvUtils.pascalcase(label);
}
public String toCamelCase() {
return StringAdvUtils.camelcase(label);
}
public String toSpinalCase() {
return StringAdvUtils.dashize(label);
}
public String toSnakeCase() {
return StringAdvUtils.snakecase(label);
}
public String getLowerCase()
{
return toLowerCase();
}
public String getUpperCase()
{
return toUpperCase();
}
public String getPascalCase() {
return toPascalCase();
}
public String getCapFirst() {
return toCapFirst();
}
public String getCamelCase() {
return toCamelCase();
}
public String getSpinalCase() {
return toSpinalCase();
}
public String getSnakeCase() {
return toSnakeCase();
}
@Override
public int length() {
return label.length();
}
@Override
public char charAt(int index) {
return label.charAt(index);
}
@Override
public CharSequence subSequence(int start, int end) {
return label.subSequence(start,end);
}
@Override
public String toString() {
return label;
}
@Override
public IntStream chars() {
return label.chars();
}
@Override
public IntStream codePoints() {
return label.codePoints();
}
@Override
public int compareTo(String o) {
return label.compareTo(o);
}
public int compareToIgnoreCase(String o) {
return label.compareToIgnoreCase(o);
}
public boolean startsWith(String prefix) {
return label.startsWith(prefix);
}
public boolean endsWith(String suffix) {
return label.endsWith(suffix);
}
public int indexOf(int ch) {
return label.indexOf(ch, 0);
}
public String substring(int beginIndex) {
return label.substring(beginIndex);
}
public String substring(int beginIndex,int endIndex) {
return label.substring(beginIndex,endIndex);
}
public String replace(char oldChar, char newChar) {
return label.replace(oldChar,newChar);
}
}
......@@ -113,7 +113,7 @@ public class ModelStorage {
{
getSystemModel().getApis().forEach(api->{
api.getApiEntities().forEach(item->{
CliOption opt=newCliOption(TemplateFileType.apiEntity).baseData(item,item.getCodeName()).set("apis",api.getCodeName().toLowerCase());
CliOption opt=newCliOption(TemplateFileType.apiEntity).baseData(item,item.getCodeName().toString()).set("apis",api.getCodeName().toLowerCase());
rt.addOption(opt);
});
});
......@@ -129,7 +129,7 @@ public class ModelStorage {
{
getSystemModel().getApps().forEach(app->{
app.getAppEntities().forEach(item->{
CliOption opt=newCliOption(TemplateFileType.appEntity).baseData(item,item.getCodeName().toLowerCase()).set("apps",app.getCodeName().toLowerCase());
CliOption opt=newCliOption(TemplateFileType.appEntity).baseData(item,item.getCodeName().toSpinalCase()).set("apps",app.getCodeName().toLowerCase());
rt.addOption(opt);
});
});
......@@ -138,7 +138,7 @@ public class ModelStorage {
{
getSystemModel().getEntities().forEach(item->{
CliOption opt=newCliOption(TemplateFileType.entity).setCliSubType(item.getStorageMode()).setModule(item.getModule())
.baseData(item,item.getCodeName());
.baseData(item,item.getCodeName().toString());
rt.addOption(opt);
});
}
......@@ -154,7 +154,7 @@ public class ModelStorage {
{
getSystemModel().getApps().forEach(app->{
app.getPages().forEach(item->{
CliOption opt=newCliOption(TemplateFileType.page).baseData(item,item.getCodeName().toLowerCase()).set("apps",app.getCodeName().toLowerCase()).set("appModules",item.getAppModule());
CliOption opt=newCliOption(TemplateFileType.page).baseData(item,item.getCodeName().toSpinalCase()).set("apps",app.getCodeName().toLowerCase()).set("appModules",item.getAppModule().toSpinalCase());
rt.addOption(opt);
});
});
......@@ -163,7 +163,7 @@ public class ModelStorage {
{
getSystemModel().getApps().forEach(app->{
app.getCtrls().forEach(item->{
CliOption opt=newCliOption(TemplateFileType.ctrl).baseData(item,item.getCodeName().toLowerCase()).set("apps",app.getCodeName().toLowerCase()).set("appEntities",item.getFolder().toLowerCase());
CliOption opt=newCliOption(TemplateFileType.ctrl).baseData(item,item.getCodeName().toSpinalCase()).set("apps",app.getCodeName().toLowerCase()).set("appEntities",item.getFolder().toSpinalCase());
rt.addOption(opt);
});
});
......
......@@ -35,10 +35,10 @@ public class PageModel extends BaseModel{
if(ctrl.getControl().getPSAppDataEntity()!=null) {
AppEntityModel ctrlAppEntity=app.getAppEntity(ctrl.getControl().getPSAppDataEntity().getCodeName());
ctrl.setAppEntity(ctrlAppEntity);
ctrlAppEntity.addCtrl(ctrl.getCodeName(),ctrl);
ctrlAppEntity.addCtrl(ctrl.getCodeName().toString(),ctrl);
}
this.app.getCtrlsMap().put(ctrl.getId(),ctrl);
this.ctrlsMap.put(ctrl.getCodeName(),ctrl);
this.ctrlsMap.put(ctrl.getCodeName().toString(),ctrl);
}
});
}
......@@ -54,14 +54,13 @@ public class PageModel extends BaseModel{
private AppEntityModel appEntity;
public String getAppModule()
public LabelExt getAppModule()
{
if(getAppView().getPSAppDataEntity()==null)
return "default";
String appModules=getAppView().getPSAppDataEntity().getCodeName();
String appModules="default";
if(getAppView().getPSAppDataEntity()!=null)
appModules=getAppView().getPSAppDataEntity().getCodeName();
appModules=appModules.toLowerCase();
return appModules;
return new LabelExt(appModules);
}
private Map<String,CtrlModel> ctrlsMap=new LinkedHashMap<>();
......
......@@ -297,7 +297,7 @@ public class TransUtils {
}
else if(!dataSet.getDatasetId().startsWith(entityModel.getEntityName().toLowerCase()+"-"))
{
POSchema.Segment segment=new POSchema.Segment().setName(dataSet.getCodeName()).setVendorProvider(dataSourceType).setBody(dataSet.getDsCode());
POSchema.Segment segment=new POSchema.Segment().setName(dataSet.getCodeName().toString()).setVendorProvider(dataSourceType).setBody(dataSet.getDsCode());
if(!StringUtils.isEmpty(dataSet.getDsModel()))
segment.setFormat(dataSet.getDsModel());
poSchema.addSegment(segment);
......
/*
* Copyright 2018 OpenAPI-Generator Contributors (https://openapi-generator.tech)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package cn.ibizlab.codegen.templating.mustache;
import cn.ibizlab.codegen.utils.StringAdvUtils;
import com.samskivert.mustache.Mustache;
import com.samskivert.mustache.Template;
import java.io.IOException;
import java.io.Writer;
/**
* Converts text in a fragment to snake case.
*
* Register:
* <pre>
* additionalProperties.put("snakecase", new SnakecaseLambda());
* </pre>
*
* Use:
* <pre>
* {{#snakecase}}{{summary}}{{/snakecase}}
* </pre>
*/
public class SpinalcaseLambda implements Mustache.Lambda {
@Override
public void execute(Template.Fragment fragment, Writer writer) throws IOException {
writer.write(StringAdvUtils.dashize(fragment.execute()));
}
}
......@@ -109,6 +109,23 @@ public class StringAdvUtils {
return camelize(word, false);
}
public static String pascalcase(String word) {
return camelize(word, true);
}
public static String camelcase(String word) {
return camelize(word, false);
}
public static String spinalcase(String word) {
return dashize(word);
}
public static String snakecase(String word) {
return underscore(word);
}
private static Pattern camelizeSlashPattern = Pattern.compile("\\/(.?)");
private static Pattern camelizeUppercasePattern = Pattern.compile("(\\.?)(\\w)([^\\.]*)$");
private static Pattern camelizeUnderscorePattern = Pattern.compile("(_)(.)");
......
预定义代码片段模板目录
其余模板文件引用时可以使用 {{>././.def/pub.txt}} 方式引用,支持相对路径
\ No newline at end of file
**.ibizlab-generator-ignore
**.DS_Store
\ No newline at end of file
**.DS_Store
**.def/**
\ No newline at end of file
{{#appEntity.ctrls}}
这里是应用实体ctrl的代码名称 {{codeName}}
lowercase {{#lowercase}}{{codeName}}{{/lowercase}}
UPPERCASE {{#uppercase}}{{codeName}}{{/uppercase}}
PascalCase {{#pascalcase}}{{codeName}}{{/pascalcase}}
camelCase {{#camelcase}}{{codeName}}{{/camelcase}}
snake_case {{#snakecase}}{{codeName}}{{/snakecase}}
spinal-case {{#spinalcase}}{{codeName}}{{/spinalcase}}
另一种便捷写法,只支持codeNamename
lowercase {{codeName.lowerCase}}
UPPERCASE {{codeName.upperCase}}
PascalCase {{codeName.pascalCase}}
camelCase {{codeName.camelCase}}
snake_case {{codeName.snakeCase}}
spinal-case {{codeName.spinalCase}}
{{/appEntity.ctrls}}
\ No newline at end of file
......@@ -9,7 +9,7 @@
<name>{{projectDesc}}</name>
<description></description>
<packaging>pom</packaging>
{{> {{{{projectName}}}}-util/pom.xml}}
<parent>
<groupId>{{packageName}}</groupId>
<artifactId>{{projectName}}-dependencies</artifactId>
......
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册