@ -8,6 +8,7 @@ import (
uuid "github.com/satori/go.uuid"
uuid "github.com/satori/go.uuid"
"go.uber.org/zap"
"go.uber.org/zap"
"gorm.io/gorm"
"gorm.io/gorm"
"strconv"
"strings"
"strings"
"time"
"time"
)
)
@ -18,7 +19,15 @@ func SaveArtShow(tx *gorm.DB, artShow *model.ArtShow) (err error) {
return nil
return nil
}
}
artShow . ShowUID = uid . String ( )
artShow . ShowUID = uid . String ( )
artShow . ShowSeq = strings . Join ( [ ] string { m . ARTSHOW_PREFIX , time . Now ( ) . Format ( "20060102150405" ) } , "" )
artShow . ShowSeq = strings . Replace ( artShow . ShowSeq , "T" , m . ARTSHOW_PREFIX , - 1 )
num := countArtistNumInShowCurrentYear ( artShow . ArtistUID )
if num < 10 {
artShow . ShowSeq = strings . Join ( [ ] string { artShow . ShowSeq , time . Now ( ) . Format ( "06" ) , "00" + strconv . FormatInt ( num , 10 ) } , "" )
} else if num >= 10 && num < 100 {
artShow . ShowSeq = strings . Join ( [ ] string { artShow . ShowSeq , time . Now ( ) . Format ( "06" ) , "0" + strconv . FormatInt ( num , 10 ) } , "" )
} else if num >= 100 {
artShow . ShowSeq = strings . Join ( [ ] string { artShow . ShowSeq , time . Now ( ) . Format ( "06" ) , strconv . FormatInt ( num , 10 ) } , "" )
}
err = tx . Model ( & model . ArtShow { } ) . Create ( & artShow ) . Error
err = tx . Model ( & model . ArtShow { } ) . Create ( & artShow ) . Error
if err != nil {
if err != nil {
zap . L ( ) . Error ( "ArtShow err" , zap . Error ( err ) )
zap . L ( ) . Error ( "ArtShow err" , zap . Error ( err ) )
@ -58,13 +67,9 @@ func ArtShowListWithRel(in *artShow.ShowListReq) (err error, total int64, out []
queryDB . Where ( " a.show_seq like ? " , "%" + in . ShowSeq + "%" )
queryDB . Where ( " a.show_seq like ? " , "%" + in . ShowSeq + "%" )
countDB . Where ( " a.show_seq like ? " , "%" + in . ShowSeq + "%" )
countDB . Where ( " a.show_seq like ? " , "%" + in . ShowSeq + "%" )
}
}
if in . IsShow != 0 {
if in . StartShowTime != "" && in . EndShowTime != "" {
queryDB . Where ( " a.is_show = ?" , in . IsShow )
queryDB . Where ( "c.show_time between ? and ?" , in . StartShowTime , in . EndShowTime )
countDB . Where ( " a.is_show = ?" , in . IsShow )
countDB . Where ( "c.show_time between ? and ?" , in . StartShowTime , in . EndShowTime )
}
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 {
if in . EndPrice != 0 {
queryDB . Where ( " a.price between ? and ?" , in . StartPrice , in . EndPrice )
queryDB . Where ( " a.price between ? and ?" , in . StartPrice , in . EndPrice )
@ -74,7 +79,14 @@ func ArtShowListWithRel(in *artShow.ShowListReq) (err error, total int64, out []
queryDB . Where ( " a.reward between ? and ?" , in . StartReward , in . EndReward )
queryDB . Where ( " a.reward between ? and ?" , in . StartReward , in . EndReward )
countDB . Where ( " a.reward between ? and ?" , in . StartReward , in . EndReward )
countDB . Where ( " a.reward between ? and ?" , in . StartReward , in . EndReward )
}
}
if in . Address != "" {
queryDB . Where ( " c.address like ?" , "%" + in . Address + "%" )
countDB . Where ( " c.address like ?" , "%" + in . Address + "%" )
}
if len ( in . IsShow ) > 0 {
queryDB . Where ( " a.is_show in ?" , in . IsShow )
countDB . Where ( " a.is_show in ?" , in . IsShow )
}
//selectDb := queryDB
//selectDb := queryDB
//countDb := queryDB
//countDb := queryDB
@ -99,12 +111,12 @@ func ArtShowList(in *artShow.ShowListReq) (err error, total int64, out []*model.
queryDB := db . DbArtShow . Model ( & model . ArtShow { } ) .
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" )
Select ( "show_uid, show_seq, show_name, artist_name, artist_uid, artwork_num, ruler, price, create_time, operator, is_show" )
if in . IsShow != 0 {
if len ( in . IsShow ) > 0 {
queryDB . Where ( " is_show = ?" , in . IsShow )
queryDB . Where ( " is_show in ?" , in . IsShow )
}
if in . StartTime != "" && in . EndTime != "" {
queryDB . Where ( "convert(a.create_time, date) between ? and ?" , in . StartTime , in . EndTime )
}
}
//if in.StartTime != "" && in.EndTime != "" {
// queryDB.Where("convert(a.create_time, date) between ? and ?", in.StartTime, in.EndTime)
//}
out = make ( [ ] * model . ArtShowRes , 0 )
out = make ( [ ] * model . ArtShowRes , 0 )
err = queryDB . Offset ( int ( ( in . Page - 1 ) * in . PageSize ) ) .
err = queryDB . Offset ( int ( ( in . Page - 1 ) * in . PageSize ) ) .
@ -134,7 +146,7 @@ func ArtShowList_apply(applyUID string) (err error, out []*model.ArtShowRes) {
func ArtShowListByApplyStatus ( in * artShow . ShowListReq ) ( err error , total int64 , out [ ] * model . ArtShowRes ) {
func ArtShowListByApplyStatus ( in * artShow . ShowListReq ) ( err error , total int64 , out [ ] * model . ArtShowRes ) {
out = make ( [ ] * model . ArtShowRes , 0 )
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 )
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 [len ( in . IsShow ) - 1 ] )
err = queryDB . Count ( & total ) . Error
err = queryDB . Count ( & total ) . Error
if err != nil {
if err != nil {
zap . L ( ) . Error ( "ArtShowListByApplyStatus Count err" , zap . Error ( err ) )
zap . L ( ) . Error ( "ArtShowListByApplyStatus Count err" , zap . Error ( err ) )
@ -150,8 +162,8 @@ func ArtShowListByApplyStatus(in *artShow.ShowListReq) (err error, total int64,
return
return
}
}
func DelArtShow ( tx * gorm . DB , show _u id string ) ( err error ) {
func DelArtShow ( tx * gorm . DB , show U id string ) ( err error ) {
err = tx . Where ( "show_uid = ?" , show _u id) . Delete ( & model . ArtShow { } ) . Error
err = tx . Where ( "show_uid = ?" , show U id) . Delete ( & model . ArtShow { } ) . Error
if err != nil {
if err != nil {
zap . L ( ) . Error ( "ArtShow delete err" , zap . Error ( err ) )
zap . L ( ) . Error ( "ArtShow delete err" , zap . Error ( err ) )
return
return
@ -159,9 +171,19 @@ func DelArtShow(tx *gorm.DB, show_uid string) (err error) {
return nil
return nil
}
}
func QueryArtShow ( show_uid [ ] string ) ( err error , out [ ] * model . ArtShowRes ) {
func UniqueShowName ( showName string ) ( out * model . ArtShowRes , err error ) {
out = new ( model . ArtShowRes )
err = db . DbArtShow . Table ( "art_show as a " ) . Select ( "a.show_uid" ) . Joins ( "left join show_rel as b on a.show_uid = b.show_uid" ) . Where ( "a.show_name = ?" , showName ) . Find ( & out ) . Error
if err != nil {
zap . L ( ) . Error ( "ArtShow Find err" , zap . Error ( err ) )
return
}
return
}
func QueryArtShow ( showUids [ ] string ) ( err error , out [ ] * model . ArtShowRes ) {
out = make ( [ ] * model . ArtShowRes , 0 )
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
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 Uids ) . Find ( & out ) . Error
if err != nil {
if err != nil {
zap . L ( ) . Error ( "ArtShow Find err" , zap . Error ( err ) )
zap . L ( ) . Error ( "ArtShow Find err" , zap . Error ( err ) )
return
return
@ -226,3 +248,12 @@ func QueryArtShowForArtwork(in *artShow.ShowListForArtworkReq) (err error, total
}
}
return
return
}
}
func countArtistNumInShowCurrentYear ( artistUid string ) ( num int64 ) {
err := db . DbArtShow . Table ( "art_show" ) . Where ( "artist_uid = ? and date_format(created_at,\"%Y\") = ? " , artistUid , time . Now ( ) . Format ( "2006" ) ) . Count ( & num ) . Error
if err != nil {
return - 1
}
num = num + 1
return
}