Browse Source

fix:修改信息点置空

zhangweixin 3 years ago
parent
commit
876d48860c

+ 1 - 1
gradle.properties

@@ -25,7 +25,7 @@
 #
 
 PERSAGY_URL = http://www.persagy.com/
-PERSAGY_KOTLIN_VERSION = 1.4.121
+PERSAGY_KOTLIN_VERSION = 1.4.128
 # android
 # SYBOTAN_KOTLIN_VERSION = 1.4.63
 

+ 30 - 22
persagy-kotlin-database/src/main/kotlin/com/persagy/database/SAbstractDao.kt

@@ -101,42 +101,50 @@ abstract class SAbstractDao<ENTITY: Any>(entityClazz: Class<ENTITY>) {
      * 在数据库中插入实体
      *
      * @param entity      插入数据库的实体
+     * @param builder  更新条件构件器
      * @return 插入是否成功
      */
-    abstract fun insert(entity: ENTITY): Boolean
+    abstract fun insert(entity: ENTITY, builder: SInsetBuilder<ENTITY>? = null): Boolean
 
     /**
      * 在数据库中插入/更新实体
      *
      * @param entity      插入/更新数据库的实体
+     * @param builder  更新条件构件器
+     *
      * @return 插入是否成功
      */
-    abstract fun replace(entity: ENTITY): Boolean
+    abstract fun replace(entity: ENTITY, builder: SReplaceBuilder<ENTITY>? = null): Boolean
 
     /**
      * 根据条件删除
      *
      * @param args        删除条件
+     * @param builder  更新条件构件器
+     *
      * @return 删除是否成功
      */
-    abstract fun delete(args: List<SFilter>): Boolean
+    abstract fun delete(args: List<SFilter>, builder: SDeleteBuilder<ENTITY>? = null): Boolean
 
     /**
      * 删除所有记录
      *
+     * @param builder  更新条件构件器
+     *
      * @return 删除是否成功
      */
-    abstract fun deleteAll(): Boolean
+    abstract fun deleteAll(builder: SDeleteBuilder<ENTITY>? = null): Boolean
 
     /**
      * 根据条件更新
      *
      * @param entity      更新的值
-     * @param projection  将被更新的字段列表(以逗号分隔),为空表示更新所有非空字段
+     * @param nullItems   将被更新的字段列表(以逗号分隔),为空表示更新所有非空字段
      * @param args        更新条件
+     * @param builder     更新条件构件器
      * @return 更新是否成功
      */
-    abstract fun update(entity: ENTITY, projection: ArrayList<String>? = null, args: List<SFilter>? = null): Boolean
+    abstract fun update(entity: ENTITY, nullItems: ArrayList<String>? = null, args: List<SFilter>? = null, builder: SUpdateBuilder<ENTITY>? = null): Boolean
 
     /**
      * 根据条件查询记录
@@ -192,8 +200,8 @@ abstract class SAbstractDao<ENTITY: Any>(entityClazz: Class<ENTITY>) {
      * @param entity      被删除的实体
      * @return 删除是否成功
      */
-    open fun delete(entity: ENTITY): Boolean {
-        return delete(entity.filterListByKeys())
+    open fun delete(entity: ENTITY, builder: SDeleteBuilder<ENTITY>? = null): Boolean {
+        return delete(entity.filterListByKeys(), builder)
     }
 
     /**
@@ -202,13 +210,13 @@ abstract class SAbstractDao<ENTITY: Any>(entityClazz: Class<ENTITY>) {
      * @param args        删除条件
      * @return 删除是否成功
      */
-    open fun delete(vararg args: Pair<String, Any>): Boolean {
+    open fun delete(builder: SDeleteBuilder<ENTITY>? = null, vararg args: Pair<String, Any>): Boolean {
         val filterList = ArrayList<SFilter>()
         for (arg in args) {     // 同时取列表元素与下标
             filterList.add(SFilter.eq(arg.first, arg.second))
         }
 
-        return delete(filterList)
+        return delete(filterList, builder)
     }
 
     /**
@@ -217,8 +225,8 @@ abstract class SAbstractDao<ENTITY: Any>(entityClazz: Class<ENTITY>) {
      * @param args        删除条件
      * @return 删除是否成功
      */
-    open fun delete(vararg args: SFilter): Boolean {
-        return delete(args.toList())
+    open fun delete(builder: SDeleteBuilder<ENTITY>? = null, vararg args: SFilter): Boolean {
+        return delete(args.toList(), builder)
     }
 
     /**
@@ -227,9 +235,9 @@ abstract class SAbstractDao<ENTITY: Any>(entityClazz: Class<ENTITY>) {
      * @param query       删除条件
      * @return 删除是否成功
      */
-    open fun delete(query: String): Boolean {
+    open fun delete(query: String, builder: SDeleteBuilder<ENTITY>? = null): Boolean {
         val parser = SSyntaxParser(ByteArrayInputStream(query.toByteArray()))
-        return delete(parser.parserFilters())
+        return delete(parser.parserFilters(), builder)
     }
 
     /**
@@ -239,8 +247,8 @@ abstract class SAbstractDao<ENTITY: Any>(entityClazz: Class<ENTITY>) {
      * @param projection  将被更新的字段列表(以逗号分隔),为空表示更新所有非空字段
      * @return 更新是否成功
      */
-    open fun update(entity: ENTITY, projection: ArrayList<String>? = null): Boolean {
-        return update(entity, projection, entity.filterListByKeys())
+    open fun update(entity: ENTITY, projection: ArrayList<String>? = null, builder: SUpdateBuilder<ENTITY>? = null): Boolean {
+        return update(entity, projection, entity.filterListByKeys(), builder)
     }
 
     /**
@@ -251,13 +259,13 @@ abstract class SAbstractDao<ENTITY: Any>(entityClazz: Class<ENTITY>) {
      * @param args        更新条件
      * @return 更新是否成功
      */
-    open fun update(entity: ENTITY, projection: ArrayList<String>? = null, vararg args: Pair<String, Any>): Boolean {
+    open fun update(entity: ENTITY, projection: ArrayList<String>? = null, builder: SUpdateBuilder<ENTITY>? = null, vararg args: Pair<String, Any>): Boolean {
         val filterList = ArrayList<SFilter>()
         for (arg in args) {
             filterList.add(SFilter.eq(arg.first, arg.second))
         }
 
-        return update(entity, projection, filterList)
+        return update(entity, projection, filterList, builder)
     }
 
     /**
@@ -268,8 +276,8 @@ abstract class SAbstractDao<ENTITY: Any>(entityClazz: Class<ENTITY>) {
      * @param args        更新条件
      * @return 更新是否成功
      */
-    open fun update(entity: ENTITY, projection: ArrayList<String>? = null, vararg args: SFilter): Boolean {
-        return update(entity, projection, args.toList())
+    open fun update(entity: ENTITY, projection: ArrayList<String>? = null, builder: SUpdateBuilder<ENTITY>? = null, vararg args: SFilter ): Boolean {
+        return update(entity, projection, args.toList(), builder)
     }
 
     /**
@@ -280,9 +288,9 @@ abstract class SAbstractDao<ENTITY: Any>(entityClazz: Class<ENTITY>) {
      * @param query       更新条件
      * @return 更新是否成功
      */
-    open fun update(entity: ENTITY, projection: ArrayList<String>? = null, query: String): Boolean {
+    open fun update(entity: ENTITY, projection: ArrayList<String>? = null, query: String, builder: SUpdateBuilder<ENTITY>? = null): Boolean {
         val parser = SSyntaxParser(ByteArrayInputStream(query.toByteArray()))
-        return update(entity, projection, parser.parserFilters())
+        return update(entity, projection, parser.parserFilters(), builder)
     }
 
     /**

+ 49 - 0
persagy-kotlin-database/src/main/kotlin/com/persagy/database/SDeleteBuilder.kt

@@ -0,0 +1,49 @@
+/*
+ * *********************************************************************************************************************
+ *
+ *          !!
+ *        .F88X
+ *        X8888Y
+ *      .}888888N;
+ *        i888888N;        .:!              .I$WI:
+ *          R888888I      .'N88~            i8}+8Y&8"l8i$8>8W~'>W8}8]KW+8IIN"8&
+ *          .R888888I    .;N8888~          .X8'  "8I.!,/8"  !%NY8`"8I8~~8>,88I
+ *            +888888N;  .8888888Y                                  "&&8Y.}8,
+ *            ./888888N;  .R888888Y        .'}~    .>}'.`+>  i}!    "i'  +/'  .'i~  !11,.:">,  .~]!  .i}i
+ *              ~888888%:  .I888888l      .]88~`1/iY88Ii+1'.R$8$8]"888888888>  Y8$  W8E  X8E  W8888'188Il}Y88$*
+ *              18888888    E8888881    .]W%8$`R8X'&8%++N8i,8N%N8+l8%`  .}8N:.R$RE%N88N%N$K$R  188,FE$8%~Y88I
+ *            .E888888I  .i8888888'      .:$8I;88+`E8R:/8N,.>881.`$8E/1/]N8X.Y8N`"KF&&FK!'88*."88K./$88%RN888+~
+ *            8888888I  .,N888888~        ~88i"8W,!N8*.I88.}888%F,i$88"F88"  888:E8X.>88!i88>`888*.}Fl1]*}1YKi'
+ *          i888888N'      I888Y          ]88;/EX*IFKFK88X  K8R  .l8W  88Y  ~88}'88E&%8W.X8N``]88!.$8K  .:W8I
+ *        .i888888N;        I8Y          .&8$  .X88!  i881.:%888>I88  ;88]  +88+.';;;;:.Y88X  18N.,88l  .+88/
+ *      .:R888888I
+ *      .&888888I                                          Copyright (c) 2009-2020.  博锐尚格科技股份有限公司
+ *        ~8888'
+ *        .!88~                                                                     All rights reserved.
+ *
+ * *********************************************************************************************************************
+ */
+
+package com.persagy.database
+
+/**
+ * 刪除条件生成器
+ *
+ * @author 庞利祥 <sybotan@126.com>
+ */
+class SDeleteBuilder<ENTITY: Any>(private val baseDao: SAbstractDao<ENTITY>) {
+
+    /** 表名 */
+    var tableName: String? = null
+
+    /**
+     * 数据库表
+     *
+     * @param name    表名
+     * @return 查询构建器
+     */
+    fun table(name: String): SDeleteBuilder<ENTITY> {
+        tableName = name
+        return this
+    }
+}

+ 49 - 0
persagy-kotlin-database/src/main/kotlin/com/persagy/database/SInsetBuilder.kt

@@ -0,0 +1,49 @@
+/*
+ * *********************************************************************************************************************
+ *
+ *          !!
+ *        .F88X
+ *        X8888Y
+ *      .}888888N;
+ *        i888888N;        .:!              .I$WI:
+ *          R888888I      .'N88~            i8}+8Y&8"l8i$8>8W~'>W8}8]KW+8IIN"8&
+ *          .R888888I    .;N8888~          .X8'  "8I.!,/8"  !%NY8`"8I8~~8>,88I
+ *            +888888N;  .8888888Y                                  "&&8Y.}8,
+ *            ./888888N;  .R888888Y        .'}~    .>}'.`+>  i}!    "i'  +/'  .'i~  !11,.:">,  .~]!  .i}i
+ *              ~888888%:  .I888888l      .]88~`1/iY88Ii+1'.R$8$8]"888888888>  Y8$  W8E  X8E  W8888'188Il}Y88$*
+ *              18888888    E8888881    .]W%8$`R8X'&8%++N8i,8N%N8+l8%`  .}8N:.R$RE%N88N%N$K$R  188,FE$8%~Y88I
+ *            .E888888I  .i8888888'      .:$8I;88+`E8R:/8N,.>881.`$8E/1/]N8X.Y8N`"KF&&FK!'88*."88K./$88%RN888+~
+ *            8888888I  .,N888888~        ~88i"8W,!N8*.I88.}888%F,i$88"F88"  888:E8X.>88!i88>`888*.}Fl1]*}1YKi'
+ *          i888888N'      I888Y          ]88;/EX*IFKFK88X  K8R  .l8W  88Y  ~88}'88E&%8W.X8N``]88!.$8K  .:W8I
+ *        .i888888N;        I8Y          .&8$  .X88!  i881.:%888>I88  ;88]  +88+.';;;;:.Y88X  18N.,88l  .+88/
+ *      .:R888888I
+ *      .&888888I                                          Copyright (c) 2009-2020.  博锐尚格科技股份有限公司
+ *        ~8888'
+ *        .!88~                                                                     All rights reserved.
+ *
+ * *********************************************************************************************************************
+ */
+
+package com.persagy.database
+
+/**
+ * 插入条件生成器
+ *
+ * @author 庞利祥 <sybotan@126.com>
+ */
+class SInsetBuilder<ENTITY: Any>(private val baseDao: SAbstractDao<ENTITY>) {
+
+    /** 表名 */
+    var tableName: String? = null
+
+    /**
+     * 数据库表
+     *
+     * @param name    表名
+     * @return 查询构建器
+     */
+    fun table(name: String): SInsetBuilder<ENTITY> {
+        tableName = name
+        return this
+    }
+}

+ 49 - 0
persagy-kotlin-database/src/main/kotlin/com/persagy/database/SReplaceBuilder.kt

@@ -0,0 +1,49 @@
+/*
+ * *********************************************************************************************************************
+ *
+ *          !!
+ *        .F88X
+ *        X8888Y
+ *      .}888888N;
+ *        i888888N;        .:!              .I$WI:
+ *          R888888I      .'N88~            i8}+8Y&8"l8i$8>8W~'>W8}8]KW+8IIN"8&
+ *          .R888888I    .;N8888~          .X8'  "8I.!,/8"  !%NY8`"8I8~~8>,88I
+ *            +888888N;  .8888888Y                                  "&&8Y.}8,
+ *            ./888888N;  .R888888Y        .'}~    .>}'.`+>  i}!    "i'  +/'  .'i~  !11,.:">,  .~]!  .i}i
+ *              ~888888%:  .I888888l      .]88~`1/iY88Ii+1'.R$8$8]"888888888>  Y8$  W8E  X8E  W8888'188Il}Y88$*
+ *              18888888    E8888881    .]W%8$`R8X'&8%++N8i,8N%N8+l8%`  .}8N:.R$RE%N88N%N$K$R  188,FE$8%~Y88I
+ *            .E888888I  .i8888888'      .:$8I;88+`E8R:/8N,.>881.`$8E/1/]N8X.Y8N`"KF&&FK!'88*."88K./$88%RN888+~
+ *            8888888I  .,N888888~        ~88i"8W,!N8*.I88.}888%F,i$88"F88"  888:E8X.>88!i88>`888*.}Fl1]*}1YKi'
+ *          i888888N'      I888Y          ]88;/EX*IFKFK88X  K8R  .l8W  88Y  ~88}'88E&%8W.X8N``]88!.$8K  .:W8I
+ *        .i888888N;        I8Y          .&8$  .X88!  i881.:%888>I88  ;88]  +88+.';;;;:.Y88X  18N.,88l  .+88/
+ *      .:R888888I
+ *      .&888888I                                          Copyright (c) 2009-2020.  博锐尚格科技股份有限公司
+ *        ~8888'
+ *        .!88~                                                                     All rights reserved.
+ *
+ * *********************************************************************************************************************
+ */
+
+package com.persagy.database
+
+/**
+ * 替換条件生成器
+ *
+ * @author 庞利祥 <sybotan@126.com>
+ */
+class SReplaceBuilder<ENTITY: Any>(private val baseDao: SAbstractDao<ENTITY>) {
+
+    /** 表名 */
+    var tableName: String? = null
+
+    /**
+     * 数据库表
+     *
+     * @param name    表名
+     * @return 查询构建器
+     */
+    fun table(name: String): SReplaceBuilder<ENTITY> {
+        tableName = name
+        return this
+    }
+}

+ 49 - 0
persagy-kotlin-database/src/main/kotlin/com/persagy/database/SUpdateBuilder.kt

@@ -0,0 +1,49 @@
+/*
+ * *********************************************************************************************************************
+ *
+ *          !!
+ *        .F88X
+ *        X8888Y
+ *      .}888888N;
+ *        i888888N;        .:!              .I$WI:
+ *          R888888I      .'N88~            i8}+8Y&8"l8i$8>8W~'>W8}8]KW+8IIN"8&
+ *          .R888888I    .;N8888~          .X8'  "8I.!,/8"  !%NY8`"8I8~~8>,88I
+ *            +888888N;  .8888888Y                                  "&&8Y.}8,
+ *            ./888888N;  .R888888Y        .'}~    .>}'.`+>  i}!    "i'  +/'  .'i~  !11,.:">,  .~]!  .i}i
+ *              ~888888%:  .I888888l      .]88~`1/iY88Ii+1'.R$8$8]"888888888>  Y8$  W8E  X8E  W8888'188Il}Y88$*
+ *              18888888    E8888881    .]W%8$`R8X'&8%++N8i,8N%N8+l8%`  .}8N:.R$RE%N88N%N$K$R  188,FE$8%~Y88I
+ *            .E888888I  .i8888888'      .:$8I;88+`E8R:/8N,.>881.`$8E/1/]N8X.Y8N`"KF&&FK!'88*."88K./$88%RN888+~
+ *            8888888I  .,N888888~        ~88i"8W,!N8*.I88.}888%F,i$88"F88"  888:E8X.>88!i88>`888*.}Fl1]*}1YKi'
+ *          i888888N'      I888Y          ]88;/EX*IFKFK88X  K8R  .l8W  88Y  ~88}'88E&%8W.X8N``]88!.$8K  .:W8I
+ *        .i888888N;        I8Y          .&8$  .X88!  i881.:%888>I88  ;88]  +88+.';;;;:.Y88X  18N.,88l  .+88/
+ *      .:R888888I
+ *      .&888888I                                          Copyright (c) 2009-2020.  博锐尚格科技股份有限公司
+ *        ~8888'
+ *        .!88~                                                                     All rights reserved.
+ *
+ * *********************************************************************************************************************
+ */
+
+package com.persagy.database
+
+/**
+ * 修改条件生成器
+ *
+ * @author 庞利祥 <sybotan@126.com>
+ */
+class SUpdateBuilder<ENTITY: Any>(private val baseDao: SAbstractDao<ENTITY>) {
+
+    /** 表名 */
+    var tableName: String? = null
+
+    /**
+     * 数据库表
+     *
+     * @param name    表名
+     * @return 查询构建器
+     */
+    fun table(name: String): SUpdateBuilder<ENTITY> {
+        tableName = name
+        return this
+    }
+}

+ 10 - 8
persagy-kotlin-mybatis/src/main/kotlin/com/persagy/mybatis/IBaseMapper.kt

@@ -26,9 +26,7 @@
 
 package com.persagy.mybatis
 
-import com.persagy.database.SFilter
-import com.persagy.database.SGroup
-import com.persagy.database.SQueryBuilder
+import com.persagy.database.*
 import org.apache.ibatis.annotations.*
 
 /**
@@ -46,7 +44,8 @@ interface IBaseMapper<ENTITY: Any> {
     @DeleteProvider(type = SSqlProvider::class, method = "delete")
     fun delete(@Param("entityClass")entityClass: Class<*>,
                @Param("filterArgs")filterArgs: List<SFilter>,
-               @Param("whereArgs")whereArgs: Map<String, Any>): Boolean
+               @Param("whereArgs")whereArgs: Map<String, Any>,
+               @Param("builder")builder: SDeleteBuilder<ENTITY>?): Boolean
 
     /**
      * 删除所有记录
@@ -55,7 +54,7 @@ interface IBaseMapper<ENTITY: Any> {
      * @return 是否成功
      */
     @DeleteProvider(type = SSqlProvider::class, method = "deleteAll")
-    fun deleteAll(@Param("entityClass")entityClass: Class<*>): Boolean
+    fun deleteAll(@Param("entityClass")entityClass: Class<*>,  @Param("builder")builder: SDeleteBuilder<ENTITY>?): Boolean
 
     /**
      * 在数据库中插入实体
@@ -66,7 +65,8 @@ interface IBaseMapper<ENTITY: Any> {
     @InsertProvider(type = SSqlProvider::class, method = "insert")
     @Options(useGeneratedKeys = true, keyProperty = "entity._id")
     fun insert(@Param("entityClass")entityClass: Class<*>,
-               @Param("entity")entity: Map<String, Any?>): Boolean
+               @Param("entity")entity: Map<String, Any?>,
+               @Param("builder")builder: SInsetBuilder<ENTITY>?): Boolean
 
     /**
      * 在数据库中插入实体
@@ -77,7 +77,8 @@ interface IBaseMapper<ENTITY: Any> {
     @InsertProvider(type = SSqlProvider::class, method = "replace")
     fun replace(@Param("entityClass")entityClass: Class<*>,
                 @Param("entity")entity: Map<String, Any?>,
-                @Param("keyColumnList")keyColumnList: ArrayList<String>): Boolean
+                @Param("keyColumnList")keyColumnList: ArrayList<String>,
+                @Param("builder")builder: SReplaceBuilder<ENTITY>?): Boolean
 
     /**
      * 根据条件更新
@@ -92,7 +93,8 @@ interface IBaseMapper<ENTITY: Any> {
                @Param("entity")entity: Map<String, Any?>,
                @Param("nullItems")nullItems: ArrayList<String>?,
                @Param("filterArgs")filterArgs: List<SFilter>?,
-               @Param("whereArgs")whereArgs: Map<String, Any>): Boolean
+               @Param("whereArgs")whereArgs: Map<String, Any>,
+               @Param("builder")builder: SUpdateBuilder<ENTITY>?): Boolean
 
     /**
      * 执行查询操作

+ 2 - 2
persagy-kotlin-mybatis/src/main/kotlin/com/persagy/mybatis/SAbstractDriver.kt

@@ -60,10 +60,10 @@ abstract class SAbstractDriver {
      * 在数据库中替换实体
      *
      * @param argsMap         注入参数
-     * @param insertSql       插入 SQL 语句
+     *
      * @return 替换 SQL 语句
      */
-    abstract fun replace(argsMap: Map<String, Any?>, insertSql: String): String
+    abstract fun replace(argsMap: Map<String, Any?>): String
 
     /**
      * 根据条件删除

+ 24 - 10
persagy-kotlin-mybatis/src/main/kotlin/com/persagy/mybatis/SAbstractMybatisDao.kt

@@ -56,11 +56,13 @@ abstract class SAbstractMybatisDao<ENTITY: Any>(entityClazz: Class<ENTITY>) : SA
      * 在数据库中插入实体
      *
      * @param entity      插入数据库的实体
+     * @param builder  更新条件构件器
+     *
      * @return 手入是否成功
      */
-    override fun insert(entity: ENTITY): Boolean {
+    override fun insert(entity: ENTITY, builder: SInsetBuilder<ENTITY>?): Boolean {
         val entityMap = entity.toInsertRow()
-        val result = mapper.insert(entityClass, entityMap)
+        val result = mapper.insert(entityClass, entityMap, builder)
         try {
             if (entityMap.containsKey("_id")) {
                 val id = entityMap["_id"]
@@ -82,11 +84,13 @@ abstract class SAbstractMybatisDao<ENTITY: Any>(entityClazz: Class<ENTITY>) : SA
      * 在数据库中插入实体
      *
      * @param entity      插入数据库的实体
+     * @param builder  更新条件构件器
+     *
      * @return 手入是否成功
      */
-    override fun replace(entity: ENTITY): Boolean {
+    override fun replace(entity: ENTITY, builder: SReplaceBuilder<ENTITY>?): Boolean {
         return try {
-            mapper.replace(entityClass, entity.toInsertRow(), entity.javaClass.keyColumnList())
+            mapper.replace(entityClass, entity.toInsertRow(), entity.javaClass.keyColumnList(), builder)
         } catch (e: Exception) {
             e.printStackTrace()
             false
@@ -97,11 +101,13 @@ abstract class SAbstractMybatisDao<ENTITY: Any>(entityClazz: Class<ENTITY>) : SA
      * 根据条件删除
      *
      * @param args        删除条件
+     * @param builder  更新条件构件器
+     *
      * @return 删除是否成功
      */
-    override fun delete(args: List<SFilter>): Boolean {
+    override fun delete(args: List<SFilter>, builder: SDeleteBuilder<ENTITY>?): Boolean {
         return try {
-            mapper.delete(entityClass, args, HashMap())
+            mapper.delete(entityClass, args, HashMap(),builder)
         } catch (e: Exception) {
             e.printStackTrace()
             false
@@ -111,11 +117,13 @@ abstract class SAbstractMybatisDao<ENTITY: Any>(entityClazz: Class<ENTITY>) : SA
     /**
      * 删除所有记录
      *
+     * @param builder  更新条件构件器
+     *
      * @return 删除是否成功
      */
-    override fun deleteAll(): Boolean {
+    override fun deleteAll(builder: SDeleteBuilder<ENTITY>?): Boolean {
         return try {
-            mapper.deleteAll(entityClass)
+            mapper.deleteAll(entityClass, builder)
         } catch (e: Exception) {
             e.printStackTrace()
             false
@@ -128,11 +136,13 @@ abstract class SAbstractMybatisDao<ENTITY: Any>(entityClazz: Class<ENTITY>) : SA
      * @param entity      实体
      * @param nullItems   置空属性列表
      * @param args        删除条件
+     * @param builder  更新条件构件器
+     *
      * @return 更新是否成功
      */
-    override fun update(entity: ENTITY, nullItems: ArrayList<String>?, args: List<SFilter>?): Boolean {
+    override fun update(entity: ENTITY, nullItems: ArrayList<String>?, args: List<SFilter>?, builder: SUpdateBuilder<ENTITY>?): Boolean {
         return try {
-            mapper.update(entityClass, entity.toUpdateRow(), nullItems, args, HashMap())
+            mapper.update(entityClass, entity.toUpdateRow(), nullItems, args, HashMap(), builder)
         } catch (e: Exception) {
             e.printStackTrace()
             false
@@ -143,6 +153,7 @@ abstract class SAbstractMybatisDao<ENTITY: Any>(entityClazz: Class<ENTITY>) : SA
      * 根据条件查询记录
      *
      * @param args        查询条件
+     *
      * @return 查询构造器
      */
     override fun select(args: List<SFilter>): SQueryBuilder<ENTITY> {
@@ -171,6 +182,7 @@ abstract class SAbstractMybatisDao<ENTITY: Any>(entityClazz: Class<ENTITY>) : SA
      * 执行查询操作
      *
      * @param builder     查询查询构造器
+     *
      * @return 查询到的记录
      */
     override fun execQuery(builder: SQueryBuilder<ENTITY>): ArrayList<ENTITY> {
@@ -190,6 +202,7 @@ abstract class SAbstractMybatisDao<ENTITY: Any>(entityClazz: Class<ENTITY>) : SA
      * 执行统计个数操作
      *
      * @param builder     查询查询构造器
+     *
      * @return 查询到的记录
      */
     override fun execCount(builder: SQueryBuilder<ENTITY>): Long {
@@ -211,6 +224,7 @@ abstract class SAbstractMybatisDao<ENTITY: Any>(entityClazz: Class<ENTITY>) : SA
      * @param self        自身级联
      * @param filter      附加过滤条件
      * @param idList      对象 ID 列表
+     *
      * @return 关系列表
      */
     override fun relationQuery(table: String, id1: String, id2: String, self: Boolean, filter: String, idList: ArrayList<Any>): ArrayList<HashMap<String, Any>> {

+ 2 - 2
persagy-kotlin-mybatis/src/main/kotlin/com/persagy/mybatis/SSqlProvider.kt

@@ -65,8 +65,8 @@ open class SSqlProvider {
      */
     @Suppress("UNCHECKED_CAST")
     open fun replace(argsMap: Map<String, Any?>): String {
-        val insertSql = insert(argsMap)
-        return driver.replace(argsMap, insertSql)
+//        val insertSql = insert(argsMap)
+        return driver.replace(argsMap)
     }
 
     /**

+ 3 - 2
persagy-kotlin-mysql/src/main/kotlin/com/persagy/mysql/SMySqlDriver.kt

@@ -89,10 +89,11 @@ class SMySqlDriver : SAbstractDriver() {
      * 在数据库中替换实体
      *
      * @param argsMap         注入参数
-     * @param insertSql       插入 SQL 语句
+     *
      * @return 替换 SQL 语句
      */
-    override fun replace(argsMap: Map<String, Any?>, insertSql: String): String {
+    override fun replace(argsMap: Map<String, Any?>): String {
+        val insertSql = ""
         val sql = insertSql.replace("INSERT INTO", "REPLACE INTO")
         logger.debug("REPLACE SQL= $sql")
         return sql

+ 74 - 8
persagy-kotlin-postgresql/src/main/kotlin/com/persagy/postgresql/SPostgreSqlDriver.kt

@@ -29,8 +29,7 @@ package com.persagy.postgresql
 import com.persagy.base.extensions.isBaseType
 import com.persagy.base.extensions.toJson
 import com.persagy.base.extensions.toJsonAll
-import com.persagy.database.SAbstractFunction
-import com.persagy.database.SFilter
+import com.persagy.database.*
 import com.persagy.database.enums.SDatabaseType
 import com.persagy.database.enums.SOps
 import com.persagy.mybatis.SAbstractDriver
@@ -59,11 +58,19 @@ class SPostgreSqlDriver : SAbstractDriver() {
      */
     @Suppress("UNCHECKED_CAST")
     override fun insert(argsMap: Map<String, Any?>): String {
+        val builder = argsMap["builder"] as SInsetBuilder<*>
         val entityClass = argsMap["entityClass"] as Class<*>
         val entity = argsMap["entity"] as HashMap<String, Any?>
         val sql = object: SQL() {
             init {
-                INSERT_INTO(SSqlProvider.driver.tableName(entityClass))
+
+                /** 如果查询构建器朱指定了表名 */
+                if (builder!=null&&!builder.tableName.isNullOrEmpty()) {
+                    INSERT_INTO(builder.tableName!!)
+                } else {
+                    INSERT_INTO(SSqlProvider.driver.tableName(entityClass))
+                }
+
                 for ((key, value) in entity) {
                     if (value != null) {
                         if (value is Map<*,*>) {
@@ -94,12 +101,13 @@ class SPostgreSqlDriver : SAbstractDriver() {
      * 在数据库中替换实体
      *
      * @param argsMap         注入参数
-     * @param insertSql       插入 SQL 语句
+     *
      * @return 替换 SQL 语句
      */
     @Suppress("UNCHECKED_CAST")
-    override fun replace(argsMap: Map<String, Any?>, insertSql: String): String {
+    override fun replace(argsMap: Map<String, Any?>): String {
         val sql: String
+        val builder = argsMap["builder"] as SReplaceBuilder<*>
         val entity = argsMap["entity"] as Map<String, Any?>
         val keyColumnList = argsMap["keyColumnList"] as ArrayList<String>
 
@@ -141,7 +149,7 @@ class SPostgreSqlDriver : SAbstractDriver() {
             confict.append("\"$it\"")
         }
 
-        sql = "$insertSql ON conflict ( $confict ) DO UPDATE SET $upSqlBuilder"
+        sql = "${replaceInsert(argsMap)} ON conflict ( $confict ) DO UPDATE SET $upSqlBuilder"
         logger.debug("REPLACE SQL= $sql")
         return sql
     }
@@ -154,6 +162,7 @@ class SPostgreSqlDriver : SAbstractDriver() {
      */
     @Suppress("UNCHECKED_CAST")
     override fun delete(argsMap: Map<String, Any?>): String {
+        val builder = argsMap["builder"] as SDeleteBuilder<*>
         val entityClass = argsMap["entityClass"] as Class<*>
         /** 从入参中获得过虑条件 */
         val filterArgs = argsMap["filterArgs"] as List<SFilter>
@@ -163,7 +172,12 @@ class SPostgreSqlDriver : SAbstractDriver() {
 
         val sql = object: SQL() {
             init {
-                DELETE_FROM(SSqlProvider.driver.tableName(entityClass))
+                /** 如果查询构建器朱指定了表名 */
+                if (builder!=null&&!builder.tableName.isNullOrEmpty()) {
+                    DELETE_FROM(builder.tableName!!)
+                } else {
+                    DELETE_FROM(SSqlProvider.driver.tableName(entityClass))
+                }
                 if (clause.isNotEmpty()) {
                     WHERE(clause)
                 }
@@ -182,10 +196,15 @@ class SPostgreSqlDriver : SAbstractDriver() {
      */
     @Suppress("UNCHECKED_CAST")
     override fun deleteAll(argsMap: Map<String, Any?>): String {
+        val builder = argsMap["builder"] as SDeleteBuilder<*>?
         val entityClass = argsMap["entityClass"] as Class<*>
         val sql = object: SQL() {
             init {
-                DELETE_FROM(SSqlProvider.driver.tableName(entityClass))
+                if (builder!=null&&!builder.tableName.isNullOrEmpty()) {
+                    DELETE_FROM(builder.tableName!!)
+                } else {
+                    DELETE_FROM(SSqlProvider.driver.tableName(entityClass))
+                }
             }
         }.toString()
 
@@ -438,4 +457,51 @@ class SPostgreSqlDriver : SAbstractDriver() {
         return "COALESCE(\"$name\", '{}') || '${value.toJsonAll().replace("'", "''")}'"
     }
 
+    /**
+     * 在数据库中替换实体-生成replace语句部分插入sql语句
+     *
+     * @param argsMap         注入参数
+     *
+     * @return 替换 SQL 语句
+     */
+    @Suppress("UNCHECKED_CAST")
+    private fun replaceInsert(argsMap: Map<String, Any?>): String {
+        val builder = argsMap["builder"] as SReplaceBuilder<*>?
+        val entityClass = argsMap["entityClass"] as Class<*>
+        val entity = argsMap["entity"] as HashMap<String, Any?>
+        val sql = object : SQL() {
+            init {
+
+                /** 如果查询构建器朱指定了表名 */
+                if (builder!=null&&!builder.tableName.isNullOrEmpty()) {
+                    INSERT_INTO(builder.tableName!!)
+                } else {
+                    INSERT_INTO(SSqlProvider.driver.tableName(entityClass))
+                }
+
+                for ((key, value) in entity) {
+                    if (value != null) {
+                        if (value is Map<*, *>) {
+                            VALUES(SSqlProvider.driver.escName(key), "'${value.toJsonAll().replace("'", "''")}'")
+                        } else if (value is List<*>) {
+                            VALUES(SSqlProvider.driver.escName(key), "'${value.toJsonAll().replace("'", "''")}'")
+                        } else if (value::class.java.isPrimitive) {
+                            VALUES(SSqlProvider.driver.escName(key), "'${value.toJsonAll().replace("'", "''")}'")
+                        } else {
+                            VALUES(SSqlProvider.driver.escName(key), SSqlProvider.driver.entityValue(entity, key))
+                        }
+//                        if (value::class.java.isPrimitive) {
+//                            VALUES(driver.escName(key), driver.entityValue(entity, key))
+//                        } else {
+//                            VALUES(driver.escName(key), "'${value.toJsonAll()}'")
+//                        }
+                    }
+                }
+            }
+        }.toString()
+
+        logger.debug("INSERT SQL= $sql")
+
+        return sql
+    }
 }