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,53 @@
package(default_visibility = ["//visibility:public"])
load(
"@io_bazel_rules_go//go:def.bzl",
"go_library",
"go_test",
)
go_library(
name = "go_default_library",
srcs = [
"academy.go",
"dao.go",
],
importpath = "go-common/app/job/main/creative/dao/academy",
tags = ["automanaged"],
visibility = ["//visibility:public"],
deps = [
"//app/job/main/creative/conf:go_default_library",
"//app/job/main/creative/model:go_default_library",
"//library/database/sql:go_default_library",
"//library/log:go_default_library",
"//library/xstr: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 = [
"academy_test.go",
"dao_test.go",
],
embed = [":go_default_library"],
tags = ["automanaged"],
deps = [
"//app/job/main/creative/conf:go_default_library",
"//vendor/github.com/smartystreets/goconvey/convey:go_default_library",
],
)

View File

@@ -0,0 +1,49 @@
package academy
import (
"context"
"fmt"
"time"
"go-common/app/job/main/creative/model"
"go-common/library/log"
"go-common/library/xstr"
)
const (
// select
_getArcsSQL = "SELECT id,oid,business FROM academy_archive WHERE state=? AND business=? AND id > ? order by id ASC limit ?"
)
//Archives get limit achives.
func (d *Dao) Archives(c context.Context, id int64, bs, limit int) (res []*model.OArchive, err error) {
rows, err := d.db.Query(c, _getArcsSQL, 0, bs, id, limit)
res = make([]*model.OArchive, 0)
for rows.Next() {
a := &model.OArchive{}
if err = rows.Scan(&a.ID, &a.OID, &a.Business); err != nil {
log.Error("rows.Scan error(%v)", err)
return
}
res = append(res, a)
}
return
}
//UPHotByAIDs update hot by aids.
func (d *Dao) UPHotByAIDs(c context.Context, hots map[int64]int64) error {
var oids []int64
sql := "UPDATE academy_archive SET hot = CASE oid "
for oid, hot := range hots {
sql += fmt.Sprintf("WHEN %d THEN %d ", oid, hot)
oids = append(oids, oid)
}
sql += fmt.Sprintf("END, mtime=? WHERE oid IN (%s)", xstr.JoinInts(oids))
_, err := d.db.Exec(c, sql, time.Now())
if err != nil {
log.Error("d.db.Exec sql(%s) error(%v)", sql, err)
}
log.Info("d.db.Exec sql(%s) hots(%+v) error(%v)", sql, hots, err)
return err
}

View File

@@ -0,0 +1,42 @@
package academy
import (
"context"
"testing"
"github.com/smartystreets/goconvey/convey"
)
func TestAcademyArchives(t *testing.T) {
convey.Convey("Archives", t, func(ctx convey.C) {
var (
c = context.Background()
id = int64(10110127)
bs = int(1)
limit = int(10)
)
ctx.Convey("When everything gose positive", func(ctx convey.C) {
_, err := d.Archives(c, id, bs, limit)
ctx.Convey("Then err should be nil.res should not be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldEqual, err)
})
})
})
}
func TestAcademyUPHotByAIDs(t *testing.T) {
convey.Convey("UPHotByAIDs", t, func(ctx convey.C) {
var (
c = context.Background()
hots = map[int64]int64{
10110127: 11,
}
)
ctx.Convey("When everything gose positive", func(ctx convey.C) {
err := d.UPHotByAIDs(c, hots)
ctx.Convey("Then err should be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldEqual, err)
})
})
})
}

View File

@@ -0,0 +1,34 @@
package academy
import (
"context"
"go-common/app/job/main/creative/conf"
"go-common/library/database/sql"
)
// Dao is creative dao.
type Dao struct {
// config
c *conf.Config
// db
db *sql.DB
}
// New init api url
func New(c *conf.Config) (d *Dao) {
d = &Dao{
c: c,
db: sql.NewMySQL(c.DB.Creative),
}
return
}
// Ping creativeDb
func (d *Dao) Ping(c context.Context) (err error) {
return d.db.Ping(c)
}
// Close creativeDb
func (d *Dao) Close() (err error) {
return d.db.Close()
}

View File

@@ -0,0 +1,34 @@
package academy
import (
"flag"
"go-common/app/job/main/creative/conf"
"os"
"testing"
)
var (
d *Dao
)
func TestMain(m *testing.M) {
if os.Getenv("DEPLOY_ENV") != "" {
flag.Set("app_id", "main.archive.creative-job")
flag.Set("conf_token", "43943fda0bb311e8865c66d44b23cda7")
flag.Set("tree_id", "16037")
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/creative-job.toml")
}
flag.Parse()
if err := conf.Init(); err != nil {
panic(err)
}
d = New(conf.Conf)
os.Exit(m.Run())
}