cn.schoolwow.util.domain.query.instanceList.QueryInstanceListResponse Maven / Gradle / Ivy
The newest version!
package cn.schoolwow.util.domain.query.instanceList;
import cn.schoolwow.quickflow.QuickFlowBuilder;
import cn.schoolwow.quickflow.domain.FlowContext;
import cn.schoolwow.util.module.query.instanceList.domain.InstanceListQueryOption;
import cn.schoolwow.util.module.query.instanceList.flow.get.GetInstanceMultipleFieldValueListBusiness;
import cn.schoolwow.util.module.query.instanceList.flow.get.GetInstanceSingleFieldValueListBusiness;
import cn.schoolwow.util.module.query.instanceList.flow.group.GroupInstanceByFieldBusiness;
import cn.schoolwow.util.module.query.instanceList.service.FilterInstanceListCompositeBusiness;
import java.util.List;
import java.util.Map;
public class QueryInstanceListResponse {
private InstanceListQueryOption instanceQueryOption;
public QueryInstanceListResponse(InstanceListQueryOption instanceQueryOption) {
this.instanceQueryOption = instanceQueryOption;
}
/**获取第一个值*/
public T getOne(){
List filterInstanceList = getList();
if(null==filterInstanceList||filterInstanceList.isEmpty()){
return null;
}
return filterInstanceList.get(0);
}
/**获取有且仅有一个过滤值,否则抛出异常*/
public T checkOne(){
List filterInstanceList = getList();
if(null==filterInstanceList||filterInstanceList.size()==0){
throw new IllegalArgumentException("符合条件的实例为空");
}
if(filterInstanceList.size()>1){
throw new IllegalArgumentException("期望获取1个实例,实际个数:"+filterInstanceList.size());
}
return filterInstanceList.get(0);
}
/**获取过滤后的列表*/
public List getList(){
FlowContext flowContext = QuickFlowBuilder.quickFlow().startFlow(new FilterInstanceListCompositeBusiness())
.putCurrentCompositeFlowData("instanceQueryOption", instanceQueryOption)
.execute();
List filterInstanceList = (List) flowContext.getData("filterInstanceList");
return filterInstanceList;
}
/**获取指定字段的值*/
public List getSingleFieldValueList(String fieldName){
FlowContext flowContext = QuickFlowBuilder.quickFlow().startFlow(new FilterInstanceListCompositeBusiness())
.next(new GetInstanceSingleFieldValueListBusiness())
.putCurrentCompositeFlowData("instanceQueryOption", instanceQueryOption)
.putCurrentCompositeFlowData("fieldName", fieldName)
.execute();
List fieldValueList = (List) flowContext.getData("fieldValueList");
return fieldValueList;
}
/**获取指定多个字段的值*/
public List getMultipleFieldValueList(String... fieldNames){
FlowContext flowContext = QuickFlowBuilder.quickFlow().startFlow(new FilterInstanceListCompositeBusiness())
.next(new GetInstanceMultipleFieldValueListBusiness())
.putCurrentCompositeFlowData("instanceQueryOption", instanceQueryOption)
.putCurrentCompositeFlowData("fieldNames", fieldNames)
.execute();
List fieldValueList = (List) flowContext.getData("fieldValueList");
return fieldValueList;
}
/**根据字段字段分组*/
public Map
> groupByFieldName(String fieldName, Class
fieldClass){
FlowContext flowContext = QuickFlowBuilder.quickFlow().startFlow(new FilterInstanceListCompositeBusiness())
.next(new GroupInstanceByFieldBusiness
())
.putCurrentCompositeFlowData("instanceQueryOption", instanceQueryOption)
.putCurrentCompositeFlowData("fieldName", fieldName)
.execute();
Map
> fieldInstanceListMap = (Map
>) flowContext.getData("fieldInstanceListMap");
return fieldInstanceListMap;
}
}