package bbxt import ( "ai_scheduler/internal/config" "ai_scheduler/internal/data/impl" "ai_scheduler/internal/data/model" "ai_scheduler/internal/pkg" "ai_scheduler/internal/pkg/lsxd" "ai_scheduler/internal/pkg/utils_oss" "ai_scheduler/utils" "context" "encoding/json" "strings" "testing" "time" "xorm.io/builder" ) func Test_StatisOursProductLossSumApiTotal(t *testing.T) { var config = &config.Config{ Oss: config.Oss{ AccessKey: "LTAI5tGGZzjf3tvqWk8SQj2G", SecretKey: "S0NKOAUaYWoK4EGSxrMFmYDzllhvpq", Bucket: "attachment-public", Domain: "https://attachment-public.oss-cn-hangzhou.aliyuncs.com", Endpoint: "https://oss-cn-hangzhou.aliyuncs.com", }, } ossClient, err := utils_oss.NewClient(config) if err != nil { panic(err) } o, err := NewBbxtTools(nil, nil) if err != nil { panic(err) } reports, err := o.DailyReport(context.Background(), time.Now(), DownWardValue, []string{"官方-爱奇艺-星钻季卡", "官方-爱奇艺-星钻半年卡", "官方--腾讯-年卡", "官方--爱奇艺-月卡"}, SumFilter, ossClient, GetReportCache) t.Log(reports, err) } func Test_StatisOursProductLossSum(t *testing.T) { run() o, err := NewBbxtTools(configConfig, lsxd.NewLogin(configConfig, utils.NewRdb(configConfig))) if err != nil { panic(err) } report, err := o.StatisOursProductLossSum(context.Background(), time.Now(), GetReportCache) t.Log(report, err) } func Test_GetProfitRankingSum(t *testing.T) { o, err := NewBbxtTools(nil, nil) if err != nil { panic(err) } report, err := o.GetProfitRankingSum(time.Now()) t.Log(report, err) } func Test_GetStatisOfficialProductSumDecline(t *testing.T) { o, err := NewBbxtTools(nil, nil) if err != nil { panic(err) } s := "官方--腾讯-周卡,官方--腾讯-月卡,官方--腾讯-季卡,官方--腾讯-年卡,官方--优酷周卡,官方--优酷月卡,官方--优酷季卡,官方--优酷年卡,官方--爱奇艺-周卡,官方--爱奇艺-月卡,官方--爱奇艺-季卡,官方--爱奇艺-年卡,官方--芒果-PC周卡,官方--芒果-PC月卡,官方--芒果-PC季卡,官方--美团外卖红包5元,官方--美团外卖红包10元,官方--QQ音乐-绿钻月卡,官方--饿了么超级会员月卡,官方--网易云黑胶vip月卡,官方--喜马拉雅巅峰会员月卡" //s := "官方--QQ音乐-绿钻月卡" report, err := o.GetStatisOfficialProductSumDecline(time.Now(), 1000, strings.Split(s, ","), -150) t.Log(report, err) } func Test_GetStatisOfficialProductSum(t *testing.T) { configs := configConfig o, err := NewBbxtTools(nil, lsxd.NewLogin(configs, utils.NewRdb(configConfig))) if err != nil { panic(err) } s := "官方--美团外卖红包5元,官方--美团外卖红包10元,官方--饿了么超级会员月卡,官方--网易云黑胶vip月卡,官方--喜马拉雅巅峰会员月卡,官方--芒果-PC季卡,官方--芒果-PC月卡,官方--芒果-PC周卡,官方--腾讯-周卡,官方--优酷周卡,官方--QQ音乐-绿钻月卡,官方--爱奇艺-周卡,官方--腾讯-月卡,官方--腾讯-季卡,官方--腾讯-年卡,官方--优酷月卡,官方--优酷季卡,官方--优酷年卡,官方--爱奇艺-月卡,官方--爱奇艺-季卡,官方--爱奇艺-年卡" report, err := o.GetStatisOfficialProductSum(time.Now(), strings.Split(s, ",")) t.Log(report, err) } var ( reportDailyCacheImpl *impl.ReportDailyCacheImpl configConfig *config.Config ) func run() { configConfig, _ = config.LoadConfigWithTest() // 初始化数据库连接 db, _ := utils.NewGormDb(configConfig) reportDailyCacheImpl = impl.NewReportDailyCacheImpl(db) } func GetReportCache(ctx context.Context, day time.Time, totalDetail []*ResellerLoss, bbxtObj *BbxtTools) error { run() var ResellerProductRelation map[int32]*ResellerLossSumProductRelation dayDate := day.Format(time.DateOnly) cond := builder.NewCond() cond = cond.And(builder.Eq{"`index`": IndexLossSumDetail}) cond = cond.And(builder.Eq{"`key`": dayDate}) var cache model.AiReportDailyCache err := reportDailyCacheImpl.GetOneBySearchToStrut(&cond, &cache) if err != nil { return err } if cache.Value == "" { ResellerProductRelation, err = bbxtObj.GetResellerLossMannagerAndLossReasonFromApi(ctx, totalDetail) if err != nil { return err } cache = model.AiReportDailyCache{ Key: dayDate, Index: IndexLossSumDetail, Value: pkg.JsonStringIgonErr(ResellerProductRelation), } _, err = reportDailyCacheImpl.Add(&cache) if err != nil { return err } } err = json.Unmarshal([]byte(cache.Value), &ResellerProductRelation) for _, v := range totalDetail { if _, ex := ResellerProductRelation[v.ResellerId]; !ex { continue } v.Manager = ResellerProductRelation[v.ResellerId].AfterSaleName for _, vv := range v.ProductLoss { if _, ex := ResellerProductRelation[v.ResellerId].Products[vv.ProductId]; !ex { continue } vv.LossReason = ResellerProductRelation[v.ResellerId].Products[vv.ProductId].LossReason } } return nil }