add
wangpengfei
2023-07-10 a9a16bf0aabf5323a658d79a87473008d2197584
add

status 销售阶段
add, Delete, update, list
5个文件已添加
9个文件已修改
695 ■■■■■ 已修改文件
api/v1/index.go 2 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
api/v1/status.go 112 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
docs/docs.go 147 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
docs/swagger.json 147 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
docs/swagger.yaml 94 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
model/index.go 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
model/request/status.go 14 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
model/response/response.go 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
model/status.go 86 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
pkg/ecode/code.go 7 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
router/index.go 2 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
router/status.go 19 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
service/index.go 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
service/status.go 59 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
api/v1/index.go
@@ -30,6 +30,7 @@
    SaleTypeApi
    RegularCustomersApi
    PossibilityApi
    StatusApi
}
var ApiGroup = new(Group)
@@ -59,4 +60,5 @@
    saleTypeService          = service.ServiceGroup.SaleTypeService
    regularCustomersService  = service.ServiceGroup.RegularCustomersService
    possibilityService       = service.ServiceGroup.PossibilityService
    statusService            = service.ServiceGroup.StatusService
)
api/v1/status.go
New file
@@ -0,0 +1,112 @@
package v1
import (
    "aps_crm/model"
    "aps_crm/model/request"
    "aps_crm/model/response"
    "aps_crm/pkg/contextx"
    "aps_crm/pkg/ecode"
    "github.com/gin-gonic/gin"
    "strconv"
)
type StatusApi struct{}
// Add
//
//    @Tags        Status
//    @Summary    添加状态
//    @Produce    application/json
//    @Param        object    body        request.AddStatus    true    "查询参数"
//    @Success    200        {object}    contextx.Response{}
//    @Router        /api/status/add [post]
func (s *StatusApi) Add(c *gin.Context) {
    var params request.AddStatus
    ctx, ok := contextx.NewContext(c, &params)
    if !ok {
        return
    }
    status := new(model.Status)
    status.Name = params.Name
    errCode := statusService.AddStatus(status)
    if errCode != ecode.OK {
        ctx.Fail(errCode)
        return
    }
    ctx.Ok()
}
// Delete
//
//    @Tags        Status
//    @Summary    删除状态
//    @Produce    application/json
//    @Param        id    path        int    true    "查询参数"
//    @Success    200    {object}    contextx.Response{}
//    @Router        /api/status/delete/{id} [delete]
func (s *StatusApi) Delete(c *gin.Context) {
    ctx, ok := contextx.NewContext(c, nil)
    if !ok {
        return
    }
    id, _ := strconv.Atoi(c.Param("id"))
    errCode := statusService.DeleteStatus(id)
    if errCode != ecode.OK {
        ctx.Fail(errCode)
        return
    }
    ctx.Ok()
}
// Update
//
//    @Tags        Status
//    @Summary    更新状态
//    @Produce    application/json
//    @Param        object    body        request.UpdateStatusList    true    "查询参数"
//    @Success    200        {object}    contextx.Response{}
//    @Router        /api/status/update [put]
func (s *StatusApi) Update(c *gin.Context) {
    var params request.UpdateStatusList
    ctx, ok := contextx.NewContext(c, &params)
    if !ok {
        return
    }
    errCode := statusService.UpdateStatus(params.List)
    if errCode != ecode.OK {
        ctx.Fail(errCode)
        return
    }
    ctx.Ok()
}
// List
//
//    @Tags        Status
//    @Summary    状态列表
//    @Produce    application/json
//    @Success    200    {object}    contextx.Response{}
//    @Router        /api/status/list [get]
func (s *StatusApi) List(c *gin.Context) {
    ctx, ok := contextx.NewContext(c, nil)
    if !ok {
        return
    }
    list, errCode := statusService.GetStatusList()
    if errCode != ecode.OK {
        ctx.Fail(errCode)
        return
    }
    ctx.OkWithDetailed(response.StatusResponse{
        List: list,
    })
}
docs/docs.go
@@ -2818,6 +2818,113 @@
                }
            }
        },
        "/api/status/add": {
            "post": {
                "produces": [
                    "application/json"
                ],
                "tags": [
                    "Status"
                ],
                "summary": "添加状态",
                "parameters": [
                    {
                        "description": "查询参数",
                        "name": "object",
                        "in": "body",
                        "required": true,
                        "schema": {
                            "$ref": "#/definitions/request.AddStatus"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK",
                        "schema": {
                            "$ref": "#/definitions/contextx.Response"
                        }
                    }
                }
            }
        },
        "/api/status/delete/{id}": {
            "delete": {
                "produces": [
                    "application/json"
                ],
                "tags": [
                    "Status"
                ],
                "summary": "删除状态",
                "parameters": [
                    {
                        "type": "integer",
                        "description": "查询参数",
                        "name": "id",
                        "in": "path",
                        "required": true
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK",
                        "schema": {
                            "$ref": "#/definitions/contextx.Response"
                        }
                    }
                }
            }
        },
        "/api/status/list": {
            "get": {
                "produces": [
                    "application/json"
                ],
                "tags": [
                    "Status"
                ],
                "summary": "状态列表",
                "responses": {
                    "200": {
                        "description": "OK",
                        "schema": {
                            "$ref": "#/definitions/contextx.Response"
                        }
                    }
                }
            }
        },
        "/api/status/update": {
            "put": {
                "produces": [
                    "application/json"
                ],
                "tags": [
                    "Status"
                ],
                "summary": "更新状态",
                "parameters": [
                    {
                        "description": "查询参数",
                        "name": "object",
                        "in": "body",
                        "required": true,
                        "schema": {
                            "$ref": "#/definitions/request.UpdateStatusList"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK",
                        "schema": {
                            "$ref": "#/definitions/contextx.Response"
                        }
                    }
                }
            }
        },
        "/api/user/changePassword": {
            "post": {
                "produces": [
@@ -4400,6 +4507,17 @@
                }
            }
        },
        "request.AddStatus": {
            "type": "object",
            "required": [
                "name"
            ],
            "properties": {
                "name": {
                    "type": "string"
                }
            }
        },
        "request.ChangePasswordReq": {
            "type": "object",
            "properties": {
@@ -5476,6 +5594,35 @@
                }
            }
        },
        "request.UpdateStatus": {
            "type": "object",
            "required": [
                "id",
                "name"
            ],
            "properties": {
                "id": {
                    "type": "integer"
                },
                "name": {
                    "type": "string"
                }
            }
        },
        "request.UpdateStatusList": {
            "type": "object",
            "required": [
                "list"
            ],
            "properties": {
                "list": {
                    "type": "array",
                    "items": {
                        "$ref": "#/definitions/request.UpdateStatus"
                    }
                }
            }
        },
        "response.CityResponse": {
            "type": "object",
            "properties": {
docs/swagger.json
@@ -2806,6 +2806,113 @@
                }
            }
        },
        "/api/status/add": {
            "post": {
                "produces": [
                    "application/json"
                ],
                "tags": [
                    "Status"
                ],
                "summary": "添加状态",
                "parameters": [
                    {
                        "description": "查询参数",
                        "name": "object",
                        "in": "body",
                        "required": true,
                        "schema": {
                            "$ref": "#/definitions/request.AddStatus"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK",
                        "schema": {
                            "$ref": "#/definitions/contextx.Response"
                        }
                    }
                }
            }
        },
        "/api/status/delete/{id}": {
            "delete": {
                "produces": [
                    "application/json"
                ],
                "tags": [
                    "Status"
                ],
                "summary": "删除状态",
                "parameters": [
                    {
                        "type": "integer",
                        "description": "查询参数",
                        "name": "id",
                        "in": "path",
                        "required": true
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK",
                        "schema": {
                            "$ref": "#/definitions/contextx.Response"
                        }
                    }
                }
            }
        },
        "/api/status/list": {
            "get": {
                "produces": [
                    "application/json"
                ],
                "tags": [
                    "Status"
                ],
                "summary": "状态列表",
                "responses": {
                    "200": {
                        "description": "OK",
                        "schema": {
                            "$ref": "#/definitions/contextx.Response"
                        }
                    }
                }
            }
        },
        "/api/status/update": {
            "put": {
                "produces": [
                    "application/json"
                ],
                "tags": [
                    "Status"
                ],
                "summary": "更新状态",
                "parameters": [
                    {
                        "description": "查询参数",
                        "name": "object",
                        "in": "body",
                        "required": true,
                        "schema": {
                            "$ref": "#/definitions/request.UpdateStatusList"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK",
                        "schema": {
                            "$ref": "#/definitions/contextx.Response"
                        }
                    }
                }
            }
        },
        "/api/user/changePassword": {
            "post": {
                "produces": [
@@ -4388,6 +4495,17 @@
                }
            }
        },
        "request.AddStatus": {
            "type": "object",
            "required": [
                "name"
            ],
            "properties": {
                "name": {
                    "type": "string"
                }
            }
        },
        "request.ChangePasswordReq": {
            "type": "object",
            "properties": {
@@ -5464,6 +5582,35 @@
                }
            }
        },
        "request.UpdateStatus": {
            "type": "object",
            "required": [
                "id",
                "name"
            ],
            "properties": {
                "id": {
                    "type": "integer"
                },
                "name": {
                    "type": "string"
                }
            }
        },
        "request.UpdateStatusList": {
            "type": "object",
            "required": [
                "list"
            ],
            "properties": {
                "list": {
                    "type": "array",
                    "items": {
                        "$ref": "#/definitions/request.UpdateStatus"
                    }
                }
            }
        },
        "response.CityResponse": {
            "type": "object",
            "properties": {
docs/swagger.yaml
@@ -895,6 +895,13 @@
    required:
    - name
    type: object
  request.AddStatus:
    properties:
      name:
        type: string
    required:
    - name
    type: object
  request.ChangePasswordReq:
    properties:
      newPassword:
@@ -1632,6 +1639,25 @@
        items:
          $ref: '#/definitions/request.UpdateSalesSources'
        type: array
    type: object
  request.UpdateStatus:
    properties:
      id:
        type: integer
      name:
        type: string
    required:
    - id
    - name
    type: object
  request.UpdateStatusList:
    properties:
      list:
        items:
          $ref: '#/definitions/request.UpdateStatus'
        type: array
    required:
    - list
    type: object
  response.CityResponse:
    properties:
@@ -3524,6 +3550,74 @@
      summary: 更新商机来源
      tags:
      - SalesSources
  /api/status/add:
    post:
      parameters:
      - description: 查询参数
        in: body
        name: object
        required: true
        schema:
          $ref: '#/definitions/request.AddStatus'
      produces:
      - application/json
      responses:
        "200":
          description: OK
          schema:
            $ref: '#/definitions/contextx.Response'
      summary: 添加状态
      tags:
      - Status
  /api/status/delete/{id}:
    delete:
      parameters:
      - description: 查询参数
        in: path
        name: id
        required: true
        type: integer
      produces:
      - application/json
      responses:
        "200":
          description: OK
          schema:
            $ref: '#/definitions/contextx.Response'
      summary: 删除状态
      tags:
      - Status
  /api/status/list:
    get:
      produces:
      - application/json
      responses:
        "200":
          description: OK
          schema:
            $ref: '#/definitions/contextx.Response'
      summary: 状态列表
      tags:
      - Status
  /api/status/update:
    put:
      parameters:
      - description: 查询参数
        in: body
        name: object
        required: true
        schema:
          $ref: '#/definitions/request.UpdateStatusList'
      produces:
      - application/json
      responses:
        "200":
          description: OK
          schema:
            $ref: '#/definitions/contextx.Response'
      summary: 更新状态
      tags:
      - Status
  /api/user/changePassword:
    post:
      parameters:
model/index.go
@@ -45,6 +45,7 @@
        SaleType{},
        RegularCustomers{},
        Possibility{},
        Status{},
    )
    return err
}
model/request/status.go
New file
@@ -0,0 +1,14 @@
package request
type AddStatus struct {
    Name string `json:"name" binding:"required"`
}
type UpdateStatus struct {
    Id   int    `json:"id" binding:"required"`
    Name string `json:"name" binding:"required"`
}
type UpdateStatusList struct {
    List []*UpdateStatus `json:"list" binding:"required"`
}
model/response/response.go
@@ -117,4 +117,8 @@
    PossibilityResponse struct {
        List []*model.Possibility `json:"list"`
    }
    StatusResponse struct {
        List []*model.Status `json:"list"`
    }
)
model/status.go
New file
@@ -0,0 +1,86 @@
package model
import (
    "aps_crm/pkg/mysqlx"
    "gorm.io/gorm"
)
type (
    // Status 状态
    Status struct {
        Id   int    `json:"id" gorm:"column:id;primary_key;AUTO_INCREMENT"`
        Name string `json:"name" gorm:"column:name;type:varchar(255);comment:状态名称"`
    }
    // StatusSearch 状态搜索条件
    StatusSearch struct {
        Status
        Orm *gorm.DB
    }
)
func (Status) TableName() string {
    return "status"
}
func NewStatusSearch() *StatusSearch {
    return &StatusSearch{
        Orm: mysqlx.GetDB(),
    }
}
func (slf *StatusSearch) build() *gorm.DB {
    var db = slf.Orm.Model(&Status{})
    if slf.Id != 0 {
        db = db.Where("id = ?", slf.Id)
    }
    if slf.Name != "" {
        db = db.Where("name = ?", slf.Name)
    }
    return db
}
func (slf *StatusSearch) Create(record *Status) error {
    var db = slf.build()
    return db.Create(record).Error
}
func (slf *StatusSearch) Delete() error {
    var db = slf.build()
    return db.Delete(&Status{}).Error
}
func (slf *StatusSearch) Update(record *Status) error {
    var db = slf.build()
    return db.Updates(record).Error
}
func (slf *StatusSearch) Find() (*Status, error) {
    var db = slf.build()
    var record = &Status{}
    err := db.First(record).Error
    return record, err
}
func (slf *StatusSearch) FindAll() ([]*Status, error) {
    var db = slf.build()
    var records = make([]*Status, 0)
    err := db.Find(&records).Error
    return records, err
}
func (slf *StatusSearch) SetId(id int) *StatusSearch {
    slf.Id = id
    return slf
}
func (slf *StatusSearch) SetName(name string) *StatusSearch {
    slf.Name = name
    return slf
}
func (slf *StatusSearch) Updates(data map[string]interface{}) error {
    var db = slf.build()
    return db.Updates(data).Error
}
pkg/ecode/code.go
@@ -170,4 +170,11 @@
    PossibilityUpdateErr = 2300005 // 更新销售机会可能性失败
    PossibilityDeleteErr = 2300006 // 删除销售机会可能性失败
    StatusExist     = 2400001 // 销售机会状态已存在
    StatusNotExist  = 2400002 // 销售机会状态不存在
    StatusListErr   = 2400003 // 获取销售机会状态列表失败
    StatusSetErr    = 2400004 // 设置销售机会状态失败
    StatusUpdateErr = 2400005 // 更新销售机会状态失败
    StatusDeleteErr = 2400006 // 删除销售机会状态失败
)
router/index.go
@@ -36,6 +36,7 @@
    SaleTypeRouter
    RegularCustomersRouter
    PossibilityRouter
    StatusRouter
}
func InitRouter() *gin.Engine {
@@ -89,6 +90,7 @@
        routerGroup.InitSaleTypeRouter(PrivateGroup)          // 注册saleType路由
        routerGroup.InitRegularCustomersRouter(PrivateGroup)  // 注册regularCustomers路由
        routerGroup.InitPossibilityRouter(PrivateGroup)       // 注册possibility路由
        routerGroup.InitStatusRouter(PrivateGroup)            // 注册status路由
    }
    return Router
}
router/status.go
New file
@@ -0,0 +1,19 @@
package router
import (
    v1 "aps_crm/api/v1"
    "github.com/gin-gonic/gin"
)
type StatusRouter struct{}
func (s *StatusRouter) InitStatusRouter(router *gin.RouterGroup) {
    statusRouter := router.Group("status")
    statusApi := v1.ApiGroup.StatusApi
    {
        statusRouter.POST("add", statusApi.Add)             // 添加状态
        statusRouter.DELETE("delete/:id", statusApi.Delete) // 删除状态
        statusRouter.PUT("update", statusApi.Update)        // 更新状态
        statusRouter.GET("list", statusApi.List)            // 获取状态列表
    }
}
service/index.go
@@ -25,6 +25,7 @@
    SaleTypeService
    RegularCustomersService
    PossibilityService
    StatusService
}
var ServiceGroup = new(Group)
service/status.go
New file
@@ -0,0 +1,59 @@
package service
import (
    "aps_crm/model"
    "aps_crm/model/request"
    "aps_crm/pkg/ecode"
)
type StatusService struct{}
func (StatusService) AddStatus(status *model.Status) int {
    err := model.NewStatusSearch().Create(status)
    if err != nil {
        return ecode.StatusExist
    }
    return ecode.OK
}
func (StatusService) DeleteStatus(id int) int {
    _, err := model.NewStatusSearch().SetId(id).Find()
    if err != nil {
        return ecode.StatusNotExist
    }
    err = model.NewStatusSearch().SetId(id).Delete()
    if err != nil {
        return ecode.StatusNotExist
    }
    return ecode.OK
}
func (StatusService) GetStatusList() ([]*model.Status, int) {
    list, err := model.NewStatusSearch().FindAll()
    if err != nil {
        return nil, ecode.StatusListErr
    }
    return list, ecode.OK
}
func (StatusService) UpdateStatus(statuses []*request.UpdateStatus) int {
    for _, v := range statuses {
        // check status exist
        _, err := model.NewStatusSearch().SetId(v.Id).Find()
        if err != nil {
            return ecode.StatusNotExist
        }
        err = model.NewStatusSearch().SetId(v.Id).Updates(map[string]interface{}{
            "name": v.Name,
        })
        if err != nil {
            return ecode.StatusSetErr
        }
    }
    return ecode.OK
}