article.go
6.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
package domain
import (
"context"
"strings"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/db/transaction"
)
// 文章
type Article struct {
Id int64 `json:"id"`
CompanyId int64 `json:"companyId"`
CreatedAt int64 `json:"createdAt,omitempty"`
UpdatedAt int64 `json:"updatedAt,omitempty"`
DeletedAt int64 `json:"deletedAt,omitempty"`
Version int `json:"version,omitempty"`
AuthorId int64 `json:"authorId"` // 发布人
Author UserSimple `json:"author"` // 发布人
Title string `json:"title"` // 文章标题
Images []Image `json:"images"` // 图片
Videos []Video `json:"videos"` // 视频
WhoRead []int64 `json:"whoRead"` // 谁可以看
WhoReview []int64 `json:"whoReview"` // 评论人
Location Location `json:"location"` // 坐标
TargetUser ArticleTarget `json:"targetUser"` // 分发方式 0 分发给所有人 1 分发给指定的人
CountLove int `json:"countLove"` // 点赞数量
CountComment int `json:"countComment"` // 评论数量
CountRead int `json:"countRead"` // 浏览数量
Show ArticleShow `json:"show"` // 评论的展示状态(1显示,2不显示、)
Tags []int64 `json:"tags"` // 定性标签
Summary string `json:"summary"` // 内容概要
MatchUrl map[string]string `json:"matchUrl"` // 匹配文章内容中的url文本
Source int `gorm:"default:1"` // 来源 1-用户发布 2-运营发布
Operator Operator `gorm:"type:jsonb;serializer:json"` // 运营操作人
DeletedType int `json:"deletedType"` // 删除类型 1-运营删除 2-用户删除
// ...more
}
type ArticleRepository interface {
Insert(ctx context.Context, conn transaction.Conn, dm *Article) (*Article, error)
Update(ctx context.Context, conn transaction.Conn, dm *Article) (*Article, error)
Delete(ctx context.Context, conn transaction.Conn, dm *Article) (*Article, error)
Restore(ctx context.Context, conn transaction.Conn, dm *Article) (*Article, error)
UpdateWithVersion(ctx context.Context, conn transaction.Conn, dm *Article) (*Article, error)
FindOne(ctx context.Context, conn transaction.Conn, id int64) (*Article, error)
FindOneWithUnscoped(ctx context.Context, conn transaction.Conn, id int64) (*Article, error)
Find(ctx context.Context, conn transaction.Conn, companyId int64, queryOptions map[string]interface{}) (int64, []*Article, error)
FindAuthorsLatestFirstArticle(ctx context.Context, conn transaction.Conn, companyId int64, authors []int64, whoRead int64, limit int) (int64, []*Article, error)
FindAuthorsLatestFirstUnreadArticle(ctx context.Context, conn transaction.Conn, companyId int64, authors []int64, whoRead int64, limit int) (int64, []*Article, error)
FindAuthorsLatestArticle(ctx context.Context, conn transaction.Conn, companyId int64, authors []int64, whoRead int64, lastId int64, limit int, queryOptions map[string]interface{}) (int64, []*Article, error)
FindLatestAccessibleArticle(ctx context.Context, conn transaction.Conn, companyId int64, whoRead int64, lastId int64, limit int) (int64, []*Article, error)
IncreaseCountLove(ctx context.Context, conn transaction.Conn, incr int, articleId int64) error //点赞数量变动
IncreaseCountComment(ctx context.Context, conn transaction.Conn, incr int, articleId int64) error //评论数量变动
IncreaseCountRead(ctx context.Context, conn transaction.Conn, incr int, articleId int64) error //浏览数量变动
// CustomSearchBy 小程序端搜索查询文章
// userId 人员id,谁查看文章
// companyId 公司id
// tagCategory 标签分类
// tagId 标签id
// createdAt 文章的发布时间,按范围查询 [开始时间,结束时间]
// titleLike 搜索标题
CustomSearchBy(ctx context.Context, conn transaction.Conn, userId int64, companyId int64,
tagCategory string, tagId int64, createdAt [2]int64, titleLike string, page int, size int) (int64, []*Article, error)
}
type ArticleTarget int
const (
ArticleTargetAll ArticleTarget = 0 //内容分发给所有人
ArticleTargetLimit ArticleTarget = 1 //分发给指定的人
ArticleSourceUser int = 1 //文章来源 用户发布
ArticleSourceOperator int = 2 //文章来源 运营发布
ArticleDeletedTypeOperator int = 1 // 文章删除类型 运营删除
ArticleDeletedTypeUser int = 2 // 文章删除类型 用户删除
)
func (a ArticleTarget) Named() string {
switch a {
case ArticleTargetAll:
return "所以人"
case ArticleTargetLimit:
return "指定人"
}
return ""
}
// 文章的展示状态(1显示,2不显示)
type ArticleShow int
const (
ArticleShowEnable ArticleShow = 1
ArticleShowDisable ArticleShow = 2
)
func (a ArticleShow) Named() string {
switch a {
case ArticleShowEnable:
return "显示"
case ArticleShowDisable:
return "隐藏"
}
return ""
}
func (m *Article) SetSummary(sectionList []*ArticleSection) {
if len(sectionList) == 0 {
return
}
//设置内容概要
// 截取内容 50个字
length := 0 //字符串长度
content := ""
for i := range sectionList {
str := strings.TrimSpace(sectionList[i].Content)
if len(str) > 0 {
content = str
break
}
}
runeContent := []rune(content)
length = len(runeContent)
if length > 50 {
length = 50
}
m.Summary = string(runeContent[0:length])
}
func (m *Article) WhoCanRead(userId int64) bool {
if m.AuthorId == userId {
return true
}
if len(m.WhoRead) == 0 {
return true
}
for _, val := range m.WhoRead {
if userId == val {
return true
}
}
return false
}
func (m *Article) WhoCanReview(userId int64) bool {
if m.AuthorId == userId {
return true
}
if len(m.WhoReview) == 0 {
return true
}
for _, val := range m.WhoReview {
if userId == val {
return true
}
}
return false
}