path.go 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. package stringutil
  2. import (
  3. "Cold_Logistic/internal/pkg/common/constant"
  4. "Cold_Logistic/internal/pkg/common/options"
  5. "path"
  6. "strconv"
  7. "strings"
  8. "gogs.baozhida.cn/Cold_Logistic_libs/pkg/contrib/util/fileutil"
  9. "gogs.baozhida.cn/Cold_Logistic_libs/pkg/contrib/util/idutil"
  10. )
  11. func GenUploadKeyPath(fileName string) (keyPath string) {
  12. return path.Join(options.OptInstance.Storage.ProjectPrefixPath, constant.UploadPath, fileutil.GenYYYYMMDDPath(), strconv.FormatUint(idutil.GetIntID(), 10), fileName)
  13. }
  14. func GenUploadBasePath(suffix string) string {
  15. return path.Join(options.OptInstance.Storage.ProjectPrefixPath, constant.UploadPath, suffix)
  16. }
  17. func GenExportBasePath(suffix string) string {
  18. return path.Join(options.OptInstance.Storage.ProjectPrefixPath, constant.ExportPath, suffix)
  19. }
  20. func GenUploadKeyPathWithCategory(fileCategory, fileName string) (keyPath string) {
  21. fileCategory = strings.TrimSpace(fileCategory)
  22. if len(fileCategory) == 0 {
  23. return GenUploadKeyPath(fileName)
  24. }
  25. return path.Join(options.OptInstance.Storage.ProjectPrefixPath, constant.UploadPath, fileCategory, fileutil.GenYYYYMMDDPath(), strconv.FormatUint(idutil.GetIntID(), 10), fileName)
  26. }
  27. func GenExcelKeyPath(fileName string) (keyPath string) {
  28. return path.Join(options.OptInstance.Storage.ProjectPrefixPath, constant.ExcelPath, fileutil.GenYYYYMMDDPath(), strconv.FormatUint(idutil.GetIntID(), 10), fileName)
  29. }
  30. func GenLocalUploadPath(fileName string) (keyPath string) {
  31. return path.Join(options.OptInstance.Storage.LocalStorageOptions.RootFilePath, fileutil.GenYYYYMMDDPath(), strconv.FormatUint(idutil.GetIntID(), 10), fileName)
  32. }
  33. func GenLocalExportPath(fileCategory, fileName string) (keyPath string) {
  34. return path.Join(options.OptInstance.Storage.LocalStorageOptions.RootFilePath, constant.ExportPath, fileCategory, fileutil.GenYYYYMMDDPath(), strconv.FormatUint(idutil.GetIntID(), 10), fileName)
  35. }