作者 tangxvhui

Merge branch 'dev' into test

... ... @@ -24,6 +24,10 @@ service Core {
@handler MiniListArticleComment
post /article_comment/list (MiniListArticleCommentRequest) returns (MiniListArticleCommentResponse)
@doc "小程序展示评论对应的一级回复列表"
@handler MiniListReplyArticleComment
post /article_comment/list_reply (MiniListReplyArticleCommentRequest) returns (MiniListReplyArticleCommentResponse)
@doc "小程序展示文章的评论列表TOP5"
@handler MiniTop5ArticleComment
post /article_comment/top5 (MiniTop5ArticleCommentRequest) returns (MiniTop5ArticleCommentResponse)
... ... @@ -159,7 +163,7 @@ type (
AtWho []CommentAtWho `json:"atWho"` // 填写评论时@的人
MatchUrl map[string]string `json:"matchUrl"` // 评论内容中的url文本
CreatedAt int64 `json:"createdAt"` //
MeLoveFlag int `json:"meLoveFlag"` //当前人员对评论的点赞标识 (0 没有点赞 1有点赞)
MeLoveFlag int `json:"meLoveFlag"` // 当前人员对评论的点赞标识 (0 没有点赞 1有点赞)
Content string `json:"content"` // 评论的内容
}
)
... ... @@ -214,6 +218,22 @@ type (
}
)
// 获取评论的回复,只返回一级
type (
MiniListReplyArticleCommentRequest {
CommentId int64 `json:"commentId"`
UserId int64 `json:",optional"`
CompanyId int64 `json:",optional"`
Page int `json:"page"`
Size int `json:"size"`
}
MiniListReplyArticleCommentResponse {
Total int64 `json:"total"`
List []ArticleCommentItem `json:"list"`
}
)
type (
SystemArticleCommentSearchMeRequest {
Page int `json:"page"`
... ...
package comment
import (
"net/http"
"github.com/zeromicro/go-zero/rest/httpx"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/logic/comment"
"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/pkg/contextdata"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/result"
)
func MiniListReplyArticleCommentHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.MiniListReplyArticleCommentRequest
if err := httpx.Parse(r, &req); err != nil {
result.HttpResult(r, w, nil, err)
return
}
l := comment.NewMiniListReplyArticleCommentLogic(r.Context(), svcCtx)
token := contextdata.GetUserTokenFromCtx(r.Context())
req.CompanyId = token.CompanyId
req.UserId = token.UserId
resp, err := l.MiniListReplyArticleComment(&req)
result.HttpResult(r, w, resp, err)
}
}
... ...
... ... @@ -70,6 +70,11 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
},
{
Method: http.MethodPost,
Path: "/article_comment/list_reply",
Handler: comment.MiniListReplyArticleCommentHandler(serverCtx),
},
{
Method: http.MethodPost,
Path: "/article_comment/top5",
Handler: comment.MiniTop5ArticleCommentHandler(serverCtx),
},
... ...
... ... @@ -161,6 +161,7 @@ func (l *MiniCreateArticleLogic) MiniCreateArticle(req *types.MiniArticleCreateR
Show: domain.ArticleShowEnable,
Tags: []int64{},
MatchUrl: map[string]string{},
Videos: []domain.Video{},
}
if len(whoRead) > 0 {
newArticle.TargetUser = domain.ArticleTargetLimit
... ...
... ... @@ -113,7 +113,7 @@ func (l *MiniSetUserLikeLogic) cancelSetUserLikeArticle(req *types.MiniSetUserLi
return nil, xerr.NewErrMsgErr("取消点赞标识失败", err)
}
articleInfo, err = l.svcCtx.ArticleRepository.FindOne(l.ctx, conn, req.ArticleId)
if err == nil {
if err != nil {
return nil, xerr.NewErrMsgErr("获取点赞数量失败", err)
}
resp = &types.MiniSetUserLikeResponse{
... ...
... ... @@ -29,8 +29,8 @@ func NewMiniListArticleCommentLogic(ctx context.Context, svcCtx *svc.ServiceCont
func (l *MiniListArticleCommentLogic) MiniListArticleComment(req *types.MiniListArticleCommentRequest) (resp *types.MiniListArticleCommentResponse, err error) {
// 先获取最顶层的评论
var conn = l.svcCtx.DefaultDBConn()
if req.Page > 40 {
req.Page = 40
if req.Size > 40 {
req.Size = 40
}
queryOption := domain.NewQueryOptions().
... ... @@ -174,7 +174,7 @@ func (l *MiniListArticleCommentLogic) listCommentReply(commentId int64, loveFlag
Position: val.ToUser.Position,
Company: val.ToUser.Company,
},
SectionContent: val.SectionContent,
SectionContent: "", //不设置值
CountReply: val.CountReply,
CountUserLove: val.CountUserLove,
CountAdminLove: val.CountAdminLove,
... ...
package comment
import (
"context"
"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/domain"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/xerr"
"github.com/zeromicro/go-zero/core/logx"
)
type MiniListReplyArticleCommentLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewMiniListReplyArticleCommentLogic(ctx context.Context, svcCtx *svc.ServiceContext) *MiniListReplyArticleCommentLogic {
return &MiniListReplyArticleCommentLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
// 获取评论对应的回复,只获取一级评论
func (l *MiniListReplyArticleCommentLogic) MiniListReplyArticleComment(req *types.MiniListReplyArticleCommentRequest) (resp *types.MiniListReplyArticleCommentResponse, err error) {
// 先获取最顶层的评论
var conn = l.svcCtx.DefaultDBConn()
if req.CommentId == 0 {
return
}
queryOption := domain.NewQueryOptions().
WithOffsetLimit(req.Page, req.Size).
MustWithKV("show", int(domain.CommentShowEnable)).
MustWithKV("companyId", req.CompanyId).
MustWithKV("pid", req.CommentId)
cnt, commentList, err := l.svcCtx.ArticleCommentRepository.Find(l.ctx, conn, queryOption)
if err != nil {
return nil, xerr.NewErrMsgErr("获取评论信息失败", err)
}
if cnt == 0 || len(commentList) == 0 {
resp = &types.MiniListReplyArticleCommentResponse{
Total: cnt,
List: make([]types.ArticleCommentItem, 0),
}
return
}
commentIds := []int64{}
for _, val := range commentList {
commentIds = append(commentIds, val.Id)
}
queryOption = domain.NewQueryOptions().WithFindOnly().
MustWithKV("commentIdList", commentIds).
MustWithKV("userId", req.UserId)
// 获取我点赞的评论
_, userFlagList, err := l.svcCtx.UserLoveFlagRepository.Find(l.ctx, conn, queryOption)
if err != nil {
return nil, xerr.NewErrMsgErr("获取评论信息失败", err)
}
// 我点赞的
flagMap := map[int64]struct{}{}
for _, val := range userFlagList {
flagMap[val.CommentId] = struct{}{}
}
resp = &types.MiniListReplyArticleCommentResponse{
Total: cnt,
List: make([]types.ArticleCommentItem, len(commentList)),
}
// 获取回复的评论
for i, val := range commentList {
item := types.ArticleCommentItem{
Id: val.Id,
Pid: val.Pid,
TopId: val.TopId,
ArtitcleId: val.ArticleId,
SectionId: val.SectionId,
FromUserId: val.FromUserId,
FromUser: types.CommentAuthor{
Id: val.FromUser.Id,
Name: val.FromUser.Name,
Avatar: val.FromUser.Avatar,
Position: val.FromUser.Position,
Company: val.FromUser.Company,
},
ToUserId: val.ToUserId,
ToUser: types.CommentAuthor{
Id: val.ToUser.Id,
Name: val.ToUser.Name,
Avatar: val.ToUser.Avatar,
Position: val.ToUser.Position,
Company: val.ToUser.Company,
},
SectionContent: val.SectionContent,
CountReply: val.CountReply,
CountUserLove: val.CountUserLove,
CountAdminLove: val.CountAdminLove,
AtWho: []types.CommentAtWho{},
MatchUrl: map[string]string{},
CreatedAt: val.CreatedAt,
MeLoveFlag: 0,
Content: val.Content,
}
if _, ok := flagMap[val.Id]; ok {
item.MeLoveFlag = 1
}
for key2, val2 := range val.MatchUrl {
item.MatchUrl[key2] = val2
}
for _, val2 := range val.AtWho {
item.AtWho = append(item.AtWho, types.CommentAtWho{
Id: val2.Id,
Name: val2.Name,
})
}
resp.List[i] = item
}
return resp, nil
}
... ...
... ... @@ -94,7 +94,7 @@ type ArticleCommentItem struct {
AtWho []CommentAtWho `json:"atWho"` // 填写评论时@的人
MatchUrl map[string]string `json:"matchUrl"` // 评论内容中的url文本
CreatedAt int64 `json:"createdAt"` //
MeLoveFlag int `json:"meLoveFlag"` //当前人员对评论的点赞标识 (0 没有点赞 1有点赞)
MeLoveFlag int `json:"meLoveFlag"` // 当前人员对评论的点赞标识 (0 没有点赞 1有点赞)
Content string `json:"content"` // 评论的内容
}
... ... @@ -138,6 +138,19 @@ type MiniArticleCommentAtWhoResponse struct {
List []CommentAtWho `json:"list"`
}
type MiniListReplyArticleCommentRequest struct {
CommentId int64 `json:"commentId"`
UserId int64 `json:",optional"`
CompanyId int64 `json:",optional"`
Page int `json:"page"`
Size int `json:"size"`
}
type MiniListReplyArticleCommentResponse struct {
Total int64 `json:"total"`
List []ArticleCommentItem `json:"list"`
}
type SystemArticleCommentSearchMeRequest struct {
Page int `json:"page"`
Size int `json:"size"`
... ...
... ... @@ -155,7 +155,9 @@ func (repository *ArticleCommentRepository) Find(ctx context.Context, conn trans
if v, ok := queryOptions["fromUserName"]; ok && v.(string) != "" {
tx = tx.Where(`from_user #>> '{"name"}' like ?`, "%"+v.(string)+"%")
}
if v, ok := queryOptions["pid"]; ok {
tx = tx.Where("pid=?", v)
}
if total, tx = transaction.PaginationAndCount(ctx, tx, queryOptions, &ms); tx.Error != nil {
return dms, tx.Error
}
... ...
... ... @@ -214,7 +214,7 @@ func (repository *ArticleRepository) FindAuthorsLatestFirstArticle(ctx context.C
tx = tx.Model(&ms).Select("max(id) id", "max(author_id) author_id", "max(created_at) created_at").
Where("company_id=?", companyId).
Where("author_id in (?)", authors).
Where("target_user=0 or who_read @>'[?]'", whoRead).
Where("target_user=0 or who_read @>? ", fmt.Sprintf("[%d]", whoRead)).
Where("show = 1").
Group("author_id").
Order("id desc")
... ... @@ -254,7 +254,7 @@ func (repository *ArticleRepository) FindAuthorsLatestFirstUnreadArticle(ctx con
tx = tx.Model(&ms).Select("max(id) id", "max(author_id) author_id", "max(created_at) created_at").
Where("company_id=?", companyId).
Where("author_id in (?)", authors).
Where("target_user=0 or who_read @>'[?]'", whoRead).
Where("target_user=0 or who_read @>? ", fmt.Sprintf("[%d]", whoRead)).
Where("show = 1").
Where("id not in (select article_id from user_read_article where user_id = ?)", whoRead).
Group("author_id").
... ...
... ... @@ -135,6 +135,9 @@ func (repository *UserLoveFlagRepository) Find(ctx context.Context, conn transac
if v, ok := queryOptions["toUserId"]; ok {
tx = tx.Where("to_user_id=?", v)
}
if v, ok := queryOptions["commentIdList"]; ok {
tx = tx.Where("comment_id in (?)", v)
}
if total, tx = transaction.PaginationAndCount(ctx, tx, queryOptions, &ms); tx.Error != nil {
return dms, tx.Error
}
... ...