From 52c85b3a51b75d85f3d1da5b01fa65fa82e77e63 Mon Sep 17 00:00:00 2001 From: Lansong <62054128+Lansongxx@users.noreply.github.com> Date: Tue, 9 Apr 2024 21:00:54 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=AE=9E=E7=8E=B0=E5=B8=96=E5=AD=90?= =?UTF-8?q?=E7=BB=BC=E5=90=88=E6=90=9C=E7=B4=A2=20(#94)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- biz/adaptor/server.go | 21 - biz/application/service/file.go | 1022 ++++++++++----------- biz/application/service/post.go | 7 +- biz/application/service/zone.go | 83 -- biz/infrastructure/convertor/convertor.go | 115 ++- biz/infrastructure/mapper/post/es.go | 96 +- go.mod | 4 +- go.sum | 12 +- provider/provider.go | 1 - provider/wire_gen.go | 6 - 10 files changed, 648 insertions(+), 719 deletions(-) delete mode 100644 biz/application/service/zone.go diff --git a/biz/adaptor/server.go b/biz/adaptor/server.go index 5fd21bc..acea28c 100644 --- a/biz/adaptor/server.go +++ b/biz/adaptor/server.go @@ -11,7 +11,6 @@ type ContentServerImpl struct { *config.Config FileService service.IFileService PostService service.IPostService - ZoneService service.IZoneService UserService service.IUserService ProductService service.IProductService CouponService service.ICouponService @@ -233,26 +232,6 @@ func (s *ContentServerImpl) CreateFile(ctx context.Context, req *content.CreateF return s.FileService.CreateFile(ctx, req) } -func (s *ContentServerImpl) GetZone(ctx context.Context, req *content.GetZoneReq) (res *content.GetZoneResp, err error) { - return s.ZoneService.GetZone(ctx, req) -} - -func (s *ContentServerImpl) GetZones(ctx context.Context, req *content.GetZonesReq) (res *content.GetZonesResp, err error) { - return s.ZoneService.GetZones(ctx, req) -} - -func (s *ContentServerImpl) CreateZone(ctx context.Context, req *content.CreateZoneReq) (*content.CreateZoneResp, error) { - return s.ZoneService.CreateZone(ctx, req) -} - -func (s *ContentServerImpl) UpdateZone(ctx context.Context, req *content.UpdateZoneReq) (*content.UpdateZoneResp, error) { - return s.ZoneService.UpdateZone(ctx, req) -} - -func (s *ContentServerImpl) DeleteZone(ctx context.Context, req *content.DeleteZoneReq) (*content.DeleteZoneResp, error) { - return s.ZoneService.DeleteZone(ctx, req) -} - func (s *ContentServerImpl) GetShareList(ctx context.Context, req *content.GetShareListReq) (*content.GetShareListResp, error) { return s.FileService.GetShareList(ctx, req) } diff --git a/biz/application/service/file.go b/biz/application/service/file.go index 809d536..ba2d77b 100644 --- a/biz/application/service/file.go +++ b/biz/application/service/file.go @@ -5,27 +5,21 @@ import ( "errors" "github.com/CloudStriver/cloudmind-content/biz/infrastructure/config" "github.com/CloudStriver/cloudmind-content/biz/infrastructure/consts" - "github.com/CloudStriver/cloudmind-content/biz/infrastructure/convertor" "github.com/CloudStriver/cloudmind-content/biz/infrastructure/kq" filemapper "github.com/CloudStriver/cloudmind-content/biz/infrastructure/mapper/file" sharefilemapper "github.com/CloudStriver/cloudmind-content/biz/infrastructure/mapper/sharefile" "github.com/CloudStriver/cloudmind-mq/app/util/message" - "github.com/CloudStriver/go-pkg/utils/pagination/esp" - "github.com/CloudStriver/go-pkg/utils/pagination/mongop" "github.com/CloudStriver/go-pkg/utils/pconvertor" "github.com/CloudStriver/go-pkg/utils/util/log" gencontent "github.com/CloudStriver/service-idl-gen-go/kitex_gen/cloudmind/content" "github.com/bytedance/sonic" "github.com/google/wire" - "github.com/samber/lo" "github.com/zeromicro/go-zero/core/mr" "github.com/zeromicro/go-zero/core/stores/monc" "go.mongodb.org/mongo-driver/bson" "go.mongodb.org/mongo-driver/bson/primitive" "go.mongodb.org/mongo-driver/mongo" - "go.mongodb.org/mongo-driver/mongo/options" "strings" - "time" ) type IFileService interface { @@ -78,226 +72,226 @@ func (s *FileService) GetFileIsExist(ctx context.Context, req *gencontent.GetFil func (s *FileService) GetFile(ctx context.Context, req *gencontent.GetFileReq) (resp *gencontent.GetFileResp, err error) { resp = new(gencontent.GetFileResp) - var file *filemapper.File - if file, err = s.FileMongoMapper.FindOne(ctx, req.FileId); err != nil { - return resp, err - } - resp.File = convertor.FileMapperToFile(file) - - // 如果是获取文件夹大小,需要计算文件夹大小 - 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, err - } - } + //var file *filemapper.File + //if file, err = s.FileMongoMapper.FindOne(ctx, req.FileId); err != nil { + // return resp, err + //} + //resp.File = convertor.FileMapperToFile(file) + // + //// 如果是获取文件夹大小,需要计算文件夹大小 + //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, err + // } + //} return resp, nil } func (s *FileService) GetFilesByIds(ctx context.Context, req *gencontent.GetFilesByIdsReq) (resp *gencontent.GetFilesByIdsResp, err error) { resp = new(gencontent.GetFilesByIdsResp) - var files []*filemapper.File - if files, err = s.FileMongoMapper.FindManyByIds(ctx, req.FileIds); err != nil { - return resp, err - } - - // 创建映射:文件ID到文件 - fileMap := make(map[string]*filemapper.File, len(req.FileIds)) - lo.ForEach(files, func(file *filemapper.File, _ int) { - fileMap[file.ID.Hex()] = file - }) - - // 按req.FileIds中的ID顺序映射和转换 - resp.Files = lo.Map(req.FileIds, func(id string, _ int) *gencontent.FileInfo { - if file, ok := fileMap[id]; ok { - return convertor.FileMapperToFile(file) - } - return nil // 或者处理找不到文件的情况 - }) + //var files []*filemapper.File + //if files, err = s.FileMongoMapper.FindManyByIds(ctx, req.FileIds); err != nil { + // return resp, err + //} + // + //// 创建映射:文件ID到文件 + //fileMap := make(map[string]*filemapper.File, len(req.FileIds)) + //lo.ForEach(files, func(file *filemapper.File, _ int) { + // fileMap[file.ID.Hex()] = file + //}) + // + //// 按req.FileIds中的ID顺序映射和转换 + //resp.Files = lo.Map(req.FileIds, func(id string, _ int) *gencontent.FileInfo { + // if file, ok := fileMap[id]; ok { + // return convertor.FileMapperToFile(file) + // } + // return nil // 或者处理找不到文件的情况 + //}) return resp, nil } func (s *FileService) GetRecycleBinFiles(ctx context.Context, req *gencontent.GetRecycleBinFilesReq) (resp *gencontent.GetRecycleBinFilesResp, err error) { resp = new(gencontent.GetRecycleBinFilesResp) - var ( - total int64 - files []*filemapper.File - ) - p := convertor.ParsePagination(req.PaginationOptions) - if files, total, err = s.FileMongoMapper.FindManyAndCount(ctx, convertor.FileFilterOptionsToFilterOptions(req.FilterOptions), - p, mongop.CreateAtDescCursorType); err != nil { - return resp, err - } - if p.LastToken != nil { - resp.Token = *p.LastToken - } - resp.Files = lo.Map[*filemapper.File, *gencontent.FileInfo](files, func(item *filemapper.File, _ int) *gencontent.FileInfo { - return convertor.FileMapperToFile(item) - }) - resp.Total = total + //var ( + // total int64 + // files []*filemapper.File + //) + //p := convertor.ParsePagination(req.PaginationOptions) + //if files, total, err = s.FileMongoMapper.FindManyAndCount(ctx, convertor.FileFilterOptionsToFilterOptions(req.FilterOptions), + // p, mongop.CreateAtDescCursorType); err != nil { + // return resp, err + //} + //if p.LastToken != nil { + // resp.Token = *p.LastToken + //} + //resp.Files = lo.Map[*filemapper.File, *gencontent.FileInfo](files, func(item *filemapper.File, _ int) *gencontent.FileInfo { + // return convertor.FileMapperToFile(item) + //}) + //resp.Total = total return resp, nil } func (s *FileService) GetFileList(ctx context.Context, req *gencontent.GetFileListReq) (resp *gencontent.GetFileListResp, err error) { resp = new(gencontent.GetFileListResp) - resp.FatherNamePath = "CloudMind" - var ( - files []*filemapper.File - total int64 - cursor mongop.MongoCursor - err2 error - ) - - if err = mr.Finish(func() error { - getFileResp, err1 := s.GetFile(ctx, &gencontent.GetFileReq{ - FileId: req.GetFilterOptions().GetOnlyFatherId(), - }) - if errors.Is(err1, consts.ErrNotFound) || errors.Is(err1, consts.ErrInvalidId) { - resp.FatherIdPath = req.GetFilterOptions().GetOnlyFatherId() - return nil - } - if err1 != nil { - return err1 - } - resp.FatherIdPath = getFileResp.File.Path - paths := strings.Split(getFileResp.File.Path, "/") - if len(paths) > 1 { - var res *gencontent.GetFilesByIdsResp - if res, err1 = s.GetFilesByIds(ctx, &gencontent.GetFilesByIdsReq{FileIds: paths[1:]}); err1 != nil { - return err1 - } - lo.ForEach(res.Files, func(item *gencontent.FileInfo, _ int) { - resp.FatherNamePath += "/" + item.Name - }) - } - return nil - }, func() error { - switch req.GetSortOptions() { - case gencontent.SortOptions_SortOptions_createAtAsc: - cursor = mongop.CreateAtAscCursorType - case gencontent.SortOptions_SortOptions_createAtDesc: - cursor = mongop.CreateAtDescCursorType - case gencontent.SortOptions_SortOptions_updateAtAsc: - cursor = mongop.UpdateAtAscCursorType - case gencontent.SortOptions_SortOptions_updateAtDesc: - cursor = mongop.UpdateAtDescCursorType - case gencontent.SortOptions_SortOptions_NameDesc: - cursor = mongop.NameDescCursorType - case gencontent.SortOptions_SortOptions_NameAsc: - cursor = mongop.NameAscCursorType - case gencontent.SortOptions_SortOptions_TypeAsc: - cursor = mongop.TypeAscCursorType - case gencontent.SortOptions_SortOptions_TypeDesc: - cursor = mongop.TypeDescCursorType - } - - filter := convertor.FileFilterOptionsToFilterOptions(req.FilterOptions) - p := convertor.ParsePagination(req.PaginationOptions) - if req.SearchOptions == nil { - if files, total, err2 = s.FileMongoMapper.FindManyAndCount(ctx, filter, p, cursor); err2 != nil { - return err2 - } - } else { - switch o := req.SearchOptions.Type.(type) { - case *gencontent.SearchOptions_AllFieldsKey: - files, total, err2 = s.FileEsMapper.Search(ctx, convertor.ConvertFileAllFieldsSearchQuery(o), filter, p, esp.ScoreCursorType) - case *gencontent.SearchOptions_MultiFieldsKey: - files, total, err2 = s.FileEsMapper.Search(ctx, convertor.ConvertFileMultiFieldsSearchQuery(o), filter, p, esp.ScoreCursorType) - } - if err2 != nil { - log.CtxError(ctx, "搜索文件列表异常[%v]\n", err2) - return err2 - } - } - - if p.LastToken != nil { - resp.Token = *p.LastToken - } - resp.Total = total - resp.Files = lo.Map[*filemapper.File, *gencontent.FileInfo](files, func(item *filemapper.File, _ int) *gencontent.FileInfo { - return convertor.FileMapperToFile(item) - }) - return nil - }); err != nil { - return resp, err - } + //resp.FatherNamePath = "CloudMind" + //var ( + // files []*filemapper.File + // total int64 + // cursor mongop.MongoCursor + // err2 error + //) + // + //if err = mr.Finish(func() error { + // getFileResp, err1 := s.GetFile(ctx, &gencontent.GetFileReq{ + // //FileId: req.GetFilterOptions().GetOnlyFatherId(), + // }) + // if errors.Is(err1, consts.ErrNotFound) || errors.Is(err1, consts.ErrInvalidId) { + // resp.FatherIdPath = req.GetFilterOptions().GetOnlyFatherId() + // return nil + // } + // if err1 != nil { + // return err1 + // } + // //resp.FatherIdPath = getFileResp.File.Path + // //paths := strings.Split(getFileResp.File.Path, "/") + // if len(paths) > 1 { + // var res *gencontent.GetFilesByIdsResp + // if res, err1 = s.GetFilesByIds(ctx, &gencontent.GetFilesByIdsReq{FileIds: paths[1:]}); err1 != nil { + // return err1 + // } + // lo.ForEach(res.Files, func(item *gencontent.FileInfo, _ int) { + // resp.FatherNamePath += "/" + item.Name + // }) + // } + // return nil + //}, func() error { + // switch req.GetSortOptions() { + // case gencontent.SortOptions_SortOptions_createAtAsc: + // cursor = mongop.CreateAtAscCursorType + // case gencontent.SortOptions_SortOptions_createAtDesc: + // cursor = mongop.CreateAtDescCursorType + // case gencontent.SortOptions_SortOptions_updateAtAsc: + // cursor = mongop.UpdateAtAscCursorType + // case gencontent.SortOptions_SortOptions_updateAtDesc: + // cursor = mongop.UpdateAtDescCursorType + // case gencontent.SortOptions_SortOptions_NameDesc: + // cursor = mongop.NameDescCursorType + // case gencontent.SortOptions_SortOptions_NameAsc: + // cursor = mongop.NameAscCursorType + // case gencontent.SortOptions_SortOptions_TypeAsc: + // cursor = mongop.TypeAscCursorType + // case gencontent.SortOptions_SortOptions_TypeDesc: + // cursor = mongop.TypeDescCursorType + // } + // + // filter := convertor.FileFilterOptionsToFilterOptions(req.FilterOptions) + // p := convertor.ParsePagination(req.PaginationOptions) + // if req.SearchOptions == nil { + // if files, total, err2 = s.FileMongoMapper.FindManyAndCount(ctx, filter, p, cursor); err2 != nil { + // return err2 + // } + // } else { + // switch o := req.SearchOptions.Type.(type) { + // case *gencontent.SearchOptions_AllFieldsKey: + // files, total, err2 = s.FileEsMapper.Search(ctx, convertor.ConvertFileAllFieldsSearchQuery(o), filter, p, esp.ScoreCursorType) + // case *gencontent.SearchOptions_MultiFieldsKey: + // files, total, err2 = s.FileEsMapper.Search(ctx, convertor.ConvertFileMultiFieldsSearchQuery(o), filter, p, esp.ScoreCursorType) + // } + // if err2 != nil { + // log.CtxError(ctx, "搜索文件列表异常[%v]\n", err2) + // return err2 + // } + // } + // + // if p.LastToken != nil { + // resp.Token = *p.LastToken + // } + // resp.Total = total + // resp.Files = lo.Map[*filemapper.File, *gencontent.FileInfo](files, func(item *filemapper.File, _ int) *gencontent.FileInfo { + // return convertor.FileMapperToFile(item) + // }) + // return nil + //}); err != nil { + // return resp, err + //} return resp, nil } func (s *FileService) CheckShareFile(ctx context.Context, req *gencontent.CheckShareFileReq) (resp *gencontent.CheckShareFileResp, err error) { resp = new(gencontent.CheckShareFileResp) - var ( - err1 error - res *gencontent.GetFileResp - shareFiles []*filemapper.File - ) - // 检查文件是否在分享文件夹中, 查询分享链接中的所有根文件 - if err = mr.Finish(func() error { - if shareFiles, err1 = s.FileMongoMapper.FindManyByIds(ctx, req.FileIds); err1 != nil { - return err1 - } - shareFiles = lo.Filter(shareFiles, func(item *filemapper.File, _ int) bool { - switch item.IsDel { - case int64(gencontent.Deletion_Deletion_notDel): - return true - default: - return false - } - }) - return nil - }, func() error { - res, err1 = s.GetFile(ctx, &gencontent.GetFileReq{FileId: req.FileId, IsGetSize: false}) - return err1 - }); err != nil { - return resp, err - } - for _, file := range shareFiles { - if strings.HasPrefix(file.Path, res.File.Path) { - resp.Ok = true - break - } - } + //var ( + // err1 error + // res *gencontent.GetFileResp + // shareFiles []*filemapper.File + //) + //// 检查文件是否在分享文件夹中, 查询分享链接中的所有根文件 + //if err = mr.Finish(func() error { + // if shareFiles, err1 = s.FileMongoMapper.FindManyByIds(ctx, req.FileIds); err1 != nil { + // return err1 + // } + // shareFiles = lo.Filter(shareFiles, func(item *filemapper.File, _ int) bool { + // switch item.IsDel { + // case int64(gencontent.Deletion_Deletion_notDel): + // return true + // default: + // return false + // } + // }) + // return nil + //}, func() error { + // res, err1 = s.GetFile(ctx, &gencontent.GetFileReq{FileId: req.FileId, IsGetSize: false}) + // return err1 + //}); err != nil { + // return resp, err + //} + //for _, file := range shareFiles { + // if strings.HasPrefix(file.Path, res.File.Path) { + // resp.Ok = true + // break + // } + //} return resp, nil } func (s *FileService) GetFileBySharingCode(ctx context.Context, req *gencontent.GetFileBySharingCodeReq) (resp *gencontent.GetFileBySharingCodeResp, err error) { resp = new(gencontent.GetFileBySharingCodeResp) - switch { - case req.OnlyFatherId != nil: - var res *gencontent.CheckShareFileResp - var data *gencontent.GetFileListResp - if res, err = s.CheckShareFile(ctx, &gencontent.CheckShareFileReq{FileIds: req.FileIds, FileId: *req.OnlyFatherId}); err != nil { - return resp, err - } - if res.Ok { - if data, err = s.GetFileList(ctx, &gencontent.GetFileListReq{ - 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 - } - default: - var shareFiles []*filemapper.File - if shareFiles, err = s.FileMongoMapper.FindManyByIds(ctx, req.FileIds); err != nil { - return resp, err - } - resp.Files = lo.FilterMap[*filemapper.File, *gencontent.FileInfo](shareFiles, func(item *filemapper.File, _ int) (*gencontent.FileInfo, bool) { - switch item.IsDel { - case int64(gencontent.Deletion_Deletion_notDel): - return convertor.FileMapperToFile(item), true - default: - return nil, false - } - }) - resp.Total = int64(len(shareFiles)) - } + //switch { + //case req.OnlyFatherId != nil: + // var res *gencontent.CheckShareFileResp + // var data *gencontent.GetFileListResp + // if res, err = s.CheckShareFile(ctx, &gencontent.CheckShareFileReq{FileIds: req.FileIds, FileId: *req.OnlyFatherId}); err != nil { + // return resp, err + // } + // if res.Ok { + // if data, err = s.GetFileList(ctx, &gencontent.GetFileListReq{ + // 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 + // } + //default: + // var shareFiles []*filemapper.File + // if shareFiles, err = s.FileMongoMapper.FindManyByIds(ctx, req.FileIds); err != nil { + // return resp, err + // } + // resp.Files = lo.FilterMap[*filemapper.File, *gencontent.FileInfo](shareFiles, func(item *filemapper.File, _ int) (*gencontent.FileInfo, bool) { + // switch item.IsDel { + // case int64(gencontent.Deletion_Deletion_notDel): + // return convertor.FileMapperToFile(item), true + // default: + // return nil, false + // } + // }) + // resp.Total = int64(len(shareFiles)) + //} return resp, nil } @@ -311,177 +305,177 @@ func (s *FileService) GetFolderSize(ctx context.Context, path string) (resp int6 func (s *FileService) CreateFile(ctx context.Context, req *gencontent.CreateFileReq) (resp *gencontent.CreateFileResp, err error) { resp = new(gencontent.CreateFileResp) - resp.FileId, resp.Name, err = s.FileMongoMapper.Insert(ctx, convertor.FileToFileMapper(req.File)) - if err != nil { - return resp, err - } + //resp.FileId, resp.Name, err = s.FileMongoMapper.Insert(ctx, convertor.FileToFileMapper(req.File)) + //if err != nil { + // return resp, err + //} return resp, nil } func (s *FileService) UpdateFile(ctx context.Context, req *gencontent.UpdateFileReq) (resp *gencontent.UpdateFileResp, err error) { resp = new(gencontent.UpdateFileResp) - data := convertor.FileToFileMapper(req.File) - if _, err = s.FileMongoMapper.Update(ctx, data); err != nil { - return resp, err - } - resp.Name = data.Name + //data := convertor.FileToFileMapper(req.File) + //if _, err = s.FileMongoMapper.Update(ctx, data); err != nil { + // return resp, err + //} + //resp.Name = data.Name return resp, nil } func (s *FileService) MoveFile(ctx context.Context, req *gencontent.MoveFileReq) (resp *gencontent.MoveFileResp, err error) { resp = new(gencontent.MoveFileResp) - var oid primitive.ObjectID - if oid, err = primitive.ObjectIDFromHex(req.FileId); err != nil { - return resp, consts.ErrInvalidId - } - tx := s.FileMongoMapper.StartClient() - err = tx.UseSession(ctx, func(sessionContext mongo.SessionContext) error { - if err = sessionContext.StartTransaction(); err != nil { - return err - } - if req.SpaceSize == int64(gencontent.Folder_Folder_Size) { // 如果是文件夹 - var data []*filemapper.File - filter := bson.M{"path": bson.M{"$regex": "^" + req.OldPath + "/"}} // 匹配该文件夹的所有子文件 - if err = s.FileMongoMapper.GetConn().Find(sessionContext, &data, filter); err != nil { - return err - } - for _, v := range data { - if _, err = s.FileMongoMapper.Update(sessionContext, &filemapper.File{ID: v.ID, Path: req.NewPath + v.Path[len(req.OldPath)-len(req.FileId)-1:]}); err != nil { - if rbErr := sessionContext.AbortTransaction(sessionContext); rbErr != nil { - log.CtxError(ctx, "移动文件中产生错误[%v]: 回滚异常[%v]\n", err, rbErr) - } - return err - } - } - } - if _, err = s.FileMongoMapper.FindAndUpdate(sessionContext, &filemapper.File{ID: oid, Name: req.Name, Path: req.NewPath + "/" + oid.Hex(), FatherId: req.FatherId, IsDel: req.IsDel}); err != nil { - if rbErr := sessionContext.AbortTransaction(sessionContext); rbErr != nil { - log.CtxError(ctx, "移动文件中产生错误[%v]: 回滚异常[%v]\n", err, rbErr) - } - return err - } - if err = sessionContext.CommitTransaction(sessionContext); err != nil { - log.CtxError(ctx, "移动文件: 提交事务异常[%v]\n", err) - return err - } - return nil - }) + //var oid primitive.ObjectID + //if oid, err = primitive.ObjectIDFromHex(req.FileId); err != nil { + // return resp, consts.ErrInvalidId + //} + //tx := s.FileMongoMapper.StartClient() + //err = tx.UseSession(ctx, func(sessionContext mongo.SessionContext) error { + // if err = sessionContext.StartTransaction(); err != nil { + // return err + // } + // if req.SpaceSize == int64(gencontent.Folder_Folder_Size) { // 如果是文件夹 + // var data []*filemapper.File + // filter := bson.M{"path": bson.M{"$regex": "^" + req.OldPath + "/"}} // 匹配该文件夹的所有子文件 + // if err = s.FileMongoMapper.GetConn().Find(sessionContext, &data, filter); err != nil { + // return err + // } + // for _, v := range data { + // if _, err = s.FileMongoMapper.Update(sessionContext, &filemapper.File{ID: v.ID, Path: req.NewPath + v.Path[len(req.OldPath)-len(req.FileId)-1:]}); err != nil { + // if rbErr := sessionContext.AbortTransaction(sessionContext); rbErr != nil { + // log.CtxError(ctx, "移动文件中产生错误[%v]: 回滚异常[%v]\n", err, rbErr) + // } + // return err + // } + // } + // } + // if _, err = s.FileMongoMapper.FindAndUpdate(sessionContext, &filemapper.File{ID: oid, Name: req.Name, Path: req.NewPath + "/" + oid.Hex(), FatherId: req.FatherId, IsDel: req.IsDel}); err != nil { + // if rbErr := sessionContext.AbortTransaction(sessionContext); rbErr != nil { + // log.CtxError(ctx, "移动文件中产生错误[%v]: 回滚异常[%v]\n", err, rbErr) + // } + // return err + // } + // if err = sessionContext.CommitTransaction(sessionContext); err != nil { + // log.CtxError(ctx, "移动文件: 提交事务异常[%v]\n", err) + // return err + // } + // return nil + //}) return resp, err } func (s *FileService) CompletelyRemoveFile(ctx context.Context, req *gencontent.CompletelyRemoveFileReq) (resp *gencontent.CompletelyRemoveFileResp, err error) { resp = new(gencontent.CompletelyRemoveFileResp) - ids := make([]string, 0, s.Config.InitialSliceLength) - tx := s.FileMongoMapper.StartClient() - err = tx.UseSession(ctx, func(sessionContext mongo.SessionContext) error { - if err = sessionContext.StartTransaction(); err != nil { - return err - } - for _, file := range req.Files { - ids = append(ids, file.FileId) - if file.SpaceSize == 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 { - return err - } - for _, v := range data { - ids = append(ids, v.ID.Hex()) - } - } - } - if _, err = s.FileMongoMapper.DeleteMany(sessionContext, ids); err != nil { - if rbErr := sessionContext.AbortTransaction(sessionContext); rbErr != nil { - log.CtxError(ctx, "删除文件过程中产生错误[%v]: 回滚异常[%v]\n", err, rbErr) - } - return err - } - if err = sessionContext.CommitTransaction(sessionContext); err != nil { - log.CtxError(ctx, "删除文件: 提交事务异常[%v]\n", err) - return err - } - return nil - }) - - data, _ := sonic.Marshal(&message.DeleteFileRelationsMessage{ - FromType: int64(gencontent.TargetType_UserType), - FromIds: ids, - }) - - if err2 := s.DeleteFileRelationKq.Push(pconvertor.Bytes2String(data)); err2 != nil { - return resp, err2 - } + //ids := make([]string, 0, s.Config.InitialSliceLength) + //tx := s.FileMongoMapper.StartClient() + //err = tx.UseSession(ctx, func(sessionContext mongo.SessionContext) error { + // if err = sessionContext.StartTransaction(); err != nil { + // return err + // } + // for _, file := range req.Files { + // ids = append(ids, file.FileId) + // if file.SpaceSize == 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 { + // return err + // } + // for _, v := range data { + // ids = append(ids, v.ID.Hex()) + // } + // } + // } + // if _, err = s.FileMongoMapper.DeleteMany(sessionContext, ids); err != nil { + // if rbErr := sessionContext.AbortTransaction(sessionContext); rbErr != nil { + // log.CtxError(ctx, "删除文件过程中产生错误[%v]: 回滚异常[%v]\n", err, rbErr) + // } + // return err + // } + // if err = sessionContext.CommitTransaction(sessionContext); err != nil { + // log.CtxError(ctx, "删除文件: 提交事务异常[%v]\n", err) + // return err + // } + // return nil + //}) + // + //data, _ := sonic.Marshal(&message.DeleteFileRelationsMessage{ + // FromType: int64(gencontent.TargetType_UserType), + // FromIds: ids, + //}) + // + //if err2 := s.DeleteFileRelationKq.Push(pconvertor.Bytes2String(data)); err2 != nil { + // return resp, err2 + //} return resp, nil } func (s *FileService) DeleteFile(ctx context.Context, req *gencontent.DeleteFileReq) (resp *gencontent.DeleteFileResp, err error) { resp = new(gencontent.DeleteFileResp) - update := bson.M{} - switch req.DeleteType { - case int64(gencontent.Deletion_Deletion_softDel): - update["$set"] = bson.M{ - consts.IsDel: int64(gencontent.Deletion_Deletion_softDel), - consts.DeletedAt: time.Now(), - } - case int64(gencontent.Deletion_Deletion_hardDel): - update["$set"] = bson.M{ - consts.IsDel: int64(gencontent.Deletion_Deletion_hardDel), - } - default: - return resp, consts.ErrInvalidDeleteType - } - if req.ClearCommunity || req.DeleteType == int64(gencontent.Deletion_Deletion_hardDel) { - update["$unset"] = bson.M{ - consts.Zone: "", - consts.SubZone: "", - consts.Description: "", - consts.Labels: "", - } - } - ids := make([]string, 0, s.Config.InitialSliceLength) - tx := s.FileMongoMapper.StartClient() - err = tx.UseSession(ctx, func(sessionContext mongo.SessionContext) error { - if err = sessionContext.StartTransaction(); err != nil { - return err - } - for _, file := range req.Files { - ids = append(ids, file.FileId) - if file.SpaceSize == 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 { - return err - } - for _, v := range data { - ids = append(ids, v.ID.Hex()) - } - } - } - if _, err = s.FileMongoMapper.UpdateMany(sessionContext, ids, update); err != nil { - if rbErr := sessionContext.AbortTransaction(sessionContext); rbErr != nil { - log.CtxError(ctx, "删除文件过程中产生错误[%v]: 回滚异常[%v]\n", err, rbErr) - } - return err - } - if err = sessionContext.CommitTransaction(sessionContext); err != nil { - log.CtxError(ctx, "删除文件: 提交事务异常[%v]\n", err) - return err - } - return nil - }) - - if req.DeleteType == int64(gencontent.Deletion_Deletion_hardDel) || req.ClearCommunity { - data, _ := sonic.Marshal(&message.DeleteFileRelationsMessage{ - FromType: int64(gencontent.TargetType_UserType), - FromIds: ids, - }) - - if err2 := s.DeleteFileRelationKq.Push(pconvertor.Bytes2String(data)); err2 != nil { - return resp, err2 - } - } + //update := bson.M{} + //switch req.DeleteType { + //case int64(gencontent.Deletion_Deletion_softDel): + // update["$set"] = bson.M{ + // consts.IsDel: int64(gencontent.Deletion_Deletion_softDel), + // consts.DeletedAt: time.Now(), + // } + //case int64(gencontent.Deletion_Deletion_hardDel): + // update["$set"] = bson.M{ + // consts.IsDel: int64(gencontent.Deletion_Deletion_hardDel), + // } + //default: + // return resp, consts.ErrInvalidDeleteType + //} + //if req.ClearCommunity || req.DeleteType == int64(gencontent.Deletion_Deletion_hardDel) { + // update["$unset"] = bson.M{ + // consts.Zone: "", + // consts.SubZone: "", + // consts.Description: "", + // consts.Labels: "", + // } + //} + //ids := make([]string, 0, s.Config.InitialSliceLength) + //tx := s.FileMongoMapper.StartClient() + //err = tx.UseSession(ctx, func(sessionContext mongo.SessionContext) error { + // if err = sessionContext.StartTransaction(); err != nil { + // return err + // } + // for _, file := range req.Files { + // ids = append(ids, file.FileId) + // if file.SpaceSize == 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 { + // return err + // } + // for _, v := range data { + // ids = append(ids, v.ID.Hex()) + // } + // } + // } + // if _, err = s.FileMongoMapper.UpdateMany(sessionContext, ids, update); err != nil { + // if rbErr := sessionContext.AbortTransaction(sessionContext); rbErr != nil { + // log.CtxError(ctx, "删除文件过程中产生错误[%v]: 回滚异常[%v]\n", err, rbErr) + // } + // return err + // } + // if err = sessionContext.CommitTransaction(sessionContext); err != nil { + // log.CtxError(ctx, "删除文件: 提交事务异常[%v]\n", err) + // return err + // } + // return nil + //}) + // + //if req.DeleteType == int64(gencontent.Deletion_Deletion_hardDel) || req.ClearCommunity { + // data, _ := sonic.Marshal(&message.DeleteFileRelationsMessage{ + // FromType: int64(gencontent.TargetType_UserType), + // FromIds: ids, + // }) + // + // if err2 := s.DeleteFileRelationKq.Push(pconvertor.Bytes2String(data)); err2 != nil { + // return resp, err2 + // } + //} return resp, nil } @@ -627,45 +621,45 @@ func (s *FileService) RecoverRecycleBinFile(ctx context.Context, req *gencontent func (s *FileService) GetShareList(ctx context.Context, req *gencontent.GetShareListReq) (resp *gencontent.GetShareListResp, err error) { resp = new(gencontent.GetShareListResp) - var ( - shareCodes []*sharefilemapper.ShareFile - total int64 - ) - p := convertor.ParsePagination(req.PaginationOptions) - if shareCodes, total, err = s.ShareFileMongoMapper.FindManyAndCount(ctx, convertor.ShareFileFilterOptionsToShareCodeOptions(req.ShareFileFilterOptions), - p, mongop.CreateAtDescCursorType); err != nil { - return resp, err - } - - if p.LastToken != nil { - resp.Token = *p.LastToken - } - resp.ShareCodes = lo.Map[*sharefilemapper.ShareFile, *gencontent.ShareCode](shareCodes, func(item *sharefilemapper.ShareFile, _ int) *gencontent.ShareCode { - return convertor.ShareFileToShareCode(item) - }) - resp.Total = total + //var ( + // shareCodes []*sharefilemapper.ShareFile + // total int64 + //) + //p := convertor.ParsePagination(req.PaginationOptions) + //if shareCodes, total, err = s.ShareFileMongoMapper.FindManyAndCount(ctx, convertor.ShareFileFilterOptionsToShareCodeOptions(req.ShareFileFilterOptions), + // p, mongop.CreateAtDescCursorType); err != nil { + // return resp, err + //} + // + //if p.LastToken != nil { + // resp.Token = *p.LastToken + //} + //resp.ShareCodes = lo.Map[*sharefilemapper.ShareFile, *gencontent.ShareCode](shareCodes, func(item *sharefilemapper.ShareFile, _ int) *gencontent.ShareCode { + // return convertor.ShareFileToShareCode(item) + //}) + //resp.Total = total return resp, nil } func (s *FileService) CreateShareCode(ctx context.Context, req *gencontent.CreateShareCodeReq) (resp *gencontent.CreateShareCodeResp, err error) { resp = new(gencontent.CreateShareCodeResp) - data := convertor.ShareFileToShareFileMapper(req.ShareFile) - data.CreateAt = time.Now() - if req.ShareFile.EffectiveTime >= 0 { - data.DeletedAt = data.CreateAt.Add(time.Duration(req.ShareFile.EffectiveTime)*time.Second + time.Duration(s.Config.DeletionCoolingOffPeriod)*time.Hour) - } - if resp.Code, resp.Key, err = s.ShareFileMongoMapper.Insert(ctx, data); err != nil { - return resp, err - } + //data := convertor.ShareFileToShareFileMapper(req.ShareFile) + //data.CreateAt = time.Now() + //if req.ShareFile.EffectiveTime >= 0 { + // data.DeletedAt = data.CreateAt.Add(time.Duration(req.ShareFile.EffectiveTime)*time.Second + time.Duration(s.Config.DeletionCoolingOffPeriod)*time.Hour) + //} + //if resp.Code, resp.Key, err = s.ShareFileMongoMapper.Insert(ctx, data); err != nil { + // return resp, err + //} return resp, nil } func (s *FileService) UpdateShareCode(ctx context.Context, req *gencontent.UpdateShareCodeReq) (resp *gencontent.UpdateShareCodeResp, err error) { - data := convertor.ShareFileToShareFileMapper(req.ShareFile) - if _, err = s.ShareFileMongoMapper.Update(ctx, data); err != nil { - return resp, err - } + //data := convertor.ShareFileToShareFileMapper(req.ShareFile) + //if _, err = s.ShareFileMongoMapper.Update(ctx, data); err != nil { + // return resp, err + //} return resp, nil } @@ -679,153 +673,153 @@ func (s *FileService) DeleteShareCode(ctx context.Context, req *gencontent.Delet func (s *FileService) ParsingShareCode(ctx context.Context, req *gencontent.ParsingShareCodeReq) (resp *gencontent.ParsingShareCodeResp, err error) { resp = new(gencontent.ParsingShareCodeResp) - var shareFile *sharefilemapper.ShareFile - if shareFile, err = s.ShareFileMongoMapper.FindOne(ctx, req.Code); err != nil { - return resp, err - } - res := convertor.ShareFileMapperToShareFile(shareFile) - resp.ShareFile = res + //var shareFile *sharefilemapper.ShareFile + //if shareFile, err = s.ShareFileMongoMapper.FindOne(ctx, req.Code); err != nil { + // return resp, err + //} + //res := convertor.ShareFileMapperToShareFile(shareFile) + //resp.ShareFile = res return resp, nil } func (s *FileService) SaveFileToPrivateSpace(ctx context.Context, req *gencontent.SaveFileToPrivateSpaceReq) (resp *gencontent.SaveFileToPrivateSpaceResp, err error) { resp = new(gencontent.SaveFileToPrivateSpaceResp) - type kv struct { - id string - path string - } - var err1 error - tx := s.FileMongoMapper.StartClient() - err = tx.UseSession(ctx, func(sessionContext mongo.SessionContext) error { - if err1 = sessionContext.StartTransaction(); err1 != nil { - return err1 - } - if resp.FileId, resp.Name, err1 = s.FileMongoMapper.FindAndInsert(sessionContext, &filemapper.File{ // 创建根文件 - UserId: req.UserId, - Name: req.Name, - Type: req.Type, - Path: req.NewPath, - FatherId: req.FatherId, - Size: req.SpaceSize, - FileMd5: req.FileMd5, - 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 req.SpaceSize == int64(gencontent.Folder_Folder_Size) { // 若是文件夹,开始根据原文件夹层层创建 - var front kv - queue := make([]kv, 0, s.Config.InitialSliceLength) - queue = append(queue, kv{id: req.FileId, path: req.NewPath + "/" + resp.FileId}) - for len(queue) > 0 { - front = queue[0] - queue = queue[1:] - var ids []string - var data []*filemapper.File - var filter bson.M - 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 == int64(gencontent.Space_Space_private) { - filter = bson.M{consts.FatherId: front.id} - } else { - if rbErr := sessionContext.AbortTransaction(sessionContext); rbErr != nil { - log.CtxError(ctx, "保存文件中产生错误[%v]: 回滚异常[%v]\n", "访问未知空间", rbErr) - } - return consts.ErrIllegalOperation - } - - if err1 = s.FileMongoMapper.GetConn().Find(sessionContext, &data, filter, &options.FindOptions{BatchSize: lo.ToPtr(int32(100))}); err1 != nil { - if rbErr := sessionContext.AbortTransaction(sessionContext); rbErr != nil { - log.CtxError(ctx, "保存文件中产生错误[%v]: 回滚异常[%v]\n", err1, rbErr) - return rbErr - } - } - - if len(data) <= 0 { - continue - } - - sonFiles := lo.Map(data, func(item *filemapper.File, _ int) *filemapper.File { - return &filemapper.File{ - UserId: req.UserId, - Name: item.Name, - Type: item.Type, - Path: front.path, - FatherId: front.path[len(front.path)-len(front.id):], - Size: item.Size, - FileMd5: item.FileMd5, - IsDel: int64(gencontent.Deletion_Deletion_notDel), - } - }) - - if ids, err1 = s.FileMongoMapper.FindAndInsertMany(sessionContext, sonFiles); err1 != nil { - if rbErr := sessionContext.AbortTransaction(sessionContext); rbErr != nil { - log.CtxError(ctx, "保存文件中产生错误[%v]: 回滚异常[%v]\n", err1, rbErr) - } - return err1 - } - - for i, v := range data { - if v.Size == int64(gencontent.Folder_Folder_Size) { - queue = append(queue, kv{id: v.ID.Hex(), path: front.path + "/" + ids[i]}) - } - } - } - } - - if err1 = sessionContext.CommitTransaction(sessionContext); err1 != nil { - log.CtxError(ctx, "保存文件: 提交事务异常[%v]\n", err1) - return err1 - } - return nil - }) + //type kv struct { + // id string + // path string + //} + //var err1 error + //tx := s.FileMongoMapper.StartClient() + //err = tx.UseSession(ctx, func(sessionContext mongo.SessionContext) error { + // if err1 = sessionContext.StartTransaction(); err1 != nil { + // return err1 + // } + // if resp.FileId, resp.Name, err1 = s.FileMongoMapper.FindAndInsert(sessionContext, &filemapper.File{ // 创建根文件 + // UserId: req.UserId, + // Name: req.Name, + // Type: req.Type, + // Path: req.NewPath, + // FatherId: req.FatherId, + // Size: req.SpaceSize, + // FileMd5: req.FileMd5, + // 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 req.SpaceSize == int64(gencontent.Folder_Folder_Size) { // 若是文件夹,开始根据原文件夹层层创建 + // var front kv + // queue := make([]kv, 0, s.Config.InitialSliceLength) + // queue = append(queue, kv{id: req.FileId, path: req.NewPath + "/" + resp.FileId}) + // for len(queue) > 0 { + // front = queue[0] + // queue = queue[1:] + // var ids []string + // var data []*filemapper.File + // var filter bson.M + // 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 == int64(gencontent.Space_Space_private) { + // filter = bson.M{consts.FatherId: front.id} + // } else { + // if rbErr := sessionContext.AbortTransaction(sessionContext); rbErr != nil { + // log.CtxError(ctx, "保存文件中产生错误[%v]: 回滚异常[%v]\n", "访问未知空间", rbErr) + // } + // return consts.ErrIllegalOperation + // } + // + // if err1 = s.FileMongoMapper.GetConn().Find(sessionContext, &data, filter, &options.FindOptions{BatchSize: lo.ToPtr(int32(100))}); err1 != nil { + // if rbErr := sessionContext.AbortTransaction(sessionContext); rbErr != nil { + // log.CtxError(ctx, "保存文件中产生错误[%v]: 回滚异常[%v]\n", err1, rbErr) + // return rbErr + // } + // } + // + // if len(data) <= 0 { + // continue + // } + // + // sonFiles := lo.Map(data, func(item *filemapper.File, _ int) *filemapper.File { + // return &filemapper.File{ + // UserId: req.UserId, + // Name: item.Name, + // Type: item.Type, + // Path: front.path, + // FatherId: front.path[len(front.path)-len(front.id):], + // Size: item.Size, + // FileMd5: item.FileMd5, + // IsDel: int64(gencontent.Deletion_Deletion_notDel), + // } + // }) + // + // if ids, err1 = s.FileMongoMapper.FindAndInsertMany(sessionContext, sonFiles); err1 != nil { + // if rbErr := sessionContext.AbortTransaction(sessionContext); rbErr != nil { + // log.CtxError(ctx, "保存文件中产生错误[%v]: 回滚异常[%v]\n", err1, rbErr) + // } + // return err1 + // } + // + // for i, v := range data { + // if v.Size == int64(gencontent.Folder_Folder_Size) { + // queue = append(queue, kv{id: v.ID.Hex(), path: front.path + "/" + ids[i]}) + // } + // } + // } + // } + // + // if err1 = sessionContext.CommitTransaction(sessionContext); err1 != nil { + // log.CtxError(ctx, "保存文件: 提交事务异常[%v]\n", err1) + // return err1 + // } + // return nil + //}) return resp, err } func (s *FileService) AddFileToPublicSpace(ctx context.Context, req *gencontent.AddFileToPublicSpaceReq) (resp *gencontent.AddFileToPublicSpaceResp, err error) { resp = new(gencontent.AddFileToPublicSpaceResp) - update := bson.M{ - "$set": bson.M{ - consts.AuditStatus: int64(gencontent.AuditStatus_AuditStatus_wait), - consts.Zone: req.Zone, - consts.SubZone: req.SubZone, - consts.Description: req.Description, - consts.Labels: req.Labels, - }, - } - ids := make([]string, 0, s.Config.InitialSliceLength) - tx := s.FileMongoMapper.StartClient() - err = tx.UseSession(ctx, func(sessionContext mongo.SessionContext) error { - if err = sessionContext.StartTransaction(); err != nil { - return err - } - ids = append(ids, req.FileId) - if req.SpaceSize == int64(gencontent.Folder_Folder_Size) { - var data []*filemapper.File - filter := bson.M{consts.Path: bson.M{"$regex": "^" + req.Path + "/"}} - if err = s.FileMongoMapper.GetConn().Find(sessionContext, &data, filter); err != nil { - return err - } - for _, v := range data { - ids = append(ids, v.ID.Hex()) - } - } - if _, err = s.FileMongoMapper.UpdateMany(sessionContext, ids, update); err != nil { - if rbErr := sessionContext.AbortTransaction(sessionContext); rbErr != nil { - log.CtxError(ctx, "上传文件到社区过程中产生错误[%v]: 回滚异常[%v]\n", err, rbErr) - } - return err - } - if err = sessionContext.CommitTransaction(sessionContext); err != nil { - log.CtxError(ctx, "上传文件到社区: 提交事务异常[%v]\n", err) - return err - } - return nil - }) - resp.FileIds = ids + //update := bson.M{ + // "$set": bson.M{ + // consts.AuditStatus: int64(gencontent.AuditStatus_AuditStatus_wait), + // consts.Zone: req.Zone, + // consts.SubZone: req.SubZone, + // consts.Description: req.Description, + // consts.Labels: req.Labels, + // }, + //} + //ids := make([]string, 0, s.Config.InitialSliceLength) + //tx := s.FileMongoMapper.StartClient() + //err = tx.UseSession(ctx, func(sessionContext mongo.SessionContext) error { + // if err = sessionContext.StartTransaction(); err != nil { + // return err + // } + // ids = append(ids, req.FileId) + // if req.SpaceSize == int64(gencontent.Folder_Folder_Size) { + // var data []*filemapper.File + // filter := bson.M{consts.Path: bson.M{"$regex": "^" + req.Path + "/"}} + // if err = s.FileMongoMapper.GetConn().Find(sessionContext, &data, filter); err != nil { + // return err + // } + // for _, v := range data { + // ids = append(ids, v.ID.Hex()) + // } + // } + // if _, err = s.FileMongoMapper.UpdateMany(sessionContext, ids, update); err != nil { + // if rbErr := sessionContext.AbortTransaction(sessionContext); rbErr != nil { + // log.CtxError(ctx, "上传文件到社区过程中产生错误[%v]: 回滚异常[%v]\n", err, rbErr) + // } + // return err + // } + // if err = sessionContext.CommitTransaction(sessionContext); err != nil { + // log.CtxError(ctx, "上传文件到社区: 提交事务异常[%v]\n", err) + // return err + // } + // return nil + //}) + //resp.FileIds = ids return resp, err } diff --git a/biz/application/service/post.go b/biz/application/service/post.go index 646fd81..fbd1489 100644 --- a/biz/application/service/post.go +++ b/biz/application/service/post.go @@ -5,7 +5,6 @@ import ( "github.com/CloudStriver/cloudmind-content/biz/infrastructure/config" "github.com/CloudStriver/cloudmind-content/biz/infrastructure/convertor" postmapper "github.com/CloudStriver/cloudmind-content/biz/infrastructure/mapper/post" - "github.com/CloudStriver/go-pkg/utils/pagination/esp" "github.com/CloudStriver/go-pkg/utils/pagination/mongop" "github.com/CloudStriver/go-pkg/utils/pconvertor" gencontent "github.com/CloudStriver/service-idl-gen-go/kitex_gen/cloudmind/content" @@ -92,9 +91,9 @@ func (s *PostService) GetPosts(ctx context.Context, req *gencontent.GetPostsReq) p := pconvertor.PaginationOptionsToModelPaginationOptions(req.PaginationOptions) filter := convertor.PostFilterOptionsToFilterOptions(req.PostFilterOptions) - if req.SearchKeyword != nil { - posts, total, err = s.PostEsMapper.Search(ctx, convertor.ConvertPostAllFieldsSearchQuery(*req.SearchKeyword), - filter, p, esp.ScoreCursorType) + if req.SearchOption != nil { + posts, total, err = s.PostEsMapper.Search(ctx, convertor.ConvertPostAllFieldsSearchQuery(*req.SearchOption.SearchKeyword), + filter, p, req.SearchOption.SearchSortType) } else { posts, total, err = s.PostMongoMapper.FindManyAndCount(ctx, filter, p, mongop.IdCursorType) diff --git a/biz/application/service/zone.go b/biz/application/service/zone.go deleted file mode 100644 index 207152d..0000000 --- a/biz/application/service/zone.go +++ /dev/null @@ -1,83 +0,0 @@ -package service - -import ( - "context" - "github.com/CloudStriver/cloudmind-content/biz/infrastructure/convertor" - zonemapper "github.com/CloudStriver/cloudmind-content/biz/infrastructure/mapper/zone" - "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/google/wire" - "github.com/samber/lo" -) - -type IZoneService interface { - GetZone(ctx context.Context, req *gencontent.GetZoneReq) (*gencontent.GetZoneResp, error) - GetZones(ctx context.Context, req *gencontent.GetZonesReq) (*gencontent.GetZonesResp, error) - CreateZone(ctx context.Context, req *gencontent.CreateZoneReq) (*gencontent.CreateZoneResp, error) - UpdateZone(ctx context.Context, req *gencontent.UpdateZoneReq) (*gencontent.UpdateZoneResp, error) - DeleteZone(ctx context.Context, req *gencontent.DeleteZoneReq) (*gencontent.DeleteZoneResp, error) -} - -type ZoneService struct { - ZoneMongoMapper zonemapper.IMongoMapper -} - -var ZoneSet = wire.NewSet( - wire.Struct(new(ZoneService), "*"), - wire.Bind(new(IZoneService), new(*ZoneService)), -) - -func (s *ZoneService) GetZone(ctx context.Context, req *gencontent.GetZoneReq) (resp *gencontent.GetZoneResp, err error) { - resp = new(gencontent.GetZoneResp) - zone, err := s.ZoneMongoMapper.FindOne(ctx, req.Id) - if err != nil { - return resp, err - } - resp.Zone = convertor.ZoneMapperToZone(zone) - return resp, nil -} - -func (s *ZoneService) GetZones(ctx context.Context, req *gencontent.GetZonesReq) (resp *gencontent.GetZonesResp, err error) { - resp = new(gencontent.GetZonesResp) - var total int64 - var zones []*zonemapper.Zone - p := convertor.ParsePagination(req.PaginationOptions) - if zones, total, err = s.ZoneMongoMapper.FindManyAndCount(ctx, req.FatherId, p, mongop.IdCursorType); err != nil { - log.CtxError(ctx, "查询文件列表: 发生异常[%v]\n", err) - return resp, err - } - - if p.LastToken != nil { - resp.Token = *p.LastToken - } - resp.Total = total - resp.Zones = lo.Map[*zonemapper.Zone, *gencontent.Zone](zones, func(item *zonemapper.Zone, _ int) *gencontent.Zone { - return convertor.ZoneMapperToZone(item) - }) - return resp, nil -} - -func (s *ZoneService) CreateZone(ctx context.Context, req *gencontent.CreateZoneReq) (resp *gencontent.CreateZoneResp, err error) { - resp = new(gencontent.CreateZoneResp) - if resp.Id, err = s.ZoneMongoMapper.Insert(ctx, convertor.ZoneToZoneMapper(req.Zone)); err != nil { - return nil, err - } - return resp, nil -} - -func (s *ZoneService) UpdateZone(ctx context.Context, req *gencontent.UpdateZoneReq) (resp *gencontent.UpdateZoneResp, err error) { - resp = new(gencontent.UpdateZoneResp) - if err = s.ZoneMongoMapper.Update(ctx, convertor.ZoneToZoneMapper(req.Zone)); err != nil { - return resp, err - } - return resp, nil -} - -func (s *ZoneService) DeleteZone(ctx context.Context, req *gencontent.DeleteZoneReq) (resp *gencontent.DeleteZoneResp, err error) { - resp = new(gencontent.DeleteZoneResp) - if _, err = s.ZoneMongoMapper.Delete(ctx, req.Id); err != nil { - return resp, err - } - return resp, nil -} diff --git a/biz/infrastructure/convertor/convertor.go b/biz/infrastructure/convertor/convertor.go index 463e1df..f19efcd 100644 --- a/biz/infrastructure/convertor/convertor.go +++ b/biz/infrastructure/convertor/convertor.go @@ -9,7 +9,6 @@ import ( productmapper "github.com/CloudStriver/cloudmind-content/biz/infrastructure/mapper/product" "github.com/CloudStriver/cloudmind-content/biz/infrastructure/mapper/sharefile" usermapper "github.com/CloudStriver/cloudmind-content/biz/infrastructure/mapper/user" - labelmapper "github.com/CloudStriver/cloudmind-content/biz/infrastructure/mapper/zone" "github.com/CloudStriver/go-pkg/utils/pagination" "github.com/CloudStriver/service-idl-gen-go/kitex_gen/basic" gencontent "github.com/CloudStriver/service-idl-gen-go/kitex_gen/cloudmind/content" @@ -34,47 +33,47 @@ func UserMapperToUser(in *usermapper.User) *gencontent.User { } } -func FileMapperToFile(data *file.File) *gencontent.FileInfo { - return &gencontent.FileInfo{ - FileId: data.ID.Hex(), - UserId: data.UserId, - Name: data.Name, - Type: data.Type, - Path: data.Path, - FatherId: data.FatherId, - SpaceSize: data.Size, - Md5: data.FileMd5, - IsDel: data.IsDel, - Zone: data.Zone, - SubZone: data.SubZone, - Description: data.Description, - AuditStatus: data.AuditStatus, - Labels: data.Labels, - CreateAt: data.CreateAt.UnixMilli(), - UpdateAt: data.UpdateAt.UnixMilli(), - } -} - -func FileToFileMapper(data *gencontent.File) *file.File { - oid, _ := primitive.ObjectIDFromHex(data.FileId) - return &file.File{ - ID: oid, - UserId: data.UserId, - Name: data.Name, - Type: data.Type, - Category: data.Category, - Path: data.Path, - FatherId: data.FatherId, - Size: data.SpaceSize, - FileMd5: data.Md5, - IsDel: data.IsDel, - Zone: data.Zone, - SubZone: data.SubZone, - Description: data.Description, - Labels: data.Labels, - AuditStatus: data.AuditStatus, - } -} +//func FileMapperToFile(data *file.File) *gencontent.FileInfo { +// return &gencontent.FileInfo{ +// FileId: data.ID.Hex(), +// UserId: data.UserId, +// Name: data.Name, +// Type: data.Type, +// Path: data.Path, +// FatherId: data.FatherId, +// SpaceSize: data.Size, +// Md5: data.FileMd5, +// IsDel: data.IsDel, +// Zone: data.Zone, +// SubZone: data.SubZone, +// Description: data.Description, +// AuditStatus: data.AuditStatus, +// Labels: data.Labels, +// CreateAt: data.CreateAt.UnixMilli(), +// UpdateAt: data.UpdateAt.UnixMilli(), +// } +//} + +//func FileToFileMapper(data *gencontent.File) *file.File { +// oid, _ := primitive.ObjectIDFromHex(data.FileId) +// return &file.File{ +// ID: oid, +// UserId: data.UserId, +// Name: data.Name, +// Type: data.Type, +// Category: data.Category, +// Path: data.Path, +// FatherId: data.FatherId, +// Size: data.SpaceSize, +// FileMd5: data.Md5, +// IsDel: data.IsDel, +// Zone: data.Zone, +// SubZone: data.SubZone, +// Description: data.Description, +// Labels: data.Labels, +// AuditStatus: data.AuditStatus, +// } +//} func IsExpired(ctime time.Time, effectiveTime int64) int64 { if effectiveTime < 0 { @@ -174,22 +173,22 @@ func ParsePagination(opts *basic.PaginationOptions) (p *pagination.PaginationOpt return } -func ZoneMapperToZone(data *labelmapper.Zone) *gencontent.Zone { - return &gencontent.Zone{ - Id: data.ID.Hex(), - FatherId: data.FatherId, - Value: data.Value, - } -} - -func ZoneToZoneMapper(data *gencontent.Zone) *labelmapper.Zone { - oid, _ := primitive.ObjectIDFromHex(data.Id) - return &labelmapper.Zone{ - ID: oid, - FatherId: data.FatherId, - Value: data.Value, - } -} +//func ZoneMapperToZone(data *labelmapper.Zone) *gencontent.Zone { +// return &gencontent.Zone{ +// Id: data.ID.Hex(), +// FatherId: data.FatherId, +// Value: data.Value, +// } +//} + +//func ZoneToZoneMapper(data *gencontent.Zone) *labelmapper.Zone { +// oid, _ := primitive.ObjectIDFromHex(data.Id) +// return &labelmapper.Zone{ +// ID: oid, +// FatherId: data.FatherId, +// Value: data.Value, +// } +//} func PostFilterOptionsToFilterOptions(in *gencontent.PostFilterOptions) *postmapper.FilterOptions { if in == nil { diff --git a/biz/infrastructure/mapper/post/es.go b/biz/infrastructure/mapper/post/es.go index c2fdac5..9a0964c 100644 --- a/biz/infrastructure/mapper/post/es.go +++ b/biz/infrastructure/mapper/post/es.go @@ -6,6 +6,9 @@ import ( "fmt" "github.com/CloudStriver/go-pkg/utils/pagination" "github.com/CloudStriver/go-pkg/utils/pagination/esp" + gencontent "github.com/CloudStriver/service-idl-gen-go/kitex_gen/cloudmind/content" + "github.com/elastic/go-elasticsearch/v8/typedapi/types/enums/multivaluemode" + "github.com/elastic/go-elasticsearch/v8/typedapi/types/enums/scoremode" "github.com/samber/lo" "log" "net/http" @@ -27,7 +30,7 @@ import ( type ( IEsMapper interface { - Search(ctx context.Context, query []types.Query, fopts *FilterOptions, popts *pagination.PaginationOptions, sorter esp.EsCursor) ([]*Post, int64, error) + Search(ctx context.Context, query []types.Query, fopts *FilterOptions, popts *pagination.PaginationOptions, sorter gencontent.SearchSortType) ([]*Post, int64, error) CountWithQuery(ctx context.Context, query []types.Query, fopts *FilterOptions) (int64, error) } @@ -76,27 +79,78 @@ func (m *EsMapper) CountWithQuery(ctx context.Context, query []types.Query, fopt return res.Count, nil } -func (m *EsMapper) Search(ctx context.Context, query []types.Query, fopts *FilterOptions, popts *pagination.PaginationOptions, sorter esp.EsCursor) ([]*Post, int64, error) { +func SortTypeToCursorType(sortType gencontent.SearchSortType) esp.EsCursor { + switch sortType { + case gencontent.SearchSortType_ScoreSearchSortType: + return esp.ScoreCursorType + case gencontent.SearchSortType_CreateTimeSearchSortType: + return esp.IdCursorType + case gencontent.SearchSortType_SynthesisSearchSortType: + return esp.ScoreCursorType + default: + return nil + } +} + +func (m *EsMapper) Search(ctx context.Context, query []types.Query, fopts *FilterOptions, popts *pagination.PaginationOptions, sorter gencontent.SearchSortType) ([]*Post, int64, error) { ctx, span := trace.TracerFromContext(ctx).Start(ctx, "elasticsearch/Search", oteltrace.WithTimestamp(time.Now()), oteltrace.WithSpanKind(oteltrace.SpanKindClient)) defer func() { span.End(oteltrace.WithTimestamp(time.Now())) }() - p := esp.NewEsPaginator(pagination.NewRawStore(sorter), popts) + p := esp.NewEsPaginator(pagination.NewRawStore(SortTypeToCursorType(sorter)), popts) filter := newPostFilter(fopts) s, sa, err := p.MakeSortOptions(ctx) if err != nil { return nil, 0, err } - res, err := m.es.Search().From(int(*popts.Offset)).Size(int(*popts.Limit)).Index(m.indexName).Request(&search.Request{ - Query: &types.Query{ - Bool: &types.BoolQuery{ - Must: query, - Filter: filter, + var req *search.Request + if sorter == gencontent.SearchSortType_SynthesisSearchSortType { + dateDecayFunc := types.NewDateDecayFunction() + decayPlacement := types.DecayPlacementDateMathDuration{ + Origin: lo.ToPtr("now"), // 衰减起点 + Scale: "2d", // 衰减尺度 + Offset: "1d", // 可选,定义不应用衰减的初始距离 + Decay: lo.ToPtr(types.Float64(0.5)), // 衰减率 + } + dateDecayFunc.DateDecayFunction[consts.CreateAt] = decayPlacement + dateDecayFunc.MultiValueMode = &multivaluemode.Avg + req = &search.Request{ + Query: &types.Query{ + Bool: &types.BoolQuery{ + Must: query, + Filter: filter, + }, }, - }, - SearchAfter: sa, - Sort: s, - }).Do(ctx) + Rescore: []types.Rescore{ + { + Query: types.RescoreQuery{ + Query: types.Query{ + FunctionScore: &types.FunctionScoreQuery{ + Functions: []types.FunctionScore{ + { + Gauss: dateDecayFunc, + }, + }, + }, + }, + ScoreMode: &scoremode.Multiply, + }, + }, + }, + } + } else { + req = &search.Request{ + Query: &types.Query{ + Bool: &types.BoolQuery{ + Must: query, + Filter: filter, + }, + }, + Sort: s, + SearchAfter: sa, + } + } + res, err := m.es.Search().From(int(*popts.Offset)).Size(int(*popts.Limit)).Index(m.indexName).Request(req).Do(ctx) if err != nil { return nil, 0, err } @@ -131,14 +185,16 @@ func (m *EsMapper) Search(ctx context.Context, query []types.Query, fopts *Filte post.Score_ = float64(hit.Score_) posts = append(posts, post) } - // 如果是反向查询,反转数据 - if *popts.Backward { - lo.Reverse(posts) - } - if len(posts) > 0 { - err = p.StoreCursor(ctx, posts[0], posts[len(posts)-1]) - if err != nil { - return nil, 0, err + if sorter != gencontent.SearchSortType_SynthesisSearchSortType { + // 如果是反向查询,反转数据 + if *popts.Backward { + lo.Reverse(posts) + } + if len(posts) > 0 { + err = p.StoreCursor(ctx, posts[0], posts[len(posts)-1]) + if err != nil { + return nil, 0, err + } } } return posts, total, nil diff --git a/go.mod b/go.mod index b6c9e1b..8cdac4b 100644 --- a/go.mod +++ b/go.mod @@ -5,7 +5,7 @@ go 1.20 require ( github.com/CloudStriver/cloudmind-mq v1.0.12-0.20240406143558-b7090c0fbb80 github.com/CloudStriver/go-pkg v0.0.0-20240329084540-20ca37a52fea - github.com/CloudStriver/service-idl-gen-go v0.0.0-20240408104721-1afd2da8f729 + github.com/CloudStriver/service-idl-gen-go v0.0.0-20240409124043-9373d87d4bde github.com/bytedance/sonic v1.10.2 github.com/cloudwego/kitex v0.8.0 github.com/elastic/go-elasticsearch/v8 v8.11.1 @@ -24,6 +24,7 @@ require ( ) //replace github.com/CloudStriver/service-idl-gen-go => ../service-idl-gen-go + //replace github.com/CloudStriver/cloudmind-mq => ../cloudmind-mq require ( @@ -62,7 +63,6 @@ require ( github.com/jhump/protoreflect v1.15.4 // indirect github.com/jinzhu/copier v0.4.0 // indirect github.com/json-iterator/go v1.1.12 // indirect - github.com/kitex-contrib/monitor-prometheus v0.2.0 // indirect github.com/klauspost/compress v1.16.7 // indirect github.com/klauspost/cpuid/v2 v2.2.4 // indirect github.com/mattn/go-colorable v0.1.13 // indirect diff --git a/go.sum b/go.sum index 422871b..df2ad8f 100644 --- a/go.sum +++ b/go.sum @@ -377,12 +377,8 @@ github.com/CloudStriver/cloudmind-mq v1.0.12-0.20240406143558-b7090c0fbb80 h1:M0 github.com/CloudStriver/cloudmind-mq v1.0.12-0.20240406143558-b7090c0fbb80/go.mod h1:LLq2w5YEUj8/wFzOIPz9kC1aBjSQr/dFivi16MBiz5Y= github.com/CloudStriver/go-pkg v0.0.0-20240329084540-20ca37a52fea h1:f+wmV1f8yaOsv9ei83oKG6kr4rbdtv3p0nPMKDZ8hUs= github.com/CloudStriver/go-pkg v0.0.0-20240329084540-20ca37a52fea/go.mod h1:SsAxWs5EIcaDE/0e5buoFOWsM4lTvFZhySkV68+RT3g= -github.com/CloudStriver/service-idl-gen-go v0.0.0-20240406140558-0b39494165c0 h1:y2ABwBsTxL6vmJFe5dbWw+uIsbK3hRXW3rkU14AoAlM= -github.com/CloudStriver/service-idl-gen-go v0.0.0-20240406140558-0b39494165c0/go.mod h1:chtR82RvfrjUujTGWROSCNAwF9Lh/U959k34bXIDvBI= -github.com/CloudStriver/service-idl-gen-go v0.0.0-20240408073658-4d6c3f470a3d h1:PHvVU9Tndk4cQAMqREmf5SNpLfEgjbmVSPJJXsk3zdg= -github.com/CloudStriver/service-idl-gen-go v0.0.0-20240408073658-4d6c3f470a3d/go.mod h1:chtR82RvfrjUujTGWROSCNAwF9Lh/U959k34bXIDvBI= -github.com/CloudStriver/service-idl-gen-go v0.0.0-20240408104721-1afd2da8f729 h1:Ba8osCuYP3i3+UYZpv29bqGk5K5okpVr84PkMRsdvr8= -github.com/CloudStriver/service-idl-gen-go v0.0.0-20240408104721-1afd2da8f729/go.mod h1:chtR82RvfrjUujTGWROSCNAwF9Lh/U959k34bXIDvBI= +github.com/CloudStriver/service-idl-gen-go v0.0.0-20240409124043-9373d87d4bde h1:DjXTGQT40LAcsuvGC10vRFhqLYvKVIGl729/m1kcdIw= +github.com/CloudStriver/service-idl-gen-go v0.0.0-20240409124043-9373d87d4bde/go.mod h1:chtR82RvfrjUujTGWROSCNAwF9Lh/U959k34bXIDvBI= github.com/DATA-DOG/go-sqlmock v1.5.0/go.mod h1:f/Ixk793poVmq4qj/V1dPUg2JEAKC73Q5eFN3EC/SaM= github.com/NYTimes/gziphandler v0.0.0-20170623195520-56545f4a5d46/go.mod h1:3wb06e3pkSAbeQ52E9H9iFoQsEEwGN64994WTCIhntQ= github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU= @@ -784,8 +780,6 @@ github.com/jung-kurt/gofpdf v1.0.0/go.mod h1:7Id9E/uU8ce6rXgefFLlgrJj/GYY22cpxn+ github.com/jung-kurt/gofpdf v1.0.3-0.20190309125859-24315acbbda5/go.mod h1:7Id9E/uU8ce6rXgefFLlgrJj/GYY22cpxn+r32jIOes= github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8= github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= -github.com/kitex-contrib/monitor-prometheus v0.2.0 h1:cgu8UMn1lpwLD/6rQZnf3jX98rqazTkY/ATmN9DsCwY= -github.com/kitex-contrib/monitor-prometheus v0.2.0/go.mod h1:ZHWQOKRHnN1Bw+PgVYeOXmB9l4+k8dlOJ9wx2xz76NU= github.com/kitex-contrib/obs-opentelemetry v0.2.5 h1:vV0rbEQnhv7gFPJJPAas4mvp0vopOUC3RU05pnXDOAw= github.com/kitex-contrib/obs-opentelemetry v0.2.5/go.mod h1:+Hfa6yIiSOIL364QSiUyWTQARkV1OI/NU527SKw+/kk= github.com/klauspost/compress v1.13.6/go.mod h1:/3/Vjq9QcHkK5uEr5lBEmyoZ1iFhe47etQ6QUkpK6sk= @@ -907,14 +901,12 @@ github.com/prometheus/client_golang v1.11.0/go.mod h1:Z6t4BnS23TR94PD6BsDNk8yVqr github.com/prometheus/client_golang v1.11.1/go.mod h1:Z6t4BnS23TR94PD6BsDNk8yVqroYurpAkEiz0P2BEV0= github.com/prometheus/client_golang v1.12.1/go.mod h1:3Z9XVyYiZYEO+YQWt3RD2R3jrbd179Rt297l4aS6nDY= github.com/prometheus/client_golang v1.13.0/go.mod h1:vTeo+zgvILHsnnj/39Ou/1fPN5nJFOEMgftOUOmlvYQ= -github.com/prometheus/client_golang v1.14.0/go.mod h1:8vpkKitgIVNcqrRBWh1C4TIUQgYNtG/XQE4E/Zae36Y= github.com/prometheus/client_golang v1.17.0 h1:rl2sfwZMtSthVU752MqfjQozy7blglC+1SOtjMAMh+Q= github.com/prometheus/client_golang v1.17.0/go.mod h1:VeL+gMmOAxkS2IqfCq0ZmHSL+LjWfWDUmp1mBz9JgUY= github.com/prometheus/client_model v0.0.0-20180712105110-5c3871d89910/go.mod h1:MbSGuTsp3dbXC40dX6PRTWyKYBIrTGTE9sqQNg2J8bo= github.com/prometheus/client_model v0.0.0-20190129233127-fd36f4220a90/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= github.com/prometheus/client_model v0.2.0/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= -github.com/prometheus/client_model v0.3.0/go.mod h1:LDGWKZIo7rky3hgvBe+caln+Dr3dPggB5dvjtD7w9+w= github.com/prometheus/client_model v0.4.1-0.20230718164431-9a2bf3000d16 h1:v7DLqVdK4VrYkVD5diGdl4sxJurKJEMnODWRJlxV9oM= github.com/prometheus/client_model v0.4.1-0.20230718164431-9a2bf3000d16/go.mod h1:oMQmHW1/JoDwqLtg57MGgP/Fb1CJEYF2imWWhWtMkYU= github.com/prometheus/common v0.4.1/go.mod h1:TNfzLD0ON7rHzMJeJkieUDPYmFC7Snx/y86RQel1bk4= diff --git a/provider/provider.go b/provider/provider.go index bed484e..8146c86 100644 --- a/provider/provider.go +++ b/provider/provider.go @@ -27,7 +27,6 @@ var AllProvider = wire.NewSet( var ApplicationSet = wire.NewSet( service.FileSet, service.PostSet, - service.ZoneSet, service.UserSet, service.CouponSet, service.ProductSet, diff --git a/provider/wire_gen.go b/provider/wire_gen.go index 8311583..ed5c126 100644 --- a/provider/wire_gen.go +++ b/provider/wire_gen.go @@ -20,7 +20,6 @@ import ( "github.com/CloudStriver/cloudmind-content/biz/infrastructure/mapper/product" "github.com/CloudStriver/cloudmind-content/biz/infrastructure/mapper/sharefile" "github.com/CloudStriver/cloudmind-content/biz/infrastructure/mapper/user" - "github.com/CloudStriver/cloudmind-content/biz/infrastructure/mapper/zone" "github.com/CloudStriver/cloudmind-content/biz/infrastructure/stores/cache" "github.com/CloudStriver/cloudmind-content/biz/infrastructure/stores/redis" ) @@ -52,10 +51,6 @@ func NewContentServerImpl() (*adaptor.ContentServerImpl, error) { PostEsMapper: iEsMapper, Redis: redisRedis, } - zoneIMongoMapper := zone.NewMongoMapper(configConfig) - zoneService := &service.ZoneService{ - ZoneMongoMapper: zoneIMongoMapper, - } iUserMongoMapper := user.NewMongoMapper(configConfig) iUserEsMapper := user.NewEsMapper(configConfig) userService := &service.UserService{ @@ -105,7 +100,6 @@ func NewContentServerImpl() (*adaptor.ContentServerImpl, error) { Config: configConfig, FileService: fileService, PostService: postService, - ZoneService: zoneService, UserService: userService, ProductService: productService, CouponService: couponService,