🎨 优化消息总结查询SQL,支持更多消息类型 #43
@ -47,12 +47,31 @@ func SaveMessage(msg entity.Message) {
|
|||||||
// @return records
|
// @return records
|
||||||
// @return err
|
// @return err
|
||||||
func GetTextMessagesById(id string) (records []vo.TextMessageItem, err error) {
|
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.
|
tx := client.MySQL.
|
||||||
Table("`t_message` AS tm").
|
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").
|
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.`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 )").
|
Where("DATE ( tm.create_at ) = DATE ( CURDATE() - INTERVAL 1 DAY )").
|
||||||
Order("tm.create_at ASC")
|
Order("tm.create_at ASC")
|
||||||
|
|
||||||
|
@ -81,6 +81,7 @@ func AiSummary() {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
replyMsg := fmt.Sprintf("#昨日消息总结\n又是一天过去了,让我们一起来看看昨儿群友们都聊了什么有趣的话题吧~\n\n%s", resp.Choices[0].Message.Content)
|
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)
|
utils.SendMessage(group.Wxid, "", replyMsg, 0)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user