add
wangpengfei
2023-07-21 993d3555339703c53ca14103d4d7899cde0d2e04
add

ServiceContractType 服务合同类型
add, Delete, update, list
5个文件已添加
12个文件已修改
842 ■■■■■ 已修改文件
api/v1/index.go 2 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
api/v1/serviceContractType.go 113 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
api/v1/serviceContracts.go 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
docs/docs.go 194 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
docs/swagger.json 194 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
docs/swagger.yaml 122 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
model/index.go 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
model/request/serviceContractType.go 15 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
model/response/response.go 8 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
model/serviceContractType.go 85 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
model/serviceContracts.go 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
pkg/ecode/code.go 7 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
router/index.go 2 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
router/serviceContractType.go 20 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
service/dataServer.go 5 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
service/index.go 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
service/serviceContractType.go 69 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
api/v1/index.go
@@ -5,6 +5,7 @@
)
type Group struct {
    ServiceContractTypeApi
    ServiceContractStatusApi
    OrderTypeApi
    ReportSourceApi
@@ -112,4 +113,5 @@
   reportSourceService    = service.ServiceGroup.ReportSourceService
   orderTypeService    = service.ServiceGroup.OrderTypeService
   serviceContractStatusService    = service.ServiceGroup.ServiceContractStatusService
   serviceContractTypeService    = service.ServiceGroup.ServiceContractTypeService
)
api/v1/serviceContractType.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 ServiceContractTypeApi struct{}
// Add
//
//    @Tags        ServiceContractType
//    @Summary    添加服务合同类型
//    @Produce    application/json
//    @Param        object    body        request.AddServiceContractType    true    "查询参数"
//    @Success    200        {object}    contextx.Response{}
//    @Router        /api/serviceContractType/add [post]
func (s *ServiceContractTypeApi) Add(c *gin.Context) {
    var params request.AddServiceContractType
    ctx, ok := contextx.NewContext(c, &params)
    if !ok {
        return
    }
    serviceContractType := new(model.ServiceContractType)
    serviceContractType.Name = params.Name
    errCode := serviceContractTypeService.AddServiceContractType(serviceContractType)
    if errCode != ecode.OK {
        ctx.Fail(errCode)
        return
    }
    ctx.Ok()
}
// Delete
//
//    @Tags        ServiceContractType
//    @Summary    删除服务合同类型
//    @Produce    application/json
//    @Param        id    path        int    true    "查询参数"
//    @Success    200    {object}    contextx.Response{}
//    @Router        /api/serviceContractType/delete/{id} [delete]
func (s *ServiceContractTypeApi) Delete(c *gin.Context) {
    ctx, ok := contextx.NewContext(c, nil)
    if !ok {
        return
    }
    id, _ := strconv.Atoi(c.Param("id"))
    errCode := serviceContractTypeService.DeleteServiceContractType(id)
    if errCode != ecode.OK {
        ctx.Fail(errCode)
        return
    }
    ctx.Ok()
}
// Update
//
//    @Tags        ServiceContractType
//    @Summary    更新服务合同类型
//    @Produce    application/json
//    @Param        object    body        request.UpdateServiceContractTypes    true    "查询参数"
//    @Success    200        {object}    contextx.Response{}
//    @Router        /api/serviceContractType/update [put]
func (s *ServiceContractTypeApi) Update(c *gin.Context) {
    var params request.UpdateServiceContractTypes
    ctx, ok := contextx.NewContext(c, &params)
    if !ok {
        return
    }
    errCode := serviceContractTypeService.UpdateServiceContractType(params.ServiceContractTypes)
    if errCode != ecode.OK {
        ctx.Fail(errCode)
        return
    }
    ctx.Ok()
}
// List
//
//    @Tags        ServiceContractType
//    @Summary    获取服务合同类型列表
//    @Produce    application/json
//    @Success    200    {object}    contextx.Response{data=response.ServiceContractTypeResponse}
//    @Router        /api/serviceContractType/list [get]
func (s *ServiceContractTypeApi) List(c *gin.Context) {
    ctx, ok := contextx.NewContext(c, nil)
    if !ok {
        return
    }
    serviceContractTypes, errCode := serviceContractTypeService.GetServiceContractTypeList()
    if errCode != ecode.OK {
        ctx.Fail(errCode)
        return
    }
    ctx.OkWithDetailed(response.ServiceContractTypeResponse{
        List: serviceContractTypes,
    })
}
api/v1/serviceContracts.go
@@ -164,7 +164,7 @@
    result.ContactId = serviceContract.ContactId
    result.SaleChanceId = serviceContract.SaleChanceId
    result.QuotationId = serviceContract.QuotationId
    result.TypeId = serviceContract.TypeId
    result.ServiceContractTypeId = serviceContract.TypeId
    result.ServiceContractStatusId = serviceContract.StatusId
    result.ServiceTimes = serviceContract.ServiceTimes
    result.Terms = serviceContract.Terms
docs/docs.go
@@ -4876,6 +4876,125 @@
                }
            }
        },
        "/api/serviceContractType/add": {
            "post": {
                "produces": [
                    "application/json"
                ],
                "tags": [
                    "ServiceContractType"
                ],
                "summary": "添加服务合同类型",
                "parameters": [
                    {
                        "description": "查询参数",
                        "name": "object",
                        "in": "body",
                        "required": true,
                        "schema": {
                            "$ref": "#/definitions/request.AddServiceContractType"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK",
                        "schema": {
                            "$ref": "#/definitions/contextx.Response"
                        }
                    }
                }
            }
        },
        "/api/serviceContractType/delete/{id}": {
            "delete": {
                "produces": [
                    "application/json"
                ],
                "tags": [
                    "ServiceContractType"
                ],
                "summary": "删除服务合同类型",
                "parameters": [
                    {
                        "type": "integer",
                        "description": "查询参数",
                        "name": "id",
                        "in": "path",
                        "required": true
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK",
                        "schema": {
                            "$ref": "#/definitions/contextx.Response"
                        }
                    }
                }
            }
        },
        "/api/serviceContractType/list": {
            "get": {
                "produces": [
                    "application/json"
                ],
                "tags": [
                    "ServiceContractType"
                ],
                "summary": "获取服务合同类型列表",
                "responses": {
                    "200": {
                        "description": "OK",
                        "schema": {
                            "allOf": [
                                {
                                    "$ref": "#/definitions/contextx.Response"
                                },
                                {
                                    "type": "object",
                                    "properties": {
                                        "data": {
                                            "$ref": "#/definitions/response.ServiceContractTypeResponse"
                                        }
                                    }
                                }
                            ]
                        }
                    }
                }
            }
        },
        "/api/serviceContractType/update": {
            "put": {
                "produces": [
                    "application/json"
                ],
                "tags": [
                    "ServiceContractType"
                ],
                "summary": "更新服务合同类型",
                "parameters": [
                    {
                        "description": "查询参数",
                        "name": "object",
                        "in": "body",
                        "required": true,
                        "schema": {
                            "$ref": "#/definitions/request.UpdateServiceContractTypes"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK",
                        "schema": {
                            "$ref": "#/definitions/contextx.Response"
                        }
                    }
                }
            }
        },
        "/api/serviceFeeManage/add": {
            "post": {
                "produces": [
@@ -7129,6 +7248,9 @@
                "serviceContractStatusId": {
                    "type": "integer"
                },
                "serviceContractTypeId": {
                    "type": "integer"
                },
                "serviceTimes": {
                    "type": "integer"
                },
@@ -7140,13 +7262,21 @@
                },
                "terms": {
                    "type": "string"
                },
                "typeId": {
                    "type": "integer"
                }
            }
        },
        "model.ServiceContractStatus": {
            "type": "object",
            "properties": {
                "id": {
                    "type": "integer"
                },
                "name": {
                    "type": "string"
                }
            }
        },
        "model.ServiceContractType": {
            "type": "object",
            "properties": {
                "id": {
@@ -8121,6 +8251,17 @@
            }
        },
        "request.AddServiceContractStatus": {
            "type": "object",
            "required": [
                "name"
            ],
            "properties": {
                "name": {
                    "type": "string"
                }
            }
        },
        "request.AddServiceContractType": {
            "type": "object",
            "required": [
                "name"
@@ -10057,6 +10198,35 @@
                }
            }
        },
        "request.UpdateServiceContractType": {
            "type": "object",
            "required": [
                "id",
                "name"
            ],
            "properties": {
                "id": {
                    "type": "integer"
                },
                "name": {
                    "type": "string"
                }
            }
        },
        "request.UpdateServiceContractTypes": {
            "type": "object",
            "required": [
                "service_contract_type"
            ],
            "properties": {
                "service_contract_type": {
                    "type": "array",
                    "items": {
                        "$ref": "#/definitions/request.UpdateServiceContractType"
                    }
                }
            }
        },
        "request.UpdateServiceFeeManage": {
            "type": "object",
            "properties": {
@@ -10583,6 +10753,13 @@
                        "$ref": "#/definitions/model.ServiceContractStatus"
                    }
                },
                "serviceContractType": {
                    "description": "服务合同类型",
                    "type": "array",
                    "items": {
                        "$ref": "#/definitions/model.ServiceContractType"
                    }
                },
                "solve_rate": {
                    "description": "解决率",
                    "type": "array",
@@ -10914,6 +11091,17 @@
                }
            }
        },
        "response.ServiceContractTypeResponse": {
            "type": "object",
            "properties": {
                "list": {
                    "type": "array",
                    "items": {
                        "$ref": "#/definitions/model.ServiceContractType"
                    }
                }
            }
        },
        "response.ServiceContractsResponse": {
            "type": "object",
            "properties": {
docs/swagger.json
@@ -4864,6 +4864,125 @@
                }
            }
        },
        "/api/serviceContractType/add": {
            "post": {
                "produces": [
                    "application/json"
                ],
                "tags": [
                    "ServiceContractType"
                ],
                "summary": "添加服务合同类型",
                "parameters": [
                    {
                        "description": "查询参数",
                        "name": "object",
                        "in": "body",
                        "required": true,
                        "schema": {
                            "$ref": "#/definitions/request.AddServiceContractType"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK",
                        "schema": {
                            "$ref": "#/definitions/contextx.Response"
                        }
                    }
                }
            }
        },
        "/api/serviceContractType/delete/{id}": {
            "delete": {
                "produces": [
                    "application/json"
                ],
                "tags": [
                    "ServiceContractType"
                ],
                "summary": "删除服务合同类型",
                "parameters": [
                    {
                        "type": "integer",
                        "description": "查询参数",
                        "name": "id",
                        "in": "path",
                        "required": true
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK",
                        "schema": {
                            "$ref": "#/definitions/contextx.Response"
                        }
                    }
                }
            }
        },
        "/api/serviceContractType/list": {
            "get": {
                "produces": [
                    "application/json"
                ],
                "tags": [
                    "ServiceContractType"
                ],
                "summary": "获取服务合同类型列表",
                "responses": {
                    "200": {
                        "description": "OK",
                        "schema": {
                            "allOf": [
                                {
                                    "$ref": "#/definitions/contextx.Response"
                                },
                                {
                                    "type": "object",
                                    "properties": {
                                        "data": {
                                            "$ref": "#/definitions/response.ServiceContractTypeResponse"
                                        }
                                    }
                                }
                            ]
                        }
                    }
                }
            }
        },
        "/api/serviceContractType/update": {
            "put": {
                "produces": [
                    "application/json"
                ],
                "tags": [
                    "ServiceContractType"
                ],
                "summary": "更新服务合同类型",
                "parameters": [
                    {
                        "description": "查询参数",
                        "name": "object",
                        "in": "body",
                        "required": true,
                        "schema": {
                            "$ref": "#/definitions/request.UpdateServiceContractTypes"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK",
                        "schema": {
                            "$ref": "#/definitions/contextx.Response"
                        }
                    }
                }
            }
        },
        "/api/serviceFeeManage/add": {
            "post": {
                "produces": [
@@ -7117,6 +7236,9 @@
                "serviceContractStatusId": {
                    "type": "integer"
                },
                "serviceContractTypeId": {
                    "type": "integer"
                },
                "serviceTimes": {
                    "type": "integer"
                },
@@ -7128,13 +7250,21 @@
                },
                "terms": {
                    "type": "string"
                },
                "typeId": {
                    "type": "integer"
                }
            }
        },
        "model.ServiceContractStatus": {
            "type": "object",
            "properties": {
                "id": {
                    "type": "integer"
                },
                "name": {
                    "type": "string"
                }
            }
        },
        "model.ServiceContractType": {
            "type": "object",
            "properties": {
                "id": {
@@ -8109,6 +8239,17 @@
            }
        },
        "request.AddServiceContractStatus": {
            "type": "object",
            "required": [
                "name"
            ],
            "properties": {
                "name": {
                    "type": "string"
                }
            }
        },
        "request.AddServiceContractType": {
            "type": "object",
            "required": [
                "name"
@@ -10045,6 +10186,35 @@
                }
            }
        },
        "request.UpdateServiceContractType": {
            "type": "object",
            "required": [
                "id",
                "name"
            ],
            "properties": {
                "id": {
                    "type": "integer"
                },
                "name": {
                    "type": "string"
                }
            }
        },
        "request.UpdateServiceContractTypes": {
            "type": "object",
            "required": [
                "service_contract_type"
            ],
            "properties": {
                "service_contract_type": {
                    "type": "array",
                    "items": {
                        "$ref": "#/definitions/request.UpdateServiceContractType"
                    }
                }
            }
        },
        "request.UpdateServiceFeeManage": {
            "type": "object",
            "properties": {
@@ -10571,6 +10741,13 @@
                        "$ref": "#/definitions/model.ServiceContractStatus"
                    }
                },
                "serviceContractType": {
                    "description": "服务合同类型",
                    "type": "array",
                    "items": {
                        "$ref": "#/definitions/model.ServiceContractType"
                    }
                },
                "solve_rate": {
                    "description": "解决率",
                    "type": "array",
@@ -10902,6 +11079,17 @@
                }
            }
        },
        "response.ServiceContractTypeResponse": {
            "type": "object",
            "properties": {
                "list": {
                    "type": "array",
                    "items": {
                        "$ref": "#/definitions/model.ServiceContractType"
                    }
                }
            }
        },
        "response.ServiceContractsResponse": {
            "type": "object",
            "properties": {
docs/swagger.yaml
@@ -841,6 +841,8 @@
        type: integer
      serviceContractStatusId:
        type: integer
      serviceContractTypeId:
        type: integer
      serviceTimes:
        type: integer
      signTime:
@@ -849,10 +851,15 @@
        type: string
      terms:
        type: string
      typeId:
        type: integer
    type: object
  model.ServiceContractStatus:
    properties:
      id:
        type: integer
      name:
        type: string
    type: object
  model.ServiceContractType:
    properties:
      id:
        type: integer
@@ -1504,6 +1511,13 @@
        type: integer
    type: object
  request.AddServiceContractStatus:
    properties:
      name:
        type: string
    required:
    - name
    type: object
  request.AddServiceContractType:
    properties:
      name:
        type: string
@@ -2812,6 +2826,25 @@
    required:
    - service_contract_status
    type: object
  request.UpdateServiceContractType:
    properties:
      id:
        type: integer
      name:
        type: string
    required:
    - id
    - name
    type: object
  request.UpdateServiceContractTypes:
    properties:
      service_contract_type:
        items:
          $ref: '#/definitions/request.UpdateServiceContractType'
        type: array
    required:
    - service_contract_type
    type: object
  request.UpdateServiceFeeManage:
    properties:
      business_scope:
@@ -3171,6 +3204,11 @@
        items:
          $ref: '#/definitions/model.ServiceContractStatus'
        type: array
      serviceContractType:
        description: 服务合同类型
        items:
          $ref: '#/definitions/model.ServiceContractType'
        type: array
      solve_rate:
        description: 解决率
        items:
@@ -3381,6 +3419,13 @@
      list:
        items:
          $ref: '#/definitions/model.ServiceContractStatus'
        type: array
    type: object
  response.ServiceContractTypeResponse:
    properties:
      list:
        items:
          $ref: '#/definitions/model.ServiceContractType'
        type: array
    type: object
  response.ServiceContractsResponse:
@@ -6413,6 +6458,79 @@
      summary: 更新服务合同状态
      tags:
      - ServiceContractStatus
  /api/serviceContractType/add:
    post:
      parameters:
      - description: 查询参数
        in: body
        name: object
        required: true
        schema:
          $ref: '#/definitions/request.AddServiceContractType'
      produces:
      - application/json
      responses:
        "200":
          description: OK
          schema:
            $ref: '#/definitions/contextx.Response'
      summary: 添加服务合同类型
      tags:
      - ServiceContractType
  /api/serviceContractType/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:
      - ServiceContractType
  /api/serviceContractType/list:
    get:
      produces:
      - application/json
      responses:
        "200":
          description: OK
          schema:
            allOf:
            - $ref: '#/definitions/contextx.Response'
            - properties:
                data:
                  $ref: '#/definitions/response.ServiceContractTypeResponse'
              type: object
      summary: 获取服务合同类型列表
      tags:
      - ServiceContractType
  /api/serviceContractType/update:
    put:
      parameters:
      - description: 查询参数
        in: body
        name: object
        required: true
        schema:
          $ref: '#/definitions/request.UpdateServiceContractTypes'
      produces:
      - application/json
      responses:
        "200":
          description: OK
          schema:
            $ref: '#/definitions/contextx.Response'
      summary: 更新服务合同类型
      tags:
      - ServiceContractType
  /api/serviceFeeManage/add:
    post:
      parameters:
model/index.go
@@ -71,6 +71,7 @@
        ReportSource{},
        OrderType{},
        ServiceContractStatus{},
        ServiceContractType{},
    )
    return err
}
model/request/serviceContractType.go
New file
@@ -0,0 +1,15 @@
package request
type AddServiceContractType struct {
    Name string `  json:"name" binding:"required"`
}
type UpdateServiceContractType struct {
    Id   int    `json:"id" binding:"required"`
    Name string `json:"name" binding:"required"`
}
type UpdateServiceContractTypes struct {
    ServiceContractTypes []*UpdateServiceContractType `json:"service_contract_type" binding:"required"`
}
model/response/response.go
@@ -180,6 +180,10 @@
    DataResponse struct {
        // 服务合同类型
        ServiceContractType []*model.ServiceContractType `json:"serviceContractType"`
        // 服务合同状态
        ServiceContractStatus []*model.ServiceContractStatus `json:"serviceContractStatus"`
@@ -270,4 +274,8 @@
    ServiceContractStatusResponse struct {
        List []*model.ServiceContractStatus `json:"list"`
    }
    ServiceContractTypeResponse struct {
        List []*model.ServiceContractType `json:"list"`
    }
)
model/serviceContractType.go
New file
@@ -0,0 +1,85 @@
package model
import (
    "aps_crm/pkg/mysqlx"
    "gorm.io/gorm"
)
type (
    // ServiceContractType 商机阶段
    ServiceContractType struct {
        Id   int    `json:"id" gorm:"column:id;primary_key;AUTO_INCREMENT"`
        Name string `json:"name" gorm:"column:name;type:varchar(255);comment:商机阶段名称"`
    }
    ServiceContractTypeSearch struct {
        ServiceContractType
        Orm *gorm.DB
    }
)
func (ServiceContractType) TableName() string {
    return "service_contract_type"
}
func NewServiceContractTypeSearch() *ServiceContractTypeSearch {
    return &ServiceContractTypeSearch{
        Orm: mysqlx.GetDB(),
    }
}
func (slf *ServiceContractTypeSearch) build() *gorm.DB {
    var db = slf.Orm.Model(&ServiceContractType{})
    if slf.Id != 0 {
        db = db.Where("id = ?", slf.Id)
    }
    if slf.Name != "" {
        db = db.Where("name = ?", slf.Name)
    }
    return db
}
func (slf *ServiceContractTypeSearch) Create(record *ServiceContractType) error {
    var db = slf.build()
    return db.Create(record).Error
}
func (slf *ServiceContractTypeSearch) Delete() error {
    var db = slf.build()
    return db.Delete(&ServiceContractType{}).Error
}
func (slf *ServiceContractTypeSearch) Update(record *ServiceContractType) error {
    var db = slf.build()
    return db.Updates(record).Error
}
func (slf *ServiceContractTypeSearch) Find() (*ServiceContractType, error) {
    var db = slf.build()
    var record = new(ServiceContractType)
    err := db.First(record).Error
    return record, err
}
func (slf *ServiceContractTypeSearch) FindAll() ([]*ServiceContractType, error) {
    var db = slf.build()
    var records = make([]*ServiceContractType, 0)
    err := db.Find(&records).Error
    return records, err
}
func (slf *ServiceContractTypeSearch) SetId(id int) *ServiceContractTypeSearch {
    slf.Id = id
    return slf
}
func (slf *ServiceContractTypeSearch) SetName(name string) *ServiceContractTypeSearch {
    slf.Name = name
    return slf
}
func (slf *ServiceContractTypeSearch) Updates(data map[string]interface{}) error {
    var db = slf.build()
    return db.Updates(data).Error
}
model/serviceContracts.go
@@ -16,7 +16,7 @@
        SaleChanceId            int       `json:"saleChanceId" gorm:"column:sale_chance_id;type:int;comment:销售机会id"`
        ContractId              int       `json:"contractId" gorm:"column:contract_id;type:int;comment:合同id"`
        QuotationId             int       `json:"quotationId" gorm:"column:quotation_id;type:int;comment:报价单id"`
        TypeId                  int       `json:"typeId" gorm:"column:type_id;type:int;comment:合同类型id"`
        ServiceContractTypeId   int       `json:"serviceContractTypeId" gorm:"column:service_contract_type_id;type:int;comment:合同类型id"`
        SignTime                time.Time `json:"signTime" gorm:"column:sign_time;type:datetime;comment:签约时间"`
        StartTime               time.Time `json:"startTime" gorm:"column:start_time;type:datetime;comment:开始时间"`
        EndTime                 time.Time `json:"endTime" gorm:"column:end_time;type:datetime;comment:结束时间"`
pkg/ecode/code.go
@@ -335,4 +335,11 @@
    ServiceContractStatusSetErr    = 4400004 // 设置服务合同状态失败
    ServiceContractStatusUpdateErr = 4400005 // 更新服务合同状态失败
    ServiceContractTypeExist     = 4400001 // 服务合同类型已存在
    ServiceContractTypeNotExist  = 4400002 // 服务合同类型不存在
    ServiceContractTypeListErr   = 4400003 // 获取服务合同类型列表失败
    ServiceContractTypeSetErr    = 4400004 // 设置服务合同类型失败
    ServiceContractTypeUpdateErr = 4400005 // 更新服务合同类型失败
)
router/index.go
@@ -11,6 +11,7 @@
)
type Group struct {
    ServiceContractTypeRouter
    ServiceContractStatusRouter
    OrderTypeRouter
    ReportSourceRouter
@@ -141,6 +142,7 @@
        routerGroup.InitReportSourceRouter(PrivateGroup)
        routerGroup.InitOrderTypeRouter(PrivateGroup)
        routerGroup.InitServiceContractStatusRouter(PrivateGroup)
        routerGroup.InitServiceContractTypeRouter(PrivateGroup)
    }
    return Router
}
router/serviceContractType.go
New file
@@ -0,0 +1,20 @@
package router
import (
    v1 "aps_crm/api/v1"
    "github.com/gin-gonic/gin"
)
type ServiceContractTypeRouter struct{}
func (s *ServiceContractTypeRouter) InitServiceContractTypeRouter(router *gin.RouterGroup) {
    serviceContractTypeRouter := router.Group("serviceContractType")
    serviceContractTypeApi := v1.ApiGroup.ServiceContractTypeApi
    {
        serviceContractTypeRouter.POST("add", serviceContractTypeApi.Add)             // 添加$CName$
        serviceContractTypeRouter.DELETE("delete/:id", serviceContractTypeApi.Delete) // 删除$CName$
        serviceContractTypeRouter.PUT("update", serviceContractTypeApi.Update)        // 更新$CName$
        serviceContractTypeRouter.GET("list", serviceContractTypeApi.List)            // 获取$CName$列表
    }
}
service/dataServer.go
@@ -111,6 +111,11 @@
    data.ServiceContractStatus = serviceContractStatusList
    // get ServiceContractType list
    serviceContractTypeList, _ := ServiceGroup.GetServiceContractTypeList()
    data.ServiceContractType = serviceContractTypeList
    errCode = ecode.OK
    return
service/index.go
@@ -52,6 +52,7 @@
    ReportSourceService
    OrderTypeService
    ServiceContractStatusService
    ServiceContractTypeService
}
var ServiceGroup = new(Group)
service/serviceContractType.go
New file
@@ -0,0 +1,69 @@
package service
import (
    "aps_crm/model"
    "aps_crm/model/request"
    "aps_crm/pkg/ecode"
)
type ServiceContractTypeService struct{}
func (ServiceContractTypeService) AddServiceContractType(serviceContractType *model.ServiceContractType) int {
    err := model.NewServiceContractTypeSearch().Create(serviceContractType)
    if err != nil {
        return ecode.ServiceContractTypeExist
    }
    return ecode.OK
}
func (ServiceContractTypeService) DeleteServiceContractType(id int) int {
    _, err := model.NewServiceContractTypeSearch().SetId(id).Find()
    if err != nil {
        return ecode.ServiceContractTypeNotExist
    }
    err = model.NewServiceContractTypeSearch().SetId(id).Delete()
    if err != nil {
        return ecode.ServiceContractTypeNotExist
    }
    return ecode.OK
}
func (ServiceContractTypeService) GetServiceContractTypeList() ([]*model.ServiceContractType, int) {
    list, err := model.NewServiceContractTypeSearch().FindAll()
    if err != nil {
        return nil, ecode.ServiceContractTypeListErr
    }
    return list, ecode.OK
}
func (ServiceContractTypeService) UpdateServiceContractType(serviceContractTypes []*request.UpdateServiceContractType) int {
    for _, v := range serviceContractTypes {
        // check serviceContractType exist
        _, err := model.NewServiceContractTypeSearch().SetId(v.Id).Find()
        if err != nil {
            return ecode.ServiceContractTypeNotExist
        }
        err = model.NewServiceContractTypeSearch().SetId(v.Id).Updates(map[string]interface{}{
            "name": v.Name,
        })
        if err != nil {
            return ecode.ServiceContractTypeSetErr
        }
    }
    return ecode.OK
}
func (ServiceContractTypeService) GetServiceContractTypeDetail(id int) (*model.ServiceContractType, int) {
    serviceContractType, err := model.NewServiceContractTypeSearch().SetId(id).Find()
    if err != nil {
        return nil, ecode.ServiceContractTypeNotExist
    }
    return serviceContractType, ecode.OK
}