From fca319958029fa924308e50cb61202d7d6ff5008 Mon Sep 17 00:00:00 2001 From: zhaoqingang <zhaoqg0118@163.com> Date: 星期三, 19 二月 2025 13:33:37 +0800 Subject: [PATCH] 暂停聚集模型 --- db/task_results.go | 79 +++++++++++++++++++++++++++++++++++---- 1 files changed, 70 insertions(+), 9 deletions(-) diff --git a/db/task_results.go b/db/task_results.go index 3e656bd..b3d912f 100644 --- a/db/task_results.go +++ b/db/task_results.go @@ -2,19 +2,27 @@ import ( "fmt" + "time" + "gorm.io/gorm" ) type ModelTaskResults struct { BaseModel - Title string `json:"name" gorm:"type:varchar(255)"` //棰勮鍚嶇О,鏆傛椂鐢ㄤ换鍔″悕绉� - Event string `json:"event" gorm:"type:varchar(255)"` //棰勮浜嬩欢 - ModelID string `json:"modelID" gorm:"type:varchar(255)"` //妯″瀷ID - ModelTaskID string `json:"modelTaskID" gorm:"type:varchar(255)"` //妯″瀷浠诲姟ID - CommunityId string `json:"communityID" gorm:"index;column:community_id;type:varchar(299);not null;"` //灏忓尯ID - OrgID string `json:"orgID" gorm:"index;column:org_id;type:varchar(299);not null;"` //娲惧嚭鎵� domain unit ID - ObjectIds string `json:"objectIds" gorm:"type:text"` //浜嬩欢瀵硅薄锛屽彲浠ユ槸浜猴紝澶氫釜鐢ㄩ�楀彿鍒嗛殧 - Location string `json:"location" gorm:"type:varchar(255)"` //鍙戠敓鍦扮偣 + Title string `json:"name" gorm:"type:varchar(255)"` // 棰勮鍚嶇О,鏆傛椂鐢ㄤ换鍔″悕绉� + Event string `json:"event" gorm:"type:varchar(255)"` // 棰勮浜嬩欢 + ModelID string `json:"modelID" gorm:"type:varchar(255)"` // 妯″瀷ID + ModelTaskID string `json:"modelTaskID" gorm:"type:varchar(255)"` // 妯″瀷浠诲姟ID + OrgID string `json:"orgID" gorm:"index;column:org_id;type:varchar(299);not null;"` // 娲惧嚭鎵� domain unit ID + CommunityId string `json:"communityID" gorm:"index;column:community_id;type:varchar(299);not null;"` // 灏忓尯ID + //PicDate string `json:"picDate" gorm:"uniqueIndex:pic_date_first_person_id;type:varchar(255);"` // 鎶撴媿鏃堕棿 + //FirstPersonID string `json:"-" gorm:"uniqueIndex:pic_date_first_person_id;type:varchar(255);"` // 绗竴涓汉鐨処D + PicDate string `json:"picDate" gorm:"type:varchar(255);"` // 鎶撴媿鏃堕棿 + FirstPersonID string `json:"-" gorm:"type:varchar(255);"` // 绗竴涓汉鐨処D + ObjectIds string `json:"objectIds" gorm:"type:text"` // 浜嬩欢瀵硅薄锛屽彲浠ユ槸浜猴紝澶氫釜鐢ㄩ�楀彿鍒嗛殧 + Location string `json:"location" gorm:"type:varchar(255)"` // 鍙戠敓鍦扮偣 + Building string `json:"building" gorm:"type:varchar(255);"` // 妤兼爧 + Floor string `json:"floor" gorm:"type:varchar(255);"` // 妤煎眰 } func (m *ModelTaskResults) TableName() string { @@ -28,6 +36,7 @@ PageSize int Order string Keyword string + location string } func NewModelTaskResultsSearch() *ModelTaskResultsSearch { @@ -63,6 +72,26 @@ return slf } +func (slf *ModelTaskResultsSearch) SetTaskId(id string) *ModelTaskResultsSearch { + slf.ModelTaskID = id + return slf +} + +func (slf *ModelTaskResultsSearch) SetFirstPersonId(firstId string) *ModelTaskResultsSearch { + slf.FirstPersonID = firstId + return slf +} + +func (slf *ModelTaskResultsSearch) SetPicDate(picDate string) *ModelTaskResultsSearch { + slf.PicDate = picDate + return slf +} + +func (slf *ModelTaskResultsSearch) SetFirstLocation(location string) *ModelTaskResultsSearch { + slf.location = location + return slf +} + func (slf *ModelTaskResultsSearch) build() *gorm.DB { var db = slf.Orm.Table(slf.TableName()) if slf.Order != "" { @@ -73,9 +102,28 @@ db = db.Where("id = ?", slf.ID) } + if slf.PicDate != "" { + db = db.Where("pic_date = ?", slf.PicDate) + } + + if slf.FirstPersonID != "" { + db = db.Where("first_person_id = ?", slf.FirstPersonID) + } + + if slf.ModelTaskID != "" { + db = db.Where("model_task_id = ?", slf.ModelTaskID) + } + if slf.Keyword != "" { kw := "%" + slf.Keyword + "%" db = db.Where("name like ?", kw) + } + if slf.Keyword != "" { + kw := "%" + slf.Keyword + "%" + db = db.Where("name like ?", kw) + } + if slf.location != "" { + db = db.Where("location = ?", slf.location) } return db @@ -159,9 +207,22 @@ return nil } +func (slf *ModelTaskResultsSearch) FirstOrCreate(record *ModelTaskResults) error { + var db = slf.build() + var exists ModelTaskResults + if err := db.First(&exists).Error; err == nil { + return nil + } + if err2 := slf.Orm.Table(slf.TableName()).Create(record).Error; err2 != nil { + return fmt.Errorf("FirstOrCreate err: %v, record: %+v", err2, record) + } + + return nil +} + func (slf *ModelTaskResultsSearch) Save(record *ModelTaskResults) error { var db = slf.build() - + record.UpdatedAt = time.Now() if err := db.Omit("CreatedAt").Save(record).Error; err != nil { return fmt.Errorf("save err: %v, record: %+v", err, record) } -- Gitblit v1.8.0