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

url 兼容map

上级 e0ab321f
...@@ -11,6 +11,7 @@ import com.alibaba.fastjson.annotation.JSONField; ...@@ -11,6 +11,7 @@ import com.alibaba.fastjson.annotation.JSONField;
import com.baomidou.mybatisplus.core.toolkit.IdWorker; import com.baomidou.mybatisplus.core.toolkit.IdWorker;
import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonProperty;
import org.springframework.util.DigestUtils;
import org.springframework.util.ObjectUtils; import org.springframework.util.ObjectUtils;
import cn.ibizlab.util.helper.DataObject; import cn.ibizlab.util.helper.DataObject;
import java.io.Serializable; import java.io.Serializable;
...@@ -191,8 +192,26 @@ public class DOModel implements Serializable { ...@@ -191,8 +192,26 @@ public class DOModel implements Serializable {
{ {
if(PojoSchema.Type.integer.getCode().equals(keyProperty.getType())||PojoSchema.Type.number.getCode().equals(keyProperty.getType())) if(PojoSchema.Type.integer.getCode().equals(keyProperty.getType())||PojoSchema.Type.number.getCode().equals(keyProperty.getType()))
key=IdWorker.getId(); key=IdWorker.getId();
else
{
Set<String> unionKeys=this.getSchema().getUnionKeys();
if(!ObjectUtils.isEmpty(unionKeys))
{
for(String unionkey:unionKeys)
{
if(ObjectUtils.isEmpty(data.get(unionkey.toLowerCase())))
return null;
if(!StringUtils.isEmpty(key))
key+="||";
else
key+=data.getStringValue(unionkey.toLowerCase());
}
key=DigestUtils.md5DigestAsHex(key.toString().getBytes());
}
else else
key=IdWorker.get32UUID(); key=IdWorker.get32UUID();
}
data.set(keyPropertyName,key); data.set(keyPropertyName,key);
} }
else else
......
...@@ -139,7 +139,6 @@ public class PojoSchema { ...@@ -139,7 +139,6 @@ public class PojoSchema {
if(properties!=null) if(properties!=null)
{ {
properties.values().forEach(prop->{ properties.values().forEach(prop->{
PojoSchema item=null; PojoSchema item=null;
if(Type.object.getCode().equalsIgnoreCase(prop.getType())&&(!StringUtils.isEmpty(prop.getRef()))) if(Type.object.getCode().equalsIgnoreCase(prop.getType())&&(!StringUtils.isEmpty(prop.getRef())))
item=prop; item=prop;
...@@ -149,9 +148,6 @@ public class PojoSchema { ...@@ -149,9 +148,6 @@ public class PojoSchema {
item=prop.getItems(); item=prop.getItems();
else else
return; return;
}); });
} }
built=true; built=true;
...@@ -235,6 +231,11 @@ public class PojoSchema { ...@@ -235,6 +231,11 @@ public class PojoSchema {
@JSONField(serialize = false) @JSONField(serialize = false)
private Map<String,PojoSchema> keyMap; private Map<String,PojoSchema> keyMap;
@JsonIgnore
@JSONField(serialize = false)
private Set<String> unionKeys;
@JsonIgnore @JsonIgnore
@JSONField(serialize = false) @JSONField(serialize = false)
public synchronized Map<String,PojoSchema> getKeyMap() public synchronized Map<String,PojoSchema> getKeyMap()
...@@ -243,24 +244,55 @@ public class PojoSchema { ...@@ -243,24 +244,55 @@ public class PojoSchema {
{ {
if(keyMap==null) if(keyMap==null)
{ {
List<PojoSchema> keys=new ArrayList<>();
keyMap=new LinkedHashMap<>(); keyMap=new LinkedHashMap<>();
getProperties().values().forEach(sub->{ getProperties().values().forEach(sub->{
if(sub.getOptions().isKeyField()&&sub.getOptions().isPhysicalField()) if(sub.getOptions().isKeyField()&&sub.getOptions().isPhysicalField())
keyMap.put(sub.getOptions().getFieldName(),sub); keys.add(sub);
}); });
if(keyMap.isEmpty()) if(keys.isEmpty())
{ {
getProperties().values().forEach(sub->{ getProperties().values().forEach(sub->{
if(sub.getOptions().isUnionKeyField()&&sub.getOptions().isPhysicalField()) if(sub.getOptions().isUnionKeyField()&&sub.getOptions().isPhysicalField())
keyMap.put(sub.getOptions().getFieldName(),sub); keys.add(sub);
}); });
} }
if(keys.size()>0)
keys.sort( (o1, o2) -> o1.getOptions().getUnionKey().compareTo(o2.getOptions().getUnionKey()) );
keys.forEach(sub->keyMap.put(sub.getOptions().getFieldName(),sub));
} }
} }
return keyMap; return keyMap;
} }
@JsonIgnore
@JSONField(serialize = false)
public synchronized Set<String> getUnionKeys()
{
if(Type.object.getCode().equals(this.type)) {
if (unionKeys == null) {
List<PojoSchema> keys=new ArrayList<>();
Set<String> unions=new LinkedHashSet<>();
if(keys.isEmpty())
{
getProperties().values().forEach(sub->{
if(sub.getOptions().isUnionKeyField()&&sub.getOptions().isPhysicalField())
keys.add(sub);
});
}
if(keys.size()>0) {
keys.sort((o1, o2) -> o1.getOptions().getUnionKey().compareTo(o2.getOptions().getUnionKey()));
keys.forEach(sub -> unions.add(sub.getName()));
unionKeys=unions;
}
}
}
return unionKeys;
}
//// array //// array
...@@ -273,7 +305,9 @@ public class PojoSchema { ...@@ -273,7 +305,9 @@ public class PojoSchema {
@JSONField(ordinal = 23) @JSONField(ordinal = 23)
private Boolean uniqueItems; private Boolean uniqueItems;
public void setUniqueItems(Boolean uniqueItems) {
this.uniqueItems = uniqueItems;
}
/// String /// String
......
...@@ -267,8 +267,6 @@ public class TransUtils { ...@@ -267,8 +267,6 @@ public class TransUtils {
if(pojoSchema.getKeyMap()!=null&&pojoSchema.getKeyMap().containsKey(column.getName())) { if(pojoSchema.getKeyMap()!=null&&pojoSchema.getKeyMap().containsKey(column.getName())) {
String primaryKeyName="PK_"+poSchema.getName().toUpperCase()+"_"+ column.getName().toUpperCase(); String primaryKeyName="PK_"+poSchema.getName().toUpperCase()+"_"+ column.getName().toUpperCase();
if(primaryKeyName.length()>30)
primaryKeyName=primaryKeyName.substring(0,30);
column.getConstraints(true).setPrimaryKey(true).setPrimaryKeyName(primaryKeyName); column.getConstraints(true).setPrimaryKey(true).setPrimaryKeyName(primaryKeyName);
} }
if(sub.getOptions().isLogicValidField()) if(sub.getOptions().isLogicValidField())
...@@ -285,8 +283,6 @@ public class TransUtils { ...@@ -285,8 +283,6 @@ public class TransUtils {
{ {
String fkName=sub.getOptions().getRelationName().toUpperCase(); String fkName=sub.getOptions().getRelationName().toUpperCase();
if((!StringUtils.isEmpty(sub.getOptions().getRefTableName()))&&(!StringUtils.isEmpty(fkName))) { if((!StringUtils.isEmpty(sub.getOptions().getRefTableName()))&&(!StringUtils.isEmpty(fkName))) {
if(fkName.length()>30)
fkName=fkName.substring(0,30);
column.getConstraints(true).setReferencedTableName(sub.getOptions().getRefTableName()).setReferencedColumnNames(sub.getOptions().getRefFieldName()).setForeignKeyName(fkName); column.getConstraints(true).setReferencedTableName(sub.getOptions().getRefTableName()).setReferencedColumnNames(sub.getOptions().getRefFieldName()).setForeignKeyName(fkName);
poSchema.addForeignKeyConstraint(new POSchema.ForeignKeyConstraint().setConstraintName(fkName).setBaseTableName(poSchema.getName()).setBaseColumnNames(column.getName()).setReferencedTableName(sub.getOptions().getRefTableName()).setReferencedColumnNames(sub.getOptions().getRefFieldName())); poSchema.addForeignKeyConstraint(new POSchema.ForeignKeyConstraint().setConstraintName(fkName).setBaseTableName(poSchema.getName()).setBaseColumnNames(column.getName()).setReferencedTableName(sub.getOptions().getRefTableName()).setReferencedColumnNames(sub.getOptions().getRefFieldName()));
...@@ -338,8 +334,6 @@ public class TransUtils { ...@@ -338,8 +334,6 @@ public class TransUtils {
if(keyMap.containsKey(column.getName())) { if(keyMap.containsKey(column.getName())) {
String primaryKeyName="PK_"+poSchema.getName().toUpperCase()+"_"+ column.getName().toUpperCase(); String primaryKeyName="PK_"+poSchema.getName().toUpperCase()+"_"+ column.getName().toUpperCase();
if(primaryKeyName.length()>30)
primaryKeyName=primaryKeyName.substring(0,30);
column.getConstraints(true).setPrimaryKey(true).setPrimaryKeyName(primaryKeyName); column.getConstraints(true).setPrimaryKey(true).setPrimaryKeyName(primaryKeyName);
} }
if(fieldModel.isLogicValidField()) if(fieldModel.isLogicValidField())
...@@ -359,8 +353,6 @@ public class TransUtils { ...@@ -359,8 +353,6 @@ public class TransUtils {
RelationshipModel relationshipModel=relationshipModelMap.get(sub.getRelationName()); RelationshipModel relationshipModel=relationshipModelMap.get(sub.getRelationName());
String fkName=sub.getRelationName().toUpperCase(); String fkName=sub.getRelationName().toUpperCase();
if(relationshipModel!=null&&(!StringUtils.isEmpty(relationshipModel.getTableName()))&&(!StringUtils.isEmpty(fkName))) { if(relationshipModel!=null&&(!StringUtils.isEmpty(relationshipModel.getTableName()))&&(!StringUtils.isEmpty(fkName))) {
if(fkName.length()>30)
fkName=fkName.substring(0,30);
column.getConstraints(true).setReferencedTableName(relationshipModel.getTableName()) column.getConstraints(true).setReferencedTableName(relationshipModel.getTableName())
.setReferencedColumnNames(sub.getRefFieldName()).setForeignKeyName(fkName); .setReferencedColumnNames(sub.getRefFieldName()).setForeignKeyName(fkName);
...@@ -369,6 +361,14 @@ public class TransUtils { ...@@ -369,6 +361,14 @@ public class TransUtils {
.setReferencedTableName(relationshipModel.getTableName()).setReferencedColumnNames(sub.getRefFieldName())); .setReferencedTableName(relationshipModel.getTableName()).setReferencedColumnNames(sub.getRefFieldName()));
} }
} }
else if((!StringUtils.isEmpty(sub.getRelationName()))) {
RelationshipModel relationshipModel = relationshipModelMap.get(sub.getRelationName());
String fkName=sub.getRelationName().toUpperCase();
if(relationshipModel!=null&&(!StringUtils.isEmpty(relationshipModel.getTableName()))&&(!StringUtils.isEmpty(fkName))) {
column.getConstraints(true).setReferencedTableName(relationshipModel.getTableName())
.setReferencedColumnNames(sub.getRefFieldName());
}
}
if(!fieldModel.isPhysicalField()) if(!fieldModel.isPhysicalField())
poSchema.addTransient(column.setComputed(true)); poSchema.addTransient(column.setComputed(true));
......
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册