diff --git a/internal/dao/bundleExtend.go b/internal/dao/bundleExtend.go index 1155f17..e34abc4 100644 --- a/internal/dao/bundleExtend.go +++ b/internal/dao/bundleExtend.go @@ -271,15 +271,22 @@ func GetVedioWorkDetail(req *bundle.GetVedioWorkDetailReq) (data model.CastWorkV } func ToBeComfirmedWorks(req *bundle.ToBeComfirmedWorksReq) (data []model.CastWorkLog, total int64, unconfirmed int64, err error) { - err = app.ModuleClients.BundleDB.Model(&model.CastWorkLog{}).Where(&model.CastWorkLog{ - ArtistUuid: req.ArtistUuid, - }).Where("confirmed_at = ?", 0).Count(&unconfirmed).Error + subQuery := app.ModuleClients.BundleDB. + Table("cast_work_log"). + Select("work_uuid, MAX(update_time) AS max_update_time"). + Group("work_uuid") + + err = app.ModuleClients.BundleDB. + Table("cast_work_log AS cwl"). + Joins("INNER JOIN (?) AS t ON cwl.work_uuid = t.work_uuid AND cwl.update_time = t.max_update_time", subQuery). + Where("artist_uuid = ?", req.ArtistUuid).Where("confirmed_at = ?", 0).Count(&unconfirmed).Error if err != nil { return } - session := app.ModuleClients.BundleDB.Model(&model.CastWorkLog{}).Where(&model.CastWorkLog{ - ArtistUuid: req.ArtistUuid, - }) + session := app.ModuleClients.BundleDB. + Table("cast_work_log AS cwl"). + Joins("INNER JOIN (?) AS t ON cwl.work_uuid = t.work_uuid AND cwl.update_time = t.max_update_time", subQuery). + Where("artist_uuid = ?", req.ArtistUuid) err = session.Count(&total).Error if err != nil { return