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_test",
"go_library",
)
go_test(
name = "go_default_test",
srcs = ["service_test.go"],
embed = [":go_default_library"],
tags = ["automanaged"],
deps = [
"//app/interface/main/creative/conf:go_default_library",
"//app/interface/main/creative/model/growup:go_default_library",
"//app/interface/main/creative/service:go_default_library",
"//vendor/github.com/smartystreets/goconvey/convey:go_default_library",
],
)
go_library(
name = "go_default_library",
srcs = [
"growup.go",
"service.go",
],
importpath = "go-common/app/interface/main/creative/service/growup",
tags = ["automanaged"],
visibility = ["//visibility:public"],
deps = [
"//app/interface/main/creative/conf:go_default_library",
"//app/interface/main/creative/dao/archive:go_default_library",
"//app/interface/main/creative/dao/growup:go_default_library",
"//app/interface/main/creative/model/growup:go_default_library",
"//app/interface/main/creative/service: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,128 @@
package growup
import (
"context"
"go-common/app/interface/main/creative/model/growup"
"go-common/library/log"
"time"
)
// UpStatus get up status. 前提:必须当前用户线上有可以观看的视频(0/-6) TODO deprecated
func (s *Service) UpStatus(c context.Context, mid int64, ip string) (us *growup.UpStatus, err error) {
if us, err = s.growup.UpStatus(c, mid, ip); err != nil {
log.Error("s.growup.UpStatus(%d) error(%v)", mid, err)
return
}
return
}
// UpInfo get up info.
func (s *Service) UpInfo(c context.Context, mid int64, ip string) (ui *growup.UpInfo, err error) {
if ui, err = s.growup.UpInfo(c, mid, ip); err != nil {
log.Error("s.growup.UpInfo(%d) error(%v)", mid, err)
}
return
}
// Join join growup.
func (s *Service) Join(c context.Context, mid int64, accTy, signTy int, ip string) (err error) {
if err = s.growup.Join(c, mid, accTy, signTy, ip); err != nil {
log.Error("s.growup.Join(%d) error(%v)", mid, err)
}
return
}
// Quit quit growup.
func (s *Service) Quit(c context.Context, mid int64, ip string) (err error) {
if err = s.growup.Quit(c, mid, ip); err != nil {
log.Error("s.growup.Quit(%d) error(%v)", mid, err)
}
return
}
// Summary get up status.
func (s *Service) Summary(c context.Context, mid int64, ip string) (us *growup.Summary, err error) {
if us, err = s.growup.Summary(c, mid, ip); err != nil {
log.Error("s.growup.Summary(%d) error(%v)", mid, err)
}
return
}
// Stat get up info.
func (s *Service) Stat(c context.Context, mid int64, ip string) (ui *growup.Stat, err error) {
if ui, err = s.growup.Stat(c, mid, ip); err != nil {
log.Error("s.growup.Stat(%d) error(%v)", mid, err)
}
if ui == nil || len(ui.Tops) == 0 {
log.Error("s.growup.Stat mid(%d) data(%v)", mid, ui)
return
}
dt := time.Now().AddDate(0, 0, -2)
year := dt.Format("2006")
month := dt.Format("01")
ui.Desc = "收入数据统计日期:" + year + "年" + month + "月"
aids := make([]int64, 0, len(ui.Tops))
for _, v := range ui.Tops {
if v != nil {
aids = append(aids, v.AID)
}
}
avm, err := s.p.BatchArchives(c, mid, aids, ip)
if err != nil {
log.Error("s.p.BatchArchives aids (%v), ip(%s) err(%v)", aids, ip, err)
return
}
if len(avm) == 0 {
return
}
for _, v := range ui.Tops {
if v != nil {
if av, ok := avm[v.AID]; ok {
v.Title = av.Archive.Title
}
}
}
return
}
// IncomeList get up status.
func (s *Service) IncomeList(c context.Context, mid int64, ty, pn, ps int, ip string) (l *growup.IncomeList, err error) {
if l, err = s.growup.IncomeList(c, mid, ty, pn, ps, ip); err != nil {
log.Error("s.growup.IncomeList(%d) error(%v)", mid, err)
return
}
if l == nil || len(l.Data) == 0 {
log.Error("s.growup.IncomeList mid(%d) type(%d) data(%v)", mid, ty, l)
return
}
aids := make([]int64, 0, len(l.Data))
for _, v := range l.Data {
if v != nil {
aids = append(aids, v.AID)
}
}
avm, err := s.p.BatchArchives(c, mid, aids, ip)
if err != nil {
log.Error("s.p.BatchArchives aids (%v), ip(%s) err(%v)", aids, ip, err)
return
}
if len(avm) == 0 {
return
}
for _, v := range l.Data {
if v != nil {
if av, ok := avm[v.AID]; ok {
v.Title = av.Archive.Title
}
}
}
return
}
// BreachList get up info.
func (s *Service) BreachList(c context.Context, mid int64, pn, ps int, ip string) (ui *growup.BreachList, err error) {
if ui, err = s.growup.BreachList(c, mid, pn, ps, ip); err != nil {
log.Error("s.growup.BreachList(%d) error(%v)", mid, err)
}
return
}

View File

@@ -0,0 +1,27 @@
package growup
import (
"go-common/app/interface/main/creative/conf"
"go-common/app/interface/main/creative/dao/archive"
"go-common/app/interface/main/creative/dao/growup"
"go-common/app/interface/main/creative/service"
)
//Service struct.
type Service struct {
c *conf.Config
arc *archive.Dao
growup *growup.Dao
p *service.Public
}
//New get service.
func New(c *conf.Config, rpcdaos *service.RPCDaos, p *service.Public) *Service {
s := &Service{
c: c,
arc: rpcdaos.Arc,
growup: growup.New(c),
p: p,
}
return s
}

View File

@@ -0,0 +1,52 @@
package growup
import (
"context"
"flag"
"go-common/app/interface/main/creative/conf"
"go-common/app/interface/main/creative/model/growup"
"path/filepath"
"testing"
"time"
"go-common/app/interface/main/creative/service"
. "github.com/smartystreets/goconvey/convey"
)
var (
s *Service
p *service.Public
)
func init() {
dir, _ := filepath.Abs("../../cmd/creative.toml")
flag.Set("conf", dir)
conf.Init()
rpcdaos := service.NewRPCDaos(conf.Conf)
p = service.New(conf.Conf, rpcdaos)
s = New(conf.Conf, rpcdaos, p)
time.Sleep(time.Second)
}
func WithService(f func(s *Service)) func() {
return func() {
Reset(func() {})
f(s)
}
}
func Test_UpInfo(t *testing.T) {
var (
c = context.TODO()
err error
res *growup.UpInfo
MID = int64(27515256)
localHost = "127.0.0.1"
)
Convey("UpInfo", t, WithService(func(s *Service) {
res, err = s.UpInfo(c, MID, localHost)
So(err, ShouldNotBeNil)
So(res, ShouldBeNil)
}))
}