|
|
@@ -0,0 +1,66 @@ |
|
|
|
package egg_energy |
|
|
|
|
|
|
|
import ( |
|
|
|
"code.fnuoos.com/EggPlanet/egg_system_rules.git/md" |
|
|
|
"code.fnuoos.com/go_rely_warehouse/zyos_go_es.git/es" |
|
|
|
"context" |
|
|
|
"fmt" |
|
|
|
"github.com/olivere/elastic/v7" |
|
|
|
"time" |
|
|
|
) |
|
|
|
|
|
|
|
// ExistOrDefaultUserEggScore 判断存在或创建默认用户蛋蛋分记录 |
|
|
|
func ExistOrDefaultUserEggScore(uid int64) error { |
|
|
|
|
|
|
|
// 1.查询用户是否有最新记录 |
|
|
|
nowIndex, err := es.GetLatestIndexFromAlias(md.EggEnergyUserEggScoreEsAlias) |
|
|
|
if err != nil { |
|
|
|
return err |
|
|
|
} |
|
|
|
boolQuery := elastic.NewBoolQuery() |
|
|
|
boolQuery.Filter(elastic.NewTermQuery("uid", uid)) |
|
|
|
searchResult, err := es.EsClient.Search(). |
|
|
|
Index(nowIndex). |
|
|
|
Query(boolQuery). |
|
|
|
Size(0). |
|
|
|
Do(context.Background()) |
|
|
|
if err != nil { |
|
|
|
return err |
|
|
|
} |
|
|
|
total := searchResult.TotalHits() |
|
|
|
if int(total) > 0 { |
|
|
|
return nil |
|
|
|
} |
|
|
|
|
|
|
|
// 2. 如果没有 新增蛋蛋分记录 |
|
|
|
now := time.Now() |
|
|
|
m := md.EggEnergyUserEggScoreEs{ |
|
|
|
Uid: uid, |
|
|
|
ScoreValue: 0, |
|
|
|
ScoreValueKind: 0, |
|
|
|
Ecpm: 0, |
|
|
|
InviteUserNums: 0, |
|
|
|
TeamActivityNums: 0, |
|
|
|
SignInNums: 0, |
|
|
|
ImActivityNums: 0, |
|
|
|
SendRedPackageNums: 0, |
|
|
|
EggEnergyExchangeAccountBalance: 0, |
|
|
|
AccountBalanceExchangeEggEnergyNums: 0, |
|
|
|
SendCircleOfFriendNums: 0, |
|
|
|
ForumCommentsNums: 0, |
|
|
|
CollegeLearningNums: 0, |
|
|
|
ViolateNums: 0, |
|
|
|
BrowseInterfaceNums: 0, |
|
|
|
PersonAddActivityValue: 0, |
|
|
|
CreatedAt: now.Format("2006-01-02 15:04:05"), |
|
|
|
UpdatedAt: now.Format("2006-01-02 15:04:05"), |
|
|
|
} |
|
|
|
year, week := now.ISOWeek() |
|
|
|
eggScoreId := fmt.Sprintf("%d%d_%d", year, week, uid) |
|
|
|
createDocRet, err := es.CreateDoc(nowIndex, eggScoreId, m) |
|
|
|
if err != nil { |
|
|
|
return err |
|
|
|
} |
|
|
|
fmt.Printf("CreateDoc ==> %+v \n\n", createDocRet) |
|
|
|
return nil |
|
|
|
} |