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.

465 lines
11 KiB
Go

package script
import (
"context"
"joybuywork/internal/app"
"joybuywork/internal/consts"
"joybuywork/internal/plugins/jsonm"
"joybuywork/internal/repository/cache"
"joybuywork/internal/repository/dao"
"joybuywork/internal/repository/model"
"joybuywork/internal/repository/mtype"
"joybuywork/internal/repository/withdefault"
pb "joybuywork/proto/go_proto/w_script"
"fmt"
"time"
"github.com/rs/xid"
bi_fission_actionpb "gits.branchcn.com/backend/fissionbi/proto/go_proto/bi_fission_action"
"gorm.io/gen"
)
type fixData struct {
ctx context.Context
taskId string
CampaignHashId string `json:"campaign_hash_id"`
Date string `json:"date"`
}
func (s fixData) fixData() {
d := dao.Q.Begin()
var err error
defer func() {
if err != nil {
app.Logger.Error(s.ctx, fmt.Sprintf("demo逻辑问题%v", err))
d.Rollback()
return
}
d.Commit()
}()
app.FeishuNormalSend("开始同步数据")
m := dao.FissionTempGroup
tm := dao.FissionTemp
list, err := m.WithContext(s.ctx).Distinct(m.ID).Join(tm, tm.GroupID.EqCol(m.ID)).
Where(m.IsDel.Eq(0), tm.IsDel.Eq(0), tm.ID.IsNotNull()).Find()
if err != nil {
return
}
var addTemp []*model.FissionTemp
var addTempImage []*model.FissionTempImage
im := dao.FissionTempImage
for _, v := range list {
one := withdefault.FissionTemp(&model.FissionTemp{
FissionID: v.FissionID,
GroupID: v.ID,
LangType: mtype.FissionLangTypeNl,
TextType: mtype.FissionTempTextTypeEn,
})
addTemp = append(addTemp, one)
enT, _ := tm.WithContext(s.ctx).Where(tm.GroupID.Eq(v.ID), tm.LangType.Eq(mtype.FissionLangTypeEn)).First()
if enT == nil {
continue
}
imgs, _ := im.WithContext(s.ctx).Where(im.TempID.Eq(enT.ID)).Find()
for _, img := range imgs {
addTempImage = append(addTempImage, withdefault.FissionTempImage(&model.FissionTempImage{
TempID: one.ID,
Mark: img.Mark,
Val: img.Val,
Desc: img.Desc,
}))
}
}
if len(addTemp) > 0 {
err = d.FissionTemp.WithContext(s.ctx).Create(addTemp...)
if err != nil {
return
}
}
if len(addTempImage) > 0 {
err = d.FissionTempImage.WithContext(s.ctx).Create(addTempImage...)
if err != nil {
return
}
}
fmt.Println(len(list))
app.FeishuNormalSend("ok")
return
}
type fixData2 struct {
ctx context.Context
taskId string
CampaignHashId string `json:"campaign_hash_id"`
}
func (s fixData2) fixData2() {
d := dao.Q.Begin()
var err error
defer func() {
if err != nil {
app.Logger.Error(s.ctx, fmt.Sprintf("demo逻辑问题%v", err))
d.Rollback()
return
}
d.Commit()
}()
app.FeishuNormalSend("开始")
m := dao.FissionCampaign
t, _ := time.ParseInLocation(time.DateOnly, "2026-02-04", time.Local)
list, err := m.WithContext(s.ctx).Where(m.EndTime.Gt(t.Unix())).Find()
if err != nil {
return
}
userM := dao.FissionUser
for _, v := range list {
userSm := dao.FissionUser.SubTable(v.ID)
var users []*model.FissionUser
_ = userSm.WithContext(s.ctx).Where(userSm.CampaignID.Eq(v.ID)).FindInBatches(&users, 200, func(tx gen.Dao, batch int) error {
var userMark []string
for _, user := range users {
userMark = append(userMark, fmt.Sprint(user.ID))
}
resI, _ := app.NewFissionBiFissionAction().Find(s.ctx, &bi_fission_actionpb.FindReq{
CampaignId: v.ID,
Type: mtype.FissionActionTypeAppInstall,
UserMarkSource: mtype.FissionActionUserMarkSourceFissionUser,
UserMark: userMark,
})
var userInstall = make(map[string]int64, len(users))
for _, action := range resI.GetList() {
if tt, ok := userInstall[action.GetUserMark()]; !ok || tt > action.GetActionTime() {
userInstall[action.GetUserMark()] = action.GetActionTime()
}
}
resR, _ := app.NewFissionBiFissionAction().Find(s.ctx, &bi_fission_actionpb.FindReq{
CampaignId: v.ID,
Type: mtype.FissionActionTypeAppRegister,
UserMarkSource: mtype.FissionActionUserMarkSourceFissionUser,
UserMark: userMark,
})
var userRegister = make(map[string]int64, len(users))
for _, action := range resR.GetList() {
if tt, ok := userRegister[action.GetUserMark()]; !ok || tt > action.GetActionTime() {
userRegister[action.GetUserMark()] = action.GetActionTime()
}
}
for _, user := range users {
var installAt int64
if at, ok := userInstall[fmt.Sprint(user.ID)]; ok {
installAt = at
}
var registerAt int64
if at, ok := userRegister[fmt.Sprint(user.ID)]; ok {
registerAt = at
}
_, _ = userM.WithContext(s.ctx).Where(userM.ID.Eq(user.ID)).UpdateSimple(userM.InstallAt.Value(installAt), userM.RegisterAt.Value(registerAt))
_, _ = userSm.WithContext(s.ctx).Where(userSm.ID.Eq(user.ID)).UpdateSimple(userSm.InstallAt.Value(installAt), userSm.RegisterAt.Value(registerAt))
_ = cache.NewFissionUser(s.ctx, user.CampaignID).Clear(user)
}
return nil
})
}
app.FeishuNormalSend("完成")
return
}
func Boot(req *pb.BootReq) (taskId string) {
taskId = xid.New().String()
ctx := context.Background()
ctx = context.WithValue(ctx, consts.CtxBootId, taskId)
switch req.Scene {
case "clearCpn": //清楚表缓存
b := clearCpn{ctx: ctx}
jsonm.StrUnmarshal(req.JsonData, &b)
app.GoSafe(b.clearCpn, fmt.Sprintf("脚本任务 clearCpn:%s", taskId))
return
case "getCache": //获取缓存值
b := getCache{ctx: ctx}
jsonm.StrUnmarshal(req.JsonData, &b)
app.GoSafe(b.getCache, fmt.Sprintf("脚本任务 getCache:%s", taskId))
return
case "printAllLog": //全量日志
b := printAllLog{ctx: ctx}
jsonm.StrUnmarshal(req.JsonData, &b)
app.GoSafe(b.printAllLog, fmt.Sprintf("脚本任务 printAllLog:%s", taskId))
return
case "collectSlowLog": //收集慢业务
b := collectSlowLog{ctx: ctx}
jsonm.StrUnmarshal(req.JsonData, &b)
app.GoSafe(b.collectSlowLog, fmt.Sprintf("脚本任务 collectSlowLog:%s", taskId))
return
case "clearStock": //清楚活动库存缓存
b := clearStock{ctx: ctx, taskId: taskId}
jsonm.StrUnmarshal(req.JsonData, &b)
app.GoSafe(b.clearStock, fmt.Sprintf("脚本任务 clearStock:%s", taskId))
return
case "clearCache": //清楚表缓存
b := clearCache{ctx: ctx}
jsonm.StrUnmarshal(req.JsonData, &b)
app.GoSafe(b.clearCache, fmt.Sprintf("脚本任务 clearCache:%s", taskId))
return
case "lang":
b := lang{
ctx: ctx,
taskId: taskId,
}
jsonm.StrUnmarshal(req.JsonData, &b)
app.GoSafe(b.lang, fmt.Sprintf("脚本任务 lang:%s", taskId))
case "langModule":
b := langModule{
ctx: ctx,
taskId: taskId,
}
jsonm.StrUnmarshal(req.JsonData, &b)
app.GoSafe(b.langModule, fmt.Sprintf("脚本任务 langModule:%s", taskId))
case "langTextMark":
b := langTextMark{
ctx: ctx,
taskId: taskId,
}
jsonm.StrUnmarshal(req.JsonData, &b)
app.GoSafe(b.langTextMark, fmt.Sprintf("脚本任务 langTextMark:%s", taskId))
case "checkLang":
b := checkLang{
ctx: ctx,
taskId: taskId,
}
jsonm.StrUnmarshal(req.JsonData, &b)
app.GoSafe(b.checkLang, fmt.Sprintf("脚本任务 checkLang:%s", taskId))
case "fillLang":
b := fillLang{
ctx: ctx,
taskId: taskId,
}
jsonm.StrUnmarshal(req.JsonData, &b)
app.GoSafe(b.fillLang, fmt.Sprintf("脚本任务 fillLang:%s", taskId))
case "pushWaitReward":
b := pushWaitReward{
ctx: ctx,
taskId: taskId,
}
jsonm.StrUnmarshal(req.JsonData, &b)
app.GoSafe(b.pushWaitReward, fmt.Sprintf("脚本任务 pushWaitReward:%s", taskId))
case "openAd":
b := openAd{
ctx: ctx,
taskId: taskId,
}
jsonm.StrUnmarshal(req.JsonData, &b)
app.GoSafe(b.openAd, fmt.Sprintf("脚本任务 openAd:%s", taskId))
case "openPushLadder":
b := openPushLadder{
ctx: ctx,
taskId: taskId,
}
jsonm.StrUnmarshal(req.JsonData, &b)
app.GoSafe(b.openPushLadder, fmt.Sprintf("脚本任务 openPushLadder:%s", taskId))
case "openCloseCopyShare":
b := openCloseCopyShare{
ctx: ctx,
taskId: taskId,
}
jsonm.StrUnmarshal(req.JsonData, &b)
app.GoSafe(b.openCloseCopyShare, fmt.Sprintf("脚本任务 openCloseCopyShare:%s", taskId))
case "openCert":
b := openCert{
ctx: ctx,
taskId: taskId,
}
jsonm.StrUnmarshal(req.JsonData, &b)
app.GoSafe(b.openCert, fmt.Sprintf("脚本任务 openCert:%s", taskId))
case "resetAdsInit":
b := resetAdsInit{
ctx: ctx,
taskId: taskId,
}
jsonm.StrUnmarshal(req.JsonData, &b)
app.GoSafe(b.resetAdsInit, fmt.Sprintf("脚本任务 resetAdsInit:%s", taskId))
case "fixData":
b := fixData{
ctx: ctx,
taskId: taskId,
}
jsonm.StrUnmarshal(req.JsonData, &b)
app.GoSafe(b.fixData, fmt.Sprintf("脚本任务 fixData:%s", taskId))
case "fixData2":
b := fixData2{
ctx: ctx,
taskId: taskId,
}
jsonm.StrUnmarshal(req.JsonData, &b)
app.GoSafe(b.fixData2, fmt.Sprintf("脚本任务 fixData2:%s", taskId))
case "openTest":
b := openTest{
ctx: ctx,
taskId: taskId,
}
jsonm.StrUnmarshal(req.JsonData, &b)
app.GoSafe(b.openTest, fmt.Sprintf("脚本任务 openTest:%s", taskId))
case "setLangParts":
b := setLangParts{
ctx: ctx,
taskId: taskId,
}
jsonm.StrUnmarshal(req.JsonData, &b)
app.GoSafe(b.setLangParts, fmt.Sprintf("脚本任务 setLangParts:%s", taskId))
case "taskCenterLang":
b := taskCenterLang{
ctx: ctx,
taskId: taskId,
}
jsonm.StrUnmarshal(req.JsonData, &b)
app.GoSafe(b.taskCenterLang, fmt.Sprintf("脚本任务 taskCenterLang:%s", taskId))
case "openLvApi":
b := openLvApi{
ctx: ctx,
taskId: taskId,
}
jsonm.StrUnmarshal(req.JsonData, &b)
app.GoSafe(b.openLvApi, fmt.Sprintf("脚本任务 openLvApi:%s", taskId))
case "openFissionTemp":
b := openFissionTemp{
ctx: ctx,
taskId: taskId,
}
jsonm.StrUnmarshal(req.JsonData, &b)
app.GoSafe(b.openFissionTemp, fmt.Sprintf("脚本任务 openFissionTemp:%s", taskId))
case "statCampaign":
b := statCampaign{
ctx: ctx,
taskId: taskId,
}
jsonm.StrUnmarshal(req.JsonData, &b)
app.GoSafe(b.statCampaign, fmt.Sprintf("脚本任务 statCampaign:%s", taskId))
default:
app.FeishuNormalSend("你设置的脚本场景不存在[%s]", req.GetScene())
app.Logger.Warn(ctx, fmt.Sprintf("not done scene: %s, data: %s", req.GetScene(), req.GetJsonData()))
}
return
}
type demo struct {
ctx context.Context
taskId string
}
func (s demo) demo() {
d := dao.Q.Begin()
var err error
defer func() {
if err != nil {
app.Logger.Error(s.ctx, fmt.Sprintf("demo逻辑问题%v", err))
d.Rollback()
return
}
d.Commit()
}()
gm := dao.FissionTempGroup
group, err := gm.WithContext(s.ctx).Where(gm.FissionID.Eq(consts.IdAdsWheel), gm.Mark.Eq("ads_wheel_orange")).Take()
if err != nil {
return
}
if group == nil {
return
}
tm := dao.FissionTemp
list, err := tm.WithContext(s.ctx).Where(tm.GroupID.Eq(group.ID)).Find()
if err != nil {
return
}
var add []*model.FissionTempImage
for _, v := range list {
add = append(add, withdefault.FissionTempImage(&model.FissionTempImage{
TempID: v.ID,
Mark: "main",
Val: fmt.Sprintf("ftg/ads_wheel_orange/main_%s.png", mtype.FissionLangTypeToMark[v.LangType]),
Desc: "活动主图",
}), withdefault.FissionTempImage(&model.FissionTempImage{
TempID: v.ID,
Mark: "windows_congrats",
Val: fmt.Sprintf("ftg/ads_wheel_orange/windows_congrats_%s.png", mtype.FissionLangTypeToMark[v.LangType]),
Desc: "弹窗-中奖标题文案",
}))
}
if len(add) > 0 {
err = d.FissionTempImage.WithContext(s.ctx).Create(add...)
if err != nil {
return
}
}
return
}