Initial commit

This commit is contained in:
Donny
2019-04-22 20:46:32 +08:00
commit 49ab8aadd1
25441 changed files with 4055000 additions and 0 deletions

View File

@@ -0,0 +1,84 @@
load(
"@io_bazel_rules_go//go:def.bzl",
"go_test",
"go_library",
)
go_test(
name = "go_default_test",
srcs = [
"archive_test.go",
"audit_result_test.go",
"dao_test.go",
"full_test.go",
"modules_test.go",
"panel_test.go",
"pgc_cond_test.go",
"playurl_test.go",
"region_test.go",
"sear_inter_test.go",
"upbfs_test.go",
"upper_test.go",
"user_test.go",
],
embed = [":go_default_library"],
rundir = ".",
tags = ["automanaged"],
deps = [
"//app/admin/main/tv/conf:go_default_library",
"//app/admin/main/tv/model:go_default_library",
"//library/log:go_default_library",
"//vendor/github.com/smartystreets/goconvey/convey:go_default_library",
"//vendor/gopkg.in/h2non/gock.v1:go_default_library",
],
)
go_library(
name = "go_default_library",
srcs = [
"archive.go",
"audit_result.go",
"dao.go",
"full.go",
"mango.go",
"modules.go",
"panel.go",
"pgc_cond.go",
"playurl.go",
"region.go",
"sear_inter.go",
"upbfs.go",
"upper.go",
"user.go",
],
importpath = "go-common/app/admin/main/tv/dao",
tags = ["automanaged"],
visibility = ["//visibility:public"],
deps = [
"//app/admin/main/tv/conf:go_default_library",
"//app/admin/main/tv/model:go_default_library",
"//library/cache/memcache:go_default_library",
"//library/database/elastic:go_default_library",
"//library/database/orm:go_default_library",
"//library/ecode:go_default_library",
"//library/log:go_default_library",
"//library/net/http/blademaster:go_default_library",
"//library/time:go_default_library",
"//vendor/github.com/jinzhu/gorm: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"],
)

View File

@@ -0,0 +1,12 @@
package dao
const (
_setManual = "REPLACE INTO ugc_archive (aid, manual, deleted) VALUES (?,?,?)"
_needImport = 1
_notDeleted = 0
)
// NeedImport sets the archive as manual, if it's deleted, we recover it
func (d *Dao) NeedImport(aid int64) (err error) {
return d.DB.Exec(_setManual, aid, _needImport, _notDeleted).Error
}

View File

@@ -0,0 +1,14 @@
package dao
import (
"testing"
. "github.com/smartystreets/goconvey/convey"
)
func TestDao_ArchiveAdd(t *testing.T) {
Convey("TestDao_ArchiveAdd", t, WithDao(func(d *Dao) {
err := d.NeedImport(123)
So(err, ShouldBeNil)
}))
}

View File

@@ -0,0 +1,53 @@
package dao
import (
"context"
"fmt"
"go-common/app/admin/main/tv/model"
"go-common/library/database/elastic"
"go-common/library/log"
)
// ArcES treats the ugc index request and call the ES to get the result
func (d *Dao) ArcES(c context.Context, req *model.ReqArcES) (data *model.EsUgcResult, err error) {
var (
cfg = d.c.Cfg.EsIdx.UgcIdx
r = d.esClient.NewRequest(cfg.Business).Index(cfg.Index).WhereEq("deleted", 0)
)
if req.Valid != "" {
r = r.WhereEq("valid", req.Valid)
}
if req.AID != "" {
r = r.WhereEq("aid", req.AID)
}
if req.Result != "" {
r = r.WhereEq("result", req.Result)
}
if len(req.Typeids) != 0 {
r = r.WhereIn("typeid", req.Typeids)
}
if req.Title != "" {
r = r.WhereLike([]string{"title"}, []string{req.Title}, true, elastic.LikeLevelMiddle)
}
if len(req.Mids) != 0 {
r = r.WhereIn("mid", req.Mids)
}
r.Ps(req.Ps).Pn(int(req.Pn))
if req.MtimeOrder != "" {
r = r.Order("mtime", req.MtimeSort())
}
if req.PubtimeOrder != "" {
r = r.Order("pubtime", req.PubtimeSort())
}
if err = r.Scan(c, &data); err != nil {
log.Error("ArcES:Scan params(%s) error(%v)", r.Params(), err)
return
}
if data == nil || data.Page == nil {
err = fmt.Errorf("data or data.Page nil")
log.Error("ArcES params(%s) error(%v)", r.Params(), err)
return
}
return
}

View File

@@ -0,0 +1,31 @@
package dao
import (
"context"
"go-common/app/admin/main/tv/model"
"testing"
"github.com/smartystreets/goconvey/convey"
)
func TestDaoArcES(t *testing.T) {
var (
c = context.Background()
req = &model.ReqArcES{
AID: "10110475",
Valid: "1",
Result: "1",
Mids: []int64{477132},
Typeids: []int32{24},
MtimeOrder: "1",
PubtimeOrder: "1",
}
)
convey.Convey("ArcES", t, func(ctx convey.C) {
data, err := d.ArcES(c, req)
ctx.Convey("Then err should be nil.data should not be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
ctx.So(data, convey.ShouldNotBeNil)
})
})
}

View File

@@ -0,0 +1,61 @@
package dao
import (
"net/http"
"time"
"go-common/app/admin/main/tv/conf"
"go-common/library/cache/memcache"
"go-common/library/database/elastic"
"go-common/library/database/orm"
httpx "go-common/library/net/http/blademaster"
"github.com/jinzhu/gorm"
)
// Dao struct user of Dao.
type Dao struct {
c *conf.Config
// db
DB *gorm.DB
// dbshow
DBShow *gorm.DB
fullURL string
httpSearch *httpx.Client
client *httpx.Client
bfsClient *http.Client
esClient *elastic.Elastic
// memcache
mc *memcache.Pool
cmsExpire int32
}
// New create a instance of Dao and return.
func New(c *conf.Config) (d *Dao) {
d = &Dao{
// conf
c: c,
// db
DB: orm.NewMySQL(c.ORM),
// dbshow
DBShow: orm.NewMySQL(c.ORMShow),
// http client
fullURL: c.HTTPSearch.FullURL,
httpSearch: httpx.NewClient(c.HTTPSearch.ClientConfig),
client: httpx.NewClient(c.HTTPClient),
bfsClient: &http.Client{Timeout: time.Duration(c.Bfs.Timeout) * time.Millisecond},
esClient: elastic.NewElastic(&elastic.Config{
Host: c.Cfg.Hosts.Manager,
HTTPClient: c.HTTPClient,
}),
mc: memcache.NewPool(c.Memcache.Config),
cmsExpire: int32(time.Duration(c.Memcache.CmsExpire) / time.Second),
}
d.initORM()
return
}
func (d *Dao) initORM() {
d.DB.LogMode(true)
d.DBShow.LogMode(true)
}

View File

@@ -0,0 +1,75 @@
package dao
import (
"context"
"encoding/json"
"fmt"
"os"
"strings"
"testing"
"go-common/app/admin/main/tv/conf"
"flag"
. "github.com/smartystreets/goconvey/convey"
"gopkg.in/h2non/gock.v1"
)
var d *Dao
func init() {
// dir, _ := filepath.Abs("../cmd/tv-admin-test.toml")
// flag.Set("conf", dir)
if os.Getenv("DEPLOY_ENV") != "" {
flag.Set("app_id", "main.web-svr.tv-admin")
flag.Set("conf_token", "3d446a004187a6572d656bab1dbff1b0")
flag.Set("tree_id", "15310")
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")
}
flag.Parse()
if err := conf.Init(); err != nil {
panic(err)
}
d = New(conf.Conf)
}
func WithDao(f func(d *Dao)) func() {
return func() {
Reset(func() {})
f(d)
}
}
func httpMock(method, url string) *gock.Request {
r := gock.New(url)
r.Method = strings.ToUpper(method)
d.client.SetTransport(gock.DefaultTransport)
d.httpSearch.SetTransport(gock.DefaultTransport)
d.bfsClient.Transport = gock.DefaultTransport
return r
}
func TestDao_MaxOrder(t *testing.T) {
Convey("TestDao_MaxOrder", t, WithDao(func(d *Dao) {
order := d.MaxOrder(context.Background())
So(order, ShouldBeGreaterThan, 0)
fmt.Println(order)
}))
}
func TestDao_MangoRecom(t *testing.T) {
Convey("TestDao_MangoRecom", t, WithDao(func(d *Dao) {
err := d.MangoRecom(context.Background(), []int64{3, 4, 5})
So(err, ShouldBeNil)
res, err2 := d.GetMRecom(context.Background())
So(err2, ShouldBeNil)
data, _ := json.Marshal(res)
fmt.Println(string(data))
}))
}

View File

@@ -0,0 +1,38 @@
package dao
import (
"context"
"fmt"
"net/url"
"go-common/app/admin/main/tv/model"
"go-common/library/ecode"
"go-common/library/log"
)
type msgReturn struct {
Code int `json:"code"`
Message string `json:"message"`
Data []*model.APKInfo `json:"data"`
}
// FullImport .
func (d *Dao) FullImport(c context.Context, build int) (result []*model.APKInfo, err error) {
var (
res = &msgReturn{}
fullURL = d.fullURL
)
params := url.Values{}
params.Set("version_code", fmt.Sprintf("%d", build))
err = d.httpSearch.Get(c, fullURL, "", params, res)
if err != nil {
log.Error("d.httpSearch.Get(%s) error(%v)", fullURL+"?"+params.Encode(), err)
return
}
result = res.Data
if res.Code != ecode.OK.Code() {
err = fmt.Errorf("return code:%d", res.Code)
log.Error("d.httpSearch.Get(%s) error(%v)", fullURL+"?"+params.Encode(), err)
}
return
}

View File

@@ -0,0 +1,33 @@
package dao
import (
"context"
"testing"
"github.com/smartystreets/goconvey/convey"
)
func TestDaoFullImport(t *testing.T) {
var (
c = context.Background()
build = int(0)
)
convey.Convey("FullImport", t, func(ctx convey.C) {
ctx.Convey("Http code err", func(ctx convey.C) {
httpMock("GET", d.fullURL).Reply(-400).JSON(``)
_, err := d.FullImport(c, build)
ctx.So(err, convey.ShouldNotBeNil)
})
ctx.Convey("Business code err", func(ctx convey.C) {
httpMock("GET", d.fullURL).Reply(200).JSON(`{"code":-400}`)
_, err := d.FullImport(c, build)
ctx.So(err, convey.ShouldNotBeNil)
})
ctx.Convey("Everything goes well", func(ctx convey.C) {
httpMock("GET", d.fullURL).Reply(200).JSON(`{"code":0,"data":[{"id":1}]}`)
data, err := d.FullImport(c, build)
ctx.So(err, convey.ShouldBeNil)
ctx.So(data, convey.ShouldNotBeNil)
})
})
}

View File

@@ -0,0 +1,72 @@
package dao
import (
"context"
"encoding/json"
"time"
"go-common/app/admin/main/tv/model"
"go-common/library/cache/memcache"
"go-common/library/log"
bm "go-common/library/net/http/blademaster"
xtime "go-common/library/time"
)
const (
_mangoKey = "mango_cms_recom"
_delRecom = "UPDATE mango_recom SET deleted = 1 WHERE id = ?"
_maxOrder = "SELECT MAX(rorder) AS ord FROM mango_recom WHERE deleted = 0"
)
//MangoRecom is used to set mango recom cache in MC
func (d *Dao) MangoRecom(c context.Context, ids []int64) (err error) {
conn := d.mc.Get(c)
defer conn.Close()
mcItem := &model.MRecomMC{
RIDs: ids,
Pubtime: xtime.Time(time.Now().Unix()),
}
itemJSON := &memcache.Item{
Key: _mangoKey,
Object: mcItem,
Flags: memcache.FlagJSON,
Expiration: 0,
}
if err = conn.Set(itemJSON); err != nil {
log.Error("MangoRecom Ids %v, Err %v", ids, err)
}
return
}
// GetMRecom get mango recom mc data
func (d *Dao) GetMRecom(c context.Context) (res *model.MRecomMC, err error) {
var item *memcache.Item
conn := d.mc.Get(c)
defer conn.Close()
if item, err = conn.Get(_mangoKey); err != nil {
log.Error("GetMRecom MangoKey, Err %v", _mangoKey, err)
return
}
err = json.Unmarshal(item.Value, &res)
return
}
// DelMRecom deletes an mango recom position
func (d *Dao) DelMRecom(c *bm.Context, id int64) (err error) {
if err = d.DB.Exec(_delRecom, id).Error; err != nil {
log.Error("DelMRecom Error %v", err)
}
return
}
// MaxOrder picks the max rorder from the table
func (d *Dao) MaxOrder(ctx context.Context) int {
var maxR = new(struct {
Ord int
})
if err := d.DB.Raw(_maxOrder).Scan(&maxR).Error; err != nil {
log.Error("MaxOrder Error %v", err)
return 0
}
return maxR.Ord
}

View File

@@ -0,0 +1,44 @@
package dao
import (
"context"
"go-common/app/admin/main/tv/model"
"go-common/library/cache/memcache"
)
//ModulePublish is used for module status MC key
const ModulePublish = "ModulePublish"
//SetModPub is used for set module publish status to MC
func (d *Dao) SetModPub(c context.Context, pageID string, p model.ModPub) (err error) {
conn := d.mc.Get(c)
defer conn.Close()
itemJSON := &memcache.Item{
Key: ModulePublish + pageID,
Object: p,
Flags: memcache.FlagJSON,
Expiration: 0,
}
if err = conn.Set(itemJSON); err != nil {
return
}
return
}
//GetModPub is used for getting module publish status
func (d *Dao) GetModPub(c context.Context, pageID string) (p model.ModPub, err error) {
var (
conn memcache.Conn
item *memcache.Item
)
conn = d.mc.Get(c)
defer conn.Close()
k := ModulePublish + pageID
if item, err = conn.Get(k); err != nil {
return
}
if err = conn.Scan(item, &p); err != nil {
return
}
return
}

View File

@@ -0,0 +1,43 @@
package dao
import (
"go-common/app/admin/main/tv/model"
"testing"
"time"
"context"
"github.com/smartystreets/goconvey/convey"
)
func TestDaoSetModulePublishCache(t *testing.T) {
var (
c = context.Background()
pageID = "18"
p = model.ModPub{
Time: time.Now().Format("2006-01-02 15:04:05"),
State: 1,
}
)
convey.Convey("SetModPub", t, func(ctx convey.C) {
err := d.SetModPub(c, pageID, p)
ctx.Convey("Then err should be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
})
})
}
func TestDaoGetModulePublishCache(t *testing.T) {
var (
c = context.Background()
pageID = "18"
)
convey.Convey("GetModPub", t, func(ctx convey.C) {
p, err := d.GetModPub(c, pageID)
ctx.Convey("Then err should be nil.p should not be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
ctx.So(p, convey.ShouldNotBeNil)
})
})
}

View File

@@ -0,0 +1,52 @@
package dao
import (
"go-common/app/admin/main/tv/model"
"go-common/library/log"
)
const (
_configTableName = "tv_price_config"
_valid = 0
_invalid = 1
)
// GetById select panel info by id
func (d *Dao) GetById(id int64) (panelInfo *model.TvPriceConfigResp, err error) {
panelInfo = &model.TvPriceConfigResp{}
if err = d.DB.Table(_configTableName).Where("id = ? and status in (?, ?)", id, _valid, _invalid).First(panelInfo).Error; err != nil {
log.Error("GetById (%v) error(%v)", panelInfo, err)
}
return
}
// PanelStatus update panel status info by id
func (d *Dao) PanelStatus(id, status int64) (err error) {
if err = d.DB.Table(_configTableName).Where("id = ? and status in (?, ?)", id, _valid, _invalid).Update("status", status).Error; err != nil {
log.Error("PanelStatus (%v) error(%v)", id, err)
}
return
}
// SavePanel update or add panel info
func (d *Dao) SavePanel(panel *model.TvPriceConfig) (err error) {
if err = d.DB.Save(panel).Error; err != nil {
log.Error("SavePanel (%v) error(%v)", panel, err)
return err
}
return
}
// ExistProduct check duplicated productId, productName
func (d *Dao) ExistProduct(productID string) (flag bool) {
panel := []model.TvPriceConfig{}
if err := d.DB.Table(_configTableName).Where("status in (?, ?) and product_id = ?", _valid, _invalid, productID).Find(&panel).Error; err != nil {
log.Error("HasDiscount %v, Err %v", productID, err)
return false
}
return !(len(panel) == 0)
}

View File

@@ -0,0 +1,67 @@
package dao
import (
"testing"
"go-common/app/admin/main/tv/model"
"github.com/smartystreets/goconvey/convey"
)
func TestDaoSavePanel(t *testing.T) {
convey.Convey("SavePanel", t, func(ctx convey.C) {
var (
panel = &model.TvPriceConfig{ID: 100000000}
)
ctx.Convey("When everything gose positive", func(ctx convey.C) {
err := d.SavePanel(panel)
ctx.Convey("Then err should be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
})
})
})
}
func TestDaoGetById(t *testing.T) {
convey.Convey("GetById", t, func(ctx convey.C) {
var (
id = int64(100000000)
)
ctx.Convey("When everything gose positive", func(ctx convey.C) {
panelInfo, err := d.GetById(id)
ctx.Convey("Then err should be nil.panelInfo should not be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
ctx.So(panelInfo, convey.ShouldNotBeNil)
})
})
})
}
func TestDaoPanelStatus(t *testing.T) {
convey.Convey("PanelStatus", t, func(ctx convey.C) {
var (
id = int64(100000000)
status = int64(2)
)
ctx.Convey("When everything gose positive", func(ctx convey.C) {
err := d.PanelStatus(id, status)
ctx.Convey("Then err should be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
})
})
})
}
func TestDaoExistProduct(t *testing.T) {
convey.Convey("ExistProduct", t, func(ctx convey.C) {
var (
productID = ""
)
ctx.Convey("When everything gose positive", func(ctx convey.C) {
flag := d.ExistProduct(productID)
ctx.Convey("Then flag should not be nil.", func(ctx convey.C) {
ctx.So(flag, convey.ShouldNotBeNil)
})
})
})
}

View File

@@ -0,0 +1,31 @@
package dao
import (
"context"
"fmt"
"net/url"
"go-common/app/admin/main/tv/model"
"go-common/library/ecode"
"github.com/pkg/errors"
)
// PgcCond picks pgc condition
func (d *Dao) PgcCond(c context.Context, snType int32) (result *model.PgcCond, err error) {
var (
host = d.c.Cfg.RefLabel.PgcAPI
params = url.Values{}
resp = model.PgcCondResp{}
)
params.Set("season_type", fmt.Sprintf("%d", snType))
if err = d.client.Get(c, host, "", params, &resp); err != nil {
return
}
if resp.Code != ecode.OK.Code() {
err = errors.Wrapf(ecode.Int(resp.Code), resp.Message)
return
}
result = resp.Result
return
}

View File

@@ -0,0 +1,23 @@
package dao
import (
"context"
"testing"
"github.com/smartystreets/goconvey/convey"
)
func TestDaoPgcCond(t *testing.T) {
var (
c = context.Background()
snType = int32(1)
)
convey.Convey("PgcCond", t, func(ctx convey.C) {
httpMock("GET", d.c.Cfg.RefLabel.PgcAPI).Reply(200).JSON(`{"code":0,"message":"success","result":{"filter":[{"id":"area","name":"地区","value":[{"id":"-1","name":"全部"},{"id":"1","name":"中国大陆"},{"id":"6,7","name":"中国港台"},{"id":"3","name":"美国"},{"id":"2","name":"日本"},{"id":"8","name":"韩国"},{"id":"9","name":"法国"},{"id":"4","name":"英国"},{"id":"15","name":"德国"},{"id":"10","name":"泰国"},{"id":"35","name":"意大利"},{"id":"13","name":"西班牙"},{"id":"5,11,12,14,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52","name":"其他国家"}]},{"id":"style_id","name":"风格","value":[{"id":"-1","name":"全部"},{"id":"460","name":"剧情"},{"id":"480","name":"喜剧"},{"id":"490","name":"爱情"},{"id":"500","name":"动作"},{"id":"510","name":"恐怖"},{"id":"520","name":"科幻"},{"id":"530","name":"犯罪"},{"id":"540","name":"惊悚"},{"id":"550","name":"悬疑"},{"id":"560","name":"奇幻"},{"id":"600","name":"战争"},{"id":"610","name":"动画"},{"id":"620","name":"传记"},{"id":"630","name":"家庭"},{"id":"640","name":"歌舞"},{"id":"650","name":"历史"},{"id":"730","name":"漫画改"}]},{"id":"year","name":"年份","value":[{"id":"-1","name":"全部"},{"id":"2018","name":"2018"},{"id":"2017","name":"2017"},{"id":"2016","name":"2016"},{"id":"2015","name":"2015"},{"id":"2014","name":"2014"},{"id":"2013-2010","name":"2013-2010"},{"id":"2009-2005","name":"2009-2005"},{"id":"2004-2000","name":"2004-2000"},{"id":"90年代","name":"90年代"},{"id":"80年代","name":"80年代"},{"id":"更早","name":"更早"}]},{"id":"season_status","name":"付费","value":[{"id":"-1","name":"全部"},{"id":"1","name":"免费"},{"id":"2,6","name":"付费"},{"id":"4,6","name":"大会员"}]}],"order":{"name":"排序","value":[{"id":"2","name":"播放数量","sort":"0,1"},{"id":"0","name":"更新时间","sort":"0,1"},{"id":"6","name":"上映时间","sort":"0,1"}]}}}`)
result, err := d.PgcCond(c, snType)
ctx.Convey("Then err should be nil.result should not be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
ctx.So(result, convey.ShouldNotBeNil)
})
})
}

View File

@@ -0,0 +1,72 @@
package dao
import (
"context"
"fmt"
"net/url"
"go-common/app/admin/main/tv/model"
"go-common/library/log"
)
const _type = "mp4"
const _maxBackup = 0
const _otype = "json"
const _qn = "16"
// Playurl Def.
func (d *Dao) Playurl(ctx context.Context, cid int) (playurl string, err error) {
var (
result = model.PlayurlResp{}
params = url.Values{}
api = d.c.Cfg.PlayurlAPI
)
params.Set("cid", fmt.Sprintf("%d", cid))
params.Set("type", _type) // to get one piece
params.Set("max_backup", fmt.Sprintf("%d", _maxBackup)) // no backup url needed
params.Set("otype", _otype) // json format response
params.Set("qn", _qn) // json format response
if err = d.client.Get(ctx, api, "", params, &result); err != nil {
log.Error("ClientGet error[%v]", err)
return
}
if result.Code != 0 { // logic error
err = fmt.Errorf("Resp Code:[%v], Message:[%v]", result.Code, result.Message)
return
}
if len(result.Durl) < 1 { // result empty
err = fmt.Errorf("Playurl Result is Empty! Resp (%v)", result)
return
}
playurl = result.Durl[0].URL
return
}
//UPlayurl ugc play url
func (d *Dao) UPlayurl(ctx context.Context, cid int) (playurl string, err error) {
var (
result = model.UPlayURLR{}
params = url.Values{}
api = d.c.Cfg.UPlayurlAPI
)
params.Set("cid", fmt.Sprintf("%d", cid))
params.Set("type", "mp4")
params.Set("max_backup", fmt.Sprintf("%d", 0))
params.Set("otype", "json")
params.Set("qn", "16")
params.Set("platform", "tvproj")
if err = d.client.Get(ctx, api, "", params, &result); err != nil {
log.Error("UPlayurl ClientGet error[%v]", err)
return
}
if result.Code != 0 { // logic error
err = fmt.Errorf("UPlayurl Resp Code:[%v], Message:[%v], Result:[%v]", result.Code, result.Message, result.Result)
return
}
if len(result.Durl) < 1 { // result empty
err = fmt.Errorf("UPlayurl Result is Empty! Resp (%v)", result)
return
}
playurl = result.Durl[0].URL
return
}

View File

@@ -0,0 +1,64 @@
package dao
import (
"context"
"testing"
"github.com/smartystreets/goconvey/convey"
)
func TestDaoPlayurl(t *testing.T) {
var (
ctx = context.Background()
cid = int(0)
normalStr = `{"Code":0,"Durl":[{"URL":"test"}]}`
httpStr = `{"Code":-400,"Durl":[{"URL":"test"}]}`
emptyStr = `{"Code":0,"Durl":[]}`
)
convey.Convey("Playurl", t, func(cx convey.C) {
cx.Convey("Normal Situation. Then err should be nil.playurl should not be nil.", func(cx convey.C) {
httpMock("GET", d.c.Cfg.PlayurlAPI).Reply(200).JSON(normalStr)
playurl, err := d.Playurl(ctx, cid)
cx.So(err, convey.ShouldBeNil)
cx.So(playurl, convey.ShouldNotBeNil)
})
cx.Convey("Http Err Situation. Then err should be nil.playurl should not be nil.", func(cx convey.C) {
httpMock("GET", d.c.Cfg.PlayurlAPI).Reply(200).JSON(httpStr)
_, err := d.Playurl(ctx, cid)
cx.So(err, convey.ShouldNotBeNil)
})
cx.Convey("Empty Durl Situation. Then err should be nil.playurl should not be nil.", func(cx convey.C) {
httpMock("GET", d.c.Cfg.PlayurlAPI).Reply(200).JSON(emptyStr)
_, err := d.Playurl(ctx, cid)
cx.So(err, convey.ShouldNotBeNil)
})
})
}
func TestDaoUPlayurl(t *testing.T) {
var (
ctx = context.Background()
cid = int(0)
normalStr = `{"Code":0,"Durl":[{"URL":"test"}]}`
httpStr = `{"Code":-400,"Durl":[{"URL":"test"}]}`
emptyStr = `{"Code":0,"Durl":[]}`
)
convey.Convey("UPlayurl", t, func(cx convey.C) {
cx.Convey("Normal Situation. Then err should be nil.playurl should not be nil.", func(cx convey.C) {
httpMock("GET", d.c.Cfg.UPlayurlAPI).Reply(200).JSON(normalStr)
playurl, err := d.UPlayurl(ctx, cid)
cx.So(err, convey.ShouldBeNil)
cx.So(playurl, convey.ShouldNotBeNil)
})
cx.Convey("Http Err Situation. Then err should be nil.playurl should not be nil.", func(cx convey.C) {
httpMock("GET", d.c.Cfg.UPlayurlAPI).Reply(200).JSON(httpStr)
_, err := d.UPlayurl(ctx, cid)
cx.So(err, convey.ShouldNotBeNil)
})
cx.Convey("Empty Durl Situation. Then err should be nil.playurl should not be nil.", func(cx convey.C) {
httpMock("GET", d.c.Cfg.UPlayurlAPI).Reply(200).JSON(emptyStr)
_, err := d.UPlayurl(ctx, cid)
cx.So(err, convey.ShouldNotBeNil)
})
})
}

View File

@@ -0,0 +1,84 @@
package dao
import (
"context"
"go-common/app/admin/main/tv/model"
"go-common/library/ecode"
"go-common/library/log"
)
const (
_addRegSQL = `INSERT INTO tv_pages (page_id,title,index_type,index_tid,rank) VALUES (?,?,?,?,?)`
_editRegSQL = `UPDATE tv_pages SET title=?,index_type=?,index_tid=? WHERE page_id=?`
_del = 0
_firpid = 1
)
// RegList region list .
func (d *Dao) RegList(ctx context.Context, arg *model.Param) (res []*model.RegDB, err error) {
if arg.PageID != "" {
if err = d.DB.Where("page_id=? AND deleted=?", arg.PageID, _del).Find(&res).Error; err != nil {
log.Error("d.DB.Where error(%v)", err)
}
} else {
if arg.State == "2" {
if err = d.DB.Order("rank ASC", true).Where("title LIKE ? AND deleted=?", "%"+arg.Title+"%", _del).Find(&res).Error; err != nil {
log.Error("d.DB.Where error(%v)", err)
}
return
}
if err = d.DB.Order("rank ASC", true).Where("title LIKE ? AND deleted=? AND valid=?", "%"+arg.Title+"%", _del, arg.State).Find(&res).Error; err != nil {
log.Error("d.DB.Order Where error(%v)", err)
}
}
return
}
// AddReg add region .
func (d *Dao) AddReg(ctx context.Context, title, itype, itid, rank string) (err error) {
var (
pid int
res = &model.RegDB{}
)
tx := d.DB.Begin()
if err = d.DB.Order("page_id DESC", true).First(res).Error; err != nil || res == nil {
if err == ecode.NothingFound {
if err = d.DB.Exec(_addRegSQL, _firpid, title, itype, itid, rank).Error; err != nil {
log.Error(" d.DB.Exec error(%v)", err)
tx.Rollback()
return
}
tx.Commit()
return
}
log.Error(" d.DB.Order error(%v)", err)
tx.Rollback()
return
}
pid = res.PageID + 1
if err = d.DB.Exec(_addRegSQL, pid, title, itype, itid, rank).Error; err != nil {
log.Error(" d.DB.Exec error(%v)", err)
tx.Rollback()
return
}
tx.Commit()
return
}
// EditReg edit region .
func (d *Dao) EditReg(ctx context.Context, pid, title, itype, itid string) (err error) {
if err = d.DB.Exec(_editRegSQL, title, itype, itid, pid).Error; err != nil {
log.Error(" d.DB.Exec error(%v)", err)
}
return
}
// UpState publish or not .
func (d *Dao) UpState(ctx context.Context, pids []int, state string) (err error) {
m := map[string]string{"valid": state}
if err = d.DB.Table("tv_pages").Where("page_id IN (?)", pids).Updates(m).Error; err != nil {
log.Error(" d.DB.Table.Where.Updates error(%v)", err)
}
return
}

View File

@@ -0,0 +1,78 @@
package dao
import (
"context"
"testing"
"go-common/app/admin/main/tv/model"
"github.com/smartystreets/goconvey/convey"
)
func TestDaoRegList(t *testing.T) {
convey.Convey("RegList", t, func(ctx convey.C) {
var (
c = context.Background()
arg = &model.Param{PageID: "1"}
)
ctx.Convey("When everything goes positive", func(ctx convey.C) {
res, err := d.RegList(c, arg)
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 TestDaoAddReg(t *testing.T) {
convey.Convey("AddReg", t, func(ctx convey.C) {
var (
c = context.Background()
title = "1"
itype = "1"
itid = "1"
rank = "1"
)
ctx.Convey("When everything goes positive", func(ctx convey.C) {
err := d.AddReg(c, title, itype, itid, rank)
ctx.Convey("Then err should be nil.", func(ctx convey.C) {
println(err)
})
})
})
}
func TestDaoEditReg(t *testing.T) {
convey.Convey("EditReg", t, func(ctx convey.C) {
var (
c = context.Background()
pid = "1"
title = "1"
itype = "1"
itid = "1"
)
ctx.Convey("When everything goes positive", func(ctx convey.C) {
err := d.EditReg(c, pid, title, itype, itid)
ctx.Convey("Then err should be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
})
})
})
}
func TestDaoUpState(t *testing.T) {
convey.Convey("UpState", t, func(ctx convey.C) {
var (
c = context.Background()
pids = []int{1}
state = "0"
)
ctx.Convey("When everything goes positive", func(ctx convey.C) {
err := d.UpState(c, pids, state)
ctx.Convey("Then err should be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
})
})
})
}

View File

@@ -0,0 +1,93 @@
package dao
import (
"encoding/json"
"context"
"go-common/app/admin/main/tv/model"
"go-common/library/cache/memcache"
)
//SiMcOutKey is used for tv search intervene key with MC
const SiMcOutKey = "_tv_search"
//SiMcStateKey is used for tv search intervene publish status key with MC
const SiMcStateKey = "_tv_search_state"
// SetSearchInterv is used for setting search inter rank cache
func (d *Dao) SetSearchInterv(c context.Context, rank []*model.OutSearchInter) (err error) {
var (
conn memcache.Conn
item *memcache.Item
bs []byte
)
bs, err = json.Marshal(rank)
if err != nil {
return
}
conn = d.mc.Get(c)
defer conn.Close()
item = &memcache.Item{
Key: SiMcOutKey,
Value: bs,
Expiration: 0,
}
err = conn.Set(item)
return
}
// GetSearchInterv is used for getting search inter rank cache
func (d *Dao) GetSearchInterv(c context.Context) (rank []*model.OutSearchInter, err error) {
var (
conn memcache.Conn
item *memcache.Item
)
conn = d.mc.Get(c)
defer conn.Close()
if item, err = conn.Get(SiMcOutKey); err != nil {
return
}
if err = json.Unmarshal(item.Value, &rank); err != nil {
return
}
return
}
// SetPublishCache is used for setting publish status
func (d *Dao) SetPublishCache(c context.Context, state *model.PublishStatus) (err error) {
var (
conn memcache.Conn
item *memcache.Item
bs []byte
)
bs, err = json.Marshal(state)
if err != nil {
return
}
conn = d.mc.Get(c)
defer conn.Close()
item = &memcache.Item{
Key: SiMcStateKey,
Value: bs,
Expiration: 0,
}
err = conn.Set(item)
return
}
// GetPublishCache is used for getting search inter rank cache
func (d *Dao) GetPublishCache(c context.Context) (state *model.PublishStatus, err error) {
var (
conn memcache.Conn
item *memcache.Item
)
conn = d.mc.Get(c)
defer conn.Close()
if item, err = conn.Get(SiMcStateKey); err != nil {
return
}
if err = json.Unmarshal(item.Value, &state); err != nil {
return
}
return
}

View File

@@ -0,0 +1,70 @@
package dao
import (
"context"
"testing"
"time"
"go-common/app/admin/main/tv/model"
"github.com/smartystreets/goconvey/convey"
)
func TestDaoSetSearInterRankCache(t *testing.T) {
var (
c = context.Background()
rank = []*model.OutSearchInter{}
)
convey.Convey("SetSearchInterv", t, func(ctx convey.C) {
rank = append(rank, &model.OutSearchInter{
Keyword: "key",
Status: "1",
})
err := d.SetSearchInterv(c, rank)
ctx.Convey("Then err should be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
})
})
}
func TestDaoGetSearInterRankCache(t *testing.T) {
var (
c = context.Background()
)
convey.Convey("GetSearchInterv", t, func(ctx convey.C) {
rank, err := d.GetSearchInterv(c)
ctx.Convey("Then err should be nil.rank should not be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
ctx.So(rank, convey.ShouldNotBeNil)
})
})
}
func TestDaoSetPublishCache(t *testing.T) {
var (
c = context.Background()
state = &model.PublishStatus{
Time: time.Now().Format("2006-01-02 15:04:05"),
State: 1,
}
)
convey.Convey("SetPublishCache", t, func(ctx convey.C) {
err := d.SetPublishCache(c, state)
ctx.Convey("Then err should be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
})
})
}
func TestDaoGetPublishCache(t *testing.T) {
var (
c = context.Background()
)
convey.Convey("GetPublishCache", t, func(ctx convey.C) {
state, err := d.GetPublishCache(c)
ctx.Convey("Then err should be nil.state should not be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
ctx.So(state, convey.ShouldNotBeNil)
})
})
}

View File

@@ -0,0 +1,83 @@
package dao
import (
"context"
"crypto/hmac"
"crypto/sha1"
"encoding/base64"
"fmt"
"hash"
"net/http"
"strconv"
"bytes"
"go-common/library/ecode"
"go-common/library/log"
)
const (
_uploadURL = "/bfs/%s/%s"
_template = "%s\n%s\n%s\n%d\n"
_method = "PUT"
)
// Upload uploads cover to bfs
func (d *Dao) Upload(c context.Context, fileName string, fileType string, timing int64, data []byte) (location string, err error) {
bfs := d.c.Bfs
var (
req *http.Request
resp *http.Response
code int
url = fmt.Sprintf(bfs.Host+_uploadURL, bfs.Bucket, fileName)
)
// prepare the data of the file and init the request
buf := new(bytes.Buffer)
_, err = buf.Write(data)
if err != nil {
log.Error("Upload.buf.Write.error(%v)", err)
err = ecode.RequestErr
return
}
if req, err = http.NewRequest(_method, url, buf); err != nil {
log.Error("http.NewRequest() Upload(%v) error(%v)", url, err)
return
}
// request setting
authorization := authorize(bfs.Key, bfs.Secret, _method, bfs.Bucket, fileName, timing)
req.Header.Set("Date", fmt.Sprint(timing))
req.Header.Set("Authorization", authorization)
req.Header.Set("Content-Type", fileType)
resp, err = d.bfsClient.Do(req)
// response treatment
if err != nil {
log.Error("Bfs client.Do(%s) error(%v)", url, err)
return
}
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
err = fmt.Errorf("Bfs status code error:%v", resp.StatusCode)
return
}
code, err = strconv.Atoi(resp.Header.Get("code"))
if err != nil || code != 200 {
err = fmt.Errorf("Bfs response code error:%v", code)
return
}
location = resp.Header.Get("Location")
return
}
// authorize returns authorization for upload file to bfs
func authorize(key, secret, method, bucket, file string, expire int64) (authorization string) {
var (
content string
mac hash.Hash
signature string
)
content = fmt.Sprintf(_template, method, bucket, file, expire)
mac = hmac.New(sha1.New, []byte(secret))
mac.Write([]byte(content))
signature = base64.StdEncoding.EncodeToString(mac.Sum(nil))
authorization = fmt.Sprintf("%s:%s:%d", key, signature, expire)
return
}

View File

@@ -0,0 +1,57 @@
package dao
import (
"context"
"fmt"
"testing"
"time"
"github.com/smartystreets/goconvey/convey"
)
func TestDaoUpload(t *testing.T) {
var (
c = context.Background()
fileName = "test.txt"
fileType = "txt"
timing = time.Now().Unix()
bfs = d.c.Bfs
data = []byte("123")
url = fmt.Sprintf(bfs.Host+_uploadURL, bfs.Bucket, fileName)
)
convey.Convey("Upload", t, func(ctx convey.C) {
ctx.Convey("http code error", func(ctx convey.C) {
httpMock(_method, url).Reply(-400)
_, err := d.Upload(c, fileName, fileType, timing, data)
ctx.So(err, convey.ShouldNotBeNil)
})
ctx.Convey("business code error", func(ctx convey.C) {
httpMock(_method, url).Reply(200).JSON(`{"code":-400}`)
_, err := d.Upload(c, fileName, fileType, timing, data)
ctx.So(err, convey.ShouldNotBeNil)
})
ctx.Convey("everything is fine", func(ctx convey.C) {
httpMock(_method, url).Reply(200).SetHeader("Location", "test").SetHeader("code", "200").JSON(`{"code":200}`)
location, err := d.Upload(c, fileName, fileType, timing, data)
ctx.So(err, convey.ShouldBeNil)
ctx.So(location, convey.ShouldNotBeNil)
})
})
}
func TestDaoauthorize(t *testing.T) {
var (
key = "key"
secret = "secret"
method = "put"
bucket = "tv-cover"
file = "file"
expire = int64(0)
)
convey.Convey("authorize", t, func(ctx convey.C) {
authorization := authorize(key, secret, method, bucket, file, expire)
ctx.Convey("Then authorization should not be nil.", func(ctx convey.C) {
ctx.So(authorization, convey.ShouldNotBeNil)
})
})
}

View File

@@ -0,0 +1,163 @@
package dao
import (
"context"
"fmt"
"strconv"
"go-common/app/admin/main/tv/model"
"go-common/library/cache/memcache"
"go-common/library/log"
"github.com/jinzhu/gorm"
)
const (
_setUploader = "REPLACE INTO ugc_uploader (mid, state) VALUES (?,?)"
_auditMids = "UPDATE ugc_uploader SET valid = ? WHERE mid IN (?) AND deleted = 0"
_intervUp = "UPDATE ugc_uploader SET cms_face = ?, cms_name = ? WHERE mid = ? AND deleted = 0"
_stateNormal = 1
_deleted = 1
// up list oder type
_ctimeNew = 1
_ctimeOld = 2
_mtimeNew = 3
_mtimeOld = 4
size = 20
)
// UpAdd def.
func (d *Dao) UpAdd(mid int64) (err error) {
if err = d.DB.Exec(_setUploader, mid, _stateNormal).Error; err != nil {
log.Error("UpAdd Error %v", err)
}
return
}
// UpList def.
func (d *Dao) UpList(order int, page int, ids []int64) (ups []*model.Upper, pager *model.Page, err error) {
var db = d.DB.Where("deleted != ?", _deleted)
if len(ids) != 0 {
db = db.Where("mid IN (?)", ids)
}
pager = &model.Page{
Num: page,
Size: size,
}
if err = db.Model(&model.Upper{}).Count(&pager.Total).Error; err != nil {
log.Error("Uplist Count Error %v", err)
return
}
db = treatOrder(order, db)
if err = db.Offset((page - 1) * size).Limit(size).Find(&ups).Error; err != nil {
log.Error("UpList Error %v, Order: %d", err, order)
}
return
}
func treatOrder(order int, db *gorm.DB) *gorm.DB {
switch order {
case _ctimeNew:
db = db.Order("ctime DESC")
case _ctimeOld:
db = db.Order("ctime ASC")
case _mtimeNew:
db = db.Order("mtime DESC")
case _mtimeOld:
db = db.Order("mtime ASC")
default:
db = db.Order("ctime DESC")
}
return db
}
// UpCmsList def.
func (d *Dao) UpCmsList(req *model.ReqUpCms) (ups []*model.CmsUpper, pager *model.Page, err error) {
var db = d.DB.Where("deleted = 0")
if req.MID != 0 {
db = db.Where("mid = ?", req.MID)
}
if req.Name != "" {
db = db.Where("ori_name LIKE ?", "%"+req.Name+"%")
}
if req.Valid != "" {
valid, _ := strconv.Atoi(req.Valid)
db = db.Where("valid = ?", valid)
}
pager = &model.Page{
Num: req.Pn,
Size: size,
}
if err = db.Model(&model.Upper{}).Count(&pager.Total).Error; err != nil {
log.Error("Uplist Count Error %v", err)
return
}
db = treatOrder(req.Order, db)
if err = db.Offset((req.Pn - 1) * size).Limit(size).Find(&ups).Error; err != nil {
log.Error("UpList Error %v, Order: %d", err, req.Order)
}
return
}
// VerifyIds verifies whether all the mids exist
func (d *Dao) VerifyIds(mids []int64) (okMids map[int64]*model.UpMC, err error) {
if len(mids) == 0 {
return
}
okMids = make(map[int64]*model.UpMC)
var ups []*model.UpMC
db := d.DB.Where("deleted != ?", _deleted).Where("mid IN (?)", mids)
if err = db.Find(&ups).Error; err != nil {
log.Error("VerifyIds Error %v, Mids %v", err, mids)
}
for _, v := range ups {
okMids[v.MID] = v
}
return
}
// AuditIds carries out the action to the given mids
func (d *Dao) AuditIds(mids []int64, validAct int) (err error) {
if err = d.DB.Exec(_auditMids, validAct, mids).Error; err != nil {
log.Error("AuditIds Error %v, Mids %v", err, mids)
}
return
}
// SetUpper updates the cms info of an upper in DB
func (d *Dao) SetUpper(req *model.ReqUpEdit) (err error) {
if err = d.DB.Exec(_intervUp, req.Face, req.Name, req.MID).Error; err != nil {
log.Error("SetUpper Error %v, Mid %v", err, req)
}
return
}
func upperMetaKey(MID int64) string {
return fmt.Sprintf("up_cms_%d", MID)
}
// SetUpMetaCache updates upinfo in MC
func (d *Dao) SetUpMetaCache(c context.Context, upper *model.UpMC) (err error) {
var (
key = upperMetaKey(upper.MID)
conn = d.mc.Get(c)
)
defer conn.Close()
if err = conn.Set(&memcache.Item{Key: key, Object: upper, Flags: memcache.FlagJSON, Expiration: d.cmsExpire}); err != nil {
log.Error("conn.Set error(%v)", err)
}
return
}
// DelCache deletes the cache from CM
func (d *Dao) DelCache(c context.Context, mid int64) (err error) {
var (
key = upperMetaKey(mid)
conn = d.mc.Get(c)
)
defer conn.Close()
if err = conn.Delete(key); err != nil {
log.Error("conn.Set error(%v)", err)
}
return
}

View File

@@ -0,0 +1,82 @@
package dao
import (
"context"
"encoding/json"
"fmt"
"testing"
"go-common/app/admin/main/tv/model"
. "github.com/smartystreets/goconvey/convey"
)
func getMids(limit int) (res []int64, err error) {
var (
db = d.DB.Where("deleted = 0")
ups []*model.Upper
)
if err = db.Limit(limit).Find(&ups).Error; err != nil {
fmt.Println("pickMid err ", err)
}
for _, v := range ups {
res = append(res, v.MID)
}
return
}
func TestDao_UpList(t *testing.T) {
Convey("TestDao_UpList", t, WithDao(func(d *Dao) {
mids, errGet := getMids(5)
if errGet != nil {
fmt.Println("empty mids")
return
}
res, pager, err := d.UpList(1, 1, mids)
So(err, ShouldBeNil)
So(pager, ShouldNotBeNil)
So(len(res), ShouldBeGreaterThan, 0)
}))
}
func TestDao_VerifyIds(t *testing.T) {
Convey("TestDao_VerifyIds", t, WithDao(func(d *Dao) {
mids, errGet := getMids(25)
if errGet != nil {
fmt.Println("empty mids")
return
}
okMids, err := d.VerifyIds(mids)
So(err, ShouldBeNil)
So(len(mids), ShouldBeGreaterThanOrEqualTo, len(okMids))
data, _ := json.Marshal(okMids)
fmt.Println(string(data))
}))
}
func TestDao_AuditIds(t *testing.T) {
Convey("TestDao_AuditIds", t, WithDao(func(d *Dao) {
mids, errGet := getMids(15)
if errGet != nil {
fmt.Println("empty mids")
return
}
err := d.AuditIds(mids, 1)
So(err, ShouldBeNil)
}))
}
func TestDao_DelCache(t *testing.T) {
Convey("TestDao_DelCache", t, WithDao(func(d *Dao) {
var (
mid = int64(88895270)
ctx = context.Background()
)
err := d.SetUpMetaCache(ctx, &model.UpMC{
MID: mid,
})
So(err, ShouldBeNil)
err = d.DelCache(ctx, mid)
So(err, ShouldBeNil)
}))
}

View File

@@ -0,0 +1,23 @@
package dao
import (
"context"
"go-common/app/admin/main/tv/model"
"go-common/library/log"
)
const (
_userTableName = "tv_user_info"
)
// GetByMId select user info by mid
func (d *Dao) GetByMId(c context.Context, mid int64) (userInfo *model.TvUserInfoResp, err error) {
userInfo = &model.TvUserInfoResp{}
if err = d.DB.Table(_userTableName).Where("mid = ?", mid).First(userInfo).Error; err != nil {
log.Error("GetByMId (%v) error(%v)", mid, err)
}
return
}

View File

@@ -0,0 +1,48 @@
package dao
import (
"context"
"testing"
"go-common/app/admin/main/tv/model"
"go-common/library/log"
"github.com/smartystreets/goconvey/convey"
)
func TestDaoGetByMId(t *testing.T) {
d.saveUser()
convey.Convey("GetByMId", t, func(ctx convey.C) {
var (
c = context.Background()
mid = int64(100000000)
)
ctx.Convey("When everything gose positive", func(ctx convey.C) {
userInfo, err := d.GetByMId(c, mid)
ctx.Convey("Then err should be nil.userInfo should not be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
ctx.So(userInfo, convey.ShouldNotBeNil)
})
})
})
d.delUser()
}
func (d *Dao) saveUser() {
userInfo := &model.TvUserInfo{
MID: 100000000,
RecentPayTime: 1544613229,
}
if err := d.DB.Save(userInfo).Error; err != nil {
log.Error("SaveUser error(%v)", err)
}
}
func (d *Dao) delUser() {
userInfo := &model.TvUserInfo{
MID: 100000000,
}
if err := d.DB.Where("mid = ?", userInfo.MID).Delete(userInfo).Error; err != nil {
log.Error("DelUser error(%v)", err)
}
}