作者 tangxvhui

Merge branch 'dev-tangxvhui' into dev

... ... @@ -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)
}
//
... ... @@ -72,5 +84,68 @@ type (
CountUserLove int `json:"countUserLove"` // 用户点赞数量
CountAdminLove int `json:"countAdminLove"` // 运营点赞数量
AtWho []CommentAuthor `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 []CommentAuthor `json:"atWho"` // 填写评论时@的人
CreatedAt int64 `json:"createdAt"` //
MeLoveFlag int `json:"meLoveFlag"` //当前人员对评论的点赞标识 (0 没有点赞 1有点赞)
}
)
// 小程序获取单个文章的评论
type (
MiniGetArticleCommentRequest {
CommentId int64 `path:"commentId"`
CompanyId int64 `json:",optional"`
}
MiniGetArticleCommentResponse {
ArticleCommentAndReply
}
)
// 小程序删除单个文章的评论
type (
MiniDeleteArticleCommentRequest {
CommentId int64 `json:"commentId"`
UserId int64 `json:",optional"`
CompanyId int64 `json:",optional"`
}
MiniDeleteArticleCommentResponse {
Id int64 `json:"id"`
}
)
\ No newline at end of file
... ...
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"),
... ...
... ... @@ -149,11 +149,18 @@ 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)
if err != nil {
return err
}
//增加评论回复计数
if pComment != nil {
err = l.svcCtx.ArticleCommentRepository.IncreaseCountReply(l.ctx, c, 1, pComment)
if err != nil {
return err
}
}
//保存评论
_, err = l.svcCtx.ArticleCommentRepository.Insert(ctx, c, &newComment)
if err != nil {
... ... @@ -193,6 +200,7 @@ func (l *MiniCreateArticleCommentLogic) MiniCreateArticleComment(req *types.Mini
CountUserLove: 0,
CountAdminLove: 0,
AtWho: []types.CommentAuthor{},
CreatedAt: newComment.CreatedAt,
}
for _, val := range newComment.AtWho {
... ...
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 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) {
// todo: add your logic here and delete this line
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/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("没有查看权限")
}
queryOption := domain.NewQueryOptions().MustWithKV("topId", commentInfo.Id).WithFindOnly()
//获取回复的评论
_, replyCommenList, err := l.svcCtx.ArticleCommentRepository.Find(l.ctx, conn, queryOption)
if err != nil {
return nil, xerr.NewErrMsgErr("获取评论信息失败", err)
}
//TODO 获取我点赞的评论
//混合数据
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.CommentAuthor{},
CreatedAt: commentInfo.CreatedAt,
}
for _, val := range commentInfo.AtWho {
commentResp.AtWho = append(commentResp.AtWho, types.CommentAuthor{
Id: val.Id,
Name: val.Name,
Avatar: val.Avatar,
Position: val.Position,
Company: val.Company,
})
}
allReply := []types.ArticleCommentItem{}
for _, val := range replyCommenList {
reply := types.ArticleCommentItem{
Id: val.Id,
Pid: val.Pid,
TopId: val.TopId,
ArtitcleId: val.ArticleId,
SectionId: val.ArticleId,
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.CommentAuthor{},
CreatedAt: val.CreatedAt,
MeLoveFlag: 0,
}
for _, val2 := range val.AtWho {
reply.AtWho = append(reply.AtWho, types.CommentAuthor{
Id: val2.Id,
Name: val2.Name,
Avatar: val2.Avatar,
Position: val2.Position,
Company: val2.Company,
})
}
}
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
}
... ...
... ... @@ -41,6 +41,63 @@ type MiniCreateArticleCommentResponse struct {
CountUserLove int `json:"countUserLove"` // 用户点赞数量
CountAdminLove int `json:"countAdminLove"` // 运营点赞数量
AtWho []CommentAuthor `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 []CommentAuthor `json:"atWho"` // 填写评论时@的人
CreatedAt int64 `json:"createdAt"` //
MeLoveFlag int `json:"meLoveFlag"` //当前人员对评论的点赞标识 (0 没有点赞 1有点赞)
}
type MiniGetArticleCommentRequest struct {
CommentId int64 `path:"commentId"`
CompanyId int64 `json:",optional"`
}
type MiniGetArticleCommentResponse struct {
ArticleCommentAndReply
}
type MiniDeleteArticleCommentRequest struct {
CommentId int64 `json:"commentId"`
UserId int64 `json:",optional"`
CompanyId int64 `json:",optional"`
}
type MiniDeleteArticleCommentResponse struct {
Id int64 `json:"id"`
}
type MessageSystemRequest struct {
... ... @@ -520,7 +577,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 {
... ...
... ... @@ -120,6 +120,9 @@ 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 total, tx = transaction.PaginationAndCount(ctx, tx, queryOptions, &ms); tx.Error != nil {
return dms, tx.Error
}
... ... @@ -215,6 +218,27 @@ func (repository *ArticleCommentRepository) IncreaseCountUserLove(ctx context.Co
}
// 点赞数量变动
func (repository *ArticleCommentRepository) IncreaseCountReply(ctx context.Context, conn transaction.Conn, incr int, dm *domain.ArticleComment) error {
var (
err error
m *models.ArticleComment
tx = conn.DB()
)
if m, err = repository.DomainModelToModel(dm); err != nil {
return err
}
queryFunc := func() (interface{}, error) {
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 {
return err
}
return nil
}
func NewArticleCommentRepository(cache *cache.CachedRepository) domain.ArticleCommentRepository {
return &ArticleCommentRepository{CachedRepository: cache}
}
... ...
... ... @@ -48,4 +48,5 @@ type ArticleCommentRepository interface {
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 //点赞数量变动
IncreaseCountReply(ctx context.Context, conn transaction.Conn, incr int, dm *ArticleComment) error // 评论回复数量变动
}
... ...