You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
305 lines
6.1 KiB
Go
305 lines
6.1 KiB
Go
package campaignnotice
|
|
|
|
import (
|
|
"context"
|
|
"joybuywork/internal/app"
|
|
"joybuywork/internal/consts/ckey"
|
|
"joybuywork/internal/repository/mtype"
|
|
"joybuywork/internal/service/queue/consumer/campaignnotice/export"
|
|
"joybuywork/internal/service/queue/consumer/campaignnotice/validevents"
|
|
"joybuywork/internal/service/queue/producer"
|
|
"joybuywork/internal/service/queue/types"
|
|
"joybuywork/internal/utils/logic"
|
|
"errors"
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/rs/xid"
|
|
"gits.branchcn.com/backend/microcode/plugins/derivative/task"
|
|
|
|
_ "joybuywork/test"
|
|
)
|
|
|
|
func TestLogic(t *testing.T) {
|
|
|
|
//wg := sync.WaitGroup{}
|
|
|
|
//for i := 0; i < 20; i++ {
|
|
//wg.Add(1)
|
|
//go func(i int) {
|
|
// defer wg.Done()
|
|
var ctx = context.Background()
|
|
var val = types.CampaignNotice{
|
|
CampaignId: 4838,
|
|
DeviceId: xid.New().String(),
|
|
UserId: "en_jjjjj",
|
|
IsInstall: false,
|
|
BehaviorTime: time.Now().Unix(),
|
|
NoticeType: types.NoticeTypePay,
|
|
NoticeTag: "",
|
|
Event: "purchases",
|
|
EventData: []types.EventData{
|
|
{
|
|
EventKey: "count",
|
|
EventVal: "2",
|
|
},
|
|
{
|
|
EventKey: "times",
|
|
EventVal: "1",
|
|
},
|
|
},
|
|
ProjectId: 143,
|
|
Ip: "",
|
|
Os: "iphone",
|
|
OsVersion: "",
|
|
DeviceModel: "",
|
|
Lang: "",
|
|
ChannelId: 0,
|
|
WebChannelId: 0,
|
|
UserMark: "948a13f1eb402f8ff16472e217608fb6",
|
|
PurchasesData: &types.PurchaseData{
|
|
TransactionId: "ffdd33",
|
|
TransactionDesc: "交易描述",
|
|
Amount: 2,
|
|
Currency: "货币单位(如:USD CNY)",
|
|
PurchaseCount: 1,
|
|
ContentItems: []types.PurchaseItem{
|
|
{
|
|
ProductId: "123",
|
|
ProductName: "产品名称",
|
|
ProductPrice: 2,
|
|
ProductQuantity: 1,
|
|
},
|
|
},
|
|
},
|
|
}
|
|
|
|
var container = new(Notice)
|
|
{
|
|
container.Init(ctx, logic.WithBp())
|
|
container.Req = &val
|
|
}
|
|
|
|
errCode := logic.Run(container)
|
|
t.Log(errCode)
|
|
|
|
//fmt.Printf("i: %d, err: %v \n", i, errCode)
|
|
//}(i)
|
|
|
|
//}
|
|
//wg.Wait()
|
|
time.Sleep(time.Second)
|
|
}
|
|
|
|
func TestOtherStat(t *testing.T) {
|
|
|
|
var userMap = map[string]struct{}{}
|
|
for i := 0; i < 20; i++ {
|
|
userMap[xid.New().String()] = struct{}{}
|
|
}
|
|
|
|
var tms = map[string]struct{}{
|
|
mtype.FissionStatOtherNoChanceClickBtn: {},
|
|
}
|
|
|
|
//wg := sync.WaitGroup{}
|
|
|
|
for i := 0; i < 20; i++ {
|
|
|
|
var mk string
|
|
for k := range tms {
|
|
mk = k
|
|
}
|
|
|
|
var userHid string
|
|
for k := range userMap {
|
|
userHid = k
|
|
}
|
|
|
|
//wg.Add(1)
|
|
//go func(i int) {
|
|
// defer wg.Done()
|
|
var ctx = context.Background()
|
|
var val = types.CampaignOtherStat{
|
|
CampaignId: 208,
|
|
Mark: mk,
|
|
UserHashId: userHid,
|
|
}
|
|
|
|
var container = new(OtherStat)
|
|
{
|
|
container.Init(ctx)
|
|
container.Req = &val
|
|
}
|
|
|
|
errCode := logic.Run(container)
|
|
t.Log(errCode)
|
|
|
|
//fmt.Printf("i: %d, err: %v \n", i, errCode)
|
|
//}(i)
|
|
|
|
}
|
|
//wg.Wait()
|
|
|
|
}
|
|
|
|
func TestDiceMap(t *testing.T) {
|
|
|
|
var container = new(DiceMap)
|
|
{
|
|
container.Init(context.Background())
|
|
container.Req = &types.CampaignDiceMap{CampaignId: 1990}
|
|
}
|
|
|
|
t.Log(logic.Run(container))
|
|
}
|
|
|
|
func TestDownload(t *testing.T) {
|
|
|
|
var container = new(export.Download)
|
|
{
|
|
container.Init(context.Background())
|
|
container.Req = &types.Download{
|
|
TaskId: "cmfm6ferdj7o6p8uls7g",
|
|
Mark: "campaign_report",
|
|
Cond: []byte("eyJjYW1wYWlnbl9oYXNoX2lkIjoiY21mNTdkbXJkajdycmZqNW4zZzAiLCJzdGFydF90aW1lIjoxNzA0ODE2MDAwLCJlbmRfdGltZSI6MTcwNDkwMjM5OX0="),
|
|
}
|
|
}
|
|
|
|
t.Log(logic.Run(container))
|
|
}
|
|
|
|
func TestValidEvents(t *testing.T) {
|
|
|
|
var ctx = context.Background()
|
|
|
|
//m := dao.FissionUser.SubTable(4323)
|
|
//
|
|
//id := xid.New().String()
|
|
//
|
|
//var users = []*model.FissionUser{
|
|
// withdefault.FissionUser(&model.FissionUser{
|
|
// CampaignID: 4323,
|
|
// ParentID: 241506581677985792,
|
|
// DeviceID: id,
|
|
// UserMark: id,
|
|
// UserType: 2,
|
|
// Source: 2,
|
|
// }),
|
|
//}
|
|
//
|
|
//m.WithContext(ctx).Create(users...)
|
|
|
|
//wg := sync.WaitGroup{}
|
|
|
|
//for i := 0; i < 20; i++ {
|
|
//wg.Add(1)
|
|
//go func(i int) {
|
|
// defer wg.Done()
|
|
|
|
// {"user_id":382170871531298816,"new_user":false,"behavior_time":1778309465,"notice_type":4,"event":"watch","event_data":[{"event_key":"stay","event_val":"1"}],"event_type":2,"ads_cond_id":382143541333184513,"campaign_id":5419,"parent_id":0}
|
|
//for _, user := range users {
|
|
|
|
var (
|
|
val = types.ValidEvents{
|
|
UserId: 386884299340845056,
|
|
//UserId: 238667159948607488,
|
|
NewUser: true,
|
|
BehaviorTime: time.Now().Unix(),
|
|
NoticeType: types.NoticeTypeCustom,
|
|
Event: "share",
|
|
EventData: []types.EventData{
|
|
{
|
|
EventKey: "share_img",
|
|
EventVal: "1",
|
|
},
|
|
},
|
|
EventType: 1,
|
|
CampaignId: 5443,
|
|
ParentId: 296975721290174464,
|
|
ClickInfo: nil,
|
|
}
|
|
)
|
|
|
|
var container = new(validevents.ValidEvents)
|
|
{
|
|
container.Init(ctx, logic.WithBp(), logic.WithTran())
|
|
container.Req = &val
|
|
}
|
|
|
|
errCode := logic.Run(container)
|
|
t.Log(errCode)
|
|
//}
|
|
|
|
//fmt.Printf("i: %d, err: %v \n", i, errCode)
|
|
//}(i)
|
|
|
|
//}
|
|
//wg.Wait()
|
|
|
|
time.Sleep(time.Second)
|
|
}
|
|
|
|
func TestName(t *testing.T) {
|
|
val := types.ValidEvents{
|
|
UserId: 284409507420909568,
|
|
NewUser: false,
|
|
BehaviorTime: time.Now().Unix(),
|
|
NoticeType: types.NoticeTypePay,
|
|
Event: "purchases",
|
|
EventData: []types.EventData{
|
|
{
|
|
EventKey: "count",
|
|
EventVal: "1",
|
|
},
|
|
},
|
|
EventType: 3,
|
|
AdsCondId: 0,
|
|
CampaignId: 4838,
|
|
ParentId: 0,
|
|
ClickInfo: nil,
|
|
}
|
|
|
|
ctx := context.Background()
|
|
ddd := app.NewRedisTask(ctx, ckey.ValidEventsKey(val.UserId))
|
|
c, err := ddd.TaskPublicAndConsume(func(td *task.Data) (err error) {
|
|
var data types.ValidEvents
|
|
err = td.ParsingMsg(&data)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
var container = new(validevents.ValidEvents)
|
|
{
|
|
container.Init(td.Ctx)
|
|
container.Req = &data
|
|
}
|
|
|
|
return logic.Run(container)
|
|
}, val)
|
|
|
|
if err != nil {
|
|
return
|
|
}
|
|
|
|
if c.Error() != nil && (errors.Is(c.Error(), task.AbnormalErr) || errors.Is(c.Error(), task.ReenterLimit)) {
|
|
producer.NewCampaignNotice(ctx).ValidEvents(val)
|
|
err = c.Error()
|
|
return
|
|
}
|
|
}
|
|
|
|
func TestRewardLimitUp(t *testing.T) {
|
|
ctx := context.Background()
|
|
var val = types.RewardLimitUp{
|
|
CampaignId: 4152,
|
|
}
|
|
var container = new(RewardLimitUp)
|
|
{
|
|
container.Init(ctx, logic.WithBp())
|
|
container.Req = &val
|
|
}
|
|
|
|
errCode := logic.Run(container)
|
|
t.Log(errCode)
|
|
}
|