瀏覽代碼

群发消息修改

renjiaojiao 1 年之前
父節點
當前提交
70eafe4c1d
共有 1 個文件被更改,包括 18 次插入4 次删除
  1. 18 4
      rpc/internal/common/newSendMsgService.go

+ 18 - 4
rpc/internal/common/newSendMsgService.go

@@ -118,16 +118,21 @@ func UpdateUserMsgSummary(in *message.MultipleSaveMsgReq) error {
 	wg := &sync.WaitGroup{}
 	group_id := MsgGroupIdMap[int(in.MsgType)]
 	str := ""
+	i := 0
 	for k, v := range userIdArr {
+		i++
 		if k != 0 {
 			str += ","
 		}
 		str += "'" + v + "'"
+		if i == 1000 {
+			go Update(str, in.MsgLogId)
+			str = ""
+			i = 0
+		}
 	}
-	fmt.Println(fmt.Sprintf(`alter table message_user_summary UPDATE allMsg = bitmapOr(allMsg,bitmapBuild([toUInt64(%d)])) where userId in (%s)`, in.MsgLogId, str))
-	err1 := entity.ClickhouseConn.Exec(context.Background(), fmt.Sprintf(`alter table message_user_summary UPDATE allMsg = bitmapOr(allMsg,bitmapBuild([toUInt64(%d)])) where userId in (%s)`, in.MsgLogId, str))
-	if err1 != nil {
-		return err1
+	if i > 0 {
+		go Update(str, in.MsgLogId)
 	}
 	//p459 特殊处理 传过来的消息内容格式为 消息内容#jy#微信模板项目名称#jy#服务地址
 	equityName, equityAddr := "", ""
@@ -182,6 +187,15 @@ func UpdateUserMsgSummary(in *message.MultipleSaveMsgReq) error {
 	return nil
 }
 
+func Update(str string, msgLogId int64) {
+	fmt.Println(fmt.Sprintf(`alter table message_user_summary UPDATE allMsg = bitmapOr(allMsg,bitmapBuild([toUInt64(%d)])) where userId in (%s)`, msgLogId, str))
+	err1 := entity.ClickhouseConn.Exec(context.Background(), fmt.Sprintf(`alter table message_user_summary UPDATE allMsg = bitmapOr(allMsg,bitmapBuild([toUInt64(%d)])) where userId in (%s)`, msgLogId, str))
+	if err1 != nil {
+		log.Printf("批量更新message_user_summary出错:%s", err1)
+		return
+	}
+}
+
 //附件下载、剑鱼币活动到期提醒存消息发送记录
 func InsertMsgSendLog(in *message.MultipleSaveMsgReq) int64 {
 	groupId := MsgGroupIdMap[int(in.MsgType)]