作者 yangfu
正在显示 26 个修改的文件 包含 331 行增加70 行删除
... ... @@ -7,6 +7,9 @@
管理后台“易数家“前端入口:https://digital-front-platform-dev.fjmaimaimai.com/
跳转后的实际管理后台地址: https://sumifcc-x-front-test.sumifcc.com
样例账号 18860183050 密码 123456
### 可设置环境变量
- DataSource
数据库连接,样例
... ...
... ... @@ -374,7 +374,7 @@ type (
SystemArticleSearchRequest {
CompanyId int64 `json:"companyId,optional"`
Title string `json:"title,optional"` //标题
Author string `json:"author,optional"` //发布人
Author int64 `json:"author,optional"` //发布人
BeginTime int64 `json:"beginTime,optional"` //开始时间
EndTime int64 `json:"endTime,optional"` //结束时间
Tags []int64 `json:"tags,optional"` //标签
... ... @@ -389,11 +389,12 @@ type (
SystemArticleSearch {
Id int64 `json:"id"` //id
Title string `json:"title"` //标题
AuthorId int64 `json:"authorId"` //发布人ID
Author string `json:"author"` //发布人
Images []string `json:"images"` //图片
CreatedAt int64 `json:"createdAt"` //文章的创建日期
CountLove int `json:"countLove"` //点赞数量
CountComment int `json:"CountComment"` //评论数量
CountComment int `json:"countComment"` //评论数量
Show int `json:"show"` //是否隐藏 [0显示、1不显示]
Tags []string `json:"tags"` //标签
TargetUser int `json:"targetUser"` //分发方式 [0分发给所有人、1分发给指定的人]
... ...
... ... @@ -76,6 +76,10 @@ service Core {
@doc "管理后台变更评论"
@handler SystemEditAticleComment
post /article_comment/edit (SystemEditCommentRequest)returns (SystemEditCommentResponse)
@doc "编辑评论的运营点赞数"
@handler SystemEditAticleCommentLove
post /article_comment/edit/love (SystemEditCommentLoveRequest)returns (SystemEditCommentLoveResponse)
}
//评论的填写人
... ... @@ -254,7 +258,7 @@ type (
Size int `json:"size"`
ArticleId int64 `json:"articleId"` // 文章ID
TopId int64 `json:"topId,optional"` // 文章顶层ID
Author string `json:"author,optional"` // 用户
Author int64 `json:"author,optional"` // 用户
Show int `json:"show,optional"` // 显示状态
BeginTime int64 `json:"beginTime,optional"` // 开始时间
EndTime int64 `json:"endTime,optional"` // 结束时间
... ... @@ -289,7 +293,7 @@ type (
Size int `json:"size"`
CompanyId int64 `json:",optional"` //
TopId int64 `json:"topId,optional"` // 评论的顶层ID
FromUser string `json:"fromUser,optional"` // 用户
FromUserId int64 `json:"fromUserId,optional"` // 用户
Show int `json:"show,optional"` // 显示状态
BeginTime int64 `json:"beginTime,optional"` // 填写评论的开始时间
EndTime int64 `json:"endTime,optional"` // 填写评论的结束时间
... ... @@ -368,3 +372,18 @@ type (
Id int64 `json:"id"`
}
)
// 管理后台变更评论的运营点赞
type (
SystemEditCommentLoveRequest {
CompanyId int64 `json:",optional"`
ParamList []SystemEditLove `json:"paramList"`
}
SystemEditLove {
Id int64 `json:"id"`
CountAdminLove int `json:"countAdminLove,optional"`
}
SystemEditCommentLoveResponse {
ParamList []SystemEditLove `json:"paramList"`
}
)
\ No newline at end of file
... ...
... ... @@ -15,7 +15,7 @@ func SystemEditAticleCommentHandler(svcCtx *svc.ServiceContext) http.HandlerFunc
return func(w http.ResponseWriter, r *http.Request) {
var req types.SystemEditCommentRequest
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
result.HttpResult(r, w, nil, err)
return
}
... ...
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 SystemEditAticleCommentLoveHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.SystemEditCommentLoveRequest
if err := httpx.Parse(r, &req); err != nil {
result.HttpResult(r, w, nil, err)
return
}
token := contextdata.GetUserTokenFromCtx(r.Context())
req.CompanyId = token.CompanyId
l := comment.NewSystemEditAticleCommentLoveLogic(r.Context(), svcCtx)
resp, err := l.SystemEditAticleCommentLove(&req)
result.HttpResult(r, w, resp, err)
}
}
... ...
... ... @@ -11,6 +11,7 @@ import (
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/result"
)
// 管理后台的评论列表
func SystemListAticleCommentHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.SystemListCommentRequest
... ...
... ... @@ -133,6 +133,11 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
Path: "/article_comment/edit",
Handler: comment.SystemEditAticleCommentHandler(serverCtx),
},
{
Method: http.MethodPost,
Path: "/article_comment/edit/love",
Handler: comment.SystemEditAticleCommentLoveHandler(serverCtx),
},
}...,
),
rest.WithJwt(serverCtx.Config.SystemAuth.AccessSecret),
... ...
... ... @@ -28,6 +28,9 @@ func NewMiniArticleSearchMeLogic(ctx context.Context, svcCtx *svc.ServiceContext
// MiniArticleSearchMe 获取我发布的文章
func (l *MiniArticleSearchMeLogic) MiniArticleSearchMe(req *types.MiniArticleSearchMeRequest) (resp *types.MiniArticleSearchMeResponse, err error) {
var conn = l.svcCtx.DefaultDBConn()
if req.Size > 100 {
req.Size = 100
}
queryOptions := domain.NewQueryOptions().
WithOffsetLimit(req.Page, req.Size).
MustWithKV("authorId", req.AuthorId)
... ...
... ... @@ -5,6 +5,7 @@ import (
"strconv"
"strings"
"text/template"
"unicode/utf8"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types"
... ... @@ -34,6 +35,16 @@ func NewMiniCreateArticleLogic(ctx context.Context, svcCtx *svc.ServiceContext)
// 创建新文章
func (l *MiniCreateArticleLogic) MiniCreateArticle(req *types.MiniArticleCreateRequest) (resp *types.MiniArticleCreateResponse, err error) {
var conn = l.svcCtx.DefaultDBConn()
// 检查文字数量
wordNum := 0
for i := range req.Section {
num := utf8.RuneCountInString(req.Section[i])
wordNum += num
}
if wordNum >= 1000 {
return nil, xerr.NewErrMsgErr("最多只能输入1000字", err)
}
// 检查发布人
author, err := l.svcCtx.UserRepository.FindOne(l.ctx, conn, req.AuthorId)
if err != nil {
... ...
... ... @@ -28,7 +28,9 @@ func NewMiniSearchArticleDraftMeLogic(ctx context.Context, svcCtx *svc.ServiceCo
// 查询我的草稿箱内容列表
func (l *MiniSearchArticleDraftMeLogic) MiniSearchArticleDraftMe(req *types.MiniArticleDraftSearchMeRequest) (resp *types.MiniArticleDraftSearchMeResponse, err error) {
var conn = l.svcCtx.DefaultDBConn()
if req.Size > 100 {
req.Size = 100
}
queryOption := domain.NewQueryOptions().
WithOffsetLimit(req.Page, req.Size).
MustWithKV("authorId", req.AuthorId)
... ...
... ... @@ -29,7 +29,9 @@ func NewMiniSearchArticlePageLogic(ctx context.Context, svcCtx *svc.ServiceConte
func (l *MiniSearchArticlePageLogic) MiniSearchArticlePage(req *types.MiniSearchArticleRequest) (resp *types.MiniSearchArticleResponse, err error) {
var conn = l.svcCtx.DefaultDBConn()
if req.Size > 100 {
req.Size = 100
}
cnt, articleList, err := l.svcCtx.ArticleRepository.CustomSearchBy(l.ctx, conn, req.UserId, req.CompanyId,
req.TagCategory, req.TagId, [2]int64{req.BeginTime, req.EndTime}, req.SearchWord, req.Page, req.Size)
if err != nil {
... ...
... ... @@ -30,7 +30,8 @@ func (l *SystemSearchArticleLogic) SystemSearchArticle(req *types.SystemArticleS
queryOptions := domain.NewQueryOptions().
WithOffsetLimit(req.Page, req.Size).
WithKV("title", req.Title).
WithKV("author", req.Author).
WithKV("authorId", req.Author).
WithKV("tags", req.Tags).
WithKV("beginCreatedAt", req.BeginTime).
WithKV("endCreatedAt", req.EndTime)
total, articles, err := l.svcCtx.ArticleRepository.Find(l.ctx, conn, req.CompanyId, queryOptions)
... ... @@ -41,23 +42,49 @@ func (l *SystemSearchArticleLogic) SystemSearchArticle(req *types.SystemArticleS
Total: int(total),
List: make([]types.SystemArticleSearch, 0),
}
authorIds := make([]int64, 0)
lo.ForEach(articles, func(item *domain.Article, index int) {
authorIds = append(authorIds, item.AuthorId)
})
//查询用户数据,重新赋值更新用户名称
_, users, _ := l.svcCtx.UserRepository.Find(l.ctx, conn, domain.NewQueryOptions().WithFindOnly().WithKV("ids", authorIds))
//获取标签
_, tags, _ := l.svcCtx.ArticleTagRepository.Find(l.ctx, conn, req.CompanyId, domain.NewQueryOptions())
lo.ForEach(articles, func(item *domain.Article, index int) {
//图片
images := make([]string, 0)
lo.ForEach(item.Images, func(img domain.Image, n int) {
images = append(images, img.Url)
})
//发布人
author := item.Author.Name
for _, user := range users {
if user.Id == item.AuthorId {
author = user.Name
}
}
//标签
articleTags := make([]string, 0)
lo.ForEach(item.Tags, func(tagId int64, index int) {
for _, t := range tags {
if t.Id == tagId {
articleTags = append(articleTags, t.Name)
}
}
})
resp.List = append(resp.List, types.SystemArticleSearch{
Id: item.Id,
Title: item.Title,
Author: item.Author.Name,
AuthorId: item.AuthorId,
Author: author,
Images: images,
CreatedAt: item.CreatedAt,
CountLove: item.CountLove,
CountComment: item.CountComment,
Show: int(item.Show),
Tags: nil,
Tags: articleTags,
TargetUser: int(item.TargetUser),
})
})
return resp, nil
return
}
... ...
... ... @@ -3,6 +3,7 @@ package article
import (
"context"
"strconv"
"unicode/utf8"
"strings"
... ... @@ -42,6 +43,17 @@ func (l *SystemUpdateArticleLogic) SystemUpdateArticle(req *types.SystemArticleU
//TargetUser 设定为分发给所有人,清空 WhoRead
req.WhoRead = make([]int64, 0)
}
// 检查文字数量
wordNum := 0
for i := range req.Section {
num := utf8.RuneCountInString(req.Section[i].Content)
wordNum += num
}
if wordNum >= 1000 {
return nil, xerr.NewErrMsgErr("最多只能输入1000字", err)
}
// 获取当前用户信息
userMe, err := l.svcCtx.ApiAuthService.MeInfo(l.ctx, authlib.RequestUserMeQuery{Token: req.AccessToken})
if err != nil {
... ...
... ... @@ -2,7 +2,6 @@ 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/db/transaction"
... ... @@ -29,61 +28,69 @@ func NewMiniDeleteArticleCommentLogic(ctx context.Context, svcCtx *svc.ServiceCo
// 小程序端人人员删除评论
func (l *MiniDeleteArticleCommentLogic) MiniDeleteArticleComment(req *types.MiniDeleteArticleCommentRequest) (resp *types.MiniDeleteArticleCommentResponse, err error) {
var conn = l.svcCtx.DefaultDBConn()
commetInfo, err := l.svcCtx.ArticleCommentRepository.FindOne(l.ctx, conn, req.CommentId)
commentInfo, err := l.svcCtx.ArticleCommentRepository.FindOne(l.ctx, conn, req.CommentId)
if err != nil {
return nil, xerr.NewErrMsgErr("删除评论信息失败", err)
}
if commetInfo.FromUserId != req.UserId {
if commentInfo.FromUserId != req.UserId {
return nil, xerr.NewErrMsg("没有操作权限")
}
if commetInfo.Show == domain.CommentShowDisable {
if commentInfo.Show == domain.CommentShowDisable {
resp = &types.MiniDeleteArticleCommentResponse{
Id: commetInfo.Id,
Id: commentInfo.Id,
}
return resp, nil
}
commetInfo.Show = domain.CommentShowDisable
commentInfo.Show = domain.CommentShowDisable
// 变更回复数量
err = transaction.UseTrans(l.ctx, conn.DB(), func(ctx context.Context, c transaction.Conn) error {
_, err = l.svcCtx.ArticleCommentRepository.Update(ctx, c, commetInfo)
_, err = l.svcCtx.ArticleCommentRepository.Update(ctx, c, commentInfo)
if err != nil {
return err
}
// 减少上级评论的回复数量
if commetInfo.Pid != 0 {
err = l.svcCtx.ArticleCommentRepository.IncreaseCountReply(l.ctx, c, -1, commetInfo.Pid)
if commentInfo.Pid != 0 {
err = l.svcCtx.ArticleCommentRepository.IncreaseCountReply(l.ctx, c, -1, commentInfo.Pid)
if err != nil {
return err
}
}
// 减少最顶层的评论回复计数
if commetInfo.TopId != 0 && commetInfo.Pid != commetInfo.TopId {
err = l.svcCtx.ArticleCommentRepository.IncreaseCountReply(l.ctx, c, -1, commetInfo.TopId)
if commentInfo.TopId != 0 && commentInfo.Pid != commentInfo.TopId {
err = l.svcCtx.ArticleCommentRepository.IncreaseCountReply(l.ctx, c, -1, commentInfo.TopId)
if err != nil {
return err
}
}
//减少加段落评论计数
if commetInfo.SectionId > 0 {
err = l.svcCtx.ArticleSectionRepository.IncreaseCountComment(ctx, c, -1, commetInfo.SectionId)
if commentInfo.SectionId > 0 {
err = l.svcCtx.ArticleSectionRepository.IncreaseCountComment(ctx, c, -1, commentInfo.SectionId)
if err != nil {
return err
}
}
// 减少文章的评论数
err = l.svcCtx.ArticleRepository.IncreaseCountComment(ctx, c, -1, commetInfo.ArticleId)
err = l.svcCtx.ArticleRepository.IncreaseCountComment(ctx, c, -1, commentInfo.ArticleId)
if err != nil {
return err
}
//// 评论被隐藏消息
//var messageLogic = message.NewMiniSystemLogic(l.ctx, l.svcCtx)
//err = messageLogic.AbnormalCommentHidden(c, commentInfo.CompanyId, commentInfo.FromUserId, commentInfo.Content)
//if err != nil {
// return err
//}
return nil
}, true)
if err != nil {
return nil, xerr.NewErrMsgErr("删除评论信息失败", err)
}
resp = &types.MiniDeleteArticleCommentResponse{Id: commetInfo.Id}
resp = &types.MiniDeleteArticleCommentResponse{Id: commentInfo.Id}
return resp, nil
}
... ...
... ... @@ -45,7 +45,7 @@ func (l *MiniGetArticleCommentLogic) MiniGetArticleComment(req *types.MiniGetArt
}
if commentInfo.Show == domain.CommentShowDisable {
return nil, xerr.NewErrMsg("具体评论已被关闭")
return nil, xerr.NewErrMsg("抱歉,此内容根据运营管理规则已隐藏,暂不可见")
}
queryOption := domain.NewQueryOptions().
... ...
... ... @@ -36,8 +36,8 @@ func (l *MiniListArticleCommentLogic) MiniListArticleComment(req *types.MiniList
if err != nil {
return nil, xerr.NewErrMsgErr("获取评论信息失败", err)
}
if req.Size > 40 {
req.Size = 40
if req.Size > 100 {
req.Size = 100
}
queryOption := domain.NewQueryOptions().
... ... @@ -119,7 +119,7 @@ func (l *MiniListArticleCommentLogic) MiniListArticleComment(req *types.MiniList
}
//获取回复的评论
cntReply, reply := l.listCommentReply(item.Comment.Id, flagMap)
cntReply, reply := l.listCommentReply(companyInfo.Id, item.Comment.Id, flagMap)
resp.List[i] = item
resp.List[i].Reply = reply
resp.List[i].TotalReply = cntReply
... ... @@ -128,9 +128,9 @@ func (l *MiniListArticleCommentLogic) MiniListArticleComment(req *types.MiniList
}
// listCommentReply
func (l *MiniListArticleCommentLogic) listCommentReply(commentId int64, loveFlagMap map[int64]struct{}) (cnt int64, replyList []types.ArticleCommentItem) {
func (l *MiniListArticleCommentLogic) listCommentReply(companyId int64, commentId int64, loveFlagMap map[int64]struct{}) (cnt int64, replyList []types.ArticleCommentItem) {
var conn = l.svcCtx.DefaultDBConn()
companyInfo, err := l.svcCtx.CompanyRepository.FindOne(l.ctx, conn, commentId)
companyInfo, err := l.svcCtx.CompanyRepository.FindOne(l.ctx, conn, companyId)
if err != nil {
return 0, []types.ArticleCommentItem{}
}
... ...
... ... @@ -35,9 +35,11 @@ func (l *SystemArticleCommentSearchLogic) SystemArticleCommentSearch(req *types.
WithKV("articleId", req.ArticleId).
WithKV("topId", req.TopId).
WithKV("show", req.Show).
WithKV("fromUserName", req.Author).
WithKV("beginCreatedAt", req.BeginTime).
WithKV("endCreatedAt", req.EndTime)
if req.Author > 0 {
queryOptions = queryOptions.WithKV("fromUserId", req.Author)
}
total, comments, err := l.svcCtx.ArticleCommentRepository.Find(l.ctx, conn, queryOptions)
if err != nil {
return nil, xerr.NewErrMsgErr("获取文章评论失败", err)
... ... @@ -46,6 +48,7 @@ func (l *SystemArticleCommentSearchLogic) SystemArticleCommentSearch(req *types.
Total: total,
List: make([]types.SystemArticleCommentSearchItem, 0),
}
authorIds := make([]int64, 0)
lo.ForEach(comments, func(item *domain.ArticleComment, index int) {
resp.List = append(resp.List, types.SystemArticleCommentSearchItem{
Id: item.Id,
... ... @@ -68,6 +71,22 @@ func (l *SystemArticleCommentSearchLogic) SystemArticleCommentSearch(req *types.
Content: item.Content,
Show: int(item.Show),
})
authorIds = append(authorIds, item.FromUserId)
})
//查询用户数据,重新赋值更新用户名称
_, users, _ := l.svcCtx.UserRepository.Find(l.ctx, conn, domain.NewQueryOptions().WithFindOnly().WithKV("ids", authorIds))
lo.ForEach(resp.List, func(item types.SystemArticleCommentSearchItem, index int) {
for _, user := range users {
if user.Id == item.FromUserId {
resp.List[index].FromUser = types.CommentAuthor{
Id: user.Id,
Name: user.Name,
Avatar: user.Avatar,
Position: user.Position,
Company: item.FromUser.Company,
}
}
}
})
return
}
... ...
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/db/transaction"
"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 SystemEditAticleCommentLoveLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewSystemEditAticleCommentLoveLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SystemEditAticleCommentLoveLogic {
return &SystemEditAticleCommentLoveLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *SystemEditAticleCommentLoveLogic) SystemEditAticleCommentLove(req *types.SystemEditCommentLoveRequest) (resp *types.SystemEditCommentLoveResponse, err error) {
var conn = l.svcCtx.DefaultDBConn()
if len(req.ParamList) <= 0 {
return &types.SystemEditCommentLoveResponse{}, nil
}
paramMap := map[int64]int{}
ids := []int64{}
for _, val := range req.ParamList {
if val.CountAdminLove < 0 {
return nil, xerr.NewErrMsg("运营点赞数不能小于0")
}
ids = append(ids, val.Id)
paramMap[val.Id] = val.CountAdminLove
}
queryOption := domain.NewQueryOptions().WithFindOnly().MustWithKV("ids", ids)
_, commetList, err := l.svcCtx.ArticleCommentRepository.Find(l.ctx, conn, queryOption)
if err != nil {
return nil, xerr.NewErrMsgErr("编辑评论信息失败", err)
}
resp = &types.SystemEditCommentLoveResponse{}
for _, val := range commetList {
if val.CompanyId != req.CompanyId {
return nil, xerr.NewErrMsg("没有操作权限")
}
if u, ok := paramMap[val.Id]; ok {
val.CountAdminLove = u
resp.ParamList = append(resp.ParamList, types.SystemEditLove{
Id: val.Id,
CountAdminLove: val.CountAdminLove,
})
}
}
err = transaction.UseTrans(l.ctx, conn.DB(), func(ctx context.Context, c transaction.Conn) error {
for _, val := range commetList {
_, err := l.svcCtx.ArticleCommentRepository.UpdateWithVersion(ctx, c, val)
if err != nil {
return err
}
}
return nil
}, true)
if err != nil {
return nil, xerr.NewErrMsgErr("编辑评论信息失败", err)
}
return resp, nil
}
... ...
... ... @@ -2,6 +2,7 @@ package comment
import (
"context"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/logic/message"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types"
... ... @@ -61,49 +62,57 @@ func (l *SystemEditAticleCommentShowLogic) SystemEditAticleCommentShow(req *type
func (l *SystemEditAticleCommentShowLogic) disableShow(commentId int64, companyId int64) error {
var conn = l.svcCtx.DefaultDBConn()
commetInfo, err := l.svcCtx.ArticleCommentRepository.FindOne(l.ctx, conn, commentId)
commentInfo, err := l.svcCtx.ArticleCommentRepository.FindOne(l.ctx, conn, commentId)
if err != nil {
return xerr.NewErrMsgErr("删除评论信息失败", err)
}
if commetInfo.CompanyId != companyId {
if commentInfo.CompanyId != companyId {
return xerr.NewErrMsg("没有操作权限")
}
if commetInfo.Show == domain.CommentShowDisable {
if commentInfo.Show == domain.CommentShowDisable {
return nil
}
commetInfo.Show = domain.CommentShowDisable
commentInfo.Show = domain.CommentShowDisable
// 变更回复数量
err = transaction.UseTrans(l.ctx, conn.DB(), func(ctx context.Context, c transaction.Conn) error {
_, err = l.svcCtx.ArticleCommentRepository.Update(ctx, c, commetInfo)
_, err = l.svcCtx.ArticleCommentRepository.Update(ctx, c, commentInfo)
if err != nil {
return err
}
// 减少上级评论的回复数量
if commetInfo.Pid != 0 {
err = l.svcCtx.ArticleCommentRepository.IncreaseCountReply(l.ctx, c, -1, commetInfo.Pid)
if commentInfo.Pid != 0 {
err = l.svcCtx.ArticleCommentRepository.IncreaseCountReply(l.ctx, c, -1, commentInfo.Pid)
if err != nil {
return err
}
}
// 减少最顶层的评论回复计数
if commetInfo.TopId != 0 && commetInfo.Pid != commetInfo.TopId {
err = l.svcCtx.ArticleCommentRepository.IncreaseCountReply(l.ctx, c, -1, commetInfo.TopId)
if commentInfo.TopId != 0 && commentInfo.Pid != commentInfo.TopId {
err = l.svcCtx.ArticleCommentRepository.IncreaseCountReply(l.ctx, c, -1, commentInfo.TopId)
if err != nil {
return err
}
}
//减少加段落评论计数
if commetInfo.SectionId > 0 {
err = l.svcCtx.ArticleSectionRepository.IncreaseCountComment(ctx, c, -1, commetInfo.SectionId)
if commentInfo.SectionId > 0 {
err = l.svcCtx.ArticleSectionRepository.IncreaseCountComment(ctx, c, -1, commentInfo.SectionId)
if err != nil {
return err
}
}
// 减少文章的评论数
err = l.svcCtx.ArticleRepository.IncreaseCountComment(ctx, c, -1, commetInfo.ArticleId)
err = l.svcCtx.ArticleRepository.IncreaseCountComment(ctx, c, -1, commentInfo.ArticleId)
if err != nil {
return err
}
// 评论被隐藏消息
var messageLogic = message.NewMiniSystemLogic(l.ctx, l.svcCtx)
err = messageLogic.AbnormalCommentHidden(c, commentInfo.CompanyId, commentInfo.FromUserId, commentInfo.Content)
if err != nil {
return err
}
return nil
}, true)
... ...
... ... @@ -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/pkg/xerr"
"github.com/zeromicro/go-zero/core/logx"
... ... @@ -14,6 +15,7 @@ type SystemListAticleCommentLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
userCache map[int64]types.CommentAuthor
}
func NewSystemListAticleCommentLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SystemListAticleCommentLogic {
... ... @@ -21,6 +23,7 @@ func NewSystemListAticleCommentLogic(ctx context.Context, svcCtx *svc.ServiceCon
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
userCache: make(map[int64]types.CommentAuthor),
}
}
... ... @@ -29,7 +32,7 @@ func (l *SystemListAticleCommentLogic) SystemListAticleComment(req *types.System
var conn = l.svcCtx.DefaultDBConn()
cnt, commentList, err := l.svcCtx.ArticleCommentRepository.CustomSearchBy(l.ctx, conn, req.CompanyId, req.Page, req.Size,
req.TopId, req.ArticleTitle, req.Content, req.FromUser, req.Show, [2]int64{req.BeginTime, req.EndTime},
req.TopId, req.ArticleTitle, req.Content, req.FromUserId, req.Show, [2]int64{req.BeginTime, req.EndTime},
)
if err != nil {
return nil, xerr.NewErrMsgErr("获取评论列表失败", err)
... ... @@ -47,13 +50,7 @@ func (l *SystemListAticleCommentLogic) SystemListAticleComment(req *types.System
TopId: val.TopId,
ArticleTitle: val.ArticleTitle,
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,
},
FromUser: l.getCommentAuthor(conn, val.FromUserId, ""),
CreatedAt: val.CreatedAt,
Content: val.Content,
Show: val.Show,
... ... @@ -65,3 +62,22 @@ func (l *SystemListAticleCommentLogic) SystemListAticleComment(req *types.System
return resp, nil
}
func (l *SystemListAticleCommentLogic) getCommentAuthor(conn transaction.Conn, userid int64, companyName string) types.CommentAuthor {
if u, ok := l.userCache[userid]; ok {
return u
}
toUser, err := l.svcCtx.UserRepository.FindOne(l.ctx, conn, userid)
if err == nil {
commentToUser := types.CommentAuthor{
Id: toUser.Id,
Name: toUser.Name,
Avatar: toUser.Avatar,
Position: toUser.Position,
Company: companyName,
}
l.userCache[toUser.Id] = commentToUser
return commentToUser
}
return types.CommentAuthor{}
}
... ...
... ... @@ -169,7 +169,7 @@ type SystemArticleCommentSearchRequest struct {
Size int `json:"size"`
ArticleId int64 `json:"articleId"` // 文章ID
TopId int64 `json:"topId,optional"` // 文章顶层ID
Author string `json:"author,optional"` // 用户
Author int64 `json:"author,optional"` // 用户
Show int `json:"show,optional"` // 显示状态
BeginTime int64 `json:"beginTime,optional"` // 开始时间
EndTime int64 `json:"endTime,optional"` // 结束时间
... ... @@ -203,7 +203,7 @@ type SystemListCommentRequest struct {
Size int `json:"size"`
CompanyId int64 `json:",optional"` //
TopId int64 `json:"topId,optional"` // 评论的顶层ID
FromUser string `json:"fromUser,optional"` // 用户
FromUserId int64 `json:"fromUserId,optional"` // 用户
Show int `json:"show,optional"` // 显示状态
BeginTime int64 `json:"beginTime,optional"` // 填写评论的开始时间
EndTime int64 `json:"endTime,optional"` // 填写评论的结束时间
... ... @@ -275,6 +275,20 @@ type SystemEditCommentResponse struct {
Id int64 `json:"id"`
}
type SystemEditCommentLoveRequest struct {
CompanyId int64 `json:",optional"`
ParamList []SystemEditLove `json:"paramList"`
}
type SystemEditLove struct {
Id int64 `json:"id"`
CountAdminLove int `json:"countAdminLove,optional"`
}
type SystemEditCommentLoveResponse struct {
ParamList []SystemEditLove `json:"paramList"`
}
type MessageRequest struct {
Page int `json:"page"`
Size int `json:"size"`
... ... @@ -1142,7 +1156,7 @@ type SystemArticleGetResponse struct {
type SystemArticleSearchRequest struct {
CompanyId int64 `json:"companyId,optional"`
Title string `json:"title,optional"` //标题
Author string `json:"author,optional"` //发布人
Author int64 `json:"author,optional"` //发布人
BeginTime int64 `json:"beginTime,optional"` //开始时间
EndTime int64 `json:"endTime,optional"` //结束时间
Tags []int64 `json:"tags,optional"` //标签
... ... @@ -1158,11 +1172,12 @@ type SystemArticleSearchResponse struct {
type SystemArticleSearch struct {
Id int64 `json:"id"` //id
Title string `json:"title"` //标题
AuthorId int64 `json:"authorId"` //发布人ID
Author string `json:"author"` //发布人
Images []string `json:"images"` //图片
CreatedAt int64 `json:"createdAt"` //文章的创建日期
CountLove int `json:"countLove"` //点赞数量
CountComment int `json:"CountComment"` //评论数量
CountComment int `json:"countComment"` //评论数量
Show int `json:"show"` //是否隐藏 [0显示、1不显示]
Tags []string `json:"tags"` //标签
TargetUser int `json:"targetUser"` //分发方式 [0分发给所有人、1分发给指定的人]
... ...
... ... @@ -143,8 +143,8 @@ with
-- 过滤出可展示的文章id
t_article_and_tag_2 as (
select article_and_tag.article_id,article_and_tag.tag_id
from article_and_tag
join article on article_and_tag.article_id = article.id
from article
join article_and_tag on article_and_tag.article_id = article.id
where article.deleted_at=0
and article.company_id = ?
and article."show" = ?
... ...
... ... @@ -337,7 +337,7 @@ func (repository *ArticleCommentRepository) Top5Comment(ctx context.Context, con
}
func (repository *ArticleCommentRepository) CustomSearchBy(ctx context.Context, conn transaction.Conn, companyId int64, page int, size int,
topId int64, articleTitle string, contentLike string, fromUserName string, show int, createdAtRange [2]int64) (int, []*domain.ArticleCommentShow, error) {
topId int64, articleTitle string, contentLike string, fromUserId int64, show int, createdAtRange [2]int64) (int, []*domain.ArticleCommentShow, error) {
if size <= 0 {
size = 20
... ... @@ -358,9 +358,9 @@ func (repository *ArticleCommentRepository) CustomSearchBy(ctx context.Context,
condition = append(condition, "%"+contentLike+"%")
}
if len(fromUserName) > 0 {
where += ` and article_comment.from_user ->>'name' like ? `
condition = append(condition, "%"+fromUserName+"%")
if fromUserId > 0 {
where += ` and article_comment.from_user_id = ? `
condition = append(condition, fromUserId)
}
if show > 0 {
where += ` and article_comment."show" =? `
... ... @@ -425,7 +425,6 @@ func (repository *ArticleCommentRepository) CustomSearchBy(ctx context.Context,
ArticleTitle: val.ArticleTitle,
Id: val.Id,
FromUserId: val.FromUserId,
FromUser: val.FromUser,
Content: val.Content,
CountReply: val.CountReply,
CountUserLove: val.CountUserLove,
... ...
... ... @@ -3,6 +3,7 @@ package repository
import (
"context"
"fmt"
"strings"
"github.com/pkg/errors"
"github.com/tiptok/gocomm/pkg/cache"
... ... @@ -127,9 +128,6 @@ func (repository *ArticleRepository) Find(ctx context.Context, conn transaction.
if v, ok := queryOptions["title"]; ok && v.(string) != "" {
tx = tx.Where("title like ?", "%"+v.(string)+"%")
}
if v, ok := queryOptions["author"]; ok && v.(string) != "" {
tx = tx.Where(`author #>> '{"name"}' like ?`, "%"+v.(string)+"%")
}
if v, ok := queryOptions["beginCreatedAt"]; ok {
tx = tx.Where("created_at >= ?", v)
}
... ... @@ -139,6 +137,13 @@ func (repository *ArticleRepository) Find(ctx context.Context, conn transaction.
if v, ok := queryOptions["authorId"]; ok {
tx = tx.Where("author_id=?", v)
}
if v, ok := queryOptions["tags"]; ok && len(v.([]int64)) > 0 {
values := make([]string, 0)
for _, item := range v.([]int64) {
values = append(values, fmt.Sprintf("%v", item))
}
tx = tx.Where("tags @> ?", "["+strings.Join(values, ",")+"]")
}
if total, tx = transaction.PaginationAndCount(ctx, tx, queryOptions, &ms); tx.Error != nil {
return dms, tx.Error
}
... ...
... ... @@ -57,7 +57,6 @@ type ArticleCommentShow struct {
TopId int64
ArticleTitle string // 文章标题
FromUserId int64 // 评论填写人的id
FromUser UserSimple // 评论填写人
Content string // 评论内容
CountReply int // 回复数量
CountUserLove int // 用户点赞数量
... ... @@ -78,5 +77,5 @@ type ArticleCommentRepository interface {
Top5Comment(ctx context.Context, conn transaction.Conn, companyId int64, articleId int64) ([]*ArticleComment, error)
// 特定的查询
CustomSearchBy(ctx context.Context, conn transaction.Conn, companyId int64, page int, size int,
topId int64, articleTitle string, contentLike string, fromUserName string, show int, createdAtRange [2]int64) (int, []*ArticleCommentShow, error)
topId int64, articleTitle string, contentLike string, fromUserId int64, show int, createdAtRange [2]int64) (int, []*ArticleCommentShow, error)
}
... ...
... ... @@ -2,8 +2,9 @@ package domain
import (
"context"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/db/transaction"
"reflect"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/db/transaction"
)
func OffsetLimit(page, size int) (offset int, limit int) {
... ...