作者 yangfu
... ... @@ -55,7 +55,7 @@ type (
CountRead int `json:"countRead"` // 浏览数量
Show int `json:"show"` // 评论的展示状态(0显示、1不显示)
Edit int `json:"edit"` // 文章是否存在变更记录 (0 不存在 1存在)
MeLoveFlag int `json:"meLoveFlag"` //当前人员对文章的点赞标识
MeLoveFlag int `json:"meLoveFlag"` // 当前人员对文章的点赞标识 (0 没有点赞 1有点赞)
}
ArticleSection {
Id int64 `json:"id"` //段落id
... ...
... ... @@ -23,6 +23,18 @@ service Core {
@doc "小程序填写文章的评论"
@handler MiniCreateArticleComment
post /article_comment (MiniCreateArticleCommentRequest) returns (MiniCreateArticleCommentResponse)
@doc "小程序展示文章的评论列表"
@handler MiniListArticleComment
post /article_comment/list (MiniListArticleCommentRequest) returns (MiniListArticleCommentResponse)
@doc "小程序展示单个文章的评论"
@handler MiniGetArticleComment
get /article_comment/:id (MiniGetArticleCommentRequest) returns (MiniGetArticleCommentResponse)
@doc "小程序展示删除文章评论"
@handler MiniDeleteArticleComment
delete /article_comment/:id (MiniDeleteArticleCommentRequest) returns (MiniDeleteArticleCommentResponse)
}
//
... ... @@ -40,9 +52,9 @@ type (
type CommentAuthor {
Id int64 `json:"id"` // 人员id
Name string `json:"name"` // 人员的名字
Avatar string `json:"avatar"` // 人员头像URL
Position string `json:"position"` // 职位
Company string `json:"company"` // 公司
Avatar string `json:"avatar,optional"` // 人员头像URL
Position string `json:"position,optional"` // 职位
Company string `json:"company,optional"` // 公司
}
// 小程序填写文章的评论
... ... @@ -52,11 +64,15 @@ type (
SectionId int64 `json:"sectionId"` // 段落id
FromUserId int64 `json:",optional"` // 填写文章的人,服务端自动获取
CompanyId int64 `json:",optional"` // 服务端自动获取
Pid int64 `json:"commnet"` // 回复那个评论的id
Pid int64 `json:"pid"` // 回复那个评论的id
Content string `json:"content"` // 评论的内容
AtWho []int64 `json:"atWho"` // 填写评论时@的人
AtWho []CommentAtWho `json:"atWho"` // 填写评论时@的人
}
CommentAtWho {
Id int64 `json:"id"`
Name string `json:"name,optional"`
}
MiniCreateArticleCommentResponse {
Id int64 `json:"id"`
Pid int64 `json:"pid"`
... ... @@ -71,6 +87,70 @@ type (
CountReply int `json:"countReply"` // 回复数量
CountUserLove int `json:"countUserLove"` // 用户点赞数量
CountAdminLove int `json:"countAdminLove"` // 运营点赞数量
AtWho []CommentAuthor `json:"atWho"` // 填写评论时@的人
AtWho []CommentAtWho `json:"atWho"` // 填写评论时@的人
CreatedAt int64 `json:"createdAt"` //
}
)
// 小程序获取文章的评论列表
type (
MiniListArticleCommentRequest {
Page int64 `json:"page"`
Size int64 `json:"size"`
CompanyId int64 `json:",optional"`
SectionId int64 `json:"sectionId"`
}
MiniListArticleCommentResponse {
Total int64 `json:"total"`
List []ArticleCommentAndReply `json:"list"`
}
ArticleCommentAndReply {
Comment ArticleCommentItem `json:"comment"` //评论
Reply []ArticleCommentItem `json:"reply"` //回复的评论
TotalReply int64 `json:"totalReply"` //回复的评论数量
}
ArticleCommentItem {
Id int64 `json:"id"`
Pid int64 `json:"pid"`
TopId int64 `json:"topId"`
ArtitcleId int64 `json:"articleId"` // 文章id
SectionId int64 `json:"sectionId"` // 段落id
FromUserId int64 `json:"fromUserId"` // 填写评论的人
FromUser CommentAuthor `json:"fromUser"` // 填写评论的人
ToUserId int64 `json:"toUserId"` // 回复哪个人
ToUser CommentAuthor `json:"toUser"` // 回复哪个人
SectionContent string `json:"sectionContent"` // 引用的文章内容文本
CountReply int `json:"countReply"` // 回复数量
CountUserLove int `json:"countUserLove"` // 用户点赞数量
CountAdminLove int `json:"countAdminLove"` // 运营点赞数量
AtWho []CommentAtWho `json:"atWho"` // 填写评论时@的人
CreatedAt int64 `json:"createdAt"` //
MeLoveFlag int `json:"meLoveFlag"` //当前人员对评论的点赞标识 (0 没有点赞 1有点赞)
}
)
// 小程序获取单个文章的评论
type (
MiniGetArticleCommentRequest {
CommentId int64 `path:"id"`
CompanyId int64 `path:",optional"`
UserId int64 `path:",optional"`
}
MiniGetArticleCommentResponse {
ArticleCommentAndReply
}
)
// 小程序删除单个文章的评论
type (
MiniDeleteArticleCommentRequest {
CommentId int64 `path:"id"`
UserId int64 `path:",optional"`
CompanyId int64 `path:",optional"`
}
MiniDeleteArticleCommentResponse {
Id int64 `json:"id"`
}
)
\ No newline at end of file
... ...
... ... @@ -48,6 +48,7 @@ type (
DepartmentUpdateRequest {
Id int64 `path:"id"`
Name string `json:"name"`
Ids []int64 `json:"ids"` // 用户ID
}
DepartmentListRequest {
... ...
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 MiniDeleteArticleCommentHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.MiniDeleteArticleCommentRequest
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
return
}
l := comment.NewMiniDeleteArticleCommentLogic(r.Context(), svcCtx)
token := contextdata.GetUserTokenFromCtx(r.Context())
req.CompanyId = token.CompanyId
req.UserId = token.UserId
resp, err := l.MiniDeleteArticleComment(&req)
result.HttpResult(r, w, resp, err)
}
}
... ...
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 MiniGetArticleCommentHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.MiniGetArticleCommentRequest
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
return
}
l := comment.NewMiniGetArticleCommentLogic(r.Context(), svcCtx)
token := contextdata.GetUserTokenFromCtx(r.Context())
req.CompanyId = token.CompanyId
resp, err := l.MiniGetArticleComment(&req)
result.HttpResult(r, w, resp, err)
}
}
... ...
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 MiniListArticleCommentHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.MiniListArticleCommentRequest
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
return
}
l := comment.NewMiniListArticleCommentLogic(r.Context(), svcCtx)
token := contextdata.GetUserTokenFromCtx(r.Context())
req.CompanyId = token.CompanyId
resp, err := l.MiniListArticleComment(&req)
result.HttpResult(r, w, resp, err)
}
}
... ...
... ... @@ -30,6 +30,21 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
Path: "/article_comment",
Handler: comment.MiniCreateArticleCommentHandler(serverCtx),
},
{
Method: http.MethodPost,
Path: "/article_comment/list",
Handler: comment.MiniListArticleCommentHandler(serverCtx),
},
{
Method: http.MethodGet,
Path: "/article_comment/:id",
Handler: comment.MiniGetArticleCommentHandler(serverCtx),
},
{
Method: http.MethodDelete,
Path: "/article_comment/:id",
Handler: comment.MiniDeleteArticleCommentHandler(serverCtx),
},
},
rest.WithJwt(serverCtx.Config.MiniAuth.AccessSecret),
rest.WithPrefix("/v1/mini"),
... ...
... ... @@ -26,6 +26,7 @@ func NewMiniArticleMarkUserReadLogic(ctx context.Context, svcCtx *svc.ServiceCon
}
}
// 记录人员浏览的文章
func (l *MiniArticleMarkUserReadLogic) MiniArticleMarkUserRead(req *types.MiniArticleMarkUserReadRequest) (resp *types.MiniArticleMarkUserReadResponse, err error) {
var conn = l.svcCtx.DefaultDBConn()
... ... @@ -84,7 +85,7 @@ func (l *MiniArticleMarkUserReadLogic) MiniArticleMarkUserRead(req *types.MiniAr
return err
}
//增加浏览计数
err = l.svcCtx.ArticleRepository.IncreaseCountRead(ctx, c, 1, articleInfo)
err = l.svcCtx.ArticleRepository.IncreaseCountRead(ctx, c, 1, articleInfo.Id)
return err
}, true)
if err != nil {
... ...
... ... @@ -28,6 +28,7 @@ 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()
// 检查发布人
... ...
... ... @@ -26,6 +26,7 @@ func NewMiniGetArticleLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Mi
}
}
// 小程序端展示文章内容
func (l *MiniGetArticleLogic) MiniGetArticle(req *types.MiniArticleGetRequest) (resp *types.MiniArticleGetResponse, err error) {
// 获取文章内容
var conn = l.svcCtx.DefaultDBConn()
... ... @@ -91,7 +92,6 @@ func (l *MiniGetArticleLogic) MiniGetArticle(req *types.MiniArticleGetRequest) (
Id: articleInfo.Author.Id,
Name: articleInfo.Author.Name,
Avatar: articleInfo.Author.Avatar,
// Group: articleInfo.Author.Group,
Position: articleInfo.Author.Position,
Company: articleInfo.Author.Company,
},
... ...
... ... @@ -93,7 +93,7 @@ func (l *MiniSetUserLikeLogic) cancelSetUserLikeArticle(req *types.MiniSetUserLi
return err
}
// 减少文章的点赞数量
err = l.svcCtx.ArticleRepository.IncreaseCountLove(ctx, c, -1, articleInfo)
err = l.svcCtx.ArticleRepository.IncreaseCountLove(ctx, c, -1, articleInfo.Id)
if err != nil {
return err
}
... ... @@ -166,7 +166,7 @@ func (l *MiniSetUserLikeLogic) cancelSetUserLikeComment(req *types.MiniSetUserLi
return err
}
// 减少评论的点赞数量
err = l.svcCtx.ArticleCommentRepository.IncreaseCountUserLove(ctx, c, -1, commentInfo)
err = l.svcCtx.ArticleCommentRepository.IncreaseCountUserLove(ctx, c, -1, commentInfo.Id)
if err != nil {
return err
}
... ... @@ -239,7 +239,7 @@ func (l *MiniSetUserLikeLogic) setUserLikeArticle(req *types.MiniSetUserLikeRequ
return err
}
// 增加文章的点赞数量
err = l.svcCtx.ArticleRepository.IncreaseCountLove(ctx, c, 1, articleInfo)
err = l.svcCtx.ArticleRepository.IncreaseCountLove(ctx, c, 1, articleInfo.Id)
if err != nil {
return err
}
... ... @@ -320,7 +320,7 @@ func (l *MiniSetUserLikeLogic) setUserLikeComment(req *types.MiniSetUserLikeRequ
return err
}
// 增加评论的点赞数量
err = l.svcCtx.ArticleCommentRepository.IncreaseCountUserLove(ctx, c, 1, commentInfo)
err = l.svcCtx.ArticleCommentRepository.IncreaseCountUserLove(ctx, c, 1, commentInfo.Id)
if err != nil {
return err
}
... ...
... ... @@ -49,7 +49,7 @@ func (l *MiniCreateArticleCommentLogic) MiniCreateArticleComment(req *types.Mini
return nil, xerr.NewErrMsg("没有评论权限")
}
//查看评论权限,
//临时注释
//TODO 临时注释
// if len(articleInfo.WhoReview) > 0 {
// ok := lo.IndexOf(articleInfo.WhoReview, req.FromUserId)
// if ok < 0 {
... ... @@ -84,14 +84,17 @@ func (l *MiniCreateArticleCommentLogic) MiniCreateArticleComment(req *types.Mini
}
var atWhoList []*domain.User
if len(req.AtWho) > 0 {
queryOption := domain.NewQueryOptions().WithFindOnly().WithKV("ids", req.AtWho)
uids := []int64{}
for _, val := range req.AtWho {
uids = append(uids, val.Id)
}
queryOption := domain.NewQueryOptions().WithFindOnly().WithKV("ids", uids)
_, atWhoList, err = l.svcCtx.UserRepository.Find(l.ctx, conn, queryOption)
if err != nil {
return nil, xerr.NewErrMsgErr("检查@的人员失败", err)
}
}
// 处理文本内容
// content:=
content := template.HTMLEscapeString(req.Content)
newComment := domain.ArticleComment{
... ... @@ -149,11 +152,25 @@ func (l *MiniCreateArticleCommentLogic) MiniCreateArticleComment(req *types.Mini
}
//保存数据
err = transaction.UseTrans(l.ctx, conn.DB(), func(ctx context.Context, c transaction.Conn) error {
// 增加平评论计数
err = l.svcCtx.ArticleRepository.IncreaseCountComment(ctx, c, 1, articleInfo)
// 增加文章评论计数
err = l.svcCtx.ArticleRepository.IncreaseCountComment(ctx, c, 1, articleInfo.Id)
if err != nil {
return err
}
//增加评论回复计数
if pComment != nil {
err = l.svcCtx.ArticleCommentRepository.IncreaseCountReply(l.ctx, c, 1, pComment.Id)
if err != nil {
return err
}
}
// 增加最顶层的评论回复计数
if newComment.TopId != 0 && newComment.Pid != newComment.TopId {
err = l.svcCtx.ArticleCommentRepository.IncreaseCountReply(l.ctx, c, 1, newComment.TopId)
if err != nil {
return err
}
}
//保存评论
_, err = l.svcCtx.ArticleCommentRepository.Insert(ctx, c, &newComment)
if err != nil {
... ... @@ -171,7 +188,7 @@ func (l *MiniCreateArticleCommentLogic) MiniCreateArticleComment(req *types.Mini
Pid: newComment.Pid,
TopId: newComment.TopId,
ArtitcleId: newComment.ArticleId,
SectionId: newComment.ArticleId,
SectionId: newComment.SectionId,
FromUserId: newComment.FromUserId,
FromUser: types.CommentAuthor{
Id: newComment.FromUser.Id,
... ... @@ -192,16 +209,14 @@ func (l *MiniCreateArticleCommentLogic) MiniCreateArticleComment(req *types.Mini
CountReply: 0,
CountUserLove: 0,
CountAdminLove: 0,
AtWho: []types.CommentAuthor{},
AtWho: []types.CommentAtWho{},
CreatedAt: newComment.CreatedAt,
}
for _, val := range newComment.AtWho {
resp.AtWho = append(resp.AtWho, types.CommentAuthor{
resp.AtWho = append(resp.AtWho, types.CommentAtWho{
Id: val.Id,
Name: val.Name,
Avatar: val.Avatar,
Position: val.Position,
Company: val.Company,
})
}
... ...
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 MiniDeleteArticleCommentLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewMiniDeleteArticleCommentLogic(ctx context.Context, svcCtx *svc.ServiceContext) *MiniDeleteArticleCommentLogic {
return &MiniDeleteArticleCommentLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
// 小程序端人人员删除评论
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)
if err != nil {
return nil, xerr.NewErrMsgErr("删除评论信息失败", err)
}
if commetInfo.FromUserId != req.UserId {
return nil, xerr.NewErrMsg("没有操作权限")
}
commetInfo.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)
if err != nil {
return err
}
// 减少上级评论的回复数量
if commetInfo.Pid != 0 {
err = l.svcCtx.ArticleCommentRepository.IncreaseCountReply(l.ctx, c, -1, commetInfo.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 err != nil {
return err
}
}
return nil
}, true)
if err != nil {
return nil, xerr.NewErrMsgErr("删除评论信息失败", err)
}
resp = &types.MiniDeleteArticleCommentResponse{Id: commetInfo.Id}
return resp, nil
}
... ...
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 MiniGetArticleCommentLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewMiniGetArticleCommentLogic(ctx context.Context, svcCtx *svc.ServiceContext) *MiniGetArticleCommentLogic {
return &MiniGetArticleCommentLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
// 获取单条评论详情
func (l *MiniGetArticleCommentLogic) MiniGetArticleComment(req *types.MiniGetArticleCommentRequest) (resp *types.MiniGetArticleCommentResponse, err error) {
var conn = l.svcCtx.DefaultDBConn()
//获取主评论
commentInfo, err := l.svcCtx.ArticleCommentRepository.FindOne(l.ctx, conn, req.CommentId)
if err != nil {
return nil, xerr.NewErrMsgErr("获取评论信息失败", err)
}
if commentInfo.CompanyId != req.CompanyId {
return nil, xerr.NewErrMsg("没有查看权限")
}
if commentInfo.Show == domain.CommentShowDisable {
return nil, xerr.NewErrMsg("没有查看权限")
}
queryOption := domain.NewQueryOptions().WithFindOnly().MustWithKV("topId", commentInfo.Id).MustWithKV("show", domain.CommentShowEnable)
//获取回复的评论
_, replyCommenList, err := l.svcCtx.ArticleCommentRepository.Find(l.ctx, conn, queryOption)
if err != nil {
return nil, xerr.NewErrMsgErr("获取评论信息失败", err)
}
queryOption = domain.NewQueryOptions().WithFindOnly().
MustWithKV("articleId", commentInfo.ArticleId).
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{}{}
}
//混合数据
commentResp := types.ArticleCommentItem{
Id: commentInfo.Id,
Pid: commentInfo.Pid,
TopId: commentInfo.TopId,
ArtitcleId: commentInfo.ArticleId,
SectionId: commentInfo.ArticleId,
FromUserId: commentInfo.FromUserId,
FromUser: types.CommentAuthor{
Id: commentInfo.FromUser.Id,
Name: commentInfo.FromUser.Name,
Avatar: commentInfo.FromUser.Avatar,
Position: commentInfo.FromUser.Position,
Company: commentInfo.FromUser.Company,
},
ToUserId: commentInfo.ToUserId,
ToUser: types.CommentAuthor{
Id: commentInfo.ToUser.Id,
Name: commentInfo.ToUser.Name,
Avatar: commentInfo.ToUser.Avatar,
Position: commentInfo.ToUser.Position,
Company: commentInfo.ToUser.Company,
},
SectionContent: commentInfo.SectionContent,
CountReply: commentInfo.CountReply,
CountUserLove: commentInfo.CountUserLove,
CountAdminLove: commentInfo.CountAdminLove,
AtWho: []types.CommentAtWho{},
CreatedAt: commentInfo.CreatedAt,
MeLoveFlag: 0,
}
if _, ok := flagMap[commentInfo.Id]; ok {
commentResp.MeLoveFlag = 1
}
for _, val := range commentInfo.AtWho {
commentResp.AtWho = append(commentResp.AtWho, types.CommentAtWho{
Id: val.Id,
Name: val.Name,
})
}
// 回复的评论
allReply := []types.ArticleCommentItem{}
for _, val := range replyCommenList {
reply := 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{},
CreatedAt: val.CreatedAt,
MeLoveFlag: 0,
}
if _, ok := flagMap[val.Id]; ok {
reply.MeLoveFlag = 1
}
for _, val2 := range val.AtWho {
reply.AtWho = append(reply.AtWho, types.CommentAtWho{
Id: val2.Id,
Name: val2.Name,
})
}
allReply = append(allReply, reply)
}
resp = &types.MiniGetArticleCommentResponse{
ArticleCommentAndReply: types.ArticleCommentAndReply{
Comment: commentResp,
Reply: allReply,
TotalReply: int64(len(replyCommenList)),
},
}
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"
"github.com/zeromicro/go-zero/core/logx"
)
type MiniListArticleCommentLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewMiniListArticleCommentLogic(ctx context.Context, svcCtx *svc.ServiceContext) *MiniListArticleCommentLogic {
return &MiniListArticleCommentLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *MiniListArticleCommentLogic) MiniListArticleComment(req *types.MiniListArticleCommentRequest) (resp *types.MiniListArticleCommentResponse, err error) {
// todo: add your logic here and delete this line
return
}
... ...
... ... @@ -31,14 +31,14 @@ func (l *SystemAddLogic) SystemAdd(req *types.DepartmentAddRequest) (resp *types
var userToken = contextdata.GetUserTokenFromCtx(l.ctx)
var conn = l.svcCtx.DefaultDBConn()
_, list, err := l.svcCtx.DepartmentRepository.Find(l.ctx, conn, domain.NewQueryOptions().
WithOffsetLimit(1, 1).WithFindOnly().
total, _, err := l.svcCtx.DepartmentRepository.Find(l.ctx, conn, domain.NewQueryOptions().
WithCountOnly().
WithKV("companyId", userToken.CompanyId).
WithKV("name", req.Name))
if err != nil {
return nil, err
}
if len(list) > 0 {
if total > 0 {
return nil, xerr.NewErrMsg("该分组名称已存在(不能重复)")
}
... ...
... ... @@ -31,15 +31,15 @@ func (l *SystemUpdateLogic) SystemUpdate(req *types.DepartmentUpdateRequest) (re
var userToken = contextdata.GetUserTokenFromCtx(l.ctx)
var conn = l.svcCtx.DefaultDBConn()
_, list, err := l.svcCtx.DepartmentRepository.Find(l.ctx, conn, domain.NewQueryOptions().
WithOffsetLimit(1, 1).WithCountOnly().
total, _, err := l.svcCtx.DepartmentRepository.Find(l.ctx, conn, domain.NewQueryOptions().
WithCountOnly().
WithKV("companyId", userToken.CompanyId).
WithKV("notId", req.Id). // 排除自己
WithKV("name", req.Name))
if err != nil {
return nil, err
}
if len(list) > 0 {
if total > 0 {
return nil, xerr.NewErrMsg("该分组名称已存在(不能重复)")
}
... ... @@ -49,10 +49,59 @@ func (l *SystemUpdateLogic) SystemUpdate(req *types.DepartmentUpdateRequest) (re
}
one.Name = req.Name
// 更新分组中的用户Id
var newIdMap = map[int64]int{}
for i := range req.Ids {
newIdMap[req.Ids[i]] = 0
}
// 更新
err = transaction.UseTrans(l.ctx, conn.DB(), func(ctx context.Context, c transaction.Conn) error {
_, err = l.svcCtx.DepartmentRepository.UpdateWithVersion(l.ctx, conn, one)
if err != nil {
return err
}
// 获取公司下的所有用户
_, users, err := l.svcCtx.UserRepository.Find(l.ctx, conn, domain.NewQueryOptions().
WithFindOnly().
WithKV(" companyId", one.CompanyId))
if err != nil {
return err
}
var findIndex = func(ids []int64, id int64) int {
for i, _ := range ids {
if ids[i] == id {
return i
}
}
return -1
}
for i := range users {
var user = users[i]
if _, ok := newIdMap[user.Id]; ok {
var targetIndex = findIndex(user.Departments, req.Id)
if targetIndex == -1 { // 归属分组不存在,则新增
user.Departments = append(user.Departments)
_, err = l.svcCtx.UserRepository.UpdateWithVersion(l.ctx, conn, user)
if err != nil {
return err
}
}
} else {
var targetIndex = findIndex(user.Departments, req.Id)
if targetIndex != -1 { // 归属分组存在,则移除
user.Departments = append(user.Departments[:targetIndex], user.Departments[targetIndex+1:]...) // 移除分组ID
_, err = l.svcCtx.UserRepository.UpdateWithVersion(l.ctx, conn, user)
if err != nil {
return err
}
}
}
}
return nil
}, true)
if err != nil {
return nil, xerr.NewErrMsgErr("分组修改失败", err)
... ...
... ... @@ -11,9 +11,9 @@ type MiniArticleCommentAtUserResponse struct {
type CommentAuthor struct {
Id int64 `json:"id"` // 人员id
Name string `json:"name"` // 人员的名字
Avatar string `json:"avatar"` // 人员头像URL
Position string `json:"position"` // 职位
Company string `json:"company"` // 公司
Avatar string `json:"avatar,optional"` // 人员头像URL
Position string `json:"position,optional"` // 职位
Company string `json:"company,optional"` // 公司
}
type MiniCreateArticleCommentRequest struct {
... ... @@ -21,9 +21,14 @@ type MiniCreateArticleCommentRequest struct {
SectionId int64 `json:"sectionId"` // 段落id
FromUserId int64 `json:",optional"` // 填写文章的人,服务端自动获取
CompanyId int64 `json:",optional"` // 服务端自动获取
Pid int64 `json:"commnet"` // 回复那个评论的id
Pid int64 `json:"pid"` // 回复那个评论的id
Content string `json:"content"` // 评论的内容
AtWho []int64 `json:"atWho"` // 填写评论时@的人
AtWho []CommentAtWho `json:"atWho"` // 填写评论时@的人
}
type CommentAtWho struct {
Id int64 `json:"id"`
Name string `json:"name,optional"`
}
type MiniCreateArticleCommentResponse struct {
... ... @@ -40,7 +45,65 @@ type MiniCreateArticleCommentResponse struct {
CountReply int `json:"countReply"` // 回复数量
CountUserLove int `json:"countUserLove"` // 用户点赞数量
CountAdminLove int `json:"countAdminLove"` // 运营点赞数量
AtWho []CommentAuthor `json:"atWho"` // 填写评论时@的人
AtWho []CommentAtWho `json:"atWho"` // 填写评论时@的人
CreatedAt int64 `json:"createdAt"` //
}
type MiniListArticleCommentRequest struct {
Page int64 `json:"page"`
Size int64 `json:"size"`
CompanyId int64 `json:",optional"`
SectionId int64 `json:"sectionId"`
}
type MiniListArticleCommentResponse struct {
Total int64 `json:"total"`
List []ArticleCommentAndReply `json:"list"`
}
type ArticleCommentAndReply struct {
Comment ArticleCommentItem `json:"comment"` //评论
Reply []ArticleCommentItem `json:"reply"` //回复的评论
TotalReply int64 `json:"totalReply"` //回复的评论数量
}
type ArticleCommentItem struct {
Id int64 `json:"id"`
Pid int64 `json:"pid"`
TopId int64 `json:"topId"`
ArtitcleId int64 `json:"articleId"` // 文章id
SectionId int64 `json:"sectionId"` // 段落id
FromUserId int64 `json:"fromUserId"` // 填写评论的人
FromUser CommentAuthor `json:"fromUser"` // 填写评论的人
ToUserId int64 `json:"toUserId"` // 回复哪个人
ToUser CommentAuthor `json:"toUser"` // 回复哪个人
SectionContent string `json:"sectionContent"` // 引用的文章内容文本
CountReply int `json:"countReply"` // 回复数量
CountUserLove int `json:"countUserLove"` // 用户点赞数量
CountAdminLove int `json:"countAdminLove"` // 运营点赞数量
AtWho []CommentAtWho `json:"atWho"` // 填写评论时@的人
CreatedAt int64 `json:"createdAt"` //
MeLoveFlag int `json:"meLoveFlag"` //当前人员对评论的点赞标识 (0 没有点赞 1有点赞)
}
type MiniGetArticleCommentRequest struct {
CommentId int64 `path:"id"`
CompanyId int64 `path:",optional"`
UserId int64 `path:",optional"`
}
type MiniGetArticleCommentResponse struct {
ArticleCommentAndReply
}
type MiniDeleteArticleCommentRequest struct {
CommentId int64 `path:"id"`
UserId int64 `path:",optional"`
CompanyId int64 `path:",optional"`
}
type MiniDeleteArticleCommentResponse struct {
Id int64 `json:"id"`
}
type MessageSystemRequest struct {
... ... @@ -520,7 +583,7 @@ type MiniArticleGetResponse struct {
CountRead int `json:"countRead"` // 浏览数量
Show int `json:"show"` // 评论的展示状态(0显示、1不显示)
Edit int `json:"edit"` // 文章是否存在变更记录 (0 不存在 1存在)
MeLoveFlag int `json:"meLoveFlag"` //当前人员对文章的点赞标识
MeLoveFlag int `json:"meLoveFlag"` // 当前人员对文章的点赞标识 (0 没有点赞 1有点赞)
}
type ArticleSection struct {
... ... @@ -851,6 +914,7 @@ type DepartmentGetResponse struct {
type DepartmentUpdateRequest struct {
Id int64 `path:"id"`
Name string `json:"name"`
Ids []int64 `json:"ids"` // 用户ID
}
type DepartmentListRequest struct {
... ...
... ... @@ -9,6 +9,7 @@ import (
"gorm.io/plugin/soft_delete"
)
// 文章的所有标签
type ArticleTag struct {
Id int64 `gorm:"primaryKey"` // 唯一标识
CompanyId int64
... ...
... ... @@ -21,9 +21,13 @@ func (repository *ArticleCommentRepository) Insert(ctx context.Context, conn tra
m = &models.ArticleComment{}
tx = conn.DB()
)
if len(dm.AtWho) == 0 {
dm.AtWho = make([]domain.UserSimple, 0)
}
if m, err = repository.DomainModelToModel(dm); err != nil {
return nil, err
}
if tx = tx.Model(m).Save(m); tx.Error != nil {
return nil, tx.Error
}
... ... @@ -120,6 +124,12 @@ func (repository *ArticleCommentRepository) Find(ctx context.Context, conn trans
)
queryFunc := func() (interface{}, error) {
tx = tx.Model(&ms).Order("id desc")
if v, ok := queryOptions["topId"]; ok {
tx = tx.Where("top_id", v)
}
if v, ok := queryOptions["show"]; ok {
tx = tx.Where("show", v)
}
if total, tx = transaction.PaginationAndCount(ctx, tx, queryOptions, &ms); tx.Error != nil {
return dms, tx.Error
}
... ... @@ -162,6 +172,7 @@ func (repository *ArticleCommentRepository) ModelToDomainModel(from *models.Arti
CountUserLove: from.CountUserLove,
CountAdminLove: from.CountAdminLove,
Show: domain.CommentShow(from.Show),
AtWho: from.AtWho,
}
// err := copier.Copy(to, from)
return to, nil
... ... @@ -173,6 +184,7 @@ func (repository *ArticleCommentRepository) DomainModelToModel(from *domain.Arti
CompanyId: from.CompanyId,
CreatedAt: from.CreatedAt,
UpdatedAt: from.UpdatedAt,
IsDel: 0,
DeletedAt: from.DeletedAt,
Version: from.Version,
Pid: from.Pid,
... ... @@ -184,6 +196,7 @@ func (repository *ArticleCommentRepository) DomainModelToModel(from *domain.Arti
FromUser: from.FromUser,
ToUserId: from.ToUser.Id,
ToUser: from.ToUser,
AtWho: from.AtWho,
Content: from.Content,
CountReply: from.CountReply,
CountUserLove: from.CountUserLove,
... ... @@ -195,17 +208,34 @@ func (repository *ArticleCommentRepository) DomainModelToModel(from *domain.Arti
}
// 点赞数量变动
func (repository *ArticleCommentRepository) IncreaseCountUserLove(ctx context.Context, conn transaction.Conn, incr int, dm *domain.ArticleComment) error {
func (repository *ArticleCommentRepository) IncreaseCountUserLove(ctx context.Context, conn transaction.Conn, incr int, commnetId int64) error {
var (
err error
m *models.ArticleComment
tx = conn.DB()
)
if m, err = repository.DomainModelToModel(dm); err != nil {
m = &models.ArticleComment{Id: commnetId}
queryFunc := func() (interface{}, error) {
tx = tx.Model(m).Update("count_user_love", gorm.Expr("count_user_love+?", incr))
return nil, tx.Error
}
if _, err = repository.Query(queryFunc, m.CacheKeyFunc()); err != nil {
return err
}
return nil
}
// 点赞数量变动
func (repository *ArticleCommentRepository) IncreaseCountReply(ctx context.Context, conn transaction.Conn, incr int, commnetId int64) error {
var (
err error
m *models.ArticleComment
tx = conn.DB()
)
m = &models.ArticleComment{Id: commnetId}
queryFunc := func() (interface{}, error) {
tx = tx.Model(m).Update("count_user_love", gorm.Expr("count_user_love+?", incr))
tx = tx.Model(m).Update("count_reply", gorm.Expr("count_reply+?", incr))
return nil, tx.Error
}
if _, err = repository.Query(queryFunc, m.CacheKeyFunc()); err != nil {
... ...
... ... @@ -203,16 +203,14 @@ func (repository *ArticleRepository) DomainModelToModel(from *domain.Article) (*
}
// 点赞数量变动
func (repository *ArticleRepository) IncreaseCountLove(ctx context.Context, conn transaction.Conn, incr int, dm *domain.Article) error {
func (repository *ArticleRepository) IncreaseCountLove(ctx context.Context, conn transaction.Conn, incr int, articleId int64) error {
//
var (
err error
m *models.Article
tx = conn.DB()
)
if m, err = repository.DomainModelToModel(dm); err != nil {
return err
}
m = &models.Article{Id: articleId}
queryFunc := func() (interface{}, error) {
tx = tx.Model(m).Updates(map[string]interface{}{
"count_love": gorm.Expr("count_love+?", incr),
... ... @@ -227,15 +225,13 @@ func (repository *ArticleRepository) IncreaseCountLove(ctx context.Context, conn
}
// 浏览数量变动
func (repository *ArticleRepository) IncreaseCountRead(ctx context.Context, conn transaction.Conn, incr int, dm *domain.Article) error {
func (repository *ArticleRepository) IncreaseCountRead(ctx context.Context, conn transaction.Conn, incr int, articleId int64) error {
var (
err error
m *models.Article
tx = conn.DB()
)
if m, err = repository.DomainModelToModel(dm); err != nil {
return err
}
m = &models.Article{Id: articleId}
queryFunc := func() (interface{}, error) {
tx = tx.Model(m).Updates(map[string]interface{}{
"version": gorm.Expr("version+1"),
... ... @@ -250,15 +246,13 @@ func (repository *ArticleRepository) IncreaseCountRead(ctx context.Context, conn
}
// 评论数量变动
func (repository *ArticleRepository) IncreaseCountComment(ctx context.Context, conn transaction.Conn, incr int, dm *domain.Article) error {
func (repository *ArticleRepository) IncreaseCountComment(ctx context.Context, conn transaction.Conn, incr int, articleId int64) error {
var (
err error
m *models.Article
tx = conn.DB()
)
if m, err = repository.DomainModelToModel(dm); err != nil {
return err
}
m = &models.Article{Id: articleId}
queryFunc := func() (interface{}, error) {
tx = tx.Model(m).Updates(map[string]interface{}{
"version": gorm.Expr("version+1"),
... ...
... ... @@ -38,9 +38,9 @@ type ArticleRepository interface {
UpdateWithVersion(ctx context.Context, conn transaction.Conn, dm *Article) (*Article, error)
FindOne(ctx context.Context, conn transaction.Conn, id int64) (*Article, error)
Find(ctx context.Context, conn transaction.Conn, companyId int64, queryOptions map[string]interface{}) (int64, []*Article, error)
IncreaseCountLove(ctx context.Context, conn transaction.Conn, incr int, dm *Article) error //点赞数量变动
IncreaseCountComment(ctx context.Context, conn transaction.Conn, incr int, dm *Article) error //评论数量变动
IncreaseCountRead(ctx context.Context, conn transaction.Conn, incr int, dm *Article) error //浏览数量变动
IncreaseCountLove(ctx context.Context, conn transaction.Conn, incr int, articleId int64) error //点赞数量变动
IncreaseCountComment(ctx context.Context, conn transaction.Conn, incr int, articleId int64) error //评论数量变动
IncreaseCountRead(ctx context.Context, conn transaction.Conn, incr int, articleId int64) error //浏览数量变动
}
type ArticleTarget int
... ...
... ... @@ -40,6 +40,16 @@ const (
CommentShowDisable CommentShow = 1
)
func (show CommentShow) Named() string {
switch show {
case CommentShowEnable:
return "显示"
case CommentShowDisable:
return "隐藏"
}
return ""
}
type ArticleCommentRepository interface {
Insert(ctx context.Context, conn transaction.Conn, dm *ArticleComment) (*ArticleComment, error)
Update(ctx context.Context, conn transaction.Conn, dm *ArticleComment) (*ArticleComment, error)
... ... @@ -47,5 +57,6 @@ type ArticleCommentRepository interface {
Delete(ctx context.Context, conn transaction.Conn, dm *ArticleComment) (*ArticleComment, error)
FindOne(ctx context.Context, conn transaction.Conn, id int64) (*ArticleComment, error)
Find(ctx context.Context, conn transaction.Conn, queryOptions map[string]interface{}) (int64, []*ArticleComment, error)
IncreaseCountUserLove(ctx context.Context, conn transaction.Conn, incr int, dm *ArticleComment) error //点赞数量变动
IncreaseCountUserLove(ctx context.Context, conn transaction.Conn, incr int, commentId int64) error //点赞数量变动
IncreaseCountReply(ctx context.Context, conn transaction.Conn, incr int, commentId int64) error // 评论回复数量变动
}
... ...