fix
wangpengfei
2023-08-01 842a1a88687dfe3893cc765b3886055f0535deb3
fix

add batch delete function to client module
8个文件已修改
112 ■■■■■ 已修改文件
api/v1/client.go 11 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
docs/docs.go 25 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
docs/swagger.json 25 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
docs/swagger.yaml 18 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
model/client.go 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
model/request/client.go 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
router/client.go 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
service/client.go 23 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
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
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": {
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": {
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:
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
}
model/request/client.go
@@ -31,3 +31,7 @@
    PageInfo
    Keyword string `json:"keyword"`
}
type DeleteClient struct {
    Ids []int `json:"ids"`
}
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)            // 获取客户列表
    }
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
}