作者 yangfu

Merge branch 'test'

正在显示 78 个修改的文件 包含 3905 行增加71 行删除

要显示太多修改。

为保证性能只显示 78 of 78+ 个文件。

... ... @@ -10,3 +10,4 @@ import "core/article_type.api"
import "core/article.api"
import "core/role.api"
import "core/department.api"
import "core/article_category.api"
\ No newline at end of file
... ...
... ... @@ -19,12 +19,15 @@ service Core {
@doc "小程序创建发布内容"
@handler MiniCreateArticle
post /article (MiniArticleCreateRequest) returns (MiniArticleCreateResponse)
@doc "小程序获取文章内容详情"
@handler MiniGetArticle
get /article/:id (MiniArticleGetRequest) returns (MiniArticleGetResponse)
@doc "小程序获取文章的点赞人员列表"
@handler MiniUserLikeArticle
post /article/user_like/list (MiniUserLikeArticleRequest) returns (MiniUserLikeArticleResponse)
@doc "小程序人员操作点赞文章/评论"
@handler MiniSetUserLike
post /article/user_like/set (MiniSetUserLikeRequset) returns (MiniSetUserLikeResponse)
... ... @@ -41,6 +44,14 @@ service Core {
@handler MiniArticleSearchMe
post /article/search/me (MiniArticleSearchMeRequest) returns (MiniArticleSearchMeResponse)
@doc "小程序我的帖子设置可见范围"
@handler MiniArticleSetView
post /article/set_view (MiniArticleSetViewRequest) returns (MiniArticleSetViewResponse)
@doc "小程序删除我的帖子"
@handler MiniArticleDelete
delete /article/delete (MiniArticleDeleteRequest) returns (MiniArticleDeleteResponse)
@doc "小程序创建文章进草稿箱"
@handler MiniCreateArticleDraft
post /article_draft (MiniArticleDraftCreateRequest) returns (MiniArticleDraftCreateResponse)
... ... @@ -121,4 +132,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 {
Enable int `form:"enable,optional"` // 启用状态 1:启用
}
CategoryOptionsResponse {
Options []CategoryOptions `json:"options"`
}
CategoryOptions {
Value int64 `json:"value"` // 分类ID
Label string `json:"label"` // 分组名称
Enable int `json:"enable,optional,omitempty"` // 启用状态 1:启用
//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 {
... ... @@ -102,6 +107,10 @@ type (
CountComment int `json:"countComment"` //评论数量
CountRead int `json:"countRead"` //浏览数量
Show int `json:"show"` //是否隐藏 [0显示、1不显示]
TargetUser int `json:"targetUser"` //分发方式 [0分发给所有人、1分发给指定的人]
WhoRead []int64 `json:"whoRead"` //谁可查看
IsDel int `json:"isDel"` //是否删除 1-删除 0-否
DeletedType int `json:"deletedType"` //类型 1-运营删除 2-用户删除
}
SystemArticleSearchMeRequest {
... ... @@ -117,6 +126,30 @@ type (
}
)
//小程序我的帖子设置可见范围
type (
MiniArticleSetViewRequest {
Id int64 `json:"id"` //id
WhoRead []int64 `json:"whoRead"` //谁可查看
}
MiniArticleSetViewResponse {
Id int64 `json:"id"` //id
Title string `json:"title"` //标题
WhoRead []int64 `json:"whoRead"` //谁可查看
}
)
//小程序删除我的帖子
type (
MiniArticleDeleteRequest {
Id int64 `json:"id"` //id
}
MiniArticleDeleteResponse {
Id int64 `json:"id"` //id
Title string `json:"title"` //标题
}
)
//小程序端获取文章有哪些人进行了点赞
type (
MiniUserLikeArticleRequest {
... ... @@ -431,11 +464,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 +505,46 @@ 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
AccessToken string `header:"x-mmm-accesstoken"` // 授权token
}
SystemArticleDeleteResponse {
Id int64 `json:"id"` //id
Title string `json:"title"` //标题
AuthorId int64 `json:"authorId,optional"` //发布人id
}
)
// 管理后台编辑历史列表
type (
//历史
... ... @@ -579,3 +655,173 @@ type (
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"` //谁可查看
WhoReadInfo []UserShowName `json:"whoReadInfo"` // 谁可查看
WhoReview []int64 `json:"whoReview,optional"` //谁可评论
WhoReviewInfo []UserShowName `json:"whoReviewInfo"` // 谁可评论
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
AccessToken string `header:"x-mmm-accesstoken"` // 授权token
}
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{
}
)
// 公司职位搜索
... ...
... ... @@ -59,6 +59,7 @@ type (
DepartmentListRequest {
Page int `json:"page"`
Size int `json:"size"`
IncludeRootCompany bool `json:"includeRootCompany,optional"` // 包含公司(把公司当作部门作为顶级节点 部门ID:0)
}
DepartmentListResponse {
... ...
... ... @@ -209,6 +209,7 @@ type(
ArticleId int64 `json:"articleId,optional"` // 按文章ID(返回文章可见的用户)
RoleId int64 `json:"roleId,optional"` // 按角色角色关联的用户
Keywords string `json:"keywords,optional"` // 按关键字搜索(名称)
DepartmentId *int64 `json:"departmentId,optional"` // 按部门过滤
}
MiniUserNewsRequest{
AuthorId int64 `json:"authorId,optional"` // 特定作者ID
... ... @@ -273,7 +274,7 @@ type(
Position string `json:"position"`// 职位
}
Department struct {
Id int64 `json:"id,omitempty"` // 部门ID
Id int64 `json:"id"` // 部门ID
CompanyId int64 `json:"companyId"` // 公司ID
ParentId int64 `json:"parentId"` // 父级ID
Name string `json:"name"` // 部门名称
... ... @@ -417,6 +418,7 @@ type(
CompanyId int64 `json:"companyId"`
CompanyName string `json:"companyName"`
Code string `json:"code"`
CompanyVisible bool `json:"companyVisible"`
}
UserStatisticsRequest{
UserId int64 `json:"userId,optional"`
... ...
... ... @@ -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
... ... @@ -40,3 +40,4 @@ ApiAuth:
Wechat:
AppID: wxae5b305849343ec8
AppSecret: f584adb68f7d784425b60e1ebb2ffd4b
QrcodeEnv: trial
\ No newline at end of file
... ...
package article
import (
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/result"
"net/http"
"github.com/zeromicro/go-zero/rest/httpx"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/logic/article"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types"
)
func MiniArticleDeleteHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.MiniArticleDeleteRequest
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
return
}
l := article.NewMiniArticleDeleteLogic(r.Context(), svcCtx)
resp, err := l.MiniArticleDelete(&req)
result.HttpResult(r, w, resp, err)
}
}
... ...
package article
import (
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/result"
"net/http"
"github.com/zeromicro/go-zero/rest/httpx"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/logic/article"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types"
)
func MiniArticleSetViewHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.MiniArticleSetViewRequest
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
return
}
l := article.NewMiniArticleSetViewLogic(r.Context(), svcCtx)
resp, err := l.MiniArticleSetView(&req)
result.HttpResult(r, w, resp, err)
}
}
... ...
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),
},
... ... @@ -500,6 +505,16 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
},
{
Method: http.MethodPost,
Path: "/article/set_view",
Handler: article.MiniArticleSetViewHandler(serverCtx),
},
{
Method: http.MethodDelete,
Path: "/article/delete",
Handler: article.MiniArticleDeleteHandler(serverCtx),
},
{
Method: http.MethodPost,
Path: "/article_draft",
Handler: article.MiniCreateArticleDraftHandler(serverCtx),
},
... ... @@ -598,6 +613,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 +738,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 (
"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/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)
result.HttpResult(r, w, resp, err)
}
}
... ...
package tags
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/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)
result.HttpResult(r, w, resp, err)
}
}
... ...
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 (
"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/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)
result.HttpResult(r, w, resp, err)
}
}
... ...
package tags
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/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)
result.HttpResult(r, w, resp, err)
}
}
... ...
package tags
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/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)
result.HttpResult(r, w, resp, err)
}
}
... ...
package tags
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/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)
result.HttpResult(r, w, resp, err)
}
}
... ...
... ... @@ -2,7 +2,6 @@ package article
import (
"context"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/domain"
... ... @@ -26,14 +25,20 @@ func NewMiniAllArticleTagLogic(ctx context.Context, svcCtx *svc.ServiceContext)
}
func (l *MiniAllArticleTagLogic) MiniAllArticleTag(req *types.MiniAllArticleTagRequest) (resp *types.MiniAllArticleTagResponse, err error) {
var conn = l.svcCtx.DefaultDBConn()
var (
conn = l.svcCtx.DefaultDBConn()
categoryList []*domain.ArticleCategory
)
queryOption := domain.NewQueryOptions().WithFindOnly()
_, tagList, err := l.svcCtx.ArticleTagRepository.Find(l.ctx, conn, req.CompanyId, queryOption)
if err != nil {
return nil, xerr.NewErrMsgErr("获取标签列表失败", err)
}
_, categoryList, err = l.svcCtx.ArticleCategoryRepository.Find(l.ctx, conn, req.CompanyId, domain.NewQueryOptions().MustWithKV("enable", 1))
if err != nil {
return nil, xerr.NewErrMsgErr("获取标签分类列表失败", err)
}
// 合并输出数据
var group []string
tagMap := map[string][]types.ArticleTagItem{}
for _, val := range tagList {
if m, ok := tagMap[val.Category]; ok {
... ... @@ -46,7 +51,6 @@ func (l *MiniAllArticleTagLogic) MiniAllArticleTag(req *types.MiniAllArticleTagR
})
tagMap[val.Category] = m
} else {
group = append(group, val.Category)
tagMap[val.Category] = []types.ArticleTagItem{
{
Id: val.Id,
... ... @@ -61,10 +65,10 @@ func (l *MiniAllArticleTagLogic) MiniAllArticleTag(req *types.MiniAllArticleTagR
resp = &types.MiniAllArticleTagResponse{
TagGroup: make([]types.ArticleTagGroup, 0),
}
for i := range group {
for _, category := range categoryList {
resp.TagGroup = append(resp.TagGroup, types.ArticleTagGroup{
Category: group[i],
Tags: tagMap[group[i]],
Category: category.Name,
Tags: tagMap[category.Name],
})
}
return resp, nil
... ...
package article
import (
"context"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/db/transaction"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/contextdata"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/xerr"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types"
"github.com/zeromicro/go-zero/core/logx"
)
type MiniArticleDeleteLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
conn transaction.Conn
}
func NewMiniArticleDeleteLogic(ctx context.Context, svcCtx *svc.ServiceContext) *MiniArticleDeleteLogic {
return &MiniArticleDeleteLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
conn: svcCtx.DefaultDBConn(),
}
}
func (l *MiniArticleDeleteLogic) MiniArticleDelete(req *types.MiniArticleDeleteRequest) (resp *types.MiniArticleDeleteResponse, err error) {
// 文章数据
article, err := l.svcCtx.ArticleRepository.FindOne(l.ctx, l.conn, req.Id)
if err != nil {
return nil, xerr.NewErrMsgErr("帖子不存在", err)
}
userToken := contextdata.GetUserTokenFromCtx(l.ctx)
if userToken.UserId != article.AuthorId || userToken.CompanyId != article.CompanyId {
return nil, xerr.NewErrMsg("您没有权限删除")
}
// 检查发布人
author, err := l.svcCtx.UserRepository.FindOne(l.ctx, l.conn, article.AuthorId)
if err != nil {
return nil, xerr.NewErrMsgErr("创建文章内容失败", err)
}
companyInfo, err := l.svcCtx.CompanyRepository.FindOne(l.ctx, l.conn, author.CompanyId)
if err != nil {
return nil, xerr.NewErrMsgErr("创建文章内容失败", err)
}
articleAuthor := domain.UserSimple{
Id: author.Id,
Name: author.Name,
Avatar: author.Avatar,
Position: author.Position,
Company: companyInfo.Name,
CompanyId: author.CompanyId,
}
article.DeletedType = domain.ArticleDeletedTypeUser
//文章内容详情
queryOption := domain.NewQueryOptions().WithFindOnly().MustWithKV("articleId", req.Id)
_, sectionList, err := l.svcCtx.ArticleSectionRepository.Find(l.ctx, l.conn, queryOption)
if err != nil {
return nil, xerr.NewErrMsgErr("帖子不存在", err)
}
var backup domain.ArticleBackup
backup.MakeBackup(articleAuthor, article, sectionList, "删除")
err = transaction.UseTrans(l.ctx, l.conn.DB(), func(ctx context.Context, conn transaction.Conn) error {
//更新删除类型
_, err = l.svcCtx.ArticleRepository.Update(l.ctx, conn, article)
if err != nil {
return err
}
//删除
_, err = l.svcCtx.ArticleRepository.Delete(l.ctx, conn, article)
if err != nil {
return err
}
//备份
_, err = l.svcCtx.ArticleBackupRepository.Insert(ctx, conn, &backup)
if err != nil {
return xerr.NewErrMsgErr("删除失败", err)
}
return nil
}, true)
if err != nil {
return nil, xerr.NewErrMsgErr("删除失败", err)
}
resp = &types.MiniArticleDeleteResponse{
Id: article.Id,
Title: article.Title,
}
return
}
... ...
... ... @@ -33,6 +33,7 @@ func (l *MiniArticleSearchMeLogic) MiniArticleSearchMe(req *types.MiniArticleSea
}
queryOptions := domain.NewQueryOptions().
WithOffsetLimit(req.Page, req.Size).
WithKV("showDel", true).
MustWithKV("authorId", req.AuthorId)
cnt, articleList, err := l.svcCtx.ArticleRepository.Find(l.ctx, conn, req.CompanyId, queryOptions)
... ... @@ -64,6 +65,10 @@ func NewArticle(article *domain.Article) types.ArticleSearchMe {
CountComment: article.CountComment,
CountRead: article.CountRead,
Show: int(article.Show),
TargetUser: int(article.TargetUser),
WhoRead: article.WhoRead,
IsDel: article.IsDel,
DeletedType: article.DeletedType,
}
return articleSearchMe
}
... ...
package article
import (
"context"
"github.com/samber/lo"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/db/transaction"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/contextdata"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/xerr"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types"
"github.com/zeromicro/go-zero/core/logx"
)
type MiniArticleSetViewLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
conn transaction.Conn
}
func NewMiniArticleSetViewLogic(ctx context.Context, svcCtx *svc.ServiceContext) *MiniArticleSetViewLogic {
return &MiniArticleSetViewLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
conn: svcCtx.DefaultDBConn(),
}
}
func (l *MiniArticleSetViewLogic) MiniArticleSetView(req *types.MiniArticleSetViewRequest) (resp *types.MiniArticleSetViewResponse, err error) {
// 文章数据
article, err := l.svcCtx.ArticleRepository.FindOne(l.ctx, l.conn, req.Id)
if err != nil {
return nil, xerr.NewErrMsgErr("帖子不存在", err)
}
userToken := contextdata.GetUserTokenFromCtx(l.ctx)
if userToken.UserId != article.AuthorId || userToken.CompanyId != article.CompanyId {
return nil, xerr.NewErrMsg("您没有权限修改")
}
// 检查发布人
author, err := l.svcCtx.UserRepository.FindOne(l.ctx, l.conn, article.AuthorId)
if err != nil {
return nil, xerr.NewErrMsgErr("创建文章内容失败", err)
}
companyInfo, err := l.svcCtx.CompanyRepository.FindOne(l.ctx, l.conn, author.CompanyId)
if err != nil {
return nil, xerr.NewErrMsgErr("创建文章内容失败", err)
}
articleAuthor := domain.UserSimple{
Id: author.Id,
Name: author.Name,
Avatar: author.Avatar,
Position: author.Position,
Company: companyInfo.Name,
CompanyId: author.CompanyId,
}
//检查文章可被哪些人查看
whoRead := []int64{}
if len(req.WhoRead) > 0 {
whoRead = lo.Uniq(req.WhoRead)
var u *domain.User
for _, val := range whoRead {
u, err = l.svcCtx.UserRepository.FindOne(l.ctx, l.conn, val)
if err != nil {
return nil, xerr.NewErrMsgErr("文章可查看人设置错误", err)
}
if u.CompanyId != userToken.CompanyId {
return nil, xerr.NewErrMsg("文章可查看人设置错误")
}
}
}
//文章内容详情
queryOption := domain.NewQueryOptions().WithFindOnly().MustWithKV("articleId", req.Id)
_, sectionList, err := l.svcCtx.ArticleSectionRepository.Find(l.ctx, l.conn, queryOption)
if err != nil {
return nil, xerr.NewErrMsgErr("帖子不存在", err)
}
var oldBackup domain.ArticleBackup
oldBackup.MakeBackup(articleAuthor, article, sectionList, "设置可见范围")
//更新数据
article.TargetUser = domain.ArticleTargetLimit
article.WhoRead = whoRead
article.WhoReview = whoRead
err = transaction.UseTrans(l.ctx, l.conn.DB(), func(ctx context.Context, c transaction.Conn) error {
//更新文章内容
_, err = l.svcCtx.ArticleRepository.Update(l.ctx, c, article)
if err != nil {
return xerr.NewErrMsgErr("保存帖子失败", err)
}
//备份文章
var backup domain.ArticleBackup
backup.MakeBackup(articleAuthor, article, sectionList, "设置可见范围")
if ok := backup.CheckChangeField(&oldBackup); ok {
_, err = l.svcCtx.ArticleBackupRepository.Insert(ctx, c, &backup)
if err != nil {
return xerr.NewErrMsgErr("保存文章日志失败", err)
}
}
return nil
}, true)
resp = &types.MiniArticleSetViewResponse{
Id: article.Id,
Title: article.Title,
WhoRead: article.WhoRead,
}
return
}
... ...
... ... @@ -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) {
//去除空
item = strings.TrimSpace(item)
if item != "" {
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/api/internal/logic/message"
"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"
"time"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types"
"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)
}
//文章内容
queryOption := domain.NewQueryOptions().WithFindOnly().MustWithKV("articleId", req.Id)
_, sectionList, err := l.svcCtx.ArticleSectionRepository.Find(l.ctx, l.conn, queryOption)
if err != nil {
return nil, xerr.NewErrMsgErr("帖子不存在", err)
}
userToken := contextdata.GetUserTokenFromCtx(l.ctx)
if userToken.CompanyId != article.CompanyId {
return nil, xerr.NewErrMsg("您没有权限")
}
// 获取当前用户信息
userMe, err := l.svcCtx.ApiAuthService.MeInfo(l.ctx, authlib.RequestUserMeQuery{Token: req.AccessToken})
if err != nil {
return nil, xerr.NewErrMsgErr("获取当前用户信息失败", err)
}
operator := domain.UserSimple{
Id: userToken.UserId,
Name: userMe.User.NickName,
Avatar: userMe.User.Avatar,
CompanyId: userToken.CompanyId,
Company: userMe.CurrentCompany.Name,
}
article.DeletedType = domain.ArticleDeletedTypeOperator
err = transaction.UseTrans(l.ctx, l.conn.DB(), func(ctx context.Context, conn transaction.Conn) error {
//更新删除类型
_, err = l.svcCtx.ArticleRepository.Update(l.ctx, conn, article)
if err != nil {
return err
}
_, err = l.svcCtx.ArticleRepository.Delete(l.ctx, conn, article)
if err != nil {
return err
}
var backup domain.ArticleBackup
backup.MakeBackup(operator, article, sectionList, "删除")
_, err = l.svcCtx.ArticleBackupRepository.Insert(ctx, conn, &backup)
if err != nil {
return xerr.NewErrMsgErr("保存文章内容失败", err)
}
//消息通知
messageLogic := message.NewMiniSystemLogic(l.ctx, l.svcCtx)
mTime := time.Unix(article.CreatedAt, 0).Format("2006-01-02 15:04")
err = messageLogic.ArticleDeleted(conn, article.CompanyId, article.AuthorId, mTime, article.Title)
if err != nil {
return xerr.NewErrMsgErr("删除失败", 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,
WhoReadInfo: make([]types.UserShowName, 0),
WhoReview: articleDraft.WhoReview,
WhoReviewInfo: make([]types.UserShowName, 0),
MatchUrl: articleDraft.MatchUrl,
Tags: articleDraft.Tags,
}
userIds := lo.Union(resp.WhoRead, resp.WhoReview)
if len(userIds) > 0 {
_, users, err := l.svcCtx.UserRepository.Find(l.ctx, l.conn, domain.NewQueryOptions().WithKV("ids", userIds))
if err != nil {
return nil, xerr.NewErrMsgErr("获取帖子异常", err)
}
userSlices := make(map[int64]types.UserShowName)
lo.ForEach(users, func(user *domain.User, index int) {
userSlices[user.Id] = types.UserShowName{
Id: int(user.Id),
Name: user.Name,
}
})
lo.ForEach(resp.WhoRead, func(userId int64, index int) {
if value, ok := userSlices[userId]; ok {
resp.WhoReadInfo = append(resp.WhoReadInfo, value)
}
})
lo.ForEach(resp.WhoReview, func(userId int64, index int) {
if value, ok := userSlices[userId]; ok {
resp.WhoReviewInfo = append(resp.WhoReviewInfo, value)
}
})
}
return
}
... ...
package article
import (
"context"
"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 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)
}
if article.IsDel != 1 {
return nil, xerr.NewErrMsg("帖子已恢复")
}
//文章内容
queryOption := domain.NewQueryOptions().WithFindOnly().MustWithKV("articleId", req.Id)
_, sectionList, err := l.svcCtx.ArticleSectionRepository.Find(l.ctx, l.conn, queryOption)
if err != nil {
return nil, xerr.NewErrMsgErr("帖子不存在", err)
}
userToken := contextdata.GetUserTokenFromCtx(l.ctx)
if userToken.CompanyId != article.CompanyId {
return nil, xerr.NewErrMsg("您没有权限")
}
// 获取当前用户信息
userMe, err := l.svcCtx.ApiAuthService.MeInfo(l.ctx, authlib.RequestUserMeQuery{Token: req.AccessToken})
if err != nil {
return nil, xerr.NewErrMsgErr("获取当前用户信息失败", err)
}
operator := domain.UserSimple{
Id: userToken.UserId,
Name: userMe.User.NickName,
Avatar: userMe.User.Avatar,
CompanyId: userToken.CompanyId,
Company: userMe.CurrentCompany.Name,
}
err = transaction.UseTrans(l.ctx, l.conn.DB(), func(ctx context.Context, conn transaction.Conn) error {
//恢复帖子
_, err = l.svcCtx.ArticleRepository.Restore(ctx, conn, article)
if err != nil {
return err
}
//备份
var backup domain.ArticleBackup
backup.MakeBackup(operator, article, sectionList, "恢复")
_, err = l.svcCtx.ArticleBackupRepository.Insert(ctx, conn, &backup)
if err != nil {
return xerr.NewErrMsgErr("恢复帖子失败", err)
}
return nil
}, true)
if err != nil {
return nil, xerr.NewErrMsg("恢复帖子失败")
}
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
}
... ...
... ... @@ -32,7 +32,7 @@ func NewMiniQrcodeInviteLogic(ctx context.Context, svcCtx *svc.ServiceContext) *
func (l *MiniQrcodeInviteLogic) MiniQrcodeInvite(req *types.MiniQrCodeRequest) (resp interface{}, err error) {
var (
q = l.svcCtx.MiniProgram.GetQRCode()
q = l.svcCtx.GetMiniProgram().GetQRCode()
cacheData = fmt.Sprintf("%s?%s", req.Page, req.Scene)
cacheKey = fmt.Sprintf("%s:qrcode:%s", l.svcCtx.Config.Name, tool.Md5ByString(cacheData))
ok bool
... ... @@ -56,7 +56,7 @@ func (l *MiniQrcodeInviteLogic) MiniQrcodeInvite(req *types.MiniQrCodeRequest) (
Path: req.Page,
Scene: req.Scene,
CheckPath: lo.ToPtr(false),
EnvVersion: "release",
EnvVersion: l.svcCtx.Config.Wechat.QrcodeEnv,
})
if err != nil {
return nil, xerr.NewErr(err)
... ...
... ... @@ -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
}
... ...
... ... @@ -39,6 +39,17 @@ func (l *SystemListLogic) SystemList(req *types.DepartmentListRequest) (resp *ty
Total: total,
List: make([]types.Department, 0),
}
if req.IncludeRootCompany {
company, _ := l.svcCtx.CompanyRepository.FindOne(l.ctx, conn, userToken.CompanyId)
if company != nil {
resp.List = append(resp.List, types.Department{
Id: 0,
CompanyId: company.Id,
ParentId: -1,
Name: company.Name,
})
}
}
for _, item := range list {
to := types.Department{
Id: item.Id,
... ...
... ... @@ -57,6 +57,11 @@ func (l *MiniSystemLogic) ArticleDefined(conn transaction.Conn, companyId, at in
return l.createMessage(conn, companyId, at, domain.MsgTypeNormal, "帖子已定性", fmt.Sprintf("您的帖子[%s]已被定性,如有疑问,请联系运营管理员了解详情。", item))
}
// ArticleDeleted 帖子删除
func (l *MiniSystemLogic) ArticleDeleted(conn transaction.Conn, companyId, at int64, createdTime, title string) (err error) {
return l.createMessage(conn, companyId, at, domain.MsgTypeDeleted, "帖子已删除", fmt.Sprintf("你于%v发布的帖子[%v]已被删除,如有疑问,请联系运营管理员了解详情。", createdTime, title))
}
//// ArticleAuth 文章权限变更
//func (l *MiniSystemLogic) ArticleAuth(conn transaction.Conn, companyId, at int64, item string) (err error) {
// return l.createMessage(conn, companyId, at, domain.MsgTypeAbnormal, "权限变更", fmt.Sprintf("您的帖子[%s]可见权限已添加,如有疑问,请联系运营管理员了解详情。", item))
... ...
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", req.Enable)
_, 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,
Enable: item.Enable,
})
}
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
dupDm *domain.ArticleCategory
userToken = contextdata.GetUserTokenFromCtx(l.ctx)
changeName = false
)
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 dupDm, err = l.svcCtx.ArticleCategoryRepository.FindOneByName(l.ctx, conn, userToken.CompanyId, req.ArticleCategory.Name); err == nil && dupDm != nil {
return nil, xerr.NewErrMsg(fmt.Sprintf("已存在分类`%s`", dupDm.Name))
}
changeName = true
}
// 更新
if err = transaction.UseTrans(l.ctx, l.svcCtx.DB, func(ctx context.Context, conn transaction.Conn) error {
// 同步标签的分类名称
if changeName {
_, articleTags, _ := l.svcCtx.ArticleTagRepository.Find(l.ctx, conn, userToken.CompanyId, domain.NewQueryOptions().MustWithKV("categoryId", dm.Id))
for _, articleTag := range articleTags {
if articleTag.CategoryId != dm.Id {
continue
}
// 新的分类名称
articleTag.Category = req.ArticleCategory.Name
if _, err = l.svcCtx.ArticleTagRepository.UpdateWithVersion(l.ctx, conn, articleTag); err != nil {
return err
}
}
}
// 赋值
dm.Name = req.ArticleCategory.Name
dm.SortBy = req.ArticleCategory.SortBy
dm.Enable = req.ArticleCategory.Enable
dm.Other = req.ArticleCategory.Other
dm, err = l.svcCtx.ArticleCategoryRepository.UpdateWithVersion(l.ctx, conn, dm)
return err
}, true); err != nil {
return nil, xerr.NewErrMsg("更新失败")
}
resp = &types.ArticleCategoryUpdateResponse{}
return
}
... ...
... ... @@ -30,18 +30,24 @@ 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,
"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{
... ... @@ -53,15 +59,17 @@ func (l *CreateTagLogic) CreateTag(req *types.TagCreateRequest) (resp *types.Tag
Version: 0,
Image: domain.Image{},
Name: req.Name,
Category: req.Category,
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)
}
//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)
... ...
... ... @@ -39,6 +39,7 @@ func (l *GetTagLogic) GetTag(req *types.TagGetRequest) (resp *types.TagGetRespon
Image: oldTag.Image.Url,
Name: oldTag.Name,
Category: oldTag.Category,
CategoryId: oldTag.CategoryId,
Remark: oldTag.Remark,
Other: oldTag.Other,
SortBy: int(oldTag.SortBy),
... ...
... ... @@ -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+"%")
... ... @@ -51,9 +54,14 @@ func (l *SearchTagLogic) SearchTag(req *types.TagListRequest) (resp *types.TagLi
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
... ...
... ... @@ -43,10 +43,15 @@ func (l *MiniAtUsersListLogic) MiniAtUsersList(req *types.MiniUsersListRequest)
onlyUsers = article.WhoRead
}
}
if _, users, err = l.svcCtx.UserRepository.FindDepartmentUsers(l.ctx, conn, userToken.CompanyId, domain.NewQueryOptions().WithKV("name", req.Keywords).WithFindOnly()); err != nil {
queryOptions := domain.NewQueryOptions().
WithKV("name", req.Keywords).WithFindOnly()
if req.DepartmentId != nil && *req.DepartmentId > 0 {
queryOptions.WithKV("departmentId", *req.DepartmentId)
}
if _, users, err = l.svcCtx.UserRepository.FindDepartmentUsers(l.ctx, conn, userToken.CompanyId, queryOptions); err != nil {
return nil, xerr.NewErrMsgErr("用户列表获取失败", err)
}
if len(onlyUsers) > 0 {
if len(onlyUsers) > 0 || (req.DepartmentId != nil && *req.DepartmentId == 0) {
onlyUsersMap := lo.KeyBy(onlyUsers, func(item int64) int64 {
return item
})
... ... @@ -54,6 +59,11 @@ func (l *MiniAtUsersListLogic) MiniAtUsersList(req *types.MiniUsersListRequest)
if _, ok := onlyUsersMap[item.Id]; ok {
return false
}
if req.DepartmentId != nil && *req.DepartmentId == 0 {
if len(item.Departments) > 0 {
return false
}
}
return true
})
}
... ...
... ... @@ -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"
... ... @@ -97,6 +98,7 @@ func (l *SystemUserInfoLogic) SystemUserInfo(req *types.SystemUserInfoRequest) (
}
}
}
resp.CompanyVisible = company.Visible == 1
err = l.initSystemData(companyId)
if err != nil {
return nil, err
... ... @@ -109,11 +111,23 @@ 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,
},
}
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},
... ... @@ -168,11 +182,37 @@ func (l *SystemUserInfoLogic) initSystemData(companyId int64) error {
Name: "小机会低风险", Category: "机会风险", Remark: "全员警戒马上解决", SortBy: 13,
},
}
cnt, _, err := l.svcCtx.ArticleCategoryRepository.Find(l.ctx, conn, companyId, queryOption)
if cnt == 0 {
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
}
... ...
... ... @@ -33,7 +33,9 @@ type ServiceContext struct {
ArticleRepository domain.ArticleRepository
ArticleSectionRepository domain.ArticleSectionRepository
ArticleTagRepository domain.ArticleTagRepository
ArticleCategoryRepository domain.ArticleCategoryRepository
ArticleAndTagRepository domain.ArticleAndTagRepository
ArticleDraftOperationRepository domain.ArticleDraftOperationRepository
CompanyRepository domain.CompanyRepository
DepartmentRepository domain.DepartmentRepository
... ... @@ -87,6 +89,8 @@ func NewServiceContext(c config.Config) *ServiceContext {
ArticleRepository: repository.NewArticleRepository(cache.NewCachedRepository(mlCache)),
ArticleSectionRepository: repository.NewArticleSectionRepository(cache.NewCachedRepository(mlCache)),
ArticleAndTagRepository: repository.NewArticleAndTagRepository(cache.NewCachedRepository(mlCache)),
ArticleCategoryRepository: repository.NewArticleCategoryRepository(cache.NewCachedRepository(mlCache)),
ArticleDraftOperationRepository: repository.NewArticleDraftOperationRepository(cache.NewCachedRepository(mlCache)),
CompanyRepository: repository.NewCompanyRepository(cache.NewCachedRepository(mlCache)),
DepartmentRepository: repository.NewDepartmentRepository(cache.NewCachedRepository(mlCache)),
... ... @@ -105,3 +109,13 @@ func NewServiceContext(c config.Config) *ServiceContext {
func (svc *ServiceContext) DefaultDBConn() transaction.Conn {
return transaction.NewTransactionContext(svc.DB)
}
func (svc *ServiceContext) GetMiniProgram() *miniprogram.MiniProgram {
c := svc.Config
miniProgram := wechat.NewWechat().GetMiniProgram(&miniConfig.Config{
AppID: c.Wechat.AppID,
AppSecret: c.Wechat.AppSecret,
Cache: minicache.NewMemory(),
})
return miniProgram
}
... ...
... ... @@ -351,10 +351,10 @@ 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"` //排序
CategoryId int64 `json:"categoryId"` // 标签Id
}
type TagCreateResponse struct {
... ... @@ -366,7 +366,7 @@ type TagEditRequest struct {
CompanyId int64 `json:",optional"`
Image string `json:"image"`
Name string `json:"name"` // 标签名称
Category string `json:"category"` // 标签分类
CategoryId int64 `json:"categoryId"` // 标签Id
Remark string `json:"remark,optional"` // 备注
Other string `json:"other,optional"`
SortBy int `json:"sortBy,optional"` // 排序
... ... @@ -386,6 +386,7 @@ type TagGetResponse struct {
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"` // 排序
... ... @@ -396,7 +397,7 @@ type TagListRequest struct {
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"`
}
... ... @@ -410,9 +411,11 @@ type TagItem struct {
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"`
}
... ... @@ -558,6 +562,7 @@ type MiniUsersListRequest struct {
ArticleId int64 `json:"articleId,optional"` // 按文章ID(返回文章可见的用户)
RoleId int64 `json:"roleId,optional"` // 按角色角色关联的用户
Keywords string `json:"keywords,optional"` // 按关键字搜索(名称)
DepartmentId *int64 `json:"departmentId,optional"` // 按部门过滤
}
type MiniUserNewsRequest struct {
... ... @@ -627,7 +632,7 @@ type Account struct {
}
type Department struct {
Id int64 `json:"id,omitempty"` // 部门ID
Id int64 `json:"id"` // 部门ID
CompanyId int64 `json:"companyId"` // 公司ID
ParentId int64 `json:"parentId"` // 父级ID
Name string `json:"name"` // 部门名称
... ... @@ -721,6 +726,7 @@ type SystemUserInfoResponse struct {
CompanyId int64 `json:"companyId"`
CompanyName string `json:"companyName"`
Code string `json:"code"`
CompanyVisible bool `json:"companyVisible"`
}
type UserStatisticsRequest struct {
... ... @@ -862,6 +868,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 +908,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"` //文章的文本内容
... ... @@ -967,6 +985,10 @@ type ArticleSearchMe struct {
CountComment int `json:"countComment"` //评论数量
CountRead int `json:"countRead"` //浏览数量
Show int `json:"show"` //是否隐藏 [0显示、1不显示]
TargetUser int `json:"targetUser"` //分发方式 [0分发给所有人、1分发给指定的人]
WhoRead []int64 `json:"whoRead"` //谁可查看
IsDel int `json:"isDel"` //是否删除 1-删除 0-否
DeletedType int `json:"deletedType"` //类型 1-运营删除 2-用户删除
}
type SystemArticleSearchMeRequest struct {
... ... @@ -982,6 +1004,26 @@ type SystemArticleSearchMeResponse struct {
List []ArticleSearchMe `json:"list"`
}
type MiniArticleSetViewRequest struct {
Id int64 `json:"id"` //id
WhoRead []int64 `json:"whoRead"` //谁可查看
}
type MiniArticleSetViewResponse struct {
Id int64 `json:"id"` //id
Title string `json:"title"` //标题
WhoRead []int64 `json:"whoRead"` //谁可查看
}
type MiniArticleDeleteRequest struct {
Id int64 `json:"id"` //id
}
type MiniArticleDeleteResponse struct {
Id int64 `json:"id"` //id
Title string `json:"title"` //标题
}
type MiniUserLikeArticleRequest struct {
ArticleId int64 `json:"articleId"` // 文章id
CompanyId int64 `json:",optional"` //公司id
... ... @@ -1263,11 +1305,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 +1344,44 @@ 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
AccessToken string `header:"x-mmm-accesstoken"` // 授权token
}
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 +1484,164 @@ 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"` //谁可查看
WhoReadInfo []UserShowName `json:"whoReadInfo"` // 谁可查看
WhoReview []int64 `json:"whoReview,optional"` //谁可评论
WhoReviewInfo []UserShowName `json:"whoReviewInfo"` // 谁可评论
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
AccessToken string `header:"x-mmm-accesstoken"` // 授权token
}
type SystemArticleDeletedRestoreResponse struct {
Id int64 `json:"id"` //ID
Title string `json:"title"` //标题
AuthorId int64 `json:"authorId"` //发布人id
}
type RoleGetRequest struct {
Id int64 `path:"id"`
}
... ... @@ -1488,9 +1729,78 @@ type DepartmentUpdateRequest struct {
type DepartmentListRequest struct {
Page int `json:"page"`
Size int `json:"size"`
IncludeRootCompany bool `json:"includeRootCompany,optional"` // 包含公司(把公司当作部门作为顶级节点 部门ID:0)
}
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 {
Enable int `form:"enable,optional"` // 启用状态 1:启用
}
type CategoryOptionsResponse struct {
Options []CategoryOptions `json:"options"`
}
type CategoryOptions struct {
Value int64 `json:"value"` // 分类ID
Label string `json:"label"` // 分组名称
Enable int `json:"enable,optional,omitempty"` // 启用状态 1:启用
}
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")
}
... ...
... ... @@ -24,6 +24,8 @@ type ArticleTag struct {
Category string // 标签分类
SortBy int64 // 顺序
Other string // 其他
CategoryId int64 // 标签分类ID
DataFrom int // 来源 0:系统初始化 1:用户自动添加(可删除)
}
func (m *ArticleTag) TableName() string {
... ...
... ... @@ -12,7 +12,7 @@ type Company struct {
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}
}
... ...