Skip to content

Commit

Permalink
Fix/修改cloudmind content.file rpc 枚举类型 (#56)
Browse files Browse the repository at this point in the history
  • Loading branch information
Love-YeLin authored Feb 11, 2024
1 parent 9c7f808 commit e4389c5
Show file tree
Hide file tree
Showing 9 changed files with 76 additions and 76 deletions.
47 changes: 27 additions & 20 deletions biz/application/service/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package service
import (
"context"
"errors"
"fmt"
"github.com/CloudStriver/cloudmind-content/biz/infrastructure/consts"
"github.com/CloudStriver/cloudmind-content/biz/infrastructure/convertor"
filemapper "github.com/CloudStriver/cloudmind-content/biz/infrastructure/mapper/file"
Expand Down Expand Up @@ -76,7 +77,7 @@ func (s *FileService) GetFile(ctx context.Context, req *gencontent.GetFileReq) (
return resp, err
}
resp.File = convertor.FileMapperToFile(file)
if req.IsGetSize && resp.File.SpaceSize == consts.FolderSize {
if req.IsGetSize && resp.File.SpaceSize == int64(gencontent.Folder_Folder_Size) {
if resp.File.SpaceSize, err = s.GetFolderSize(ctx, resp.File.Path); err != nil {
return resp, consts.ErrCalFileSize
}
Expand Down Expand Up @@ -243,11 +244,12 @@ func (s *FileService) GetFileBySharingCode(ctx context.Context, req *gencontent.

if shareFiles, err = s.FileMongoMapper.FindManyNotPagination(ctx, &filemapper.FilterOptions{
OnlyFileIds: req.FileIds,
OnlyIsDel: lo.ToPtr(consts.NotDel),
OnlyIsDel: lo.ToPtr(int64(gencontent.Deletion_Deletion_notDel)),
}); err != nil {
return resp, err
}

fmt.Printf("\n[%v]\n", req)
if req.OnlyFileId != nil {
if res, ok, err = s.CheckShareFile(ctx, shareFiles, req.OnlyFileId); err != nil {
return resp, err
Expand All @@ -261,20 +263,25 @@ func (s *FileService) GetFileBySharingCode(ctx context.Context, req *gencontent.
}
if ok {
if data, err = s.GetFileList(ctx, &gencontent.GetFileListReq{
FilterOptions: &gencontent.FileFilterOptions{OnlyFatherId: req.OnlyFatherId, OnlyIsDel: lo.ToPtr(consts.NotDel)},
FilterOptions: &gencontent.FileFilterOptions{OnlyFatherId: req.OnlyFatherId, OnlyIsDel: lo.ToPtr(int64(gencontent.Deletion_Deletion_notDel))},
PaginationOptions: req.PaginationOptions,
SortOptions: req.SortOptions,
}); err != nil {
return resp, err
}
resp.Files = data.Files
resp.Total = data.Total
resp.Token = data.Token
resp.FatherIdPath = data.FatherIdPath
resp.FatherNamePath = data.FatherNamePath
}
} else {
resp.Files = lo.Map[*filemapper.File, *gencontent.FileInfo](shareFiles, func(item *filemapper.File, _ int) *gencontent.FileInfo {
return convertor.FileMapperToFile(item)
})
resp.Total = int64(len(shareFiles))
resp.FatherIdPath = data.FatherIdPath
resp.FatherNamePath = data.FatherNamePath
}

return resp, nil
Expand Down Expand Up @@ -318,7 +325,7 @@ func (s *FileService) MoveFile(ctx context.Context, req *gencontent.MoveFileReq)
if err = sessionContext.StartTransaction(); err != nil {
return err
}
if *file.Size == consts.FolderSize {
if *file.Size == int64(gencontent.Folder_Folder_Size) {
var data []*filemapper.File
filter := bson.M{"path": bson.M{"$regex": "^" + file.Path + "/"}}
if err = s.FileMongoMapper.GetConn().Find(sessionContext, &data, filter); err != nil {
Expand Down Expand Up @@ -371,20 +378,20 @@ func (s *FileService) DeleteFile(ctx context.Context, req *gencontent.DeleteFile

update := bson.M{}
switch req.DeleteType {
case consts.SoftDel:
case int64(gencontent.Deletion_Deletion_softDel):
update["$set"] = bson.M{
consts.IsDel: consts.SoftDel,
consts.IsDel: int64(gencontent.Deletion_Deletion_softDel),
consts.DeletedAt: time.Now(),
}
case consts.HardDel:
case int64(gencontent.Deletion_Deletion_hardDel):
update["$set"] = bson.M{
consts.IsDel: consts.HardDel,
consts.IsDel: int64(gencontent.Deletion_Deletion_hardDel),
}
default:
return resp, consts.ErrInvalidDeleteType
}

if req.ClearCommunity || req.DeleteType == consts.HardDel {
if req.ClearCommunity || req.DeleteType == int64(gencontent.Deletion_Deletion_hardDel) {
update["$unset"] = bson.M{
consts.Zone: "",
consts.SubZone: "",
Expand All @@ -401,7 +408,7 @@ func (s *FileService) DeleteFile(ctx context.Context, req *gencontent.DeleteFile
}

ids = append(ids, file.ID.Hex())
if *file.Size == consts.FolderSize {
if *file.Size == int64(gencontent.Folder_Folder_Size) {
var data []*filemapper.File
filter := bson.M{"path": bson.M{"$regex": "^" + file.Path + "/"}}
if err = s.FileMongoMapper.GetConn().Find(sessionContext, &data, filter); err != nil {
Expand Down Expand Up @@ -432,7 +439,7 @@ func (s *FileService) RecoverRecycleBinFile(ctx context.Context, req *gencontent
resp = new(gencontent.RecoverRecycleBinFileResp)
file := convertor.FileInfoToFileMapper(req.File)
update := bson.M{
"$set": bson.M{consts.IsDel: consts.NotDel},
"$set": bson.M{consts.IsDel: int64(gencontent.Deletion_Deletion_notDel)},
"$unset": bson.M{consts.DeletedAt: ""},
}

Expand All @@ -442,7 +449,7 @@ func (s *FileService) RecoverRecycleBinFile(ctx context.Context, req *gencontent
if err = sessionContext.StartTransaction(); err != nil {
return err
}
if *file.Size == consts.FolderSize {
if *file.Size == int64(gencontent.Folder_Folder_Size) {
var data []*filemapper.File
filter := bson.M{"path": bson.M{"$regex": "^" + file.Path + "/"}}
if err = s.FileMongoMapper.GetConn().Find(sessionContext, &data, filter); err != nil {
Expand Down Expand Up @@ -546,7 +553,7 @@ func (s *FileService) ParsingShareCode(ctx context.Context, req *gencontent.Pars
return resp, err
}
res := convertor.ShareFileMapperToShareFile(shareFile)
if res.Status == consts.Invalid {
if res.Status == int64(gencontent.Validity_Validity_expired) {
return resp, nil
}
resp.ShareFile = res
Expand Down Expand Up @@ -575,14 +582,14 @@ func (s *FileService) SaveFileToPrivateSpace(ctx context.Context, req *genconten
FatherId: req.FatherId,
Size: file.Size,
FileMd5: file.FileMd5,
IsDel: consts.NotDel,
IsDel: int64(gencontent.Deletion_Deletion_notDel),
}); err1 != nil {
if rbErr := sessionContext.AbortTransaction(sessionContext); rbErr != nil {
log.CtxError(ctx, "保存文件中产生错误[%v]: 回滚异常[%v]\n", err1, rbErr)
}
return err1
}
if *file.Size == consts.FolderSize { // 若是文件夹,开始根据原文件夹层层创建
if *file.Size == int64(gencontent.Folder_Folder_Size) { // 若是文件夹,开始根据原文件夹层层创建
var front kv
queue := make([]kv, 0, 20)
queue = append(queue, kv{id: file.ID.Hex(), path: req.NewPath + "/" + resp.FileId})
Expand All @@ -592,9 +599,9 @@ func (s *FileService) SaveFileToPrivateSpace(ctx context.Context, req *genconten
var ids []string
var data []*filemapper.File
var filter bson.M
if req.DocumentType == consts.PublicSpace {
if req.DocumentType == int64(gencontent.Space_Space_public) {
filter = bson.M{consts.FatherId: front.id, consts.Zone: bson.M{"$exists": true, "$ne": ""}, consts.SubZone: bson.M{"$exists": true, "$ne": ""}}
} else if req.DocumentType == consts.PrivateSpace {
} else if req.DocumentType == int64(gencontent.Space_Space_private) {
filter = bson.M{consts.FatherId: front.id}
} else {
if rbErr := sessionContext.AbortTransaction(sessionContext); rbErr != nil {
Expand Down Expand Up @@ -623,7 +630,7 @@ func (s *FileService) SaveFileToPrivateSpace(ctx context.Context, req *genconten
FatherId: front.path[len(front.path)-len(front.id):],
Size: item.Size,
FileMd5: item.FileMd5,
IsDel: consts.NotDel,
IsDel: int64(gencontent.Deletion_Deletion_notDel),
}
})

Expand All @@ -635,7 +642,7 @@ func (s *FileService) SaveFileToPrivateSpace(ctx context.Context, req *genconten
}

for i, v := range data {
if *v.Size == consts.FolderSize {
if *v.Size == int64(gencontent.Folder_Folder_Size) {
queue = append(queue, kv{id: v.ID.Hex(), path: front.path + "/" + ids[i]})
}
}
Expand Down Expand Up @@ -670,7 +677,7 @@ func (s *FileService) AddFileToPublicSpace(ctx context.Context, req *gencontent.
return err
}
ids = append(ids, file.ID.Hex())
if *file.Size == consts.FolderSize {
if *file.Size == int64(gencontent.Folder_Folder_Size) {
var data []*filemapper.File
filter := bson.M{consts.Path: bson.M{"$regex": "^" + file.Path + "/"}}
if err = s.FileMongoMapper.GetConn().Find(sessionContext, &data, filter); err != nil {
Expand Down
73 changes: 31 additions & 42 deletions biz/infrastructure/consts/field.go
Original file line number Diff line number Diff line change
@@ -1,49 +1,38 @@
package consts

const (
ID = "_id"
UserId = "userId"
TypeString = "typeString"
Name = "name"
ProductId = "productId"
ProductName = "productName"
Type = "type"
Path = "path"
FatherId = "fatherId"
Size = "size"
FileMd5 = "fileMd5"
IsDel = "isDel"
SpaceSize = "spaceSize"
Tags = "tags"
Zone = "zone"
Key = "key"
SubZone = "subZone"
Status = "status"
Title = "title"
Text = "text"
Description = "description"
Labels = "labels"
CreateAt = "createAt"
UpdateAt = "updateAt"
DeletedAt = "deletedAt"
TargetId = "targetId"
TargetType = "targetType"
RelationType = "relationType"
DefaultAvatarUrl = "d2042520dce2223751906a11e547d43e.png"
DefaultDescription = "点击添加描述,让大家更好的了解你..."
PrivateSpace = 1
PublicSpace = 2
Intersection = 1
UnionSet = 2
Perpetuity = 0 // 永久有效
Effective int64 = 1 // 有效
Invalid int64 = 2 // 无效
FolderSize int64 = -1
ID = "_id"
UserId = "userId"
TypeString = "typeString"
Name = "name"
ProductId = "productId"
ProductName = "productName"
Type = "type"
Path = "path"
FatherId = "fatherId"
Size = "size"
FileMd5 = "fileMd5"
IsDel = "isDel"
SpaceSize = "spaceSize"
Tags = "tags"
Zone = "zone"
Key = "key"
SubZone = "subZone"
Status = "status"
Title = "title"
Text = "text"
Description = "description"
Labels = "labels"
CreateAt = "createAt"
UpdateAt = "updateAt"
DeletedAt = "deletedAt"
TargetId = "targetId"
TargetType = "targetType"
RelationType = "relationType"
DefaultAvatarUrl = "d2042520dce2223751906a11e547d43e.png"
DefaultDescription = "点击添加描述,让大家更好的了解你..."
)

var (
NotDel int64 = 1
SoftDel int64 = 2
HardDel int64 = 3
DefaultLimit = 10
DefaultLimit = 10
)
8 changes: 3 additions & 5 deletions biz/infrastructure/convertor/convertor.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,18 +90,16 @@ func FileInfoToFileMapper(data *gencontent.FileInfo) *file.File {
}
}

// 0:永久有效 1:有效 2:已失效 ...

func IsExpired(ctime time.Time, effectiveTime int64) int64 {
if effectiveTime < 0 {
return 0
return int64(gencontent.Validity_Validity_perpetuity)
}
now := time.Now()
ctime = ctime.Add(time.Duration(effectiveTime) * time.Second)
if now.After(ctime) {
return 2
return int64(gencontent.Validity_Validity_expired)
} else {
return 1
return int64(gencontent.Validity_Validity_temporary)
}
}

Expand Down
5 changes: 3 additions & 2 deletions biz/infrastructure/mapper/file/filter.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package file

import (
gencontent "github.com/CloudStriver/service-idl-gen-go/kitex_gen/cloudmind/content"
"github.com/elastic/go-elasticsearch/v8/typedapi/types"
"github.com/samber/lo"
"go.mongodb.org/mongo-driver/bson"
Expand Down Expand Up @@ -89,7 +90,7 @@ func (f *MongoFileFilter) CheckOnlyIsDel() {
}

func (f *MongoFileFilter) CheckOnlyDocumentType() {
if f.OnlyDocumentType != nil && *f.OnlyDocumentType == consts.PublicSpace {
if f.OnlyDocumentType != nil && *f.OnlyDocumentType == int64(gencontent.Space_Space_public) {
if f.OnlyZone != nil {
f.m[consts.Zone] = *f.OnlyZone
} else {
Expand Down Expand Up @@ -143,7 +144,7 @@ func (f *EsFilter) checkOnlyIsDel() {
}

func (f *EsFilter) checkOnlyDocumentType() {
if f.OnlyDocumentType != nil && *f.OnlyDocumentType == consts.PublicSpace {
if f.OnlyDocumentType != nil && *f.OnlyDocumentType == int64(gencontent.Space_Space_public) {
if f.OnlyZone != nil {
f.q = append(f.q, types.Query{
Term: map[string]types.TermQuery{
Expand Down
5 changes: 3 additions & 2 deletions biz/infrastructure/mapper/file/mongo.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/CloudStriver/go-pkg/utils/pagination"
"github.com/CloudStriver/go-pkg/utils/pagination/mongop"
"github.com/CloudStriver/go-pkg/utils/util/log"
gencontent "github.com/CloudStriver/service-idl-gen-go/kitex_gen/cloudmind/content"
"github.com/samber/lo"
"github.com/zeromicro/go-zero/core/mr"
"github.com/zeromicro/go-zero/core/stores/monc"
Expand Down Expand Up @@ -322,8 +323,8 @@ func (m *MongoMapper) FindFolderSize(ctx context.Context, path string) (int64, e
{
{"$match", bson.M{
consts.Path: bson.M{"$regex": "^" + path},
consts.Size: bson.M{"$ne": consts.FolderSize},
consts.IsDel: consts.NotDel,
consts.Size: bson.M{"$ne": int64(gencontent.Folder_Folder_Size)},
consts.IsDel: int64(gencontent.Deletion_Deletion_notDel),
}},
},
{
Expand Down
5 changes: 3 additions & 2 deletions biz/infrastructure/mapper/post/filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package post

import (
"github.com/CloudStriver/cloudmind-content/biz/infrastructure/consts"
gencontent "github.com/CloudStriver/service-idl-gen-go/kitex_gen/cloudmind/content"
"github.com/elastic/go-elasticsearch/v8/typedapi/types"
"github.com/samber/lo"
"go.mongodb.org/mongo-driver/bson"
Expand Down Expand Up @@ -81,9 +82,9 @@ func (f *MongoFilter) CheckOnlyText() {
func (f *MongoFilter) CheckOnlyTags() {
if f.OnlyTags != nil {
if f.OnlySetRelation != nil {
if int(*f.OnlySetRelation) == consts.Intersection {
if *f.OnlySetRelation == int64(gencontent.SetRelation_Set_intersection) {
f.m[consts.Tags] = bson.M{"$all": f.OnlyTags}
} else if *f.OnlySetRelation == consts.UnionSet {
} else if *f.OnlySetRelation == int64(gencontent.SetRelation_Set_unionSet) {
f.m[consts.Tags] = bson.M{"$in": f.OnlyTags}
}
}
Expand Down
5 changes: 3 additions & 2 deletions biz/infrastructure/mapper/product/filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package product

import (
"github.com/CloudStriver/cloudmind-content/biz/infrastructure/consts"
gencontent "github.com/CloudStriver/service-idl-gen-go/kitex_gen/cloudmind/content"
"github.com/elastic/go-elasticsearch/v8/typedapi/types"
"github.com/samber/lo"
"go.mongodb.org/mongo-driver/bson"
Expand Down Expand Up @@ -72,9 +73,9 @@ func (f *MongoFilter) CheckOnlyProductId() {
func (f *MongoFilter) CheckOnlyTags() {
if f.OnlyTags != nil {
if f.OnlySetRelation != nil {
if int(*f.OnlySetRelation) == consts.Intersection {
if *f.OnlySetRelation == int64(gencontent.SetRelation_Set_intersection) {
f.m[consts.Tags] = bson.M{"$all": f.OnlyTags}
} else if *f.OnlySetRelation == consts.UnionSet {
} else if *f.OnlySetRelation == int64(gencontent.SetRelation_Set_unionSet) {
f.m[consts.Tags] = bson.M{"$in": f.OnlyTags}
}
}
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ go 1.20

require (
github.com/CloudStriver/go-pkg v0.0.0-20231229114943-910edcb8788d
github.com/CloudStriver/service-idl-gen-go v0.0.0-20240211095735-6297dd4f7912
github.com/CloudStriver/service-idl-gen-go v0.0.0-20240211102054-e091e312444a
github.com/bytedance/sonic v1.10.2
github.com/cloudwego/kitex v0.8.0
github.com/elastic/go-elasticsearch/v8 v8.11.1
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ github.com/CloudStriver/service-idl-gen-go v0.0.0-20240211084619-f9a18d01eddc h1
github.com/CloudStriver/service-idl-gen-go v0.0.0-20240211084619-f9a18d01eddc/go.mod h1:chtR82RvfrjUujTGWROSCNAwF9Lh/U959k34bXIDvBI=
github.com/CloudStriver/service-idl-gen-go v0.0.0-20240211095735-6297dd4f7912 h1:3wvm8bGkpcoU13ybVeyGkd1qM3U0FEciFAjtvDWXP90=
github.com/CloudStriver/service-idl-gen-go v0.0.0-20240211095735-6297dd4f7912/go.mod h1:chtR82RvfrjUujTGWROSCNAwF9Lh/U959k34bXIDvBI=
github.com/CloudStriver/service-idl-gen-go v0.0.0-20240211102054-e091e312444a h1:tzTIsj2uK3va1lLLwTC1fQ0r0lL4KmmC80JnNTk72kc=
github.com/CloudStriver/service-idl-gen-go v0.0.0-20240211102054-e091e312444a/go.mod h1:chtR82RvfrjUujTGWROSCNAwF9Lh/U959k34bXIDvBI=
github.com/ajstarks/deck v0.0.0-20200831202436-30c9fc6549a9/go.mod h1:JynElWSGnm/4RlzPXRlREEwqTHAN3T56Bv2ITsFT3gY=
github.com/ajstarks/deck/generate v0.0.0-20210309230005-c3f852c02e19/go.mod h1:T13YZdzov6OU0A1+RfKZiZN9ca6VeKdBdyDV+BY97Tk=
github.com/ajstarks/svgo v0.0.0-20180226025133-644b8db467af/go.mod h1:K08gAheRH3/J6wwsYMMT4xOr94bZjxIelGM0+d/wbFw=
Expand Down

0 comments on commit e4389c5

Please sign in to comment.