作者 tangxvhui

Merge branch 'dev' into test

... ... @@ -544,6 +544,7 @@ type (
MiniSearchArticleItem{
ArticleId int64 `json:"articleId"`
Title string `json:"title"`
AuthorId int64 `json:"authorId"`
Author string `json:"author"` // 发布人
Avatar string `json:"avatar"`// 发布人的头像
Images []string `json:"images"`
... ...
... ... @@ -80,7 +80,7 @@ func (l *MiniGetArticleLogic) MiniGetArticle(req *types.MiniArticleGetRequest) (
}
//获取作者信息
author, _ := l.svcCtx.UserRepository.FindOne(l.ctx, conn, int64(req.UserId))
author, _ := l.svcCtx.UserRepository.FindOne(l.ctx, conn, int64(articleInfo.AuthorId))
var meLoveFlag int
if req.UserId > 0 {
... ...
... ... @@ -5,6 +5,7 @@ import (
"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/xerr"
... ... @@ -13,8 +14,9 @@ import (
type MiniSearchArticlePageLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
ctx context.Context
svcCtx *svc.ServiceContext
userCache map[int64]*domain.User
}
func NewMiniSearchArticlePageLogic(ctx context.Context, svcCtx *svc.ServiceContext) *MiniSearchArticlePageLogic {
... ... @@ -63,11 +65,13 @@ func (l *MiniSearchArticlePageLogic) MiniSearchArticlePage(req *types.MiniSearch
}
for i, val := range articleList {
author := l.getAuthor(conn, val.AuthorId)
item := types.MiniSearchArticleItem{
ArticleId: val.Id,
Title: val.Title,
Author: val.Author.Name,
Avatar: val.Author.Avatar,
AuthorId: val.AuthorId,
Author: author.Name,
Avatar: author.Avatar,
Images: []string{},
CreatedAt: val.CreatedAt,
MeReadFlag: 0,
... ... @@ -84,3 +88,15 @@ func (l *MiniSearchArticlePageLogic) MiniSearchArticlePage(req *types.MiniSearch
return resp, nil
}
func (l *MiniSearchArticlePageLogic) getAuthor(conn transaction.Conn, userid int64) domain.User {
if u, ok := l.userCache[userid]; ok {
return *u
}
toUser, err := l.svcCtx.UserRepository.FindOne(l.ctx, conn, userid)
if err == nil {
l.userCache[toUser.Id] = toUser
return *toUser
}
return domain.User{}
}
... ...
... ... @@ -90,6 +90,7 @@ func (l *SystemUpdateArticleLogic) SystemUpdateArticle(req *types.SystemArticleU
Height: h,
})
}
//检查文章可被哪些人查看
whoRead := []int64{}
if len(req.WhoRead) > 0 {
... ...
... ... @@ -44,6 +44,8 @@ func (l *MiniUserNewsLogic) MiniUserNews(req *types.MiniUserNewsRequest) (resp *
)
if req.AuthorId > 0 {
users = []int64{req.AuthorId}
} else {
users = append(users, user.Id)
}
if _, articles, err = l.svcCtx.ArticleRepository.FindAuthorsLatestArticle(l.ctx, conn, user.CompanyId, users, user.Id, req.LastArticleId, req.Size); err != nil {
return nil, xerr.NewErrMsgErr("获取快讯异常", err)
... ...
... ... @@ -1315,6 +1315,7 @@ type MiniSearchArticleResponse struct {
type MiniSearchArticleItem struct {
ArticleId int64 `json:"articleId"`
Title string `json:"title"`
AuthorId int64 `json:"authorId"`
Author string `json:"author"` // 发布人
Avatar string `json:"avatar"` // 发布人的头像
Images []string `json:"images"`
... ...
... ... @@ -176,7 +176,7 @@ func (repository *ArticleRepository) FindAuthorsLatestArticle(ctx context.Contex
queryFunc := func() (interface{}, error) {
tx = tx.Model(&ms).
Where("company_id=?", companyId).
Where("author_id in (?)", append(authors, whoRead)). // 包含自己的文章
Where("author_id in (?)", authors). // 包含自己的文章
Where(fmt.Sprintf("author_id = %d or target_user=0 or who_read @>'[%d]'", whoRead, whoRead)).
Where("show = 1")
if lastId > 0 {
... ...