From 115bd9b51f5d8eade4658f844de37516486c60e7 Mon Sep 17 00:00:00 2001 From: liujiandao <274878379@qq.com> Date: 星期六, 18 十一月 2023 17:25:25 +0800 Subject: [PATCH] crm获取aps项目模块信息 --- model/serviceFollowup.go | 188 +++++++++++++++++++++++++++++++++++++++------- 1 files changed, 159 insertions(+), 29 deletions(-) diff --git a/model/serviceFollowup.go b/model/serviceFollowup.go index c534dcf..65ffa14 100644 --- a/model/serviceFollowup.go +++ b/model/serviceFollowup.go @@ -1,38 +1,56 @@ package model import ( + "aps_crm/constvar" "aps_crm/pkg/mysqlx" + "fmt" "gorm.io/gorm" + "gorm.io/gorm/clause" ) type ( ServiceFollowup struct { - Id int `json:"id" gorm:"column:id;primary_key;AUTO_INCREMENT"` - ClientId int `json:"clientId" gorm:"column:client_id;type:int;comment:瀹㈡埛id"` - Number string `json:"number" gorm:"column:number;type:varchar(255);comment:鍚堝悓缂栧彿"` - ContactId int `json:"contactId" gorm:"column:contact_id;type:int;comment:鑱旂郴浜篿d"` - ServiceId int `json:"serviceId" gorm:"column:service_id;type:int;comment:瀹㈡埛鏈嶅姟鍗昳d"` - CustomerServiceSheet CustomerServiceSheet `json:"customerServiceSheet" gorm:"foreignKey:ServiceId"` - MemberId int `json:"memberId" gorm:"column:member_id;type:int;comment:鏈嶅姟浜哄憳id"` - PlanId int `json:"planId" gorm:"column:plan_id;type:int;comment:鏈嶅姟璁″垝id"` - SatisfactionId int `json:"satisfactionId" gorm:"column:satisfaction_id;type:int;comment:婊℃剰搴d"` - TimelyRateId int `json:"timelyRateId" gorm:"column:timely_rate_id;type:int;comment:鍙婃椂鐜噄d"` - SolveRateId int `json:"solveRateId" gorm:"column:solve_rate_id;type:int;comment:瑙e喅鐜噄d"` - IsVisitId int `json:"isVisitId" gorm:"column:is_visit_id;type:int;comment:鏈嶅姟浜哄憳鏄惁鏉ヨ繃id"` - OldMemberId int `json:"oldMemberId" gorm:"column:old_member_id;type:int;comment:鍘熸湇鍔′汉鍛�"` - Remark string `json:"remark" gorm:"column:remark;type:text;comment:澶囨敞"` - File string `json:"file" gorm:"column:file;type:varchar(255);comment:闄勪欢"` - - gorm.Model `json:"-"` + Id int `json:"id" gorm:"column:id;primary_key;AUTO_INCREMENT"` + ClientId int `json:"clientId" gorm:"column:client_id;type:int;comment:瀹㈡埛id"` + Client Client `json:"client" gorm:"foreignKey:ClientId"` + Number string `json:"number" gorm:"column:number;type:varchar(255);comment:鍚堝悓缂栧彿"` + ContactId int `json:"contactId" gorm:"column:contact_id;type:int;comment:鑱旂郴浜篿d"` + Contact Contact `json:"contact" gorm:"foreignKey:ContactId"` + ServiceOrderId int `json:"serviceOrderId" gorm:"column:service_order_id;type:int;comment:瀹㈡埛鏈嶅姟鍗昳d"` + ServiceOrder ServiceOrder `gorm:"foreignKey:ServiceOrderId"` + MemberId int `json:"memberId" gorm:"column:member_id;type:int;comment:鏈嶅姟浜哄憳id"` + Member User `json:"Member" gorm:"foreignKey:MemberId"` + PlanId int `json:"planId" gorm:"column:plan_id;type:int;comment:鏈嶅姟璁″垝id"` + SatisfactionId int `json:"satisfactionId" gorm:"column:satisfaction_id;type:int;comment:婊℃剰搴d"` + Satisfaction Satisfaction `json:"satisfaction" gorm:"foreignKey:SatisfactionId"` + TimelyRateId int `json:"timelyRateId" gorm:"column:timely_rate_id;type:int;comment:鍙婃椂鐜噄d"` + TimelyRate TimelyRate `json:"timelyRate" gorm:"foreignKey:TimelyRateId"` + SolveRateId int `json:"solveRateId" gorm:"column:solve_rate_id;type:int;comment:瑙e喅鐜噄d"` + SolveRate SolveRate `json:"solveRate" gorm:"foreignKey:SolveRateId"` + IsVisitId int `json:"isVisitId" gorm:"column:is_visit_id;type:int;comment:鏈嶅姟浜哄憳鏄惁鏉ヨ繃id"` + IsVisit IsVisit `json:"isVisit" gorm:"foreignKey:IsVisitId"` + OldMemberId int `json:"oldMemberId" gorm:"column:old_member_id;type:int;comment:鍘熸湇鍔′汉鍛�"` + OldMember User `json:"oldMember" gorm:"foreignKey:OldMemberId"` + Remark string `json:"remark" gorm:"column:remark;type:text;comment:澶囨敞"` + File string `json:"file" gorm:"column:file;type:varchar(255);comment:闄勪欢"` + CodeStandID string `json:"codeStandID" gorm:"column:code_stand_id;type:varchar(255);comment:缂栫爜id"` + CrmModel } ServiceFollowupSearch struct { ServiceFollowup - Orm *gorm.DB + Orm *gorm.DB + KeywordType constvar.ServiceFollowupKeywordType + Keyword string + OrderBy string + PageNum int + PageSize int + Preload bool + MemberIds []int } ) -func (ServiceFollowup) TableName() string { +func (*ServiceFollowup) TableName() string { return "service_followup" } @@ -46,6 +64,45 @@ var db = slf.Orm.Model(&ServiceFollowup{}) if slf.Id != 0 { db = db.Where("id = ?", slf.Id) + } + + switch slf.KeywordType { + case constvar.ServiceFollowupKeywordFollowupNo: + db = db.Where("number like ?", fmt.Sprintf("%%%s%%", slf.Keyword)) + case constvar.ServiceFollowupKeywordCustomerName: + db = db.Joins("Client", clause.LeftJoin).Where("Client.name like ?", fmt.Sprintf("%%%s%%", slf.Keyword)) + case constvar.ServiceFollowupKeywordContactName: + db = db.Joins("Contact").Where("Contact.name like ?", fmt.Sprintf("%%%s%%", slf.Keyword)) + case constvar.ServiceFollowupKeywordCustomerServiceNo: + db = db.Joins("ServiceOrder").Where("ServiceOrder.service_number like ?", fmt.Sprintf("%%%s%%", slf.Keyword)) + case constvar.ServiceFollowupKeywordVisitor: + db = db.Joins("left join user on user.id = service_followup.member_id").Where("user.username like ?", fmt.Sprintf("%%%s%%", slf.Keyword)) + case constvar.ServiceFollowupKeywordSatisfactionDegree: + db = db.Joins("Satisfaction").Where("Satisfaction.name like ?", fmt.Sprintf("%%%s%%", slf.Keyword)) + + } + + if slf.ServiceOrderId > 0 { + db = db.Where("service_order_id = ?", slf.ServiceOrderId) + } + + if slf.Preload { + db = db.Preload("Client"). + Preload("Contact"). + Preload("ServiceOrder"). + Preload("Member"). + Preload("Satisfaction"). + Preload("TimelyRate"). + Preload("SolveRate"). + Preload("IsVisit"). + Preload("OldMember") + } + + if len(slf.MemberIds) > 0 { + db = db.Where("service_followup.member_id in ?", slf.MemberIds) + } + if slf.Number != "" { + db = db.Where("number = ?", slf.Number) } return db @@ -73,11 +130,48 @@ return record, err } -func (slf *ServiceFollowupSearch) FindAll() ([]*ServiceFollowup, error) { +func (slf *ServiceFollowupSearch) FindAll() ([]*ServiceFollowup, int64, error) { var db = slf.build() var records = make([]*ServiceFollowup, 0) - err := db.Preload("CustomerServiceSheet").Find(&records).Error - return records, err + 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.Order("id desc").Find(&records).Error + return records, total, err +} + +func (slf *ServiceFollowupSearch) Count() (int64, error) { + var db = slf.build() + var total int64 + err := db.Count(&total).Error + return total, err +} + +func (slf *ServiceFollowupSearch) MaxAutoIncr() (int, error) { + type Result struct { + Max int + } + + var ( + result Result + db = slf.build() + ) + + err := db.Select("MAX(id) as max").Scan(&result).Error + if err != nil { + return result.Max, fmt.Errorf("max err: %v", err) + } + return result.Max, nil +} + +func (slf *ServiceFollowupSearch) SetNumber(number string) *ServiceFollowupSearch { + slf.Number = number + return slf } func (slf *ServiceFollowupSearch) SetId(id int) *ServiceFollowupSearch { @@ -85,10 +179,46 @@ return slf } -// 鍙婃椂鐜� 瑙e喅鐜� 婊℃剰搴� 鏈嶅姟浜哄憳鏄惁鏉ヨ繃 锛堟湇鍔″洖璁垮崟锛� -// 宸ュ崟绫诲瀷 鎶ヤ慨鏉ユ簮锛堝伐鍗曠鐞嗭級 -// 鍚堝悓绫诲瀷 鍚堝悓鐘舵�侊紙鏈嶅姟鍚堝悓锛� -// 浠樻鏂瑰紡 鏄惁寮�绁� 璐︽埛锛堥攢鍞��娆惧崟锛� -// 閫�鍏ヤ粨搴� 鐘舵�侊紙閿�鍞��璐у崟锛� -// 鎶ヤ环鍗曠姸鎬� 锛堟姤浠峰崟锛� -// 鍙兘鎬� 甯佺 褰撳墠鐘舵�侊紙閿�鍞満浼氾級 +func (slf *ServiceFollowupSearch) SetServiceOrderId(id int) *ServiceFollowupSearch { + slf.ServiceOrderId = id + return slf +} + +func (slf *ServiceFollowupSearch) SetPreload(preload bool) *ServiceFollowupSearch { + slf.Preload = preload + return slf +} + +func (slf *ServiceFollowupSearch) SetKeywordType(keyword constvar.ServiceFollowupKeywordType) *ServiceFollowupSearch { + slf.KeywordType = keyword + return slf +} + +func (slf *ServiceFollowupSearch) SetKeyword(keyword string) *ServiceFollowupSearch { + slf.Keyword = keyword + return slf +} + +func (slf *ServiceFollowupSearch) SetPage(page, size int) *ServiceFollowupSearch { + slf.PageNum, slf.PageSize = page, size + return slf +} + +func (slf *ServiceFollowupSearch) SetOrder(order string) *ServiceFollowupSearch { + slf.OrderBy = order + return slf +} +func (slf *ServiceFollowupSearch) SetIds(ids []int) *ServiceFollowupSearch { + slf.Orm = slf.Orm.Where("id in (?)", ids) + return slf +} + +func (slf *ServiceFollowupSearch) SetMemberIds(memberIds []int) *ServiceFollowupSearch { + slf.MemberIds = memberIds + return slf +} + +func (slf *ServiceFollowupSearch) UpdateByMap(data map[string]interface{}) error { + var db = slf.build() + return db.Updates(data).Error +} -- Gitblit v1.8.0