add
wangpengfei
2023-07-20 aab89dff18f597d4cdd10c73b9ad8c3c14d82d28
add

timelyRate 及时率模块
add, Delete, update, list
5个文件已添加
14个文件已修改
890 ■■■■■ 已修改文件
api/v1/index.go 2 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
api/v1/satisfaction.go 14 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
api/v1/serviceFollowup.go 26 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
api/v1/timelyRate.go 113 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
docs/docs.go 192 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
docs/swagger.json 192 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
docs/swagger.yaml 122 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
model/index.go 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
model/request/timelyRate.go 15 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
model/response/response.go 16 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
model/serviceFeeManage.go 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
model/serviceFollowup.go 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
model/timelyRate.go 85 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
pkg/ecode/code.go 7 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
router/index.go 2 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
router/timelyRate.go 19 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
service/dataServer.go 8 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
service/index.go 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
service/timelyRate.go 69 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
api/v1/index.go
@@ -50,6 +50,7 @@
    DepartmentApi
    VettingApi
    SatisfactionApi
    TimelyRateApi
}
var ApiGroup = new(Group)
@@ -100,4 +101,5 @@
    departmentService           = service.ServiceGroup.DepartmentService
    vettingService              = service.ServiceGroup.VettingService
    satisfactionService         = service.ServiceGroup.SatisfactionService
    timelyRateService           = service.ServiceGroup.TimelyRateService
)
api/v1/satisfaction.go
@@ -68,8 +68,8 @@
//    @Tags        Satisfaction
//    @Summary    更新满意度
//    @Produce    application/json
//    @Param        object    body        request.UpdateSatisfactions true    "查询参数"
//    @Success    200    {object}    contextx.Response{}
//    @Param        object    body        request.UpdateSatisfactions    true    "查询参数"
//    @Success    200        {object}    contextx.Response{}
//    @Router        /api/satisfaction/update [put]
func (s *SatisfactionApi) Update(c *gin.Context) {
    var params request.UpdateSatisfactions
@@ -89,11 +89,11 @@
// List
//
//        @Tags        Satisfaction
//        @Summary    满意度列表
//        @Produce    application/json
//     @Success    200    {object}    contextx.Response{data=response.SatisfactionResponse}
//        @Router        /api/satisfaction/list [get]
//    @Tags        Satisfaction
//    @Summary    满意度列表
//    @Produce    application/json
//    @Success    200    {object}    contextx.Response{data=response.SatisfactionResponse}
//    @Router        /api/satisfaction/list [get]
func (s *SatisfactionApi) List(c *gin.Context) {
    ctx, ok := contextx.NewContext(c, nil)
    if !ok {
api/v1/serviceFollowup.go
@@ -133,19 +133,19 @@
    //}
    serviceFollowupModel = model.ServiceFollowup{
        ClientId:     serviceFollowup.ClientId,
        Number:       serviceFollowup.Number,
        ContactId:    serviceFollowup.ContactId,
        ServiceId:    serviceFollowup.ServiceId,
        MemberId:     serviceFollowup.MemberId,
        PlanId:       serviceFollowup.PlanId,
        Satisfaction: serviceFollowup.Satisfaction,
        TimelyRate:   serviceFollowup.TimelyRate,
        SolveRate:    serviceFollowup.SolveRate,
        IsVisit:      serviceFollowup.IsVisit,
        OldMemberId:  serviceFollowup.OldMemberId,
        Remark:       serviceFollowup.Remark,
        File:         serviceFollowup.File,
        ClientId:       serviceFollowup.ClientId,
        Number:         serviceFollowup.Number,
        ContactId:      serviceFollowup.ContactId,
        ServiceId:      serviceFollowup.ServiceId,
        MemberId:       serviceFollowup.MemberId,
        PlanId:         serviceFollowup.PlanId,
        SatisfactionId: serviceFollowup.Satisfaction,
        TimelyRateId:   serviceFollowup.TimelyRate,
        SolveRate:      serviceFollowup.SolveRate,
        IsVisit:        serviceFollowup.IsVisit,
        OldMemberId:    serviceFollowup.OldMemberId,
        Remark:         serviceFollowup.Remark,
        File:           serviceFollowup.File,
    }
    return ecode.OK, serviceFollowupModel
api/v1/timelyRate.go
New file
@@ -0,0 +1,113 @@
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 TimelyRateApi struct{}
// Add
//
//    @Tags        TimelyRate
//    @Summary    添加销售阶段
//    @Produce    application/json
//    @Param        object    body        request.AddTimelyRate    true    "查询参数"
//    @Success    200        {object}    contextx.Response{}
//    @Router        /api/timelyRate/add [post]
func (s *TimelyRateApi) Add(c *gin.Context) {
    var params request.AddTimelyRate
    ctx, ok := contextx.NewContext(c, &params)
    if !ok {
        return
    }
    timelyRate := new(model.TimelyRate)
    timelyRate.Name = params.Name
    errCode := timelyRateService.AddTimelyRate(timelyRate)
    if errCode != ecode.OK {
        ctx.Fail(errCode)
        return
    }
    ctx.Ok()
}
// Delete
//
//    @Tags        TimelyRate
//    @Summary    删除销售阶段
//    @Produce    application/json
//    @Param        id    path        int    true    "查询参数"
//    @Success    200    {object}    contextx.Response{}
//    @Router        /api/timelyRate/delete/{id} [delete]
func (s *TimelyRateApi) Delete(c *gin.Context) {
    ctx, ok := contextx.NewContext(c, nil)
    if !ok {
        return
    }
    id, _ := strconv.Atoi(c.Param("id"))
    errCode := timelyRateService.DeleteTimelyRate(id)
    if errCode != ecode.OK {
        ctx.Fail(errCode)
        return
    }
    ctx.Ok()
}
// Update
//
//    @Tags        TimelyRate
//    @Summary    更新销售阶段
//    @Produce    application/json
//    @Param        object    body        request.UpdateTimelyRates    true    "查询参数"
//    @Success    200        {object}    contextx.Response{}
//    @Router        /api/timelyRate/update [put]
func (s *TimelyRateApi) Update(c *gin.Context) {
    var params request.UpdateTimelyRates
    ctx, ok := contextx.NewContext(c, &params)
    if !ok {
        return
    }
    errCode := timelyRateService.UpdateTimelyRate(params.TimelyRates)
    if errCode != ecode.OK {
        ctx.Fail(errCode)
        return
    }
    ctx.Ok()
}
// List
//
//    @Tags        TimelyRate
//    @Summary    获取销售阶段列表
//    @Produce    application/json
//    @Success    200    {object}    contextx.Response{data=response.TimelyRateResponse}
//    @Router        /api/timelyRate/list [get]
func (s *TimelyRateApi) List(c *gin.Context) {
    ctx, ok := contextx.NewContext(c, nil)
    if !ok {
        return
    }
    timelyRates, errCode := timelyRateService.GetTimelyRateList()
    if errCode != ecode.OK {
        ctx.Fail(errCode)
        return
    }
    ctx.OkWithDetailed(response.TimelyRateResponse{
        List: timelyRates,
    })
}
docs/docs.go
@@ -4864,6 +4864,125 @@
                }
            }
        },
        "/api/timelyRate/add": {
            "post": {
                "produces": [
                    "application/json"
                ],
                "tags": [
                    "TimelyRate"
                ],
                "summary": "添加销售阶段",
                "parameters": [
                    {
                        "description": "查询参数",
                        "name": "object",
                        "in": "body",
                        "required": true,
                        "schema": {
                            "$ref": "#/definitions/request.AddTimelyRate"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK",
                        "schema": {
                            "$ref": "#/definitions/contextx.Response"
                        }
                    }
                }
            }
        },
        "/api/timelyRate/delete/{id}": {
            "delete": {
                "produces": [
                    "application/json"
                ],
                "tags": [
                    "TimelyRate"
                ],
                "summary": "删除销售阶段",
                "parameters": [
                    {
                        "type": "integer",
                        "description": "查询参数",
                        "name": "id",
                        "in": "path",
                        "required": true
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK",
                        "schema": {
                            "$ref": "#/definitions/contextx.Response"
                        }
                    }
                }
            }
        },
        "/api/timelyRate/list": {
            "get": {
                "produces": [
                    "application/json"
                ],
                "tags": [
                    "TimelyRate"
                ],
                "summary": "获取销售阶段列表",
                "responses": {
                    "200": {
                        "description": "OK",
                        "schema": {
                            "allOf": [
                                {
                                    "$ref": "#/definitions/contextx.Response"
                                },
                                {
                                    "type": "object",
                                    "properties": {
                                        "data": {
                                            "$ref": "#/definitions/response.TimelyRateResponse"
                                        }
                                    }
                                }
                            ]
                        }
                    }
                }
            }
        },
        "/api/timelyRate/update": {
            "put": {
                "produces": [
                    "application/json"
                ],
                "tags": [
                    "TimelyRate"
                ],
                "summary": "更新销售阶段",
                "parameters": [
                    {
                        "description": "查询参数",
                        "name": "object",
                        "in": "body",
                        "required": true,
                        "schema": {
                            "$ref": "#/definitions/request.UpdateTimelyRates"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK",
                        "schema": {
                            "$ref": "#/definitions/contextx.Response"
                        }
                    }
                }
            }
        },
        "/api/user/changePassword": {
            "post": {
                "produces": [
@@ -6461,7 +6580,7 @@
                "remark": {
                    "type": "string"
                },
                "satisfaction": {
                "satisfactionId": {
                    "type": "integer"
                },
                "serviceId": {
@@ -6470,7 +6589,7 @@
                "solveRate": {
                    "type": "integer"
                },
                "timelyRate": {
                "timelyRateId": {
                    "type": "integer"
                }
            }
@@ -6501,6 +6620,17 @@
                    "items": {
                        "$ref": "#/definitions/model.Product"
                    }
                }
            }
        },
        "model.TimelyRate": {
            "type": "object",
            "properties": {
                "id": {
                    "type": "integer"
                },
                "name": {
                    "type": "string"
                }
            }
        },
@@ -7484,6 +7614,17 @@
                    "items": {
                        "$ref": "#/definitions/model.Product"
                    }
                }
            }
        },
        "request.AddTimelyRate": {
            "type": "object",
            "required": [
                "name"
            ],
            "properties": {
                "name": {
                    "type": "string"
                }
            }
        },
@@ -9300,6 +9441,35 @@
                }
            }
        },
        "request.UpdateTimelyRate": {
            "type": "object",
            "required": [
                "id",
                "name"
            ],
            "properties": {
                "id": {
                    "type": "integer"
                },
                "name": {
                    "type": "string"
                }
            }
        },
        "request.UpdateTimelyRates": {
            "type": "object",
            "required": [
                "timely_rate"
            ],
            "properties": {
                "timely_rate": {
                    "type": "array",
                    "items": {
                        "$ref": "#/definitions/request.UpdateTimelyRate"
                    }
                }
            }
        },
        "response.CityResponse": {
            "type": "object",
            "properties": {
@@ -9526,6 +9696,13 @@
                    "type": "array",
                    "items": {
                        "$ref": "#/definitions/model.SalesSources"
                    }
                },
                "satisfaction": {
                    "description": "满意度",
                    "type": "array",
                    "items": {
                        "$ref": "#/definitions/model.Satisfaction"
                    }
                }
            }
@@ -9845,6 +10022,17 @@
                }
            }
        },
        "response.TimelyRateResponse": {
            "type": "object",
            "properties": {
                "list": {
                    "type": "array",
                    "items": {
                        "$ref": "#/definitions/model.TimelyRate"
                    }
                }
            }
        },
        "response.UserResponse": {
            "type": "object",
            "properties": {
docs/swagger.json
@@ -4852,6 +4852,125 @@
                }
            }
        },
        "/api/timelyRate/add": {
            "post": {
                "produces": [
                    "application/json"
                ],
                "tags": [
                    "TimelyRate"
                ],
                "summary": "添加销售阶段",
                "parameters": [
                    {
                        "description": "查询参数",
                        "name": "object",
                        "in": "body",
                        "required": true,
                        "schema": {
                            "$ref": "#/definitions/request.AddTimelyRate"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK",
                        "schema": {
                            "$ref": "#/definitions/contextx.Response"
                        }
                    }
                }
            }
        },
        "/api/timelyRate/delete/{id}": {
            "delete": {
                "produces": [
                    "application/json"
                ],
                "tags": [
                    "TimelyRate"
                ],
                "summary": "删除销售阶段",
                "parameters": [
                    {
                        "type": "integer",
                        "description": "查询参数",
                        "name": "id",
                        "in": "path",
                        "required": true
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK",
                        "schema": {
                            "$ref": "#/definitions/contextx.Response"
                        }
                    }
                }
            }
        },
        "/api/timelyRate/list": {
            "get": {
                "produces": [
                    "application/json"
                ],
                "tags": [
                    "TimelyRate"
                ],
                "summary": "获取销售阶段列表",
                "responses": {
                    "200": {
                        "description": "OK",
                        "schema": {
                            "allOf": [
                                {
                                    "$ref": "#/definitions/contextx.Response"
                                },
                                {
                                    "type": "object",
                                    "properties": {
                                        "data": {
                                            "$ref": "#/definitions/response.TimelyRateResponse"
                                        }
                                    }
                                }
                            ]
                        }
                    }
                }
            }
        },
        "/api/timelyRate/update": {
            "put": {
                "produces": [
                    "application/json"
                ],
                "tags": [
                    "TimelyRate"
                ],
                "summary": "更新销售阶段",
                "parameters": [
                    {
                        "description": "查询参数",
                        "name": "object",
                        "in": "body",
                        "required": true,
                        "schema": {
                            "$ref": "#/definitions/request.UpdateTimelyRates"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK",
                        "schema": {
                            "$ref": "#/definitions/contextx.Response"
                        }
                    }
                }
            }
        },
        "/api/user/changePassword": {
            "post": {
                "produces": [
@@ -6449,7 +6568,7 @@
                "remark": {
                    "type": "string"
                },
                "satisfaction": {
                "satisfactionId": {
                    "type": "integer"
                },
                "serviceId": {
@@ -6458,7 +6577,7 @@
                "solveRate": {
                    "type": "integer"
                },
                "timelyRate": {
                "timelyRateId": {
                    "type": "integer"
                }
            }
@@ -6489,6 +6608,17 @@
                    "items": {
                        "$ref": "#/definitions/model.Product"
                    }
                }
            }
        },
        "model.TimelyRate": {
            "type": "object",
            "properties": {
                "id": {
                    "type": "integer"
                },
                "name": {
                    "type": "string"
                }
            }
        },
@@ -7472,6 +7602,17 @@
                    "items": {
                        "$ref": "#/definitions/model.Product"
                    }
                }
            }
        },
        "request.AddTimelyRate": {
            "type": "object",
            "required": [
                "name"
            ],
            "properties": {
                "name": {
                    "type": "string"
                }
            }
        },
@@ -9288,6 +9429,35 @@
                }
            }
        },
        "request.UpdateTimelyRate": {
            "type": "object",
            "required": [
                "id",
                "name"
            ],
            "properties": {
                "id": {
                    "type": "integer"
                },
                "name": {
                    "type": "string"
                }
            }
        },
        "request.UpdateTimelyRates": {
            "type": "object",
            "required": [
                "timely_rate"
            ],
            "properties": {
                "timely_rate": {
                    "type": "array",
                    "items": {
                        "$ref": "#/definitions/request.UpdateTimelyRate"
                    }
                }
            }
        },
        "response.CityResponse": {
            "type": "object",
            "properties": {
@@ -9514,6 +9684,13 @@
                    "type": "array",
                    "items": {
                        "$ref": "#/definitions/model.SalesSources"
                    }
                },
                "satisfaction": {
                    "description": "满意度",
                    "type": "array",
                    "items": {
                        "$ref": "#/definitions/model.Satisfaction"
                    }
                }
            }
@@ -9833,6 +10010,17 @@
                }
            }
        },
        "response.TimelyRateResponse": {
            "type": "object",
            "properties": {
                "list": {
                    "type": "array",
                    "items": {
                        "$ref": "#/definitions/model.TimelyRate"
                    }
                }
            }
        },
        "response.UserResponse": {
            "type": "object",
            "properties": {
docs/swagger.yaml
@@ -872,13 +872,13 @@
        type: integer
      remark:
        type: string
      satisfaction:
      satisfactionId:
        type: integer
      serviceId:
        type: integer
      solveRate:
        type: integer
      timelyRate:
      timelyRateId:
        type: integer
    type: object
  model.SubOrder:
@@ -899,6 +899,13 @@
        items:
          $ref: '#/definitions/model.Product'
        type: array
    type: object
  model.TimelyRate:
    properties:
      id:
        type: integer
      name:
        type: string
    type: object
  model.User:
    properties:
@@ -1564,6 +1571,13 @@
        items:
          $ref: '#/definitions/model.Product'
        type: array
    type: object
  request.AddTimelyRate:
    properties:
      name:
        type: string
    required:
    - name
    type: object
  request.AddVetting:
    properties:
@@ -2793,6 +2807,25 @@
          $ref: '#/definitions/model.Product'
        type: array
    type: object
  request.UpdateTimelyRate:
    properties:
      id:
        type: integer
      name:
        type: string
    required:
    - id
    - name
    type: object
  request.UpdateTimelyRates:
    properties:
      timely_rate:
        items:
          $ref: '#/definitions/request.UpdateTimelyRate'
        type: array
    required:
    - timely_rate
    type: object
  response.CityResponse:
    properties:
      list:
@@ -2947,6 +2980,11 @@
        description: 商机来源
        items:
          $ref: '#/definitions/model.SalesSources'
        type: array
      satisfaction:
        description: 满意度
        items:
          $ref: '#/definitions/model.Satisfaction'
        type: array
    type: object
  response.DepartmentResponse:
@@ -3148,6 +3186,13 @@
      list:
        items:
          $ref: '#/definitions/model.SubOrder'
        type: array
    type: object
  response.TimelyRateResponse:
    properties:
      list:
        items:
          $ref: '#/definitions/model.TimelyRate'
        type: array
    type: object
  response.UserResponse:
@@ -6133,6 +6178,79 @@
      summary: 更新子订单
      tags:
      - SubOrder
  /api/timelyRate/add:
    post:
      parameters:
      - description: 查询参数
        in: body
        name: object
        required: true
        schema:
          $ref: '#/definitions/request.AddTimelyRate'
      produces:
      - application/json
      responses:
        "200":
          description: OK
          schema:
            $ref: '#/definitions/contextx.Response'
      summary: 添加销售阶段
      tags:
      - TimelyRate
  /api/timelyRate/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:
      - TimelyRate
  /api/timelyRate/list:
    get:
      produces:
      - application/json
      responses:
        "200":
          description: OK
          schema:
            allOf:
            - $ref: '#/definitions/contextx.Response'
            - properties:
                data:
                  $ref: '#/definitions/response.TimelyRateResponse'
              type: object
      summary: 获取销售阶段列表
      tags:
      - TimelyRate
  /api/timelyRate/update:
    put:
      parameters:
      - description: 查询参数
        in: body
        name: object
        required: true
        schema:
          $ref: '#/definitions/request.UpdateTimelyRates'
      produces:
      - application/json
      responses:
        "200":
          description: OK
          schema:
            $ref: '#/definitions/contextx.Response'
      summary: 更新销售阶段
      tags:
      - TimelyRate
  /api/user/changePassword:
    post:
      parameters:
model/index.go
@@ -64,6 +64,7 @@
        Api{},
        Department{},
        Satisfaction{},
        TimelyRate{},
    )
    return err
}
model/request/timelyRate.go
New file
@@ -0,0 +1,15 @@
package request
type AddTimelyRate struct {
    Name string `  json:"name" binding:"required"`
}
type UpdateTimelyRate struct {
    Id   int    `json:"id" binding:"required"`
    Name string `json:"name" binding:"required"`
}
type UpdateTimelyRates struct {
    TimelyRates []*UpdateTimelyRate `json:"timely_rate" binding:"required"`
}
model/response/response.go
@@ -215,6 +215,10 @@
        Member []*model.User `json:"member"`
        // 部门
        Department []*model.Department `json:"department"`
        // 满意度
        Satisfaction []*model.Satisfaction `json:"satisfaction"`
        // 及时率
        TimelyRate []*model.TimelyRate `json:"timely_rate"`
    }
    DepartmentResponse struct {
@@ -224,4 +228,16 @@
    SatisfactionResponse struct {
        List []*model.Satisfaction `json:"list"`
    }
    TimelyRateResponse struct {
        List []*model.TimelyRate `json:"list"`
    }
)
// 及时率 解决率 满意度 服务人员是否来过 (服务回访单)
// 工单类型 报修来源(工单管理)
// 合同类型 合同状态(服务合同)
// 付款方式 是否开票 账户(销售退款单)
// 退入仓库 状态(销售退货单)
// 报价单状态 (报价单)
// 可能性 币种 当前状态(销售机会)
model/serviceFeeManage.go
@@ -80,6 +80,6 @@
func (slf *ServiceFeeManageSearch) FindAll() ([]*ServiceFeeManage, error) {
    var db = slf.build()
    var records = make([]*ServiceFeeManage, 0)
    err := db.Find(&records).Error
    err := db.Preload("Client").Find(&records).Error
    return records, err
}
model/serviceFollowup.go
@@ -15,8 +15,8 @@
        CustomerServiceSheet CustomerServiceSheet `json:"customerServiceSheet" gorm:"foreignKey:ServiceId"`
        MemberId             int                  `json:"memberId" gorm:"column:member_id;type:int;comment:服务人员id"`
        PlanId               int                  `json:"planId" gorm:"column:plan_id;type:int;comment:服务计划id"`
        Satisfaction         int                  `json:"satisfaction" gorm:"column:satisfaction;type:int;comment:满意度"`
        TimelyRate           int                  `json:"timelyRate" gorm:"column:timely_rate;type:int;comment:及时率"`
        SatisfactionId       int                  `json:"satisfactionId" gorm:"column:satisfaction_id;type:int;comment:满意度id"`
        TimelyRateId         int                  `json:"timelyRateId" gorm:"column:timely_rate_id;type:int;comment:及时率id"`
        SolveRate            int                  `json:"solveRate" gorm:"column:solve_rate;type:int;comment:解决率"`
        IsVisit              int                  `json:"isVisit" gorm:"column:is_visit;type:int;comment:服务人员是否来过"`
        OldMemberId          int                  `json:"oldMemberId" gorm:"column:old_member_id;type:int;comment:原服务人员"`
model/timelyRate.go
New file
@@ -0,0 +1,85 @@
package model
import (
    "aps_crm/pkg/mysqlx"
    "gorm.io/gorm"
)
type (
    // TimelyRate 商机阶段
    TimelyRate struct {
        Id   int    `json:"id" gorm:"column:id;primary_key;AUTO_INCREMENT"`
        Name string `json:"name" gorm:"column:name;type:varchar(255);comment:商机阶段名称"`
    }
    TimelyRateSearch struct {
        TimelyRate
        Orm *gorm.DB
    }
)
func (TimelyRate) TableName() string {
    return "timely_rate"
}
func NewTimelyRateSearch() *TimelyRateSearch {
    return &TimelyRateSearch{
        Orm: mysqlx.GetDB(),
    }
}
func (slf *TimelyRateSearch) build() *gorm.DB {
    var db = slf.Orm.Model(&TimelyRate{})
    if slf.Id != 0 {
        db = db.Where("id = ?", slf.Id)
    }
    if slf.Name != "" {
        db = db.Where("name = ?", slf.Name)
    }
    return db
}
func (slf *TimelyRateSearch) Create(record *TimelyRate) error {
    var db = slf.build()
    return db.Create(record).Error
}
func (slf *TimelyRateSearch) Delete() error {
    var db = slf.build()
    return db.Delete(&TimelyRate{}).Error
}
func (slf *TimelyRateSearch) Update(record *TimelyRate) error {
    var db = slf.build()
    return db.Updates(record).Error
}
func (slf *TimelyRateSearch) Find() (*TimelyRate, error) {
    var db = slf.build()
    var record = new(TimelyRate)
    err := db.First(record).Error
    return record, err
}
func (slf *TimelyRateSearch) FindAll() ([]*TimelyRate, error) {
    var db = slf.build()
    var records = make([]*TimelyRate, 0)
    err := db.Find(&records).Error
    return records, err
}
func (slf *TimelyRateSearch) SetId(id int) *TimelyRateSearch {
    slf.Id = id
    return slf
}
func (slf *TimelyRateSearch) SetName(name string) *TimelyRateSearch {
    slf.Name = name
    return slf
}
func (slf *TimelyRateSearch) Updates(data map[string]interface{}) error {
    var db = slf.build()
    return db.Updates(data).Error
}
pkg/ecode/code.go
@@ -297,4 +297,11 @@
    SatisfactionListErr   = 4200003 // 获取满意度列表失败
    SatisfactionSetErr    = 4200004 // 设置满意度失败
    SatisfactionUpdateErr = 4200005 // 更新满意度失败
    TimelyRateExist     = 4300001 // 及时率已存在
    TimelyRateNotExist  = 4300002 // 及时率不存在
    TimelyRateListErr   = 4300003 // 获取及时率列表失败
    TimelyRateSetErr    = 4300004 // 设置及时率失败
    TimelyRateUpdateErr = 4300005 // 更新及时率失败
)
router/index.go
@@ -55,6 +55,7 @@
    DataRouter
    DepartmentRouter
    SatisfactionRouter
    TimelyRateRouter
}
func InitRouter() *gin.Engine {
@@ -129,6 +130,7 @@
        routerGroup.InitDataRouter(PrivateGroup)                 // 注册data路由
        routerGroup.InitDepartmentRouter(PrivateGroup)           // 注册department路由
        routerGroup.InitSatisfactionRouter(PrivateGroup)         // 注册satisfaction路由
        routerGroup.InitTimelyRateRouter(PrivateGroup)           // 注册timelyRate路由
    }
    return Router
}
router/timelyRate.go
New file
@@ -0,0 +1,19 @@
package router
import (
    v1 "aps_crm/api/v1"
    "github.com/gin-gonic/gin"
)
type TimelyRateRouter struct{}
func (s *TimelyRateRouter) InitTimelyRateRouter(router *gin.RouterGroup) {
    timelyRateRouter := router.Group("timelyRate")
    timelyRateApi := v1.ApiGroup.TimelyRateApi
    {
        timelyRateRouter.POST("add", timelyRateApi.Add)             // 添加销售阶段
        timelyRateRouter.DELETE("delete/:id", timelyRateApi.Delete) // 删除销售阶段
        timelyRateRouter.PUT("update", timelyRateApi.Update)        // 更新销售阶段
        timelyRateRouter.GET("list", timelyRateApi.List)            // 获取销售阶段列表
    }
}
service/dataServer.go
@@ -80,6 +80,14 @@
    departmentList, _ := ServiceGroup.GetDepartmentList()
    data.Department = departmentList
    // get Satisfaction list
    satisfactionList, _ := ServiceGroup.GetSatisfactionList()
    data.Satisfaction = satisfactionList
    // get TimelyRate list
    timelyRateList, _ := ServiceGroup.GetTimelyRateList()
    data.TimelyRate = timelyRateList
    errCode = ecode.OK
    return
service/index.go
@@ -46,6 +46,7 @@
    DepartmentService
    VettingService
    SatisfactionService
    TimelyRateService
}
var ServiceGroup = new(Group)
service/timelyRate.go
New file
@@ -0,0 +1,69 @@
package service
import (
    "aps_crm/model"
    "aps_crm/model/request"
    "aps_crm/pkg/ecode"
)
type TimelyRateService struct{}
func (TimelyRateService) AddTimelyRate(timelyRate *model.TimelyRate) int {
    err := model.NewTimelyRateSearch().Create(timelyRate)
    if err != nil {
        return ecode.TimelyRateExist
    }
    return ecode.OK
}
func (TimelyRateService) DeleteTimelyRate(id int) int {
    _, err := model.NewTimelyRateSearch().SetId(id).Find()
    if err != nil {
        return ecode.TimelyRateNotExist
    }
    err = model.NewTimelyRateSearch().SetId(id).Delete()
    if err != nil {
        return ecode.TimelyRateNotExist
    }
    return ecode.OK
}
func (TimelyRateService) GetTimelyRateList() ([]*model.TimelyRate, int) {
    list, err := model.NewTimelyRateSearch().FindAll()
    if err != nil {
        return nil, ecode.TimelyRateListErr
    }
    return list, ecode.OK
}
func (TimelyRateService) UpdateTimelyRate(timelyRates []*request.UpdateTimelyRate) int {
    for _, v := range timelyRates {
        // check timelyRate exist
        _, err := model.NewTimelyRateSearch().SetId(v.Id).Find()
        if err != nil {
            return ecode.TimelyRateNotExist
        }
        err = model.NewTimelyRateSearch().SetId(v.Id).Updates(map[string]interface{}{
            "name": v.Name,
        })
        if err != nil {
            return ecode.TimelyRateSetErr
        }
    }
    return ecode.OK
}
func (TimelyRateService) GetTimelyRateDetail(id int) (*model.TimelyRate, int) {
    timelyRate, err := model.NewTimelyRateSearch().SetId(id).Find()
    if err != nil {
        return nil, ecode.TimelyRateNotExist
    }
    return timelyRate, ecode.OK
}