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,47 @@
package(default_visibility = ["//visibility:public"])
load(
"@io_bazel_rules_go//go:def.bzl",
"go_test",
"go_library",
)
go_test(
name = "go_default_test",
srcs = ["splash_test.go"],
embed = [":go_default_library"],
rundir = ".",
tags = ["automanaged"],
deps = [
"//app/interface/main/app-resource/conf:go_default_library",
"//vendor/github.com/smartystreets/goconvey/convey:go_default_library",
],
)
go_library(
name = "go_default_library",
srcs = ["splash.go"],
importpath = "go-common/app/interface/main/app-resource/dao/splash",
tags = ["automanaged"],
visibility = ["//visibility:public"],
deps = [
"//app/interface/main/app-resource/conf:go_default_library",
"//app/interface/main/app-resource/model/splash:go_default_library",
"//library/database/sql:go_default_library",
"//library/log: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,118 @@
package splash
import (
"context"
"go-common/app/interface/main/app-resource/conf"
"go-common/app/interface/main/app-resource/model/splash"
"go-common/library/database/sql"
"go-common/library/log"
)
const (
_actAllSQL = `SELECT i.splash_id,s.animate,s.duration,s.type,s.times,s.goto,s.param,s.skip,s.starttime,s.endtime,s.platform,i.url,i.hash,i.width,i.height,s.area,s.conditions,s.build,s.operate,s.no_preview FROM
splash AS s, splash_image AS i WHERE s.id=i.splash_id AND s.publish=1 AND i.type=3 AND s.platform!=0 AND s.type!=2 AND s.type!=4 AND s.state=0 ORDER BY s.starttime DESC`
_actBirthSQL = `SELECT i.splash_id,s.animate,s.duration,s.type,s.times,s.goto,s.param,s.skip,s.starttime,s.endtime,s.platform,i.url,i.hash,i.width,i.height,s.area,s.conditions,s.build,s.operate FROM
splash AS s, splash_image AS i WHERE s.id=i.splash_id AND s.publish=1 AND i.type=3 AND s.platform!=0 AND s.type=2 AND s.state=0 ORDER BY s.starttime DESC`
_actVipSQL = `SELECT i.splash_id,s.animate,s.duration,s.type,s.times,s.goto,s.param,s.skip,s.starttime,s.endtime,s.platform,i.url,i.hash,i.width,i.height,s.area,s.conditions,s.build,s.operate FROM
splash AS s, splash_image AS i WHERE s.id=i.splash_id AND s.publish=1 AND i.type=3 AND s.platform!=0 AND s.type=4 AND s.state=0 ORDER BY s.starttime DESC`
)
// Dao is splash dao.
type Dao struct {
resdb *sql.DB
// splash_active
actAll *sql.Stmt
actBirth *sql.Stmt
actVip *sql.Stmt
}
// New new splash dao and return.
func New(c *conf.Config) *Dao {
d := &Dao{
resdb: sql.NewMySQL(c.MySQL.Resource),
}
// splah_active
d.actAll = d.resdb.Prepared(_actAllSQL)
d.actBirth = d.resdb.Prepared(_actBirthSQL)
d.actVip = d.resdb.Prepared(_actVipSQL)
return d
}
// GetActiveAll get all splash from table splash_active.
func (d *Dao) ActiveAll(ctx context.Context) (res []*splash.Splash, err error) {
rows, err := d.actAll.Query(ctx)
if err != nil {
log.Error("dao.Exec(), err (%v)", err)
return
}
defer rows.Close()
for rows.Next() {
sp := &splash.Splash{}
if err = rows.Scan(&sp.ID, &sp.Animate, &sp.Duration, &sp.Type, &sp.Times, &sp.Goto, &sp.Param, &sp.Skip, &sp.Start,
&sp.End, &sp.Plat, &sp.Image, &sp.Hash, &sp.Width, &sp.Height, &sp.Area, &sp.Condition, &sp.Build, &sp.Operate, &sp.NoPreview); err != nil {
log.Error("rows.Scan err (%v)", err)
res = nil
return
}
sp.PlatChange()
if sp.Operate == 1 {
res = append([]*splash.Splash{sp}, res...)
} else {
res = append(res, sp)
}
}
return
}
// ActiveBirth from table splash and splash_image.
func (d *Dao) ActiveBirth(ctx context.Context) (res []*splash.Splash, err error) {
rows, err := d.actBirth.Query(ctx)
if err != nil {
log.Error("dao.Exec(), err (%v)", err)
return
}
defer rows.Close()
for rows.Next() {
sp := &splash.Splash{}
if err = rows.Scan(&sp.ID, &sp.Animate, &sp.Duration, &sp.Type, &sp.Times, &sp.Goto, &sp.Param, &sp.Skip, &sp.Start,
&sp.End, &sp.Plat, &sp.Image, &sp.Hash, &sp.Width, &sp.Height, &sp.Area, &sp.Condition, &sp.Build, &sp.Operate); err != nil {
log.Error("rows.Scan err (%v)", err)
res = nil
return
}
sp.PlatChange()
sp.BirthDate()
res = append(res, sp)
}
return
}
// ActiveVip form table vip splash
func (d *Dao) ActiveVip(ctx context.Context) (res []*splash.Splash, err error) {
rows, err := d.actVip.Query(ctx)
if err != nil {
log.Error("dao.Exec(), err (%v)", err)
return
}
defer rows.Close()
for rows.Next() {
sp := &splash.Splash{}
if err = rows.Scan(&sp.ID, &sp.Animate, &sp.Duration, &sp.Type, &sp.Times, &sp.Goto, &sp.Param, &sp.Skip, &sp.Start,
&sp.End, &sp.Plat, &sp.Image, &sp.Hash, &sp.Width, &sp.Height, &sp.Area, &sp.Condition, &sp.Build, &sp.Operate); err != nil {
log.Error("rows.Scan err (%v)", err)
res = nil
return
}
sp.PlatChange()
res = append(res, sp)
}
return
}
// Close close memcache resource.
func (dao *Dao) Close() {
if dao.resdb != nil {
dao.resdb.Close()
}
}

View File

@@ -0,0 +1,53 @@
package splash
import (
"context"
"flag"
"path/filepath"
"testing"
"time"
"go-common/app/interface/main/app-resource/conf"
. "github.com/smartystreets/goconvey/convey"
)
var (
d *Dao
)
func ctx() context.Context {
return context.Background()
}
func init() {
dir, _ := filepath.Abs("../../cmd/app-resource-test.toml")
flag.Set("conf", dir)
conf.Init()
d = New(conf.Conf)
time.Sleep(time.Second)
}
func TestActiveAll(t *testing.T) {
Convey("get ActiveAll all", t, func() {
res, err := d.ActiveAll(ctx())
So(err, ShouldBeNil)
So(res, ShouldNotBeEmpty)
})
}
func TestActiveBirth(t *testing.T) {
Convey("get ActiveBirth all", t, func() {
res, err := d.ActiveBirth(ctx())
So(err, ShouldBeNil)
So(res, ShouldNotBeEmpty)
})
}
func TestActiveVip(t *testing.T) {
Convey("get ActiveVip all", t, func() {
res, err := d.ActiveVip(ctx())
So(err, ShouldBeNil)
So(res, ShouldNotBeEmpty)
})
}