优化待确认作品查询逻辑,拆分状态条件子查询

This commit is contained in:
lzh 2025-06-27 17:42:10 +08:00
parent 4ec5bb8915
commit a556777369

View File

@ -272,18 +272,22 @@ func GetVedioWorkDetail(req *bundle.GetVedioWorkDetailReq) (data model.CastWorkV
}
func ToBeComfirmedWorks(req *bundle.ToBeComfirmedWorksReq) (data []model.CastWorkLog, total int64, unconfirmed int64, err error) {
subQuery := app.ModuleClients.BundleDB.
unConfirmSubQuery := app.ModuleClients.BundleDB.
Table("cast_work_log").
Select("work_uuid, MAX(update_time) AS max_update_time").
Group("work_uuid").Where("work_status in ?", []int{4, 5, 6, 7})
Group("work_uuid").Where("work_status = ?", 4)
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).
Joins("INNER JOIN (?) AS t ON cwl.work_uuid = t.work_uuid AND cwl.update_time = t.max_update_time", unConfirmSubQuery).
Where("artist_uuid = ?", req.ArtistUuid).Where("confirmed_at = ?", 0).Count(&unconfirmed).Error
if err != nil {
return
}
subQuery := app.ModuleClients.BundleDB.
Table("cast_work_log").
Select("work_uuid, MAX(update_time) AS max_update_time").
Group("work_uuid").Where("work_status in ?", []int{4, 5, 6, 7})
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).