Create & Init Project...
This commit is contained in:
29
app/admin/main/point/BUILD
Normal file
29
app/admin/main/point/BUILD
Normal file
@ -0,0 +1,29 @@
|
||||
package(default_visibility = ["//visibility:public"])
|
||||
|
||||
load(
|
||||
"@io_bazel_rules_go//go:def.bzl",
|
||||
"go_library",
|
||||
"go_test",
|
||||
)
|
||||
|
||||
filegroup(
|
||||
name = "package-srcs",
|
||||
srcs = glob(["**"]),
|
||||
tags = ["automanaged"],
|
||||
visibility = ["//visibility:private"],
|
||||
)
|
||||
|
||||
filegroup(
|
||||
name = "all-srcs",
|
||||
srcs = [
|
||||
":package-srcs",
|
||||
"//app/admin/main/point/cmd:all-srcs",
|
||||
"//app/admin/main/point/conf:all-srcs",
|
||||
"//app/admin/main/point/dao:all-srcs",
|
||||
"//app/admin/main/point/http:all-srcs",
|
||||
"//app/admin/main/point/model:all-srcs",
|
||||
"//app/admin/main/point/service:all-srcs",
|
||||
],
|
||||
tags = ["automanaged"],
|
||||
visibility = ["//visibility:public"],
|
||||
)
|
20
app/admin/main/point/CHANGELOG.md
Normal file
20
app/admin/main/point/CHANGELOG.md
Normal file
@ -0,0 +1,20 @@
|
||||
# v1.1.4
|
||||
1. update permit point
|
||||
|
||||
# v1.1.3
|
||||
1. clear old code
|
||||
|
||||
# v1.1.2
|
||||
1. fix point v3 search sort bug
|
||||
|
||||
# v1.1.1
|
||||
1. fix point v3 search bug
|
||||
|
||||
# v1.1.0
|
||||
1. point v3 search
|
||||
|
||||
# v1.0.1
|
||||
1. 增加积分增加admin接口
|
||||
|
||||
# v1.0.0
|
||||
1. 大会员积分管理后台
|
11
app/admin/main/point/CONTRIBUTORS.md
Normal file
11
app/admin/main/point/CONTRIBUTORS.md
Normal file
@ -0,0 +1,11 @@
|
||||
# Owner
|
||||
yubaihai
|
||||
zhaogangtao
|
||||
|
||||
# Author
|
||||
yubaihai
|
||||
zhaogangtao
|
||||
|
||||
# Reviewer
|
||||
zhaogangtao
|
||||
linmiao
|
15
app/admin/main/point/OWNERS
Normal file
15
app/admin/main/point/OWNERS
Normal file
@ -0,0 +1,15 @@
|
||||
# See the OWNERS docs at https://go.k8s.io/owners
|
||||
|
||||
approvers:
|
||||
- yubaihai
|
||||
- zhaogangtao
|
||||
labels:
|
||||
- admin
|
||||
- admin/main/point
|
||||
- main
|
||||
options:
|
||||
no_parent_owners: true
|
||||
reviewers:
|
||||
- linmiao
|
||||
- yubaihai
|
||||
- zhaogangtao
|
14
app/admin/main/point/README.md
Normal file
14
app/admin/main/point/README.md
Normal file
@ -0,0 +1,14 @@
|
||||
# point
|
||||
|
||||
# 项目简介
|
||||
1. 大会员积分管理后台
|
||||
|
||||
# 编译环境
|
||||
go 1.8.4
|
||||
|
||||
# 依赖包
|
||||
|
||||
|
||||
# 编译执行
|
||||
|
||||
|
43
app/admin/main/point/cmd/BUILD
Normal file
43
app/admin/main/point/cmd/BUILD
Normal file
@ -0,0 +1,43 @@
|
||||
package(default_visibility = ["//visibility:public"])
|
||||
|
||||
load(
|
||||
"@io_bazel_rules_go//go:def.bzl",
|
||||
"go_binary",
|
||||
"go_library",
|
||||
)
|
||||
|
||||
go_binary(
|
||||
name = "cmd",
|
||||
embed = [":go_default_library"],
|
||||
tags = ["automanaged"],
|
||||
)
|
||||
|
||||
go_library(
|
||||
name = "go_default_library",
|
||||
srcs = ["main.go"],
|
||||
data = ["point-admin.toml"],
|
||||
importpath = "go-common/app/admin/main/point/cmd",
|
||||
tags = ["automanaged"],
|
||||
visibility = ["//visibility:public"],
|
||||
deps = [
|
||||
"//app/admin/main/point/conf:go_default_library",
|
||||
"//app/admin/main/point/http:go_default_library",
|
||||
"//library/ecode/tip:go_default_library",
|
||||
"//library/log:go_default_library",
|
||||
"//library/net/trace: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"],
|
||||
)
|
49
app/admin/main/point/cmd/main.go
Normal file
49
app/admin/main/point/cmd/main.go
Normal file
@ -0,0 +1,49 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"os"
|
||||
"os/signal"
|
||||
"syscall"
|
||||
|
||||
"go-common/app/admin/main/point/conf"
|
||||
"go-common/app/admin/main/point/http"
|
||||
ecode "go-common/library/ecode/tip"
|
||||
"go-common/library/log"
|
||||
"go-common/library/net/trace"
|
||||
)
|
||||
|
||||
func main() {
|
||||
flag.Parse()
|
||||
if err := conf.Init(); err != nil {
|
||||
log.Error("conf.Init() error(%v)", err)
|
||||
panic(err)
|
||||
}
|
||||
// init log
|
||||
log.Init(conf.Conf.Log)
|
||||
defer log.Close()
|
||||
log.Info("point start")
|
||||
// init trace
|
||||
trace.Init(conf.Conf.Tracer)
|
||||
defer trace.Close()
|
||||
// ecode init
|
||||
ecode.Init(conf.Conf.Ecode)
|
||||
// service init
|
||||
http.Init(conf.Conf)
|
||||
// init pprof conf.Conf.Perf
|
||||
// init signal
|
||||
c := make(chan os.Signal, 1)
|
||||
signal.Notify(c, syscall.SIGHUP, syscall.SIGQUIT, syscall.SIGTERM, syscall.SIGINT)
|
||||
for {
|
||||
s := <-c
|
||||
log.Info("point get a signal %s", s.String())
|
||||
switch s {
|
||||
case syscall.SIGQUIT, syscall.SIGTERM, syscall.SIGINT:
|
||||
log.Info("point exit")
|
||||
return
|
||||
case syscall.SIGHUP:
|
||||
default:
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
102
app/admin/main/point/cmd/point-admin.toml
Normal file
102
app/admin/main/point/cmd/point-admin.toml
Normal file
@ -0,0 +1,102 @@
|
||||
# This is a TOML document. Boom
|
||||
|
||||
version = "1.0.0"
|
||||
|
||||
|
||||
[log]
|
||||
dir = "/data/log/point-admin"
|
||||
|
||||
[bm]
|
||||
addr = "0.0.0.0:9001"
|
||||
maxListen = 10
|
||||
timeout = "1s"
|
||||
|
||||
[auth]
|
||||
managerHost = "http://manager.bilibili.co"
|
||||
dashboardHost = "http://dashboard-mng.bilibili.co"
|
||||
dashboardCaller = "manager-go"
|
||||
[auth.DsHTTPClient]
|
||||
key = "manager-go"
|
||||
secret = "949bbb2dd3178252638c2407578bc7ad"
|
||||
dial = "1s"
|
||||
timeout = "1s"
|
||||
keepAlive = "60s"
|
||||
[auth.DsHTTPClient.breaker]
|
||||
window = "3s"
|
||||
sleep = "100ms"
|
||||
bucket = 10
|
||||
ratio = 0.5
|
||||
request = 100
|
||||
[auth.MaHTTPClient]
|
||||
key = "f6433799dbd88751"
|
||||
secret = "36f8ddb1806207fe07013ab6a77a3935"
|
||||
dial = "1s"
|
||||
timeout = "1s"
|
||||
keepAlive = "60s"
|
||||
[auth.MaHTTPClient.breaker]
|
||||
window = "3s"
|
||||
sleep = "100ms"
|
||||
bucket = 10
|
||||
ratio = 0.5
|
||||
request = 100
|
||||
[auth.session]
|
||||
sessionIDLength = 32
|
||||
cookieLifeTime = 1800
|
||||
cookieName = "mng-go"
|
||||
domain = ".bilibili.co"
|
||||
[auth.session.Memcache]
|
||||
name = "go-business/auth"
|
||||
proto = "tcp"
|
||||
addr = "172.16.33.54:11211"
|
||||
active = 5
|
||||
idle = 5
|
||||
dialTimeout = "1s"
|
||||
readTimeout = "1s"
|
||||
writeTimeout = "1s"
|
||||
idleTimeout = "80s"
|
||||
|
||||
[mysql]
|
||||
addr = "172.22.34.101:3308"
|
||||
dsn = "bilibili_point:QC9YPHkRv7fItBMK5Zb41dEn0WU63Xes@tcp(172.22.34.101:3308)/bilibili_point?timeout=200ms&readTimeout=200ms&writeTimeout=200ms&parseTime=true&loc=Local&charset=utf8,utf8mb4"
|
||||
active = 20
|
||||
idle = 10
|
||||
idleTimeout ="4h"
|
||||
queryTimeout = "1s"
|
||||
execTimeout = "1s"
|
||||
tranTimeout = "2s"
|
||||
[mysql.breaker]
|
||||
window = "3s"
|
||||
sleep = "100ms"
|
||||
bucket = 10
|
||||
ratio = 0.5
|
||||
request = 100
|
||||
|
||||
[memcache]
|
||||
name = "point"
|
||||
proto = "tcp"
|
||||
addr = ""
|
||||
idle = 5
|
||||
active = 10
|
||||
dialTimeout = "1s"
|
||||
readTimeout = "1s"
|
||||
writeTimeout = "1s"
|
||||
idleTimeout = "10s"
|
||||
expire = "24h"
|
||||
|
||||
[httpClient]
|
||||
key = "ad4bb9b8f5d9d4a7"
|
||||
secret = "6912080d78d58be7cb94f57d50d438f6"
|
||||
dial = "1s"
|
||||
timeout = "10s"
|
||||
keepAlive = "60s"
|
||||
timer = 1000
|
||||
[httpClient.breaker]
|
||||
window = "10s"
|
||||
sleep = "100ms"
|
||||
bucket = 10
|
||||
ratio = 0.5
|
||||
request = 100
|
||||
|
||||
[rpc]
|
||||
[rpc.point]
|
||||
timeout = "1s"
|
41
app/admin/main/point/conf/BUILD
Normal file
41
app/admin/main/point/conf/BUILD
Normal file
@ -0,0 +1,41 @@
|
||||
package(default_visibility = ["//visibility:public"])
|
||||
|
||||
load(
|
||||
"@io_bazel_rules_go//go:def.bzl",
|
||||
"go_library",
|
||||
)
|
||||
|
||||
go_library(
|
||||
name = "go_default_library",
|
||||
srcs = ["conf.go"],
|
||||
importpath = "go-common/app/admin/main/point/conf",
|
||||
tags = ["automanaged"],
|
||||
visibility = ["//visibility:public"],
|
||||
deps = [
|
||||
"//library/cache/memcache:go_default_library",
|
||||
"//library/cache/redis:go_default_library",
|
||||
"//library/conf:go_default_library",
|
||||
"//library/database/sql:go_default_library",
|
||||
"//library/ecode/tip:go_default_library",
|
||||
"//library/log:go_default_library",
|
||||
"//library/net/http/blademaster:go_default_library",
|
||||
"//library/net/http/blademaster/middleware/permit:go_default_library",
|
||||
"//library/net/rpc:go_default_library",
|
||||
"//library/net/trace:go_default_library",
|
||||
"//vendor/github.com/BurntSushi/toml: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"],
|
||||
)
|
108
app/admin/main/point/conf/conf.go
Normal file
108
app/admin/main/point/conf/conf.go
Normal file
@ -0,0 +1,108 @@
|
||||
package conf
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"flag"
|
||||
|
||||
"go-common/library/cache/memcache"
|
||||
"go-common/library/cache/redis"
|
||||
"go-common/library/conf"
|
||||
"go-common/library/database/sql"
|
||||
ecode "go-common/library/ecode/tip"
|
||||
"go-common/library/log"
|
||||
bm "go-common/library/net/http/blademaster"
|
||||
"go-common/library/net/http/blademaster/middleware/permit"
|
||||
"go-common/library/net/rpc"
|
||||
"go-common/library/net/trace"
|
||||
|
||||
"github.com/BurntSushi/toml"
|
||||
)
|
||||
|
||||
// global var
|
||||
var (
|
||||
confPath string
|
||||
client *conf.Client
|
||||
// Conf config
|
||||
Conf = &Config{}
|
||||
)
|
||||
|
||||
// Config config set
|
||||
type Config struct {
|
||||
// base
|
||||
// elk
|
||||
Log *log.Config
|
||||
// http
|
||||
BM *bm.ServerConfig
|
||||
// tracer
|
||||
Tracer *trace.Config
|
||||
// redis
|
||||
Redis *redis.Config
|
||||
// memcache
|
||||
Memcache *memcache.Config
|
||||
// MySQL
|
||||
MySQL *sql.Config
|
||||
// ecode
|
||||
Ecode *ecode.Config
|
||||
//auth
|
||||
Auth *permit.Config
|
||||
//httpclient
|
||||
HTTPClient *bm.ClientConfig
|
||||
// rpc server
|
||||
RPC *RPCClient
|
||||
}
|
||||
|
||||
// RPCClient def.
|
||||
type RPCClient struct {
|
||||
Point *rpc.ClientConfig
|
||||
}
|
||||
|
||||
func init() {
|
||||
flag.StringVar(&confPath, "conf", "", "default config path")
|
||||
}
|
||||
|
||||
// Init init conf
|
||||
func Init() error {
|
||||
if confPath != "" {
|
||||
return local()
|
||||
}
|
||||
return remote()
|
||||
}
|
||||
|
||||
func local() (err error) {
|
||||
_, err = toml.DecodeFile(confPath, &Conf)
|
||||
return
|
||||
}
|
||||
|
||||
func remote() (err error) {
|
||||
if client, err = conf.New(); err != nil {
|
||||
return
|
||||
}
|
||||
if err = load(); err != nil {
|
||||
return
|
||||
}
|
||||
go func() {
|
||||
for range client.Event() {
|
||||
log.Info("config reload")
|
||||
if load() != nil {
|
||||
log.Error("config reload error (%v)", err)
|
||||
}
|
||||
}
|
||||
}()
|
||||
return
|
||||
}
|
||||
|
||||
func load() (err error) {
|
||||
var (
|
||||
s string
|
||||
ok bool
|
||||
tmpConf *Config
|
||||
)
|
||||
if s, ok = client.Toml2(); !ok {
|
||||
return errors.New("load config center error")
|
||||
}
|
||||
if _, err = toml.Decode(s, &tmpConf); err != nil {
|
||||
return errors.New("could not decode config")
|
||||
}
|
||||
*Conf = *tmpConf
|
||||
return
|
||||
}
|
55
app/admin/main/point/dao/BUILD
Normal file
55
app/admin/main/point/dao/BUILD
Normal file
@ -0,0 +1,55 @@
|
||||
package(default_visibility = ["//visibility:public"])
|
||||
|
||||
load(
|
||||
"@io_bazel_rules_go//go:def.bzl",
|
||||
"go_test",
|
||||
"go_library",
|
||||
)
|
||||
|
||||
go_test(
|
||||
name = "go_default_test",
|
||||
srcs = ["dao_test.go"],
|
||||
embed = [":go_default_library"],
|
||||
rundir = ".",
|
||||
tags = ["automanaged"],
|
||||
deps = [
|
||||
"//app/admin/main/point/conf:go_default_library",
|
||||
"//app/admin/main/point/model:go_default_library",
|
||||
"//vendor/github.com/smartystreets/goconvey/convey:go_default_library",
|
||||
],
|
||||
)
|
||||
|
||||
go_library(
|
||||
name = "go_default_library",
|
||||
srcs = [
|
||||
"dao.go",
|
||||
"point.go",
|
||||
"search.go",
|
||||
],
|
||||
importpath = "go-common/app/admin/main/point/dao",
|
||||
tags = ["automanaged"],
|
||||
visibility = ["//visibility:public"],
|
||||
deps = [
|
||||
"//app/admin/main/point/conf:go_default_library",
|
||||
"//app/admin/main/point/model:go_default_library",
|
||||
"//library/cache/memcache:go_default_library",
|
||||
"//library/database/elastic:go_default_library",
|
||||
"//library/database/sql: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"],
|
||||
)
|
53
app/admin/main/point/dao/dao.go
Normal file
53
app/admin/main/point/dao/dao.go
Normal file
@ -0,0 +1,53 @@
|
||||
package dao
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"go-common/app/admin/main/point/conf"
|
||||
"go-common/library/cache/memcache"
|
||||
"go-common/library/database/elastic"
|
||||
xsql "go-common/library/database/sql"
|
||||
bm "go-common/library/net/http/blademaster"
|
||||
)
|
||||
|
||||
const _searchBussinss = "vip_point_change_history"
|
||||
|
||||
// Dao dao
|
||||
type Dao struct {
|
||||
c *conf.Config
|
||||
mc *memcache.Pool
|
||||
db *xsql.DB
|
||||
client *bm.Client
|
||||
es *elastic.Elastic
|
||||
}
|
||||
|
||||
// New init mysql db
|
||||
func New(c *conf.Config) (dao *Dao) {
|
||||
dao = &Dao{
|
||||
c: c,
|
||||
mc: memcache.NewPool(c.Memcache),
|
||||
db: xsql.NewMySQL(c.MySQL),
|
||||
client: bm.NewClient(c.HTTPClient),
|
||||
// es
|
||||
es: elastic.NewElastic(nil),
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// Close close the resource.
|
||||
func (dao *Dao) Close() {
|
||||
dao.mc.Close()
|
||||
dao.db.Close()
|
||||
}
|
||||
|
||||
// Ping dao ping
|
||||
func (dao *Dao) Ping(c context.Context) error {
|
||||
return dao.pingMC(c)
|
||||
}
|
||||
|
||||
// pingMc ping
|
||||
func (dao *Dao) pingMC(c context.Context) (err error) {
|
||||
conn := dao.mc.Get(c)
|
||||
defer conn.Close()
|
||||
return
|
||||
}
|
33
app/admin/main/point/dao/dao_test.go
Normal file
33
app/admin/main/point/dao/dao_test.go
Normal file
@ -0,0 +1,33 @@
|
||||
package dao
|
||||
|
||||
import (
|
||||
"context"
|
||||
"flag"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
"go-common/app/admin/main/point/conf"
|
||||
"go-common/app/admin/main/point/model"
|
||||
|
||||
. "github.com/smartystreets/goconvey/convey"
|
||||
)
|
||||
|
||||
var (
|
||||
d *Dao
|
||||
)
|
||||
|
||||
func init() {
|
||||
dir, _ := filepath.Abs("../cmd/point-admin.toml")
|
||||
flag.Set("conf", dir)
|
||||
conf.Init()
|
||||
d = New(conf.Conf)
|
||||
}
|
||||
|
||||
func Test_PointHistory(t *testing.T) {
|
||||
Convey("Test_PointHistory", t, func() {
|
||||
arg := &model.ArgPointHistory{}
|
||||
res, err := d.PointHistory(context.TODO(), arg)
|
||||
So(err, ShouldBeNil)
|
||||
So(res, ShouldNotBeNil)
|
||||
})
|
||||
}
|
100
app/admin/main/point/dao/point.go
Normal file
100
app/admin/main/point/dao/point.go
Normal file
@ -0,0 +1,100 @@
|
||||
package dao
|
||||
|
||||
import (
|
||||
"context"
|
||||
xsql "database/sql"
|
||||
|
||||
"go-common/app/admin/main/point/model"
|
||||
"go-common/library/database/sql"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
const (
|
||||
_allPointConf = "SELECT id,app_id,point,operator,change_type,ctime,mtime FROM point_conf"
|
||||
_getPointConf = "SELECT id,app_id,point,operator,change_type,ctime,mtime FROM point_conf WHERE id=?"
|
||||
_addPointConf = "INSERT INTO point_conf (app_id,point,operator,change_type) VALUES (?,?,?,?)"
|
||||
_updatePointConf = "UPDATE point_conf SET point=?,operator=?,change_type=? where ID=?"
|
||||
_allAppInfo = "SELECT `id`,`name`,`app_key`,`purge_url` FROM `point_app_info`;"
|
||||
)
|
||||
|
||||
// PointConfList .
|
||||
func (d *Dao) PointConfList(c context.Context) (res []*model.PointConf, err error) {
|
||||
var rows *sql.Rows
|
||||
if rows, err = d.db.Query(c, _allPointConf); err != nil {
|
||||
err = errors.WithStack(err)
|
||||
return
|
||||
}
|
||||
defer rows.Close()
|
||||
for rows.Next() {
|
||||
r := &model.PointConf{}
|
||||
if err = rows.Scan(&r.ID, &r.AppID, &r.Point, &r.Operator, &r.ChangeType, &r.Ctime, &r.Mtime); err != nil {
|
||||
err = errors.WithStack(err)
|
||||
res = nil
|
||||
return
|
||||
}
|
||||
res = append(res, r)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// PointCoinInfo .
|
||||
func (d *Dao) PointCoinInfo(c context.Context, id int64) (r *model.PointConf, err error) {
|
||||
row := d.db.QueryRow(c, _getPointConf, id)
|
||||
r = new(model.PointConf)
|
||||
if err = row.Scan(&r.ID, &r.AppID, &r.Point, &r.Operator, &r.ChangeType, &r.Ctime, &r.Mtime); err != nil {
|
||||
if err == sql.ErrNoRows {
|
||||
err = nil
|
||||
r = nil
|
||||
} else {
|
||||
err = errors.WithStack(err)
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// PointCoinAdd .
|
||||
func (d *Dao) PointCoinAdd(c context.Context, pc *model.PointConf) (id int64, err error) {
|
||||
var res xsql.Result
|
||||
if res, err = d.db.Exec(c, _addPointConf, pc.AppID, pc.Point, pc.Operator, pc.ChangeType); err != nil {
|
||||
err = errors.WithStack(err)
|
||||
return
|
||||
}
|
||||
if id, err = res.LastInsertId(); err != nil {
|
||||
err = errors.WithStack(err)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// PointCoinEdit .
|
||||
func (d *Dao) PointCoinEdit(c context.Context, mp *model.PointConf) (eff int64, err error) {
|
||||
var res xsql.Result
|
||||
if res, err = d.db.Exec(c, _updatePointConf, mp.Point, mp.Operator, mp.ChangeType, mp.ID); err != nil {
|
||||
err = errors.WithStack(err)
|
||||
return
|
||||
}
|
||||
if eff, err = res.RowsAffected(); err != nil {
|
||||
err = errors.WithStack(err)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// AllAppInfo all appinfo.
|
||||
func (d *Dao) AllAppInfo(c context.Context) (res []*model.AppInfo, err error) {
|
||||
var rows *sql.Rows
|
||||
if rows, err = d.db.Query(c, _allAppInfo); err != nil {
|
||||
err = errors.WithStack(err)
|
||||
return
|
||||
}
|
||||
defer rows.Close()
|
||||
for rows.Next() {
|
||||
r := &model.AppInfo{}
|
||||
if err = rows.Scan(&r.ID, &r.Name, &r.AppKey, &r.PurgeURL); err != nil {
|
||||
err = errors.WithStack(err)
|
||||
res = nil
|
||||
return
|
||||
}
|
||||
res = append(res, r)
|
||||
}
|
||||
return
|
||||
}
|
37
app/admin/main/point/dao/search.go
Normal file
37
app/admin/main/point/dao/search.go
Normal file
@ -0,0 +1,37 @@
|
||||
package dao
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"go-common/app/admin/main/point/model"
|
||||
"go-common/library/database/elastic"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
// PointHistory get point change history from es.
|
||||
func (d *Dao) PointHistory(c context.Context, arg *model.ArgPointHistory) (res *model.SearchData, err error) {
|
||||
var changeTimeFrom, changeTimeTo string
|
||||
req := d.es.NewRequest(_searchBussinss).Index(_searchBussinss).Pn(int(arg.PN)).Ps(int(arg.PS))
|
||||
req.Fields("id", "mid", "order_id", "relation_id", "point_balance", "change_time", "change_type", "remark", "operator")
|
||||
if arg.ChangeType != 0 {
|
||||
req.WhereEq("change_type", arg.ChangeType)
|
||||
}
|
||||
if arg.Mid > 0 {
|
||||
req.WhereEq("mid", arg.Mid)
|
||||
}
|
||||
if arg.StartChangeTime != 0 {
|
||||
changeTimeFrom = time.Unix(arg.StartChangeTime, 0).Format("2006-01-02 15:04:05")
|
||||
}
|
||||
if arg.EndChangeTime != 0 {
|
||||
changeTimeTo = time.Unix(arg.EndChangeTime, 0).Format("2006-01-02 15:04:05")
|
||||
}
|
||||
req.WhereRange("change_time", changeTimeFrom, changeTimeTo, elastic.RangeScopeLcRc)
|
||||
req.Order("change_time", "desc")
|
||||
res = &model.SearchData{}
|
||||
if err = req.Scan(c, &res); err != nil {
|
||||
err = errors.WithStack(err)
|
||||
}
|
||||
return
|
||||
}
|
41
app/admin/main/point/http/BUILD
Normal file
41
app/admin/main/point/http/BUILD
Normal file
@ -0,0 +1,41 @@
|
||||
package(default_visibility = ["//visibility:public"])
|
||||
|
||||
load(
|
||||
"@io_bazel_rules_go//go:def.bzl",
|
||||
"go_library",
|
||||
)
|
||||
|
||||
go_library(
|
||||
name = "go_default_library",
|
||||
srcs = [
|
||||
"http.go",
|
||||
"point.go",
|
||||
],
|
||||
importpath = "go-common/app/admin/main/point/http",
|
||||
tags = ["automanaged"],
|
||||
visibility = ["//visibility:public"],
|
||||
deps = [
|
||||
"//app/admin/main/point/conf:go_default_library",
|
||||
"//app/admin/main/point/model:go_default_library",
|
||||
"//app/admin/main/point/service:go_default_library",
|
||||
"//app/service/main/point/model:go_default_library",
|
||||
"//library/ecode:go_default_library",
|
||||
"//library/log:go_default_library",
|
||||
"//library/net/http/blademaster:go_default_library",
|
||||
"//library/net/http/blademaster/middleware/permit: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"],
|
||||
)
|
52
app/admin/main/point/http/http.go
Normal file
52
app/admin/main/point/http/http.go
Normal file
@ -0,0 +1,52 @@
|
||||
package http
|
||||
|
||||
import (
|
||||
"go-common/app/admin/main/point/conf"
|
||||
"go-common/app/admin/main/point/service"
|
||||
"go-common/library/log"
|
||||
bm "go-common/library/net/http/blademaster"
|
||||
"go-common/library/net/http/blademaster/middleware/permit"
|
||||
)
|
||||
|
||||
var (
|
||||
svc *service.Service
|
||||
authSvc *permit.Permit
|
||||
)
|
||||
|
||||
// Init init
|
||||
func Init(c *conf.Config) {
|
||||
initService(c)
|
||||
// init router
|
||||
engine := bm.DefaultServer(c.BM)
|
||||
initRouter(engine)
|
||||
if err := engine.Start(); err != nil {
|
||||
log.Error("engine.Start error(%v)", err)
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
// initService init services.
|
||||
func initService(c *conf.Config) {
|
||||
authSvc = permit.New(c.Auth)
|
||||
svc = service.New(c)
|
||||
}
|
||||
|
||||
// initRouter init outer router api path.
|
||||
func initRouter(e *bm.Engine) {
|
||||
//init api
|
||||
e.Ping(ping)
|
||||
group := e.Group("/x/admin/point", authSvc.Permit("VIP_POINT"))
|
||||
{
|
||||
group.GET("/conf/list", pointConfList)
|
||||
group.GET("/conf/info", pointConfInfo)
|
||||
group.POST("/conf/add", pointConfAdd)
|
||||
group.POST("/conf/edit", pointConfEdit)
|
||||
group.GET("/history/list", pointHistory)
|
||||
group.POST("/user/add", pointUserAdd)
|
||||
}
|
||||
}
|
||||
|
||||
// ping check server ok.
|
||||
func ping(c *bm.Context) {
|
||||
svc.Ping(c)
|
||||
}
|
125
app/admin/main/point/http/point.go
Normal file
125
app/admin/main/point/http/point.go
Normal file
@ -0,0 +1,125 @@
|
||||
package http
|
||||
|
||||
import (
|
||||
"go-common/app/admin/main/point/model"
|
||||
pointmol "go-common/app/service/main/point/model"
|
||||
"go-common/library/ecode"
|
||||
"go-common/library/log"
|
||||
bm "go-common/library/net/http/blademaster"
|
||||
)
|
||||
|
||||
func pointConfList(c *bm.Context) {
|
||||
var (
|
||||
err error
|
||||
res []*model.PointConf
|
||||
)
|
||||
if res, err = svc.PointConfList(c); err != nil {
|
||||
return
|
||||
}
|
||||
c.JSON(&model.PageInfo{Count: len(res), Item: res}, nil)
|
||||
}
|
||||
|
||||
func pointConfInfo(c *bm.Context) {
|
||||
var (
|
||||
err error
|
||||
res *model.PointConf
|
||||
)
|
||||
arg := &model.ArgID{}
|
||||
if err = c.Bind(arg); err != nil {
|
||||
return
|
||||
}
|
||||
if res, err = svc.PointCoinInfo(c, arg.ID); err != nil {
|
||||
log.Error("svc.PointCoinInfo(%d), err(%+v)", arg.ID, err)
|
||||
c.JSON(nil, err)
|
||||
return
|
||||
}
|
||||
c.JSON(res, nil)
|
||||
}
|
||||
|
||||
func pointConfAdd(c *bm.Context) {
|
||||
var (
|
||||
err error
|
||||
)
|
||||
opI, ok := c.Get("username")
|
||||
if !ok {
|
||||
c.JSON(nil, ecode.AccessDenied)
|
||||
return
|
||||
}
|
||||
pc := &model.PointConf{}
|
||||
if err = c.Bind(pc); err != nil {
|
||||
return
|
||||
}
|
||||
pc.Operator = opI.(string)
|
||||
if _, err = svc.PointCoinAdd(c, pc); err != nil {
|
||||
log.Error("svc.PointCoinAdd(%+v), err(%+v)", pc, err)
|
||||
c.JSON(nil, err)
|
||||
return
|
||||
}
|
||||
c.JSON(nil, nil)
|
||||
}
|
||||
|
||||
func pointConfEdit(c *bm.Context) {
|
||||
var (
|
||||
err error
|
||||
)
|
||||
opI, ok := c.Get("username")
|
||||
if !ok {
|
||||
c.JSON(nil, ecode.AccessDenied)
|
||||
return
|
||||
}
|
||||
pc := &model.PointConf{}
|
||||
if err = c.Bind(pc); err != nil {
|
||||
return
|
||||
} else if pc.ID == 0 {
|
||||
c.JSON(nil, ecode.RequestErr)
|
||||
return
|
||||
}
|
||||
pc.Operator = opI.(string)
|
||||
if err = svc.PointCoinEdit(c, pc); err != nil {
|
||||
log.Error("svc.PointCoinEdit(%+v), err(%+v)", pc, err)
|
||||
c.JSON(nil, err)
|
||||
return
|
||||
}
|
||||
c.JSON(nil, nil)
|
||||
}
|
||||
|
||||
func pointHistory(c *bm.Context) {
|
||||
var err error
|
||||
arg := &model.ArgPointHistory{}
|
||||
if err = c.Bind(arg); err != nil {
|
||||
return
|
||||
}
|
||||
c.JSON(svc.PointHistory(c, arg))
|
||||
}
|
||||
|
||||
func pointUserAdd(c *bm.Context) {
|
||||
var (
|
||||
err error
|
||||
)
|
||||
opI, ok := c.Get("username")
|
||||
if !ok {
|
||||
c.JSON(nil, ecode.AccessDenied)
|
||||
return
|
||||
}
|
||||
req := new(model.ArgPoint)
|
||||
if err = c.Bind(req); err != nil {
|
||||
log.Error("point add bind %+v", err)
|
||||
return
|
||||
}
|
||||
if req.Point <= 0 {
|
||||
c.JSON(nil, ecode.RequestErr)
|
||||
return
|
||||
}
|
||||
arg := new(pointmol.ArgPoint)
|
||||
arg.Mid = req.Mid
|
||||
arg.Point = req.Point
|
||||
arg.Remark = req.Remark
|
||||
arg.Operator = opI.(string)
|
||||
arg.ChangeType = model.PointSystem
|
||||
if err = svc.PointAdd(c, arg); err != nil {
|
||||
log.Error("point add(%+v) faild(%+v)", arg, err)
|
||||
c.JSON(nil, err)
|
||||
return
|
||||
}
|
||||
c.JSON(nil, nil)
|
||||
}
|
32
app/admin/main/point/model/BUILD
Normal file
32
app/admin/main/point/model/BUILD
Normal file
@ -0,0 +1,32 @@
|
||||
package(default_visibility = ["//visibility:public"])
|
||||
|
||||
load(
|
||||
"@io_bazel_rules_go//go:def.bzl",
|
||||
"go_library",
|
||||
)
|
||||
|
||||
go_library(
|
||||
name = "go_default_library",
|
||||
srcs = [
|
||||
"model.go",
|
||||
"point.go",
|
||||
"search.go",
|
||||
],
|
||||
importpath = "go-common/app/admin/main/point/model",
|
||||
tags = ["automanaged"],
|
||||
visibility = ["//visibility:public"],
|
||||
)
|
||||
|
||||
filegroup(
|
||||
name = "package-srcs",
|
||||
srcs = glob(["**"]),
|
||||
tags = ["automanaged"],
|
||||
visibility = ["//visibility:private"],
|
||||
)
|
||||
|
||||
filegroup(
|
||||
name = "all-srcs",
|
||||
srcs = [":package-srcs"],
|
||||
tags = ["automanaged"],
|
||||
visibility = ["//visibility:public"],
|
||||
)
|
49
app/admin/main/point/model/model.go
Normal file
49
app/admin/main/point/model/model.go
Normal file
@ -0,0 +1,49 @@
|
||||
package model
|
||||
|
||||
// ArgPointHistory .
|
||||
type ArgPointHistory struct {
|
||||
Mid int64 `form:"mid"`
|
||||
ChangeType int64 `form:"change_type"`
|
||||
StartChangeTime int64 `form:"begin_time"`
|
||||
EndChangeTime int64 `form:"end_time"`
|
||||
BatchID string `form:"batch_id"`
|
||||
RelationID string `form:"relation_id"`
|
||||
PN int64 `form:"pn" default:"1"`
|
||||
PS int64 `form:"ps" default:"50"`
|
||||
}
|
||||
|
||||
// ArgID .
|
||||
type ArgID struct {
|
||||
ID int64 `form:"id" validate:"required,min=1,gte=1"`
|
||||
}
|
||||
|
||||
// PageInfo common page info.
|
||||
type PageInfo struct {
|
||||
Count int `json:"count"`
|
||||
CurrentPage int `json:"currentPage,omitempty"`
|
||||
Item interface{} `json:"item"`
|
||||
}
|
||||
|
||||
// point add suc.
|
||||
const (
|
||||
PointAddSuc = 1
|
||||
)
|
||||
|
||||
// point change type
|
||||
const (
|
||||
ExchangeVip = iota + 1
|
||||
Charge //充电
|
||||
Contract //承包
|
||||
PointSystem //系统发放
|
||||
FYMReward //分院帽奖励
|
||||
ExchangePendant //兑换挂件
|
||||
MJActive //萌节活动
|
||||
ReAcquirePointDedution //重复领取
|
||||
)
|
||||
|
||||
// ArgPoint .
|
||||
type ArgPoint struct {
|
||||
Mid int64 `form:"mid" validate:"required,min=1,gte=1"`
|
||||
Point int64 `form:"point"`
|
||||
Remark string `form:"remark"`
|
||||
}
|
38
app/admin/main/point/model/point.go
Normal file
38
app/admin/main/point/model/point.go
Normal file
@ -0,0 +1,38 @@
|
||||
package model
|
||||
|
||||
import "time"
|
||||
|
||||
// PointConf .
|
||||
type PointConf struct {
|
||||
ID int64 `json:"id" form:"id"`
|
||||
AppID int64 `json:"app_id" form:"app_id"`
|
||||
Point int64 `json:"point" form:"point"`
|
||||
Operator string `json:"operator" form:"operator"`
|
||||
ChangeType int64 `json:"change_type" form:"change_type"`
|
||||
Name string `json:"business_name" form:"name"`
|
||||
Ctime time.Time `json:"-"`
|
||||
Mtime time.Time `json:"mtime"`
|
||||
}
|
||||
|
||||
// PointHistory .
|
||||
type PointHistory struct {
|
||||
ID int64 `json:"id"`
|
||||
Mid int64 `json:"mid"`
|
||||
OrderID string `json:"order_id"`
|
||||
RelationID string `json:"relation_id"`
|
||||
PointBalance float64 `json:"point_balance"`
|
||||
ChangeTime string `json:"change_time"`
|
||||
ChangeType int8 `json:"change_type"`
|
||||
Remark string `json:"remark"`
|
||||
Operator string `json:"operator"`
|
||||
}
|
||||
|
||||
// AppInfo .
|
||||
type AppInfo struct {
|
||||
ID int64 `json:"_"`
|
||||
Name string `json:"name"`
|
||||
AppKey string `json:"app_key"`
|
||||
PurgeURL string `json:"purge_url"`
|
||||
Ctime time.Time `json:"-"`
|
||||
Mtime time.Time `json:"mtime"`
|
||||
}
|
16
app/admin/main/point/model/search.go
Normal file
16
app/admin/main/point/model/search.go
Normal file
@ -0,0 +1,16 @@
|
||||
package model
|
||||
|
||||
// SearchPage struct.
|
||||
type SearchPage struct {
|
||||
PN int `json:"num"`
|
||||
PS int `json:"size"`
|
||||
Total int `json:"total"`
|
||||
}
|
||||
|
||||
// SearchData search result detail.
|
||||
type SearchData struct {
|
||||
Order string `json:"order"`
|
||||
Sort string `json:"sort"`
|
||||
Page *SearchPage `json:"page"`
|
||||
Result []*PointHistory `json:"result"`
|
||||
}
|
56
app/admin/main/point/service/BUILD
Normal file
56
app/admin/main/point/service/BUILD
Normal file
@ -0,0 +1,56 @@
|
||||
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"],
|
||||
rundir = ".",
|
||||
tags = ["automanaged"],
|
||||
deps = [
|
||||
"//app/admin/main/point/conf:go_default_library",
|
||||
"//app/admin/main/point/model:go_default_library",
|
||||
"//app/service/main/point/model:go_default_library",
|
||||
"//vendor/github.com/smartystreets/goconvey/convey:go_default_library",
|
||||
],
|
||||
)
|
||||
|
||||
go_library(
|
||||
name = "go_default_library",
|
||||
srcs = [
|
||||
"point.go",
|
||||
"service.go",
|
||||
],
|
||||
importpath = "go-common/app/admin/main/point/service",
|
||||
tags = ["automanaged"],
|
||||
visibility = ["//visibility:public"],
|
||||
deps = [
|
||||
"//app/admin/main/point/conf:go_default_library",
|
||||
"//app/admin/main/point/dao:go_default_library",
|
||||
"//app/admin/main/point/model:go_default_library",
|
||||
"//app/service/main/point/model:go_default_library",
|
||||
"//app/service/main/point/rpc/client:go_default_library",
|
||||
"//library/ecode:go_default_library",
|
||||
"//library/log: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"],
|
||||
)
|
91
app/admin/main/point/service/point.go
Normal file
91
app/admin/main/point/service/point.go
Normal file
@ -0,0 +1,91 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
|
||||
"go-common/app/admin/main/point/model"
|
||||
pointmol "go-common/app/service/main/point/model"
|
||||
"go-common/library/ecode"
|
||||
)
|
||||
|
||||
// PointConfList .
|
||||
func (s *Service) PointConfList(c context.Context) (res []*model.PointConf, err error) {
|
||||
res, err = s.dao.PointConfList(c)
|
||||
if res == nil {
|
||||
return
|
||||
}
|
||||
for _, v := range res {
|
||||
v.Name = s.appMap[v.AppID]
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// PointCoinInfo .
|
||||
func (s *Service) PointCoinInfo(c context.Context, id int64) (res *model.PointConf, err error) {
|
||||
res, err = s.dao.PointCoinInfo(c, id)
|
||||
if res == nil {
|
||||
return
|
||||
}
|
||||
res.Name = s.appMap[res.AppID]
|
||||
return
|
||||
}
|
||||
|
||||
// PointCoinAdd .
|
||||
func (s *Service) PointCoinAdd(c context.Context, pc *model.PointConf) (id int64, err error) {
|
||||
if _, ok := s.appMap[pc.AppID]; !ok {
|
||||
err = ecode.RequestErr
|
||||
return
|
||||
}
|
||||
return s.dao.PointCoinAdd(c, pc)
|
||||
}
|
||||
|
||||
// PointCoinEdit .
|
||||
func (s *Service) PointCoinEdit(c context.Context, pc *model.PointConf) (err error) {
|
||||
var (
|
||||
info *model.PointConf
|
||||
)
|
||||
if info, err = s.PointCoinInfo(c, pc.ID); err != nil {
|
||||
err = errors.WithStack(err)
|
||||
return
|
||||
}
|
||||
if info == nil {
|
||||
err = ecode.RequestErr
|
||||
return
|
||||
}
|
||||
if _, err = s.dao.PointCoinEdit(c, pc); err != nil {
|
||||
err = errors.WithStack(err)
|
||||
return
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// PointHistory .
|
||||
func (s *Service) PointHistory(c context.Context, arg *model.ArgPointHistory) (res *model.PageInfo, err error) {
|
||||
var sr *model.SearchData
|
||||
if sr, err = s.dao.PointHistory(c, arg); err != nil {
|
||||
return
|
||||
}
|
||||
res = &model.PageInfo{
|
||||
Item: sr.Result,
|
||||
Count: sr.Page.Total,
|
||||
CurrentPage: sr.Page.PN,
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// PointAdd point add.
|
||||
func (s *Service) PointAdd(c context.Context, pc *pointmol.ArgPoint) (err error) {
|
||||
var (
|
||||
status int8
|
||||
)
|
||||
if status, err = s.pointRPC.AddPoint(c, pc); err != nil {
|
||||
err = errors.Wrapf(err, "s.pointRPC.AddPoint(%v)", pc)
|
||||
return
|
||||
}
|
||||
if status != model.PointAddSuc {
|
||||
err = errors.New("point add not success")
|
||||
}
|
||||
return
|
||||
}
|
66
app/admin/main/point/service/service.go
Normal file
66
app/admin/main/point/service/service.go
Normal file
@ -0,0 +1,66 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"go-common/app/admin/main/point/conf"
|
||||
"go-common/app/admin/main/point/dao"
|
||||
"go-common/app/admin/main/point/model"
|
||||
pointrpc "go-common/app/service/main/point/rpc/client"
|
||||
"go-common/library/log"
|
||||
)
|
||||
|
||||
// Service struct
|
||||
type Service struct {
|
||||
c *conf.Config
|
||||
dao *dao.Dao
|
||||
pointRPC *pointrpc.Service
|
||||
appMap map[int64]string
|
||||
}
|
||||
|
||||
// New init
|
||||
func New(c *conf.Config) (s *Service) {
|
||||
s = &Service{
|
||||
c: c,
|
||||
dao: dao.New(c),
|
||||
pointRPC: pointrpc.New(c.RPC.Point),
|
||||
appMap: make(map[int64]string),
|
||||
}
|
||||
go s.loadappinfoproc()
|
||||
return s
|
||||
}
|
||||
|
||||
// Ping Service
|
||||
func (s *Service) Ping(c context.Context) (err error) {
|
||||
return s.dao.Ping(c)
|
||||
}
|
||||
|
||||
// Close Service
|
||||
func (s *Service) Close() {
|
||||
s.dao.Close()
|
||||
}
|
||||
|
||||
func (s *Service) loadappinfoproc() {
|
||||
|
||||
for {
|
||||
s.loadAppInfo()
|
||||
time.Sleep(time.Minute * 2)
|
||||
}
|
||||
}
|
||||
|
||||
func (s *Service) loadAppInfo() {
|
||||
var (
|
||||
res []*model.AppInfo
|
||||
err error
|
||||
)
|
||||
if res, err = s.dao.AllAppInfo(context.TODO()); err != nil {
|
||||
log.Error("loadAppInfo AllAppInfo error(%v)", err)
|
||||
return
|
||||
}
|
||||
aMap := make(map[int64]string, len(res))
|
||||
for _, v := range res {
|
||||
aMap[v.ID] = v.Name
|
||||
}
|
||||
s.appMap = aMap
|
||||
}
|
86
app/admin/main/point/service/service_test.go
Normal file
86
app/admin/main/point/service/service_test.go
Normal file
@ -0,0 +1,86 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"context"
|
||||
"flag"
|
||||
"fmt"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"go-common/app/admin/main/point/conf"
|
||||
"go-common/app/admin/main/point/model"
|
||||
pointmol "go-common/app/service/main/point/model"
|
||||
|
||||
. "github.com/smartystreets/goconvey/convey"
|
||||
)
|
||||
|
||||
var (
|
||||
s *Service
|
||||
c = context.TODO()
|
||||
)
|
||||
|
||||
func init() {
|
||||
dir, _ := filepath.Abs("../cmd/point-admin.toml")
|
||||
flag.Set("conf", dir)
|
||||
conf.Init()
|
||||
s = New(conf.Conf)
|
||||
fmt.Printf("%+v", conf.Conf)
|
||||
time.Sleep(time.Second)
|
||||
}
|
||||
|
||||
func Test_PointHistory(t *testing.T) {
|
||||
Convey("Test_PointHistory", t, func() {
|
||||
arg := &model.ArgPointHistory{}
|
||||
res, err := s.PointHistory(context.TODO(), arg)
|
||||
So(err, ShouldBeNil)
|
||||
So(res, ShouldNotBeNil)
|
||||
})
|
||||
}
|
||||
|
||||
func Test_PointCoinInfo(t *testing.T) {
|
||||
Convey("Test_PointCoinInfo", t, func() {
|
||||
res, err := s.PointCoinInfo(context.TODO(), 1)
|
||||
So(err, ShouldBeNil)
|
||||
So(res, ShouldNotBeNil)
|
||||
})
|
||||
}
|
||||
|
||||
func Test_PointCoin(t *testing.T) {
|
||||
Convey("Test_PointCoin", t, func() {
|
||||
var (
|
||||
id int64
|
||||
err error
|
||||
res *model.PointConf
|
||||
)
|
||||
pc := &model.PointConf{AppID: 1}
|
||||
id, err = s.PointCoinAdd(context.TODO(), pc)
|
||||
So(err, ShouldBeNil)
|
||||
So(id, ShouldBeGreaterThanOrEqualTo, 1)
|
||||
res, err = s.PointCoinInfo(context.TODO(), id)
|
||||
So(err, ShouldBeNil)
|
||||
So(res, ShouldNotBeNil)
|
||||
So(res.AppID, ShouldEqual, pc.AppID)
|
||||
})
|
||||
}
|
||||
|
||||
func Test_PointConfList(t *testing.T) {
|
||||
Convey("Test_PointConfList", t, func() {
|
||||
res, err := s.PointConfList(context.TODO())
|
||||
So(err, ShouldBeNil)
|
||||
So(res, ShouldNotBeNil)
|
||||
})
|
||||
}
|
||||
|
||||
func TestPointAdd(t *testing.T) {
|
||||
Convey("TestPointAdd", t, func() {
|
||||
arg := new(pointmol.ArgPoint)
|
||||
arg.Mid = int64(2222)
|
||||
arg.Point = int64(1)
|
||||
arg.Remark = "系统发放"
|
||||
arg.Operator = "yubaihai"
|
||||
arg.ChangeType = model.PointSystem
|
||||
err := s.PointAdd(c, arg)
|
||||
So(err, ShouldBeNil)
|
||||
})
|
||||
}
|
Reference in New Issue
Block a user