|
@@ -18,6 +18,7 @@ var GlobMsgMap map[int]map[string]interface{}
|
|
|
|
|
|
func LoadTask() {
|
|
func LoadTask() {
|
|
// 每隔10分钟执行一次
|
|
// 每隔10分钟执行一次
|
|
|
|
+ StatisticalUser(true)
|
|
c := cron.New(cron.WithSeconds())
|
|
c := cron.New(cron.WithSeconds())
|
|
c.AddFunc(config.ConfigJson.GlobMsgLoadTime, LoadMsgOnTime)
|
|
c.AddFunc(config.ConfigJson.GlobMsgLoadTime, LoadMsgOnTime)
|
|
c.AddFunc(config.ConfigJson.FreeIntelTime, FreeIntelUserPush) //免费用户推送
|
|
c.AddFunc(config.ConfigJson.FreeIntelTime, FreeIntelUserPush) //免费用户推送
|
|
@@ -41,12 +42,12 @@ func LoadMsgOnTime() {
|
|
}
|
|
}
|
|
|
|
|
|
func FreeIntelUserPush() {
|
|
func FreeIntelUserPush() {
|
|
- id := FreeMessageData(config.ConfigJson.FreePushNumber)
|
|
|
|
- if id == 0 {
|
|
|
|
|
|
+ ids := FreeMessageData(config.ConfigJson.FreePushNumber)
|
|
|
|
+ if len(ids) == 0 {
|
|
return
|
|
return
|
|
}
|
|
}
|
|
users := StatisticalUser(true)
|
|
users := StatisticalUser(true)
|
|
- PushData(users, id, nil)
|
|
|
|
|
|
+ PushData(users, ids, nil)
|
|
}
|
|
}
|
|
|
|
|
|
func PayIntelUserPush() {
|
|
func PayIntelUserPush() {
|
|
@@ -55,14 +56,13 @@ func PayIntelUserPush() {
|
|
return
|
|
return
|
|
}
|
|
}
|
|
users := StatisticalUser(false)
|
|
users := StatisticalUser(false)
|
|
- PushData(users, 0, data)
|
|
|
|
|
|
+ PushData(users, nil, data)
|
|
}
|
|
}
|
|
|
|
|
|
-func PushData(users []string, id int64, data *[]map[string]interface{}) {
|
|
|
|
|
|
+func PushData(users []string, ids []int64, data *[]map[string]interface{}) {
|
|
log.Printf("需推送用户:%d\n", len(users))
|
|
log.Printf("需推送用户:%d\n", len(users))
|
|
- switch id {
|
|
|
|
|
|
+ switch len(ids) {
|
|
case 0: //付费用户
|
|
case 0: //付费用户
|
|
- var ids []int64
|
|
|
|
if data != nil {
|
|
if data != nil {
|
|
for _, m := range *data {
|
|
for _, m := range *data {
|
|
_id := common.InterfaceToStr(m["_id"])
|
|
_id := common.InterfaceToStr(m["_id"])
|
|
@@ -113,8 +113,12 @@ func PushData(users []string, id int64, data *[]map[string]interface{}) {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
default: //免费用户
|
|
default: //免费用户
|
|
- log.Println(fmt.Sprintf(`alter table message_user_summary UPDATE allMsg = bitmapOr(allMsg,bitmapBuild([toUInt64(%d)])) where 1=1`, id))
|
|
|
|
- err1 := entity.ClickhouseConn.Exec(context.Background(), fmt.Sprintf(`alter table message_user_summary UPDATE allMsg = bitmapOr(allMsg,bitmapBuild([toUInt64(%d)])) where 1=1`, id))
|
|
|
|
|
|
+ var bits []string
|
|
|
|
+ for _, i2 := range ids {
|
|
|
|
+ bits = append(bits, fmt.Sprintf("toUInt64(%d)", i2))
|
|
|
|
+ }
|
|
|
|
+ log.Println(fmt.Sprintf(`alter table message_user_summary UPDATE allMsg = bitmapOr(allMsg,bitmapBuild([%s])) where 1=1`, strings.Join(bits, ",")))
|
|
|
|
+ err1 := entity.ClickhouseConn.Exec(context.Background(), fmt.Sprintf(`alter table message_user_summary UPDATE allMsg = bitmapOr(allMsg,bitmapBuild([%s])) where 1=1`, strings.Join(bits, ",")))
|
|
if err1 != nil {
|
|
if err1 != nil {
|
|
log.Printf("批量更新message_user_summary出错:%s", err1)
|
|
log.Printf("批量更新message_user_summary出错:%s", err1)
|
|
return
|
|
return
|
|
@@ -263,14 +267,17 @@ func messageData(number int) *[]map[string]interface{} {
|
|
return data
|
|
return data
|
|
}
|
|
}
|
|
|
|
|
|
-func FreeMessageData(number int) int64 {
|
|
|
|
|
|
+func FreeMessageData(number int) []int64 {
|
|
|
|
+ var ids []int64
|
|
now := time.Now()
|
|
now := time.Now()
|
|
startTime := time.Date(now.Year(), now.Month(), now.Day(), 0, 0, 0, 0, time.Local).String()
|
|
startTime := time.Date(now.Year(), now.Month(), now.Day(), 0, 0, 0, 0, time.Local).String()
|
|
m := entity.Mysql.SelectBySql(fmt.Sprintf(`SELECT id FROM message_send_log WHERE createtime > '%s' and send_userid = '商机情报定时推送' ORDER BY createtime DESC LIMIT %d `, startTime, number))
|
|
m := entity.Mysql.SelectBySql(fmt.Sprintf(`SELECT id FROM message_send_log WHERE createtime > '%s' and send_userid = '商机情报定时推送' ORDER BY createtime DESC LIMIT %d `, startTime, number))
|
|
if m != nil && len(*m) > 0 {
|
|
if m != nil && len(*m) > 0 {
|
|
- return common.Int64All((*m)[0]["id"])
|
|
|
|
|
|
+ for _, i2 := range *m {
|
|
|
|
+ ids = append(ids, common.Int64All(i2["id"]))
|
|
|
|
+ }
|
|
}
|
|
}
|
|
- return 0
|
|
|
|
|
|
+ return ids
|
|
}
|
|
}
|
|
|
|
|
|
func UpdateBatch(ids []string, bitStr string) {
|
|
func UpdateBatch(ids []string, bitStr string) {
|