|
@@ -1,6 +1,7 @@
|
|
|
package com.persagy.dmp.rwd.digital.controller;
|
|
|
|
|
|
import cn.hutool.core.collection.CollUtil;
|
|
|
+import cn.hutool.core.util.ReflectUtil;
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
@@ -25,7 +26,9 @@ import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
|
import javax.validation.Valid;
|
|
|
+import java.util.Iterator;
|
|
|
import java.util.List;
|
|
|
+import java.util.Set;
|
|
|
|
|
|
/**
|
|
|
* 对象数据 Controller
|
|
@@ -47,8 +50,8 @@ public class ObjectDigitalController {
|
|
|
QueryWrapper<ObjectDigital> wrapper = new QueryWrapper<>();
|
|
|
// 添加所属项目条件
|
|
|
ConditionUtil.ensureProjectCriteria(wrapper);
|
|
|
- // 处理关系条件
|
|
|
- ensureRelationCond(wrapper, criteria.getCriteria());
|
|
|
+ // 处理扩展条件
|
|
|
+ ensureExtraCond(wrapper, criteria.getCriteria());
|
|
|
// 转换查询条件
|
|
|
QueryCriteriaHelper.toWrapper(wrapper, criteria);
|
|
|
Page page = service.queryByCondition(QueryCriteriaHelper.toPage(criteria), wrapper);
|
|
@@ -58,6 +61,79 @@ public class ObjectDigitalController {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
+ * 拼接扩展条件
|
|
|
+ * @param wrapper
|
|
|
+ * @param criteria
|
|
|
+ */
|
|
|
+ private void ensureExtraCond(QueryWrapper<ObjectDigital> wrapper, ObjectNode criteria) {
|
|
|
+ ensureSearchCond(wrapper, criteria);
|
|
|
+ ensureRelationCond(wrapper, criteria);
|
|
|
+ ensureJsonCond(wrapper, criteria);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 拼接json条件
|
|
|
+ * @param wrapper
|
|
|
+ * @param criteria
|
|
|
+ */
|
|
|
+ private void ensureJsonCond(QueryWrapper<ObjectDigital> wrapper, ObjectNode criteria) {
|
|
|
+ Set<String> fieldSet = ReflectUtil.getFieldMap(ObjectDigital.class).keySet();
|
|
|
+ Iterator<String> fieldNames = criteria.fieldNames();
|
|
|
+ while (fieldNames.hasNext()) {
|
|
|
+ String infoCode = fieldNames.next();
|
|
|
+ // 基础属性不用处理
|
|
|
+ if(fieldSet.contains(infoCode)) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ JsonNode value = criteria.get(infoCode);
|
|
|
+ if(value == null || value.isNull()) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ // 如果值是对象
|
|
|
+ if(value.isObject()) {
|
|
|
+ // 包含
|
|
|
+ if (value.has("$contains")) {
|
|
|
+ JsonNode valueNode = value.get("$contains");
|
|
|
+ String valueStr = valueNode.isTextual() ? value.asText():value.toString();
|
|
|
+ wrapper.eq(StrUtil.format("json_contains({}, {}, '$.{}')", "infos", valueStr, infoCode), 1);
|
|
|
+ } else if (value.has("$notcontains")) {
|
|
|
+ // 不包含
|
|
|
+ JsonNode valueNode = value.get("$notcontains");
|
|
|
+ String valueStr = valueNode.isTextual() ? value.asText():value.toString();
|
|
|
+ wrapper.eq(StrUtil.format("json_contains({}, {}, '$.{}')", "infos", valueStr, infoCode), 0);
|
|
|
+ }
|
|
|
+ } else if(value.isTextual()) {
|
|
|
+ wrapper.eq(StrUtil.format("json_unquote(json_extract({}, '$.{}'))", "infos", infoCode), value.asText());
|
|
|
+ } else if(value.isInt()) {
|
|
|
+ wrapper.eq(StrUtil.format("ifnull(json_extract({}, '$.{}'), -9999)", "infos", infoCode), value.asInt());
|
|
|
+ } else if(value.isDouble()) {
|
|
|
+ wrapper.eq(StrUtil.format("ifnull(json_extract({}, '$.{}'), -9999.99)", "infos", infoCode), value.asDouble());
|
|
|
+ }
|
|
|
+ // 处理完成后删除
|
|
|
+ fieldNames.remove();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 拼接$search条件
|
|
|
+ * @param wrapper
|
|
|
+ * @param criteria
|
|
|
+ */
|
|
|
+ private void ensureSearchCond(QueryWrapper<ObjectDigital> wrapper, ObjectNode criteria) {
|
|
|
+ if(criteria == null || criteria.isNull()) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ // 处理relationFrom
|
|
|
+ JsonNode search = criteria.get("$search");
|
|
|
+ if(search != null && search.isTextual()) {
|
|
|
+ String searchValue = search.asText();
|
|
|
+ wrapper.isNotNull(StrUtil.format("json_search({0}, 'one', {1})", "infos", searchValue));
|
|
|
+ // 处理完成后删除
|
|
|
+ criteria.remove("$search");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
* 处理关系条件
|
|
|
* @param wrapper
|
|
|
* @param criteria
|