spark-server/internal/module/message/model/row.go
zhr 13b42cef7b chore: 合并本地改动与 main(t_ 表名、lint、音乐分类)
在 fast-forward 到 origin/main 后解决 music logic/repo 冲突,SQL 与模型统一 t_* 表名;Makefile 修正 golangci-lint 变量并令 test/deploy 依赖 lint;补齐 admin/transport 等 lint 修复与 music logic 单测以满足覆盖率门禁。

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-09-24 10:56:59 +08:00

72 lines
2.3 KiB
Go
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package model
import (
"time"
"spark-server/internal/module/message/entity"
)
const (
tablePrivateMessage = "t_private_message"
tableGroupMessage = "t_group_message"
)
// MessageRow is shared columns for private_message and group_message. Must be exported so GORM can embed it.
type MessageRow struct {
ID int64 `gorm:"column:id;primaryKey;autoIncrement:false;comment:Snowflake MsgId,主键、排序键、同步游标"`
ConversationID int64 `gorm:"column:conversation_id;comment:所属会话 id"`
SenderID int64 `gorm:"column:sender_id;comment:发送者 user_id"`
ClientMsgID string `gorm:"column:client_msg_id;comment:客户端消息 id,与 sender+会话 组成幂等键"`
MessageType int16 `gorm:"column:message_type;comment:消息类型:1文本 2图片 3语音 4视频 5表情 6GIF 7文件 8位置 9系统"`
Content []byte `gorm:"column:content;type:blob;comment:序列化后的消息体(JSON 字节),禁止存原始 string;媒体只存对象存储 key"`
Status int `gorm:"column:status;comment:1=正常 2=已撤回 3=审核隐藏"`
CreatedAt time.Time `gorm:"column:created_at;comment:服务端入库时间"`
}
func (r *MessageRow) entity(kind entity.Kind) *entity.Message {
if r == nil {
return nil
}
return &entity.Message{
ID: r.ID,
ConversationID: r.ConversationID,
SenderID: r.SenderID,
ClientMsgID: r.ClientMsgID,
Type: entity.Type(r.MessageType),
Kind: kind,
Content: r.Content,
Status: entity.Status(r.Status),
CreatedAtMS: r.CreatedAt.UnixMilli(),
}
}
func rowFrom(m *entity.Message) MessageRow {
if m == nil {
return MessageRow{}
}
return MessageRow{
ID: m.ID,
ConversationID: m.ConversationID,
SenderID: m.SenderID,
ClientMsgID: m.ClientMsgID,
MessageType: int16(m.Type),
Content: m.Content,
Status: int(m.Status),
}
}
func privateRow(m *entity.Message, base *MessageRow) PrivateMessage {
return PrivateMessage{MessageRow: *base, ReceiverID: m.ReceiverID}
}
func groupRow(m *entity.Message, base *MessageRow) GroupMessage {
return GroupMessage{MessageRow: *base, GroupID: m.GroupID}
}
func tableOf(kind entity.Kind) string {
if kind == entity.KindGroup {
return tableGroupMessage
}
return tablePrivateMessage
}