message_subscribe.go 2.8 KB
package domain

import (
	"context"
	"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/db/transaction"
	"gorm.io/plugin/soft_delete"
)

type MessageSubscribe struct {
	Id           int64                  `json:"id"`                                       // 唯一标识
	Type         int                    `json:"type"`                                     // 分类(1评论回复 2获赞 3关注人更新)
	CompanyId    int64                  `json:"companyId"`                                // 公司ID
	UserId       int64                  `json:"userId"`                                   // 用户ID
	OpenId       string                 `json:"openId"`                                   // 微信openID
	TemplateId   string                 `json:"templateId"`                               // 模板ID
	TemplateData map[string]interface{} `json:"templateData"`                             // 模板参数
	Result       string                 `json:"result"`                                   // 发送结果
	Error        string                 `json:"error"`                                    // 调用接口错误信息
	CreatedAt    int64                  `json:",omitempty"`                               // 创建时间
	UpdatedAt    int64                  `json:",omitempty"`                               // 更新时间
	DeletedAt    int64                  `json:",omitempty"`                               // 删除时间
	Version      int                    `json:",omitempty"`                               // 版本
	IsDel        soft_delete.DeletedAt  `gorm:"softDelete:flag,DeletedAtField:DeletedAt"` // 删除标记
}

var (
	SubscribeTypeReplyComment = 1 // 评论回复
	SubscribeTypeLike         = 2 // 点赞
	SubscribeTypeFollow       = 3 // 关注人更新

	SubscribeTemplateComment = "DxnQTZVHKrH7TOJiV-tK9w72hbkfLM87eXzhVy4cyhE" // 订阅消息 评论提醒
	SubscribeTemplateLike    = "oRdUINwfMK5_4ok_3lNgpkKT_SJqyGOvP4ZDgdsea9E" // 订阅消息 动态点赞通知
	SubscribeTemplateFollow  = "XdS11h2ZGGByzu-wMd16KxJ-LPjZy0yxZDmgQaVfDHE" // 订阅消息 关注更新提醒
)

type MessageSubscribeRepository interface {
	Insert(ctx context.Context, conn transaction.Conn, dm *MessageSubscribe) (*MessageSubscribe, error)
	Update(ctx context.Context, conn transaction.Conn, dm *MessageSubscribe) (*MessageSubscribe, error)
	UpdateWithVersion(ctx context.Context, conn transaction.Conn, dm *MessageSubscribe) (*MessageSubscribe, error)
	Delete(ctx context.Context, conn transaction.Conn, dm *MessageSubscribe) (*MessageSubscribe, error)
	FindOne(ctx context.Context, conn transaction.Conn, id int64) (*MessageSubscribe, error)
	Find(ctx context.Context, conn transaction.Conn, queryOptions map[string]interface{}) (int64, []*MessageSubscribe, error)
}

func (m *MessageSubscribe) Identify() interface{} {
	if m.Id == 0 {
		return nil
	}
	return m.Id
}