作者 yangfu
... ... @@ -313,14 +313,16 @@ type (
TagId int64 `json:"tagId"` // 标签id
}
MiniAllArticleTagResponse{
TagGroup []string `json:"tagGroup"`
Tags []ArticleTagItem `json:"tags"`
TagGroup []ArticleTagGroup `json:"tagGroup"`
}
ArticleTagGroup {
Group string `json:"group"`
Tags []ArticleTagItem `json:"tags"`
}
ArticleTagItem {
Id int64 `json:"id"`
Group string `json:"group"`
Name string `json:"name"`
Name string `json:"name"`
}
)
... ...
... ... @@ -7,6 +7,8 @@ import (
"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 MiniArticleCommentAtWhoHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
... ... @@ -18,11 +20,10 @@ func MiniArticleCommentAtWhoHandler(svcCtx *svc.ServiceContext) http.HandlerFunc
}
l := comment.NewMiniArticleCommentAtWhoLogic(r.Context(), svcCtx)
token := contextdata.GetUserTokenFromCtx(r.Context())
req.CompanyId = token.CompanyId
req.UserId = token.UserId
resp, err := l.MiniArticleCommentAtWho(&req)
if err != nil {
httpx.ErrorCtx(r.Context(), w, err)
} else {
httpx.OkJsonCtx(r.Context(), w, resp)
}
result.HttpResult(r, w, resp, err)
}
}
... ...
... ... @@ -2,6 +2,7 @@ package article
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"
... ... @@ -97,6 +98,14 @@ func (l *MiniSetUserLikeLogic) cancelSetUserLikeArticle(req *types.MiniSetUserLi
if err != nil {
return err
}
// 删除点赞文章消息
var messageLogic = message.NewMiniBusinessLogic(l.ctx, l.svcCtx)
err = messageLogic.UnLikeArticle(c, articleInfo.Id)
if err != nil {
return err
}
return nil
}, true)
if err != nil {
... ... @@ -170,6 +179,14 @@ func (l *MiniSetUserLikeLogic) cancelSetUserLikeComment(req *types.MiniSetUserLi
if err != nil {
return err
}
// 删除点赞评论消息
var messageLogic = message.NewMiniBusinessLogic(l.ctx, l.svcCtx)
err = messageLogic.UnLikeComment(c, commentInfo.ArticleId, commentInfo.Id)
if err != nil {
return err
}
return nil
}, true)
if err != nil {
... ... @@ -243,6 +260,14 @@ func (l *MiniSetUserLikeLogic) setUserLikeArticle(req *types.MiniSetUserLikeRequ
if err != nil {
return err
}
// 创建点赞消息
var messageLogic = message.NewMiniBusinessLogic(l.ctx, l.svcCtx)
err = messageLogic.LikeArticle(c, articleInfo.Id, articleInfo.AuthorId)
if err != nil {
return err
}
return nil
}, true)
if err != nil {
... ... @@ -324,6 +349,14 @@ func (l *MiniSetUserLikeLogic) setUserLikeComment(req *types.MiniSetUserLikeRequ
if err != nil {
return err
}
// 创建点赞消息
var messageLogic = message.NewMiniBusinessLogic(l.ctx, l.svcCtx)
err = messageLogic.LikeComment(c, commentInfo.ArticleId, commentInfo.Id, commentInfo.FromUserId)
if err != nil {
return err
}
return nil
}, true)
if err != nil {
... ...
... ... @@ -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/pkg/xerr"
"github.com/zeromicro/go-zero/core/logx"
)
... ... @@ -24,7 +25,21 @@ func NewMiniArticleCommentAtWhoLogic(ctx context.Context, svcCtx *svc.ServiceCon
}
func (l *MiniArticleCommentAtWhoLogic) MiniArticleCommentAtWho(req *types.MiniArticleCommentAtWhoRequest) (resp *types.MiniArticleCommentAtWhoResponse, err error) {
// todo: add your logic here and delete this line
var conn = l.svcCtx.DefaultDBConn()
articleInfo, err := l.svcCtx.ArticleRepository.FindOne(l.ctx, conn, req.ArticleId)
if err != nil {
return nil, xerr.NewErrMsgErr("获取评论人信息失败", err)
}
if articleInfo.CompanyId != req.CompanyId {
resp = &types.MiniArticleCommentAtWhoResponse{}
return resp, nil
}
// userList := []*domain.User{}
// if len(articleInfo.WhoRead) == 0 {
// return
// }
return
}
... ...
... ... @@ -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"
... ... @@ -12,6 +13,7 @@ import (
"text/template"
"github.com/samber/lo"
"github.com/zeromicro/go-zero/core/logx"
)
... ... @@ -88,11 +90,15 @@ func (l *MiniCreateArticleCommentLogic) MiniCreateArticleComment(req *types.Mini
for _, val := range req.AtWho {
atWhoIds = append(atWhoIds, val.Id)
}
atWhoIds = lo.Uniq(atWhoIds)
queryOption := domain.NewQueryOptions().WithFindOnly().WithKV("ids", atWhoIds)
_, atWhoList, err = l.svcCtx.UserRepository.Find(l.ctx, conn, queryOption)
if err != nil {
return nil, xerr.NewErrMsgErr("检查@的人员失败", err)
}
if len(atWhoIds) != len(atWhoList) {
return nil, xerr.NewErrMsg("检查@的人员失败")
}
}
// 处理文本内容
content := template.HTMLEscapeString(req.Content)
... ...
... ... @@ -222,8 +222,18 @@ func (l *MiniBusinessLogic) LikeArticle(conn transaction.Conn, articleId int64,
}
// LikeComment 点赞评论
func (l *MiniBusinessLogic) LikeComment(conn transaction.Conn, articleId int64, sectionId int64, commentId int64, at int64) (err error) {
return l.createMessage(conn, domain.MsgTypeLike, domain.OptTypeComment, articleId, sectionId, commentId, "", []int64{at})
func (l *MiniBusinessLogic) LikeComment(conn transaction.Conn, articleId int64, commentId int64, at int64) (err error) {
return l.createMessage(conn, domain.MsgTypeLike, domain.OptTypeComment, articleId, 0, commentId, "", []int64{at})
}
// UnLikeArticle 取消点赞文章
func (l *MiniBusinessLogic) UnLikeArticle(conn transaction.Conn, articleId int64) (err error) {
return l.deleteMessage(conn, domain.OptTypeArticle, articleId, 0)
}
// UnLikeComment 取消点赞评论
func (l *MiniBusinessLogic) UnLikeComment(conn transaction.Conn, articleId int64, commentId int64) (err error) {
return l.deleteMessage(conn, domain.OptTypeComment, articleId, commentId)
}
func (l *MiniBusinessLogic) createMessage(
... ... @@ -257,3 +267,27 @@ func (l *MiniBusinessLogic) createMessage(
}
return nil
}
func (l *MiniBusinessLogic) deleteMessage(conn transaction.Conn, optType domain.MsgBusinessOpt, articleId int64, commentId int64) (err error) {
var userToken = contextdata.GetUserTokenFromCtx(l.ctx)
queryOption := domain.NewQueryOptions().WithFindOnly().WithOffsetLimit(1, 1).
MustWithKV("type", domain.MsgTypeLike).
MustWithKV("optType", optType).
MustWithKV("companyId", userToken.CompanyId).
MustWithKV("recipientId", userToken.UserId).
MustWithKV("articleId", articleId).
MustWithKV("commentId", commentId)
_, list, err := l.svcCtx.MessageBusinessRepository.Find(l.ctx, conn, queryOption)
if err != nil {
return err
}
for i := range list {
_, err = l.svcCtx.MessageBusinessRepository.Delete(l.ctx, conn, list[i])
if err != nil {
return err
}
}
return nil
}
... ...
... ... @@ -852,8 +852,12 @@ type MiniAllArticleTagRequest struct {
}
type MiniAllArticleTagResponse struct {
TagGroup []string `json:"tagGroup"`
Tags []ArticleTagItem `json:"tags"`
TagGroup []ArticleTagGroup `json:"tagGroup"`
}
type ArticleTagGroup struct {
Group string `json:"group"`
Tags []ArticleTagItem `json:"tags"`
}
type ArticleTagItem struct {
... ...
... ... @@ -8,6 +8,7 @@ import (
"gorm.io/gorm"
)
// 保存文章和标签的关系,主要用于分组统计用
type ArticleAndTag struct {
Id int64 // 唯一标识
CompanyId int64 `json:"companyId"`
... ... @@ -28,7 +29,7 @@ func (m *ArticleAndTag) BeforeCreate(tx *gorm.DB) (err error) {
}
func (m *ArticleAndTag) BeforeUpdate(tx *gorm.DB) (err error) {
// m.UpdatedAt = time.Now().Unix()
m.UpdatedAt = time.Now().Unix()
return
}
... ...
... ... @@ -22,6 +22,7 @@ type ArticleTag struct {
Name string // 标签名称
Group string // 标签分类
Remark string // 备注
SortBy int64 // 顺序
}
func (m *ArticleTag) TableName() string {
... ...
... ... @@ -121,9 +121,24 @@ func (repository *MessageBusinessRepository) Find(ctx context.Context, conn tran
)
queryFunc := func() (interface{}, error) {
tx = tx.Model(&ms).Order("id desc")
if v, ok := queryOptions["type"]; ok {
tx.Where("type = ?", v)
}
if v, ok := queryOptions["optType"]; ok {
tx.Where("opt_type = ?", v)
}
if v, ok := queryOptions["companyId"]; ok {
tx.Where("company_id = ?", v)
}
if v, ok := queryOptions["recipientId"]; ok {
tx.Where("recipient_id = ?", v)
}
if v, ok := queryOptions["articleId"]; ok {
tx.Where("article_id = ?", v)
}
if v, ok := queryOptions["commentId"]; ok {
tx.Where("comment_id = ?", v)
}
if total, tx = transaction.PaginationAndCount(ctx, tx, queryOptions, &ms); tx.Error != nil {
return dms, tx.Error
}
... ...
... ... @@ -19,6 +19,7 @@ type ArticleTag struct {
Name string `json:"name"` // 标签名称
Group string `json:"group"` // 标签分类
Remark string `json:"remark"` // 备注
SortBy int64 `json:"sortBy"` // 顺序
}
type ArticleTagRepository interface {
Insert(ctx context.Context, conn transaction.Conn, dm *ArticleTag) (*ArticleTag, error)
... ...
... ... @@ -36,7 +36,7 @@ const (
const (
OptTypeArticle MsgBusinessOpt = 1 // 操作分类-针对文章
OptTypeComment MsgBusinessOpt = 2 // 操作分类-针对评论()
OptTypeComment MsgBusinessOpt = 2 // 操作分类-针对评论
OptTypeDiscussion MsgBusinessOpt = 3 // 操作分类-针对讨论
)
... ...