浏览代码

find not in

zhangxinlei1996 5 年之前
父节点
当前提交
a283aa169f
共有 1 个文件被更改,包括 9 次插入0 次删除
  1. 9 0
      common/src/qfw/util/mysql/mysql.go

+ 9 - 0
common/src/qfw/util/mysql/mysql.go

@@ -150,6 +150,7 @@ func (m *Mysql) ExecBySqlByTx(tx *sql.Tx, q string, args ...interface{}) (sql.Re
 }
 
 /*不等于 map[string]string{"ne":"1"}
+ *不等于多个 map[string]string{"notin":[]interface{}{1,2}}
  *字段为空 map[string]string{"name":"$isNull"}
  *字段不为空 map[string]string{"name":"$isNotNull"}
  */
@@ -165,6 +166,14 @@ func (m *Mysql) Find(tableName string, query map[string]interface{}, fields, ord
 					fs = append(fs, fmt.Sprintf("%s!=?", k))
 					vs = append(vs, rv.MapIndex(rv_k).Interface())
 				}
+				if rv_k.String() == "notin" {
+					if len(rv.MapIndex(rv_k).Interface().([]interface{})) > 0 {
+						for _, v := range rv.MapIndex(rv_k).Interface().([]interface{}) {
+							fs = append(fs, fmt.Sprintf("%s!=?", k))
+							vs = append(vs, v)
+						}
+					}
+				}
 			}
 		} else {
 			if v == "$isNull" {