|
|
@@ -2,7 +2,6 @@ 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" |
|
|
@@ -11,6 +10,8 @@ import ( |
|
|
|
"xorm.io/xorm" |
|
|
|
) |
|
|
|
|
|
|
|
const deleteLimit = 1000 |
|
|
|
|
|
|
|
// EggEnergyAutoUpdateUserAccess 自动更新用户访问次数记录 |
|
|
|
func EggEnergyAutoUpdateUserAccess(engine *xorm.Engine) { |
|
|
|
fmt.Println("svc_egg_energy_auto_update_user_access...") |
|
|
@@ -20,9 +21,9 @@ func EggEnergyAutoUpdateUserAccess(engine *xorm.Engine) { |
|
|
|
return |
|
|
|
} |
|
|
|
}() |
|
|
|
fmt.Println("----------------------------EggEnergyAutoUpdateUserAccess_begin-------------------------------") |
|
|
|
|
|
|
|
now := time.Now() |
|
|
|
fmt.Println(now.Hour()) |
|
|
|
if !(now.Hour() >= 2 && now.Hour() < 6) { |
|
|
|
//TODO::只在凌晨两点 ~ 凌晨六点运行 |
|
|
|
return |
|
|
@@ -39,7 +40,7 @@ func EggEnergyAutoUpdateUserAccess(engine *xorm.Engine) { |
|
|
|
for { |
|
|
|
list, err := totalDb.EggAccessTotalGetByPage(year, week, page, limit) |
|
|
|
if err != nil { |
|
|
|
logx.Warn("EggEnergyAutoUpdateUserAccess:::", err) |
|
|
|
fmt.Println("EggEnergyAutoUpdateUserAccess_GetAccessTotalFailed:::", err) |
|
|
|
return |
|
|
|
} |
|
|
|
ids := make([]string, 0, len(list)) |
|
|
@@ -54,7 +55,7 @@ func EggEnergyAutoUpdateUserAccess(engine *xorm.Engine) { |
|
|
|
} |
|
|
|
updateBulkDocRet, err := es2.UpdateBulkDoc(index, ids, updateInfoMap) |
|
|
|
if err != nil { |
|
|
|
logx.Warn("EggEnergyAutoUpdateUserAccess:::", err) |
|
|
|
fmt.Println("EggEnergyAutoUpdateUserAccess_UpdateEsFailed:::", err) |
|
|
|
return |
|
|
|
} |
|
|
|
fmt.Printf("updateBulkDocRet ==> %+v \n\n", updateBulkDocRet) |
|
|
@@ -64,4 +65,24 @@ func EggEnergyAutoUpdateUserAccess(engine *xorm.Engine) { |
|
|
|
page++ |
|
|
|
} |
|
|
|
} |
|
|
|
// 删除前一天记录 |
|
|
|
for { |
|
|
|
toDeleteDateStr := now.AddDate(0, 0, -1).Format("2006-01-02") |
|
|
|
recordsDb := implement.NewEggAccessRecordsDb(engine) |
|
|
|
affected, err := recordsDb.EggAccessRecordsDeleteByDateByPage(toDeleteDateStr, deleteLimit) |
|
|
|
if err != nil { |
|
|
|
fmt.Println("EggEnergyAutoUpdateUserAccess_DeleteAccessRecordFailed:::", err) |
|
|
|
return |
|
|
|
} |
|
|
|
if affected < deleteLimit { |
|
|
|
break |
|
|
|
} |
|
|
|
} |
|
|
|
_, err := engine.Exec("OPTIMIZE table egg_access_records") |
|
|
|
if err != nil { |
|
|
|
fmt.Println("EggEnergyAutoUpdateUserAccess_OPTIMIZEFailed:::", err) |
|
|
|
return |
|
|
|
} |
|
|
|
fmt.Println("----------------------------EggEnergyAutoUpdateUserAccess_end-------------------------------") |
|
|
|
|
|
|
|
} |