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

默认值

上级 189eef7c
......@@ -259,6 +259,23 @@ public class DynamicModelService {
modes.add("query");
metaFieldModel.set("search_modes",String.join(",",modes));
}
if((!StringUtils.isEmpty(defield.getDefaultValueType()))||(!StringUtils.isEmpty(defield.getDefaultValue())))
{
String defaultValue="";
if(StringUtils.isEmpty(defield.getDefaultValueType())||"NONE".equalsIgnoreCase(defield.getDefaultValueType()))
{
defaultValue=defield.getDefaultValue();
}
else if(!StringUtils.isEmpty(defield.getDefaultValue()))
{
defaultValue=String.format("${%1$s.%2$s}",defield.getDefaultValueType(),defield.getDefaultValue());
}
else
{
defaultValue=String.format("${%1$s}",defield.getDefaultValueType());
}
metaFieldModel.set("default_value",defaultValue);
}
fieldModel.setCodeName(metaFieldModel.getCodeName()).setColumnName(metaFieldModel.getFieldName()).setUnionName(metaFieldModel.getFieldUniName()).setShowName(metaFieldModel.getFieldShowName())
.setComment(metaFieldModel.getFieldLogicName()).setField(metaFieldModel);
......
......@@ -402,6 +402,13 @@ public class POSchema {
@JSONField(ordinal = 11)
private Set<String> searchModes;
public Column setDefaultValue(String defaultValue)
{
if((!StringUtils.isEmpty(defaultValue))&&(!defaultValue.startsWith("$")))
this.defaultValue=defaultValue;
return this;
}
public Column putSearchModes(String searchModes)
{
......
......@@ -232,11 +232,11 @@ public class PojoOption extends DataObj
return this.set("dict",dict);
}
public String getDefaultValue() {
return this.getStringValue("defaultValue");
return this.getStringValue("default_value");
}
public PojoOption setDefaultValue(String defaultValue) {
return this.set("defaultValue",defaultValue);
return this.set("default_value",defaultValue);
}
public String getDataType() {
return this.getStringValue("data_type");
......
......@@ -5,6 +5,7 @@ import cn.ibizlab.core.data.dto.FilterData;
import cn.ibizlab.util.errors.BadRequestAlertException;
import cn.ibizlab.util.helper.DataObject;
import cn.ibizlab.util.helper.Inflector;
import cn.ibizlab.util.security.AuthenticationUser;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.annotation.JSONField;
......@@ -27,6 +28,7 @@ import java.math.BigDecimal;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.StandardOpenOption;
import java.sql.Timestamp;
import java.util.*;
@Getter
......@@ -56,7 +58,7 @@ public class PojoSchema {
public String getName()
{
if(name==null)
name=this.getOptions()==null?"":this.getOptions().getName();
name=this.getOptions().getName();
return name;
}
......@@ -76,35 +78,35 @@ public class PojoSchema {
@JsonIgnore
public String getCodeName()
{
return this.getOptions()==null?this.getName():this.getOptions().getStringValue("code_name",this.getName());
return this.getOptions().getStringValue("code_name",this.getName());
}
@JSONField(serialize = false)
@JsonIgnore
public String getSystem()
{
return this.getOptions()==null?"":this.getOptions().getSystem();
return this.getOptions().getSystem();
}
@JSONField(serialize = false)
@JsonIgnore
public String getDefaultDataSoruce()
{
return this.getOptions()==null?"":this.getOptions().getDefaultDataSoruce();
return this.getOptions().getDefaultDataSoruce();
}
@JSONField(serialize = false)
@JsonIgnore
public String getDefaultTableName()
{
return this.getOptions()==null?"":this.getOptions().getTableName();
return this.getOptions().getTableName();
}
@JSONField(serialize = false)
@JsonIgnore
public String getPackage()
{
return this.getOptions()==null?"":this.getOptions().getSystem();
return this.getOptions().getSystem();
}
......@@ -121,6 +123,13 @@ public class PojoSchema {
@JSONField(ordinal = 6)
private PojoOption options;
public PojoOption getOptions()
{
if(options==null)
options=new PojoOption();
return options;
}
public PojoSchema setOptions(PojoOption options)
{
if(options==null)
......@@ -221,7 +230,7 @@ public class PojoSchema {
{
references=new ArrayList<>();
getProperties().values().forEach(prop->{
if(Type.object.getCode().equalsIgnoreCase(prop.getType())&&prop.getOptions()!=null&&(!StringUtils.isEmpty(prop.getOptions().getRelationName()))) {
if(Type.object.getCode().equalsIgnoreCase(prop.getType())&&(!StringUtils.isEmpty(prop.getOptions().getRelationName()))) {
references.add(prop);
}
});
......@@ -242,7 +251,7 @@ public class PojoSchema {
referenceMap=new LinkedHashMap<>();
getProperties().keySet().forEach(key->{
PojoSchema prop=getProperties().get(key);
if(Type.object.getCode().equalsIgnoreCase(prop.getType())&&prop.getOptions()!=null&&(!StringUtils.isEmpty(prop.getOptions().getRelationName()))) {
if(Type.object.getCode().equalsIgnoreCase(prop.getType())&&(!StringUtils.isEmpty(prop.getOptions().getRelationName()))) {
referenceMap.put(key, prop);
if(!key.equals(key.toLowerCase()))
referenceMap.put(key.toLowerCase(),prop);
......@@ -280,14 +289,14 @@ public class PojoSchema {
public Map<String,PojoSchema> getRefProperties()
{
Map<String,PojoSchema> refProperties=new LinkedHashMap<>();
if(this.getOwner()!=null&&Type.object.getCode().equalsIgnoreCase(this.getType())&&this.getOptions()!=null&&(!StringUtils.isEmpty(this.getOptions().getRelationName())))
if(this.getOwner()!=null&&Type.object.getCode().equalsIgnoreCase(this.getType())&&(!StringUtils.isEmpty(this.getOptions().getRelationName())))
{
this.getOwner().getProperties().entrySet().forEach(entry-> {
String key=entry.getKey();
if(key.equals(this.getName()))
return;
PojoSchema prop = entry.getValue();
if(prop.getOptions()!=null&&(!StringUtils.isEmpty(prop.getOptions().getRelationName()))&&prop.getOptions().getRelationName().equals(this.getOptions().getRelationName()))
if((!StringUtils.isEmpty(prop.getOptions().getRelationName()))&&prop.getOptions().getRelationName().equals(this.getOptions().getRelationName()))
{
refProperties.put(key,prop);
}
......@@ -307,7 +316,7 @@ public class PojoSchema {
if(key.equals(refSchema.getName()))
return;
PojoSchema prop = entry.getValue();
if(prop.getOptions()!=null&&(!StringUtils.isEmpty(prop.getOptions().getRelationName()))&&prop.getOptions().getRelationName().equals(refSchema.getOptions().getRelationName()))
if((!StringUtils.isEmpty(prop.getOptions().getRelationName()))&&prop.getOptions().getRelationName().equals(refSchema.getOptions().getRelationName()))
{
refProperties.put(key,prop);
}
......@@ -335,7 +344,7 @@ public class PojoSchema {
{
required=new LinkedHashSet<>();
properties.values().forEach(prop->{
if (prop.getOptions()!=null&&(!prop.getOptions().isNullable()))
if (!prop.getOptions().isNullable())
required.add(prop.getName());
});
}
......@@ -379,6 +388,8 @@ public class PojoSchema {
List<PojoSchema> keys=new ArrayList<>();
keyMap=new LinkedHashMap<>();
getProperties().values().forEach(sub->{
if(Type.array.getCode().equals(sub.getType())||Type.object.getCode().equals(sub.getType()))
return;
if(sub.getOptions().isKeyField())
keyProperty=sub;
if(sub.getOptions().isKeyField()&&sub.getOptions().isPhysicalField())
......@@ -387,6 +398,8 @@ public class PojoSchema {
if(keys.isEmpty())
{
getProperties().values().forEach(sub->{
if(Type.array.getCode().equals(sub.getType())||Type.object.getCode().equals(sub.getType()))
return;
if(sub.getOptions().isUnionKeyField()&&sub.getOptions().isPhysicalField())
keys.add(sub);
});
......@@ -410,13 +423,12 @@ public class PojoSchema {
List<PojoSchema> keys=new ArrayList<>();
Map<String,PojoSchema> unions=new LinkedHashMap<>();
if(keys.isEmpty())
{
getProperties().values().forEach(sub->{
if(sub.getOptions().isUnionKeyField()&&sub.getOptions().isPhysicalField())
keys.add(sub);
});
}
getProperties().values().forEach(sub->{
if(Type.array.getCode().equals(sub.getType())||Type.object.getCode().equals(sub.getType()))
return;
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.put(sub.getOptions().getFieldName(),sub));
......@@ -657,19 +669,16 @@ public class PojoSchema {
for(Map.Entry<String,PojoSchema> entrySet:refProperties.entrySet())
{
PojoSchema prop=entrySet.getValue();
if(prop.getOptions()!=null)
{
if("PICKUP".equalsIgnoreCase(prop.getOptions().getFieldType())) {
if(!ObjectUtils.isEmpty(parent.getKey()))
data.set(entrySet.getKey().toLowerCase(), parent.getKey());
if(parent.keySet().size()==1)
break;
}
String refFieldCodeName=prop.getOptions().getRefFieldCodeName();
if((!StringUtils.isEmpty(refFieldCodeName))&&parent.get(refFieldCodeName.toLowerCase())!=null)
data.set(entrySet.getKey().toLowerCase(), parent.get(refFieldCodeName.toLowerCase()));
if("PICKUP".equalsIgnoreCase(prop.getOptions().getFieldType())) {
if(!ObjectUtils.isEmpty(parent.getKey()))
data.set(entrySet.getKey().toLowerCase(), parent.getKey());
if(parent.keySet().size()==1)
break;
}
String refFieldCodeName=prop.getOptions().getRefFieldCodeName();
if((!StringUtils.isEmpty(refFieldCodeName))&&parent.get(refFieldCodeName.toLowerCase())!=null)
data.set(entrySet.getKey().toLowerCase(), parent.get(refFieldCodeName.toLowerCase()));
}
if(refProperties.size()>1)
......@@ -686,6 +695,54 @@ public class PojoSchema {
return data;
}
public BaseData fillDefaultValue(BaseData data,boolean newFlag)
{
AuthenticationUser curUser=AuthenticationUser.getAuthenticationUser();
if(StringUtils.isEmpty(curUser.getUserid()))
{
curUser.setUserid(data.getStringValue("SRF_PERSONID"));
curUser.setPersonname(data.getStringValue("SRF_PERSONNAME"));
}
getProperties().values().forEach(sub-> {
if (Type.array.getCode().equals(sub.getType()) || Type.object.getCode().equals(sub.getType()) || !sub.getOptions().isPhysicalField() || (!StringUtils.isEmpty(sub.getOptions().getDefaultValue())))
return;
if(newFlag&&(!ObjectUtils.isEmpty(data.get(sub.getName().toLowerCase()))))
return;
String predefined=this.getOptions().getPredefined();
if(!newFlag)
{
if(predefined.equals("UPDATEDATE"))
data.set(sub.getName().toLowerCase(),new Timestamp(System.currentTimeMillis()));
else if(predefined.equals("UPDATEMAN"))
data.set(sub.getName().toLowerCase(),curUser.getUserid());
else if(predefined.equals("UPDATEMANNAME"))
data.set(sub.getName().toLowerCase(),curUser.getPersonname());
return;
}
String DV=sub.getOptions().getDefaultValue();
String defaultValueType="";
String defaultValue="";
if(DV.startsWith("$"))
{
DV=DV.replace("${","").replace("}","");
String dvs[] = DV.split("[.]");
if(dvs.length>=1)
defaultValueType=dvs[0];
if(dvs.length>=2)
defaultValue=dvs[1];
}
else
defaultValue=DV;
});
return data;
}
public FilterData fillParentFilter(FilterData data)
{
if(ObjectUtils.isEmpty(data.getParentDatas()))
......@@ -698,13 +755,10 @@ public class PojoSchema {
for(Map.Entry<String,PojoSchema> keyset:this.getRefProperties(refSchema).entrySet())
{
PojoSchema prop=keyset.getValue();
if(prop.getOptions()!=null)
{
if("PICKUP".equalsIgnoreCase(prop.getOptions().getFieldType())) {
if(!StringUtils.isEmpty(prop.getOptions().getFieldName()))
data.set("n_"+prop.getOptions().getFieldName()+"_eq", parent.getKey());
break;
}
if("PICKUP".equalsIgnoreCase(prop.getOptions().getFieldType())) {
if(!StringUtils.isEmpty(prop.getOptions().getFieldName()))
data.set("n_"+prop.getOptions().getFieldName()+"_eq", parent.getKey());
break;
}
}
......
......@@ -4,6 +4,7 @@ import cn.ibizlab.core.data.domain.POModel;
import cn.ibizlab.core.data.lite.*;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import org.springframework.util.ObjectUtils;
import org.springframework.util.StringUtils;
import java.util.LinkedHashMap;
......@@ -102,7 +103,7 @@ public class TransUtils {
}
else {
property.setPropertyType(PojoModel.PropertyType.valueOf(sub.getType()));
if(sub.getOptions()!=null&&(!StringUtils.isEmpty(sub.getOptions().getDict())))
if(!StringUtils.isEmpty(sub.getOptions().getDict()))
property.setDict(sub.getOptions().getDict());
}
......@@ -140,9 +141,13 @@ public class TransUtils {
.setOptions(new PojoOption().setAll(JSONObject.parseObject(JSON.toJSONString(fieldModel.getField()))));
Object searchModes=fieldModel.getField().get("search_modes");
if(searchModes!=null)
if(!ObjectUtils.isEmpty(searchModes))
sub.getOptions().setSearchModes(searchModes.toString());
Object defaultValue=fieldModel.getField().get("default_value");
if(!ObjectUtils.isEmpty(defaultValue))
sub.getOptions().setDefaultValue(defaultValue.toString());
sub.getOptions().remove("ext_params");
......
......@@ -240,12 +240,9 @@ public class BaseDataService implements IDataService {
{
refProperties.entrySet().forEach(propEntry->{
PojoSchema prop=propEntry.getValue();
if(prop.getOptions()!=null)
{
String refFieldCodeName=prop.getOptions().getRefFieldCodeName();
if((!StringUtils.isEmpty(refFieldCodeName))&&parentData.get(refFieldCodeName.toLowerCase())!=null)
et.set(propEntry.getKey().toLowerCase(), parentData.get(refFieldCodeName.toLowerCase()));
}
String refFieldCodeName=prop.getOptions().getRefFieldCodeName();
if((!StringUtils.isEmpty(refFieldCodeName))&&parentData.get(refFieldCodeName.toLowerCase())!=null)
et.set(propEntry.getKey().toLowerCase(), parentData.get(refFieldCodeName.toLowerCase()));
});
}
......
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册