From a32c022b30a30982358464ba0f68aab0b2a103c2 Mon Sep 17 00:00:00 2001 From: wangpengfei <274878379@qq.com> Date: 星期三, 12 七月 2023 15:26:15 +0800 Subject: [PATCH] add --- api/v1/index.go | 2 model/contract.go | 76 +++++ router/contract.go | 19 + pkg/ecode/code.go | 7 api/v1/contract.go | 1 docs/swagger.yaml | 129 +++++++++ docs/docs.go | 205 +++++++++++++++ docs/swagger.json | 205 +++++++++++++++ model/response/response.go | 4 model/request/contract.go | 19 + service/index.go | 1 service/contract.go | 54 ++++ model/index.go | 1 logs/aps-admin.err.log | 1 router/index.go | 2 15 files changed, 726 insertions(+), 0 deletions(-) diff --git a/api/v1/contract.go b/api/v1/contract.go new file mode 100644 index 0000000..b7b1f99 --- /dev/null +++ b/api/v1/contract.go @@ -0,0 +1 @@ +package v1 diff --git a/api/v1/index.go b/api/v1/index.go index 92307c2..e183aea 100644 --- a/api/v1/index.go +++ b/api/v1/index.go @@ -37,6 +37,7 @@ SalesDetailsApi SalesReturnApi SalesRefundApi + ContractApi } var ApiGroup = new(Group) @@ -73,4 +74,5 @@ salesDetailsService = service.ServiceGroup.SalesDetailsService salesReturnService = service.ServiceGroup.SalesReturnService salesRefundService = service.ServiceGroup.SalesRefundService + contractService = service.ServiceGroup.ContractService ) diff --git a/docs/docs.go b/docs/docs.go index d262056..e61468e 100644 --- a/docs/docs.go +++ b/docs/docs.go @@ -952,6 +952,125 @@ } } }, + "/api/contract/add": { + "post": { + "produces": [ + "application/json" + ], + "tags": [ + "Contract" + ], + "summary": "娣诲姞鍚堝悓", + "parameters": [ + { + "description": "鏌ヨ鍙傛暟", + "name": "object", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/request.AddContract" + } + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/contextx.Response" + } + } + } + } + }, + "/api/contract/delete/{id}": { + "delete": { + "produces": [ + "application/json" + ], + "tags": [ + "Contract" + ], + "summary": "鍒犻櫎鍚堝悓", + "parameters": [ + { + "type": "integer", + "description": "鏌ヨ鍙傛暟", + "name": "id", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/contextx.Response" + } + } + } + } + }, + "/api/contract/list": { + "get": { + "produces": [ + "application/json" + ], + "tags": [ + "Contract" + ], + "summary": "鑾峰彇鍚堝悓鍒楄〃", + "responses": { + "200": { + "description": "OK", + "schema": { + "allOf": [ + { + "$ref": "#/definitions/contextx.Response" + }, + { + "type": "object", + "properties": { + "data": { + "$ref": "#/definitions/response.ContractResponse" + } + } + } + ] + } + } + } + } + }, + "/api/contract/update": { + "put": { + "produces": [ + "application/json" + ], + "tags": [ + "Contract" + ], + "summary": "鏇存柊鍚堝悓", + "parameters": [ + { + "description": "鏌ヨ鍙傛暟", + "name": "object", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/request.UpdateContract" + } + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/contextx.Response" + } + } + } + } + }, "/api/country/add": { "post": { "produces": [ @@ -4272,6 +4391,32 @@ } } }, + "model.Contract": { + "type": "object", + "properties": { + "clientId": { + "type": "integer" + }, + "file": { + "type": "string" + }, + "id": { + "type": "integer" + }, + "memberId": { + "type": "integer" + }, + "number": { + "type": "string" + }, + "quotationId": { + "type": "integer" + }, + "statusId": { + "type": "integer" + } + } + }, "model.Country": { "type": "object", "properties": { @@ -5135,6 +5280,29 @@ "wechat": { "description": "寰俊鍙�", "type": "string" + } + } + }, + "request.AddContract": { + "type": "object", + "properties": { + "client_id": { + "type": "integer" + }, + "file": { + "type": "string" + }, + "member_id": { + "type": "integer" + }, + "number": { + "type": "string" + }, + "quotation_id": { + "type": "integer" + }, + "status_id": { + "type": "integer" } } }, @@ -6254,6 +6422,32 @@ } } }, + "request.UpdateContract": { + "type": "object", + "properties": { + "client_id": { + "type": "integer" + }, + "file": { + "type": "string" + }, + "id": { + "type": "integer" + }, + "member_id": { + "type": "integer" + }, + "number": { + "type": "string" + }, + "quotation_id": { + "type": "integer" + }, + "status_id": { + "type": "integer" + } + } + }, "request.UpdateCountry": { "type": "object", "properties": { @@ -6986,6 +7180,17 @@ } } }, + "response.ContractResponse": { + "type": "object", + "properties": { + "list": { + "type": "array", + "items": { + "$ref": "#/definitions/model.Contract" + } + } + } + }, "response.CountryResponse": { "type": "object", "properties": { diff --git a/docs/swagger.json b/docs/swagger.json index f49b538..3b8054d 100644 --- a/docs/swagger.json +++ b/docs/swagger.json @@ -940,6 +940,125 @@ } } }, + "/api/contract/add": { + "post": { + "produces": [ + "application/json" + ], + "tags": [ + "Contract" + ], + "summary": "娣诲姞鍚堝悓", + "parameters": [ + { + "description": "鏌ヨ鍙傛暟", + "name": "object", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/request.AddContract" + } + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/contextx.Response" + } + } + } + } + }, + "/api/contract/delete/{id}": { + "delete": { + "produces": [ + "application/json" + ], + "tags": [ + "Contract" + ], + "summary": "鍒犻櫎鍚堝悓", + "parameters": [ + { + "type": "integer", + "description": "鏌ヨ鍙傛暟", + "name": "id", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/contextx.Response" + } + } + } + } + }, + "/api/contract/list": { + "get": { + "produces": [ + "application/json" + ], + "tags": [ + "Contract" + ], + "summary": "鑾峰彇鍚堝悓鍒楄〃", + "responses": { + "200": { + "description": "OK", + "schema": { + "allOf": [ + { + "$ref": "#/definitions/contextx.Response" + }, + { + "type": "object", + "properties": { + "data": { + "$ref": "#/definitions/response.ContractResponse" + } + } + } + ] + } + } + } + } + }, + "/api/contract/update": { + "put": { + "produces": [ + "application/json" + ], + "tags": [ + "Contract" + ], + "summary": "鏇存柊鍚堝悓", + "parameters": [ + { + "description": "鏌ヨ鍙傛暟", + "name": "object", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/request.UpdateContract" + } + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/contextx.Response" + } + } + } + } + }, "/api/country/add": { "post": { "produces": [ @@ -4260,6 +4379,32 @@ } } }, + "model.Contract": { + "type": "object", + "properties": { + "clientId": { + "type": "integer" + }, + "file": { + "type": "string" + }, + "id": { + "type": "integer" + }, + "memberId": { + "type": "integer" + }, + "number": { + "type": "string" + }, + "quotationId": { + "type": "integer" + }, + "statusId": { + "type": "integer" + } + } + }, "model.Country": { "type": "object", "properties": { @@ -5123,6 +5268,29 @@ "wechat": { "description": "寰俊鍙�", "type": "string" + } + } + }, + "request.AddContract": { + "type": "object", + "properties": { + "client_id": { + "type": "integer" + }, + "file": { + "type": "string" + }, + "member_id": { + "type": "integer" + }, + "number": { + "type": "string" + }, + "quotation_id": { + "type": "integer" + }, + "status_id": { + "type": "integer" } } }, @@ -6242,6 +6410,32 @@ } } }, + "request.UpdateContract": { + "type": "object", + "properties": { + "client_id": { + "type": "integer" + }, + "file": { + "type": "string" + }, + "id": { + "type": "integer" + }, + "member_id": { + "type": "integer" + }, + "number": { + "type": "string" + }, + "quotation_id": { + "type": "integer" + }, + "status_id": { + "type": "integer" + } + } + }, "request.UpdateCountry": { "type": "object", "properties": { @@ -6974,6 +7168,17 @@ } } }, + "response.ContractResponse": { + "type": "object", + "properties": { + "list": { + "type": "array", + "items": { + "$ref": "#/definitions/model.Contract" + } + } + } + }, "response.CountryResponse": { "type": "object", "properties": { diff --git a/docs/swagger.yaml b/docs/swagger.yaml index f9dc27a..83d99fd 100644 --- a/docs/swagger.yaml +++ b/docs/swagger.yaml @@ -266,6 +266,23 @@ wechat: type: string type: object + model.Contract: + properties: + clientId: + type: integer + file: + type: string + id: + type: integer + memberId: + type: integer + number: + type: string + quotationId: + type: integer + statusId: + type: integer + type: object model.Country: properties: id: @@ -846,6 +863,21 @@ wechat: description: 寰俊鍙� type: string + type: object + request.AddContract: + properties: + client_id: + type: integer + file: + type: string + member_id: + type: integer + number: + type: string + quotation_id: + type: integer + status_id: + type: integer type: object request.AddCountry: properties: @@ -1607,6 +1639,23 @@ description: 寰俊鍙� type: string type: object + request.UpdateContract: + properties: + client_id: + type: integer + file: + type: string + id: + type: integer + member_id: + type: integer + number: + type: string + quotation_id: + type: integer + status_id: + type: integer + type: object request.UpdateCountry: properties: id: @@ -2088,6 +2137,13 @@ list: items: $ref: '#/definitions/model.ContactDetail' + type: array + type: object + response.ContractResponse: + properties: + list: + items: + $ref: '#/definitions/model.Contract' type: array type: object response.CountryResponse: @@ -2821,6 +2877,79 @@ summary: 鏇存柊鑱旂郴浜� tags: - Contact + /api/contract/add: + post: + parameters: + - description: 鏌ヨ鍙傛暟 + in: body + name: object + required: true + schema: + $ref: '#/definitions/request.AddContract' + produces: + - application/json + responses: + "200": + description: OK + schema: + $ref: '#/definitions/contextx.Response' + summary: 娣诲姞鍚堝悓 + tags: + - Contract + /api/contract/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: + - Contract + /api/contract/list: + get: + produces: + - application/json + responses: + "200": + description: OK + schema: + allOf: + - $ref: '#/definitions/contextx.Response' + - properties: + data: + $ref: '#/definitions/response.ContractResponse' + type: object + summary: 鑾峰彇鍚堝悓鍒楄〃 + tags: + - Contract + /api/contract/update: + put: + parameters: + - description: 鏌ヨ鍙傛暟 + in: body + name: object + required: true + schema: + $ref: '#/definitions/request.UpdateContract' + produces: + - application/json + responses: + "200": + description: OK + schema: + $ref: '#/definitions/contextx.Response' + summary: 鏇存柊鍚堝悓 + tags: + - Contract /api/country/add: post: parameters: diff --git a/logs/aps-admin.err.log b/logs/aps-admin.err.log index dd58b9b..1071cdb 100644 --- a/logs/aps-admin.err.log +++ b/logs/aps-admin.err.log @@ -345,3 +345,4 @@ [2023-07-11 11:33:55] [error] [gorm.io/gorm/migrator.Migrator.AutoMigrate:104] failed to parse value model.SubOrder{Id:0, ClientId:0, MemberId:0, MasterOrderId:0, Number:"", ProductOrder:model.ProductOrder{Id:0, Products:[]model.Product(nil)}, Model:gorm.Model{ID:0x0, CreatedAt:time.Date(1, time.January, 1, 0, 0, 0, 0, time.UTC), UpdatedAt:time.Date(1, time.January, 1, 0, 0, 0, 0, time.UTC), DeletedAt:gorm.DeletedAt{Time:time.Date(1, time.January, 1, 0, 0, 0, 0, time.UTC), Valid:false}}}, got error invalid field found for struct aps_crm/model.SubOrder's field ProductOrder: define a valid foreign key for relations or implement the Valuer/Scanner interface [2023-07-11 11:33:55] [error] [gorm.io/gorm/migrator.Migrator.CreateTable:198] failed to parse value model.SubOrder{Id:0, ClientId:0, MemberId:0, MasterOrderId:0, Number:"", ProductOrder:model.ProductOrder{Id:0, Products:[]model.Product(nil)}, Model:gorm.Model{ID:0x0, CreatedAt:time.Date(1, time.January, 1, 0, 0, 0, 0, time.UTC), UpdatedAt:time.Date(1, time.January, 1, 0, 0, 0, 0, time.UTC), DeletedAt:gorm.DeletedAt{Time:time.Date(1, time.January, 1, 0, 0, 0, 0, time.UTC), Valid:false}}}, got error invalid field found for struct aps_crm/model.SubOrder's field ProductOrder: define a valid foreign key for relations or implement the Valuer/Scanner interface [2023-07-11 11:33:55] [error] [main.main:29] model Init err:invalid field found for struct aps_crm/model.SubOrder's field ProductOrder: define a valid foreign key for relations or implement the Valuer/Scanner interface +[2023-07-12 15:23:10] [error] [aps_crm/model.(*ContractSearch).Create:46] trace {"error": "Error 1146 (42S02): Table 'aps_crm.contract' doesn't exist", "elapsed": 0.003547, "rows": 0, "sql": "INSERT INTO `contract` (`client_id`,`member_id`,`number`,`quotation_id`,`status_id`,`file`) VALUES (11,11,'ZDYB02-2',0,0,'string')"} diff --git a/model/contract.go b/model/contract.go new file mode 100644 index 0000000..b47cedc --- /dev/null +++ b/model/contract.go @@ -0,0 +1,76 @@ +package model + +import ( + "aps_crm/pkg/mysqlx" + "gorm.io/gorm" +) + +type ( + Contract struct { + Id int `json:"id" gorm:"column:id;primary_key;AUTO_INCREMENT"` + ClientId int `json:"clientId" gorm:"column:client_id;type:int;comment:瀹㈡埛id"` + MemberId int `json:"memberId" gorm:"column:member_id;type:int;comment:璐熻矗浜篿d"` + Number string `json:"number" gorm:"column:number;type:varchar(255);comment:鍚堝悓缂栧彿"` + QuotationId int `json:"quotationId" gorm:"column:quotation_id;type:int;comment:鎶ヤ环鍗昳d"` + StatusId int `json:"statusId" gorm:"column:status_id;type:int;comment:鍚堝悓鐘舵��"` + File string `json:"file" gorm:"column:file;type:varchar(255);comment:鍚堝悓鏂囦欢"` + } + + ContractSearch struct { + Contract + Orm *gorm.DB + } +) + +func (Contract) TableName() string { + return "contract" +} + +func NewContractSearch() *ContractSearch { + return &ContractSearch{ + Orm: mysqlx.GetDB(), + } +} + +func (slf *ContractSearch) build() *gorm.DB { + var db = slf.Orm.Model(&Contract{}) + if slf.Id != 0 { + db = db.Where("id = ?", slf.Id) + } + + return db +} + +func (slf *ContractSearch) Create(record *Contract) error { + var db = slf.build() + return db.Create(record).Error +} + +func (slf *ContractSearch) Delete() error { + var db = slf.build() + return db.Delete(&Contract{}).Error +} + +func (slf *ContractSearch) Update(record *Contract) error { + var db = slf.build() + return db.Updates(record).Error +} + +func (slf *ContractSearch) Find() (*Contract, error) { + var db = slf.build() + var record = &Contract{} + err := db.First(record).Error + return record, err +} + +func (slf *ContractSearch) FindAll() ([]*Contract, error) { + var db = slf.build() + var records = make([]*Contract, 0) + err := db.Find(&records).Error + return records, err +} + +func (slf *ContractSearch) SetId(id int) *ContractSearch { + slf.Id = id + return slf +} diff --git a/model/index.go b/model/index.go index 3a0814a..26b4bab 100644 --- a/model/index.go +++ b/model/index.go @@ -53,6 +53,7 @@ SalesDetails{}, SalesReturn{}, SalesRefund{}, + Contract{}, ) return err } diff --git a/model/request/contract.go b/model/request/contract.go new file mode 100644 index 0000000..ce085ce --- /dev/null +++ b/model/request/contract.go @@ -0,0 +1,19 @@ +package request + +type AddContract struct { + Contract +} + +type Contract struct { + ClientId int `json:"client_id"` + MemberId int `json:"member_id"` + Number string `json:"number"` + QuotationId int `json:"quotation_id"` + StatusId int `json:"status_id"` + File string `json:"file"` +} + +type UpdateContract struct { + Id int `json:"id"` + Contract +} diff --git a/model/response/response.go b/model/response/response.go index e4291dd..8ce4fc0 100644 --- a/model/response/response.go +++ b/model/response/response.go @@ -145,4 +145,8 @@ SalesRefundResponse struct { List []*model.SalesRefund `json:"list"` } + + ContractResponse struct { + List []*model.Contract `json:"list"` + } ) diff --git a/pkg/ecode/code.go b/pkg/ecode/code.go index d0dd587..9e9f0de 100644 --- a/pkg/ecode/code.go +++ b/pkg/ecode/code.go @@ -218,4 +218,11 @@ SalesRefundSetErr = 3000004 // 璁剧疆閿�鍞��娆惧崟澶辫触 SalesRefundUpdateErr = 3000005 // 鏇存柊閿�鍞��娆惧崟澶辫触 SalesRefundDeleteErr = 3000006 // 鍒犻櫎閿�鍞��娆惧崟澶辫触 + + ContractExist = 3100001 // 鍚堝悓宸插瓨鍦� + ContractNotExist = 3100002 // 鍚堝悓涓嶅瓨鍦� + ContractListErr = 3100003 // 鑾峰彇鍚堝悓鍒楄〃澶辫触 + ContractSetErr = 3100004 // 璁剧疆鍚堝悓澶辫触 + ContractUpdateErr = 3100005 // 鏇存柊鍚堝悓澶辫触 + ContractDeleteErr = 3100006 // 鍒犻櫎鍚堝悓澶辫触 ) diff --git a/router/contract.go b/router/contract.go new file mode 100644 index 0000000..d83f1e1 --- /dev/null +++ b/router/contract.go @@ -0,0 +1,19 @@ +package router + +import ( + v1 "aps_crm/api/v1" + "github.com/gin-gonic/gin" +) + +type ContractRouter struct{} + +func (s *ContractRouter) InitContractRouter(router *gin.RouterGroup) { + contractRouter := router.Group("contract") + contractApi := v1.ApiGroup.ContractApi + { + contractRouter.POST("add", contractApi.Add) // 娣诲姞鍚堝悓 + contractRouter.DELETE("delete/:id", contractApi.Delete) // 鍒犻櫎鍚堝悓 + contractRouter.PUT("update", contractApi.Update) // 鏇存柊鍚堝悓 + contractRouter.GET("list", contractApi.List) // 鑾峰彇鍚堝悓鍒楄〃 + } +} diff --git a/router/index.go b/router/index.go index 8676fdf..81035c8 100644 --- a/router/index.go +++ b/router/index.go @@ -43,6 +43,7 @@ SalesDetailsRouter SalesReturnRouter SalesRefundRouter + ContractRouter } func InitRouter() *gin.Engine { @@ -103,6 +104,7 @@ routerGroup.InitSalesDetailsRouter(PrivateGroup) // 娉ㄥ唽salesDetails璺敱 routerGroup.InitSalesReturnRouter(PrivateGroup) // 娉ㄥ唽salesReturn璺敱 routerGroup.InitSalesRefundRouter(PrivateGroup) // 娉ㄥ唽salesRefund璺敱 + routerGroup.InitContractRouter(PrivateGroup) // 娉ㄥ唽contract璺敱 } return Router } diff --git a/service/contract.go b/service/contract.go new file mode 100644 index 0000000..58cb8e0 --- /dev/null +++ b/service/contract.go @@ -0,0 +1,54 @@ +package service + +import ( + "aps_crm/model" + "aps_crm/pkg/ecode" +) + +type ContractService struct{} + +func (ContractService) AddContract(contract *model.Contract) int { + err := model.NewContractSearch().Create(contract) + if err != nil { + return ecode.ContractExist + } + + return ecode.OK +} + +func (ContractService) DeleteContract(id int) int { + _, err := model.NewContractSearch().SetId(id).Find() + if err != nil { + return ecode.ContractNotExist + } + + err = model.NewContractSearch().SetId(id).Delete() + if err != nil { + return ecode.ContractNotExist + } + return ecode.OK +} + +func (ContractService) GetContractList() ([]*model.Contract, int) { + list, err := model.NewContractSearch().FindAll() + if err != nil { + return nil, ecode.ContractListErr + } + + return list, ecode.OK +} + +func (ContractService) UpdateContract(contract *model.Contract) int { + // check contract exist + _, err := model.NewContractSearch().SetId(contract.Id).Find() + if err != nil { + return ecode.ContractNotExist + } + + err = model.NewContractSearch().SetId(contract.Id).Update(contract) + if err != nil { + return ecode.ContractSetErr + } + + return ecode.OK +} diff --git a/service/index.go b/service/index.go index 3743020..e387979 100644 --- a/service/index.go +++ b/service/index.go @@ -32,6 +32,7 @@ SalesDetailsService SalesReturnService SalesRefundService + ContractService } var ServiceGroup = new(Group) -- Gitblit v1.8.0