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.

177 lines
6.4 KiB
Go

2 years ago
package dao
import (
"fmt"
2 years ago
"fonchain-artshow/cmd/model"
2 years ago
"fonchain-artshow/pb/artShow"
2 years ago
"fonchain-artshow/pkg/db"
2 years ago
"fonchain-artshow/pkg/m"
uuid "github.com/satori/go.uuid"
2 years ago
"go.uber.org/zap"
"gorm.io/gorm"
2 years ago
"strings"
"time"
2 years ago
)
func SaveArtShow(tx *gorm.DB, artShow *model.ArtShow) (err error) {
2 years ago
uid, err := uuid.NewV4()
if err != nil {
return nil
2 years ago
}
2 years ago
artShow.ShowUID = uid.String()
artShow.ShowSeq = strings.Join([]string{m.ARTSHOW_PREFIX, time.Now().Format("20060102150405")}, "")
err = tx.Model(&model.ArtShow{}).Create(&artShow).Error
2 years ago
if err != nil {
zap.L().Error("ArtShow err", zap.Error(err))
return
}
return
}
2 years ago
func UpdateArtShow(tx *gorm.DB, artShow *model.ArtShow) (err error) {
err = tx.Model(&model.ArtShow{}).Omit("show_uid").Where("show_uid = ?", artShow.ShowUID).Updates(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.ArtShowRes) {
queryDB := 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.create_time, 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 ")
2 years ago
if in.Name != "" {
queryDB.Where(" a.artist_name like ? or a.show_name like ? or b.artwork_name like ? ", "%"+in.Name+"%", "%"+in.Name+"%", "%"+in.Name+"%")
2 years ago
}
2 years ago
if in.IsShow != 0 {
queryDB.Where(" a.is_show = ?", in.IsShow)
}
if in.StartTime != "" && in.EndTime != "" {
queryDB.Where("convert(a.create_time, date) between ? and ?", in.StartTime, in.EndTime)
2 years ago
}
2 years ago
out = make([]*model.ArtShowRes, 0)
err = queryDB.Where("a.deleted_at is null").Offset(int((in.Page - 1) * in.PageSize)).
Limit(int(in.PageSize)).Find(&out).Error
2 years ago
if err != nil {
zap.L().Error("ArtShowList Find err", zap.Error(err))
2 years ago
return
}
err = queryDB.Where("a.deleted_at is null").Group("a.id").Count(&total).Error
2 years ago
if err != nil {
zap.L().Error("ArtShowList Count err", zap.Error(err))
2 years ago
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
2 years ago
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
2 years ago
if err != nil {
zap.L().Error("ArtShowListByApplyStatus Count err", zap.Error(err))
return
}
err = queryDB.Offset(int((in.Page - 1) * in.PageSize)).
2 years ago
Limit(int(in.PageSize)).Find(&out).Error
if err != nil {
zap.L().Error("ArtShowListByApplyStatus Find err", zap.Error(err))
return
}
return
}
2 years ago
func DelArtShow(tx *gorm.DB, show_uid string) (err error) {
err = tx.Where("show_uid = ?", show_uid).Delete(&model.ArtShow{}).Error
2 years ago
if err != nil {
zap.L().Error("ArtShow delete err", zap.Error(err))
return
}
return
}
func QueryArtShow(show_uid string) (err error, out *model.ArtShowRes) {
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.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 = ?", show_uid).Find(&out).Error
2 years ago
if err != nil {
zap.L().Error("ArtShow Find err", zap.Error(err))
return
}
fmt.Printf("%+v\n", out)
2 years ago
return
}
2 years ago
func ShowStatistical(isShow int32) (err error, artistNum, packageNum, totalNum, NotShowNum, ShowHisNum int64) {
2 years ago
2 years ago
artistNum = 0
2 years ago
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
}
2 years ago
packageNum = 0
2 years ago
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
}
2 years ago
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
2 years ago
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
2 years ago
if err != nil {
zap.L().Error("ShowStatistical totalNum count err", zap.Error(err))
return
}
2 years ago
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
}