package svc import ( "applet/app/db" "applet/app/utils" "applet/app/utils/cache" "applet/app/utils/logx" "code.fnuoos.com/EggPlanet/egg_models.git/src/implement" "strings" "time" ) // 简单的recover func Rev() { if err := recover(); err != nil { _ = logx.Error(err) } } func GetOssUrl(img string) string { redisConn := cache.GetPool().Get() sysCfgDb := implement.NewSysCfgDb(db.Db, redisConn) sysCfg := sysCfgDb.SysCfgFindWithDb("file_bucket_scheme", "file_bucket_host") if strings.Contains(img, "http") == false && img != "" { img = sysCfg["file_bucket_scheme"] + "://" + sysCfg["file_bucket_host"] + img } return img } func GetSysCfgStr(key string) string { redisConn := cache.GetPool().Get() sysCfgDb := implement.NewSysCfgDb(db.Db, redisConn) return sysCfgDb.SysCfgGetWithDb(key) } // GetYearsAndWeekStr 获取年份和周数 func GetYearsAndWeekStr(esIndexName string) (string, string) { parts := strings.Split(esIndexName, "_") return parts[len(parts)-1][:4], parts[len(parts)-1][4:] } // GetWeekInfo 获取周数、开始时间、结束时间 func GetWeekInfo(dateStr string) (string, string, string, string) { date := utils.TimeParseStd(dateStr) year, week := date.ISOWeek() location, _ := time.LoadLocation("Asia/Shanghai") // 计算给定年份1月1日是星期几 startOfYear := time.Date(year, time.January, 1, 0, 0, 0, 0, location) daysOffset := int(startOfYear.Weekday()) - int(time.Monday) + 1 // 计算给定年份的第一周的开始日期 firstWeekStart := startOfYear.AddDate(0, 0, -daysOffset+1) // 计算给定周的开始日期 weekStart := firstWeekStart.AddDate(0, 0, (week-1)*7) weekEnd := weekStart.AddDate(0, 0, 6) return utils.IntToStr(year), utils.IntToStr(week), weekStart.Format("2006-01-02"), weekEnd.Format("2006-01-02") }