article.go
4.7 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
package domain
import (
"context"
"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"` // 图片
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文本
// ...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)
UpdateWithVersion(ctx context.Context, conn transaction.Conn, dm *Article) (*Article, error)
FindOne(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) (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 //分发给指定的人
)
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) MakeBackup(operator UserSimple, section []ArticleSection) *ArticleBackup {
b := ArticleBackup{
Id: 0,
CompanyId: m.CompanyId,
CreatedAt: 0,
UpdatedAt: 0,
DeletedAt: 0,
Version: m.Version,
Operator: operator,
ArticleId: m.Id,
Title: m.Title,
Section: section,
Images: m.Images,
Action: "",
TargetUser: m.TargetUser,
WhoRead: m.WhoRead,
WhoReview: m.WhoReview,
Tags: m.Tags,
MatchUrl: map[string]string{},
}
for k, v := range m.MatchUrl {
b.MatchUrl[k] = v
}
return &b
}