作者 tangxvhui

调试 文章标签设置

... ... @@ -2,6 +2,7 @@ package article
import (
"context"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/contextdata"
... ... @@ -25,6 +26,7 @@ func NewMiniArticleMarkListLogic(ctx context.Context, svcCtx *svc.ServiceContext
}
}
// 获取我的文章浏览记录
func (l *MiniArticleMarkListLogic) MiniArticleMarkList(req *types.MiniArticleMarkListRequest) (resp *types.MiniArticleMarkListResponse, err error) {
var userToken = contextdata.GetUserTokenFromCtx(l.ctx)
... ...
... ... @@ -5,6 +5,9 @@ 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/cmd/discuss/interanl/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/xerr"
"github.com/zeromicro/go-zero/core/logx"
)
... ... @@ -25,7 +28,57 @@ func NewMiniArticleSetTagLogic(ctx context.Context, svcCtx *svc.ServiceContext)
// 设置文章的定性标签
func (l *MiniArticleSetTagLogic) MiniArticleSetTag(req *types.MiniArticleSetTagRequest) (resp *types.MiniArticleSetTagResponse, err error) {
var conn = l.svcCtx.DefaultDBConn()
//
return
articleInfo, err := l.svcCtx.ArticleRepository.FindOne(l.ctx, conn, req.ArticleId)
if err != nil {
return nil, xerr.NewErrMsgErr("获取文章信息失败", err)
}
tagInfo, err := l.svcCtx.ArticleTagRepository.FindOne(l.ctx, conn, req.TagId)
if err != nil {
return nil, xerr.NewErrMsgErr("获取标签信息失败", err)
}
// 查询可能存在的 ArticleAndTag
queryOption := domain.NewQueryOptions().WithFindOnly().MustWithKV("articleId", articleInfo.Id)
_, oldTags, err := l.svcCtx.ArticleAndTagRepository.Find(l.ctx, conn, queryOption)
if err != nil {
return nil, xerr.NewErrMsgErr("检查文章的标签失败", err)
}
articleInfo.Tags = []int64{tagInfo.Id}
// 额外保存一份ArticleAndTag
articleAndTag := domain.ArticleAndTag{
Id: 0,
CompanyId: articleInfo.CompanyId,
CreatedAt: 0,
UpdatedAt: 0,
ArticleId: articleInfo.Id,
TagId: tagInfo.Id,
}
err = transaction.UseTrans(l.ctx, conn.DB(), func(ctx context.Context, c transaction.Conn) error {
//清理可能存在的 ArticleAndTag
for _, v := range oldTags {
_, err = l.svcCtx.ArticleAndTagRepository.Delete(ctx, c, v)
if err != nil {
return err
}
}
// 更新article
_, err = l.svcCtx.ArticleRepository.UpdateWithVersion(ctx, c, articleInfo)
if err != nil {
return err
}
_, err = l.svcCtx.ArticleAndTagRepository.Insert(ctx, c, &articleAndTag)
if err != nil {
return err
}
return nil
}, true)
resp = &types.MiniArticleSetTagResponse{
Id: articleAndTag.Id,
}
return resp, nil
}
... ...
... ... @@ -26,6 +26,7 @@ type ServiceContext struct {
ArticleRepository domain.ArticleRepository
ArticleSectionRepository domain.ArticleSectionRepository
ArticleTagRepository domain.ArticleTagRepository
ArticleAndTagRepository domain.ArticleAndTagRepository
CompanyRepository domain.CompanyRepository
CommentRepository domain.CommentRepository // 待移除
... ... @@ -59,12 +60,14 @@ func NewServiceContext(c config.Config) *ServiceContext {
ApiAuthService: apiAuth,
LoginStatusCheck: middleware.NewLoginStatusCheckMiddleware(apiAuth).Handle,
CommentRepository: repository.NewCommentRepository(cache.NewCachedRepository(mlCache)),
ArticleBackupRepository: repository.NewArticleBackupRepository(cache.NewCachedRepository(mlCache)),
ArticleCommentRepository: repository.NewArticleCommentRepository(cache.NewCachedRepository(mlCache)),
ArticleDraftRepository: repository.NewArticleDraftRepository(cache.NewCachedRepository(mlCache)),
ArticleRepository: repository.NewArticleRepository(cache.NewCachedRepository(mlCache)),
ArticleSectionRepository: repository.NewArticleSectionRepository(cache.NewCachedRepository(mlCache)),
CommentRepository: repository.NewCommentRepository(cache.NewCachedRepository(mlCache)),
ArticleBackupRepository: repository.NewArticleBackupRepository(cache.NewCachedRepository(mlCache)),
ArticleCommentRepository: repository.NewArticleCommentRepository(cache.NewCachedRepository(mlCache)),
ArticleDraftRepository: repository.NewArticleDraftRepository(cache.NewCachedRepository(mlCache)),
ArticleRepository: repository.NewArticleRepository(cache.NewCachedRepository(mlCache)),
ArticleSectionRepository: repository.NewArticleSectionRepository(cache.NewCachedRepository(mlCache)),
ArticleAndTagRepository: repository.NewArticleAndTagRepository(cache.NewCachedRepository(mlCache)),
CompanyRepository: repository.NewCompanyRepository(cache.NewCachedRepository(mlCache)),
DepartmentRepository: repository.NewDepartmentRepository(cache.NewCachedRepository(mlCache)),
MessageBusinessRepository: repository.NewMessageBusinessRepository(cache.NewCachedRepository(mlCache)),
... ...
... ... @@ -97,6 +97,9 @@ func (repository *ArticleAndTagRepository) Find(ctx context.Context, conn transa
)
queryFunc := func() (interface{}, error) {
tx = tx.Model(&ms).Order("id desc")
if v, ok := queryOptions["articleId"]; ok {
tx = tx.Where("article_id=?", v)
}
if total, tx = transaction.PaginationAndCount(ctx, tx, queryOptions, &ms); tx.Error != nil {
return dms, tx.Error
}
... ...
... ... @@ -14,8 +14,8 @@ type ArticleBackup struct {
UpdatedAt int64 `json:"updatedAt,omitempty"`
DeletedAt int64 `json:"deletedAt,omitempty"`
Version int `json:"version,omitempty"`
Operator UserSimple `json:"operator"` // 操作人
ArticleId int64 `json:"articleId"`
Operator UserSimple `json:"operator"` // 操作人
ArticleId int64 `json:"articleId"` //
Title string `json:"title"` // 标题
Section []ArticleSection `json:"section"` // 分段内容
Images []Image `json:"images"` // 图片
... ...
... ... @@ -29,11 +29,9 @@ type Opinion struct {
}
type UserSimple struct {
Id int64 `json:"id"` // 人员id
Name string `json:"name"` // 人员的名字
Avatar string `json:"avatar,omitempty"` // 人员头像URL
// GroupId int64 `json:"groupId"` //分组id
//Group string `json:"group,omitempty"` // 人员的分组
Id int64 `json:"id"` // 人员id
Name string `json:"name"` // 人员的名字
Avatar string `json:"avatar,omitempty"` // 人员头像URL
Position string `json:"position,omitempty"` // 职位
Company string `json:"company,omitempty"` // 公司
CompanyId int64 `json:"companyId"`
... ...