feat:实现动态响应处理
This commit is contained in:
parent
b18a8c4de8
commit
f313db715f
@ -23,6 +23,8 @@ public class BaseQo<T extends Domain> implements Qo<T> {
|
||||
|
||||
protected IUser user;
|
||||
|
||||
protected List<String> fields;
|
||||
|
||||
public Qo<T> accept(List<T> result, Pageable pageable) {
|
||||
this.pageable = pageable;
|
||||
this.result = result;
|
||||
@ -106,6 +108,16 @@ public class BaseQo<T extends Domain> implements Qo<T> {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取查询的字段
|
||||
*
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public List<String> getFields() {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 内置的builder,重写后自动合并结果
|
||||
*
|
||||
|
@ -1,7 +1,6 @@
|
||||
package com.flyfish.framework.domain.base;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import com.flyfish.framework.domain.po.User;
|
||||
import org.springframework.data.domain.Example;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.domain.Sort;
|
||||
@ -74,6 +73,14 @@ public interface Qo<T> {
|
||||
@JsonIgnore
|
||||
Criteria getCriteria();
|
||||
|
||||
/**
|
||||
* 获取查询的字段
|
||||
*
|
||||
* @return 结果
|
||||
*/
|
||||
@JsonIgnore
|
||||
List<String> getFields();
|
||||
|
||||
/**
|
||||
* 让值全部包含在Pojo里
|
||||
*
|
||||
|
@ -2,6 +2,7 @@ package com.flyfish.framework.repository.impl;
|
||||
|
||||
import com.flyfish.framework.domain.base.Qo;
|
||||
import com.flyfish.framework.utils.CopyUtils;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.springframework.data.domain.Example;
|
||||
import org.springframework.data.mongodb.core.query.Criteria;
|
||||
import org.springframework.data.mongodb.core.query.Query;
|
||||
@ -17,6 +18,22 @@ abstract class QueryBuildUtils {
|
||||
* @return 结果
|
||||
*/
|
||||
static <T> Optional<Query> getQuery(Qo<T> qo) {
|
||||
return buildQuery(qo).map(query -> {
|
||||
if (CollectionUtils.isNotEmpty(qo.getFields())) {
|
||||
query.fields().include(qo.getFields().toArray(new String[]{}));
|
||||
}
|
||||
return query;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 构建查询
|
||||
*
|
||||
* @param qo 查询实体
|
||||
* @param <T> 泛型
|
||||
* @return 结果
|
||||
*/
|
||||
static <T> Optional<Query> buildQuery(Qo<T> qo) {
|
||||
Criteria criteria = null;
|
||||
if (null != qo.getCriteria()) {
|
||||
criteria = qo.getCriteria();
|
||||
|
@ -1,8 +1,13 @@
|
||||
package com.flyfish.framework.dict.domain;
|
||||
|
||||
import com.flyfish.framework.builder.CriteriaBuilder;
|
||||
import com.flyfish.framework.domain.base.NameLikeQo;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 字典查询实体
|
||||
@ -12,4 +17,20 @@ import lombok.Setter;
|
||||
@Getter
|
||||
@Setter
|
||||
public class DictionaryQo extends NameLikeQo<Dictionary> {
|
||||
|
||||
// 包含的code
|
||||
private List<String> codes;
|
||||
|
||||
@Override
|
||||
public CriteriaBuilder<Dictionary> criteriaBuilder() {
|
||||
return super.criteriaBuilder().with("codes", "code", CriteriaBuilder.Builders.IN);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getFields() {
|
||||
if (CollectionUtils.isNotEmpty(codes)) {
|
||||
return Arrays.asList("_id", "code");
|
||||
}
|
||||
return super.getFields();
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user