From f2c7c7aa3218cd5ef688975ea9b5a0f3a6e5e74f Mon Sep 17 00:00:00 2001 From: wangpengfei <274878379@qq.com> Date: 星期四, 10 八月 2023 16:38:41 +0800 Subject: [PATCH] temp --- api/v1/index.go | 2 api/v1/collectionProjection.go | 40 +++ pkg/ecode/code.go | 5 docs/swagger.yaml | 54 ++++ model/request/collectionProjection.go | 11 + docs/docs.go | 79 +++++++ docs/swagger.json | 79 +++++++ model/collectionProjection.go | 85 +++++++ service/index.go | 1 service/collectionProjection.go | 17 + router/colletionProjection.go | 19 + model/index.go | 216 +++++++++--------- router/index.go | 3 13 files changed, 499 insertions(+), 112 deletions(-) diff --git a/api/v1/collectionProjection.go b/api/v1/collectionProjection.go new file mode 100644 index 0000000..7556283 --- /dev/null +++ b/api/v1/collectionProjection.go @@ -0,0 +1,40 @@ +package v1 + +import ( + "aps_crm/model" + "aps_crm/model/request" + "aps_crm/pkg/contextx" + "aps_crm/pkg/ecode" + "github.com/gin-gonic/gin" +) + +type CollectionProjectionApi struct{} + +// Add +// +// @Tags CollectionProjection +// @Summary 娣诲姞鏀舵棰勬祴 +// @Produce application/json +// @Param object body request.AddCollectionProjection true "鏌ヨ鍙傛暟" +// @Success 200 {object} contextx.Response{} +// @Router /api/collectionProjection/add [post] +func (cp *CollectionProjectionApi) Add(c *gin.Context) { + var params request.AddCollectionProjection + ctx, ok := contextx.NewContext(c, ¶ms) + if !ok { + return + } + + tmp := new(model.CollectionProjection) + tmp.EstimatedCollectionAmount = params.CollectionProjection.EstimatedCollectionAmount + tmp.EstimatedCollectionDate = params.CollectionProjection.EstimatedCollectionTime + tmp.SaleChanceId = params.CollectionProjection.SaleChanceId + + errCode := collectionProjectionService.AddCollectionProjection(tmp) + if errCode != ecode.OK { + ctx.Fail(errCode) + return + } + + ctx.Ok() +} diff --git a/api/v1/index.go b/api/v1/index.go index 00c8f70..b1d7c1e 100644 --- a/api/v1/index.go +++ b/api/v1/index.go @@ -65,6 +65,7 @@ VettingApi SatisfactionApi AssignApi + CollectionProjectionApi } var ApiGroup = new(Group) @@ -130,4 +131,5 @@ quotationStatusService = service.ServiceGroup.QuotationStatusService currencyService = service.ServiceGroup.CurrencyService assignService = service.ServiceGroup.AssignService + collectionProjectionService = service.ServiceGroup.CollectionProjectionService ) diff --git a/docs/docs.go b/docs/docs.go index e39c3f4..aa46c54 100644 --- a/docs/docs.go +++ b/docs/docs.go @@ -1242,6 +1242,36 @@ } } }, + "/api/collectionProjection/add": { + "post": { + "produces": [ + "application/json" + ], + "tags": [ + "CollectionProjection" + ], + "summary": "娣诲姞鏀舵棰勬祴", + "parameters": [ + { + "description": "鏌ヨ鍙傛暟", + "name": "object", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/request.AddCollectionProjection" + } + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/contextx.Response" + } + } + } + } + }, "/api/contact/add": { "post": { "produces": [ @@ -10457,6 +10487,12 @@ "description": "閿�鍞礋璐d汉id", "type": "integer" }, + "products": { + "type": "array", + "items": { + "$ref": "#/definitions/model.Product" + } + }, "sourceId": { "description": "婧愬崟id", "type": "integer" @@ -10706,7 +10742,7 @@ "type": "object", "properties": { "amount": { - "type": "integer" + "type": "number" }, "desc": { "type": "string" @@ -11380,6 +11416,13 @@ "amountReceived": { "description": "宸叉敹閲戦", "type": "number" + }, + "amountUnInvoiced": { + "description": "鏈紑绁ㄩ噾棰�", + "type": "number" + }, + "client": { + "$ref": "#/definitions/model.Client" }, "clientId": { "type": "integer" @@ -12060,6 +12103,23 @@ } } }, + "request.AddCollectionProjection": { + "type": "object", + "properties": { + "estimated_collection_amount": { + "description": "棰勮鏀舵閲戦", + "type": "number" + }, + "estimated_collection_time": { + "description": "棰勮鏀舵鏃堕棿", + "type": "string" + }, + "sale_chance_id": { + "description": "閿�鍞満浼歩d", + "type": "integer" + } + } + }, "request.AddContact": { "type": "object", "properties": { @@ -12311,6 +12371,13 @@ "principalId": { "description": "閿�鍞礋璐d汉id", "type": "integer" + }, + "products": { + "description": "鍙戠エ瀵瑰簲浜у搧锛屼粠鐩稿簲婧愬崟閲岃幏鍙�", + "type": "array", + "items": { + "$ref": "#/definitions/model.Product" + } }, "sourceId": { "description": "婧愬崟id", @@ -14907,6 +14974,9 @@ }, "request.UpdateInvoice": { "type": "object", + "required": [ + "id" + ], "properties": { "clientId": { "description": "瀹㈡埛id", @@ -14943,6 +15013,13 @@ "description": "閿�鍞礋璐d汉id", "type": "integer" }, + "products": { + "description": "鍙戠エ瀵瑰簲浜у搧锛屼粠鐩稿簲婧愬崟閲岃幏鍙�", + "type": "array", + "items": { + "$ref": "#/definitions/model.Product" + } + }, "sourceId": { "description": "婧愬崟id", "type": "integer" diff --git a/docs/swagger.json b/docs/swagger.json index 97e2fca..a976d71 100644 --- a/docs/swagger.json +++ b/docs/swagger.json @@ -1230,6 +1230,36 @@ } } }, + "/api/collectionProjection/add": { + "post": { + "produces": [ + "application/json" + ], + "tags": [ + "CollectionProjection" + ], + "summary": "娣诲姞鏀舵棰勬祴", + "parameters": [ + { + "description": "鏌ヨ鍙傛暟", + "name": "object", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/request.AddCollectionProjection" + } + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/contextx.Response" + } + } + } + } + }, "/api/contact/add": { "post": { "produces": [ @@ -10445,6 +10475,12 @@ "description": "閿�鍞礋璐d汉id", "type": "integer" }, + "products": { + "type": "array", + "items": { + "$ref": "#/definitions/model.Product" + } + }, "sourceId": { "description": "婧愬崟id", "type": "integer" @@ -10694,7 +10730,7 @@ "type": "object", "properties": { "amount": { - "type": "integer" + "type": "number" }, "desc": { "type": "string" @@ -11368,6 +11404,13 @@ "amountReceived": { "description": "宸叉敹閲戦", "type": "number" + }, + "amountUnInvoiced": { + "description": "鏈紑绁ㄩ噾棰�", + "type": "number" + }, + "client": { + "$ref": "#/definitions/model.Client" }, "clientId": { "type": "integer" @@ -12048,6 +12091,23 @@ } } }, + "request.AddCollectionProjection": { + "type": "object", + "properties": { + "estimated_collection_amount": { + "description": "棰勮鏀舵閲戦", + "type": "number" + }, + "estimated_collection_time": { + "description": "棰勮鏀舵鏃堕棿", + "type": "string" + }, + "sale_chance_id": { + "description": "閿�鍞満浼歩d", + "type": "integer" + } + } + }, "request.AddContact": { "type": "object", "properties": { @@ -12299,6 +12359,13 @@ "principalId": { "description": "閿�鍞礋璐d汉id", "type": "integer" + }, + "products": { + "description": "鍙戠エ瀵瑰簲浜у搧锛屼粠鐩稿簲婧愬崟閲岃幏鍙�", + "type": "array", + "items": { + "$ref": "#/definitions/model.Product" + } }, "sourceId": { "description": "婧愬崟id", @@ -14895,6 +14962,9 @@ }, "request.UpdateInvoice": { "type": "object", + "required": [ + "id" + ], "properties": { "clientId": { "description": "瀹㈡埛id", @@ -14931,6 +15001,13 @@ "description": "閿�鍞礋璐d汉id", "type": "integer" }, + "products": { + "description": "鍙戠エ瀵瑰簲浜у搧锛屼粠鐩稿簲婧愬崟閲岃幏鍙�", + "type": "array", + "items": { + "$ref": "#/definitions/model.Product" + } + }, "sourceId": { "description": "婧愬崟id", "type": "integer" diff --git a/docs/swagger.yaml b/docs/swagger.yaml index 058fde4..fb0cc54 100644 --- a/docs/swagger.yaml +++ b/docs/swagger.yaml @@ -670,6 +670,10 @@ principalId: description: 閿�鍞礋璐d汉id type: integer + products: + items: + $ref: '#/definitions/model.Product' + type: array sourceId: description: 婧愬崟id type: integer @@ -832,7 +836,7 @@ model.Product: properties: amount: - type: integer + type: number desc: type: string id: @@ -1281,6 +1285,11 @@ amountReceived: description: 宸叉敹閲戦 type: number + amountUnInvoiced: + description: 鏈紑绁ㄩ噾棰� + type: number + client: + $ref: '#/definitions/model.Client' clientId: type: integer contactId: @@ -1744,6 +1753,18 @@ required: - name type: object + request.AddCollectionProjection: + properties: + estimated_collection_amount: + description: 棰勮鏀舵閲戦 + type: number + estimated_collection_time: + description: 棰勮鏀舵鏃堕棿 + type: string + sale_chance_id: + description: 閿�鍞満浼歩d + type: integer + type: object request.AddContact: properties: birthday: @@ -1916,6 +1937,11 @@ principalId: description: 閿�鍞礋璐d汉id type: integer + products: + description: 鍙戠エ瀵瑰簲浜у搧锛屼粠鐩稿簲婧愬崟閲岃幏鍙� + items: + $ref: '#/definitions/model.Product' + type: array sourceId: description: 婧愬崟id type: integer @@ -3711,6 +3737,11 @@ principalId: description: 閿�鍞礋璐d汉id type: integer + products: + description: 鍙戠エ瀵瑰簲浜у搧锛屼粠鐩稿簲婧愬崟閲岃幏鍙� + items: + $ref: '#/definitions/model.Product' + type: array sourceId: description: 婧愬崟id type: integer @@ -3723,6 +3754,8 @@ taxpayerIdNumber: description: 绾崇◣璇嗗埆鍙� type: string + required: + - id type: object request.UpdateInvoiceStatus: properties: @@ -6067,6 +6100,25 @@ summary: 鏇存柊瀹㈡埛绫诲瀷 tags: - ClientType + /api/collectionProjection/add: + post: + parameters: + - description: 鏌ヨ鍙傛暟 + in: body + name: object + required: true + schema: + $ref: '#/definitions/request.AddCollectionProjection' + produces: + - application/json + responses: + "200": + description: OK + schema: + $ref: '#/definitions/contextx.Response' + summary: 娣诲姞鏀舵棰勬祴 + tags: + - CollectionProjection /api/contact/add: post: parameters: diff --git a/model/collectionProjection.go b/model/collectionProjection.go new file mode 100644 index 0000000..c289864 --- /dev/null +++ b/model/collectionProjection.go @@ -0,0 +1,85 @@ +package model + +import ( + "aps_crm/pkg/mysqlx" + "gorm.io/gorm" +) + +type ( + CollectionProjection struct { + Id int `json:"id" gorm:"column:id;primaryKey;autoIncrement;not null"` + SaleChanceId int `json:"sale_chance_id" gorm:"column:sale_chance_id;type:int(11);comment:閿�鍞満浼歩d"` + Creator int `json:"creator" gorm:"column:creator;type:int(11);comment:鍒涘缓浜�"` + Modifier int `json:"modifier" gorm:"column:modifier;type:int(11);comment:淇敼浜�"` + EstimatedCollectionDate string `json:"estimated_collection_date" gorm:"column:estimated_collection_date;type:datetime;comment:棰勮鏀舵鏃ユ湡"` + EstimatedCollectionAmount float64 `json:"estimated_collection_amount" gorm:"column:estimated_collection_amount;type:decimal(10,2);comment:棰勮鏀舵閲戦"` + gorm.Model + } + + CollectionProjectionSearch struct { + CollectionProjection + + Orm *gorm.DB + OrderBy string + PageNum int + PageSize int + } +) + +func (CollectionProjection) TableName() string { + return "collection_projection" +} + +func NewCollectionProjectionSearch() *CollectionProjectionSearch { + return &CollectionProjectionSearch{ + Orm: mysqlx.GetDB(), + } +} + +func (slf *CollectionProjectionSearch) build() *gorm.DB { + var db = slf.Orm.Model(&CollectionProjection{}) + if slf.Id != 0 { + db = db.Where("id = ?", slf.Id) + } + + return db +} + +func (slf *CollectionProjectionSearch) Create(record *CollectionProjection) (err error) { + var db = slf.build() + err = db.Create(record).Error + return +} + +func (slf *CollectionProjectionSearch) Update(record *CollectionProjection) (err error) { + var db = slf.build() + err = db.Updates(record).Error + return +} + +func (slf *CollectionProjectionSearch) Delete() (err error) { + var db = slf.build() + err = db.Delete(&CollectionProjection{}).Error + return +} + +func (slf *CollectionProjectionSearch) Find() (record CollectionProjection, err error) { + var db = slf.build() + err = db.First(&record).Error + return +} + +func (slf *CollectionProjectionSearch) SetID(id int) *CollectionProjectionSearch { + slf.Id = id + return slf +} + +func (slf *CollectionProjectionSearch) SetSaleChanceId(saleChanceId int) *CollectionProjectionSearch { + slf.SaleChanceId = saleChanceId + return slf +} + +func (slf *CollectionProjectionSearch) SetPage(page, size int) *CollectionProjectionSearch { + slf.PageNum, slf.PageSize = page, size + return slf +} diff --git a/model/index.go b/model/index.go index 04856fa..7a90d35 100644 --- a/model/index.go +++ b/model/index.go @@ -1,108 +1,108 @@ -package model - -import ( - "aps_crm/conf" - "aps_crm/pkg/logx" - "aps_crm/pkg/mysqlx" - "aps_crm/pkg/safe" - "gorm.io/gorm/schema" -) - -func Init() error { - if err := mysqlx.Init(&conf.Conf.Mysql, logx.GetLogger()); err != nil { - return err - } - - if err := RegisterTables(); err != nil { - return err - } - safe.Go(func() { - InsertDefaultData() - }) - return nil -} - -func RegisterTables() error { - db := mysqlx.GetDB() - err := db.AutoMigrate( - User{}, - Menu{}, - JwtBlacklist{}, - Country{}, - Province{}, - City{}, - Client{}, - ClientLevel{}, - ClientOrigin{}, - ClientStatus{}, - ClientType{}, - Contact{}, - EnterpriseNature{}, - EnterpriseScale{}, - FollowRecord{}, - Industry{}, - RegisteredCapital{}, - SaleChance{}, - SalesLeads{}, - SalesSources{}, - SaleStage{}, - SaleType{}, - RegularCustomers{}, - Possibility{}, - Status{}, - Quotation{}, - MasterOrder{}, - SubOrder{}, - Product{}, - SalesDetails{}, - SalesReturn{}, - SalesRefund{}, - Contract{}, - Plan{}, - ServiceContract{}, - OrderManage{}, - ServiceFollowup{}, - CustomerServiceSheet{}, - ServiceFeeManage{}, - Authority{}, - Api{}, - Department{}, - Satisfaction{}, - TimelyRate{}, - SolveRate{}, - IsVisit{}, - IsVisit{}, - ReportSource{}, - OrderType{}, - ServiceContractStatus{}, - ServiceContractType{}, - RefundMethod{}, - IsInvoice{}, - AccountId{}, - SalesReturnStatus{}, - Repository{}, - QuotationStatus{}, - Currency{}, - ) - return err -} - -type InitDefaultData interface { - InitDefaultData() error -} - -func InsertDefaultData() { - models := []interface{}{ - NewServiceTypeSearch(), - NewPriorityLevelSearch(), - NewSeveritySearch(), - NewTimeSpentSearch(), - } - for _, model := range models { - if id, ok := model.(InitDefaultData); ok { - if err := id.InitDefaultData(); err != nil { - logx.Errorf("InitDefaultData for table: %v, err :%v", model.(schema.Tabler).TableName(), err.Error()) - } - } - } -} +package model + +import ( + "aps_crm/conf" + "aps_crm/pkg/logx" + "aps_crm/pkg/mysqlx" + "aps_crm/pkg/safe" + "gorm.io/gorm/schema" +) + +func Init() error { + if err := mysqlx.Init(&conf.Conf.Mysql, logx.GetLogger()); err != nil { + return err + } + + if err := RegisterTables(); err != nil { + return err + } + safe.Go(func() { + InsertDefaultData() + }) + return nil +} + +func RegisterTables() error { + db := mysqlx.GetDB() + err := db.AutoMigrate( + User{}, + Menu{}, + JwtBlacklist{}, + Country{}, + Province{}, + City{}, + Client{}, + ClientLevel{}, + ClientOrigin{}, + ClientStatus{}, + ClientType{}, + Contact{}, + EnterpriseNature{}, + EnterpriseScale{}, + FollowRecord{}, + Industry{}, + RegisteredCapital{}, + SaleChance{}, + SalesLeads{}, + SalesSources{}, + SaleStage{}, + SaleType{}, + RegularCustomers{}, + Possibility{}, + Status{}, + Quotation{}, + MasterOrder{}, + SubOrder{}, + Product{}, + SalesDetails{}, + SalesReturn{}, + SalesRefund{}, + Contract{}, + Plan{}, + ServiceContract{}, + OrderManage{}, + ServiceFollowup{}, + CustomerServiceSheet{}, + ServiceFeeManage{}, + Authority{}, + Api{}, + Department{}, + Satisfaction{}, + TimelyRate{}, + SolveRate{}, + IsVisit{}, + IsVisit{}, + ReportSource{}, + OrderType{}, + ServiceContractStatus{}, + ServiceContractType{}, + RefundMethod{}, + IsInvoice{}, + AccountId{}, + SalesReturnStatus{}, + Repository{}, + QuotationStatus{}, + Currency{}, + ) + return err +} + +type InitDefaultData interface { + InitDefaultData() error +} + +func InsertDefaultData() { + models := []interface{}{ + NewServiceTypeSearch(), + NewPriorityLevelSearch(), + NewSeveritySearch(), + NewTimeSpentSearch(), + } + for _, model := range models { + if id, ok := model.(InitDefaultData); ok { + if err := id.InitDefaultData(); err != nil { + logx.Errorf("InitDefaultData for table: %v, err :%v", model.(schema.Tabler).TableName(), err.Error()) + } + } + } +} diff --git a/model/request/collectionProjection.go b/model/request/collectionProjection.go new file mode 100644 index 0000000..e5f1202 --- /dev/null +++ b/model/request/collectionProjection.go @@ -0,0 +1,11 @@ +package request + +type AddCollectionProjection struct { + CollectionProjection +} + +type CollectionProjection struct { + EstimatedCollectionAmount float64 `json:"estimated_collection_amount"` // 棰勮鏀舵閲戦 + EstimatedCollectionTime string `json:"estimated_collection_time"` // 棰勮鏀舵鏃堕棿 + SaleChanceId int `json:"sale_chance_id"` // 閿�鍞満浼歩d +} diff --git a/pkg/ecode/code.go b/pkg/ecode/code.go index 6a3d1a2..9701a5a 100644 --- a/pkg/ecode/code.go +++ b/pkg/ecode/code.go @@ -393,4 +393,9 @@ AssignWrongId = 5700003 // 鍒嗛厤澶辫触锛屽垎閰嶅璞′负绌� AssignWrongModelType = 5700004 // 鍒嗛厤澶辫触锛屽垎閰嶅璞$被鍨嬩负绌� + CollectionProjectionExist = 5800001 // 鏀舵棰勬祴宸插瓨鍦� + CollectionProjectionNotExist = 5800002 // 鏀舵棰勬祴涓嶅瓨鍦� + CollectionProjectionListErr = 5800003 // 鑾峰彇鏀舵棰勬祴鍒楄〃澶辫触 + CollectionProjectionSetErr = 5800004 // 璁剧疆鏀舵棰勬祴澶辫触 + CollectionProjectionUpdateErr = 5800005 // 鏇存柊鏀舵棰勬祴澶辫触 ) diff --git a/router/colletionProjection.go b/router/colletionProjection.go new file mode 100644 index 0000000..80e463e --- /dev/null +++ b/router/colletionProjection.go @@ -0,0 +1,19 @@ +package router + +import ( + v1 "aps_crm/api/v1" + "github.com/gin-gonic/gin" +) + +type CollectionProjectionRouter struct{} + +func (c *CollectionProjectionRouter) InitCollectionProjectionRouter(router *gin.RouterGroup) { + collectionProjectionRouter := router.Group("collectionProjection") + collectionProjectionApi := v1.ApiGroup.CollectionProjectionApi + { + collectionProjectionRouter.POST("add", collectionProjectionApi.Add) // 娣诲姞鏀舵棰勬祴 + //collectionProjectionRouter.DELETE("delete", collectionProjectionApi.Delete) // 鍒犻櫎鏀舵棰勬祴 + //collectionProjectionRouter.PUT("update", collectionProjectionApi.Update) // 鏇存柊鏀舵棰勬祴 + //collectionProjectionRouter.POST("list", collectionProjectionApi.List) // 鑾峰彇鏀舵棰勬祴鍒楄〃 + } +} diff --git a/router/index.go b/router/index.go index 1b0ecd3..bc3afe4 100644 --- a/router/index.go +++ b/router/index.go @@ -70,6 +70,7 @@ DepartmentRouter SatisfactionRouter AssignRouter + CollectionProjectionRouter } func InitRouter() *gin.Engine { @@ -176,7 +177,7 @@ InitInvoiceTypeRouter(PrivateGroup) InitCourierCompanyRouter(PrivateGroup) InitProductRouter(PrivateGroup) - + InitServiceCollectionPlanRouter(PrivateGroup) } return Router } diff --git a/service/collectionProjection.go b/service/collectionProjection.go new file mode 100644 index 0000000..b86d98b --- /dev/null +++ b/service/collectionProjection.go @@ -0,0 +1,17 @@ +package service + +import ( + "aps_crm/model" + "aps_crm/pkg/ecode" +) + +type CollectionProjectionService struct{} + +func (CollectionProjectionService) AddCollectionProjection(collectionProjection *model.CollectionProjection) int { + err := model.NewCollectionProjectionSearch().Create(collectionProjection) + if err != nil { + return ecode.CollectionProjectionExist + } + + return ecode.OK +} diff --git a/service/index.go b/service/index.go index ae1c0c6..e76998e 100644 --- a/service/index.go +++ b/service/index.go @@ -61,6 +61,7 @@ QuotationStatusService CurrencyService AssignService + CollectionProjectionService } var ServiceGroup = new(Group) -- Gitblit v1.8.0