作者 郑周

1. 消息列表 优化

... ... @@ -27,9 +27,11 @@ func NewMiniBusinessLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Mini
}
func (l *MiniBusinessLogic) MiniBusiness(req *types.MessageBusinessRequest) (resp *types.MessageBusinessResponse, err error) {
var userToken = contextdata.GetUserTokenFromCtx(l.ctx)
var conn = l.svcCtx.DefaultDBConn()
var msgType = req.Type
total, list, err := l.svcCtx.MessageBusinessRepository.Find(l.ctx, l.svcCtx.DefaultDBConn(), domain.NewQueryOptions().
total, list, err := l.svcCtx.MessageBusinessRepository.Find(l.ctx, conn, domain.NewQueryOptions().
WithOffsetLimit(req.Page, req.Size).
WithKV("type", msgType))
if err != nil {
... ... @@ -96,8 +98,7 @@ func (l *MiniBusinessLogic) MiniBusiness(req *types.MessageBusinessRequest) (res
// 获取公司
if len(companyIds) > 0 {
_, companyList, err := l.svcCtx.CompanyRepository.Find(l.ctx, l.svcCtx.DefaultDBConn(),
domain.NewQueryOptions().
_, companyList, err := l.svcCtx.CompanyRepository.Find(l.ctx, conn, domain.NewQueryOptions().
WithFindOnly().
WithKV("ids", userIds).
WithKV("limit", len(userIds)))
... ... @@ -111,8 +112,7 @@ func (l *MiniBusinessLogic) MiniBusiness(req *types.MessageBusinessRequest) (res
// 获取用户
if len(userIds) > 0 {
_, userList, err := l.svcCtx.UserRepository.Find(l.ctx, l.svcCtx.DefaultDBConn(),
domain.NewQueryOptions().
_, userList, err := l.svcCtx.UserRepository.Find(l.ctx, conn, domain.NewQueryOptions().
WithFindOnly().
WithKV("ids", userIds).
WithKV("limit", len(userIds)))
... ... @@ -126,8 +126,7 @@ func (l *MiniBusinessLogic) MiniBusiness(req *types.MessageBusinessRequest) (res
// 获取评论
if len(commentIds) > 0 {
_, commentList, err := l.svcCtx.CommentRepository.Find(l.ctx, l.svcCtx.DefaultDBConn(),
domain.NewQueryOptions().
_, commentList, err := l.svcCtx.CommentRepository.Find(l.ctx, conn, domain.NewQueryOptions().
WithFindOnly().
WithKV("ids", commentIds).
WithKV("limit", len(commentIds)))
... ... @@ -141,8 +140,7 @@ func (l *MiniBusinessLogic) MiniBusiness(req *types.MessageBusinessRequest) (res
// 获取文章数据
if len(articleIds) > 0 {
_, articleList, err := l.svcCtx.ArticleRepository.Find(l.ctx, l.svcCtx.DefaultDBConn(), 0,
domain.NewQueryOptions().
_, articleList, err := l.svcCtx.ArticleRepository.Find(l.ctx, conn, userToken.CompanyId, domain.NewQueryOptions().
WithFindOnly().
WithKV("ids", articleIds).
WithKV("limit", len(articleIds)))
... ... @@ -164,8 +162,8 @@ func (l *MiniBusinessLogic) MiniBusiness(req *types.MessageBusinessRequest) (res
RecipientId: item.RecipientId,
ArticleId: item.ArticleId,
CommentId: item.CommentId,
DiscussionId: item.DiscussionId,
DiscussionOpinionId: item.DiscussionOpinionId,
//DiscussionId: item.DiscussionId,
//DiscussionOpinionId: item.DiscussionOpinionId,
Content: item.Content,
CreatedAt: item.CreatedAt,
}
... ...
... ... @@ -16,16 +16,16 @@ type MessageBusiness struct {
CompanyId int64 `json:"companyId"` // 操作人公司ID
UserId int64 `json:"userId"` // 操作人用户ID
RecipientId int64 `json:"recipientId"` // 接收人用户ID
ArticleId int64 `json:"articleId"` // 文章ID
ArticleId int64 `json:"articleId,omitempty"` // 文章ID
CommentId int64 `json:"commentId,omitempty"` // 评论ID
DiscussionId int64 `json:"discussionId,omitempty"` // 圆桌ID
DiscussionOpinionId int64 `json:"discussionOpinionId,omitempty"` // 观点ID
Content string `json:"content,omitempty"` // 消息内容
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"`
//DiscussionId int64 `json:"discussionId,omitempty"` // 圆桌ID
//DiscussionOpinionId int64 `json:"discussionOpinionId,omitempty"` // 观点ID
}
func (m *MessageBusiness) TableName() string {
... ...
... ... @@ -121,6 +121,9 @@ func (repository *MessageBusinessRepository) Find(ctx context.Context, conn tran
)
queryFunc := func() (interface{}, error) {
tx = tx.Model(&ms).Order("created_at desc")
if v, ok := queryOptions["companyId"]; ok {
tx.Where("company_id = ?", v)
}
if total, tx = transaction.PaginationAndCount(ctx, tx, queryOptions, &ms); tx.Error != nil {
return dms, tx.Error
}
... ...
... ... @@ -14,13 +14,14 @@ type MessageBusiness struct {
RecipientId int64 `json:"recipientId"` // 接收人用户ID
ArticleId int64 `json:"articleId"` // 文章ID
CommentId int64 `json:"commentId"` // 评论ID
DiscussionId int64 `json:"discussionId"` // 圆桌ID
DiscussionOpinionId int64 `json:"discussionOpinionId"` // 观点ID
Content string `json:"content"` // 消息内容
CreatedAt int64 `json:",omitempty"`
UpdatedAt int64 `json:",omitempty"`
DeletedAt int64 `json:",omitempty"`
Version int `json:",omitempty"`
//DiscussionId int64 `json:"discussionId"` // 圆桌ID
//DiscussionOpinionId int64 `json:"discussionOpinionId"` // 观点ID
}
type MsgBusinessType int
... ...