Browse Source

解决实体类没有设置主键会删除表里面所有数据

zhangweixin 4 years ago
parent
commit
765e4f52c7

+ 1 - 1
README.md

@@ -1,4 +1,4 @@
-# saga-service
+# persagy-service
 
 # 标准接口
 ## 查询接口

+ 3 - 3
gradle.properties

@@ -17,7 +17,7 @@
 #          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) 2016-2020.  博锐尚格科技股份有限公司
+#      .&888888I                                          Copyright (c) 2016-2020.  \u535A\u9510\u5C1A\u683C\u79D1\u6280\u80A1\u4EFD\u6709\u9650\u516C\u53F8
 #        ~8888'
 #        .!88~                                                                     All rights reserved.
 #
@@ -26,7 +26,7 @@
 
 PERSAGY_URL = http://www.persagy.com
 PERSAGY_KOTLIN_VERSION = 1.4.112
-PERSAGY_SERVICE_VERSION = 1.4.147
+PERSAGY_SERVICE_VERSION = 1.4.153
 
 MAVEN_REPO_PUBLIC_URL = http://dev.dp.sagacloud.cn:8082/repository/maven-public/
 MAVEN_REPO_RELEASE_URL = http://dev.dp.sagacloud.cn:8082/repository/maven-releases/
@@ -70,7 +70,7 @@ TESTNG_VERSION = 7.0.0
 # https://mvnrepository.com/artifact/org.hibernate.validator/hibernate-validator
 VALIDATOR_VERSION = 6.1.0.Final
 # https://mvnrepository.com/artifact/com.google.zxing/core
-# ������
+# \uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD
 ZXING_VERSION = 3.2.1
 
 # https://repo.spring.io/milestone

+ 7 - 3
persagy-service-base/src/main/kotlin/com/persagy/service/SObjectService.kt

@@ -101,13 +101,17 @@ open class SObjectService<ENTITY: Any>
      * @return  删除结果应答信息
      */
     fun deleteByKeysList(@RequestBody entityList: ArrayList<ENTITY>, withFilterList: ArrayList<SFilter>? = null): SBaseResponse {
-        return try {
+         try {
             for (entity in entityList) {
                 val filterList = ArrayList<SFilter>()
                 entity.keyMap().forEach {
                     filterList.add(SFilter.eq(it.key, it.value))
                 }
 
+                if (filterList.isNullOrEmpty()){
+                    return SBaseResponse(SResponseType.failure, "实体类缺少主键定义")
+                }
+
                 if (withFilterList != null) {
                     filterList.addAll(withFilterList)
                 }
@@ -120,10 +124,10 @@ open class SObjectService<ENTITY: Any>
                 }
             }
             onDeleteSuccess(entityList)
-            SBaseResponse(SResponseType.success)
+             return SBaseResponse(SResponseType.success)
         } catch (e: Exception) {
             e.printStackTrace()
-            SBaseResponse(SResponseType.failure, e.message!!)
+             return SBaseResponse(SResponseType.failure, e.message!!)
         }
     } // Fun deleteByKeysList()
 

+ 29 - 15
persagy-service-mysql/src/main/kotlin/com/persagy/service/postgresql/controllers/SDatabaseDocController.kt

@@ -24,17 +24,13 @@
  * *********************************************************************************************************************
  */
 
-package com.persagy.service.postgresql.controllers
+package com.persagy.service.mysql.controllers
 
 import com.persagy.service.SObjectService
-import com.persagy.service.models.requests.SQueryRequest
-import com.persagy.service.models.responses.SQueryResponse
-import com.persagy.service.postgresql.models.SColumn
-import com.persagy.service.postgresql.models.STable
+import com.persagy.service.mysql.models.SColumn
+import com.persagy.service.mysql.models.STable
 import io.swagger.annotations.Api
-import io.swagger.annotations.ApiImplicitParam
 import io.swagger.annotations.ApiOperation
-import org.springframework.beans.factory.annotation.Autowired
 import org.springframework.web.bind.annotation.*
 
 /**
@@ -73,16 +69,34 @@ class SDatabaseDocController {
      */
     @ApiOperation(value="查询字段信息", notes="")
     @RequestMapping(value = ["/column-list"], method = [RequestMethod.GET, RequestMethod.POST])
-    fun columnList(schema: String, table: String): List<Any> {
+    fun columnList(schema: String, table: String): ArrayList<SColumn> {
         val builder = columnService.select("schemaName" to schema, "tableName" to table)
-//        builder.tableName =
-//                "(SELECT *,\n" +
-//                "    (SELECT \"description\" FROM \"pg_description\"\n" +
-//                "    JOIN \"pg_class\" ON \"pg_description\".\"objoid\" = \"pg_class\".\"oid\"\n" +
-//                "    JOIN \"pg_namespace\" ON \"pg_class\".\"relnamespace\" = \"pg_namespace\".\"oid\"\n" +
-//                "WHERE \"relname\" = \"t\".\"table_name\" and \"nspname\"= \"t\".\"table_schema\" and \"objsubid\" = \"t\".\"ordinal_position\")\n" +
-//                "FROM \"information_schema\".\"columns\" t) ct"
+        builder.tableName =
+                "(SELECT *,\n" +
+                "    (SELECT \"description\" FROM \"pg_description\"\n" +
+                "    JOIN \"pg_class\" ON \"pg_description\".\"objoid\" = \"pg_class\".\"oid\"\n" +
+                "    JOIN \"pg_namespace\" ON \"pg_class\".\"relnamespace\" = \"pg_namespace\".\"oid\"\n" +
+                "WHERE \"relname\" = \"t\".\"table_name\" and \"nspname\"= \"t\".\"table_schema\" and \"objsubid\" = \"t\".\"ordinal_position\")\n" +
+                "FROM \"information_schema\".\"columns\" t) ct"
         return builder.exec()
         //return mapper.columnList(schema, table)
     } // Function columnList()
+
+
+    /**
+     *  查询表、字段信息
+     */
+    @ApiOperation(value="查询字段信息", notes="")
+    @RequestMapping(value = ["/table-info"], method = [RequestMethod.GET, RequestMethod.POST])
+    fun tableInfo(schema: String, table: String): STable {
+        val sTable = STable()
+        sTable.schemaName = schema
+        sTable.tableName = table
+        sTable.columnList = columnList(schema, table)
+        return sTable
+    } // Function
+
+
+
+
 } // Class SDatabaseDocController

+ 1 - 1
persagy-service-mysql/src/main/kotlin/com/persagy/service/postgresql/models/SColumn.kt

@@ -24,7 +24,7 @@
  * *********************************************************************************************************************
  */
 
-package com.persagy.service.postgresql.models
+package com.persagy.service.mysql.models
 
 import io.swagger.annotations.ApiModel
 import io.swagger.annotations.ApiModelProperty

+ 5 - 1
persagy-service-mysql/src/main/kotlin/com/persagy/service/postgresql/models/STable.kt

@@ -24,7 +24,7 @@
  * *********************************************************************************************************************
  */
 
-package com.persagy.service.postgresql.models
+package com.persagy.service.mysql.models
 
 import io.swagger.annotations.ApiModel
 import io.swagger.annotations.ApiModelProperty
@@ -53,4 +53,8 @@ open class STable {
     @ApiModelProperty(value = "注释")
     @Column(name = "TABLE_COMMENT")
     var description: String? = null
+
+    @ApiModelProperty(value = "字段列表")
+    var columnList: ArrayList<SColumn>? = null
+
 } // Class STable

+ 19 - 5
persagy-service-postgresql/src/main/kotlin/com/persagy/service/postgresql/controllers/SDatabaseDocController.kt

@@ -27,15 +27,12 @@
 package com.persagy.service.postgresql.controllers
 
 import com.persagy.service.SObjectService
-import com.persagy.service.models.requests.SQueryRequest
-import com.persagy.service.models.responses.SQueryResponse
 import com.persagy.service.postgresql.models.SColumn
 import com.persagy.service.postgresql.models.STable
 import io.swagger.annotations.Api
-import io.swagger.annotations.ApiImplicitParam
 import io.swagger.annotations.ApiOperation
-import org.springframework.beans.factory.annotation.Autowired
 import org.springframework.web.bind.annotation.*
+import springfox.documentation.annotations.ApiIgnore
 
 /**
  * 数据库设计接口
@@ -43,6 +40,7 @@ import org.springframework.web.bind.annotation.*
  * @author  庞利祥(sybotan@126.com)
  */
 @Api(tags= ["数据库设计接口"])
+@ApiIgnore
 @RestController
 @RequestMapping("/--database-doc--/")
 class SDatabaseDocController {
@@ -73,7 +71,7 @@ class SDatabaseDocController {
      */
     @ApiOperation(value="查询字段信息", notes="")
     @RequestMapping(value = ["/column-list"], method = [RequestMethod.GET, RequestMethod.POST])
-    fun columnList(schema: String, table: String): List<Any> {
+    fun columnList(schema: String, table: String): ArrayList<SColumn> {
         val builder = columnService.select("schemaName" to schema, "tableName" to table)
         builder.tableName =
                 "(SELECT *,\n" +
@@ -85,4 +83,20 @@ class SDatabaseDocController {
         return builder.exec()
         //return mapper.columnList(schema, table)
     } // Function columnList()
+
+    /**
+     * 查询表、字段信息
+     */
+    @ApiOperation(value="查询表、字段信息", notes="")
+    @RequestMapping(value = ["/table-info"], method = [RequestMethod.GET, RequestMethod.POST])
+    fun tableInfo(schema: String, table: String): STable{
+        val sTable = STable()
+        sTable.schemaName = schema
+        sTable.tableName = table
+        sTable.columnList = columnList(schema,table)
+        return sTable
+    } // Function tableInfo()
+
+
+
 } // Class SDatabaseDocController

+ 5 - 0
persagy-service-postgresql/src/main/kotlin/com/persagy/service/postgresql/models/STable.kt

@@ -53,4 +53,9 @@ open class STable {
     @ApiModelProperty(value = "注释")
     @Column(name = "description")
     var description: String? = null
+
+    /** 注释 */
+    @ApiModelProperty(value = "注释")
+    var columnList : ArrayList<SColumn>? = null
+
 } // Class STable