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