Create & Init Project...

This commit is contained in:
2019-04-22 18:49:16 +08:00
commit fc4fa37393
25440 changed files with 4054998 additions and 0 deletions

View File

@@ -0,0 +1,86 @@
package(default_visibility = ["//visibility:public"])
load(
"@io_bazel_rules_go//go:def.bzl",
"go_test",
"go_library",
)
go_test(
name = "go_default_test",
srcs = [
"addit_test.go",
"archive_biz_test.go",
"archive_test.go",
"arhive_history_test.go",
"config_test.go",
"dao_test.go",
"video_test.go",
],
embed = [":go_default_library"],
rundir = ".",
tags = ["automanaged"],
deps = [
"//app/job/main/videoup/conf:go_default_library",
"//app/job/main/videoup/model/archive:go_default_library",
"//library/database/sql:go_default_library",
"//vendor/github.com/bouk/monkey:go_default_library",
"//vendor/github.com/go-sql-driver/mysql:go_default_library",
"//vendor/github.com/smartystreets/goconvey/convey:go_default_library",
],
)
go_library(
name = "go_default_library",
srcs = [
"addit.go",
"archive.go",
"archive_biz.go",
"archive_history.go",
"config.go",
"cover.go",
"dao.go",
"databus.go",
"delay.go",
"first_pass.go",
"forbid.go",
"new_video.go",
"oper.go",
"staff.go",
"stat.go",
"type.go",
"video.go",
"video_audit.go",
"video_cover.go",
"video_oper.go",
"video_shot.go",
],
importpath = "go-common/app/job/main/videoup/dao/archive",
tags = ["automanaged"],
visibility = ["//visibility:public"],
deps = [
"//app/job/main/videoup/conf:go_default_library",
"//app/job/main/videoup/model/archive:go_default_library",
"//library/cache/redis:go_default_library",
"//library/database/sql:go_default_library",
"//library/ecode:go_default_library",
"//library/log:go_default_library",
"//library/net/http/blademaster:go_default_library",
"//library/xstr:go_default_library",
"//vendor/github.com/dgryski/go-farm:go_default_library",
],
)
filegroup(
name = "package-srcs",
srcs = glob(["**"]),
tags = ["automanaged"],
visibility = ["//visibility:private"],
)
filegroup(
name = "all-srcs",
srcs = [":package-srcs"],
tags = ["automanaged"],
visibility = ["//visibility:public"],
)

View File

@@ -0,0 +1,28 @@
package archive
import (
"context"
"go-common/app/job/main/videoup/model/archive"
"go-common/library/database/sql"
"go-common/library/log"
)
const (
_additSQL = "SELECT id,aid,source,redirect_url,mission_id,up_from,order_id,dynamic FROM archive_addit WHERE aid=?"
)
// Addit get archive addit.
func (d *Dao) Addit(c context.Context, aid int64) (addit *archive.Addit, err error) {
row := d.db.QueryRow(c, _additSQL, aid)
addit = &archive.Addit{}
if err = row.Scan(&addit.ID, &addit.Aid, &addit.Source, &addit.RedirectURL, &addit.MissionID, &addit.UpFrom, &addit.OrderID, &addit.Dynamic); err != nil {
if err == sql.ErrNoRows {
addit = nil
err = nil
} else {
log.Error("row.Scan error(%v)", err)
}
}
return
}

View File

@@ -0,0 +1,18 @@
package archive
import (
"context"
. "github.com/smartystreets/goconvey/convey"
"testing"
)
func Test_Addit(t *testing.T) {
var (
c = context.TODO()
err error
)
Convey("Test_Addit", t, WithDao(func(d *Dao) {
_, err = d.Addit(c, 23333)
So(err, ShouldBeNil)
}))
}

View File

@@ -0,0 +1,178 @@
package archive
import (
"context"
"database/sql"
"time"
"go-common/app/job/main/videoup/model/archive"
xsql "go-common/library/database/sql"
"go-common/library/log"
)
const (
_upStateSQL = "UPDATE archive SET state=? where id=?"
_upAccessSQL = "UPDATE archive SET access=? where id=?"
_upRoundSQL = "UPDATE archive SET round=? where id=?"
_upAttrSQL = "UPDATE archive SET attribute=attribute|? where id=?"
_upCoverSQL = "UPDATE archive SET cover=? where id=?"
_upDuraSQL = "UPDATE archive SET duration=? where id=?"
_upAttrBitSQL = "UPDATE archive SET attribute=attribute&(~(1<<?))|(?<<?) WHERE id=?"
_upPTimeSQL = "UPDATE archive SET pubtime=? WHERE id=?"
_upDelayRoundSQL = "UPDATE archive SET round = ? WHERE state>=? AND round=? AND mtime >= ? AND mtime <= ?"
// select
_arcSQL = "SELECT id,mid,typeid,copyright,author,title,cover,content,tag,duration,round,attribute,access,state,reject_reason,pubtime,ctime,mtime,forward FROM archive WHERE id=?"
_upperArcStates = "SELECT id,state FROM archive WHERE mid=?"
)
// Archive get a archive by avid.
func (d *Dao) Archive(c context.Context, aid int64) (a *archive.Archive, err error) {
var reason sql.NullString
row := d.db.QueryRow(c, _arcSQL, aid)
a = &archive.Archive{}
if err = row.Scan(&a.Aid, &a.Mid, &a.TypeID, &a.Copyright, &a.Author, &a.Title, &a.Cover, &a.Desc, &a.Tag, &a.Duration,
&a.Round, &a.Attribute, &a.Access, &a.State, &reason, &a.PTime, &a.CTime, &a.MTime, &a.Forward); err != nil {
if err == sql.ErrNoRows {
a = nil
err = nil
} else {
log.Error("row.Scan error(%v)", err)
}
return
}
a.Reason = reason.String
return
}
// UpperArcStateMap 获取UP主的稿件状态
func (d *Dao) UpperArcStateMap(c context.Context, mid int64) (sMap map[int64]int8, err error) {
sMap = make(map[int64]int8)
rows, err := d.rdb.Query(c, _upperArcStates, mid)
if err != nil {
log.Error("d.rdb.Query() error(%v)", err)
return
}
defer rows.Close()
for rows.Next() {
a := struct {
ID int64
State int8
}{}
if err = rows.Scan(&a.ID, &a.State); err != nil {
log.Error("rows.Scan error(%v)", err)
return
}
sMap[a.ID] = a.State
}
return
}
// UpDelayRound update round to the end by conf
func (d *Dao) UpDelayRound(c context.Context, minTime, maxTime time.Time) (rows int64, err error) {
res, err := d.db.Exec(c, _upDelayRoundSQL, archive.RoundEnd, archive.StateOpen, archive.RoundReviewFirstWaitTrigger, minTime, maxTime)
if err != nil {
log.Error("d.db.Exec error(%v)", err)
return
}
rows, err = res.RowsAffected()
return
}
// TxUpState update state of a archive by id.
func (d *Dao) TxUpState(tx *xsql.Tx, aid int64, state int8) (rows int64, err error) {
res, err := tx.Exec(_upStateSQL, state, aid)
if err != nil {
log.Error("tx.Exec(%d, %d) error(%v)", state, aid, err)
return
}
rows, err = res.RowsAffected()
return
}
// TxUpAccess update access of a archive by id.
func (d *Dao) TxUpAccess(tx *xsql.Tx, aid int64, access int16) (rows int64, err error) {
res, err := tx.Exec(_upAccessSQL, access, aid)
if err != nil {
log.Error("tx.Exec(%d, %d) error(%v)", access, aid, err)
return
}
rows, err = res.RowsAffected()
return
}
// TxUpRound update round of a archive by id.
func (d *Dao) TxUpRound(tx *xsql.Tx, aid int64, round int8) (rows int64, err error) {
res, err := tx.Exec(_upRoundSQL, round, aid)
if err != nil {
log.Error("tx.Exec(%d, %d) error(%v)", round, aid, err)
return
}
rows, err = res.RowsAffected()
return
}
// TxUpAttr update attribute value of a archive by id.
func (d *Dao) TxUpAttr(tx *xsql.Tx, aid int64, attr archive.Attr) (rows int64, err error) {
res, err := tx.Exec(_upAttrSQL, attr, aid)
if err != nil {
log.Error("tx.Exec(%d, %d) error(%v)", aid, attr, err)
return
}
rows, err = res.RowsAffected()
return
}
// TxUpCover update cover of a archive by id.
func (d *Dao) TxUpCover(tx *xsql.Tx, aid int64, cover string) (rows int64, err error) {
res, err := tx.Exec(_upCoverSQL, cover, aid)
if err != nil {
log.Error("tx.Exec(%d, %s) error(%v)", aid, cover, err)
return
}
rows, err = res.RowsAffected()
return
}
// UpCover update cover of a archive by id.
func (d *Dao) UpCover(c context.Context, aid int64, cover string) (rows int64, err error) {
res, err := d.db.Exec(c, _upCoverSQL, cover, aid)
if err != nil {
log.Error("tx.Exec(%d, %s) error(%v)", aid, cover, err)
return
}
rows, err = res.RowsAffected()
return
}
// TxUpArcDuration update duration of a archive by id.
func (d *Dao) TxUpArcDuration(tx *xsql.Tx, aid, duration int64) (rows int64, err error) {
res, err := tx.Exec(_upDuraSQL, duration, aid)
if err != nil {
log.Error("tx.Exec(%d, %d) error(%v)", aid, duration, err)
return
}
rows, err = res.RowsAffected()
return
}
// TxUpAttrBit update attribute bit value of a archive by id.
func (d *Dao) TxUpAttrBit(tx *xsql.Tx, aid int64, v int32, bit uint) (rows int64, err error) {
res, err := tx.Exec(_upAttrBitSQL, bit, v, bit, aid)
if err != nil {
log.Error("tx.Exec(%d, %d, %d) error(%v)", aid, v, bit, err)
return
}
rows, err = res.RowsAffected()
return
}
// TxUpPTime update ptime by aid
func (d *Dao) TxUpPTime(tx *xsql.Tx, aid int64, ptime time.Time) (rows int64, err error) {
res, err := tx.Exec(_upPTimeSQL, ptime, aid)
if err != nil {
log.Error("tx.Exec(%s, %v, %v) error(%v)", _upPTimeSQL, ptime, aid, err)
return
}
rows, err = res.RowsAffected()
return
}

View File

@@ -0,0 +1,46 @@
package archive
import (
"context"
"go-common/app/job/main/videoup/model/archive"
xsql "go-common/library/database/sql"
"go-common/library/log"
)
const (
_arcPOISQL = "SELECT data from archive_biz WHERE aid=? AND type= ?"
_arcVoteSQL = "SELECT data from archive_biz WHERE aid=? AND type=2"
)
// POI get a archive POI by avid.
func (d *Dao) POI(c context.Context, aid int64) (data []byte, err error) {
var (
row = d.db.QueryRow(c, _arcPOISQL, aid, archive.BIZPOI)
)
if err = row.Scan(&data); err != nil {
if err == xsql.ErrNoRows {
err = nil
} else {
log.Error("row.Scan error(%v)", err)
}
return
}
return
}
// Vote get a archive Vote by avid.
func (d *Dao) Vote(c context.Context, aid int64) (data []byte, err error) {
var (
row = d.db.QueryRow(c, _arcVoteSQL, aid)
)
if err = row.Scan(&data); err != nil {
if err == xsql.ErrNoRows {
err = nil
} else {
log.Error("row.Scan error(%v)", err)
}
return
}
return
}

View File

@@ -0,0 +1,29 @@
package archive
import (
"context"
. "github.com/smartystreets/goconvey/convey"
"testing"
)
func Test_POI(t *testing.T) {
var (
c = context.TODO()
err error
)
Convey("Test_POI", t, WithDao(func(d *Dao) {
_, err = d.POI(c, 23333)
So(err, ShouldBeNil)
}))
}
func Test_Vote(t *testing.T) {
var (
c = context.TODO()
err error
)
Convey("Test_Vote", t, WithDao(func(d *Dao) {
_, err = d.Vote(c, 23333)
So(err, ShouldBeNil)
}))
}

View File

@@ -0,0 +1,48 @@
package archive
import (
"context"
"database/sql"
"time"
"go-common/library/log"
)
const (
_hisCntSQL = "SELECT COUNT(*) FROM archive_edit_history WHERE aid=?"
_delEditHisSQL = "DELETE FROM archive_edit_history WHERE mtime < ? LIMIT ?"
_delVideoEditHisSQL = "DELETE FROM archive_video_edit_history WHERE mtime < ? LIMIT ?"
)
// HistoryCount get a archive history count.
func (d *Dao) HistoryCount(c context.Context, aid int64) (count int, err error) {
row := d.db.QueryRow(c, _hisCntSQL, aid)
if err = row.Scan(&count); err != nil {
if err == sql.ErrNoRows {
err = nil
} else {
log.Error("row.Scan error(%v)", err)
}
}
return
}
// DelArcEditHistoryBefore delete archive_edit_history before t.
func (d *Dao) DelArcEditHistoryBefore(c context.Context, t time.Time, limit int64) (rows int64, err error) {
res, err := d.db.Exec(c, _delEditHisSQL, t, limit)
if err != nil {
log.Error("db.Exec(%s, %s) error(%v)", _delEditHisSQL, t, err)
return
}
return res.RowsAffected()
}
// DelArcVideoEditHistoryBefore delete archive_video_edit_history before t.
func (d *Dao) DelArcVideoEditHistoryBefore(c context.Context, t time.Time, limit int64) (rows int64, err error) {
res, err := d.db.Exec(c, _delVideoEditHisSQL, t, limit)
if err != nil {
log.Error("db.Exec(%s, %s) error(%v)", _delVideoEditHisSQL, t, err)
return
}
return res.RowsAffected()
}

View File

@@ -0,0 +1,561 @@
package archive
import (
"context"
xsql "database/sql"
"fmt"
"reflect"
"time"
"go-common/app/job/main/videoup/model/archive"
"go-common/library/database/sql"
"testing"
"github.com/bouk/monkey"
_ "github.com/go-sql-driver/mysql"
. "github.com/smartystreets/goconvey/convey"
)
func Test_Archive(t *testing.T) {
var (
c = context.TODO()
err error
sub *archive.Archive
)
Convey("Tool", t, WithDao(func(d *Dao) {
sub, err = d.Archive(c, 23333)
So(err, ShouldBeNil)
So(sub, ShouldBeNil)
}))
}
func Test_UpperArcStateMap(t *testing.T) {
var (
c = context.TODO()
err error
)
Convey("UpperArcStateMap", t, WithDao(func(d *Dao) {
_, err = d.UpperArcStateMap(c, 23333)
So(err, ShouldBeNil)
}))
}
func Test_UpDelayRound(t *testing.T) {
var (
c = context.TODO()
err error
mt1, mt2 time.Time
)
Convey("UpDelayRound", t, WithDao(func(d *Dao) {
_, err = d.UpDelayRound(c, mt1, mt2)
So(err, ShouldBeNil)
}))
}
func TestDao_TxUpState(t *testing.T) {
var (
c = context.Background()
tx, _ = d.BeginTran(c)
)
Convey("TxUpState", t, func(ctx C) {
_, err := d.TxUpState(tx, 2333, 0)
if err != nil {
tx.Rollback()
} else {
tx.Commit()
}
So(err, ShouldBeNil)
})
}
func TestDao_TxUpAccess(t *testing.T) {
var (
c = context.Background()
tx, _ = d.BeginTran(c)
)
Convey("TxUpAccess", t, func(ctx C) {
_, err := d.TxUpAccess(tx, 2333, 0)
if err != nil {
tx.Rollback()
} else {
tx.Commit()
}
So(err, ShouldBeNil)
})
}
func TestDao_TxUpRound(t *testing.T) {
var (
c = context.Background()
tx, _ = d.BeginTran(c)
)
Convey("TxUpRound", t, func(ctx C) {
_, err := d.TxUpRound(tx, 2333, 0)
if err != nil {
tx.Rollback()
} else {
tx.Commit()
}
So(err, ShouldBeNil)
})
}
func TestDao_TxUpAttr(t *testing.T) {
var (
c = context.Background()
tx, _ = d.BeginTran(c)
)
Convey("TxUpAttr", t, func(ctx C) {
_, err := d.TxUpAttr(tx, 2333, 0)
if err != nil {
tx.Rollback()
} else {
tx.Commit()
}
So(err, ShouldBeNil)
})
}
func TestDao_TxUpCover(t *testing.T) {
var (
c = context.Background()
tx, _ = d.BeginTran(c)
)
Convey("TxUpCover", t, func(ctx C) {
_, err := d.TxUpCover(tx, 2333, "")
if err != nil {
tx.Rollback()
} else {
tx.Commit()
}
So(err, ShouldBeNil)
})
}
func TestDao_UpCover(t *testing.T) {
var (
c = context.Background()
)
Convey("UpCover", t, func(ctx C) {
_, err := d.UpCover(c, 2333, "")
So(err, ShouldBeNil)
})
}
func TestDao_TxUpArcDuration(t *testing.T) {
var (
c = context.Background()
tx, _ = d.BeginTran(c)
)
Convey("TxUpArcDuration", t, func(ctx C) {
_, err := d.TxUpArcDuration(tx, 2333, 0)
if err != nil {
tx.Rollback()
} else {
tx.Commit()
}
So(err, ShouldBeNil)
})
}
func TestDao_TxUpAttrBit(t *testing.T) {
var (
c = context.Background()
tx, _ = d.BeginTran(c)
)
Convey("TxUpAttrBit", t, func(ctx C) {
_, err := d.TxUpAttrBit(tx, 2333, 0, 1)
if err != nil {
tx.Rollback()
} else {
tx.Commit()
}
So(err, ShouldBeNil)
})
}
func TestDao_TxUpPTime(t *testing.T) {
var (
c = context.Background()
tx, _ = d.BeginTran(c)
tm time.Time
)
Convey("TxUpPTime", t, func(ctx C) {
_, err := d.TxUpPTime(tx, 2333, tm)
if err != nil {
tx.Rollback()
} else {
tx.Commit()
}
So(err, ShouldBeNil)
})
}
func Test_ArchiveAddict(t *testing.T) {
var (
c = context.TODO()
err error
sub *archive.Addit
)
Convey("Addit", t, WithDao(func(d *Dao) {
sub, err = d.Addit(c, 23333)
So(err, ShouldBeNil)
So(sub, ShouldBeNil)
}))
}
func Test_Delay(t *testing.T) {
var (
c = context.TODO()
err error
sub *archive.Delay
)
Convey("Delay", t, WithDao(func(d *Dao) {
sub, err = d.Delay(c, 2333)
So(err, ShouldBeNil)
So(sub, ShouldBeNil)
}))
}
func Test_NowDelays(t *testing.T) {
var (
c = context.TODO()
err error
sub []*archive.Delay
)
Convey("NowDelays", t, WithDao(func(d *Dao) {
sub, err = d.NowDelays(c, time.Now())
So(err, ShouldBeNil)
So(sub, ShouldBeNil)
}))
}
func Test_Forbid(t *testing.T) {
var (
c = context.TODO()
err error
sub *archive.ForbidAttr
)
Convey("Forbid", t, WithDao(func(d *Dao) {
sub, err = d.Forbid(c, 23333)
So(err, ShouldBeNil)
So(sub, ShouldNotBeNil)
}))
}
func Test_TrackPassed(t *testing.T) {
var (
c = context.TODO()
err error
sub int64
)
Convey("TrackPassed", t, WithDao(func(d *Dao) {
sub, err = d.GetFirstPassByAID(c, 233)
So(err, ShouldBeNil)
So(sub, ShouldBeZeroValue)
}))
}
func Test_TypeMapping(t *testing.T) {
var (
c = context.TODO()
err error
)
Convey("TypeMapping", t, WithDao(func(d *Dao) {
_, err = d.TypeMapping(c)
So(err, ShouldBeNil)
}))
}
/*func Test_AddRdsCovers(t *testing.T) {
var (
c = context.TODO()
err error
cvs = []*archive.Cover{
&archive.Cover{
Filename: "sssss",
},
}
)
Convey("AddRdsCovers", t, WithDao(func(d *Dao) {
_, err = d.AddRdsCovers(c, cvs)
So(err, ShouldBeNil)
}))
}*/
func Test_DBus(t *testing.T) {
var (
c = context.TODO()
err error
)
Convey("DBus", t, WithDao(func(d *Dao) {
_, err = d.DBus(c, "sss", "sssew", 888)
So(err, ShouldBeNil)
}))
}
func Test_UpDBus(t *testing.T) {
var (
c = context.TODO()
err error
)
Convey("UpDBus", t, WithDao(func(d *Dao) {
_, err = d.UpDBus(c, "sss", "sssew", 888, 33)
So(err, ShouldBeNil)
}))
}
func Test_DelAdminDelay(t *testing.T) {
var (
c = context.TODO()
err error
)
Convey("DelAdminDelay", t, WithDao(func(d *Dao) {
_, err = d.DelAdminDelay(c, 2333)
So(err, ShouldBeNil)
}))
}
func Test_DelDelayByIds(t *testing.T) {
var (
c = context.TODO()
err error
)
Convey("DelDelayByIds", t, WithDao(func(d *Dao) {
_, err = d.DelDelayByIds(c, []int64{2333})
So(err, ShouldBeNil)
}))
}
func Test_FirstPassCount(t *testing.T) {
var (
c = context.TODO()
err error
)
Convey("FirstPassCount", t, WithDao(func(d *Dao) {
_, err = d.FirstPassCount(c, []int64{2333})
So(err, ShouldBeNil)
}))
}
func TestDao_TxUpForbid(t *testing.T) {
var (
c = context.Background()
tx, _ = d.BeginTran(c)
af = &archive.ForbidAttr{
Aid: 2333,
}
)
Convey("TxUpForbid", t, func(ctx C) {
_, err := d.TxUpForbid(tx, af)
if err != nil {
tx.Rollback()
} else {
tx.Commit()
}
So(err, ShouldBeNil)
})
}
func TestDao_TxUpVideoXState(t *testing.T) {
var (
c = context.Background()
tx, _ = d.BeginTran(c)
)
Convey("TxUpVideoXState", t, func(ctx C) {
_, err := d.TxUpVideoXState(tx, "sssss", 4)
if err != nil {
tx.Rollback()
} else {
tx.Commit()
}
So(err, ShouldBeNil)
})
}
func TestDao_TxUpVideoPlayurl(t *testing.T) {
var (
c = context.Background()
tx, _ = d.BeginTran(c)
)
Convey("TxUpVideoPlayurl", t, func(ctx C) {
_, err := d.TxUpVideoPlayurl(tx, "sssss", "")
if err != nil {
tx.Rollback()
} else {
tx.Commit()
}
So(err, ShouldBeNil)
})
}
func TestDao_TxUpVDuration(t *testing.T) {
var (
c = context.Background()
tx, _ = d.BeginTran(c)
)
Convey("TxUpVDuration", t, func(ctx C) {
_, err := d.TxUpVDuration(tx, "sssss", 4)
if err != nil {
tx.Rollback()
} else {
tx.Commit()
}
So(err, ShouldBeNil)
})
}
func TestDao_TxUpVideoFilesize(t *testing.T) {
var (
c = context.Background()
tx, _ = d.BeginTran(c)
)
Convey("TxUpVideoFilesize", t, func(ctx C) {
_, err := d.TxUpVideoFilesize(tx, "sssss", 4)
if err != nil {
tx.Rollback()
} else {
tx.Commit()
}
So(err, ShouldBeNil)
})
}
func TestDao_TxUpVideoResolutionsAndDimensions(t *testing.T) {
var (
c = context.Background()
tx, _ = d.BeginTran(c)
)
Convey("TxUpVideoResolutionsAndDimensions", t, func(ctx C) {
_, err := d.TxUpVideoResolutionsAndDimensions(tx, "sssss", "", "1280,720,0")
if err != nil {
tx.Rollback()
} else {
tx.Commit()
}
So(err, ShouldBeNil)
})
}
func TestDao_TxUpVideoFailCode(t *testing.T) {
var (
c = context.Background()
tx, _ = d.BeginTran(c)
)
Convey("TxUpVideoFailCode", t, func(ctx C) {
_, err := d.TxUpVideoFailCode(tx, "sssss", -2)
if err != nil {
tx.Rollback()
} else {
tx.Commit()
}
So(err, ShouldBeNil)
})
}
func TestDao_TxUpRelationStatus(t *testing.T) {
var (
c = context.Background()
tx, _ = d.BeginTran(c)
)
Convey("TxUpRelationStatus", t, func(ctx C) {
_, err := d.TxUpRelationStatus(tx, 2333, 0)
if err != nil {
tx.Rollback()
} else {
tx.Commit()
}
So(err, ShouldBeNil)
})
}
func TestDao_NewVideos(t *testing.T) {
var (
c = context.Background()
)
Convey("NewVideos", t, func(ctx C) {
_, err := d.NewVideos(c, 2333)
So(err, ShouldBeNil)
})
}
func TestDao_ValidAidByCid(t *testing.T) {
var (
c = context.Background()
)
Convey("ValidAidByCid", t, func(ctx C) {
_, err := d.ValidAidByCid(c, 2333)
So(err, ShouldBeNil)
})
}
func TestDao_Stat(t *testing.T) {
var (
c = context.Background()
)
Convey("Stat", t, func(ctx C) {
_, err := d.Stat(c, 2333)
So(err, ShouldBeNil)
})
}
func TestDao_TypeNaming(t *testing.T) {
var (
c = context.Background()
)
Convey("TypeNaming", t, func(ctx C) {
_, err := d.TypeNaming(c)
So(err, ShouldBeNil)
})
}
func TestDao_VdoWithArcCntCapable(t *testing.T) {
var (
c = context.Background()
)
Convey("VdoWithArcCntCapable", t, func(ctx C) {
_, err := d.VdoWithArcCntCapable(c, 2333)
So(err, ShouldBeNil)
})
}
func TestDao_VideoCountCapable(t *testing.T) {
var (
c = context.Background()
)
Convey("VideoCountCapable", t, func(ctx C) {
_, err := d.VideoCountCapable(c, 2333)
So(err, ShouldBeNil)
})
}
func TestDao_Videos(t *testing.T) {
var (
c = context.Background()
)
Convey("Videos", t, func(ctx C) {
_, err := d.Videos(c, 2333)
So(err, ShouldBeNil)
})
}
func TestDao_Video(t *testing.T) {
var (
c = context.Background()
)
Convey("Video", t, func(ctx C) {
_, err := d.Video(c, "sssss")
So(err, ShouldBeNil)
})
}
func TestDao_TranVideoOper(t *testing.T) {
var (
c = context.Background()
tx, _ = d.BeginTran(c)
)
Convey("TranVideoOper", t, func(ctx C) {
guard := monkey.PatchInstanceMethod(reflect.TypeOf(tx), "Exec",
func(_ *sql.Tx, _ string, _ ...interface{}) (xsql.Result, error) {
return nil, fmt.Errorf("tx.Exec Error")
})
defer guard.Unpatch()
_, err := d.TranVideoOper(c, tx, 2333, 111, 0, 0)
if err != nil {
tx.Rollback()
} else {
tx.Commit()
}
So(err, ShouldBeNil)
})
}
/*func TestDao_AICover(t *testing.T) {
var (
c = context.Background()
)
Convey("AICover", t, func(ctx C) {
_, err := d.AICover(c, "sssss")
So(err, ShouldBeNil)
})
}*/

View File

@@ -0,0 +1,45 @@
package archive
import (
"context"
_ "github.com/go-sql-driver/mysql"
. "github.com/smartystreets/goconvey/convey"
"testing"
"time"
)
func Test_ArchiveHistory(t *testing.T) {
var (
c = context.TODO()
err error
)
Convey("HistoryCount", t, WithDao(func(d *Dao) {
_, err = d.HistoryCount(c, 23333)
So(err, ShouldBeNil)
}))
}
func Test_DelArcEditHistoryBefore(t *testing.T) {
var (
c = context.TODO()
err error
tm time.Time
)
Convey("DelArcEditHistoryBefore", t, WithDao(func(d *Dao) {
_, err = d.DelArcEditHistoryBefore(c, tm, 1)
So(err, ShouldBeNil)
}))
}
func Test_DelArcVideoEditHistoryBefore(t *testing.T) {
var (
c = context.TODO()
err error
tm time.Time
)
Convey("DelArcVideoEditHistoryBefore", t, WithDao(func(d *Dao) {
_, err = d.DelArcVideoEditHistoryBefore(c, tm, 1)
So(err, ShouldBeNil)
}))
}

View File

@@ -0,0 +1,127 @@
package archive
import (
"context"
"database/sql"
"encoding/json"
"strconv"
"strings"
"go-common/app/job/main/videoup/model/archive"
"go-common/library/log"
"go-common/library/xstr"
)
const (
_confSQL = "SELECT value FROM archive_config WHERE state=0 AND name=?"
)
//RoundEndConf round_delay_time 正常状态的配置
func (d *Dao) RoundEndConf(c context.Context) (days int64, err error) {
row := d.db.QueryRow(c, _confSQL, archive.ConfForRoundEnd)
var val string
if err = row.Scan(&val); err != nil {
if err == sql.ErrNoRows {
err = nil
} else {
log.Error("row.Scan error(%v)", err)
}
return
}
if days, err = strconv.ParseInt(val, 10, 64); err != nil {
log.Error("srconv.ParseInt(%s) error(%v)", val, err)
}
return
}
//FansConf round_limit_fans正常状态的配置
func (d *Dao) FansConf(c context.Context) (fans int64, err error) {
row := d.db.QueryRow(c, _confSQL, archive.ConfForClick)
var val string
if err = row.Scan(&val); err != nil {
if err == sql.ErrNoRows {
err = nil
} else {
log.Error("row.Scan error(%v)", err)
}
return
}
if fans, err = strconv.ParseInt(val, 10, 64); err != nil {
log.Error("strconv.ParseInt(%s) error(%v)", val, err)
}
return
}
//RoundTypeConf round_limit_tids 正常状态的配置
func (d *Dao) RoundTypeConf(c context.Context) (roundTypes map[int16]struct{}, err error) {
roundTypes = map[int16]struct{}{}
row := d.db.QueryRow(c, _confSQL, archive.ConfForRoundType)
var (
val string
tids []string
tid int64
)
if err = row.Scan(&val); err != nil {
if err == sql.ErrNoRows {
err = nil
} else {
log.Error("row.Scan error(%v)", err)
}
return
}
tids = strings.Split(val, ",")
for _, tidStr := range tids {
if tid, err = strconv.ParseInt(tidStr, 10, 64); err != nil {
log.Error("strconv.ParseInt(%d) error(%v)", tid, err)
return
}
roundTypes[int16(tid)] = struct{}{}
}
return
}
//AuditTypesConf wait_audit_arctype 状态正常的配置
func (d *Dao) AuditTypesConf(c context.Context) (atps map[int16]struct{}, err error) {
row := d.db.QueryRow(c, _confSQL, archive.ConfForAuditType)
var (
value string
typeIDs []int64
)
if err = row.Scan(&value); err != nil {
if err == sql.ErrNoRows {
err = nil
} else {
log.Error("row.Scan error(%v)", err)
}
return
}
typeIDs, err = xstr.SplitInts(value)
if err != nil {
log.Error("archive_config value(%s) xstr.SplitInts error(%v)", value, err)
return
}
atps = map[int16]struct{}{}
for _, typeid := range typeIDs {
atps[int16(typeid)] = struct{}{}
}
return
}
//ThresholdConf ThresholdConf is second types opposite first types.
func (d *Dao) ThresholdConf(c context.Context) (tpThr map[int16]int, err error) {
row := d.db.QueryRow(c, _confSQL, archive.ConfForThreshold)
var value string
if err = row.Scan(&value); err != nil {
if err == sql.ErrNoRows {
err = nil
} else {
log.Error("row.Scan() error(%v)", err)
}
return
}
if err = json.Unmarshal([]byte(value), &tpThr); err != nil {
log.Error("json.Unmarshal(%s) error(%v)", value, err)
return
}
return
}

View File

@@ -0,0 +1,70 @@
package archive
import (
"context"
_ "github.com/go-sql-driver/mysql"
. "github.com/smartystreets/goconvey/convey"
"testing"
)
func Test_RoundEndConf(t *testing.T) {
var (
c = context.TODO()
err error
)
Convey("RoundEndConf", t, WithDao(func(d *Dao) {
_, err = d.RoundEndConf(c)
So(err, ShouldBeNil)
}))
}
func Test_FansConf(t *testing.T) {
var (
c = context.TODO()
err error
sub int64
)
Convey("FansConf", t, WithDao(func(d *Dao) {
sub, err = d.FansConf(c)
So(err, ShouldBeNil)
So(sub, ShouldNotBeEmpty)
}))
}
func Test_RoundTypeConf(t *testing.T) {
var (
c = context.TODO()
err error
sub map[int16]struct{}
)
Convey("RoundTypeConf", t, WithDao(func(d *Dao) {
sub, err = d.RoundTypeConf(c)
So(err, ShouldBeNil)
So(sub, ShouldNotBeNil)
}))
}
func Test_AuditTypesConf(t *testing.T) {
var (
c = context.TODO()
err error
sub map[int16]struct{}
)
Convey("AuditTypesConf", t, WithDao(func(d *Dao) {
sub, err = d.AuditTypesConf(c)
So(err, ShouldBeNil)
So(sub, ShouldNotBeNil)
}))
}
func Test_ThresholdConf(t *testing.T) {
var (
c = context.TODO()
err error
sub map[int16]int
)
Convey("ThresholdConf", t, WithDao(func(d *Dao) {
sub, err = d.ThresholdConf(c)
So(err, ShouldBeNil)
So(sub, ShouldNotBeNil)
}))
}

View File

@@ -0,0 +1,45 @@
package archive
import (
"context"
"fmt"
"time"
"go-common/app/job/main/videoup/model/archive"
"go-common/library/cache/redis"
"go-common/library/log"
)
func vcoverKey(filename string) string {
return fmt.Sprintf("%s_%s", "vcover_", filename)
}
// AddRdsCovers fn.
func (d *Dao) AddRdsCovers(c context.Context, covers []*archive.Cover) (ok bool, err error) {
var conn = d.coverRds.Get(c)
defer conn.Close()
var key string
log.Info("AddRdsCovers info:(%+v)", covers)
for _, c := range covers {
if key == "" {
key = vcoverKey(c.Filename)
}
if err = conn.Send("SADD", key, c.BFSPath); err != nil {
log.Error("conn.Do(SETEX, %s, %s, %d, %d) error(%v)", c.Filename, c.BFSPath, d.coverExpire, time.Now().Unix(), err)
}
}
if err = conn.Send("EXPIRE", key, d.coverExpire); err != nil {
log.Error("conn.Send(EXPIRE, %s, %d) error(%v)", key, d.coverExpire, err)
return
}
if err = conn.Flush(); err != nil {
log.Error("conn.Flush error(%v)", err)
return
}
for i := 0; i < len(covers); i++ {
if ok, err = redis.Bool(conn.Receive()); err != nil {
log.Error("conn.Receive error(%v)", err)
}
}
return
}

View File

@@ -0,0 +1,51 @@
package archive
import (
"context"
"go-common/app/job/main/videoup/conf"
xredis "go-common/library/cache/redis"
xsql "go-common/library/database/sql"
xhttp "go-common/library/net/http/blademaster"
)
// Dao is redis dao.
type Dao struct {
c *conf.Config
db *xsql.DB
rdb *xsql.DB
coverRds *xredis.Pool
coverExpire int32
client *xhttp.Client
statURI string
recommendURI string
}
// New new a archive dao.
func New(c *conf.Config) (d *Dao) {
d = &Dao{
c: c,
db: xsql.NewMySQL(c.DB.Archive),
rdb: xsql.NewMySQL(c.DB.ArchiveRead),
coverRds: xredis.NewPool(c.Redis),
coverExpire: 86400 * 15,
client: xhttp.NewClient(c.HTTPClient),
statURI: c.Host.API + "/x/internal/v2/archive/stat",
recommendURI: c.Host.RecCover + "/cover_recomm",
}
return d
}
// BeginTran begin transcation.
func (d *Dao) BeginTran(c context.Context) (tx *xsql.Tx, err error) {
return d.db.Begin(c)
}
// Close fn
func (d *Dao) Close() {
d.coverRds.Close()
}
// Ping hbase
func (d *Dao) Ping(c context.Context) (err error) {
return nil
}

View File

@@ -0,0 +1,41 @@
package archive
import (
"flag"
. "github.com/smartystreets/goconvey/convey"
"go-common/app/job/main/videoup/conf"
"os"
"testing"
)
var (
d *Dao
)
func WithDao(f func(d *Dao)) func() {
return func() {
Reset(func() {})
f(d)
}
}
func TestMain(m *testing.M) {
if os.Getenv("DEPLOY_ENV") != "" {
flag.Set("app_id", "main.archive.videoup-job")
flag.Set("conf_token", "c31b4b632890e663002ab6ac22835cda")
flag.Set("tree_id", "2304")
flag.Set("conf_version", "docker-1")
flag.Set("deploy_env", "uat")
flag.Set("conf_host", "config.bilibili.co")
flag.Set("conf_path", "/tmp")
flag.Set("region", "sh")
flag.Set("zone", "sh001")
} else {
flag.Set("conf", "../../cmd/videoup-job-test.toml")
}
flag.Parse()
if err := conf.Init(); err != nil {
panic(err)
}
d = New(conf.Conf)
os.Exit(m.Run())
}

View File

@@ -0,0 +1,50 @@
package archive
import (
"context"
"go-common/app/job/main/videoup/model/archive"
"go-common/library/database/sql"
"go-common/library/log"
)
const (
_dbusSQL = "SELECT id,gp,topic,part,last_offset FROM archive_databus WHERE gp=? AND topic=? AND part=?"
_inDBusSQL = "INSERT INTO archive_databus(gp,topic,part,last_offset) VALUES(?,?,?,?)"
_upDBusSQL = "UPDATE archive_databus SET last_offset=? WHERE gp=? AND topic=? AND part=?"
)
// DBus get DBus by group+topic+partition
func (d *Dao) DBus(c context.Context, group, topic string, partition int32) (dbus *archive.Databus, err error) {
row := d.db.QueryRow(c, _dbusSQL, group, topic, partition)
dbus = &archive.Databus{}
if err = row.Scan(&dbus.ID, &dbus.Group, &dbus.Topic, &dbus.Partition, &dbus.Offset); err != nil {
if err == sql.ErrNoRows {
dbus = nil
err = nil
} else {
log.Error("row.Scan error(%v)", err)
}
}
return
}
// AddDBus add databus
func (d *Dao) AddDBus(c context.Context, group, topic string, partition int32, offset int64) (rows int64, err error) {
res, err := d.db.Exec(c, _inDBusSQL, group, topic, partition, offset)
if err != nil {
log.Error("d.db.Exec(%s, %s, %d, %d) error(%v)", group, topic, partition, offset, err)
return
}
return res.RowsAffected()
}
// UpDBus update databus offset
func (d *Dao) UpDBus(c context.Context, group, topic string, partition int32, offset int64) (rows int64, err error) {
res, err := d.db.Exec(c, _upDBusSQL, offset, group, topic, partition)
if err != nil {
log.Error("d.db.Exec(%d, %s, %s, %d) error(%v)", offset, group, topic, partition, err)
return
}
return res.RowsAffected()
}

View File

@@ -0,0 +1,78 @@
package archive
import (
"context"
"fmt"
"time"
"go-common/app/job/main/videoup/model/archive"
"go-common/library/database/sql"
"go-common/library/log"
"go-common/library/xstr"
)
const (
_delaysSQL = "SELECT id,aid,dtime,type,state FROM archive_delay WHERE aid=? AND deleted_at = 0 ORDER BY dtime DESC LIMIT 1"
_getNowDelaysSQL = "SELECT id,aid,dtime,type,state FROM archive_delay WHERE dtime<=? AND deleted_at = 0"
_delAdminDelaySQL = "UPDATE archive_delay SET deleted_at = ? WHERE aid=? AND type=1"
_delDelayByIdsSQL = "UPDATE archive_delay SET deleted_at = ? WHERE id IN(%s)"
)
// Delay get delay by aid
func (d *Dao) Delay(c context.Context, aid int64) (delay *archive.Delay, err error) {
rows := d.db.QueryRow(c, _delaysSQL, aid)
delay = &archive.Delay{}
if err = rows.Scan(&delay.ID, &delay.Aid, &delay.DTime, &delay.Type, &delay.State); err != nil {
if err == sql.ErrNoRows {
delay = nil
err = nil
} else {
log.Error("row.Scan error(%v)", err)
}
}
return
}
// NowDelays get current minute dalay archive
func (d *Dao) NowDelays(c context.Context, dtime time.Time) (delays []*archive.Delay, err error) {
rows, err := d.db.Query(c, _getNowDelaysSQL, dtime)
if err != nil {
log.Error("d.db.Query(%s) error(%v)", dtime, err)
return
}
defer rows.Close()
for rows.Next() {
v := &archive.Delay{}
if err = rows.Scan(&v.ID, &v.Aid, &v.DTime, &v.Type, &v.State); err != nil {
log.Error("rows.Scan error(%v)", err)
return
}
delays = append(delays, v)
}
return
}
// DelAdminDelay delete admin delay by aid
func (d *Dao) DelAdminDelay(c context.Context, aid int64) (rows int64, err error) {
res, err := d.db.Exec(c, _delAdminDelaySQL, time.Now(), aid)
if err != nil {
log.Error("d.db.Exec(%d) error(%v)", aid, err)
return
}
rows, err = res.RowsAffected()
return
}
// DelDelayByIds delete delays by ids
func (d *Dao) DelDelayByIds(c context.Context, ids []int64) (rows int64, err error) {
if len(ids) == 0 {
return
}
res, err := d.db.Exec(c, fmt.Sprintf(_delDelayByIdsSQL, xstr.JoinInts(ids)), time.Now())
if err != nil {
log.Error("d.DelDelayByIds() error(%v)", err)
return
}
rows, err = res.RowsAffected()
return
}

View File

@@ -0,0 +1,58 @@
package archive
import (
"context"
"fmt"
"go-common/library/database/sql"
"go-common/library/log"
"go-common/library/xstr"
"time"
)
const (
_slFirstPassByAID = "SELECT `id` FROM `archive_first_pass` WHERE `aid`=? LIMIT 1;"
_firstPassCount = "SELECT COUNT(id) FROM archive_first_pass WHERE aid IN (%s)"
_inFirstPass = "INSERT INTO `archive_first_pass`(`aid`, `ctime`, `mtime`) VALUES(?,?,?);"
)
//GetFirstPassByAID 根据aid获取第一次过审的记录
func (d *Dao) GetFirstPassByAID(c context.Context, aid int64) (id int64, err error) {
row := d.db.QueryRow(c, _slFirstPassByAID, aid)
if err = row.Scan(&id); err != nil {
if err == sql.ErrNoRows {
err = nil
} else {
log.Error("GetFirstPassByAID error(%v) aid(%d)", err, aid)
}
return
}
return
}
// FirstPassCount 根据aid获取第一次过审的数量
func (d *Dao) FirstPassCount(c context.Context, aids []int64) (count int, err error) {
if len(aids) < 1 {
return
}
row := d.rdb.QueryRow(c, fmt.Sprintf(_firstPassCount, xstr.JoinInts(aids)))
if err = row.Scan(&count); err != nil {
if err == sql.ErrNoRows {
err = nil
} else {
log.Error("row.Scan() error(%v) aid(%v)", err, aids)
}
return
}
return
}
//AddFirstPass 添加一条 第一次过审的记录
func (d *Dao) AddFirstPass(tx *sql.Tx, aid int64) (err error) {
now := time.Now()
if _, err = tx.Exec(_inFirstPass, aid, now, now); err != nil {
log.Error("AddFirstPass error(%v) aid(%d)", aid, err)
}
return
}

View File

@@ -0,0 +1,42 @@
package archive
import (
"context"
"go-common/app/job/main/videoup/model/archive"
"go-common/library/database/sql"
"go-common/library/log"
)
const (
_inForbidSQL = `INSERT INTO archive_forbid (aid,rank_attr,recommend_attr,dynamic_attr,show_attr) VALUES (?,?,?,?,?) ON DUPLICATE KEY UPDATE
rank_attr=?,recommend_attr=?,dynamic_attr=?,show_attr=?`
_forbidSQL = `SELECT aid,rank_attr,recommend_attr,dynamic_attr,show_attr,on_flow_id FROM archive_forbid WHERE aid=?`
)
// TxUpForbid insert archive_oper.
func (d *Dao) TxUpForbid(tx *sql.Tx, af *archive.ForbidAttr) (rows int64, err error) {
res, err := tx.Exec(_inForbidSQL, af.Aid, af.RankV, af.RecommendV, af.DynamicV, af.ShowV, af.RankV, af.RecommendV, af.DynamicV, af.ShowV)
if err != nil {
log.Error("d.inForbid.Exec error(%v)", err)
return
}
rows, err = res.RowsAffected()
return
}
// Forbid get a archive forbid.
func (d *Dao) Forbid(c context.Context, aid int64) (af *archive.ForbidAttr, err error) {
row := d.db.QueryRow(c, _forbidSQL, aid)
af = &archive.ForbidAttr{Aid: aid}
if err = row.Scan(&af.Aid, &af.RankV, &af.RecommendV, &af.DynamicV, &af.ShowV, &af.OnFlowID); err != nil {
if err == sql.ErrNoRows {
// af = nil // NOTE: for init
err = nil
} else {
log.Error("row.Scan error(%v)", err)
}
return
}
return
}

View File

@@ -0,0 +1,264 @@
package archive
import (
"context"
"database/sql"
xsql "go-common/library/database/sql"
"go-common/library/log"
"go-common/app/job/main/videoup/model/archive"
farm "github.com/dgryski/go-farm"
)
const (
_upVideoXStateSQL = "UPDATE video SET xcode_state=? WHERE hash64=? AND filename=?"
_upVideoStatusSQL = "UPDATE video SET status=? WHERE hash64=? AND filename=?"
_upVideoPlayurlSQL = "UPDATE video SET playurl=? WHERE hash64=? AND filename=?"
_upVideoDuraSQL = "UPDATE video SET duration=? WHERE hash64=? AND filename=?"
_upVideoFilesizeSQL = "UPDATE video SET filesize=? WHERE hash64=? AND filename=?"
_upVideoResolutionSQL = "UPDATE video SET resolutions=?,dimensions=? WHERE hash64=? AND filename=?"
_upVideoFailCodeSQL = "UPDATE video SET failcode=? WHERE hash64=? AND filename=?"
_upRelationStatusSQL = "UPDATE archive_video_relation SET state=? WHERE cid=?"
_newVideoByFnSQL = `SELECT avr.id,v.filename,avr.cid,avr.aid,avr.title,avr.description,v.src_type,v.duration,v.filesize,v.resolutions,v.playurl,v.failcode,
avr.index_order,v.attribute,v.xcode_state,avr.state,v.status,avr.ctime,avr.mtime FROM archive_video_relation avr JOIN video v on avr.cid = v.id
WHERE hash64=? AND filename=?`
_newVideoByAidFnSQL = `SELECT avr.id,v.filename,avr.cid,avr.aid,avr.title,avr.description,v.src_type,v.duration,v.filesize,v.resolutions,v.playurl,v.failcode,
avr.index_order,v.attribute,v.xcode_state,avr.state,v.status,avr.ctime,avr.mtime FROM archive_video_relation avr JOIN video v on avr.cid = v.id
WHERE aid=? AND hash64=? AND filename=?`
_newVideosSQL = `SELECT avr.id,v.filename,avr.cid,avr.aid,avr.title,avr.description,v.src_type,v.duration,v.filesize,v.resolutions,v.playurl,v.failcode,
avr.index_order,v.attribute,v.xcode_state,avr.state,v.status,avr.ctime,avr.mtime FROM archive_video_relation avr JOIN video v on avr.cid = v.id
WHERE aid=? ORDER BY index_order`
_newVideoCntSQL = `SELECT COUNT(*) FROM archive_video_relation WHERE aid=? AND state!=-100`
_newSumDuraSQL = `SELECT SUM(duration) FROM archive_video_relation avr JOIN video v on avr.cid = v.id WHERE aid=? AND avr.state=0 AND (v.status=0 || v.status=10000)`
_newVdoBvcCntSQL = `SELECT COUNT(*) FROM archive_video_relation avr JOIN video v on avr.cid = v.id WHERE cid=? AND avr.state=0 AND (v.status=0 || v.status=10000) AND v.xcode_state=6`
_validAidByCid = `SELECT DISTINCT aid FROM archive_video_relation avr JOIN video v on avr.cid = v.id WHERE cid=? AND avr.state=0 AND (v.status=0 || v.status=10000) AND v.xcode_state=6`
)
// TxUpVideoXState update video xcodestate.
func (d *Dao) TxUpVideoXState(tx *xsql.Tx, filename string, xState int8) (rows int64, err error) {
hash64 := int64(farm.Hash64([]byte(filename)))
res, err := tx.Exec(_upVideoXStateSQL, xState, hash64, filename)
if err != nil {
log.Error("tx.upVideoXState.Exec(%d, %s) error(%v)", xState, filename, err)
return
}
return res.RowsAffected()
}
// TxUpVideoStatus update video status.
func (d *Dao) TxUpVideoStatus(tx *xsql.Tx, filename string, status int16) (rows int64, err error) {
hash64 := int64(farm.Hash64([]byte(filename)))
res, err := tx.Exec(_upVideoStatusSQL, status, hash64, filename)
if err != nil {
log.Error("tx.upVideoStatus.Exec(%d, %s) error(%v)", status, filename, err)
return
}
return res.RowsAffected()
}
// TxUpVideoPlayurl update video playurl and duration.
func (d *Dao) TxUpVideoPlayurl(tx *xsql.Tx, filename, playurl string) (rows int64, err error) {
hash64 := int64(farm.Hash64([]byte(filename)))
res, err := tx.Exec(_upVideoPlayurlSQL, playurl, hash64, filename)
if err != nil {
log.Error("tx.upVideoPlayurl.Exec(%s, %s) error(%v)", playurl, filename, err)
return
}
return res.RowsAffected()
}
// TxUpVDuration update video playurl and duration.
func (d *Dao) TxUpVDuration(tx *xsql.Tx, filename string, duration int64) (rows int64, err error) {
hash64 := int64(farm.Hash64([]byte(filename)))
res, err := tx.Exec(_upVideoDuraSQL, duration, hash64, filename)
if err != nil {
log.Error("tx.upVideoDura.Exec(%d, %s) error(%v)", duration, filename, err)
return
}
return res.RowsAffected()
}
// TxUpVideoFilesize update video filesize.
func (d *Dao) TxUpVideoFilesize(tx *xsql.Tx, filename string, filesize int64) (rows int64, err error) {
hash64 := int64(farm.Hash64([]byte(filename)))
res, err := tx.Exec(_upVideoFilesizeSQL, filesize, hash64, filename)
if err != nil {
log.Error("tx.upVideoFilesize.Exec(%d, %s) error(%v)", filesize, filename, err)
}
return res.RowsAffected()
}
// TxUpVideoResolutionsAndDimensions update video resolutions and dimensions.
func (d *Dao) TxUpVideoResolutionsAndDimensions(tx *xsql.Tx, filename, resolutions, dimensions string) (rows int64, err error) {
hash64 := int64(farm.Hash64([]byte(filename)))
res, err := tx.Exec(_upVideoResolutionSQL, resolutions, dimensions, hash64, filename)
if err != nil {
log.Error("tx.TxUpVideoResolutionsAndDimensions.Exec(%s,%s, %s) error(%v)", resolutions, dimensions, filename, err)
return
}
return res.RowsAffected()
}
// TxUpVideoFailCode update video fail info.
func (d *Dao) TxUpVideoFailCode(tx *xsql.Tx, filename string, fileCode int8) (rows int64, err error) {
hash64 := int64(farm.Hash64([]byte(filename)))
res, err := tx.Exec(_upVideoFailCodeSQL, fileCode, hash64, filename)
if err != nil {
log.Error("tx.upVideoFailCode.Exec(%s, %d) error(%v)", filename, fileCode, err)
return
}
return res.RowsAffected()
}
// TxUpRelationStatus update video status.
func (d *Dao) TxUpRelationStatus(tx *xsql.Tx, cid int64, status int8) (rows int64, err error) {
res, err := tx.Exec(_upRelationStatusSQL, status, cid)
if err != nil {
log.Error("tx.TxUpRelationStatus.Exec(%d, %d) error(%v)", status, cid, err)
return
}
return res.RowsAffected()
}
// NewVideo get video info by filename.
func (d *Dao) NewVideo(c context.Context, filename string) (v *archive.Video, err error) {
hash64 := int64(farm.Hash64([]byte(filename)))
row := d.db.QueryRow(c, _newVideoByFnSQL, hash64, filename)
v = &archive.Video{}
var avrState, vState int16
if err = row.Scan(&v.ID, &v.Filename, &v.Cid, &v.Aid, &v.Title, &v.Desc, &v.SrcType, &v.Duration, &v.Filesize, &v.Resolutions,
&v.Playurl, &v.FailCode, &v.Index, &v.Attribute, &v.XcodeState, &avrState, &vState, &v.CTime, &v.MTime); err != nil {
if err == sql.ErrNoRows {
v = nil
err = nil
} else {
log.Error("row.Scan error(%v)", err)
}
return
}
// 2 state map to 1
if avrState == archive.VideoStatusDelete {
v.Status = archive.VideoStatusDelete
} else {
v.Status = vState
}
return
}
// NewVideoByAid get video info by filename. and aid
func (d *Dao) NewVideoByAid(c context.Context, filename string, aid int64) (v *archive.Video, err error) {
hash64 := int64(farm.Hash64([]byte(filename)))
row := d.db.QueryRow(c, _newVideoByAidFnSQL, aid, hash64, filename)
v = &archive.Video{}
var avrState, vState int16
if err = row.Scan(&v.ID, &v.Filename, &v.Cid, &v.Aid, &v.Title, &v.Desc, &v.SrcType, &v.Duration, &v.Filesize, &v.Resolutions,
&v.Playurl, &v.FailCode, &v.Index, &v.Attribute, &v.XcodeState, &avrState, &vState, &v.CTime, &v.MTime); err != nil {
if err == sql.ErrNoRows {
v = nil
err = nil
} else {
log.Error("row.Scan error(%v)", err)
}
return
}
// 2 state map to 1
if avrState == archive.VideoStatusDelete {
v.Status = archive.VideoStatusDelete
} else {
v.Status = vState
}
return
}
// NewVideos get videos info by aid.
func (d *Dao) NewVideos(c context.Context, aid int64) (vs []*archive.Video, err error) {
rows, err := d.db.Query(c, _newVideosSQL, aid)
if err != nil {
log.Error("d.db.Query(%d) error(%v)", aid, err)
return
}
defer rows.Close()
for rows.Next() {
v := &archive.Video{}
var avrState, vState int16
if err = rows.Scan(&v.ID, &v.Filename, &v.Cid, &v.Aid, &v.Title, &v.Desc, &v.SrcType, &v.Duration, &v.Filesize, &v.Resolutions,
&v.Playurl, &v.FailCode, &v.Index, &v.Attribute, &v.XcodeState, &avrState, &vState, &v.CTime, &v.MTime); err != nil {
log.Error("rows.Scan error(%v)", err)
return
}
// 2 state map to 1
if avrState == archive.VideoStatusDelete {
v.Status = archive.VideoStatusDelete
} else {
v.Status = vState
}
vs = append(vs, v)
}
return
}
// NewVideoCount get all video duration by aid.
func (d *Dao) NewVideoCount(c context.Context, aid int64) (count int, err error) {
row := d.db.QueryRow(c, _newVideoCntSQL, aid)
if err = row.Scan(&count); err != nil {
if err == sql.ErrNoRows {
err = nil
} else {
log.Error("row.Scan error(%v)", err)
}
}
return
}
// NewSumDuration get all video duration by aid.
func (d *Dao) NewSumDuration(c context.Context, aid int64) (sumDura int64, err error) {
var (
r = &sql.NullInt64{}
row = d.db.QueryRow(c, _newSumDuraSQL, aid)
)
if err = row.Scan(r); err != nil {
if err == sql.ErrNoRows {
err = nil
} else {
log.Error("row.Scan error(%v)", err)
}
return
}
sumDura = r.Int64
return
}
// NewVideoCountCapable get all video duration by aid.
func (d *Dao) NewVideoCountCapable(c context.Context, cid int64) (count int, err error) {
row := d.db.QueryRow(c, _newVdoBvcCntSQL, cid)
if err = row.Scan(&count); err != nil {
if err == sql.ErrNoRows {
err = nil
} else {
log.Error("row.Scan error(%v)", err)
}
}
return
}
// ValidAidByCid get all video duration by aid.
func (d *Dao) ValidAidByCid(c context.Context, cid int64) (aids []int64, err error) {
rows, err := d.db.Query(c, _validAidByCid, cid)
if err != nil {
log.Error("d.db.Query(%d) error(%v)", cid, err)
return
}
defer rows.Close()
for rows.Next() {
var aid int64
if err = rows.Scan(&aid); err != nil {
log.Error("rows.Scan error(%v)", err)
return
}
aids = append(aids, aid)
}
return
}

View File

@@ -0,0 +1,49 @@
package archive
import (
"context"
"go-common/app/job/main/videoup/model/archive"
"go-common/library/database/sql"
"go-common/library/log"
)
const (
_inArchiveOperSQL = "INSERT INTO archive_oper(aid,uid,typeid,state,round,attribute,last_id,content) VALUES(?,399,?,?,?,?,?,?)"
_arcPassedOperSQL = "SELECT id FROM archive_oper WHERE aid=? AND state>=? LIMIT 1"
)
// TxArchiveOper add archive oper log
func (d *Dao) TxArchiveOper(tx *sql.Tx, aid int64, typeID int16, state int8, round int8, attr int32, lastID int64, content string) (rows int64, err error) {
res, err := tx.Exec(_inArchiveOperSQL, aid, typeID, state, round, attr, lastID, content)
if err != nil {
log.Error("tx.Exec error(%v)", err)
return
}
rows, err = res.RowsAffected()
return
}
// ArchiveOper add archive oper log
func (d *Dao) ArchiveOper(c context.Context, aid int64, typeID int16, state int8, round int8, attr int32, lastID int64, content string) (rows int64, err error) {
res, err := d.db.Exec(c, _inArchiveOperSQL, aid, typeID, state, round, attr, lastID, content)
if err != nil {
log.Error("tx.Exec error(%v)", err)
return
}
rows, err = res.RowsAffected()
return
}
// PassedOper check archive passed
func (d *Dao) PassedOper(c context.Context, aid int64) (id int64, err error) {
row := d.db.QueryRow(c, _arcPassedOperSQL, aid, archive.StateOpen)
if err = row.Scan(&id); err != nil {
if err == sql.ErrNoRows {
err = nil
} else {
log.Error("row.Scan error(%v)", err)
}
}
return
}

View File

@@ -0,0 +1,30 @@
package archive
import (
"context"
"go-common/app/job/main/videoup/model/archive"
"go-common/library/log"
)
const (
_staffsSQL = "SELECT id,aid,mid,staff_mid,staff_title,staff_title_id,state FROM archive_staff WHERE aid=? AND state=?"
)
// Staffs get .
func (d *Dao) Staffs(c context.Context, AID int64) (fs []*archive.Staff, err error) {
rows, err := d.db.Query(c, _staffsSQL, AID, archive.STATESTAFFON)
if err != nil {
log.Error("d.db.Staffs(%d) error(%v)", AID, err)
return
}
defer rows.Close()
for rows.Next() {
f := &archive.Staff{}
if err = rows.Scan(&f.ID, &f.AID, &f.MID, &f.StaffMID, &f.StaffTitle, &f.StaffTitleID, &f.State); err != nil {
log.Error("rows.Scan error(%v)", err)
return
}
fs = append(fs, f)
}
return
}

View File

@@ -0,0 +1,32 @@
package archive
import (
"context"
"fmt"
"net/url"
"strconv"
"go-common/library/log"
)
// Stat get archive stat.
func (d *Dao) Stat(c context.Context, aid int64) (click int, err error) {
params := url.Values{}
params.Set("aid", strconv.FormatInt(aid, 10))
var res struct {
Code int `json:"code"`
Data struct {
Click int `json:"click"`
} `json:"data"`
}
if err = d.client.Get(c, d.statURI, "", params, &res); err != nil {
log.Error("archive stat url(%s) error(%v)", d.statURI, err)
return
}
if res.Code != 0 {
err = fmt.Errorf("archive stat call failed")
return
}
click = res.Data.Click
return
}

View File

@@ -0,0 +1,53 @@
package archive
import (
"context"
"go-common/app/job/main/videoup/model/archive"
"go-common/library/log"
)
const (
_tpsSQL = "SELECT id,pid,name FROM archive_type WHERE pid !=0"
_alltpsSQL = "SELECT id,pid,name FROM archive_type"
)
// TypeMapping is second types opposite first types.
func (d *Dao) TypeMapping(c context.Context) (rmap map[int16]int16, err error) {
rows, err := d.db.Query(c, _tpsSQL)
if err != nil {
log.Error("d.db.Query error(%v)", err)
return
}
defer rows.Close()
rmap = map[int16]int16{}
for rows.Next() {
var t = &archive.Type{}
if err = rows.Scan(&t.ID, &t.PID, &t.Name); err != nil {
log.Error("rows.Scan error(%v)", err)
return
}
rmap[t.ID] = t.PID
}
return
}
// TypeNaming is all type name
func (d *Dao) TypeNaming(c context.Context) (nmap map[int16]string, err error) {
rows, err := d.db.Query(c, _alltpsSQL)
if err != nil {
log.Error("d.db.Query error(%v)", err)
return
}
defer rows.Close()
nmap = map[int16]string{}
for rows.Next() {
var t = &archive.Type{}
if err = rows.Scan(&t.ID, &t.PID, &t.Name); err != nil {
log.Error("rows.Scan error(%v)", err)
return
}
nmap[t.ID] = t.Name
}
return
}

View File

@@ -0,0 +1,213 @@
package archive
import (
"context"
"database/sql"
"go-common/app/job/main/videoup/model/archive"
xsql "go-common/library/database/sql"
"go-common/library/log"
)
const (
// insert // NOTE: will delete???
// _inFilenameSQL = `INSERT INTO archive_video (filename,filesize,xcode_state) VALUES(?,?,?)
// ON DUPLICATE KEY UPDATE filesize=?,xcode_state=?`
// update
_upXStateSQL = "UPDATE archive_video SET xcode_state=? WHERE filename=?"
_upStatusSQL = "UPDATE archive_video SET status=? WHERE filename=?"
_upPlayurlSQL = "UPDATE archive_video SET playurl=? WHERE filename=?"
_upVDuraSQL = "UPDATE archive_video SET duration=? WHERE filename=?"
_upResolutionSQL = "UPDATE archive_video SET resolutions=? WHERE filename=?"
_upFilesizeSQL = "UPDATE archive_video SET filesize=? WHERE filename=?"
_upFailCodeSQL = "UPDATE archive_video SET failinfo=? WHERE filename=?"
// select
_videoSQL = `SELECT id,filename,cid,aid,eptitle,description,src_type,duration,filesize,resolutions,playurl,failinfo,
index_order,attribute,xcode_state,status,ctime,mtime FROM archive_video WHERE filename=?`
_videoByAidSQL = `SELECT id,filename,cid,aid,eptitle,description,src_type,duration,filesize,resolutions,playurl,failinfo,
index_order,attribute,xcode_state,status,ctime,mtime FROM archive_video WHERE filename=? AND aid=?`
_videosSQL = `SELECT id,filename,cid,aid,eptitle,description,src_type,duration,filesize,resolutions,playurl,failinfo,
index_order,attribute,xcode_state,status,ctime,mtime FROM archive_video WHERE aid=? ORDER BY index_order`
_videoCntSQL = `SELECT COUNT(*) FROM archive_video WHERE aid=? AND status!=-100`
_sumDuraSQL = `SELECT SUM(duration) FROM archive_video WHERE aid=? AND (status=0 || status=10000)`
_vdoBvcCntSQL = `SELECT COUNT(*) FROM archive_video WHERE cid=? AND (status=0 || status=10000) AND xcode_state=6`
_vdoAidBvcCntSQL = `SELECT COUNT(*) FROM archive_video av LEFT JOIN archive a ON av.aid=a.id WHERE
av.cid=? AND (av.status=0 || av.status=10000) AND av.xcode_state=6 AND (a.state>=0 || a.state=-6)`
)
// TxUpXcodeState update video state.
func (d *Dao) TxUpXcodeState(tx *xsql.Tx, filename string, xState int8) (rows int64, err error) {
res, err := tx.Exec(_upXStateSQL, xState, filename)
if err != nil {
log.Error("tx.Exec(%d, %s) error(%v)", xState, filename, err)
return
}
return res.RowsAffected()
}
// TxUpStatus update video status.
func (d *Dao) TxUpStatus(tx *xsql.Tx, filename string, status int16) (rows int64, err error) {
res, err := tx.Exec(_upStatusSQL, status, filename)
if err != nil {
log.Error("tx.Exec(%d, %s) error(%v)", status, filename, err)
return
}
return res.RowsAffected()
}
// TxUpPlayurl update video playurl and duration.
func (d *Dao) TxUpPlayurl(tx *xsql.Tx, filename, playurl string) (rows int64, err error) {
res, err := tx.Exec(_upPlayurlSQL, playurl, filename)
if err != nil {
log.Error("tx.Exec(%s, %s) error(%v)", playurl, filename, err)
return
}
return res.RowsAffected()
}
// TxUpVideoDuration update video playurl and duration.
func (d *Dao) TxUpVideoDuration(tx *xsql.Tx, filename string, duration int64) (rows int64, err error) {
res, err := tx.Exec(_upVDuraSQL, duration, filename)
if err != nil {
log.Error("tx.Exec(%d, %s) error(%v)", duration, filename, err)
return
}
return res.RowsAffected()
}
// TxUpFilesize update video filesize.
func (d *Dao) TxUpFilesize(tx *xsql.Tx, filename string, filesize int64) (rows int64, err error) {
res, err := tx.Exec(_upFilesizeSQL, filesize, filename)
if err != nil {
log.Error("tx.Exec(%d, %s) error(%v)", filesize, filename, err)
}
return res.RowsAffected()
}
// TxUpResolutions update video resolutions.
func (d *Dao) TxUpResolutions(tx *xsql.Tx, filename, resolutions string) (rows int64, err error) {
res, err := tx.Exec(_upResolutionSQL, resolutions, filename)
if err != nil {
log.Error("tx.Exec(%s, %s) error(%v)", resolutions, filename, err)
return
}
return res.RowsAffected()
}
// TxUpFailCode update video fail info.
func (d *Dao) TxUpFailCode(tx *xsql.Tx, filename string, fileCode int8) (rows int64, err error) {
res, err := tx.Exec(_upFailCodeSQL, fileCode, filename)
if err != nil {
log.Error("tx.Exec(%s, %d) error(%v)", filename, fileCode, err)
return
}
return res.RowsAffected()
}
// Video get video info by filename. NOTE Deprecated
func (d *Dao) Video(c context.Context, filename string) (v *archive.Video, err error) {
row := d.db.QueryRow(c, _videoSQL, filename)
v = &archive.Video{}
if err = row.Scan(&v.ID, &v.Filename, &v.Cid, &v.Aid, &v.Title, &v.Desc, &v.SrcType, &v.Duration, &v.Filesize, &v.Resolutions,
&v.Playurl, &v.FailCode, &v.Index, &v.Attribute, &v.XcodeState, &v.Status, &v.CTime, &v.MTime); err != nil {
if err == sql.ErrNoRows {
v = nil
err = nil
} else {
log.Error("row.Scan error(%v)", err)
}
}
return
}
// VideoByAid get video info by filename. and aid. NOTE Deprecated
func (d *Dao) VideoByAid(c context.Context, filename string, aid int64) (v *archive.Video, err error) {
row := d.db.QueryRow(c, _videoByAidSQL, filename, aid)
v = &archive.Video{}
if err = row.Scan(&v.ID, &v.Filename, &v.Cid, &v.Aid, &v.Title, &v.Desc, &v.SrcType, &v.Duration, &v.Filesize, &v.Resolutions,
&v.Playurl, &v.FailCode, &v.Index, &v.Attribute, &v.XcodeState, &v.Status, &v.CTime, &v.MTime); err != nil {
if err == sql.ErrNoRows {
v = nil
err = nil
} else {
log.Error("row.Scan error(%v)", err)
}
}
return
}
// Videos get videos info by aid. NOTE Deprecated
func (d *Dao) Videos(c context.Context, aid int64) (vs []*archive.Video, err error) {
rows, err := d.db.Query(c, _videosSQL, aid)
if err != nil {
log.Error("d.db.Query(%d) error(%v)", aid, err)
return
}
defer rows.Close()
for rows.Next() {
v := &archive.Video{}
if err = rows.Scan(&v.ID, &v.Filename, &v.Cid, &v.Aid, &v.Title, &v.Desc, &v.SrcType, &v.Duration, &v.Filesize, &v.Resolutions,
&v.Playurl, &v.FailCode, &v.Index, &v.Attribute, &v.XcodeState, &v.Status, &v.CTime, &v.MTime); err != nil {
log.Error("rows.Scan error(%v)", err)
return
}
vs = append(vs, v)
}
return
}
// VideoCount get all video duration by aid. NOTE Deprecated
func (d *Dao) VideoCount(c context.Context, aid int64) (count int, err error) {
row := d.db.QueryRow(c, _videoCntSQL, aid)
if err = row.Scan(&count); err != nil {
if err == sql.ErrNoRows {
err = nil
} else {
log.Error("row.Scan error(%v)", err)
}
}
return
}
// SumDuration get all video duration by aid. NOTE Deprecated
func (d *Dao) SumDuration(c context.Context, aid int64) (sumDura int64, err error) {
var (
r = &sql.NullInt64{}
row = d.db.QueryRow(c, _sumDuraSQL, aid)
)
if err = row.Scan(r); err != nil {
if err == sql.ErrNoRows {
err = nil
} else {
log.Error("row.Scan error(%v)", err)
}
}
sumDura = r.Int64
return
}
// VideoCountCapable get all video duration by aid. NOTE Deprecated
func (d *Dao) VideoCountCapable(c context.Context, cid int64) (count int, err error) {
row := d.db.QueryRow(c, _vdoBvcCntSQL, cid)
if err = row.Scan(&count); err != nil {
if err == sql.ErrNoRows {
err = nil
} else {
log.Error("row.Scan error(%v)", err)
}
}
return
}
// VdoWithArcCntCapable get all video duration by aid. NOTE Deprecated
func (d *Dao) VdoWithArcCntCapable(c context.Context, cid int64) (count int, err error) {
row := d.db.QueryRow(c, _vdoAidBvcCntSQL, cid)
if err = row.Scan(&count); err != nil {
if err == sql.ErrNoRows {
err = nil
} else {
log.Error("row.Scan error(%v)", err)
}
}
return
}

View File

@@ -0,0 +1,39 @@
package archive
import (
"context"
"database/sql"
xsql "go-common/library/database/sql"
"go-common/library/log"
)
const (
// insert
_inAuditSQL = `INSERT IGNORE INTO archive_video_audit (vid,aid,tid,oname,reason) VALUES(?,?,0,'videoup-job',?)
ON DUPLICATE KEY UPDATE oname='videoup-job',reason=?`
_seRsnSQL = "SELECT reason FROM archive_video_audit WHERE vid=?"
)
// TxAddAudit add video audit by vid.
func (d *Dao) TxAddAudit(tx *xsql.Tx, vid, aid int64, reason string) (rows int64, err error) {
row, err := tx.Exec(_inAuditSQL, vid, aid, reason, reason)
if err != nil {
log.Error("tx.Exec(%d, %d, %s) error(%v)", vid, aid, reason, err)
return
}
return row.RowsAffected()
}
// Reason get a archive video reject reason by vid.
func (d *Dao) Reason(c context.Context, vid int64) (reason string, err error) {
row := d.db.QueryRow(c, _seRsnSQL, vid)
if err = row.Scan(&reason); err != nil {
if err == sql.ErrNoRows {
err = nil
} else {
log.Error("row.Scan error(%v)", err)
}
}
return
}

View File

@@ -0,0 +1,33 @@
package archive
import (
"context"
"go-common/library/ecode"
"go-common/library/log"
"net/url"
)
// AICover get covers from ai
func (d *Dao) AICover(c context.Context, filename string) (covers []string, err error) {
params := url.Values{}
params.Set("filename", filename)
params.Set("from", "videoup-job")
var res struct {
Code int `json:"code"`
Data []string `json:"data"`
}
if err = d.client.Get(c, d.recommendURI, "", params, &res); err != nil {
log.Error("AICover error(%v), url(%s)", err, d.recommendURI+"?"+params.Encode())
return
}
if res.Code != 0 {
err = ecode.CreativeDataErr
log.Error("AICover code not 0, url(%s) res(%v)", d.recommendURI+"?"+params.Encode(), err)
return
}
covers = res.Data
return
}

View File

@@ -0,0 +1,23 @@
package archive
import (
"context"
"go-common/library/database/sql"
"go-common/library/log"
)
const (
_inVideoOperSQL = "INSERT INTO archive_video_oper(aid,uid,vid,status,attribute,last_id) VALUES(?,399,?,?,?,1)"
)
//TranVideoOper insert a record
func (d *Dao) TranVideoOper(c context.Context, tx *sql.Tx, aid, vid int64, status int16, attr int32) (rows int64, err error) {
res, err := tx.Exec(_inVideoOperSQL, aid, vid, status, attr)
if err != nil {
log.Error("tx.Exec(%s, %d, %d, %d, %d) error(%v)", _inVideoOperSQL, aid, vid, status, attr, err)
return
}
rows, err = res.RowsAffected()
return
}

View File

@@ -0,0 +1,23 @@
package archive
import (
"context"
"time"
"go-common/library/log"
)
const (
_inVideoShotSQL = "INSERT INTO archive_video_shot (id,count,ctime,mtime) VALUES (?,?,?,?) ON DUPLICATE KEY UPDATE count=?,mtime=? "
)
// AddVideoShot add a videoshot into mysql.
func (d *Dao) AddVideoShot(c context.Context, cid int64, count int) (rows int64, err error) {
var now = time.Now()
res, err := d.db.Exec(c, _inVideoShotSQL, cid, count, now, now, count, now)
if err != nil {
log.Error("d.db.Exec error(%v)", err)
return
}
return res.RowsAffected()
}

View File

@@ -0,0 +1,153 @@
package archive
import (
"context"
"go-common/app/job/main/videoup/model/archive"
_ "github.com/go-sql-driver/mysql"
. "github.com/smartystreets/goconvey/convey"
"testing"
)
func Test_NewVideo(t *testing.T) {
var (
c = context.TODO()
err error
sub *archive.Video
)
Convey("NewVideo", t, WithDao(func(d *Dao) {
sub, err = d.NewVideo(c, "2333")
So(err, ShouldBeNil)
So(sub, ShouldBeNil)
}))
}
func Test_NewSumDuration(t *testing.T) {
var (
c = context.TODO()
err error
sub int64
)
Convey("NewVideo", t, WithDao(func(d *Dao) {
sub, err = d.NewSumDuration(c, 2333)
So(err, ShouldBeNil)
So(sub, ShouldBeZeroValue)
}))
}
func Test_NewVideoByAid(t *testing.T) {
var (
c = context.TODO()
err error
sub *archive.Video
)
Convey("NewVideoByAid", t, WithDao(func(d *Dao) {
sub, err = d.NewVideoByAid(c, "filename", 2333)
So(err, ShouldBeNil)
So(sub, ShouldBeNil)
}))
}
func Test_NewVideoCount(t *testing.T) {
var (
c = context.TODO()
err error
sub int
)
Convey("NewVideoCount", t, WithDao(func(d *Dao) {
sub, err = d.NewVideoCount(c, 2333)
So(err, ShouldBeNil)
So(sub, ShouldBeZeroValue)
}))
}
func Test_NewVideoCountCapable(t *testing.T) {
var (
c = context.TODO()
err error
sub int
)
Convey("NewVideoCountCapable", t, WithDao(func(d *Dao) {
sub, err = d.NewVideoCountCapable(c, 2333)
So(err, ShouldBeNil)
So(sub, ShouldBeZeroValue)
}))
}
// old TODO deprecated
func Test_Video(t *testing.T) {
var (
c = context.TODO()
err error
sub *archive.Video
)
Convey("Video", t, WithDao(func(d *Dao) {
sub, err = d.NewVideo(c, "2333")
So(err, ShouldBeNil)
So(sub, ShouldBeNil)
}))
}
func Test_SumDuration(t *testing.T) {
var (
c = context.TODO()
err error
sub int64
)
Convey("Video", t, WithDao(func(d *Dao) {
sub, err = d.SumDuration(c, 2333)
So(err, ShouldBeNil)
So(sub, ShouldBeZeroValue)
}))
}
func Test_VideoByAid(t *testing.T) {
var (
c = context.TODO()
err error
sub *archive.Video
)
Convey("VideoByAid", t, WithDao(func(d *Dao) {
sub, err = d.VideoByAid(c, "filename", 2333)
So(err, ShouldBeNil)
So(sub, ShouldBeNil)
}))
}
func Test_VideoCount(t *testing.T) {
var (
c = context.TODO()
err error
)
Convey("VideoCount", t, WithDao(func(d *Dao) {
_, err = d.VideoCount(c, 2333)
So(err, ShouldBeNil)
}))
}
func Test_VideoCountCapable(t *testing.T) {
var (
c = context.TODO()
err error
sub int
)
Convey("VideoCountCapable", t, WithDao(func(d *Dao) {
sub, err = d.VideoCountCapable(c, 2333)
So(err, ShouldBeNil)
So(sub, ShouldBeZeroValue)
}))
}
func Test_Reason(t *testing.T) {
var (
c = context.TODO()
err error
sub string
)
Convey("Reason", t, WithDao(func(d *Dao) {
sub, err = d.Reason(c, 2333)
So(err, ShouldBeNil)
So(sub, ShouldBeEmpty)
}))
}