作者 yangfu

用户列表

正在显示 61 个修改的文件 包含 950 行增加234 行删除
... ... @@ -751,32 +751,6 @@
]
}
},
"v1/mini/user/at-users-list": {
"post": {
"summary": "@用户列表",
"operationId": "miniAtUsersList",
"responses": {
"200": {
"description": "A successful response.",
"schema": {}
}
},
"parameters": [
{
"name": "body",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/MiniAtUsersListRequest"
}
}
],
"requestBody": {},
"tags": [
"user"
]
}
},
"v1/mini/user/audit": {
"post": {
"summary": "用户审核",
... ... @@ -838,7 +812,9 @@
"responses": {
"200": {
"description": "A successful response.",
"schema": {}
"schema": {
"$ref": "#/definitions/MiniUserInfoResponse"
}
}
},
"parameters": [
... ... @@ -1275,6 +1251,34 @@
]
}
},
"v1/system/article/restore": {
"post": {
"summary": "管理后台文章恢复",
"operationId": "SystemArticleRestore",
"responses": {
"200": {
"description": "A successful response.",
"schema": {
"$ref": "#/definitions/SystemArticleRestoreResponse"
}
}
},
"parameters": [
{
"name": "body",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/SystemArticleRestoreRequest"
}
}
],
"requestBody": {},
"tags": [
"article"
]
}
},
"v1/system/article/search": {
"post": {
"summary": "管理后台获取文章列表",
... ... @@ -3823,17 +3827,6 @@
"id"
]
},
"MiniAtUsersListRequest": {
"type": "object",
"properties": {
"articleId": {
"type": "integer",
"format": "int64",
"description": " 按文章ID(返回文章可见的用户)"
}
},
"title": "MiniAtUsersListRequest"
},
"MiniCreateArticleCommentRequest": {
"type": "object",
"properties": {
... ... @@ -4337,6 +4330,21 @@
"$ref": "#/definitions/UserItem",
"description": " 用户信息"
},
"totalArticle": {
"type": "integer",
"format": "int64",
"description": " 累计信息发布"
},
"totalLoved": {
"type": "integer",
"format": "int64",
"description": " 累计收到的赞"
},
"totalAccepted": {
"type": "integer",
"format": "int64",
"description": " 累计被采纳"
},
"accounts": {
"type": "array",
"items": {
... ... @@ -4355,6 +4363,9 @@
"title": "MiniUserInfoResponse",
"required": [
"user",
"totalArticle",
"totalLoved",
"totalAccepted",
"accounts",
"auths"
]
... ... @@ -4969,15 +4980,6 @@
"type": "string",
"description": " 标题"
},
"authorId": {
"type": "integer",
"format": "int64",
"description": " 发布人id"
},
"author": {
"$ref": "#/definitions/ArticleAuthor",
"description": " 发布人"
},
"createdAt": {
"type": "integer",
"format": "int64",
... ... @@ -5031,30 +5033,18 @@
"$ref": "#/definitions/Location",
"description": " 定位坐标"
},
"countLove": {
"type": "integer",
"format": "int32",
"description": " 点赞数量"
},
"countComment": {
"type": "integer",
"format": "int32",
"description": " 评论数量"
},
"countRead": {
"type": "integer",
"format": "int32",
"description": " 浏览数量"
},
"show": {
"type": "integer",
"format": "int32",
"description": " 评论的展示状态(0显示、1不显示)"
},
"targetUser": {
"type": "integer",
"format": "int32",
"description": "分发方式 [0分发给所有人、1分发给指定的人]"
"description": " 分发方式 [0分发给所有人、1分发给指定的人]"
},
"tags": {
"type": "array",
"items": {
"type": "integer",
"format": "int64"
},
"description": " 标签"
}
},
"title": "SystemArticleGetHistoryResponse",
... ... @@ -5062,8 +5052,6 @@
"id",
"articleId",
"title",
"authorId",
"author",
"createdAt",
"section",
"images",
... ... @@ -5072,11 +5060,8 @@
"whoReview",
"whoReviewInfo",
"location",
"countLove",
"countComment",
"countRead",
"show",
"targetUser"
"targetUser",
"tags"
]
},
"SystemArticleGetRequest": {
... ... @@ -5310,6 +5295,45 @@
"list"
]
},
"SystemArticleRestoreRequest": {
"type": "object",
"properties": {
"id": {
"type": "integer",
"format": "int64",
"description": "ID"
},
"AccessToken": {
"type": "string",
"description": " 授权token"
}
},
"title": "SystemArticleRestoreRequest",
"required": [
"id",
"x-mmm-accesstoken"
]
},
"SystemArticleRestoreResponse": {
"type": "object",
"properties": {
"id": {
"type": "integer",
"format": "int64",
"description": "ID"
},
"articleId": {
"type": "integer",
"format": "int64",
"description": "文章ID"
}
},
"title": "SystemArticleRestoreResponse",
"required": [
"id",
"articleId"
]
},
"SystemArticleSearch": {
"type": "object",
"properties": {
... ...
... ... @@ -72,6 +72,14 @@ service Core {
@doc "小程序所有的定性标签"
@handler MiniAllArticleTag
get /article_tag/list/all (MiniAllArticleTagRequest) returns (MiniAllArticleTagResponse)
@doc "小程序首页数据展示"
@handler MiniShowHomePage
get /show/home_page (MiniHomePageRequest) returns (MiniHomePageResponse)
@doc "小程序首页搜索文章"
@handler MiniSearchArticlePage
post /show/search_article (MiniSearchArticleRequest) returns (MiniSearchArticleResponse)
}
// 管理后台接口
... ... @@ -105,4 +113,7 @@ service Core {
@handler SystemArticleSearchMe
post /article/search/me (SystemArticleSearchMeRequest) returns (SystemArticleSearchMeResponse)
@doc "管理后台文章恢复"
@handler SystemArticleRestore
post /article/restore (SystemArticleRestoreRequest) returns (SystemArticleRestoreResponse)
}
\ No newline at end of file
... ...
... ... @@ -53,9 +53,10 @@ type (
CountLove int `json:"countLove"` // 点赞数量
CountComment int `json:"countComment"` // 评论数量
CountRead int `json:"countRead"` // 浏览数量
Show int `json:"show"` // 评论的展示状态(0显示、1不显示)
Show int `json:"show"` // 评论的展示状态(1显示、2不显示)
Edit int `json:"edit"` // 文章是否存在变更记录 (0 不存在 1存在)
MeLoveFlag int `json:"meLoveFlag"` // 当前人员对文章的点赞标识 (0 没有点赞 1有点赞)
Tags []string `json:"tags"` //文章的标签
}
ArticleSection {
Id int64 `json:"id"` //段落id
... ... @@ -281,13 +282,13 @@ type (
}
MiniArticleMarkItem {
Id int64 `json:"id"`
CompanyId int64 `json:"companyId"`
UserId int64 `json:"userId"`
ArticleId int64 `json:"articleId"`
Title string `json:"title"`
Id int64 `json:"id"`
CompanyId int64 `json:"companyId"`
UserId int64 `json:"userId"`
ArticleId int64 `json:"articleId"`
Title string `json:"title"`
Author SimpleUser `json:"author"` // 发布人
UpdatedAt int64 `json:"updatedAt"`
UpdatedAt int64 `json:"updatedAt"`
}
)
... ... @@ -314,14 +315,14 @@ type (
TagGroup []ArticleTagGroup `json:"tagGroup"`
}
ArticleTagGroup {
Group string `json:"group"`
Category string `json:"category"`
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"`
Category string `json:"category"`
Name string `json:"name"`
Image string `json:"image"`
}
)
... ... @@ -389,17 +390,18 @@ 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分发给指定的人]
Tags []int64 `json:"tags"` // 标签
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"` // 标签
AccessToken string `header:"x-mmm-accesstoken"` // 授权token
}
SystemArticleUpdateResponse {
Id int64 `json:"id"` //id
... ... @@ -408,7 +410,7 @@ type (
Images []string `json:"images"` //图片
CreatedAt int64 `json:"createdAt"` //文章的创建日期
CountLove int `json:"countLove"` //点赞数量
CountComment int `json:"CountComment"` //评论数量
CountComment int `json:"countComment"` //评论数量
Show int `json:"show"` //是否隐藏 [0显示、1不显示]
Tags []int64 `json:"tags"` //标签
TargetUser int `json:"targetUser"` //分发方式 [0分发给所有人、1分发给指定的人]
... ... @@ -440,8 +442,6 @@ type (
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"` // 图片
... ... @@ -450,10 +450,66 @@ type (
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分发给指定的人]
TargetUser int `json:"targetUser"` // 分发方式 [0分发给所有人、1分发给指定的人]
Tags []int64 `json:"tags"` // 标签
}
SystemArticleRestoreRequest {
Id int64 `json:"id"` //ID
AccessToken string `header:"x-mmm-accesstoken"` // 授权token
}
SystemArticleRestoreResponse {
Id int64 `json:"id"` //ID
ArticleId int64 `json:"articleId"` //文章ID
}
)
//小程序端 首页数据展示
// 统计各标签下的文章数量,和已被人员阅读的数量
type (
MiniHomePageRequest {
CompanyId int64 `path:",optional"`
UserId int64 `path:",optional"`
}
MiniHomePageResponse {
TagCategory []string `json:"tagCategory"`
Tags []ArticleTagCount `json:"tags"`
}
ArticleTagCount {
TagCategory string `json:"tagCategory"` // 标签分组
TagId int64 `json:"tagId"` // 标签id
TagImage string `json:"tagImage"` // 对应的图标
TagName string `json:"tagName"` // 标签名称
TagRemark string `json:"tagRemark"` // 标签备注
TotalArticle int `json:"totalArticle"` // 总的文章数量
ReadArticle int `json:"readArticle"` // 已读的标签数量
}
)
//小程序首页搜索文章
type (
MiniSearchArticleRequest {
Page int `json:"page"`
Size int `json:"size"`
CompanyId int64 `json:",optional"`
UserId int64 `json:",optional"`
TagGroup string `json:"tagGroup"`
TagId int64 `json:"tagId"`
BeginTime int64 `json:"beginTime"`
EndTime int `json:"endTime"`
SearchWord string `json:"searchWord"`
}
//
MiniSearchArticleResponse {
Total int `json:"total"`
List []MiniSearchArticleItem `json:"list"`
}
//
MiniSearchArticleItem{
ArticleId int64 `json:"articleId"`
Title string `json:"title"`
Author string `json:"author"` // 发布人
Images []string `json:"images"`
CreatedAt int64 `json:"createdAt"`
MeReadFlag int `json:"meReadFlag"` //已读标识 [0:未读] [1:已读]
}
)
\ No newline at end of file
... ...
... ... @@ -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
}
... ...
package article
import (
"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 MiniSearchArticlePageHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.MiniSearchArticleRequest
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
return
}
l := article.NewMiniSearchArticlePageLogic(r.Context(), svcCtx)
resp, err := l.MiniSearchArticlePage(&req)
if err != nil {
httpx.ErrorCtx(r.Context(), w, err)
} else {
httpx.OkJsonCtx(r.Context(), w, resp)
}
}
}
... ...
... ... @@ -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
}
... ...
package article
import (
"net/http"
"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 MiniShowHomePageHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.MiniHomePageRequest
// if err := httpx.Parse(r, &req); err != nil {
// httpx.ErrorCtx(r.Context(), w, err)
// return
// }
l := article.NewMiniShowHomePageLogic(r.Context(), svcCtx)
token := contextdata.GetUserTokenFromCtx(r.Context())
req.UserId = token.UserId
req.CompanyId = token.CompanyId
resp, err := l.MiniShowHomePage(&req)
result.HttpResult(r, w, resp, err)
}
}
... ...
... ... @@ -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 SystemArticleRestoreHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.SystemArticleRestoreRequest
if err := httpx.Parse(r, &req); err != nil {
result.ParamErrorResult(r, w, err)
return
}
l := article.NewSystemArticleRestoreLogic(r.Context(), svcCtx)
resp, err := l.SystemArticleRestore(&req)
result.HttpResult(r, w, resp, err)
}
}
... ...
... ... @@ -18,7 +18,7 @@ func SystemUpdateArticleHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return
}
l := article.NewSystemUpdateArticleLogic(r.Context(), svcCtx)
resp, err := l.SystemUpdateArticle(&req, r.Header.Get("x-mmm-accesstoken"))
resp, err := l.SystemUpdateArticle(&req)
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
}
... ...
... ... @@ -379,6 +379,16 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
Path: "/article_tag/list/all",
Handler: article.MiniAllArticleTagHandler(serverCtx),
},
{
Method: http.MethodGet,
Path: "/show/home_page",
Handler: article.MiniShowHomePageHandler(serverCtx),
},
{
Method: http.MethodPost,
Path: "/show/search_article",
Handler: article.MiniSearchArticlePageHandler(serverCtx),
},
},
rest.WithJwt(serverCtx.Config.MiniAuth.AccessSecret),
rest.WithPrefix("/v1/mini"),
... ... @@ -416,6 +426,11 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
Path: "/article/search/me",
Handler: article.SystemArticleSearchMeHandler(serverCtx),
},
{
Method: http.MethodPost,
Path: "/article/restore",
Handler: article.SystemArticleRestoreHandler(serverCtx),
},
},
rest.WithJwt(serverCtx.Config.SystemAuth.AccessSecret),
rest.WithPrefix("/v1/system"),
... ...
... ... @@ -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
}
... ...
... ... @@ -38,20 +38,20 @@ func (l *MiniAllArticleTagLogic) MiniAllArticleTag(req *types.MiniAllArticleTagR
for _, val := range tagList {
if m, ok := tagMap[val.Category]; ok {
m = append(m, types.ArticleTagItem{
Id: val.Id,
Group: val.Category,
Name: val.Name,
Image: val.Image.Url,
Id: val.Id,
Category: val.Category,
Name: val.Name,
Image: val.Image.Url,
})
tagMap[val.Category] = m
} else {
group = append(group, val.Category)
tagMap[val.Category] = []types.ArticleTagItem{
{
Id: val.Id,
Group: val.Category,
Name: val.Name,
Image: val.Image.Url,
Id: val.Id,
Category: val.Category,
Name: val.Name,
Image: val.Image.Url,
},
}
}
... ... @@ -61,8 +61,8 @@ func (l *MiniAllArticleTagLogic) MiniAllArticleTag(req *types.MiniAllArticleTagR
}
for i := range group {
resp.TagGroup = append(resp.TagGroup, types.ArticleTagGroup{
Group: group[i],
Tags: tagMap[group[i]],
Category: group[i],
Tags: tagMap[group[i]],
})
}
return resp, nil
... ...
... ... @@ -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"
... ... @@ -80,6 +81,14 @@ func (l *MiniArticleSetTagLogic) MiniArticleSetTag(req *types.MiniArticleSetTagR
if err != nil {
return err
}
// 定性消息通知
messageLogic := message.NewMiniSystemLogic(ctx, l.svcCtx)
err = messageLogic.ArticleDefined(c, articleInfo.CompanyId, articleInfo.AuthorId, articleInfo.Title)
if err != nil {
return err
}
return nil
}, true)
... ...
... ... @@ -2,6 +2,7 @@ package article
import (
"context"
"strconv"
"strings"
"text/template"
... ... @@ -9,6 +10,7 @@ import (
"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/tool/oss"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/xerr"
"github.com/samber/lo"
... ... @@ -52,13 +54,16 @@ func (l *MiniCreateArticleLogic) MiniCreateArticle(req *types.MiniArticleCreateR
if len(req.Images) > 9 {
return nil, xerr.NewErrMsg("图片数量最多9张")
}
//TODO 获取图片的尺寸大小
//获取图片的尺寸大小
images := []domain.Image{}
for _, val := range req.Images {
fInfo, _ := oss.GetImageInfo(val)
w, _ := strconv.Atoi(fInfo.ImageWidth.Value)
h, _ := strconv.Atoi(fInfo.ImageHeight.Value)
images = append(images, domain.Image{
Url: val,
Width: 0,
Height: 0,
Width: w,
Height: h,
})
}
... ... @@ -157,7 +162,7 @@ func (l *MiniCreateArticleLogic) MiniCreateArticle(req *types.MiniArticleCreateR
CountLove: 0,
CountComment: 0,
CountRead: 0,
Show: 0,
Show: domain.ArticleShowEnable,
Tags: []int64{},
}
if len(whoRead) > 0 {
... ...
... ... @@ -38,9 +38,7 @@ func (l *MiniGetArticleLogic) MiniGetArticle(req *types.MiniArticleGetRequest) (
if articleInfo.CompanyId != req.CompanyId {
return nil, xerr.NewErrMsg("没有查看权限")
}
//TODO 检查可查看人
if articleInfo.Show == domain.ArticleShowDisable {
// 文章内容不显示
resp = &types.MiniArticleGetResponse{
... ... @@ -71,6 +69,14 @@ func (l *MiniGetArticleLogic) MiniGetArticle(req *types.MiniArticleGetRequest) (
meLoveFlag = 1
}
}
tags := []string{}
if len(articleInfo.Tags) > 0 {
queryOption := domain.NewQueryOptions().WithFindOnly().MustWithKV("ids", articleInfo.Tags)
_, tagList, _ := l.svcCtx.ArticleTagRepository.Find(l.ctx, conn, req.CompanyId, queryOption)
for _, val := range tagList {
tags = append(tags, val.Name)
}
}
sortBy := domain.SortArticleSection(sectionList)
sort.Sort(sortBy)
... ... @@ -111,6 +117,7 @@ func (l *MiniGetArticleLogic) MiniGetArticle(req *types.MiniArticleGetRequest) (
Show: int(articleInfo.Show),
Edit: 0,
MeLoveFlag: meLoveFlag,
Tags: tags,
}
if articleInfo.CreatedAt != articleInfo.UpdatedAt {
resp.Edit = 1
... ...
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 MiniSearchArticlePageLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewMiniSearchArticlePageLogic(ctx context.Context, svcCtx *svc.ServiceContext) *MiniSearchArticlePageLogic {
return &MiniSearchArticlePageLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *MiniSearchArticlePageLogic) MiniSearchArticlePage(req *types.MiniSearchArticleRequest) (resp *types.MiniSearchArticleResponse, err error) {
// todo: add your logic here and delete this line
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"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/xerr"
"github.com/samber/lo"
"github.com/zeromicro/go-zero/core/logx"
)
type MiniShowHomePageLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewMiniShowHomePageLogic(ctx context.Context, svcCtx *svc.ServiceContext) *MiniShowHomePageLogic {
return &MiniShowHomePageLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *MiniShowHomePageLogic) MiniShowHomePage(req *types.MiniHomePageRequest) (resp *types.MiniHomePageResponse, err error) {
// 获取所有的标签
var conn = l.svcCtx.DefaultDBConn()
queryOption := domain.NewQueryOptions().WithFindOnly()
_, allTags, err := l.svcCtx.ArticleTagRepository.Find(l.ctx, conn, req.CompanyId, queryOption)
if err != nil {
return nil, xerr.NewErrMsgErr("获取标签列表失败", err)
}
// 获取统计数据
countData, err := l.svcCtx.ArticleAndTagRepository.CountArticleReadGroupByTag(l.ctx, conn, req.UserId, req.CompanyId)
if err != nil {
return nil, xerr.NewErrMsgErr("获取文章汇总数量失败", err)
}
countDataMap := map[int64]*domain.CountArticleTagRead{}
for _, val := range countData {
countDataMap[val.TagId] = val
}
tagCategory := []string{}
tagCount := []types.ArticleTagCount{}
for _, val := range allTags {
tagCategory = append(tagCategory, val.Category)
m := types.ArticleTagCount{
TagCategory: val.Category,
TagId: val.Id,
TagImage: val.Image.Url,
TagName: val.Name,
TagRemark: val.Remark,
TotalArticle: 0,
ReadArticle: 0,
}
if count, ok := countDataMap[val.Id]; ok {
m.TotalArticle = count.TotalArticle
m.ReadArticle = count.ReadArticle
}
tagCount = append(tagCount, m)
}
tagCategory = lo.Uniq(tagCategory)
resp = &types.MiniHomePageResponse{
TagCategory: tagCategory,
Tags: tagCount,
}
return resp, nil
}
... ...
... ... @@ -2,6 +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"
... ... @@ -24,7 +27,67 @@ func NewSystemArticleGetHistoryLogic(ctx context.Context, svcCtx *svc.ServiceCon
}
func (l *SystemArticleGetHistoryLogic) SystemArticleGetHistory(req *types.SystemArticleGetHistoryRequest) (resp *types.SystemArticleGetHistoryResponse, err error) {
//var conn = l.svcCtx.DefaultDBConn()
var conn = l.svcCtx.DefaultDBConn()
backup, err := l.svcCtx.ArticleBackupRepository.FindOne(l.ctx, conn, req.Id)
if err != nil {
return nil, xerr.NewErrMsgErr("获取编辑历史记录失败", err)
}
resp = &types.SystemArticleGetHistoryResponse{
Id: backup.Id,
ArticleId: backup.ArticleId,
Title: backup.Title,
CreatedAt: backup.CreatedAt,
Section: make([]types.ArticleSection, 0),
Images: make([]string, 0),
WhoRead: backup.WhoRead,
WhoReadInfo: make([]types.UserShowName, 0),
WhoReview: backup.WhoReview,
WhoReviewInfo: make([]types.UserShowName, 0),
Location: types.Location{
Longitude: backup.Location.Longitude,
Latitude: backup.Location.Latitude,
Descript: backup.Location.Descript,
},
TargetUser: int(backup.TargetUser),
Tags: backup.Tags,
}
//文章段落内容
lo.ForEach(backup.Section, func(item domain.ArticleSection, index int) {
resp.Section = append(resp.Section, types.ArticleSection{
Id: item.Id,
Content: item.Content,
SortBy: item.SortBy,
TotalComment: item.TotalComment,
})
})
//图片
lo.ForEach(backup.Images, func(item domain.Image, index int) {
resp.Images = append(resp.Images, item.Url)
})
//用户
userIds := lo.Union(resp.WhoRead, resp.WhoReview)
if len(userIds) > 0 {
_, users, err := l.svcCtx.UserRepository.Find(l.ctx, conn, domain.NewQueryOptions().WithKV("ids", userIds))
if err != nil {
return nil, xerr.NewErrMsgErr("获取帖子异常", err)
}
userSlices := make(map[int64]types.UserShowName)
lo.ForEach(users, func(user *domain.User, index int) {
userSlices[user.Id] = types.UserShowName{
Id: int(user.Id),
Name: user.Name,
}
})
lo.ForEach(resp.WhoRead, func(userId int64, index int) {
if value, ok := userSlices[userId]; ok {
resp.WhoReadInfo = append(resp.WhoReadInfo, value)
}
})
lo.ForEach(resp.WhoReview, func(userId int64, index int) {
if value, ok := userSlices[userId]; ok {
resp.WhoReviewInfo = append(resp.WhoReviewInfo, value)
}
})
}
return
}
... ...
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/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"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types"
"github.com/zeromicro/go-zero/core/logx"
)
type SystemArticleRestoreLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewSystemArticleRestoreLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SystemArticleRestoreLogic {
return &SystemArticleRestoreLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *SystemArticleRestoreLogic) SystemArticleRestore(req *types.SystemArticleRestoreRequest) (resp *types.SystemArticleRestoreResponse, err error) {
var conn = l.svcCtx.DefaultDBConn()
backup, err := l.svcCtx.ArticleBackupRepository.FindOne(l.ctx, conn, req.Id)
if err != nil {
return nil, xerr.NewErrMsgErr("获取编辑历史记录失败", err)
}
article, err := l.svcCtx.ArticleRepository.FindOne(l.ctx, conn, backup.ArticleId)
if err != nil {
return nil, xerr.NewErrMsgErr("获取文章失败", err)
}
article.Version = article.Version + 1
article.Images = backup.Images
article.Title = backup.Title
articleSections := make([]domain.ArticleSection, 0)
lo.ForEach(backup.Section, func(item domain.ArticleSection, index int) {
articleSections = append(articleSections, domain.ArticleSection{
Id: item.Id,
CompanyId: item.CompanyId,
Version: article.Version,
ArticleId: article.Id,
Content: item.Content,
SortBy: item.SortBy,
})
})
//获取当前用户信息
userToken := contextdata.GetUserTokenFromCtx(l.ctx)
userMe, err := l.svcCtx.ApiAuthService.MeInfo(l.ctx, authlib.RequestUserMeQuery{Token: req.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(ctx, c, article)
if err != nil {
return xerr.NewErrMsgErr("恢复文章版本失败", err)
}
//保存段落
updateSectionIds := []int64{}
for _, item := range articleSections {
section, err := l.svcCtx.ArticleSectionRepository.FindOne(ctx, c, item.Id)
if err == nil && section.Id > 0 {
section.Content = item.Content
section.SortBy = item.SortBy
section.Version = item.Version
_, err = l.svcCtx.ArticleSectionRepository.Update(ctx, c, section)
if err != nil {
return xerr.NewErrMsgErr("恢复文章版本失败", err)
}
} else {
_, err = l.svcCtx.ArticleSectionRepository.Insert(ctx, c, &item)
if err != nil {
return xerr.NewErrMsgErr("恢复文章版本失败", err)
}
}
updateSectionIds = append(updateSectionIds, item.Id)
}
if len(updateSectionIds) > 0 {
err = l.svcCtx.ArticleSectionRepository.DeleteBy(ctx, c, domain.NewQueryOptions().WithKV("articleId", article.Id).WithKV("notIds", updateSectionIds))
if err != nil {
return xerr.NewErrMsgErr("保存文章内容失败", err)
}
}
//备份数据
newBackUp := article.MakeBackup(domain.UserSimple{
Id: userToken.UserId,
Name: userMe.User.NickName,
Avatar: userMe.User.Avatar,
CompanyId: userToken.CompanyId,
Company: userMe.CurrentCompany.Name,
}, articleSections)
newBackUp.Action = "恢复"
_, err = l.svcCtx.ArticleBackupRepository.Insert(ctx, c, newBackUp)
if err != nil {
return xerr.NewErrMsgErr("恢复文章版本失败", err)
}
return nil
}, true)
resp = &types.SystemArticleRestoreResponse{
Id: req.Id,
ArticleId: article.Id,
}
return
}
... ...
... ... @@ -2,6 +2,7 @@ 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"
... ... @@ -71,10 +72,10 @@ func (l *SystemGetArticleLogic) SystemGetArticle(req *types.SystemArticleGetRequ
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,
Id: tag.Id,
Category: tag.Category,
Name: tag.Name,
Image: tag.Image.Url,
})
})
}
... ...
... ... @@ -2,11 +2,14 @@ package article
import (
"context"
"strconv"
"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/tool/oss"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/xerr"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc"
... ... @@ -29,20 +32,23 @@ func NewSystemUpdateArticleLogic(ctx context.Context, svcCtx *svc.ServiceContext
}
}
func (l *SystemUpdateArticleLogic) SystemUpdateArticle(req *types.SystemArticleUpdateRequest, accessToken string) (resp *types.SystemArticleUpdateResponse, err error) {
func (l *SystemUpdateArticleLogic) SystemUpdateArticle(req *types.SystemArticleUpdateRequest) (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)
}
//TODO 获取图片的尺寸大小
//获取图片的尺寸大小
images := []domain.Image{}
for _, val := range req.Images {
fInfo, _ := oss.GetImageInfo(val)
w, _ := strconv.Atoi(fInfo.ImageWidth.Value)
h, _ := strconv.Atoi(fInfo.ImageHeight.Value)
images = append(images, domain.Image{
Url: val,
Width: 0,
Height: 0,
Width: w,
Height: h,
})
}
article.Title = req.Title
... ... @@ -84,7 +90,7 @@ 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})
userMe, err := l.svcCtx.ApiAuthService.MeInfo(l.ctx, authlib.RequestUserMeQuery{Token: req.AccessToken})
if err != nil {
return nil, xerr.NewErrMsgErr("获取当前用户信息失败", err)
}
... ...
... ... @@ -130,7 +130,7 @@ func (l *MiniCreateArticleCommentLogic) MiniCreateArticleComment(req *types.Mini
CountReply: 0,
CountUserLove: 0,
CountAdminLove: 0,
Show: 0,
Show: domain.CommentShowEnable,
AtWho: []domain.UserSimple{},
}
... ...
... ... @@ -6,6 +6,7 @@ import (
"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"
)
... ... @@ -29,13 +30,13 @@ func (l *SystemDeleteLogic) SystemDelete(req *types.DepartmentGetRequest) (resp
one, err := l.svcCtx.DepartmentRepository.FindOne(l.ctx, conn, req.Id)
if err != nil {
return nil, err
return nil, xerr.NewErrMsg("数据不存在")
}
// 获取公司下的所有用户
_, users, err := l.svcCtx.UserRepository.Find(l.ctx, conn, domain.NewQueryOptions().
WithFindOnly().
WithKV(" companyId", one.CompanyId))
WithKV("companyId", one.CompanyId))
if err != nil {
return nil, err
}
... ...
... ... @@ -4,6 +4,7 @@ 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/pkg/xerr"
"github.com/zeromicro/go-zero/core/logx"
)
... ... @@ -26,7 +27,7 @@ func (l *SystemGetLogic) SystemGet(req *types.DepartmentGetRequest) (resp *types
var conn = l.svcCtx.DefaultDBConn()
department, err := l.svcCtx.DepartmentRepository.FindOne(l.ctx, conn, req.Id)
if err != nil {
return nil, err
return nil, xerr.NewErrMsg("数据不存在")
}
resp = &types.DepartmentGetResponse{
Department: types.Department{
... ...
... ... @@ -58,7 +58,7 @@ func (l *SystemUpdateLogic) SystemUpdate(req *types.DepartmentUpdateRequest) (re
// 获取公司下的所有用户
_, users, err := l.svcCtx.UserRepository.Find(l.ctx, conn, domain.NewQueryOptions().
WithFindOnly().
WithKV(" companyId", one.CompanyId))
WithKV("companyId", one.CompanyId))
if err != nil {
return nil, err
}
... ... @@ -83,7 +83,7 @@ func (l *SystemUpdateLogic) SystemUpdate(req *types.DepartmentUpdateRequest) (re
if _, ok := newIdMap[user.Id]; ok {
var targetIndex = findIndex(user.Departments, req.Id)
if targetIndex == -1 { // 归属分组不存在,则新增
user.Departments = append(user.Departments)
user.Departments = append(user.Departments, req.Id)
_, err = l.svcCtx.UserRepository.UpdateWithVersion(l.ctx, conn, user)
if err != nil {
return err
... ...
... ... @@ -3,10 +3,12 @@ package tags
import (
"context"
"fmt"
"strconv"
"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/tool/oss"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/xerr"
"github.com/zeromicro/go-zero/core/logx"
... ... @@ -41,8 +43,10 @@ func (l *CreateTagLogic) CreateTag(req *types.TagCreateRequest) (resp *types.Tag
if cnt > 0 {
return nil, xerr.NewErrMsg(fmt.Sprintf("已存在标签 分类[%s]名称[%s]", req.Category, req.Name))
}
//TODO 获取图片的尺寸大小
//获取图片的尺寸大小
fInfo, _ := oss.GetImageInfo(req.Image)
w, _ := strconv.Atoi(fInfo.ImageWidth.Value)
h, _ := strconv.Atoi(fInfo.ImageHeight.Value)
newTag := &domain.ArticleTag{
Id: 0,
CompanyId: req.CompanyId,
... ... @@ -52,8 +56,8 @@ func (l *CreateTagLogic) CreateTag(req *types.TagCreateRequest) (resp *types.Tag
Version: 0,
Image: domain.Image{
Url: req.Image,
Width: 0,
Height: 0,
Width: w,
Height: h,
},
Name: req.Name,
Category: req.Category,
... ...
... ... @@ -3,10 +3,12 @@ package tags
import (
"context"
"fmt"
"strconv"
"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/tool/oss"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/xerr"
"github.com/zeromicro/go-zero/core/logx"
... ... @@ -52,11 +54,16 @@ func (l *EditTagLogic) EditTag(req *types.TagEditRequest) (resp *types.TagEditRe
if oldTag.CompanyId != req.CompanyId {
return nil, xerr.NewErrMsg("修改标签失败")
}
//TODO 获取图片的尺寸大小
//获取图片的尺寸大小
fInfo, _ := oss.GetImageInfo(req.Image)
w, _ := strconv.Atoi(fInfo.ImageWidth.Value)
h, _ := strconv.Atoi(fInfo.ImageHeight.Value)
oldTag.Category = req.Category
oldTag.Image.Url = req.Image
oldTag.Image = domain.Image{
Url: req.Image,
Width: w,
Height: h,
}
oldTag.Name = req.Name
oldTag.Remark = req.Remark
oldTag.Other = req.Other
... ...
... ... @@ -621,9 +621,10 @@ type MiniArticleGetResponse struct {
CountLove int `json:"countLove"` // 点赞数量
CountComment int `json:"countComment"` // 评论数量
CountRead int `json:"countRead"` // 浏览数量
Show int `json:"show"` // 评论的展示状态(0显示、1不显示)
Show int `json:"show"` // 评论的展示状态(1显示、2不显示)
Edit int `json:"edit"` // 文章是否存在变更记录 (0 不存在 1存在)
MeLoveFlag int `json:"meLoveFlag"` // 当前人员对文章的点赞标识 (0 没有点赞 1有点赞)
Tags []string `json:"tags"` //文章的标签
}
type ArticleSection struct {
... ... @@ -855,15 +856,15 @@ type MiniAllArticleTagResponse struct {
}
type ArticleTagGroup struct {
Group string `json:"group"`
Tags []ArticleTagItem `json:"tags"`
Category string `json:"category"`
Tags []ArticleTagItem `json:"tags"`
}
type ArticleTagItem struct {
Id int64 `json:"id"`
Group string `json:"group"`
Name string `json:"name"`
Image string `json:"image"`
Id int64 `json:"id"`
Category string `json:"category"`
Name string `json:"name"`
Image string `json:"image"`
}
type SystemArticleGetRequest struct {
... ... @@ -926,17 +927,18 @@ type SystemArticleSearch struct {
}
type SystemArticleUpdateRequest struct {
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"` // 标签
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"` // 标签
AccessToken string `header:"x-mmm-accesstoken"` // 授权token
}
type SystemArticleUpdateResponse struct {
... ... @@ -946,7 +948,7 @@ type SystemArticleUpdateResponse struct {
Images []string `json:"images"` //图片
CreatedAt int64 `json:"createdAt"` //文章的创建日期
CountLove int `json:"countLove"` //点赞数量
CountComment int `json:"CountComment"` //评论数量
CountComment int `json:"countComment"` //评论数量
Show int `json:"show"` //是否隐藏 [0显示、1不显示]
Tags []int64 `json:"tags"` //标签
TargetUser int `json:"targetUser"` //分发方式 [0分发给所有人、1分发给指定的人]
... ... @@ -982,8 +984,6 @@ 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"` // 图片
... ... @@ -992,11 +992,64 @@ type SystemArticleGetHistoryResponse struct {
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分发给指定的人]
TargetUser int `json:"targetUser"` // 分发方式 [0分发给所有人、1分发给指定的人]
Tags []int64 `json:"tags"` // 标签
}
type SystemArticleRestoreRequest struct {
Id int64 `json:"id"` //ID
AccessToken string `header:"x-mmm-accesstoken"` // 授权token
}
type SystemArticleRestoreResponse struct {
Id int64 `json:"id"` //ID
ArticleId int64 `json:"articleId"` //文章ID
}
type MiniHomePageRequest struct {
CompanyId int64 `path:",optional"`
UserId int64 `path:",optional"`
}
type MiniHomePageResponse struct {
TagCategory []string `json:"tagCategory"`
Tags []ArticleTagCount `json:"tags"`
}
type ArticleTagCount struct {
TagCategory string `json:"tagCategory"` // 标签分组
TagId int64 `json:"tagId"` // 标签id
TagImage string `json:"tagImage"` // 对应的图标
TagName string `json:"tagName"` // 标签名称
TagRemark string `json:"tagRemark"` // 标签备注
TotalArticle int `json:"totalArticle"` // 总的文章数量
ReadArticle int `json:"readArticle"` // 已读的标签数量
}
type MiniSearchArticleRequest struct {
Page int `json:"page"`
Size int `json:"size"`
CompanyId int64 `json:",optional"`
UserId int64 `json:",optional"`
TagGroup string `json:"tagGroup"`
TagId int64 `json:"tagId"`
BeginTime int64 `json:"beginTime"`
EndTime int `json:"endTime"`
SearchWord string `json:"searchWord"`
}
type MiniSearchArticleResponse struct {
Total int `json:"total"`
List []MiniSearchArticleItem `json:"list"`
}
type MiniSearchArticleItem struct {
ArticleId int64 `json:"articleId"`
Title string `json:"title"`
Author string `json:"author"` // 发布人
Images []string `json:"images"`
CreatedAt int64 `json:"createdAt"`
MeReadFlag int `json:"meReadFlag"` //已读标识 [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 = ?
and article."show" = ?
and (article.target_user =0 or article.who_read @> ?)
),
-- 查询人员已查看的文章
t_user_read as(
select user_read_article.article_id from user_read_article where user_read_article.user_id = ?
)
-- 汇总统计 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,
domain.ArticleShowEnable,
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}
}
... ...
... ... @@ -279,11 +279,11 @@ func (repository *ArticleCommentRepository) Top5Comment(ctx context.Context, con
article_comment.id ,
(article_comment.count_reply +article_comment.count_user_love +article_comment.count_admin_love ) cnt
from article_comment
where top_id =0 and article_id =? and deleted_at=0 and show=0 and company_id=?
where top_id =0 and article_id =? and deleted_at=0 and show= ? and company_id=?
order by cnt desc,article_comment.id desc
limit 5 `
db := conn.DB()
rows, err := db.Raw(sql1, articleId, companyId).Rows()
rows, err := db.Raw(sql1, articleId, domain.CommentShowEnable, companyId).Rows()
if err != nil {
return nil, err
}
... ...
... ... @@ -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
// ;
... ...
... ... @@ -121,8 +121,7 @@ func (repository *ArticleTagRepository) Find(ctx context.Context, conn transacti
)
queryFunc := func() (interface{}, error) {
tx = tx.Model(&ms).
Where("company_id=?", companyId).
Order("id asc")
Where("company_id=?", companyId).Order("sort_by asc").Order("id asc")
if v, ok := queryOptions["name"]; ok {
tx = tx.Where("name like ?", v)
... ...
... ... @@ -25,7 +25,7 @@ type Article struct {
CountLove int `json:"countLove"` // 点赞数量
CountComment int `json:"countComment"` // 评论数量
CountRead int `json:"countRead"` // 浏览数量
Show ArticleShow `json:"show"` // 评论的展示状态(0显示、1不显示
Show ArticleShow `json:"show"` // 评论的展示状态(1显示,2不显示、
Tags []int64 `json:"tags"` // 定性标签
Summary string `json:"summary"` // 内容概要
// ...more
... ... @@ -60,12 +60,12 @@ func (a ArticleTarget) Named() string {
return ""
}
// 文章的展示状态(0显示、1不显示)
// 文章的展示状态(1显示,2不显示)
type ArticleShow int
const (
ArticleShowEnable ArticleShow = 0
ArticleShowDisable ArticleShow = 1
ArticleShowEnable ArticleShow = 1
ArticleShowDisable ArticleShow = 2
)
func (a ArticleShow) Named() string {
... ...
... ... @@ -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)
}
... ...
... ... @@ -27,17 +27,17 @@ type ArticleComment struct {
CountReply int `json:"countReply"` // 回复数量
CountUserLove int `json:"countUserLove"` // 用户点赞数量
CountAdminLove int `json:"countAdminLove"` // 运营点赞数量
Show CommentShow `json:"showState"` // 评论的展示状态(0显示、1不显示)
Show CommentShow `json:"showState"` // 评论的展示状态(1显示、2不显示)
AtWho []UserSimple `json:"atWho"` // 填写评论时@的人
// ...more
}
// 评论的展示状态(0显示、1不显示)
// 评论的展示状态(1显示、2不显示)
type CommentShow int
const (
CommentShowEnable CommentShow = 0
CommentShowDisable CommentShow = 1
CommentShowEnable CommentShow = 1
CommentShowDisable CommentShow = 2
)
func (show CommentShow) Named() string {
... ...
package oss
import (
"encoding/json"
"fmt"
"image"
_ "image/jpeg"
"net/http"
"strings"
"time"
)
type FileInfo struct {
FileSize struct {
Value string
}
Format struct {
Value string
}
ImageHeight struct {
Value string
}
ImageWidth struct {
Value string
}
}
func GetImageInfo(url string) (info FileInfo, err error) {
//ok := strings.HasPrefix(url, "https://timeless-world.oss-cn-shenzhen.aliyuncs.com")
ok := strings.HasPrefix(url, "http")
if !ok {
return
}
ok = strings.Contains(url, "aliyuncs")
if !ok {
return
}
apiUrl := url + `?x-oss-process=image/info`
req, err := http.NewRequest(http.MethodGet, apiUrl, nil)
if err != nil {
return info, err
}
httpclient := http.Client{
Timeout: 30 * time.Second,
}
resp, err := httpclient.Do(req)
if err != nil {
return info, err
}
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
return
}
jDecoder := json.NewDecoder(resp.Body)
err = jDecoder.Decode(&info)
if err != nil {
return info, err
}
return info, nil
}
// 获取视频封面图
func GetVideoCover(videoUrl string) (coverUrl string, w int, h int, err error) {
ok := strings.HasPrefix(videoUrl, "http")
if !ok {
return
}
ok = strings.Contains(videoUrl, "aliyuncs")
if !ok {
return
}
videoUrl = videoUrl + "?x-oss-process=video/snapshot,t_100,f_jpg,m_fast"
res, err := http.Get(videoUrl)
if err != nil || res.StatusCode != http.StatusOK {
return videoUrl, 600, 600, fmt.Errorf("获取图片失败:%s", err)
}
defer res.Body.Close()
m, _, err := image.Decode(res.Body)
if err != nil {
return videoUrl, 600, 600, fmt.Errorf("获取图片失败:%s", err)
}
return videoUrl, m.Bounds().Dx(), m.Bounds().Dy(), nil
}
... ...
package oss
import "testing"
func TestGetVideoCover(t *testing.T) {
cover, w, h, err := GetVideoCover("https://timeless-world.oss-cn-shenzhen.aliyuncs.com/open-api/dev_online/20230913/object/1694587897_yYfG6TYTsGMCKETxdnTEhAQjXpYGD3MB.mp4")
t.Logf("cover=%v, w=%v, h=%v, err=%v", cover, w, h, err)
}
... ...