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

默认值

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