Explorar el Código

update

master
shenjiachi hace 1 semana
padre
commit
f5e235fd5d
Se han modificado 3 ficheros con 69 adiciones y 1 borrados
  1. +1
    -0
      app/task/init.go
  2. +67
    -0
      app/task/svc/svc_egg_energy_auto_update_user_access.go
  3. +1
    -1
      go.mod

+ 1
- 0
app/task/init.go Ver fichero

@@ -96,4 +96,5 @@ func initTasks() {
jobs[taskMd.CornEggEnergyDealUserPublicPlatoonPunish] = taskEggEnergyDealUserPublicPlatoonPunish // 蛋蛋能量-公排处罚
jobs[taskMd.CornEggEnergyAutoAdjustPrice] = taskEggEnergyAutoAdjustPrice // 蛋蛋能量-自动调整价格
jobs[taskMd.CornEggEnergyAutoCommunityDividends] = taskEggEnergyCommunityDividends // 蛋蛋能量-社区分红

}

+ 67
- 0
app/task/svc/svc_egg_energy_auto_update_user_access.go Ver fichero

@@ -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++
}
}
}

+ 1
- 1
go.mod Ver fichero

@@ -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


Cargando…
Cancelar
Guardar