You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

118 lines
3.2 KiB
Go

package dao
import (
"fonchain-artshow/cmd/model"
"fonchain-artshow/pb/artShow"
"fonchain-artshow/pkg/db"
"go.uber.org/zap"
"gorm.io/gorm"
)
func SaveArtShow(tx *gorm.DB, artShow *model.ArtShow) (err error) {
if artShow.ID != uint(0) {
err = tx.Model(&model.ArtShow{}).Omit("id").Where("id = ?", artShow.ID).Updates(&artShow).Error
} else {
err = tx.Model(&model.ArtShow{}).Create(artShow).Error
}
if err != nil {
zap.L().Error("ArtShow err", zap.Error(err))
return
}
return
}
func ArtShowList(in *artShow.ShowListReq) (err error, total int64, out []*model.ArtShow) {
queryDB := db.DbArtShow.Model(&model.ArtShow{})
if in.ArtistID != "" {
queryDB = queryDB.Where("artist_id = ? ", in.ArtistID)
}
if in.StartTime != "" && in.EndTime != "" {
queryDB = queryDB.Where("convert(show_time, date) between ? and ?", in.StartTime, in.EndTime)
}
if in.IsShow != 0 {
queryDB = queryDB.Where("is_show = ?", in.IsShow)
}
err = queryDB.Count(&total).Error
if err != nil {
zap.L().Error("ArtShowList Count err", zap.Error(err))
return
}
out = make([]*model.ArtShow, 0)
err = queryDB.Offset(int((in.Page - 1) * in.PageSize)).
Limit(int(in.PageSize)).Find(&out).Error
if err != nil {
zap.L().Error("ArtShowList Find err", zap.Error(err))
return
}
return
}
func ArtShowList_apply(applyID uint) (err error, out []*model.ArtShow) {
out = make([]*model.ArtShow, 0)
err = db.DbArtShow.Table("art_show as a ").Select("a.*").Distinct("a.id").Joins(" right join show_rel as b on a.id = b.show_id").Where("b.apply_id = ? ", applyID).Find(&out).Error
if err != nil {
zap.L().Error("ArtShowList_apply Find err", zap.Error(err))
return
}
return
}
func ArtShowListByApplyStatus(in *artShow.ShowListReq) (err error, total int64, out []*model.ArtShow) {
out = make([]*model.ArtShow, 0)
tx := db.DbArtShow.Table("art_show as a")
tx.Joins(" left join show_rel as b on b.show_id = a.id").Where("a.is_show = ?", in.IsShow)
err = tx.Count(&total).Error
if err != nil {
zap.L().Error("ArtShowListByApplyStatus Count err", zap.Error(err))
return
}
err = tx.Offset(int((in.Page - 1) * in.PageSize)).
Limit(int(in.PageSize)).Find(&out).Error
if err != nil {
zap.L().Error("ArtShowListByApplyStatus Find err", zap.Error(err))
return
}
return
}
func DelArtShow(in *artShow.DelShowReq) (err error) {
err = db.DbArtShow.Where("id = ?", in.ShowID).Delete(&model.ArtShow{}).Error
if err != nil {
zap.L().Error("ArtShow delete err", zap.Error(err))
return
}
return
}
func QueryArtShow(id uint) (err error, out *model.ArtShow) {
err = db.DbArtShow.Model(&model.ArtShow{}).Where("id = ?", id).Find(&out).Error
if err != nil {
zap.L().Error("ArtShow Find err", zap.Error(err))
return
}
return
}
func ShowStatistical(isShow int32) (err error, artistNum int64, packageNum int64) {
err = db.DbArtShow.Model(&model.ArtShow{}).Distinct("artist_name").Where("is_show = ?", isShow).Count(&artistNum).Error
if err != nil {
zap.L().Error("ShowStatistical artistNum count err", zap.Error(err))
return
}
err = db.DbArtShow.Model(&model.ArtShow{}).Where("is_show = ?", isShow).Count(&packageNum).Error
if err != nil {
zap.L().Error("ShowStatistical packageNum count err", zap.Error(err))
return
}
return
}