提交 24e16db1 编写于 作者: ibiz4j's avatar ibiz4j

xiugai

上级 34a81fb9
......@@ -12,4 +12,5 @@
**.iml
*.jar
*.log
.model
.DS_Store
......@@ -115,6 +115,7 @@ public class CodegenConfig {
additionalProperties.put("snakecase", new SnakecaseLambda());
additionalProperties.put("spinalcase", new SpinalcaseLambda());
additionalProperties.put("titlecase", new TitlecaseLambda());
additionalProperties.put("pluralize", new PluralizeLambda());
additionalProperties.put("camelcase", new CamelCaseLambda(true).generator(this));
additionalProperties.put("pascalcase", new CamelCaseLambda(false).generator(this));
additionalProperties.put("indented", new IndentedLambda());
......
......@@ -32,29 +32,29 @@ public class EntityModel extends BaseModel {
public String getEntityName() {
return getEntity().getName();
return getDataEntity().getName();
}
public String getTableName() {
return getEntity().getTableName();
return getDataEntity().getTableName();
}
public String getLogicName() {
return getEntity().getLogicName();
return getDataEntity().getLogicName();
}
public String getModule() {
if(getEntity().getPSSystemModule()!=null)
return getEntity().getPSSystemModule().getCodeName().toLowerCase();
if(getDataEntity().getPSSystemModule()!=null)
return getDataEntity().getPSSystemModule().getCodeName().toLowerCase();
return "ungroup";
}
public IPSDataEntity getEntity(){
public IPSDataEntity getDataEntity(){
return (IPSDataEntity)opt;
}
......@@ -159,7 +159,7 @@ public class EntityModel extends BaseModel {
public boolean isLogicValid()
{
return getEntity().isLogicValid();
return getDataEntity().isLogicValid();
}
......@@ -184,7 +184,7 @@ public class EntityModel extends BaseModel {
public String getValidLogicValue()
{
String validLogicValue=this.getEntity().getValidLogicValue();
String validLogicValue=this.getDataEntity().getValidLogicValue();
if(StringUtils.isEmpty(validLogicValue))
validLogicValue="1";
return validLogicValue;
......@@ -193,7 +193,7 @@ public class EntityModel extends BaseModel {
public String getInvalidLogicValue()
{
String invalidLogicValue=this.getEntity().getInvalidLogicValue();
String invalidLogicValue=this.getDataEntity().getInvalidLogicValue();
if(StringUtils.isEmpty(invalidLogicValue))
invalidLogicValue="0";
return invalidLogicValue;
......@@ -245,7 +245,7 @@ public class EntityModel extends BaseModel {
public String getDsName()
{
String dsName=this.getEntity().getDSLink();
String dsName=this.getDataEntity().getDSLink();
if(StringUtils.isEmpty(dsName)||"DEFAULT".equalsIgnoreCase(dsName))
{
dsName="master";
......@@ -383,6 +383,8 @@ public class EntityModel extends BaseModel {
rel.setRelationType(der.getDERType()).setCodeName(der.getCodeName()).setEntityId(der.getMajorPSDataEntity().getId())
.setEntityCodeName(der.getMajorPSDataEntity().getCodeName()).setEntityName(der.getMajorPSDataEntity().getName())
.setEntityLogicName(der.getMajorPSDataEntity().getLogicName()).setTableName(der.getMajorPSDataEntity().getTableName());
if(der.getMajorPSDataEntity().getPSSystemModule()!=null)
rel.setModule(der.getMajorPSDataEntity().getPSSystemModule().getCodeName().toLowerCase());
......@@ -406,25 +408,45 @@ public class EntityModel extends BaseModel {
{
for(IPSDERBase der : dataEntity.getMajorPSDERs())
{
if(StringUtils.isEmpty(der.getMinorCodeName()))
continue;
RelationshipModel rel=new RelationshipModel(this,der);
rel.setRelationType(der.getDERType()).setCodeName(der.getMinorCodeName()).setEntityId(der.getMinorPSDataEntity().getId())
.setEntityCodeName(der.getMinorPSDataEntity().getCodeName()).setEntityName(der.getMinorPSDataEntity().getName())
.setEntityLogicName(der.getMinorPSDataEntity().getLogicName()).setTableName(der.getMinorPSDataEntity().getTableName());
if(der instanceof IPSDER1N)
{
IPSDER1N der1n=(IPSDER1N)der;
String codeName=der.getMinorCodeName();
boolean nestedRS=false;
if(der1n.isNestedRS())
nestedRS=true;
else if(der1n.getPSOne2ManyDataDEField()!=null)
{
nestedRS=true;
}
else if(der1n.getMinorPSDataEntity().getPSSubSysServiceAPIDE()!=null&&der1n.getMinorPSDataEntity().getPSSubSysServiceAPIDE().isNested())
{
nestedRS=true;
}
if(!nestedRS)
continue;
if(StringUtils.isEmpty(codeName))
codeName=der.getMinorPSDataEntity().getCodeName();
RelationshipModel rel=new RelationshipModel(this,der);
rel.setRelationType(der.getDERType()).setCodeName(codeName).setEntityId(der.getMinorPSDataEntity().getId())
.setEntityCodeName(der.getMinorPSDataEntity().getCodeName()).setEntityName(der.getMinorPSDataEntity().getName())
.setEntityLogicName(der.getMinorPSDataEntity().getLogicName()).setTableName(der.getMinorPSDataEntity().getTableName());
if(der.getMinorPSDataEntity().getPSSystemModule()!=null)
rel.setModule(der.getMinorPSDataEntity().getPSSystemModule().getCodeName().toLowerCase());
String relfieldname=der1n.getPSPickupDEField().getObjectNode().get("getRelatedPSDEField").get("name").asText();
LookupModel lookupModel=new LookupModel().setRelationid(der.getId())
.setFieldname(der1n.getPickupDEFName()).setReffieldname(relfieldname);
rel.addLookup(lookupModel);
this.addNested(rel);
}
this.addNested(rel);
}
}
......@@ -432,14 +454,17 @@ public class EntityModel extends BaseModel {
for(IPSDEField defield:dataEntity.getAllPSDEFields())
{
String dict=null;
try { dict=defield.getPSCodeList()!=null?defield.getPSCodeList().getCodeName():null; } catch (Exception ex){}
if(defield.isPasteReset())
this.hasResetField=true;
FieldModel fieldModel=new FieldModel(this,defield);
try {
fieldModel.setDict(defield.getPSCodeList()!=null?defield.getPSCodeList().getCodeName():null);
} catch (Exception ex){}
if(defield.getAllPSDEFDTColumns()!=null)
{
defield.getAllPSDEFDTColumns().forEach(col->{
......
......@@ -8,9 +8,16 @@ import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.experimental.Accessors;
import net.ibizsys.model.dataentity.defield.IPSDEField;
import org.springframework.util.ObjectUtils;
import org.springframework.util.StringUtils;
import cn.ibizlab.codegen.utils.StringAdvUtils;
import java.security.Timestamp;
import java.util.ArrayList;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;
@Getter
......@@ -34,6 +41,85 @@ public class FieldModel extends BaseModel {
return getDataEntityField().getName();
}
public String getColumnName() {
return getFieldName().toLowerCase();
}
public String getJsonName() {
return getDataEntityField().getCodeName().toLowerCase();
}
private String format;
private String timeType;
public String getTimeType()
{
getFormat();
return timeType;
}
public String getFormat(){
if("Timestamp".equals(getType().getJava())&&StringUtils.isEmpty(format))
{
if(getDataEntityField().getDataType().equals("DATE")||"%1$tY-%1$tm-%1$td".equalsIgnoreCase(getDataEntityField().getValueFormat())){
timeType="DATE";
format = "yyyy-MM-dd";
}
else if(getDataEntityField().getDataType().equals("TIME")||"%1$tH:%1$tM:%1$tS".equalsIgnoreCase(getDataEntityField().getValueFormat())){
timeType="TIME";
format = "HH:mm:ss";
}
else{
timeType="DATETIME";
format = "yyyy-MM-dd HH:mm:ss";
}
}
return format;
}
public boolean isEnableAudit()
{
return getDataEntityField().isEnableAudit()&&this.getEntity().getDataEntity()!=null&&this.getEntity().getDataEntity().getAuditMode()!=0;
}
public String getAnnotation()
{
String annotation="name = \""+getFieldName().toLowerCase()+"\"";
if(!StringUtils.isEmpty(getDataEntityField().getDefaultValue()))
annotation+=" , defaultValue = \""+getDataEntityField().getDefaultValue()+"\"";
if(!StringUtils.isEmpty(getDataEntityField().getDefaultValueType()))
annotation+=" , defaultValueType = DEFieldDefaultValueType."+getDataEntityField().getDefaultValueType().toUpperCase();
if(isKeyDEField())
annotation+=" , isKeyField = true";
if(!StringUtils.isEmpty(getDataEntityField().getPredefinedType()))
annotation+=" , preType = DEPredefinedFieldType."+getDataEntityField().getPredefinedType().toUpperCase();
if(isLogicValidField()){
annotation+=" , logicval = \""+getEntity().getValidLogicValue()+"\"";
annotation+=" , logicdelval = \""+getEntity().getInvalidLogicValue()+"\"";
}
if(!StringUtils.isEmpty(dict))
annotation+=" , dict = \""+dict+"\"";
if("ALL".equalsIgnoreCase(getDataEntityField().getDupCheckMode()))
{
annotation+=" , dupCheck = DupCheck.ALL";
if(!ObjectUtils.isEmpty(getDataEntityField().getDupCheckPSDEFields()))
{
List<String> dups=new ArrayList<>();
for(IPSDEField dup:getDataEntityField().getDupCheckPSDEFields()){
dups.add(StringAdvUtils.camelcase(dup.getCodeName()));
}
if(dups.size()>0)
annotation+=" , dupCheckField = \""+String.join(",", dups)+"\"";
}
}
if(isEnableAudit()&&getFormat()!=null)
annotation+=" , fieldType = \""+timeType+"\", format = \""+format+"\"";
if(getDataEntityField().isMultiFormDEField() && getEntity().getDataEntity()!=null && (getEntity().getDataEntity().getDynaInstMode()==1||getEntity().getDataEntity().getDynaInstMode()==1))
annotation+=" , dynaInstTagField = true";
return annotation;
}
public String getLogicName() {
return getDataEntityField().getLogicName();
}
......@@ -45,6 +131,7 @@ public class FieldModel extends BaseModel {
private String expression;
private String dict;
public IPSDEField getDataEntityField()
{
......@@ -84,6 +171,11 @@ public class FieldModel extends BaseModel {
return "CREATEDATE".equals(this.getDataEntityField().getPredefinedType());
}
public boolean isInsertOnly()
{
return "CREATEDATE".equals(this.getDataEntityField().getPredefinedType())||"CREATEMAN".equals(this.getDataEntityField().getPredefinedType());
}
public boolean isUnionKeyField()
{
return !StringUtils.isEmpty(this.getDataEntityField().getUnionKeyValue());
......
package cn.ibizlab.codegen.model;
import cn.ibizlab.codegen.utils.Inflector;
import cn.ibizlab.codegen.utils.StringAdvUtils;
import org.springframework.util.StringUtils;
......@@ -23,7 +24,6 @@ public class LabelExt implements java.io.Serializable, Comparable<String>, CharS
return label.toUpperCase();
}
public String toPascalCase() {
return StringAdvUtils.pascalcase(label);
}
......@@ -44,6 +44,10 @@ public class LabelExt implements java.io.Serializable, Comparable<String>, CharS
return StringAdvUtils.snakecase(label);
}
public String toPluralize() {
return Inflector.getInstance().pluralize(label);
}
public String getLowerCase()
{
return toLowerCase();
......@@ -54,7 +58,6 @@ public class LabelExt implements java.io.Serializable, Comparable<String>, CharS
return toUpperCase();
}
public String getPascalCase() {
return toPascalCase();
}
......@@ -75,6 +78,10 @@ public class LabelExt implements java.io.Serializable, Comparable<String>, CharS
return toSnakeCase();
}
public String getPluralize() {
return toPluralize();
}
@Override
public int length() {
......
......@@ -41,11 +41,17 @@ public class RelationshipModel extends BaseModel{
private String entityId;
private String module;
private String tableName;
private String relationType;
private boolean nested;
private String listCode;
public IPSDERBase getDer()
{
......
......@@ -207,7 +207,7 @@ public class TransUtils {
POSchema poSchema=new POSchema().setDsType(dataSourceType).setName(entityModel.getTableName(dataSourceType)).setDefaultDataSource(entityModel.getDsName())
.setRemarks(entityModel.getLogicName()).setLogicVal(entityModel.getValidLogicValue()).setLogicDelVal(entityModel.getInvalidLogicValue());
poSchema.setNode(entityModel.getEntity());
poSchema.setNode(entityModel.getDataEntity());
Map<String,FieldModel> keyMap=new LinkedHashMap<>();
Map<String,RelationshipModel> relationshipModelMap = new LinkedHashMap<>();
......
......@@ -16,6 +16,7 @@
package cn.ibizlab.codegen.templating;
import com.samskivert.mustache.Escapers;
import com.samskivert.mustache.Mustache;
import com.samskivert.mustache.Template;
import org.slf4j.Logger;
......@@ -56,6 +57,7 @@ public class MustacheEngineAdapter implements TemplatingEngineAdapter {
public String compileTemplate(TemplatingExecutor executor, Map<String, Object> bundle, String templateFile) throws IOException {
Template tmpl = compiler
.withLoader(name -> findTemplate(executor, name))
.withEscaper(Escapers.NONE)
.defaultValue("")
.compile(executor.getFullTemplateContents(templateFile));
......
/*
* Copyright 2018 OpenAPI-Generator Contributors (https://openapi-generator.tech)
* Copyright 2018 SmartBear Software
*
* 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.CodegenConfig;
import cn.ibizlab.codegen.utils.Inflector;
import com.samskivert.mustache.Mustache;
import com.samskivert.mustache.Template;
import java.io.IOException;
import java.io.Writer;
/**
* Converts text in a fragment to lowercase.
*
* Register:
* <pre>
* additionalProperties.put("lowercase", new LowercaseLambda());
* </pre>
*
* Use:
* <pre>
* {{#lowercase}}{{httpMethod}}{{/lowercase}}
* </pre>
*/
public class PluralizeLambda implements Mustache.Lambda {
private CodegenConfig generator = null;
public PluralizeLambda() {
}
public PluralizeLambda generator(final CodegenConfig generator) {
this.generator = generator;
return this;
}
@Override
public void execute(Template.Fragment fragment, Writer writer) throws IOException {
String text = Inflector.getInstance().pluralize(fragment.execute());
writer.write(text);
}
}
......@@ -9,7 +9,7 @@
<name>{{projectDesc}}</name>
<description></description>
<packaging>pom</packaging>
{{>{{{{!}}projectName}}-util/pom.xml}}
<parent>
<groupId>{{packageName}}</groupId>
<artifactId>{{projectName}}-dependencies</artifactId>
......
......@@ -4,8 +4,8 @@ import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.math.BigInteger;
import java.util.HashMap;
import java.math.BigInteger;
import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import com.alibaba.fastjson.annotation.JSONField;
......@@ -19,16 +19,16 @@ import {{packageName}}.util.annotation.DEField;
import {{packageName}}.util.enums.DEPredefinedFieldType;
import {{packageName}}.util.enums.DEFieldDefaultValueType;
import {{packageName}}.util.helper.DataObject;
import {{packageName}}.util.annotation.Audit;
import {{packageName}}.util.enums.DupCheck;
import {{packageName}}.util.domain.EntityMP;
import java.io.Serializable;
import lombok.*;
import org.springframework.data.annotation.Transient;
import {{packageName}}.util.annotation.Audit;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.baomidou.mybatisplus.annotation.*;
import {{packageName}}.util.domain.EntityMP;
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
@Getter
......@@ -38,27 +38,59 @@ import com.baomidou.mybatisplus.core.toolkit.IdWorker;
@JsonIgnoreProperties(value = "handler")
@TableName(value = "{{entity.tableName}}", resultMap = "{{entity.codeName}}ResultMap")
@ApiModel("{{entity.logicName}}")
public class {{entity.codeName}} extends EntityMP implements Serializable
public class {{entity.codeName}} extends EntityMP implements Serializable
{
{{#entity.fields}}
/**
* {{logicName}}
*/
{{#keyDEField}}
@TableId(value = "{{name.lowerCase}}"{{#type.number}} , type = IdType.ASSIGN_ID{{/type.number}}{{#type.string}} , type = IdType.ASSIGN_UUID{{/type.string}})
{{#phisicalDEField}}
@TableId(value = "{{columnName}}"{{#type.number}} , type = IdType.ASSIGN_ID{{/type.number}}{{#type.string}} , type = IdType.ASSIGN_UUID{{/type.string}})
{{/phisicalDEField}}
{{/keyDEField}}
{{^keyDEField}}
@TableField(value = "{{name.lowerCase}}"{{^phisicalDEField}} , exist = false{{/phisicalDEField}})
@TableField(value = "{{columnName}}"{{#insertOnly}} , fill = FieldFill.INSERT{{/insertOnly}}{{^phisicalDEField}} , exist = false{{/phisicalDEField}})
{{#logicValidField}}
@TableLogic{{#validLogicValue}}(value = "{{validLogicValue}}"{{#invalidLogicValue}} , delval = "{{invalidLogicValue}}"{{/invalidLogicValue}}){{/validLogicValue}}
{{/logicValidField}}
{{/keyDEField}}
@JsonProperty("{{codeName.lowerCase}}")
@JSONField(name = "{{codeName.lowerCase}}")
{{#enableAudit}}
@Audit
{{/enableAudit}}
@Defield({{annotation}})
@JsonProperty("{{jsonName}}")
{{#timeType}}
@JsonFormat(pattern = "{{format}}", locale = "zh", timezone = "GMT+8")
{{/timeType}}
@JSONField(name = "{{jsonName}}"{{#timeType}} , format = "{{format}}"{{/timeType}})
@ApiModelProperty("{{logicName}}")
private {{type.java}} {{codeName.camelCase}};
{{/entity.fields}}
{{#entity.references}}
/**
* {{logicName}}
*/
@JsonIgnore
@JSONField(serialize = false)
@TableField(exist = false)
private {{packageName}}.core.{{module}}.domain.{{entityCodeName}} {{codeName.camelCase}};
{{/entity.references}}
{{#entity.fields}}
{{^keyDEField}}
{{^predefinedType}}
public {{entity.codeName}} set{{codeName.pascalCase}}({{type.java}} {{codeName.camelCase}}) {
this.{{codeName.camelCase}} = {{codeName.camelCase}};
this.modify("{{name.lowerCase}}", {{codeName.camelCase}});
return this;
}
{{/predefinedType}}
{{/keyDEField}}
{{/entity.fields}}
}
\ No newline at end of file
package {{packageName}}.{{entity.module}}.service.impl;
package {{packageName}}.core.{{entity.module}}.service.impl;
import {{packageName}}.{{entity.module}}.service.I{{entity.codeName}}Service;
import {{packageName}}.core.{{entity.module}}.service.I{{entity.codeName}}Service;
public class {{entity.codeName}}ServiceImpl implements I{{entity.codeName}}Service
{
......
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册