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,56 @@
package(default_visibility = ["//visibility:public"])
load(
"@io_bazel_rules_go//go:def.bzl",
"go_library",
"go_test",
)
go_library(
name = "go_default_library",
srcs = [
"dao.go",
"workflow.go",
],
importpath = "go-common/app/interface/main/creative/dao/appeal",
tags = ["automanaged"],
visibility = ["//visibility:public"],
deps = [
"//app/interface/main/creative/conf:go_default_library",
"//app/interface/main/creative/model/appeal:go_default_library",
"//library/ecode:go_default_library",
"//library/log:go_default_library",
"//library/net/http/blademaster: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 = [
"dao_test.go",
"workflow_test.go",
],
embed = [":go_default_library"],
rundir = ".",
tags = ["automanaged"],
deps = [
"//app/interface/main/creative/conf:go_default_library",
"//app/interface/main/creative/model/appeal:go_default_library",
"//vendor/github.com/smartystreets/goconvey/convey:go_default_library",
],
)

View File

@@ -0,0 +1,39 @@
package appeal
import (
"go-common/app/interface/main/creative/conf"
httpx "go-common/library/net/http/blademaster"
)
// Dao define
type Dao struct {
// config
c *conf.Config
// http client
client *httpx.Client
// appeal list
list string
detail string
addappeal string
addreply string
appealstar string
appealstate string
appealStarInfo string
}
// New init dao
func New(c *conf.Config) (d *Dao) {
d = &Dao{
c: c,
// http client
client: httpx.NewClient(c.HTTPClient.Normal),
list: c.Host.API + _list,
detail: c.Host.API + _detail,
addappeal: c.Host.API + _addappeal,
addreply: c.Host.API + _addreply,
appealstar: c.Host.API + _appealstar,
appealstate: c.Host.API + _appealstate,
appealStarInfo: c.Host.API + _appealStarInfo,
}
return
}

View File

@@ -0,0 +1,35 @@
package appeal
import (
"flag"
"go-common/app/interface/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")
flag.Set("conf_token", "96b6a6c10bb311e894c14a552f48fef8")
flag.Set("tree_id", "2305")
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.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,197 @@
package appeal
import (
"context"
"net/url"
"strconv"
"go-common/app/interface/main/creative/model/appeal"
"go-common/library/ecode"
"go-common/library/log"
"github.com/pkg/errors"
)
// appeal url
const (
_list = "/x/internal/workflow/appeal/list"
_detail = "/x/internal/workflow/appeal/info"
_addappeal = "/x/internal/workflow/appeal/add"
_addreply = "/x/internal/workflow/appeal/reply/add"
_appealstar = "/x/internal/workflow/appeal/extra/up"
_appealstate = "/x/internal/workflow/appeal/state"
_appealStarInfo = "/x/internal/workflow/appeal/extra/info"
)
// AppealList appeal list .
func (d *Dao) AppealList(c context.Context, mid int64, business int, ip string) (as []*appeal.AppealMeta, err error) {
params := url.Values{}
params.Set("mid", strconv.FormatInt(mid, 10))
params.Set("business", strconv.Itoa(business))
var res struct {
Code int `json:"code"`
Data []*appeal.AppealMeta `json:"data"`
}
if err = d.client.Get(c, d.list, ip, params, &res); err != nil {
err = errors.Wrap(err, "appeal list api")
return
}
if res.Code != 0 {
log.Error("appeal list url(%s) mid(%d) res(%v)", d.list+"?"+params.Encode(), mid, res)
err = ecode.Int(res.Code)
return
}
as = res.Data
return
}
// AppealDetail appeal detail.
func (d *Dao) AppealDetail(c context.Context, mid, id int64, business int, ip string) (a *appeal.AppealMeta, err error) {
params := url.Values{}
params.Set("mid", strconv.FormatInt(mid, 10))
params.Set("id", strconv.FormatInt(id, 10))
params.Set("business", strconv.Itoa(business))
var res struct {
Code int `json:"code"`
Data *appeal.AppealMeta `json:"data"`
}
if err = d.client.Get(c, d.detail, ip, params, &res); err != nil {
err = errors.Wrap(err, "appeal api")
return
}
if res.Code != 0 {
log.Error("appeal url(%s) mid(%d) res(%v)", d.detail+"?"+params.Encode(), mid, res)
err = ecode.Int(res.Code)
return
}
a = res.Data
return
}
// AddAppeal add appeal.
func (d *Dao) AddAppeal(c context.Context, tid, aid, mid, business int64, qq, phone, email, desc, attachments, ip string, ap *appeal.BusinessAppeal) (apID int64, err error) {
params := url.Values{}
params.Set("tid", strconv.FormatInt(tid, 10))
params.Set("oid", strconv.FormatInt(aid, 10))
params.Set("mid", strconv.FormatInt(mid, 10))
params.Set("business", strconv.FormatInt(business, 10))
params.Set("qq", qq)
params.Set("phone", phone)
params.Set("email", email)
params.Set("description", desc)
params.Set("attachments", attachments)
params.Set("business_typeid", strconv.FormatInt(ap.BusinessTypeID, 10))
params.Set("business_mid", strconv.FormatInt(ap.BusinessMID, 10))
params.Set("business_title", ap.BusinessTitle)
params.Set("business_content", ap.BusinessContent)
params.Set("business_state", strconv.FormatInt(appeal.StateCreate, 10))
var res struct {
Code int `json:"code"`
Data struct {
ChallengeNo int64 `json:"challengeNo"`
} `json:"data"`
}
log.Info("AddAppeal params(%v)", params)
if err = d.client.Post(c, d.addappeal, ip, params, &res); err != nil {
err = errors.Wrap(err, "appeal api")
return
}
if res.Code != 0 {
log.Error("add appeal url(%s) mid(%d) res(%v)", d.addappeal+"?"+params.Encode(), mid, res)
err = ecode.Int(res.Code)
}
apID = res.Data.ChallengeNo
return
}
// AddReply add appeal reply .
func (d *Dao) AddReply(c context.Context, cid, event int64, content, attachments, ip string) (err error) {
params := url.Values{}
params.Set("cid", strconv.FormatInt(cid, 10))
params.Set("content", content)
params.Set("attachments", attachments)
params.Set("event", strconv.FormatInt(event, 10))
var res struct {
Code int `json:"code"`
}
if err = d.client.Post(c, d.addreply, ip, params, &res); err != nil {
err = errors.Wrap(err, "appeal reply api")
return
}
if res.Code != 0 {
log.Error("add appeal url(%s) res(%v)", d.addreply+"?"+params.Encode(), res)
err = ecode.Int(res.Code)
}
return
}
// AppealExtra modify appeal extra.
func (d *Dao) AppealExtra(c context.Context, mid, cid, business, val int64, key, ip string) (err error) {
params := url.Values{}
params.Set("mid", strconv.FormatInt(mid, 10))
params.Set("cid", strconv.FormatInt(cid, 10))
params.Set("business", strconv.FormatInt(business, 10))
params.Set("key", key)
params.Set("val", strconv.FormatInt(val, 10))
var res struct {
Code int `json:"code"`
}
log.Info("AppealExtra params(%v)", params)
if err = d.client.Post(c, d.appealstar, ip, params, &res); err != nil {
err = errors.Wrap(err, "appeal star api")
return
}
if res.Code != 0 {
log.Error("appeal start url(%s) res(%v)", d.appealstar+"?"+params.Encode(), res)
err = ecode.Int(res.Code)
}
return
}
// AppealState modify appeal state .
func (d *Dao) AppealState(c context.Context, mid, id, business, state int64, ip string) (err error) {
params := url.Values{}
params.Set("id", strconv.FormatInt(id, 10))
params.Set("mid", strconv.FormatInt(mid, 10))
params.Set("business", strconv.FormatInt(business, 10))
params.Set("business_state", strconv.FormatInt(state, 10))
var res struct {
Code int `json:"code"`
}
if err = d.client.Post(c, d.appealstate, ip, params, &res); err != nil {
err = errors.Wrap(err, "appeal state api")
return
}
if res.Code != 0 {
log.Error("appeal state url(%s) res(%v)", d.appealstate+"?"+params.Encode(), res)
err = ecode.Int(res.Code)
}
return
}
// AppealStarInfo appeal star detail.
func (d *Dao) AppealStarInfo(c context.Context, mid, cid int64, business int, ip string) (star, etime string, err error) {
params := url.Values{}
params.Set("mid", strconv.FormatInt(mid, 10))
params.Set("cid", strconv.FormatInt(cid, 10))
params.Set("business", strconv.Itoa(business))
var res struct {
Code int `json:"code"`
Data struct {
Star string `json:"star"`
ETime string `json:"etime"`
} `json:"data"`
}
if err = d.client.Get(c, d.appealStarInfo, ip, params, &res); err != nil {
err = errors.Wrap(err, "appeal api")
return
}
if res.Code != 0 {
log.Error("appeal url(%s) mid(%d) res(%v)", d.detail+"?"+params.Encode(), mid, res)
err = ecode.Int(res.Code)
return
}
star = res.Data.Star
etime = res.Data.ETime
return
}

View File

@@ -0,0 +1,136 @@
package appeal
import (
"context"
"go-common/app/interface/main/creative/model/appeal"
"testing"
"github.com/smartystreets/goconvey/convey"
)
func TestAppealAppealList(t *testing.T) {
var (
c = context.TODO()
mid = int64(0)
business = int(0)
ip = ""
)
convey.Convey("AppealList", t, func(ctx convey.C) {
as, err := d.AppealList(c, mid, business, ip)
ctx.Convey("Then err should be nil.as should not be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
ctx.So(as, convey.ShouldNotBeNil)
})
})
}
func TestAppealAppealDetail(t *testing.T) {
var (
c = context.TODO()
mid = int64(0)
id = int64(0)
business = int(0)
ip = ""
)
convey.Convey("AppealDetail", t, func(ctx convey.C) {
a, err := d.AppealDetail(c, mid, id, business, ip)
ctx.Convey("Then err should be nil.a should not be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
ctx.So(a, convey.ShouldNotBeNil)
})
})
}
func TestAppealAddAppeal(t *testing.T) {
var (
c = context.TODO()
tid = int64(0)
aid = int64(0)
mid = int64(0)
business = int64(0)
qq = ""
phone = ""
email = ""
desc = ""
attachments = ""
ip = ""
ap = &appeal.BusinessAppeal{}
)
convey.Convey("AddAppeal", t, func(ctx convey.C) {
apID, err := d.AddAppeal(c, tid, aid, mid, business, qq, phone, email, desc, attachments, ip, ap)
ctx.Convey("Then err should be nil.apID should not be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
ctx.So(apID, convey.ShouldNotBeNil)
})
})
}
func TestAppealAddReply(t *testing.T) {
var (
c = context.TODO()
cid = int64(0)
event = int64(0)
content = ""
attachments = ""
ip = ""
)
convey.Convey("AddReply", t, func(ctx convey.C) {
err := d.AddReply(c, cid, event, content, attachments, ip)
ctx.Convey("Then err should be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
})
})
}
func TestAppealAppealExtra(t *testing.T) {
var (
c = context.TODO()
mid = int64(0)
cid = int64(0)
business = int64(0)
val = int64(0)
key = ""
ip = ""
)
convey.Convey("AppealExtra", t, func(ctx convey.C) {
err := d.AppealExtra(c, mid, cid, business, val, key, ip)
ctx.Convey("Then err should be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
})
})
}
func TestAppealAppealState(t *testing.T) {
var (
c = context.TODO()
mid = int64(0)
id = int64(0)
business = int64(0)
state = int64(0)
ip = ""
)
convey.Convey("AppealState", t, func(ctx convey.C) {
err := d.AppealState(c, mid, id, business, state, ip)
ctx.Convey("Then err should be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
})
})
}
func TestAppealAppealStarInfo(t *testing.T) {
var (
c = context.TODO()
mid = int64(0)
cid = int64(0)
business = int(0)
ip = ""
)
convey.Convey("AppealStarInfo", t, func(ctx convey.C) {
star, etime, err := d.AppealStarInfo(c, mid, cid, business, ip)
ctx.Convey("Then err should be nil.star,etime should not be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
ctx.So(etime, convey.ShouldNotBeNil)
ctx.So(star, convey.ShouldNotBeNil)
})
})
}