Create & Init Project...
This commit is contained in:
75
app/admin/main/mcn/dao/up/BUILD
Normal file
75
app/admin/main/mcn/dao/up/BUILD
Normal file
@ -0,0 +1,75 @@
|
||||
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",
|
||||
"mcn_account.go",
|
||||
"mcn_manage.go",
|
||||
"mcn_recommend.go",
|
||||
"memcache.go",
|
||||
"statistics.go",
|
||||
"up_base_Info.go",
|
||||
],
|
||||
importpath = "go-common/app/admin/main/mcn/dao/up",
|
||||
tags = ["automanaged"],
|
||||
visibility = ["//visibility:public"],
|
||||
deps = [
|
||||
"//app/admin/main/mcn/conf:go_default_library",
|
||||
"//app/admin/main/mcn/model:go_default_library",
|
||||
"//app/interface/main/mcn/model/datamodel:go_default_library",
|
||||
"//app/interface/main/mcn/model/mcnmodel:go_default_library",
|
||||
"//library/cache/memcache:go_default_library",
|
||||
"//library/database/sql:go_default_library",
|
||||
"//library/ecode:go_default_library",
|
||||
"//library/log:go_default_library",
|
||||
"//library/net/http/blademaster:go_default_library",
|
||||
"//library/net/metadata:go_default_library",
|
||||
"//library/time:go_default_library",
|
||||
"//library/xstr: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",
|
||||
"mcn_account_test.go",
|
||||
"mcn_manage_test.go",
|
||||
"mcn_recommend_test.go",
|
||||
"memcache_test.go",
|
||||
"statistics_test.go",
|
||||
"up_base_Info_test.go",
|
||||
],
|
||||
embed = [":go_default_library"],
|
||||
rundir = ".",
|
||||
tags = ["automanaged"],
|
||||
deps = [
|
||||
"//app/admin/main/mcn/conf:go_default_library",
|
||||
"//app/admin/main/mcn/model:go_default_library",
|
||||
"//library/time:go_default_library",
|
||||
"//vendor/github.com/smartystreets/goconvey/convey:go_default_library",
|
||||
"//vendor/gopkg.in/h2non/gock.v1:go_default_library",
|
||||
],
|
||||
)
|
60
app/admin/main/mcn/dao/up/dao.go
Normal file
60
app/admin/main/mcn/dao/up/dao.go
Normal file
@ -0,0 +1,60 @@
|
||||
package up
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"go-common/app/admin/main/mcn/conf"
|
||||
"go-common/library/cache/memcache"
|
||||
xsql "go-common/library/database/sql"
|
||||
bm "go-common/library/net/http/blademaster"
|
||||
)
|
||||
|
||||
// Dao dao
|
||||
type Dao struct {
|
||||
c *conf.Config
|
||||
mc *memcache.Pool
|
||||
db *xsql.DB
|
||||
client *bm.Client
|
||||
arcTopURL string
|
||||
dataFansURL string
|
||||
dataFansBaseAttrURL string
|
||||
dataFansAreaURL string
|
||||
dataFansTypeURL string
|
||||
dataFansTagURL string
|
||||
}
|
||||
|
||||
// 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),
|
||||
// http client
|
||||
client: bm.NewClient(c.HTTPClient),
|
||||
// url
|
||||
arcTopURL: c.Host.API + _arcTopURL,
|
||||
dataFansURL: c.Host.API + _dataFansURL,
|
||||
dataFansBaseAttrURL: c.Host.API + _dataFansBaseAttrURL,
|
||||
dataFansAreaURL: c.Host.API + _dataFansAreaURL,
|
||||
dataFansTypeURL: c.Host.API + _dataFansTypeURL,
|
||||
dataFansTagURL: c.Host.API + _dataFansTagURL,
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// Close close the resource.
|
||||
func (d *Dao) Close() {
|
||||
d.mc.Close()
|
||||
d.db.Close()
|
||||
}
|
||||
|
||||
// Ping dao ping
|
||||
func (d *Dao) Ping(c context.Context) error {
|
||||
// TODO: if you need use mc,redis, please add
|
||||
return d.db.Ping(c)
|
||||
}
|
||||
|
||||
// BeginTran start tx .
|
||||
func (d *Dao) BeginTran(c context.Context) (tx *xsql.Tx, err error) {
|
||||
return d.db.Begin(c)
|
||||
}
|
47
app/admin/main/mcn/dao/up/dao_test.go
Normal file
47
app/admin/main/mcn/dao/up/dao_test.go
Normal file
@ -0,0 +1,47 @@
|
||||
package up
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"os"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"go-common/app/admin/main/mcn/conf"
|
||||
|
||||
"gopkg.in/h2non/gock.v1"
|
||||
)
|
||||
|
||||
var (
|
||||
d *Dao
|
||||
)
|
||||
|
||||
func TestMain(m *testing.M) {
|
||||
if os.Getenv("DEPLOY_ENV") != "" {
|
||||
flag.Set("app_id", "main.archive.mcn-admin")
|
||||
flag.Set("conf_token", "220af473858ad67f75586b66bece0e6b")
|
||||
flag.Set("tree_id", "58930")
|
||||
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/mcn-admin-test.toml")
|
||||
}
|
||||
|
||||
flag.Parse()
|
||||
if err := conf.Init(); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
d = New(conf.Conf)
|
||||
d.client.SetTransport(gock.DefaultTransport)
|
||||
m.Run()
|
||||
os.Exit(0)
|
||||
}
|
||||
|
||||
func httpMock(method, url string) *gock.Request {
|
||||
r := gock.New(url)
|
||||
r.Method = strings.ToUpper(method)
|
||||
return r
|
||||
}
|
280
app/admin/main/mcn/dao/up/mcn_account.go
Normal file
280
app/admin/main/mcn/dao/up/mcn_account.go
Normal file
@ -0,0 +1,280 @@
|
||||
package up
|
||||
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"go-common/app/admin/main/mcn/model"
|
||||
xsql "go-common/library/database/sql"
|
||||
xtime "go-common/library/time"
|
||||
"go-common/library/xstr"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
const (
|
||||
_inMcnSignEntrySQL = "INSERT mcn_sign(mcn_mid,begin_date,end_date,permission) VALUES (?,?,?,?)"
|
||||
_inMcnSignPaySQL = "INSERT mcn_sign_pay(mcn_mid,sign_id,due_date,pay_value,note) VALUES (?,?,?,?,?)"
|
||||
_upMcnSignOPSQL = "UPDATE mcn_sign SET state = ?, reject_time = ?, reject_reason = ? WHERE id = ?"
|
||||
_upMcnUpOPSQL = "UPDATE mcn_up SET state = ?, reject_time = ?, reject_reason = ?, state_change_time = ? WHERE id = ?"
|
||||
_mcnUpPermitOPSQL = "UPDATE mcn_up SET permission = ?, up_auth_link = ? WHERE sign_id = ? AND mcn_mid = ? AND up_mid = ?"
|
||||
_upPermitApplyOPSQL = "UPDATE mcn_up_permission_apply SET state = ?, reject_reason = ?, reject_time = ?, admin_id = ?, admin_name = ? WHERE id = ?"
|
||||
_selMcnSignsSQL = `SELECT id,mcn_mid,company_name,company_license_id,company_license_link,contract_link,contact_name,
|
||||
contact_title,contact_idcard,contact_phone,begin_date,end_date,reject_reason,reject_time,state,ctime,mtime,permission FROM mcn_sign WHERE state = ? ORDER BY mtime DESC limit ?,?`
|
||||
_selMcnSignSQL = `SELECT id,mcn_mid,company_name,company_license_id,company_license_link,contract_link,contact_name,
|
||||
contact_title,contact_idcard,contact_phone,begin_date,end_date,reject_reason,reject_time,state,ctime,mtime,permission FROM mcn_sign WHERE id = ?`
|
||||
_selMcnSignPayMapSQL = "SELECT id,sign_id,due_date,pay_value,state FROM mcn_sign_pay WHERE sign_id IN (%s) AND state IN (0,1)"
|
||||
_selMcnUpsSQL = "SELECT id,sign_id,mcn_mid,up_mid,begin_date,end_date,contract_link,up_auth_link,reject_reason,reject_time,state,ctime,mtime,up_type,site_link,confirm_time,publication_price,permission FROM mcn_up WHERE state = ? ORDER BY mtime DESC limit ?,?"
|
||||
_selMcnUpSQL = "SELECT id,sign_id,mcn_mid,up_mid,begin_date,end_date,contract_link,up_auth_link,reject_reason,reject_time,state,ctime,mtime,up_type,site_link,confirm_time,publication_price,permission FROM mcn_up WHERE id = ?"
|
||||
_selMcnSignCountUQTimeSQL = "SELECT COUNT(1) FROM mcn_sign WHERE mcn_mid = ? AND state IN (0,1,2,10,13,15) AND (end_date >= ? OR end_date >= ?) AND begin_date <= ?"
|
||||
_mcnSignTotalSQL = "SELECT COUNT(1) FROM mcn_sign WHERE state = ?"
|
||||
_mcnUpTotalSQL = "SELECT COUNT(1) FROM mcn_up WHERE state = ?"
|
||||
_mcnSignNoStateCountSQL = "SELECT COUNT(1) FROM mcn_sign WHERE mcn_mid = ? AND state IN (0,1,2,10,13,15)"
|
||||
_mcnUpPermitReviewsSQL = "SELECT id,mcn_mid,up_mid,sign_id,new_permission,old_permission,reject_reason,reject_time,state,ctime,mtime,admin_id,admin_name,up_auth_link FROM mcn_up_permission_apply WHERE state = ? ORDER BY mtime DESC limit ?,?"
|
||||
_mcnUpPermitReviewSQL = "SELECT id,mcn_mid,up_mid,sign_id,new_permission,old_permission,reject_reason,reject_time,state,ctime,mtime,admin_id,admin_name,up_auth_link FROM mcn_up_permission_apply WHERE id = ?"
|
||||
_mcnUpPermitTotalSQL = "SELECT COUNT(1) FROM mcn_up_permission_apply WHERE state = ?"
|
||||
)
|
||||
|
||||
// TxAddMcnSignEntry .
|
||||
func (d *Dao) TxAddMcnSignEntry(tx *xsql.Tx, mcnMid int64, beginDate, endDate string, permission uint32) (lastID int64, err error) {
|
||||
var res sql.Result
|
||||
if res, err = tx.Exec(_inMcnSignEntrySQL, mcnMid, beginDate, endDate, permission); err != nil {
|
||||
return lastID, err
|
||||
}
|
||||
if lastID, err = res.LastInsertId(); err != nil {
|
||||
return lastID, errors.Errorf("res.LastInsertId(%d,%s,%s,%d) error(%+v)", mcnMid, beginDate, endDate, permission, err)
|
||||
}
|
||||
return lastID, nil
|
||||
}
|
||||
|
||||
// TxAddMcnSignPay .
|
||||
func (d *Dao) TxAddMcnSignPay(tx *xsql.Tx, mcnMid, signID, payValue int64, dueDate, note string) (rows int64, err error) {
|
||||
var res sql.Result
|
||||
if res, err = tx.Exec(_inMcnSignPaySQL, mcnMid, signID, dueDate, payValue, note); err != nil {
|
||||
return rows, err
|
||||
}
|
||||
return res.RowsAffected()
|
||||
}
|
||||
|
||||
// UpMcnSignOP .
|
||||
func (d *Dao) UpMcnSignOP(c context.Context, signID int64, state int8, rejectTime xtime.Time, rejectReason string) (rows int64, err error) {
|
||||
var res sql.Result
|
||||
if res, err = d.db.Exec(c, _upMcnSignOPSQL, state, rejectTime, rejectReason, signID); err != nil {
|
||||
return rows, err
|
||||
}
|
||||
return res.RowsAffected()
|
||||
}
|
||||
|
||||
// UpMcnUpOP .
|
||||
func (d *Dao) UpMcnUpOP(c context.Context, signUpID int64, state int8, rejectTime xtime.Time, rejectReason string) (rows int64, err error) {
|
||||
var res sql.Result
|
||||
if res, err = d.db.Exec(c, _upMcnUpOPSQL, state, rejectTime, rejectReason, time.Now(), signUpID); err != nil {
|
||||
return rows, err
|
||||
}
|
||||
return res.RowsAffected()
|
||||
}
|
||||
|
||||
// TxMcnUpPermitOP .
|
||||
func (d *Dao) TxMcnUpPermitOP(tx *xsql.Tx, signID, mcnMid, upMid int64, permission uint32, upAuthLink string) (rows int64, err error) {
|
||||
var res sql.Result
|
||||
if res, err = tx.Exec(_mcnUpPermitOPSQL, permission, upAuthLink, signID, mcnMid, upMid); err != nil {
|
||||
return rows, err
|
||||
}
|
||||
return res.RowsAffected()
|
||||
}
|
||||
|
||||
// TxUpPermitApplyOP .
|
||||
func (d *Dao) TxUpPermitApplyOP(tx *xsql.Tx, arg *model.McnUpPermissionApply) (rows int64, err error) {
|
||||
var res sql.Result
|
||||
if res, err = tx.Exec(_upPermitApplyOPSQL, arg.State, arg.RejectReason, arg.RejectTime, arg.AdminID, arg.AdminName, arg.ID); err != nil {
|
||||
return rows, err
|
||||
}
|
||||
return res.RowsAffected()
|
||||
}
|
||||
|
||||
// McnSigns .
|
||||
func (d *Dao) McnSigns(c context.Context, arg *model.MCNSignStateReq) (ms []*model.MCNSignInfoReply, err error) {
|
||||
var rows *xsql.Rows
|
||||
limit, offset := arg.PageArg.CheckPageValidation()
|
||||
if rows, err = d.db.Query(c, _selMcnSignsSQL, arg.State, offset, limit); err != nil {
|
||||
return
|
||||
}
|
||||
defer rows.Close()
|
||||
for rows.Next() {
|
||||
m := new(model.MCNSignInfoReply)
|
||||
if err = rows.Scan(&m.SignID, &m.McnMid, &m.CompanyName, &m.CompanyLicenseID, &m.CompanyLicenseLink, &m.ContractLink, &m.ContactName,
|
||||
&m.ContactTitle, &m.ContactIdcard, &m.ContactPhone, &m.BeginDate, &m.EndDate, &m.RejectReason, &m.RejectTime, &m.State, &m.Ctime, &m.Mtime, &m.Permission); err != nil {
|
||||
return
|
||||
}
|
||||
ms = append(ms, m)
|
||||
}
|
||||
err = rows.Err()
|
||||
return
|
||||
}
|
||||
|
||||
// McnSign .
|
||||
func (d *Dao) McnSign(c context.Context, signID int64) (m *model.MCNSignInfoReply, err error) {
|
||||
row := d.db.QueryRow(c, _selMcnSignSQL, signID)
|
||||
m = new(model.MCNSignInfoReply)
|
||||
if err = row.Scan(&m.SignID, &m.McnMid, &m.CompanyName, &m.CompanyLicenseID, &m.CompanyLicenseLink, &m.ContractLink, &m.ContactName,
|
||||
&m.ContactTitle, &m.ContactIdcard, &m.ContactPhone, &m.BeginDate, &m.EndDate, &m.RejectReason, &m.RejectTime, &m.State, &m.Ctime, &m.Mtime, &m.Permission); err != nil {
|
||||
if err == xsql.ErrNoRows {
|
||||
err = nil
|
||||
m = nil
|
||||
return
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// McnSignPayMap .
|
||||
func (d *Dao) McnSignPayMap(c context.Context, signIDs []int64) (sm map[int64][]*model.SignPayInfoReply, err error) {
|
||||
var rows *xsql.Rows
|
||||
if rows, err = d.db.Query(c, fmt.Sprintf(_selMcnSignPayMapSQL, xstr.JoinInts(signIDs))); err != nil {
|
||||
return
|
||||
}
|
||||
defer rows.Close()
|
||||
sm = make(map[int64][]*model.SignPayInfoReply)
|
||||
for rows.Next() {
|
||||
s := new(model.SignPayInfoReply)
|
||||
if err = rows.Scan(&s.SignPayID, &s.SignID, &s.DueDate, &s.PayValue, &s.State); err != nil {
|
||||
return
|
||||
}
|
||||
sm[s.SignID] = append(sm[s.SignID], s)
|
||||
}
|
||||
err = rows.Err()
|
||||
return
|
||||
}
|
||||
|
||||
// McnUps .
|
||||
func (d *Dao) McnUps(c context.Context, arg *model.MCNUPStateReq) (ups []*model.MCNUPInfoReply, err error) {
|
||||
var rows *xsql.Rows
|
||||
limit, offset := arg.PageArg.CheckPageValidation()
|
||||
if rows, err = d.db.Query(c, _selMcnUpsSQL, arg.State, offset, limit); err != nil {
|
||||
return
|
||||
}
|
||||
defer rows.Close()
|
||||
for rows.Next() {
|
||||
up := new(model.MCNUPInfoReply)
|
||||
if err = rows.Scan(&up.SignUpID, &up.SignID, &up.McnMid, &up.UpMid, &up.BeginDate, &up.EndDate, &up.ContractLink,
|
||||
&up.UpAuthLink, &up.RejectReason, &up.RejectTime, &up.State, &up.Ctime, &up.Mtime, &up.UPType, &up.SiteLink,
|
||||
&up.ConfirmTime, &up.PubPrice, &up.Permission); err != nil {
|
||||
return
|
||||
}
|
||||
ups = append(ups, up)
|
||||
}
|
||||
err = rows.Err()
|
||||
return
|
||||
}
|
||||
|
||||
// McnUp .
|
||||
func (d *Dao) McnUp(c context.Context, signUpID int64) (up *model.MCNUPInfoReply, err error) {
|
||||
row := d.db.QueryRow(c, _selMcnUpSQL, signUpID)
|
||||
up = new(model.MCNUPInfoReply)
|
||||
if err = row.Scan(&up.SignUpID, &up.SignID, &up.McnMid, &up.UpMid, &up.BeginDate, &up.EndDate, &up.ContractLink,
|
||||
&up.UpAuthLink, &up.RejectReason, &up.RejectTime, &up.State, &up.Ctime, &up.Mtime, &up.UPType, &up.SiteLink,
|
||||
&up.ConfirmTime, &up.PubPrice, &up.Permission); err != nil {
|
||||
if err == xsql.ErrNoRows {
|
||||
err = nil
|
||||
up = nil
|
||||
return
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// McnSignCountUQTime .
|
||||
func (d *Dao) McnSignCountUQTime(c context.Context, mcnMid int64, stime, etime xtime.Time) (count int64, err error) {
|
||||
row := d.db.QueryRow(c, _selMcnSignCountUQTimeSQL, mcnMid, stime, etime, etime)
|
||||
if err = row.Scan(&count); err != nil {
|
||||
if err == xsql.ErrNoRows {
|
||||
err = nil
|
||||
return
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// McnSignTotal .
|
||||
func (d *Dao) McnSignTotal(c context.Context, arg *model.MCNSignStateReq) (count int64, err error) {
|
||||
row := d.db.QueryRow(c, _mcnSignTotalSQL, arg.State)
|
||||
if err = row.Scan(&count); err != nil {
|
||||
if err == xsql.ErrNoRows {
|
||||
err = nil
|
||||
return
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// McnUpTotal .
|
||||
func (d *Dao) McnUpTotal(c context.Context, arg *model.MCNUPStateReq) (count int64, err error) {
|
||||
row := d.db.QueryRow(c, _mcnUpTotalSQL, arg.State)
|
||||
if err = row.Scan(&count); err != nil {
|
||||
if err == xsql.ErrNoRows {
|
||||
err = nil
|
||||
return
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// McnSignNoOKState .
|
||||
func (d *Dao) McnSignNoOKState(c context.Context, mcnMid int64) (count int64, err error) {
|
||||
row := d.db.QueryRow(c, _mcnSignNoStateCountSQL, mcnMid)
|
||||
if err = row.Scan(&count); err != nil {
|
||||
if err == xsql.ErrNoRows {
|
||||
err = nil
|
||||
return
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// McnUpPermits .
|
||||
func (d *Dao) McnUpPermits(c context.Context, arg *model.MCNUPPermitStateReq) (ms []*model.McnUpPermissionApply, err error) {
|
||||
var rows *xsql.Rows
|
||||
limit, offset := arg.PageArg.CheckPageValidation()
|
||||
if rows, err = d.db.Query(c, _mcnUpPermitReviewsSQL, arg.State, offset, limit); err != nil {
|
||||
return
|
||||
}
|
||||
defer rows.Close()
|
||||
for rows.Next() {
|
||||
m := new(model.McnUpPermissionApply)
|
||||
if err = rows.Scan(&m.ID, &m.McnMid, &m.UpMid, &m.SignID, &m.NewPermission, &m.OldPermission, &m.RejectReason,
|
||||
&m.RejectTime, &m.State, &m.Ctime, &m.Mtime, &m.AdminID, &m.AdminName, &m.UpAuthLink); err != nil {
|
||||
return
|
||||
}
|
||||
ms = append(ms, m)
|
||||
}
|
||||
err = rows.Err()
|
||||
return
|
||||
}
|
||||
|
||||
// McnUpPermit .
|
||||
func (d *Dao) McnUpPermit(c context.Context, id int64) (m *model.McnUpPermissionApply, err error) {
|
||||
row := d.db.QueryRow(c, _mcnUpPermitReviewSQL, id)
|
||||
m = new(model.McnUpPermissionApply)
|
||||
if err = row.Scan(&m.ID, &m.McnMid, &m.UpMid, &m.SignID, &m.NewPermission, &m.OldPermission, &m.RejectReason,
|
||||
&m.RejectTime, &m.State, &m.Ctime, &m.Mtime, &m.AdminID, &m.AdminName, &m.UpAuthLink); err != nil {
|
||||
if err == xsql.ErrNoRows {
|
||||
err = nil
|
||||
return
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// McnUpPermitTotal .
|
||||
func (d *Dao) McnUpPermitTotal(c context.Context, arg *model.MCNUPPermitStateReq) (count int64, err error) {
|
||||
row := d.db.QueryRow(c, _mcnUpPermitTotalSQL, arg.State)
|
||||
if err = row.Scan(&count); err != nil {
|
||||
if err == xsql.ErrNoRows {
|
||||
err = nil
|
||||
return
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
225
app/admin/main/mcn/dao/up/mcn_account_test.go
Normal file
225
app/admin/main/mcn/dao/up/mcn_account_test.go
Normal file
@ -0,0 +1,225 @@
|
||||
package up
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
"go-common/app/admin/main/mcn/model"
|
||||
xtime "go-common/library/time"
|
||||
|
||||
"github.com/smartystreets/goconvey/convey"
|
||||
)
|
||||
|
||||
func TestUpTxAddMcnSignEntry(t *testing.T) {
|
||||
convey.Convey("TxAddMcnSignEntry", t, func(ctx convey.C) {
|
||||
var (
|
||||
tx, _ = d.BeginTran(context.Background())
|
||||
mcnMid = int64(0)
|
||||
beginDate = ""
|
||||
endDate = ""
|
||||
permission = uint32(0)
|
||||
)
|
||||
ctx.Convey("When everything goes positive", func(ctx convey.C) {
|
||||
lastID, err := d.TxAddMcnSignEntry(tx, mcnMid, beginDate, endDate, permission)
|
||||
t.Logf("last id=%d", lastID)
|
||||
defer tx.Rollback()
|
||||
ctx.Convey("Then err should be nil.lastID should not be nil.", func(ctx convey.C) {
|
||||
ctx.So(err, convey.ShouldBeNil)
|
||||
ctx.So(lastID, convey.ShouldNotBeNil)
|
||||
})
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
func TestUpTxAddMcnSignPay(t *testing.T) {
|
||||
convey.Convey("TxAddMcnSignPay", t, func(ctx convey.C) {
|
||||
var (
|
||||
tx, _ = d.BeginTran(context.Background())
|
||||
mcnMid = int64(0)
|
||||
signID = int64(0)
|
||||
payValue = int64(0)
|
||||
dueDate = ""
|
||||
note = ""
|
||||
)
|
||||
ctx.Convey("When everything goes positive", func(ctx convey.C) {
|
||||
rows, err := d.TxAddMcnSignPay(tx, mcnMid, signID, payValue, dueDate, note)
|
||||
defer tx.Rollback()
|
||||
ctx.Convey("Then err should be nil.rows should not be nil.", func(ctx convey.C) {
|
||||
ctx.So(err, convey.ShouldBeNil)
|
||||
ctx.So(rows, convey.ShouldNotBeNil)
|
||||
})
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
func TestUpUpMcnSignOP(t *testing.T) {
|
||||
convey.Convey("UpMcnSignOP", t, func(ctx convey.C) {
|
||||
var (
|
||||
c = context.Background()
|
||||
signID = int64(0)
|
||||
state = int8(0)
|
||||
rejectTime xtime.Time
|
||||
rejectReason = ""
|
||||
)
|
||||
ctx.Convey("When everything goes positive", func(ctx convey.C) {
|
||||
rows, err := d.UpMcnSignOP(c, signID, state, rejectTime, rejectReason)
|
||||
ctx.Convey("Then err should be nil.rows should not be nil.", func(ctx convey.C) {
|
||||
ctx.So(err, convey.ShouldBeNil)
|
||||
ctx.So(rows, convey.ShouldNotBeNil)
|
||||
})
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
func TestUpUpMcnUpOP(t *testing.T) {
|
||||
convey.Convey("UpMcnUpOP", t, func(ctx convey.C) {
|
||||
var (
|
||||
c = context.Background()
|
||||
signUpID = int64(0)
|
||||
state = int8(0)
|
||||
rejectTime xtime.Time
|
||||
rejectReason = ""
|
||||
)
|
||||
ctx.Convey("When everything goes positive", func(ctx convey.C) {
|
||||
rows, err := d.UpMcnUpOP(c, signUpID, state, rejectTime, rejectReason)
|
||||
ctx.Convey("Then err should be nil.rows should not be nil.", func(ctx convey.C) {
|
||||
ctx.So(err, convey.ShouldBeNil)
|
||||
ctx.So(rows, convey.ShouldNotBeNil)
|
||||
})
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
func TestUpTxMcnUpPermitOP(t *testing.T) {
|
||||
convey.Convey("TxMcnUpPermitOP", t, func(ctx convey.C) {
|
||||
var (
|
||||
tx, _ = d.BeginTran(context.Background())
|
||||
signID = int64(0)
|
||||
mcnMid = int64(0)
|
||||
upMid = int64(0)
|
||||
permission = uint32(0)
|
||||
upAuthLink = ""
|
||||
)
|
||||
ctx.Convey("When everything gose positive", func(ctx convey.C) {
|
||||
rows, err := d.TxMcnUpPermitOP(tx, signID, mcnMid, upMid, permission, upAuthLink)
|
||||
defer tx.Rollback()
|
||||
ctx.Convey("Then err should be nil.rows should not be nil.", func(ctx convey.C) {
|
||||
ctx.So(err, convey.ShouldBeNil)
|
||||
ctx.So(rows, convey.ShouldNotBeNil)
|
||||
})
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
func TestUpTxUpPermitApplyOP(t *testing.T) {
|
||||
convey.Convey("TxUpPermitApplyOP", t, func(ctx convey.C) {
|
||||
var (
|
||||
tx, _ = d.BeginTran(context.Background())
|
||||
arg = &model.McnUpPermissionApply{}
|
||||
)
|
||||
ctx.Convey("When everything gose positive", func(ctx convey.C) {
|
||||
rows, err := d.TxUpPermitApplyOP(tx, arg)
|
||||
defer tx.Rollback()
|
||||
ctx.Convey("Then err should be nil.rows should not be nil.", func(ctx convey.C) {
|
||||
ctx.So(err, convey.ShouldBeNil)
|
||||
ctx.So(rows, convey.ShouldNotBeNil)
|
||||
})
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
func TestUpMcnSigns(t *testing.T) {
|
||||
convey.Convey("McnSigns", t, func(ctx convey.C) {
|
||||
var (
|
||||
c = context.Background()
|
||||
arg = &model.MCNSignStateReq{}
|
||||
)
|
||||
ctx.Convey("When everything goes positive", func(ctx convey.C) {
|
||||
ms, err := d.McnSigns(c, arg)
|
||||
ctx.Convey("Then err should be nil.ms should not be nil.", func(ctx convey.C) {
|
||||
ctx.So(err, convey.ShouldBeNil)
|
||||
ctx.So(ms, convey.ShouldNotBeNil)
|
||||
})
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
func TestUpMcnSignTotal(t *testing.T) {
|
||||
convey.Convey("McnSignTotal", t, func(ctx convey.C) {
|
||||
var (
|
||||
c = context.Background()
|
||||
arg = &model.MCNSignStateReq{}
|
||||
)
|
||||
ctx.Convey("When everything goes positive", func(ctx convey.C) {
|
||||
count, err := d.McnSignTotal(c, arg)
|
||||
ctx.Convey("Then err should be nil.count should not be nil.", func(ctx convey.C) {
|
||||
ctx.So(err, convey.ShouldBeNil)
|
||||
ctx.So(count, convey.ShouldNotBeNil)
|
||||
})
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
func TestUpMcnUpTotal(t *testing.T) {
|
||||
convey.Convey("McnUpTotal", t, func(ctx convey.C) {
|
||||
var (
|
||||
c = context.Background()
|
||||
arg = &model.MCNUPStateReq{}
|
||||
)
|
||||
ctx.Convey("When everything goes positive", func(ctx convey.C) {
|
||||
count, err := d.McnUpTotal(c, arg)
|
||||
ctx.Convey("Then err should be nil.count should not be nil.", func(ctx convey.C) {
|
||||
ctx.So(err, convey.ShouldBeNil)
|
||||
ctx.So(count, convey.ShouldNotBeNil)
|
||||
})
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
func TestUpMcnUpPermits(t *testing.T) {
|
||||
convey.Convey("McnUpPermits", t, func(ctx convey.C) {
|
||||
var (
|
||||
c = context.Background()
|
||||
arg = &model.MCNUPPermitStateReq{}
|
||||
)
|
||||
ctx.Convey("When everything gose positive", func(ctx convey.C) {
|
||||
ms, err := d.McnUpPermits(c, arg)
|
||||
ctx.Convey("Then err should be nil.ms should not be nil.", func(ctx convey.C) {
|
||||
ctx.So(err, convey.ShouldBeNil)
|
||||
ctx.So(ms, convey.ShouldNotBeNil)
|
||||
})
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
func TestUpMcnUpPermit(t *testing.T) {
|
||||
convey.Convey("McnUpPermit", t, func(ctx convey.C) {
|
||||
var (
|
||||
c = context.Background()
|
||||
id = int64(0)
|
||||
)
|
||||
ctx.Convey("When everything gose positive", func(ctx convey.C) {
|
||||
m, err := d.McnUpPermit(c, id)
|
||||
ctx.Convey("Then err should be nil.m should not be nil.", func(ctx convey.C) {
|
||||
ctx.So(err, convey.ShouldBeNil)
|
||||
ctx.So(m, convey.ShouldNotBeNil)
|
||||
})
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
func TestUpMcnUpPermitTotal(t *testing.T) {
|
||||
convey.Convey("McnUpPermitTotal", t, func(ctx convey.C) {
|
||||
var (
|
||||
c = context.Background()
|
||||
arg = &model.MCNUPPermitStateReq{}
|
||||
)
|
||||
ctx.Convey("When everything gose positive", func(ctx convey.C) {
|
||||
count, err := d.McnUpPermitTotal(c, arg)
|
||||
ctx.Convey("Then err should be nil.count should not be nil.", func(ctx convey.C) {
|
||||
ctx.So(err, convey.ShouldBeNil)
|
||||
ctx.So(count, convey.ShouldNotBeNil)
|
||||
})
|
||||
})
|
||||
})
|
||||
}
|
689
app/admin/main/mcn/dao/up/mcn_manage.go
Normal file
689
app/admin/main/mcn/dao/up/mcn_manage.go
Normal file
@ -0,0 +1,689 @@
|
||||
package up
|
||||
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"fmt"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
|
||||
"go-common/app/admin/main/mcn/model"
|
||||
xsql "go-common/library/database/sql"
|
||||
"go-common/library/xstr"
|
||||
)
|
||||
|
||||
const (
|
||||
_inMCNRenewalSQL = `INSERT INTO mcn_sign(mcn_mid,company_name,company_license_id,company_license_link,
|
||||
contract_link,contact_name,contact_title,contact_idcard,contact_phone,begin_date,end_date,state,permission) VALUES (?,?,?,?,?,?,?,?,?,?,?,15,?)`
|
||||
_inMCNPaySQL = "INSERT INTO mcn_sign_pay(mcn_mid,sign_id,due_date,pay_value) VALUES %s"
|
||||
_inMCNUPsSQL = "INSERT INTO mcn_up(sign_id,mcn_mid,up_mid,begin_date,end_date,contract_link,up_auth_link,state,state_change_time,up_type,site_link,confirm_time,permission,publication_price) VALUES %s"
|
||||
|
||||
_upMCNStateSQL = "UPDATE mcn_sign SET state=? WHERE id=? AND mcn_mid=?"
|
||||
_upMCNPaySQL = "UPDATE mcn_sign_pay SET due_date=?,pay_value=? WHERE id=? AND mcn_mid=? AND sign_id=?"
|
||||
_upMCNPayStateSQL = "UPDATE mcn_sign_pay SET state=? WHERE id=? AND mcn_mid=? AND sign_id=?"
|
||||
// _upMCNSignRenewaIDSQL = "UPDATE mcn_sign SET renewal_id=? WHERE id=?"
|
||||
_upMCNUPStateSQL = "UPDATE mcn_up SET state=?,state_change_time=? WHERE id =? AND sign_id=? AND mcn_mid=? AND up_mid=?"
|
||||
_upMCNImportUPSQL = "UPDATE mcn_data_import_up SET is_reward=1 WHERE sign_id=? AND up_mid=?"
|
||||
_upMCNPermissionSQL = "UPDATE mcn_sign SET permission = ? WHERE id=?"
|
||||
_selMCNListSQL = `SELECT s.id, s.mcn_mid,s.state,s.begin_date,s.end_date,s.permission,ifnull(ds.up_count,0),ifnull(ds.fans_count_accumulate,0),
|
||||
ifnull(ds.fans_count_online_accumulate,0),ifnull(ds.fans_count_real_accumulate,0),ifnull(ds.fans_count_cheat_accumulate,0),ifnull(ds.generate_date,0)
|
||||
FROM (SELECT * FROM mcn_data_summary WHERE generate_date=(SELECT MAX(generate_date) FROM mcn_data_summary a WHERE a.sign_id=mcn_data_summary.sign_id) AND active_tid=? AND data_type=1) AS ds
|
||||
RIGHT JOIN mcn_sign s ON s.id=ds.sign_id WHERE `
|
||||
_countMCNListSQL = `SELECT COUNT(*) FROM (SELECT * FROM mcn_data_summary WHERE generate_date=(SELECT MAX(generate_date) FROM mcn_data_summary a
|
||||
WHERE a.sign_id=mcn_data_summary.sign_id) AND active_tid=? AND data_type=1) AS ds RIGHT JOIN mcn_sign s ON s.id=ds.sign_id WHERE %s`
|
||||
_selMCNPayInfosByID = "SELECT id,mcn_mid,sign_id,due_date,pay_value,state FROM mcn_sign_pay WHERE id=?"
|
||||
_selMCNPayInfosBySignIDsSQL = "SELECT id,mcn_mid,sign_id,due_date,pay_value,state FROM mcn_sign_pay WHERE sign_id in(%s) ORDER BY due_date ASC"
|
||||
_selMCNRenewalUPsSQL = "SELECT sign_id,mcn_mid,up_mid,begin_date,end_date,contract_link,up_auth_link,reject_reason,reject_time,state,state_change_time,up_type,site_link,confirm_time,permission,publication_price FROM mcn_up WHERE sign_id=? AND mcn_mid=? AND state IN(10,11,15)"
|
||||
_selMCNInfoSQL = `SELECT s.id,s.mcn_mid,s.company_name,s.company_license_id,s.company_license_link,s.contract_link,s.contact_name,s.contact_title,s.contact_idcard,s.contact_phone,
|
||||
s.begin_date,s.end_date,ifnull(s.state,0),ifnull(ds.up_count,0),ifnull(ds.fans_count_accumulate,0),ifnull(ds.archive_count_accumulate,0),ifnull(ds.play_count_accumulate,0),
|
||||
ifnull(ds.fans_count_cheat_accumulate,0),ifnull(ds.fans_count_real_accumulate,0),ifnull(ds.fans_count_online_accumulate,0)
|
||||
FROM mcn_sign s LEFT JOIN mcn_data_summary ds ON s.id=ds.sign_id AND ds.active_tid=? AND ds.data_type=1 WHERE s.id = ? ORDER BY ds.generate_date DESC LIMIT 1`
|
||||
_selMCNUPListSQL = `SELECT u.id,u.sign_id,u.mcn_mid,u.up_mid,u.publication_price,u.permission,ifnull(du.active_tid,0),ifnull(du.fans_count,0),ifnull(du.fans_count_active,0),u.begin_date,u.end_date,u.state,
|
||||
ifnull(du.fans_increase_accumulate,0),ifnull(du.archive_count,0),ifnull(du.play_count,0),u.contract_link,u.up_auth_link,u.up_type, ifnull(u.site_link, "")
|
||||
FROM (SELECT * FROM mcn_data_up WHERE generate_date=(SELECT MAX(generate_date) FROM mcn_data_up a WHERE a.up_mid=mcn_data_up.up_mid)) du
|
||||
RIGHT JOIN mcn_up u ON u.sign_id=du.sign_id AND u.up_mid=du.up_mid AND du.data_type=? WHERE u.state IN(10,11,12,14,15) AND `
|
||||
_countMCNUPListSQL = `SELECT COUNT(*) FROM (SELECT * FROM mcn_data_up WHERE generate_date=(SELECT MAX(generate_date) FROM mcn_data_up a WHERE a.up_mid=mcn_data_up.up_mid)) du
|
||||
RIGHT JOIN mcn_up u ON u.sign_id=du.sign_id AND u.up_mid=du.up_mid AND du.data_type=? WHERE u.state IN(10,11,12,14,15) AND %s`
|
||||
_selMCNByMCNMIDSQL = `SELECT id,mcn_mid,company_name,company_license_id,company_license_link,contract_link,contact_name,
|
||||
contact_title,contact_idcard,contact_phone,begin_date,end_date,reject_reason,reject_time,state,ctime,mtime FROM mcn_sign WHERE state IN(10,11,15) AND mcn_mid = ? ORDER BY begin_date DESC LIMIT 1`
|
||||
_selMCNCheatListSQL = `SELECT fans_count_accumulate,fans_count_cheat_accumulate,mcn_mid,sign_id,up_mid,fans_count_cheat_increase_day,fans_count_cheat_cleaned_accumulate FROM mcn_data_up_cheat WHERE `
|
||||
_countMCNCheatListSQL = "SELECT COUNT(*) FROM mcn_data_up_cheat WHERE %s"
|
||||
_selMCNCheatUPListSQL = `SELECT sign_id,generate_date,fans_count_accumulate,fans_count_cheat_accumulate,mcn_mid,fans_count_cheat_increase_day,fans_count_cheat_cleaned_accumulate FROM mcn_data_up_cheat WHERE up_mid=? ORDER BY generate_date DESC LIMIT ?,?`
|
||||
_countMCNCheatUPListSQL = "SELECT COUNT(*) FROM mcn_data_up_cheat WHERE up_mid=?"
|
||||
_selMCNImportUPInfoSQL = "SELECT id,mcn_mid,sign_id,up_mid,standard_fans_date,standard_archive_count,standard_fans_count,is_reward FROM mcn_data_import_up WHERE sign_id=? AND up_mid=? AND standard_fans_type=1"
|
||||
_selMCNDataSummaryListSQL = `SELECT id,sign_id,data_type,active_tid,generate_date,up_count,fans_count_online_accumulate,fans_count_real_accumulate,fans_count_cheat_accumulate,fans_count_increase_day,archive_count_accumulate,archive_count_day,
|
||||
play_count_accumulate,play_count_increase_day,fans_count_accumulate FROM mcn_data_summary WHERE `
|
||||
_countMCNDataSummaryListSQL = "SELECT COUNT(*) FROM mcn_data_summary WHERE %s"
|
||||
)
|
||||
|
||||
// TxAddMCNRenewal .
|
||||
func (d *Dao) TxAddMCNRenewal(tx *xsql.Tx, arg *model.MCNSign) (lastID int64, err error) {
|
||||
var res sql.Result
|
||||
if res, err = tx.Exec(_inMCNRenewalSQL, arg.MCNMID, arg.CompanyName, arg.CompanyLicenseID, arg.CompanyLicenseLink, arg.ContractLink, arg.ContactName, arg.ContactTitle, arg.ContactIdcard, arg.ContactPhone, arg.BeginDate, arg.EndDate, arg.Permission); err != nil {
|
||||
return lastID, err
|
||||
}
|
||||
if lastID, err = res.LastInsertId(); err != nil {
|
||||
return lastID, errors.Errorf("TxAddMCNRenewal res.LastInsertId(%+v) error(%+v)", arg, err)
|
||||
}
|
||||
return lastID, nil
|
||||
}
|
||||
|
||||
// TxAddMCNPays .
|
||||
func (d *Dao) TxAddMCNPays(tx *xsql.Tx, lastID, mcnMID int64, arg []*model.SignPayReq) (err error) {
|
||||
l := len(arg)
|
||||
valueStrings := make([]string, 0, l)
|
||||
valueArgs := make([]interface{}, 0, l*5)
|
||||
for _, v := range arg {
|
||||
valueStrings = append(valueStrings, "(?,?,?,?)")
|
||||
valueArgs = append(valueArgs, strconv.FormatInt(mcnMID, 10))
|
||||
valueArgs = append(valueArgs, strconv.FormatInt(lastID, 10))
|
||||
valueArgs = append(valueArgs, v.DueDate)
|
||||
valueArgs = append(valueArgs, strconv.FormatInt(v.PayValue, 10))
|
||||
}
|
||||
stmt := fmt.Sprintf(_inMCNPaySQL, strings.Join(valueStrings, ","))
|
||||
_, err = tx.Exec(stmt, valueArgs...)
|
||||
return
|
||||
}
|
||||
|
||||
// TxAddMCNUPs .
|
||||
func (d *Dao) TxAddMCNUPs(tx *xsql.Tx, signID, mcnMID int64, arg []*model.MCNUP) (err error) {
|
||||
l := len(arg)
|
||||
valueStrings := make([]string, 0, l)
|
||||
valueArgs := make([]interface{}, 0, l*15)
|
||||
for _, v := range arg {
|
||||
valueStrings = append(valueStrings, "(?,?,?,?,?,?,?,?,?,?,?,?,?,?)")
|
||||
valueArgs = append(valueArgs, strconv.FormatInt(signID, 10))
|
||||
valueArgs = append(valueArgs, strconv.FormatInt(mcnMID, 10))
|
||||
valueArgs = append(valueArgs, strconv.FormatInt(v.UPMID, 10))
|
||||
valueArgs = append(valueArgs, v.BeginDate.Time().Format(model.TimeFormatDay))
|
||||
valueArgs = append(valueArgs, v.EndDate.Time().Format(model.TimeFormatDay))
|
||||
valueArgs = append(valueArgs, v.ContractLink)
|
||||
valueArgs = append(valueArgs, v.UPAuthLink)
|
||||
valueArgs = append(valueArgs, strconv.FormatInt(int64(v.State), 10))
|
||||
valueArgs = append(valueArgs, v.StateChangeTime.Time().Format(model.TimeFormatSec))
|
||||
valueArgs = append(valueArgs, strconv.FormatInt(int64(v.UpType), 10))
|
||||
valueArgs = append(valueArgs, v.SiteLink)
|
||||
valueArgs = append(valueArgs, v.ConfirmTime.Time().Format(model.TimeFormatSec))
|
||||
valueArgs = append(valueArgs, strconv.FormatInt(int64(v.Permission), 10))
|
||||
valueArgs = append(valueArgs, strconv.FormatInt(int64(v.PublicationPrice), 10))
|
||||
}
|
||||
stmt := fmt.Sprintf(_inMCNUPsSQL, strings.Join(valueStrings, ","))
|
||||
_, err = tx.Exec(stmt, valueArgs...)
|
||||
return
|
||||
}
|
||||
|
||||
// // TxUpMCNSignRenewaID .
|
||||
// func (d *Dao) TxUpMCNSignRenewaID(tx *xsql.Tx, signID, renewalID int64) (rows int64, err error) {
|
||||
// var res sql.Result
|
||||
// if res, err = tx.Exec(_upMCNSignRenewaIDSQL, renewalID, signID); err != nil {
|
||||
// return rows, err
|
||||
// }
|
||||
// return res.RowsAffected()
|
||||
// }
|
||||
|
||||
// UpMCNState .
|
||||
func (d *Dao) UpMCNState(c context.Context, arg *model.MCNStateEditReq) (rows int64, err error) {
|
||||
var res sql.Result
|
||||
if res, err = d.db.Exec(c, _upMCNStateSQL, arg.State, arg.ID, arg.MCNMID); err != nil {
|
||||
return rows, err
|
||||
}
|
||||
return res.RowsAffected()
|
||||
}
|
||||
|
||||
// UpMCNPay update mcn_sign_pay.
|
||||
func (d *Dao) UpMCNPay(c context.Context, arg *model.MCNPayEditReq) (rows int64, err error) {
|
||||
var res sql.Result
|
||||
if res, err = d.db.Exec(c, _upMCNPaySQL, arg.DueDate, arg.PayValue, arg.ID, arg.MCNMID, arg.SignID); err != nil {
|
||||
return rows, err
|
||||
}
|
||||
return res.RowsAffected()
|
||||
}
|
||||
|
||||
// UpMCNPayState update mcn_sign_pay state.
|
||||
func (d *Dao) UpMCNPayState(c context.Context, arg *model.MCNPayStateEditReq) (rows int64, err error) {
|
||||
var res sql.Result
|
||||
if res, err = d.db.Exec(c, _upMCNPayStateSQL, arg.State, arg.ID, arg.MCNMID, arg.SignID); err != nil {
|
||||
return rows, err
|
||||
}
|
||||
return res.RowsAffected()
|
||||
}
|
||||
|
||||
// UpMCNImportUPRewardSign .
|
||||
func (d *Dao) UpMCNImportUPRewardSign(c context.Context, arg *model.MCNImportUPRewardSignReq) (rows int64, err error) {
|
||||
var res sql.Result
|
||||
if res, err = d.db.Exec(c, _upMCNImportUPSQL, arg.SignID, arg.UPMID); err != nil {
|
||||
return rows, err
|
||||
}
|
||||
return res.RowsAffected()
|
||||
}
|
||||
|
||||
// UpMCNPermission .
|
||||
func (d *Dao) UpMCNPermission(c context.Context, signID int64, permission uint32) (rows int64, err error) {
|
||||
var res sql.Result
|
||||
if res, err = d.db.Exec(c, _upMCNPermissionSQL, permission, signID); err != nil {
|
||||
return rows, err
|
||||
}
|
||||
return res.RowsAffected()
|
||||
}
|
||||
|
||||
// MCNList .
|
||||
func (d *Dao) MCNList(c context.Context, arg *model.MCNListReq) (res []*model.MCNListOne, ids, mids []int64, err error) {
|
||||
sql, values := d.buildMCNListSQL("list", arg)
|
||||
rows, err := d.db.Query(c, sql, values...)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
defer rows.Close()
|
||||
for rows.Next() {
|
||||
m := &model.MCNListOne{}
|
||||
err = rows.Scan(&m.ID, &m.MCNMID, &m.State, &m.BeginDate, &m.EndDate, &m.Permission, &m.UPCount, &m.FansCountAccumulate, &m.FansCountOnlineAccumulate, &m.FansCountRealAccumulate, &m.FansCountCheatAccumulate, &m.GenerateDate)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
res = append(res, m)
|
||||
ids = append(ids, m.ID)
|
||||
mids = append(mids, m.MCNMID)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// buildMCNListSQL build a MCNList sql string.
|
||||
func (d *Dao) buildMCNListSQL(SQLType string, arg *model.MCNListReq) (sql string, values []interface{}) {
|
||||
values = make([]interface{}, 0, 11)
|
||||
var (
|
||||
cond []string
|
||||
condStr string
|
||||
curTime = time.Now()
|
||||
date = time.Date(curTime.Year(), curTime.Month(), curTime.Day(), 0, 0, 0, 0, time.Local)
|
||||
orderSign = false
|
||||
)
|
||||
// defualt where
|
||||
cond = append(cond, "s.state IN(10,11,12,13,14,15)")
|
||||
values = append(values, model.AllActiveTid)
|
||||
if arg.ExpirePay {
|
||||
cond = append(cond, "s.pay_expire_state = ?")
|
||||
values = append(values, model.MCNStatePayed)
|
||||
}
|
||||
if arg.ExpireSign {
|
||||
cond = append(cond, "s.end_date <= ? AND s.state = 10")
|
||||
values = append(values, date.AddDate(0, 0, 30))
|
||||
}
|
||||
if arg.FansNumMin != 0 {
|
||||
cond = append(cond, "ds.fans_count_accumulate >= ?")
|
||||
values = append(values, arg.FansNumMin)
|
||||
}
|
||||
if arg.FansNumMax != 0 && arg.FansNumMax >= arg.FansNumMin {
|
||||
cond = append(cond, "ds.fans_count_accumulate <= ?")
|
||||
values = append(values, arg.FansNumMax)
|
||||
}
|
||||
if arg.MCNMID != 0 {
|
||||
cond = append(cond, "s.mcn_mid=?")
|
||||
values = append(values, arg.MCNMID)
|
||||
}
|
||||
if arg.State != -1 {
|
||||
cond = append(cond, "s.state=?")
|
||||
values = append(values, arg.State)
|
||||
}
|
||||
var permission = arg.GetAttrPermitVal()
|
||||
if permission != 0 {
|
||||
cond = append(cond, "((permission & ?) = ?)")
|
||||
values = append(values, permission, permission)
|
||||
}
|
||||
if checkSort(arg.SortUP, orderSign) {
|
||||
arg.Order = "ds.up_count"
|
||||
arg.Sort = arg.SortUP
|
||||
orderSign = true
|
||||
}
|
||||
if checkSort(arg.SortAllFans, orderSign) {
|
||||
arg.Order = "ds.fans_count_accumulate"
|
||||
arg.Sort = arg.SortAllFans
|
||||
orderSign = true
|
||||
}
|
||||
if checkSort(arg.SortRiseFans, orderSign) {
|
||||
arg.Order = "ds.fans_count_online_accumulate"
|
||||
arg.Sort = arg.SortRiseFans
|
||||
orderSign = true
|
||||
}
|
||||
if checkSort(arg.SortTrueRiseFans, orderSign) {
|
||||
arg.Order = "ds.fans_count_real_accumulate"
|
||||
arg.Sort = arg.SortTrueRiseFans
|
||||
orderSign = true
|
||||
}
|
||||
if checkSort(arg.SortCheatFans, orderSign) {
|
||||
arg.Order = "ds.fans_count_cheat_accumulate"
|
||||
arg.Sort = arg.SortCheatFans
|
||||
}
|
||||
condStr = d.joinStringSQL(cond)
|
||||
switch SQLType {
|
||||
case "list":
|
||||
if arg.Export == model.ResponeModelCSV {
|
||||
sql = fmt.Sprintf(_selMCNListSQL+_orderByConditionNotLimitSQL, condStr, arg.Order, arg.Sort)
|
||||
return
|
||||
}
|
||||
sql = fmt.Sprintf(_selMCNListSQL+_orderByConditionSQL, condStr, arg.Order, arg.Sort)
|
||||
limit, offset := arg.PageArg.CheckPageValidation()
|
||||
values = append(values, offset, limit)
|
||||
case "count":
|
||||
sql = fmt.Sprintf(_countMCNListSQL, condStr)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func checkSort(arg string, orderSign bool) bool {
|
||||
return arg != "" && (arg == "asc" || arg == "desc") && !orderSign
|
||||
}
|
||||
|
||||
// MCNListTotal .
|
||||
func (d *Dao) MCNListTotal(c context.Context, arg *model.MCNListReq) (count int64, err error) {
|
||||
sql, values := d.buildMCNListSQL("count", arg)
|
||||
row := d.db.QueryRow(c, sql, values...)
|
||||
if err = row.Scan(&count); err != nil {
|
||||
if err == xsql.ErrNoRows {
|
||||
err = nil
|
||||
return
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// MCNPayInfo .
|
||||
func (d *Dao) MCNPayInfo(c context.Context, arg *model.MCNPayStateEditReq) (m *model.SignPayInfoReply, err error) {
|
||||
row := d.db.QueryRow(c, _selMCNPayInfosByID, arg.ID)
|
||||
m = new(model.SignPayInfoReply)
|
||||
// id,mcn_mid,sign_id,due_date,pay_value,state
|
||||
if err = row.Scan(&m.SignPayID, &m.McnMid, &m.SignID, &m.DueDate, &m.PayValue, &m.State); err != nil {
|
||||
if err == xsql.ErrNoRows {
|
||||
err = nil
|
||||
m = nil
|
||||
return
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// MCNPayInfos .
|
||||
func (d *Dao) MCNPayInfos(c context.Context, ids []int64) (res map[int64][]*model.SignPayInfoReply, err error) {
|
||||
rows, err := d.db.Query(c, fmt.Sprintf(_selMCNPayInfosBySignIDsSQL, xstr.JoinInts(ids)))
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
defer rows.Close()
|
||||
res = make(map[int64][]*model.SignPayInfoReply, len(ids))
|
||||
for rows.Next() {
|
||||
m := &model.SignPayInfoReply{}
|
||||
err = rows.Scan(&m.SignPayID, &m.McnMid, &m.SignID, &m.DueDate, &m.PayValue, &m.State)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
res[m.SignID] = append(res[m.SignID], m)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// TxMCNRenewalUPs .
|
||||
func (d *Dao) TxMCNRenewalUPs(tx *xsql.Tx, signID, mcnID int64) (ups []*model.MCNUP, err error) {
|
||||
var rows *xsql.Rows
|
||||
if rows, err = tx.Query(_selMCNRenewalUPsSQL, signID, mcnID); err != nil {
|
||||
return
|
||||
}
|
||||
defer rows.Close()
|
||||
for rows.Next() {
|
||||
up := new(model.MCNUP)
|
||||
if err = rows.Scan(&up.SignID, &up.MCNMID, &up.UPMID, &up.BeginDate, &up.EndDate, &up.ContractLink,
|
||||
&up.UPAuthLink, &up.RejectReason, &up.RejectTime, &up.State, &up.StateChangeTime, &up.UpType,
|
||||
&up.SiteLink, &up.ConfirmTime, &up.Permission, &up.PublicationPrice); err != nil {
|
||||
return
|
||||
}
|
||||
ups = append(ups, up)
|
||||
}
|
||||
err = rows.Err()
|
||||
return
|
||||
}
|
||||
|
||||
// MCNInfo .
|
||||
func (d *Dao) MCNInfo(c context.Context, arg *model.MCNInfoReq) (m *model.MCNInfoReply, err error) {
|
||||
row := d.db.QueryRow(c, _selMCNInfoSQL, model.AllActiveTid, arg.ID)
|
||||
m = new(model.MCNInfoReply)
|
||||
if err = row.Scan(&m.ID, &m.MCNMID, &m.CompanyName, &m.CompanyLicenseID, &m.CompanyLicenseLink, &m.ContractLink, &m.ContactName,
|
||||
&m.ContactTitle, &m.ContactIdcard, &m.ContactPhone, &m.BeginDate, &m.EndDate, &m.State, &m.UPCount, &m.FansCountAccumulate,
|
||||
&m.ArchiveCountAccumulate, &m.PlayCountAccumulate, &m.FansCountOnline, &m.FansCountRealAccumulate, &m.FansCountOnlineAccumulate); err != nil {
|
||||
if err == xsql.ErrNoRows {
|
||||
err = nil
|
||||
m = nil
|
||||
return
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// MCNUPList .
|
||||
func (d *Dao) MCNUPList(c context.Context, arg *model.MCNUPListReq) (res []*model.MCNUPInfoReply, err error) {
|
||||
sql, values := d.buildMCNUPListSQL("list", arg)
|
||||
rows, err := d.db.Query(c, sql, values...)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
defer rows.Close()
|
||||
for rows.Next() {
|
||||
m := &model.MCNUPInfoReply{}
|
||||
err = rows.Scan(&m.SignUpID, &m.SignID, &m.McnMid, &m.UpMid, &m.PubPrice, &m.Permission, &m.ActiveTid, &m.FansCount, &m.FansCountActive,
|
||||
&m.BeginDate, &m.EndDate, &m.State, &m.FansIncreaseAccumulate, &m.ArchiveCount, &m.PlayCount, &m.ContractLink, &m.UpAuthLink, &m.UPType, &m.SiteLink)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
res = append(res, m)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// MCNUPListTotal .
|
||||
func (d *Dao) MCNUPListTotal(c context.Context, arg *model.MCNUPListReq) (count int64, err error) {
|
||||
sql, values := d.buildMCNUPListSQL("count", arg)
|
||||
row := d.db.QueryRow(c, sql, values...)
|
||||
if err = row.Scan(&count); err != nil {
|
||||
if err == xsql.ErrNoRows {
|
||||
err = nil
|
||||
return
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// buildMCNUPListSQL build a MCNUPList sql string.
|
||||
func (d *Dao) buildMCNUPListSQL(SQLType string, arg *model.MCNUPListReq) (sql string, values []interface{}) {
|
||||
values = make([]interface{}, 0, 8)
|
||||
var (
|
||||
cond []string
|
||||
condStr string
|
||||
orderSign = false
|
||||
)
|
||||
values = append(values, arg.DataType)
|
||||
cond = append(cond, "u.sign_id=?")
|
||||
values = append(values, arg.SignID)
|
||||
if arg.FansNumMin != 0 {
|
||||
cond = append(cond, "du.fans_count>=?")
|
||||
values = append(values, arg.FansNumMin)
|
||||
}
|
||||
if arg.FansNumMax != 0 && arg.FansNumMax >= arg.FansNumMin {
|
||||
cond = append(cond, "du.fans_count<=?")
|
||||
values = append(values, arg.FansNumMax)
|
||||
}
|
||||
if arg.ActiveTID != 0 {
|
||||
cond = append(cond, "du.active_tid=?")
|
||||
values = append(values, arg.ActiveTID)
|
||||
}
|
||||
if arg.State != -1 {
|
||||
cond = append(cond, "u.state=?")
|
||||
values = append(values, arg.State)
|
||||
}
|
||||
if arg.UPMID != 0 {
|
||||
cond = append(cond, "u.up_mid=?")
|
||||
values = append(values, arg.UPMID)
|
||||
}
|
||||
if arg.UpType != -1 {
|
||||
cond = append(cond, "u.up_type=?")
|
||||
values = append(values, arg.UpType)
|
||||
}
|
||||
|
||||
var permission = arg.GetAttrPermitVal()
|
||||
if permission != 0 {
|
||||
cond = append(cond, "((permission & ?) = ?)")
|
||||
values = append(values, permission, permission)
|
||||
}
|
||||
if checkSort(arg.SortFansCount, orderSign) {
|
||||
arg.Order = "du.fans_count"
|
||||
arg.Sort = arg.SortFansCount
|
||||
orderSign = true
|
||||
}
|
||||
if checkSort(arg.SortFansCountActive, orderSign) {
|
||||
arg.Order = "du.fans_count_active"
|
||||
arg.Sort = arg.SortFansCountActive
|
||||
orderSign = true
|
||||
}
|
||||
if checkSort(arg.SortFansIncreaseAccumulate, orderSign) {
|
||||
arg.Order = "du.fans_increase_accumulate"
|
||||
arg.Sort = arg.SortFansIncreaseAccumulate
|
||||
orderSign = true
|
||||
}
|
||||
if checkSort(arg.SortArchiveCount, orderSign) {
|
||||
arg.Order = "du.archive_count"
|
||||
arg.Sort = arg.SortArchiveCount
|
||||
orderSign = true
|
||||
}
|
||||
if checkSort(arg.SortPlayCount, orderSign) {
|
||||
arg.Order = "du.play_count"
|
||||
arg.Sort = arg.SortPlayCount
|
||||
orderSign = true
|
||||
}
|
||||
if checkSort(arg.SortPubPrice, orderSign) {
|
||||
arg.Order = "u.publication_price"
|
||||
arg.Sort = arg.SortPubPrice
|
||||
}
|
||||
condStr = d.joinStringSQL(cond)
|
||||
switch SQLType {
|
||||
case "list":
|
||||
if arg.Export == model.ResponeModelCSV {
|
||||
sql = fmt.Sprintf(_selMCNUPListSQL+_orderByConditionNotLimitSQL, condStr, arg.Order, arg.Sort)
|
||||
return
|
||||
}
|
||||
sql = fmt.Sprintf(_selMCNUPListSQL+_orderByConditionSQL, condStr, arg.Order, arg.Sort)
|
||||
limit, offset := arg.PageArg.CheckPageValidation()
|
||||
values = append(values, offset, limit)
|
||||
case "count":
|
||||
sql = fmt.Sprintf(_countMCNUPListSQL, condStr)
|
||||
fmt.Println(sql)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// UpMCNUPState .
|
||||
func (d *Dao) UpMCNUPState(c context.Context, arg *model.MCNUPStateEditReq) (rows int64, err error) {
|
||||
var res sql.Result
|
||||
if res, err = d.db.Exec(c, _upMCNUPStateSQL, arg.State, time.Now(), arg.ID, arg.SignID, arg.MCNMID, arg.UPMID); err != nil {
|
||||
return rows, err
|
||||
}
|
||||
return res.RowsAffected()
|
||||
}
|
||||
|
||||
// McnSignByMCNMID .
|
||||
func (d *Dao) McnSignByMCNMID(c context.Context, MCNID int64) (m *model.MCNSignInfoReply, err error) {
|
||||
row := d.db.QueryRow(c, _selMCNByMCNMIDSQL, MCNID)
|
||||
m = new(model.MCNSignInfoReply)
|
||||
if err = row.Scan(&m.SignID, &m.McnMid, &m.CompanyName, &m.CompanyLicenseID, &m.CompanyLicenseLink, &m.ContractLink, &m.ContactName,
|
||||
&m.ContactTitle, &m.ContactIdcard, &m.ContactPhone, &m.BeginDate, &m.EndDate, &m.RejectReason, &m.RejectTime, &m.State, &m.Ctime, &m.Mtime); err != nil {
|
||||
if err == xsql.ErrNoRows {
|
||||
err = nil
|
||||
m = nil
|
||||
return
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// MCNCheatList .
|
||||
func (d *Dao) MCNCheatList(c context.Context, arg *model.MCNCheatListReq) (res []*model.MCNCheatReply, mids []int64, err error) {
|
||||
sql, values := d.buildMCNCheatListSQL("list", arg)
|
||||
rows, err := d.db.Query(c, sql, values...)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
defer rows.Close()
|
||||
for rows.Next() {
|
||||
m := &model.MCNCheatReply{}
|
||||
err = rows.Scan(&m.FansCountReal, &m.FansCountCheatAccumulate, &m.MCNMID, &m.SignID, &m.UpMID, &m.FansCountCheatIncreaseDay, &m.FansCountCheatCleanedAccumulate)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
res = append(res, m)
|
||||
mids = append(mids, m.UpMID, m.MCNMID)
|
||||
}
|
||||
mids = SliceUnique(mids)
|
||||
return
|
||||
}
|
||||
|
||||
// MCNCheatListTotal .
|
||||
func (d *Dao) MCNCheatListTotal(c context.Context, arg *model.MCNCheatListReq) (count int64, err error) {
|
||||
sql, values := d.buildMCNCheatListSQL("count", arg)
|
||||
row := d.db.QueryRow(c, sql, values...)
|
||||
if err = row.Scan(&count); err != nil {
|
||||
if err == xsql.ErrNoRows {
|
||||
err = nil
|
||||
return
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
//SliceUnique unique
|
||||
func SliceUnique(s []int64) []int64 {
|
||||
result := make([]int64, 0, len(s))
|
||||
temp := map[int64]struct{}{}
|
||||
for _, item := range s {
|
||||
if _, ok := temp[item]; !ok {
|
||||
temp[item] = struct{}{}
|
||||
result = append(result, item)
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
// buildMCNCheatListSQL build a MCNCheatList sql string.
|
||||
func (d *Dao) buildMCNCheatListSQL(SQLType string, arg *model.MCNCheatListReq) (sql string, values []interface{}) {
|
||||
values = make([]interface{}, 0, 3)
|
||||
var (
|
||||
cond []string
|
||||
condStr string
|
||||
)
|
||||
cond = append(cond, "generate_date=(SELECT generate_date FROM mcn_data_up_cheat ORDER BY generate_date DESC LIMIT 1)")
|
||||
if arg.MCNMID > 0 {
|
||||
cond = append(cond, "mcn_mid=?")
|
||||
values = append(values, arg.MCNMID)
|
||||
}
|
||||
if arg.UPMID > 0 {
|
||||
cond = append(cond, "up_mid=?")
|
||||
values = append(values, arg.UPMID)
|
||||
}
|
||||
condStr = d.joinStringSQL(cond)
|
||||
switch SQLType {
|
||||
case "list":
|
||||
sql = fmt.Sprintf(_selMCNCheatListSQL+_orderByConditionSQL, condStr, "generate_date DESC,fans_count_cheat_accumulate", "DESC")
|
||||
limit, offset := arg.PageArg.CheckPageValidation()
|
||||
values = append(values, offset, limit)
|
||||
case "count":
|
||||
sql = fmt.Sprintf(_countMCNCheatListSQL, condStr)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// MCNCheatUPList .
|
||||
func (d *Dao) MCNCheatUPList(c context.Context, arg *model.MCNCheatUPListReq) (res []*model.MCNCheatUPReply, err error) {
|
||||
limit, offset := arg.PageArg.CheckPageValidation()
|
||||
rows, err := d.db.Query(c, _selMCNCheatUPListSQL, arg.UPMID, offset, limit)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
defer rows.Close()
|
||||
for rows.Next() {
|
||||
m := &model.MCNCheatUPReply{}
|
||||
err = rows.Scan(&m.SignID, &m.GenerateDate, &m.FansCountReal, &m.FansCountCheatAccumulate, &m.MCNMID, &m.FansCountCheatIncreaseDay, &m.FansCountCheatCleanedAccumulate)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
res = append(res, m)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// MCNCheatUPListTotal .
|
||||
func (d *Dao) MCNCheatUPListTotal(c context.Context, arg *model.MCNCheatUPListReq) (count int64, err error) {
|
||||
row := d.db.QueryRow(c, _countMCNCheatUPListSQL, arg.UPMID)
|
||||
if err = row.Scan(&count); err != nil {
|
||||
if err == xsql.ErrNoRows {
|
||||
err = nil
|
||||
return
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// MCNImportUPInfo .
|
||||
func (d *Dao) MCNImportUPInfo(c context.Context, arg *model.MCNImportUPInfoReq) (m *model.MCNImportUPInfoReply, err error) {
|
||||
row := d.db.QueryRow(c, _selMCNImportUPInfoSQL, arg.SignID, arg.UPMID)
|
||||
m = new(model.MCNImportUPInfoReply)
|
||||
if err = row.Scan(&m.ID, &m.MCNMID, &m.SignID, &m.UpMID, &m.StandardFansDate, &m.StandardArchiveCount, &m.StandardFansCount, &m.IsReward); err != nil {
|
||||
if err == xsql.ErrNoRows {
|
||||
err = nil
|
||||
return
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// MCNIncreaseList .
|
||||
func (d *Dao) MCNIncreaseList(c context.Context, arg *model.MCNIncreaseListReq) (res []*model.MCNIncreaseReply, err error) {
|
||||
sql, values := d.buildMCNIncreaseListSQL("list", arg)
|
||||
rows, err := d.db.Query(c, sql, values...)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
defer rows.Close()
|
||||
for rows.Next() {
|
||||
m := &model.MCNIncreaseReply{}
|
||||
err = rows.Scan(&m.ID, &m.SignID, &m.DataType, &m.ActiveTID, &m.GenerateDate, &m.UPCount, &m.FansCountOnlineAccumulate, &m.FansCountRealAccumulate, &m.FansCountCheatAccumulate, &m.FansCountIncreaseDay,
|
||||
&m.ArchiveCountAccumulate, &m.ArchiveCountDay, &m.PlayCountAccumulate, &m.PlayCountIncreaseDay, &m.FansCountAccumulate)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
res = append(res, m)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// MCNIncreaseListTotal .
|
||||
func (d *Dao) MCNIncreaseListTotal(c context.Context, arg *model.MCNIncreaseListReq) (count int64, err error) {
|
||||
sql, values := d.buildMCNIncreaseListSQL("count", arg)
|
||||
row := d.db.QueryRow(c, sql, values...)
|
||||
if err = row.Scan(&count); err != nil {
|
||||
if err == xsql.ErrNoRows {
|
||||
err = nil
|
||||
return
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// buildMCNIncreaseListSQL build a MCNIncreaseList sql string.
|
||||
func (d *Dao) buildMCNIncreaseListSQL(SQLType string, arg *model.MCNIncreaseListReq) (sql string, values []interface{}) {
|
||||
values = make([]interface{}, 0, 3)
|
||||
var (
|
||||
cond []string
|
||||
condStr string
|
||||
)
|
||||
cond = append(cond, "sign_id=?")
|
||||
values = append(values, arg.SignID)
|
||||
if arg.DataType > 0 {
|
||||
cond = append(cond, "data_type=?")
|
||||
values = append(values, arg.DataType)
|
||||
}
|
||||
if arg.ActiveTID == 0 {
|
||||
arg.ActiveTID = model.AllActiveTid
|
||||
}
|
||||
if arg.ActiveTID > 0 {
|
||||
cond = append(cond, "active_tid=?")
|
||||
values = append(values, arg.ActiveTID)
|
||||
}
|
||||
condStr = d.joinStringSQL(cond)
|
||||
switch SQLType {
|
||||
case "list":
|
||||
sql = fmt.Sprintf(_selMCNDataSummaryListSQL+_orderByConditionSQL, condStr, "generate_date", "DESC")
|
||||
limit, offset := arg.PageArg.CheckPageValidation()
|
||||
values = append(values, offset, limit)
|
||||
case "count":
|
||||
sql = fmt.Sprintf(_countMCNDataSummaryListSQL, condStr)
|
||||
}
|
||||
return
|
||||
}
|
535
app/admin/main/mcn/dao/up/mcn_manage_test.go
Normal file
535
app/admin/main/mcn/dao/up/mcn_manage_test.go
Normal file
@ -0,0 +1,535 @@
|
||||
package up
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
"go-common/app/admin/main/mcn/model"
|
||||
|
||||
"github.com/smartystreets/goconvey/convey"
|
||||
)
|
||||
|
||||
func TestUpTxAddMCNRenewal(t *testing.T) {
|
||||
convey.Convey("TxAddMCNRenewal", t, func(ctx convey.C) {
|
||||
var (
|
||||
tx, err = d.BeginTran(context.Background())
|
||||
arg = &model.MCNSign{MCNMID: 1}
|
||||
)
|
||||
ctx.Convey("When everything goes positive", func(ctx convey.C) {
|
||||
ctx.So(err, convey.ShouldBeNil)
|
||||
lastID, err := d.TxAddMCNRenewal(tx, arg)
|
||||
defer tx.Rollback()
|
||||
|
||||
ctx.Convey("Then err should be nil. lastID should greater than zero.", func(ctx convey.C) {
|
||||
ctx.So(err, convey.ShouldBeNil)
|
||||
ctx.So(lastID, convey.ShouldBeGreaterThan, 0)
|
||||
})
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
func TestUpTxAddMCNPays(t *testing.T) {
|
||||
convey.Convey("TxAddMCNPays", t, func(ctx convey.C) {
|
||||
var (
|
||||
tx, err = d.BeginTran(context.Background())
|
||||
lastID = int64(1)
|
||||
mcnMID = int64(1)
|
||||
payInfo1, payInfo2 = &model.SignPayReq{}, &model.SignPayReq{}
|
||||
arg = []*model.SignPayReq{}
|
||||
)
|
||||
payInfo1.DueDate = "2018-10-25"
|
||||
payInfo1.PayValue = 10000
|
||||
arg = append(arg, payInfo1)
|
||||
payInfo2.DueDate = "2018-11-25"
|
||||
payInfo2.PayValue = 20000
|
||||
arg = append(arg, payInfo2)
|
||||
ctx.So(err, convey.ShouldBeNil)
|
||||
ctx.Convey("When everything goes positive", func(ctx convey.C) {
|
||||
err := d.TxAddMCNPays(tx, lastID, mcnMID, arg)
|
||||
defer tx.Rollback()
|
||||
ctx.Convey("Then err should be nil.", func(ctx convey.C) {
|
||||
ctx.So(err, convey.ShouldBeNil)
|
||||
})
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
func TestUpTxAddMCNUPs(t *testing.T) {
|
||||
convey.Convey("TxAddMCNUPs", t, func(ctx convey.C) {
|
||||
var (
|
||||
tx, _ = d.BeginTran(context.Background())
|
||||
lastID = int64(1)
|
||||
mcnMID = int64(1)
|
||||
arg []*model.MCNUP
|
||||
up = &model.MCNUP{
|
||||
SignID: 1,
|
||||
MCNMID: 1,
|
||||
UPMID: 1,
|
||||
BeginDate: 0,
|
||||
EndDate: 0,
|
||||
ContractLink: "http://www.baidu.com",
|
||||
UPAuthLink: "http://www.baidu.com",
|
||||
State: 1,
|
||||
StateChangeTime: 0,
|
||||
Permission: 1,
|
||||
}
|
||||
)
|
||||
arg = append(arg, up)
|
||||
ctx.Convey("When everything goes positive", func(ctx convey.C) {
|
||||
err := d.TxAddMCNUPs(tx, lastID, mcnMID, arg)
|
||||
defer func() {
|
||||
tx.Rollback()
|
||||
}()
|
||||
ctx.Convey("Then err should be nil.", func(ctx convey.C) {
|
||||
ctx.So(err, convey.ShouldBeNil)
|
||||
})
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
func TestUpUpMCNState(t *testing.T) {
|
||||
convey.Convey("UpMCNState", t, func(ctx convey.C) {
|
||||
var (
|
||||
c = context.Background()
|
||||
arg = &model.MCNStateEditReq{}
|
||||
)
|
||||
ctx.Convey("When everything goes positive", func(ctx convey.C) {
|
||||
rows, err := d.UpMCNState(c, arg)
|
||||
ctx.Convey("Then err should be nil.rows should not be nil.", func(ctx convey.C) {
|
||||
ctx.So(err, convey.ShouldBeNil)
|
||||
ctx.So(rows, convey.ShouldNotBeNil)
|
||||
})
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
func TestUpUpMCNPay(t *testing.T) {
|
||||
convey.Convey("UpMCNPay", t, func(ctx convey.C) {
|
||||
var (
|
||||
c = context.Background()
|
||||
arg = &model.MCNPayEditReq{}
|
||||
)
|
||||
ctx.Convey("When everything goes positive", func(ctx convey.C) {
|
||||
rows, err := d.UpMCNPay(c, arg)
|
||||
ctx.Convey("Then err should be nil.rows should not be nil.", func(ctx convey.C) {
|
||||
ctx.So(err, convey.ShouldBeNil)
|
||||
ctx.So(rows, convey.ShouldNotBeNil)
|
||||
})
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
func TestUpUpMCNPayState(t *testing.T) {
|
||||
convey.Convey("UpMCNPayState", t, func(ctx convey.C) {
|
||||
var (
|
||||
c = context.Background()
|
||||
arg = &model.MCNPayStateEditReq{}
|
||||
)
|
||||
ctx.Convey("When everything goes positive", func(ctx convey.C) {
|
||||
rows, err := d.UpMCNPayState(c, arg)
|
||||
ctx.Convey("Then err should be nil.rows should not be nil.", func(ctx convey.C) {
|
||||
ctx.So(err, convey.ShouldBeNil)
|
||||
ctx.So(rows, convey.ShouldNotBeNil)
|
||||
})
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
func TestUpMCNList(t *testing.T) {
|
||||
convey.Convey("MCNList", t, func(ctx convey.C) {
|
||||
var (
|
||||
c = context.Background()
|
||||
arg = &model.MCNListReq{}
|
||||
)
|
||||
arg.State = -1
|
||||
arg.Order = "s.mtime"
|
||||
arg.Sort = "DESC"
|
||||
arg.Page = 1
|
||||
arg.Size = 10
|
||||
ctx.Convey("When everything goes positive", func(ctx convey.C) {
|
||||
res, ids, mids, err := d.MCNList(c, arg)
|
||||
ctx.Convey("Then err should be nil.res,ids should not be nil.", func(ctx convey.C) {
|
||||
ctx.So(err, convey.ShouldBeNil)
|
||||
ctx.So(ids, convey.ShouldNotBeNil)
|
||||
ctx.So(mids, convey.ShouldNotBeNil)
|
||||
ctx.So(res, convey.ShouldNotBeNil)
|
||||
})
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
func TestUpbuildMCNListSQL(t *testing.T) {
|
||||
convey.Convey("buildMCNListSQL", t, func(ctx convey.C) {
|
||||
var (
|
||||
SQLType = ""
|
||||
arg = &model.MCNListReq{}
|
||||
)
|
||||
ctx.Convey("When everything goes positive", func(ctx convey.C) {
|
||||
sql, values := d.buildMCNListSQL(SQLType, arg)
|
||||
ctx.Convey("Then sql,values should not be nil.", func(ctx convey.C) {
|
||||
ctx.So(values, convey.ShouldNotBeNil)
|
||||
ctx.So(sql, convey.ShouldNotBeNil)
|
||||
})
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
func TestUpcheckSort(t *testing.T) {
|
||||
convey.Convey("checkSort", t, func(ctx convey.C) {
|
||||
var (
|
||||
arg = ""
|
||||
orderSign bool
|
||||
)
|
||||
ctx.Convey("When everything goes positive", func(ctx convey.C) {
|
||||
p1 := checkSort(arg, orderSign)
|
||||
ctx.Convey("Then p1 should not be nil.", func(ctx convey.C) {
|
||||
ctx.So(p1, convey.ShouldNotBeNil)
|
||||
})
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
func TestUpMcnListTotal(t *testing.T) {
|
||||
convey.Convey("McnListTotal", t, func(ctx convey.C) {
|
||||
var (
|
||||
c = context.Background()
|
||||
arg = &model.MCNListReq{
|
||||
State: -1,
|
||||
}
|
||||
)
|
||||
ctx.Convey("When everything goes positive", func(ctx convey.C) {
|
||||
count, err := d.MCNListTotal(c, arg)
|
||||
ctx.Convey("Then err should be nil.count should not be nil.", func(ctx convey.C) {
|
||||
ctx.So(err, convey.ShouldBeNil)
|
||||
ctx.So(count, convey.ShouldNotBeNil)
|
||||
})
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
func TestUpMCNPayInfos(t *testing.T) {
|
||||
convey.Convey("MCNPayInfos", t, func(ctx convey.C) {
|
||||
var (
|
||||
c = context.Background()
|
||||
ids = []int64{1, 2}
|
||||
)
|
||||
ctx.Convey("When everything goes positive", func(ctx convey.C) {
|
||||
res, err := d.MCNPayInfos(c, ids)
|
||||
ctx.Convey("Then err should be nil.res should not be nil.", func(ctx convey.C) {
|
||||
ctx.So(err, convey.ShouldBeNil)
|
||||
ctx.So(res, convey.ShouldNotBeNil)
|
||||
})
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
func TestUpTxMCNRenewalUPs(t *testing.T) {
|
||||
convey.Convey("TxMCNRenewalUPs", t, func(ctx convey.C) {
|
||||
var (
|
||||
tx, _ = d.BeginTran(context.Background())
|
||||
signID = int64(1)
|
||||
mcnID = int64(1)
|
||||
)
|
||||
ctx.Convey("When everything goes positive", func(ctx convey.C) {
|
||||
ups, err := d.TxMCNRenewalUPs(tx, signID, mcnID)
|
||||
defer func() {
|
||||
if err != nil {
|
||||
tx.Rollback()
|
||||
} else {
|
||||
tx.Commit()
|
||||
}
|
||||
}()
|
||||
ctx.Convey("Then err should be nil.ups should not be nil.", func(ctx convey.C) {
|
||||
ctx.So(err, convey.ShouldBeNil)
|
||||
if len(ups) == 0 {
|
||||
ctx.So(ups, convey.ShouldBeEmpty)
|
||||
} else {
|
||||
ctx.So(ups, convey.ShouldNotBeNil)
|
||||
}
|
||||
})
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
func TestUpMCNInfo(t *testing.T) {
|
||||
convey.Convey("MCNInfo", t, func(ctx convey.C) {
|
||||
var (
|
||||
c = context.Background()
|
||||
arg = &model.MCNInfoReq{ID: 1}
|
||||
)
|
||||
arg.MCNMID = 1
|
||||
ctx.Convey("When everything gose positive", func(ctx convey.C) {
|
||||
m, err := d.MCNInfo(c, arg)
|
||||
ctx.Convey("Then err should be nil.m should not be nil.", func(ctx convey.C) {
|
||||
ctx.So(err, convey.ShouldBeNil)
|
||||
if m == nil {
|
||||
ctx.So(m, convey.ShouldBeNil)
|
||||
} else {
|
||||
ctx.So(m, convey.ShouldNotBeNil)
|
||||
}
|
||||
})
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
func TestUpMCNUPList(t *testing.T) {
|
||||
convey.Convey("MCNUPList", t, func(ctx convey.C) {
|
||||
var (
|
||||
c = context.Background()
|
||||
arg = &model.MCNUPListReq{}
|
||||
)
|
||||
arg.DataType = 1
|
||||
arg.State = -1
|
||||
arg.UpType = -1
|
||||
arg.Order = "u.mtime"
|
||||
arg.Sort = "DESC"
|
||||
arg.Page = 1
|
||||
arg.Size = 10
|
||||
ctx.Convey("When everything goes positive", func(ctx convey.C) {
|
||||
res, err := d.MCNUPList(c, arg)
|
||||
ctx.Convey("Then err should be nil.res should not be nil.", func(ctx convey.C) {
|
||||
ctx.So(err, convey.ShouldBeNil)
|
||||
ctx.So(res, convey.ShouldBeEmpty)
|
||||
})
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
func TestUpMCNUPListTotal(t *testing.T) {
|
||||
convey.Convey("MCNUPListTotal", t, func(ctx convey.C) {
|
||||
var (
|
||||
c = context.Background()
|
||||
arg = &model.MCNUPListReq{}
|
||||
)
|
||||
arg.DataType = 1
|
||||
arg.State = -1
|
||||
arg.UpType = -1
|
||||
arg.Order = "u.mtime"
|
||||
arg.Sort = "DESC"
|
||||
arg.Page = 1
|
||||
arg.Size = 10
|
||||
ctx.Convey("When everything goes positive", func(ctx convey.C) {
|
||||
count, err := d.MCNUPListTotal(c, arg)
|
||||
ctx.Convey("Then err should be nil.count should not be nil.", func(ctx convey.C) {
|
||||
ctx.So(err, convey.ShouldBeNil)
|
||||
ctx.So(count, convey.ShouldNotBeNil)
|
||||
})
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
func TestUpbuildMCNUPListSQL(t *testing.T) {
|
||||
convey.Convey("buildMCNUPListSQL", t, func(ctx convey.C) {
|
||||
var (
|
||||
SQLType = ""
|
||||
arg = &model.MCNUPListReq{}
|
||||
)
|
||||
ctx.Convey("When everything goes positive", func(ctx convey.C) {
|
||||
sql, values := d.buildMCNUPListSQL(SQLType, arg)
|
||||
ctx.Convey("Then sql,values should not be nil.", func(ctx convey.C) {
|
||||
ctx.So(values, convey.ShouldNotBeNil)
|
||||
ctx.So(sql, convey.ShouldNotBeNil)
|
||||
})
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
func TestUpUpMCNUPState(t *testing.T) {
|
||||
convey.Convey("UpMCNUPState", t, func(ctx convey.C) {
|
||||
var (
|
||||
c = context.Background()
|
||||
arg = &model.MCNUPStateEditReq{}
|
||||
)
|
||||
ctx.Convey("When everything goes positive", func(ctx convey.C) {
|
||||
rows, err := d.UpMCNUPState(c, arg)
|
||||
ctx.Convey("Then err should be nil.rows should not be nil.", func(ctx convey.C) {
|
||||
ctx.So(err, convey.ShouldBeNil)
|
||||
ctx.So(rows, convey.ShouldNotBeNil)
|
||||
})
|
||||
})
|
||||
})
|
||||
}
|
||||
func TestUpMcnSignByMCNMID(t *testing.T) {
|
||||
convey.Convey("McnSignByMCNMID", t, func(ctx convey.C) {
|
||||
var (
|
||||
c = context.Background()
|
||||
mcnID = int64(1)
|
||||
)
|
||||
ctx.Convey("When everything goes positive", func(ctx convey.C) {
|
||||
row, err := d.McnSignByMCNMID(c, mcnID)
|
||||
ctx.Convey("Then err should be nil.rows should not be nil.", func(ctx convey.C) {
|
||||
ctx.So(err, convey.ShouldBeNil)
|
||||
ctx.So(row, convey.ShouldNotBeEmpty)
|
||||
})
|
||||
})
|
||||
})
|
||||
}
|
||||
func TestUpMCNCheatList(t *testing.T) {
|
||||
convey.Convey("TestUpMCNCheatList", t, func(ctx convey.C) {
|
||||
var (
|
||||
c = context.Background()
|
||||
arg = &model.MCNCheatListReq{}
|
||||
)
|
||||
ctx.Convey("When everything goes positive", func(ctx convey.C) {
|
||||
rows, mids, err := d.MCNCheatList(c, arg)
|
||||
ctx.Convey("Then err should be nil.rows should not be nil.", func(ctx convey.C) {
|
||||
for k, r := range rows {
|
||||
fmt.Printf("%d:%+v \n", k, r)
|
||||
}
|
||||
ctx.So(err, convey.ShouldBeNil)
|
||||
ctx.So(rows, convey.ShouldNotBeNil)
|
||||
ctx.So(mids, convey.ShouldNotBeNil)
|
||||
})
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
func TestUpMCNCheatListTotal(t *testing.T) {
|
||||
convey.Convey("TestUpMCNCheatListTotal", t, func(ctx convey.C) {
|
||||
var (
|
||||
c = context.Background()
|
||||
arg = &model.MCNCheatListReq{}
|
||||
)
|
||||
ctx.Convey("When everything goes positive", func(ctx convey.C) {
|
||||
count, err := d.MCNCheatListTotal(c, arg)
|
||||
ctx.Convey("Then err should be nil.rows should not be nil.", func(ctx convey.C) {
|
||||
fmt.Printf("count:%d \n", count)
|
||||
ctx.So(err, convey.ShouldBeNil)
|
||||
ctx.So(count, convey.ShouldNotBeNil)
|
||||
})
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
func TestUpMCNCheatUPList(t *testing.T) {
|
||||
convey.Convey("TestUpMCNCheatUPList", t, func(ctx convey.C) {
|
||||
var (
|
||||
c = context.Background()
|
||||
arg = &model.MCNCheatUPListReq{UPMID: 1}
|
||||
)
|
||||
arg.Page = 1
|
||||
arg.Size = 10
|
||||
ctx.Convey("When everything goes positive", func(ctx convey.C) {
|
||||
rows, err := d.MCNCheatUPList(c, arg)
|
||||
ctx.Convey("Then err should be nil.rows should not be nil.", func(ctx convey.C) {
|
||||
for k, r := range rows {
|
||||
fmt.Printf("%d:%+v \n", k, r)
|
||||
}
|
||||
ctx.So(err, convey.ShouldBeNil)
|
||||
if len(rows) == 0 {
|
||||
ctx.So(rows, convey.ShouldBeEmpty)
|
||||
} else {
|
||||
ctx.So(rows, convey.ShouldNotBeNil)
|
||||
}
|
||||
|
||||
})
|
||||
})
|
||||
})
|
||||
}
|
||||
func TestUpMCNCheatUPListTotal(t *testing.T) {
|
||||
convey.Convey("TestUpMCNCheatUPListTotal", t, func(ctx convey.C) {
|
||||
var (
|
||||
c = context.Background()
|
||||
arg = &model.MCNCheatUPListReq{UPMID: 1}
|
||||
)
|
||||
ctx.Convey("When everything goes positive", func(ctx convey.C) {
|
||||
count, err := d.MCNCheatUPListTotal(c, arg)
|
||||
ctx.Convey("Then err should be nil.rows should not be nil.", func(ctx convey.C) {
|
||||
fmt.Printf("count:%d \n", count)
|
||||
ctx.So(err, convey.ShouldBeNil)
|
||||
ctx.So(count, convey.ShouldNotBeNil)
|
||||
})
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
func TestUpMCNImportUPInfo(t *testing.T) {
|
||||
convey.Convey("TestUpMCNImportUPInfo", t, func(ctx convey.C) {
|
||||
var (
|
||||
c = context.Background()
|
||||
arg = &model.MCNImportUPInfoReq{UPMID: 1}
|
||||
)
|
||||
arg.SignID = 1
|
||||
ctx.Convey("When everything gose positive", func(ctx convey.C) {
|
||||
res, err := d.MCNImportUPInfo(c, arg)
|
||||
ctx.Convey("Then err should be nil.rows should not be nil.", func(ctx convey.C) {
|
||||
fmt.Printf("res:%+v \n", res)
|
||||
ctx.So(err, convey.ShouldBeNil)
|
||||
ctx.So(res, convey.ShouldNotBeNil)
|
||||
})
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
func TestUpUpMCNImportUPRewardSign(t *testing.T) {
|
||||
convey.Convey("TestUpUpMCNImportUPRewardSign", t, func(ctx convey.C) {
|
||||
var (
|
||||
c = context.Background()
|
||||
arg = &model.MCNImportUPRewardSignReq{UPMID: 1}
|
||||
)
|
||||
arg.SignID = 1
|
||||
ctx.Convey("When everything gose positive", func(ctx convey.C) {
|
||||
res, err := d.UpMCNImportUPRewardSign(c, arg)
|
||||
ctx.Convey("Then err should be nil.rows should not be nil.", func(ctx convey.C) {
|
||||
fmt.Printf("res:%+v \n", res)
|
||||
ctx.So(err, convey.ShouldBeNil)
|
||||
ctx.So(res, convey.ShouldNotBeNil)
|
||||
})
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
func TestUpUpMCNPermission(t *testing.T) {
|
||||
convey.Convey("UpMCNPermission", t, func(ctx convey.C) {
|
||||
var (
|
||||
c = context.Background()
|
||||
signID = int64(0)
|
||||
permission = uint32(0)
|
||||
)
|
||||
ctx.Convey("When everything gose positive", func(ctx convey.C) {
|
||||
rows, err := d.UpMCNPermission(c, signID, permission)
|
||||
ctx.Convey("Then err should be nil.rows should not be nil.", func(ctx convey.C) {
|
||||
ctx.So(err, convey.ShouldBeNil)
|
||||
ctx.So(rows, convey.ShouldNotBeNil)
|
||||
})
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
func TestUpMCNIncreaseList(t *testing.T) {
|
||||
convey.Convey("TestUpMCNIncreaseList", t, func(ctx convey.C) {
|
||||
var (
|
||||
c = context.Background()
|
||||
arg = &model.MCNIncreaseListReq{}
|
||||
)
|
||||
arg.SignID = 99
|
||||
ctx.Convey("When everything gose positive", func(ctx convey.C) {
|
||||
rows, err := d.MCNIncreaseList(c, arg)
|
||||
ctx.Convey("Then err should be nil.rows should not be nil.", func(ctx convey.C) {
|
||||
for k, r := range rows {
|
||||
fmt.Printf("%d:%+v \n", k, r)
|
||||
}
|
||||
ctx.So(err, convey.ShouldBeNil)
|
||||
ctx.So(rows, convey.ShouldNotBeNil)
|
||||
})
|
||||
})
|
||||
})
|
||||
}
|
||||
func TestUpMCNIncreaseListTotal(t *testing.T) {
|
||||
convey.Convey("TestUpMCNIncreaseListTotal", t, func(ctx convey.C) {
|
||||
var (
|
||||
c = context.Background()
|
||||
arg = &model.MCNIncreaseListReq{}
|
||||
)
|
||||
arg.SignID = 99
|
||||
ctx.Convey("When everything gose positive", func(ctx convey.C) {
|
||||
count, err := d.MCNIncreaseListTotal(c, arg)
|
||||
ctx.Convey("Then err should be nil.rows should not be nil.", func(ctx convey.C) {
|
||||
fmt.Printf("count:%d \n", count)
|
||||
ctx.So(err, convey.ShouldBeNil)
|
||||
ctx.So(count, convey.ShouldNotBeNil)
|
||||
})
|
||||
})
|
||||
})
|
||||
}
|
257
app/admin/main/mcn/dao/up/mcn_recommend.go
Normal file
257
app/admin/main/mcn/dao/up/mcn_recommend.go
Normal file
@ -0,0 +1,257 @@
|
||||
package up
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"database/sql"
|
||||
"fmt"
|
||||
"sync"
|
||||
|
||||
"go-common/app/admin/main/mcn/model"
|
||||
xsql "go-common/library/database/sql"
|
||||
"go-common/library/xstr"
|
||||
)
|
||||
|
||||
const (
|
||||
// private condition
|
||||
_inMcnUpRecommendSQL = `INSERT mcn_up_recommend_pool(up_mid,fans_count,archive_count,play_count_accumulate,play_count_average,active_tid,source) VALUES (?,?,?,?,?,?,2)
|
||||
ON DUPLICATE KEY UPDATE fans_count=?, archive_count=?, play_count_accumulate=?, play_count_average=?, active_tid=?, state=1, source=2, fans_count_increase_month=0,
|
||||
last_archive_time='1970-01-01 08:00:00', generate_time='1970-01-01 08:00:00'`
|
||||
_upMcnUpRecommendOPSQL = "UPDATE mcn_up_recommend_pool SET state = ? WHERE up_mid IN (%s)"
|
||||
_mcnUpRecommendsSQL = `SELECT id,up_mid,fans_count,fans_count_increase_month,archive_count,
|
||||
play_count_accumulate,play_count_average,active_tid,last_archive_time,state,source,generate_time,ctime,mtime FROM mcn_up_recommend_pool %s`
|
||||
_mcnUpRecommendTotalSQL = "SELECT COUNT(1) FROM mcn_up_recommend_pool %s"
|
||||
_mcnUpBindMidsSQL = "SELECT up_mid FROM mcn_up WHERE up_mid IN (%s) AND state IN (2,10,11,15)"
|
||||
_mcnUpRecommendMidSQL = `SELECT id,up_mid,fans_count,fans_count_increase_month,archive_count,
|
||||
play_count_accumulate,play_count_average,active_tid,last_archive_time,state,source,generate_time,ctime,mtime FROM mcn_up_recommend_pool WHERE up_mid = ?`
|
||||
_mcnUpRecommendMidsSQL = `SELECT id,up_mid,fans_count,fans_count_increase_month,archive_count,
|
||||
play_count_accumulate,play_count_average,active_tid,last_archive_time,state,source,generate_time,ctime,mtime FROM mcn_up_recommend_pool WHERE up_mid IN (%s)`
|
||||
|
||||
// common condition
|
||||
_orderByConditionSQL = " %s ORDER BY %s %s LIMIT ?,?"
|
||||
_orderByConditionNotLimitSQL = " %s ORDER BY %s %s"
|
||||
_orderByNoConditionSQL = " ORDER BY %s %s LIMIT ?,?"
|
||||
_orderByNoConditionNotLimitSQL = " ORDER BY %s %s"
|
||||
)
|
||||
|
||||
// AddMcnUpRecommend .
|
||||
func (d *Dao) AddMcnUpRecommend(c context.Context, arg *model.McnUpRecommendPool) (rows int64, err error) {
|
||||
var res sql.Result
|
||||
if res, err = d.db.Exec(c, _inMcnUpRecommendSQL, arg.UpMid, arg.FansCount, arg.ArchiveCount, arg.PlayCountAccumulate, arg.PlayCountAverage, arg.ActiveTid,
|
||||
arg.FansCount, arg.ArchiveCount, arg.PlayCountAccumulate, arg.PlayCountAverage, arg.ActiveTid); err != nil {
|
||||
return rows, err
|
||||
}
|
||||
return res.RowsAffected()
|
||||
}
|
||||
|
||||
// UpMcnUpsRecommendOP .
|
||||
func (d *Dao) UpMcnUpsRecommendOP(c context.Context, upMids []int64, state model.MCNUPRecommendState) (rows int64, err error) {
|
||||
var res sql.Result
|
||||
if res, err = d.db.Exec(c, fmt.Sprintf(_upMcnUpRecommendOPSQL, xstr.JoinInts(upMids)), state); err != nil {
|
||||
return rows, err
|
||||
}
|
||||
return res.RowsAffected()
|
||||
}
|
||||
|
||||
// McnUpRecommends .
|
||||
func (d *Dao) McnUpRecommends(c context.Context, arg *model.MCNUPRecommendReq) (res []*model.McnUpRecommendPool, err error) {
|
||||
sql, values := d.buildUpRecommendSQL("list", arg)
|
||||
rows, err := d.db.Query(c, sql, values...)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
defer rows.Close()
|
||||
for rows.Next() {
|
||||
m := &model.McnUpRecommendPool{}
|
||||
err = rows.Scan(&m.ID, &m.UpMid, &m.FansCount, &m.FansCountIncreaseMonth, &m.ArchiveCount, &m.PlayCountAccumulate, &m.PlayCountAverage,
|
||||
&m.ActiveTid, &m.LastArchiveTime, &m.State, &m.Source, &m.GenerateTime, &m.Ctime, &m.Mtime)
|
||||
if err != nil {
|
||||
if err == xsql.ErrNoRows {
|
||||
err = nil
|
||||
}
|
||||
res = nil
|
||||
return
|
||||
}
|
||||
res = append(res, m)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// McnUpRecommendTotal .
|
||||
func (d *Dao) McnUpRecommendTotal(c context.Context, arg *model.MCNUPRecommendReq) (count int, err error) {
|
||||
sql, values := d.buildUpRecommendSQL("count", arg)
|
||||
row := d.db.QueryRow(c, sql, values...)
|
||||
if err = row.Scan(&count); err != nil {
|
||||
if err == xsql.ErrNoRows {
|
||||
err = nil
|
||||
return
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// McnUpBindMids .
|
||||
func (d *Dao) McnUpBindMids(c context.Context, mids []int64) (bmids []int64, err error) {
|
||||
rows, err := d.db.Query(c, fmt.Sprintf(_mcnUpBindMidsSQL, xstr.JoinInts(mids)))
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
defer rows.Close()
|
||||
for rows.Next() {
|
||||
var upMids int64
|
||||
err = rows.Scan(&upMids)
|
||||
if err != nil {
|
||||
if err == xsql.ErrNoRows {
|
||||
err = nil
|
||||
}
|
||||
return
|
||||
}
|
||||
bmids = append(bmids, upMids)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// McnUpRecommendMid .
|
||||
func (d *Dao) McnUpRecommendMid(c context.Context, mid int64) (m *model.McnUpRecommendPool, err error) {
|
||||
row := d.db.QueryRow(c, _mcnUpRecommendMidSQL, mid)
|
||||
m = &model.McnUpRecommendPool{}
|
||||
err = row.Scan(&m.ID, &m.UpMid, &m.FansCount, &m.FansCountIncreaseMonth, &m.ArchiveCount, &m.PlayCountAccumulate, &m.PlayCountAverage,
|
||||
&m.ActiveTid, &m.LastArchiveTime, &m.State, &m.Source, &m.GenerateTime, &m.Ctime, &m.Mtime)
|
||||
if err != nil {
|
||||
if err == xsql.ErrNoRows {
|
||||
err = nil
|
||||
}
|
||||
m = nil
|
||||
return
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// McnUpRecommendMids .
|
||||
func (d *Dao) McnUpRecommendMids(c context.Context, mids []int64) (mrp map[int64]*model.McnUpRecommendPool, err error) {
|
||||
rows, err := d.db.Query(c, fmt.Sprintf(_mcnUpRecommendMidsSQL, xstr.JoinInts(mids)))
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
defer rows.Close()
|
||||
mrp = make(map[int64]*model.McnUpRecommendPool, len(mids))
|
||||
for rows.Next() {
|
||||
m := &model.McnUpRecommendPool{}
|
||||
err = rows.Scan(&m.ID, &m.UpMid, &m.FansCount, &m.FansCountIncreaseMonth, &m.ArchiveCount, &m.PlayCountAccumulate, &m.PlayCountAverage,
|
||||
&m.ActiveTid, &m.LastArchiveTime, &m.State, &m.Source, &m.GenerateTime, &m.Ctime, &m.Mtime)
|
||||
if err != nil {
|
||||
if err == xsql.ErrNoRows {
|
||||
err = nil
|
||||
}
|
||||
mrp = nil
|
||||
return
|
||||
}
|
||||
mrp[m.UpMid] = m
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// buildUpRecommendSQL build a up recommend sql string.
|
||||
func (d *Dao) buildUpRecommendSQL(tp string, arg *model.MCNUPRecommendReq) (sql string, values []interface{}) {
|
||||
values = make([]interface{}, 0, 11)
|
||||
var (
|
||||
cond []string
|
||||
condStr string
|
||||
)
|
||||
if arg.TID != 0 {
|
||||
cond = append(cond, "active_tid = ?")
|
||||
values = append(values, arg.TID)
|
||||
}
|
||||
if arg.UpMid != 0 {
|
||||
cond = append(cond, "up_mid = ?")
|
||||
values = append(values, arg.UpMid)
|
||||
}
|
||||
if arg.FansMin != 0 {
|
||||
cond = append(cond, "fans_count >= ?")
|
||||
values = append(values, arg.FansMin)
|
||||
}
|
||||
if arg.FansMax != 0 {
|
||||
cond = append(cond, "fans_count <= ?")
|
||||
values = append(values, arg.FansMax)
|
||||
}
|
||||
if arg.PlayMin != 0 {
|
||||
cond = append(cond, "play_count_accumulate >= ?")
|
||||
values = append(values, arg.PlayMin)
|
||||
}
|
||||
if arg.PlayMax != 0 {
|
||||
cond = append(cond, "play_count_accumulate <= ?")
|
||||
values = append(values, arg.PlayMax)
|
||||
}
|
||||
if arg.PlayAverageMin != 0 {
|
||||
cond = append(cond, "play_count_average >= ?")
|
||||
values = append(values, arg.PlayAverageMin)
|
||||
}
|
||||
if arg.PlayAverageMax != 0 {
|
||||
cond = append(cond, "play_count_average <= ?")
|
||||
values = append(values, arg.PlayAverageMax)
|
||||
}
|
||||
if arg.State != model.MCNUPRecommendStateUnKnown {
|
||||
cond = append(cond, "state = ?")
|
||||
values = append(values, arg.State)
|
||||
} else {
|
||||
cond = append(cond, "state IN (1,2,3)")
|
||||
}
|
||||
if arg.Source != model.MCNUPRecommendSourceUnKnown {
|
||||
cond = append(cond, "source = ?")
|
||||
values = append(values, arg.Source)
|
||||
}
|
||||
condStr = d.joinStringSQL(cond)
|
||||
switch tp {
|
||||
case "count":
|
||||
if condStr != "" {
|
||||
sql = fmt.Sprintf(_mcnUpRecommendTotalSQL+" %s", "WHERE", condStr)
|
||||
return
|
||||
}
|
||||
sql = fmt.Sprintf(_mcnUpRecommendTotalSQL, condStr)
|
||||
case "list":
|
||||
// 导出
|
||||
if arg.Export == model.ResponeModelCSV {
|
||||
if condStr != "" {
|
||||
sql = fmt.Sprintf(_mcnUpRecommendsSQL+_orderByConditionNotLimitSQL, "WHERE", condStr, arg.Order, arg.Sort)
|
||||
return
|
||||
}
|
||||
sql = fmt.Sprintf(_mcnUpRecommendsSQL+_orderByNoConditionNotLimitSQL, condStr, arg.Order, arg.Sort)
|
||||
return
|
||||
}
|
||||
// 非导出
|
||||
if condStr != "" {
|
||||
sql = fmt.Sprintf(_mcnUpRecommendsSQL+_orderByConditionSQL, "WHERE", condStr, arg.Order, arg.Sort)
|
||||
} else {
|
||||
sql = fmt.Sprintf(_mcnUpRecommendsSQL+_orderByNoConditionSQL, condStr, arg.Order, arg.Sort)
|
||||
}
|
||||
limit, offset := arg.PageArg.CheckPageValidation()
|
||||
values = append(values, offset, limit)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (d *Dao) joinStringSQL(is []string) string {
|
||||
if len(is) == 0 {
|
||||
return ""
|
||||
}
|
||||
if len(is) == 1 {
|
||||
return is[0]
|
||||
}
|
||||
var bfPool = sync.Pool{
|
||||
New: func() interface{} {
|
||||
return bytes.NewBuffer([]byte{})
|
||||
},
|
||||
}
|
||||
buf := bfPool.Get().(*bytes.Buffer)
|
||||
for _, i := range is {
|
||||
buf.WriteString(i)
|
||||
buf.WriteString(" AND ")
|
||||
}
|
||||
if buf.Len() > 0 {
|
||||
buf.Truncate(buf.Len() - 4)
|
||||
}
|
||||
s := buf.String()
|
||||
buf.Reset()
|
||||
bfPool.Put(buf)
|
||||
return s
|
||||
}
|
146
app/admin/main/mcn/dao/up/mcn_recommend_test.go
Normal file
146
app/admin/main/mcn/dao/up/mcn_recommend_test.go
Normal file
@ -0,0 +1,146 @@
|
||||
package up
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
"go-common/app/admin/main/mcn/model"
|
||||
|
||||
"github.com/smartystreets/goconvey/convey"
|
||||
)
|
||||
|
||||
func TestUpAddMcnUpRecommend(t *testing.T) {
|
||||
convey.Convey("AddMcnUpRecommend", t, func(ctx convey.C) {
|
||||
var (
|
||||
c = context.Background()
|
||||
arg = &model.McnUpRecommendPool{}
|
||||
)
|
||||
ctx.Convey("When everything goes positive", func(ctx convey.C) {
|
||||
rows, err := d.AddMcnUpRecommend(c, arg)
|
||||
d.db.Exec(c, "delete from mcn_up_recommend_pool where up_mid=0")
|
||||
ctx.Convey("Then err should be nil.rows should not be nil.", func(ctx convey.C) {
|
||||
ctx.So(err, convey.ShouldBeNil)
|
||||
ctx.So(rows, convey.ShouldNotBeNil)
|
||||
})
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
func TestUpUpMcnUpsRecommendOP(t *testing.T) {
|
||||
convey.Convey("UpMcnUpsRecommendOP", t, func(ctx convey.C) {
|
||||
var (
|
||||
c = context.Background()
|
||||
upMids = []int64{1, 2}
|
||||
state = model.MCNUPRecommendState(2)
|
||||
)
|
||||
ctx.Convey("When everything goes positive", func(ctx convey.C) {
|
||||
rows, err := d.UpMcnUpsRecommendOP(c, upMids, state)
|
||||
ctx.Convey("Then err should be nil.rows should not be nil.", func(ctx convey.C) {
|
||||
ctx.So(err, convey.ShouldBeNil)
|
||||
ctx.So(rows, convey.ShouldNotBeNil)
|
||||
})
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
func TestUpMcnUpRecommends(t *testing.T) {
|
||||
convey.Convey("McnUpRecommends", t, func(ctx convey.C) {
|
||||
var (
|
||||
c = context.Background()
|
||||
arg = &model.MCNUPRecommendReq{}
|
||||
)
|
||||
arg.Order = "mtime"
|
||||
arg.Sort = "DESC"
|
||||
arg.Page = 1
|
||||
arg.Size = 10
|
||||
ctx.Convey("When everything goes positive", func(ctx convey.C) {
|
||||
res, err := d.McnUpRecommends(c, arg)
|
||||
ctx.Convey("Then err should be nil.res should not be nil.", func(ctx convey.C) {
|
||||
ctx.So(err, convey.ShouldBeNil)
|
||||
ctx.So(res, convey.ShouldNotBeNil)
|
||||
})
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
func TestUpMcnUpRecommendTotal(t *testing.T) {
|
||||
convey.Convey("McnUpRecommendTotal", t, func(ctx convey.C) {
|
||||
var (
|
||||
c = context.Background()
|
||||
arg = &model.MCNUPRecommendReq{}
|
||||
)
|
||||
ctx.Convey("When everything goes positive", func(ctx convey.C) {
|
||||
count, err := d.McnUpRecommendTotal(c, arg)
|
||||
ctx.Convey("Then err should be nil.count should not be nil.", func(ctx convey.C) {
|
||||
ctx.So(err, convey.ShouldBeNil)
|
||||
ctx.So(count, convey.ShouldNotBeNil)
|
||||
})
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
func TestUpMcnUpBindMids(t *testing.T) {
|
||||
convey.Convey("McnUpBindMids", t, func(ctx convey.C) {
|
||||
var (
|
||||
c = context.Background()
|
||||
mids = []int64{1, 2}
|
||||
)
|
||||
ctx.Convey("When everything goes positive", func(ctx convey.C) {
|
||||
bmids, err := d.McnUpBindMids(c, mids)
|
||||
ctx.Convey("Then err should be nil.bmids should not be nil.", func(ctx convey.C) {
|
||||
ctx.So(err, convey.ShouldBeNil)
|
||||
if len(bmids) == 0 {
|
||||
ctx.So(bmids, convey.ShouldBeEmpty)
|
||||
} else {
|
||||
ctx.So(bmids, convey.ShouldNotBeNil)
|
||||
}
|
||||
})
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
func TestUpMcnUpRecommendMid(t *testing.T) {
|
||||
convey.Convey("McnUpRecommendMid", t, func(ctx convey.C) {
|
||||
var (
|
||||
c = context.Background()
|
||||
mid = int64(0)
|
||||
)
|
||||
ctx.Convey("When everything goes positive", func(ctx convey.C) {
|
||||
m, err := d.McnUpRecommendMid(c, mid)
|
||||
ctx.Convey("Then err should be nil.m should not be nil.", func(ctx convey.C) {
|
||||
ctx.So(err, convey.ShouldBeNil)
|
||||
ctx.So(m, convey.ShouldBeNil)
|
||||
})
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
func TestUpbuildUpRecommendSQL(t *testing.T) {
|
||||
convey.Convey("buildUpRecommendSQL", t, func(ctx convey.C) {
|
||||
var (
|
||||
tp = ""
|
||||
arg = &model.MCNUPRecommendReq{}
|
||||
)
|
||||
ctx.Convey("When everything goes positive", func(ctx convey.C) {
|
||||
sql, values := d.buildUpRecommendSQL(tp, arg)
|
||||
ctx.Convey("Then sql,values should not be nil.", func(ctx convey.C) {
|
||||
ctx.So(values, convey.ShouldNotBeNil)
|
||||
ctx.So(sql, convey.ShouldNotBeNil)
|
||||
})
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
func TestUpjoinStringSQL(t *testing.T) {
|
||||
convey.Convey("joinStringSQL", t, func(ctx convey.C) {
|
||||
var (
|
||||
is = []string{}
|
||||
)
|
||||
ctx.Convey("When everything goes positive", func(ctx convey.C) {
|
||||
p1 := d.joinStringSQL(is)
|
||||
ctx.Convey("Then p1 should not be nil.", func(ctx convey.C) {
|
||||
ctx.So(p1, convey.ShouldNotBeNil)
|
||||
})
|
||||
})
|
||||
})
|
||||
}
|
53
app/admin/main/mcn/dao/up/memcache.go
Normal file
53
app/admin/main/mcn/dao/up/memcache.go
Normal file
@ -0,0 +1,53 @@
|
||||
package up
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"strconv"
|
||||
|
||||
gmc "go-common/library/cache/memcache"
|
||||
"go-common/library/log"
|
||||
)
|
||||
|
||||
const (
|
||||
_mcnSign = "mcn_s_"
|
||||
_mcnUpper = "mcn_upperm_%d_%d"
|
||||
)
|
||||
|
||||
// user mcn sign key.
|
||||
func mcnSignKey(mcnMid int64) string {
|
||||
return _mcnSign + strconv.FormatInt(mcnMid, 10)
|
||||
}
|
||||
|
||||
// user upper key.
|
||||
func mcnUpperKey(signID, upMid int64) string {
|
||||
return fmt.Sprintf(_mcnUpper, signID, upMid)
|
||||
}
|
||||
|
||||
// DelMcnSignCache del mcn sign cache info.
|
||||
func (d *Dao) DelMcnSignCache(c context.Context, mcnMid int64) (err error) {
|
||||
conn := d.mc.Get(c)
|
||||
defer conn.Close()
|
||||
if err = conn.Delete(mcnSignKey(mcnMid)); err != nil {
|
||||
if err == gmc.ErrNotFound {
|
||||
err = nil
|
||||
return
|
||||
}
|
||||
log.Error("conn.Delete(%d) error(%v)", mcnMid, err)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// DelMcnUpperCache del mcn upper cache.
|
||||
func (d *Dao) DelMcnUpperCache(c context.Context, signID, upMid int64) (err error) {
|
||||
conn := d.mc.Get(c)
|
||||
defer conn.Close()
|
||||
if err = conn.Delete(mcnUpperKey(signID, upMid)); err != nil {
|
||||
if err == gmc.ErrNotFound {
|
||||
err = nil
|
||||
return
|
||||
}
|
||||
log.Error("conn.Delete(%d, %d) error(%v)", signID, upMid, err)
|
||||
}
|
||||
return
|
||||
}
|
68
app/admin/main/mcn/dao/up/memcache_test.go
Normal file
68
app/admin/main/mcn/dao/up/memcache_test.go
Normal file
@ -0,0 +1,68 @@
|
||||
package up
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
"github.com/smartystreets/goconvey/convey"
|
||||
)
|
||||
|
||||
func TestUpmcnSignKey(t *testing.T) {
|
||||
convey.Convey("mcnSignKey", t, func(ctx convey.C) {
|
||||
var (
|
||||
mcnMid = int64(0)
|
||||
)
|
||||
ctx.Convey("When everything gose positive", func(ctx convey.C) {
|
||||
p1 := mcnSignKey(mcnMid)
|
||||
ctx.Convey("Then p1 should not be nil.", func(ctx convey.C) {
|
||||
ctx.So(p1, convey.ShouldNotBeNil)
|
||||
})
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
func TestUpmcnUpperKey(t *testing.T) {
|
||||
convey.Convey("mcnUpperKey", t, func(ctx convey.C) {
|
||||
var (
|
||||
signID = int64(0)
|
||||
upMid = int64(0)
|
||||
)
|
||||
ctx.Convey("When everything gose positive", func(ctx convey.C) {
|
||||
p1 := mcnUpperKey(signID, upMid)
|
||||
ctx.Convey("Then p1 should not be nil.", func(ctx convey.C) {
|
||||
ctx.So(p1, convey.ShouldNotBeNil)
|
||||
})
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
func TestUpDelMcnSignCache(t *testing.T) {
|
||||
convey.Convey("DelMcnSignCache", t, func(ctx convey.C) {
|
||||
var (
|
||||
c = context.Background()
|
||||
mcnMid = int64(0)
|
||||
)
|
||||
ctx.Convey("When everything gose positive", func(ctx convey.C) {
|
||||
err := d.DelMcnSignCache(c, mcnMid)
|
||||
ctx.Convey("Then err should be nil.", func(ctx convey.C) {
|
||||
ctx.So(err, convey.ShouldBeNil)
|
||||
})
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
func TestUpDelMcnUpperCache(t *testing.T) {
|
||||
convey.Convey("DelMcnUpperCache", t, func(ctx convey.C) {
|
||||
var (
|
||||
c = context.Background()
|
||||
signID = int64(0)
|
||||
upMid = int64(0)
|
||||
)
|
||||
ctx.Convey("When everything gose positive", func(ctx convey.C) {
|
||||
err := d.DelMcnUpperCache(c, signID, upMid)
|
||||
ctx.Convey("Then err should be nil.", func(ctx convey.C) {
|
||||
ctx.So(err, convey.ShouldBeNil)
|
||||
})
|
||||
})
|
||||
})
|
||||
}
|
261
app/admin/main/mcn/dao/up/statistics.go
Normal file
261
app/admin/main/mcn/dao/up/statistics.go
Normal file
@ -0,0 +1,261 @@
|
||||
package up
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"net/url"
|
||||
|
||||
"go-common/app/admin/main/mcn/model"
|
||||
dtmdl "go-common/app/interface/main/mcn/model/datamodel"
|
||||
ifmdl "go-common/app/interface/main/mcn/model/mcnmodel"
|
||||
xsql "go-common/library/database/sql"
|
||||
"go-common/library/ecode"
|
||||
"go-common/library/net/metadata"
|
||||
xtime "go-common/library/time"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
const (
|
||||
_mcnDataOverviewSQL = `SELECT mcns, sign_ups, sign_ups_incr, fans_50, fans_10, fans_1, fans_incr_50, fans_incr_10, fans_incr_1 FROM mcn_data_overview WHERE generate_date = ?`
|
||||
_mcnRankFansOverviewSQL = `SELECT id, sign_id, mid, data_view, data_type, rank, fans_incr, fans FROM mcn_rank_fans_overview WHERE data_view IN (1,2,3,4) AND data_type = ? AND generate_date = ? ORDER BY rank ASC limit ?`
|
||||
_mcnRankArchiveLikesOverviewSQL = `SELECT id, mcn_mid, up_mid, sign_id, avid, tid, rank, data_type, likes, plays FROM mcn_rank_archive_likes_overview WHERE data_type = ? AND generate_date = ? ORDER BY rank ASC limit ?`
|
||||
_mcnDataTypeSummarySQL = `SELECT id, tid, data_view, data_type, amount FROM mcn_data_type_summary WHERE data_view IN (1,2,3,4) AND data_type IN (1,2) AND generate_date = ?`
|
||||
_arcTopURL = "/x/internal/mcn/rank/archive_likes"
|
||||
_dataFansURL = "/x/internal/mcn/data/fans"
|
||||
_dataFansBaseAttrURL = "/x/internal/mcn/data/fans/base/attr"
|
||||
_dataFansAreaURL = "/x/internal/mcn/data/fans/area"
|
||||
_dataFansTypeURL = "/x/internal/mcn/data/fans/type"
|
||||
_dataFansTagURL = "/x/internal/mcn/data/fans/tag"
|
||||
)
|
||||
|
||||
// McnDataOverview .
|
||||
func (d *Dao) McnDataOverview(c context.Context, date xtime.Time) (m *model.McnDataOverview, err error) {
|
||||
row := d.db.QueryRow(c, _mcnDataOverviewSQL, date)
|
||||
m = new(model.McnDataOverview)
|
||||
if err = row.Scan(&m.Mcns, &m.SignUps, &m.SignUpsIncr, &m.Fans50, &m.Fans10, &m.Fans1, &m.FansIncr50, &m.FansIncr10, &m.FansIncr1); err != nil {
|
||||
if err == xsql.ErrNoRows {
|
||||
err = nil
|
||||
m = nil
|
||||
return
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// McnRankFansOverview .
|
||||
func (d *Dao) McnRankFansOverview(c context.Context, dataType model.DataType, date xtime.Time, topLen int) (mrf map[int8][]*model.McnRankFansOverview, mids []int64, err error) {
|
||||
rows, err := d.db.Query(c, _mcnRankFansOverviewSQL, dataType, date, topLen*4)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
defer rows.Close()
|
||||
mrf = make(map[int8][]*model.McnRankFansOverview, topLen*4)
|
||||
for rows.Next() {
|
||||
rf := new(model.McnRankFansOverview)
|
||||
err = rows.Scan(&rf.ID, &rf.SignID, &rf.Mid, &rf.DataView, &rf.DataType, &rf.Rank, &rf.FansIncr, &rf.Fans)
|
||||
if err != nil {
|
||||
if err == xsql.ErrNoRows {
|
||||
err = nil
|
||||
}
|
||||
return
|
||||
}
|
||||
mids = append(mids, rf.Mid)
|
||||
mrf[rf.DataView] = append(mrf[rf.DataView], rf)
|
||||
}
|
||||
err = rows.Err()
|
||||
return
|
||||
}
|
||||
|
||||
// McnRankArchiveLikesOverview .
|
||||
func (d *Dao) McnRankArchiveLikesOverview(c context.Context, dataType model.DataType, date xtime.Time, topLen int) (ras []*model.McnRankArchiveLikesOverview, mids, avids, tids []int64, err error) {
|
||||
rows, err := d.db.Query(c, _mcnRankArchiveLikesOverviewSQL, dataType, date, topLen)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
defer rows.Close()
|
||||
for rows.Next() {
|
||||
ra := new(model.McnRankArchiveLikesOverview)
|
||||
err = rows.Scan(&ra.ID, &ra.McnMid, &ra.UpMid, &ra.SignID, &ra.Avid, &ra.Tid, &ra.Rank, &ra.DataType, &ra.Likes, &ra.Plays)
|
||||
if err != nil {
|
||||
if err == xsql.ErrNoRows {
|
||||
err = nil
|
||||
}
|
||||
return
|
||||
}
|
||||
ras = append(ras, ra)
|
||||
mids = append(mids, ra.McnMid)
|
||||
mids = append(mids, ra.UpMid)
|
||||
avids = append(avids, ra.Avid)
|
||||
tids = append(tids, int64(ra.Tid))
|
||||
}
|
||||
err = rows.Err()
|
||||
return
|
||||
}
|
||||
|
||||
// McnDataTypeSummary .
|
||||
func (d *Dao) McnDataTypeSummary(c context.Context, date xtime.Time) (mmd map[string][]*model.McnDataTypeSummary, tids []int64, err error) {
|
||||
rows, err := d.db.Query(c, _mcnDataTypeSummarySQL, date)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
defer rows.Close()
|
||||
mmd = make(map[string][]*model.McnDataTypeSummary)
|
||||
for rows.Next() {
|
||||
md := new(model.McnDataTypeSummary)
|
||||
err = rows.Scan(&md.ID, &md.Tid, &md.DataView, &md.DataType, &md.Amount)
|
||||
if err != nil {
|
||||
if err == xsql.ErrNoRows {
|
||||
err = nil
|
||||
}
|
||||
return
|
||||
}
|
||||
tids = append(tids, int64(md.Tid))
|
||||
mmd[fmt.Sprintf("%d-%d", md.DataView, md.DataType)] = append(mmd[fmt.Sprintf("%d-%d", md.DataView, md.DataType)], md)
|
||||
}
|
||||
err = rows.Err()
|
||||
return
|
||||
}
|
||||
|
||||
// ArcTopDataStatistics .
|
||||
func (d *Dao) ArcTopDataStatistics(c context.Context, arg *model.McnGetRankReq) (reply *model.McnGetRankUpFansReply, err error) {
|
||||
params := url.Values{}
|
||||
params.Set("sign_id", fmt.Sprintf("%d", arg.SignID))
|
||||
params.Set("tid", fmt.Sprintf("%d", arg.Tid))
|
||||
params.Set("data_type", fmt.Sprintf("%d", arg.DataType))
|
||||
var res struct {
|
||||
Code int `json:"code"`
|
||||
Data *model.McnGetRankUpFansReply `json:"data"`
|
||||
}
|
||||
if err = d.client.Get(c, d.arcTopURL, metadata.String(c, metadata.RemoteIP), params, &res); err != nil {
|
||||
return
|
||||
}
|
||||
if res.Code != 0 {
|
||||
err = errors.Wrapf(ecode.Int(res.Code), "arcRankFansTop d.client.Get(%s,%d)", d.arcTopURL+"?"+params.Encode(), res.Code)
|
||||
}
|
||||
reply = res.Data
|
||||
if reply != nil {
|
||||
for _, v := range reply.Result {
|
||||
v.PlayAccumulate = int64(v.Stat.View)
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// DataFans .
|
||||
func (d *Dao) DataFans(c context.Context, arg *model.McnCommonReq) (reply *dtmdl.DmConMcnFansD, err error) {
|
||||
params := url.Values{}
|
||||
params.Set("sign_id", fmt.Sprintf("%d", arg.SignID))
|
||||
var res struct {
|
||||
Code int `json:"code"`
|
||||
Data *ifmdl.McnGetMcnFansReply `json:"data"`
|
||||
}
|
||||
if err = d.client.Get(c, d.dataFansURL, metadata.String(c, metadata.RemoteIP), params, &res); err != nil {
|
||||
return
|
||||
}
|
||||
if res.Code != 0 {
|
||||
err = errors.Wrapf(ecode.Int(res.Code), "dataFans d.client.Get(%s,%d)", d.dataFansURL+"?"+params.Encode(), res.Code)
|
||||
}
|
||||
if res.Data == nil {
|
||||
return
|
||||
}
|
||||
reply = &dtmdl.DmConMcnFansD{
|
||||
LogDate: res.Data.LogDate,
|
||||
FansAll: res.Data.FansAll,
|
||||
FansInc: res.Data.FansInc,
|
||||
ActFans: res.Data.ActFans,
|
||||
FansDecAll: res.Data.FansDecAll,
|
||||
FansDec: res.Data.FansDec,
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// DataFansBaseAttr .
|
||||
func (d *Dao) DataFansBaseAttr(c context.Context, arg *model.McnCommonReq) (sex *dtmdl.DmConMcnFansSexW, age *dtmdl.DmConMcnFansAgeW, playWay *dtmdl.DmConMcnFansPlayWayW, err error) {
|
||||
params := url.Values{}
|
||||
params.Set("sign_id", fmt.Sprintf("%d", arg.SignID))
|
||||
params.Set("user_type", ifmdl.UserTypeFans)
|
||||
var res struct {
|
||||
Code int `json:"code"`
|
||||
Data *ifmdl.McnGetBaseFansAttrReply `json:"data"`
|
||||
}
|
||||
if err = d.client.Get(c, d.dataFansBaseAttrURL, metadata.String(c, metadata.RemoteIP), params, &res); err != nil {
|
||||
return
|
||||
}
|
||||
if res.Code != 0 {
|
||||
err = errors.Wrapf(ecode.Int(res.Code), "aataFansBaseAttr d.client.Get(%s,%d)", d.dataFansBaseAttrURL+"?"+params.Encode(), res.Code)
|
||||
}
|
||||
if res.Data == nil {
|
||||
return
|
||||
}
|
||||
sex = res.Data.FansSex
|
||||
age = res.Data.FansAge
|
||||
playWay = res.Data.FansPlayWay
|
||||
return
|
||||
}
|
||||
|
||||
// DataFansArea .
|
||||
func (d *Dao) DataFansArea(c context.Context, arg *model.McnCommonReq) (reply []*dtmdl.DmConMcnFansAreaW, err error) {
|
||||
params := url.Values{}
|
||||
params.Set("sign_id", fmt.Sprintf("%d", arg.SignID))
|
||||
params.Set("user_type", ifmdl.UserTypeFans)
|
||||
var res struct {
|
||||
Code int `json:"code"`
|
||||
Data *ifmdl.McnGetFansAreaReply `json:"data"`
|
||||
}
|
||||
if err = d.client.Get(c, d.dataFansAreaURL, metadata.String(c, metadata.RemoteIP), params, &res); err != nil {
|
||||
return
|
||||
}
|
||||
if res.Code != 0 {
|
||||
err = errors.Wrapf(ecode.Int(res.Code), "dataFansArea d.client.Get(%s,%d)", d.dataFansAreaURL+"?"+params.Encode(), res.Code)
|
||||
}
|
||||
if res.Data == nil {
|
||||
return
|
||||
}
|
||||
reply = res.Data.Result
|
||||
return
|
||||
}
|
||||
|
||||
// DataFansType .
|
||||
func (d *Dao) DataFansType(c context.Context, arg *model.McnCommonReq) (reply []*dtmdl.DmConMcnFansTypeW, err error) {
|
||||
params := url.Values{}
|
||||
params.Set("sign_id", fmt.Sprintf("%d", arg.SignID))
|
||||
params.Set("user_type", ifmdl.UserTypeFans)
|
||||
var res struct {
|
||||
Code int `json:"code"`
|
||||
Data *ifmdl.McnGetFansTypeReply `json:"data"`
|
||||
}
|
||||
if err = d.client.Get(c, d.dataFansTypeURL, metadata.String(c, metadata.RemoteIP), params, &res); err != nil {
|
||||
return
|
||||
}
|
||||
if res.Code != 0 {
|
||||
err = errors.Wrapf(ecode.Int(res.Code), "dataFansType d.client.Get(%s,%d)", d.dataFansTypeURL+"?"+params.Encode(), res.Code)
|
||||
}
|
||||
if res.Data == nil {
|
||||
return
|
||||
}
|
||||
reply = res.Data.Result
|
||||
return
|
||||
}
|
||||
|
||||
// DataFansTag .
|
||||
func (d *Dao) DataFansTag(c context.Context, arg *model.McnCommonReq) (reply []*dtmdl.DmConMcnFansTagW, err error) {
|
||||
params := url.Values{}
|
||||
params.Set("sign_id", fmt.Sprintf("%d", arg.SignID))
|
||||
params.Set("user_type", ifmdl.UserTypeFans)
|
||||
var res struct {
|
||||
Code int `json:"code"`
|
||||
Data *ifmdl.McnGetFansTagReply `json:"data"`
|
||||
}
|
||||
if err = d.client.Get(c, d.dataFansTagURL, metadata.String(c, metadata.RemoteIP), params, &res); err != nil {
|
||||
return
|
||||
}
|
||||
if res.Code != 0 {
|
||||
err = errors.Wrapf(ecode.Int(res.Code), "dataFansTag d.client.Get(%s,%d)", d.dataFansTagURL+"?"+params.Encode(), res.Code)
|
||||
}
|
||||
if res.Data == nil {
|
||||
return
|
||||
}
|
||||
reply = res.Data.Result
|
||||
return
|
||||
}
|
313
app/admin/main/mcn/dao/up/statistics_test.go
Normal file
313
app/admin/main/mcn/dao/up/statistics_test.go
Normal file
@ -0,0 +1,313 @@
|
||||
package up
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
"go-common/app/admin/main/mcn/model"
|
||||
xtime "go-common/library/time"
|
||||
|
||||
"github.com/smartystreets/goconvey/convey"
|
||||
"gopkg.in/h2non/gock.v1"
|
||||
)
|
||||
|
||||
func TestUpMcnDataOverview(t *testing.T) {
|
||||
convey.Convey("McnDataOverview", t, func(ctx convey.C) {
|
||||
var (
|
||||
c = context.Background()
|
||||
date = xtime.Time(1542124800)
|
||||
)
|
||||
ctx.Convey("When everything gose positive", func(ctx convey.C) {
|
||||
m, err := d.McnDataOverview(c, date)
|
||||
ctx.Convey("Then err should be nil.m should not be nil.", func(ctx convey.C) {
|
||||
ctx.So(err, convey.ShouldBeNil)
|
||||
ctx.So(m, convey.ShouldBeNil)
|
||||
})
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
func TestUpMcnRankFansOverview(t *testing.T) {
|
||||
convey.Convey("McnRankFansOverview", t, func(ctx convey.C) {
|
||||
var (
|
||||
c = context.Background()
|
||||
dataType = model.DataType(2)
|
||||
date = xtime.Time(1542124800)
|
||||
topLen = int(5)
|
||||
)
|
||||
ctx.Convey("When everything gose positive", func(ctx convey.C) {
|
||||
mrf, mids, err := d.McnRankFansOverview(c, dataType, date, topLen)
|
||||
ctx.Convey("Then err should be nil.mrf,mids should not be nil.", func(ctx convey.C) {
|
||||
ctx.So(err, convey.ShouldBeNil)
|
||||
ctx.So(mids, convey.ShouldBeNil)
|
||||
ctx.So(mrf, convey.ShouldNotBeNil)
|
||||
})
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
func TestUpMcnRankArchiveLikesOverview(t *testing.T) {
|
||||
convey.Convey("McnRankArchiveLikesOverview", t, func(ctx convey.C) {
|
||||
var (
|
||||
c = context.Background()
|
||||
dataType = model.DataType(2)
|
||||
date = xtime.Time(1542124800)
|
||||
topLen = int(5)
|
||||
)
|
||||
ctx.Convey("When everything gose positive", func(ctx convey.C) {
|
||||
ras, mids, avids, tids, err := d.McnRankArchiveLikesOverview(c, dataType, date, topLen)
|
||||
ctx.Convey("Then err should be nil.ras,mids,avids,tids should not be nil.", func(ctx convey.C) {
|
||||
ctx.So(err, convey.ShouldBeNil)
|
||||
ctx.So(tids, convey.ShouldBeNil)
|
||||
ctx.So(avids, convey.ShouldBeNil)
|
||||
ctx.So(mids, convey.ShouldBeNil)
|
||||
ctx.So(ras, convey.ShouldBeNil)
|
||||
})
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
func TestUpMcnDataTypeSummary(t *testing.T) {
|
||||
convey.Convey("McnDataTypeSummary", t, func(ctx convey.C) {
|
||||
var (
|
||||
c = context.Background()
|
||||
date = xtime.Time(1542124800)
|
||||
)
|
||||
ctx.Convey("When everything gose positive", func(ctx convey.C) {
|
||||
mmd, tids, err := d.McnDataTypeSummary(c, date)
|
||||
ctx.Convey("Then err should be nil.mmd,tids should not be nil.", func(ctx convey.C) {
|
||||
ctx.So(err, convey.ShouldBeNil)
|
||||
ctx.So(tids, convey.ShouldBeNil)
|
||||
ctx.So(mmd, convey.ShouldNotBeNil)
|
||||
})
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
func TestUpArcTopDataStatistics(t *testing.T) {
|
||||
convey.Convey("ArcTopDataStatistics", t, func(ctx convey.C) {
|
||||
var (
|
||||
c = context.Background()
|
||||
arg = &model.McnGetRankReq{}
|
||||
)
|
||||
arg.SignID = 214
|
||||
ctx.Convey("When everything gose positive", func(ctx convey.C) {
|
||||
defer gock.OffAll()
|
||||
result := `
|
||||
{
|
||||
"message":"0",
|
||||
"code":0,
|
||||
"data":{
|
||||
"type_list":[
|
||||
{
|
||||
"tid":1,
|
||||
"name":"视频"
|
||||
}
|
||||
],
|
||||
"result":[
|
||||
{
|
||||
"data_type":1,
|
||||
"likes_increase":13,
|
||||
"likes_accumulate":13,
|
||||
"play_increase":7,
|
||||
"archive_id":10110514,
|
||||
"archive_title":"不同清晰度",
|
||||
"pic":"http://i1.hdslb.com/bfs/archive/3348cb2cb34423f936916444a0a77e59f9daf1d",
|
||||
"tid_name":"日常",
|
||||
"tid":21,
|
||||
"ctime":1535362150,
|
||||
"author":{
|
||||
"face":"http://static.hdslb.com/images/member/noface.gif",
|
||||
"mid":27515266,
|
||||
"name":"Testeew还觉得是发货"
|
||||
},
|
||||
"stat":{
|
||||
"view":0
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"ttl":1
|
||||
}`
|
||||
httpMock("GET", d.arcTopURL).Reply(200).JSON(result)
|
||||
reply, err := d.ArcTopDataStatistics(c, arg)
|
||||
ctx.Convey("Then err should be nil.reply should not be nil.", func(ctx convey.C) {
|
||||
ctx.So(err, convey.ShouldBeNil)
|
||||
ctx.So(reply, convey.ShouldNotBeNil)
|
||||
})
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
func TestUpDataFans(t *testing.T) {
|
||||
convey.Convey("DataFans", t, func(ctx convey.C) {
|
||||
var (
|
||||
c = context.Background()
|
||||
arg = &model.McnCommonReq{SignID: 1}
|
||||
)
|
||||
ctx.Convey("When everything gose positive", func(ctx convey.C) {
|
||||
defer gock.OffAll()
|
||||
result := `{
|
||||
"message":"",
|
||||
"code":0,
|
||||
"data":{
|
||||
"fans_all":0,
|
||||
"fans_inc":0,
|
||||
"act_fans":0,
|
||||
"fans_dec_all":0,
|
||||
"fans_dec":0,
|
||||
"view_fans_rate":0,
|
||||
"act_fans_rate":0,
|
||||
"reply_fans_rate":0,
|
||||
"danmu_fans_rate":0,
|
||||
"coin_fans_rate":0,
|
||||
"like_fans_rate":0,
|
||||
"fav_fans_rate":0,
|
||||
"share_fans_rate":0,
|
||||
"live_gift_fans_rate":0,
|
||||
"live_danmu_fans_rate":0
|
||||
}
|
||||
}`
|
||||
httpMock("GET", d.dataFansURL).Reply(200).JSON(result)
|
||||
reply, err := d.DataFans(c, arg)
|
||||
ctx.Convey("Then err should be nil.reply should not be nil.", func(ctx convey.C) {
|
||||
ctx.So(err, convey.ShouldBeNil)
|
||||
ctx.So(reply, convey.ShouldNotBeNil)
|
||||
})
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
func TestUpDataFansBaseAttr(t *testing.T) {
|
||||
convey.Convey("DataFansBaseAttr", t, func(ctx convey.C) {
|
||||
var (
|
||||
c = context.Background()
|
||||
arg = &model.McnCommonReq{SignID: 1}
|
||||
)
|
||||
ctx.Convey("When everything gose positive", func(ctx convey.C) {
|
||||
defer gock.OffAll()
|
||||
result := `{
|
||||
"message":"",
|
||||
"code":0,
|
||||
"data":{
|
||||
"fans_sex":{
|
||||
"male":0,
|
||||
"female":0
|
||||
},
|
||||
"fans_age":{
|
||||
"a":0,
|
||||
"b":0,
|
||||
"c":0,
|
||||
"d":0
|
||||
},
|
||||
"fans_play_way":{
|
||||
"app":0,
|
||||
"pc":0,
|
||||
"outside":0,
|
||||
"other":0
|
||||
}
|
||||
}
|
||||
}`
|
||||
httpMock("GET", d.dataFansBaseAttrURL).Reply(200).JSON(result)
|
||||
sex, age, playWay, err := d.DataFansBaseAttr(c, arg)
|
||||
ctx.Convey("Then err should be nil.sex,age,playWay should not be nil.", func(ctx convey.C) {
|
||||
ctx.So(err, convey.ShouldBeNil)
|
||||
ctx.So(playWay, convey.ShouldNotBeNil)
|
||||
ctx.So(age, convey.ShouldNotBeNil)
|
||||
ctx.So(sex, convey.ShouldNotBeNil)
|
||||
})
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
func TestUpDataFansArea(t *testing.T) {
|
||||
convey.Convey("DataFansArea", t, func(ctx convey.C) {
|
||||
var (
|
||||
c = context.Background()
|
||||
arg = &model.McnCommonReq{SignID: 1}
|
||||
)
|
||||
ctx.Convey("When everything gose positive", func(ctx convey.C) {
|
||||
defer gock.OffAll()
|
||||
result := `{
|
||||
"message":"",
|
||||
"code":0,
|
||||
"data":{
|
||||
"result":[
|
||||
{
|
||||
"province":"",
|
||||
"user":0
|
||||
}
|
||||
]
|
||||
}
|
||||
}`
|
||||
httpMock("GET", d.dataFansAreaURL).Reply(200).JSON(result)
|
||||
reply, err := d.DataFansArea(c, arg)
|
||||
ctx.Convey("Then err should be nil.reply should not be nil.", func(ctx convey.C) {
|
||||
ctx.So(err, convey.ShouldBeNil)
|
||||
ctx.So(reply, convey.ShouldNotBeNil)
|
||||
})
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
func TestUpDataFansType(t *testing.T) {
|
||||
convey.Convey("DataFansType", t, func(ctx convey.C) {
|
||||
var (
|
||||
c = context.Background()
|
||||
arg = &model.McnCommonReq{SignID: 1}
|
||||
)
|
||||
ctx.Convey("When everything gose positive", func(ctx convey.C) {
|
||||
defer gock.OffAll()
|
||||
result := `{
|
||||
"message":"",
|
||||
"code":0,
|
||||
"data":{
|
||||
"result":[
|
||||
{
|
||||
"type_id":0,
|
||||
"user":0,
|
||||
"type_name":""
|
||||
}
|
||||
]
|
||||
}
|
||||
}`
|
||||
httpMock("GET", d.dataFansTypeURL).Reply(200).JSON(result)
|
||||
reply, err := d.DataFansType(c, arg)
|
||||
ctx.Convey("Then err should be nil.reply should not be nil.", func(ctx convey.C) {
|
||||
ctx.So(err, convey.ShouldBeNil)
|
||||
ctx.So(reply, convey.ShouldNotBeNil)
|
||||
})
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
func TestUpDataFansTag(t *testing.T) {
|
||||
convey.Convey("DataFansTag", t, func(ctx convey.C) {
|
||||
var (
|
||||
c = context.Background()
|
||||
arg = &model.McnCommonReq{SignID: 1}
|
||||
)
|
||||
ctx.Convey("When everything gose positive", func(ctx convey.C) {
|
||||
defer gock.OffAll()
|
||||
result := `{
|
||||
"message":"",
|
||||
"code":0,
|
||||
"data":{
|
||||
"result":[
|
||||
{
|
||||
"tag_id":0,
|
||||
"user":0,
|
||||
"tag_name":""
|
||||
}
|
||||
]
|
||||
}
|
||||
}`
|
||||
httpMock("GET", d.dataFansTagURL).Reply(200).JSON(result)
|
||||
reply, err := d.DataFansTag(c, arg)
|
||||
ctx.Convey("Then err should be nil.reply should not be nil.", func(ctx convey.C) {
|
||||
ctx.So(err, convey.ShouldBeNil)
|
||||
ctx.So(reply, convey.ShouldNotBeNil)
|
||||
})
|
||||
})
|
||||
})
|
||||
}
|
56
app/admin/main/mcn/dao/up/up_base_Info.go
Normal file
56
app/admin/main/mcn/dao/up/up_base_Info.go
Normal file
@ -0,0 +1,56 @@
|
||||
package up
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"go-common/app/admin/main/mcn/model"
|
||||
xsql "go-common/library/database/sql"
|
||||
"go-common/library/xstr"
|
||||
)
|
||||
|
||||
const (
|
||||
_selUpBaseInfoMapSQL = "SELECT mid,fans_count,active_tid,article_count_accumulate FROM up_base_info WHERE mid IN (%s) AND business_type = 1"
|
||||
_selUpPlayInfoMapSQL = "SELECT mid,play_count_accumulate,article_count FROM up_play_info WHERE mid IN (%s) AND business_type = 1"
|
||||
)
|
||||
|
||||
// UpBaseInfoMap .
|
||||
func (d *Dao) UpBaseInfoMap(c context.Context, mids []int64) (mbi map[int64]*model.UpBaseInfo, err error) {
|
||||
var rows *xsql.Rows
|
||||
if rows, err = d.db.Query(c, fmt.Sprintf(_selUpBaseInfoMapSQL, xstr.JoinInts(mids))); err != nil {
|
||||
return
|
||||
}
|
||||
defer rows.Close()
|
||||
mbi = make(map[int64]*model.UpBaseInfo, len(mids))
|
||||
for rows.Next() {
|
||||
bi := new(model.UpBaseInfo)
|
||||
if err = rows.Scan(&bi.Mid, &bi.FansCount, &bi.ActiveTid, &bi.ArticleCountAccumulate); err != nil {
|
||||
return
|
||||
}
|
||||
mbi[bi.Mid] = bi
|
||||
}
|
||||
err = rows.Err()
|
||||
return
|
||||
}
|
||||
|
||||
// UpPlayInfoMap .
|
||||
func (d *Dao) UpPlayInfoMap(c context.Context, mids []int64) (mpi map[int64]*model.UpPlayInfo, err error) {
|
||||
var rows *xsql.Rows
|
||||
if rows, err = d.db.Query(c, fmt.Sprintf(_selUpPlayInfoMapSQL, xstr.JoinInts(mids))); err != nil {
|
||||
return
|
||||
}
|
||||
defer rows.Close()
|
||||
mpi = make(map[int64]*model.UpPlayInfo, len(mids))
|
||||
for rows.Next() {
|
||||
pi := new(model.UpPlayInfo)
|
||||
if err = rows.Scan(&pi.Mid, &pi.PlayCountAccumulate, &pi.ArticleCount); err != nil {
|
||||
return
|
||||
}
|
||||
if pi.ArticleCount != 0 {
|
||||
pi.PlayCountAverage = pi.PlayCountAccumulate / pi.ArticleCount
|
||||
}
|
||||
mpi[pi.Mid] = pi
|
||||
}
|
||||
err = rows.Err()
|
||||
return
|
||||
}
|
24
app/admin/main/mcn/dao/up/up_base_Info_test.go
Normal file
24
app/admin/main/mcn/dao/up/up_base_Info_test.go
Normal file
@ -0,0 +1,24 @@
|
||||
package up
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
"github.com/smartystreets/goconvey/convey"
|
||||
)
|
||||
|
||||
func TestUpUpBaseInfoMap(t *testing.T) {
|
||||
convey.Convey("UpBaseInfoMap", t, func(ctx convey.C) {
|
||||
var (
|
||||
c = context.Background()
|
||||
mids = []int64{1, 2}
|
||||
)
|
||||
ctx.Convey("When everything goes positive", func(ctx convey.C) {
|
||||
mbi, err := d.UpBaseInfoMap(c, mids)
|
||||
ctx.Convey("Then err should be nil.mbi should not be nil.", func(ctx convey.C) {
|
||||
ctx.So(err, convey.ShouldBeNil)
|
||||
ctx.So(mbi, convey.ShouldNotBeNil)
|
||||
})
|
||||
})
|
||||
})
|
||||
}
|
Reference in New Issue
Block a user