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.

229 lines
8.5 KiB
Go

package dao
import (
"fonchain-artshow/cmd/model"
"fonchain-artshow/pb/artShow"
"fonchain-artshow/pkg/db"
"fonchain-artshow/pkg/m"
uuid "github.com/satori/go.uuid"
"go.uber.org/zap"
"gorm.io/gorm"
"strings"
"time"
)
func SaveArtShow(tx *gorm.DB, artShow *model.ArtShow) (err error) {
uid, err := uuid.NewV4()
if err != nil {
return nil
}
artShow.ShowUID = uid.String()
artShow.ShowSeq = strings.Join([]string{m.ARTSHOW_PREFIX, time.Now().Format("20060102150405")}, "")
err = tx.Model(&model.ArtShow{}).Create(&artShow).Error
if err != nil {
zap.L().Error("ArtShow err", zap.Error(err))
return
}
return
}
func UpdateArtShow(tx *gorm.DB, artShow *model.ArtShow) (err error) {
err = tx.Model(&model.ArtShow{}).Omit("show_uid,operator").Where("show_uid = ?", artShow.ShowUID).Updates(artShow).Error
if err != nil {
zap.L().Error("ArtShow err", zap.Error(err))
return
}
return
}
func ArtShowListWithRel(in *artShow.ShowListReq) (err error, total int64, out []*model.ArtShowRes) {
queryDB := db.DbArtShow.Table("art_show as a ").Omit("a.created_at").Distinct("a.id").
Select("a.show_uid, a.show_seq, a.show_name, a.artist_name, a.artist_uid, a.artwork_num, a.ruler, a.price, a.reward ,a.create_time, a.operator, a.is_show, c.address ,c.show_time, a.created_at").
Joins("left join artwork_price as b on a.show_uid = b.show_uid").
Joins("left join show_rel as c on a.show_uid = c.show_uid ")
countDB := db.DbArtShow.Table("art_show as a ").Distinct("a.id").
Select("a.show_uid, a.show_seq, a.show_name, a.artist_name, a.artist_uid, a.artwork_num, a.ruler, a.price, a.reward , a.create_time, a.operator, a.is_show, c.address ,c.show_time").
Joins("left join artwork_price as b on a.show_uid = b.show_uid").
Joins("left join show_rel as c on a.show_uid = c.show_uid ")
if in.ArtistName != "" {
queryDB.Where(" a.artist_name like ? ", "%"+in.ArtistName+"%")
countDB.Where(" a.artist_name like ? ", "%"+in.ArtistName+"%")
}
if in.ShowName != "" {
queryDB.Where(" a.show_name like ? ", "%"+in.ShowName+"%")
countDB.Where(" a.show_name like ? ", "%"+in.ShowName+"%")
}
if in.ShowSeq != "" {
queryDB.Where(" a.show_seq like ? ", "%"+in.ShowSeq+"%")
countDB.Where(" a.show_seq like ? ", "%"+in.ShowSeq+"%")
}
if in.IsShow != 0 {
queryDB.Where(" a.is_show = ?", in.IsShow)
countDB.Where(" a.is_show = ?", in.IsShow)
}
if in.StartTime != "" && in.EndTime != "" {
queryDB.Where("convert(a.create_time, date) between ? and ?", in.StartTime, in.EndTime)
countDB.Where("convert(a.create_time, date) between ? and ?", in.StartTime, in.EndTime)
}
if in.EndPrice != 0 {
queryDB.Where(" a.price between ? and ?", in.StartPrice, in.EndPrice)
countDB.Where(" a.price between ? and ?", in.StartPrice, in.EndPrice)
}
if in.EndReward != 0 {
queryDB.Where(" a.reward between ? and ?", in.StartReward, in.EndReward)
countDB.Where(" a.reward between ? and ?", in.StartReward, in.EndReward)
}
//selectDb := queryDB
//countDb := queryDB
out = make([]*model.ArtShowRes, 0)
err = queryDB.Where("a.deleted_at is null and c.deleted_at is null").Offset(int((in.Page - 1) * in.PageSize)).
Limit(int(in.PageSize)).Order("a.created_at desc ").Find(&out).Error
if err != nil {
zap.L().Error("ArtShowList Find err", zap.Error(err))
return
}
err = countDB.Where("a.deleted_at is null").Group("a.id").Count(&total).Error
if err != nil {
zap.L().Error("ArtShowList Count err", zap.Error(err))
return
}
return
}
func ArtShowList(in *artShow.ShowListReq) (err error, total int64, out []*model.ArtShowRes) {
queryDB := db.DbArtShow.Model(&model.ArtShow{}).
Select("show_uid, show_seq, show_name, artist_name, artist_uid, artwork_num, ruler, price, create_time, operator, is_show")
if in.IsShow != 0 {
queryDB.Where(" is_show = ?", in.IsShow)
}
if in.StartTime != "" && in.EndTime != "" {
queryDB.Where("convert(a.create_time, date) between ? and ?", in.StartTime, in.EndTime)
}
out = make([]*model.ArtShowRes, 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
}
err = queryDB.Count(&total).Error
if err != nil {
zap.L().Error("ArtShowList Count err", zap.Error(err))
return
}
return
}
func ArtShowList_apply(applyUID string) (err error, out []*model.ArtShowRes) {
out = make([]*model.ArtShowRes, 0)
err = db.DbArtShow.Table("art_show as a ").Distinct("a.show_uid").Select("a.show_uid, a.show_seq, a.show_name, a.artist_name, a.artist_uid, a.artwork_num, a.ruler, a.price, a.reward, a.create_time, a.is_show, b.address ,b.show_time").Joins(" right join show_rel as b on a.show_uid = b.show_uid").Where("b.apply_uid = ? ", applyUID).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.ArtShowRes) {
out = make([]*model.ArtShowRes, 0)
queryDB := db.DbArtShow.Table("art_show as a").Select("a.show_uid, a.show_seq, a.show_name, a.artist_name, a.artist_uid, a.artwork_num, a.ruler, a.price, a.create_time, a.is_show, b.address ,b.show_time").Joins(" left join show_rel as b on b.show_uid = a.show_uid").Where("a.is_show = ?", in.IsShow)
err = queryDB.Count(&total).Error
if err != nil {
zap.L().Error("ArtShowListByApplyStatus Count err", zap.Error(err))
return
}
err = queryDB.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(tx *gorm.DB, show_uid string) (err error) {
err = tx.Where("show_uid = ?", show_uid).Delete(&model.ArtShow{}).Error
if err != nil {
zap.L().Error("ArtShow delete err", zap.Error(err))
return
}
return nil
}
func QueryArtShow(show_uid []string) (err error, out []*model.ArtShowRes) {
out = make([]*model.ArtShowRes, 0)
err = db.DbArtShow.Table("art_show as a ").Select("a.show_uid, a.show_seq, a.show_name, a.artist_name, a.artist_uid, a.artwork_num, a.ruler, a.price, a.create_time, a.operator a.is_show, b.address ,b.show_time").Joins("left join show_rel as b on a.show_uid = b.show_uid").Where("a.show_uid in ?", show_uid).Find(&out).Error
if err != nil {
zap.L().Error("ArtShow Find err", zap.Error(err))
return
}
return
}
func ShowStatistical(isShow int32) (err error, artistNum, packageNum, totalNum, NotShowNum, ShowHisNum int64) {
artistNum = 0
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
}
packageNum = 0
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
}
totalNum = 0
err = db.DbArtShow.Model(&model.ArtShow{}).Count(&totalNum).Error
if err != nil {
zap.L().Error("ShowStatistical totalNum count err", zap.Error(err))
return
}
NotShowNum = 0
err = db.DbArtShow.Table("art_show as a").Distinct("a.artist_uid").Joins(" join artwork_price as b on b.show_uid = a.show_uid").Where("a.is_show in (1,2) and a.deleted_at is null").Count(&NotShowNum).Error
if err != nil {
zap.L().Error("ShowStatistical totalNum count err", zap.Error(err))
return
}
ShowHisNum = 0
err = db.DbArtShow.Table("art_show as a").Distinct("a.artist_uid").Joins(" join artwork_price as b on b.show_uid = a.show_uid").Where("a.is_show = 3 and a.deleted_at is null").Count(&ShowHisNum).Error
if err != nil {
zap.L().Error("ShowStatistical totalNum count err", zap.Error(err))
return
}
return
}
func QueryArtShowForArtwork(in *artShow.ShowListForArtworkReq) (err error, total int64, out []*model.ArtShowRes) {
// 查询 画家已出展 画展包
queryDB := db.DbArtShow.Table("art_show as a ").Select("a.show_uid, a.show_seq, a.show_name, a.artist_name, a.artist_uid, a.artwork_num, a.ruler, a.price, a.create_time, a.is_show, b.address ,b.show_time").Joins("left join show_rel as b on a.show_uid = b.show_uid").Where("a.artist_uid = ? and a.is_show = ?", in.ArtistUID, 3)
err = queryDB.Count(&total).Error
if err != nil {
zap.L().Error("QueryArtShowForArtwork count err", zap.Error(err))
return
}
out = make([]*model.ArtShowRes, 0)
err = queryDB.Offset(int((in.Page - 1) * in.PageSize)).
Limit(int(in.PageSize)).Find(&out).Error
if err != nil {
zap.L().Error("QueryArtShowForArtwork err", zap.Error(err))
return
}
return
}