|
@@ -88,28 +88,70 @@ public class QueryCriteriaHelper {
|
|
|
wrapper.or(orWrapper -> addOrCondition(orWrapper, fieldValue));
|
|
|
continue;
|
|
|
}
|
|
|
- // 值节点
|
|
|
- if(fieldValue.isValueNode()) {
|
|
|
- wrapper.eq(dbField, JsonNodeUtils.getNodeValue(fieldValue));
|
|
|
+ // 20210827增加or条件支持
|
|
|
+ if(QueryOperator.AND_OR.getIndex().equalsIgnoreCase(field)) {
|
|
|
+ // 内部重新创建QueryWrapper
|
|
|
+
|
|
|
+ wrapper.and(orWrapper -> addAndOrCondition(orWrapper, fieldValue));
|
|
|
continue;
|
|
|
}
|
|
|
- // 数组
|
|
|
- if(fieldValue.isArray()) {
|
|
|
- List listValue = JsonNodeUtils.getListValue(fieldValue);
|
|
|
- if (CollUtil.isEmpty(listValue)){
|
|
|
- continue;
|
|
|
- }
|
|
|
- wrapper.in(dbField, listValue);
|
|
|
- continue;
|
|
|
+ commonAddCondition(wrapper,fieldValue,dbField);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ /***
|
|
|
+ * Description: andOr的条件
|
|
|
+ * @param wrapper : 查询条件
|
|
|
+ * @param fieldObj : 字段对象
|
|
|
+ * @return : void
|
|
|
+ * @author : lijie
|
|
|
+ * @date :2021/8/27 21:39
|
|
|
+ * Update By lijie 2021/8/27 21:39
|
|
|
+ */
|
|
|
+ private static <T extends BaseEntity> void addAndOrCondition(QueryWrapper<T> wrapper, JsonNode fieldObj) {
|
|
|
+ if (!fieldObj.isObject()){
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ Iterator<String> fieldNames = fieldObj.fieldNames();
|
|
|
+ while (fieldNames.hasNext()){
|
|
|
+ String field = fieldNames.next();
|
|
|
+ JsonNode fieldValue = fieldObj.get(field);
|
|
|
+ // #JSON#开关的不转驼峰
|
|
|
+ String dbField = toUnderlineCase(field);
|
|
|
+ wrapper.or(sonWrapper->commonAddCondition(sonWrapper,fieldValue,dbField));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ /***
|
|
|
+ * Description: 通用查询条件组装语句
|
|
|
+ * @param wrapper : 查询对象
|
|
|
+ * @param fieldValue : 字段值
|
|
|
+ * @param dbField : 数据库字段
|
|
|
+ * @return : void
|
|
|
+ * @author : lijie
|
|
|
+ * @date :2021/8/27 21:41
|
|
|
+ * Update By lijie 2021/8/27 21:41
|
|
|
+ */
|
|
|
+ private static <T extends BaseEntity> void commonAddCondition(QueryWrapper<T> wrapper,JsonNode fieldValue,String dbField) {
|
|
|
+ // 值节点
|
|
|
+ if(fieldValue.isValueNode()) {
|
|
|
+ wrapper.eq(dbField, JsonNodeUtils.getNodeValue(fieldValue));
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ // 数组
|
|
|
+ if(fieldValue.isArray()) {
|
|
|
+ List listValue = JsonNodeUtils.getListValue(fieldValue);
|
|
|
+ if (CollUtil.isEmpty(listValue)){
|
|
|
+ return;
|
|
|
}
|
|
|
- // 对象
|
|
|
- if(fieldValue.isObject()) {
|
|
|
- Iterator<String> valueOperators = fieldValue.fieldNames();
|
|
|
- while(valueOperators.hasNext()) {
|
|
|
- String valueOperator = valueOperators.next();
|
|
|
- JsonNode operatorValue = fieldValue.get(valueOperator);
|
|
|
- addCondition(wrapper, dbField, valueOperator,operatorValue);
|
|
|
- }
|
|
|
+ wrapper.in(dbField, listValue);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ // 对象
|
|
|
+ if(fieldValue.isObject()) {
|
|
|
+ Iterator<String> valueOperators = fieldValue.fieldNames();
|
|
|
+ while(valueOperators.hasNext()) {
|
|
|
+ String valueOperator = valueOperators.next();
|
|
|
+ JsonNode operatorValue = fieldValue.get(valueOperator);
|
|
|
+ addCondition(wrapper, dbField, valueOperator,operatorValue);
|
|
|
}
|
|
|
}
|
|
|
}
|