|
@@ -1,14 +1,17 @@
|
|
|
package com.persagy.dmp.rwd.digital.controller;
|
|
|
|
|
|
import cn.hutool.core.collection.CollUtil;
|
|
|
+import cn.hutool.core.util.StrUtil;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
+import com.fasterxml.jackson.databind.JsonNode;
|
|
|
import com.fasterxml.jackson.databind.node.ArrayNode;
|
|
|
import com.fasterxml.jackson.databind.node.ObjectNode;
|
|
|
import com.persagy.dmp.basic.model.QueryCriteria;
|
|
|
import com.persagy.dmp.basic.utils.JsonNodeUtils;
|
|
|
import com.persagy.dmp.common.constant.ResponseCode;
|
|
|
import com.persagy.dmp.common.exception.BusinessException;
|
|
|
+import com.persagy.dmp.common.model.entity.BaseEntity;
|
|
|
import com.persagy.dmp.common.model.response.CommonResult;
|
|
|
import com.persagy.dmp.common.model.response.PageList;
|
|
|
import com.persagy.dmp.common.utils.ResultHelper;
|
|
@@ -38,17 +41,72 @@ public class ObjectDigitalController {
|
|
|
private IObjectDigitalService service;
|
|
|
|
|
|
@PostMapping("/query")
|
|
|
- public CommonResult<PageList<ObjectDigital>> query(@RequestBody QueryCriteria criteria) {
|
|
|
+ public CommonResult<PageList<ObjectNode>> query(@RequestBody QueryCriteria criteria) {
|
|
|
if(criteria == null) {
|
|
|
throw new BusinessException(ResponseCode.A0400.getCode(), ResponseCode.A0400.getDesc());
|
|
|
}
|
|
|
QueryWrapper<ObjectDigital> wrapper = new QueryWrapper<>();
|
|
|
// 添加所属项目条件
|
|
|
ConditionUtil.ensureProjectCriteria(wrapper);
|
|
|
+ // 处理关系条件
|
|
|
+ ensureRelationCond(wrapper, criteria.getCriteria());
|
|
|
// 转换查询条件
|
|
|
QueryCriteriaHelper.toWrapper(wrapper, criteria);
|
|
|
Page page = service.queryByCondition(QueryCriteriaHelper.toPage(criteria), wrapper);
|
|
|
- return ResultHelper.multi(page.getRecords(), page.getTotal());
|
|
|
+ // 处理扩展属性
|
|
|
+ List<ObjectNode> records = JsonNodeUtils.toListNode(page.getRecords(), "infos", criteria.getWithColumns());
|
|
|
+ return ResultHelper.multi(records, page.getTotal());
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 处理关系条件
|
|
|
+ * @param wrapper
|
|
|
+ * @param criteria
|
|
|
+ */
|
|
|
+ private void ensureRelationCond(QueryWrapper<ObjectDigital> wrapper, ObjectNode criteria) {
|
|
|
+ if(criteria == null || criteria.isNull()) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ // 处理relationFrom
|
|
|
+ JsonNode relationFrom = criteria.get("relationFrom");
|
|
|
+ if(relationFrom != null && relationFrom.isObject() && relationFrom.size() > 0) {
|
|
|
+ StringBuilder inSql = new StringBuilder("(select obj_from from dt_relation where 1=1 ");
|
|
|
+ addWhereCond(relationFrom, inSql, "graphId");
|
|
|
+ addWhereCond(relationFrom, inSql, "graphCode");
|
|
|
+ addWhereCond(relationFrom, inSql, "relCode");
|
|
|
+ addWhereCond(relationFrom, inSql, "objTo");
|
|
|
+ inSql.append(")");
|
|
|
+ wrapper.inSql(BaseEntity.PROP_ID, inSql.toString());
|
|
|
+ // 处理完成后删除
|
|
|
+ criteria.remove("relationFrom");
|
|
|
+ }
|
|
|
+ // 处理relationTo
|
|
|
+ JsonNode relationTo = criteria.get("relationTo");
|
|
|
+ if(relationTo != null && relationTo.isObject() && relationTo.size() > 0) {
|
|
|
+ StringBuilder inSql = new StringBuilder("(select obj_to from dt_relation where 1=1 ");
|
|
|
+ addWhereCond(relationTo, inSql, "graphId");
|
|
|
+ addWhereCond(relationTo, inSql, "graphCode");
|
|
|
+ addWhereCond(relationTo, inSql, "relCode");
|
|
|
+ addWhereCond(relationTo, inSql, "objFrom");
|
|
|
+ inSql.append(")");
|
|
|
+ wrapper.inSql(BaseEntity.PROP_ID, inSql.toString());
|
|
|
+ // 处理完成后删除
|
|
|
+ criteria.remove("relationTo");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 添加where条件
|
|
|
+ * @param node json对象
|
|
|
+ * @param inSql in条件
|
|
|
+ * @param field 属性名
|
|
|
+ */
|
|
|
+ private void addWhereCond(JsonNode node, StringBuilder inSql, String field) {
|
|
|
+ String value = (String) JsonNodeUtils.getNodeValue(node.get(field));
|
|
|
+ if(StrUtil.isNotEmpty(value)) {
|
|
|
+ String column = StrUtil.toUnderlineCase(field);
|
|
|
+ inSql.append("and " + column + " = '" + value + "' ");
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
@PostMapping("/createOne")
|