蛋蛋星球-客户端
Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.
 
 
 
 
 
 

56 wiersze
1.8 KiB

  1. package svc
  2. import (
  3. "applet/app/db"
  4. "applet/app/utils"
  5. "applet/app/utils/cache"
  6. "applet/app/utils/logx"
  7. "code.fnuoos.com/EggPlanet/egg_models.git/src/implement"
  8. "strings"
  9. "time"
  10. )
  11. // 简单的recover
  12. func Rev() {
  13. if err := recover(); err != nil {
  14. _ = logx.Error(err)
  15. }
  16. }
  17. func GetOssUrl(img string) string {
  18. redisConn := cache.GetPool().Get()
  19. sysCfgDb := implement.NewSysCfgDb(db.Db, redisConn)
  20. sysCfg := sysCfgDb.SysCfgFindWithDb("file_bucket_scheme", "file_bucket_host")
  21. if strings.Contains(img, "http") == false && img != "" {
  22. img = sysCfg["file_bucket_scheme"] + "://" + sysCfg["file_bucket_host"] + img
  23. }
  24. return img
  25. }
  26. func GetSysCfgStr(key string) string {
  27. redisConn := cache.GetPool().Get()
  28. sysCfgDb := implement.NewSysCfgDb(db.Db, redisConn)
  29. return sysCfgDb.SysCfgGetWithDb(key)
  30. }
  31. // GetYearsAndWeekStr 获取年份和周数
  32. func GetYearsAndWeekStr(esIndexName string) (string, string) {
  33. parts := strings.Split(esIndexName, "_")
  34. return parts[len(parts)-1][:4], parts[len(parts)-1][4:]
  35. }
  36. // GetWeekInfo 获取周数、开始时间、结束时间
  37. func GetWeekInfo(dateStr string) (string, string, string, string) {
  38. date := utils.TimeParseStd(dateStr)
  39. year, week := date.ISOWeek()
  40. location, _ := time.LoadLocation("Asia/Shanghai")
  41. // 计算给定年份1月1日是星期几
  42. startOfYear := time.Date(year, time.January, 1, 0, 0, 0, 0, location)
  43. daysOffset := int(startOfYear.Weekday()) - int(time.Monday) + 1
  44. // 计算给定年份的第一周的开始日期
  45. firstWeekStart := startOfYear.AddDate(0, 0, -daysOffset+1)
  46. // 计算给定周的开始日期
  47. weekStart := firstWeekStart.AddDate(0, 0, (week-1)*7)
  48. weekEnd := weekStart.AddDate(0, 0, 6)
  49. return utils.IntToStr(year), utils.IntToStr(week), weekStart.Format("2006-01-02"), weekEnd.Format("2006-01-02")
  50. }