From 5d2b172ae64789fc371afa8eb14a3ef2c0ba90ab Mon Sep 17 00:00:00 2001 From: wangpengfei <274878379@qq.com> Date: 星期三, 12 七月 2023 16:49:25 +0800 Subject: [PATCH] add --- api/v1/index.go | 2 api/v1/plan.go | 155 +++++++++ model/plan.go | 82 +++++ pkg/ecode/code.go | 7 docs/swagger.yaml | 142 ++++++++ docs/docs.go | 225 ++++++++++++++ docs/swagger.json | 225 ++++++++++++++ model/response/response.go | 4 model/request/plan.go | 22 + service/index.go | 1 service/plan.go | 54 +++ model/index.go | 1 router/index.go | 2 router/plan.go | 19 + 14 files changed, 941 insertions(+), 0 deletions(-) diff --git a/api/v1/index.go b/api/v1/index.go index e183aea..e3b75f6 100644 --- a/api/v1/index.go +++ b/api/v1/index.go @@ -38,6 +38,7 @@ SalesReturnApi SalesRefundApi ContractApi + PlanApi } var ApiGroup = new(Group) @@ -75,4 +76,5 @@ salesReturnService = service.ServiceGroup.SalesReturnService salesRefundService = service.ServiceGroup.SalesRefundService contractService = service.ServiceGroup.ContractService + planService = service.ServiceGroup.PlanService ) diff --git a/api/v1/plan.go b/api/v1/plan.go new file mode 100644 index 0000000..7fe3265 --- /dev/null +++ b/api/v1/plan.go @@ -0,0 +1,155 @@ +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 PlanApi struct{} + +// Add +// +// @Tags Plan +// @Summary 娣诲姞璁″垝 +// @Produce application/json +// @Param object body request.AddPlan true "鏌ヨ鍙傛暟" +// @Success 200 {object} contextx.Response{} +// @Router /api/plan/add [post] +func (s *PlanApi) Add(c *gin.Context) { + var params request.AddPlan + ctx, ok := contextx.NewContext(c, ¶ms) + if !ok { + return + } + + errCode, plan := checkPlanParams(params.Plan) + if errCode != ecode.OK { + ctx.Fail(errCode) + return + } + + errCode = planService.AddPlan(&plan) + if errCode != ecode.OK { + ctx.Fail(errCode) + return + } + + ctx.Ok() +} + +// Delete +// +// @Tags Plan +// @Summary 鍒犻櫎璁″垝 +// @Produce application/json +// @Param id path int true "鏌ヨ鍙傛暟" +// @Success 200 {object} contextx.Response{} +// @Router /api/plan/delete/{id} [delete] +func (s *PlanApi) Delete(c *gin.Context) { + ctx, ok := contextx.NewContext(c, nil) + if !ok { + return + } + + id, _ := strconv.Atoi(c.Param("id")) + errCode := planService.DeletePlan(id) + if errCode != ecode.OK { + ctx.Fail(errCode) + return + } + + ctx.Ok() +} + +// Update +// +// @Tags Plan +// @Summary 鏇存柊璁″垝 +// @Produce application/json +// @Param object body request.UpdatePlan true "鏌ヨ鍙傛暟" +// @Success 200 {object} contextx.Response{} +// @Router /api/plan/update [put] +func (s *PlanApi) Update(c *gin.Context) { + var params request.UpdatePlan + ctx, ok := contextx.NewContext(c, ¶ms) + if !ok { + return + } + + errCode, plan := checkPlanParams(params.Plan) + if errCode != ecode.OK { + ctx.Fail(errCode) + return + } + + errCode = planService.UpdatePlan(&plan) + if errCode != ecode.OK { + ctx.Fail(errCode) + return + } + + ctx.Ok() +} + +// List +// +// @Tags Plan +// @Summary 鑾峰彇璁″垝鍒楄〃 +// @Produce application/json +// @Success 200 {object} contextx.Response{data=response.PlanResponse} +// @Router /api/plan/list [get] +func (s *PlanApi) List(c *gin.Context) { + ctx, ok := contextx.NewContext(c, nil) + if !ok { + return + } + + list, errCode := planService.GetPlanList() + if errCode != ecode.OK { + ctx.Fail(errCode) + return + } + + ctx.OkWithDetailed(response.PlanResponse{ + List: list, + }) +} + +func checkPlanParams(plan request.Plan) (errCode int, p model.Plan) { + if plan.Number == "" { + return ecode.InvalidParams, p + } + + if plan.MemberId == 0 { + return ecode.InvalidParams, p + } + + t, err := checkTimeFormat(plan.StartTime) + if err != nil { + return ecode.InvalidParams, p + } + + p.StartTime = t + + t, err = checkTimeFormat(plan.EndTime) + if err != nil { + return ecode.InvalidParams, p + } + + p.EndTime = t + + p.ClientId = plan.ClientId + p.Number = plan.Number + p.MemberId = plan.MemberId + p.SubOrderId = plan.SubOrderId + p.SalesDetailsId = plan.SalesDetailsId + p.Content = plan.Content + p.File = plan.File + + return ecode.OK, p +} diff --git a/docs/docs.go b/docs/docs.go index e61468e..6c4e9ba 100644 --- a/docs/docs.go +++ b/docs/docs.go @@ -1818,6 +1818,125 @@ } } }, + "/api/plan/add": { + "post": { + "produces": [ + "application/json" + ], + "tags": [ + "Plan" + ], + "summary": "娣诲姞璁″垝", + "parameters": [ + { + "description": "鏌ヨ鍙傛暟", + "name": "object", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/request.AddPlan" + } + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/contextx.Response" + } + } + } + } + }, + "/api/plan/delete/{id}": { + "delete": { + "produces": [ + "application/json" + ], + "tags": [ + "Plan" + ], + "summary": "鍒犻櫎璁″垝", + "parameters": [ + { + "type": "integer", + "description": "鏌ヨ鍙傛暟", + "name": "id", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/contextx.Response" + } + } + } + } + }, + "/api/plan/list": { + "get": { + "produces": [ + "application/json" + ], + "tags": [ + "Plan" + ], + "summary": "鑾峰彇璁″垝鍒楄〃", + "responses": { + "200": { + "description": "OK", + "schema": { + "allOf": [ + { + "$ref": "#/definitions/contextx.Response" + }, + { + "type": "object", + "properties": { + "data": { + "$ref": "#/definitions/response.PlanResponse" + } + } + } + ] + } + } + } + } + }, + "/api/plan/update": { + "put": { + "produces": [ + "application/json" + ], + "tags": [ + "Plan" + ], + "summary": "鏇存柊璁″垝", + "parameters": [ + { + "description": "鏌ヨ鍙傛暟", + "name": "object", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/request.UpdatePlan" + } + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/contextx.Response" + } + } + } + } + }, "/api/possibility/add": { "post": { "produces": [ @@ -4409,6 +4528,9 @@ "number": { "type": "string" }, + "quotation": { + "$ref": "#/definitions/model.Quotation" + }, "quotationId": { "type": "integer" }, @@ -4540,6 +4662,47 @@ }, "start_time": { "type": "string" + } + } + }, + "model.Plan": { + "type": "object", + "properties": { + "clientId": { + "type": "integer" + }, + "content": { + "type": "string" + }, + "endTime": { + "type": "string" + }, + "file": { + "type": "string" + }, + "id": { + "type": "integer" + }, + "memberId": { + "type": "integer" + }, + "number": { + "type": "string" + }, + "salesDetails": { + "$ref": "#/definitions/model.SalesDetails" + }, + "salesDetailsId": { + "type": "integer" + }, + "startTime": { + "type": "string" + }, + "subOrder": { + "$ref": "#/definitions/model.SubOrder" + }, + "subOrderId": { + "type": "integer" } } }, @@ -5382,6 +5545,14 @@ } } }, + "request.AddPlan": { + "type": "object", + "properties": { + "plan": { + "$ref": "#/definitions/request.Plan" + } + } + }, "request.AddPossibility": { "type": "object", "required": [ @@ -5896,6 +6067,38 @@ "username": { "description": "鐢ㄦ埛鍚�", "type": "string" + } + } + }, + "request.Plan": { + "type": "object", + "properties": { + "clientId": { + "type": "integer" + }, + "content": { + "type": "string" + }, + "endTime": { + "type": "string" + }, + "file": { + "type": "string" + }, + "memberId": { + "type": "integer" + }, + "number": { + "type": "string" + }, + "salesDetailsId": { + "type": "integer" + }, + "startTime": { + "type": "string" + }, + "subOrderId": { + "type": "integer" } } }, @@ -6579,6 +6782,17 @@ }, "start_time": { "type": "string" + } + } + }, + "request.UpdatePlan": { + "type": "object", + "properties": { + "id": { + "type": "integer" + }, + "plan": { + "$ref": "#/definitions/request.Plan" } } }, @@ -7286,6 +7500,17 @@ } } }, + "response.PlanResponse": { + "type": "object", + "properties": { + "list": { + "type": "array", + "items": { + "$ref": "#/definitions/model.Plan" + } + } + } + }, "response.PossibilityResponse": { "type": "object", "properties": { diff --git a/docs/swagger.json b/docs/swagger.json index 3b8054d..36036ed 100644 --- a/docs/swagger.json +++ b/docs/swagger.json @@ -1806,6 +1806,125 @@ } } }, + "/api/plan/add": { + "post": { + "produces": [ + "application/json" + ], + "tags": [ + "Plan" + ], + "summary": "娣诲姞璁″垝", + "parameters": [ + { + "description": "鏌ヨ鍙傛暟", + "name": "object", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/request.AddPlan" + } + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/contextx.Response" + } + } + } + } + }, + "/api/plan/delete/{id}": { + "delete": { + "produces": [ + "application/json" + ], + "tags": [ + "Plan" + ], + "summary": "鍒犻櫎璁″垝", + "parameters": [ + { + "type": "integer", + "description": "鏌ヨ鍙傛暟", + "name": "id", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/contextx.Response" + } + } + } + } + }, + "/api/plan/list": { + "get": { + "produces": [ + "application/json" + ], + "tags": [ + "Plan" + ], + "summary": "鑾峰彇璁″垝鍒楄〃", + "responses": { + "200": { + "description": "OK", + "schema": { + "allOf": [ + { + "$ref": "#/definitions/contextx.Response" + }, + { + "type": "object", + "properties": { + "data": { + "$ref": "#/definitions/response.PlanResponse" + } + } + } + ] + } + } + } + } + }, + "/api/plan/update": { + "put": { + "produces": [ + "application/json" + ], + "tags": [ + "Plan" + ], + "summary": "鏇存柊璁″垝", + "parameters": [ + { + "description": "鏌ヨ鍙傛暟", + "name": "object", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/request.UpdatePlan" + } + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/contextx.Response" + } + } + } + } + }, "/api/possibility/add": { "post": { "produces": [ @@ -4397,6 +4516,9 @@ "number": { "type": "string" }, + "quotation": { + "$ref": "#/definitions/model.Quotation" + }, "quotationId": { "type": "integer" }, @@ -4528,6 +4650,47 @@ }, "start_time": { "type": "string" + } + } + }, + "model.Plan": { + "type": "object", + "properties": { + "clientId": { + "type": "integer" + }, + "content": { + "type": "string" + }, + "endTime": { + "type": "string" + }, + "file": { + "type": "string" + }, + "id": { + "type": "integer" + }, + "memberId": { + "type": "integer" + }, + "number": { + "type": "string" + }, + "salesDetails": { + "$ref": "#/definitions/model.SalesDetails" + }, + "salesDetailsId": { + "type": "integer" + }, + "startTime": { + "type": "string" + }, + "subOrder": { + "$ref": "#/definitions/model.SubOrder" + }, + "subOrderId": { + "type": "integer" } } }, @@ -5370,6 +5533,14 @@ } } }, + "request.AddPlan": { + "type": "object", + "properties": { + "plan": { + "$ref": "#/definitions/request.Plan" + } + } + }, "request.AddPossibility": { "type": "object", "required": [ @@ -5884,6 +6055,38 @@ "username": { "description": "鐢ㄦ埛鍚�", "type": "string" + } + } + }, + "request.Plan": { + "type": "object", + "properties": { + "clientId": { + "type": "integer" + }, + "content": { + "type": "string" + }, + "endTime": { + "type": "string" + }, + "file": { + "type": "string" + }, + "memberId": { + "type": "integer" + }, + "number": { + "type": "string" + }, + "salesDetailsId": { + "type": "integer" + }, + "startTime": { + "type": "string" + }, + "subOrderId": { + "type": "integer" } } }, @@ -6567,6 +6770,17 @@ }, "start_time": { "type": "string" + } + } + }, + "request.UpdatePlan": { + "type": "object", + "properties": { + "id": { + "type": "integer" + }, + "plan": { + "$ref": "#/definitions/request.Plan" } } }, @@ -7274,6 +7488,17 @@ } } }, + "response.PlanResponse": { + "type": "object", + "properties": { + "list": { + "type": "array", + "items": { + "$ref": "#/definitions/model.Plan" + } + } + } + }, "response.PossibilityResponse": { "type": "object", "properties": { diff --git a/docs/swagger.yaml b/docs/swagger.yaml index 83d99fd..2452796 100644 --- a/docs/swagger.yaml +++ b/docs/swagger.yaml @@ -278,6 +278,8 @@ type: integer number: type: string + quotation: + $ref: '#/definitions/model.Quotation' quotationId: type: integer statusId: @@ -364,6 +366,33 @@ type: string start_time: type: string + type: object + model.Plan: + properties: + clientId: + type: integer + content: + type: string + endTime: + type: string + file: + type: string + id: + type: integer + memberId: + type: integer + number: + type: string + salesDetails: + $ref: '#/definitions/model.SalesDetails' + salesDetailsId: + type: integer + startTime: + type: string + subOrder: + $ref: '#/definitions/model.SubOrder' + subOrderId: + type: integer type: object model.Possibility: properties: @@ -928,6 +957,11 @@ start_time: type: string type: object + request.AddPlan: + properties: + plan: + $ref: '#/definitions/request.Plan' + type: object request.AddPossibility: properties: name: @@ -1278,6 +1312,27 @@ username: description: 鐢ㄦ埛鍚� type: string + type: object + request.Plan: + properties: + clientId: + type: integer + content: + type: string + endTime: + type: string + file: + type: string + memberId: + type: integer + number: + type: string + salesDetailsId: + type: integer + startTime: + type: string + subOrderId: + type: integer type: object request.Register: properties: @@ -1744,6 +1799,13 @@ start_time: type: string type: object + request.UpdatePlan: + properties: + id: + type: integer + plan: + $ref: '#/definitions/request.Plan' + type: object request.UpdatePossibilities: properties: possibilities: @@ -2206,6 +2268,13 @@ type: integer total: type: integer + type: object + response.PlanResponse: + properties: + list: + items: + $ref: '#/definitions/model.Plan' + type: array type: object response.PossibilityResponse: properties: @@ -3406,6 +3475,79 @@ summary: 鏇存柊涓昏鍗� tags: - MasterOrder + /api/plan/add: + post: + parameters: + - description: 鏌ヨ鍙傛暟 + in: body + name: object + required: true + schema: + $ref: '#/definitions/request.AddPlan' + produces: + - application/json + responses: + "200": + description: OK + schema: + $ref: '#/definitions/contextx.Response' + summary: 娣诲姞璁″垝 + tags: + - Plan + /api/plan/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: + - Plan + /api/plan/list: + get: + produces: + - application/json + responses: + "200": + description: OK + schema: + allOf: + - $ref: '#/definitions/contextx.Response' + - properties: + data: + $ref: '#/definitions/response.PlanResponse' + type: object + summary: 鑾峰彇璁″垝鍒楄〃 + tags: + - Plan + /api/plan/update: + put: + parameters: + - description: 鏌ヨ鍙傛暟 + in: body + name: object + required: true + schema: + $ref: '#/definitions/request.UpdatePlan' + produces: + - application/json + responses: + "200": + description: OK + schema: + $ref: '#/definitions/contextx.Response' + summary: 鏇存柊璁″垝 + tags: + - Plan /api/possibility/add: post: parameters: diff --git a/model/index.go b/model/index.go index 26b4bab..2002ea9 100644 --- a/model/index.go +++ b/model/index.go @@ -54,6 +54,7 @@ SalesReturn{}, SalesRefund{}, Contract{}, + Plan{}, ) return err } diff --git a/model/plan.go b/model/plan.go new file mode 100644 index 0000000..3046ef9 --- /dev/null +++ b/model/plan.go @@ -0,0 +1,82 @@ +package model + +import ( + "aps_crm/pkg/mysqlx" + "gorm.io/gorm" + "time" +) + +type ( + Plan struct { + Id int `json:"id" gorm:"column:id;primary_key;AUTO_INCREMENT"` + ClientId int `json:"clientId" gorm:"column:client_id;type:int;comment:瀹㈡埛id"` + Number string `json:"number" gorm:"column:number;type:varchar(255);comment:鍗曟嵁缂栧彿"` + MemberId int `json:"memberId" gorm:"column:member_id;type:int;comment:璐熻矗浜篿d"` + SubOrderId int `json:"subOrderId" gorm:"column:sub_order_id;type:int;comment:瀛愯鍗昳d"` + SubOrder SubOrder `json:"subOrder" gorm:"foreignKey:SubOrderId"` + SalesDetailsId int `json:"salesDetailsId" gorm:"column:sales_details_id;type:int;comment:閿�鍞槑缁唅d"` + SalesDetails SalesDetails `json:"salesDetails" gorm:"foreignKey:SalesDetailsId"` + StartTime time.Time `json:"startTime" gorm:"column:start_time;type:datetime;comment:寮�濮嬫椂闂�"` + EndTime time.Time `json:"endTime" gorm:"column:end_time;type:datetime;comment:缁撴潫鏃堕棿"` + Content string `json:"content" gorm:"column:content;type:varchar(255);comment:璁″垝鍐呭"` + File string `json:"file" gorm:"column:file;type:varchar(255);comment:闄勪欢"` + } + + PlanSearch struct { + Plan + Orm *gorm.DB + } +) + +func (Plan) TableName() string { + return "plan" +} + +func NewPlanSearch() *PlanSearch { + return &PlanSearch{ + Orm: mysqlx.GetDB(), + } +} + +func (slf *PlanSearch) build() *gorm.DB { + var db = slf.Orm.Model(&Plan{}) + if slf.Id != 0 { + db = db.Where("id = ?", slf.Id) + } + + return db +} + +func (slf *PlanSearch) Create(record *Plan) error { + var db = slf.build() + return db.Create(record).Error +} + +func (slf *PlanSearch) Delete() error { + var db = slf.build() + return db.Delete(&Plan{}).Error +} + +func (slf *PlanSearch) Update(record *Plan) error { + var db = slf.build() + return db.Updates(record).Error +} + +func (slf *PlanSearch) Find() (*Plan, error) { + var db = slf.build() + var record = &Plan{} + err := db.First(record).Error + return record, err +} + +func (slf *PlanSearch) FindAll() ([]*Plan, error) { + var db = slf.build() + var record = make([]*Plan, 0) + err := db.Find(&record).Error + return record, err +} + +func (slf *PlanSearch) SetId(id int) *PlanSearch { + slf.Id = id + return slf +} diff --git a/model/request/plan.go b/model/request/plan.go new file mode 100644 index 0000000..f262cec --- /dev/null +++ b/model/request/plan.go @@ -0,0 +1,22 @@ +package request + +type AddPlan struct { + Plan Plan `json:"plan"` +} + +type Plan struct { + ClientId int `json:"clientId"` + Number string `json:"number"` + MemberId int `json:"memberId"` + SubOrderId int `json:"subOrderId"` + SalesDetailsId int `json:"salesDetailsId"` + StartTime string `json:"startTime"` + EndTime string `json:"endTime"` + Content string `json:"content"` + File string `json:"file"` +} + +type UpdatePlan struct { + Id int `json:"id"` + Plan Plan `json:"plan"` +} diff --git a/model/response/response.go b/model/response/response.go index 8ce4fc0..8a41e2d 100644 --- a/model/response/response.go +++ b/model/response/response.go @@ -149,4 +149,8 @@ ContractResponse struct { List []*model.Contract `json:"list"` } + + PlanResponse struct { + List []*model.Plan `json:"list"` + } ) diff --git a/pkg/ecode/code.go b/pkg/ecode/code.go index 9e9f0de..c895394 100644 --- a/pkg/ecode/code.go +++ b/pkg/ecode/code.go @@ -225,4 +225,11 @@ ContractSetErr = 3100004 // 璁剧疆鍚堝悓澶辫触 ContractUpdateErr = 3100005 // 鏇存柊鍚堝悓澶辫触 ContractDeleteErr = 3100006 // 鍒犻櫎鍚堝悓澶辫触 + + PlanExist = 3200001 // 璁″垝宸插瓨鍦� + PlanNotExist = 3200002 // 璁″垝涓嶅瓨鍦� + PlanListErr = 3200003 // 鑾峰彇璁″垝鍒楄〃澶辫触 + PlanSetErr = 3200004 // 璁剧疆璁″垝澶辫触 + PlanUpdateErr = 3200005 // 鏇存柊璁″垝澶辫触 + PlanDeleteErr = 3200006 // 鍒犻櫎璁″垝澶辫触 ) diff --git a/router/index.go b/router/index.go index 81035c8..7e4ef85 100644 --- a/router/index.go +++ b/router/index.go @@ -44,6 +44,7 @@ SalesReturnRouter SalesRefundRouter ContractRouter + PlanRouter } func InitRouter() *gin.Engine { @@ -105,6 +106,7 @@ routerGroup.InitSalesReturnRouter(PrivateGroup) // 娉ㄥ唽salesReturn璺敱 routerGroup.InitSalesRefundRouter(PrivateGroup) // 娉ㄥ唽salesRefund璺敱 routerGroup.InitContractRouter(PrivateGroup) // 娉ㄥ唽contract璺敱 + routerGroup.InitPlanRouter(PrivateGroup) // 娉ㄥ唽plan璺敱 } return Router } diff --git a/router/plan.go b/router/plan.go new file mode 100644 index 0000000..e0b3923 --- /dev/null +++ b/router/plan.go @@ -0,0 +1,19 @@ +package router + +import ( + v1 "aps_crm/api/v1" + "github.com/gin-gonic/gin" +) + +type PlanRouter struct{} + +func (p *PlanRouter) InitPlanRouter(router *gin.RouterGroup) { + planRouter := router.Group("plan") + planApi := v1.ApiGroup.PlanApi + { + planRouter.POST("add", planApi.Add) // 娣诲姞璁″垝 + planRouter.DELETE("delete/:id", planApi.Delete) // 鍒犻櫎璁″垝 + planRouter.PUT("update", planApi.Update) // 鏇存柊璁″垝 + planRouter.GET("list", planApi.List) // 鑾峰彇璁″垝鍒楄〃 + } +} diff --git a/service/index.go b/service/index.go index e387979..4116a99 100644 --- a/service/index.go +++ b/service/index.go @@ -33,6 +33,7 @@ SalesReturnService SalesRefundService ContractService + PlanService } var ServiceGroup = new(Group) diff --git a/service/plan.go b/service/plan.go new file mode 100644 index 0000000..9e175fb --- /dev/null +++ b/service/plan.go @@ -0,0 +1,54 @@ +package service + +import ( + "aps_crm/model" + "aps_crm/pkg/ecode" +) + +type PlanService struct{} + +func (PlanService) AddPlan(plan *model.Plan) int { + err := model.NewPlanSearch().Create(plan) + if err != nil { + return ecode.PlanExist + } + + return ecode.OK +} + +func (PlanService) DeletePlan(id int) int { + _, err := model.NewPlanSearch().SetId(id).Find() + if err != nil { + return ecode.PlanNotExist + } + + err = model.NewPlanSearch().SetId(id).Delete() + if err != nil { + return ecode.PlanNotExist + } + return ecode.OK +} + +func (PlanService) GetPlanList() ([]*model.Plan, int) { + list, err := model.NewPlanSearch().FindAll() + if err != nil { + return nil, ecode.PlanListErr + } + + return list, ecode.OK +} + +func (PlanService) UpdatePlan(plan *model.Plan) int { + // check plan exist + _, err := model.NewPlanSearch().SetId(plan.Id).Find() + if err != nil { + return ecode.PlanNotExist + } + + err = model.NewPlanSearch().SetId(plan.Id).Update(plan) + if err != nil { + return ecode.PlanSetErr + } + + return ecode.OK +} -- Gitblit v1.8.0