From 7e0823fc3b352cfcbb4a2f21088c00db2c00c395 Mon Sep 17 00:00:00 2001 From: wangpengfei <274878379@qq.com> Date: 星期三, 02 八月 2023 17:29:27 +0800 Subject: [PATCH] fix --- model/request/salesLeads.go | 4 model/salesLeads.go | 4 router/followRecord.go | 2 service/followRecord.go | 124 ++--- service/salesLeads.go | 24 docs/swagger.yaml | 34 + docs/docs.go | 48 + docs/swagger.json | 48 + model/followRecord.go | 374 +++++++++--------- api/v1/salesLeads.go | 11 api/v1/followRecord.go | 447 +++++++++++----------- model/request/followRecord.go | 68 +- router/salesLeads.go | 2 13 files changed, 630 insertions(+), 560 deletions(-) diff --git a/api/v1/followRecord.go b/api/v1/followRecord.go index ca3ef2f..239d715 100644 --- a/api/v1/followRecord.go +++ b/api/v1/followRecord.go @@ -1,224 +1,223 @@ -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" - "time" -) - -type FollowRecordApi struct{} - -// Add -// -// @Tags FollowRecord -// @Summary 娣诲姞璺熻繘璁板綍 -// @Produce application/json -// @Param object body request.AddFollowRecord true "鏌ヨ鍙傛暟" -// @Success 200 {object} contextx.Response{} -// @Router /api/followRecord/add [post] -func (fr *FollowRecordApi) Add(c *gin.Context) { - var params request.AddFollowRecord - ctx, ok := contextx.NewContext(c, ¶ms) - if !ok { - return - } - - errCode, followRecord := checkFollowRecordParams(params.FollowRecord) - if errCode != ecode.OK { - ctx.Fail(errCode) - return - } - - errCode = followRecordService.AddFollowRecord(followRecord) - if errCode != ecode.OK { - ctx.Fail(errCode) - return - } - - ctx.Ok() -} - -// Delete -// -// @Tags FollowRecord -// @Summary 鍒犻櫎璺熻繘璁板綍 -// @Produce application/json -// @Param id path string true "璺熻繘璁板綍id" -// @Success 200 {object} contextx.Response{} -// @Router /api/followRecord/delete/{id} [delete] -func (fr *FollowRecordApi) Delete(c *gin.Context) { - ctx, ok := contextx.NewContext(c, nil) - if !ok { - return - } - - id, _ := strconv.Atoi(c.Param("id")) - errCode := followRecordService.DeleteFollowRecord(id) - if errCode != ecode.OK { - ctx.Fail(errCode) - return - } - - ctx.Ok() -} - -// Update -// -// @Tags FollowRecord -// @Summary 鏇存柊璺熻繘璁板綍 -// @Produce application/json -// @Param object body request.UpdateFollowRecord true "鏌ヨ鍙傛暟" -// @Success 200 {object} contextx.Response{} -// @Router /api/followRecord/update [put] -func (fr *FollowRecordApi) Update(c *gin.Context) { - var params request.UpdateFollowRecord - ctx, ok := contextx.NewContext(c, ¶ms) - if !ok { - return - } - - errCode, followRecord := checkFollowRecordParams(params.FollowRecord) - if errCode != ecode.OK { - ctx.Fail(errCode) - return - } - - followRecord.Id = params.Id - errCode = followRecordService.UpdateFollowRecord(followRecord) - if errCode != ecode.OK { - ctx.Fail(errCode) - return - } - - ctx.Ok() -} - -// checkFollowRecordParams -// 妫�鏌ヨ窡杩涜褰曞弬鏁� -func checkFollowRecordParams(followRecord request.FollowRecord) (int, *model.FollowRecord) { - var followRecordModel model.FollowRecord - - //if followRecord.ClientId != 0 { - // // check client exist - // if service.CheckClientExist(followRecord.ClientId) != ecode.OK { - // return ecode.ClientNotExist, &followRecordModel - // } - //} - // - //if followRecord.ContactId != 0 { - // // check contact exist - // if service.CheckContactExist(followRecord.ContactId) != ecode.OK { - // return ecode.ContactNotExist, &followRecordModel - // } - //} - // - //if followRecord.SalesLeadsId != 0 { - // // check sales leads exist - // if service.CheckSalesLeadsExist(followRecord.SalesLeadsId) != ecode.OK { - // return ecode.SalesLeadsNotExist, &followRecordModel - // } - //} - // - //// check member id - //if followRecord.MemberId == 0 { - // // todo check member exist - // return ecode.InvalidParams, &followRecordModel - //} - // - //// check number - //if followRecord.Number == "" { - // return ecode.InvalidParams, &followRecordModel - //} - // - //// check follow content - //if followRecord.Content == "" { - // return ecode.InvalidParams, &followRecordModel - //} - - // check follow time - t, err := checkTimeFormat(followRecord.FollowTime) - if err != nil { - return ecode.InvalidParams, &followRecordModel - } - - followRecordModel.FollowTime = t - - t, err = checkTimeFormat(followRecord.NextFollowTime) - if err != nil { - return ecode.InvalidParams, &followRecordModel - } - followRecordModel.NextFollowTime = t - - followRecordModel.ClientId = followRecord.ClientId - followRecordModel.Content = followRecord.Content - followRecordModel.MemberId = followRecord.MemberId - followRecordModel.Number = followRecord.Number - followRecordModel.ClientStatusId = followRecord.ClientStatusId - followRecordModel.ContactId = followRecord.ContactId - followRecordModel.Topic = followRecord.Topic - followRecordModel.SalesLeadsId = followRecord.SalesLeadsId - followRecordModel.SaleChanceId = followRecord.SaleChanceId - followRecordModel.ContactInformationId = followRecord.ContactInformationId - followRecordModel.Purpose = followRecord.Purpose - followRecordModel.Content = followRecord.Content - followRecordModel.Record = followRecord.Record - - return ecode.OK, &followRecordModel -} - -// checkTimeFormat -// 妫�鏌ユ椂闂存牸寮� -func checkTimeFormat(t string) (time.Time, error) { - if t == "" { - t = "1900-01-01T00:00:00+08:00" - } - - location, err := time.LoadLocation("Asia/Shanghai") - if err != nil { - return time.Time{}, err - } - - tt, err := time.Parse("2006-01-02T15:04:05.000Z", t) - if err == nil { - return tt.In(location), nil - } - - tt, err = time.Parse("2006-01-02T15:04:05-07:00", t) - if err == nil { - return tt.In(location), nil - } - - return time.Time{}, err -} - -// List -// -// @Tags FollowRecord -// @Summary 鍥炶璁板綍鍒楄〃 -// @Produce application/json -// @Param object body request.GetFollowRecordList true "鍙傛暟" -// @Success 200 {object} contextx.Response{data=response.FollowRecordResponse} -// @Router /api/followRecord/list [post] -func (fr *FollowRecordApi) List(c *gin.Context) { - var params request.GetFollowRecordList - ctx, ok := contextx.NewContext(c, ¶ms) - if !ok { - return - } - - followRecords, total, errCode := followRecordService.GetFollowRecordList(params.Page, params.PageSize, params.Keyword) - if errCode != ecode.OK { - ctx.Fail(errCode) - return - } - - ctx.OkWithDetailed(response.FollowRecordResponse{ - List: followRecords, - Count: int(total), - }) -} \ No newline at end of file +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" + "time" +) + +type FollowRecordApi struct{} + +// Add +// +// @Tags FollowRecord +// @Summary 娣诲姞璺熻繘璁板綍 +// @Produce application/json +// @Param object body request.AddFollowRecord true "鏌ヨ鍙傛暟" +// @Success 200 {object} contextx.Response{} +// @Router /api/followRecord/add [post] +func (fr *FollowRecordApi) Add(c *gin.Context) { + var params request.AddFollowRecord + ctx, ok := contextx.NewContext(c, ¶ms) + if !ok { + return + } + + errCode, followRecord := checkFollowRecordParams(params.FollowRecord) + if errCode != ecode.OK { + ctx.Fail(errCode) + return + } + + errCode = followRecordService.AddFollowRecord(followRecord) + if errCode != ecode.OK { + ctx.Fail(errCode) + return + } + + ctx.Ok() +} + +// Delete +// +// @Tags FollowRecord +// @Summary 鍒犻櫎璺熻繘璁板綍 +// @Produce application/json +// @Param object body request.DeleteFollowRecord true "鏌ヨ鍙傛暟" +// @Success 200 {object} contextx.Response{} +// @Router /api/followRecord/delete [delete] +func (fr *FollowRecordApi) Delete(c *gin.Context) { + var params request.DeleteFollowRecord + ctx, ok := contextx.NewContext(c, ¶ms) + if !ok { + return + } + + errCode := followRecordService.DeleteFollowRecord(params.Ids) + if errCode != ecode.OK { + ctx.Fail(errCode) + return + } + + ctx.Ok() +} + +// Update +// +// @Tags FollowRecord +// @Summary 鏇存柊璺熻繘璁板綍 +// @Produce application/json +// @Param object body request.UpdateFollowRecord true "鏌ヨ鍙傛暟" +// @Success 200 {object} contextx.Response{} +// @Router /api/followRecord/update [put] +func (fr *FollowRecordApi) Update(c *gin.Context) { + var params request.UpdateFollowRecord + ctx, ok := contextx.NewContext(c, ¶ms) + if !ok { + return + } + + errCode, followRecord := checkFollowRecordParams(params.FollowRecord) + if errCode != ecode.OK { + ctx.Fail(errCode) + return + } + + followRecord.Id = params.Id + errCode = followRecordService.UpdateFollowRecord(followRecord) + if errCode != ecode.OK { + ctx.Fail(errCode) + return + } + + ctx.Ok() +} + +// checkFollowRecordParams +// 妫�鏌ヨ窡杩涜褰曞弬鏁� +func checkFollowRecordParams(followRecord request.FollowRecord) (int, *model.FollowRecord) { + var followRecordModel model.FollowRecord + + //if followRecord.ClientId != 0 { + // // check client exist + // if service.CheckClientExist(followRecord.ClientId) != ecode.OK { + // return ecode.ClientNotExist, &followRecordModel + // } + //} + // + //if followRecord.ContactId != 0 { + // // check contact exist + // if service.CheckContactExist(followRecord.ContactId) != ecode.OK { + // return ecode.ContactNotExist, &followRecordModel + // } + //} + // + //if followRecord.SalesLeadsId != 0 { + // // check sales leads exist + // if service.CheckSalesLeadsExist(followRecord.SalesLeadsId) != ecode.OK { + // return ecode.SalesLeadsNotExist, &followRecordModel + // } + //} + // + //// check member id + //if followRecord.MemberId == 0 { + // // todo check member exist + // return ecode.InvalidParams, &followRecordModel + //} + // + //// check number + //if followRecord.Number == "" { + // return ecode.InvalidParams, &followRecordModel + //} + // + //// check follow content + //if followRecord.Content == "" { + // return ecode.InvalidParams, &followRecordModel + //} + + // check follow time + t, err := checkTimeFormat(followRecord.FollowTime) + if err != nil { + return ecode.InvalidParams, &followRecordModel + } + + followRecordModel.FollowTime = t + + t, err = checkTimeFormat(followRecord.NextFollowTime) + if err != nil { + return ecode.InvalidParams, &followRecordModel + } + followRecordModel.NextFollowTime = t + + followRecordModel.ClientId = followRecord.ClientId + followRecordModel.Content = followRecord.Content + followRecordModel.MemberId = followRecord.MemberId + followRecordModel.Number = followRecord.Number + followRecordModel.ClientStatusId = followRecord.ClientStatusId + followRecordModel.ContactId = followRecord.ContactId + followRecordModel.Topic = followRecord.Topic + followRecordModel.SalesLeadsId = followRecord.SalesLeadsId + followRecordModel.SaleChanceId = followRecord.SaleChanceId + followRecordModel.ContactInformationId = followRecord.ContactInformationId + followRecordModel.Purpose = followRecord.Purpose + followRecordModel.Content = followRecord.Content + followRecordModel.Record = followRecord.Record + + return ecode.OK, &followRecordModel +} + +// checkTimeFormat +// 妫�鏌ユ椂闂存牸寮� +func checkTimeFormat(t string) (time.Time, error) { + if t == "" { + t = "1900-01-01T00:00:00+08:00" + } + + location, err := time.LoadLocation("Asia/Shanghai") + if err != nil { + return time.Time{}, err + } + + tt, err := time.Parse("2006-01-02T15:04:05.000Z", t) + if err == nil { + return tt.In(location), nil + } + + tt, err = time.Parse("2006-01-02T15:04:05-07:00", t) + if err == nil { + return tt.In(location), nil + } + + return time.Time{}, err +} + +// List +// +// @Tags FollowRecord +// @Summary 鍥炶璁板綍鍒楄〃 +// @Produce application/json +// @Param object body request.GetFollowRecordList true "鍙傛暟" +// @Success 200 {object} contextx.Response{data=response.FollowRecordResponse} +// @Router /api/followRecord/list [post] +func (fr *FollowRecordApi) List(c *gin.Context) { + var params request.GetFollowRecordList + ctx, ok := contextx.NewContext(c, ¶ms) + if !ok { + return + } + + followRecords, total, errCode := followRecordService.GetFollowRecordList(params.Page, params.PageSize, params.Keyword) + if errCode != ecode.OK { + ctx.Fail(errCode) + return + } + + ctx.OkWithDetailed(response.FollowRecordResponse{ + List: followRecords, + Count: int(total), + }) +} diff --git a/api/v1/salesLeads.go b/api/v1/salesLeads.go index c0b3215..af5f778 100644 --- a/api/v1/salesLeads.go +++ b/api/v1/salesLeads.go @@ -8,7 +8,6 @@ "aps_crm/pkg/contextx" "aps_crm/pkg/ecode" "github.com/gin-gonic/gin" - "strconv" ) type SalesLeadsApi struct{} @@ -48,17 +47,17 @@ // @Tags SalesLeads // @Summary 鍒犻櫎閿�鍞嚎绱� // @Produce application/json -// @Param id path int true "鏌ヨ鍙傛暟" +// @Param object body request.DeleteSalesLeads true "鏌ヨ鍙傛暟" // @Success 200 {object} contextx.Response{} -// @Router /api/salesLeads/delete/{id} [delete] +// @Router /api/salesLeads/delete [delete] func (s *SalesLeadsApi) Delete(c *gin.Context) { - ctx, ok := contextx.NewContext(c, nil) + var params request.DeleteSalesLeads + ctx, ok := contextx.NewContext(c, ¶ms) if !ok { return } - id, _ := strconv.Atoi(c.Param("id")) - errCode := salesLeadsService.DeleteSalesLeads(id) + errCode := salesLeadsService.DeleteSalesLeads(params.Ids) if errCode != ecode.OK { ctx.Fail(errCode) return diff --git a/docs/docs.go b/docs/docs.go index 109093a..c98b043 100644 --- a/docs/docs.go +++ b/docs/docs.go @@ -2106,7 +2106,7 @@ } } }, - "/api/followRecord/delete/{id}": { + "/api/followRecord/delete": { "delete": { "produces": [ "application/json" @@ -2117,11 +2117,13 @@ "summary": "鍒犻櫎璺熻繘璁板綍", "parameters": [ { - "type": "string", - "description": "璺熻繘璁板綍id", - "name": "id", - "in": "path", - "required": true + "description": "鏌ヨ鍙傛暟", + "name": "object", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/request.DeleteFollowRecord" + } } ], "responses": { @@ -4943,7 +4945,7 @@ } } }, - "/api/salesLeads/delete/{id}": { + "/api/salesLeads/delete": { "delete": { "produces": [ "application/json" @@ -4954,11 +4956,13 @@ "summary": "鍒犻櫎閿�鍞嚎绱�", "parameters": [ { - "type": "integer", "description": "鏌ヨ鍙傛暟", - "name": "id", - "in": "path", - "required": true + "name": "object", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/request.DeleteSalesLeads" + } } ], "responses": { @@ -9954,6 +9958,28 @@ } } }, + "request.DeleteFollowRecord": { + "type": "object", + "properties": { + "ids": { + "type": "array", + "items": { + "type": "integer" + } + } + } + }, + "request.DeleteSalesLeads": { + "type": "object", + "properties": { + "ids": { + "type": "array", + "items": { + "type": "integer" + } + } + } + }, "request.DeleteUserReq": { "type": "object", "properties": { diff --git a/docs/swagger.json b/docs/swagger.json index 55b7c9e..f8580fa 100644 --- a/docs/swagger.json +++ b/docs/swagger.json @@ -2094,7 +2094,7 @@ } } }, - "/api/followRecord/delete/{id}": { + "/api/followRecord/delete": { "delete": { "produces": [ "application/json" @@ -2105,11 +2105,13 @@ "summary": "鍒犻櫎璺熻繘璁板綍", "parameters": [ { - "type": "string", - "description": "璺熻繘璁板綍id", - "name": "id", - "in": "path", - "required": true + "description": "鏌ヨ鍙傛暟", + "name": "object", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/request.DeleteFollowRecord" + } } ], "responses": { @@ -4931,7 +4933,7 @@ } } }, - "/api/salesLeads/delete/{id}": { + "/api/salesLeads/delete": { "delete": { "produces": [ "application/json" @@ -4942,11 +4944,13 @@ "summary": "鍒犻櫎閿�鍞嚎绱�", "parameters": [ { - "type": "integer", "description": "鏌ヨ鍙傛暟", - "name": "id", - "in": "path", - "required": true + "name": "object", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/request.DeleteSalesLeads" + } } ], "responses": { @@ -9942,6 +9946,28 @@ } } }, + "request.DeleteFollowRecord": { + "type": "object", + "properties": { + "ids": { + "type": "array", + "items": { + "type": "integer" + } + } + } + }, + "request.DeleteSalesLeads": { + "type": "object", + "properties": { + "ids": { + "type": "array", + "items": { + "type": "integer" + } + } + } + }, "request.DeleteUserReq": { "type": "object", "properties": { diff --git a/docs/swagger.yaml b/docs/swagger.yaml index ddfa118..f791646 100644 --- a/docs/swagger.yaml +++ b/docs/swagger.yaml @@ -1918,6 +1918,20 @@ description: 鍥藉ID type: integer type: object + request.DeleteFollowRecord: + properties: + ids: + items: + type: integer + type: array + type: object + request.DeleteSalesLeads: + properties: + ids: + items: + type: integer + type: array + type: object request.DeleteUserReq: properties: userId: @@ -5372,14 +5386,15 @@ summary: 娣诲姞璺熻繘璁板綍 tags: - FollowRecord - /api/followRecord/delete/{id}: + /api/followRecord/delete: delete: parameters: - - description: 璺熻繘璁板綍id - in: path - name: id + - description: 鏌ヨ鍙傛暟 + in: body + name: object required: true - type: string + schema: + $ref: '#/definitions/request.DeleteFollowRecord' produces: - application/json responses: @@ -7114,14 +7129,15 @@ summary: 娣诲姞閿�鍞嚎绱� tags: - SalesLeads - /api/salesLeads/delete/{id}: + /api/salesLeads/delete: delete: parameters: - description: 鏌ヨ鍙傛暟 - in: path - name: id + in: body + name: object required: true - type: integer + schema: + $ref: '#/definitions/request.DeleteSalesLeads' produces: - application/json responses: diff --git a/model/followRecord.go b/model/followRecord.go index 7107b14..352cd29 100644 --- a/model/followRecord.go +++ b/model/followRecord.go @@ -1,185 +1,189 @@ -package model - -import ( - "aps_crm/pkg/mysqlx" - "gorm.io/gorm" - "time" -) - -type ( - FollowRecord struct { - Id int `json:"id" gorm:"column:id;primary_key;AUTO_INCREMENT"` - ClientId int `json:"client_id" gorm:"column:client_id;type:int(11);comment:瀹㈡埛id"` - ClientStatusId int `json:"client_status_id" gorm:"column:client_status_id;type:int(11);comment:瀹㈡埛鐘舵�乮d"` - MemberId int `json:"member_id" gorm:"column:member_id;type:int(11);comment:璺熻繘浜篿d"` - Number string `json:"number" gorm:"column:number;type:varchar(255);comment:璺熻繘缂栧彿"` - ContactId int `json:"contact_id" gorm:"column:contact_id;type:int(11);comment:鑱旂郴浜篿d"` - Topic string `json:"topic" gorm:"column:topic;type:varchar(255);comment:璺熻繘涓婚"` - Record string `json:"record" gorm:"column:record;type:MEDIUMTEXT;comment:璺熻繘璁板綍"` - SaleChanceId int `json:"sale_chance_id" gorm:"column:sale_chance_id;type:int(11);comment:閿�鍞満浼歩d"` - SalesLeadsId int `json:"sales_leads_id" gorm:"column:sales_leads_id;type:int(11);comment:閿�鍞嚎绱d"` - ContactInformationId int `json:"contact_information_id" gorm:"column:contact_information_id;type:int(11);comment:鑱旂郴鏂瑰紡id"` - FollowTime time.Time `json:"follow_time" gorm:"column:follow_time;type:datetime;comment:璺熻繘鏃堕棿"` - NextFollowTime time.Time `json:"next_follow_time" gorm:"column:next_follow_time;type:datetime;comment:涓嬫璺熻繘鏃堕棿"` - Purpose string `json:"purpose" gorm:"column:purpose;type:varchar(255);comment:璺熻繘鐩殑"` - Content string `json:"content" gorm:"column:content;type:MEDIUMTEXT;comment:璺熻繘鍐呭"` - Client Client `json:"client" gorm:"foreignKey:ClientId"` - Contact Contact `json:"contact" gorm:"foreignKey:ContactId"` - gorm.Model `json:"-"` - } - - FollowRecordSearch struct { - FollowRecord - - Orm *gorm.DB - Keyword string - OrderBy string - PageNum int - PageSize int - } -) - -func (FollowRecord) TableName() string { - return "follow_records" -} - -func NewFollowRecordSearch() *FollowRecordSearch { - return &FollowRecordSearch{ - Orm: mysqlx.GetDB(), - } -} - -func (slf *FollowRecordSearch) build() *gorm.DB { - var db = slf.Orm.Model(&FollowRecord{}) - if slf.Keyword != "" { - db = db.Where("name LIKE ?", "%"+slf.Keyword+"%") - } - if slf.Keyword != "" { - db = db.Where("topic LIKE ?", "%"+slf.Keyword+"%") - } - if slf.Id != 0 { - db = db.Where("id = ?", slf.Id) - } - if slf.ClientId != 0 { - db = db.Where("client_id = ?", slf.ClientId) - } - if slf.ClientStatusId != 0 { - db = db.Where("client_status_id = ?", slf.ClientStatusId) - } - if slf.MemberId != 0 { - db = db.Where("member_id = ?", slf.MemberId) - } - if slf.Number != "" { - db = db.Where("number = ?", slf.Number) - } - if slf.ContactId != 0 { - db = db.Where("contact_id = ?", slf.ContactId) - } - if slf.Topic != "" { - db = db.Where("topic = ?", slf.Topic) - } - if slf.Record != "" { - db = db.Where("record = ?", slf.Record) - } - if slf.SaleChanceId != 0 { - db = db.Where("sale_chance_id = ?", slf.SaleChanceId) - } - if slf.SalesLeadsId != 0 { - db = db.Where("sales_leads_id = ?", slf.SalesLeadsId) - } - if slf.ContactInformationId != 0 { - db = db.Where("contact_information_id = ?", slf.ContactInformationId) - } - if !slf.FollowTime.IsZero() { - db = db.Where("follow_time = ?", slf.FollowTime) - } - if !slf.NextFollowTime.IsZero() { - db = db.Where("next_follow_time = ?", slf.NextFollowTime) - } - if slf.Purpose != "" { - db = db.Where("purpose = ?", slf.Purpose) - } - if slf.Content != "" { - db = db.Where("content = ?", slf.Content) - } - - return db -} - -func (slf *FollowRecordSearch) First() (*FollowRecord, error) { - var record = new(FollowRecord) - err := slf.build().First(record).Error - return record, err -} - -func (slf *FollowRecordSearch) FindAll() ([]*FollowRecord, int64, error) { - var db = slf.build() - var records = make([]*FollowRecord, 0) - var total int64 - if err := db.Count(&total).Error; err != nil { - return records, total, err - } - if slf.PageNum > 0 && slf.PageSize > 0 { - db = db.Limit(slf.PageSize).Offset((slf.PageNum - 1) * slf.PageSize) - } - - err := db.Preload("Client").Preload("Contact").Find(&records).Error - return records, total, err -} - -func (slf *FollowRecordSearch) Count() (int64, error) { - var count int64 - err := slf.build().Count(&count).Error - return count, err -} - -func (slf *FollowRecordSearch) Page(page, pageSize int) ([]*FollowRecord, int64, error) { - var records = make([]*FollowRecord, 0) - var count int64 - err := slf.build().Count(&count).Error - if err != nil { - return records, count, err - } - err = slf.build().Offset((page - 1) * pageSize).Limit(pageSize).Find(&records).Error - return records, count, err -} - -func (slf *FollowRecordSearch) Create(record *FollowRecord) error { - var db = slf.build() - return db.Create(record).Error -} - -func (slf *FollowRecordSearch) Update(record *FollowRecord) error { - var db = slf.build() - return db.Updates(record).Error -} - -func (slf *FollowRecordSearch) Delete() error { - var db = slf.build() - return db.Delete(&slf.FollowRecord).Error -} - -func (slf *FollowRecordSearch) SetId(id int) *FollowRecordSearch { - slf.Id = id - return slf -} - -func (slf *FollowRecordSearch) SetClientId(clientId int) *FollowRecordSearch { - slf.ClientId = clientId - return slf -} - -func (slf *FollowRecordSearch) SetKeyword(keyword string) *FollowRecordSearch { - slf.Keyword = keyword - return slf -} - -func (slf *FollowRecordSearch) SetPage(page, size int) *FollowRecordSearch { - slf.PageNum, slf.PageSize = page, size - return slf -} - -func (slf *FollowRecordSearch) SetOrder(order string) *FollowRecordSearch { - slf.OrderBy = order - return slf -} +package model + +import ( + "aps_crm/pkg/mysqlx" + "gorm.io/gorm" + "time" +) + +type ( + FollowRecord struct { + Id int `json:"id" gorm:"column:id;primary_key;AUTO_INCREMENT"` + ClientId int `json:"client_id" gorm:"column:client_id;type:int(11);comment:瀹㈡埛id"` + ClientStatusId int `json:"client_status_id" gorm:"column:client_status_id;type:int(11);comment:瀹㈡埛鐘舵�乮d"` + MemberId int `json:"member_id" gorm:"column:member_id;type:int(11);comment:璺熻繘浜篿d"` + Number string `json:"number" gorm:"column:number;type:varchar(255);comment:璺熻繘缂栧彿"` + ContactId int `json:"contact_id" gorm:"column:contact_id;type:int(11);comment:鑱旂郴浜篿d"` + Topic string `json:"topic" gorm:"column:topic;type:varchar(255);comment:璺熻繘涓婚"` + Record string `json:"record" gorm:"column:record;type:MEDIUMTEXT;comment:璺熻繘璁板綍"` + SaleChanceId int `json:"sale_chance_id" gorm:"column:sale_chance_id;type:int(11);comment:閿�鍞満浼歩d"` + SalesLeadsId int `json:"sales_leads_id" gorm:"column:sales_leads_id;type:int(11);comment:閿�鍞嚎绱d"` + ContactInformationId int `json:"contact_information_id" gorm:"column:contact_information_id;type:int(11);comment:鑱旂郴鏂瑰紡id"` + FollowTime time.Time `json:"follow_time" gorm:"column:follow_time;type:datetime;comment:璺熻繘鏃堕棿"` + NextFollowTime time.Time `json:"next_follow_time" gorm:"column:next_follow_time;type:datetime;comment:涓嬫璺熻繘鏃堕棿"` + Purpose string `json:"purpose" gorm:"column:purpose;type:varchar(255);comment:璺熻繘鐩殑"` + Content string `json:"content" gorm:"column:content;type:MEDIUMTEXT;comment:璺熻繘鍐呭"` + Client Client `json:"client" gorm:"foreignKey:ClientId"` + Contact Contact `json:"contact" gorm:"foreignKey:ContactId"` + gorm.Model `json:"-"` + } + + FollowRecordSearch struct { + FollowRecord + + Orm *gorm.DB + Keyword string + OrderBy string + PageNum int + PageSize int + } +) + +func (FollowRecord) TableName() string { + return "follow_records" +} + +func NewFollowRecordSearch() *FollowRecordSearch { + return &FollowRecordSearch{ + Orm: mysqlx.GetDB(), + } +} + +func (slf *FollowRecordSearch) build() *gorm.DB { + var db = slf.Orm.Model(&FollowRecord{}) + if slf.Keyword != "" { + db = db.Where("name LIKE ?", "%"+slf.Keyword+"%") + } + if slf.Keyword != "" { + db = db.Where("topic LIKE ?", "%"+slf.Keyword+"%") + } + if slf.Id != 0 { + db = db.Where("id = ?", slf.Id) + } + if slf.ClientId != 0 { + db = db.Where("client_id = ?", slf.ClientId) + } + if slf.ClientStatusId != 0 { + db = db.Where("client_status_id = ?", slf.ClientStatusId) + } + if slf.MemberId != 0 { + db = db.Where("member_id = ?", slf.MemberId) + } + if slf.Number != "" { + db = db.Where("number = ?", slf.Number) + } + if slf.ContactId != 0 { + db = db.Where("contact_id = ?", slf.ContactId) + } + if slf.Topic != "" { + db = db.Where("topic = ?", slf.Topic) + } + if slf.Record != "" { + db = db.Where("record = ?", slf.Record) + } + if slf.SaleChanceId != 0 { + db = db.Where("sale_chance_id = ?", slf.SaleChanceId) + } + if slf.SalesLeadsId != 0 { + db = db.Where("sales_leads_id = ?", slf.SalesLeadsId) + } + if slf.ContactInformationId != 0 { + db = db.Where("contact_information_id = ?", slf.ContactInformationId) + } + if !slf.FollowTime.IsZero() { + db = db.Where("follow_time = ?", slf.FollowTime) + } + if !slf.NextFollowTime.IsZero() { + db = db.Where("next_follow_time = ?", slf.NextFollowTime) + } + if slf.Purpose != "" { + db = db.Where("purpose = ?", slf.Purpose) + } + if slf.Content != "" { + db = db.Where("content = ?", slf.Content) + } + + return db +} + +func (slf *FollowRecordSearch) First() (*FollowRecord, error) { + var record = new(FollowRecord) + err := slf.build().First(record).Error + return record, err +} + +func (slf *FollowRecordSearch) FindAll() ([]*FollowRecord, int64, error) { + var db = slf.build() + var records = make([]*FollowRecord, 0) + var total int64 + if err := db.Count(&total).Error; err != nil { + return records, total, err + } + if slf.PageNum > 0 && slf.PageSize > 0 { + db = db.Limit(slf.PageSize).Offset((slf.PageNum - 1) * slf.PageSize) + } + + err := db.Preload("Client").Preload("Contact").Find(&records).Error + return records, total, err +} + +func (slf *FollowRecordSearch) Count() (int64, error) { + var count int64 + err := slf.build().Count(&count).Error + return count, err +} + +func (slf *FollowRecordSearch) Page(page, pageSize int) ([]*FollowRecord, int64, error) { + var records = make([]*FollowRecord, 0) + var count int64 + err := slf.build().Count(&count).Error + if err != nil { + return records, count, err + } + err = slf.build().Offset((page - 1) * pageSize).Limit(pageSize).Find(&records).Error + return records, count, err +} + +func (slf *FollowRecordSearch) Create(record *FollowRecord) error { + var db = slf.build() + return db.Create(record).Error +} + +func (slf *FollowRecordSearch) Update(record *FollowRecord) error { + var db = slf.build() + return db.Updates(record).Error +} + +func (slf *FollowRecordSearch) Delete() error { + var db = slf.build() + return db.Delete(&slf.FollowRecord).Error +} + +func (slf *FollowRecordSearch) SetId(id int) *FollowRecordSearch { + slf.Id = id + return slf +} + +func (slf *FollowRecordSearch) SetClientId(clientId int) *FollowRecordSearch { + slf.ClientId = clientId + return slf +} + +func (slf *FollowRecordSearch) SetKeyword(keyword string) *FollowRecordSearch { + slf.Keyword = keyword + return slf +} + +func (slf *FollowRecordSearch) SetPage(page, size int) *FollowRecordSearch { + slf.PageNum, slf.PageSize = page, size + return slf +} + +func (slf *FollowRecordSearch) SetOrder(order string) *FollowRecordSearch { + slf.OrderBy = order + return slf +} +func (slf *FollowRecordSearch) SetIds(ids []int) *FollowRecordSearch { + slf.Orm = slf.Orm.Where("id in (?)", ids) + return slf +} diff --git a/model/request/followRecord.go b/model/request/followRecord.go index b24bda9..084736a 100644 --- a/model/request/followRecord.go +++ b/model/request/followRecord.go @@ -1,32 +1,36 @@ -package request - -type AddFollowRecord struct { - FollowRecord FollowRecord `json:"follow_record" binding:"required"` -} - -type FollowRecord struct { - ClientId int `json:"client_id" gorm:"column:client_id;type:int(11);comment:瀹㈡埛id"` - ClientStatusId int `json:"client_status_id" gorm:"column:client_status_id;type:int(11);comment:瀹㈡埛鐘舵�乮d"` - MemberId int `json:"member_id" gorm:"column:member_id;type:int(11);comment:璺熻繘浜篿d"` - Number string `json:"number" gorm:"column:number;type:varchar(255);comment:璺熻繘缂栧彿"` - ContactId int `json:"contact_id" gorm:"column:contact_id;type:int(11);comment:鑱旂郴浜篿d"` - Topic string `json:"topic" gorm:"column:topic;type:varchar(255);comment:璺熻繘涓婚"` - Record string `json:"record" gorm:"column:record;type:MEDIUMTEXT;comment:璺熻繘璁板綍"` - SaleChanceId int `json:"sale_chance_id" gorm:"column:sale_chance_id;type:int(11);comment:閿�鍞満浼歩d"` - SalesLeadsId int `json:"sales_leads_id" gorm:"column:sales_leads_id;type:int(11);comment:閿�鍞嚎绱d"` - ContactInformationId int `json:"contact_information_id" gorm:"column:contact_information_id;type:int(11);comment:鑱旂郴鏂瑰紡id"` - FollowTime string `json:"follow_time" gorm:"column:follow_time;type:datetime;comment:璺熻繘鏃堕棿"` - NextFollowTime string `json:"next_follow_time" gorm:"column:next_follow_time;type:datetime;comment:涓嬫璺熻繘鏃堕棿"` - Purpose string `json:"purpose" gorm:"column:purpose;type:varchar(255);comment:璺熻繘鐩殑"` - Content string `json:"content" gorm:"column:content;type:varchar(255);comment:璺熻繘鍐呭"` -} - -type UpdateFollowRecord struct { - Id int `json:"id" gorm:"column:id;primary_key;AUTO_INCREMENT"` - FollowRecord FollowRecord `json:"follow_record" binding:"required"` -} - -type GetFollowRecordList struct { - PageInfo - Keyword string `json:"keyword"` -} +package request + +type AddFollowRecord struct { + FollowRecord FollowRecord `json:"follow_record" binding:"required"` +} + +type FollowRecord struct { + ClientId int `json:"client_id" gorm:"column:client_id;type:int(11);comment:瀹㈡埛id"` + ClientStatusId int `json:"client_status_id" gorm:"column:client_status_id;type:int(11);comment:瀹㈡埛鐘舵�乮d"` + MemberId int `json:"member_id" gorm:"column:member_id;type:int(11);comment:璺熻繘浜篿d"` + Number string `json:"number" gorm:"column:number;type:varchar(255);comment:璺熻繘缂栧彿"` + ContactId int `json:"contact_id" gorm:"column:contact_id;type:int(11);comment:鑱旂郴浜篿d"` + Topic string `json:"topic" gorm:"column:topic;type:varchar(255);comment:璺熻繘涓婚"` + Record string `json:"record" gorm:"column:record;type:MEDIUMTEXT;comment:璺熻繘璁板綍"` + SaleChanceId int `json:"sale_chance_id" gorm:"column:sale_chance_id;type:int(11);comment:閿�鍞満浼歩d"` + SalesLeadsId int `json:"sales_leads_id" gorm:"column:sales_leads_id;type:int(11);comment:閿�鍞嚎绱d"` + ContactInformationId int `json:"contact_information_id" gorm:"column:contact_information_id;type:int(11);comment:鑱旂郴鏂瑰紡id"` + FollowTime string `json:"follow_time" gorm:"column:follow_time;type:datetime;comment:璺熻繘鏃堕棿"` + NextFollowTime string `json:"next_follow_time" gorm:"column:next_follow_time;type:datetime;comment:涓嬫璺熻繘鏃堕棿"` + Purpose string `json:"purpose" gorm:"column:purpose;type:varchar(255);comment:璺熻繘鐩殑"` + Content string `json:"content" gorm:"column:content;type:varchar(255);comment:璺熻繘鍐呭"` +} + +type UpdateFollowRecord struct { + Id int `json:"id" gorm:"column:id;primary_key;AUTO_INCREMENT"` + FollowRecord FollowRecord `json:"follow_record" binding:"required"` +} + +type GetFollowRecordList struct { + PageInfo + Keyword string `json:"keyword"` +} + +type DeleteFollowRecord struct { + Ids []int `json:"ids"` +} diff --git a/model/request/salesLeads.go b/model/request/salesLeads.go index 578feb7..b7c9208 100644 --- a/model/request/salesLeads.go +++ b/model/request/salesLeads.go @@ -25,3 +25,7 @@ PageInfo Keyword string `json:"keyword"` } + +type DeleteSalesLeads struct { + Ids []int `json:"ids"` +} diff --git a/model/salesLeads.go b/model/salesLeads.go index 796e15e..fa5951e 100644 --- a/model/salesLeads.go +++ b/model/salesLeads.go @@ -163,3 +163,7 @@ var db = slf.build() return db.Updates(data).Error } +func (slf *SalesLeadsSearch) SetIds(ids []int) *SalesLeadsSearch { + slf.Orm = slf.Orm.Where("id in (?)", ids) + return slf +} diff --git a/router/followRecord.go b/router/followRecord.go index 0dbe91c..b3e34eb 100644 --- a/router/followRecord.go +++ b/router/followRecord.go @@ -12,7 +12,7 @@ followRecordApi := v1.ApiGroup.FollowRecordApi { followRecordRouter.POST("add", followRecordApi.Add) // 娣诲姞璺熻繘璁板綍 - followRecordRouter.DELETE("delete/:id", followRecordApi.Delete) // 鍒犻櫎璺熻繘璁板綍 + followRecordRouter.DELETE("delete", followRecordApi.Delete) // 鍒犻櫎璺熻繘璁板綍 followRecordRouter.PUT("update", followRecordApi.Update) // 鏇存柊璺熻繘璁板綍 followRecordRouter.POST("list", followRecordApi.List) // 鑾峰彇璺熻繘璁板綍鍒楄〃 } diff --git a/router/salesLeads.go b/router/salesLeads.go index 9e810ef..30860a4 100644 --- a/router/salesLeads.go +++ b/router/salesLeads.go @@ -12,7 +12,7 @@ salesLeadsApi := v1.ApiGroup.SalesLeadsApi { salesLeadsRouter.POST("add", salesLeadsApi.Add) // 娣诲姞閿�鍞嚎绱� - salesLeadsRouter.DELETE("delete/:id", salesLeadsApi.Delete) // 鍒犻櫎閿�鍞嚎绱� + salesLeadsRouter.DELETE("delete", salesLeadsApi.Delete) // 鍒犻櫎閿�鍞嚎绱� salesLeadsRouter.PUT("update", salesLeadsApi.Update) // 鏇存柊閿�鍞嚎绱� salesLeadsRouter.POST("list", salesLeadsApi.List) // 鑾峰彇閿�鍞嚎绱㈠垪琛� } diff --git a/service/followRecord.go b/service/followRecord.go index e765804..44b464b 100644 --- a/service/followRecord.go +++ b/service/followRecord.go @@ -1,65 +1,59 @@ -package service - -import ( - "aps_crm/model" - "aps_crm/pkg/ecode" -) - -type FollowRecordService struct{} - -func (FollowRecordService) AddFollowRecord(followRecord *model.FollowRecord) int { - err := model.NewFollowRecordSearch().Create(followRecord) - if err != nil { - return ecode.FollowRecordExist - } - return ecode.OK -} - -func (FollowRecordService) DeleteFollowRecord(id int) int { - // check followRecord exist - _, err := model.NewFollowRecordSearch().SetId(id).First() - if err != nil { - return ecode.FollowRecordNotExist - } - - // delete followRecord - err = model.NewFollowRecordSearch().SetId(id).Delete() - if err != nil { - return ecode.FollowRecordDeleteErr - } - return ecode.OK -} - -// check followRecord exist -func checkFollowRecordExist(id int) int { - _, err := model.NewFollowRecordSearch().SetId(id).First() - if err != nil { - return ecode.FollowRecordNotExist - } - - return ecode.OK -} - -func (FollowRecordService) UpdateFollowRecord(followRecord *model.FollowRecord) int { - // check followRecord exist - errCode := checkFollowRecordExist(followRecord.Id) - if errCode != ecode.OK { - return errCode - } - - // update followRecord - err := model.NewFollowRecordSearch().SetId(followRecord.Id).Update(followRecord) - if err != nil { - return ecode.FollowRecordUpdateErr - } - return ecode.OK -} - -func (FollowRecordService) GetFollowRecordList(page, pageSize int, keyword string) ([]*model.FollowRecord, int64, int) { - // get contact list - contacts, total, err := model.NewFollowRecordSearch().SetKeyword(keyword).SetPage(page, pageSize).FindAll() - if err != nil { - return nil, 0, ecode.FollowRecordListErr - } - return contacts, total, ecode.OK -} \ No newline at end of file +package service + +import ( + "aps_crm/model" + "aps_crm/pkg/ecode" +) + +type FollowRecordService struct{} + +func (FollowRecordService) AddFollowRecord(followRecord *model.FollowRecord) int { + err := model.NewFollowRecordSearch().Create(followRecord) + if err != nil { + return ecode.FollowRecordExist + } + return ecode.OK +} + +// check followRecord exist +func checkFollowRecordExist(id int) int { + _, err := model.NewFollowRecordSearch().SetId(id).First() + if err != nil { + return ecode.FollowRecordNotExist + } + + return ecode.OK +} + +func (FollowRecordService) UpdateFollowRecord(followRecord *model.FollowRecord) int { + // check followRecord exist + errCode := checkFollowRecordExist(followRecord.Id) + if errCode != ecode.OK { + return errCode + } + + // update followRecord + err := model.NewFollowRecordSearch().SetId(followRecord.Id).Update(followRecord) + if err != nil { + return ecode.FollowRecordUpdateErr + } + return ecode.OK +} + +func (FollowRecordService) GetFollowRecordList(page, pageSize int, keyword string) ([]*model.FollowRecord, int64, int) { + // get contact list + contacts, total, err := model.NewFollowRecordSearch().SetKeyword(keyword).SetPage(page, pageSize).FindAll() + if err != nil { + return nil, 0, ecode.FollowRecordListErr + } + return contacts, total, ecode.OK +} + +func (FollowRecordService) DeleteFollowRecord(ids []int) int { + // delete client + err := model.NewFollowRecordSearch().SetIds(ids).Delete() + if err != nil { + return ecode.FollowRecordDeleteErr + } + return ecode.OK +} diff --git a/service/salesLeads.go b/service/salesLeads.go index f31fd9a..cced6d3 100644 --- a/service/salesLeads.go +++ b/service/salesLeads.go @@ -15,21 +15,6 @@ return ecode.OK } -func (SalesLeadsService) DeleteSalesLeads(id int) int { - // check salesLeads exist - _, err := model.NewSalesLeadsSearch().SetId(id).Find() - if err != nil { - return ecode.SalesLeadsNotExist - } - - // delete salesLeads - err = model.NewSalesLeadsSearch().SetId(id).Delete() - if err != nil { - return ecode.SalesLeadsDeleteErr - } - return ecode.OK -} - func (SalesLeadsService) UpdateSalesLeads(salesLeads *model.SalesLeads) int { // update salesLeads err := model.NewSalesLeadsSearch().SetId(salesLeads.Id).Update(salesLeads) @@ -80,3 +65,12 @@ return ecode.OK } + +func (SalesLeadsService) DeleteSalesLeads(ids []int) int { + // delete client + err := model.NewSalesLeadsSearch().SetIds(ids).Delete() + if err != nil { + return ecode.SalesLeadsDeleteErr + } + return ecode.OK +} -- Gitblit v1.8.0