From f5e235fd5dc421db6724497c53600f69a89f0c8f Mon Sep 17 00:00:00 2001 From: shenjiachi Date: Sat, 7 Dec 2024 17:53:36 +0800 Subject: [PATCH] update --- app/task/init.go | 1 + .../svc_egg_energy_auto_update_user_access.go | 67 +++++++++++++++++++ go.mod | 2 +- 3 files changed, 69 insertions(+), 1 deletion(-) create mode 100644 app/task/svc/svc_egg_energy_auto_update_user_access.go diff --git a/app/task/init.go b/app/task/init.go index c1633ef..43fbd50 100644 --- a/app/task/init.go +++ b/app/task/init.go @@ -96,4 +96,5 @@ func initTasks() { jobs[taskMd.CornEggEnergyDealUserPublicPlatoonPunish] = taskEggEnergyDealUserPublicPlatoonPunish // 蛋蛋能量-公排处罚 jobs[taskMd.CornEggEnergyAutoAdjustPrice] = taskEggEnergyAutoAdjustPrice // 蛋蛋能量-自动调整价格 jobs[taskMd.CornEggEnergyAutoCommunityDividends] = taskEggEnergyCommunityDividends // 蛋蛋能量-社区分红 + } diff --git a/app/task/svc/svc_egg_energy_auto_update_user_access.go b/app/task/svc/svc_egg_energy_auto_update_user_access.go new file mode 100644 index 0000000..1553879 --- /dev/null +++ b/app/task/svc/svc_egg_energy_auto_update_user_access.go @@ -0,0 +1,67 @@ +package svc + +import ( + "applet/app/utils" + "applet/app/utils/logx" + "code.fnuoos.com/EggPlanet/egg_models.git/src/implement" + "code.fnuoos.com/EggPlanet/egg_system_rules.git/utils/es" + es2 "code.fnuoos.com/go_rely_warehouse/zyos_go_es.git/es" + "fmt" + "time" + "xorm.io/xorm" +) + +// EggEnergyAutoUpdateUserAccess 自动更新用户访问次数记录 +func EggEnergyAutoUpdateUserAccess(engine *xorm.Engine) { + fmt.Println("svc_egg_energy_auto_update_user_access...") + defer func() { + if err := recover(); err != nil { + fmt.Println(err) + return + } + }() + + now := time.Now() + fmt.Println(now.Hour()) + if !(now.Hour() >= 2 && now.Hour() < 6) { + //TODO::只在凌晨两点 ~ 凌晨六点运行 + return + } + + // 获取当周信息 + year, week := time.Now().ISOWeek() + yearStr := utils.IntToStr(year) + weekStr := utils.IntToStr(week) + index := es.GetAppointIndexFromAlias(yearStr, weekStr) + page := 1 + limit := 100 + totalDb := implement.NewEggAccessTotalDb(engine) + for { + list, err := totalDb.EggAccessTotalGetByPage(year, week, page, limit) + if err != nil { + logx.Warn("EggEnergyAutoUpdateUserAccess:::", err) + return + } + ids := make([]string, 0, len(list)) + updateInfoMap := make([]interface{}, 0, len(list)) + for _, node := range list { + uid := node.Uid + id := fmt.Sprintf("%d%d-%d", year, week, uid) + ids = append(ids, id) + updateInfoMap = append(updateInfoMap, map[string]interface{}{ + "browse_interface_nums": node.Total, + }) + } + updateBulkDocRet, err := es2.UpdateBulkDoc(index, ids, updateInfoMap) + if err != nil { + logx.Warn("EggEnergyAutoUpdateUserAccess:::", err) + return + } + fmt.Printf("updateBulkDocRet ==> %+v \n\n", updateBulkDocRet) + if len(list) < limit { + break + } else { + page++ + } + } +} diff --git a/go.mod b/go.mod index 96d220c..34c8776 100644 --- a/go.mod +++ b/go.mod @@ -33,7 +33,7 @@ require ( ) require ( - code.fnuoos.com/EggPlanet/egg_models.git v0.2.1-0.20241207021144-5eb7d8513c6a + code.fnuoos.com/EggPlanet/egg_models.git v0.2.1-0.20241207095049-e0ad89412565 code.fnuoos.com/EggPlanet/egg_system_rules.git v0.0.4-0.20241205075006-9c0bf995c788 code.fnuoos.com/go_rely_warehouse/zyos_go_es.git v1.0.1-0.20241118083738-0f22da9ba0be code.fnuoos.com/go_rely_warehouse/zyos_go_mq.git v0.0.5