作者 yangfu

Merge branch 'dev' into test

正在显示 78 个修改的文件 包含 3934 行增加241 行删除
... ... @@ -9,4 +9,5 @@ import "core/company.api"
import "core/article_type.api"
import "core/article.api"
import "core/role.api"
import "core/department.api"
\ No newline at end of file
import "core/department.api"
import "core/article_category.api"
\ No newline at end of file
... ...
... ... @@ -121,4 +121,40 @@ service Core {
@doc "管理后台文章恢复"
@handler SystemArticleRestore
post /article/restore (SystemArticleRestoreRequest) returns (SystemArticleRestoreResponse)
@doc "管理后台删除文章"
@handler SystemDeleteArticle
delete /article (SystemArticleDeleteRequest) returns (SystemArticleDeleteResponse)
@doc "管理后台新增文章"
@handler SystemCreateArticle
post /article (SystemArticleCreateRequest) returns (SystemArticleCreateResponse)
@doc "管理后台新增草稿"
@handler SystemCreateArticleDraft
post /article/draft (SystemArticleDraftCreateRequest) returns (SystemArticleDraftCreateResponse)
@doc "管理后台编辑草稿"
@handler SystemUpdateArticleDraft
put /article/draft (SystemArticleDraftUpdateRequest) returns (SystemArticleDraftUpdateResponse)
@doc "管理后台草稿列表"
@handler SystemSearchArticleDraft
post /article/draft/search (SystemArticleDraftSearchRequest) returns (SystemArticleDraftSearchResponse)
@doc "管理后台删除草稿"
@handler SystemDeleteArticleDraft
delete /article/draft (SystemArticleDraftDeleteRequest) returns (SystemArticleDraftDeleteResponse)
@doc "管理后台获取草稿"
@handler SystemGetArticleDraft
get /article/draft/:id (SystemArticleDraftGetRequest) returns (SystemArticleDraftGetResponse)
@doc "管理后台已删除列表"
@handler SystemArticleSearchDeleted
post /article/deleted/list (SystemArticleSearchDeletedRequest) returns (SystemArticleSearchDeletedResponse)
@doc "管理后台文章删除恢复"
@handler SystemRestoreArticleDeleted
put /article/deleted/restore (SystemArticleDeletedRestoreRequest) returns (SystemArticleDeletedRestoreResponse)
}
\ No newline at end of file
... ...
@server(
prefix: v1/system
group: tags
middleware: LoginStatusCheck,LogRequest
jwt: SystemAuth
)
service Core {
@doc "标签分类详情"
@handler articleCategoryGet
get /article_category/:id (ArticleCategoryGetRequest) returns (ArticleCategoryGetResponse)
@doc "标签分类保存"
@handler articleCategorySave
post /article_category (ArticleCategorySaveRequest) returns (ArticleCategorySaveResponse)
@doc "标签分类删除"
@handler articleCategoryDelete
delete /article_category/:id (ArticleCategoryDeleteRequest) returns (ArticleCategoryDeleteResponse)
@doc "标签分类更新"
@handler articleCategoryUpdate
put /article_category/:id (ArticleCategoryUpdateRequest) returns (ArticleCategoryUpdateResponse)
@doc "标签分类搜索"
@handler articleCategorySearch
post /article_category/search (ArticleCategorySearchRequest) returns (ArticleCategorySearchResponse)
@doc "标签分类下拉列表"
@handler articleCategoryOptions
get /article_category/options (CategoryOptionsRequest) returns (CategoryOptionsResponse)
}
@server(
prefix: v1/system
group: tags
)
service Core {
@doc "标签分类初始化"
@handler articleCategoryInit
get /article_category/init
}
type (
ArticleCategoryGetRequest {
Id int64 `path:"id"`
}
ArticleCategoryGetResponse struct{
ArticleCategory ArticleCategoryItem `json:"category"`
}
ArticleCategorySaveRequest struct{
ArticleCategory ArticleCategoryItem `json:"category"`
}
ArticleCategorySaveResponse struct{}
ArticleCategoryDeleteRequest struct{
Id int64 `path:"id"`
}
ArticleCategoryDeleteResponse struct{}
ArticleCategoryUpdateRequest struct{
Id int64 `path:"id"`
ArticleCategory ArticleCategoryItem `json:"category"`
}
ArticleCategoryUpdateResponse struct{}
ArticleCategorySearchRequest struct{
Page int `json:"page"`
Size int `json:"size"`
}
ArticleCategorySearchResponse{
List []ArticleCategoryItem `json:"list"`
Total int64 `json:"total"`
}
ArticleCategoryItem struct{
Id int64 `json:"id,optional"` // 唯一标识
CompanyId int64 `json:"companyId,optional,omitempty"`
Name string `json:"name"`
SortBy int `json:"sortBy,optional,omitempty"` // 排序
Enable int `json:"enable,omitempty"` // 启用状态 1:启用 2:禁用
Other string `json:"other,optional,omitempty"` // 其他备注说明
}
)
//标签下拉列表
type (
CategoryOptionsRequest {
CompanyId int64 `path:",optional"` // 公司ID
}
CategoryOptionsResponse {
Options []CategoryOptions `json:"options"`
}
CategoryOptions {
Value int64 `json:"value"` // 分类ID
Label string `json:"label"` // 分组名称
//Options []CategoryOptionValue `json:"options,omitempty"`
}
CategoryOptionValue {
Label string `json:"label"` // 名称
Value int64 `json:"value"` // 分类ID
}
)
\ No newline at end of file
... ...
... ... @@ -46,10 +46,11 @@ type (
CompanyId int64 `json:",optional"`
Image string `json:"image"`
Name string `json:"name"` // 标签名称
Category string `json:"category"` // 标签分类
//Category string `json:"category"` // 标签分类
Remark string `json:"remark,optional"` // 备注
Other string `json:"other,optional"`
SortBy int `json:"sortBy,optional"` //排序
CategoryId int64 `json:"categoryId"` // 标签Id
}
TagCreateResponse {
... ... @@ -64,7 +65,8 @@ type (
CompanyId int64 `json:",optional"`
Image string `json:"image"`
Name string `json:"name"` // 标签名称
Category string `json:"category"` // 标签分类
//Category string `json:"category"` // 标签分类
CategoryId int64 `json:"categoryId"` // 标签Id
Remark string `json:"remark,optional"` // 备注
Other string `json:"other,optional"`
SortBy int `json:"sortBy,optional"` // 排序
... ... @@ -86,6 +88,7 @@ type (
Image string `json:"image"`
Name string `json:"name"` // 标签名称
Category string `json:"category"` // 标签分类
CategoryId int64 `json:"categoryId"` // 标签分类Id
Remark string `json:"remark"` // 备注
Other string `json:"other"`
SortBy int `json:"sortBy,optional"` // 排序
... ... @@ -99,7 +102,7 @@ type (
Size int `json:"size"`
CompanyId int64 `json:",optional"`
TagName string `json:"tagName,optional"`
Category string `json:"category,optional"`
CategoryId int64 `json:"categoryId,optional"`
Remark string `json:"remark,optional"`
}
TagListResponse {
... ... @@ -111,9 +114,11 @@ type (
Image string `json:"image"`
Name string `json:"name"` // 标签名称
Category string `json:"category"` // 标签分类
CategoryId int64 `json:"categoryId"` // 标签分类Id
Remark string `json:"remark"` // 备注
CreatedAt int64 `json:"createdAt"`
SortBy int `json:"sortBy,optional"` // 排序
Removeable bool `json:"removeable,optional"` // 可删除
}
)
... ... @@ -137,7 +142,8 @@ type (
Options []TagOptions `json:"options"`
}
TagOptions {
Label string `json:"label"` // 分组名称
Value int64 `json:"value"` // 分类ID
Label string `json:"label"` // 分类名称
Options []TagOptionValue `json:"options"`
}
TagOptionValue {
... ...
... ... @@ -25,6 +25,11 @@ type ArticleAuthor {
Company string `json:"company"` // 公司
}
type Operator {
Id int64 `json:"id,string"`// 人员id
Name string `json:"name"` // 人员的名字
}
//小程序端创建发布文章
type (
MiniArticleCreateRequest {
... ... @@ -431,11 +436,14 @@ type (
Author string `json:"author"` //发布人
Images []string `json:"images"` //图片
CreatedAt int64 `json:"createdAt"` //文章的创建日期
UpdatedAt int64 `json:"updatedAt"` //文章的编辑日期
CountLove int `json:"countLove"` //点赞数量
CountComment int `json:"countComment"` //评论数量
Show int `json:"show"` //是否隐藏 [0显示、1不显示]
Tags []string `json:"tags"` //标签
TargetUser int `json:"targetUser"` //分发方式 [0分发给所有人、1分发给指定的人]
Operator Operator `json:"operator"` //运营操作人
Source int `json:"source"` //来源[1用户发布、2运营发布]
}
)
// 管理后台编辑文章
... ... @@ -469,6 +477,45 @@ type (
TargetUser int `json:"targetUser"` //分发方式 [0分发给所有人、1分发给指定的人]
}
)
// 管理后台新增文章
type (
SystemArticleCreateRequest {
Title string `json:"title"` //标题
Content string `json:"content"` //文章的文本内容
AuthorId int64 `json:"authorId"` //发布人id
Images []string `json:"images,optional"` //图片
Videos []Video `json:"video,optional"` // 视频
TargetUser int `json:"targetUser"` // 分发方式 [0分发给所有人、1分发给指定的人]
WhoRead []int64 `json:"whoRead,optional"` //谁可查看
WhoReview []int64 `json:"whoReview,optional"` //谁可评论
MatchUrl map[string]string `json:"matchUrl,optional"` // 匹配文章内容中的url文本
ArticleDraftId int64 `json:"articleDraftId"` // 草稿ID
AccessToken string `header:"x-mmm-accesstoken"` // 授权token
}
SystemArticleCreateResponse {
Id int64 `json:"id"` //id
Title string `json:"title"` //标题
Content string `json:"content"` //文章的文本内容
AuthorId int64 `json:"authorId,optional"` //发布人id
Images []string `json:"images,optional"` //图片
Videos []Video `json:"video,optional"` // 视频
TargetUser int `json:"targetUser"` // 分发方式 [0分发给所有人、1分发给指定的人]
WhoRead []int64 `json:"whoRead,optional"` //谁可查看
WhoReview []int64 `json:"whoReview,optional"` //谁可评论
MatchUrl map[string]string `json:"matchUrl"` // 匹配文章内容中的url文本
}
)
//管理后台删除文章
type (
SystemArticleDeleteRequest {
Id int64 `json:"id"` //id
}
SystemArticleDeleteResponse {
Id int64 `json:"id"` //id
Title string `json:"title"` //标题
AuthorId int64 `json:"authorId,optional"` //发布人id
}
)
// 管理后台编辑历史列表
type (
//历史
... ... @@ -578,4 +625,171 @@ type (
CreatedAt int64 `json:"createdAt"`
MeReadFlag int `json:"meReadFlag"` //已读标识 [0:未读] [1:已读]
}
)
//后台新增文章草稿
type (
SystemArticleDraftCreateRequest {
Title string `json:"title"` //标题
Content string `json:"content"` //文章的文本内容
AuthorId int64 `json:"authorId"` //发布人id
Images []string `json:"images,optional"` //图片
Videos []Video `json:"video,optional"` // 视频
TargetUser int `json:"targetUser"` // 分发方式 [0分发给所有人、1分发给指定的人]
WhoRead []int64 `json:"whoRead,optional"` //谁可查看
WhoReview []int64 `json:"whoReview,optional"` //谁可评论
MatchUrl map[string]string `json:"matchUrl,optional"` // 匹配文章内容中的url文本
Tags []int64 `json:"tags"` // 标签
AccessToken string `header:"x-mmm-accesstoken"` // 授权token
}
SystemArticleDraftCreateResponse {
Id int64 `json:"id"` //ID
Title string `json:"title"` //标题
Content string `json:"content"` //文章的文本内容
AuthorId int64 `json:"authorId"` //发布人id
Images []string `json:"images,optional"` //图片
Videos []Video `json:"video,optional"` // 视频
TargetUser int `json:"targetUser"` // 分发方式 [0分发给所有人、1分发给指定的人]
WhoRead []int64 `json:"whoRead,optional"` //谁可查看
WhoReview []int64 `json:"whoReview,optional"` //谁可评论
MatchUrl map[string]string `json:"matchUrl,optional"` // 匹配文章内容中的url文本
Tags []int64 `json:"tags"` // 标签
}
)
//后台编辑文章草稿
type (
SystemArticleDraftUpdateRequest {
Id int64 `json:"id"` // ID
Title string `json:"title"` //标题
Content string `json:"content"` //文章的文本内容
AuthorId int64 `json:"authorId"` //发布人id
Images []string `json:"images,optional"` //图片
Videos []Video `json:"video,optional"` // 视频
TargetUser int `json:"targetUser"` // 分发方式 [0分发给所有人、1分发给指定的人]
WhoRead []int64 `json:"whoRead,optional"` //谁可查看
WhoReview []int64 `json:"whoReview,optional"` //谁可评论
MatchUrl map[string]string `json:"matchUrl,optional"` // 匹配文章内容中的url文本
Tags []int64 `json:"tags"` // 标签
AccessToken string `header:"x-mmm-accesstoken"` // 授权token
}
SystemArticleDraftUpdateResponse {
Id int64 `json:"id"` //ID
Title string `json:"title"` //标题
Content string `json:"content"` //文章的文本内容
AuthorId int64 `json:"authorId"` //发布人id
Images []string `json:"images,optional"` //图片
Videos []Video `json:"video,optional"` // 视频
TargetUser int `json:"targetUser"` // 分发方式 [0分发给所有人、1分发给指定的人]
WhoRead []int64 `json:"whoRead,optional"` //谁可查看
WhoReview []int64 `json:"whoReview,optional"` //谁可评论
MatchUrl map[string]string `json:"matchUrl,optional"` // 匹配文章内容中的url文本
Tags []int64 `json:"tags"` // 标签
}
)
//管理后台文章草稿列表
type (
SystemArticleDraftSearchRequest {
Page int `json:"page"` //页码
Size int `json:"size"` //每页行数
CompanyId int64 `json:"companyId,optional"` //公司ID(前端不传)
Title string `json:"title,optional"` //标题
Operator string `json:"operator,optional"` //编辑人
BeginTime int64 `json:"beginTime,optional"`//开始时间
EndTime int64 `json:"endTime,optional"` //结束时间
}
SystemArticleDraftSearchResponse {
Total int `json:"total"`
List []SystemArticleDraftSearch `json:"list"`
}
SystemArticleDraftSearch {
Id int64 `json:"id"` //ID
Title string `json:"title"` //标题
Images []string `json:"images"` //图片
Operator string `json:"operator"` //操作人
AuthorId int64 `json:"authorId"` //发布人id
Author string `json:"author"` //发布人
UpdatedAt int64 `json:"updatedAt"` //编辑时间
}
)
//管理后台删除草稿
type (
SystemArticleDraftDeleteRequest {
Id int64 `json:"id"` //ID
}
SystemArticleDraftDeleteResponse {
Id int64 `json:"id"` //ID
Title string `json:"title"` //标题
Content string `json:"content"` //文章的文本内容
AuthorId int64 `json:"authorId"` //发布人id
Images []string `json:"images,optional"` //图片
Videos []Video `json:"video,optional"` // 视频
TargetUser int `json:"targetUser"` // 分发方式 [0分发给所有人、1分发给指定的人]
WhoRead []int64 `json:"whoRead,optional"` //谁可查看
WhoReview []int64 `json:"whoReview,optional"` //谁可评论
MatchUrl map[string]string `json:"matchUrl,optional"` // 匹配文章内容中的url文本
Tags []int64 `json:"tags"` // 标签
}
)
//管理后台获取草稿
type (
SystemArticleDraftGetRequest {
Id int64 `path:"id"` //id
CompanyId int64 `path:",optional"` //公司ID(前端不传)
}
SystemArticleDraftGetResponse {
Id int64 `json:"id"` //ID
Title string `json:"title"` //标题
Content string `json:"content"` //文章的文本内容
AuthorId int64 `json:"authorId"` //发布人id
Images []string `json:"images,optional"` //图片
Videos []Video `json:"video,optional"` // 视频
TargetUser int `json:"targetUser"` // 分发方式 [0分发给所有人、1分发给指定的人]
WhoRead []int64 `json:"whoRead,optional"` //谁可查看
WhoReview []int64 `json:"whoReview,optional"` //谁可评论
MatchUrl map[string]string `json:"matchUrl,optional"` // 匹配文章内容中的url文本
Tags []int64 `json:"tags"` // 标签
}
)
//管理后台已删除列表
type (
SystemArticleSearchDeletedRequest {
Page int `json:"page"` //页码
Size int `json:"size"` //每页行数
Title string `json:"title,optional"` //标题
Author int64 `json:"author,optional"` //发布人
DeletedType int `json:"deletedType,optional"`//类型 1-运营删除 2-用户删除
BeginTime int64 `json:"beginTime,optional"`//开始时间
EndTime int64 `json:"endTime,optional"` //结束时间
}
SystemArticleSearchDeletedResponse {
Total int `json:"total"`
List []SystemArticleSearchDeletedItem `json:"list"`
}
SystemArticleSearchDeletedItem {
Id int64 `json:"id"` //ID
Title string `json:"title"` //标题
Images []string `json:"images"` //图片
AuthorId int64 `json:"authorId"` //发布人id
Author string `json:"author"` //发布人
Source int `json:"source"` //来源 1-用户发布 2-运营发布
DeletedType int `json:"deletedType"` //类型 1-运营删除 2-用户删除
DeletedAt int64 `json:"deletedAt"` //删除时间
}
)
//管理后台已删除文章恢复
type (
SystemArticleDeletedRestoreRequest {
Id int64 `json:"id"` //ID
}
SystemArticleDeletedRestoreResponse {
Id int64 `json:"id"` //ID
Title string `json:"title"` //标题
AuthorId int64 `json:"authorId"` //发布人id
}
)
\ No newline at end of file
... ...
... ... @@ -41,6 +41,10 @@ service Core {
jwt : SystemAuth
)
service Core {
@doc "公司可见开关"
@handler systemCompanyVisibleSwitch
post /system/company/visible_switch(CompanyVisibleSwitchRequest) returns (CompanyVisibleSwitchResponse)
@doc "公司搜索"
@handler systemCompanySearch
post /system/company/search(CompanySearchRequest) returns (CompanySearchResponse)
... ... @@ -70,6 +74,13 @@ type (
Logo string `json:"logo,omitempty"` // 公司LOGO
JoinedFlag int `json:"joinedFlag"` // 已加入标识(1:已加入 其他:未加入)
}
CompanyVisibleSwitchRequest{
Visible bool `json:"visible"` // 可见性 true:可被搜索 false:不可被搜索
}
CompanyVisibleSwitchResponse{
}
)
// 公司职位搜索
... ...
... ... @@ -2,7 +2,7 @@ Name: discuss
Host: 0.0.0.0
Port: 8081
Verbose: false
Migrate: false
Migrate: true
Timeout: 30000
# CertFile: ./key/fjmaimaimai.com_bundle.crt
# KeyFile: ./key/fjmaimaimai.com.key
... ...
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 SystemArticleSearchDeletedHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.SystemArticleSearchDeletedRequest
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
return
}
l := article.NewSystemArticleSearchDeletedLogic(r.Context(), svcCtx)
resp, err := l.SystemArticleSearchDeleted(&req)
result.HttpResult(r, w, resp, err)
}
}
... ...
package article
import (
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/result"
"net/http"
"github.com/zeromicro/go-zero/rest/httpx"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/logic/article"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types"
)
func SystemCreateArticleDraftHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.SystemArticleDraftCreateRequest
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
return
}
l := article.NewSystemCreateArticleDraftLogic(r.Context(), svcCtx)
resp, err := l.SystemCreateArticleDraft(&req)
result.HttpResult(r, w, resp, err)
}
}
... ...
package article
import (
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/result"
"net/http"
"github.com/zeromicro/go-zero/rest/httpx"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/logic/article"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types"
)
func SystemCreateArticleHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.SystemArticleCreateRequest
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
return
}
l := article.NewSystemCreateArticleLogic(r.Context(), svcCtx)
resp, err := l.SystemCreateArticle(&req)
result.HttpResult(r, w, resp, err)
}
}
... ...
package article
import (
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/result"
"net/http"
"github.com/zeromicro/go-zero/rest/httpx"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/logic/article"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types"
)
func SystemDeleteArticleDraftHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.SystemArticleDraftDeleteRequest
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
return
}
l := article.NewSystemDeleteArticleDraftLogic(r.Context(), svcCtx)
resp, err := l.SystemDeleteArticleDraft(&req)
result.HttpResult(r, w, resp, err)
}
}
... ...
package article
import (
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/result"
"net/http"
"github.com/zeromicro/go-zero/rest/httpx"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/logic/article"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types"
)
func SystemDeleteArticleHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.SystemArticleDeleteRequest
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
return
}
l := article.NewSystemDeleteArticleLogic(r.Context(), svcCtx)
resp, err := l.SystemDeleteArticle(&req)
result.HttpResult(r, w, resp, err)
}
}
... ...
package article
import (
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/result"
"net/http"
"github.com/zeromicro/go-zero/rest/httpx"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/logic/article"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types"
)
func SystemGetArticleDraftHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.SystemArticleDraftGetRequest
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
return
}
l := article.NewSystemGetArticleDraftLogic(r.Context(), svcCtx)
resp, err := l.SystemGetArticleDraft(&req)
result.HttpResult(r, w, resp, err)
}
}
... ...
package article
import (
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/result"
"net/http"
"github.com/zeromicro/go-zero/rest/httpx"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/logic/article"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types"
)
func SystemRestoreArticleDeletedHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.SystemArticleDeletedRestoreRequest
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
return
}
l := article.NewSystemRestoreArticleDeletedLogic(r.Context(), svcCtx)
resp, err := l.SystemRestoreArticleDeleted(&req)
result.HttpResult(r, w, resp, err)
}
}
... ...
package article
import (
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/contextdata"
"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 SystemSearchArticleDraftHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.SystemArticleDraftSearchRequest
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
return
}
userToken := contextdata.GetUserTokenFromCtx(r.Context())
req.CompanyId = userToken.CompanyId
l := article.NewSystemSearchArticleDraftLogic(r.Context(), svcCtx)
resp, err := l.SystemSearchArticleDraft(&req)
result.HttpResult(r, w, resp, err)
}
}
... ...
package article
import (
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/result"
"net/http"
"github.com/zeromicro/go-zero/rest/httpx"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/logic/article"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types"
)
func SystemUpdateArticleDraftHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.SystemArticleDraftUpdateRequest
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
return
}
l := article.NewSystemUpdateArticleDraftLogic(r.Context(), svcCtx)
resp, err := l.SystemUpdateArticleDraft(&req)
result.HttpResult(r, w, resp, err)
}
}
... ...
package company
import (
"net/http"
"github.com/zeromicro/go-zero/rest/httpx"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/logic/company"
"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 SystemCompanyVisibleSwitchHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.CompanyVisibleSwitchRequest
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
return
}
l := company.NewSystemCompanyVisibleSwitchLogic(r.Context(), svcCtx)
resp, err := l.SystemCompanyVisibleSwitch(&req)
if err != nil {
httpx.ErrorCtx(r.Context(), w, err)
} else {
httpx.OkJsonCtx(r.Context(), w, resp)
}
}
}
... ...
... ... @@ -445,6 +445,11 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
[]rest.Route{
{
Method: http.MethodPost,
Path: "/system/company/visible_switch",
Handler: company.SystemCompanyVisibleSwitchHandler(serverCtx),
},
{
Method: http.MethodPost,
Path: "/system/company/search",
Handler: company.SystemCompanySearchHandler(serverCtx),
},
... ... @@ -598,6 +603,51 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
Path: "/article/restore",
Handler: article.SystemArticleRestoreHandler(serverCtx),
},
{
Method: http.MethodDelete,
Path: "/article",
Handler: article.SystemDeleteArticleHandler(serverCtx),
},
{
Method: http.MethodPost,
Path: "/article",
Handler: article.SystemCreateArticleHandler(serverCtx),
},
{
Method: http.MethodPost,
Path: "/article/draft",
Handler: article.SystemCreateArticleDraftHandler(serverCtx),
},
{
Method: http.MethodPut,
Path: "/article/draft",
Handler: article.SystemUpdateArticleDraftHandler(serverCtx),
},
{
Method: http.MethodPost,
Path: "/article/draft/search",
Handler: article.SystemSearchArticleDraftHandler(serverCtx),
},
{
Method: http.MethodDelete,
Path: "/article/draft",
Handler: article.SystemDeleteArticleDraftHandler(serverCtx),
},
{
Method: http.MethodGet,
Path: "/article/draft/:id",
Handler: article.SystemGetArticleDraftHandler(serverCtx),
},
{
Method: http.MethodPost,
Path: "/article/deleted/list",
Handler: article.SystemArticleSearchDeletedHandler(serverCtx),
},
{
Method: http.MethodPut,
Path: "/article/deleted/restore",
Handler: article.SystemRestoreArticleDeletedHandler(serverCtx),
},
}...,
),
rest.WithJwt(serverCtx.Config.SystemAuth.AccessSecret),
... ... @@ -678,4 +728,55 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
rest.WithJwt(serverCtx.Config.SystemAuth.AccessSecret),
rest.WithPrefix("/v1"),
)
server.AddRoutes(
rest.WithMiddlewares(
[]rest.Middleware{serverCtx.LoginStatusCheck, serverCtx.LogRequest},
[]rest.Route{
{
Method: http.MethodGet,
Path: "/article_category/:id",
Handler: tags.ArticleCategoryGetHandler(serverCtx),
},
{
Method: http.MethodPost,
Path: "/article_category",
Handler: tags.ArticleCategorySaveHandler(serverCtx),
},
{
Method: http.MethodDelete,
Path: "/article_category/:id",
Handler: tags.ArticleCategoryDeleteHandler(serverCtx),
},
{
Method: http.MethodPut,
Path: "/article_category/:id",
Handler: tags.ArticleCategoryUpdateHandler(serverCtx),
},
{
Method: http.MethodPost,
Path: "/article_category/search",
Handler: tags.ArticleCategorySearchHandler(serverCtx),
},
{
Method: http.MethodGet,
Path: "/article_category/options",
Handler: tags.ArticleCategoryOptionsHandler(serverCtx),
},
}...,
),
rest.WithJwt(serverCtx.Config.SystemAuth.AccessSecret),
rest.WithPrefix("/v1/system"),
)
server.AddRoutes(
[]rest.Route{
{
Method: http.MethodGet,
Path: "/article_category/init",
Handler: tags.ArticleCategoryInitHandler(serverCtx),
},
},
rest.WithPrefix("/v1/system"),
)
}
... ...
package tags
import (
"net/http"
"github.com/zeromicro/go-zero/rest/httpx"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/logic/tags"
"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 ArticleCategoryDeleteHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.ArticleCategoryDeleteRequest
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
return
}
l := tags.NewArticleCategoryDeleteLogic(r.Context(), svcCtx)
resp, err := l.ArticleCategoryDelete(&req)
if err != nil {
httpx.ErrorCtx(r.Context(), w, err)
} else {
httpx.OkJsonCtx(r.Context(), w, resp)
}
}
}
... ...
package tags
import (
"net/http"
"github.com/zeromicro/go-zero/rest/httpx"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/logic/tags"
"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 ArticleCategoryGetHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.ArticleCategoryGetRequest
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
return
}
l := tags.NewArticleCategoryGetLogic(r.Context(), svcCtx)
resp, err := l.ArticleCategoryGet(&req)
if err != nil {
httpx.ErrorCtx(r.Context(), w, err)
} else {
httpx.OkJsonCtx(r.Context(), w, resp)
}
}
}
... ...
package tags
import (
"net/http"
"github.com/zeromicro/go-zero/rest/httpx"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/logic/tags"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc"
)
func ArticleCategoryInitHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
l := tags.NewArticleCategoryInitLogic(r.Context(), svcCtx)
err := l.ArticleCategoryInit()
if err != nil {
httpx.ErrorCtx(r.Context(), w, err)
} else {
httpx.Ok(w)
}
}
}
... ...
package tags
import (
"net/http"
"github.com/zeromicro/go-zero/rest/httpx"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/logic/tags"
"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 ArticleCategoryOptionsHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.CategoryOptionsRequest
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
return
}
l := tags.NewArticleCategoryOptionsLogic(r.Context(), svcCtx)
resp, err := l.ArticleCategoryOptions(&req)
if err != nil {
httpx.ErrorCtx(r.Context(), w, err)
} else {
httpx.OkJsonCtx(r.Context(), w, resp)
}
}
}
... ...
package tags
import (
"net/http"
"github.com/zeromicro/go-zero/rest/httpx"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/logic/tags"
"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 ArticleCategorySaveHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.ArticleCategorySaveRequest
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
return
}
l := tags.NewArticleCategorySaveLogic(r.Context(), svcCtx)
resp, err := l.ArticleCategorySave(&req)
if err != nil {
httpx.ErrorCtx(r.Context(), w, err)
} else {
httpx.OkJsonCtx(r.Context(), w, resp)
}
}
}
... ...
package tags
import (
"net/http"
"github.com/zeromicro/go-zero/rest/httpx"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/logic/tags"
"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 ArticleCategorySearchHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.ArticleCategorySearchRequest
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
return
}
l := tags.NewArticleCategorySearchLogic(r.Context(), svcCtx)
resp, err := l.ArticleCategorySearch(&req)
if err != nil {
httpx.ErrorCtx(r.Context(), w, err)
} else {
httpx.OkJsonCtx(r.Context(), w, resp)
}
}
}
... ...
package tags
import (
"net/http"
"github.com/zeromicro/go-zero/rest/httpx"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/logic/tags"
"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 ArticleCategoryUpdateHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.ArticleCategoryUpdateRequest
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
return
}
l := tags.NewArticleCategoryUpdateLogic(r.Context(), svcCtx)
resp, err := l.ArticleCategoryUpdate(&req)
if err != nil {
httpx.ErrorCtx(r.Context(), w, err)
} else {
httpx.OkJsonCtx(r.Context(), w, resp)
}
}
}
... ...
... ... @@ -47,10 +47,15 @@ func (l *MiniShowHomePageLogic) MiniShowHomePage(req *types.MiniHomePageRequest)
countDataMap[val.TagId] = val
}
tagCategory := []string{}
tagCount := []types.ArticleTagCount{}
_, categoryList, _ := l.svcCtx.ArticleCategoryRepository.Find(l.ctx, conn, req.CompanyId, domain.NewQueryOptions().MustWithKV("enable", 1))
tagCount := make([]types.ArticleTagCount, 0)
tagCategory := domain.Values(categoryList, func(item *domain.ArticleCategory) string {
return item.Name
})
categoryMap := lo.KeyBy(categoryList, func(item *domain.ArticleCategory) int64 {
return item.Id
})
for _, val := range allTags {
tagCategory = append(tagCategory, val.Category)
m := types.ArticleTagCount{
TagCategory: val.Category,
TagId: val.Id,
... ... @@ -65,9 +70,13 @@ func (l *MiniShowHomePageLogic) MiniShowHomePage(req *types.MiniHomePageRequest)
m.TotalArticle = count.TotalArticle
m.ReadArticle = count.ReadArticle
}
if v, ok := categoryMap[val.CategoryId]; ok {
m.TagCategory = v.Name
} else {
continue
}
tagCount = append(tagCount, m)
}
tagCategory = lo.Uniq(tagCategory)
resp = &types.MiniHomePageResponse{
TagCategory: tagCategory,
Tags: tagCount,
... ...
package article
import (
"context"
"github.com/samber/lo"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/db/transaction"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/contextdata"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/xerr"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types"
"github.com/zeromicro/go-zero/core/logx"
)
type SystemArticleSearchDeletedLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
conn transaction.Conn
}
func NewSystemArticleSearchDeletedLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SystemArticleSearchDeletedLogic {
return &SystemArticleSearchDeletedLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
conn: svcCtx.DefaultDBConn(),
}
}
func (l *SystemArticleSearchDeletedLogic) SystemArticleSearchDeleted(req *types.SystemArticleSearchDeletedRequest) (resp *types.SystemArticleSearchDeletedResponse, err error) {
queryOptions := domain.NewQueryOptions().
WithOffsetLimit(req.Page, req.Size).
WithKV("isDel", 1).
WithKV("title", req.Title).
WithKV("authorId", req.Author).
WithKV("beginDeletedAt", req.BeginTime).
WithKV("endDeletedAt", req.EndTime).
WithKV("deletedType", req.DeletedType).
WithKV("orderMode", "deletedAt descending")
userToken := contextdata.GetUserTokenFromCtx(l.ctx)
total, articles, err := l.svcCtx.ArticleRepository.Find(l.ctx, l.conn, userToken.CompanyId, queryOptions)
if err != nil {
return nil, xerr.NewErrMsgErr("搜索已删除列表异常", err)
}
resp = &types.SystemArticleSearchDeletedResponse{
Total: int(total),
List: make([]types.SystemArticleSearchDeletedItem, 0),
}
authorIds := make([]int64, 0)
lo.ForEach(articles, func(item *domain.Article, index int) {
authorIds = append(authorIds, item.AuthorId)
})
//查询用户数据,重新赋值更新用户名称
_, users, _ := l.svcCtx.UserRepository.Find(l.ctx, l.conn, domain.NewQueryOptions().WithFindOnly().WithKV("ids", authorIds))
lo.ForEach(articles, func(item *domain.Article, index int) {
//图片
images := make([]string, 0)
lo.ForEach(item.Images, func(img domain.Image, n int) {
images = append(images, img.Url)
})
//发布人
author := item.Author.Name
for _, user := range users {
if user.Id == item.AuthorId {
author = user.Name
}
}
resp.List = append(resp.List, types.SystemArticleSearchDeletedItem{
Id: item.Id,
Title: item.Title,
Images: images,
AuthorId: item.AuthorId,
Author: author,
Source: item.Source,
DeletedType: item.DeletedType,
DeletedAt: item.DeletedAt,
})
})
return
}
... ...
package article
import (
"context"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/db/transaction"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/gateway/authlib"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/contextdata"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/tool/oss"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/xerr"
"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"
"github.com/zeromicro/go-zero/core/logx"
)
type SystemCreateArticleDraftLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
conn transaction.Conn
}
func NewSystemCreateArticleDraftLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SystemCreateArticleDraftLogic {
return &SystemCreateArticleDraftLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
conn: svcCtx.DefaultDBConn(),
}
}
func (l *SystemCreateArticleDraftLogic) SystemCreateArticleDraft(req *types.SystemArticleDraftCreateRequest) (resp *types.SystemArticleDraftCreateResponse, err error) {
// 检查发布人
author, err := l.svcCtx.UserRepository.FindOne(l.ctx, l.conn, req.AuthorId)
if err != nil {
return nil, xerr.NewErrMsgErr("创建草稿失败", err)
}
companyInfo, err := l.svcCtx.CompanyRepository.FindOne(l.ctx, l.conn, author.CompanyId)
if err != nil {
return nil, xerr.NewErrMsgErr("创建草稿失败", err)
}
//图片
images, err := getImages(req.Images)
if err != nil {
return nil, xerr.NewErrMsg(err.Error())
}
//视频
videos, err := getVideos(req.Videos)
if err != nil {
return nil, xerr.NewErrMsg(err.Error())
}
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)
}
articleDraft := &domain.ArticleDraftOperation{
CompanyId: companyInfo.Id,
AuthorId: req.AuthorId,
Title: req.Title,
Content: req.Content,
Images: images,
Videos: videos,
TargetUser: domain.ArticleTarget(req.TargetUser),
WhoRead: req.WhoRead,
WhoReview: req.WhoReview,
MatchUrl: req.MatchUrl,
Source: domain.ArticleSourceOperator,
Operator: domain.Operator{
Id: userToken.UserId,
Name: userMe.User.NickName,
},
Tags: req.Tags,
}
err = transaction.UseTrans(l.ctx, l.conn.DB(), func(ctx context.Context, conn transaction.Conn) error {
_, err := l.svcCtx.ArticleDraftOperationRepository.Insert(ctx, conn, articleDraft)
if err != nil {
return err
}
return nil
}, true)
resp = &types.SystemArticleDraftCreateResponse{
Id: articleDraft.Id,
Title: articleDraft.Title,
Content: articleDraft.Content,
AuthorId: articleDraft.AuthorId,
Images: req.Images,
Videos: req.Videos,
TargetUser: req.TargetUser,
WhoRead: req.WhoRead,
WhoReview: req.WhoReview,
MatchUrl: req.MatchUrl,
Tags: req.Tags,
}
return
}
// getImages 获取图片信息
func getImages(imgs []string) ([]domain.Image, error) {
// 获取图片的尺寸大小
images := make([]domain.Image, 0)
if len(imgs) <= 0 {
return images, nil
}
for _, val := range imgs {
fInfo, err := oss.GetImageInfo(val)
if err != nil {
return images, xerr.NewErrMsg("获取图片失败")
}
w, _ := strconv.Atoi(fInfo.ImageWidth.Value)
h, _ := strconv.Atoi(fInfo.ImageHeight.Value)
images = append(images, domain.Image{
Url: val,
Width: w,
Height: h,
})
}
return images, nil
}
// getVideos 获取视频信息
func getVideos(list []types.Video) ([]domain.Video, error) {
videos := make([]domain.Video, 0)
if len(list) <= 0 {
return videos, nil
}
if len(list) > 0 {
for _, item := range list {
cover, w, h, err := oss.GetVideoCover(item.Url)
if err != nil {
return videos, xerr.NewErrMsg("获取视频信息失败")
}
videos = append(videos, domain.Video{
Url: item.Url,
Cover: cover,
Width: w,
Height: h,
})
}
}
return videos, nil
}
... ...
package article
import (
"context"
"github.com/pkg/errors"
"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"
"strconv"
"strings"
"unicode/utf8"
"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 SystemCreateArticleLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
conn transaction.Conn
}
func NewSystemCreateArticleLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SystemCreateArticleLogic {
return &SystemCreateArticleLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
conn: svcCtx.DefaultDBConn(),
}
}
func (l *SystemCreateArticleLogic) SystemCreateArticle(req *types.SystemArticleCreateRequest) (resp *types.SystemArticleCreateResponse, err error) {
err = l.validate(req)
if err != nil {
return nil, xerr.NewErrMsg(err.Error())
}
// 检查发布人
author, err := l.svcCtx.UserRepository.FindOne(l.ctx, l.conn, req.AuthorId)
if err != nil {
return nil, xerr.NewErrMsgErr("创建文章内容失败", err)
}
companyInfo, err := l.svcCtx.CompanyRepository.FindOne(l.ctx, l.conn, author.CompanyId)
if err != nil {
return nil, xerr.NewErrMsgErr("创建文章内容失败", err)
}
//文章作者
articleAuthor := domain.UserSimple{
Id: author.Id,
Name: author.Name,
Avatar: author.Avatar,
Position: author.Position,
Company: companyInfo.Name,
CompanyId: author.CompanyId,
}
//图片
images, err := l.getImages(req)
if err != nil {
return nil, xerr.NewErrMsg(err.Error())
}
//视频
videos, err := l.getVideos(req)
if err != nil {
return nil, xerr.NewErrMsg(err.Error())
}
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)
}
article := &domain.Article{
CompanyId: companyInfo.Id,
AuthorId: req.AuthorId,
Author: articleAuthor,
Title: req.Title,
Images: images,
Videos: videos,
WhoRead: make([]int64, 0),
WhoReview: make([]int64, 0),
Location: domain.Location{},
TargetUser: domain.ArticleTarget(req.TargetUser),
Show: domain.ArticleShowEnable,
Tags: make([]int64, 0),
MatchUrl: make(map[string]string),
Source: domain.ArticleSourceOperator,
Operator: domain.Operator{
Id: userToken.UserId,
Name: userMe.User.NickName,
},
}
if len(req.MatchUrl) > 0 {
article.MatchUrl = req.MatchUrl
}
//检查文章可被哪些人查看
whoRead, err := l.validateAndGetWhoRead(req, article)
if err != nil {
return nil, err
}
//检查文章可被哪些人评论
whoReview := []int64{}
if len(req.WhoReview) > 0 {
whoReview = lo.Uniq(req.WhoReview)
}
//验证可评论
if err = l.validateWhoReview(whoRead, whoReview, article); err != nil {
return nil, err
}
article.WhoRead = whoRead
article.WhoReview = whoReview
sections := l.getSections(req, article)
//设置内容摘要
article.SetSummary(sections)
//草稿ID
if req.ArticleDraftId > 0 {
articleDraft, err := l.svcCtx.ArticleDraftOperationRepository.FindOne(l.ctx, l.conn, req.ArticleDraftId)
if err != nil {
return nil, xerr.NewErrMsg("草稿不存在")
}
if articleDraft.CompanyId != userToken.CompanyId {
return nil, xerr.NewErrMsg("您没有权限")
}
}
//保存数据
err = transaction.UseTrans(l.ctx, l.conn.DB(), func(ctx context.Context, conn transaction.Conn) error {
_, err = l.svcCtx.ArticleRepository.Insert(ctx, conn, article)
if err != nil {
return xerr.NewErrMsgErr("创建文章失败", err)
}
for i := range sections {
sections[i].ArticleId = article.Id
_, err = l.svcCtx.ArticleSectionRepository.Insert(ctx, conn, sections[i])
if err != nil {
return xerr.NewErrMsgErr("创建文章内容失败", err)
}
}
// 生成 备份数据
var backupData domain.ArticleBackup
backupData.MakeBackup(articleAuthor, article, sections, "原始版本")
_, err = l.svcCtx.ArticleBackupRepository.Insert(l.ctx, conn, &backupData)
if err != nil {
return xerr.NewErrMsgErr("创建文章失败", err)
}
//删除草稿
if req.ArticleDraftId > 0 {
_, err = l.svcCtx.ArticleDraftOperationRepository.Delete(l.ctx, conn, &domain.ArticleDraftOperation{Id: req.ArticleDraftId})
if err != nil {
return xerr.NewErrMsg("删除草稿失败")
}
}
return nil
}, true)
if err != nil {
return nil, xerr.NewErrMsgErr("创建文章失败", err)
}
resp = &types.SystemArticleCreateResponse{
Id: article.Id,
Title: article.Title,
Content: req.Content,
AuthorId: req.AuthorId,
Images: req.Images,
Videos: req.Videos,
TargetUser: req.TargetUser,
WhoRead: whoRead,
WhoReview: whoReview,
}
return
}
// validate 验证
func (l *SystemCreateArticleLogic) validate(req *types.SystemArticleCreateRequest) error {
//文章标题
if utf8.RuneCountInString(req.Title) > 64 {
return errors.New("标题最多只能输入64字")
}
//文章内容
if utf8.RuneCountInString(req.Content) > 1000 {
return errors.New("内容最多只能输入1000字")
}
//图片
if len(req.Images) > 9 {
return errors.New("图片数量最多9张")
}
return nil
}
// getImages 获取图片信息
func (l *SystemCreateArticleLogic) getImages(req *types.SystemArticleCreateRequest) ([]domain.Image, error) {
// 获取图片的尺寸大小
images := make([]domain.Image, 0)
for _, val := range req.Images {
fInfo, err := oss.GetImageInfo(val)
if err != nil {
return images, xerr.NewErrMsg("获取图片失败")
}
w, _ := strconv.Atoi(fInfo.ImageWidth.Value)
h, _ := strconv.Atoi(fInfo.ImageHeight.Value)
images = append(images, domain.Image{
Url: val,
Width: w,
Height: h,
})
}
return images, nil
}
// getVideo 获取视频信息
func (l *SystemCreateArticleLogic) getVideos(req *types.SystemArticleCreateRequest) ([]domain.Video, error) {
videos := make([]domain.Video, 0)
if len(req.Videos) > 0 {
for _, item := range req.Videos {
cover, w, h, err := oss.GetVideoCover(item.Url)
if err != nil {
return videos, xerr.NewErrMsg("获取视频信息失败")
}
videos = append(videos, domain.Video{
Url: item.Url,
Cover: cover,
Width: w,
Height: h,
})
}
}
return videos, nil
}
// validateAndGetWhoRead 验证并获取可阅读
func (l *SystemCreateArticleLogic) validateAndGetWhoRead(req *types.SystemArticleCreateRequest, article *domain.Article) ([]int64, error) {
whoRead := make([]int64, 0)
if len(req.WhoRead) > 0 {
whoRead = lo.Uniq(req.WhoRead)
var u *domain.User
var err error
for _, val := range whoRead {
u, err = l.svcCtx.UserRepository.FindOne(l.ctx, l.conn, val)
if err != nil {
return whoRead, xerr.NewErrMsgErr("文章可查看人设置错误", err)
}
if u.CompanyId != article.CompanyId {
return whoRead, xerr.NewErrMsg("文章可查看人设置错误")
}
}
}
return whoRead, nil
}
// validateWhoReview 验证可评论
func (l *SystemCreateArticleLogic) validateWhoReview(whoRead []int64, whoReview []int64, article *domain.Article) error {
//有指定可查看人的情况
if len(whoRead) > 0 {
if len(whoReview) > 0 {
// 检查 whoRead 是否 完全包含 whoReview
ok := lo.Every(whoRead, whoReview)
if !ok {
return xerr.NewErrMsg("文章可评论人设置错误")
}
}
if len(whoReview) == 0 {
//有指定可查看人 ,但未指定可评论人
return xerr.NewErrMsg("文章可评论人设置错误")
}
}
//没有指定可查看人的情况
if len(whoRead) == 0 {
if len(whoReview) > 0 {
// 未指定可查看人(全员可看),有指定可评论人,
var u *domain.User
var err error
for _, val := range whoReview {
u, err = l.svcCtx.UserRepository.FindOne(l.ctx, l.conn, val)
if err != nil {
return xerr.NewErrMsgErr("文章可评论人设置错误", err)
}
if u.CompanyId != article.CompanyId {
return xerr.NewErrMsg("文章可评论人设置错误")
}
}
}
}
return nil
}
// getSections 文章内容
func (l *SystemCreateArticleLogic) getSections(req *types.SystemArticleCreateRequest, article *domain.Article) []*domain.ArticleSection {
articleSections := make([]*domain.ArticleSection, 0)
sortBy := 1
sections := strings.Split(req.Content, "\n")
lo.ForEach(sections, func(item string, index int) {
section := domain.ArticleSection{
CompanyId: article.CompanyId,
Version: article.Version,
ArticleId: article.Id,
Content: item,
SortBy: sortBy,
}
articleSections = append(articleSections, &section)
sortBy++
})
return articleSections
}
... ...
package article
import (
"context"
"github.com/samber/lo"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/db/transaction"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/contextdata"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/xerr"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types"
"github.com/zeromicro/go-zero/core/logx"
)
type SystemDeleteArticleDraftLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
conn transaction.Conn
}
func NewSystemDeleteArticleDraftLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SystemDeleteArticleDraftLogic {
return &SystemDeleteArticleDraftLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
conn: svcCtx.DefaultDBConn(),
}
}
func (l *SystemDeleteArticleDraftLogic) SystemDeleteArticleDraft(req *types.SystemArticleDraftDeleteRequest) (resp *types.SystemArticleDraftDeleteResponse, err error) {
// 草稿数据
articleDraft, err := l.svcCtx.ArticleDraftOperationRepository.FindOne(l.ctx, l.conn, req.Id)
if err != nil {
return nil, xerr.NewErrMsg("草稿不存在")
}
//操作人
userToken := contextdata.GetUserTokenFromCtx(l.ctx)
if userToken.CompanyId != articleDraft.CompanyId {
return nil, xerr.NewErrMsg("您没有权限删除")
}
_, err = l.svcCtx.ArticleDraftOperationRepository.Delete(l.ctx, l.conn, articleDraft)
if err != nil {
return nil, xerr.NewErrMsg("删除草稿失败")
}
//图片
images := make([]string, 0)
lo.ForEach(articleDraft.Images, func(img domain.Image, n int) {
images = append(images, img.Url)
})
//视频
videos := make([]types.Video, 0)
lo.ForEach(articleDraft.Videos, func(video domain.Video, n int) {
videos = append(videos, types.Video{
Url: video.Url,
Cover: video.Cover,
Width: video.Width,
Height: video.Height,
})
})
resp = &types.SystemArticleDraftDeleteResponse{
Id: articleDraft.Id,
Title: articleDraft.Title,
Content: articleDraft.Content,
AuthorId: articleDraft.AuthorId,
Images: images,
Videos: videos,
TargetUser: int(articleDraft.TargetUser),
WhoRead: articleDraft.WhoRead,
WhoReview: articleDraft.WhoReview,
MatchUrl: articleDraft.MatchUrl,
Tags: articleDraft.Tags,
}
return
}
... ...
package article
import (
"context"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/db/transaction"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/contextdata"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/xerr"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types"
"github.com/zeromicro/go-zero/core/logx"
)
type SystemDeleteArticleLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
conn transaction.Conn
}
func NewSystemDeleteArticleLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SystemDeleteArticleLogic {
return &SystemDeleteArticleLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
conn: svcCtx.DefaultDBConn(),
}
}
func (l *SystemDeleteArticleLogic) SystemDeleteArticle(req *types.SystemArticleDeleteRequest) (resp *types.SystemArticleDeleteResponse, err error) {
// 文章数据
article, err := l.svcCtx.ArticleRepository.FindOne(l.ctx, l.conn, req.Id)
if err != nil {
return nil, xerr.NewErrMsgErr("帖子不存在", err)
}
userToken := contextdata.GetUserTokenFromCtx(l.ctx)
if userToken.CompanyId != article.CompanyId {
return nil, xerr.NewErrMsg("您没有权限")
}
article.DeletedType = domain.ArticleDeletedTypeOperator
err = transaction.UseTrans(l.ctx, l.conn.DB(), func(ctx context.Context, conn transaction.Conn) error {
//更新删除类型
_, err = l.svcCtx.ArticleRepository.Update(l.ctx, conn, article)
if err != nil {
return err
}
_, err = l.svcCtx.ArticleRepository.Delete(l.ctx, l.conn, article)
if err != nil {
return err
}
return nil
}, true)
if err != nil {
return nil, xerr.NewErrMsgErr("删除失败", err)
}
resp = &types.SystemArticleDeleteResponse{
Id: article.Id,
Title: article.Title,
AuthorId: article.AuthorId,
}
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/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 SystemGetArticleDraftLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
conn transaction.Conn
}
func NewSystemGetArticleDraftLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SystemGetArticleDraftLogic {
return &SystemGetArticleDraftLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
conn: svcCtx.DefaultDBConn(),
}
}
func (l *SystemGetArticleDraftLogic) SystemGetArticleDraft(req *types.SystemArticleDraftGetRequest) (resp *types.SystemArticleDraftGetResponse, err error) {
// 草稿数据
articleDraft, err := l.svcCtx.ArticleDraftOperationRepository.FindOne(l.ctx, l.conn, req.Id)
if err != nil {
return nil, xerr.NewErrMsg("草稿不存在")
}
//操作人
userToken := contextdata.GetUserTokenFromCtx(l.ctx)
//不同公司不能获取数据
if userToken.CompanyId != articleDraft.CompanyId {
return nil, xerr.NewErrMsg("您没有权限查看该数据")
}
//图片
images := make([]string, 0)
lo.ForEach(articleDraft.Images, func(img domain.Image, n int) {
images = append(images, img.Url)
})
//视频
videos := make([]types.Video, 0)
lo.ForEach(articleDraft.Videos, func(video domain.Video, n int) {
videos = append(videos, types.Video{
Url: video.Url,
Cover: video.Cover,
Width: video.Width,
Height: video.Height,
})
})
resp = &types.SystemArticleDraftGetResponse{
Id: articleDraft.Id,
Title: articleDraft.Title,
Content: articleDraft.Content,
AuthorId: articleDraft.AuthorId,
Images: images,
Videos: videos,
TargetUser: int(articleDraft.TargetUser),
WhoRead: articleDraft.WhoRead,
WhoReview: articleDraft.WhoReview,
MatchUrl: articleDraft.MatchUrl,
Tags: articleDraft.Tags,
}
return
}
... ...
package article
import (
"context"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/db/transaction"
"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 SystemRestoreArticleDeletedLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
conn transaction.Conn
}
func NewSystemRestoreArticleDeletedLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SystemRestoreArticleDeletedLogic {
return &SystemRestoreArticleDeletedLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
conn: svcCtx.DefaultDBConn(),
}
}
func (l *SystemRestoreArticleDeletedLogic) SystemRestoreArticleDeleted(req *types.SystemArticleDeletedRestoreRequest) (resp *types.SystemArticleDeletedRestoreResponse, err error) {
// 文章数据
article, err := l.svcCtx.ArticleRepository.FindOneWithUnscoped(l.ctx, l.conn, req.Id)
if err != nil {
return nil, xerr.NewErrMsgErr("帖子不存在", err)
}
_, err = l.svcCtx.ArticleRepository.Restore(l.ctx, l.conn, article)
if err != nil {
return nil, xerr.NewErrMsg("恢复帖子失败")
}
resp = &types.SystemArticleDeletedRestoreResponse{
Id: article.Id,
Title: article.Title,
AuthorId: article.AuthorId,
}
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/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 SystemSearchArticleDraftLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
conn transaction.Conn
}
func NewSystemSearchArticleDraftLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SystemSearchArticleDraftLogic {
return &SystemSearchArticleDraftLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
conn: svcCtx.DefaultDBConn(),
}
}
func (l *SystemSearchArticleDraftLogic) SystemSearchArticleDraft(req *types.SystemArticleDraftSearchRequest) (resp *types.SystemArticleDraftSearchResponse, err error) {
queryOptions := domain.NewQueryOptions().
WithOffsetLimit(req.Page, req.Size).
WithKV("companyId", req.CompanyId).
WithKV("title", req.Title).
WithKV("operator", req.Operator).
WithKV("beginTime", req.BeginTime).
WithKV("endTime", req.EndTime)
total, articleDrafts, err := l.svcCtx.ArticleDraftOperationRepository.Find(l.ctx, l.conn, queryOptions)
if err != nil {
return nil, xerr.NewErrMsgErr("搜索草稿异常", err)
}
resp = &types.SystemArticleDraftSearchResponse{
Total: int(total),
List: make([]types.SystemArticleDraftSearch, 0),
}
authorIds := make([]int64, 0)
lo.ForEach(articleDrafts, func(item *domain.ArticleDraftOperation, index int) {
authorIds = append(authorIds, item.AuthorId)
})
//查询用户数据,重新赋值更新用户名称
_, users, _ := l.svcCtx.UserRepository.Find(l.ctx, l.conn, domain.NewQueryOptions().WithFindOnly().WithKV("ids", authorIds))
lo.ForEach(articleDrafts, func(item *domain.ArticleDraftOperation, index int) {
//图片
images := make([]string, 0)
lo.ForEach(item.Images, func(img domain.Image, n int) {
images = append(images, img.Url)
})
//发布人
author := ""
for _, user := range users {
if user.Id == item.AuthorId {
author = user.Name
}
}
resp.List = append(resp.List, types.SystemArticleDraftSearch{
Id: item.Id,
Title: item.Title,
Images: images,
Operator: item.Operator.Name,
AuthorId: item.AuthorId,
Author: author,
UpdatedAt: item.UpdatedAt,
})
})
return
}
... ...
... ... @@ -82,11 +82,17 @@ func (l *SystemSearchArticleLogic) SystemSearchArticle(req *types.SystemArticleS
Author: author,
Images: images,
CreatedAt: item.CreatedAt,
UpdatedAt: item.UpdatedAt,
CountLove: item.CountLove,
CountComment: item.CountComment,
Show: int(item.Show),
Tags: articleTags,
TargetUser: int(item.TargetUser),
Source: item.Source,
Operator: types.Operator{
Id: item.Operator.Id,
Name: item.Operator.Name,
},
})
})
return
... ...
package article
import (
"context"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/db/transaction"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/gateway/authlib"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/contextdata"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/xerr"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types"
"github.com/zeromicro/go-zero/core/logx"
)
type SystemUpdateArticleDraftLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
conn transaction.Conn
}
func NewSystemUpdateArticleDraftLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SystemUpdateArticleDraftLogic {
return &SystemUpdateArticleDraftLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
conn: svcCtx.DefaultDBConn(),
}
}
func (l *SystemUpdateArticleDraftLogic) SystemUpdateArticleDraft(req *types.SystemArticleDraftUpdateRequest) (resp *types.SystemArticleDraftUpdateResponse, err error) {
// 草稿数据
articleDraft, err := l.svcCtx.ArticleDraftOperationRepository.FindOne(l.ctx, l.conn, req.Id)
if err != nil {
return nil, xerr.NewErrMsgErr("草稿不存在", err)
}
articleDraft.Title = req.Title
articleDraft.Content = req.Content
articleDraft.AuthorId = req.AuthorId
articleDraft.TargetUser = domain.ArticleTarget(req.TargetUser)
articleDraft.WhoRead = req.WhoRead
articleDraft.WhoReview = req.WhoReview
articleDraft.Tags = req.Tags
articleDraft.Source = domain.ArticleSourceOperator
articleDraft.MatchUrl = req.MatchUrl
//图片
images, err := getImages(req.Images)
if err != nil {
return nil, xerr.NewErrMsg(err.Error())
}
articleDraft.Images = images
//视频
videos, err := getVideos(req.Videos)
if err != nil {
return nil, xerr.NewErrMsg(err.Error())
}
articleDraft.Videos = videos
//操作人
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)
}
articleDraft.Operator = domain.Operator{
Id: userToken.UserId,
Name: userMe.User.NickName,
}
err = transaction.UseTrans(l.ctx, l.conn.DB(), func(ctx context.Context, conn transaction.Conn) error {
_, err := l.svcCtx.ArticleDraftOperationRepository.Update(ctx, conn, articleDraft)
if err != nil {
return err
}
return nil
}, true)
if err != nil {
return nil, xerr.NewErrMsg("保存草稿失败")
}
resp = &types.SystemArticleDraftUpdateResponse{
Id: articleDraft.Id,
Title: articleDraft.Title,
Content: articleDraft.Content,
AuthorId: articleDraft.AuthorId,
Images: req.Images,
Videos: req.Videos,
TargetUser: int(articleDraft.TargetUser),
WhoRead: articleDraft.WhoRead,
WhoReview: articleDraft.WhoReview,
MatchUrl: articleDraft.MatchUrl,
Tags: articleDraft.Tags,
}
return
}
... ...
... ... @@ -91,6 +91,10 @@ func (l *MiniCompanySearchJoinedLogic) MiniCompanySearchJoined(req *types.Compan
if lo.Contains(companyJoiningList, company.Id) {
company.JoinedFlag = 0
}
// 过滤掉不可见且未加入的企业。
if company.JoinedFlag != 1 && item.Visible == 0 {
return
}
resp.List = append(resp.List, company)
})
resp.Total = total
... ...
... ... @@ -38,6 +38,7 @@ func (l *MiniCompanySearchLogic) MiniCompanySearch(req *types.CompanySearchReque
if req.Code != "" {
queryOptions.WithKV("code", req.Code)
}
queryOptions.MustWithKV("visible", 1)
total, companyList, err = l.svcCtx.CompanyRepository.Find(l.ctx, conn, queryOptions)
if err != nil {
return nil, xerr.NewErrMsgErr("公司列表获取失败", err)
... ...
package company
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/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 SystemCompanyVisibleSwitchLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewSystemCompanyVisibleSwitchLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SystemCompanyVisibleSwitchLogic {
return &SystemCompanyVisibleSwitchLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *SystemCompanyVisibleSwitchLogic) SystemCompanyVisibleSwitch(req *types.CompanyVisibleSwitchRequest) (resp *types.CompanyVisibleSwitchResponse, err error) {
var (
conn = l.svcCtx.DefaultDBConn()
company *domain.Company
userToken = contextdata.GetUserTokenFromCtx(l.ctx)
)
if company, err = l.svcCtx.CompanyRepository.FindOne(l.ctx, conn, userToken.CompanyId); err != nil {
return nil, xerr.NewErrMsg("设置失败")
}
company.Visible = lo.Ternary(req.Visible, 1, 0)
if company, err = l.svcCtx.CompanyRepository.UpdateWithVersion(l.ctx, conn, company); err != nil {
return nil, xerr.NewErrMsg("设置失败")
}
resp = &types.CompanyVisibleSwitchResponse{}
return
}
... ...
package tags
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 ArticleCategoryDeleteLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewArticleCategoryDeleteLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ArticleCategoryDeleteLogic {
return &ArticleCategoryDeleteLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *ArticleCategoryDeleteLogic) ArticleCategoryDelete(req *types.ArticleCategoryDeleteRequest) (resp *types.ArticleCategoryDeleteResponse, err error) {
// todo: add your logic here and delete this line
return
}
... ...
package tags
import (
"context"
"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"
"github.com/zeromicro/go-zero/core/logx"
)
type ArticleCategoryGetLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewArticleCategoryGetLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ArticleCategoryGetLogic {
return &ArticleCategoryGetLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *ArticleCategoryGetLogic) ArticleCategoryGet(req *types.ArticleCategoryGetRequest) (resp *types.ArticleCategoryGetResponse, err error) {
var (
conn = l.svcCtx.DefaultDBConn()
dm *domain.ArticleCategory
)
if dm, err = l.svcCtx.ArticleCategoryRepository.FindOne(l.ctx, conn, req.Id); err != nil {
return nil, xerr.NewErrMsgErr("不存在", err)
}
resp = &types.ArticleCategoryGetResponse{
ArticleCategory: NewTypesArticleCategory(dm),
}
return
}
... ...
package tags
import (
"context"
"fmt"
"github.com/zeromicro/go-zero/core/logx"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc"
"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"
)
type ArticleCategoryInitLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewArticleCategoryInitLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ArticleCategoryInitLogic {
return &ArticleCategoryInitLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *ArticleCategoryInitLogic) ArticleCategoryInit() error {
var (
conn = l.svcCtx.DefaultDBConn()
companyList []*domain.Company
categoryList = []*domain.ArticleCategory{
{
Name: "机会风险",
SortBy: 1,
Enable: 1,
Other: "",
},
{
Name: "紧急重要",
SortBy: 2,
Enable: 2,
Other: "",
},
}
dm *domain.ArticleCategory
err error
)
_, companyList, _ = l.svcCtx.CompanyRepository.Find(l.ctx, conn, domain.NewQueryOptions())
for _, company := range companyList {
for _, category := range categoryList {
if dm, err = l.svcCtx.ArticleCategoryRepository.FindOneByName(l.ctx, conn, company.Id, category.Name); err == nil && dm != nil {
continue
}
if err = transaction.UseTrans(l.ctx, l.svcCtx.DB, func(ctx context.Context, conn transaction.Conn) error {
articleCategory := &domain.ArticleCategory{
Name: category.Name,
SortBy: category.SortBy,
Enable: category.Enable,
Other: category.Other,
CompanyId: company.Id,
}
articleCategory, err = l.svcCtx.ArticleCategoryRepository.Insert(l.ctx, conn, articleCategory)
if err != nil {
return err
}
_, tagList, _ := l.svcCtx.ArticleTagRepository.Find(l.ctx, conn, company.Id, domain.NewQueryOptions().WithKV("category", articleCategory.Name))
for _, tag := range tagList {
if tag.CategoryId != 0 {
continue
}
tag.CategoryId = articleCategory.Id
if _, err = l.svcCtx.ArticleTagRepository.UpdateWithVersion(l.ctx, conn, tag); err != nil {
break
}
}
logx.Info(fmt.Sprintf("初始化 公司:%v(%d) 标签分类:%v(%d) 标签数:%v", company.Name, company.Id, articleCategory.Name, articleCategory.Id, len(tagList)))
return err
}, true); err != nil {
return xerr.NewErrMsg("保存失败")
}
}
}
return nil
}
... ...
package tags
import (
"context"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/contextdata"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/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 ArticleCategoryOptionsLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewArticleCategoryOptionsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ArticleCategoryOptionsLogic {
return &ArticleCategoryOptionsLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *ArticleCategoryOptionsLogic) ArticleCategoryOptions(req *types.CategoryOptionsRequest) (resp *types.CategoryOptionsResponse, err error) {
var (
conn = l.svcCtx.DefaultDBConn()
dms []*domain.ArticleCategory
userToken = contextdata.GetUserTokenFromCtx(l.ctx)
)
queryOptions := domain.NewQueryOptions().WithKV("enable", 1)
_, dms, err = l.svcCtx.ArticleCategoryRepository.Find(l.ctx, conn, userToken.CompanyId, queryOptions)
list := make([]types.CategoryOptions, 0)
for _, item := range dms {
list = append(list, types.CategoryOptions{
Label: item.Name,
Value: item.Id,
})
}
resp = &types.CategoryOptionsResponse{
Options: list,
}
return
}
... ...
package tags
import (
"context"
"fmt"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/db/transaction"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/contextdata"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/xerr"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types"
"github.com/zeromicro/go-zero/core/logx"
)
type ArticleCategorySaveLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewArticleCategorySaveLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ArticleCategorySaveLogic {
return &ArticleCategorySaveLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *ArticleCategorySaveLogic) ArticleCategorySave(req *types.ArticleCategorySaveRequest) (resp *types.ArticleCategorySaveResponse, err error) {
var (
conn = l.svcCtx.DefaultDBConn()
dm *domain.ArticleCategory
userToken = contextdata.GetUserTokenFromCtx(l.ctx)
)
// 唯一判断
if dm, err = l.svcCtx.ArticleCategoryRepository.FindOneByName(l.ctx, conn, userToken.CompanyId, req.ArticleCategory.Name); err == nil && dm != nil {
return nil, xerr.NewErrMsg(fmt.Sprintf("已存在分类`%s`", dm.Name))
}
dm = NewDomainArticleCategory(req.ArticleCategory)
dm.CompanyId = userToken.CompanyId
if err = transaction.UseTrans(l.ctx, l.svcCtx.DB, func(ctx context.Context, conn transaction.Conn) error {
dm, err = l.svcCtx.ArticleCategoryRepository.Insert(l.ctx, conn, dm)
return err
}, true); err != nil {
return nil, xerr.NewErrMsg("保存失败")
}
resp = &types.ArticleCategorySaveResponse{}
return
}
func NewDomainArticleCategory(item types.ArticleCategoryItem) *domain.ArticleCategory {
return &domain.ArticleCategory{
Name: item.Name,
Enable: item.Enable,
SortBy: item.SortBy,
Other: item.Other,
}
}
func NewTypesArticleCategory(item *domain.ArticleCategory) types.ArticleCategoryItem {
return types.ArticleCategoryItem{
Id: item.Id,
Name: item.Name,
Enable: item.Enable,
SortBy: item.SortBy,
Other: item.Other,
}
}
... ...
package tags
import (
"context"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/contextdata"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/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 ArticleCategorySearchLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewArticleCategorySearchLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ArticleCategorySearchLogic {
return &ArticleCategorySearchLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *ArticleCategorySearchLogic) ArticleCategorySearch(req *types.ArticleCategorySearchRequest) (resp *types.ArticleCategorySearchResponse, err error) {
var (
conn = l.svcCtx.DefaultDBConn()
dms []*domain.ArticleCategory
total int64
userToken = contextdata.GetUserTokenFromCtx(l.ctx)
)
queryOptions := domain.NewQueryOptions().WithOffsetLimit(req.Page, req.Size)
total, dms, err = l.svcCtx.ArticleCategoryRepository.Find(l.ctx, conn, userToken.CompanyId, queryOptions)
list := make([]types.ArticleCategoryItem, 0)
for _, item := range dms {
list = append(list, NewTypesArticleCategory(item))
}
resp = &types.ArticleCategorySearchResponse{
List: list,
Total: total,
}
return
}
... ...
package tags
import (
"context"
"fmt"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/db/transaction"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/contextdata"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/xerr"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types"
"github.com/zeromicro/go-zero/core/logx"
)
type ArticleCategoryUpdateLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewArticleCategoryUpdateLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ArticleCategoryUpdateLogic {
return &ArticleCategoryUpdateLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *ArticleCategoryUpdateLogic) ArticleCategoryUpdate(req *types.ArticleCategoryUpdateRequest) (resp *types.ArticleCategoryUpdateResponse, err error) {
var (
conn = l.svcCtx.DefaultDBConn()
dm *domain.ArticleCategory
userToken = contextdata.GetUserTokenFromCtx(l.ctx)
)
if dm, err = l.svcCtx.ArticleCategoryRepository.FindOne(l.ctx, conn, req.Id); err != nil {
return nil, xerr.NewErrMsgErr("不存在", err)
}
// 不可编辑判断
if dm.Name != req.ArticleCategory.Name {
if dm, err = l.svcCtx.ArticleCategoryRepository.FindOneByName(l.ctx, conn, userToken.CompanyId, req.ArticleCategory.Name); err == nil && dm != nil {
return nil, xerr.NewErrMsg(fmt.Sprintf("已存在分类`%s`", dm.Name))
}
}
// 赋值
dm.Name = req.ArticleCategory.Name
dm.SortBy = req.ArticleCategory.SortBy
dm.Enable = req.ArticleCategory.Enable
dm.Other = req.ArticleCategory.Other
// 更新
if err = transaction.UseTrans(l.ctx, l.svcCtx.DB, func(ctx context.Context, conn transaction.Conn) error {
dm, err = l.svcCtx.ArticleCategoryRepository.UpdateWithVersion(l.ctx, conn, dm)
return err
}, true); err != nil {
return nil, xerr.NewErrMsg("更新失败")
}
resp = &types.ArticleCategoryUpdateResponse{}
return
}
... ...
... ... @@ -30,38 +30,46 @@ func NewCreateTagLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CreateT
// 创建标签
func (l *CreateTagLogic) CreateTag(req *types.TagCreateRequest) (resp *types.TagCreateResponse, err error) {
var conn = l.svcCtx.DefaultDBConn()
var (
conn = l.svcCtx.DefaultDBConn()
articleCategory *domain.ArticleCategory
)
if articleCategory, err = l.svcCtx.ArticleCategoryRepository.FindOne(l.ctx, conn, req.CategoryId); err != nil {
return nil, xerr.NewErrMsgErr("添加标签失败", err)
}
//检查重复
cnt, _, err := l.svcCtx.ArticleTagRepository.Find(l.ctx, conn, req.CompanyId, map[string]interface{}{
"name": req.Name,
"category": req.Category,
"countOnly": true,
"name": req.Name,
"categoryId": req.CategoryId,
"countOnly": true,
})
if err != nil {
return nil, xerr.NewErrMsgErr("添加标签失败", err)
}
if cnt > 0 {
return nil, xerr.NewErrMsg(fmt.Sprintf("已存在标签 分类[%s]名称[%s]", req.Category, req.Name))
return nil, xerr.NewErrMsg(fmt.Sprintf("已存在标签 分类[%s]名称[%s]", articleCategory.Name, req.Name))
}
newTag := &domain.ArticleTag{
Id: 0,
CompanyId: req.CompanyId,
CreatedAt: 0,
UpdatedAt: 0,
DeletedAt: 0,
Version: 0,
Image: domain.Image{},
Name: req.Name,
Category: req.Category,
Remark: req.Remark,
Other: req.Other,
SortBy: int64(req.SortBy),
}
err = newTag.SetCategory(req.Category)
if err != nil {
return nil, xerr.NewErrMsgErr("添加标签失败", err)
Id: 0,
CompanyId: req.CompanyId,
CreatedAt: 0,
UpdatedAt: 0,
DeletedAt: 0,
Version: 0,
Image: domain.Image{},
Name: req.Name,
Category: articleCategory.Name,
CategoryId: articleCategory.Id,
Remark: req.Remark,
Other: req.Other,
SortBy: int64(req.SortBy),
DataFrom: 1,
}
//err = newTag.SetCategory(req.Category)
//if err != nil {
// return nil, xerr.NewErrMsgErr("添加标签失败", err)
//}
if len(req.Image) > 0 {
//获取图片的尺寸大小
fInfo, _ := oss.GetImageInfo(req.Image)
... ...
... ... @@ -33,6 +33,9 @@ func (l *DeleteTagLogic) DeleteTag(req *types.TagDeleteRequest) (resp *types.Tag
if oldTag.CompanyId != req.CompanyId {
return nil, xerr.NewErrMsg("删除标签失败")
}
if oldTag.DataFrom == 0 {
return nil, xerr.NewErrMsg("系统标签不可删除")
}
_, err = l.svcCtx.ArticleTagRepository.Delete(l.ctx, conn, oldTag)
if err != nil {
return nil, xerr.NewErrMsg("删除标签失败")
... ...
... ... @@ -30,21 +30,26 @@ func NewEditTagLogic(ctx context.Context, svcCtx *svc.ServiceContext) *EditTagLo
// 编辑标签
func (l *EditTagLogic) EditTag(req *types.TagEditRequest) (resp *types.TagEditResponse, err error) {
var conn = l.svcCtx.DefaultDBConn()
var (
conn = l.svcCtx.DefaultDBConn()
articleCategory *domain.ArticleCategory
)
//检查重复
queryOptions := domain.NewQueryOptions().
WithFindOnly().
MustWithKV("name", req.Name).
MustWithKV("category", req.Category).
MustWithKV("categoryId", req.CategoryId).
WithOffsetLimit(1, 1)
if articleCategory, err = l.svcCtx.ArticleCategoryRepository.FindOne(l.ctx, conn, req.CategoryId); err != nil {
return nil, xerr.NewErrMsgErr("标签分类不存在失败", err)
}
_, tagList, err := l.svcCtx.ArticleTagRepository.Find(l.ctx, conn, req.CompanyId, queryOptions)
if err != nil {
return nil, xerr.NewErrMsgErr("修改标签失败", err)
}
if len(tagList) > 0 {
if tagList[0].Id != req.Id {
return nil, xerr.NewErrMsg(fmt.Sprintf("已存在标签 分类[%s]名称[%s]", req.Category, req.Name))
return nil, xerr.NewErrMsg(fmt.Sprintf("已存在标签 分类[%s]名称[%s]", articleCategory.Name, req.Name))
}
}
oldTag, err := l.svcCtx.ArticleTagRepository.FindOne(l.ctx, conn, req.Id)
... ... @@ -66,15 +71,16 @@ func (l *EditTagLogic) EditTag(req *types.TagEditRequest) (resp *types.TagEditRe
Height: h,
}
}
oldTag.Category = req.Category
oldTag.Name = req.Name
oldTag.Remark = req.Remark
oldTag.Other = req.Other
oldTag.SortBy = int64(req.SortBy)
err = oldTag.SetCategory(req.Category)
if err != nil {
return nil, xerr.NewErrMsgErr("添加标签失败", err)
}
oldTag.CategoryId = articleCategory.Id
oldTag.Category = articleCategory.Name
//err = oldTag.SetCategory(req.Category)
//if err != nil {
// return nil, xerr.NewErrMsgErr("添加标签失败", err)
//}
oldTag, err = l.svcCtx.ArticleTagRepository.Update(l.ctx, conn, oldTag)
if err != nil {
return nil, xerr.NewErrMsgErr("添加标签失败", err)
... ...
... ... @@ -35,13 +35,14 @@ func (l *GetTagLogic) GetTag(req *types.TagGetRequest) (resp *types.TagGetRespon
return nil, xerr.NewErrMsg("获取标签失败")
}
resp = &types.TagGetResponse{
Id: oldTag.Id,
Image: oldTag.Image.Url,
Name: oldTag.Name,
Category: oldTag.Category,
Remark: oldTag.Remark,
Other: oldTag.Other,
SortBy: int(oldTag.SortBy),
Id: oldTag.Id,
Image: oldTag.Image.Url,
Name: oldTag.Name,
Category: oldTag.Category,
CategoryId: oldTag.CategoryId,
Remark: oldTag.Remark,
Other: oldTag.Other,
SortBy: int(oldTag.SortBy),
}
return
}
... ...
... ... @@ -24,11 +24,14 @@ func NewSearchTagLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SearchT
}
func (l *SearchTagLogic) SearchTag(req *types.TagListRequest) (resp *types.TagListResponse, err error) {
var conn = l.svcCtx.DefaultDBConn()
var (
conn = l.svcCtx.DefaultDBConn()
categoryMap = make(map[int64]*domain.ArticleCategory)
)
queryOptions := domain.NewQueryOptions().WithOffsetLimit(req.Page, req.Size)
if len(req.Category) > 0 {
queryOptions = queryOptions.MustWithKV("category", "%"+req.Category+"%")
if req.CategoryId > 0 {
queryOptions = queryOptions.MustWithKV("categoryId", req.CategoryId)
}
if len(req.TagName) > 0 {
queryOptions = queryOptions.MustWithKV("name", "%"+req.TagName+"%")
... ... @@ -47,13 +50,18 @@ func (l *SearchTagLogic) SearchTag(req *types.TagListRequest) (resp *types.TagLi
}
for i := range tagList {
resp.List[i] = types.TagItem{
Id: tagList[i].Id,
Image: tagList[i].Image.Url,
Name: tagList[i].Name,
Category: tagList[i].Category,
Remark: tagList[i].Remark,
CreatedAt: tagList[i].CreatedAt,
SortBy: int(tagList[i].SortBy),
Id: tagList[i].Id,
Image: tagList[i].Image.Url,
Name: tagList[i].Name,
Category: tagList[i].Category,
CategoryId: tagList[i].CategoryId,
Remark: tagList[i].Remark,
CreatedAt: tagList[i].CreatedAt,
SortBy: int(tagList[i].SortBy),
Removeable: tagList[i].DataFrom != 0,
}
if category, _ := domain.LazyLoad(categoryMap, l.ctx, conn, tagList[i].CategoryId, l.svcCtx.ArticleCategoryRepository.FindOne); category != nil {
resp.List[i].Category = category.Name
}
}
return resp, nil
... ...
... ... @@ -3,6 +3,7 @@ package user
import (
"context"
"fmt"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/db/transaction"
"strconv"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc"
... ... @@ -109,70 +110,108 @@ func (l *SystemUserInfoLogic) initSystemData(companyId int64) error {
// 初始设置文章标签
queryOption := domain.NewQueryOptions().WithCountOnly()
conn := l.svcCtx.DefaultDBConn()
cnt, _, err := l.svcCtx.ArticleTagRepository.Find(l.ctx, conn, companyId, queryOption)
if err != nil {
return xerr.NewErrMsgErr("初始话公司数据失败", err)
categoryList := []*domain.ArticleCategory{
{
Name: "机会风险",
SortBy: 1,
Enable: 1,
Other: "",
CompanyId: companyId,
},
{
Name: "紧急重要",
SortBy: 2,
Enable: 1,
Other: "",
CompanyId: companyId,
},
}
articleTags := []*domain.ArticleTag{
{
Id: 0, CompanyId: companyId, Image: domain.Image{Url: "https://timeless-world.oss-cn-shenzhen.aliyuncs.com/open-api/test/20231115/object/index_imp_01.png", Width: 0, Height: 0},
Name: "紧急重要", Category: "紧急重要", Remark: "优先解决", SortBy: 1,
},
{
Id: 0, CompanyId: companyId, Image: domain.Image{Url: "https://timeless-world.oss-cn-shenzhen.aliyuncs.com/open-api/test/20231115/object/index_imp_04.png", Width: 0, Height: 0},
Name: "不紧急不重要", Category: "紧急重要", Remark: "给别人做", SortBy: 2,
},
{
Id: 0, CompanyId: companyId, Image: domain.Image{Url: "https://timeless-world.oss-cn-shenzhen.aliyuncs.com/open-api/test/20231115/object/index_imp_03.png", Width: 0, Height: 0},
Name: "紧急不重要", Category: "紧急重要", Remark: "有空再做", SortBy: 3,
},
{
Id: 0, CompanyId: companyId, Image: domain.Image{Url: "https://timeless-world.oss-cn-shenzhen.aliyuncs.com/open-api/test/20231115/object/index_imp_02.png", Width: 0, Height: 0},
Name: "不紧急重要", Category: "紧急重要", Remark: "制定计划去做", SortBy: 4,
},
{
Id: 0, CompanyId: companyId, Image: domain.Image{Url: "https://timeless-world.oss-cn-shenzhen.aliyuncs.com/open-api/test/20231115/object/index_chance_03.png", Width: 0, Height: 0},
Name: "大机会高风险", Category: "机会风险", Remark: "谨慎考虑专项讨论", SortBy: 5,
},
{
Id: 0, CompanyId: companyId, Image: domain.Image{Url: "https://timeless-world.oss-cn-shenzhen.aliyuncs.com/open-api/test/20231115/object/index_chance_02.png", Width: 0, Height: 0},
Name: "大机会中风险", Category: "机会风险", Remark: "加大关注值得尝试", SortBy: 6,
},
{
Id: 0, CompanyId: companyId, Image: domain.Image{Url: "https://timeless-world.oss-cn-shenzhen.aliyuncs.com/open-api/test/20231115/object/index_chance_01.png", Width: 0, Height: 0},
Name: "大机会低风险", Category: "机会风险", Remark: "全员投入抓紧落实", SortBy: 7,
},
{
Id: 0, CompanyId: companyId, Image: domain.Image{Url: "https://timeless-world.oss-cn-shenzhen.aliyuncs.com/open-api/test/20231115/object/index_chance_04.png", Width: 0, Height: 0},
Name: "中机会高风险", Category: "机会风险", Remark: "专人跟踪成立项目", SortBy: 8,
},
{
Id: 0, CompanyId: companyId, Image: domain.Image{Url: "https://timeless-world.oss-cn-shenzhen.aliyuncs.com/open-api/test/20231115/object/index_chance_05.png", Width: 0, Height: 0},
Name: "中机会中风险", Category: "机会风险", Remark: "讨论落实", SortBy: 9,
},
{
Id: 0, CompanyId: companyId, Image: domain.Image{Url: "https://timeless-world.oss-cn-shenzhen.aliyuncs.com/open-api/test/20231115/object/index_chance_06.png", Width: 0, Height: 0},
Name: "中机会低风险", Category: "机会风险", Remark: "解决问题多手准备", SortBy: 10,
},
{
Id: 0, CompanyId: companyId, Image: domain.Image{Url: "https://timeless-world.oss-cn-shenzhen.aliyuncs.com/open-api/test/20231115/object/index_chance_07.png", Width: 0, Height: 0},
Name: "小机会高风险", Category: "机会风险", Remark: "有空看看", SortBy: 11,
},
{
Id: 0, CompanyId: companyId, Image: domain.Image{Url: "https://timeless-world.oss-cn-shenzhen.aliyuncs.com/open-api/test/20231115/object/index_chance_08.png", Width: 0, Height: 0},
Name: "小机会中风险", Category: "机会风险", Remark: "持续监控做好控制", SortBy: 12,
},
{
Id: 0, CompanyId: companyId, Image: domain.Image{Url: "https://timeless-world.oss-cn-shenzhen.aliyuncs.com/open-api/test/20231115/object/index_chance_09.png", Width: 0, Height: 0},
Name: "小机会低风险", Category: "机会风险", Remark: "全员警戒马上解决", SortBy: 13,
},
}
cnt, _, err := l.svcCtx.ArticleCategoryRepository.Find(l.ctx, conn, companyId, queryOption)
if cnt == 0 {
articleTags := []*domain.ArticleTag{
{
Id: 0, CompanyId: companyId, Image: domain.Image{Url: "https://timeless-world.oss-cn-shenzhen.aliyuncs.com/open-api/test/20231115/object/index_imp_01.png", Width: 0, Height: 0},
Name: "紧急重要", Category: "紧急重要", Remark: "优先解决", SortBy: 1,
},
{
Id: 0, CompanyId: companyId, Image: domain.Image{Url: "https://timeless-world.oss-cn-shenzhen.aliyuncs.com/open-api/test/20231115/object/index_imp_04.png", Width: 0, Height: 0},
Name: "不紧急不重要", Category: "紧急重要", Remark: "给别人做", SortBy: 2,
},
{
Id: 0, CompanyId: companyId, Image: domain.Image{Url: "https://timeless-world.oss-cn-shenzhen.aliyuncs.com/open-api/test/20231115/object/index_imp_03.png", Width: 0, Height: 0},
Name: "紧急不重要", Category: "紧急重要", Remark: "有空再做", SortBy: 3,
},
{
Id: 0, CompanyId: companyId, Image: domain.Image{Url: "https://timeless-world.oss-cn-shenzhen.aliyuncs.com/open-api/test/20231115/object/index_imp_02.png", Width: 0, Height: 0},
Name: "不紧急重要", Category: "紧急重要", Remark: "制定计划去做", SortBy: 4,
},
{
Id: 0, CompanyId: companyId, Image: domain.Image{Url: "https://timeless-world.oss-cn-shenzhen.aliyuncs.com/open-api/test/20231115/object/index_chance_03.png", Width: 0, Height: 0},
Name: "大机会高风险", Category: "机会风险", Remark: "谨慎考虑专项讨论", SortBy: 5,
},
{
Id: 0, CompanyId: companyId, Image: domain.Image{Url: "https://timeless-world.oss-cn-shenzhen.aliyuncs.com/open-api/test/20231115/object/index_chance_02.png", Width: 0, Height: 0},
Name: "大机会中风险", Category: "机会风险", Remark: "加大关注值得尝试", SortBy: 6,
},
{
Id: 0, CompanyId: companyId, Image: domain.Image{Url: "https://timeless-world.oss-cn-shenzhen.aliyuncs.com/open-api/test/20231115/object/index_chance_01.png", Width: 0, Height: 0},
Name: "大机会低风险", Category: "机会风险", Remark: "全员投入抓紧落实", SortBy: 7,
},
{
Id: 0, CompanyId: companyId, Image: domain.Image{Url: "https://timeless-world.oss-cn-shenzhen.aliyuncs.com/open-api/test/20231115/object/index_chance_04.png", Width: 0, Height: 0},
Name: "中机会高风险", Category: "机会风险", Remark: "专人跟踪成立项目", SortBy: 8,
},
{
Id: 0, CompanyId: companyId, Image: domain.Image{Url: "https://timeless-world.oss-cn-shenzhen.aliyuncs.com/open-api/test/20231115/object/index_chance_05.png", Width: 0, Height: 0},
Name: "中机会中风险", Category: "机会风险", Remark: "讨论落实", SortBy: 9,
},
{
Id: 0, CompanyId: companyId, Image: domain.Image{Url: "https://timeless-world.oss-cn-shenzhen.aliyuncs.com/open-api/test/20231115/object/index_chance_06.png", Width: 0, Height: 0},
Name: "中机会低风险", Category: "机会风险", Remark: "解决问题多手准备", SortBy: 10,
},
{
Id: 0, CompanyId: companyId, Image: domain.Image{Url: "https://timeless-world.oss-cn-shenzhen.aliyuncs.com/open-api/test/20231115/object/index_chance_07.png", Width: 0, Height: 0},
Name: "小机会高风险", Category: "机会风险", Remark: "有空看看", SortBy: 11,
},
{
Id: 0, CompanyId: companyId, Image: domain.Image{Url: "https://timeless-world.oss-cn-shenzhen.aliyuncs.com/open-api/test/20231115/object/index_chance_08.png", Width: 0, Height: 0},
Name: "小机会中风险", Category: "机会风险", Remark: "持续监控做好控制", SortBy: 12,
},
{
Id: 0, CompanyId: companyId, Image: domain.Image{Url: "https://timeless-world.oss-cn-shenzhen.aliyuncs.com/open-api/test/20231115/object/index_chance_09.png", Width: 0, Height: 0},
Name: "小机会低风险", Category: "机会风险", Remark: "全员警戒马上解决", SortBy: 13,
},
}
err = l.svcCtx.ArticleTagRepository.CreateInBatches(l.ctx, conn, articleTags)
if err != nil {
if err = transaction.UseTrans(l.ctx, l.svcCtx.DB, func(ctx context.Context, conn transaction.Conn) error {
for _, category := range categoryList {
category, err = l.svcCtx.ArticleCategoryRepository.Insert(l.ctx, conn, category)
if err != nil {
return err
}
}
cnt, _, err = l.svcCtx.ArticleTagRepository.Find(l.ctx, conn, companyId, queryOption)
if err != nil {
return xerr.NewErrMsgErr("初始话公司数据失败", err)
}
for _, tag := range articleTags {
for _, category := range categoryList {
if category.Name == tag.Category {
tag.CategoryId = category.Id
}
}
}
if cnt == 0 {
err = l.svcCtx.ArticleTagRepository.CreateInBatches(l.ctx, conn, articleTags)
if err != nil {
return xerr.NewErrMsgErr("初始话公司数据失败", err)
}
}
return nil
}, true); err != nil {
return xerr.NewErrMsgErr("初始话公司数据失败", err)
}
}
return nil
}
... ...
... ... @@ -27,13 +27,15 @@ type ServiceContext struct {
DB *gorm.DB
Redis *redis.Redis
ArticleBackupRepository domain.ArticleBackupRepository
ArticleCommentRepository domain.ArticleCommentRepository
ArticleDraftRepository domain.ArticleDraftRepository
ArticleRepository domain.ArticleRepository
ArticleSectionRepository domain.ArticleSectionRepository
ArticleTagRepository domain.ArticleTagRepository
ArticleAndTagRepository domain.ArticleAndTagRepository
ArticleBackupRepository domain.ArticleBackupRepository
ArticleCommentRepository domain.ArticleCommentRepository
ArticleDraftRepository domain.ArticleDraftRepository
ArticleRepository domain.ArticleRepository
ArticleSectionRepository domain.ArticleSectionRepository
ArticleTagRepository domain.ArticleTagRepository
ArticleCategoryRepository domain.ArticleCategoryRepository
ArticleAndTagRepository domain.ArticleAndTagRepository
ArticleDraftOperationRepository domain.ArticleDraftOperationRepository
CompanyRepository domain.CompanyRepository
DepartmentRepository domain.DepartmentRepository
... ...
... ... @@ -348,13 +348,13 @@ type SimpleArticle struct {
}
type TagCreateRequest struct {
CompanyId int64 `json:",optional"`
Image string `json:"image"`
Name string `json:"name"` // 标签名称
Category string `json:"category"` // 标签分类
Remark string `json:"remark,optional"` // 备注
Other string `json:"other,optional"`
SortBy int `json:"sortBy,optional"` //排序
CompanyId int64 `json:",optional"`
Image string `json:"image"`
Name string `json:"name"` // 标签名称
Remark string `json:"remark,optional"` // 备注
Other string `json:"other,optional"`
SortBy int `json:"sortBy,optional"` //排序
CategoryId int64 `json:"categoryId"` // 标签Id
}
type TagCreateResponse struct {
... ... @@ -362,14 +362,14 @@ type TagCreateResponse struct {
}
type TagEditRequest struct {
Id int64 `json:"id"`
CompanyId int64 `json:",optional"`
Image string `json:"image"`
Name string `json:"name"` // 标签名称
Category string `json:"category"` // 标签分类
Remark string `json:"remark,optional"` // 备注
Other string `json:"other,optional"`
SortBy int `json:"sortBy,optional"` // 排序
Id int64 `json:"id"`
CompanyId int64 `json:",optional"`
Image string `json:"image"`
Name string `json:"name"` // 标签名称
CategoryId int64 `json:"categoryId"` // 标签Id
Remark string `json:"remark,optional"` // 备注
Other string `json:"other,optional"`
SortBy int `json:"sortBy,optional"` // 排序
}
type TagEditResponse struct {
... ... @@ -382,22 +382,23 @@ type TagGetRequest struct {
}
type TagGetResponse struct {
Id int64 `json:"id"`
Image string `json:"image"`
Name string `json:"name"` // 标签名称
Category string `json:"category"` // 标签分类
Remark string `json:"remark"` // 备注
Other string `json:"other"`
SortBy int `json:"sortBy,optional"` // 排序
Id int64 `json:"id"`
Image string `json:"image"`
Name string `json:"name"` // 标签名称
Category string `json:"category"` // 标签分类
CategoryId int64 `json:"categoryId"` // 标签分类Id
Remark string `json:"remark"` // 备注
Other string `json:"other"`
SortBy int `json:"sortBy,optional"` // 排序
}
type TagListRequest struct {
Page int `json:"page"`
Size int `json:"size"`
CompanyId int64 `json:",optional"`
TagName string `json:"tagName,optional"`
Category string `json:"category,optional"`
Remark string `json:"remark,optional"`
Page int `json:"page"`
Size int `json:"size"`
CompanyId int64 `json:",optional"`
TagName string `json:"tagName,optional"`
CategoryId int64 `json:"categoryId,optional"`
Remark string `json:"remark,optional"`
}
type TagListResponse struct {
... ... @@ -406,13 +407,15 @@ type TagListResponse struct {
}
type TagItem struct {
Id int64 `json:"id"`
Image string `json:"image"`
Name string `json:"name"` // 标签名称
Category string `json:"category"` // 标签分类
Remark string `json:"remark"` // 备注
CreatedAt int64 `json:"createdAt"`
SortBy int `json:"sortBy,optional"` // 排序
Id int64 `json:"id"`
Image string `json:"image"`
Name string `json:"name"` // 标签名称
Category string `json:"category"` // 标签分类
CategoryId int64 `json:"categoryId"` // 标签分类Id
Remark string `json:"remark"` // 备注
CreatedAt int64 `json:"createdAt"`
SortBy int `json:"sortBy,optional"` // 排序
Removeable bool `json:"removeable,optional"` // 可删除
}
type TagDeleteRequest struct {
... ... @@ -433,7 +436,8 @@ type TagOptionsResponse struct {
}
type TagOptions struct {
Label string `json:"label"` // 分组名称
Value int64 `json:"value"` // 分类ID
Label string `json:"label"` // 分类名称
Options []TagOptionValue `json:"options"`
}
... ... @@ -862,6 +866,13 @@ type Company struct {
JoinedFlag int `json:"joinedFlag"` // 已加入标识(1:已加入 其他:未加入)
}
type CompanyVisibleSwitchRequest struct {
Visible bool `json:"visible"` // 可见性 true:可被搜索 false:不可被搜索
}
type CompanyVisibleSwitchResponse struct {
}
type CompanyPositionsSearchRequest struct {
}
... ... @@ -895,6 +906,11 @@ type ArticleAuthor struct {
Company string `json:"company"` // 公司
}
type Operator struct {
Id int64 `json:"id,string"` // 人员id
Name string `json:"name"` // 人员的名字
}
type MiniArticleCreateRequest struct {
Title string `json:"title"` //标题
Section []string `json:"section"` //文章的文本内容
... ... @@ -1263,11 +1279,14 @@ type SystemArticleSearch struct {
Author string `json:"author"` //发布人
Images []string `json:"images"` //图片
CreatedAt int64 `json:"createdAt"` //文章的创建日期
UpdatedAt int64 `json:"updatedAt"` //文章的编辑日期
CountLove int `json:"countLove"` //点赞数量
CountComment int `json:"countComment"` //评论数量
Show int `json:"show"` //是否隐藏 [0显示、1不显示]
Tags []string `json:"tags"` //标签
TargetUser int `json:"targetUser"` //分发方式 [0分发给所有人、1分发给指定的人]
Operator Operator `json:"operator"` //运营操作人
Source int `json:"source"` //来源[1用户发布、2运营发布]
}
type SystemArticleUpdateRequest struct {
... ... @@ -1299,6 +1318,43 @@ type SystemArticleUpdateResponse struct {
TargetUser int `json:"targetUser"` //分发方式 [0分发给所有人、1分发给指定的人]
}
type SystemArticleCreateRequest struct {
Title string `json:"title"` //标题
Content string `json:"content"` //文章的文本内容
AuthorId int64 `json:"authorId"` //发布人id
Images []string `json:"images,optional"` //图片
Videos []Video `json:"video,optional"` // 视频
TargetUser int `json:"targetUser"` // 分发方式 [0分发给所有人、1分发给指定的人]
WhoRead []int64 `json:"whoRead,optional"` //谁可查看
WhoReview []int64 `json:"whoReview,optional"` //谁可评论
MatchUrl map[string]string `json:"matchUrl,optional"` // 匹配文章内容中的url文本
ArticleDraftId int64 `json:"articleDraftId"` // 草稿ID
AccessToken string `header:"x-mmm-accesstoken"` // 授权token
}
type SystemArticleCreateResponse struct {
Id int64 `json:"id"` //id
Title string `json:"title"` //标题
Content string `json:"content"` //文章的文本内容
AuthorId int64 `json:"authorId,optional"` //发布人id
Images []string `json:"images,optional"` //图片
Videos []Video `json:"video,optional"` // 视频
TargetUser int `json:"targetUser"` // 分发方式 [0分发给所有人、1分发给指定的人]
WhoRead []int64 `json:"whoRead,optional"` //谁可查看
WhoReview []int64 `json:"whoReview,optional"` //谁可评论
MatchUrl map[string]string `json:"matchUrl"` // 匹配文章内容中的url文本
}
type SystemArticleDeleteRequest struct {
Id int64 `json:"id"` //id
}
type SystemArticleDeleteResponse struct {
Id int64 `json:"id"` //id
Title string `json:"title"` //标题
AuthorId int64 `json:"authorId,optional"` //发布人id
}
type SystemArticleHistoryRequest struct {
ArticleId int64 `json:"articleId"` //文章ID
Author string `json:"author,optional"` //发布人
... ... @@ -1401,6 +1457,161 @@ type MiniSearchArticleItem struct {
MeReadFlag int `json:"meReadFlag"` //已读标识 [0:未读] [1:已读]
}
type SystemArticleDraftCreateRequest struct {
Title string `json:"title"` //标题
Content string `json:"content"` //文章的文本内容
AuthorId int64 `json:"authorId"` //发布人id
Images []string `json:"images,optional"` //图片
Videos []Video `json:"video,optional"` // 视频
TargetUser int `json:"targetUser"` // 分发方式 [0分发给所有人、1分发给指定的人]
WhoRead []int64 `json:"whoRead,optional"` //谁可查看
WhoReview []int64 `json:"whoReview,optional"` //谁可评论
MatchUrl map[string]string `json:"matchUrl,optional"` // 匹配文章内容中的url文本
Tags []int64 `json:"tags"` // 标签
AccessToken string `header:"x-mmm-accesstoken"` // 授权token
}
type SystemArticleDraftCreateResponse struct {
Id int64 `json:"id"` //ID
Title string `json:"title"` //标题
Content string `json:"content"` //文章的文本内容
AuthorId int64 `json:"authorId"` //发布人id
Images []string `json:"images,optional"` //图片
Videos []Video `json:"video,optional"` // 视频
TargetUser int `json:"targetUser"` // 分发方式 [0分发给所有人、1分发给指定的人]
WhoRead []int64 `json:"whoRead,optional"` //谁可查看
WhoReview []int64 `json:"whoReview,optional"` //谁可评论
MatchUrl map[string]string `json:"matchUrl,optional"` // 匹配文章内容中的url文本
Tags []int64 `json:"tags"` // 标签
}
type SystemArticleDraftUpdateRequest struct {
Id int64 `json:"id"` // ID
Title string `json:"title"` //标题
Content string `json:"content"` //文章的文本内容
AuthorId int64 `json:"authorId"` //发布人id
Images []string `json:"images,optional"` //图片
Videos []Video `json:"video,optional"` // 视频
TargetUser int `json:"targetUser"` // 分发方式 [0分发给所有人、1分发给指定的人]
WhoRead []int64 `json:"whoRead,optional"` //谁可查看
WhoReview []int64 `json:"whoReview,optional"` //谁可评论
MatchUrl map[string]string `json:"matchUrl,optional"` // 匹配文章内容中的url文本
Tags []int64 `json:"tags"` // 标签
AccessToken string `header:"x-mmm-accesstoken"` // 授权token
}
type SystemArticleDraftUpdateResponse struct {
Id int64 `json:"id"` //ID
Title string `json:"title"` //标题
Content string `json:"content"` //文章的文本内容
AuthorId int64 `json:"authorId"` //发布人id
Images []string `json:"images,optional"` //图片
Videos []Video `json:"video,optional"` // 视频
TargetUser int `json:"targetUser"` // 分发方式 [0分发给所有人、1分发给指定的人]
WhoRead []int64 `json:"whoRead,optional"` //谁可查看
WhoReview []int64 `json:"whoReview,optional"` //谁可评论
MatchUrl map[string]string `json:"matchUrl,optional"` // 匹配文章内容中的url文本
Tags []int64 `json:"tags"` // 标签
}
type SystemArticleDraftSearchRequest struct {
Page int `json:"page"` //页码
Size int `json:"size"` //每页行数
CompanyId int64 `json:"companyId,optional"` //公司ID(前端不传)
Title string `json:"title,optional"` //标题
Operator string `json:"operator,optional"` //编辑人
BeginTime int64 `json:"beginTime,optional"` //开始时间
EndTime int64 `json:"endTime,optional"` //结束时间
}
type SystemArticleDraftSearchResponse struct {
Total int `json:"total"`
List []SystemArticleDraftSearch `json:"list"`
}
type SystemArticleDraftSearch struct {
Id int64 `json:"id"` //ID
Title string `json:"title"` //标题
Images []string `json:"images"` //图片
Operator string `json:"operator"` //操作人
AuthorId int64 `json:"authorId"` //发布人id
Author string `json:"author"` //发布人
UpdatedAt int64 `json:"updatedAt"` //编辑时间
}
type SystemArticleDraftDeleteRequest struct {
Id int64 `json:"id"` //ID
}
type SystemArticleDraftDeleteResponse struct {
Id int64 `json:"id"` //ID
Title string `json:"title"` //标题
Content string `json:"content"` //文章的文本内容
AuthorId int64 `json:"authorId"` //发布人id
Images []string `json:"images,optional"` //图片
Videos []Video `json:"video,optional"` // 视频
TargetUser int `json:"targetUser"` // 分发方式 [0分发给所有人、1分发给指定的人]
WhoRead []int64 `json:"whoRead,optional"` //谁可查看
WhoReview []int64 `json:"whoReview,optional"` //谁可评论
MatchUrl map[string]string `json:"matchUrl,optional"` // 匹配文章内容中的url文本
Tags []int64 `json:"tags"` // 标签
}
type SystemArticleDraftGetRequest struct {
Id int64 `path:"id"` //id
CompanyId int64 `path:",optional"` //公司ID(前端不传)
}
type SystemArticleDraftGetResponse struct {
Id int64 `json:"id"` //ID
Title string `json:"title"` //标题
Content string `json:"content"` //文章的文本内容
AuthorId int64 `json:"authorId"` //发布人id
Images []string `json:"images,optional"` //图片
Videos []Video `json:"video,optional"` // 视频
TargetUser int `json:"targetUser"` // 分发方式 [0分发给所有人、1分发给指定的人]
WhoRead []int64 `json:"whoRead,optional"` //谁可查看
WhoReview []int64 `json:"whoReview,optional"` //谁可评论
MatchUrl map[string]string `json:"matchUrl,optional"` // 匹配文章内容中的url文本
Tags []int64 `json:"tags"` // 标签
}
type SystemArticleSearchDeletedRequest struct {
Page int `json:"page"` //页码
Size int `json:"size"` //每页行数
Title string `json:"title,optional"` //标题
Author int64 `json:"author,optional"` //发布人
DeletedType int `json:"deletedType,optional"` //类型 1-运营删除 2-用户删除
BeginTime int64 `json:"beginTime,optional"` //开始时间
EndTime int64 `json:"endTime,optional"` //结束时间
}
type SystemArticleSearchDeletedResponse struct {
Total int `json:"total"`
List []SystemArticleSearchDeletedItem `json:"list"`
}
type SystemArticleSearchDeletedItem struct {
Id int64 `json:"id"` //ID
Title string `json:"title"` //标题
Images []string `json:"images"` //图片
AuthorId int64 `json:"authorId"` //发布人id
Author string `json:"author"` //发布人
Source int `json:"source"` //来源 1-用户发布 2-运营发布
DeletedType int `json:"deletedType"` //类型 1-运营删除 2-用户删除
DeletedAt int64 `json:"deletedAt"` //删除时间
}
type SystemArticleDeletedRestoreRequest struct {
Id int64 `json:"id"` //ID
}
type SystemArticleDeletedRestoreResponse struct {
Id int64 `json:"id"` //ID
Title string `json:"title"` //标题
AuthorId int64 `json:"authorId"` //发布人id
}
type RoleGetRequest struct {
Id int64 `path:"id"`
}
... ... @@ -1494,3 +1705,70 @@ type DepartmentListResponse struct {
List []Department `json:"list"`
Total int64 `json:"total"`
}
type ArticleCategoryGetRequest struct {
Id int64 `path:"id"`
}
type ArticleCategoryGetResponse struct {
ArticleCategory ArticleCategoryItem `json:"category"`
}
type ArticleCategorySaveRequest struct {
ArticleCategory ArticleCategoryItem `json:"category"`
}
type ArticleCategorySaveResponse struct {
}
type ArticleCategoryDeleteRequest struct {
Id int64 `path:"id"`
}
type ArticleCategoryDeleteResponse struct {
}
type ArticleCategoryUpdateRequest struct {
Id int64 `path:"id"`
ArticleCategory ArticleCategoryItem `json:"category"`
}
type ArticleCategoryUpdateResponse struct {
}
type ArticleCategorySearchRequest struct {
Page int `json:"page"`
Size int `json:"size"`
}
type ArticleCategorySearchResponse struct {
List []ArticleCategoryItem `json:"list"`
Total int64 `json:"total"`
}
type ArticleCategoryItem struct {
Id int64 `json:"id,optional"` // 唯一标识
CompanyId int64 `json:"companyId,optional,omitempty"`
Name string `json:"name"`
SortBy int `json:"sortBy,optional,omitempty"` // 排序
Enable int `json:"enable,omitempty"` // 启用状态 1:启用 2:禁用
Other string `json:"other,optional,omitempty"` // 其他备注说明
}
type CategoryOptionsRequest struct {
CompanyId int64 `path:",optional"` // 公司ID
}
type CategoryOptionsResponse struct {
Options []CategoryOptions `json:"options"`
}
type CategoryOptions struct {
Value int64 `json:"value"` // 分类ID
Label string `json:"label"` // 分组名称
}
type CategoryOptionValue struct {
Label string `json:"label"` // 名称
Value int64 `json:"value"` // 分类ID
}
... ...
syntax = "v1"
info(
title: "xx实例"
desc: "xx实例"
author: "author"
email: "email"
version: "v1"
)
@server(
prefix: article_category/v1
group: article_category
jwt: JwtAuth
)
service Core {
@doc "详情"
@handler article_categoryGet
get /article_category/:id (ArticleCategoryGetRequest) returns (ArticleCategoryGetResponse)
@doc "保存"
@handler article_categorySave
post /article_category (ArticleCategorySaveRequest) returns (ArticleCategorySaveResponse)
@doc "删除"
@handler article_categoryDelete
delete /article_category/:id (ArticleCategoryDeleteRequest) returns (ArticleCategoryDeleteResponse)
@doc "更新"
@handler article_categoryUpdate
put /article_category/:id (ArticleCategoryUpdateRequest) returns (ArticleCategoryUpdateResponse)
@doc "搜索"
@handler article_categorySearch
post /article_category/search (ArticleCategorySearchRequest) returns (ArticleCategorySearchResponse)
}
type (
ArticleCategoryGetRequest {
Id int64 `path:"id"`
}
ArticleCategoryGetResponse struct{
ArticleCategory ArticleCategoryItem `json:"article_category"`
}
ArticleCategorySaveRequest struct{
ArticleCategory ArticleCategoryItem `json:"article_category"`
}
ArticleCategorySaveResponse struct{}
ArticleCategoryDeleteRequest struct{
Id int64 `path:"id"`
}
ArticleCategoryDeleteResponse struct{}
ArticleCategoryUpdateRequest struct{
Id int64 `path:"id"`
ArticleCategory ArticleCategoryItem `json:"article_category"`
}
ArticleCategoryUpdateResponse struct{}
ArticleCategorySearchRequest struct{
Page int `json:"page"`
Size int `json:"size"`
}
ArticleCategorySearchResponse{
List []ArticleCategoryItem `json:"list"`
Total int64 `json:"total"`
}
ArticleCategoryItem struct{
}
)
// logic CRUD
// Save
//var (
// conn = l.svcCtx.DefaultDBConn()
// dm *domain.ArticleCategory
//)
//// 唯一判断
//dm = NewDomainArticleCategory(req.ArticleCategory)
//if err = transaction.UseTrans(l.ctx, l.svcCtx.DB, func(ctx context.Context, conn transaction.Conn) error {
// dm, err = l.svcCtx.ArticleCategoryRepository.Insert(l.ctx, conn, dm)
// return err
//}, true); err != nil {
// return nil, xerr.NewErrMsg("保存失败")
//}
////resp = &types.ArticleCategorySaveResponse{}
//return
//func NewDomainArticleCategory(item types.ArticleCategoryItem) *domain.ArticleCategory {
// return &domain.ArticleCategory{
// }
//}
//
//func NewTypesArticleCategory(item *domain.ArticleCategory) types.ArticleCategoryItem {
// return types.ArticleCategoryItem{
// Id: item.Id,
// }
//}
// Get
//var (
// conn = l.svcCtx.DefaultDBConn()
// dm *domain.ArticleCategory
//)
//// 货号唯一
//if dm, err = l.svcCtx.ArticleCategoryRepository.FindOne(l.ctx, conn, req.Id); err != nil {
// return nil, xerr.NewErrMsgErr("不存在", err)
//}
//resp = &types.ArticleCategoryGetResponse{
// ArticleCategory: NewTypesArticleCategory(dm),
//}
//return
// Delete
//var (
// conn = l.svcCtx.DefaultDBConn()
// dm *domain.ArticleCategory
//)
//if dm, err = l.svcCtx.ArticleCategoryRepository.FindOne(l.ctx, conn, req.Id); err != nil {
// return nil, xerr.NewErrMsgErr("不存在", err)
//}
//if err = transaction.UseTrans(l.ctx, l.svcCtx.DB, func(ctx context.Context, conn transaction.Conn) error {
// if dm, err = l.svcCtx.ArticleCategoryRepository.Delete(l.ctx, conn, dm); err != nil {
// return err
// }
// return nil
//}, true); err != nil {
// return nil, xerr.NewErrMsgErr("移除失败", err)
//}
//return
// Search
//var (
// conn = l.svcCtx.DefaultDBConn()
// dms []*domain.ArticleCategory
// total int64
//)
//
//queryOptions := domain.NewQueryOptions().WithOffsetLimit(req.Page, req.Size).
// WithKV("", "")
//total, dms, err = l.svcCtx.ArticleCategoryRepository.Find(l.ctx, conn, queryOptions)
//list := make([]types.ArticleCategoryItem, 0)
//for i := range dms {
// list = append(list, NewTypesArticleCategory(dms[i]))
//}
//resp = &types.ArticleCategorySearchResponse{
// List: list,
// Total: total,
//}
//return
// Update
//var (
// conn = l.svcCtx.DefaultDBConn()
// dm *domain.ArticleCategory
//)
//if dm, err = l.svcCtx.ArticleCategoryRepository.FindOne(l.ctx, conn, req.Id); err != nil {
// return nil, xerr.NewErrMsgErr("不存在", err)
//}
//// 不可编辑判断
//// 赋值
//// 更新
//if err = transaction.UseTrans(l.ctx, l.svcCtx.DB, func(ctx context.Context, conn transaction.Conn) error {
// dm, err = l.svcCtx.ArticleCategoryRepository.UpdateWithVersion(l.ctx, conn, dm)
// return err
//}, true); err != nil {
// return nil, xerr.NewErrMsg("更新失败")
//}
//resp = &types.ArticleCategoryUpdateResponse{}
//return
... ...
syntax = "v1"
info(
title: "xx实例"
desc: "xx实例"
author: "author"
email: "email"
version: "v1"
)
@server(
prefix: article_draft_operation/v1
group: article_draft_operation
jwt: JwtAuth
)
service Core {
@handler getArticleDraftOperation
post /article_draft_operation/:id (ArticleDraftOperationGetRequest) returns (ArticleDraftOperationGetResponse)
@handler saveArticleDraftOperation
post /article_draft_operation (ArticleDraftOperationSaveRequest) returns (ArticleDraftOperationSaveResponse)
@handler deleteArticleDraftOperation
delete /article_draft_operation/:id (ArticleDraftOperationDeleteRequest) returns (ArticleDraftOperationDeleteResponse)
@handler updateArticleDraftOperation
put /article_draft_operation/:id (ArticleDraftOperationUpdateRequest) returns (ArticleDraftOperationUpdateResponse)
@handler searchArticleDraftOperation
post /article_draft_operation/search (ArticleDraftOperationSearchRequest) returns (ArticleDraftOperationSearchResponse)
}
type (
ArticleDraftOperationGetRequest {
Id int64 `path:"id"`
}
ArticleDraftOperationGetResponse struct{
ArticleDraftOperation ArticleDraftOperationItem `json:"article_draft_operation"`
}
ArticleDraftOperationSaveRequest struct{
ArticleDraftOperation ArticleDraftOperationItem `json:"article_draft_operation"`
}
ArticleDraftOperationSaveResponse struct{}
ArticleDraftOperationDeleteRequest struct{
Id int64 `path:"id"`
}
ArticleDraftOperationDeleteResponse struct{}
ArticleDraftOperationUpdateRequest struct{
Id int64 `path:"id"`
ArticleDraftOperation ArticleDraftOperationItem `json:"article_draft_operation"`
}
ArticleDraftOperationUpdateResponse struct{}
ArticleDraftOperationSearchRequest struct{
Page int `json:"page"`
Size int `json:"size"`
}
ArticleDraftOperationSearchResponse{
List []ArticleDraftOperationItem `json:"list"`
Total int64 `json:"total"`
}
ArticleDraftOperationItem struct{
}
)
... ...
syntax = "proto3";
option go_package ="./pb";
package pb;
message ArticleCategoryGetReq {
int64 Id = 1;
}
message ArticleCategoryGetResp{
ArticleCategoryItem User = 1;
}
message ArticleCategorySaveReq {
}
message ArticleCategorySaveResp{
}
message ArticleCategoryDeleteReq {
int64 Id = 1;
}
message ArticleCategoryDeleteResp{
}
message ArticleCategoryUpdateReq {
int64 Id = 1;
}
message ArticleCategoryUpdateResp{
}
message ArticleCategorySearchReq {
int64 PageNumber = 1;
int64 PageSize = 2;
}
message ArticleCategorySearchResp{
repeated ArticleCategoryItem List =1;
int64 Total =2;
}
message ArticleCategoryItem {
}
service ArticleCategoryService {
rpc ArticleCategoryGet(ArticleCategoryGetReq) returns(ArticleCategoryGetResp);
rpc ArticleCategorySave(ArticleCategorySaveReq) returns(ArticleCategorySaveResp);
rpc ArticleCategoryDelete(ArticleCategoryDeleteReq) returns(ArticleCategoryDeleteResp);
rpc ArticleCategoryUpdate(ArticleCategoryUpdateReq) returns(ArticleCategoryUpdateResp);
rpc ArticleCategorySearch(ArticleCategorySearchReq) returns(ArticleCategorySearchResp);
}
... ...
syntax = "proto3";
option go_package ="./pb";
package pb;
message ArticleDraftOperationGetReq {
int64 Id = 1;
}
message ArticleDraftOperationGetResp{
ArticleDraftOperationItem User = 1;
}
message ArticleDraftOperationSaveReq {
}
message ArticleDraftOperationSaveResp{
}
message ArticleDraftOperationDeleteReq {
int64 Id = 1;
}
message ArticleDraftOperationDeleteResp{
}
message ArticleDraftOperationUpdateReq {
int64 Id = 1;
}
message ArticleDraftOperationUpdateResp{
}
message ArticleDraftOperationSearchReq {
int64 PageNumber = 1;
int64 PageSize = 2;
}
message ArticleDraftOperationSearchResp{
repeated ArticleDraftOperationItem List =1;
int64 Total =2;
}
message ArticleDraftOperationItem {
}
service ArticleDraftOperationService {
rpc ArticleDraftOperationGet(ArticleDraftOperationGetReq) returns(ArticleDraftOperationGetResp);
rpc ArticleDraftOperationSave(ArticleDraftOperationSaveReq) returns(ArticleDraftOperationSaveResp);
rpc ArticleDraftOperationDelete(ArticleDraftOperationDeleteReq) returns(ArticleDraftOperationDeleteResp);
rpc ArticleDraftOperationUpdate(ArticleDraftOperationUpdateReq) returns(ArticleDraftOperationUpdateResp);
rpc ArticleDraftOperationSearch(ArticleDraftOperationSearchReq) returns(ArticleDraftOperationSearchResp);
}
... ...
... ... @@ -7,23 +7,25 @@ import (
func Migrate(db *gorm.DB) {
modelsList := []interface{}{
&models.Article{},
&models.ArticleSection{},
&models.ArticleBackup{},
&models.ArticleDraft{},
&models.ArticleComment{},
&models.ArticleTag{},
&models.UserLoveFlag{},
&models.UserReadArticle{},
&models.User{},
&models.UserRole{},
&models.Role{},
&models.Company{},
&models.UserFollow{},
&models.MessageSystem{},
&models.MessageBusiness{},
&models.Department{},
&models.ArticleAndTag{},
//&models.Article{},
//&models.ArticleSection{},
//&models.ArticleBackup{},
//&models.ArticleDraft{},
//&models.ArticleComment{},
//&models.ArticleTag{},
//&models.UserLoveFlag{},
//&models.UserReadArticle{},
//&models.User{},
//&models.UserRole{},
//&models.Role{},
//&models.Company{},
//&models.UserFollow{},
//&models.MessageSystem{},
//&models.MessageBusiness{},
//&models.Department{},
//&models.ArticleAndTag{},
&models.ArticleDraftOperation{},
&models.ArticleCategory{},
}
db.AutoMigrate(modelsList...)
... ...
... ... @@ -2,11 +2,10 @@ package models
import (
"fmt"
"time"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/domain"
"gorm.io/gorm"
"gorm.io/plugin/soft_delete"
"time"
)
type Article struct {
... ... @@ -33,6 +32,9 @@ type Article struct {
Show int // 评论的展示状态(1显示、2不显示)
Summary string // 内容概要
MatchUrl map[string]string `gorm:"type:jsonb;serializer:json"` // 匹配文章内容中的url文本
Source int `gorm:"default:1"` // 来源 1-用户发布 2-运营发布
Operator domain.Operator `gorm:"type:jsonb;serializer:json"` // 运营操作人
DeletedType int `json:"deletedType"` // 删除类型 1-运营删除 2-用户删除
}
func (m *Article) TableName() string {
... ...
package models
import (
"fmt"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/domain"
"gorm.io/gorm"
"gorm.io/plugin/soft_delete"
"time"
)
type ArticleCategory struct {
Id int64 // 唯一标识
CompanyId int64
Name string
SortBy int
Enable int
Other string
CreatedAt int64
UpdatedAt int64
IsDel soft_delete.DeletedAt `gorm:"softDelete:flag,DeletedAtField:DeletedAt"`
DeletedAt int64
Version int
}
func (m *ArticleCategory) TableName() string {
return "article_category"
}
func (m *ArticleCategory) BeforeCreate(tx *gorm.DB) (err error) {
m.CreatedAt = time.Now().Unix()
m.UpdatedAt = time.Now().Unix()
return
}
func (m *ArticleCategory) BeforeUpdate(tx *gorm.DB) (err error) {
m.UpdatedAt = time.Now().Unix()
return
}
func (m *ArticleCategory) CacheKeyFunc() string {
if m.Id == 0 {
return ""
}
return fmt.Sprintf("%v:cache:%v:id:%v", domain.ProjectName, m.TableName(), m.Id)
}
func (m *ArticleCategory) CacheKeyFuncByObject(obj interface{}) string {
if v, ok := obj.(*ArticleCategory); ok {
return v.CacheKeyFunc()
}
return ""
}
func (m *ArticleCategory) CachePrimaryKeyFunc() string {
if len("") == 0 {
return ""
}
return fmt.Sprintf("%v:cache:%v:primarykey:%v", domain.ProjectName, m.TableName(), "key")
}
... ...
package models
import (
"fmt"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/domain"
"gorm.io/gorm"
"gorm.io/plugin/soft_delete"
"time"
)
// ArticleDraftOperation 运营草稿
type ArticleDraftOperation struct {
Id int64 `gorm:"primaryKey"` // 唯一标识
CompanyId int64 `gorm:"comment:公司ID"` // 公司ID
AuthorId int64 `gorm:"comment:发布人ID"` // 发布人
Title string `gorm:"comment:标题"` // 文章标题
Content string `json:"content"` // 文章内容
Images []domain.Image `gorm:"type:jsonb;serializer:json"` // 图片
Videos []domain.Video `gorm:"type:jsonb;serializer:json"` // 视频
TargetUser domain.ArticleTarget `gorm:"comment:分发方式 0所有人 1指定人"` // 分发方式 0 分发给所有人 1 分发给指定的人
WhoRead []int64 `gorm:"type:jsonb;serializer:json"` // 谁可以看
WhoReview []int64 `gorm:"type:jsonb;serializer:json"` // 评论人
Tags []int64 `gorm:"type:jsonb;serializer:json"` //定性标签
MatchUrl map[string]string `gorm:"type:jsonb;serializer:json"` // 匹配文章内容中的url文本
Source int `gorm:"default:1"` // 来源 1-用户发布 2-运营发布
Operator domain.Operator `gorm:"type:jsonb;serializer:json"` // 运营操作人
Version int `gorm:"comment:版本号"` // 版本号
CreatedAt int64 `gorm:"comment:创建时间"` // 创建时间
UpdatedAt int64 `gorm:"comment:编辑时间"` // 编辑时间
IsDel soft_delete.DeletedAt `gorm:"softDelete:flag,DeletedAtField:DeletedAt"` // 删除标记
DeletedAt int64 `gorm:"comment:删除时间"` // 删除时间
}
func (m *ArticleDraftOperation) TableName() string {
return "article_draft_operation"
}
func (m *ArticleDraftOperation) BeforeCreate(tx *gorm.DB) (err error) {
nowTime := time.Now().Unix()
m.CreatedAt = nowTime
m.UpdatedAt = nowTime
return
}
func (m *ArticleDraftOperation) BeforeUpdate(tx *gorm.DB) (err error) {
m.UpdatedAt = time.Now().Unix()
m.Version += 1
return
}
func (m *ArticleDraftOperation) CacheKeyFunc() string {
if m.Id == 0 {
return ""
}
return fmt.Sprintf("%v:cache:%v:id:%v", domain.ProjectName, m.TableName(), m.Id)
}
func (m *ArticleDraftOperation) CacheKeyFuncByObject(obj interface{}) string {
if v, ok := obj.(*ArticleDraftOperation); ok {
return v.CacheKeyFunc()
}
return ""
}
func (m *ArticleDraftOperation) CachePrimaryKeyFunc() string {
if len("") == 0 {
return ""
}
return fmt.Sprintf("%v:cache:%v:primarykey:%v", domain.ProjectName, m.TableName(), "key")
}
... ...
... ... @@ -11,19 +11,21 @@ import (
// 文章的所有标签
type ArticleTag struct {
Id int64 `gorm:"primaryKey"` // 唯一标识
CompanyId int64
CreatedAt int64
UpdatedAt int64
DeletedAt int64
IsDel soft_delete.DeletedAt `gorm:"softDelete:flag,DeletedAtField:DeletedAt"`
Version int
Image domain.Image `gorm:"type:jsonb;serializer:json"` // 图片
Name string // 标签名称
Remark string // 备注
Category string // 标签分类
SortBy int64 // 顺序
Other string // 其他
Id int64 `gorm:"primaryKey"` // 唯一标识
CompanyId int64
CreatedAt int64
UpdatedAt int64
DeletedAt int64
IsDel soft_delete.DeletedAt `gorm:"softDelete:flag,DeletedAtField:DeletedAt"`
Version int
Image domain.Image `gorm:"type:jsonb;serializer:json"` // 图片
Name string // 标签名称
Remark string // 备注
Category string // 标签分类
SortBy int64 // 顺序
Other string // 其他
CategoryId int64 // 标签分类ID
DataFrom int // 来源 0:系统初始化 1:用户自动添加(可删除)
}
func (m *ArticleTag) TableName() string {
... ...
... ... @@ -8,11 +8,11 @@ import (
)
type Company struct {
Id int64 // 唯一标识
Name string // 名称
Code string `gorm:"uniqueIndex:idx_company_code"` // 编码(搜索使用,4位字母数字)
Logo string // 公司LOGO
Id int64 // 唯一标识
Name string // 名称
Code string `gorm:"uniqueIndex:idx_company_code"` // 编码(搜索使用,4位字母数字)
Logo string // 公司LOGO
Visible int
CreatedAt int64
UpdatedAt int64
DeletedAt int64
... ...
package repository
import (
"context"
"github.com/jinzhu/copier"
"github.com/pkg/errors"
"github.com/tiptok/gocomm/pkg/cache"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/db/models"
"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"
"gorm.io/gorm"
)
type ArticleCategoryRepository struct {
*cache.CachedRepository
}
func (repository *ArticleCategoryRepository) Insert(ctx context.Context, conn transaction.Conn, dm *domain.ArticleCategory) (*domain.ArticleCategory, error) {
var (
err error
m = &models.ArticleCategory{}
tx = conn.DB()
)
if m, err = repository.DomainModelToModel(dm); err != nil {
return nil, err
}
if tx = tx.Model(m).Save(m); tx.Error != nil {
return nil, tx.Error
}
dm.Id = m.Id
return repository.ModelToDomainModel(m)
}
func (repository *ArticleCategoryRepository) Update(ctx context.Context, conn transaction.Conn, dm *domain.ArticleCategory) (*domain.ArticleCategory, error) {
var (
err error
m *models.ArticleCategory
tx = conn.DB()
)
if m, err = repository.DomainModelToModel(dm); err != nil {
return nil, err
}
queryFunc := func() (interface{}, error) {
tx = tx.Model(m).Updates(m)
return nil, tx.Error
}
if _, err = repository.Query(queryFunc, m.CacheKeyFunc()); err != nil {
return nil, err
}
return repository.ModelToDomainModel(m)
}
func (repository *ArticleCategoryRepository) UpdateWithVersion(ctx context.Context, transaction transaction.Conn, dm *domain.ArticleCategory) (*domain.ArticleCategory, error) {
var (
err error
m *models.ArticleCategory
tx = transaction.DB()
)
if m, err = repository.DomainModelToModel(dm); err != nil {
return nil, err
}
oldVersion := dm.Version
m.Version += 1
queryFunc := func() (interface{}, error) {
tx = tx.Model(m).Select("*").Where("id = ?", m.Id).Where("version = ?", oldVersion).Updates(m)
if tx.RowsAffected == 0 {
return nil, domain.ErrUpdateFail
}
return nil, tx.Error
}
if _, err = repository.Query(queryFunc, m.CacheKeyFunc()); err != nil {
return nil, err
}
return repository.ModelToDomainModel(m)
}
func (repository *ArticleCategoryRepository) Delete(ctx context.Context, conn transaction.Conn, dm *domain.ArticleCategory) (*domain.ArticleCategory, error) {
var (
tx = conn.DB()
m = &models.ArticleCategory{Id: dm.Identify().(int64)}
)
queryFunc := func() (interface{}, error) {
tx = tx.Where("id = ?", m.Id).Delete(m)
return m, tx.Error
}
if _, err := repository.Query(queryFunc, m.CacheKeyFunc()); err != nil {
return dm, err
}
return repository.ModelToDomainModel(m)
}
func (repository *ArticleCategoryRepository) FindOne(ctx context.Context, conn transaction.Conn, id int64) (*domain.ArticleCategory, error) {
var (
err error
tx = conn.DB()
m = new(models.ArticleCategory)
)
queryFunc := func() (interface{}, error) {
tx = tx.Model(m).Where("id = ?", id).First(m)
if errors.Is(tx.Error, gorm.ErrRecordNotFound) {
return nil, domain.ErrNotFound
}
return m, tx.Error
}
cacheModel := new(models.ArticleCategory)
cacheModel.Id = id
if err = repository.QueryCache(cacheModel.CacheKeyFunc, m, queryFunc); err != nil {
return nil, err
}
return repository.ModelToDomainModel(m)
}
func (repository *ArticleCategoryRepository) FindOneByName(ctx context.Context, conn transaction.Conn, companyId int64, name string) (*domain.ArticleCategory, error) {
var (
err error
tx = conn.DB()
m = new(models.ArticleCategory)
)
queryFunc := func() (interface{}, error) {
tx = tx.Model(m).Where("company_id = ?", companyId).Where("name = ?", name).First(m)
if errors.Is(tx.Error, gorm.ErrRecordNotFound) {
return nil, domain.ErrNotFound
}
return m, tx.Error
}
if _, err = repository.Query(queryFunc); err != nil {
return nil, err
}
return repository.ModelToDomainModel(m)
}
func (repository *ArticleCategoryRepository) Find(ctx context.Context, conn transaction.Conn, companyId int64, queryOptions map[string]interface{}) (int64, []*domain.ArticleCategory, error) {
var (
tx = conn.DB()
ms []*models.ArticleCategory
dms = make([]*domain.ArticleCategory, 0)
total int64
)
queryFunc := func() (interface{}, error) {
tx = tx.Model(&ms).Where("company_id = ?", companyId)
if v, ok := queryOptions["enable"]; ok {
tx.Where("enable = ?", v)
}
tx.Order("sort_by asc").Order("id asc")
if total, tx = transaction.PaginationAndCount(ctx, tx, queryOptions, &ms); tx.Error != nil {
return dms, tx.Error
}
return dms, nil
}
if _, err := repository.Query(queryFunc); err != nil {
return 0, nil, err
}
for _, item := range ms {
if dm, err := repository.ModelToDomainModel(item); err != nil {
return 0, dms, err
} else {
dms = append(dms, dm)
}
}
return total, dms, nil
}
func (repository *ArticleCategoryRepository) ModelToDomainModel(from *models.ArticleCategory) (*domain.ArticleCategory, error) {
to := &domain.ArticleCategory{}
err := copier.Copy(to, from)
return to, err
}
func (repository *ArticleCategoryRepository) DomainModelToModel(from *domain.ArticleCategory) (*models.ArticleCategory, error) {
to := &models.ArticleCategory{}
err := copier.Copy(to, from)
return to, err
}
func NewArticleCategoryRepository(cache *cache.CachedRepository) domain.ArticleCategoryRepository {
return &ArticleCategoryRepository{CachedRepository: cache}
}
... ...
package repository
import (
"context"
"github.com/jinzhu/copier"
"github.com/pkg/errors"
"github.com/tiptok/gocomm/pkg/cache"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/db/models"
"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"
"gorm.io/gorm"
)
type ArticleDraftOperationRepository struct {
*cache.CachedRepository
}
func (repository *ArticleDraftOperationRepository) Insert(ctx context.Context, conn transaction.Conn, dm *domain.ArticleDraftOperation) (*domain.ArticleDraftOperation, error) {
var (
err error
m = &models.ArticleDraftOperation{}
tx = conn.DB()
)
if m, err = repository.DomainModelToModel(dm); err != nil {
return nil, err
}
if tx = tx.Model(m).Save(m); tx.Error != nil {
return nil, tx.Error
}
dm.Id = m.Id
return repository.ModelToDomainModel(m)
}
func (repository *ArticleDraftOperationRepository) Update(ctx context.Context, conn transaction.Conn, dm *domain.ArticleDraftOperation) (*domain.ArticleDraftOperation, error) {
var (
err error
m *models.ArticleDraftOperation
tx = conn.DB()
)
if m, err = repository.DomainModelToModel(dm); err != nil {
return nil, err
}
queryFunc := func() (interface{}, error) {
tx = tx.Model(m).Updates(m)
return nil, tx.Error
}
if _, err = repository.Query(queryFunc, m.CacheKeyFunc()); err != nil {
return nil, err
}
return repository.ModelToDomainModel(m)
}
func (repository *ArticleDraftOperationRepository) UpdateWithVersion(ctx context.Context, transaction transaction.Conn, dm *domain.ArticleDraftOperation) (*domain.ArticleDraftOperation, error) {
var (
err error
m *models.ArticleDraftOperation
tx = transaction.DB()
)
if m, err = repository.DomainModelToModel(dm); err != nil {
return nil, err
}
oldVersion := dm.Version
m.Version += 1
queryFunc := func() (interface{}, error) {
tx = tx.Model(m).Select("*").Where("id = ?", m.Id).Where("version = ?", oldVersion).Updates(m)
if tx.RowsAffected == 0 {
return nil, domain.ErrUpdateFail
}
return nil, tx.Error
}
if _, err = repository.Query(queryFunc, m.CacheKeyFunc()); err != nil {
return nil, err
}
return repository.ModelToDomainModel(m)
}
func (repository *ArticleDraftOperationRepository) Delete(ctx context.Context, conn transaction.Conn, dm *domain.ArticleDraftOperation) (*domain.ArticleDraftOperation, error) {
var (
tx = conn.DB()
m = &models.ArticleDraftOperation{Id: dm.Identify().(int64)}
)
queryFunc := func() (interface{}, error) {
tx = tx.Where("id = ?", m.Id).Delete(m)
return m, tx.Error
}
if _, err := repository.Query(queryFunc, m.CacheKeyFunc()); err != nil {
return dm, err
}
return repository.ModelToDomainModel(m)
}
func (repository *ArticleDraftOperationRepository) FindOne(ctx context.Context, conn transaction.Conn, id int64) (*domain.ArticleDraftOperation, error) {
var (
err error
tx = conn.DB()
m = new(models.ArticleDraftOperation)
)
queryFunc := func() (interface{}, error) {
tx = tx.Model(m).Where("id = ?", id).First(m)
if errors.Is(tx.Error, gorm.ErrRecordNotFound) {
return nil, domain.ErrNotFound
}
return m, tx.Error
}
cacheModel := new(models.ArticleDraftOperation)
cacheModel.Id = id
if err = repository.QueryCache(cacheModel.CacheKeyFunc, m, queryFunc); err != nil {
return nil, err
}
return repository.ModelToDomainModel(m)
}
func (repository *ArticleDraftOperationRepository) Find(ctx context.Context, conn transaction.Conn, queryOptions map[string]interface{}) (int64, []*domain.ArticleDraftOperation, error) {
var (
tx = conn.DB()
ms []*models.ArticleDraftOperation
dms = make([]*domain.ArticleDraftOperation, 0)
total int64
)
queryFunc := func() (interface{}, error) {
tx = tx.Model(&ms).Order("updated_at desc")
//标题
if v, ok := queryOptions["title"]; ok {
tx = tx.Where("title like ?", "%"+v.(string)+"%")
}
//公司ID
if v, ok := queryOptions["companyId"]; ok {
tx = tx.Where("company_id = ?", v)
}
//最近修改时间
if v, ok := queryOptions["beginTime"]; ok {
tx = tx.Where("updated_at >= ?", v)
}
if v, ok := queryOptions["endTime"]; ok {
tx = tx.Where("updated_at <= ?", v)
}
//操作人
if v, ok := queryOptions["operator"]; ok {
tx = tx.Where(`"operator" ->> 'name' like ?`, "%"+v.(string)+"%")
}
if total, tx = transaction.PaginationAndCount(ctx, tx, queryOptions, &ms); tx.Error != nil {
return dms, tx.Error
}
return dms, nil
}
if _, err := repository.Query(queryFunc); err != nil {
return 0, nil, err
}
for _, item := range ms {
if dm, err := repository.ModelToDomainModel(item); err != nil {
return 0, dms, err
} else {
dms = append(dms, dm)
}
}
return total, dms, nil
}
func (repository *ArticleDraftOperationRepository) ModelToDomainModel(from *models.ArticleDraftOperation) (*domain.ArticleDraftOperation, error) {
to := &domain.ArticleDraftOperation{}
err := copier.Copy(to, from)
return to, err
}
func (repository *ArticleDraftOperationRepository) DomainModelToModel(from *domain.ArticleDraftOperation) (*models.ArticleDraftOperation, error) {
to := &models.ArticleDraftOperation{}
err := copier.Copy(to, from)
return to, err
}
func NewArticleDraftOperationRepository(cache *cache.CachedRepository) domain.ArticleDraftOperationRepository {
return &ArticleDraftOperationRepository{CachedRepository: cache}
}
... ...
... ... @@ -3,6 +3,7 @@ package repository
import (
"context"
"fmt"
"gorm.io/plugin/soft_delete"
"strings"
"github.com/pkg/errors"
... ... @@ -53,6 +54,28 @@ func (repository *ArticleRepository) Update(ctx context.Context, conn transactio
return repository.ModelToDomainModel(m)
}
func (repository *ArticleRepository) Restore(ctx context.Context, conn transaction.Conn, dm *domain.Article) (*domain.Article, error) {
var (
err error
m *models.Article
tx = conn.DB()
)
if m, err = repository.DomainModelToModel(dm); err != nil {
return nil, err
}
m.DeletedAt = 0
m.IsDel = soft_delete.DeletedAt(soft_delete.FlagActived)
m.DeletedType = 0
queryFunc := func() (interface{}, error) {
tx = tx.Model(m).Unscoped().Select("*").Updates(m)
return nil, tx.Error
}
if _, err = repository.Query(queryFunc, m.CacheKeyFunc()); err != nil {
return nil, err
}
return repository.ModelToDomainModel(m)
}
func (repository *ArticleRepository) UpdateWithVersion(ctx context.Context, transaction transaction.Conn, dm *domain.Article) (*domain.Article, error) {
var (
err error
... ... @@ -113,6 +136,27 @@ func (repository *ArticleRepository) FindOne(ctx context.Context, conn transacti
return repository.ModelToDomainModel(m)
}
func (repository *ArticleRepository) FindOneWithUnscoped(ctx context.Context, conn transaction.Conn, id int64) (*domain.Article, error) {
var (
err error
tx = conn.DB()
m = new(models.Article)
)
queryFunc := func() (interface{}, error) {
tx = tx.Model(m).Unscoped().Where("id = ?", id).First(m)
if errors.Is(tx.Error, gorm.ErrRecordNotFound) {
return nil, domain.ErrNotFound
}
return m, tx.Error
}
cacheModel := new(models.Article)
cacheModel.Id = id
if err = repository.QueryCache(cacheModel.CacheKeyFunc, m, queryFunc); err != nil {
return nil, err
}
return repository.ModelToDomainModel(m)
}
func (repository *ArticleRepository) Find(ctx context.Context, conn transaction.Conn, companyId int64, queryOptions map[string]interface{}) (int64, []*domain.Article, error) {
var (
tx = conn.DB()
... ... @@ -133,6 +177,8 @@ func (repository *ArticleRepository) Find(ctx context.Context, conn transaction.
tx = tx.Order("count_love asc")
case "countLove descending":
tx = tx.Order("count_love desc")
case "deletedAt descending":
tx = tx.Order("deleted_at desc")
default:
tx = tx.Order("created_at desc")
}
... ... @@ -154,6 +200,20 @@ func (repository *ArticleRepository) Find(ctx context.Context, conn transaction.
if v, ok := queryOptions["authorId"]; ok {
tx = tx.Where("author_id=?", v)
}
if v, ok := queryOptions["deletedType"]; ok {
tx = tx.Where("deleted_type = ?", v)
}
//删除
if v, ok := queryOptions["isDel"]; ok {
tx = tx.Unscoped().Where("is_del = ?", v)
}
//删除时间
if v, ok := queryOptions["beginDeletedAt"]; ok {
tx = tx.Where("deleted_at >= ?", v)
}
if v, ok := queryOptions["endDeletedAt"]; ok {
tx = tx.Where("deleted_at < ?", v)
}
if v, ok := queryOptions["tags"]; ok && len(v.([]int64)) > 0 {
values := make([]string, 0)
for _, item := range v.([]int64) {
... ... @@ -384,6 +444,9 @@ func (repository *ArticleRepository) ModelToDomainModel(from *models.Article) (*
Summary: from.Summary,
MatchUrl: from.MatchUrl,
Videos: from.Videos,
Source: from.Source,
Operator: from.Operator,
DeletedType: from.DeletedType,
}
return to, nil
}
... ... @@ -413,6 +476,9 @@ func (repository *ArticleRepository) DomainModelToModel(from *domain.Article) (*
Summary: from.Summary,
MatchUrl: from.MatchUrl,
Videos: from.Videos,
Source: from.Source,
Operator: from.Operator,
DeletedType: from.DeletedType,
}
// err := copier.Copy(to, from)
return to, nil
... ...
... ... @@ -152,6 +152,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["categoryId"]; ok {
tx = tx.Where("category_id = ?", v)
}
if v, ok := queryOptions["ids"]; ok {
tx = tx.Where("id in (?)", v)
}
... ...
... ... @@ -144,6 +144,9 @@ func (repository *CompanyRepository) Find(ctx context.Context, conn transaction.
if v, ok := queryOptions["ids"]; ok {
tx.Where("id in (?)", v)
}
if v, ok := queryOptions["visible"]; ok {
tx.Where("visible = ?", v)
}
if v, ok := queryOptions["excludeIds"]; ok {
tx.Where("id not in (?)", v)
}
... ...
... ... @@ -15,22 +15,25 @@ type Article struct {
UpdatedAt int64 `json:"updatedAt,omitempty"`
DeletedAt int64 `json:"deletedAt,omitempty"`
Version int `json:"version,omitempty"`
AuthorId int64 `json:"authorId"` // 发布人
Author UserSimple `json:"author"` // 发布人
Title string `json:"title"` // 文章标题
Images []Image `json:"images"` // 图片
Videos []Video `json:"videos"` // 视频
WhoRead []int64 `json:"whoRead"` // 谁可以看
WhoReview []int64 `json:"whoReview"` // 评论人
Location Location `json:"location"` // 坐标
TargetUser ArticleTarget `json:"targetUser"` // 分发方式 0 分发给所有人 1 分发给指定的人
CountLove int `json:"countLove"` // 点赞数量
CountComment int `json:"countComment"` // 评论数量
CountRead int `json:"countRead"` // 浏览数量
Show ArticleShow `json:"show"` // 评论的展示状态(1显示,2不显示、)
Tags []int64 `json:"tags"` // 定性标签
Summary string `json:"summary"` // 内容概要
MatchUrl map[string]string `json:"matchUrl"` // 匹配文章内容中的url文本
AuthorId int64 `json:"authorId"` // 发布人
Author UserSimple `json:"author"` // 发布人
Title string `json:"title"` // 文章标题
Images []Image `json:"images"` // 图片
Videos []Video `json:"videos"` // 视频
WhoRead []int64 `json:"whoRead"` // 谁可以看
WhoReview []int64 `json:"whoReview"` // 评论人
Location Location `json:"location"` // 坐标
TargetUser ArticleTarget `json:"targetUser"` // 分发方式 0 分发给所有人 1 分发给指定的人
CountLove int `json:"countLove"` // 点赞数量
CountComment int `json:"countComment"` // 评论数量
CountRead int `json:"countRead"` // 浏览数量
Show ArticleShow `json:"show"` // 评论的展示状态(1显示,2不显示、)
Tags []int64 `json:"tags"` // 定性标签
Summary string `json:"summary"` // 内容概要
MatchUrl map[string]string `json:"matchUrl"` // 匹配文章内容中的url文本
Source int `gorm:"default:1"` // 来源 1-用户发布 2-运营发布
Operator Operator `gorm:"type:jsonb;serializer:json"` // 运营操作人
DeletedType int `json:"deletedType"` // 删除类型 1-运营删除 2-用户删除
// ...more
}
... ... @@ -38,8 +41,10 @@ type ArticleRepository interface {
Insert(ctx context.Context, conn transaction.Conn, dm *Article) (*Article, error)
Update(ctx context.Context, conn transaction.Conn, dm *Article) (*Article, error)
Delete(ctx context.Context, conn transaction.Conn, dm *Article) (*Article, error)
Restore(ctx context.Context, conn transaction.Conn, dm *Article) (*Article, error)
UpdateWithVersion(ctx context.Context, conn transaction.Conn, dm *Article) (*Article, error)
FindOne(ctx context.Context, conn transaction.Conn, id int64) (*Article, error)
FindOneWithUnscoped(ctx context.Context, conn transaction.Conn, id int64) (*Article, error)
Find(ctx context.Context, conn transaction.Conn, companyId int64, queryOptions map[string]interface{}) (int64, []*Article, error)
FindAuthorsLatestFirstArticle(ctx context.Context, conn transaction.Conn, companyId int64, authors []int64, whoRead int64, limit int) (int64, []*Article, error)
FindAuthorsLatestFirstUnreadArticle(ctx context.Context, conn transaction.Conn, companyId int64, authors []int64, whoRead int64, limit int) (int64, []*Article, error)
... ... @@ -65,6 +70,12 @@ type ArticleTarget int
const (
ArticleTargetAll ArticleTarget = 0 //内容分发给所有人
ArticleTargetLimit ArticleTarget = 1 //分发给指定的人
ArticleSourceUser int = 1 //文章来源 用户发布
ArticleSourceOperator int = 2 //文章来源 运营发布
ArticleDeletedTypeOperator int = 1 // 文章删除类型 运营删除
ArticleDeletedTypeUser int = 2 // 文章删除类型 用户删除
)
func (a ArticleTarget) Named() string {
... ...
package domain
import (
"context"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/db/transaction"
)
type ArticleCategory struct {
Id int64 // 唯一标识
CompanyId int64 `json:"companyId"`
Name string `json:"name"`
SortBy int `json:"sortBy"` // 排序
Enable int `json:"enable,omitempty"` // 启用状态 1:启用 2:禁用
Other string `json:"other"` // 其他备注说明
CreatedAt int64 `json:"createdAt,omitempty"`
UpdatedAt int64 `json:"updatedAt,omitempty"`
DeletedAt int64 `json:"deletedAt,omitempty"`
Version int `json:"version,omitempty"`
}
type ArticleCategoryRepository interface {
Insert(ctx context.Context, conn transaction.Conn, dm *ArticleCategory) (*ArticleCategory, error)
Update(ctx context.Context, conn transaction.Conn, dm *ArticleCategory) (*ArticleCategory, error)
UpdateWithVersion(ctx context.Context, conn transaction.Conn, dm *ArticleCategory) (*ArticleCategory, error)
Delete(ctx context.Context, conn transaction.Conn, dm *ArticleCategory) (*ArticleCategory, error)
FindOne(ctx context.Context, conn transaction.Conn, id int64) (*ArticleCategory, error)
FindOneByName(ctx context.Context, conn transaction.Conn, companyId int64, name string) (*ArticleCategory, error)
Find(ctx context.Context, conn transaction.Conn, companyId int64, queryOptions map[string]interface{}) (int64, []*ArticleCategory, error)
}
func (m *ArticleCategory) Identify() interface{} {
if m.Id == 0 {
return nil
}
return m.Id
}
... ...
package domain
import (
"context"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/db/transaction"
"gorm.io/plugin/soft_delete"
)
// ArticleDraftOperation 运营草稿
type ArticleDraftOperation struct {
Id int64 `json:"id"` // 唯一标识
CompanyId int64 `json:"companyId,string"` // 公司ID
AuthorId int64 `json:"authorId"` // 发布人
Title string `json:"title"` // 文章标题
Content string `json:"content"` // 文章内容
Images []Image `json:"images"` // 图片
Videos []Video `json:"videos"` // 视频
TargetUser ArticleTarget `json:"targetUser"` // 分发方式 0 分发给所有人 1 分发给指定的人
WhoRead []int64 `json:"whoRead"` // 谁可以看
WhoReview []int64 `json:"whoReview"` // 评论人
Tags []int64 `json:"tags"` //定性标签
MatchUrl map[string]string `json:"matchUrl"` // 匹配文章内容中的url文本
Source int `json:"source"` // 来源 1-用户发布 2-运营发布
Operator Operator `json:"operator"` // 运营操作人
Version int `json:"version,omitempty"` // 版本号
CreatedAt int64 `json:"createdAt,omitempty"` // 创建时间
UpdatedAt int64 `json:"updatedAt,omitempty"` // 编辑时间
IsDel soft_delete.DeletedAt `json:"isDel,omitempty"` // 删除标记
DeletedAt int64 `json:"deletedAt,omitempty"` // 删除时间
}
type ArticleDraftOperationRepository interface {
Insert(ctx context.Context, conn transaction.Conn, dm *ArticleDraftOperation) (*ArticleDraftOperation, error)
Update(ctx context.Context, conn transaction.Conn, dm *ArticleDraftOperation) (*ArticleDraftOperation, error)
UpdateWithVersion(ctx context.Context, conn transaction.Conn, dm *ArticleDraftOperation) (*ArticleDraftOperation, error)
Delete(ctx context.Context, conn transaction.Conn, dm *ArticleDraftOperation) (*ArticleDraftOperation, error)
FindOne(ctx context.Context, conn transaction.Conn, id int64) (*ArticleDraftOperation, error)
Find(ctx context.Context, conn transaction.Conn, queryOptions map[string]interface{}) (int64, []*ArticleDraftOperation, error)
}
func (m *ArticleDraftOperation) Identify() interface{} {
if m.Id == 0 {
return nil
}
return m.Id
}
... ...
... ... @@ -10,18 +10,20 @@ import (
// 文章全部的标签
type ArticleTag struct {
Id int64 `json:"id"`
CompanyId int64 `json:"companyId"`
CreatedAt int64 `json:"createdAt,omitempty"`
UpdatedAt int64 `json:"updatedAt,omitempty"`
DeletedAt int64 `json:"deletedAt,omitempty"`
Version int `json:"version,omitempty"`
Image Image `json:"image"` // 图片
Name string `json:"name"` // 标签名称
Category string `json:"category"` // 标签分类 [紧急重要]、[机会风险]
Remark string `json:"remark"` // 备注
SortBy int64 `json:"sortBy"` // 顺序
Other string `json:"other"` //
Id int64 `json:"id"`
CompanyId int64 `json:"companyId"`
CreatedAt int64 `json:"createdAt,omitempty"`
UpdatedAt int64 `json:"updatedAt,omitempty"`
DeletedAt int64 `json:"deletedAt,omitempty"`
Version int `json:"version,omitempty"`
Image Image `json:"image"` // 图片
Name string `json:"name"` // 标签名称
Category string `json:"category"` // 标签分类 [紧急重要]、[机会风险]
CategoryId int64 `json:"categoryId"` // 标签分类ID
DataFrom int `json:"dataFrom"` // 来源 0:系统初始化 1:用户自动添加(可删除)
Remark string `json:"remark"` // 备注
SortBy int64 `json:"sortBy"` // 顺序
Other string `json:"other"` //
}
type ArticleTagRepository interface {
... ...
... ... @@ -6,15 +6,15 @@ import (
)
type Company struct {
Id int64 `json:"id,omitempty"` // 唯一标识
Name string `json:"name,omitempty"` // 名称
Code string `json:"code,omitempty"` // 编码(搜索使用,4位字母数字)
Logo string `json:"logo,omitempty"` // 公司LOGO
CreatedAt int64 `json:"createdAt,omitempty"`
UpdatedAt int64 `json:"updatedAt,omitempty"`
DeletedAt int64 `json:"deletedAt,omitempty"`
Version int `json:"version,omitempty"`
Id int64 `json:"id,omitempty"` // 唯一标识
Name string `json:"name,omitempty"` // 名称
Code string `json:"code,omitempty"` // 编码(搜索使用,4位字母数字)
Logo string `json:"logo,omitempty"` // 公司LOGO
Visible int `json:"visible,omitempty"` // 可见的 1:可见 0:不可见
CreatedAt int64 `json:"createdAt,omitempty"`
UpdatedAt int64 `json:"updatedAt,omitempty"`
DeletedAt int64 `json:"deletedAt,omitempty"`
Version int `json:"version,omitempty"`
}
type CompanyRepository interface {
... ...
... ... @@ -45,10 +45,8 @@ type UserSimple struct {
CompanyId int64 `json:"companyId"`
}
// 记录数据的操作人
// type Operator struct {
// From string `json:"from"` // 操作来源
// Id int `json:"id"` // 人员id
// Name string `json:"name"` // 人员名字
// UpdatedAt int64 `json:"updatedAt"` // 时间
// }
// 运营操作人
type Operator struct {
Id int64 `json:"id,string"` // 人员id
Name string `json:"name"` // 人员名字
}
... ...
... ... @@ -26,4 +26,14 @@ CREATE TABLE `company` (
CREATE TABLE `user_follow` (
`id` int(0) NOT NULL COMMENT '唯一标识',
PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci ROW_FORMAT = Dynamic;
CREATE TABLE `article_draft_operation` (
`id` int(0) NOT NULL COMMENT '唯一标识',
PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci ROW_FORMAT = Dynamic;
CREATE TABLE `article_category` (
`id` int(0) NOT NULL COMMENT '唯一标识',
PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci ROW_FORMAT = Dynamic;
\ No newline at end of file
... ...
-- 增加字段
alter table article_tag add column category_id int8;
alter table article_tag add column data_from int2;
alter table company add column visible int2;
-- 更新数据
update article_tag set data_from = 0;
update company set visible = 0;
\ No newline at end of file
... ...