From b54c384d9bb8bec57e0c480d4d65716a3b799370 Mon Sep 17 00:00:00 2001 From: wangpengfei <274878379@qq.com> Date: 星期四, 20 七月 2023 17:24:17 +0800 Subject: [PATCH] add --- api/v1/satisfaction.go | 112 ++++++++ api/v1/serviceFeeManage.go | 14 model/satisfaction.go | 79 +++++ pkg/ecode/code.go | 5 docs/swagger.yaml | 119 ++++++++ docs/docs.go | 190 +++++++++++++ docs/swagger.json | 190 +++++++++++++ model/response/response.go | 4 router/satisfaction.go | 19 + service/satisfaction.go | 59 ++++ model/request/satisfaction.go | 14 + service/index.go | 1 model/index.go | 1 router/index.go | 2 14 files changed, 806 insertions(+), 3 deletions(-) diff --git a/api/v1/satisfaction.go b/api/v1/satisfaction.go new file mode 100644 index 0000000..5f96bfc --- /dev/null +++ b/api/v1/satisfaction.go @@ -0,0 +1,112 @@ +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 SatisfactionApi struct{} + +// Add +// +// @Tags Satisfaction +// @Summary 娣诲姞婊℃剰搴� +// @Produce application/json +// @Param object body request.AddSatisfaction true "鏌ヨ鍙傛暟" +// @Success 200 {object} contextx.Response{} +// @Router /api/satisfaction/add [post] +func (s *SatisfactionApi) Add(c *gin.Context) { + var params request.AddSatisfaction + ctx, ok := contextx.NewContext(c, ¶ms) + if !ok { + return + } + + satisfaction := new(model.Satisfaction) + satisfaction.Name = params.Name + + errCode := satisfactionService.AddSatisfaction(satisfaction) + if errCode != ecode.OK { + ctx.Fail(errCode) + return + } + + ctx.Ok() +} + +// Delete +// +// @Tags Satisfaction +// @Summary 鍒犻櫎婊℃剰搴� +// @Produce application/json +// @Param id path int true "鏌ヨ鍙傛暟" +// @Success 200 {object} contextx.Response{} +// @Router /api/satisfaction/delete/{id} [delete] +func (s *SatisfactionApi) Delete(c *gin.Context) { + ctx, ok := contextx.NewContext(c, nil) + if !ok { + return + } + + id, _ := strconv.Atoi(c.Param("id")) + errCode := satisfactionService.DeleteSatisfaction(id) + if errCode != ecode.OK { + ctx.Fail(errCode) + return + } + + ctx.Ok() +} + +// Update +// +// @Tags Satisfaction +// @Summary 鏇存柊婊℃剰搴� +// @Produce application/json +// @Param object body request.UpdateSatisfactions true "鏌ヨ鍙傛暟" +// @Success 200 {object} contextx.Response{} +// @Router /api/satisfaction/update [put] +func (s *SatisfactionApi) Update(c *gin.Context) { + var params request.UpdateSatisfactions + ctx, ok := contextx.NewContext(c, ¶ms) + if !ok { + return + } + + errCode := satisfactionService.UpdateSatisfaction(params.Satisfactions) + if errCode != ecode.OK { + ctx.Fail(errCode) + return + } + + ctx.Ok() +} + +// List +// +// @Tags Satisfaction +// @Summary 婊℃剰搴﹀垪琛� +// @Produce application/json +// @Success 200 {object} contextx.Response{data=response.SatisfactionResponse} +// @Router /api/satisfaction/list [get] +func (s *SatisfactionApi) List(c *gin.Context) { + ctx, ok := contextx.NewContext(c, nil) + if !ok { + return + } + + satisfactions, errCode := satisfactionService.GetSatisfactionList() + if errCode != ecode.OK { + ctx.Fail(errCode) + return + } + + ctx.OkWithDetailed(response.SatisfactionResponse{ + List: satisfactions, + }) +} diff --git a/api/v1/serviceFeeManage.go b/api/v1/serviceFeeManage.go index 9771dc9..834ad2c 100644 --- a/api/v1/serviceFeeManage.go +++ b/api/v1/serviceFeeManage.go @@ -33,6 +33,14 @@ return } + code, client := checkClientParams(params.Client) + if code != ecode.OK { + ctx.Fail(code) + return + } + + serviceFeeManage.Client = client + errCode = serviceFeeManageService.AddServiceFeeManage(&serviceFeeManage) if errCode != ecode.OK { ctx.Fail(errCode) @@ -135,9 +143,9 @@ // return ecode.InvalidParams, result //} - if serviceFeeManage.MemberId == 0 { - return ecode.InvalidParams, result - } + //if serviceFeeManage.MemberId == 0 { + // return ecode.InvalidParams, result + //} t, err := checkTimeFormat(serviceFeeManage.LatestDate) if err != nil { diff --git a/docs/docs.go b/docs/docs.go index 5f12fa8..6d6eace 100644 --- a/docs/docs.go +++ b/docs/docs.go @@ -4162,6 +4162,125 @@ } } }, + "/api/satisfaction/add": { + "post": { + "produces": [ + "application/json" + ], + "tags": [ + "Satisfaction" + ], + "summary": "娣诲姞婊℃剰搴�", + "parameters": [ + { + "description": "鏌ヨ鍙傛暟", + "name": "object", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/request.AddSatisfaction" + } + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/contextx.Response" + } + } + } + } + }, + "/api/satisfaction/delete/{id}": { + "delete": { + "produces": [ + "application/json" + ], + "tags": [ + "Satisfaction" + ], + "summary": "鍒犻櫎婊℃剰搴�", + "parameters": [ + { + "type": "integer", + "description": "鏌ヨ鍙傛暟", + "name": "id", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/contextx.Response" + } + } + } + } + }, + "/api/satisfaction/list": { + "get": { + "produces": [ + "application/json" + ], + "tags": [ + "Satisfaction" + ], + "summary": "婊℃剰搴﹀垪琛�", + "responses": { + "200": { + "description": "OK", + "schema": { + "allOf": [ + { + "$ref": "#/definitions/contextx.Response" + }, + { + "type": "object", + "properties": { + "data": { + "$ref": "#/definitions/response.SatisfactionResponse" + } + } + } + ] + } + } + } + } + }, + "/api/satisfaction/update": { + "put": { + "produces": [ + "application/json" + ], + "tags": [ + "Satisfaction" + ], + "summary": "鏇存柊婊℃剰搴�", + "parameters": [ + { + "description": "鏌ヨ鍙傛暟", + "name": "object", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/request.UpdateSatisfactions" + } + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/contextx.Response" + } + } + } + } + }, "/api/serviceContract/add": { "post": { "produces": [ @@ -5630,6 +5749,9 @@ "model.MasterOrder": { "type": "object", "properties": { + "client": { + "$ref": "#/definitions/model.Client" + }, "client_id": { "type": "integer" }, @@ -6011,6 +6133,9 @@ "addressee": { "type": "string" }, + "client": { + "$ref": "#/definitions/model.Client" + }, "clientId": { "type": "integer" }, @@ -6204,6 +6329,17 @@ } } }, + "model.Satisfaction": { + "type": "object", + "properties": { + "id": { + "type": "integer" + }, + "name": { + "type": "string" + } + } + }, "model.ServiceContract": { "type": "object", "properties": { @@ -6342,6 +6478,9 @@ "model.SubOrder": { "type": "object", "properties": { + "client": { + "$ref": "#/definitions/model.Client" + }, "clientId": { "type": "integer" }, @@ -7091,6 +7230,17 @@ } }, "request.AddSalesSources": { + "type": "object", + "required": [ + "name" + ], + "properties": { + "name": { + "type": "string" + } + } + }, + "request.AddSatisfaction": { "type": "object", "required": [ "name" @@ -8857,6 +9007,35 @@ } } }, + "request.UpdateSatisfaction": { + "type": "object", + "required": [ + "id", + "name" + ], + "properties": { + "id": { + "type": "integer" + }, + "name": { + "type": "string" + } + } + }, + "request.UpdateSatisfactions": { + "type": "object", + "required": [ + "satisfactions" + ], + "properties": { + "satisfactions": { + "type": "array", + "items": { + "$ref": "#/definitions/request.UpdateSatisfaction" + } + } + } + }, "request.UpdateServiceContract": { "type": "object", "properties": { @@ -9611,6 +9790,17 @@ } } }, + "response.SatisfactionResponse": { + "type": "object", + "properties": { + "list": { + "type": "array", + "items": { + "$ref": "#/definitions/model.Satisfaction" + } + } + } + }, "response.ServiceContractsResponse": { "type": "object", "properties": { diff --git a/docs/swagger.json b/docs/swagger.json index e3d258e..4fb2c34 100644 --- a/docs/swagger.json +++ b/docs/swagger.json @@ -4150,6 +4150,125 @@ } } }, + "/api/satisfaction/add": { + "post": { + "produces": [ + "application/json" + ], + "tags": [ + "Satisfaction" + ], + "summary": "娣诲姞婊℃剰搴�", + "parameters": [ + { + "description": "鏌ヨ鍙傛暟", + "name": "object", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/request.AddSatisfaction" + } + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/contextx.Response" + } + } + } + } + }, + "/api/satisfaction/delete/{id}": { + "delete": { + "produces": [ + "application/json" + ], + "tags": [ + "Satisfaction" + ], + "summary": "鍒犻櫎婊℃剰搴�", + "parameters": [ + { + "type": "integer", + "description": "鏌ヨ鍙傛暟", + "name": "id", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/contextx.Response" + } + } + } + } + }, + "/api/satisfaction/list": { + "get": { + "produces": [ + "application/json" + ], + "tags": [ + "Satisfaction" + ], + "summary": "婊℃剰搴﹀垪琛�", + "responses": { + "200": { + "description": "OK", + "schema": { + "allOf": [ + { + "$ref": "#/definitions/contextx.Response" + }, + { + "type": "object", + "properties": { + "data": { + "$ref": "#/definitions/response.SatisfactionResponse" + } + } + } + ] + } + } + } + } + }, + "/api/satisfaction/update": { + "put": { + "produces": [ + "application/json" + ], + "tags": [ + "Satisfaction" + ], + "summary": "鏇存柊婊℃剰搴�", + "parameters": [ + { + "description": "鏌ヨ鍙傛暟", + "name": "object", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/request.UpdateSatisfactions" + } + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/contextx.Response" + } + } + } + } + }, "/api/serviceContract/add": { "post": { "produces": [ @@ -5618,6 +5737,9 @@ "model.MasterOrder": { "type": "object", "properties": { + "client": { + "$ref": "#/definitions/model.Client" + }, "client_id": { "type": "integer" }, @@ -5999,6 +6121,9 @@ "addressee": { "type": "string" }, + "client": { + "$ref": "#/definitions/model.Client" + }, "clientId": { "type": "integer" }, @@ -6192,6 +6317,17 @@ } } }, + "model.Satisfaction": { + "type": "object", + "properties": { + "id": { + "type": "integer" + }, + "name": { + "type": "string" + } + } + }, "model.ServiceContract": { "type": "object", "properties": { @@ -6330,6 +6466,9 @@ "model.SubOrder": { "type": "object", "properties": { + "client": { + "$ref": "#/definitions/model.Client" + }, "clientId": { "type": "integer" }, @@ -7079,6 +7218,17 @@ } }, "request.AddSalesSources": { + "type": "object", + "required": [ + "name" + ], + "properties": { + "name": { + "type": "string" + } + } + }, + "request.AddSatisfaction": { "type": "object", "required": [ "name" @@ -8845,6 +8995,35 @@ } } }, + "request.UpdateSatisfaction": { + "type": "object", + "required": [ + "id", + "name" + ], + "properties": { + "id": { + "type": "integer" + }, + "name": { + "type": "string" + } + } + }, + "request.UpdateSatisfactions": { + "type": "object", + "required": [ + "satisfactions" + ], + "properties": { + "satisfactions": { + "type": "array", + "items": { + "$ref": "#/definitions/request.UpdateSatisfaction" + } + } + } + }, "request.UpdateServiceContract": { "type": "object", "properties": { @@ -9599,6 +9778,17 @@ } } }, + "response.SatisfactionResponse": { + "type": "object", + "properties": { + "list": { + "type": "array", + "items": { + "$ref": "#/definitions/model.Satisfaction" + } + } + } + }, "response.ServiceContractsResponse": { "type": "object", "properties": { diff --git a/docs/swagger.yaml b/docs/swagger.yaml index afe66fa..9eb98ef 100644 --- a/docs/swagger.yaml +++ b/docs/swagger.yaml @@ -404,6 +404,8 @@ type: object model.MasterOrder: properties: + client: + $ref: '#/definitions/model.Client' client_id: type: integer end_time: @@ -654,6 +656,8 @@ type: string addressee: type: string + client: + $ref: '#/definitions/model.Client' clientId: type: integer conditions: @@ -781,6 +785,13 @@ name: type: string type: object + model.Satisfaction: + properties: + id: + type: integer + name: + type: string + type: object model.ServiceContract: properties: clientId: @@ -872,6 +883,8 @@ type: object model.SubOrder: properties: + client: + $ref: '#/definitions/model.Client' clientId: type: integer id: @@ -1377,6 +1390,13 @@ $ref: '#/definitions/request.SalesReturn' type: object request.AddSalesSources: + properties: + name: + type: string + required: + - name + type: object + request.AddSatisfaction: properties: name: type: string @@ -2574,6 +2594,25 @@ $ref: '#/definitions/request.UpdateSalesSources' type: array type: object + request.UpdateSatisfaction: + properties: + id: + type: integer + name: + type: string + required: + - id + - name + type: object + request.UpdateSatisfactions: + properties: + satisfactions: + items: + $ref: '#/definitions/request.UpdateSatisfaction' + type: array + required: + - satisfactions + type: object request.UpdateServiceContract: properties: clientId: @@ -3074,6 +3113,13 @@ list: items: $ref: '#/definitions/model.SalesSources' + type: array + type: object + response.SatisfactionResponse: + properties: + list: + items: + $ref: '#/definitions/model.Satisfaction' type: array type: object response.ServiceContractsResponse: @@ -5654,6 +5700,79 @@ summary: 鏇存柊鍟嗘満鏉ユ簮 tags: - SalesSources + /api/satisfaction/add: + post: + parameters: + - description: 鏌ヨ鍙傛暟 + in: body + name: object + required: true + schema: + $ref: '#/definitions/request.AddSatisfaction' + produces: + - application/json + responses: + "200": + description: OK + schema: + $ref: '#/definitions/contextx.Response' + summary: 娣诲姞婊℃剰搴� + tags: + - Satisfaction + /api/satisfaction/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: + - Satisfaction + /api/satisfaction/list: + get: + produces: + - application/json + responses: + "200": + description: OK + schema: + allOf: + - $ref: '#/definitions/contextx.Response' + - properties: + data: + $ref: '#/definitions/response.SatisfactionResponse' + type: object + summary: 婊℃剰搴﹀垪琛� + tags: + - Satisfaction + /api/satisfaction/update: + put: + parameters: + - description: 鏌ヨ鍙傛暟 + in: body + name: object + required: true + schema: + $ref: '#/definitions/request.UpdateSatisfactions' + produces: + - application/json + responses: + "200": + description: OK + schema: + $ref: '#/definitions/contextx.Response' + summary: 鏇存柊婊℃剰搴� + tags: + - Satisfaction /api/serviceContract/add: post: parameters: diff --git a/model/index.go b/model/index.go index 8abb6b1..722dfce 100644 --- a/model/index.go +++ b/model/index.go @@ -63,6 +63,7 @@ Authority{}, Api{}, Department{}, + Satisfaction{}, ) return err } diff --git a/model/request/satisfaction.go b/model/request/satisfaction.go new file mode 100644 index 0000000..e06816c --- /dev/null +++ b/model/request/satisfaction.go @@ -0,0 +1,14 @@ +package request + +type AddSatisfaction struct { + Name string `json:"name" binding:"required"` +} + +type UpdateSatisfaction struct { + Id int `json:"id" binding:"required"` + Name string `json:"name" binding:"required"` +} + +type UpdateSatisfactions struct { + Satisfactions []*UpdateSatisfaction `json:"satisfactions" binding:"required"` +} diff --git a/model/response/response.go b/model/response/response.go index 4a69550..364428d 100644 --- a/model/response/response.go +++ b/model/response/response.go @@ -220,4 +220,8 @@ DepartmentResponse struct { List []*model.Department `json:"list"` } + + SatisfactionResponse struct { + List []*model.Satisfaction `json:"list"` + } ) diff --git a/model/satisfaction.go b/model/satisfaction.go new file mode 100644 index 0000000..11690e6 --- /dev/null +++ b/model/satisfaction.go @@ -0,0 +1,79 @@ +package model + +import ( + "aps_crm/pkg/mysqlx" + "gorm.io/gorm" +) + +type ( + Satisfaction struct { + Id int `json:"id" gorm:"column:id;primary_key;AUTO_INCREMENT"` + Name string `json:"name" gorm:"column:name;type:varchar(255);comment:婊℃剰搴﹀悕绉�"` + } + + SatisfactionSearch struct { + Satisfaction + Orm *gorm.DB + } +) + +func (Satisfaction) TableName() string { + return "satisfaction" +} + +func NewSatisfactionSearch() *SatisfactionSearch { + return &SatisfactionSearch{ + Orm: mysqlx.GetDB(), + } +} + +func (slf *SatisfactionSearch) build() *gorm.DB { + var db = slf.Orm.Model(&Satisfaction{}) + if slf.Id != 0 { + db = db.Where("id = ?", slf.Id) + } + if slf.Name != "" { + db = db.Where("name = ?", slf.Name) + } + + return db +} + +func (slf *SatisfactionSearch) Create(record *Satisfaction) error { + var db = slf.build() + return db.Create(record).Error +} + +func (slf *SatisfactionSearch) Delete() error { + var db = slf.build() + return db.Delete(&Satisfaction{}).Error +} + +func (slf *SatisfactionSearch) Update(record *Satisfaction) error { + var db = slf.build() + return db.Updates(record).Error +} + +func (slf *SatisfactionSearch) Find() (*Satisfaction, error) { + var db = slf.build() + var record = new(Satisfaction) + err := db.First(record).Error + return record, err +} + +func (slf *SatisfactionSearch) FindAll() ([]*Satisfaction, error) { + var db = slf.build() + var records = make([]*Satisfaction, 0) + err := db.Find(&records).Error + return records, err +} + +func (slf *SatisfactionSearch) SetId(id int) *SatisfactionSearch { + slf.Id = id + return slf +} + +func (slf *SatisfactionSearch) Updates(data map[string]interface{}) error { + var db = slf.build() + return db.Updates(data).Error +} diff --git a/pkg/ecode/code.go b/pkg/ecode/code.go index 5a1d754..310ef8b 100644 --- a/pkg/ecode/code.go +++ b/pkg/ecode/code.go @@ -292,4 +292,9 @@ VettingListErr = 4100003 // 鑾峰彇瀹℃壒鍒楄〃澶辫触 VettingSetErr = 4100004 // 璁剧疆瀹℃壒澶辫触 + SatisfactionExist = 4200001 // 婊℃剰搴﹀凡瀛樺湪 + SatisfactionNotExist = 4200002 // 婊℃剰搴︿笉瀛樺湪 + SatisfactionListErr = 4200003 // 鑾峰彇婊℃剰搴﹀垪琛ㄥけ璐� + SatisfactionSetErr = 4200004 // 璁剧疆婊℃剰搴﹀け璐� + SatisfactionUpdateErr = 4200005 // 鏇存柊婊℃剰搴﹀け璐� ) diff --git a/router/index.go b/router/index.go index b57c38c..19ce012 100644 --- a/router/index.go +++ b/router/index.go @@ -54,6 +54,7 @@ MenuRouter DataRouter DepartmentRouter + SatisfactionRouter } func InitRouter() *gin.Engine { @@ -127,6 +128,7 @@ routerGroup.InitMenuRouter(PrivateGroup) // 娉ㄥ唽menu璺敱 routerGroup.InitDataRouter(PrivateGroup) // 娉ㄥ唽data璺敱 routerGroup.InitDepartmentRouter(PrivateGroup) // 娉ㄥ唽department璺敱 + routerGroup.InitSatisfactionRouter(PrivateGroup) // 娉ㄥ唽satisfaction璺敱 } return Router } diff --git a/router/satisfaction.go b/router/satisfaction.go new file mode 100644 index 0000000..66c8d46 --- /dev/null +++ b/router/satisfaction.go @@ -0,0 +1,19 @@ +package router + +import ( + v1 "aps_crm/api/v1" + "github.com/gin-gonic/gin" +) + +type SatisfactionRouter struct{} + +func (s *SatisfactionRouter) InitSatisfactionRouter(router *gin.RouterGroup) { + satisfactionRouter := router.Group("satisfaction") + satisfactionApi := v1.ApiGroup.SatisfactionApi + { + satisfactionRouter.POST("add", satisfactionApi.Add) // 娣诲姞婊℃剰搴� + satisfactionRouter.DELETE("delete/:id", satisfactionApi.Delete) // 鍒犻櫎婊℃剰搴� + satisfactionRouter.PUT("update", satisfactionApi.Update) // 鏇存柊婊℃剰搴� + satisfactionRouter.GET("list", satisfactionApi.List) // 鑾峰彇婊℃剰搴﹀垪琛� + } +} diff --git a/service/index.go b/service/index.go index 2ecec7b..ef84553 100644 --- a/service/index.go +++ b/service/index.go @@ -45,6 +45,7 @@ DataServer DepartmentService VettingService + SatisfactionService } var ServiceGroup = new(Group) diff --git a/service/satisfaction.go b/service/satisfaction.go new file mode 100644 index 0000000..1eec341 --- /dev/null +++ b/service/satisfaction.go @@ -0,0 +1,59 @@ +package service + +import ( + "aps_crm/model" + "aps_crm/model/request" + "aps_crm/pkg/ecode" +) + +type SatisfactionService struct{} + +func (SatisfactionService) AddSatisfaction(satisfaction *model.Satisfaction) int { + err := model.NewSatisfactionSearch().Create(satisfaction) + if err != nil { + return ecode.SatisfactionExist + } + + return ecode.OK +} + +func (SatisfactionService) DeleteSatisfaction(id int) int { + _, err := model.NewSatisfactionSearch().SetId(id).Find() + if err != nil { + return ecode.SatisfactionNotExist + } + + err = model.NewSatisfactionSearch().SetId(id).Delete() + if err != nil { + return ecode.SatisfactionNotExist + } + return ecode.OK +} + +func (SatisfactionService) GetSatisfactionList() ([]*model.Satisfaction, int) { + list, err := model.NewSatisfactionSearch().FindAll() + if err != nil { + return nil, ecode.SatisfactionListErr + } + + return list, ecode.OK +} + +func (SatisfactionService) UpdateSatisfaction(satisfactions []*request.UpdateSatisfaction) int { + for _, v := range satisfactions { + // check satisfaction exist + _, err := model.NewSatisfactionSearch().SetId(v.Id).Find() + if err != nil { + return ecode.SatisfactionNotExist + } + + err = model.NewSatisfactionSearch().SetId(v.Id).Updates(map[string]interface{}{ + "name": v.Name, + }) + if err != nil { + return ecode.SatisfactionSetErr + } + } + + return ecode.OK +} -- Gitblit v1.8.0