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,76 @@
package(default_visibility = ["//visibility:public"])
load(
"@io_bazel_rules_go//go:def.bzl",
"go_library",
"go_test",
)
go_library(
name = "go_default_library",
srcs = [
"cache.go",
"dao.cache.go",
"dao.go",
"mysql.go",
"pointdata.go",
"redis.go",
"search.go",
],
importpath = "go-common/app/interface/main/esports/dao",
tags = ["automanaged"],
visibility = ["//visibility:public"],
deps = [
"//app/interface/main/esports/conf:go_default_library",
"//app/interface/main/esports/model:go_default_library",
"//app/service/main/archive/api:go_default_library",
"//app/service/main/archive/model/archive:go_default_library",
"//library/cache/redis:go_default_library",
"//library/database/elastic: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/net/metadata:go_default_library",
"//library/stat/prom:go_default_library",
"//library/sync/pipeline/fanout:go_default_library",
"//library/xstr:go_default_library",
"//vendor/github.com/pkg/errors: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"],
)
go_test(
name = "go_default_test",
srcs = [
"cache_test.go",
"dao.cache_test.go",
"dao_test.go",
"mysql_test.go",
"pointdata_test.go",
"redis_test.go",
"search_test.go",
],
embed = [":go_default_library"],
rundir = ".",
tags = ["automanaged"],
deps = [
"//app/interface/main/esports/conf:go_default_library",
"//app/interface/main/esports/model:go_default_library",
"//app/service/main/archive/api:go_default_library",
"//vendor/github.com/smartystreets/goconvey/convey:go_default_library",
],
)

View File

@@ -0,0 +1,19 @@
package dao
import (
"context"
"go-common/app/interface/main/esports/model"
)
//go:generate $GOPATH/src/go-common/app/tool/cache/gen
type _cache interface {
// cache
EpContests(c context.Context, ids []int64) (map[int64]*model.Contest, error)
// cache
EpSeasons(c context.Context, ids []int64) (map[int64]*model.Season, error)
// cache
EpTeams(c context.Context, ids []int64) (map[int64]*model.Team, error)
// cache
EpContestsData(c context.Context, ids []int64) (map[int64][]*model.ContestsData, error)
}

View File

@@ -0,0 +1 @@
package dao

View File

@@ -0,0 +1,156 @@
// Code generated by $GOPATH/src/go-common/app/tool/cache/gen. DO NOT EDIT.
/*
Package dao is a generated cache proxy package.
It is generated from:
type _cache interface {
// cache
EpContests(c context.Context, ids []int64) (map[int64]*model.Contest, error)
// cache
EpSeasons(c context.Context, ids []int64) (map[int64]*model.Season, error)
// cache
EpTeams(c context.Context, ids []int64) (map[int64]*model.Team, error)
// cache
EpContestsData(c context.Context, ids []int64) (map[int64][]*model.ContestsData, error)
}
*/
package dao
import (
"context"
"go-common/app/interface/main/esports/model"
"go-common/library/stat/prom"
)
var _ _cache
// EpContests get data from cache if miss will call source method, then add to cache.
func (d *Dao) EpContests(c context.Context, keys []int64) (res map[int64]*model.Contest, err error) {
if len(keys) == 0 {
return
}
addCache := true
if res, err = d.CacheEpContests(c, keys); err != nil {
addCache = false
res = nil
err = nil
}
var miss []int64
for _, key := range keys {
if (res == nil) || (res[key] == nil) {
miss = append(miss, key)
}
}
prom.CacheHit.Add("EpContests", int64(len(keys)-len(miss)))
missLen := len(miss)
if missLen == 0 {
return
}
var missData map[int64]*model.Contest
prom.CacheMiss.Add("EpContests", int64(len(miss)))
missData, err = d.RawEpContests(c, miss)
if res == nil {
res = make(map[int64]*model.Contest, len(keys))
}
for k, v := range missData {
res[k] = v
}
if err != nil {
return
}
if !addCache {
return
}
d.cache.Do(c, func(c context.Context) {
d.AddCacheEpContests(c, missData)
})
return
}
// EpSeasons get data from cache if miss will call source method, then add to cache.
func (d *Dao) EpSeasons(c context.Context, keys []int64) (res map[int64]*model.Season, err error) {
if len(keys) == 0 {
return
}
addCache := true
if res, err = d.CacheEpSeasons(c, keys); err != nil {
addCache = false
res = nil
err = nil
}
var miss []int64
for _, key := range keys {
if (res == nil) || (res[key] == nil) {
miss = append(miss, key)
}
}
prom.CacheHit.Add("EpSeasons", int64(len(keys)-len(miss)))
missLen := len(miss)
if missLen == 0 {
return
}
var missData map[int64]*model.Season
prom.CacheMiss.Add("EpSeasons", int64(len(miss)))
missData, err = d.RawEpSeasons(c, miss)
if res == nil {
res = make(map[int64]*model.Season, len(keys))
}
for k, v := range missData {
res[k] = v
}
if err != nil {
return
}
if !addCache {
return
}
d.cache.Do(c, func(c context.Context) {
d.AddCacheEpSeasons(c, missData)
})
return
}
// EpTeams get data from cache if miss will call source method, then add to cache.
func (d *Dao) EpTeams(c context.Context, keys []int64) (res map[int64]*model.Team, err error) {
if len(keys) == 0 {
return
}
addCache := true
if res, err = d.CacheEpTeams(c, keys); err != nil {
addCache = false
res = nil
err = nil
}
var miss []int64
for _, key := range keys {
if (res == nil) || (res[key] == nil) {
miss = append(miss, key)
}
}
prom.CacheHit.Add("EpTeams", int64(len(keys)-len(miss)))
missLen := len(miss)
if missLen == 0 {
return
}
var missData map[int64]*model.Team
prom.CacheMiss.Add("EpTeams", int64(len(miss)))
missData, err = d.RawEpTeams(c, miss)
if res == nil {
res = make(map[int64]*model.Team, len(keys))
}
for k, v := range missData {
res[k] = v
}
if err != nil {
return
}
if !addCache {
return
}
d.cache.Do(c, func(c context.Context) {
d.AddCacheEpTeams(c, missData)
})
return
}

View File

@@ -0,0 +1,51 @@
package dao
import (
"context"
"testing"
"github.com/smartystreets/goconvey/convey"
)
func TestDaoEpContests(t *testing.T) {
var (
c = context.Background()
keys = []int64{1, 2, 3}
)
convey.Convey("EpContests", t, func(ctx convey.C) {
res, err := d.EpContests(c, keys)
ctx.Convey("Then err should be nil.res should not be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
ctx.So(res, convey.ShouldNotBeNil)
})
})
}
func TestDaoEpSeasons(t *testing.T) {
var (
c = context.Background()
keys = []int64{1, 2, 3}
)
convey.Convey("EpSeasons", t, func(ctx convey.C) {
res, err := d.EpSeasons(c, keys)
ctx.Convey("Then err should be nil.res should not be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
ctx.So(res, convey.ShouldNotBeNil)
})
})
}
func TestDaoEpTeams(t *testing.T) {
convey.Convey("EpTeams", t, func(convCtx convey.C) {
var (
c = context.Background()
keys = []int64{1, 2, 3}
)
convCtx.Convey("When everything goes positive", func(convCtx convey.C) {
res, err := d.EpTeams(c, keys)
convCtx.Convey("Then err should be nil.res should not be nil.", func(convCtx convey.C) {
convCtx.So(err, convey.ShouldBeNil)
convCtx.So(res, convey.ShouldNotBeNil)
})
})
})
}

View File

@@ -0,0 +1,61 @@
package dao
import (
"context"
"net/http"
"time"
"go-common/app/interface/main/esports/conf"
"go-common/library/cache/redis"
"go-common/library/database/elastic"
"go-common/library/database/sql"
bm "go-common/library/net/http/blademaster"
"go-common/library/sync/pipeline/fanout"
)
const (
_searchURL = "/esports/search"
)
// Dao dao struct.
type Dao struct {
// config
c *conf.Config
// db
db *sql.DB
// redis
redis *redis.Pool
filterExpire, listExpire int32
// http client
http *bm.Client
ldClient *http.Client
searchURL string
ela *elastic.Elastic
cache *fanout.Fanout
}
// New new dao.
func New(c *conf.Config) (d *Dao) {
d = &Dao{
// config
c: c,
db: sql.NewMySQL(c.Mysql),
redis: redis.NewPool(c.Redis.Config),
filterExpire: int32(time.Duration(c.Redis.FilterExpire) / time.Second),
listExpire: int32(time.Duration(c.Redis.ListExpire) / time.Second),
http: bm.NewClient(c.HTTPClient),
ldClient: http.DefaultClient,
searchURL: c.Host.Search + _searchURL,
ela: elastic.NewElastic(nil),
cache: fanout.New("fanout"),
}
return
}
// Ping ping dao
func (d *Dao) Ping(c context.Context) (err error) {
if err = d.db.Ping(c); err != nil {
return
}
return
}

View File

@@ -0,0 +1,36 @@
package dao
import (
"flag"
"os"
"testing"
"go-common/app/interface/main/esports/conf"
)
var (
d *Dao
)
func TestMain(m *testing.M) {
if os.Getenv("DEPLOY_ENV") != "" {
flag.Set("app_id", "main.web-svr.esports")
flag.Set("conf_token", "a144f51d7157d638749686d63b13c693")
flag.Set("tree_id", "38395")
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/esports-test.toml")
}
flag.Parse()
if err := conf.Init(); err != nil {
panic(err)
}
d = New(conf.Conf)
m.Run()
os.Exit(0)
}

View File

@@ -0,0 +1,628 @@
package dao
import (
"context"
"database/sql"
"fmt"
"strconv"
"strings"
"go-common/app/interface/main/esports/model"
xsql "go-common/library/database/sql"
"go-common/library/log"
"go-common/library/xstr"
)
const (
_matchsSQL = "SELECT id,title,sub_title,logo,rank FROM es_matchs WHERE status=0 order by rank DESC , ID ASC"
_gamesSQL = "SELECT id,title,sub_title,logo FROM es_games WHERE status=0 order by id ASC"
_teamsSQL = "SELECT id,title,sub_title,logo FROM es_teams WHERE is_deleted=0 order by id ASC"
_tagsSQL = "SELECT id,name FROM es_tags WHERE status=0 order by id ASC"
_yearsSQL = "SELECT distinct year as id, year FROM es_year_map WHERE is_deleted=0 order by id ASC"
_dayContestSQL = "SELECT FROM_UNIXTIME(stime, '%Y-%m-%d') as s,count(1) as c FROM `es_contests` WHERE status=0 AND stime >= ? and stime <= ? GROUP BY s ORDER BY stime"
_seasonSQL = "SELECT id,mid,title,sub_title,stime,etime,sponsor,logo,dic,ctime,mtime,status,rank,is_app,url,data_focus,focus_url FROM es_seasons WHERE status = 0 ORDER BY stime DESC"
_epSeasonSQL = "SELECT id,mid,title,sub_title,stime,etime,sponsor,logo,dic,ctime,mtime,status,rank,is_app,url,data_focus,focus_url FROM es_seasons WHERE status = 0 and id in (%s) ORDER BY stime DESC"
_seasonMSQL = "SELECT id,mid,title,sub_title,stime,etime,sponsor,logo,dic,ctime,mtime,status,rank,is_app,url,data_focus,focus_url FROM es_seasons WHERE status = 0 AND is_app = 1 ORDER BY rank DESC,stime DESC"
_seasonsSQL = "SELECT id,title,sub_title,logo,url,data_focus,focus_url FROM es_seasons WHERE status = 0 ORDER BY stime DESC"
_contestSQL = "SELECT id,game_stage,stime,etime,home_id,away_id,home_score,away_score,live_room,aid,collection,game_state,dic,ctime,mtime,status,sid,mid,special,special_name,special_tips,success_team,special_image,playback,collection_url,live_url,data_type,match_id FROM `es_contests` WHERE id= ?"
_contestsSQL = "SELECT id,game_stage,stime,etime,home_id,away_id,home_score,away_score,live_room,aid,collection,game_state,dic,ctime,mtime,status,sid,mid,special,special_name,special_tips,success_team,special_image,playback,collection_url,live_url,data_type,match_id FROM `es_contests` WHERE id in (%s) ORDER BY ID ASC"
_contestLeidaSQL = "SELECT id,game_stage,stime,etime,home_id,away_id,home_score,away_score,live_room,aid,collection,game_state,dic,ctime,mtime,status,sid,mid,special,special_name,special_tips,success_team,special_image,playback,collection_url,live_url,data_type,match_id FROM `es_contests` WHERE match_id > 0 and status = 0"
_moduleSQL = "SELECT id,ma_id,name,oids FROM `es_matchs_module` WHERE id = ? AND status = 0"
_activeSQL = "SELECT id,mid,sid,background,live_id,intr,focus,url,back_color,color_step,h5_background,h5_back_color,intr_logo,intr_title,intr_text,h5_focus,h5_url FROM es_matchs_active WHERE id = ? AND `status`= 0"
_modulesSQL = "SELECT id,ma_id,name,oids FROM `es_matchs_module` WHERE ma_id = ? AND status = 0 ORDER BY ID ASC"
_pDetailSQL = "SELECT ma_id,game_type,stime,etime FROM es_matchs_detail WHERE id = ? AND `status` = 0"
_actDetail = "SELECT id,ma_id,game_type,stime,etime,score_id,game_stage,knockout_type,winner_type,online FROM es_matchs_detail WHERE ma_id = ? AND status = 0"
_treeSQL = "SELECT id,ma_id,mad_id,pid,root_id,game_rank,mid FROM es_matchs_tree WHERE mad_id = ? AND is_deleted=0 ORDER BY root_id ASC,pid ASC,game_rank ASC"
_teamsInSQL = "SELECT id,title,sub_title,logo FROM es_teams WHERE is_deleted=0 AND id in (%s)"
_kDetailsSQL = "SELECT id,ma_id,game_type,stime,etime,online FROM es_matchs_detail WHERE `status` = 0 AND game_type = 2"
_contestDataSQL = "SELECT id,cid,url,point_data FROM `es_contests_data` WHERE cid = ? AND is_deleted = 0"
_contestRecent = "SELECT id,game_stage,stime,etime,home_id,away_id,home_score,away_score,live_room,aid,collection,game_state,dic,ctime,mtime,status,sid,mid,special,special_name,special_tips,success_team,special_image,playback,collection_url,live_url,data_type FROM es_contests WHERE ( `status` = 0 AND home_id = ? AND away_id = ? ) OR ( `status` = 0 AND home_id = ? AND away_id = ? ) ORDER BY stime DESC LIMIT ?"
)
// logoURL convert logo url to full url.
func logoURL(uri string) (logo string) {
if uri == "" {
return
}
logo = uri
if strings.Index(uri, "http://") == 0 || strings.Index(uri, "//") == 0 {
return
}
if len(uri) >= 10 && uri[:10] == "/templets/" {
return
}
if strings.HasPrefix(uri, "group1") {
logo = "//i0.hdslb.com/" + uri
return
}
if pos := strings.Index(uri, "/uploads/"); pos != -1 && (pos == 0 || pos == 3) {
logo = uri[pos+8:]
}
logo = strings.Replace(logo, "{IMG}", "", -1)
logo = "//i0.hdslb.com" + logo
return
}
// Matchs filter matchs.
func (d *Dao) Matchs(c context.Context) (res []*model.Filter, err error) {
var (
rows *xsql.Rows
)
if rows, err = d.db.Query(c, _matchsSQL); err != nil {
log.Error("Match:d.db.Query error(%v)", err)
return
}
defer rows.Close()
for rows.Next() {
r := new(model.Filter)
if err = rows.Scan(&r.ID, &r.Title, &r.SubTitle, &r.Logo, &r.Rank); err != nil {
log.Error("Match:row.Scan() error(%v)", err)
return
}
r.Logo = logoURL(r.Logo)
res = append(res, r)
}
if err = rows.Err(); err != nil {
log.Error("rows.Err() error(%v)", err)
}
return
}
// Games filter games.
func (d *Dao) Games(c context.Context) (res []*model.Filter, err error) {
var (
rows *xsql.Rows
)
if rows, err = d.db.Query(c, _gamesSQL); err != nil {
log.Error("Games:d.db.Query error(%v)", err)
return
}
defer rows.Close()
for rows.Next() {
r := new(model.Filter)
if err = rows.Scan(&r.ID, &r.Title, &r.SubTitle, &r.Logo); err != nil {
log.Error("Games:row.Scan() error(%v)", err)
return
}
r.Logo = logoURL(r.Logo)
res = append(res, r)
}
if err = rows.Err(); err != nil {
log.Error("rows.Err() error(%v)", err)
}
return
}
// Teams filter teams.
func (d *Dao) Teams(c context.Context) (res []*model.Filter, err error) {
var (
rows *xsql.Rows
)
if rows, err = d.db.Query(c, _teamsSQL); err != nil {
log.Error("Teams:d.db.Query error(%v)", err)
return
}
defer rows.Close()
for rows.Next() {
r := new(model.Filter)
if err = rows.Scan(&r.ID, &r.Title, &r.SubTitle, &r.Logo); err != nil {
log.Error("Teams:row.Scan() error(%v)", err)
return
}
r.Logo = logoURL(r.Logo)
res = append(res, r)
}
if err = rows.Err(); err != nil {
log.Error("rows.Err() error(%v)", err)
}
return
}
// Tags filter Tags.
func (d *Dao) Tags(c context.Context) (res []*model.Filter, err error) {
var (
rows *xsql.Rows
)
if rows, err = d.db.Query(c, _tagsSQL); err != nil {
log.Error("Tags:d.db.Query error(%v)", err)
return
}
defer rows.Close()
for rows.Next() {
r := new(model.Filter)
if err = rows.Scan(&r.ID, &r.Title); err != nil {
log.Error("Tags:row.Scan() error(%v)", err)
return
}
r.Logo = logoURL(r.Logo)
res = append(res, r)
}
if err = rows.Err(); err != nil {
log.Error("rows.Err() error(%v)", err)
}
return
}
// Years filter years.
func (d *Dao) Years(c context.Context) (res []*model.Filter, err error) {
var (
rows *xsql.Rows
)
if rows, err = d.db.Query(c, _yearsSQL); err != nil {
log.Error("Years:d.db.Query error(%v)", err)
return
}
defer rows.Close()
for rows.Next() {
r := new(model.Year)
if err = rows.Scan(&r.ID, &r.Year); err != nil {
log.Error("Years:row.Scan() error(%v)", err)
return
}
res = append(res, &model.Filter{ID: r.ID, Title: strconv.FormatInt(r.Year, 10)})
}
if err = rows.Err(); err != nil {
log.Error("rows.Err() error(%v)", err)
}
return
}
// Calendar calendar count.
func (d *Dao) Calendar(c context.Context, stime, etime int64) (res []*model.Calendar, err error) {
var (
rows *xsql.Rows
)
if rows, err = d.db.Query(c, _dayContestSQL, stime, etime); err != nil {
log.Error("Calendar:d.db.Query(%d,%d) error(%v)", stime, etime, err)
return
}
defer rows.Close()
for rows.Next() {
r := new(model.Calendar)
if err = rows.Scan(&r.Stime, &r.Count); err != nil {
log.Error("Calendar:row.Scan() error(%v)", err)
return
}
res = append(res, r)
}
return
}
// Season season list.
func (d *Dao) Season(c context.Context) (res []*model.Season, err error) {
var (
rows *xsql.Rows
)
if rows, err = d.db.Query(c, _seasonSQL); err != nil {
log.Error("Contest:d.db.Query error(%v)", err)
return
}
defer rows.Close()
for rows.Next() {
r := new(model.Season)
if err = rows.Scan(&r.ID, &r.Mid, &r.Title, &r.SubTitle, &r.Stime, &r.Etime, &r.Sponsor, &r.Logo, &r.Dic, &r.Ctime,
&r.Mtime, &r.Status, &r.Rank, &r.IsApp, &r.URL, &r.DataFocus, &r.FocusURL); err != nil {
log.Error("Contest:row.Scan() error(%v)", err)
return
}
r.Logo = logoURL(r.Logo)
res = append(res, r)
}
if err = rows.Err(); err != nil {
log.Error("rows.Err() error(%v)", err)
}
return
}
// Module active module
func (d *Dao) Module(c context.Context, mmid int64) (mod *model.Module, err error) {
mod = &model.Module{}
row := d.db.QueryRow(c, _moduleSQL, mmid)
if err = row.Scan(&mod.ID, &mod.MAid, &mod.Name, &mod.Oids); err != nil {
if err == sql.ErrNoRows {
mod = nil
err = nil
} else {
log.Error("Esport dao Module:row.Scan error(%v)", err)
}
}
return
}
// Modules active module
func (d *Dao) Modules(c context.Context, aid int64) (mods []*model.Module, err error) {
var (
rows *xsql.Rows
)
if rows, err = d.db.Query(c, _modulesSQL, aid); err != nil {
log.Error("Esport dao Modules:d.db.Query error(%v)", err)
return
}
defer rows.Close()
for rows.Next() {
r := new(model.Module)
if err = rows.Scan(&r.ID, &r.MAid, &r.Name, &r.Oids); err != nil {
log.Error("Esport dao Modules:row.Scan() error(%v)", err)
return
}
mods = append(mods, r)
}
if err = rows.Err(); err != nil {
log.Error("Esport dao Modules.Err() error(%v)", err)
}
return
}
// Trees match tree
func (d *Dao) Trees(c context.Context, madID int64) (mods []*model.Tree, err error) {
var (
rows *xsql.Rows
)
if rows, err = d.db.Query(c, _treeSQL, madID); err != nil {
log.Error("Esport dao Trees:d.db.Query error(%v)", err)
return
}
defer rows.Close()
for rows.Next() {
r := new(model.Tree)
if err = rows.Scan(&r.ID, &r.MaID, &r.MadID, &r.Pid, &r.RootID, &r.GameRank, &r.Mid); err != nil {
log.Error("Esport dao Trees:row.Scan() error(%v)", err)
return
}
mods = append(mods, r)
}
if err = rows.Err(); err != nil {
log.Error("Esport dao Trees.Err() error(%v)", err)
}
return
}
// Active matchs active
func (d *Dao) Active(c context.Context, aid int64) (mod *model.Active, err error) {
mod = &model.Active{}
row := d.db.QueryRow(c, _activeSQL, aid)
if err = row.Scan(&mod.ID, &mod.Mid, &mod.Sid, &mod.Background, &mod.Liveid, &mod.Intr, &mod.Focus, &mod.URL, &mod.BackColor, &mod.ColorStep, &mod.H5Background, &mod.H5BackColor, &mod.IntrLogo, &mod.IntrTitle, &mod.IntrText, &mod.H5Focus, &mod.H5Url); err != nil {
if err == sql.ErrNoRows {
mod = nil
err = nil
} else {
log.Error("Esport dao Active:row.Scan error(%v)", err)
}
}
return
}
// PActDetail poin match detail
func (d *Dao) PActDetail(c context.Context, id int64) (mod *model.ActiveDetail, err error) {
mod = &model.ActiveDetail{}
row := d.db.QueryRow(c, _pDetailSQL, id)
if err = row.Scan(&mod.Maid, &mod.GameType, &mod.STime, &mod.ETime); err != nil {
if err == sql.ErrNoRows {
mod = nil
err = nil
} else {
log.Error("Esport dao Contest:row.Scan error(%v)", err)
}
}
return
}
// ActDetail data module
func (d *Dao) ActDetail(c context.Context, aid int64) (actDetail []*model.ActiveDetail, err error) {
var (
rows *xsql.Rows
)
if rows, err = d.db.Query(c, _actDetail, aid); err != nil {
log.Error("Esport dao Modules:d.db.Query error(%v)", err)
return
}
defer rows.Close()
for rows.Next() {
r := new(model.ActiveDetail)
if err = rows.Scan(&r.ID, &r.Maid, &r.GameType, &r.STime, &r.ETime, &r.ScoreID, &r.GameStage, &r.KnockoutType, &r.WinnerType, &r.Online); err != nil {
log.Error("Esport dao ActDetail:row.Scan() error(%v)", err)
return
}
actDetail = append(actDetail, r)
}
if err = rows.Err(); err != nil {
log.Error("Esport dao ActDetail.Err() error(%v)", err)
}
return
}
// AppSeason season match list.
func (d *Dao) AppSeason(c context.Context) (res []*model.Season, err error) {
var (
rows *xsql.Rows
)
if rows, err = d.db.Query(c, _seasonMSQL); err != nil {
log.Error("Contest:d.db.Query error(%v)", err)
return
}
defer rows.Close()
for rows.Next() {
r := new(model.Season)
if err = rows.Scan(&r.ID, &r.Mid, &r.Title, &r.SubTitle, &r.Stime, &r.Etime, &r.Sponsor, &r.Logo,
&r.Dic, &r.Ctime, &r.Mtime, &r.Status, &r.Rank, &r.IsApp, &r.URL, &r.DataFocus, &r.FocusURL); err != nil {
log.Error("Contest:row.Scan() error(%v)", err)
return
}
r.Logo = logoURL(r.Logo)
res = append(res, r)
}
if err = rows.Err(); err != nil {
log.Error("rows.Err() error(%v)", err)
}
return
}
// SeasonAll all season list.
func (d *Dao) SeasonAll(c context.Context) (res []*model.Filter, err error) {
var (
rows *xsql.Rows
)
if rows, err = d.db.Query(c, _seasonsSQL); err != nil {
log.Error("SeasonAll:d.db.Query error(%v)", err)
return
}
defer rows.Close()
for rows.Next() {
r := new(model.Filter)
if err = rows.Scan(&r.ID, &r.Title, &r.SubTitle, &r.Logo, &r.URL, &r.DataFocus, &r.FocusURL); err != nil {
log.Error("SeasonAll:row.Scan() error(%v)", err)
return
}
r.Logo = logoURL(r.Logo)
res = append(res, r)
}
if err = rows.Err(); err != nil {
log.Error("rows.Err() error(%v)", err)
}
return
}
// Contest get contest by id.
func (d *Dao) Contest(c context.Context, cid int64) (res *model.Contest, err error) {
res = &model.Contest{}
row := d.db.QueryRow(c, _contestSQL, cid)
if err = row.Scan(&res.ID, &res.GameStage, &res.Stime, &res.Etime, &res.HomeID, &res.AwayID, &res.HomeScore, &res.AwayScore,
&res.LiveRoom, &res.Aid, &res.Collection, &res.GameState, &res.Dic, &res.Ctime, &res.Mtime, &res.Status, &res.Sid, &res.Mid,
&res.Special, &res.SpecialName, &res.SpecialTips, &res.SuccessTeam, &res.SpecialImage, &res.Playback, &res.CollectionURL,
&res.LiveURL, &res.DataType, &res.MatchID); err != nil {
if err == sql.ErrNoRows {
err = nil
} else {
log.Error("Contest:row.Scan error(%v)", err)
}
}
return
}
// ContestRecent get recent contest
func (d *Dao) ContestRecent(c context.Context, homeid, awayid, contestid, ps int64) (res []*model.Contest, err error) {
var (
rows *xsql.Rows
)
if rows, err = d.db.Query(c, _contestRecent, homeid, awayid, awayid, homeid, ps+1); err != nil {
log.Error("ContestRecent: db.Exec(%s) error(%v)", _contestRecent, err)
return
}
defer rows.Close()
res = make([]*model.Contest, 0)
for rows.Next() {
r := new(model.Contest)
if err = rows.Scan(&r.ID, &r.GameStage, &r.Stime, &r.Etime, &r.HomeID, &r.AwayID, &r.HomeScore, &r.AwayScore,
&r.LiveRoom, &r.Aid, &r.Collection, &r.GameState, &r.Dic, &r.Ctime, &r.Mtime, &r.Status, &r.Sid, &r.Mid,
&r.Special, &r.SpecialName, &r.SpecialTips, &r.SuccessTeam, &r.SpecialImage, &r.Playback, &r.CollectionURL, &r.LiveURL, &r.DataType); err != nil {
log.Error("Contests:row.Scan() error(%v)", err)
return
}
if r.ID != contestid && len(res) != int(ps) {
res = append(res, r)
}
}
if err = rows.Err(); err != nil {
log.Error("rows.Err() error(%v)", err)
}
return
}
// ContestData get contest by id.
func (d *Dao) ContestData(c context.Context, cid int64) (res []*model.ContestsData, err error) {
var (
rows *xsql.Rows
)
if rows, err = d.db.Query(c, _contestDataSQL, cid); err != nil {
log.Error("ContestsData: db.Exec(%s) error(%v)", _contestDataSQL, err)
return
}
defer rows.Close()
for rows.Next() {
data := new(model.ContestsData)
if err = rows.Scan(&data.ID, &data.Cid, &data.URL, &data.PointData); err != nil {
log.Error("ContestsData:row.Scan() error(%v)", err)
return
}
res = append(res, data)
}
if err = rows.Err(); err != nil {
log.Error("ContestssData rows.Err() error(%v)", err)
}
return
}
// ContestDatas contest datas.
func (d *Dao) ContestDatas(c context.Context) (res []*model.Contest, err error) {
var (
rows *xsql.Rows
)
if rows, err = d.db.Query(c, _contestLeidaSQL); err != nil {
log.Error("Contests: db.Exec(%s) error(%v)", _contestLeidaSQL, err)
return
}
defer rows.Close()
res = make([]*model.Contest, 0)
for rows.Next() {
r := new(model.Contest)
if err = rows.Scan(&r.ID, &r.GameStage, &r.Stime, &r.Etime, &r.HomeID, &r.AwayID, &r.HomeScore, &r.AwayScore,
&r.LiveRoom, &r.Aid, &r.Collection, &r.GameState, &r.Dic, &r.Ctime, &r.Mtime, &r.Status, &r.Sid, &r.Mid,
&r.Special, &r.SpecialName, &r.SpecialTips, &r.SuccessTeam, &r.SpecialImage, &r.Playback, &r.CollectionURL, &r.LiveURL, &r.DataType, &r.MatchID); err != nil {
log.Error("Contests:row.Scan() error(%v)", err)
return
}
res = append(res, r)
}
if err = rows.Err(); err != nil {
log.Error("rows.Err() error(%v)", err)
}
return
}
// RawEpContests get contests by ids.
func (d *Dao) RawEpContests(c context.Context, cids []int64) (res map[int64]*model.Contest, err error) {
var (
rows *xsql.Rows
)
if rows, err = d.db.Query(c, fmt.Sprintf(_contestsSQL, xstr.JoinInts(cids))); err != nil {
log.Error("Contests: db.Exec(%s) error(%v)", xstr.JoinInts(cids), err)
return
}
defer rows.Close()
res = make(map[int64]*model.Contest, len(cids))
for rows.Next() {
r := new(model.Contest)
if err = rows.Scan(&r.ID, &r.GameStage, &r.Stime, &r.Etime, &r.HomeID, &r.AwayID, &r.HomeScore, &r.AwayScore,
&r.LiveRoom, &r.Aid, &r.Collection, &r.GameState, &r.Dic, &r.Ctime, &r.Mtime, &r.Status, &r.Sid, &r.Mid,
&r.Special, &r.SpecialName, &r.SpecialTips, &r.SuccessTeam, &r.SpecialImage, &r.Playback, &r.CollectionURL,
&r.LiveURL, &r.DataType, &r.MatchID); err != nil {
log.Error("Contests:row.Scan() error(%v)", err)
return
}
res[r.ID] = r
}
if err = rows.Err(); err != nil {
log.Error("rows.Err() error(%v)", err)
}
return
}
// RawEpSeasons get seasons by ids.
func (d *Dao) RawEpSeasons(c context.Context, sids []int64) (res map[int64]*model.Season, err error) {
var (
rows *xsql.Rows
)
if rows, err = d.db.Query(c, fmt.Sprintf(_epSeasonSQL, xstr.JoinInts(sids))); err != nil {
log.Error("Contests: db.Exec(%s) error(%v)", xstr.JoinInts(sids), err)
return
}
defer rows.Close()
res = make(map[int64]*model.Season, len(sids))
for rows.Next() {
r := new(model.Season)
if err = rows.Scan(&r.ID, &r.Mid, &r.Title, &r.SubTitle, &r.Stime, &r.Etime, &r.Sponsor, &r.Logo, &r.Dic, &r.Ctime,
&r.Mtime, &r.Status, &r.Rank, &r.IsApp, &r.URL, &r.DataFocus, &r.FocusURL); err != nil {
log.Error("Contest:row.Scan() error(%v)", err)
return
}
res[r.ID] = r
}
if err = rows.Err(); err != nil {
log.Error("rows.Err() error(%v)", err)
}
return
}
// ActTeams get teams by ids in
func (d *Dao) ActTeams(c context.Context, tids []int64) (res []*model.Team, err error) {
var (
rows *xsql.Rows
)
if rows, err = d.db.Query(c, fmt.Sprintf(_teamsInSQL, xstr.JoinInts(tids))); err != nil {
log.Error("ActTeams: db.Exec(%s) error(%v)", xstr.JoinInts(tids), err)
return
}
defer rows.Close()
res = make([]*model.Team, len(tids))
for rows.Next() {
r := new(model.Team)
if err = rows.Scan(&r.ID, &r.Title, &r.SubTitle, &r.Logo); err != nil {
log.Error("ActTeams:row.Scan() error(%v)", err)
return
}
res = append(res, r)
}
if err = rows.Err(); err != nil {
log.Error("ActTeams rows.Err() error(%v)", err)
}
return
}
// RawEpTeams get seasons by ids.
func (d *Dao) RawEpTeams(c context.Context, tids []int64) (res map[int64]*model.Team, err error) {
var (
rows *xsql.Rows
)
if rows, err = d.db.Query(c, fmt.Sprintf(_teamsInSQL, xstr.JoinInts(tids))); err != nil {
log.Error("RawEpTeams: db.Exec(%s) error(%v)", xstr.JoinInts(tids), err)
return
}
defer rows.Close()
res = make(map[int64]*model.Team, len(tids))
for rows.Next() {
r := new(model.Team)
if err = rows.Scan(&r.ID, &r.Title, &r.SubTitle, &r.Logo); err != nil {
log.Error("RawEpTeams:row.Scan() error(%v)", err)
return
}
res[r.ID] = r
}
if err = rows.Err(); err != nil {
log.Error("RawEpTeams.Err() error(%v)", err)
}
return
}
// KDetails knockout detail
func (d *Dao) KDetails(c context.Context) (res []*model.ActiveDetail, err error) {
var (
rows *xsql.Rows
)
if rows, err = d.db.Query(c, _kDetailsSQL); err != nil {
log.Error("ActPDetails: db.Exec(%s) error(%v)", _kDetailsSQL, err)
return
}
defer rows.Close()
for rows.Next() {
detail := new(model.ActiveDetail)
if err = rows.Scan(&detail.ID, &detail.Maid, &detail.GameType, &detail.STime, &detail.ETime, &detail.Online); err != nil {
log.Error("KDetails:row.Scan() error(%v)", err)
return
}
res = append(res, detail)
}
if err = rows.Err(); err != nil {
log.Error("KDetails rows.Err() error(%v)", err)
}
return
}

View File

@@ -0,0 +1,368 @@
package dao
import (
"context"
"testing"
"github.com/smartystreets/goconvey/convey"
)
func TestDaologoURL(t *testing.T) {
convey.Convey("logoURL", t, func(ctx convey.C) {
var (
uri = "/bfs/archive/ad22dba8f05bb7dee6889492d3bb544413ee42c1.jpg"
)
ctx.Convey("When everything goes positive", func(ctx convey.C) {
logo := logoURL(uri)
ctx.Convey("Then logo should not be nil.", func(ctx convey.C) {
ctx.So(logo, convey.ShouldNotBeNil)
})
})
})
}
func TestDaoMatchs(t *testing.T) {
convey.Convey("Matchs", t, func(ctx convey.C) {
var (
c = context.Background()
)
ctx.Convey("When everything goes positive", func(ctx convey.C) {
res, err := d.Matchs(c)
ctx.Convey("Then err should be nil.res should not be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
ctx.So(res, convey.ShouldNotBeNil)
})
})
})
}
func TestDaoGames(t *testing.T) {
convey.Convey("Games", t, func(ctx convey.C) {
var (
c = context.Background()
)
ctx.Convey("When everything goes positive", func(ctx convey.C) {
res, err := d.Games(c)
ctx.Convey("Then err should be nil.res should not be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
ctx.So(res, convey.ShouldNotBeNil)
})
})
})
}
func TestDaoTeams(t *testing.T) {
convey.Convey("Teams", t, func(ctx convey.C) {
var (
c = context.Background()
)
ctx.Convey("When everything goes positive", func(ctx convey.C) {
res, err := d.Teams(c)
ctx.Convey("Then err should be nil.res should not be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
ctx.So(res, convey.ShouldNotBeNil)
})
})
})
}
func TestDaoTags(t *testing.T) {
convey.Convey("Tags", t, func(ctx convey.C) {
var (
c = context.Background()
)
ctx.Convey("When everything goes positive", func(ctx convey.C) {
res, err := d.Tags(c)
ctx.Convey("Then err should be nil.res should not be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
ctx.So(res, convey.ShouldNotBeNil)
})
})
})
}
func TestDaoYears(t *testing.T) {
convey.Convey("Years", t, func(ctx convey.C) {
var (
c = context.Background()
)
ctx.Convey("When everything goes positive", func(ctx convey.C) {
res, err := d.Years(c)
ctx.Convey("Then err should be nil.res should not be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
ctx.So(res, convey.ShouldNotBeNil)
})
})
})
}
func TestDaoCalendar(t *testing.T) {
convey.Convey("Calendar", t, func(ctx convey.C) {
var (
c = context.Background()
stime = int64(0)
etime = int64(0)
)
ctx.Convey("When everything goes positive", func(ctx convey.C) {
res, err := d.Calendar(c, stime, etime)
ctx.Convey("Then err should be nil.res should not be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
ctx.So(res, convey.ShouldNotBeNil)
})
})
})
}
func TestDaoSeason(t *testing.T) {
convey.Convey("Season", t, func(ctx convey.C) {
var (
c = context.Background()
)
ctx.Convey("When everything goes positive", func(ctx convey.C) {
res, err := d.Season(c)
ctx.Convey("Then err should be nil.res should not be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
ctx.So(res, convey.ShouldNotBeNil)
})
})
})
}
func TestDaoModule(t *testing.T) {
convey.Convey("Module", t, func(ctx convey.C) {
var (
c = context.Background()
mmid = int64(69)
)
ctx.Convey("When everything goes positive", func(ctx convey.C) {
mod, err := d.Module(c, mmid)
ctx.Convey("Then err should be nil.mod should not be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
ctx.So(mod, convey.ShouldNotBeNil)
})
})
})
}
func TestDaoModules(t *testing.T) {
convey.Convey("Modules", t, func(ctx convey.C) {
var (
c = context.Background()
aid = int64(1)
)
ctx.Convey("When everything goes positive", func(ctx convey.C) {
mods, err := d.Modules(c, aid)
ctx.Convey("Then err should be nil.mods should not be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
ctx.So(mods, convey.ShouldNotBeNil)
})
})
})
}
func TestDaoTrees(t *testing.T) {
convey.Convey("Trees", t, func(ctx convey.C) {
var (
c = context.Background()
madID = int64(1)
)
ctx.Convey("When everything goes positive", func(ctx convey.C) {
mods, err := d.Trees(c, madID)
ctx.Convey("Then err should be nil.mods should not be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
ctx.So(mods, convey.ShouldNotBeNil)
})
})
})
}
func TestDaoActive(t *testing.T) {
convey.Convey("Active", t, func(ctx convey.C) {
var (
c = context.Background()
aid = int64(1)
)
ctx.Convey("When everything goes positive", func(ctx convey.C) {
mod, err := d.Active(c, aid)
ctx.Convey("Then err should be nil.mod should not be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
ctx.So(mod, convey.ShouldNotBeNil)
})
})
})
}
func TestDaoPActDetail(t *testing.T) {
convey.Convey("PActDetail", t, func(ctx convey.C) {
var (
c = context.Background()
id = int64(2)
)
ctx.Convey("When everything goes positive", func(ctx convey.C) {
_, err := d.PActDetail(c, id)
ctx.Convey("Then err should be nil.mod should not be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
})
})
})
}
func TestDaoActData(t *testing.T) {
convey.Convey("ActDetail", t, func(ctx convey.C) {
var (
c = context.Background()
aid = int64(1)
)
ctx.Convey("When everything goes positive", func(ctx convey.C) {
actData, err := d.ActDetail(c, aid)
ctx.Convey("Then err should be nil.actData should not be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
ctx.So(actData, convey.ShouldNotBeNil)
})
})
})
}
func TestDaoAppSeason(t *testing.T) {
convey.Convey("AppSeason", t, func(ctx convey.C) {
var (
c = context.Background()
)
ctx.Convey("When everything goes positive", func(ctx convey.C) {
res, err := d.AppSeason(c)
ctx.Convey("Then err should be nil.res should not be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
ctx.So(res, convey.ShouldNotBeNil)
})
})
})
}
func TestDaoSeasonAll(t *testing.T) {
convey.Convey("SeasonAll", t, func(ctx convey.C) {
var (
c = context.Background()
)
ctx.Convey("When everything goes positive", func(ctx convey.C) {
res, err := d.SeasonAll(c)
ctx.Convey("Then err should be nil.res should not be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
ctx.So(res, convey.ShouldNotBeNil)
})
})
})
}
func TestDaoContest(t *testing.T) {
convey.Convey("Contest", t, func(ctx convey.C) {
var (
c = context.Background()
cid = int64(1)
)
ctx.Convey("When everything goes positive", func(ctx convey.C) {
res, err := d.Contest(c, cid)
ctx.Convey("Then err should be nil.res should not be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
ctx.So(res, convey.ShouldNotBeNil)
})
})
})
}
func TestDaoContestRecent(t *testing.T) {
convey.Convey("ContestRecent", t, func(ctx convey.C) {
var (
c = context.Background()
homeid = int64(1)
awayid = int64(2)
contestid = int64(1)
ps = int64(2)
)
ctx.Convey("When everything gose positive", func(ctx convey.C) {
res, err := d.ContestRecent(c, homeid, awayid, contestid, ps)
ctx.Convey("Then err should be nil.res should not be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
ctx.So(res, convey.ShouldNotBeNil)
})
})
})
}
func TestDaoContestData(t *testing.T) {
convey.Convey("ContestData", t, func(ctx convey.C) {
var (
c = context.Background()
cid = int64(458)
)
ctx.Convey("When everything gose positive", func(ctx convey.C) {
res, err := d.ContestData(c, cid)
ctx.Convey("Then err should be nil.res should not be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
ctx.So(res, convey.ShouldNotBeNil)
})
})
})
}
func TestDaoRawEpSeasons(t *testing.T) {
convey.Convey("RawEpSeasons", t, func(ctx convey.C) {
var (
c = context.Background()
sids = []int64{1}
)
ctx.Convey("When everything goes positive", func(ctx convey.C) {
res, err := d.RawEpSeasons(c, sids)
ctx.Convey("Then err should be nil.res should not be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
ctx.So(res, convey.ShouldNotBeNil)
})
})
})
}
func TestDaoActTeams(t *testing.T) {
convey.Convey("ActTeams", t, func(ctx convey.C) {
var (
c = context.Background()
tids = []int64{1}
)
ctx.Convey("When everything goes positive", func(ctx convey.C) {
res, err := d.ActTeams(c, tids)
ctx.Convey("Then err should be nil.res should not be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
ctx.So(res, convey.ShouldNotBeNil)
})
})
})
}
func TestDaoKDetails(t *testing.T) {
convey.Convey("KDetails", t, func(ctx convey.C) {
var (
c = context.Background()
)
ctx.Convey("When everything goes positive", func(ctx convey.C) {
res, err := d.KDetails(c)
ctx.Convey("Then err should be nil.res should not be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
ctx.So(res, convey.ShouldNotBeNil)
})
})
})
}
func TestDaoRawEpContests(t *testing.T) {
convey.Convey("RawEpContests", t, func(ctx convey.C) {
var (
c = context.Background()
cids = []int64{1, 2, 3, 4, 5, 6}
)
ctx.Convey("When everything gose positive", func(ctx convey.C) {
res, err := d.RawEpContests(c, cids)
ctx.Convey("Then err should be nil.res should not be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
ctx.So(res, convey.ShouldNotBeNil)
})
})
})
}

View File

@@ -0,0 +1,47 @@
package dao
import (
"context"
"fmt"
"io/ioutil"
"net/http"
"time"
"go-common/library/log"
"github.com/pkg/errors"
)
// Leida get leidata.
func (d *Dao) Leida(c context.Context, url string) (rs []byte, err error) {
if rs, err = d.ThirdGet(c, url); err != nil {
log.Error("d.ThirdGet url(%s) error(%+v)", url, err)
}
return
}
// ThirdGet get.
func (d *Dao) ThirdGet(c context.Context, url string) (res []byte, err error) {
var (
req *http.Request
resp *http.Response
)
if req, err = http.NewRequest("GET", url, nil); err != nil {
err = errors.Wrapf(err, "ThirdGet http.NewRequest(%s)", url)
return
}
ctx, cancel := context.WithTimeout(c, time.Duration(d.c.Leidata.Timeout))
defer cancel()
req = req.WithContext(ctx)
if resp, err = d.ldClient.Do(req); err != nil {
err = errors.Wrapf(err, "ThirdGet d.ldClient.Do(%s)", url)
return
}
defer resp.Body.Close()
if resp.StatusCode >= http.StatusBadRequest {
err = fmt.Errorf("ThirdGet url(%s) resp.StatusCode(%v)", url, resp.StatusCode)
return
}
res, err = ioutil.ReadAll(resp.Body)
return
}

View File

@@ -0,0 +1,40 @@
package dao
import (
"context"
"testing"
"github.com/smartystreets/goconvey/convey"
)
func TestDaoLeida(t *testing.T) {
convey.Convey("Leida", t, func(convCtx convey.C) {
var (
c = context.Background()
url = "http://47.95.28.113/nesport/index.php/Api/lol/games?match_id=328266&key=d076eef519773c5954081e6a352c726d"
)
convCtx.Convey("When everything goes positive", func(convCtx convey.C) {
rs, err := d.Leida(c, url)
convCtx.Convey("Then err should be nil.rs should not be nil.", func(convCtx convey.C) {
convCtx.So(err, convey.ShouldBeNil)
convCtx.So(rs, convey.ShouldNotBeNil)
})
})
})
}
func TestDaoThirdGet(t *testing.T) {
convey.Convey("ThirdGet", t, func(convCtx convey.C) {
var (
c = context.Background()
url = "http://47.95.28.113/nesport/index.php/Api/lol/games?match_id=328266&key=d076eef519773c5954081e6a352c726d"
)
convCtx.Convey("When everything goes positive", func(convCtx convey.C) {
res, err := d.ThirdGet(c, url)
convCtx.Convey("Then err should be nil.res should not be nil.", func(convCtx convey.C) {
convCtx.So(err, convey.ShouldBeNil)
convCtx.So(res, convey.ShouldNotBeNil)
})
})
})
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,893 @@
package dao
import (
"context"
"go-common/app/interface/main/esports/model"
arcmdl "go-common/app/service/main/archive/api"
"testing"
"github.com/smartystreets/goconvey/convey"
)
func TestDaokeyCale(t *testing.T) {
convey.Convey("keyCale", t, func(ctx convey.C) {
var (
stime = ""
etime = ""
)
ctx.Convey("When everything goes positive", func(ctx convey.C) {
p1 := keyCale(stime, etime)
ctx.Convey("Then p1 should not be nil.", func(ctx convey.C) {
ctx.So(p1, convey.ShouldNotBeNil)
})
})
})
}
func TestDaokeyCont(t *testing.T) {
convey.Convey("keyCont", t, func(ctx convey.C) {
var (
ps = int(1)
)
ctx.Convey("When everything goes positive", func(ctx convey.C) {
p1 := keyCont(ps)
ctx.Convey("Then p1 should not be nil.", func(ctx convey.C) {
ctx.So(p1, convey.ShouldNotBeNil)
})
})
})
}
func TestDaokeyVideo(t *testing.T) {
convey.Convey("keyVideo", t, func(ctx convey.C) {
var (
ps = int(1)
)
ctx.Convey("When everything goes positive", func(ctx convey.C) {
p1 := keyVideo(ps)
ctx.Convey("Then p1 should not be nil.", func(ctx convey.C) {
ctx.So(p1, convey.ShouldNotBeNil)
})
})
})
}
func TestDaokeyContID(t *testing.T) {
convey.Convey("keyContID", t, func(ctx convey.C) {
var (
cid = int64(1)
)
ctx.Convey("When everything goes positive", func(ctx convey.C) {
p1 := keyContID(cid)
ctx.Convey("Then p1 should not be nil.", func(ctx convey.C) {
ctx.So(p1, convey.ShouldNotBeNil)
})
})
})
}
func TestDaokeyCoFav(t *testing.T) {
convey.Convey("keyCoFav", t, func(ctx convey.C) {
var (
mid = int64(1)
)
ctx.Convey("When everything goes positive", func(ctx convey.C) {
p1 := keyCoFav(mid)
ctx.Convey("Then p1 should not be nil.", func(ctx convey.C) {
ctx.So(p1, convey.ShouldNotBeNil)
})
})
})
}
func TestDaokeyCoAppFav(t *testing.T) {
convey.Convey("keyCoAppFav", t, func(ctx convey.C) {
var (
mid = int64(1)
)
ctx.Convey("When everything goes positive", func(ctx convey.C) {
p1 := keyCoAppFav(mid)
ctx.Convey("Then p1 should not be nil.", func(ctx convey.C) {
ctx.So(p1, convey.ShouldNotBeNil)
})
})
})
}
func TestDaokeySID(t *testing.T) {
convey.Convey("keySID", t, func(ctx convey.C) {
var (
sid = int64(1)
)
ctx.Convey("When everything goes positive", func(ctx convey.C) {
p1 := keySID(sid)
ctx.Convey("Then p1 should not be nil.", func(ctx convey.C) {
ctx.So(p1, convey.ShouldNotBeNil)
})
})
})
}
func TestDaokeyMatchAct(t *testing.T) {
convey.Convey("keyMatchAct", t, func(ctx convey.C) {
var (
aid = int64(1)
)
ctx.Convey("When everything goes positive", func(ctx convey.C) {
p1 := keyMatchAct(aid)
ctx.Convey("Then p1 should not be nil.", func(ctx convey.C) {
ctx.So(p1, convey.ShouldNotBeNil)
})
})
})
}
func TestDaokeyMatchModule(t *testing.T) {
convey.Convey("keyMatchModule", t, func(ctx convey.C) {
var (
mmid = int64(1)
)
ctx.Convey("When everything goes positive", func(ctx convey.C) {
p1 := keyMatchModule(mmid)
ctx.Convey("Then p1 should not be nil.", func(ctx convey.C) {
ctx.So(p1, convey.ShouldNotBeNil)
})
})
})
}
func TestDaokeyKnock(t *testing.T) {
convey.Convey("keyKnock", t, func(ctx convey.C) {
var (
mdID = int64(1)
)
ctx.Convey("When everything goes positive", func(ctx convey.C) {
p1 := keyKnock(mdID)
ctx.Convey("Then p1 should not be nil.", func(ctx convey.C) {
ctx.So(p1, convey.ShouldNotBeNil)
})
})
})
}
func TestDaokeyTop(t *testing.T) {
convey.Convey("keyTop", t, func(ctx convey.C) {
var (
aid = int64(1)
ps = int64(1)
)
ctx.Convey("When everything goes positive", func(ctx convey.C) {
p1 := keyTop(aid, ps)
ctx.Convey("Then p1 should not be nil.", func(ctx convey.C) {
ctx.So(p1, convey.ShouldNotBeNil)
})
})
})
}
func TestDaokeyPoint(t *testing.T) {
convey.Convey("keyPoint", t, func(ctx convey.C) {
var (
aid = int64(1)
mdID = int64(1)
ps = int64(1)
)
ctx.Convey("When everything goes positive", func(ctx convey.C) {
p1 := keyPoint(aid, mdID, ps)
ctx.Convey("Then p1 should not be nil.", func(ctx convey.C) {
ctx.So(p1, convey.ShouldNotBeNil)
})
})
})
}
func TestDaoFMatCache(t *testing.T) {
convey.Convey("FMatCache", t, func(ctx convey.C) {
var (
c = context.Background()
)
ctx.Convey("When everything goes positive", func(ctx convey.C) {
_, err := d.FMatCache(c)
ctx.Convey("Then err should be nil.res should not be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
})
})
})
}
func TestDaoFVideoCache(t *testing.T) {
convey.Convey("FVideoCache", t, func(ctx convey.C) {
var (
c = context.Background()
)
ctx.Convey("When everything goes positive", func(ctx convey.C) {
_, err := d.FVideoCache(c)
ctx.Convey("Then err should be nil.res should not be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
})
})
})
}
func TestDaofilterCache(t *testing.T) {
convey.Convey("filterCache", t, func(ctx convey.C) {
var (
c = context.Background()
key = "1"
)
ctx.Convey("When everything goes positive", func(ctx convey.C) {
_, err := d.filterCache(c, key)
ctx.Convey("Then err should be nil.rs should not be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
})
})
})
}
func TestDaoSetFMatCache(t *testing.T) {
convey.Convey("SetFMatCache", t, func(ctx convey.C) {
var (
c = context.Background()
fs map[string][]*model.Filter
)
ctx.Convey("When everything goes positive", func(ctx convey.C) {
err := d.SetFMatCache(c, fs)
ctx.Convey("Then err should be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
})
})
})
}
func TestDaoSetFVideoCache(t *testing.T) {
convey.Convey("SetFVideoCache", t, func(ctx convey.C) {
var (
c = context.Background()
fs map[string][]*model.Filter
)
ctx.Convey("When everything goes positive", func(ctx convey.C) {
err := d.SetFVideoCache(c, fs)
ctx.Convey("Then err should be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
})
})
})
}
func TestDaosetFilterCache(t *testing.T) {
convey.Convey("setFilterCache", t, func(ctx convey.C) {
var (
c = context.Background()
key = ""
fs map[string][]*model.Filter
)
ctx.Convey("When everything goes positive", func(ctx convey.C) {
err := d.setFilterCache(c, key, fs)
ctx.Convey("Then err should be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
})
})
})
}
func TestDaoContestCache(t *testing.T) {
convey.Convey("ContestCache", t, func(ctx convey.C) {
var (
c = context.Background()
ps = int(1)
)
ctx.Convey("When everything goes positive", func(ctx convey.C) {
_, total, err := d.ContestCache(c, ps)
ctx.Convey("Then err should be nil.res,total should not be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
ctx.So(total, convey.ShouldNotBeNil)
})
})
})
}
func TestDaoFavCoCache(t *testing.T) {
convey.Convey("FavCoCache", t, func(ctx convey.C) {
var (
c = context.Background()
mid = int64(1)
)
ctx.Convey("When everything goes positive", func(ctx convey.C) {
_, total, err := d.FavCoCache(c, mid)
ctx.Convey("Then err should be nil.res,total should not be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
ctx.So(total, convey.ShouldNotBeNil)
})
})
})
}
func TestDaoFavCoAppCache(t *testing.T) {
convey.Convey("FavCoAppCache", t, func(ctx convey.C) {
var (
c = context.Background()
mid = int64(1)
)
ctx.Convey("When everything goes positive", func(ctx convey.C) {
_, total, err := d.FavCoAppCache(c, mid)
ctx.Convey("Then err should be nil.res,total should not be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
ctx.So(total, convey.ShouldNotBeNil)
})
})
})
}
func TestDaocosCache(t *testing.T) {
convey.Convey("cosCache", t, func(ctx convey.C) {
var (
c = context.Background()
key = "1"
)
ctx.Convey("When everything goes positive", func(ctx convey.C) {
_, total, err := d.cosCache(c, key)
ctx.Convey("Then err should be nil.res,total should not be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
ctx.So(total, convey.ShouldNotBeNil)
})
})
})
}
func TestDaoSetContestCache(t *testing.T) {
convey.Convey("SetContestCache", t, func(ctx convey.C) {
var (
c = context.Background()
ps = int(1)
con = &model.Contest{}
contests = []*model.Contest{con}
total = int(0)
)
ctx.Convey("When everything goes positive", func(ctx convey.C) {
err := d.SetContestCache(c, ps, contests, total)
ctx.Convey("Then err should be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
})
})
})
}
func TestDaoSetFavCoCache(t *testing.T) {
convey.Convey("SetFavCoCache", t, func(ctx convey.C) {
var (
c = context.Background()
mid = int64(0)
con = &model.Contest{}
contests = []*model.Contest{con}
total = int(0)
)
ctx.Convey("When everything goes positive", func(ctx convey.C) {
err := d.SetFavCoCache(c, mid, contests, total)
ctx.Convey("Then err should be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
})
})
})
}
func TestDaoSetAppFavCoCache(t *testing.T) {
convey.Convey("SetAppFavCoCache", t, func(ctx convey.C) {
var (
c = context.Background()
mid = int64(0)
con = &model.Contest{}
contests = []*model.Contest{con}
total = int(0)
)
ctx.Convey("When everything goes positive", func(ctx convey.C) {
err := d.SetAppFavCoCache(c, mid, contests, total)
ctx.Convey("Then err should be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
})
})
})
}
func TestDaoDelFavCoCache(t *testing.T) {
convey.Convey("DelFavCoCache", t, func(ctx convey.C) {
var (
c = context.Background()
mid = int64(1)
)
ctx.Convey("When everything goes positive", func(ctx convey.C) {
err := d.DelFavCoCache(c, mid)
ctx.Convey("Then err should be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
})
})
})
}
func TestDaosetCosCache(t *testing.T) {
convey.Convey("setCosCache", t, func(ctx convey.C) {
var (
c = context.Background()
key = ""
con = &model.Contest{}
contests = []*model.Contest{con}
total = int(1)
)
ctx.Convey("When everything goes positive", func(ctx convey.C) {
err := d.setCosCache(c, key, contests, total)
ctx.Convey("Then err should be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
})
})
})
}
func TestDaoCalendarCache(t *testing.T) {
convey.Convey("CalendarCache", t, func(ctx convey.C) {
var (
c = context.Background()
p = &model.ParamFilter{}
)
ctx.Convey("When everything goes positive", func(ctx convey.C) {
_, err := d.CalendarCache(c, p)
ctx.Convey("Then err should be nil.res should not be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
})
})
})
}
func TestDaoSetCalendarCache(t *testing.T) {
convey.Convey("SetCalendarCache", t, func(ctx convey.C) {
var (
c = context.Background()
p = &model.ParamFilter{}
cal = &model.Calendar{}
cales = []*model.Calendar{cal}
)
ctx.Convey("When everything goes positive", func(ctx convey.C) {
err := d.SetCalendarCache(c, p, cales)
ctx.Convey("Then err should be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
})
})
})
}
func TestDaoVideoCache(t *testing.T) {
convey.Convey("VideoCache", t, func(ctx convey.C) {
var (
c = context.Background()
ps = int(1)
)
ctx.Convey("When everything goes positive", func(ctx convey.C) {
_, total, err := d.VideoCache(c, ps)
ctx.Convey("Then err should be nil.res,total should not be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
ctx.So(total, convey.ShouldNotBeNil)
})
})
})
}
func TestDaoSetVideoCache(t *testing.T) {
convey.Convey("SetVideoCache", t, func(ctx convey.C) {
var (
c = context.Background()
ps = int(0)
arc = &arcmdl.Arc{}
videos = []*arcmdl.Arc{arc}
total = int(0)
)
ctx.Convey("When everything goes positive", func(ctx convey.C) {
err := d.SetVideoCache(c, ps, videos, total)
ctx.Convey("Then err should be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
})
})
})
}
func TestDaoseasonsCache(t *testing.T) {
convey.Convey("seasonsCache", t, func(ctx convey.C) {
var (
c = context.Background()
key = "1"
start = int(0)
end = int(0)
)
ctx.Convey("When everything goes positive", func(ctx convey.C) {
_, total, err := d.seasonsCache(c, key, start, end)
ctx.Convey("Then err should be nil.res,total should not be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
ctx.So(total, convey.ShouldNotBeNil)
})
})
})
}
func TestDaosetSeasonsCache(t *testing.T) {
convey.Convey("setSeasonsCache", t, func(ctx convey.C) {
var (
c = context.Background()
key = "1"
seasons = []*model.Season{}
total = int(0)
)
ctx.Convey("When everything goes positive", func(ctx convey.C) {
err := d.setSeasonsCache(c, key, seasons, total)
ctx.Convey("Then err should be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
})
})
})
}
func TestDaoSeasonCache(t *testing.T) {
convey.Convey("SeasonCache", t, func(ctx convey.C) {
var (
c = context.Background()
start = int(0)
end = int(0)
)
ctx.Convey("When everything goes positive", func(ctx convey.C) {
_, total, err := d.SeasonCache(c, start, end)
ctx.Convey("Then err should be nil.res,total should not be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
ctx.So(total, convey.ShouldNotBeNil)
})
})
})
}
func TestDaoSetSeasonCache(t *testing.T) {
convey.Convey("SetSeasonCache", t, func(ctx convey.C) {
var (
c = context.Background()
seasons = []*model.Season{}
total = int(0)
)
ctx.Convey("When everything goes positive", func(ctx convey.C) {
err := d.SetSeasonCache(c, seasons, total)
ctx.Convey("Then err should be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
})
})
})
}
func TestDaoSeasonMCache(t *testing.T) {
convey.Convey("SeasonMCache", t, func(ctx convey.C) {
var (
c = context.Background()
start = int(0)
end = int(0)
)
ctx.Convey("When everything goes positive", func(ctx convey.C) {
_, total, err := d.SeasonMCache(c, start, end)
ctx.Convey("Then err should be nil.res,total should not be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
ctx.So(total, convey.ShouldNotBeNil)
})
})
})
}
func TestDaoSetSeasonMCache(t *testing.T) {
convey.Convey("SetSeasonMCache", t, func(ctx convey.C) {
var (
c = context.Background()
seasons = []*model.Season{}
total = int(0)
)
ctx.Convey("When everything goes positive", func(ctx convey.C) {
err := d.SetSeasonMCache(c, seasons, total)
ctx.Convey("Then err should be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
})
})
})
}
func TestDaofrom(t *testing.T) {
convey.Convey("from", t, func(ctx convey.C) {
var (
i = int64(0)
)
ctx.Convey("When everything goes positive", func(ctx convey.C) {
p1 := from(i)
ctx.Convey("Then p1 should not be nil.", func(ctx convey.C) {
ctx.So(p1, convey.ShouldNotBeNil)
})
})
})
}
func TestDaocombine(t *testing.T) {
convey.Convey("combine", t, func(ctx convey.C) {
var (
sort = int64(0)
count = int(0)
)
ctx.Convey("When everything goes positive", func(ctx convey.C) {
p1 := combine(sort, count)
ctx.Convey("Then p1 should not be nil.", func(ctx convey.C) {
ctx.So(p1, convey.ShouldNotBeNil)
})
})
})
}
func TestDaoCacheEpContests(t *testing.T) {
convey.Convey("CacheEpContests", t, func(ctx convey.C) {
var (
c = context.Background()
ids = []int64{1}
)
ctx.Convey("When everything goes positive", func(ctx convey.C) {
res, err := d.CacheEpContests(c, ids)
ctx.Convey("Then err should be nil.res should not be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
ctx.So(res, convey.ShouldNotBeNil)
})
})
})
}
func TestDaoAddCacheEpContests(t *testing.T) {
convey.Convey("AddCacheEpContests", t, func(ctx convey.C) {
var (
c = context.Background()
data map[int64]*model.Contest
)
ctx.Convey("When everything goes positive", func(ctx convey.C) {
err := d.AddCacheEpContests(c, data)
ctx.Convey("Then err should be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
})
})
})
}
func TestDaoCacheEpSeasons(t *testing.T) {
convey.Convey("CacheEpSeasons", t, func(ctx convey.C) {
var (
c = context.Background()
ids = []int64{1}
)
ctx.Convey("When everything goes positive", func(ctx convey.C) {
res, err := d.CacheEpSeasons(c, ids)
ctx.Convey("Then err should be nil.res should not be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
ctx.So(res, convey.ShouldNotBeNil)
})
})
})
}
func TestDaoAddCacheEpSeasons(t *testing.T) {
convey.Convey("AddCacheEpSeasons", t, func(ctx convey.C) {
var (
c = context.Background()
data map[int64]*model.Season
)
ctx.Convey("When everything goes positive", func(ctx convey.C) {
err := d.AddCacheEpSeasons(c, data)
ctx.Convey("Then err should be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
})
})
})
}
func TestDaoGetActPageCache(t *testing.T) {
convey.Convey("GetActPageCache", t, func(ctx convey.C) {
var (
c = context.Background()
id = int64(0)
)
ctx.Convey("When everything goes positive", func(ctx convey.C) {
_, err := d.GetActPageCache(c, id)
ctx.Convey("Then err should be nil.act should not be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
})
})
})
}
func TestDaoAddActPageCache(t *testing.T) {
convey.Convey("AddActPageCache", t, func(ctx convey.C) {
var (
c = context.Background()
aid = int64(0)
act = &model.ActivePage{}
)
ctx.Convey("When everything goes positive", func(ctx convey.C) {
err := d.AddActPageCache(c, aid, act)
ctx.Convey("Then err should be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
})
})
})
}
func TestDaoGetActModuleCache(t *testing.T) {
convey.Convey("GetActModuleCache", t, func(ctx convey.C) {
var (
c = context.Background()
mmid = int64(0)
)
ctx.Convey("When everything goes positive", func(ctx convey.C) {
_, err := d.GetActModuleCache(c, mmid)
ctx.Convey("Then err should be nil.res should not be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
})
})
})
}
func TestDaoAddActModuleCache(t *testing.T) {
convey.Convey("AddActModuleCache", t, func(ctx convey.C) {
var (
c = context.Background()
mmid = int64(0)
module []*arcmdl.Arc
)
ctx.Convey("When everything goes positive", func(ctx convey.C) {
err := d.AddActModuleCache(c, mmid, module)
ctx.Convey("Then err should be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
})
})
})
}
func TestDaoGetActTopCache(t *testing.T) {
convey.Convey("GetActTopCache", t, func(ctx convey.C) {
var (
c = context.Background()
aid = int64(0)
ps = int64(0)
)
ctx.Convey("When everything goes positive", func(ctx convey.C) {
_, total, err := d.GetActTopCache(c, aid, ps)
ctx.Convey("Then err should be nil.res,total should not be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
ctx.So(total, convey.ShouldNotBeNil)
})
})
})
}
func TestDaoAddActTopCache(t *testing.T) {
convey.Convey("AddActTopCache", t, func(ctx convey.C) {
var (
c = context.Background()
aid = int64(0)
ps = int64(0)
con = &model.Contest{}
tops = []*model.Contest{con}
total = int(0)
)
ctx.Convey("When everything goes positive", func(ctx convey.C) {
err := d.AddActTopCache(c, aid, ps, tops, total)
ctx.Convey("Then err should be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
})
})
})
}
func TestDaoGetActPointsCache(t *testing.T) {
convey.Convey("GetActPointsCache", t, func(ctx convey.C) {
var (
c = context.Background()
aid = int64(0)
mdID = int64(0)
ps = int64(0)
)
ctx.Convey("When everything goes positive", func(ctx convey.C) {
_, total, err := d.GetActPointsCache(c, aid, mdID, ps)
ctx.Convey("Then err should be nil.res,total should not be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
ctx.So(total, convey.ShouldNotBeNil)
})
})
})
}
func TestDaoAddActPointsCache(t *testing.T) {
convey.Convey("AddActPointsCache", t, func(ctx convey.C) {
var (
c = context.Background()
aid = int64(0)
mdID = int64(0)
ps = int64(0)
con = &model.Contest{}
points = []*model.Contest{con}
total = int(0)
)
ctx.Convey("When everything goes positive", func(ctx convey.C) {
err := d.AddActPointsCache(c, aid, mdID, ps, points, total)
ctx.Convey("Then err should be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
})
})
})
}
func TestDaoGetActKnockoutCache(t *testing.T) {
convey.Convey("GetActKnockoutCache", t, func(ctx convey.C) {
var (
c = context.Background()
mdID = int64(0)
)
ctx.Convey("When everything goes positive", func(ctx convey.C) {
_, err := d.GetActKnockoutCache(c, mdID)
ctx.Convey("Then err should be nil.res should not be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
})
})
})
}
func TestDaoAddActKnockoutCache(t *testing.T) {
convey.Convey("AddActKnockoutCache", t, func(ctx convey.C) {
var (
c = context.Background()
mdID = int64(0)
knock = [][]*model.TreeList{}
)
ctx.Convey("When everything goes positive", func(ctx convey.C) {
err := d.AddActKnockoutCache(c, mdID, knock)
ctx.Convey("Then err should be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
})
})
})
}
func TestDaoAddActKnockCacheTime(t *testing.T) {
convey.Convey("AddActKnockCacheTime", t, func(convCtx convey.C) {
var (
c = context.Background()
mdID = int64(1)
)
convCtx.Convey("When everything goes positive", func(convCtx convey.C) {
err := d.AddActKnockCacheTime(c, mdID)
convCtx.Convey("Then err should be nil.", func(convCtx convey.C) {
convCtx.So(err, convey.ShouldBeNil)
})
})
})
}
func TestDaoGetMActCache(t *testing.T) {
convey.Convey("GetMActCache", t, func(convCtx convey.C) {
var (
c = context.Background()
aid = int64(1)
)
convCtx.Convey("When everything goes positive", func(convCtx convey.C) {
res, err := d.GetMActCache(c, aid)
convCtx.Convey("Then err should be nil.res should not be nil.", func(convCtx convey.C) {
convCtx.So(err, convey.ShouldBeNil)
println(res)
})
})
})
}
func TestDaoAddMActCache(t *testing.T) {
convey.Convey("AddMActCache", t, func(convCtx convey.C) {
var (
c = context.Background()
aid = int64(1)
act = &model.Active{}
)
convCtx.Convey("When everything goes positive", func(convCtx convey.C) {
err := d.AddMActCache(c, aid, act)
convCtx.Convey("Then err should be nil.", func(convCtx convey.C) {
convCtx.So(err, convey.ShouldBeNil)
})
})
})
}

View File

@@ -0,0 +1,377 @@
package dao
import (
"context"
"net/url"
"strconv"
"strings"
"time"
"go-common/app/interface/main/esports/model"
arcMdl "go-common/app/service/main/archive/model/archive"
"go-common/library/database/elastic"
"go-common/library/ecode"
"go-common/library/log"
"go-common/library/net/metadata"
)
const (
_esports = "esports"
_contest = "esports_contests"
_videomap = "esports_map"
_matchmap = "esports_contests_map"
_calendar = "esports_contests_date"
_contestFav = "esports_fav"
_searchPlatform = "web"
_fromSource = "esports_search"
_searchType = "vesports"
_searchVer = "v3"
_orderRank = "totalrank"
_orderHot = "hot"
_orderPub = "pubdate"
_active = 1
_pageNum = 1
_pageSize = 1000
)
// Search search api.
func (d *Dao) Search(c context.Context, mid int64, p *model.ParamSearch, buvid string) (rs *model.SearchEsp, err error) {
var (
params = url.Values{}
ip = metadata.String(c, metadata.RemoteIP)
)
params.Set("keyword", p.Keyword)
params.Set("platform", _searchPlatform)
params.Set("from_source", _fromSource)
params.Set("search_type", _searchType)
params.Set("main_ver", _searchVer)
params.Set("clientip", ip)
params.Set("userid", strconv.FormatInt(mid, 10))
params.Set("buvid", buvid)
params.Set("page", strconv.Itoa(p.Pn))
params.Set("pagesize", strconv.Itoa(p.Ps))
if p.Sort == 0 {
params.Set("order", _orderRank)
} else if p.Sort == 1 {
params.Set("order", _orderPub)
} else if p.Sort == 2 {
params.Set("order", _orderHot)
}
if err = d.http.Get(c, d.searchURL, ip, params, &rs); err != nil {
log.Error("Search接口错误 Search d.http.Get(%s) error(%v)", d.searchURL+"?"+params.Encode(), err)
return
}
if rs.Code != ecode.OK.Code() {
log.Error("Search接口code错误 Search d.http.Do(%s) code error(%d)", d.searchURL, rs.Code)
err = ecode.Int(rs.Code)
}
return
}
// SearchVideo search video.
func (d *Dao) SearchVideo(c context.Context, p *model.ParamVideo) (rs []*model.SearchVideo, total int, err error) {
var res struct {
Page model.Page `json:"page"`
Result []*model.SearchVideo `json:"result"`
}
states := []int64{arcMdl.StateForbidFixed, arcMdl.StateOpen, arcMdl.StateOrange}
r := d.ela.NewRequest(_esports).WhereIn("state", states).WhereEq("is_deleted", 0).Fields("aid").Index(_esports).Pn(p.Pn).Ps(p.Ps)
if p.Gid > 0 {
r.WhereEq("gid", p.Gid)
}
if p.Mid > 0 {
r.WhereEq("matchs", p.Mid)
}
if p.Year > 0 {
r.WhereEq("year", p.Year)
}
if p.Tid > 0 {
r.WhereEq("teams", p.Tid)
}
if p.Tag > 0 {
r.WhereEq("tags", p.Tag)
}
if p.Sort == 0 {
r.Order("score", elastic.OrderDesc)
} else if p.Sort == 1 {
r.Order("pubtime", elastic.OrderDesc)
} else if p.Sort == 2 {
r.Order("click", elastic.OrderDesc)
}
if err = r.Scan(c, &res); err != nil {
log.Error("r.Scan error(%v)", err)
return
}
total = res.Page.Total
rs = res.Result
return
}
// SearchContest search contest.
func (d *Dao) SearchContest(c context.Context, p *model.ParamContest) (rs []*model.Contest, total int, err error) {
var res struct {
Page model.Page `json:"page"`
Result []*model.Contest `json:"result"`
}
r := d.ela.NewRequest(_contest).Index(_contest).WhereEq("status", 0).Pn(p.Pn).Ps(p.Ps)
r.Fields("id", "game_stage", "stime", "etime", "home_id", "away_id", "home_score", "away_score", "live_room", "aid", "collection", "game_state", "dic", "ctime", "mtime", "status", "sid", "mid")
if p.Sort == 1 {
r.Order("stime", elastic.OrderDesc)
} else {
r.Order("stime", elastic.OrderAsc)
}
if p.Gid > 0 {
r.WhereEq("gid", p.Gid)
}
if p.Mid > 0 {
r.WhereEq("mid", p.Mid)
}
if p.Tid > 0 {
r.WhereOr("home_id", p.Tid).WhereOr("away_id", p.Tid)
}
if p.Stime != "" && p.Etime != "" {
start, _ := time.ParseInLocation("2006-01-02 15:04:05", p.Stime+" 00:00:00", time.Local)
end, _ := time.ParseInLocation("2006-01-02 15:04:05", p.Etime+" 23:59:59", time.Local)
r.WhereRange("stime", start.Unix(), end.Unix(), elastic.RangeScopeLcRc)
} else if p.Stime != "" && p.Etime == "" {
start, _ := time.ParseInLocation("2006-01-02 15:04:05", p.Stime+" 00:00:00", time.Local)
r.WhereRange("stime", start.Unix(), "", elastic.RangeScopeLcRo)
} else if p.Stime == "" && p.Etime != "" {
end, _ := time.ParseInLocation("2006-01-02 15:04:05", p.Etime+" 23:59:59", time.Local)
r.WhereRange("stime", "", end.Unix(), elastic.RangeScopeLoRc)
}
if p.GState != "" {
r.WhereIn("game_state", strings.Split(p.GState, ","))
}
if len(p.Sids) > 0 {
r.WhereIn("sid", p.Sids)
}
if err = r.Scan(c, &res); err != nil {
log.Error("r.Scan error(%v)", err)
return
}
total = res.Page.Total
rs = res.Result
return
}
// SearchContestQuery search contest.
func (d *Dao) SearchContestQuery(c context.Context, p *model.ParamContest) (rs []*model.Contest, total int, err error) {
var res struct {
Page model.Page `json:"page"`
Result []*model.Contest `json:"result"`
}
r := d.ela.NewRequest(_contest).Index(_contest).WhereEq("status", 0).Pn(p.Pn).Ps(p.Ps)
r.Fields("id", "game_stage", "stime", "etime", "home_id", "away_id", "home_score", "away_score", "live_room", "aid", "collection", "game_state", "dic", "ctime", "mtime", "status", "sid", "mid")
if p.Sort == 1 {
r.Order("stime", elastic.OrderDesc)
} else {
r.Order("stime", elastic.OrderAsc)
}
if p.Gid > 0 {
r.WhereEq("gid", p.Gid)
}
if p.Mid > 0 {
r.WhereEq("mid", p.Mid)
}
if p.Tid > 0 {
r.WhereOr("home_id", p.Tid).WhereOr("away_id", p.Tid)
}
if p.Stime != "" && p.Etime != "" {
start, _ := time.ParseInLocation("2006-01-02 15:04:05", p.Stime, time.Local)
end, _ := time.ParseInLocation("2006-01-02 15:04:05", p.Etime, time.Local)
r.WhereRange("stime", start.Unix(), end.Unix(), elastic.RangeScopeLcRc)
} else if p.Stime != "" && p.Etime == "" {
start, _ := time.ParseInLocation("2006-01-02 15:04:05", p.Stime, time.Local)
r.WhereRange("stime", start.Unix(), "", elastic.RangeScopeLcRo)
} else if p.Stime == "" && p.Etime != "" {
end, _ := time.ParseInLocation("2006-01-02 15:04:05", p.Etime, time.Local)
r.WhereRange("stime", "", end.Unix(), elastic.RangeScopeLoRc)
}
if p.GState != "" {
r.WhereIn("game_state", strings.Split(p.GState, ","))
}
if len(p.Sids) > 0 {
r.WhereIn("sid", p.Sids)
}
if err = r.Scan(c, &res); err != nil {
log.Error("r.Scan error(%v)", err)
return
}
total = res.Page.Total
rs = res.Result
return
}
// FilterVideo video filter.
func (d *Dao) FilterVideo(c context.Context, p *model.ParamFilter) (rs *model.FilterES, err error) {
var res struct {
Page model.Page `json:"page"`
Result *model.FilterES `json:"result"`
}
r := d.ela.NewRequest(_videomap).Index(_videomap).Pn(_pageNum).Ps(_pageSize)
r.WhereEq("active", _active).GroupBy("group_by", "gid", nil).GroupBy("group_by", "match", nil).GroupBy("group_by", "tag", nil).GroupBy("group_by", "team", nil).GroupBy("group_by", "year", nil)
if p.Gid > 0 {
r.WhereEq("gid", p.Gid).WhereEq("active", _active)
}
if p.Mid > 0 {
r.WhereEq("match", p.Mid).WhereEq("active", _active)
}
if p.Tid > 0 {
r.WhereOr("team", p.Tid).WhereEq("active", _active)
}
if p.Tag > 0 {
r.WhereEq("tag", p.Tag).WhereEq("active", _active)
}
if p.Year > 0 {
r.WhereEq("year", p.Year).WhereEq("active", _active)
}
if err = r.Scan(c, &res); err != nil {
log.Error("r.Scan error(%v)", err)
return
}
rs = res.Result
return
}
// FilterMatch match filter.
func (d *Dao) FilterMatch(c context.Context, p *model.ParamFilter) (rs *model.FilterES, err error) {
var res struct {
Page model.Page `json:"page"`
Result *model.FilterES `json:"result"`
}
r := d.ela.NewRequest(_matchmap).Index(_matchmap).Pn(_pageNum).Ps(_pageSize)
r.WhereEq("active", _active).GroupBy("group_by", "match", nil).GroupBy("group_by", "gid", nil).GroupBy("group_by", "team", nil)
if p.Mid > 0 {
r.WhereEq("match", p.Mid).WhereEq("active", _active)
}
if p.Gid > 0 {
r.WhereEq("gid", p.Gid).WhereEq("active", _active)
}
if p.Tid > 0 {
r.WhereOr("team", p.Tid).WhereEq("active", _active)
}
if p.Stime != "" {
r.WhereOr("stime", p.Stime).WhereEq("active", _active)
}
if err = r.Scan(c, &res); err != nil {
log.Error("r.Scan error(%v)", err)
return
}
rs = res.Result
return
}
// FilterCale Calendar filter.
func (d *Dao) FilterCale(c context.Context, p *model.ParamFilter) (rs map[string]int64, err error) {
var res struct {
Page model.Page `json:"page"`
Result map[string]int64 `json:"result"`
}
r := d.ela.NewRequest(_calendar).Index(_matchmap).Pn(_pageNum).Ps(_pageSize).WhereEq("active", _active).WhereRange("stime", p.Stime, p.Etime, elastic.RangeScopeLcRc)
r.GroupBy("group_by", "stime", nil)
if p.Mid > 0 {
r.WhereEq("match", p.Mid).WhereEq("active", _active)
}
if p.Gid > 0 {
r.WhereEq("gid", p.Gid).WhereEq("active", _active)
}
if p.Tid > 0 {
r.WhereOr("team", p.Tid).WhereEq("active", _active)
}
if err = r.Scan(c, &res); err != nil {
log.Error("r.Scan error(%v)", err)
return
}
rs = res.Result
return
}
// SearchFav search app fav contest.
func (d *Dao) SearchFav(c context.Context, mid int64, p *model.ParamFav) (rs []int64, total int, err error) {
var res struct {
Page model.Page `json:"page"`
Result []*model.ElaSub `json:"result"`
}
r := d.ela.NewRequest(_contestFav).Index(_contestFav).WhereEq("mid", mid).WhereEq("state", 0).Pn(p.Pn).Ps(p.Ps).Fields("oid")
if p.Sort == 1 {
r.Order("stime", elastic.OrderDesc)
} else {
r.Order("stime", elastic.OrderAsc)
}
if p.Stime != "" && p.Etime != "" {
start, _ := time.ParseInLocation("2006-01-02 15:04:05", p.Stime+" 00:00:00", time.Local)
end, _ := time.ParseInLocation("2006-01-02 15:04:05", p.Etime+" 23:59:59", time.Local)
r.WhereRange("stime", start.Unix(), end.Unix(), elastic.RangeScopeLcRc)
} else if p.Stime != "" && p.Etime == "" {
start, _ := time.ParseInLocation("2006-01-02 15:04:05", p.Stime+" 00:00:00", time.Local)
r.WhereRange("stime", start.Unix(), "", elastic.RangeScopeLcRo)
} else if p.Stime == "" && p.Etime != "" {
end, _ := time.ParseInLocation("2006-01-02 15:04:05", p.Etime+" 23:59:59", time.Local)
r.WhereRange("stime", "", end.Unix(), elastic.RangeScopeLoRc)
}
if len(p.Sids) > 0 {
r.WhereIn("sid", p.Sids)
}
if err = r.Scan(c, &res); err != nil {
log.Error("r.Scan error(%v)", err)
return
}
total = res.Page.Total
if total == 0 {
return
}
for _, contest := range res.Result {
rs = append(rs, contest.Oid)
}
return
}
// SeasonFav fav season list.
func (d *Dao) SeasonFav(c context.Context, mid int64, p *model.ParamSeason) (rs []*model.ElaSub, total int, err error) {
var res struct {
Page model.Page `json:"page"`
Result []*model.ElaSub `json:"result"`
}
r := d.ela.NewRequest(_contestFav).Index(_contestFav).WhereEq("mid", mid).WhereEq("state", 0).Pn(p.Pn).Ps(p.Ps).Fields("sid", "oid")
if p.Sort == 1 {
r.Order("season_stime", elastic.OrderDesc)
} else {
r.Order("season_stime", elastic.OrderAsc)
}
if err = r.Scan(c, &res); err != nil {
log.Error("r.Scan error(%v)", err)
return
}
total = res.Page.Total
if total == 0 {
return
}
rs = res.Result
return
}
// StimeFav fav contest stime list.
func (d *Dao) StimeFav(c context.Context, mid int64, p *model.ParamSeason) (rs []*model.ElaSub, total int, err error) {
var res struct {
Page model.Page `json:"page"`
Result []*model.ElaSub `json:"result"`
}
r := d.ela.NewRequest(_contestFav).Index(_contestFav).WhereEq("mid", mid).WhereEq("state", 0).Pn(p.Pn).Ps(p.Ps).Fields("stime", "oid")
if p.Sort == 1 {
r.Order("stime", elastic.OrderDesc)
} else {
r.Order("stime", elastic.OrderAsc)
}
if err = r.Scan(c, &res); err != nil {
log.Error("r.Scan error(%v)", err)
return
}
total = res.Page.Total
if total == 0 {
return
}
rs = res.Result
return
}

View File

@@ -0,0 +1,146 @@
package dao
import (
"context"
"testing"
"go-common/app/interface/main/esports/model"
"github.com/smartystreets/goconvey/convey"
)
func TestDaoSearch(t *testing.T) {
var (
c = context.Background()
mid = int64(111)
p = &model.ParamSearch{Keyword: "test", Pn: 1, Ps: 100, Sort: 0}
buvid = ""
)
convey.Convey("Search", t, func(ctx convey.C) {
rs, err := d.Search(c, mid, p, buvid)
ctx.Convey("Then err should be nil.rs should not be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
println(rs)
})
})
}
func TestDaoSearchVideo(t *testing.T) {
var (
c = context.Background()
p = &model.ParamVideo{Pn: 1, Ps: 30}
)
convey.Convey("SearchVideo", t, func(ctx convey.C) {
rs, total, err := d.SearchVideo(c, p)
ctx.Convey("Then err should be nil.rs,total should not be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
ctx.So(total, convey.ShouldNotBeNil)
ctx.So(len(rs), convey.ShouldBeGreaterThanOrEqualTo, 0)
})
})
}
func TestDaoSearchContest(t *testing.T) {
var (
c = context.Background()
p = &model.ParamContest{Pn: 1, Ps: 30}
)
convey.Convey("SearchContest", t, func(ctx convey.C) {
rs, total, err := d.SearchContest(c, p)
ctx.Convey("Then err should be nil.rs,total should not be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
ctx.So(total, convey.ShouldNotBeNil)
ctx.So(len(rs), convey.ShouldBeGreaterThanOrEqualTo, 0)
})
})
}
func TestDaoFilterVideo(t *testing.T) {
var (
c = context.Background()
p = &model.ParamFilter{Mid: 2}
)
convey.Convey("FilterVideo", t, func(ctx convey.C) {
rs, err := d.FilterVideo(c, p)
ctx.Convey("Then err should be nil.rs should not be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
ctx.So(rs, convey.ShouldNotBeNil)
})
})
}
func TestDaoFilterMatch(t *testing.T) {
var (
c = context.Background()
p = &model.ParamFilter{}
)
convey.Convey("FilterMatch", t, func(ctx convey.C) {
rs, err := d.FilterMatch(c, p)
ctx.Convey("Then err should be nil.rs should not be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
ctx.So(rs, convey.ShouldNotBeNil)
})
})
}
func TestDaoFilterCale(t *testing.T) {
var (
c = context.Background()
p = &model.ParamFilter{}
)
convey.Convey("FilterCale", t, func(ctx convey.C) {
rs, err := d.FilterCale(c, p)
ctx.Convey("Then err should be nil.rs should not be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
ctx.So(len(rs), convey.ShouldBeGreaterThanOrEqualTo, 0)
})
})
}
func TestDaoSearchFav(t *testing.T) {
var (
c = context.Background()
mid = int64(111)
p = &model.ParamFav{Pn: 1, Ps: 30}
)
convey.Convey("SearchFav", t, func(ctx convey.C) {
rs, total, err := d.SearchFav(c, mid, p)
ctx.Convey("Then err should be nil.rs,total should not be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
ctx.So(total, convey.ShouldNotBeNil)
ctx.So(len(rs), convey.ShouldBeGreaterThanOrEqualTo, 0)
})
})
}
func TestDaoSeasonFav(t *testing.T) {
var (
c = context.Background()
mid = int64(111)
p = &model.ParamSeason{Pn: 1, Ps: 30}
)
convey.Convey("SeasonFav", t, func(ctx convey.C) {
rs, total, err := d.SeasonFav(c, mid, p)
ctx.Convey("Then err should be nil.rs,total should not be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
ctx.So(total, convey.ShouldNotBeNil)
ctx.So(len(rs), convey.ShouldBeGreaterThanOrEqualTo, 0)
})
})
}
func TestDaoStimeFav(t *testing.T) {
var (
c = context.Background()
mid = int64(111)
p = &model.ParamSeason{Pn: 1, Ps: 30}
)
convey.Convey("StimeFav", t, func(ctx convey.C) {
rs, total, err := d.StimeFav(c, mid, p)
ctx.Convey("Then err should be nil.rs,total should not be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
ctx.So(total, convey.ShouldNotBeNil)
ctx.So(len(rs), convey.ShouldBeGreaterThanOrEqualTo, 0)
})
})
}