|
@@ -93,36 +93,39 @@ abstract class SAbstractDriver {
|
|
|
val entity = argsMap["entity"] as HashMap<String, Any?>
|
|
|
val filterArgs = argsMap["filterArgs"] as List<SFilter>
|
|
|
val whereArgs = argsMap["whereArgs"] as HashMap<String, Any>
|
|
|
- val fieldList = ArrayList<String>()
|
|
|
+ val nullItemList = ArrayList<String>()
|
|
|
|
|
|
- if (argsMap.containsKey("projection")) {
|
|
|
- val fields = argsMap["projection"] as ArrayList<String>?
|
|
|
+ if (argsMap.containsKey("nullItems")) {
|
|
|
+ val fields = argsMap["nullItems"] as ArrayList<String>?
|
|
|
/** 转换属性名 */
|
|
|
fields?.forEach {
|
|
|
try {
|
|
|
val colName = SAbstractDao.columnName(entityClass, it.trim())
|
|
|
- fieldList.add(colName)
|
|
|
+ nullItemList.add(colName)
|
|
|
} catch (e: Exception) {
|
|
|
e.printStackTrace()
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- val updateNull = fieldList.size > 0
|
|
|
+// val updateNull = fieldList.size > 0
|
|
|
+ //
|
|
|
val clause = buildWhereArgList(entityClass, filterArgs, whereArgs)
|
|
|
|
|
|
val sql = object: SQL() {
|
|
|
init {
|
|
|
UPDATE(SSqlProvider.driver.tableName(entityClass))
|
|
|
|
|
|
+ // 遍历传入的对象的属性 键值
|
|
|
for ((key, value) in entity) {
|
|
|
- if (fieldList.size > 0 && !fieldList.contains(key)) {
|
|
|
- continue
|
|
|
- }
|
|
|
- if (value == null && updateNull) {
|
|
|
- // PostgreSQL使用参数更新,为空更新不成功。必须使用sql直接设置
|
|
|
- SET("${SSqlProvider.driver.escName(key)} = null")
|
|
|
- }
|
|
|
+// if (nullItemList.size > 0 && !nullItemList.contains(key)) {
|
|
|
+// continue
|
|
|
+// }
|
|
|
+// if (value == null && updateNull) {
|
|
|
+// // PostgreSQL使用参数更新,为空更新不成功。必须使用sql直接设置
|
|
|
+// SET("${SSqlProvider.driver.escName(key)} = null")
|
|
|
+// }
|
|
|
+ // 值不为空的更新
|
|
|
if (value != null) {
|
|
|
if (value is Map<*,*>) {
|
|
|
SET("${SSqlProvider.driver.escName(key)} = ${SSqlProvider.driver.updateJson(key, value)}")
|
|
@@ -136,6 +139,17 @@ abstract class SAbstractDriver {
|
|
|
// }
|
|
|
}
|
|
|
}
|
|
|
+ // 遍历置空属性列表
|
|
|
+ for (nullItem in nullItemList){
|
|
|
+ // PostgreSQL使用参数更新,为空更新不成功。必须使用sql直接设置
|
|
|
+ val pos = nullItem.indexOf(".")
|
|
|
+ if (pos > 0){
|
|
|
+ SET(SSqlProvider.driver.updateNullItem(nullItem))
|
|
|
+ }else{
|
|
|
+ SET("${SSqlProvider.driver.escName(nullItem)} = null")
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 更新条件为空不拼接条件
|
|
|
if (clause.isNotEmpty()) {
|
|
|
WHERE(clause)
|
|
|
}
|
|
@@ -403,6 +417,13 @@ abstract class SAbstractDriver {
|
|
|
abstract fun processFunction(func: SAbstractFunction, colName: String): String;
|
|
|
|
|
|
/**
|
|
|
+ * jsonb 中属性置空
|
|
|
+ *
|
|
|
+ * @param nullItem 表列名
|
|
|
+ */
|
|
|
+ abstract fun updateNullItem(nullItem: String): String
|
|
|
+
|
|
|
+ /**
|
|
|
* 构造 where 子句参数
|
|
|
*
|
|
|
* @param filterList 过滤条件
|