作者 郑周

Merge remote-tracking branch 'origin/dev' into dev

正在显示 51 个修改的文件 包含 551 行增加223 行删除
package main
import (
"context"
"flag"
"github.com/zeromicro/go-zero/rest/httpx"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/db"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/result"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/xerr"
"net/http"
"strings"
"github.com/zeromicro/go-zero/core/logx"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/domain"
"github.com/golang-jwt/jwt/v4/request"
"github.com/zeromicro/go-zero/core/conf"
"github.com/zeromicro/go-zero/core/logx"
"github.com/zeromicro/go-zero/rest"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/config"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/handler"
... ... @@ -20,27 +23,16 @@ import (
var configFile = flag.String("f", "cmd/discuss/api/etc/core.yaml", "the config file")
func main() {
// 配置加载
flag.Parse()
var c config.Config
conf.MustLoad(*configFile, &c)
// 默认的token头 Authorization 修改未 x-token
request.AuthorizationHeaderExtractor = &request.PostExtractionFilter{
request.HeaderExtractor{"x-mmm-accesstoken"}, func(tok string) (string, error) {
// Should be a bearer token
if len(tok) > 6 && strings.ToUpper(tok[0:7]) == "BEARER " {
return tok[7:], nil
}
return tok, nil
},
}
// 初始化Domain里面的配置
domain.ProjectName = c.Name
// 系统设置
systemSetup(c)
// 服务初始化
opts := make([]rest.RunOption, 0)
// cors
opt := rest.WithCustomCors(func(header http.Header) {
header.Set("Access-Control-Allow-Headers", "*")
}, func(writer http.ResponseWriter) {
... ... @@ -49,14 +41,40 @@ func main() {
opts = append(opts, opt)
server := rest.MustNewServer(c.RestConf, opts...)
defer server.Stop()
ctx := svc.NewServiceContext(c)
handler.RegisterHandlers(server, ctx)
// 数据迁移
if c.Migrate {
db.Migrate(ctx.DB)
}
// 服务启动
logx.Infof("Starting server at %s:%d... \n", c.Host, c.Port)
server.Start()
}
func systemSetup(c config.Config) {
// 初始化Domain里面的配置
domain.ProjectName = c.Name
// 默认的token头 Authorization 修改为 x-mmm-accesstoken
request.AuthorizationHeaderExtractor = &request.PostExtractionFilter{
request.HeaderExtractor{"x-mmm-accesstoken"}, func(tok string) (string, error) {
// Should be a bearer token
if len(tok) > 6 && strings.ToUpper(tok[0:7]) == "BEARER " {
return tok[7:], nil
}
return tok, nil
},
}
// 系统错误应答包装
httpx.SetErrorHandlerCtx(func(ctx context.Context, err error) (int, any) {
return http.StatusOK, result.Error(xerr.ServerCommonError, err.Error())
})
// 系统成功应答包装
httpx.SetOkHandler(func(ctx context.Context, a any) any {
return result.Success(a)
})
}
... ...
... ... @@ -5024,55 +5024,94 @@
"show"
]
},
"SystemArticleHistoryRequest": {
"SystemArticleHistory": {
"type": "object",
"properties": {
"articleId": {
"id": {
"type": "integer",
"format": "int64",
"description": "文章ID"
"description": "id"
},
"author": {
"type": "string",
"description": "发布人"
"description": "编辑人"
},
"updatedAt": {
"action": {
"type": "string",
"description": "修改日期"
"description": "编辑类型"
},
"updatedAt": {
"type": "integer",
"format": "int64",
"description": "编辑时间"
}
},
"title": "SystemArticleHistoryRequest",
"title": "SystemArticleHistory",
"required": [
"articleId"
"id",
"author",
"action",
"updatedAt"
]
},
"SystemArticleHistoryResponse": {
"SystemArticleHistoryRequest": {
"type": "object",
"properties": {
"id": {
"articleId": {
"type": "integer",
"format": "int64",
"description": "id"
"description": "文章ID"
},
"author": {
"type": "string",
"description": "编辑人"
"description": "发布人"
},
"action": {
"type": "string",
"description": "编辑类型"
"beginTime": {
"type": "integer",
"format": "int64",
"description": "开始时间"
},
"updatedAt": {
"type": "string",
"description": "编辑时间"
"endTime": {
"type": "integer",
"format": "int64",
"description": "结束时间"
},
"page": {
"type": "integer",
"format": "int32",
"description": "页码"
},
"size": {
"type": "integer",
"format": "int32",
"description": "每页行数"
}
},
"title": "SystemArticleHistoryRequest",
"required": [
"articleId",
"page",
"size"
]
},
"SystemArticleHistoryResponse": {
"type": "object",
"properties": {
"total": {
"type": "integer",
"format": "int32"
},
"list": {
"type": "array",
"items": {
"$ref": "#/definitions/SystemArticleHistory"
}
}
},
"title": "SystemArticleHistoryResponse",
"required": [
"id",
"author",
"action",
"updatedAt"
"total",
"list"
]
},
"SystemArticleSearch": {
... ... @@ -5214,16 +5253,22 @@
"type": "string",
"description": "发布人"
},
"publishDate": {
"type": "string",
"description": "发布日期"
"beginTime": {
"type": "integer",
"format": "int64",
"description": "开始时间"
},
"pageNumber": {
"endTime": {
"type": "integer",
"format": "int64",
"description": "结束时间"
},
"page": {
"type": "integer",
"format": "int32",
"description": "页码"
},
"pageSize": {
"size": {
"type": "integer",
"format": "int32",
"description": "每页行数"
... ... @@ -5231,8 +5276,8 @@
},
"title": "SystemArticleSearchRequest",
"required": [
"pageNumber",
"pageSize"
"page",
"size"
]
},
"SystemArticleSearchResponse": {
... ...
... ... @@ -72,6 +72,12 @@ service Core {
@doc "小程序所有的定性标签"
@handler MiniAllArticleTag
get /article_tag/list/all (MiniAllArticleTagRequest) returns (MiniAllArticleTagResponse)
@doc "小程序首页数据展示"
@handler MinishowHomePage
get /show/home_page (MiniAllArticleTagRequest) returns (MiniAllArticleTagResponse)
}
// 管理后台接口
... ... @@ -97,6 +103,10 @@ service Core {
@handler SystemHistoryArticle
post /article/history (SystemArticleHistoryRequest) returns (SystemArticleHistoryResponse)
@doc "管理后台帖子历史详情"
@handler SystemArticleGetHistory
get /article/history/:id (SystemArticleGetHistoryRequest) returns (SystemArticleGetHistoryResponse)
@doc "管理后台获取我发布的文章"
@handler SystemArticleSearchMe
post /article/search/me (SystemArticleSearchMeRequest) returns (SystemArticleSearchMeResponse)
... ...
... ... @@ -35,15 +35,15 @@ type (
//小程序端查看文章的详情
type (
MiniArticleGetRequest {
Id int64 `path:"id"` //id
CompanyId int64 `path:",optional"`//当前公司
UserId int `path:",optional"` //当前用户
Id int64 `path:"id"` //id
CompanyId int64 `path:",optional"` //当前公司
UserId int `path:",optional"` //当前用户
}
MiniArticleGetResponse {
Id int64 `json:"id"` //id
Title string `json:"title"` //标题
AuthorId int64 `json:"authorId"` //发布人id
Author ArticleAuthor `json:"author"` //发布人
Author ArticleAuthor `json:"author"` //发布人
CreatedAt int64 `json:"createdAt"` //文章的发布时间
Section []ArticleSection `json:"section"` //文章的文本内容
Images []string `json:"images"` //图片
... ... @@ -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"` // 当前人员对文章的点赞标识 (0 没有点赞 1有点赞)
MeLoveFlag int `json:"meLoveFlag"` // 当前人员对文章的点赞标识 (0 没有点赞 1有点赞)
}
ArticleSection {
Id int64 `json:"id"` //段落id
... ... @@ -92,9 +92,9 @@ type (
SystemArticleSearchMeRequest {
Page int `json:"page"`
Size int `json:"size"`
AuthorId int64 `json:"authorId"` // 用户
AuthorId int64 `json:"authorId"` // 用户
BeginTime int64 `json:"beginTime,optional"` // 开始时间
EndTime int64 `json:"endTime,optional"` // 结束时间
EndTime int64 `json:"endTime,optional"` // 结束时间
}
SystemArticleSearchMeResponse {
Total int `json:"total"`
... ... @@ -119,7 +119,7 @@ type (
UserId int64 `json:"userId"` // 人员id
Name string `json:"name"` // 人员名称
Avatar string `json:"avatar"` // 人员头像
Position string `json:"position"` // 职位
Position string `json:"position"` // 职位
CreatedAt int64 `json:"createdAt"` // 点赞记录的时间
}
)
... ... @@ -271,8 +271,8 @@ type (
// 小程序端获取我的浏览记录
type (
MiniArticleMarkListRequest {
Page int `json:"page"`
Size int `json:"size"`
Page int `json:"page"`
Size int `json:"size"`
}
MiniArticleMarkListResponse {
... ... @@ -293,41 +293,38 @@ type (
//小程序端设置文章的定性标签
type (
MiniArticleSetTagRequest{
MiniArticleSetTagRequest {
CompanyId int64 `json:",optional"` // 公司id
UserId int64 `json:",optional"` // 公司id
ArticleId int64 `json:"articleId"` // 文章id
TagId int64 `json:"tagId"` // 标签id
}
MiniArticleSetTagResponse{
MiniArticleSetTagResponse {
Id int64 `json:"id"`
}
)
//小程序端获取所有的定性标签
type (
MiniAllArticleTagRequest{
MiniAllArticleTagRequest {
CompanyId int64 `json:",optional"` // 公司id
UserId int64 `json:",optional"` // 公司id
}
MiniAllArticleTagResponse{
TagGroup []ArticleTagGroup `json:"tagGroup"`
}
MiniAllArticleTagResponse {
TagGroup []ArticleTagGroup `json:"tagGroup"`
}
ArticleTagGroup {
Group string `json:"group"`
Tags []ArticleTagItem `json:"tags"`
Group string `json:"group"`
Tags []ArticleTagItem `json:"tags"`
}
ArticleTagItem {
Id int64 `json:"id"`
Group string `json:"group"`
Name string `json:"name"`
Image string `json:"image"`
Id int64 `json:"id"`
Group string `json:"group"`
Name string `json:"name"`
Image string `json:"image"`
}
)
//管理后台获取文章详情
type (
SystemArticleGetRequest {
... ... @@ -336,7 +333,7 @@ type (
}
UserShowName {
Id int `json:"id"`
Id int `json:"id"`
Name string `json:"name"`
}
... ... @@ -344,7 +341,7 @@ type (
Id int64 `json:"id"` // id
Title string `json:"title"` // 标题
AuthorId int64 `json:"authorId"` // 发布人id
Author ArticleAuthor `json:"author"` // 发布人
Author ArticleAuthor `json:"author"` // 发布人
CreatedAt int64 `json:"createdAt"` // 文章的发布时间
Section []ArticleSection `json:"section"` // 文章的文本内容
Images []string `json:"images"` // 图片
... ... @@ -357,18 +354,21 @@ type (
CountComment int `json:"countComment"` // 评论数量
CountRead int `json:"countRead"` // 浏览数量
Show int `json:"show"` // 评论的展示状态(0显示、1不显示)
Tags []ArticleTagItem `json:"tags"` //标签
}
)
//管理后台获取文章列表
type (
SystemArticleSearchRequest {
CompanyId int64 `json:"companyId,optional"`
Title string `json:"title,optional"` //标题
Author string `json:"author,optional"` //发布人
PublishDate string `json:"publishDate,optional"` //发布日期
PageNumber int `json:"pageNumber"` //页码
PageSize int `json:"pageSize"` //每页行数
CompanyId int64 `json:"companyId,optional"`
Title string `json:"title,optional"` //标题
Author string `json:"author,optional"` //发布人
BeginTime int64 `json:"beginTime,optional"` //开始时间
EndTime int64 `json:"endTime,optional"` //结束时间
Tags []int64 `json:"tags,optional"` //标签
Page int `json:"page"` //页码
Size int `json:"size"` //每页行数
}
SystemArticleSearchResponse {
... ... @@ -389,16 +389,17 @@ type (
}
//编辑
SystemArticleUpdateRequest {
Id int64 `json:"id"`
CompanyId int64 `json:"companyId,optional"`
Template int `json:"template"` // 使用哪个模板进行编辑 0、无 1、演绎式 2、归纳式
Section []ArticleSection `json:"section"` // 填写的内容
Title string `json:"title"` // 标题
Images []string `json:"images"` // 图片
WhoRead []int64 `json:"whoRead"` // 谁可以看
WhoReview []int64 `json:"whoReview"` // 评论人
Location Location `json:"location"` // 坐标
TargetUser int `json:"targetUser"` //分发方式 [0分发给所有人、1分发给指定的人]
Id int64 `json:"id"`
CompanyId int64 `json:"companyId,optional"`
Template int `json:"template"` // 使用哪个模板进行编辑 0、无 1、演绎式 2、归纳式
Section []ArticleSection `json:"section"` // 填写的内容
Title string `json:"title"` // 标题
Images []string `json:"images"` // 图片
WhoRead []int64 `json:"whoRead"` // 谁可以看
WhoReview []int64 `json:"whoReview"` // 评论人
Location Location `json:"location"` // 坐标
TargetUser int `json:"targetUser"` //分发方式 [0分发给所有人、1分发给指定的人]
Tags []int64 `json:"tags"` // 标签
}
SystemArticleUpdateResponse {
Id int64 `json:"id"` //id
... ... @@ -409,19 +410,54 @@ type (
CountLove int `json:"countLove"` //点赞数量
CountComment int `json:"CountComment"` //评论数量
Show int `json:"show"` //是否隐藏 [0显示、1不显示]
Tags []string `json:"tags"` //标签
Tags []int64 `json:"tags"` //标签
TargetUser int `json:"targetUser"` //分发方式 [0分发给所有人、1分发给指定的人]
}
//历史
SystemArticleHistoryRequest {
ArticleId int64 `json:"articleId"` //文章ID
Author string `json:"author,optional"` //发布人
UpdatedAt string `json:"updatedAt,optional"` //修改日期
ArticleId int64 `json:"articleId"` //文章ID
Author string `json:"author,optional"` //发布人
BeginTime int64 `json:"beginTime,optional"` //开始时间
EndTime int64 `json:"endTime,optional"` //结束时间
Page int `json:"page"` //页码
Size int `json:"size"` //每页行数
}
SystemArticleHistoryResponse {
Id int64 `json:"id"` //id
Author string `json:"author"` //编辑人
Action string `json:"action"` //编辑类型
UpdatedAt string `json:"updatedAt"` //编辑时间
Total int `json:"total"`
List []SystemArticleHistory `json:"list"`
}
SystemArticleHistory {
Id int64 `json:"id"` //id
Author string `json:"author"` //编辑人
Action string `json:"action"` //编辑类型
UpdatedAt int64 `json:"updatedAt"` //编辑时间
}
SystemArticleGetHistoryRequest {
Id int64 `path:"id"` //id
CompanyId int64 `path:",optional"`
}
)
\ No newline at end of file
SystemArticleGetHistoryResponse {
Id int64 `json:"id"` // id
ArticleId int64 `json:"articleId"` // 文章ID
Title string `json:"title"` // 标题
AuthorId int64 `json:"authorId"` // 发布人id
Author ArticleAuthor `json:"author"` // 发布人
CreatedAt int64 `json:"createdAt"` // 文章的发布时间
Section []ArticleSection `json:"section"` // 文章的文本内容
Images []string `json:"images"` // 图片
WhoRead []int64 `json:"whoRead"` // 谁可查看
WhoReadInfo []UserShowName `json:"whoReadInfo"` // 谁可查看
WhoReview []int64 `json:"whoReview"` // 谁可评论
WhoReviewInfo []UserShowName `json:"whoReviewInfo"` // 谁可评论
Location Location `json:"location"` // 定位坐标
CountLove int `json:"countLove"` // 点赞数量
CountComment int `json:"countComment"` // 评论数量
CountRead int `json:"countRead"` // 浏览数量
Show int `json:"show"` // 评论的展示状态(0显示、1不显示)
TargetUser int `json:"targetUser"` //分发方式 [0分发给所有人、1分发给指定的人]
}
)
//小程序端 首页数据展示
// 统计各标签下的文章数量,和已被人员阅读的数量
type
\ No newline at end of file
... ...
... ... @@ -9,27 +9,27 @@ info(
)
@server(
prefix: v1
group: role
middleware: LoginStatusCheck
jwt: SystemAuth
prefix: v1
group: role
middleware: LoginStatusCheck
jwt: SystemAuth
)
service Core {
@doc "角色详情"
@handler systemGetRole
get /system/role/:id (RoleGetRequest) returns (RoleGetResponse)
@doc "角色新增"
@handler systemSaveRole
post /system/role (RoleSaveRequest) returns (RoleSaveResponse)
@doc "角色删除"
@handler systemDeleteRole
delete /system/role/:id (RoleDeleteRequest) returns (RoleDeleteResponse)
@doc "角色更新"
@handler systemUpdateRole
put /system/role/:id (RoleUpdateRequest) returns (RoleUpdateResponse)
@doc "角色列表搜索"
@handler systemSearchRole
post /system/role/search (RoleSearchRequest) returns (RoleSearchResponse)
@doc "角色详情"
@handler systemGetRole
get /system/role/:id (RoleGetRequest) returns (RoleGetResponse)
@doc "角色新增"
@handler systemSaveRole
post /system/role (RoleSaveRequest) returns (RoleSaveResponse)
@doc "角色删除"
@handler systemDeleteRole
delete /system/role/:id (RoleDeleteRequest) returns (RoleDeleteResponse)
@doc "角色更新"
@handler systemUpdateRole
put /system/role/:id (RoleUpdateRequest) returns (RoleUpdateResponse)
@doc "角色列表搜索"
@handler systemSearchRole
post /system/role/search (RoleSearchRequest) returns (RoleSearchResponse)
}
type (
... ...
... ... @@ -84,9 +84,6 @@ type(
}
MiniUserInfoResponse {
User *UserItem `json:"user,omitempty"` // 用户信息
TotalArticle int64 `json:"totalArticle"` // 累计信息发布
TotalLoved int64 `json:"totalLoved"` // 累计收到的赞
TotalAccepted int64 `json:"totalAccepted"` // 累计被采纳
Accounts []Account `json:"accounts"` // 公司账号
Auths []Auth `json:"auths"` // 权限列表
}
... ...
... ... @@ -15,7 +15,7 @@ func MiniAllArticleTagHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.MiniAllArticleTagRequest
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
result.HttpResult(r, w, nil, err)
return
}
... ...
... ... @@ -15,7 +15,7 @@ func MiniArticleBackupSearchHandler(svcCtx *svc.ServiceContext) http.HandlerFunc
return func(w http.ResponseWriter, r *http.Request) {
var req types.MiniArticleBackupSearchRequest
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
result.HttpResult(r, w, nil, err)
return
}
token := contextdata.GetUserTokenFromCtx(r.Context())
... ...
package article
import (
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/result"
"net/http"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/result"
"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"
... ... @@ -14,7 +15,7 @@ func MiniArticleMarkListHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.MiniArticleMarkListRequest
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
result.HttpResult(r, w, nil, err)
return
}
... ...
... ... @@ -16,7 +16,7 @@ func MiniArticleMarkUserReadHandler(svcCtx *svc.ServiceContext) http.HandlerFunc
return func(w http.ResponseWriter, r *http.Request) {
var req types.MiniArticleMarkUserReadRequest
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
result.HttpResult(r, w, nil, err)
return
}
... ...
... ... @@ -15,7 +15,7 @@ func MiniArticleSearchMeHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.MiniArticleSearchMeRequest
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
result.HttpResult(r, w, nil, err)
return
}
... ...
... ... @@ -15,7 +15,7 @@ func MiniArticleSetTagHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.MiniArticleSetTagRequest
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
result.HttpResult(r, w, nil, err)
return
}
... ...
... ... @@ -15,7 +15,7 @@ func MiniCreateArticleDraftHandler(svcCtx *svc.ServiceContext) http.HandlerFunc
return func(w http.ResponseWriter, r *http.Request) {
var req types.MiniArticleDraftCreateRequest
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
result.HttpResult(r, w, nil, err)
return
}
... ...
... ... @@ -15,7 +15,7 @@ func MiniCreateArticleHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.MiniArticleCreateRequest
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
result.HttpResult(r, w, nil, err)
return
}
token := contextdata.GetUserTokenFromCtx(r.Context())
... ...
... ... @@ -15,7 +15,7 @@ func MiniDeleteArticleDraftMeHandler(svcCtx *svc.ServiceContext) http.HandlerFun
return func(w http.ResponseWriter, r *http.Request) {
var req types.MiniArticleDraftDeleteMeRequest
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
result.HttpResult(r, w, nil, err)
return
}
... ...
... ... @@ -7,22 +7,23 @@ import (
"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"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/contextdata"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/result"
)
func MiniGetArticleDraftMeHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.MiniArticleDraftGetMeRequest
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
result.HttpResult(r, w, nil, err)
return
}
l := article.NewMiniGetArticleDraftMeLogic(r.Context(), svcCtx)
token := contextdata.GetUserTokenFromCtx(r.Context())
req.AuthorId = token.UserId
req.CompanyId = token.CompanyId
resp, err := l.MiniGetArticleDraftMe(&req)
if err != nil {
httpx.ErrorCtx(r.Context(), w, err)
} else {
httpx.OkJsonCtx(r.Context(), w, resp)
}
result.HttpResult(r, w, resp, err)
}
}
... ...
... ... @@ -15,7 +15,7 @@ func MiniGetArticleHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.MiniArticleGetRequest
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
result.HttpResult(r, w, nil, err)
return
}
... ...
... ... @@ -15,7 +15,7 @@ func MiniSearchArticleDraftMeHandler(svcCtx *svc.ServiceContext) http.HandlerFun
return func(w http.ResponseWriter, r *http.Request) {
var req types.MiniArticleDraftSearchMeRequest
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
result.HttpResult(r, w, nil, err)
return
}
... ...
... ... @@ -15,7 +15,7 @@ func MiniSetUserLikeHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.MiniSetUserLikeRequset
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
result.HttpResult(r, w, nil, err)
return
}
... ...
... ... @@ -15,7 +15,7 @@ func MiniUpdateArticleDraftHandler(svcCtx *svc.ServiceContext) http.HandlerFunc
return func(w http.ResponseWriter, r *http.Request) {
var req types.MiniArticleDraftUpdateRequest
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
result.HttpResult(r, w, nil, err)
return
}
l := article.NewMiniUpdateArticleDraftLogic(r.Context(), svcCtx)
... ...
... ... @@ -15,7 +15,7 @@ func MiniUserLikeArticleHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.MiniUserLikeArticleRequest
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
result.HttpResult(r, w, nil, err)
return
}
... ...
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 SystemArticleGetHistoryHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.SystemArticleGetHistoryRequest
if err := httpx.Parse(r, &req); err != nil {
result.ParamErrorResult(r, w, err)
return
}
l := article.NewSystemArticleGetHistoryLogic(r.Context(), svcCtx)
resp, err := l.SystemArticleGetHistory(&req)
result.HttpResult(r, w, resp, err)
}
}
... ...
... ... @@ -15,7 +15,7 @@ func SystemGetArticleHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.SystemArticleGetRequest
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
result.ParamErrorResult(r, w, err)
return
}
... ...
package article
import (
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/result"
"net/http"
"github.com/zeromicro/go-zero/rest/httpx"
... ... @@ -13,16 +14,12 @@ func SystemHistoryArticleHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.SystemArticleHistoryRequest
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
result.ParamErrorResult(r, w, err)
return
}
l := article.NewSystemHistoryArticleLogic(r.Context(), svcCtx)
resp, err := l.SystemHistoryArticle(&req)
if err != nil {
httpx.ErrorCtx(r.Context(), w, err)
} else {
httpx.OkJsonCtx(r.Context(), w, resp)
}
result.HttpResult(r, w, resp, err)
}
}
... ...
... ... @@ -15,7 +15,7 @@ func SystemSearchArticleHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.SystemArticleSearchRequest
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
result.ParamErrorResult(r, w, err)
return
}
... ...
package article
import (
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/result"
"net/http"
"github.com/zeromicro/go-zero/rest/httpx"
... ... @@ -13,16 +14,11 @@ func SystemUpdateArticleHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.SystemArticleUpdateRequest
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
result.ParamErrorResult(r, w, err)
return
}
l := article.NewSystemUpdateArticleLogic(r.Context(), svcCtx)
resp, err := l.SystemUpdateArticle(&req)
if err != nil {
httpx.ErrorCtx(r.Context(), w, err)
} else {
httpx.OkJsonCtx(r.Context(), w, resp)
}
resp, err := l.SystemUpdateArticle(&req, r.Header.Get("x-mmm-accesstoken"))
result.HttpResult(r, w, resp, err)
}
}
... ...
... ... @@ -15,7 +15,7 @@ func MiniArticleCommentAtWhoHandler(svcCtx *svc.ServiceContext) http.HandlerFunc
return func(w http.ResponseWriter, r *http.Request) {
var req types.MiniArticleCommentAtWhoRequest
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
result.HttpResult(r, w, nil, err)
return
}
... ...
... ... @@ -15,7 +15,7 @@ func MiniCreateArticleCommentHandler(svcCtx *svc.ServiceContext) http.HandlerFun
return func(w http.ResponseWriter, r *http.Request) {
var req types.MiniCreateArticleCommentRequest
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
result.HttpResult(r, w, nil, err)
return
}
l := comment.NewMiniCreateArticleCommentLogic(r.Context(), svcCtx)
... ...
... ... @@ -15,7 +15,7 @@ func MiniDeleteArticleCommentHandler(svcCtx *svc.ServiceContext) http.HandlerFun
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)
result.HttpResult(r, w, nil, err)
return
}
... ...
... ... @@ -15,7 +15,7 @@ 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)
result.HttpResult(r, w, nil, err)
return
}
... ...
... ... @@ -15,7 +15,7 @@ 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)
result.HttpResult(r, w, nil, err)
return
}
l := comment.NewMiniListArticleCommentLogic(r.Context(), svcCtx)
... ...
... ... @@ -15,7 +15,7 @@ func MiniTop5ArticleCommentHandler(svcCtx *svc.ServiceContext) http.HandlerFunc
return func(w http.ResponseWriter, r *http.Request) {
var req types.MiniTop5ArticleCommentRequest
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
result.HttpResult(r, w, nil, err)
return
}
... ...
... ... @@ -392,6 +392,11 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
Handler: article.SystemHistoryArticleHandler(serverCtx),
},
{
Method: http.MethodGet,
Path: "/article/history/:id",
Handler: article.SystemArticleGetHistoryHandler(serverCtx),
},
{
Method: http.MethodPost,
Path: "/article/search/me",
Handler: article.SystemArticleSearchMeHandler(serverCtx),
... ...
... ... @@ -15,7 +15,7 @@ func CreateTagHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.TagCreateRequest
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
result.HttpResult(r, w, nil, err)
return
}
... ...
... ... @@ -15,7 +15,7 @@ func DeleteTagHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.TagDeleteRequest
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
result.HttpResult(r, w, nil, err)
return
}
... ...
... ... @@ -15,7 +15,7 @@ func EditTagHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.TagEditRequest
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
result.HttpResult(r, w, nil, err)
return
}
... ...
... ... @@ -15,7 +15,7 @@ func GetTagHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.TagGetRequest
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
result.HttpResult(r, w, nil, err)
return
}
token := contextdata.GetUserTokenFromCtx(r.Context())
... ...
... ... @@ -15,7 +15,7 @@ func SearchTagHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.TagListRequest
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
result.HttpResult(r, w, nil, err)
return
}
... ...
package article
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 SystemArticleGetHistoryLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewSystemArticleGetHistoryLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SystemArticleGetHistoryLogic {
return &SystemArticleGetHistoryLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *SystemArticleGetHistoryLogic) SystemArticleGetHistory(req *types.SystemArticleGetHistoryRequest) (resp *types.SystemArticleGetHistoryResponse, err error) {
//var conn = l.svcCtx.DefaultDBConn()
return
}
... ...
... ... @@ -63,6 +63,21 @@ func (l *SystemGetArticleLogic) SystemGetArticle(req *types.SystemArticleGetRequ
CountComment: article.CountComment,
CountRead: article.CountRead,
Show: int(article.Show),
Tags: make([]types.ArticleTagItem, 0),
}
//标签
if len(article.Tags) > 0 {
_, tags, err := l.svcCtx.ArticleTagRepository.Find(l.ctx, conn, article.CompanyId, domain.NewQueryOptions().WithKV("ids", article.Tags))
if err == nil && len(tags) > 0 {
lo.ForEach(tags, func(tag *domain.ArticleTag, index int) {
resp.Tags = append(resp.Tags, types.ArticleTagItem{
Id: tag.Id,
Group: tag.Category,
Name: tag.Name,
Image: tag.Image.Url,
})
})
}
}
//文章段落
_, articleSections, err := l.svcCtx.ArticleSectionRepository.Find(l.ctx, conn, domain.NewQueryOptions().WithKV("articleId", req.Id))
... ...
... ... @@ -2,7 +2,9 @@ package article
import (
"context"
"github.com/samber/lo"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/domain"
"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"
... ... @@ -26,13 +28,30 @@ func NewSystemHistoryArticleLogic(ctx context.Context, svcCtx *svc.ServiceContex
func (l *SystemHistoryArticleLogic) SystemHistoryArticle(req *types.SystemArticleHistoryRequest) (resp *types.SystemArticleHistoryResponse, err error) {
var conn = l.svcCtx.DefaultDBConn()
l.svcCtx.ArticleBackupRepository.Find(
total, list, err := l.svcCtx.ArticleBackupRepository.Find(
l.ctx,
conn,
domain.NewQueryOptions().
WithOffsetLimit(req.Page, req.Size).
WithKV("articleId", req.ArticleId).
WithKV("author", req.Author).
WithKV("updatedAt", req.UpdatedAt),
WithKV("operator", req.Author).
WithKV("beginCreatedAt", req.BeginTime).
WithKV("endCreatedAt", req.EndTime),
)
if err != nil {
return nil, xerr.NewErrMsgErr("搜索编辑历史异常", err)
}
resp = &types.SystemArticleHistoryResponse{
Total: int(total),
List: make([]types.SystemArticleHistory, 0),
}
lo.ForEach(list, func(item *domain.ArticleBackup, index int) {
resp.List = append(resp.List, types.SystemArticleHistory{
Id: item.Id,
Author: item.Operator.Name,
Action: item.Action,
UpdatedAt: item.CreatedAt,
})
})
return
}
... ...
... ... @@ -2,14 +2,11 @@ package article
import (
"context"
"github.com/jinzhu/now"
"github.com/samber/lo"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/xerr"
"time"
"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"
)
... ... @@ -30,14 +27,12 @@ func NewSystemSearchArticleLogic(ctx context.Context, svcCtx *svc.ServiceContext
func (l *SystemSearchArticleLogic) SystemSearchArticle(req *types.SystemArticleSearchRequest) (resp *types.SystemArticleSearchResponse, err error) {
var conn = l.svcCtx.DefaultDBConn()
queryOptions := domain.NewQueryOptions().WithOffsetLimit(req.PageNumber, req.PageSize).WithKV("title", req.Title).WithKV("author", req.Author)
if req.PublishDate != "" {
publishTime, err := now.ParseInLocation(time.Local, req.PublishDate)
if err == nil {
queryOptions.WithKV("beginCreatedAt", now.With(publishTime).BeginningOfDay().Unix())
queryOptions.WithKV("endCreatedAt", now.With(publishTime).EndOfDay().Unix())
}
}
queryOptions := domain.NewQueryOptions().
WithOffsetLimit(req.Page, req.Size).
WithKV("title", req.Title).
WithKV("author", req.Author).
WithKV("beginCreatedAt", req.BeginTime).
WithKV("endCreatedAt", req.EndTime)
total, articles, err := l.svcCtx.ArticleRepository.Find(l.ctx, conn, req.CompanyId, queryOptions)
if err != nil {
return nil, xerr.NewErrMsgErr("搜索帖子异常", err)
... ...
... ... @@ -5,6 +5,8 @@ import (
"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/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"
... ... @@ -27,8 +29,9 @@ func NewSystemUpdateArticleLogic(ctx context.Context, svcCtx *svc.ServiceContext
}
}
func (l *SystemUpdateArticleLogic) SystemUpdateArticle(req *types.SystemArticleUpdateRequest) (resp *types.SystemArticleUpdateResponse, err error) {
func (l *SystemUpdateArticleLogic) SystemUpdateArticle(req *types.SystemArticleUpdateRequest, accessToken string) (resp *types.SystemArticleUpdateResponse, err error) {
var conn = l.svcCtx.DefaultDBConn()
userToken := contextdata.GetUserTokenFromCtx(l.ctx)
article, err := l.svcCtx.ArticleRepository.FindOne(l.ctx, conn, req.Id)
if err != nil {
return nil, xerr.NewErrMsgErr("帖子不存在", err)
... ... @@ -53,6 +56,7 @@ func (l *SystemUpdateArticleLogic) SystemUpdateArticle(req *types.SystemArticleU
Latitude: req.Location.Latitude,
Descript: req.Location.Descript,
}
article.Tags = req.Tags
//文章内容
articleSections := []domain.ArticleSection{}
lo.ForEach(req.Section, func(item types.ArticleSection, index int) {
... ... @@ -79,8 +83,13 @@ func (l *SystemUpdateArticleLogic) SystemUpdateArticle(req *types.SystemArticleU
}
article.Summary = req.Section[0].Content[0:stringIndex]
}
//获取当前用户信息
userMe, err := l.svcCtx.ApiAuthService.MeInfo(l.ctx, authlib.RequestUserMeQuery{Token: accessToken})
if err != nil {
return nil, xerr.NewErrMsgErr("获取当前用户信息失败", err)
}
err = transaction.UseTrans(l.ctx, conn.DB(), func(ctx context.Context, c transaction.Conn) error {
_, err = l.svcCtx.ArticleRepository.Update(l.ctx, conn, article)
_, err = l.svcCtx.ArticleRepository.Update(l.ctx, c, article)
if err != nil {
return xerr.NewErrMsgErr("保存文章失败", err)
}
... ... @@ -116,7 +125,13 @@ func (l *SystemUpdateArticleLogic) SystemUpdateArticle(req *types.SystemArticleU
}
}
//备份数据
backup := article.MakeBackup(article.Author, articleSections)
backup := article.MakeBackup(domain.UserSimple{
Id: userToken.UserId,
Name: userMe.User.NickName,
Avatar: userMe.User.Avatar,
CompanyId: userToken.CompanyId,
Company: userMe.CurrentCompany.Name,
}, articleSections)
backup.Action = "编辑"
_, err = l.svcCtx.ArticleBackupRepository.Insert(ctx, c, backup)
if err != nil {
... ... @@ -124,5 +139,16 @@ func (l *SystemUpdateArticleLogic) SystemUpdateArticle(req *types.SystemArticleU
}
return nil
}, true)
resp = &types.SystemArticleUpdateResponse{
Id: article.Id,
Title: article.Title,
Images: req.Images,
CreatedAt: article.CreatedAt,
CountLove: article.CountLove,
CountComment: article.CountComment,
Show: int(article.Show),
TargetUser: int(article.TargetUser),
Tags: article.Tags,
}
return
}
... ...
... ... @@ -299,12 +299,9 @@ type MiniUserInfoRequest struct {
}
type MiniUserInfoResponse struct {
User *UserItem `json:"user,omitempty"` // 用户信息
TotalArticle int64 `json:"totalArticle"` // 累计信息发布
TotalLoved int64 `json:"totalLoved"` // 累计收到的赞
TotalAccepted int64 `json:"totalAccepted"` // 累计被采纳
Accounts []Account `json:"accounts"` // 公司账号
Auths []Auth `json:"auths"` // 权限列表
User *UserItem `json:"user,omitempty"` // 用户信息
Accounts []Account `json:"accounts"` // 公司账号
Auths []Auth `json:"auths"` // 权限列表
}
type MiniUserApplyJoinCompanyRequest struct {
... ... @@ -890,15 +887,18 @@ type SystemArticleGetResponse struct {
CountComment int `json:"countComment"` // 评论数量
CountRead int `json:"countRead"` // 浏览数量
Show int `json:"show"` // 评论的展示状态(0显示、1不显示)
Tags []ArticleTagItem `json:"tags"` //标签
}
type SystemArticleSearchRequest struct {
CompanyId int64 `json:",optional"`
Title string `json:"title"` //标题
Author string `json:"author"` //发布人
PublishDate string `json:"publishDate"` //发布日期
PageNumber int `json:"pageNumber"` //页码
PageSize int `json:"pageSize"` //每页行数
CompanyId int64 `json:"companyId,optional"`
Title string `json:"title,optional"` //标题
Author string `json:"author,optional"` //发布人
BeginTime int64 `json:"beginTime,optional"` //开始时间
EndTime int64 `json:"endTime,optional"` //结束时间
Tags []int64 `json:"tags,optional"` //标签
Page int `json:"page"` //页码
Size int `json:"size"` //每页行数
}
type SystemArticleSearchResponse struct {
... ... @@ -921,7 +921,7 @@ type SystemArticleSearch struct {
type SystemArticleUpdateRequest struct {
Id int64 `json:"id"`
CompanyId int64 `json:",optional"`
CompanyId int64 `json:"companyId,optional"`
Template int `json:"template"` // 使用哪个模板进行编辑 0、无 1、演绎式 2、归纳式
Section []ArticleSection `json:"section"` // 填写的内容
Title string `json:"title"` // 标题
... ... @@ -930,6 +930,7 @@ type SystemArticleUpdateRequest struct {
WhoReview []int64 `json:"whoReview"` // 评论人
Location Location `json:"location"` // 坐标
TargetUser int `json:"targetUser"` //分发方式 [0分发给所有人、1分发给指定的人]
Tags []int64 `json:"tags"` // 标签
}
type SystemArticleUpdateResponse struct {
... ... @@ -941,21 +942,55 @@ type SystemArticleUpdateResponse struct {
CountLove int `json:"countLove"` //点赞数量
CountComment int `json:"CountComment"` //评论数量
Show int `json:"show"` //是否隐藏 [0显示、1不显示]
Tags []string `json:"tags"` //标签
Tags []int64 `json:"tags"` //标签
TargetUser int `json:"targetUser"` //分发方式 [0分发给所有人、1分发给指定的人]
}
type SystemArticleHistoryRequest struct {
ArticleId int64 `json:"articleId"` //文章ID
Author string `json:"author,optional"` //发布人
UpdatedAt string `json:"updatedAt,optional"` //修改日期
BeginTime int64 `json:"beginTime,optional"` //开始时间
EndTime int64 `json:"endTime,optional"` //结束时间
Page int `json:"page"` //页码
Size int `json:"size"` //每页行数
}
type SystemArticleHistoryResponse struct {
Total int `json:"total"`
List []SystemArticleHistory `json:"list"`
}
type SystemArticleHistory struct {
Id int64 `json:"id"` //id
Author string `json:"author"` //编辑人
Action string `json:"action"` //编辑类型
UpdatedAt string `json:"updatedAt"` //编辑时间
UpdatedAt int64 `json:"updatedAt"` //编辑时间
}
type SystemArticleGetHistoryRequest struct {
Id int64 `path:"id"` //id
CompanyId int64 `path:",optional"`
}
type SystemArticleGetHistoryResponse struct {
Id int64 `json:"id"` // id
ArticleId int64 `json:"articleId"` // 文章ID
Title string `json:"title"` // 标题
AuthorId int64 `json:"authorId"` // 发布人id
Author ArticleAuthor `json:"author"` // 发布人
CreatedAt int64 `json:"createdAt"` // 文章的发布时间
Section []ArticleSection `json:"section"` // 文章的文本内容
Images []string `json:"images"` // 图片
WhoRead []int64 `json:"whoRead"` // 谁可查看
WhoReadInfo []UserShowName `json:"whoReadInfo"` // 谁可查看
WhoReview []int64 `json:"whoReview"` // 谁可评论
WhoReviewInfo []UserShowName `json:"whoReviewInfo"` // 谁可评论
Location Location `json:"location"` // 定位坐标
CountLove int `json:"countLove"` // 点赞数量
CountComment int `json:"countComment"` // 评论数量
CountRead int `json:"countRead"` // 浏览数量
Show int `json:"show"` // 评论的展示状态(0显示、1不显示)
TargetUser int `json:"targetUser"` //分发方式 [0分发给所有人、1分发给指定的人]
}
type RoleGetRequest struct {
... ...
... ... @@ -53,3 +53,10 @@ func (m *ArticleAndTag) CachePrimaryKeyFunc() string {
}
return fmt.Sprintf("%v:cache:%v:primarykey:%v", domain.ProjectName, m.TableName(), "key")
}
// 统计所有已有标签的文章和人员已读的文章
type CountArticleTagRead struct {
TotalArticle int `gorm:"total_article"` //标签下文章的数量
ReadArticle int `gorm:"read_article"` //人员已读的文章
TagId int64 `gorm:"tag_id"` // 标签的id
}
... ...
... ... @@ -2,6 +2,7 @@ package repository
import (
"context"
"fmt"
"github.com/jinzhu/copier"
"github.com/pkg/errors"
... ... @@ -132,6 +133,59 @@ func (repository *ArticleAndTagRepository) DomainModelToModel(from *domain.Artic
return to, err
}
// 以TagId作为分组,统计所有已有标签的文章和人员已读的文章
func (repository *ArticleAndTagRepository) CountArticleReadGroupByTag(ctx context.Context, conn transaction.Conn, userId int64, companyId int64) ([]*domain.CountArticleTagRead, error) {
sqlStr := `
-- 首页统计数据
with
-- 按查看权限查询文章
-- 获取有标签的文章
-- 过滤出可展示的文章id
t_article_and_tag_2 as (
select article_and_tag.article_id , article_and_tag.tag_id
from article_and_tag
join article on article_and_tag.article_id = article.id
where article.deleted_at=0
and article.company_id =1598224576532189184
and article."show" =0
and (article.target_user =0 or article.who_read @>'[1]')
),
-- 查询人员已查看的文章
t_user_read as(
select user_read_article.article_id from user_read_article where user_read_article.user_id =1
)
-- 汇总统计 total_article 符合条件的文章总数,read_article 已浏览的数量
select count(t_article_and_tag_2.article_id) as total_article ,count(t_user_read.article_id) as read_article, t_article_and_tag_2.tag_id
from t_article_and_tag_2
left join t_user_read on t_article_and_tag_2.article_id=t_user_read.article_id
group by t_article_and_tag_2.tag_id
`
condition := []interface{}{
companyId,
fmt.Sprintf("[%d]", userId),
userId,
}
m := []*models.CountArticleTagRead{}
db := conn.DB()
result := db.Raw(sqlStr, condition...).Scan(&m)
if result.Error != nil {
return nil, result.Error
}
var dm []*domain.CountArticleTagRead
for _, val := range m {
dm = append(dm, &domain.CountArticleTagRead{
TagId: val.TagId,
TotalArticle: val.TotalArticle,
ReadArticle: val.ReadArticle,
})
}
return dm, nil
}
func NewArticleAndTagRepository(cache *cache.CachedRepository) domain.ArticleAndTagRepository {
return &ArticleAndTagRepository{CachedRepository: cache}
}
... ...
... ... @@ -120,6 +120,18 @@ func (repository *ArticleBackupRepository) Find(ctx context.Context, conn transa
)
queryFunc := func() (interface{}, error) {
tx = tx.Model(&ms).Order("id desc")
if v, ok := queryOptions["beginCreatedAt"]; ok {
tx = tx.Where("created_at >= ?", v)
}
if v, ok := queryOptions["endCreatedAt"]; ok {
tx = tx.Where("created_at < ?", v)
}
if v, ok := queryOptions["articleId"]; ok {
tx = tx.Where("article_id = ?", v)
}
if v, ok := queryOptions["operator"]; ok && v.(string) != "" {
tx = tx.Where(`operator #>> '{"name"}' like ?`, "%"+v.(string)+"%")
}
if total, tx = transaction.PaginationAndCount(ctx, tx, queryOptions, &ms); tx.Error != nil {
return dms, tx.Error
}
... ...
... ... @@ -126,7 +126,7 @@ func (repository *ArticleRepository) Find(ctx context.Context, conn transaction.
if v, ok := queryOptions["title"]; ok && v.(string) != "" {
tx = tx.Where("title like ?", "%"+v.(string)+"%")
}
if v, ok := queryOptions["author"]; ok {
if v, ok := queryOptions["author"]; ok && v.(string) != "" {
tx = tx.Where(`author #>> '{"name"}' like ?`, "%"+v.(string)+"%")
}
if v, ok := queryOptions["beginCreatedAt"]; ok {
... ... @@ -278,34 +278,27 @@ func NewArticleRepository(cache *cache.CachedRepository) domain.ArticleRepositor
return &ArticleRepository{CachedRepository: cache}
}
// -- 首页统计数据
// with
// -- 按查看权限查询文章
// t_article as(
// select article.id
// from article
// -- 获取有标签的文章
// -- 过滤出可展示的文章id
// t_article_and_tag_2 as (
// select article_and_tag.article_id , article_and_tag.tag_id
// from article_and_tag
// join article on article_and_tag.article_id = article.id
// where article.deleted_at=0
// and article.company_id =1598224576532189184
// and article."show" =0
// and (article.target_user =0 or article.who_read @>'[1]')
// ),
// -- 获取有标签的文章
// t_article_and_tag as (
// select article_and_tag.article_id ,article_and_tag.tag_id
// from article_and_tag
// where article_and_tag.company_id =1598224576532189184
// ),
// -- 过滤出可展示的文章id
// t_article_and_tag_2 as (
// select t_article_and_tag.article_id, t_article_and_tag.tag_id
// from t_article_and_tag
// join t_article on t_article_and_tag.article_id = t_article.id
// ),
// -- 查询人员已查看的文章
// t_user_read as(
// select user_read_article.article_id from user_read_article where user_read_article.user_id =1
// select user_read_article.article_id from user_read_article where user_read_article.user_id =1
// )
// -- 汇总统计 cnt_1符合条件的文章总数,cnt_2 已浏览的数量
// select count(t_article_and_tag_2.article_id) as cnt_1 ,count(t_user_read.article_id) as cnt_2, t_article_and_tag_2.tag_id
// from t_article_and_tag_2
// left join t_user_read on t_article_and_tag_2.article_id=t_user_read.article_id
// group by t_article_and_tag_2.tag_id
// ;
... ...
... ... @@ -130,6 +130,9 @@ func (repository *ArticleTagRepository) Find(ctx context.Context, conn transacti
if v, ok := queryOptions["category"]; ok {
tx = tx.Where("category like ?", v)
}
if v, ok := queryOptions["ids"]; ok {
tx = tx.Where("id in (?)", v)
}
if total, tx = transaction.PaginationAndCount(ctx, tx, queryOptions, &ms); tx.Error != nil {
return dms, tx.Error
... ...
... ... @@ -86,7 +86,7 @@ func (m *Article) MakeBackup(operator UserSimple, section []ArticleSection) *Art
CreatedAt: 0,
UpdatedAt: 0,
DeletedAt: 0,
Version: 0,
Version: m.Version,
Operator: operator,
ArticleId: m.Id,
Title: m.Title,
... ...
... ... @@ -16,10 +16,18 @@ type ArticleAndTag struct {
TagId int64 `json:"tagId"`
}
// 以TagId作为分组,统计所有已有标签的文章和人员已读的文章
type CountArticleTagRead struct {
TotalArticle int `gorm:"total_article"` //标签下文章的数量
ReadArticle int `gorm:"read_article"` //人员已读的文章
TagId int64 `gorm:"tag_id"` // 标签的id
}
type ArticleAndTagRepository interface {
Insert(ctx context.Context, conn transaction.Conn, dm *ArticleAndTag) (*ArticleAndTag, error)
Update(ctx context.Context, conn transaction.Conn, dm *ArticleAndTag) (*ArticleAndTag, error)
Delete(ctx context.Context, conn transaction.Conn, dm *ArticleAndTag) (*ArticleAndTag, error)
FindOne(ctx context.Context, conn transaction.Conn, id int64) (*ArticleAndTag, error)
Find(ctx context.Context, conn transaction.Conn, queryOptions map[string]interface{}) (int64, []*ArticleAndTag, error)
CountArticleReadGroupByTag(ctx context.Context, con transaction.Conn, userId int64, companyId int64) ([]*CountArticleTagRead, error)
}
... ...