107 lines
3.0 KiB
Go
107 lines
3.0 KiB
Go
// Package dao -----------------------------
|
|
// @file : artistinfo_artshow.go
|
|
// @author : JJXu
|
|
// @contact : wavingbear@163.com
|
|
// @time : 2023/3/2 12:06
|
|
// -------------------------------------------
|
|
package dao
|
|
|
|
import (
|
|
"errors"
|
|
"github.com/fonchain/fonchain-artistinfo/cmd/model"
|
|
"github.com/fonchain/fonchain-artistinfo/pb/artistinfoArtshow"
|
|
db "github.com/fonchain/fonchain-artistinfo/pkg/db"
|
|
"gorm.io/gorm"
|
|
"gorm.io/gorm/clause"
|
|
)
|
|
|
|
var ArtistinfoArtshowVideo = new(artistinfoArtshowVideo)
|
|
|
|
type artistinfoArtshowVideo struct{}
|
|
|
|
func (a artistinfoArtshowVideo) BatchCreateData(datas []model.ArtshowRecord) error {
|
|
//return db.DB.Create(&datas).Error
|
|
tx := db.DB.Begin()
|
|
for _, v := range datas {
|
|
err := a.CreateData(&v, tx)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
}
|
|
tx.Commit()
|
|
return nil
|
|
}
|
|
func (a artistinfoArtshowVideo) CreateData(data *model.ArtshowRecord, tx ...*gorm.DB) error {
|
|
var txdb *gorm.DB
|
|
if tx != nil {
|
|
txdb = tx[0]
|
|
} else {
|
|
txdb = db.DB
|
|
}
|
|
var exist = model.ArtshowRecord{}
|
|
db.DB.Where("artist_uid = ? AND status = 2", data.ArtistUid).Find(&exist)
|
|
if exist.ID != 0 {
|
|
return errors.New("数据已存在")
|
|
}
|
|
return txdb.Create(&data).Error
|
|
}
|
|
|
|
func (a artistinfoArtshowVideo) UpdateData(data *model.ArtshowRecord) error {
|
|
return db.DB.Create(&data).Error
|
|
|
|
}
|
|
|
|
func (a artistinfoArtshowVideo) DeletedData(id ...int64) (err error) {
|
|
if len(id) == 1 {
|
|
err = db.DB.Where("id = ?", id[0]).Delete(&model.ArtshowRecord{}).Error
|
|
} else if len(id) > 0 {
|
|
err = db.DB.Where("id = ?", id).Delete(&model.ArtshowRecord{}).Error
|
|
}
|
|
return err
|
|
}
|
|
|
|
func (a artistinfoArtshowVideo) GetData(id int64) (data *model.ArtshowRecord, err error) {
|
|
err = db.DB.Where("id = ?", id).First(data).Error
|
|
return
|
|
}
|
|
|
|
func (a artistinfoArtshowVideo) GetDataList(req *artistinfoArtshow.GetArtshowVideoListRequst) (datas []model.ArtshowRecord, total int64, err error) {
|
|
datas = []model.ArtshowRecord{}
|
|
var tx = db.DB.Model(model.ArtshowRecord{})
|
|
if req.ArtistUid != "" {
|
|
tx = tx.Where("artist_uid = ?", req.ArtistUid)
|
|
}
|
|
if req.LockTime != "" {
|
|
tx = tx.Where("lock_time = ?", req.LockTime)
|
|
}
|
|
if req.ArtistName != "" {
|
|
tx = tx.Clauses(clause.Like{
|
|
Column: "artist_name",
|
|
Value: "%" + req.ArtistName + "%",
|
|
})
|
|
}
|
|
if req.Status != 0 {
|
|
tx = tx.Where("status = ?", req.Status)
|
|
}
|
|
//if req.VideoUrl != "" {
|
|
// tx = tx.Where("video_url = ?", req.VideoUrl)
|
|
//}
|
|
if req.AuditStatus != 0 {
|
|
tx = tx.Where("audit_status = ?", req.AuditStatus)
|
|
}
|
|
//if req.AuditMark1 != "" {
|
|
// tx = tx.Where("audit_mark1 = ?", req.AuditMark1)
|
|
//}
|
|
//if req.AuditMark2 != "" {
|
|
// tx = tx.Where("audit_mark2 = ?", req.AuditMark2)
|
|
//}
|
|
err = tx.Count(&total).Scopes(db.Pagination(req.Page, req.PageSize)).Find(&datas).Error
|
|
return
|
|
}
|
|
func (a artistinfoArtshowVideo) Audit(auditStatus model.AuditStatus, mark1, mark2 string, ids ...int64) error {
|
|
return db.DB.Model(model.ArtshowRecord{}).Where("id in ?", ids).
|
|
Update("audit_status", auditStatus).
|
|
Update("audit_mark1", mark1).
|
|
Update("audit_mark2", mark2).Error
|
|
}
|