shenjiachi 2 дней назад
Родитель
Сommit
83177316dc
6 измененных файлов: 76 добавлений и 7 удалений
  1. +1
    -1
      app/task/init.go
  2. +1
    -0
      app/task/md/cron_key.go
  3. +25
    -4
      app/task/svc/svc_egg_energy_auto_update_user_access.go
  4. +25
    -0
      app/task/svc/svc_egg_energy_auto_update_user_access_test.go
  5. +22
    -0
      app/task/task_egg_energy_auto_update_user_access.go
  6. +2
    -2
      go.mod

+ 1
- 1
app/task/init.go Просмотреть файл

@@ -97,5 +97,5 @@ func initTasks() {
jobs[taskMd.CornEggEnergyAutoAdjustPrice] = taskEggEnergyAutoAdjustPrice // 蛋蛋能量-自动调整价格
jobs[taskMd.CornEggEnergyAutoCommunityDividends] = taskEggEnergyCommunityDividends // 蛋蛋能量-社区分红
jobs[taskMd.CornEggEnergyAutomaticScoring] = taskEggEnergyAutomaticScoring // 蛋蛋能量-自动打分
jobs[taskMd.CornEggEnergyAutoCachingEggPointStatistics] = taskAutoCachingEggPointStatistics // 蛋蛋分统计落地页-缓存
jobs[taskMd.CornEggEnergyAutoUpdateUserAccess] = taskEggEnergyAutoUpdateUserAccess // 蛋蛋分统计落地页-缓存
}

+ 1
- 0
app/task/md/cron_key.go Просмотреть файл

@@ -12,4 +12,5 @@ const (
CornEggEnergyAutoCommunityDividends = "cron_egg_energy_community_dividends" // 社区分红
CornEggEnergyAutomaticScoring = "cron_egg_energy_automatic_score" // 自动打分
CornEggEnergyAutoCachingEggPointStatistics = "cron_egg_energy_auto_caching_egg_point_statistics" // 缓存蛋蛋分统计落地页
CornEggEnergyAutoCachingEggPointStatistics = "cron_egg_energy_auto_caching_egg_point_statistics" // 缓存蛋蛋分统计落地页
)

+ 25
- 4
app/task/svc/svc_egg_energy_auto_update_user_access.go Просмотреть файл

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

}

+ 25
- 0
app/task/svc/svc_egg_energy_auto_update_user_access_test.go Просмотреть файл

@@ -0,0 +1,25 @@
package svc

import (
"applet/app/cfg"
"applet/app/db"
"code.fnuoos.com/go_rely_warehouse/zyos_go_es.git/es"
"testing"
)

func TestEggEnergyAutoUpdateUserAccess(t *testing.T) {
dbcfg := cfg.DBCfg{
Host: "119.23.182.117:3306",
Name: "egg",
User: "root",
Psw: "Fnuo123com@",
ShowLog: true,
MaxLifetime: 30,
MaxOpenConns: 100,
MaxIdleConns: 100,
Path: "tmp/%s.log",
}
db.InitDB(&dbcfg)
es.Init("http://123.57.140.192:9200/", "elastic", "fnuo123")
EggEnergyAutoUpdateUserAccess(db.Db)
}

+ 22
- 0
app/task/task_egg_energy_auto_update_user_access.go Просмотреть файл

@@ -0,0 +1,22 @@
package task

import (
"applet/app/task/svc"
"math/rand"
"time"
"xorm.io/xorm"
)

func taskEggEnergyAutoUpdateUserAccess(eg *xorm.Engine) {
for {
if len(ch) > workerNum {
time.Sleep(time.Millisecond * time.Duration(rand.Intn(1000)))
} else {
goto START
}
}
START:
ch <- 1
svc.EggEnergyAutoUpdateUserAccess(eg)
<-ch
}

+ 2
- 2
go.mod Просмотреть файл

@@ -33,8 +33,8 @@ require (
)

require (
code.fnuoos.com/EggPlanet/egg_models.git v0.2.1-0.20241216065523-f6396041c02b
code.fnuoos.com/EggPlanet/egg_system_rules.git v0.0.4-0.20241214095427-b3f9e6ed2446
code.fnuoos.com/EggPlanet/egg_models.git v0.2.1-0.20241216101124-4d30878258da
code.fnuoos.com/EggPlanet/egg_system_rules.git v0.0.4-0.20241216085945-78fe55637e4b
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
github.com/360EntSecGroup-Skylar/excelize v1.4.1


Загрузка…
Отмена
Сохранить