Browse Source

Merge remote-tracking branch 'origin/develop' into develop

lijie 3 years ago
parent
commit
8faefbafeb

+ 28 - 26
dmp-business/dmp-rwd/src/main/java/com/persagy/dmp/rwd/digital/utils/ObjectDigitalCriteriaHelper.java

@@ -3,6 +3,7 @@ package com.persagy.dmp.rwd.digital.utils;
 import cn.hutool.core.collection.CollUtil;
 import cn.hutool.core.map.MapUtil;
 import cn.hutool.core.util.ArrayUtil;
+import cn.hutool.core.util.BooleanUtil;
 import cn.hutool.core.util.ReflectUtil;
 import cn.hutool.core.util.StrUtil;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
@@ -32,6 +33,8 @@ public class ObjectDigitalCriteriaHelper {
 
     /** 对象类字段集 */
     public static final Set<String> DIGITAL_FIELDS = ReflectUtil.getFieldMap(ObjectDigital.class).keySet();
+    /** 未绑定关系标识 */
+    private static final String BIND_FLAG = "$bindFlag";
 
     /**
      * 对象查询条件预处理:主要处理infos扩展内容
@@ -269,9 +272,8 @@ public class ObjectDigitalCriteriaHelper {
         }
         //增加默认有效标示
         ObjectNode jsonNode = (ObjectNode) relationCond;
-        if(jsonNode.get("valid") == null){
-            jsonNode.put("valid",ValidEnum.TRUE.getType());
-            relationCond = jsonNode;
+        if(jsonNode.get(BaseEntity.PROP_VALID) == null){
+            jsonNode.put(BaseEntity.PROP_VALID, ValidEnum.TRUE.getType());
         }
         /** 20210827 relation条件支持复杂条件 - 使用Wrapper方式只能先查询出来,可以改为拼接sql提升效率,但需要大量扩展,不便于维护。
         // 查询关系的条件
@@ -294,14 +296,18 @@ public class ObjectDigitalCriteriaHelper {
         criteria.remove(flagKey);
          **/
         StringBuilder inSql = new StringBuilder("(select "+selectKey+" from dt_relation where 1=1 ");
-        addWhereCond(relationCond, inSql, "graphId");
-        addWhereCond(relationCond, inSql, "graphCode");
-        addWhereCond(relationCond, inSql, "relCode");
-        addObjectWhereCond(relationCond, inSql, "valid");
-        addWhereCond(relationCond, inSql, whereKey);
+        addWhereCond(jsonNode, inSql, "graphId");
+        addWhereCond(jsonNode, inSql, "graphCode");
+        addWhereCond(jsonNode, inSql, "relCode");
+        addWhereCond(jsonNode, inSql, "valid");
+        addWhereCond(jsonNode, inSql, whereKey);
         inSql.append(")");
+        // 查询已绑定or未绑定关系的对象 - $bindFlag设置为false 才为查未绑定对象
+        Object bindFlag = JsonNodeUtils.getNodeValue(jsonNode.get(BIND_FLAG));
+        boolean notBind = bindFlag != null && bindFlag instanceof Boolean && BooleanUtil.isFalse((Boolean) bindFlag);
+        // 重置查询条件
         ObjectNode inObj = criteria.putObject(BaseEntity.PROP_ID);
-        inObj.put(QueryOperator.IN_SQL.getIndex(), inSql.toString());
+        inObj.put(notBind?QueryOperator.NOT_IN_SQL.getIndex():QueryOperator.IN_SQL.getIndex(), inSql.toString());
         // 处理完成后删除
         criteria.remove(flagKey);
     }
@@ -313,24 +319,20 @@ public class ObjectDigitalCriteriaHelper {
      * @param field 属性名
      */
     private static 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 + "' ");
+        Object value = JsonNodeUtils.getNodeValue(node.get(field));
+        if(value == null) {
+            return;
         }
-    }
-
-    /**
-     * 添加where条件
-     * @param node json对象
-     * @param inSql in条件
-     * @param field 属性名
-     */
-    private static void addObjectWhereCond(JsonNode node, StringBuilder inSql, String field) {
-        Object nodeValue = JsonNodeUtils.getNodeValue(node.get(field));
-        if(nodeValue != null) {
-            String column = StrUtil.toUnderlineCase(field);
-            inSql.append("and " + column + " = " + nodeValue + " ");
+        // 转下划线
+        String column = StrUtil.toUnderlineCase(field);
+        // 字符串的加单引号,其他的不加
+        if(value instanceof String) {
+            String stringValue = (String) value;
+            if(StrUtil.isNotEmpty(stringValue)) {
+                inSql.append("and " + column + " = '" + stringValue + "' ");
+            }
+        } else {
+            inSql.append("and " + column + " = " + StrUtil.toString(value) + " ");
         }
     }
 

+ 1 - 0
dmp-comp/dmp-digital-starter/src/main/java/com/persagy/dmp/basic/model/QueryOperator.java

@@ -31,6 +31,7 @@ public enum QueryOperator {
     SQL("$sql", "SQL"),
     /** 20210816 支持relation条件 */
     IN_SQL("$inSql", "IN_SQL"),
+    NOT_IN_SQL("$notInSql", "NOT_IN_SQL"),
     /** 20210816 支持or条件 */
     AND("$and", "且"),
     OR("$or", "或"),

+ 2 - 0
dmp-comp/dmp-digital-starter/src/main/java/com/persagy/dmp/basic/utils/QueryCriteriaHelper.java

@@ -217,6 +217,8 @@ public class QueryCriteriaHelper {
             wrapper.in(field, JsonNodeUtils.getListValue(valueNode));
         } else if(QueryOperator.IN_SQL.getIndex().equalsIgnoreCase(operator)) {
             wrapper.inSql(field, (String) JsonNodeUtils.getNodeValue(valueNode));
+        } else if(QueryOperator.NOT_IN_SQL.getIndex().equalsIgnoreCase(operator)) {
+            wrapper.notInSql(field, (String) JsonNodeUtils.getNodeValue(valueNode));
         } else if(QueryOperator.LIKE.getIndex().equalsIgnoreCase(operator)) {
             wrapper.like(field, JsonNodeUtils.getNodeValue(valueNode));
         } else if(QueryOperator.LIKE_LEFT.getIndex().equalsIgnoreCase(operator)) {