作者 tangxvhui

更新模型

@@ -20,6 +20,7 @@ type ServiceContext struct { @@ -20,6 +20,7 @@ type ServiceContext struct {
20 ArticleCommentRepository domain.ArticleCommentRepository 20 ArticleCommentRepository domain.ArticleCommentRepository
21 ArticleDraftRepository domain.ArticleDraftRepository 21 ArticleDraftRepository domain.ArticleDraftRepository
22 ArticleRepository domain.ArticleRepository 22 ArticleRepository domain.ArticleRepository
  23 + ArticleSectionRepository domain.ArticleSectionRepository
23 24
24 CompanyRepository domain.CompanyRepository 25 CompanyRepository domain.CompanyRepository
25 CommentRepository domain.CommentRepository // 待移除 26 CommentRepository domain.CommentRepository // 待移除
@@ -47,6 +48,7 @@ func NewServiceContext(c config.Config) *ServiceContext { @@ -47,6 +48,7 @@ func NewServiceContext(c config.Config) *ServiceContext {
47 ArticleCommentRepository: repository.NewArticleCommentRepository(cache.NewCachedRepository(mlCache)), 48 ArticleCommentRepository: repository.NewArticleCommentRepository(cache.NewCachedRepository(mlCache)),
48 ArticleDraftRepository: repository.NewArticleDraftRepository(cache.NewCachedRepository(mlCache)), 49 ArticleDraftRepository: repository.NewArticleDraftRepository(cache.NewCachedRepository(mlCache)),
49 ArticleRepository: repository.NewArticleRepository(cache.NewCachedRepository(mlCache)), 50 ArticleRepository: repository.NewArticleRepository(cache.NewCachedRepository(mlCache)),
  51 + ArticleSectionRepository: repository.NewArticleSectionRepository(cache.NewCachedRepository(mlCache)),
50 CompanyRepository: repository.NewCompanyRepository(cache.NewCachedRepository(mlCache)), 52 CompanyRepository: repository.NewCompanyRepository(cache.NewCachedRepository(mlCache)),
51 DepartmentRepository: repository.NewDepartmentRepository(cache.NewCachedRepository(mlCache)), 53 DepartmentRepository: repository.NewDepartmentRepository(cache.NewCachedRepository(mlCache)),
52 MessageBusinessRepository: repository.NewMessageBusinessRepository(cache.NewCachedRepository(mlCache)), 54 MessageBusinessRepository: repository.NewMessageBusinessRepository(cache.NewCachedRepository(mlCache)),
1 package db 1 package db
2 2
3 import ( 3 import (
  4 + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/db/models"
4 "gorm.io/gorm" 5 "gorm.io/gorm"
5 ) 6 )
6 7
7 func Migrate(db *gorm.DB) { 8 func Migrate(db *gorm.DB) {
8 - db.AutoMigrate() 9 + modelsList := []interface{}{
  10 + &models.Article{},
  11 + &models.ArticleSection{},
  12 + &models.ArticleBackup{},
  13 + &models.ArticleDraft{},
  14 + &models.ArticleComment{},
  15 + &models.UserLoveFlag{},
  16 + }
  17 +
  18 + db.AutoMigrate(modelsList...)
9 } 19 }
@@ -18,16 +18,16 @@ type Article struct { @@ -18,16 +18,16 @@ type Article struct {
18 IsDel soft_delete.DeletedAt `gorm:"softDelete:flag,DeletedAtField:DeletedAt"` 18 IsDel soft_delete.DeletedAt `gorm:"softDelete:flag,DeletedAtField:DeletedAt"`
19 Version int 19 Version int
20 AuthorId int64 // 发布人 20 AuthorId int64 // 发布人
21 - Author domain.UserSimple // 发布人 21 + Author domain.UserSimple `gorm:"type:jsonb;serializer:json"` // 发布人
22 Title string // 文章标题 22 Title string // 文章标题
23 - Images []domain.Image // 图片  
24 - WhoRead []int64 // 谁可以看  
25 - WhoReview []int64 // 评论人  
26 - Location domain.Location // 坐标 23 + Images []domain.Image `gorm:"type:jsonb;serializer:json"` // 图片
  24 + WhoRead []int64 `gorm:"type:jsonb;serializer:json"` // 谁可以看
  25 + WhoReview []int64 `gorm:"type:jsonb;serializer:json"` // 评论人
  26 + Location domain.Location `gorm:"type:jsonb;serializer:json"` // 坐标
27 TargetUser int // 分发方式 0 分发给所有人 1 分发给指定的人 27 TargetUser int // 分发方式 0 分发给所有人 1 分发给指定的人
28 CountLove int // 点赞数量 28 CountLove int // 点赞数量
29 CountComment int // 评论数量 29 CountComment int // 评论数量
30 - Tags []int // 标签 30 + Tags []int `gorm:"type:jsonb;serializer:json"` // 标签
31 Show int // 评论的展示状态(0显示、1不显示) 31 Show int // 评论的展示状态(0显示、1不显示)
32 } 32 }
33 33
@@ -17,14 +17,14 @@ type ArticleBackup struct { @@ -17,14 +17,14 @@ type ArticleBackup struct {
17 DeletedAt int64 17 DeletedAt int64
18 IsDel soft_delete.DeletedAt `gorm:"softDelete:flag,DeletedAtField:DeletedAt"` 18 IsDel soft_delete.DeletedAt `gorm:"softDelete:flag,DeletedAtField:DeletedAt"`
19 Version int 19 Version int
20 - Operator domain.UserSimple // 操作人 20 + Operator domain.UserSimple `gorm:"type:jsonb;serializer:json"` // 操作人
21 Title string // 标题 21 Title string // 标题
22 - Section []domain.ArticleSection // 分段内容  
23 - Images []domain.Image // 图片 22 + Section []domain.ArticleSection `gorm:"type:jsonb;serializer:json"` // 分段内容
  23 + Images []domain.Image `gorm:"type:jsonb;serializer:json"` // 图片
24 Action string // 操作 24 Action string // 操作
25 - WhoRead []int64 // 谁可以看  
26 - WhoReview []int64 // 评论人  
27 - Tags []int // 标签 25 + WhoRead []int64 `gorm:"type:jsonb;serializer:json"` // 谁可以看
  26 + WhoReview []int64 `gorm:"type:jsonb;serializer:json"` // 评论人
  27 + Tags []int `gorm:"type:jsonb;serializer:json"` // 标签
28 TargetUser int // 分发方式 0 分发给所有人 1 分发给指定的人 28 TargetUser int // 分发方式 0 分发给所有人 1 分发给指定的人
29 } 29 }
30 30
@@ -23,9 +23,9 @@ type ArticleComment struct { @@ -23,9 +23,9 @@ type ArticleComment struct {
23 ArticleSectionId int64 // 文本内容id 23 ArticleSectionId int64 // 文本内容id
24 SectionContent string // 引用的文章内容文本 24 SectionContent string // 引用的文章内容文本
25 FromUserId int64 // 谁填写的评论 25 FromUserId int64 // 谁填写的评论
26 - FromUser domain.UserSimple // 谁填写的评论 26 + FromUser domain.UserSimple `gorm:"type:jsonb;serializer:json"` // 谁填写的评论
27 ToUserId int64 // 回复谁的评论 27 ToUserId int64 // 回复谁的评论
28 - ToUser domain.UserSimple // 回复谁的评论 28 + ToUser domain.UserSimple `gorm:"type:jsonb;serializer:json"` // 回复谁的评论
29 Content string // 评论内容 29 Content string // 评论内容
30 CountReply int // 回复数量 30 CountReply int // 回复数量
31 CountUserLove int // 用户点赞数量 31 CountUserLove int // 用户点赞数量
@@ -17,13 +17,13 @@ type ArticleDraft struct { @@ -17,13 +17,13 @@ type ArticleDraft struct {
17 DeletedAt int64 17 DeletedAt int64
18 Version int 18 Version int
19 Template int // 填写内容时用的样板0、无 1、演绎式 2、归纳式 19 Template int // 填写内容时用的样板0、无 1、演绎式 2、归纳式
20 - Content []string // 文章内容 20 + Content []string `gorm:"type:jsonb;serializer:json"` // 文章内容
21 AuthorId int64 // 发布人 21 AuthorId int64 // 发布人
22 Title string // 文章标题 22 Title string // 文章标题
23 - Images []domain.Image // 图片  
24 - WhoRead []int64 // 谁可以看  
25 - WhoReview []int64 // 评论人  
26 - Location domain.Location // 坐标 23 + Images []domain.Image `gorm:"type:jsonb;serializer:json"` // 图片
  24 + WhoRead []int64 `gorm:"type:jsonb;serializer:json"` // 谁可以看
  25 + WhoReview []int64 `gorm:"type:jsonb;serializer:json"` // 评论人
  26 + Location domain.Location `gorm:"type:jsonb;serializer:json"` // 坐标
27 } 27 }
28 28
29 func (m *ArticleDraft) TableName() string { 29 func (m *ArticleDraft) TableName() string {
@@ -68,6 +68,7 @@ type ArticleRepository interface { @@ -68,6 +68,7 @@ type ArticleRepository interface {
68 Insert(ctx context.Context, conn transaction.Conn, dm *Article) (*Article, error) 68 Insert(ctx context.Context, conn transaction.Conn, dm *Article) (*Article, error)
69 Update(ctx context.Context, conn transaction.Conn, dm *Article) (*Article, error) 69 Update(ctx context.Context, conn transaction.Conn, dm *Article) (*Article, error)
70 Delete(ctx context.Context, conn transaction.Conn, dm *Article) (*Article, error) 70 Delete(ctx context.Context, conn transaction.Conn, dm *Article) (*Article, error)
  71 + UpdateWithVersion(ctx context.Context, conn transaction.Conn, dm *Article) (*Article, error)
71 FindOne(ctx context.Context, conn transaction.Conn, id int64) (*Article, error) 72 FindOne(ctx context.Context, conn transaction.Conn, id int64) (*Article, error)
72 Find(ctx context.Context, conn transaction.Conn, queryOptions map[string]interface{}) (int64, []*Article, error) 73 Find(ctx context.Context, conn transaction.Conn, queryOptions map[string]interface{}) (int64, []*Article, error)
73 } 74 }
@@ -28,6 +28,7 @@ type ArticleBackup struct { @@ -28,6 +28,7 @@ type ArticleBackup struct {
28 type ArticleBackupRepository interface { 28 type ArticleBackupRepository interface {
29 Insert(ctx context.Context, conn transaction.Conn, dm *ArticleBackup) (*ArticleBackup, error) 29 Insert(ctx context.Context, conn transaction.Conn, dm *ArticleBackup) (*ArticleBackup, error)
30 Update(ctx context.Context, conn transaction.Conn, dm *ArticleBackup) (*ArticleBackup, error) 30 Update(ctx context.Context, conn transaction.Conn, dm *ArticleBackup) (*ArticleBackup, error)
  31 + UpdateWithVersion(ctx context.Context, conn transaction.Conn, dm *ArticleBackup) (*ArticleBackup, error)
31 Delete(ctx context.Context, conn transaction.Conn, dm *ArticleBackup) (*ArticleBackup, error) 32 Delete(ctx context.Context, conn transaction.Conn, dm *ArticleBackup) (*ArticleBackup, error)
32 FindOne(ctx context.Context, conn transaction.Conn, id int64) (*ArticleBackup, error) 33 FindOne(ctx context.Context, conn transaction.Conn, id int64) (*ArticleBackup, error)
33 Find(ctx context.Context, conn transaction.Conn, queryOptions map[string]interface{}) (int64, []*ArticleBackup, error) 34 Find(ctx context.Context, conn transaction.Conn, queryOptions map[string]interface{}) (int64, []*ArticleBackup, error)
@@ -42,6 +42,7 @@ const ( @@ -42,6 +42,7 @@ const (
42 type ArticleCommentRepository interface { 42 type ArticleCommentRepository interface {
43 Insert(ctx context.Context, conn transaction.Conn, dm *ArticleComment) (*ArticleComment, error) 43 Insert(ctx context.Context, conn transaction.Conn, dm *ArticleComment) (*ArticleComment, error)
44 Update(ctx context.Context, conn transaction.Conn, dm *ArticleComment) (*ArticleComment, error) 44 Update(ctx context.Context, conn transaction.Conn, dm *ArticleComment) (*ArticleComment, error)
  45 + UpdateWithVersion(ctx context.Context, conn transaction.Conn, dm *ArticleComment) (*ArticleComment, error)
45 Delete(ctx context.Context, conn transaction.Conn, dm *ArticleComment) (*ArticleComment, error) 46 Delete(ctx context.Context, conn transaction.Conn, dm *ArticleComment) (*ArticleComment, error)
46 FindOne(ctx context.Context, conn transaction.Conn, id int64) (*ArticleComment, error) 47 FindOne(ctx context.Context, conn transaction.Conn, id int64) (*ArticleComment, error)
47 Find(ctx context.Context, conn transaction.Conn, queryOptions map[string]interface{}) (int64, []*ArticleComment, error) 48 Find(ctx context.Context, conn transaction.Conn, queryOptions map[string]interface{}) (int64, []*ArticleComment, error)
@@ -27,6 +27,7 @@ type ArticleDraft struct { @@ -27,6 +27,7 @@ type ArticleDraft struct {
27 type ArticleDraftRepository interface { 27 type ArticleDraftRepository interface {
28 Insert(ctx context.Context, conn transaction.Conn, dm *ArticleDraft) (*ArticleDraft, error) 28 Insert(ctx context.Context, conn transaction.Conn, dm *ArticleDraft) (*ArticleDraft, error)
29 Update(ctx context.Context, conn transaction.Conn, dm *ArticleDraft) (*ArticleDraft, error) 29 Update(ctx context.Context, conn transaction.Conn, dm *ArticleDraft) (*ArticleDraft, error)
  30 + UpdateWithVersion(ctx context.Context, conn transaction.Conn, dm *ArticleDraft) (*ArticleDraft, error)
30 Delete(ctx context.Context, conn transaction.Conn, dm *ArticleDraft) (*ArticleDraft, error) 31 Delete(ctx context.Context, conn transaction.Conn, dm *ArticleDraft) (*ArticleDraft, error)
31 FindOne(ctx context.Context, conn transaction.Conn, id int64) (*ArticleDraft, error) 32 FindOne(ctx context.Context, conn transaction.Conn, id int64) (*ArticleDraft, error)
32 Find(ctx context.Context, conn transaction.Conn, queryOptions map[string]interface{}) (int64, []*ArticleDraft, error) 33 Find(ctx context.Context, conn transaction.Conn, queryOptions map[string]interface{}) (int64, []*ArticleDraft, error)
@@ -6,7 +6,7 @@ import ( @@ -6,7 +6,7 @@ import (
6 "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/db/transaction" 6 "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/db/transaction"
7 ) 7 )
8 8
9 -// 文章段落 9 +// 文章段落内容
10 type ArticleSection struct { 10 type ArticleSection struct {
11 Id int64 `json:"id"` 11 Id int64 `json:"id"`
12 CompanyId int64 `json:"companyId"` 12 CompanyId int64 `json:"companyId"`
@@ -23,6 +23,7 @@ type ArticleSection struct { @@ -23,6 +23,7 @@ type ArticleSection struct {
23 type ArticleSectionRepository interface { 23 type ArticleSectionRepository interface {
24 Insert(ctx context.Context, conn transaction.Conn, dm *ArticleSection) (*ArticleSection, error) 24 Insert(ctx context.Context, conn transaction.Conn, dm *ArticleSection) (*ArticleSection, error)
25 Update(ctx context.Context, conn transaction.Conn, dm *ArticleSection) (*ArticleSection, error) 25 Update(ctx context.Context, conn transaction.Conn, dm *ArticleSection) (*ArticleSection, error)
  26 + UpdateWithVersion(ctx context.Context, conn transaction.Conn, dm *ArticleSection) (*ArticleSection, error)
26 Delete(ctx context.Context, conn transaction.Conn, dm *ArticleSection) (*ArticleSection, error) 27 Delete(ctx context.Context, conn transaction.Conn, dm *ArticleSection) (*ArticleSection, error)
27 FindOne(ctx context.Context, conn transaction.Conn, id int64) (*ArticleSection, error) 28 FindOne(ctx context.Context, conn transaction.Conn, id int64) (*ArticleSection, error)
28 Find(ctx context.Context, conn transaction.Conn, queryOptions map[string]interface{}) (int64, []*ArticleSection, error) 29 Find(ctx context.Context, conn transaction.Conn, queryOptions map[string]interface{}) (int64, []*ArticleSection, error)
@@ -6,7 +6,7 @@ import ( @@ -6,7 +6,7 @@ import (
6 "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/db/transaction" 6 "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/db/transaction"
7 ) 7 )
8 8
9 -// 文章的标签 9 +// 文章全部的标签
10 10
11 type ArticleTag struct { 11 type ArticleTag struct {
12 Id int64 `json:"id"` 12 Id int64 `json:"id"`
@@ -22,8 +22,9 @@ type ArticleTag struct { @@ -22,8 +22,9 @@ type ArticleTag struct {
22 } 22 }
23 type ArticleTagRepository interface { 23 type ArticleTagRepository interface {
24 Insert(ctx context.Context, conn transaction.Conn, dm *ArticleTag) (*ArticleTag, error) 24 Insert(ctx context.Context, conn transaction.Conn, dm *ArticleTag) (*ArticleTag, error)
25 - Update(ctx context.Context, conn transaction.Conn, dm *ArticleTag) (*ArticleSection, error) 25 + Update(ctx context.Context, conn transaction.Conn, dm *ArticleTag) (*ArticleTag, error)
26 Delete(ctx context.Context, conn transaction.Conn, dm *ArticleTag) (*ArticleTag, error) 26 Delete(ctx context.Context, conn transaction.Conn, dm *ArticleTag) (*ArticleTag, error)
  27 + UpdateWithVersion(ctx context.Context, conn transaction.Conn, dm *ArticleTag) (*ArticleTag, error)
27 FindOne(ctx context.Context, conn transaction.Conn, id int64) (*ArticleTag, error) 28 FindOne(ctx context.Context, conn transaction.Conn, id int64) (*ArticleTag, error)
28 Find(ctx context.Context, conn transaction.Conn, queryOptions map[string]interface{}) (int64, []*ArticleTag, error) 29 Find(ctx context.Context, conn transaction.Conn, queryOptions map[string]interface{}) (int64, []*ArticleTag, error)
29 } 30 }
1 package domain 1 package domain
2 2
  3 +import (
  4 + "context"
  5 +
  6 + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/db/transaction"
  7 +)
  8 +
3 // 人员查看文章详情后,标记一个记录 9 // 人员查看文章详情后,标记一个记录
4 // 浏览记录 10 // 浏览记录
5 11
@@ -14,3 +20,12 @@ type UserReadArticle struct { @@ -14,3 +20,12 @@ type UserReadArticle struct {
14 DeletedAt int64 `json:"deletedAt,omitempty"` 20 DeletedAt int64 `json:"deletedAt,omitempty"`
15 Version int `json:"version,omitempty"` 21 Version int `json:"version,omitempty"`
16 } 22 }
  23 +
  24 +type UserReadArticleRepository interface {
  25 + Insert(ctx context.Context, conn transaction.Conn, dm *UserReadArticle) (*UserReadArticle, error)
  26 + Update(ctx context.Context, conn transaction.Conn, dm *UserReadArticle) (*UserReadArticle, error)
  27 + UpdateWithVersion(ctx context.Context, conn transaction.Conn, dm *UserReadArticle) (*UserReadArticle, error)
  28 + Delete(ctx context.Context, conn transaction.Conn, dm *UserReadArticle) (*UserReadArticle, error)
  29 + FindOne(ctx context.Context, conn transaction.Conn, id int64) (*UserReadArticle, error)
  30 + Find(ctx context.Context, conn transaction.Conn, queryOptions map[string]interface{}) (int64, []*UserReadArticle, error)
  31 +}