add
wangpengfei
2023-07-10 ac5468a5ce91c4a9ba7c9610c6bef78e24bf6dce
add

Possibility 销售预测可能性
add, Delete, update, list
5个文件已添加
12个文件已修改
791 ■■■■■ 已修改文件
api/v1/index.go 2 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
api/v1/possibilities.go 110 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
api/v1/saleChance.go 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
docs/docs.go 183 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
docs/swagger.json 183 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
docs/swagger.yaml 115 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
logs/aps-admin.err.log 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
model/index.go 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
model/possibilities.go 86 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
model/request/possibility.go 14 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
model/response/response.go 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
model/saleChance.go 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
pkg/ecode/code.go 7 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
router/index.go 2 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
router/possibilities.go 19 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
service/index.go 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
service/possibilities.go 59 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
api/v1/index.go
@@ -29,6 +29,7 @@
    SaleStageApi
    SaleTypeApi
    RegularCustomersApi
    PossibilityApi
}
var ApiGroup = new(Group)
@@ -57,4 +58,5 @@
    saleStageService         = service.ServiceGroup.SaleStageService
    saleTypeService          = service.ServiceGroup.SaleTypeService
    regularCustomersService  = service.ServiceGroup.RegularCustomersService
    possibilityService       = service.ServiceGroup.PossibilityService
)
api/v1/possibilities.go
New file
@@ -0,0 +1,110 @@
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 PossibilityApi struct{}
// Add
//
//    @Tags        Possibility
//    @Summary    添加商机可能性
//    @Produce    application/json
//    @Param        object    body        request.AddPossibility    true    "查询参数"
//    @Success    200        {object}    contextx.Response{}
//    @Router        /api/possibility/add [post]
func (s *PossibilityApi) Add(c *gin.Context) {
    var params request.AddPossibility
    ctx, ok := contextx.NewContext(c, &params)
    if !ok {
        return
    }
    possibility := new(model.Possibility)
    possibility.Name = params.Name
    errCode := possibilityService.AddPossibility(possibility)
    if errCode != ecode.OK {
        ctx.Fail(errCode)
        return
    }
    ctx.Ok()
}
// Delete
//
//    @Tags        Possibility
//    @Summary    删除商机可能性
//    @Produce    application/json
//    @Param        id    path        int    true    "查询参数"
//    @Success    200    {object}    contextx.Response{}
//    @Router        /api/possibility/delete/{id} [delete]
func (s *PossibilityApi) Delete(c *gin.Context) {
    ctx, ok := contextx.NewContext(c, nil)
    if !ok {
        return
    }
    id, _ := strconv.Atoi(c.Param("id"))
    errCode := possibilityService.DeletePossibility(id)
    if errCode != ecode.OK {
        ctx.Fail(errCode)
        return
    }
    ctx.Ok()
}
// Update
//
//    @Tags        Possibility
//    @Summary    更新商机可能性
//    @Produce    application/json
//    @Param        object    body        request.UpdatePossibilities    true    "查询参数"
//    @Success    200        {object}    contextx.Response{}
//    @Router        /api/possibility/update [put]
func (s *PossibilityApi) Update(c *gin.Context) {
    var params request.UpdatePossibilities
    ctx, ok := contextx.NewContext(c, &params)
    if !ok {
        return
    }
    errCode := possibilityService.UpdatePossibility(params.Possibilities)
    if errCode != ecode.OK {
        ctx.Fail(errCode)
        return
    }
    ctx.Ok()
}
// List
//
//    @Tags        Possibility
//    @Summary    商机可能性列表
//    @Produce    application/json
//    @Success    200    {object}    contextx.Response{data=response.PossibilityResponse}
//    @Router        /api/possibility/list [get]
func (s *PossibilityApi) List(c *gin.Context) {
    ctx, ok := contextx.NewContext(c, nil)
    if !ok {
        return
    }
    possibilityList, errCode := possibilityService.GetPossibilityList()
    if errCode != ecode.OK {
        ctx.Fail(errCode)
        return
    }
    ctx.OkWithDetailed(response.PossibilityResponse{List: possibilityList})
}
api/v1/saleChance.go
@@ -183,7 +183,7 @@
    sc.MemberId = saleChance.MemberId
    sc.RegularCustomersId = saleChance.RegularCustomersId
    sc.Competitors = saleChance.Competitors
    sc.Possibilities = saleChance.Possibilities
    sc.PossibilitiesId = saleChance.Possibilities
    sc.Budget = saleChance.Budget
    sc.ProjectedAmount = saleChance.ProjectedAmount
    sc.Currency = constvar.CurrencyType(saleChance.Currency)
docs/docs.go
@@ -1580,6 +1580,125 @@
                }
            }
        },
        "/api/possibility/add": {
            "post": {
                "produces": [
                    "application/json"
                ],
                "tags": [
                    "Possibility"
                ],
                "summary": "添加商机可能性",
                "parameters": [
                    {
                        "description": "查询参数",
                        "name": "object",
                        "in": "body",
                        "required": true,
                        "schema": {
                            "$ref": "#/definitions/request.AddPossibility"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK",
                        "schema": {
                            "$ref": "#/definitions/contextx.Response"
                        }
                    }
                }
            }
        },
        "/api/possibility/delete/{id}": {
            "delete": {
                "produces": [
                    "application/json"
                ],
                "tags": [
                    "Possibility"
                ],
                "summary": "删除商机可能性",
                "parameters": [
                    {
                        "type": "integer",
                        "description": "查询参数",
                        "name": "id",
                        "in": "path",
                        "required": true
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK",
                        "schema": {
                            "$ref": "#/definitions/contextx.Response"
                        }
                    }
                }
            }
        },
        "/api/possibility/list": {
            "get": {
                "produces": [
                    "application/json"
                ],
                "tags": [
                    "Possibility"
                ],
                "summary": "商机可能性列表",
                "responses": {
                    "200": {
                        "description": "OK",
                        "schema": {
                            "allOf": [
                                {
                                    "$ref": "#/definitions/contextx.Response"
                                },
                                {
                                    "type": "object",
                                    "properties": {
                                        "data": {
                                            "$ref": "#/definitions/response.PossibilityResponse"
                                        }
                                    }
                                }
                            ]
                        }
                    }
                }
            }
        },
        "/api/possibility/update": {
            "put": {
                "produces": [
                    "application/json"
                ],
                "tags": [
                    "Possibility"
                ],
                "summary": "更新商机可能性",
                "parameters": [
                    {
                        "description": "查询参数",
                        "name": "object",
                        "in": "body",
                        "required": true,
                        "schema": {
                            "$ref": "#/definitions/request.UpdatePossibilities"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK",
                        "schema": {
                            "$ref": "#/definitions/contextx.Response"
                        }
                    }
                }
            }
        },
        "/api/province/add": {
            "post": {
                "produces": [
@@ -3444,6 +3563,17 @@
                }
            }
        },
        "model.Possibility": {
            "type": "object",
            "properties": {
                "id": {
                    "type": "integer"
                },
                "name": {
                    "type": "string"
                }
            }
        },
        "model.Province": {
            "type": "object",
            "properties": {
@@ -3566,7 +3696,7 @@
                "pain_points": {
                    "type": "string"
                },
                "possibilities": {
                "possibilities_id": {
                    "type": "integer"
                },
                "process": {
@@ -4029,6 +4159,17 @@
            }
        },
        "request.AddIndustry": {
            "type": "object",
            "required": [
                "name"
            ],
            "properties": {
                "name": {
                    "type": "string"
                }
            }
        },
        "request.AddPossibility": {
            "type": "object",
            "required": [
                "name"
@@ -4961,6 +5102,35 @@
                }
            }
        },
        "request.UpdatePossibilities": {
            "type": "object",
            "required": [
                "possibilities"
            ],
            "properties": {
                "possibilities": {
                    "type": "array",
                    "items": {
                        "$ref": "#/definitions/request.UpdatePossibility"
                    }
                }
            }
        },
        "request.UpdatePossibility": {
            "type": "object",
            "required": [
                "id",
                "name"
            ],
            "properties": {
                "id": {
                    "type": "integer"
                },
                "name": {
                    "type": "string"
                }
            }
        },
        "request.UpdateProvince": {
            "type": "object",
            "properties": {
@@ -5467,6 +5637,17 @@
                }
            }
        },
        "response.PossibilityResponse": {
            "type": "object",
            "properties": {
                "list": {
                    "type": "array",
                    "items": {
                        "$ref": "#/definitions/model.Possibility"
                    }
                }
            }
        },
        "response.ProvinceResponse": {
            "type": "object",
            "properties": {
docs/swagger.json
@@ -1568,6 +1568,125 @@
                }
            }
        },
        "/api/possibility/add": {
            "post": {
                "produces": [
                    "application/json"
                ],
                "tags": [
                    "Possibility"
                ],
                "summary": "添加商机可能性",
                "parameters": [
                    {
                        "description": "查询参数",
                        "name": "object",
                        "in": "body",
                        "required": true,
                        "schema": {
                            "$ref": "#/definitions/request.AddPossibility"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK",
                        "schema": {
                            "$ref": "#/definitions/contextx.Response"
                        }
                    }
                }
            }
        },
        "/api/possibility/delete/{id}": {
            "delete": {
                "produces": [
                    "application/json"
                ],
                "tags": [
                    "Possibility"
                ],
                "summary": "删除商机可能性",
                "parameters": [
                    {
                        "type": "integer",
                        "description": "查询参数",
                        "name": "id",
                        "in": "path",
                        "required": true
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK",
                        "schema": {
                            "$ref": "#/definitions/contextx.Response"
                        }
                    }
                }
            }
        },
        "/api/possibility/list": {
            "get": {
                "produces": [
                    "application/json"
                ],
                "tags": [
                    "Possibility"
                ],
                "summary": "商机可能性列表",
                "responses": {
                    "200": {
                        "description": "OK",
                        "schema": {
                            "allOf": [
                                {
                                    "$ref": "#/definitions/contextx.Response"
                                },
                                {
                                    "type": "object",
                                    "properties": {
                                        "data": {
                                            "$ref": "#/definitions/response.PossibilityResponse"
                                        }
                                    }
                                }
                            ]
                        }
                    }
                }
            }
        },
        "/api/possibility/update": {
            "put": {
                "produces": [
                    "application/json"
                ],
                "tags": [
                    "Possibility"
                ],
                "summary": "更新商机可能性",
                "parameters": [
                    {
                        "description": "查询参数",
                        "name": "object",
                        "in": "body",
                        "required": true,
                        "schema": {
                            "$ref": "#/definitions/request.UpdatePossibilities"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK",
                        "schema": {
                            "$ref": "#/definitions/contextx.Response"
                        }
                    }
                }
            }
        },
        "/api/province/add": {
            "post": {
                "produces": [
@@ -3432,6 +3551,17 @@
                }
            }
        },
        "model.Possibility": {
            "type": "object",
            "properties": {
                "id": {
                    "type": "integer"
                },
                "name": {
                    "type": "string"
                }
            }
        },
        "model.Province": {
            "type": "object",
            "properties": {
@@ -3554,7 +3684,7 @@
                "pain_points": {
                    "type": "string"
                },
                "possibilities": {
                "possibilities_id": {
                    "type": "integer"
                },
                "process": {
@@ -4017,6 +4147,17 @@
            }
        },
        "request.AddIndustry": {
            "type": "object",
            "required": [
                "name"
            ],
            "properties": {
                "name": {
                    "type": "string"
                }
            }
        },
        "request.AddPossibility": {
            "type": "object",
            "required": [
                "name"
@@ -4949,6 +5090,35 @@
                }
            }
        },
        "request.UpdatePossibilities": {
            "type": "object",
            "required": [
                "possibilities"
            ],
            "properties": {
                "possibilities": {
                    "type": "array",
                    "items": {
                        "$ref": "#/definitions/request.UpdatePossibility"
                    }
                }
            }
        },
        "request.UpdatePossibility": {
            "type": "object",
            "required": [
                "id",
                "name"
            ],
            "properties": {
                "id": {
                    "type": "integer"
                },
                "name": {
                    "type": "string"
                }
            }
        },
        "request.UpdateProvince": {
            "type": "object",
            "properties": {
@@ -5455,6 +5625,17 @@
                }
            }
        },
        "response.PossibilityResponse": {
            "type": "object",
            "properties": {
                "list": {
                    "type": "array",
                    "items": {
                        "$ref": "#/definitions/model.Possibility"
                    }
                }
            }
        },
        "response.ProvinceResponse": {
            "type": "object",
            "properties": {
docs/swagger.yaml
@@ -331,6 +331,13 @@
      name:
        type: string
    type: object
  model.Possibility:
    properties:
      id:
        type: integer
      name:
        type: string
    type: object
  model.Province:
    properties:
      cities:
@@ -411,7 +418,7 @@
        type: string
      pain_points:
        type: string
      possibilities:
      possibilities_id:
        type: integer
      process:
        type: string
@@ -728,6 +735,13 @@
    - follow_record
    type: object
  request.AddIndustry:
    properties:
      name:
        type: string
    required:
    - name
    type: object
  request.AddPossibility:
    properties:
      name:
        type: string
@@ -1369,6 +1383,25 @@
    - id
    - name
    type: object
  request.UpdatePossibilities:
    properties:
      possibilities:
        items:
          $ref: '#/definitions/request.UpdatePossibility'
        type: array
    required:
    - possibilities
    type: object
  request.UpdatePossibility:
    properties:
      id:
        type: integer
      name:
        type: string
    required:
    - id
    - name
    type: object
  request.UpdateProvince:
    properties:
      id:
@@ -1702,6 +1735,13 @@
        type: integer
      total:
        type: integer
    type: object
  response.PossibilityResponse:
    properties:
      list:
        items:
          $ref: '#/definitions/model.Possibility'
        type: array
    type: object
  response.ProvinceResponse:
    properties:
@@ -2721,6 +2761,79 @@
      summary: 更新行业
      tags:
      - Industry
  /api/possibility/add:
    post:
      parameters:
      - description: 查询参数
        in: body
        name: object
        required: true
        schema:
          $ref: '#/definitions/request.AddPossibility'
      produces:
      - application/json
      responses:
        "200":
          description: OK
          schema:
            $ref: '#/definitions/contextx.Response'
      summary: 添加商机可能性
      tags:
      - Possibility
  /api/possibility/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:
      - Possibility
  /api/possibility/list:
    get:
      produces:
      - application/json
      responses:
        "200":
          description: OK
          schema:
            allOf:
            - $ref: '#/definitions/contextx.Response'
            - properties:
                data:
                  $ref: '#/definitions/response.PossibilityResponse'
              type: object
      summary: 商机可能性列表
      tags:
      - Possibility
  /api/possibility/update:
    put:
      parameters:
      - description: 查询参数
        in: body
        name: object
        required: true
        schema:
          $ref: '#/definitions/request.UpdatePossibilities'
      produces:
      - application/json
      responses:
        "200":
          description: OK
          schema:
            $ref: '#/definitions/contextx.Response'
      summary: 更新商机可能性
      tags:
      - Possibility
  /api/province/add:
    post:
      parameters:
logs/aps-admin.err.log
@@ -331,3 +331,4 @@
[2023-07-06 13:52:52]    [error]    [main.main:29]    model Init err:Error 1170 (42000): BLOB/TEXT column 'name' used in key specification without a key length
[2023-07-06 13:55:26]    [error]    [gorm.io/driver/mysql.Migrator.AlterColumn.func1:59]    trace    {"error": "Error 1170 (42000): BLOB/TEXT column 'name' used in key specification without a key length", "elapsed": 0.0007354, "rows": 0, "sql": "ALTER TABLE `client_level` MODIFY COLUMN `name` longtext"}
[2023-07-06 13:55:26]    [error]    [main.main:29]    model Init err:Error 1170 (42000): BLOB/TEXT column 'name' used in key specification without a key length
[2023-07-10 11:06:33]    [error]    [aps_crm/model.(*PossibilitySearch).Create:46]    trace    {"error": "Error 1146 (42S02): Table 'aps_crm.possibility' doesn't exist", "elapsed": 0.0032687, "rows": 0, "sql": "INSERT INTO `possibility` (`name`) VALUES ('10')"}
model/index.go
@@ -44,6 +44,7 @@
        SaleStage{},
        SaleType{},
        RegularCustomers{},
        Possibility{},
    )
    return err
}
model/possibilities.go
New file
@@ -0,0 +1,86 @@
package model
import (
    "aps_crm/pkg/mysqlx"
    "gorm.io/gorm"
)
type (
    // Possibility 商机可能性
    Possibility struct {
        Id   int    `json:"id" gorm:"column:id;primary_key;AUTO_INCREMENT"`
        Name string `json:"name" gorm:"column:name;type:varchar(255);comment:商机可能性名称"`
    }
    // PossibilitySearch 商机可能性搜索条件
    PossibilitySearch struct {
        Possibility
        Orm *gorm.DB
    }
)
func (Possibility) TableName() string {
    return "possibility"
}
func NewPossibilitySearch() *PossibilitySearch {
    return &PossibilitySearch{
        Orm: mysqlx.GetDB(),
    }
}
func (slf *PossibilitySearch) build() *gorm.DB {
    var db = slf.Orm.Model(&Possibility{})
    if slf.Id != 0 {
        db = db.Where("id = ?", slf.Id)
    }
    if slf.Name != "" {
        db = db.Where("name = ?", slf.Name)
    }
    return db
}
func (slf *PossibilitySearch) Create(record *Possibility) error {
    var db = slf.build()
    return db.Create(record).Error
}
func (slf *PossibilitySearch) Delete() error {
    var db = slf.build()
    return db.Delete(&Possibility{}).Error
}
func (slf *PossibilitySearch) Update(record *Possibility) error {
    var db = slf.build()
    return db.Updates(record).Error
}
func (slf *PossibilitySearch) Find() (*Possibility, error) {
    var db = slf.build()
    var record = new(Possibility)
    err := db.First(record).Error
    return record, err
}
func (slf *PossibilitySearch) FindAll() ([]*Possibility, error) {
    var db = slf.build()
    var records = make([]*Possibility, 0)
    err := db.Find(&records).Error
    return records, err
}
func (slf *PossibilitySearch) SetId(id int) *PossibilitySearch {
    slf.Id = id
    return slf
}
func (slf *PossibilitySearch) SetName(name string) *PossibilitySearch {
    slf.Name = name
    return slf
}
func (slf *PossibilitySearch) Updates(data map[string]interface{}) error {
    var db = slf.build()
    return db.Updates(data).Error
}
model/request/possibility.go
New file
@@ -0,0 +1,14 @@
package request
type AddPossibility struct {
    Name string `json:"name" binding:"required"`
}
type UpdatePossibility struct {
    Id   int    `json:"id" binding:"required"`
    Name string `json:"name" binding:"required"`
}
type UpdatePossibilities struct {
    Possibilities []*UpdatePossibility `json:"possibilities" binding:"required"`
}
model/response/response.go
@@ -113,4 +113,8 @@
    RegularCustomersResponse struct {
        List []*model.RegularCustomers `json:"list"`
    }
    PossibilityResponse struct {
        List []*model.Possibility `json:"list"`
    }
)
model/saleChance.go
@@ -20,7 +20,7 @@
        MemberId           int                   `json:"member_id" gorm:"column:member_id;type:int(11);comment:销售负责人ID"`
        RegularCustomersId int                   `json:"regular_customers_id" gorm:"column:regular_customers_id;type:int(11);comment:常客ID"`
        Competitors        string                `json:"competitors" gorm:"column:competitors;type:varchar(255);comment:竞争对手"`
        Possibilities      int                   `json:"possibilities" gorm:"column:possibilities;type:int(11);comment:可能性"`
        PossibilitiesId    int                   `json:"possibilities_id" gorm:"column:possibilities_id;type:int(11);comment:可能性ID"`
        Budget             float64               `json:"budget" gorm:"column:budget;type:decimal(10,2);comment:预算"`
        ProjectedAmount    float64               `json:"projected_amount" gorm:"column:projected_amount;type:decimal(10,2);comment:预计金额"`
        Currency           constvar.CurrencyType `json:"currency" gorm:"column:currency;type:int(11);comment:货币类型"`
pkg/ecode/code.go
@@ -163,4 +163,11 @@
    RegularCustomersUpdateErr = 2200005 // 更新固定客户失败
    RegularCustomersDeleteErr = 2200006 // 删除固定客户失败
    PossibilityExist     = 2300001 // 销售机会可能性已存在
    PossibilityNotExist  = 2300002 // 销售机会可能性不存在
    PossibilityListErr   = 2300003 // 获取销售机会可能性列表失败
    PossibilitySetErr    = 2300004 // 设置销售机会可能性失败
    PossibilityUpdateErr = 2300005 // 更新销售机会可能性失败
    PossibilityDeleteErr = 2300006 // 删除销售机会可能性失败
)
router/index.go
@@ -35,6 +35,7 @@
    SaleStageRouter
    SaleTypeRouter
    RegularCustomersRouter
    PossibilityRouter
}
func InitRouter() *gin.Engine {
@@ -87,6 +88,7 @@
        routerGroup.InitSaleStageRouter(PrivateGroup)         // 注册saleStage路由
        routerGroup.InitSaleTypeRouter(PrivateGroup)          // 注册saleType路由
        routerGroup.InitRegularCustomersRouter(PrivateGroup)  // 注册regularCustomers路由
        routerGroup.InitPossibilityRouter(PrivateGroup)       // 注册possibility路由
    }
    return Router
}
router/possibilities.go
New file
@@ -0,0 +1,19 @@
package router
import (
    v1 "aps_crm/api/v1"
    "github.com/gin-gonic/gin"
)
type PossibilityRouter struct{}
func (p *PossibilityRouter) InitPossibilityRouter(router *gin.RouterGroup) {
    possibilityRouter := router.Group("possibility")
    possibilityApi := v1.ApiGroup.PossibilityApi
    {
        possibilityRouter.POST("add", possibilityApi.Add)             // 添加销售线索
        possibilityRouter.DELETE("delete/:id", possibilityApi.Delete) // 删除销售线索
        possibilityRouter.PUT("update", possibilityApi.Update)        // 更新销售线索
        possibilityRouter.GET("list", possibilityApi.List)            // 获取销售线索列表
    }
}
service/index.go
@@ -24,6 +24,7 @@
    SaleStageService
    SaleTypeService
    RegularCustomersService
    PossibilityService
}
var ServiceGroup = new(Group)
service/possibilities.go
New file
@@ -0,0 +1,59 @@
package service
import (
    "aps_crm/model"
    "aps_crm/model/request"
    "aps_crm/pkg/ecode"
)
type PossibilityService struct{}
func (PossibilityService) AddPossibility(possibility *model.Possibility) int {
    err := model.NewPossibilitySearch().Create(possibility)
    if err != nil {
        return ecode.PossibilityExist
    }
    return ecode.OK
}
func (PossibilityService) DeletePossibility(id int) int {
    _, err := model.NewPossibilitySearch().SetId(id).Find()
    if err != nil {
        return ecode.PossibilityNotExist
    }
    err = model.NewPossibilitySearch().SetId(id).Delete()
    if err != nil {
        return ecode.PossibilityNotExist
    }
    return ecode.OK
}
func (PossibilityService) GetPossibilityList() ([]*model.Possibility, int) {
    list, err := model.NewPossibilitySearch().FindAll()
    if err != nil {
        return nil, ecode.PossibilityListErr
    }
    return list, ecode.OK
}
func (PossibilityService) UpdatePossibility(possibilities []*request.UpdatePossibility) int {
    for _, v := range possibilities {
        // check possibility exist
        _, err := model.NewPossibilitySearch().SetId(v.Id).Find()
        if err != nil {
            return ecode.PossibilityNotExist
        }
        err = model.NewPossibilitySearch().SetId(v.Id).Updates(map[string]interface{}{
            "name": v.Name,
        })
        if err != nil {
            return ecode.PossibilitySetErr
        }
    }
    return ecode.OK
}