作者 庄敏学

合并分支 'dev' 到 'test'

Dev



查看合并请求 !9
... ... @@ -111,6 +111,34 @@
]
}
},
"v1/mini/article/delete": {
"delete": {
"summary": "小程序删除我的帖子",
"operationId": "MiniArticleDelete",
"responses": {
"200": {
"description": "A successful response.",
"schema": {
"$ref": "#/definitions/MiniArticleDeleteResponse"
}
}
},
"parameters": [
{
"name": "body",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/MiniArticleDeleteRequest"
}
}
],
"requestBody": {},
"tags": [
"article"
]
}
},
"v1/mini/article/mark/list": {
"post": {
"summary": "小程序获取文章浏览记录",
... ... @@ -223,6 +251,34 @@
]
}
},
"v1/mini/article/set_view": {
"post": {
"summary": "小程序我的帖子设置可见范围",
"operationId": "MiniArticleSetView",
"responses": {
"200": {
"description": "A successful response.",
"schema": {
"$ref": "#/definitions/MiniArticleSetViewResponse"
}
}
},
"parameters": [
{
"name": "body",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/MiniArticleSetViewRequest"
}
}
],
"requestBody": {},
"tags": [
"article"
]
}
},
"v1/mini/article/user_like/list": {
"post": {
"summary": "小程序获取文章的点赞人员列表",
... ... @@ -2211,6 +2267,22 @@
]
}
},
"v1/system/article_category/init": {
"get": {
"summary": "标签分类初始化",
"operationId": "articleCategoryInit",
"responses": {
"200": {
"description": "A successful response.",
"schema": {}
}
},
"requestBody": {},
"tags": [
"tags"
]
}
},
"v1/system/article_category/options": {
"get": {
"summary": "标签分类下拉列表",
... ... @@ -2223,6 +2295,16 @@
}
}
},
"parameters": [
{
"name": "enable",
"description": " 启用状态 1:启用",
"in": "query",
"required": false,
"type": "integer",
"format": "int32"
}
],
"requestBody": {},
"tags": [
"tags"
... ... @@ -3670,6 +3752,19 @@
"type": "integer",
"format": "int32",
"description": "是否隐藏 [0显示、1不显示]"
},
"targetUser": {
"type": "integer",
"format": "int32",
"description": "分发方式 [0分发给所有人、1分发给指定的人]"
},
"whoRead": {
"type": "array",
"items": {
"type": "integer",
"format": "int64"
},
"description": "谁可查看"
}
},
"title": "ArticleSearchMe",
... ... @@ -3681,7 +3776,9 @@
"countLove",
"countComment",
"countRead",
"show"
"show",
"targetUser",
"whoRead"
]
},
"ArticleSection": {
... ... @@ -3881,10 +3978,10 @@
"CategoryOptionsRequest": {
"type": "object",
"properties": {
"": {
"enable": {
"type": "integer",
"format": "int64",
"description": " 公司ID"
"format": "int32",
"description": " 启用状态 1:启用"
}
},
"title": "CategoryOptionsRequest"
... ... @@ -4702,6 +4799,39 @@
"id"
]
},
"MiniArticleDeleteRequest": {
"type": "object",
"properties": {
"id": {
"type": "integer",
"format": "int64",
"description": "id"
}
},
"title": "MiniArticleDeleteRequest",
"required": [
"id"
]
},
"MiniArticleDeleteResponse": {
"type": "object",
"properties": {
"id": {
"type": "integer",
"format": "int64",
"description": "id"
},
"title": {
"type": "string",
"description": "标题"
}
},
"title": "MiniArticleDeleteResponse",
"required": [
"id",
"title"
]
},
"MiniArticleDraftCreateRequest": {
"type": "object",
"properties": {
... ... @@ -5475,6 +5605,57 @@
"id"
]
},
"MiniArticleSetViewRequest": {
"type": "object",
"properties": {
"id": {
"type": "integer",
"format": "int64",
"description": "id"
},
"whoRead": {
"type": "array",
"items": {
"type": "integer",
"format": "int64"
},
"description": "谁可查看"
}
},
"title": "MiniArticleSetViewRequest",
"required": [
"id",
"whoRead"
]
},
"MiniArticleSetViewResponse": {
"type": "object",
"properties": {
"id": {
"type": "integer",
"format": "int64",
"description": "id"
},
"title": {
"type": "string",
"description": "标题"
},
"whoRead": {
"type": "array",
"items": {
"type": "integer",
"format": "int64"
},
"description": "谁可查看"
}
},
"title": "MiniArticleSetViewResponse",
"required": [
"id",
"title",
"whoRead"
]
},
"MiniBeLikedRequest": {
"type": "object",
"properties": {
... ... @@ -8034,6 +8215,13 @@
},
"description": "谁可查看"
},
"whoReadInfo": {
"type": "array",
"items": {
"$ref": "#/definitions/UserShowName"
},
"description": " 谁可查看"
},
"whoReview": {
"type": "array",
"items": {
... ... @@ -8042,6 +8230,13 @@
},
"description": "谁可评论"
},
"whoReviewInfo": {
"type": "array",
"items": {
"$ref": "#/definitions/UserShowName"
},
"description": " 谁可评论"
},
"matchUrl": {
"type": "object",
"description": " 匹配文章内容中的url文本"
... ... @@ -8062,6 +8257,8 @@
"content",
"authorId",
"targetUser",
"whoReadInfo",
"whoReviewInfo",
"tags"
]
},
... ... @@ -10104,10 +10301,6 @@
"type": "string",
"description": " 标签名称"
},
"category": {
"type": "string",
"description": " 标签分类"
},
"remark": {
"type": "string",
"description": " 备注"
... ... @@ -10119,13 +10312,18 @@
"type": "integer",
"format": "int32",
"description": "排序"
},
"categoryId": {
"type": "integer",
"format": "int64",
"description": " 标签Id"
}
},
"title": "TagCreateRequest",
"required": [
"image",
"name",
"category"
"categoryId"
]
},
"TagCreateResponse": {
... ... @@ -10189,9 +10387,10 @@
"type": "string",
"description": " 标签名称"
},
"category": {
"type": "string",
"description": " 标签分类"
"categoryId": {
"type": "integer",
"format": "int64",
"description": " 标签Id"
},
"remark": {
"type": "string",
... ... @@ -10211,7 +10410,7 @@
"id",
"image",
"name",
"category"
"categoryId"
]
},
"TagEditResponse": {
... ... @@ -10262,6 +10461,11 @@
"type": "string",
"description": " 标签分类"
},
"categoryId": {
"type": "integer",
"format": "int64",
"description": " 标签分类Id"
},
"remark": {
"type": "string",
"description": " 备注"
... ... @@ -10281,6 +10485,7 @@
"image",
"name",
"category",
"categoryId",
"remark",
"other"
]
... ... @@ -10303,6 +10508,11 @@
"type": "string",
"description": " 标签分类"
},
"categoryId": {
"type": "integer",
"format": "int64",
"description": " 标签分类Id"
},
"remark": {
"type": "string",
"description": " 备注"
... ... @@ -10315,6 +10525,11 @@
"type": "integer",
"format": "int32",
"description": " 排序"
},
"removeable": {
"type": "boolean",
"format": "boolean",
"description": " 可删除"
}
},
"title": "TagItem",
... ... @@ -10323,6 +10538,7 @@
"image",
"name",
"category",
"categoryId",
"remark",
"createdAt"
]
... ... @@ -10345,8 +10561,9 @@
"tagName": {
"type": "string"
},
"category": {
"type": "string"
"categoryId": {
"type": "integer",
"format": "int64"
},
"remark": {
"type": "string"
... ...
... ... @@ -19,12 +19,15 @@ service Core {
@doc "小程序创建发布内容"
@handler MiniCreateArticle
post /article (MiniArticleCreateRequest) returns (MiniArticleCreateResponse)
@doc "小程序获取文章内容详情"
@handler MiniGetArticle
get /article/:id (MiniArticleGetRequest) returns (MiniArticleGetResponse)
@doc "小程序获取文章的点赞人员列表"
@handler MiniUserLikeArticle
post /article/user_like/list (MiniUserLikeArticleRequest) returns (MiniUserLikeArticleResponse)
@doc "小程序人员操作点赞文章/评论"
@handler MiniSetUserLike
post /article/user_like/set (MiniSetUserLikeRequset) returns (MiniSetUserLikeResponse)
... ... @@ -41,6 +44,14 @@ service Core {
@handler MiniArticleSearchMe
post /article/search/me (MiniArticleSearchMeRequest) returns (MiniArticleSearchMeResponse)
@doc "小程序我的帖子设置可见范围"
@handler MiniArticleSetView
post /article/set_view (MiniArticleSetViewRequest) returns (MiniArticleSetViewResponse)
@doc "小程序删除我的帖子"
@handler MiniArticleDelete
delete /article/delete (MiniArticleDeleteRequest) returns (MiniArticleDeleteResponse)
@doc "小程序创建文章进草稿箱"
@handler MiniCreateArticleDraft
post /article_draft (MiniArticleDraftCreateRequest) returns (MiniArticleDraftCreateResponse)
... ...
... ... @@ -107,6 +107,10 @@ type (
CountComment int `json:"countComment"` //评论数量
CountRead int `json:"countRead"` //浏览数量
Show int `json:"show"` //是否隐藏 [0显示、1不显示]
TargetUser int `json:"targetUser"` //分发方式 [0分发给所有人、1分发给指定的人]
WhoRead []int64 `json:"whoRead"` //谁可查看
IsDel int `json:"isDel"` //是否删除 1-删除 0-否
DeletedType int `json:"deletedType"` //类型 1-运营删除 2-用户删除
}
SystemArticleSearchMeRequest {
... ... @@ -122,6 +126,30 @@ type (
}
)
//小程序我的帖子设置可见范围
type (
MiniArticleSetViewRequest {
Id int64 `json:"id"` //id
WhoRead []int64 `json:"whoRead"` //谁可查看
}
MiniArticleSetViewResponse {
Id int64 `json:"id"` //id
Title string `json:"title"` //标题
WhoRead []int64 `json:"whoRead"` //谁可查看
}
)
//小程序删除我的帖子
type (
MiniArticleDeleteRequest {
Id int64 `json:"id"` //id
}
MiniArticleDeleteResponse {
Id int64 `json:"id"` //id
Title string `json:"title"` //标题
}
)
//小程序端获取文章有哪些人进行了点赞
type (
MiniUserLikeArticleRequest {
... ... @@ -509,6 +537,7 @@ type (
type (
SystemArticleDeleteRequest {
Id int64 `json:"id"` //id
AccessToken string `header:"x-mmm-accesstoken"` // 授权token
}
SystemArticleDeleteResponse {
Id int64 `json:"id"` //id
... ... @@ -788,6 +817,7 @@ type (
type (
SystemArticleDeletedRestoreRequest {
Id int64 `json:"id"` //ID
AccessToken string `header:"x-mmm-accesstoken"` // 授权token
}
SystemArticleDeletedRestoreResponse {
Id int64 `json:"id"` //ID
... ...
package article
import (
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/result"
"net/http"
"github.com/zeromicro/go-zero/rest/httpx"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/logic/article"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types"
)
func MiniArticleDeleteHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.MiniArticleDeleteRequest
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
return
}
l := article.NewMiniArticleDeleteLogic(r.Context(), svcCtx)
resp, err := l.MiniArticleDelete(&req)
result.HttpResult(r, w, resp, err)
}
}
... ...
package article
import (
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/result"
"net/http"
"github.com/zeromicro/go-zero/rest/httpx"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/logic/article"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types"
)
func MiniArticleSetViewHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.MiniArticleSetViewRequest
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
return
}
l := article.NewMiniArticleSetViewLogic(r.Context(), svcCtx)
resp, err := l.MiniArticleSetView(&req)
result.HttpResult(r, w, resp, err)
}
}
... ...
... ... @@ -505,6 +505,16 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
},
{
Method: http.MethodPost,
Path: "/article/set_view",
Handler: article.MiniArticleSetViewHandler(serverCtx),
},
{
Method: http.MethodDelete,
Path: "/article/delete",
Handler: article.MiniArticleDeleteHandler(serverCtx),
},
{
Method: http.MethodPost,
Path: "/article_draft",
Handler: article.MiniCreateArticleDraftHandler(serverCtx),
},
... ...
package article
import (
"context"
"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/contextdata"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/xerr"
"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 MiniArticleDeleteLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
conn transaction.Conn
}
func NewMiniArticleDeleteLogic(ctx context.Context, svcCtx *svc.ServiceContext) *MiniArticleDeleteLogic {
return &MiniArticleDeleteLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
conn: svcCtx.DefaultDBConn(),
}
}
func (l *MiniArticleDeleteLogic) MiniArticleDelete(req *types.MiniArticleDeleteRequest) (resp *types.MiniArticleDeleteResponse, err error) {
// 文章数据
article, err := l.svcCtx.ArticleRepository.FindOne(l.ctx, l.conn, req.Id)
if err != nil {
return nil, xerr.NewErrMsgErr("帖子不存在", err)
}
userToken := contextdata.GetUserTokenFromCtx(l.ctx)
if userToken.UserId != article.AuthorId || userToken.CompanyId != article.CompanyId {
return nil, xerr.NewErrMsg("您没有权限删除")
}
// 检查发布人
author, err := l.svcCtx.UserRepository.FindOne(l.ctx, l.conn, article.AuthorId)
if err != nil {
return nil, xerr.NewErrMsgErr("创建文章内容失败", err)
}
companyInfo, err := l.svcCtx.CompanyRepository.FindOne(l.ctx, l.conn, author.CompanyId)
if err != nil {
return nil, xerr.NewErrMsgErr("创建文章内容失败", err)
}
articleAuthor := domain.UserSimple{
Id: author.Id,
Name: author.Name,
Avatar: author.Avatar,
Position: author.Position,
Company: companyInfo.Name,
CompanyId: author.CompanyId,
}
article.DeletedType = domain.ArticleDeletedTypeUser
//文章内容详情
queryOption := domain.NewQueryOptions().WithFindOnly().MustWithKV("articleId", req.Id)
_, sectionList, err := l.svcCtx.ArticleSectionRepository.Find(l.ctx, l.conn, queryOption)
if err != nil {
return nil, xerr.NewErrMsgErr("帖子不存在", err)
}
var backup domain.ArticleBackup
backup.MakeBackup(articleAuthor, article, sectionList, "删除")
err = transaction.UseTrans(l.ctx, l.conn.DB(), func(ctx context.Context, conn transaction.Conn) error {
//更新删除类型
_, err = l.svcCtx.ArticleRepository.Update(l.ctx, conn, article)
if err != nil {
return err
}
//删除
_, err = l.svcCtx.ArticleRepository.Delete(l.ctx, conn, article)
if err != nil {
return err
}
//备份
_, err = l.svcCtx.ArticleBackupRepository.Insert(ctx, conn, &backup)
if err != nil {
return xerr.NewErrMsgErr("删除失败", err)
}
return nil
}, true)
if err != nil {
return nil, xerr.NewErrMsgErr("删除失败", err)
}
resp = &types.MiniArticleDeleteResponse{
Id: article.Id,
Title: article.Title,
}
return
}
... ...
... ... @@ -33,6 +33,7 @@ func (l *MiniArticleSearchMeLogic) MiniArticleSearchMe(req *types.MiniArticleSea
}
queryOptions := domain.NewQueryOptions().
WithOffsetLimit(req.Page, req.Size).
WithKV("showDel", true).
MustWithKV("authorId", req.AuthorId)
cnt, articleList, err := l.svcCtx.ArticleRepository.Find(l.ctx, conn, req.CompanyId, queryOptions)
... ... @@ -64,6 +65,10 @@ func NewArticle(article *domain.Article) types.ArticleSearchMe {
CountComment: article.CountComment,
CountRead: article.CountRead,
Show: int(article.Show),
TargetUser: int(article.TargetUser),
WhoRead: article.WhoRead,
IsDel: article.IsDel,
DeletedType: article.DeletedType,
}
return articleSearchMe
}
... ...
package article
import (
"context"
"github.com/samber/lo"
"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/contextdata"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/xerr"
"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 MiniArticleSetViewLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
conn transaction.Conn
}
func NewMiniArticleSetViewLogic(ctx context.Context, svcCtx *svc.ServiceContext) *MiniArticleSetViewLogic {
return &MiniArticleSetViewLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
conn: svcCtx.DefaultDBConn(),
}
}
func (l *MiniArticleSetViewLogic) MiniArticleSetView(req *types.MiniArticleSetViewRequest) (resp *types.MiniArticleSetViewResponse, err error) {
// 文章数据
article, err := l.svcCtx.ArticleRepository.FindOne(l.ctx, l.conn, req.Id)
if err != nil {
return nil, xerr.NewErrMsgErr("帖子不存在", err)
}
userToken := contextdata.GetUserTokenFromCtx(l.ctx)
if userToken.UserId != article.AuthorId || userToken.CompanyId != article.CompanyId {
return nil, xerr.NewErrMsg("您没有权限修改")
}
// 检查发布人
author, err := l.svcCtx.UserRepository.FindOne(l.ctx, l.conn, article.AuthorId)
if err != nil {
return nil, xerr.NewErrMsgErr("创建文章内容失败", err)
}
companyInfo, err := l.svcCtx.CompanyRepository.FindOne(l.ctx, l.conn, author.CompanyId)
if err != nil {
return nil, xerr.NewErrMsgErr("创建文章内容失败", err)
}
articleAuthor := domain.UserSimple{
Id: author.Id,
Name: author.Name,
Avatar: author.Avatar,
Position: author.Position,
Company: companyInfo.Name,
CompanyId: author.CompanyId,
}
//检查文章可被哪些人查看
whoRead := []int64{}
if len(req.WhoRead) > 0 {
whoRead = lo.Uniq(req.WhoRead)
var u *domain.User
for _, val := range whoRead {
u, err = l.svcCtx.UserRepository.FindOne(l.ctx, l.conn, val)
if err != nil {
return nil, xerr.NewErrMsgErr("文章可查看人设置错误", err)
}
if u.CompanyId != userToken.CompanyId {
return nil, xerr.NewErrMsg("文章可查看人设置错误")
}
}
}
//文章内容详情
queryOption := domain.NewQueryOptions().WithFindOnly().MustWithKV("articleId", req.Id)
_, sectionList, err := l.svcCtx.ArticleSectionRepository.Find(l.ctx, l.conn, queryOption)
if err != nil {
return nil, xerr.NewErrMsgErr("帖子不存在", err)
}
var oldBackup domain.ArticleBackup
oldBackup.MakeBackup(articleAuthor, article, sectionList, "设置可见范围")
//更新数据
article.TargetUser = domain.ArticleTargetLimit
article.WhoRead = whoRead
article.WhoReview = whoRead
err = transaction.UseTrans(l.ctx, l.conn.DB(), func(ctx context.Context, c transaction.Conn) error {
//更新文章内容
_, err = l.svcCtx.ArticleRepository.Update(l.ctx, c, article)
if err != nil {
return xerr.NewErrMsgErr("保存帖子失败", err)
}
//备份文章
var backup domain.ArticleBackup
backup.MakeBackup(articleAuthor, article, sectionList, "设置可见范围")
if ok := backup.CheckChangeField(&oldBackup); ok {
_, err = l.svcCtx.ArticleBackupRepository.Insert(ctx, c, &backup)
if err != nil {
return xerr.NewErrMsgErr("保存文章日志失败", err)
}
}
return nil
}, true)
resp = &types.MiniArticleSetViewResponse{
Id: article.Id,
Title: article.Title,
WhoRead: article.WhoRead,
}
return
}
... ...
... ... @@ -4,6 +4,7 @@ import (
"context"
"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/cmd/discuss/interanl/pkg/gateway/authlib"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/contextdata"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/xerr"
... ... @@ -35,10 +36,28 @@ func (l *SystemDeleteArticleLogic) SystemDeleteArticle(req *types.SystemArticleD
if err != nil {
return nil, xerr.NewErrMsgErr("帖子不存在", err)
}
//文章内容
queryOption := domain.NewQueryOptions().WithFindOnly().MustWithKV("articleId", req.Id)
_, sectionList, err := l.svcCtx.ArticleSectionRepository.Find(l.ctx, l.conn, queryOption)
if err != nil {
return nil, xerr.NewErrMsgErr("帖子不存在", err)
}
userToken := contextdata.GetUserTokenFromCtx(l.ctx)
if userToken.CompanyId != article.CompanyId {
return nil, xerr.NewErrMsg("您没有权限")
}
// 获取当前用户信息
userMe, err := l.svcCtx.ApiAuthService.MeInfo(l.ctx, authlib.RequestUserMeQuery{Token: req.AccessToken})
if err != nil {
return nil, xerr.NewErrMsgErr("获取当前用户信息失败", err)
}
operator := domain.UserSimple{
Id: userToken.UserId,
Name: userMe.User.NickName,
Avatar: userMe.User.Avatar,
CompanyId: userToken.CompanyId,
Company: userMe.CurrentCompany.Name,
}
article.DeletedType = domain.ArticleDeletedTypeOperator
err = transaction.UseTrans(l.ctx, l.conn.DB(), func(ctx context.Context, conn transaction.Conn) error {
//更新删除类型
... ... @@ -50,6 +69,12 @@ func (l *SystemDeleteArticleLogic) SystemDeleteArticle(req *types.SystemArticleD
if err != nil {
return err
}
var backup domain.ArticleBackup
backup.MakeBackup(operator, article, sectionList, "删除")
_, err = l.svcCtx.ArticleBackupRepository.Insert(ctx, conn, &backup)
if err != nil {
return xerr.NewErrMsgErr("保存文章内容失败", err)
}
return nil
}, true)
if err != nil {
... ...
... ... @@ -3,6 +3,9 @@ package article
import (
"context"
"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/cmd/discuss/interanl/pkg/gateway/authlib"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/contextdata"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/xerr"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc"
... ... @@ -33,7 +36,46 @@ func (l *SystemRestoreArticleDeletedLogic) SystemRestoreArticleDeleted(req *type
if err != nil {
return nil, xerr.NewErrMsgErr("帖子不存在", err)
}
_, err = l.svcCtx.ArticleRepository.Restore(l.ctx, l.conn, article)
if article.IsDel != 1 {
return nil, xerr.NewErrMsg("帖子已恢复")
}
//文章内容
queryOption := domain.NewQueryOptions().WithFindOnly().MustWithKV("articleId", req.Id)
_, sectionList, err := l.svcCtx.ArticleSectionRepository.Find(l.ctx, l.conn, queryOption)
if err != nil {
return nil, xerr.NewErrMsgErr("帖子不存在", err)
}
userToken := contextdata.GetUserTokenFromCtx(l.ctx)
if userToken.CompanyId != article.CompanyId {
return nil, xerr.NewErrMsg("您没有权限")
}
// 获取当前用户信息
userMe, err := l.svcCtx.ApiAuthService.MeInfo(l.ctx, authlib.RequestUserMeQuery{Token: req.AccessToken})
if err != nil {
return nil, xerr.NewErrMsgErr("获取当前用户信息失败", err)
}
operator := domain.UserSimple{
Id: userToken.UserId,
Name: userMe.User.NickName,
Avatar: userMe.User.Avatar,
CompanyId: userToken.CompanyId,
Company: userMe.CurrentCompany.Name,
}
err = transaction.UseTrans(l.ctx, l.conn.DB(), func(ctx context.Context, conn transaction.Conn) error {
//恢复帖子
_, err = l.svcCtx.ArticleRepository.Restore(ctx, conn, article)
if err != nil {
return err
}
//备份
var backup domain.ArticleBackup
backup.MakeBackup(operator, article, sectionList, "恢复")
_, err = l.svcCtx.ArticleBackupRepository.Insert(ctx, conn, &backup)
if err != nil {
return xerr.NewErrMsgErr("恢复帖子失败", err)
}
return nil
}, true)
if err != nil {
return nil, xerr.NewErrMsg("恢复帖子失败")
}
... ...
... ... @@ -984,6 +984,10 @@ type ArticleSearchMe struct {
CountComment int `json:"countComment"` //评论数量
CountRead int `json:"countRead"` //浏览数量
Show int `json:"show"` //是否隐藏 [0显示、1不显示]
TargetUser int `json:"targetUser"` //分发方式 [0分发给所有人、1分发给指定的人]
WhoRead []int64 `json:"whoRead"` //谁可查看
IsDel int `json:"isDel"` //是否删除 1-删除 0-否
DeletedType int `json:"deletedType"` //类型 1-运营删除 2-用户删除
}
type SystemArticleSearchMeRequest struct {
... ... @@ -999,6 +1003,26 @@ type SystemArticleSearchMeResponse struct {
List []ArticleSearchMe `json:"list"`
}
type MiniArticleSetViewRequest struct {
Id int64 `json:"id"` //id
WhoRead []int64 `json:"whoRead"` //谁可查看
}
type MiniArticleSetViewResponse struct {
Id int64 `json:"id"` //id
Title string `json:"title"` //标题
WhoRead []int64 `json:"whoRead"` //谁可查看
}
type MiniArticleDeleteRequest struct {
Id int64 `json:"id"` //id
}
type MiniArticleDeleteResponse struct {
Id int64 `json:"id"` //id
Title string `json:"title"` //标题
}
type MiniUserLikeArticleRequest struct {
ArticleId int64 `json:"articleId"` // 文章id
CompanyId int64 `json:",optional"` //公司id
... ... @@ -1347,7 +1371,8 @@ type SystemArticleCreateResponse struct {
}
type SystemArticleDeleteRequest struct {
Id int64 `json:"id"` //id
Id int64 `json:"id"` //id
AccessToken string `header:"x-mmm-accesstoken"` // 授权token
}
type SystemArticleDeleteResponse struct {
... ... @@ -1606,7 +1631,8 @@ type SystemArticleSearchDeletedItem struct {
}
type SystemArticleDeletedRestoreRequest struct {
Id int64 `json:"id"` //ID
Id int64 `json:"id"` //ID
AccessToken string `header:"x-mmm-accesstoken"` // 授权token
}
type SystemArticleDeletedRestoreResponse struct {
... ...
... ... @@ -207,6 +207,9 @@ func (repository *ArticleRepository) Find(ctx context.Context, conn transaction.
if v, ok := queryOptions["isDel"]; ok {
tx = tx.Unscoped().Where("is_del = ?", v)
}
if _, ok := queryOptions["showDel"]; ok {
tx = tx.Unscoped()
}
//删除时间
if v, ok := queryOptions["beginDeletedAt"]; ok {
tx = tx.Where("deleted_at >= ?", v)
... ... @@ -447,6 +450,7 @@ func (repository *ArticleRepository) ModelToDomainModel(from *models.Article) (*
Source: from.Source,
Operator: from.Operator,
DeletedType: from.DeletedType,
IsDel: int(from.IsDel),
}
return to, nil
}
... ...
... ... @@ -14,6 +14,7 @@ type Article struct {
CreatedAt int64 `json:"createdAt,omitempty"`
UpdatedAt int64 `json:"updatedAt,omitempty"`
DeletedAt int64 `json:"deletedAt,omitempty"`
IsDel int `json:"isDel,omitempty"`
Version int `json:"version,omitempty"`
AuthorId int64 `json:"authorId"` // 发布人
Author UserSimple `json:"author"` // 发布人
... ...
... ... @@ -147,26 +147,27 @@ func (bk *ArticleBackup) MakeBackup(operator UserSimple, article *Article, secti
sectionBackup[i] = *section[i]
}
b := ArticleBackup{
Id: 0,
CompanyId: article.CompanyId,
CreatedAt: 0,
UpdatedAt: 0,
DeletedAt: 0,
Version: article.Version,
Operator: operator,
ArticleId: article.Id,
Title: article.Title,
Section: sectionBackup,
Images: make([]Image, len(article.Images)),
Videos: make([]Video, len(article.Videos)),
Action: action,
TargetUser: article.TargetUser,
WhoRead: article.WhoRead,
WhoReview: article.WhoReview,
Tags: article.Tags,
MatchUrl: map[string]string{},
Show: article.Show,
Location: article.Location,
Id: 0,
CompanyId: article.CompanyId,
CreatedAt: 0,
UpdatedAt: 0,
DeletedAt: 0,
Version: article.Version,
Operator: operator,
ArticleId: article.Id,
Title: article.Title,
Section: sectionBackup,
Images: make([]Image, len(article.Images)),
Videos: make([]Video, len(article.Videos)),
Action: action,
TargetUser: article.TargetUser,
WhoRead: article.WhoRead,
WhoReview: article.WhoReview,
Tags: article.Tags,
MatchUrl: map[string]string{},
Show: article.Show,
Location: article.Location,
ChangeField: []string{},
}
if action == "原始版本" {
b.ChangeField = append(b.ChangeField, "Section")
... ...