提交 571d4ed0 编写于 作者: xignzi's avatar xignzi

修复.eq .in等相关查询条件值未设置异常

上级 0390107b
......@@ -51,23 +51,22 @@ public class BaseFilter<T> extends BaseData implements ISearchContextDTO {
@Override
public void init(IDEMethodDTORuntime iDEMethodDTORuntime, Object objData, boolean bDTOData) throws Exception {
if(!(iDEMethodDTORuntime instanceof IDEFilterDTORuntime)) {
if (!(iDEMethodDTORuntime instanceof IDEFilterDTORuntime)) {
throw new Exception(String.format("传入实体方法DTO运行时对象不正确"));
}
if(!bDTOData) {
if (!bDTOData) {
throw new Exception(String.format("仅支持传入DTO"));
}
this.iDEFilterDTORuntime = (IDEFilterDTORuntime)iDEMethodDTORuntime;
this.iDEFilterDTORuntime = (IDEFilterDTORuntime) iDEMethodDTORuntime;
if (objData instanceof Map) {
Map<String,Object> map = (Map<String,Object>)objData;
Map<String, Object> map = (Map<String, Object>) objData;
for(java.util.Map.Entry<String, Object> entry : map.entrySet()) {
if(entry.getKey().equalsIgnoreCase("searchconds")&&(!ObjectUtils.isEmpty(entry.getValue())))
{
List list=(List)entry.getValue();
if(!(list.get(0) instanceof ISearchCond))
for (java.util.Map.Entry<String, Object> entry : map.entrySet()) {
if (entry.getKey().equalsIgnoreCase("searchconds") && (!ObjectUtils.isEmpty(entry.getValue()))) {
List list = (List) entry.getValue();
if (!(list.get(0) instanceof ISearchCond))
continue;
}
......@@ -79,35 +78,33 @@ public class BaseFilter<T> extends BaseData implements ISearchContextDTO {
}
protected void onInit() throws Exception {
Object objSearchConds = this.getSearchConds();
if(objSearchConds != null) {
if (objSearchConds != null) {
//实际展开条件
if(objSearchConds instanceof List) {
if (objSearchConds instanceof List) {
List list = new ArrayList();
((List) objSearchConds).forEach(objItem->{
if(!(objItem instanceof Map)) {
((List) objSearchConds).forEach(objItem -> {
if (!(objItem instanceof Map)) {
return;
}
list.add(objItem);
});
for(Object objItem : list) {
ISearchCond iSearchCond = net.ibizsys.central.util.SearchGroupCond.getSearchCond((Map)objItem, true);
if(iSearchCond != null) {
for (Object objItem : list) {
ISearchCond iSearchCond = net.ibizsys.central.util.SearchGroupCond.getSearchCond((Map) objItem, true);
if (iSearchCond != null) {
this.getSearchCondsIf().add(iSearchCond);
}
}
}
}
if(this.getDEMethodDTORuntime()!=null) {
if (this.getDEMethodDTORuntime() != null) {
//计算查询条件
java.util.List<IPSDEFilterDTOField> psDEFilterDTOFieldList = this.getDEMethodDTORuntime().getPSDEFilterDTO().getPSDEFilterDTOFields();
if(psDEFilterDTOFieldList != null) {
for(IPSDEFilterDTOField iPSDEFilterDTOField : psDEFilterDTOFieldList) {
if (psDEFilterDTOFieldList != null) {
for (IPSDEFilterDTOField iPSDEFilterDTOField : psDEFilterDTOFieldList) {
Object objValue = this.get(iPSDEFilterDTOField.getLowerCaseName());
if(ObjectUtils.isEmpty(objValue)) {
if (ObjectUtils.isEmpty(objValue)) {
continue;
}
......@@ -118,21 +115,21 @@ public class BaseFilter<T> extends BaseData implements ISearchContextDTO {
searchFieldCond.setValue(iPSDEFilterDTOField.getLowerCaseName());
searchFieldCond.setDataType(iPSDEFilterDTOField.getStdDataType());
searchFieldCond.setValueFunc(iPSDEFilterDTOField.getPSDEFSearchModeMust().getValueFunc());
if(StringUtils.isEmpty(searchFieldCond.getValueFunc())&&hasFieldCond(iPSDEFilterDTOField.getLowerCaseName()))
if (StringUtils.isEmpty(searchFieldCond.getValueFunc()) && hasFieldCond(iPSDEFilterDTOField.getLowerCaseName()))
continue;
this.getSearchCondsIf().add(searchFieldCond);
}
}
if(!ObjectUtils.isEmpty(query)) {
if (!ObjectUtils.isEmpty(query)) {
//获取所有支持快速搜索的属性
List<IPSDEField> psDEFieldList = this.getDEMethodDTORuntime().getDataEntityRuntime().getQuickSearchPSDEFields();
if(psDEFieldList != null && psDEFieldList.size() > 0) {
if (psDEFieldList != null && psDEFieldList.size() > 0) {
SearchGroupCond searchGroupCond = new SearchGroupCond();
searchGroupCond.setCondOp(Conditions.OR);
for(IPSDEField iPSDEField: psDEFieldList ) {
for (IPSDEField iPSDEField : psDEFieldList) {
SearchFieldCond searchFieldCond = new SearchFieldCond();
searchFieldCond.setFieldName(iPSDEField.getName());
searchFieldCond.setParamMode(true);
......@@ -151,9 +148,9 @@ public class BaseFilter<T> extends BaseData implements ISearchContextDTO {
}
Object predefinedcond = this.get(PARAM_PREDEFINEDCOND);
if(predefinedcond instanceof String) {
if(!ObjectUtils.isEmpty(predefinedcond)) {
SearchContextDTO.addSearchPredefinedCond(this, (String)predefinedcond, null);
if (predefinedcond instanceof String) {
if (!ObjectUtils.isEmpty(predefinedcond)) {
SearchContextDTO.addSearchPredefinedCond(this, (String) predefinedcond, null);
}
}
}
......@@ -174,16 +171,18 @@ public class BaseFilter<T> extends BaseData implements ISearchContextDTO {
@JsonIgnore
@JSONField(serialize = false)
private List<ISearchCond> searchconds = null;
@Override
@JsonIgnore
@JSONField(serialize = false)
public List<ISearchCond> getSearchConds() {
return searchconds;
}
@JsonIgnore
@JSONField(serialize = false)
public List<ISearchCond> getSearchCondsIf() {
if(this.searchconds == null) {
if (this.searchconds == null) {
this.searchconds = new ArrayList<ISearchCond>();
}
return this.searchconds;
......@@ -195,36 +194,36 @@ public class BaseFilter<T> extends BaseData implements ISearchContextDTO {
SearchFieldCond searchFieldCond = new SearchFieldCond();
searchFieldCond.setFieldName(strFieldName);
searchFieldCond.setCondOp(strCondOp);
if(Conditions.ISNULL.equals(strCondOp)
if (Conditions.ISNULL.equals(strCondOp)
|| Conditions.ISNOTNULL.equals(strCondOp)) {
objValue="1";
objValue = "1";
}
searchFieldCond.setParamMode(true);
String strParamName = String.format("n_%1$s_%2$s", strFieldName, strCondOp).toLowerCase();
if(!hasFieldCond(strParamName)) {
if (!hasFieldCond(strParamName)) {
searchFieldCond.setValue(strParamName);
this.getParamMap().put(strParamName, objValue);
this.getSearchCondsIf().add(searchFieldCond);
}
String fieldRealName = FieldCache.getFieldRealName(BaseFilter.class, strParamName);
if (StringUtils.isEmpty(fieldRealName) && (!this.getClass().isAssignableFrom(BaseFilter.class))) {
fieldRealName = FieldCache.getFieldRealName(this.getClass(), strParamName);
}
if (!StringUtils.isEmpty(fieldRealName)) {
FieldCache.FieldItem filedItem = FieldCache.getField(this.getClass(),strParamName);
if (filedItem!=null) {
try {
Field field = this.getClass().getDeclaredField(fieldRealName);
Field field = filedItem.getField();
field.setAccessible(true);
if (objValue instanceof Collection) {
Collection collection = (Collection) objValue;
Object joinObject = collection.stream().collect(Collectors.joining(","));
field.set(this, joinObject != null ? String.valueOf(joinObject) : joinObject);
}else {
} else if (objValue instanceof String[]) {
String[] array = (String[]) objValue;
Collection collection = Arrays.asList(array);
Object joinObject = collection.stream().collect(Collectors.joining(","));
field.set(this, joinObject != null ? String.valueOf(joinObject) : joinObject);
} else {
field.set(this, objValue);
}
} catch (NoSuchFieldException e) {
} catch (IllegalAccessException e) {
}
......@@ -234,11 +233,12 @@ public class BaseFilter<T> extends BaseData implements ISearchContextDTO {
}
public boolean hasFieldCond(String fieldCondName) {
return this.getSearchCondsIf().stream().filter(f->f instanceof SearchFieldCond && fieldCondName.equals(((SearchFieldCond) f).getValue())).count()>0;
return this.getSearchCondsIf().stream().filter(f -> f instanceof SearchFieldCond && fieldCondName.equals(((SearchFieldCond) f).getValue())).count() > 0;
}
/**
* 指定属性值等于条件值
*
* @param strFieldName
*/
@Override
......@@ -249,6 +249,7 @@ public class BaseFilter<T> extends BaseData implements ISearchContextDTO {
/**
* 指定属性值不等于条件值
*
* @param strFieldName
*/
@Override
......@@ -259,6 +260,7 @@ public class BaseFilter<T> extends BaseData implements ISearchContextDTO {
/**
* 指定属性值大于条件值
*
* @param strFieldName
*/
@Override
......@@ -269,6 +271,7 @@ public class BaseFilter<T> extends BaseData implements ISearchContextDTO {
/**
* 指定属性值大于等于条件值
*
* @param strFieldName
*/
@Override
......@@ -279,6 +282,7 @@ public class BaseFilter<T> extends BaseData implements ISearchContextDTO {
/**
* 指定属性值小于条件值
*
* @param strFieldName
*/
@Override
......@@ -289,6 +293,7 @@ public class BaseFilter<T> extends BaseData implements ISearchContextDTO {
/**
* 指定属性值小于等于条件值
*
* @param strFieldName
*/
@Override
......@@ -299,6 +304,7 @@ public class BaseFilter<T> extends BaseData implements ISearchContextDTO {
/**
* 指定属性值匹配条件值
*
* @param strFieldName
*/
@Override
......@@ -309,6 +315,7 @@ public class BaseFilter<T> extends BaseData implements ISearchContextDTO {
/**
* 指定属性值左侧匹配条件值
*
* @param strFieldName
*/
@Override
......@@ -319,6 +326,7 @@ public class BaseFilter<T> extends BaseData implements ISearchContextDTO {
/**
* 指定属性值右侧匹配条件值
*
* @param strFieldName
*/
@Override
......@@ -329,6 +337,7 @@ public class BaseFilter<T> extends BaseData implements ISearchContextDTO {
/**
* 指定属性值为空
*
* @param strFieldName
*/
@Override
......@@ -339,6 +348,7 @@ public class BaseFilter<T> extends BaseData implements ISearchContextDTO {
/**
* 指定属性值不为空
*
* @param strFieldName
*/
@Override
......@@ -349,6 +359,7 @@ public class BaseFilter<T> extends BaseData implements ISearchContextDTO {
/**
* 指定属性值在值范围中
*
* @param strFieldName
*/
@Override
......@@ -359,6 +370,7 @@ public class BaseFilter<T> extends BaseData implements ISearchContextDTO {
/**
* 指定属性值不在值范围中
*
* @param strFieldName
*/
@Override
......@@ -369,6 +381,7 @@ public class BaseFilter<T> extends BaseData implements ISearchContextDTO {
/**
* 添加自定义条件
*
* @param strCustomCond
*/
@Override
......@@ -392,7 +405,6 @@ public class BaseFilter<T> extends BaseData implements ISearchContextDTO {
}
@Override
@JsonIgnore
@JSONField(serialize = false)
......@@ -446,6 +458,7 @@ public class BaseFilter<T> extends BaseData implements ISearchContextDTO {
/**
* 设置直接变量值
*
* @param strName
* @param objValue
* @return
......@@ -496,8 +509,8 @@ public class BaseFilter<T> extends BaseData implements ISearchContextDTO {
@JSONField(serialize = false)
public String getDrillDownCond() {
Object drilldowncond = this.get(PARAM_DRILLDOWNCOND);
if(drilldowncond instanceof String) {
return (String)drilldowncond;
if (drilldowncond instanceof String) {
return (String) drilldowncond;
}
return null;
}
......@@ -508,30 +521,33 @@ public class BaseFilter<T> extends BaseData implements ISearchContextDTO {
@JSONField(serialize = false)
public String getGroupCond() {
Object groupcond = this.get(PARAM_GROUPCOND);
if(groupcond instanceof String) {
return (String)groupcond;
if (groupcond instanceof String) {
return (String) groupcond;
}
return null;
}
public void setCount(boolean count)
{
this.setObject("count",count);
public void setCount(boolean count) {
this.setObject("count", count);
}
@JsonIgnore
@JSONField(serialize = false)
public boolean getCount(){return this.getBoolean("count",true).booleanValue();}
public boolean getCount() {
return this.getBoolean("count", true).booleanValue();
}
@JsonIgnore
@JSONField(serialize = false)
public boolean isCount(){return this.getBoolean("count",true).booleanValue();}
public boolean isCount() {
return this.getBoolean("count", true).booleanValue();
}
@Override
public BaseFilter count(boolean bCount) {
this.setObject("count",bCount);
this.setObject("count", bCount);
return this;
}
......@@ -540,13 +556,15 @@ public class BaseFilter<T> extends BaseData implements ISearchContextDTO {
public Long offset = 0L;
public String sort;
public void setSort(String sort) {
if (sort !=null) {
if (sort != null) {
sort = sort.trim();
this.setPageSort(sort);
}
this.sort=sort;
this.sort = sort;
}
@Override
public BaseFilter sort(String strSortInfo) {
this.setSort(strSortInfo);
......@@ -556,12 +574,13 @@ public class BaseFilter<T> extends BaseData implements ISearchContextDTO {
@JsonIgnore
@JSONField(serialize = false)
private Sort pageSort = null;
public void setPageSort(String strSortInfo) {
Sort pageSort = null;
if (StringUtils.hasLength(strSortInfo)) {
List<Sort.Order> list = new ArrayList<Sort.Order>();
String[] parts = strSortInfo.split("[;]");
for(String strPart : parts) {
for (String strPart : parts) {
String[] items = strPart.split("[,]");
if (items.length == 1) {
list.add(Sort.Order.asc(items[0]));
......@@ -577,8 +596,8 @@ public class BaseFilter<T> extends BaseData implements ISearchContextDTO {
pageSort = Sort.by(list);
}
}
this.sort=strSortInfo;
this.pageSort=pageSort;
this.sort = strSortInfo;
this.pageSort = pageSort;
}
@Override
......@@ -603,26 +622,25 @@ public class BaseFilter<T> extends BaseData implements ISearchContextDTO {
@Override
public void setPageSort(Sort pageSort) {
String strSortInfo=null;
if(pageSort != null && pageSort != Sort.unsorted()) {
String strSortInfo = null;
if (pageSort != null && pageSort != Sort.unsorted()) {
java.util.Iterator<Sort.Order> orders = pageSort.iterator();
if(orders != null) {
if (orders != null) {
List<String> sortInfos = new ArrayList<>();
while (orders.hasNext()) {
Sort.Order order = orders.next();
if(order.isAscending()) {
if (order.isAscending()) {
sortInfos.add(String.format("%1$s,asc", order.getProperty()));
}
else {
} else {
sortInfos.add(String.format("%1$s,desc", order.getProperty()));
}
}
if(sortInfos.size()>0)
strSortInfo=String.join(";",sortInfos);
if (sortInfos.size() > 0)
strSortInfo = String.join(";", sortInfos);
}
}
this.sort=strSortInfo;
this.pageSort=pageSort;
this.sort = strSortInfo;
this.pageSort = pageSort;
}
@Override
......@@ -649,27 +667,27 @@ public class BaseFilter<T> extends BaseData implements ISearchContextDTO {
@JsonIgnore
@JSONField(serialize = false)
private Pageable pageable = null;
public void setPageable(Pageable pageable){
this.page=pageable.getPageNumber();
this.size=pageable.getPageSize();
this.offset=pageable.getOffset();
this.pageable=pageable;
public void setPageable(Pageable pageable) {
this.page = pageable.getPageNumber();
this.size = pageable.getPageSize();
this.offset = pageable.getOffset();
this.pageable = pageable;
}
public void setPageable(int nPageNumber, int nPageSize, long nOffset) {
this.setPageable(PageRequest.of(nPageNumber, nPageSize, nOffset));
}
public Pageable getPageable() {
if(pageable==null) {
pageable=PageRequest.of(page, size, offset);
if (pageable == null) {
pageable = PageRequest.of(page, size, offset);
}
return pageable;
}
public Object get(String strName){
public Object get(String strName) {
return getObject(strName);
}
......@@ -682,103 +700,94 @@ public class BaseFilter<T> extends BaseData implements ISearchContextDTO {
@JsonIgnore
@JSONField(serialize = false)
@Transient
private BeanMap getMap()
{
if(map==null) {
map=BeanMap.create(this);
private BeanMap getMap() {
if (map == null) {
map = BeanMap.create(this);
}
return map;
return map;
}
public Object getObject(String strName)
{
String fieldRealName= FieldCache.getFieldRealName(BaseFilter.class,strName);
if(StringUtils.isEmpty(fieldRealName)&&(!this.getClass().isAssignableFrom(BaseFilter.class))) {
fieldRealName=FieldCache.getFieldRealName(this.getClass(),strName);
public Object getObject(String strName) {
String fieldRealName = FieldCache.getFieldRealName(BaseFilter.class, strName);
if (StringUtils.isEmpty(fieldRealName) && (!this.getClass().isAssignableFrom(BaseFilter.class))) {
fieldRealName = FieldCache.getFieldRealName(this.getClass(), strName);
}
if(!StringUtils.isEmpty(fieldRealName)) {
if (!StringUtils.isEmpty(fieldRealName)) {
return getMap().get(fieldRealName);
}
else {
} else {
return this.getParamMap().get(strName);
}
}
public QueryWrapper<T> getSearchCond(boolean gen)
{
public QueryWrapper<T> getSearchCond(boolean gen) {
return QueryHelper.getQueryWrapper(this);
}
public void modify(String field,Object val) {
public void modify(String field, Object val) {
}
public void set(String field, String value) {
setObject(field,value);
setObject(field, value);
}
public void set(String field, Object value) {
setObject(field,value);
setObject(field, value);
}
@JsonAnySetter
@JSONField(name = "_any", unwrapped = true, serialize = false, deserialize = true)
public void setObject(String field, Object value) {
try
{
switch (field.toLowerCase())
{
try {
switch (field.toLowerCase()) {
case "size":
this.setSize(DataTypeUtils.getIntegerValue(value,20));
this.setSize(DataTypeUtils.getIntegerValue(value, 20));
break;
case "page":
this.setPage(DataTypeUtils.getIntegerValue(value,0));
this.setPage(DataTypeUtils.getIntegerValue(value, 0));
break;
case "offset":
this.setOffset(DataTypeUtils.getLongValue(value,0L));
this.setOffset(DataTypeUtils.getLongValue(value, 0L));
break;
case "searchconds":
if((!ObjectUtils.isEmpty(value))&&(value instanceof List))
this.setSearchconds((List)value);
if ((!ObjectUtils.isEmpty(value)) && (value instanceof List))
this.setSearchconds((List) value);
break;
case "query":
this.setQuery(DataTypeUtils.getStringValue(value,null));
this.setQuery(DataTypeUtils.getStringValue(value, null));
break;
case "pageable":
if(value instanceof Pageable)
this.setPageable((Pageable)value);
if (value instanceof Pageable)
this.setPageable((Pageable) value);
case "pagesort":
if(value instanceof Sort)
this.setPageSort((Sort)value);
if (value instanceof Sort)
this.setPageSort((Sort) value);
else
this.setPageSort(DataTypeUtils.getStringValue(value,null));
this.setPageSort(DataTypeUtils.getStringValue(value, null));
break;
case "sort":
this.setSort(DataTypeUtils.getStringValue(value,null));
this.setSort(DataTypeUtils.getStringValue(value, null));
break;
case "idefilterdtoruntime":
if(value instanceof IDEFilterDTORuntime)
this.setIDEFilterDTORuntime((IDEFilterDTORuntime)value);
if (value instanceof IDEFilterDTORuntime)
this.setIDEFilterDTORuntime((IDEFilterDTORuntime) value);
break;
default:
String fieldRealName= FieldCache.getFieldRealName(this.getClass(),field);
if(!StringUtils.isEmpty(fieldRealName)) {
String fieldRealName = FieldCache.getFieldRealName(this.getClass(), field);
if (!StringUtils.isEmpty(fieldRealName)) {
if (value == null) {
getMap().put(fieldRealName, null);
}
else {
} else {
getMap().put(fieldRealName, FieldCache.fieldValueOf(this.getClass(), fieldRealName, value));
}
}
else {
this.getParamMap().put(field,value);
} else {
this.getParamMap().put(field, value);
}
}
}catch (Exception ex){}
} catch (Exception ex) {
}
}
......@@ -787,14 +796,14 @@ public class BaseFilter<T> extends BaseData implements ISearchContextDTO {
@JsonIgnore
@JSONField(serialize = false)
public void resetAll() {
getMap().keySet().forEach(key->{
if((!key.toString().equalsIgnoreCase("dataSet"))&&(!key.toString().toLowerCase().endsWith("defilterdtoruntime")))
map.put(key,null);
getMap().keySet().forEach(key -> {
if ((!key.toString().equalsIgnoreCase("dataSet")) && (!key.toString().toLowerCase().endsWith("defilterdtoruntime")))
map.put(key, null);
});
super.resetAll();
page=0;
size=20;
offset=0L;
page = 0;
size = 20;
offset = 0L;
}
public String getCat() {
......
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册