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

url 兼容map

上级 e0ab321f
......@@ -11,6 +11,7 @@ import com.alibaba.fastjson.annotation.JSONField;
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import org.springframework.util.DigestUtils;
import org.springframework.util.ObjectUtils;
import cn.ibizlab.util.helper.DataObject;
import java.io.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()))
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
key=IdWorker.get32UUID();
}
data.set(keyPropertyName,key);
}
else
......
......@@ -139,7 +139,6 @@ public class PojoSchema {
if(properties!=null)
{
properties.values().forEach(prop->{
PojoSchema item=null;
if(Type.object.getCode().equalsIgnoreCase(prop.getType())&&(!StringUtils.isEmpty(prop.getRef())))
item=prop;
......@@ -149,9 +148,6 @@ public class PojoSchema {
item=prop.getItems();
else
return;
});
}
built=true;
......@@ -235,6 +231,11 @@ public class PojoSchema {
@JSONField(serialize = false)
private Map<String,PojoSchema> keyMap;
@JsonIgnore
@JSONField(serialize = false)
private Set<String> unionKeys;
@JsonIgnore
@JSONField(serialize = false)
public synchronized Map<String,PojoSchema> getKeyMap()
......@@ -243,24 +244,55 @@ public class PojoSchema {
{
if(keyMap==null)
{
List<PojoSchema> keys=new ArrayList<>();
keyMap=new LinkedHashMap<>();
getProperties().values().forEach(sub->{
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->{
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;
}
@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
......@@ -273,7 +305,9 @@ public class PojoSchema {
@JSONField(ordinal = 23)
private Boolean uniqueItems;
public void setUniqueItems(Boolean uniqueItems) {
this.uniqueItems = uniqueItems;
}
/// String
......
......@@ -267,8 +267,6 @@ public class TransUtils {
if(pojoSchema.getKeyMap()!=null&&pojoSchema.getKeyMap().containsKey(column.getName())) {
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);
}
if(sub.getOptions().isLogicValidField())
......@@ -285,8 +283,6 @@ public class TransUtils {
{
String fkName=sub.getOptions().getRelationName().toUpperCase();
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);
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 {
if(keyMap.containsKey(column.getName())) {
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);
}
if(fieldModel.isLogicValidField())
......@@ -359,8 +353,6 @@ public class TransUtils {
RelationshipModel relationshipModel=relationshipModelMap.get(sub.getRelationName());
String fkName=sub.getRelationName().toUpperCase();
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())
.setReferencedColumnNames(sub.getRefFieldName()).setForeignKeyName(fkName);
......@@ -369,6 +361,14 @@ public class TransUtils {
.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())
poSchema.addTransient(column.setComputed(true));
......
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册