...
|
...
|
@@ -2,10 +2,12 @@ package message |
|
|
|
|
|
import (
|
|
|
"context"
|
|
|
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/domain"
|
|
|
|
|
|
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc"
|
|
|
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types"
|
|
|
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/db/transaction"
|
|
|
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/domain"
|
|
|
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/contextdata"
|
|
|
|
|
|
"github.com/zeromicro/go-zero/core/logx"
|
|
|
)
|
...
|
...
|
@@ -25,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 {
|
...
|
...
|
@@ -94,11 +98,10 @@ 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().
|
|
|
WithFindOnly().
|
|
|
WithKV("ids", userIds).
|
|
|
WithKV("limit", len(userIds)))
|
|
|
_, companyList, err := l.svcCtx.CompanyRepository.Find(l.ctx, conn, domain.NewQueryOptions().
|
|
|
WithFindOnly().
|
|
|
WithKV("ids", userIds).
|
|
|
WithKV("limit", len(userIds)))
|
|
|
if err != nil {
|
|
|
return nil, err
|
|
|
}
|
...
|
...
|
@@ -109,11 +112,10 @@ 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().
|
|
|
WithFindOnly().
|
|
|
WithKV("ids", userIds).
|
|
|
WithKV("limit", len(userIds)))
|
|
|
_, userList, err := l.svcCtx.UserRepository.Find(l.ctx, conn, domain.NewQueryOptions().
|
|
|
WithFindOnly().
|
|
|
WithKV("ids", userIds).
|
|
|
WithKV("limit", len(userIds)))
|
|
|
if err != nil {
|
|
|
return nil, err
|
|
|
}
|
...
|
...
|
@@ -124,11 +126,10 @@ 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().
|
|
|
WithFindOnly().
|
|
|
WithKV("ids", commentIds).
|
|
|
WithKV("limit", len(commentIds)))
|
|
|
_, commentList, err := l.svcCtx.CommentRepository.Find(l.ctx, conn, domain.NewQueryOptions().
|
|
|
WithFindOnly().
|
|
|
WithKV("ids", commentIds).
|
|
|
WithKV("limit", len(commentIds)))
|
|
|
if err != nil {
|
|
|
return nil, err
|
|
|
}
|
...
|
...
|
@@ -137,38 +138,34 @@ func (l *MiniBusinessLogic) MiniBusiness(req *types.MessageBusinessRequest) (res |
|
|
}
|
|
|
}
|
|
|
|
|
|
// 只有这个才需要
|
|
|
if msgType == int(domain.MsgTypeReply) || msgType == int(domain.MsgTypeLike) {
|
|
|
// 获取文章数据
|
|
|
if len(articleIds) > 0 {
|
|
|
_, articleList, err := l.svcCtx.ArticleRepository.Find(l.ctx, l.svcCtx.DefaultDBConn(),
|
|
|
domain.NewQueryOptions().
|
|
|
WithFindOnly().
|
|
|
WithKV("ids", articleIds).
|
|
|
WithKV("limit", len(articleIds)))
|
|
|
if err != nil {
|
|
|
return nil, err
|
|
|
}
|
|
|
for i := range articleList {
|
|
|
articleIdMap[articleList[i].Id] = articleList[i]
|
|
|
}
|
|
|
// 获取文章数据
|
|
|
if len(articleIds) > 0 {
|
|
|
_, articleList, err := l.svcCtx.ArticleRepository.Find(l.ctx, conn, userToken.CompanyId, domain.NewQueryOptions().
|
|
|
WithFindOnly().
|
|
|
WithKV("ids", articleIds).
|
|
|
WithKV("limit", len(articleIds)))
|
|
|
if err != nil {
|
|
|
return nil, err
|
|
|
}
|
|
|
for i := range articleList {
|
|
|
articleIdMap[articleList[i].Id] = articleList[i]
|
|
|
}
|
|
|
}
|
|
|
|
|
|
for _, item := range list {
|
|
|
to := types.MessageBusinessItem{
|
|
|
Id: item.Id,
|
|
|
Type: item.Type,
|
|
|
OptType: item.OptType,
|
|
|
CompanyId: item.CompanyId,
|
|
|
UserId: item.UserId,
|
|
|
RecipientId: item.RecipientId,
|
|
|
ArticleId: item.ArticleId,
|
|
|
CommentId: item.CommentId,
|
|
|
DiscussionId: item.DiscussionId,
|
|
|
DiscussionOpinionId: item.DiscussionOpinionId,
|
|
|
Content: item.Content,
|
|
|
CreatedAt: item.CreatedAt,
|
|
|
Id: item.Id,
|
|
|
Type: int(item.Type),
|
|
|
OptType: int(item.OptType),
|
|
|
CompanyId: item.CompanyId,
|
|
|
UserId: item.UserId,
|
|
|
RecipientId: item.RecipientId,
|
|
|
ArticleId: item.ArticleId,
|
|
|
CommentId: item.CommentId,
|
|
|
//DiscussionId: item.DiscussionId,
|
|
|
//DiscussionOpinionId: item.DiscussionOpinionId,
|
|
|
Content: item.Content,
|
|
|
CreatedAt: item.CreatedAt,
|
|
|
}
|
|
|
|
|
|
if v, ok := userIdMap[item.UserId]; ok {
|
...
|
...
|
@@ -177,6 +174,7 @@ func (l *MiniBusinessLogic) MiniBusiness(req *types.MessageBusinessRequest) (res |
|
|
CompanyId: v.CompanyId,
|
|
|
Position: v.Position,
|
|
|
Name: v.Name,
|
|
|
Avatar: v.Avatar,
|
|
|
}
|
|
|
|
|
|
if v, ok := companyIdMap[item.CompanyId]; ok {
|
...
|
...
|
@@ -206,3 +204,53 @@ func (l *MiniBusinessLogic) MiniBusiness(req *types.MessageBusinessRequest) (res |
|
|
}
|
|
|
return resp, nil
|
|
|
}
|
|
|
|
|
|
// CommentArticle 评论文章
|
|
|
func (l *MiniBusinessLogic) CommentArticle(conn transaction.Conn, articleId int64, content string, at []int64) (err error) {
|
|
|
return l.submit(conn, domain.MsgTypeReply, domain.OptTypeArticle, articleId, 0, content, at)
|
|
|
}
|
|
|
|
|
|
// CommentReply 评论回复
|
|
|
func (l *MiniBusinessLogic) CommentReply(conn transaction.Conn, articleId int64, commentId int64, content string, at []int64) (err error) {
|
|
|
return l.submit(conn, domain.MsgTypeReply, domain.OptTypeComment, articleId, commentId, content, at)
|
|
|
}
|
|
|
|
|
|
// LikeArticle 点赞文章
|
|
|
func (l *MiniBusinessLogic) LikeArticle(conn transaction.Conn, articleId int64, at int64) (err error) {
|
|
|
return l.submit(conn, domain.MsgTypeLike, domain.OptTypeArticle, articleId, 0, "", []int64{at})
|
|
|
}
|
|
|
|
|
|
// LikeComment 点赞评论
|
|
|
func (l *MiniBusinessLogic) LikeComment(conn transaction.Conn, articleId int64, commentId int64, at int64) (err error) {
|
|
|
return l.submit(conn, domain.MsgTypeLike, domain.OptTypeComment, articleId, commentId, "", []int64{at})
|
|
|
}
|
|
|
|
|
|
func (l *MiniBusinessLogic) submit(
|
|
|
conn transaction.Conn,
|
|
|
msgType domain.MsgBusinessType,
|
|
|
optType domain.MsgBusinessOpt,
|
|
|
articleId int64,
|
|
|
commentId int64,
|
|
|
content string,
|
|
|
at []int64) (err error) {
|
|
|
|
|
|
var userToken = contextdata.GetUserTokenFromCtx(l.ctx)
|
|
|
// 评论中携带了 @其他用户
|
|
|
for i := range at {
|
|
|
var msg = &domain.MessageBusiness{
|
|
|
Type: msgType,
|
|
|
OptType: optType,
|
|
|
CompanyId: userToken.CompanyId,
|
|
|
UserId: userToken.UserId,
|
|
|
RecipientId: at[i],
|
|
|
ArticleId: articleId,
|
|
|
CommentId: commentId,
|
|
|
Content: content,
|
|
|
}
|
|
|
msg, err = l.svcCtx.MessageBusinessRepository.Insert(l.ctx, conn, msg)
|
|
|
if err != nil {
|
|
|
return err
|
|
|
}
|
|
|
}
|
|
|
return nil
|
|
|
} |
...
|
...
|
|