package com.xuqm.im.entity; import com.fasterxml.jackson.databind.annotation.JsonSerialize; import com.fasterxml.jackson.databind.annotation.JsonDeserialize; import com.xuqm.im.json.EpochMillisLocalDateTimeDeserializer; import com.xuqm.im.json.EpochMillisLocalDateTimeSerializer; import jakarta.persistence.Column; import jakarta.persistence.Entity; import jakarta.persistence.EnumType; import jakarta.persistence.Enumerated; import jakarta.persistence.Id; import jakarta.persistence.Index; import jakarta.persistence.Table; import jakarta.persistence.Transient; import java.time.LocalDateTime; @Entity @Table(name = "im_message", indexes = { @Index(name = "idx_app_from", columnList = "appId,fromUserId"), @Index(name = "idx_app_to", columnList = "appId,toId") }) public class ImMessageEntity { public enum ChatType { SINGLE, GROUP } public enum MsgType { TEXT, IMAGE, VIDEO, AUDIO, FILE, CUSTOM, LOCATION, NOTIFY, RICH_TEXT, CALL_AUDIO, CALL_VIDEO, FORWARD, QUOTE, MERGE, REVOKED } public enum MsgStatus { SENT, DELIVERED, READ, REVOKED } @Id private String id; @Column(nullable = false, length = 64) private String appId; @Column(nullable = false, length = 128) private String fromUserId; @Column(nullable = false, length = 128) private String toId; @Enumerated(EnumType.STRING) @Column(nullable = false, length = 16) private ChatType chatType; @Enumerated(EnumType.STRING) @Column(nullable = false, length = 16) private MsgType msgType; @Column(nullable = false, columnDefinition = "TEXT") private String content; @Enumerated(EnumType.STRING) @Column(nullable = false, length = 16) private MsgStatus status; @Column(length = 128) private String mentionedUserIds; @Transient private Integer groupReadCount; @Column @JsonSerialize(using = EpochMillisLocalDateTimeSerializer.class) @JsonDeserialize(using = EpochMillisLocalDateTimeDeserializer.class) private LocalDateTime editedAt; @Column(nullable = false) @JsonSerialize(using = EpochMillisLocalDateTimeSerializer.class) @JsonDeserialize(using = EpochMillisLocalDateTimeDeserializer.class) private LocalDateTime createdAt; public String getId() { return id; } public void setId(String id) { this.id = id; } public String getAppId() { return appId; } public void setAppId(String appId) { this.appId = appId; } public String getFromUserId() { return fromUserId; } public void setFromUserId(String fromUserId) { this.fromUserId = fromUserId; } public String getToId() { return toId; } public void setToId(String toId) { this.toId = toId; } public ChatType getChatType() { return chatType; } public void setChatType(ChatType chatType) { this.chatType = chatType; } public MsgType getMsgType() { return msgType; } public void setMsgType(MsgType msgType) { this.msgType = msgType; } public String getContent() { return content; } public void setContent(String content) { this.content = content; } public MsgStatus getStatus() { return status; } public void setStatus(MsgStatus status) { this.status = status; } public String getMentionedUserIds() { return mentionedUserIds; } public void setMentionedUserIds(String mentionedUserIds) { this.mentionedUserIds = mentionedUserIds; } public Integer getGroupReadCount() { return groupReadCount; } public void setGroupReadCount(Integer groupReadCount) { this.groupReadCount = groupReadCount; } @JsonSerialize(using = EpochMillisLocalDateTimeSerializer.class) @JsonDeserialize(using = EpochMillisLocalDateTimeDeserializer.class) public LocalDateTime getEditedAt() { return editedAt; } public void setEditedAt(LocalDateTime editedAt) { this.editedAt = editedAt; } @JsonSerialize(using = EpochMillisLocalDateTimeSerializer.class) @JsonDeserialize(using = EpochMillisLocalDateTimeDeserializer.class) public LocalDateTime getCreatedAt() { return createdAt; } public void setCreatedAt(LocalDateTime createdAt) { this.createdAt = createdAt; } }