From 842a1a88687dfe3893cc765b3886055f0535deb3 Mon Sep 17 00:00:00 2001
From: wangpengfei <274878379@qq.com>
Date: 星期二, 01 八月 2023 15:29:56 +0800
Subject: [PATCH] fix

---
 api/v1/client.go        |   11 ++---
 service/client.go       |   23 ++++-------
 model/client.go         |    4 ++
 model/request/client.go |    4 ++
 docs/swagger.yaml       |   18 ++++++--
 router/client.go        |    2 
 docs/docs.go            |   25 +++++++++---
 docs/swagger.json       |   25 +++++++++---
 8 files changed, 74 insertions(+), 38 deletions(-)

diff --git a/api/v1/client.go b/api/v1/client.go
index ad91842..3be607b 100644
--- a/api/v1/client.go
+++ b/api/v1/client.go
@@ -7,7 +7,6 @@
 	"aps_crm/pkg/contextx"
 	"aps_crm/pkg/ecode"
 	"github.com/gin-gonic/gin"
-	"strconv"
 )
 
 type ClientApi struct{}
@@ -120,17 +119,17 @@
 //	@Tags		Client
 //	@Summary	鍒犻櫎瀹㈡埛
 //	@Produce	application/json
-//	@Param		id	path		int	true	"瀹㈡埛ID"
+//	@Param		object	body		request.DeleteClient true	"鏌ヨ鍙傛暟"
 //	@Success	200	{object}	contextx.Response{}
-//	@Router		/api/client/delete/{id} [delete]
+//	@Router		/api/client/delete [delete]
 func (cli *ClientApi) Delete(c *gin.Context) {
-	ctx, ok := contextx.NewContext(c, nil)
+	var params request.DeleteClient
+	ctx, ok := contextx.NewContext(c, &params)
 	if !ok {
 		return
 	}
 
-	id, _ := strconv.Atoi(c.Param("id"))
-	errCode := clientService.DeleteClient(id)
+	errCode := clientService.DeleteClient(params.Ids)
 	if errCode != ecode.OK {
 		ctx.Fail(errCode)
 		return
diff --git a/docs/docs.go b/docs/docs.go
index e705bbf..ba26073 100644
--- a/docs/docs.go
+++ b/docs/docs.go
@@ -501,7 +501,7 @@
                 }
             }
         },
-        "/api/client/delete/{id}": {
+        "/api/client/delete": {
             "delete": {
                 "produces": [
                     "application/json"
@@ -512,11 +512,13 @@
                 "summary": "鍒犻櫎瀹㈡埛",
                 "parameters": [
                     {
-                        "type": "integer",
-                        "description": "瀹㈡埛ID",
-                        "name": "id",
-                        "in": "path",
-                        "required": true
+                        "description": "鏌ヨ鍙傛暟",
+                        "name": "object",
+                        "in": "body",
+                        "required": true,
+                        "schema": {
+                            "$ref": "#/definitions/request.DeleteClient"
+                        }
                     }
                 ],
                 "responses": {
@@ -9919,6 +9921,17 @@
                 }
             }
         },
+        "request.DeleteClient": {
+            "type": "object",
+            "properties": {
+                "ids": {
+                    "type": "array",
+                    "items": {
+                        "type": "integer"
+                    }
+                }
+            }
+        },
         "request.DeleteCountry": {
             "type": "object",
             "properties": {
diff --git a/docs/swagger.json b/docs/swagger.json
index 4164e14..2da771e 100644
--- a/docs/swagger.json
+++ b/docs/swagger.json
@@ -489,7 +489,7 @@
                 }
             }
         },
-        "/api/client/delete/{id}": {
+        "/api/client/delete": {
             "delete": {
                 "produces": [
                     "application/json"
@@ -500,11 +500,13 @@
                 "summary": "鍒犻櫎瀹㈡埛",
                 "parameters": [
                     {
-                        "type": "integer",
-                        "description": "瀹㈡埛ID",
-                        "name": "id",
-                        "in": "path",
-                        "required": true
+                        "description": "鏌ヨ鍙傛暟",
+                        "name": "object",
+                        "in": "body",
+                        "required": true,
+                        "schema": {
+                            "$ref": "#/definitions/request.DeleteClient"
+                        }
                     }
                 ],
                 "responses": {
@@ -9907,6 +9909,17 @@
                 }
             }
         },
+        "request.DeleteClient": {
+            "type": "object",
+            "properties": {
+                "ids": {
+                    "type": "array",
+                    "items": {
+                        "type": "integer"
+                    }
+                }
+            }
+        },
         "request.DeleteCountry": {
             "type": "object",
             "properties": {
diff --git a/docs/swagger.yaml b/docs/swagger.yaml
index 15c3026..26faa50 100644
--- a/docs/swagger.yaml
+++ b/docs/swagger.yaml
@@ -1898,6 +1898,13 @@
         description: 寰俊鍙�
         type: string
     type: object
+  request.DeleteClient:
+    properties:
+      ids:
+        items:
+          type: integer
+        type: array
+    type: object
   request.DeleteCountry:
     properties:
       id:
@@ -4372,14 +4379,15 @@
       summary: 娣诲姞瀹㈡埛
       tags:
       - Client
-  /api/client/delete/{id}:
+  /api/client/delete:
     delete:
       parameters:
-      - description: 瀹㈡埛ID
-        in: path
-        name: id
+      - description: 鏌ヨ鍙傛暟
+        in: body
+        name: object
         required: true
-        type: integer
+        schema:
+          $ref: '#/definitions/request.DeleteClient'
       produces:
       - application/json
       responses:
diff --git a/model/client.go b/model/client.go
index 8c694d8..d58a5c8 100644
--- a/model/client.go
+++ b/model/client.go
@@ -143,3 +143,7 @@
 	slf.OrderBy = order
 	return slf
 }
+func (slf *ClientSearch) SetIds(ids []int) *ClientSearch {
+	slf.Orm = slf.Orm.Where("id in (?)", ids)
+	return slf
+}
diff --git a/model/request/client.go b/model/request/client.go
index e27bb01..527f503 100644
--- a/model/request/client.go
+++ b/model/request/client.go
@@ -31,3 +31,7 @@
 	PageInfo
 	Keyword string `json:"keyword"`
 }
+
+type DeleteClient struct {
+	Ids []int `json:"ids"`
+}
diff --git a/router/client.go b/router/client.go
index 1302ef8..3563b8d 100644
--- a/router/client.go
+++ b/router/client.go
@@ -12,7 +12,7 @@
 	clientApi := v1.ApiGroup.ClientApi
 	{
 		clientRouter.POST("add", clientApi.Add)             // 娣诲姞瀹㈡埛
-		clientRouter.DELETE("delete/:id", clientApi.Delete) // 鍒犻櫎瀹㈡埛
+		clientRouter.DELETE("delete", clientApi.Delete)     // 鍒犻櫎瀹㈡埛
 		clientRouter.PUT("update", clientApi.Update)        // 鏇存柊瀹㈡埛
 		clientRouter.POST("list", clientApi.List)            // 鑾峰彇瀹㈡埛鍒楄〃
 	}
diff --git a/service/client.go b/service/client.go
index 79f2c7e..49c8bb7 100644
--- a/service/client.go
+++ b/service/client.go
@@ -15,20 +15,6 @@
 	return ecode.OK
 }
 
-func (ClientService) DeleteClient(id int) int {
-	// check client exist
-	_, err := model.NewClientSearch(nil).SetId(id).First()
-	if err != nil {
-		return ecode.ClientNotExist
-	}
-
-	// delete client
-	err = model.NewClientSearch(nil).SetId(id).Delete()
-	if err != nil {
-		return ecode.ClientDeleteErr
-	}
-	return ecode.OK
-}
 
 // CheckClientExist check client exist
 func CheckClientExist(id int) int {
@@ -82,3 +68,12 @@
 
 	return ecode.OK
 }
+
+func (ClientService) DeleteClient (ids []int) int {
+	// delete client
+	err := model.NewClientSearch(nil).SetIds(ids).Delete()
+	if err != nil {
+		return ecode.ClientDeleteErr
+	}
+	return ecode.OK
+}
\ No newline at end of file

--
Gitblit v1.8.0