From e8523c1e3e44930d7bd89b031dd7eaa18ff292af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E5=AF=BB=E6=AC=A2?= Date: Mon, 29 Apr 2024 10:12:50 +0800 Subject: [PATCH] =?UTF-8?q?:art:=20=E4=BC=98=E5=8C=96=E6=B6=88=E6=81=AF?= =?UTF-8?q?=E6=80=BB=E7=BB=93=E6=9F=A5=E8=AF=A2SQL=EF=BC=8C=E6=94=AF?= =?UTF-8?q?=E6=8C=81=E6=9B=B4=E5=A4=9A=E6=B6=88=E6=81=AF=E7=B1=BB=E5=9E=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- service/message.go | 23 +++++++++++++++++++++-- tasks/summary/summary.go | 3 ++- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/service/message.go b/service/message.go index 343fd0e3..866cfd50 100644 --- a/service/message.go +++ b/service/message.go @@ -47,12 +47,31 @@ func SaveMessage(msg entity.Message) { // @return records // @return err func GetTextMessagesById(id string) (records []vo.TextMessageItem, err error) { + // APP消息类型 + appMsgList := []string{"57", "4", "5", "6"} + // 这个查询子句抽出来写,方便后续扩展 + selectStr := `CASE + WHEN tm.type = 49 THEN + CASE + WHEN EXTRACTVALUE ( tm.content, "/msg/appmsg/type" ) = '57' THEN + EXTRACTVALUE ( tm.content, "/msg/appmsg/title" ) + WHEN EXTRACTVALUE ( tm.content, "/msg/appmsg/type" ) = '5' THEN + CONCAT("网页分享消息,标题: ", EXTRACTVALUE (tm.content, "/msg/appmsg/title"), ",描述:", EXTRACTVALUE (tm.content, "/msg/appmsg/des")) + WHEN EXTRACTVALUE ( tm.content, "/msg/appmsg/type" ) = '4' THEN + CONCAT("网页分享消息,标题: ", EXTRACTVALUE (tm.content, "/msg/appmsg/title"), ",描述:", EXTRACTVALUE (tm.content, "/msg/appmsg/des")) + WHEN EXTRACTVALUE ( tm.content, "/msg/appmsg/type" ) = '6' THEN + CONCAT("文件消息,文件名: ", EXTRACTVALUE (tm.content, "/msg/appmsg/title")) + + ELSE EXTRACTVALUE ( tm.content, "/msg/appmsg/des" ) + END ELSE tm.content + END` + tx := client.MySQL. Table("`t_message` AS tm"). Joins("LEFT JOIN t_group_user AS tgu ON tm.group_user = tgu.wxid AND tgu.group_id = tm.from_user"). - Select("tgu.nickname", "IF( tm.type = 49, EXTRACTVALUE ( tm.content, \"/msg/appmsg/title\" ), tm.content ) AS message"). + Select("tgu.nickname", selectStr+" AS message"). Where("tm.`from_user` = ?", id). - Where(`(tm.type = 1 OR ( tm.type = 49 AND EXTRACTVALUE ( tm.content, "/msg/appmsg/type" ) = '57' ))`). + Where(`(tm.type = 1 OR ( tm.type = 49 AND EXTRACTVALUE ( tm.content, "/msg/appmsg/type" ) IN (?) ))`, appMsgList). Where("DATE ( tm.create_at ) = DATE ( CURDATE() - INTERVAL 1 DAY )"). Order("tm.create_at ASC") diff --git a/tasks/summary/summary.go b/tasks/summary/summary.go index 0ec5052b..359cca2d 100644 --- a/tasks/summary/summary.go +++ b/tasks/summary/summary.go @@ -42,7 +42,7 @@ func AiSummary() { 注意,他们可能是多个话题,请仔细甄别。 每一行代表一个人的发言,每一行的的格式为: {"{nickname}": "{content}"}--end-- -聊天记录如下: +聊天记录如下: %s ` @@ -81,6 +81,7 @@ func AiSummary() { continue } replyMsg := fmt.Sprintf("#昨日消息总结\n又是一天过去了,让我们一起来看看昨儿群友们都聊了什么有趣的话题吧~\n\n%s", resp.Choices[0].Message.Content) + //log.Printf("群[%s]对话记录总结成功,总结内容: %s", group.Wxid, replyMsg) utils.SendMessage(group.Wxid, "", replyMsg, 0) } }