add
wangpengfei
2023-07-31 309001358628a493208b6130c3b6088e5749a8d7
add

add client assign
4个文件已添加
9个文件已修改
251 ■■■■■ 已修改文件
api/v1/assign.go 49 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
api/v1/index.go 2 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
docs/docs.go 44 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
docs/swagger.json 44 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
docs/swagger.yaml 28 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
model/request/assign.go 7 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
model/user.go 5 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
pkg/ecode/code.go 5 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
router/assign.go 16 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
router/index.go 2 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
service/assign.go 25 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
service/client.go 23 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
service/index.go 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
api/v1/assign.go
New file
@@ -0,0 +1,49 @@
package v1
import (
    "aps_crm/model/request"
    "aps_crm/pkg/contextx"
    "aps_crm/pkg/ecode"
    "github.com/gin-gonic/gin"
)
type AssignApi struct{}
// Assign
//
//    @Tags        Assign
//    @Summary    审核
//    @Produce    application/json
//    @Param        object    body        request.Assign true    "查询参数"
//    @Success    200        {object}    contextx.Response{}
//    @Router        /api/assign/assign [post]
func (au *AssignApi) Assign(c *gin.Context) {
    var params request.Assign
    ctx, ok := contextx.NewContext(c, &params)
    if !ok {
        return
    }
    if params.MemberId == 0 {
        ctx.Fail(ecode.AssignWrongMemberId)
        return
    }
    if params.Id == 0 {
        ctx.Fail(ecode.AssignWrongId)
        return
    }
    if params.Type == "" {
        ctx.Fail(ecode.AssignWrongModelType)
        return
    }
    errCode := assignService.Assign(params.MemberId, params.Id, params.Type)
    if errCode != ecode.OK {
        ctx.Fail(errCode)
        return
    }
    ctx.Ok()
}
api/v1/index.go
@@ -64,6 +64,7 @@
    DepartmentApi
    VettingApi
    SatisfactionApi
    AssignApi
}
var ApiGroup = new(Group)
@@ -128,4 +129,5 @@
   repositoryService    = service.ServiceGroup.RepositoryService
   quotationStatusService    = service.ServiceGroup.QuotationStatusService
   currencyService    = service.ServiceGroup.CurrencyService
    assignService                = service.ServiceGroup.AssignService
)
docs/docs.go
@@ -135,6 +135,36 @@
                }
            }
        },
        "/api/assign/assign": {
            "post": {
                "produces": [
                    "application/json"
                ],
                "tags": [
                    "Assign"
                ],
                "summary": "审核",
                "parameters": [
                    {
                        "description": "查询参数",
                        "name": "object",
                        "in": "body",
                        "required": true,
                        "schema": {
                            "$ref": "#/definitions/request.Assign"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK",
                        "schema": {
                            "$ref": "#/definitions/contextx.Response"
                        }
                    }
                }
            }
        },
        "/api/authority/add": {
            "post": {
                "security": [
@@ -9754,6 +9784,20 @@
                }
            }
        },
        "request.Assign": {
            "type": "object",
            "properties": {
                "id": {
                    "type": "integer"
                },
                "member_id": {
                    "type": "integer"
                },
                "type": {
                    "type": "string"
                }
            }
        },
        "request.CasbinInfo": {
            "type": "object",
            "properties": {
docs/swagger.json
@@ -123,6 +123,36 @@
                }
            }
        },
        "/api/assign/assign": {
            "post": {
                "produces": [
                    "application/json"
                ],
                "tags": [
                    "Assign"
                ],
                "summary": "审核",
                "parameters": [
                    {
                        "description": "查询参数",
                        "name": "object",
                        "in": "body",
                        "required": true,
                        "schema": {
                            "$ref": "#/definitions/request.Assign"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK",
                        "schema": {
                            "$ref": "#/definitions/contextx.Response"
                        }
                    }
                }
            }
        },
        "/api/authority/add": {
            "post": {
                "security": [
@@ -9742,6 +9772,20 @@
                }
            }
        },
        "request.Assign": {
            "type": "object",
            "properties": {
                "id": {
                    "type": "integer"
                },
                "member_id": {
                    "type": "integer"
                },
                "type": {
                    "type": "string"
                }
            }
        },
        "request.CasbinInfo": {
            "type": "object",
            "properties": {
docs/swagger.yaml
@@ -1801,6 +1801,15 @@
    - vettingId
    - vettingType
    type: object
  request.Assign:
    properties:
      id:
        type: integer
      member_id:
        type: integer
      type:
        type: string
    type: object
  request.CasbinInfo:
    properties:
      method:
@@ -4141,6 +4150,25 @@
      summary: 更新账户
      tags:
      - AccountId
  /api/assign/assign:
    post:
      parameters:
      - description: 查询参数
        in: body
        name: object
        required: true
        schema:
          $ref: '#/definitions/request.Assign'
      produces:
      - application/json
      responses:
        "200":
          description: OK
          schema:
            $ref: '#/definitions/contextx.Response'
      summary: 审核
      tags:
      - Assign
  /api/authority/add:
    post:
      consumes:
model/request/assign.go
New file
@@ -0,0 +1,7 @@
package request
type Assign struct {
    MemberId int    `json:"member_id"`
    Type     string `json:"type"`
    Id       int    `json:"id"`
}
model/user.go
@@ -70,6 +70,11 @@
    return slf
}
func (slf *UserSearch) SetUserId(userId int) *UserSearch {
    slf.ID = userId
    return slf
}
func (slf *UserSearch) SetUserName(username string) *UserSearch {
    slf.Username = username
    return slf
pkg/ecode/code.go
@@ -383,4 +383,9 @@
    CurrencySetErr    = 5600004 // 设置币种失败
    CurrencyUpdateErr = 5600005 // 更新币种失败
    AssignErr            = 5700001 // 分配失败
    AssignWrongMemberId  = 5700002 // 分配失败,分配人为空
    AssignWrongId        = 5700003 // 分配失败,分配对象为空
    AssignWrongModelType = 5700004 // 分配失败,分配对象类型为空
)
router/assign.go
New file
@@ -0,0 +1,16 @@
package router
import (
    v1 "aps_crm/api/v1"
    "github.com/gin-gonic/gin"
)
type AssignRouter struct{}
func (a *AssignRouter) InitAssignRouter(router *gin.RouterGroup) {
    assignRouter := router.Group("assign")
    assignApi := v1.ApiGroup.AssignApi
    {
        assignRouter.POST("assign", assignApi.Assign) // 分配
    }
}
router/index.go
@@ -69,6 +69,7 @@
    DataRouter
    DepartmentRouter
    SatisfactionRouter
    AssignRouter
}
func InitRouter() *gin.Engine {
@@ -157,6 +158,7 @@
        routerGroup.InitRepositoryRouter(PrivateGroup)
        routerGroup.InitQuotationStatusRouter(PrivateGroup)
        routerGroup.InitCurrencyRouter(PrivateGroup)
        routerGroup.InitAssignRouter(PrivateGroup)
    }
    return Router
}
service/assign.go
New file
@@ -0,0 +1,25 @@
package service
import "aps_crm/pkg/ecode"
type AssignService struct{}
type Assign interface {
    Assign(id int) error
}
func (AssignService) Assign(memberId, id int, modelType string) int {
    var errCode int
    switch modelType {
    case "client":
        errCode = ClientService{}.Assign(id, memberId)
    default:
        errCode = ecode.AssignWrongModelType
    }
    if errCode != ecode.OK {
        return errCode
    }
    return ecode.OK
}
service/client.go
@@ -64,3 +64,26 @@
    }
    return contacts, total, ecode.OK
}
func (ClientService) Assign(id, memberId int) int {
    // check member exist
    _, err := model.NewUserSearch(nil).SetUserId(memberId).First()
    if err != nil {
        return ecode.UserNotExist
    }
    // check client exist
    errCode := CheckClientExist(id)
    if errCode != ecode.OK {
        return errCode
    }
    // assign client
    err = model.NewClientSearch(nil).SetId(id).UpdateByMap(map[string]interface{}{
        "member_id": memberId,
    })
    if err != nil {
        return ecode.AssignErr
    }
    return ecode.OK
}
service/index.go
@@ -60,6 +60,7 @@
    RepositoryService
    QuotationStatusService
    CurrencyService
    AssignService
}
var ServiceGroup = new(Group)