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

reset逻辑修复

上级 e9a0b07f
......@@ -65,7 +65,7 @@ public class BaseData implements IEntityDTO {
public void setEnableAny(Boolean enableAny)
{
this.actionInputDTO=enableAny.booleanValue();
this.enableAny=enableAny.booleanValue();
}
@Override
......@@ -419,15 +419,13 @@ public class BaseData implements IEntityDTO {
@JSONField(serialize = false)
public void resetAll() {
getMap().keySet().forEach(key->{
if(!key.equals("map"))
if(!_SYSTEMPROP.contains(key))
map.put(key,null);
});
this.paramMap.clear();
this.focusNull.clear();
}
public void copyTo(IEntity iEntity) {
copyTo(iEntity, false);
}
......@@ -770,8 +768,10 @@ public class BaseData implements IEntityDTO {
public Map<String, Object> toMap()
{
Map<String, Object> map = new HashMap<>();
map.putAll((JSONObject)JSON.toJSON(this));
focusNull.forEach(item->map.put(item,null));
map.putAll(JSON.parseObject(JSON.toJSONString(this)));
focusNull.forEach(item->{
map.put(item,null);
});
return map;
}
......@@ -891,6 +891,7 @@ public class BaseData implements IEntityDTO {
return TypeUtils.castToJavaBean(objValue,clazz);
}
private static Set<String> _SYSTEMPROP=new BaseData().getMap().keySet();
}
......@@ -28,10 +28,7 @@ import org.springframework.data.domain.Sort;
import org.springframework.util.ObjectUtils;
import org.springframework.util.StringUtils;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.*;
@Getter
@Setter
......@@ -47,17 +44,7 @@ public class BaseFilter<T> extends BaseData implements ISearchContextDTO {
@JsonIgnore
@JSONField(serialize = false)
private Pageable pageable = null;
public void setPageable(Pageable pageable){
this.pageable=pageable;
}
@JsonIgnore
@JSONField(serialize = false)
private Sort pageSort = null;
private IPSDEDataSet dataSet;
@Override
public void init(IDEMethodDTORuntime iDEMethodDTORuntime, Object objData, boolean bDTOData) throws Exception {
......@@ -93,75 +80,8 @@ public class BaseFilter<T> extends BaseData implements ISearchContextDTO {
protected void onInit() throws Exception {
if (sort !=null) {
String strSortInfo = (String) sort;
strSortInfo = strSortInfo.trim();
this.setPageSort(strSortInfo);
}
this.setPageable(PageRequest.of(page, size, offset));
Object objSearchConds = this.getSearchConds();
if(objSearchConds == null) {
if(this.getDEMethodDTORuntime()!=null) {
//计算查询条件
java.util.List<IPSDEFilterDTOField> psDEFilterDTOFieldList = this.getDEMethodDTORuntime().getPSDEFilterDTO().getPSDEFilterDTOFields();
if(psDEFilterDTOFieldList != null) {
for(IPSDEFilterDTOField iPSDEFilterDTOField : psDEFilterDTOFieldList) {
Object objValue = this.get(iPSDEFilterDTOField.getLowerCaseName());
if(ObjectUtils.isEmpty(objValue)) {
continue;
}
SearchFieldCond searchFieldCond = new SearchFieldCond();
searchFieldCond.setFieldName(iPSDEFilterDTOField.getPSDEFieldMust().getName());
searchFieldCond.setParamMode(true);
searchFieldCond.setCondOp(iPSDEFilterDTOField.getPSDEFSearchModeMust().getValueOP());
searchFieldCond.setValue(iPSDEFilterDTOField.getLowerCaseName());
searchFieldCond.setDataType(iPSDEFilterDTOField.getStdDataType());
searchFieldCond.setValueFunc(iPSDEFilterDTOField.getPSDEFSearchModeMust().getValueFunc());
this.getSearchCondsIf().add(searchFieldCond);
}
}
if(!ObjectUtils.isEmpty(query)) {
//获取所有支持快速搜索的属性
List<IPSDEField> psDEFieldList = this.getDEMethodDTORuntime().getDataEntityRuntime().getQuickSearchPSDEFields();
if(psDEFieldList != null && psDEFieldList.size() > 0) {
SearchGroupCond searchGroupCond = new SearchGroupCond();
searchGroupCond.setCondOp(Conditions.OR);
for(IPSDEField iPSDEField: psDEFieldList ) {
SearchFieldCond searchFieldCond = new SearchFieldCond();
searchFieldCond.setFieldName(iPSDEField.getName());
searchFieldCond.setParamMode(true);
searchFieldCond.setCondOp(Conditions.LIKE);
searchFieldCond.setValue(PARAM_QUERY);
searchFieldCond.setDataType(iPSDEField.getStdDataType());
searchGroupCond.getSearchCondsIf().add(searchFieldCond);
}
this.getSearchCondsIf().add(searchGroupCond);
}
}
}
Object predefinedcond = this.get(PARAM_PREDEFINEDCOND);
if(predefinedcond instanceof String) {
if(!ObjectUtils.isEmpty(predefinedcond)) {
SearchContextDTO.addSearchPredefinedCond(this, (String)predefinedcond, null);
}
}
}
else {
if(objSearchConds != null) {
//实际展开条件
if(objSearchConds instanceof List) {
List list = new ArrayList();
......@@ -179,6 +99,61 @@ public class BaseFilter<T> extends BaseData implements ISearchContextDTO {
}
}
}
if(this.getDEMethodDTORuntime()!=null) {
//计算查询条件
java.util.List<IPSDEFilterDTOField> psDEFilterDTOFieldList = this.getDEMethodDTORuntime().getPSDEFilterDTO().getPSDEFilterDTOFields();
if(psDEFilterDTOFieldList != null) {
for(IPSDEFilterDTOField iPSDEFilterDTOField : psDEFilterDTOFieldList) {
Object objValue = this.get(iPSDEFilterDTOField.getLowerCaseName());
if(ObjectUtils.isEmpty(objValue)) {
continue;
}
SearchFieldCond searchFieldCond = new SearchFieldCond();
searchFieldCond.setFieldName(iPSDEFilterDTOField.getPSDEFieldMust().getName());
searchFieldCond.setParamMode(true);
searchFieldCond.setCondOp(iPSDEFilterDTOField.getPSDEFSearchModeMust().getValueOP());
searchFieldCond.setValue(iPSDEFilterDTOField.getLowerCaseName());
searchFieldCond.setDataType(iPSDEFilterDTOField.getStdDataType());
searchFieldCond.setValueFunc(iPSDEFilterDTOField.getPSDEFSearchModeMust().getValueFunc());
if(StringUtils.isEmpty(searchFieldCond.getValueFunc())&&hasFieldCond(iPSDEFilterDTOField.getLowerCaseName()))
continue;
this.getSearchCondsIf().add(searchFieldCond);
}
}
if(!ObjectUtils.isEmpty(query)) {
//获取所有支持快速搜索的属性
List<IPSDEField> psDEFieldList = this.getDEMethodDTORuntime().getDataEntityRuntime().getQuickSearchPSDEFields();
if(psDEFieldList != null && psDEFieldList.size() > 0) {
SearchGroupCond searchGroupCond = new SearchGroupCond();
searchGroupCond.setCondOp(Conditions.OR);
for(IPSDEField iPSDEField: psDEFieldList ) {
SearchFieldCond searchFieldCond = new SearchFieldCond();
searchFieldCond.setFieldName(iPSDEField.getName());
searchFieldCond.setParamMode(true);
searchFieldCond.setCondOp(Conditions.LIKE);
searchFieldCond.setValue(PARAM_QUERY);
searchFieldCond.setDataType(iPSDEField.getStdDataType());
searchGroupCond.getSearchCondsIf().add(searchFieldCond);
}
this.getSearchCondsIf().add(searchGroupCond);
}
}
}
Object predefinedcond = this.get(PARAM_PREDEFINEDCOND);
if(predefinedcond instanceof String) {
if(!ObjectUtils.isEmpty(predefinedcond)) {
SearchContextDTO.addSearchPredefinedCond(this, (String)predefinedcond, null);
}
}
}
......@@ -197,8 +172,12 @@ 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() {
......@@ -215,34 +194,23 @@ public class BaseFilter<T> extends BaseData implements ISearchContextDTO {
searchFieldCond.setCondOp(strCondOp);
if(!Conditions.ISNULL.equals(strCondOp)
&& !Conditions.ISNOTNULL.equals(strCondOp)) {
searchFieldCond.setParamMode(true);
String strParamName = "";
int nIndex = 1;
while(true) {
if(nIndex == 1) {
strParamName = String.format("n_%1$s_%2$s", strFieldName, strCondOp).toLowerCase();
}
else {
strParamName = String.format("n_%1$s_%2$s_%3$s", strFieldName, strCondOp, nIndex).toLowerCase();
}
objValue="1";
}
searchFieldCond.setParamMode(true);
nIndex ++;
if(!contains(strParamName)) {
searchFieldCond.setValue(strParamName);
this.getParamMap().put(strParamName, objValue);
break;
}
}
//
// String strParamName = String.format("n_%1$s_%2$s", strFieldName, strCondOp).toLowerCase();
// searchFieldCond.setValue(strParamName);
// this.getParamMap().put(strParamName, objValue);
String strParamName = String.format("n_%1$s_%2$s", strFieldName, strCondOp).toLowerCase();
if(!hasFieldCond(strParamName)) {
searchFieldCond.setValue(strParamName);
this.getParamMap().put(strParamName, objValue);
this.getSearchCondsIf().add(searchFieldCond);
}
this.getSearchCondsIf().add(searchFieldCond);
return this;
}
public boolean hasFieldCond(String fieldCondName) {
return this.getSearchCondsIf().stream().filter(f->f instanceof SearchFieldCond && fieldCondName.equals(((SearchFieldCond) f).getValue())).count()>0;
}
/**
* 指定属性值等于条件值
......@@ -422,11 +390,7 @@ public class BaseFilter<T> extends BaseData implements ISearchContextDTO {
@Override
public BaseFilter sort(String strSortInfo) {
this.setPageSort(strSortInfo);
return this;
}
@Override
@JsonIgnore
......@@ -514,14 +478,6 @@ public class BaseFilter<T> extends BaseData implements ISearchContextDTO {
}
public Integer size = 20;
public Integer page = 0;
public Long offset = 0L;
public String sort ;
public void setCount(boolean count)
{
this.setObject("count",count);
......@@ -535,79 +491,38 @@ public class BaseFilter<T> extends BaseData implements ISearchContextDTO {
@JSONField(serialize = false)
public boolean isCount(){return this.getBoolean("count",true).booleanValue();}
public void setSort(String sort)
{
if(!StringUtils.isEmpty(sort))
this.setPageSort(sort);
this.sort=sort;
}
public String getSort() {
if(this.getPageSort() != null && this.getPageSort() != Sort.unsorted()) {
java.util.Iterator<Sort.Order> orders = pageSort.iterator();
if(orders != null) {
String strSortInfo = "";
while (orders.hasNext()) {
if(StringUtils.hasLength(strSortInfo)) {
strSortInfo += ";";
}
Sort.Order order = orders.next();
if(order.isAscending()) {
strSortInfo += String.format("%1$s,asc", order.getProperty());
}
else {
strSortInfo += String.format("%1$s,desc", order.getProperty());
}
}
return strSortInfo;
}
}
return sort;
}
public long getOffset() {
if(this.getPageable() != null) {
return this.getPageable().getOffset();
}
return offset;
@Override
public BaseFilter count(boolean bCount) {
this.setObject("count",bCount);
return this;
}
public int getSize() {
if(this.getPageable() != null) {
return this.getPageable().getPageSize();
}
return size;
}
public Integer size = 20;
public Integer page = 0;
public Long offset = 0L;
public int getPage() {
if(this.getPageable() != null) {
return this.getPageable().getPageNumber();
public String sort;
public void setSort(String sort) {
if (sort !=null) {
sort = sort.trim();
this.setPageSort(sort);
}
return page;
this.sort=sort;
}
@Override
public BaseFilter count(boolean bCount) {
this.setObject("count",bCount);
public BaseFilter sort(String strSortInfo) {
this.setSort(strSortInfo);
return this;
}
public void setPageable(int nPageNumber, int nPageSize, long nOffset) {
this.setPageable(PageRequest.of(nPageNumber, nPageSize, nOffset));
}
@Override
@JsonIgnore
@JSONField(serialize = false)
public List<ISearchCond> getSearchConds() {
return searchconds;
}
private Sort pageSort = null;
public void setPageSort(String strSortInfo) {
Sort sort = null;
Sort pageSort = null;
if (StringUtils.hasLength(strSortInfo)) {
List<Sort.Order> list = new ArrayList<Sort.Order>();
String[] parts = strSortInfo.split("[;]");
for(String strPart : parts) {
String[] items = strPart.split("[,]");
......@@ -621,21 +536,61 @@ public class BaseFilter<T> extends BaseData implements ISearchContextDTO {
}
}
}
if (list.size() > 0) {
sort = Sort.by(list);
pageSort = Sort.by(list);
}
}
this.setPageSort(sort);
this.sort=strSortInfo;
this.pageSort=pageSort;
}
@Override
public void setPageSort(Sort sort) {
this.pageSort=sort;
public void setPageSort(Sort pageSort) {
String strSortInfo=null;
if(pageSort != null && pageSort != Sort.unsorted()) {
java.util.Iterator<Sort.Order> orders = pageSort.iterator();
if(orders != null) {
List<String> sortInfos = new ArrayList<>();
while (orders.hasNext()) {
Sort.Order order = orders.next();
if(order.isAscending()) {
sortInfos.add(String.format("%1$s,asc", order.getProperty()));
}
else {
sortInfos.add(String.format("%1$s,desc", order.getProperty()));
}
}
if(sortInfos.size()>0)
strSortInfo=String.join(";",sortInfos);
}
}
this.sort=strSortInfo;
this.pageSort=pageSort;
}
@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(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);
}
return pageable;
}
public Object get(String strName){
return getObject(strName);
}
......@@ -706,26 +661,28 @@ public class BaseFilter<T> extends BaseData implements ISearchContextDTO {
case "offset":
this.setOffset(DataTypeUtils.getLongValue(value,0L));
break;
case "searchconds":
if((!ObjectUtils.isEmpty(value))&&(value instanceof List))
this.setSearchconds((List)value);
break;
case "query":
this.setQuery(DataTypeUtils.getStringValue(value,null));
break;
case "pageable":
if(value instanceof Pageable)
this.setPageable((Pageable)value);
case "pagesort":
if(value instanceof Sort)
this.setPageSort((Sort)value);
else
this.setPageSort(DataTypeUtils.getStringValue(value,null));
break;
case "searchconds":
this.setSearchconds((List)value);
break;
case "query":
this.setQuery(DataTypeUtils.getStringValue(value,null));
break;
case "sort":
this.setSort(DataTypeUtils.getStringValue(value,null));
break;
case "idefilterdtoruntime":
if(value instanceof IDEFilterDTORuntime)
this.setIDEFilterDTORuntime((IDEFilterDTORuntime)value);
else
this.setIDEFilterDTORuntime(null);
break;
default:
String fieldRealName= FieldCache.getFieldRealName(this.getClass(),field);
......@@ -748,8 +705,19 @@ public class BaseFilter<T> extends BaseData implements ISearchContextDTO {
}
@JsonIgnore
@JSONField(serialize = false)
private IPSDEDataSet dataSet;
public void resetAll() {
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;
}
}
package net.ibizsys.central.plugin.boot.core.service;
import net.ibizsys.central.dataentity.IDataEntityRuntime;
import net.ibizsys.central.dataentity.IDataEntityRuntimeContext;
import net.ibizsys.central.plugin.boot.core.domain.BaseData;
import net.ibizsys.central.plugin.boot.core.filter.BaseFilter;
import net.ibizsys.central.plugin.boot.core.helper.StringAdvUtils;
import net.ibizsys.central.plugin.boot.core.runtime.IBootService;
import net.ibizsys.central.plugin.boot.core.runtime.IBootSystemRuntime;
import net.ibizsys.model.dataentity.action.IPSDEAction;
import net.ibizsys.model.dataentity.ds.IPSDEDataSet;
import org.springframework.data.domain.Page;
import java.io.Serializable;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;
public interface IServiceApiService<T extends BaseData, F extends BaseFilter> extends IBaseService<T,F>{
default Object onRealAction(String strActionName,Object arg) throws Throwable{
return this.getDataEntityRuntimeContext().executeActionReal(strActionName, null, new Object[]{arg}, null);
}
default Object onRealFetch(String dsName,F arg) throws Throwable{
return this.getDataEntityRuntimeContext().fetchDataSetReal("DEFAULT", arg.getDataSet(), new Object[]{arg}, null);
}
default <K extends Serializable> T onGet(K key) throws Throwable {
return (T)onRealAction("Get",key);
}
default T onGetDraft(T dto) throws Throwable {
return (T)onRealAction("GetDraft",dto);
}
default Integer onCheckKey(T dto) throws Throwable {
return (Integer) onRealAction("CheckKey",dto);
}
default Page<T> onFetchDefault(F dto) throws Throwable {
return (Page) onRealFetch("DEFAULT",dto);
}
default List<T> selectDefault(F dto) throws Throwable {
return (List)this.getRuntimeService().getDataEntityRuntime().selectDataQuery("DEFAULT", dto);
}
default List<T> selectSimple(F dto) throws Throwable {
return (List)this.getRuntimeService().getDataEntityRuntime().selectDataQuery("SIMPLE", dto);
}
default List<T> selectView(F dto) throws Throwable {
return (List)this.getRuntimeService().getDataEntityRuntime().selectDataQuery("VIEW", dto);
}
}
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册