fix
wangpengfei
2023-08-15 dd39909b3d8172856313ea7b2e19d1d7a039a582
fix
8个文件已修改
156 ■■■■■ 已修改文件
api/v1/client.go 24 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
docs/docs.go 38 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
docs/swagger.json 38 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
docs/swagger.yaml 24 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
model/client.go 12 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
model/request/client.go 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
router/client.go 5 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
service/client.go 11 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
api/v1/client.go
@@ -201,3 +201,27 @@
        Count: int(total),
    })
}
// CheckName
//
//    @Tags        Client
//    @Summary    检查客户名称是否重复
//    @Produce    application/json
//    @Param        object    body        request.CheckClientName    true    "参数"
//    @Success    200        {object}    contextx.Response{}
//    @Router        /api/client/checkName [post]
func (cli *ClientApi) CheckName(c *gin.Context) {
    var params request.CheckClientName
    ctx, ok := contextx.NewContext(c, &params)
    if !ok {
        return
    }
    errCode := clientService.CheckName(params.Name)
    if errCode != ecode.OK {
        ctx.Fail(errCode)
        return
    }
    ctx.Ok()
}
docs/docs.go
@@ -664,6 +664,36 @@
                }
            }
        },
        "/api/client/checkName": {
            "post": {
                "produces": [
                    "application/json"
                ],
                "tags": [
                    "Client"
                ],
                "summary": "检查客户名称是否重复",
                "parameters": [
                    {
                        "description": "参数",
                        "name": "object",
                        "in": "body",
                        "required": true,
                        "schema": {
                            "$ref": "#/definitions/request.CheckClientName"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK",
                        "schema": {
                            "$ref": "#/definitions/contextx.Response"
                        }
                    }
                }
            }
        },
        "/api/client/delete": {
            "delete": {
                "produces": [
@@ -14515,6 +14545,14 @@
                }
            }
        },
        "request.CheckClientName": {
            "type": "object",
            "properties": {
                "name": {
                    "type": "string"
                }
            }
        },
        "request.Contact": {
            "type": "object",
            "properties": {
docs/swagger.json
@@ -652,6 +652,36 @@
                }
            }
        },
        "/api/client/checkName": {
            "post": {
                "produces": [
                    "application/json"
                ],
                "tags": [
                    "Client"
                ],
                "summary": "检查客户名称是否重复",
                "parameters": [
                    {
                        "description": "参数",
                        "name": "object",
                        "in": "body",
                        "required": true,
                        "schema": {
                            "$ref": "#/definitions/request.CheckClientName"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK",
                        "schema": {
                            "$ref": "#/definitions/contextx.Response"
                        }
                    }
                }
            }
        },
        "/api/client/delete": {
            "delete": {
                "produces": [
@@ -14503,6 +14533,14 @@
                }
            }
        },
        "request.CheckClientName": {
            "type": "object",
            "properties": {
                "name": {
                    "type": "string"
                }
            }
        },
        "request.Contact": {
            "type": "object",
            "properties": {
docs/swagger.yaml
@@ -3103,6 +3103,11 @@
        description: 用户岗位
        type: string
    type: object
  request.CheckClientName:
    properties:
      name:
        type: string
    type: object
  request.Contact:
    properties:
      birthday:
@@ -6286,6 +6291,25 @@
      summary: 添加客户
      tags:
      - Client
  /api/client/checkName:
    post:
      parameters:
      - description: 参数
        in: body
        name: object
        required: true
        schema:
          $ref: '#/definitions/request.CheckClientName'
      produces:
      - application/json
      responses:
        "200":
          description: OK
          schema:
            $ref: '#/definitions/contextx.Response'
      summary: 检查客户名称是否重复
      tags:
      - Client
  /api/client/delete:
    delete:
      parameters:
model/client.go
@@ -10,7 +10,8 @@
type (
    Client struct {
        Id                int            `json:"id" gorm:"column:id;primaryKey;autoIncrement;not null"`
        Name              string         `json:"name" gorm:"column:name;unique;type:varchar(255);comment:客户名称"`
        Name              string         `json:"name" gorm:"column:name;uniqueIndex:name_isDeleted_idx;type:varchar(255);comment:客户名称"`
        IsDeleted         bool           `json:"-" gorm:"column:is_deleted;uniqueIndex:name_isDeleted_idx;type:tinyint(1);comment:是否删除"`
        Number            string         `json:"number" gorm:"column:number;type:varchar(255);comment:客户编号"`
        ClientStatusId    int            `json:"client_status_id" gorm:"column:client_status_id;type:int(11);comment:客户状态ID"`
        ClientStatus      ClientStatus   `json:"client_status" gorm:"foreignKey:ClientStatusId"`
@@ -59,6 +60,15 @@
    }
}
func (c *Client) BeforeSave(tx *gorm.DB) (err error) {
    if c.DeletedAt.Valid {
        c.IsDeleted = true
    } else {
        c.IsDeleted = false
    }
    return
}
func (slf *ClientSearch) build() *gorm.DB {
    var db = slf.Orm.Model(&Client{})
    if slf.Id != 0 {
model/request/client.go
@@ -36,3 +36,7 @@
type DeleteClient struct {
    Ids []int `json:"ids"`
}
type CheckClientName struct {
    Name string `json:"name"`
}
router/client.go
@@ -14,6 +14,7 @@
        clientRouter.POST("add", clientApi.Add)             // 添加客户
        clientRouter.DELETE("delete", clientApi.Delete)     // 删除客户
        clientRouter.PUT("update", clientApi.Update)        // 更新客户
        clientRouter.POST("list", clientApi.List)            // 获取客户列表
        clientRouter.POST("list", clientApi.List)           // 获取客户列表
        clientRouter.POST("checkName", clientApi.CheckName) // 检查客户名称是否重复
    }
}
}
service/client.go
@@ -4,6 +4,7 @@
    "aps_crm/model"
    "aps_crm/pkg/ecode"
    "aps_crm/pkg/mysqlx"
    "gorm.io/gorm"
)
type ClientService struct{}
@@ -121,3 +122,13 @@
    }
    return ecode.OK
}
func (ClientService) CheckName(name string) int {
    // check client exist
    _, err := model.NewClientSearch(nil).SetName(name).First()
    if err != gorm.ErrRecordNotFound {
        return ecode.ClientExist
    }
    return ecode.OK
}