@@ -6,12 +6,15 @@ import ( | |||
md "applet/app/md/institutional_management/egg_energy" | |||
"applet/app/svc/egg_energy" | |||
"applet/app/utils" | |||
"applet/app/utils/cache" | |||
"code.fnuoos.com/EggPlanet/egg_models.git/src/implement" | |||
"code.fnuoos.com/EggPlanet/egg_models.git/src/model" | |||
md2 "code.fnuoos.com/EggPlanet/egg_system_rules.git/md" | |||
"code.fnuoos.com/go_rely_warehouse/zyos_go_es.git/es" | |||
"errors" | |||
"fmt" | |||
"github.com/gin-gonic/gin" | |||
"github.com/go-redis/redis" | |||
"time" | |||
) | |||
@@ -96,77 +99,84 @@ func StatisticsUserEggIndex(c *gin.Context) { | |||
esIndexName = md2.EggEnergyUserEggScoreEsAlias + "_" + req.Year + req.Week | |||
resp.Year, resp.Week = req.Year, req.Week | |||
} | |||
//统计用户"ecpm"范围 | |||
resp.StatisticsUserEggEcpmRange, err = egg_energy.StatisticsUserEggEcpmRange(esIndexName) | |||
if err != nil { | |||
e.OutErr(c, e.ERR, err.Error()) | |||
} | |||
//统计用户"拉新人数"范围 | |||
resp.StatisticsUserEggInviteUserNumsRange, err = egg_energy.StatisticsUserEggInviteUserNumsRange(esIndexName) | |||
if err != nil { | |||
e.OutErr(c, e.ERR, err.Error()) | |||
} | |||
//统计用户"团队活跃次数"范围 | |||
resp.StatisticsUserEggTeamActivityNumsRange, err = egg_energy.StatisticsUserEggTeamActivityNumsRange(esIndexName) | |||
if err != nil { | |||
e.OutErr(c, e.ERR, err.Error()) | |||
} | |||
//统计用户"签到次数"范围 | |||
resp.StatisticsUserEggSignInNumsRange, err = egg_energy.StatisticsUserEggSignInNumsRange(esIndexName) | |||
if err != nil { | |||
e.OutErr(c, e.ERR, err.Error()) | |||
} | |||
//统计用户"发红包次数"范围 | |||
resp.StatisticsUserEggSendRedPackageNumsRange, err = egg_energy.StatisticsUserEggSendRedPackageNumsRange(esIndexName) | |||
if err != nil { | |||
e.OutErr(c, e.ERR, err.Error()) | |||
} | |||
//统计用户"蛋蛋能量兑换余额数量"范围 | |||
resp.StatisticsUserEggEggEnergyExchangeAccountBalanceRange, err = egg_energy.StatisticsUserEggEggEnergyExchangeAccountBalanceRange(esIndexName) | |||
if err != nil { | |||
e.OutErr(c, e.ERR, err.Error()) | |||
} | |||
//统计用户"蛋蛋能量兑换余额数量"范围 | |||
resp.StatisticsUserEggAccountBalanceExchangeEggEnergyNumsRange, err = egg_energy.StatisticsUserEggAccountBalanceExchangeEggEnergyNumsRange(esIndexName) | |||
if err != nil { | |||
e.OutErr(c, e.ERR, err.Error()) | |||
} | |||
//统计用户"发朋友圈次数"范围 | |||
resp.StatisticsUserEggSendCircleOfFriendNumsRange, err = egg_energy.StatisticsUserEggSendCircleOfFriendNumsRange(esIndexName) | |||
if err != nil { | |||
e.OutErr(c, e.ERR, err.Error()) | |||
} | |||
//统计用户"论坛评论次数"范围 | |||
resp.StatisticsUserEggForumCommentsNumsRange, err = egg_energy.StatisticsUserEggForumCommentsNumsRange(esIndexName) | |||
if err != nil { | |||
e.OutErr(c, e.ERR, err.Error()) | |||
} | |||
//统计用户"学院学习次数"范围 | |||
resp.StatisticsUserEggCollegeLearningNumsRange, err = egg_energy.StatisticsUserEggCollegeLearningNumsRange(esIndexName) | |||
if err != nil { | |||
e.OutErr(c, e.ERR, err.Error()) | |||
} | |||
//统计用户"违规次数"范围 | |||
resp.StatisticsUserEggViolateNumsRange, err = egg_energy.StatisticsUserEggViolateNumsRange(esIndexName) | |||
if err != nil { | |||
e.OutErr(c, e.ERR, err.Error()) | |||
} | |||
//统计用户"浏览界面次数"范围 | |||
resp.StatisticsUserEggBrowseInterfaceNumsRange, err = egg_energy.StatisticsUserEggBrowseInterfaceNumsRange(esIndexName) | |||
if err != nil { | |||
e.OutErr(c, e.ERR, err.Error()) | |||
} | |||
//统计用户"个人活跃积分增量值"范围 | |||
resp.StatisticsUserEggPersonAddActivityValueRange, err = egg_energy.StatisticsUserEggPersonAddActivityValueRange(esIndexName) | |||
if err != nil { | |||
e.OutErr(c, e.ERR, err.Error()) | |||
yearAndWeekStr := req.Year + req.Week | |||
redisKey := fmt.Sprintf(md.AutoCachingEggPointRedisKey, yearAndWeekStr) | |||
err1 := cache.GetJson(redisKey, &resp) | |||
if err1 != nil && !errors.Is(err1, redis.Nil) { | |||
e.OutErr(c, e.ERR, err1.Error()) | |||
return | |||
} else if errors.Is(err1, redis.Nil) { | |||
// 缓存不存在数据直接查询 | |||
//统计用户"ecpm"范围 | |||
resp.StatisticsUserEggEcpmRange, err = egg_energy.StatisticsUserEggEcpmRange(esIndexName) | |||
if err != nil { | |||
e.OutErr(c, e.ERR, err.Error()) | |||
} | |||
//统计用户"拉新人数"范围 | |||
resp.StatisticsUserEggInviteUserNumsRange, err = egg_energy.StatisticsUserEggInviteUserNumsRange(esIndexName) | |||
if err != nil { | |||
e.OutErr(c, e.ERR, err.Error()) | |||
} | |||
//统计用户"团队活跃次数"范围 | |||
resp.StatisticsUserEggTeamActivityNumsRange, err = egg_energy.StatisticsUserEggTeamActivityNumsRange(esIndexName) | |||
if err != nil { | |||
e.OutErr(c, e.ERR, err.Error()) | |||
} | |||
//统计用户"签到次数"范围 | |||
resp.StatisticsUserEggSignInNumsRange, err = egg_energy.StatisticsUserEggSignInNumsRange(esIndexName) | |||
if err != nil { | |||
e.OutErr(c, e.ERR, err.Error()) | |||
} | |||
//统计用户"发红包次数"范围 | |||
resp.StatisticsUserEggSendRedPackageNumsRange, err = egg_energy.StatisticsUserEggSendRedPackageNumsRange(esIndexName) | |||
if err != nil { | |||
e.OutErr(c, e.ERR, err.Error()) | |||
} | |||
//统计用户"蛋蛋能量兑换余额数量"范围 | |||
resp.StatisticsUserEggEggEnergyExchangeAccountBalanceRange, err = egg_energy.StatisticsUserEggEggEnergyExchangeAccountBalanceRange(esIndexName) | |||
if err != nil { | |||
e.OutErr(c, e.ERR, err.Error()) | |||
} | |||
//统计用户"蛋蛋能量兑换余额数量"范围 | |||
resp.StatisticsUserEggAccountBalanceExchangeEggEnergyNumsRange, err = egg_energy.StatisticsUserEggAccountBalanceExchangeEggEnergyNumsRange(esIndexName) | |||
if err != nil { | |||
e.OutErr(c, e.ERR, err.Error()) | |||
} | |||
//统计用户"发朋友圈次数"范围 | |||
resp.StatisticsUserEggSendCircleOfFriendNumsRange, err = egg_energy.StatisticsUserEggSendCircleOfFriendNumsRange(esIndexName) | |||
if err != nil { | |||
e.OutErr(c, e.ERR, err.Error()) | |||
} | |||
//统计用户"论坛评论次数"范围 | |||
resp.StatisticsUserEggForumCommentsNumsRange, err = egg_energy.StatisticsUserEggForumCommentsNumsRange(esIndexName) | |||
if err != nil { | |||
e.OutErr(c, e.ERR, err.Error()) | |||
} | |||
//统计用户"学院学习次数"范围 | |||
resp.StatisticsUserEggCollegeLearningNumsRange, err = egg_energy.StatisticsUserEggCollegeLearningNumsRange(esIndexName) | |||
if err != nil { | |||
e.OutErr(c, e.ERR, err.Error()) | |||
} | |||
//统计用户"违规次数"范围 | |||
resp.StatisticsUserEggViolateNumsRange, err = egg_energy.StatisticsUserEggViolateNumsRange(esIndexName) | |||
if err != nil { | |||
e.OutErr(c, e.ERR, err.Error()) | |||
} | |||
//统计用户"浏览界面次数"范围 | |||
resp.StatisticsUserEggBrowseInterfaceNumsRange, err = egg_energy.StatisticsUserEggBrowseInterfaceNumsRange(esIndexName) | |||
if err != nil { | |||
e.OutErr(c, e.ERR, err.Error()) | |||
} | |||
//统计用户"个人活跃积分增量值"范围 | |||
resp.StatisticsUserEggPersonAddActivityValueRange, err = egg_energy.StatisticsUserEggPersonAddActivityValueRange(esIndexName) | |||
if err != nil { | |||
e.OutErr(c, e.ERR, err.Error()) | |||
} | |||
// 更新缓存 | |||
cache.SetJson(redisKey, resp, -1) | |||
} | |||
resp.YearAndWeekList, err = egg_energy.GetYearsAndWeeks() | |||
if err != nil { | |||
return | |||
} | |||
if err != nil { | |||
e.OutErr(c, e.ERR, err.Error()) | |||
} | |||
@@ -12,6 +12,8 @@ type UserEggIndexReq struct { | |||
Week string `json:"week" example:"周份"` | |||
} | |||
const AutoCachingEggPointRedisKey = "EggEnergy:AutoCachingEggPoint:%s" // 年-周 | |||
type StatisticsEggPointResp struct { | |||
Year string `json:"year" example:"年份"` | |||
Week string `json:"week" example:"周份"` | |||
@@ -97,4 +97,5 @@ func initTasks() { | |||
jobs[taskMd.CornEggEnergyAutoAdjustPrice] = taskEggEnergyAutoAdjustPrice // 蛋蛋能量-自动调整价格 | |||
jobs[taskMd.CornEggEnergyAutoCommunityDividends] = taskEggEnergyCommunityDividends // 蛋蛋能量-社区分红 | |||
jobs[taskMd.CornEggEnergyAutomaticScoring] = taskEggEnergyAutomaticScoring // 蛋蛋能量-自动打分 | |||
jobs[taskMd.CornEggEnergyAutoCachingEggPointStatistics] = taskAutoCachingEggPointStatistics // 蛋蛋分统计落地页-缓存 | |||
} |
@@ -1,14 +1,15 @@ | |||
package md | |||
const ( | |||
CronEggEnergyAutoRecordPrices = "cron_egg_energy_auto_record_price" // 自动记录价格 | |||
CronEggEnergyDealPlatformRevenueData = "cron_egg_energy_deal_platform_revenue_data" // 处理平台收益 | |||
CronEggEnergyDealFundData = "cron_egg_energy_deal_fund_data" // 处理价值投入 | |||
CronEggEnergyUserEggScore = "cron_egg_energy_user_egg_score" // 处理蛋蛋分 | |||
CornEggEnergyAutoReleaseTeamEggEnergy = "cron_egg_energy_auto_release_team_egg_energy" // 处理团队蛋蛋能量释放到个人蛋蛋能量 | |||
CornSettlementStarLevelDividends = "cron_egg_energy_settlement_star_level_dividends" // 结算星级分红 | |||
CornEggEnergyDealUserPublicPlatoonPunish = "cron_egg_energy_deal_user_public_platoon_punish" // 公排处罚 | |||
CornEggEnergyAutoAdjustPrice = "cron_egg_energy_auto_adjust_price" // 自动调整价格 | |||
CornEggEnergyAutoCommunityDividends = "cron_egg_energy_community_dividends" // 社区分红 | |||
CornEggEnergyAutomaticScoring = "corn_egg_energy_automatic_score" // 自动打分 | |||
CronEggEnergyAutoRecordPrices = "cron_egg_energy_auto_record_price" // 自动记录价格 | |||
CronEggEnergyDealPlatformRevenueData = "cron_egg_energy_deal_platform_revenue_data" // 处理平台收益 | |||
CronEggEnergyDealFundData = "cron_egg_energy_deal_fund_data" // 处理价值投入 | |||
CronEggEnergyUserEggScore = "cron_egg_energy_user_egg_score" // 处理蛋蛋分 | |||
CornEggEnergyAutoReleaseTeamEggEnergy = "cron_egg_energy_auto_release_team_egg_energy" // 处理团队蛋蛋能量释放到个人蛋蛋能量 | |||
CornSettlementStarLevelDividends = "cron_egg_energy_settlement_star_level_dividends" // 结算星级分红 | |||
CornEggEnergyDealUserPublicPlatoonPunish = "cron_egg_energy_deal_user_public_platoon_punish" // 公排处罚 | |||
CornEggEnergyAutoAdjustPrice = "cron_egg_energy_auto_adjust_price" // 自动调整价格 | |||
CornEggEnergyAutoCommunityDividends = "cron_egg_energy_community_dividends" // 社区分红 | |||
CornEggEnergyAutomaticScoring = "corn_egg_energy_automatic_score" // 自动打分 | |||
CornEggEnergyAutoCachingEggPointStatistics = "corn_egg_energy_auto_caching_egg_point_statistics" // 缓存蛋蛋分统计落地页 // 自动打分 | |||
) |
@@ -8,6 +8,3 @@ type RevenueDataNode struct { | |||
Data model.PlatformRevenueData `json:"data"` | |||
EveryAmount string `json:"every_amount" ` // 每次结算金额 | |||
} | |||
type name struct { | |||
} |
@@ -0,0 +1,132 @@ | |||
package svc | |||
import ( | |||
md2 "applet/app/md/institutional_management/egg_energy" | |||
"applet/app/svc/egg_energy" | |||
"applet/app/utils/cache" | |||
"code.fnuoos.com/EggPlanet/egg_system_rules.git/md" | |||
"code.fnuoos.com/go_rely_warehouse/zyos_go_es.git/es" | |||
"context" | |||
"fmt" | |||
"strings" | |||
"time" | |||
"xorm.io/xorm" | |||
) | |||
const AutoCachingEggPointStatisticsLockKey = "egg_energy_auto_automatic_scoring_lock_key" | |||
func AutoCachingEggPointStatistics(engine *xorm.Engine) { | |||
fmt.Println("svc_egg_energy_auto_caching_egg_point_statistics...") | |||
defer func() { | |||
if err := recover(); err != nil { | |||
fmt.Println(err) | |||
return | |||
} | |||
}() | |||
fmt.Println("----------------------------AutoCachingEggPointStatistics_begin-------------------------------") | |||
getString, _ := cache.GetString(AutoCachingEggPointStatisticsLockKey) | |||
if getString != "" { | |||
fmt.Println("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!", "上一次蛋蛋分统计未执行完") | |||
return | |||
} | |||
cache.SetEx(AutoCachingEggPointStatisticsLockKey, "running", 10*60) // 10 min | |||
// 1. 查询所有蛋蛋分索引 | |||
aliasName := md.EggEnergyUserEggScoreEsAlias | |||
aliases, err := es.EsClient.Aliases(). | |||
Index(aliasName). // 指定别名 | |||
Do(context.Background()) | |||
if err != nil { | |||
fmt.Println("AutoCachingEggPointStatistics_GetAllIndexFailed_ERR:::::", err.Error()) | |||
return | |||
} | |||
now := time.Now() | |||
year, week := now.ISOWeek() | |||
currentWeekIndex := fmt.Sprintf(md.EggEnergyUserEggScoreEsAlias+"_%d%d", year, week) | |||
// 2. 按周处理蛋蛋分记录 | |||
for esIndexName, _ := range aliases.Indices { | |||
// 2.1 查询是否有此周且不为当周记录 | |||
egg_energy.GetYearsAndWeekStr(esIndexName) | |||
if esIndexName != currentWeekIndex { | |||
exists := cache.Exists(md2.AutoCachingEggPointRedisKey) | |||
if exists { | |||
continue | |||
} | |||
} | |||
// 2.2 更新记录 | |||
var tempWeek md2.StatisticsEggPointResp | |||
//统计用户"ecpm"范围 | |||
tempWeek.StatisticsUserEggEcpmRange, err = egg_energy.StatisticsUserEggEcpmRange(esIndexName) | |||
if err != nil { | |||
fmt.Println("AutoCachingEggPointStatistics_StatisticsFailed_ERR:::::", err.Error()) | |||
} | |||
//统计用户"拉新人数"范围 | |||
tempWeek.StatisticsUserEggInviteUserNumsRange, err = egg_energy.StatisticsUserEggInviteUserNumsRange(esIndexName) | |||
if err != nil { | |||
fmt.Println("AutoCachingEggPointStatistics_StatisticsFailed_ERR:::::", err.Error()) | |||
} | |||
//统计用户"团队活跃次数"范围 | |||
tempWeek.StatisticsUserEggTeamActivityNumsRange, err = egg_energy.StatisticsUserEggTeamActivityNumsRange(esIndexName) | |||
if err != nil { | |||
fmt.Println("AutoCachingEggPointStatistics_StatisticsFailed_ERR:::::", err.Error()) | |||
} | |||
//统计用户"签到次数"范围 | |||
tempWeek.StatisticsUserEggSignInNumsRange, err = egg_energy.StatisticsUserEggSignInNumsRange(esIndexName) | |||
if err != nil { | |||
fmt.Println("AutoCachingEggPointStatistics_StatisticsFailed_ERR:::::", err.Error()) | |||
} | |||
//统计用户"发红包次数"范围 | |||
tempWeek.StatisticsUserEggSendRedPackageNumsRange, err = egg_energy.StatisticsUserEggSendRedPackageNumsRange(esIndexName) | |||
if err != nil { | |||
fmt.Println("AutoCachingEggPointStatistics_StatisticsFailed_ERR:::::", err.Error()) | |||
} | |||
//统计用户"蛋蛋能量兑换余额数量"范围 | |||
tempWeek.StatisticsUserEggEggEnergyExchangeAccountBalanceRange, err = egg_energy.StatisticsUserEggEggEnergyExchangeAccountBalanceRange(esIndexName) | |||
if err != nil { | |||
fmt.Println("AutoCachingEggPointStatistics_StatisticsFailed_ERR:::::", err.Error()) | |||
} | |||
//统计用户"蛋蛋能量兑换余额数量"范围 | |||
tempWeek.StatisticsUserEggAccountBalanceExchangeEggEnergyNumsRange, err = egg_energy.StatisticsUserEggAccountBalanceExchangeEggEnergyNumsRange(esIndexName) | |||
if err != nil { | |||
fmt.Println("AutoCachingEggPointStatistics_StatisticsFailed_ERR:::::", err.Error()) | |||
} | |||
//统计用户"发朋友圈次数"范围 | |||
tempWeek.StatisticsUserEggSendCircleOfFriendNumsRange, err = egg_energy.StatisticsUserEggSendCircleOfFriendNumsRange(esIndexName) | |||
if err != nil { | |||
fmt.Println("AutoCachingEggPointStatistics_StatisticsFailed_ERR:::::", err.Error()) | |||
} | |||
//统计用户"论坛评论次数"范围 | |||
tempWeek.StatisticsUserEggForumCommentsNumsRange, err = egg_energy.StatisticsUserEggForumCommentsNumsRange(esIndexName) | |||
if err != nil { | |||
fmt.Println("AutoCachingEggPointStatistics_StatisticsFailed_ERR:::::", err.Error()) | |||
} | |||
//统计用户"学院学习次数"范围 | |||
tempWeek.StatisticsUserEggCollegeLearningNumsRange, err = egg_energy.StatisticsUserEggCollegeLearningNumsRange(esIndexName) | |||
if err != nil { | |||
fmt.Println("AutoCachingEggPointStatistics_StatisticsFailed_ERR:::::", err.Error()) | |||
} | |||
//统计用户"违规次数"范围 | |||
tempWeek.StatisticsUserEggViolateNumsRange, err = egg_energy.StatisticsUserEggViolateNumsRange(esIndexName) | |||
if err != nil { | |||
fmt.Println("AutoCachingEggPointStatistics_StatisticsFailed_ERR:::::", err.Error()) | |||
} | |||
//统计用户"浏览界面次数"范围 | |||
tempWeek.StatisticsUserEggBrowseInterfaceNumsRange, err = egg_energy.StatisticsUserEggBrowseInterfaceNumsRange(esIndexName) | |||
if err != nil { | |||
fmt.Println("AutoCachingEggPointStatistics_StatisticsFailed_ERR:::::", err.Error()) | |||
} | |||
//统计用户"个人活跃积分增量值"范围 | |||
tempWeek.StatisticsUserEggPersonAddActivityValueRange, err = egg_energy.StatisticsUserEggPersonAddActivityValueRange(esIndexName) | |||
if err != nil { | |||
fmt.Println("AutoCachingEggPointStatistics_StatisticsFailed_ERR:::::", err.Error()) | |||
} | |||
parts := strings.Split(esIndexName, "_") | |||
yearAndWeekStr := parts[len(parts)-1] | |||
redisKey := fmt.Sprintf(md2.AutoCachingEggPointRedisKey, yearAndWeekStr) | |||
cache.SetJson(redisKey, tempWeek, -1) | |||
} | |||
fmt.Println("----------------------------AutoCachingEggPointStatistics_end-------------------------------") | |||
} |
@@ -46,7 +46,7 @@ func EggEnergyAutoUpdateUserAccess(engine *xorm.Engine) { | |||
updateInfoMap := make([]interface{}, 0, len(list)) | |||
for _, node := range list { | |||
uid := node.Uid | |||
id := fmt.Sprintf("%d%d-%d", year, week, 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, | |||
@@ -16,10 +16,10 @@ import ( | |||
"xorm.io/xorm" | |||
) | |||
const LockKey = "egg_energy_auto_automatic_scoring_lock_key" | |||
const EggEnergyAutomaticScoringLockKey = "egg_energy_auto_automatic_scoring_lock_key" | |||
func EggEnergyAutomaticScoring(engine *xorm.Engine) { | |||
fmt.Println("svc_egg_energy_auto_update_user_access...") | |||
fmt.Println("svc_egg_energy_auto_score...") | |||
defer func() { | |||
if err := recover(); err != nil { | |||
fmt.Println(err) | |||
@@ -29,12 +29,12 @@ func EggEnergyAutomaticScoring(engine *xorm.Engine) { | |||
fmt.Println("----------------------------EggEnergyAutomaticScoring_begin-------------------------------") | |||
// 增加“悲观锁”防止串行 | |||
getString, _ := cache.GetString(LockKey) | |||
getString, _ := cache.GetString(EggEnergyAutomaticScoringLockKey) | |||
if getString != "" { | |||
fmt.Println("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!", "上一次蛋蛋分自动打分未执行完") | |||
return | |||
} | |||
cache.SetEx(LockKey, "running", 3600*6) // 6小时 | |||
cache.SetEx(EggEnergyAutomaticScoringLockKey, "running", 3600*6) // 6小时 | |||
now := time.Now() | |||
fmt.Println(now.Hour()) | |||
@@ -0,0 +1,22 @@ | |||
package task | |||
import ( | |||
"applet/app/task/svc" | |||
"math/rand" | |||
"time" | |||
"xorm.io/xorm" | |||
) | |||
func taskAutoCachingEggPointStatistics(eg *xorm.Engine) { | |||
for { | |||
if len(ch) > workerNum { | |||
time.Sleep(time.Millisecond * time.Duration(rand.Intn(1000))) | |||
} else { | |||
goto START | |||
} | |||
} | |||
START: | |||
ch <- 1 | |||
svc.AutoCachingEggPointStatistics(eg) | |||
<-ch | |||
} |