From ac5468a5ce91c4a9ba7c9610c6bef78e24bf6dce Mon Sep 17 00:00:00 2001
From: wangpengfei <274878379@qq.com>
Date: 星期一, 10 七月 2023 11:14:18 +0800
Subject: [PATCH] add
---
api/v1/index.go | 2
model/saleChance.go | 2
pkg/ecode/code.go | 7
docs/swagger.yaml | 115 ++++++++
docs/docs.go | 183 +++++++++++++
router/possibilities.go | 19 +
docs/swagger.json | 183 +++++++++++++
model/possibilities.go | 86 ++++++
model/response/response.go | 4
model/request/possibility.go | 14 +
api/v1/saleChance.go | 2
service/possibilities.go | 59 ++++
service/index.go | 1
model/index.go | 1
api/v1/possibilities.go | 110 +++++++
logs/aps-admin.err.log | 1
router/index.go | 2
17 files changed, 786 insertions(+), 5 deletions(-)
diff --git a/api/v1/index.go b/api/v1/index.go
index febef50..3c575ef 100644
--- a/api/v1/index.go
+++ b/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
)
diff --git a/api/v1/possibilities.go b/api/v1/possibilities.go
new file mode 100644
index 0000000..66cc1dd
--- /dev/null
+++ b/api/v1/possibilities.go
@@ -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, ¶ms)
+ 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, ¶ms)
+ 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})
+}
diff --git a/api/v1/saleChance.go b/api/v1/saleChance.go
index 72438f3..7e91845 100644
--- a/api/v1/saleChance.go
+++ b/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)
diff --git a/docs/docs.go b/docs/docs.go
index 4200359..e2eca69 100644
--- a/docs/docs.go
+++ b/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": {
diff --git a/docs/swagger.json b/docs/swagger.json
index 16de0c0..6f711d6 100644
--- a/docs/swagger.json
+++ b/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": {
diff --git a/docs/swagger.yaml b/docs/swagger.yaml
index 55dbd57..219a2f8 100644
--- a/docs/swagger.yaml
+++ b/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:
diff --git a/logs/aps-admin.err.log b/logs/aps-admin.err.log
index 734c0c9..ff4e4b6 100644
--- a/logs/aps-admin.err.log
+++ b/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')"}
diff --git a/model/index.go b/model/index.go
index 7f7b1bc..27988b4 100644
--- a/model/index.go
+++ b/model/index.go
@@ -44,6 +44,7 @@
SaleStage{},
SaleType{},
RegularCustomers{},
+ Possibility{},
)
return err
}
diff --git a/model/possibilities.go b/model/possibilities.go
new file mode 100644
index 0000000..ae0dce8
--- /dev/null
+++ b/model/possibilities.go
@@ -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
+}
diff --git a/model/request/possibility.go b/model/request/possibility.go
new file mode 100644
index 0000000..6f96821
--- /dev/null
+++ b/model/request/possibility.go
@@ -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"`
+}
diff --git a/model/response/response.go b/model/response/response.go
index d298bb2..71e7f48 100644
--- a/model/response/response.go
+++ b/model/response/response.go
@@ -113,4 +113,8 @@
RegularCustomersResponse struct {
List []*model.RegularCustomers `json:"list"`
}
+
+ PossibilityResponse struct {
+ List []*model.Possibility `json:"list"`
+ }
)
diff --git a/model/saleChance.go b/model/saleChance.go
index 2bc6a2b..40f3d40 100644
--- a/model/saleChance.go
+++ b/model/saleChance.go
@@ -20,7 +20,7 @@
MemberId int `json:"member_id" gorm:"column:member_id;type:int(11);comment:閿�鍞礋璐d汉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:鍙兘鎬D"`
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:璐у竵绫诲瀷"`
diff --git a/pkg/ecode/code.go b/pkg/ecode/code.go
index 4fefc1f..1307751 100644
--- a/pkg/ecode/code.go
+++ b/pkg/ecode/code.go
@@ -163,4 +163,11 @@
RegularCustomersUpdateErr = 2200005 // 鏇存柊鍥哄畾瀹㈡埛澶辫触
RegularCustomersDeleteErr = 2200006 // 鍒犻櫎鍥哄畾瀹㈡埛澶辫触
+ PossibilityExist = 2300001 // 閿�鍞満浼氬彲鑳芥�у凡瀛樺湪
+ PossibilityNotExist = 2300002 // 閿�鍞満浼氬彲鑳芥�т笉瀛樺湪
+ PossibilityListErr = 2300003 // 鑾峰彇閿�鍞満浼氬彲鑳芥�у垪琛ㄥけ璐�
+ PossibilitySetErr = 2300004 // 璁剧疆閿�鍞満浼氬彲鑳芥�уけ璐�
+ PossibilityUpdateErr = 2300005 // 鏇存柊閿�鍞満浼氬彲鑳芥�уけ璐�
+ PossibilityDeleteErr = 2300006 // 鍒犻櫎閿�鍞満浼氬彲鑳芥�уけ璐�
+
)
diff --git a/router/index.go b/router/index.go
index 8787204..52471eb 100644
--- a/router/index.go
+++ b/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
}
diff --git a/router/possibilities.go b/router/possibilities.go
new file mode 100644
index 0000000..ab50e99
--- /dev/null
+++ b/router/possibilities.go
@@ -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) // 鑾峰彇閿�鍞嚎绱㈠垪琛�
+ }
+}
diff --git a/service/index.go b/service/index.go
index c5091d2..60ed2a6 100644
--- a/service/index.go
+++ b/service/index.go
@@ -24,6 +24,7 @@
SaleStageService
SaleTypeService
RegularCustomersService
+ PossibilityService
}
var ServiceGroup = new(Group)
diff --git a/service/possibilities.go b/service/possibilities.go
new file mode 100644
index 0000000..cb05d9c
--- /dev/null
+++ b/service/possibilities.go
@@ -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
+}
--
Gitblit v1.8.0