浏览代码

新增获取周开始和结束日期

longyu 2 年之前
父节点
当前提交
928724445e
共有 3 个文件被更改,包括 27 次插入4 次删除
  1. 1 2
      controller/auth.go
  2. 4 1
      services/index.go
  3. 22 1
      utils/common.go

+ 1 - 2
controller/auth.go

@@ -6,10 +6,9 @@ import (
 )
 
 type AuthController struct {
-
 }
 
-func (a *AuthController) Login(c *gin.Context)  {
+func (a *AuthController) Login(c *gin.Context) {
 	resp.OkData("登录成功", nil, c)
 	return
 }

+ 4 - 1
services/index.go

@@ -150,6 +150,7 @@ func IndexRefreshAll() {
 		time.Sleep(1 * time.Second)
 		if v.Frequency == "周度" {
 			if v.UpdateWeek == "" && v.UpdateTime == "" && v.UpdateTime2 == "" {
+				//判断本周的数据是否已经存在
 				MysteelChemicalRefresh(v.FilePath)
 			}
 		} else if v.Frequency == "月度" || v.Frequency == "旬度" {
@@ -161,7 +162,9 @@ func IndexRefreshAll() {
 				MysteelChemicalRefresh(v.FilePath)
 			}
 		} else if v.Frequency == "日度" {
-			MysteelChemicalRefresh(v.FilePath)
+			if v.EndDate != nowDate {
+				MysteelChemicalRefresh(v.FilePath)
+			}
 		} else {
 			global.LOG.Info("无效频度:" + v.IndexCode + ";" + v.Frequency)
 		}

+ 22 - 1
utils/common.go

@@ -1046,4 +1046,25 @@ func GetWeekZn(updateWeek string) (week string) {
 		week = "周日"
 	}
 	return week
-}
+}
+
+func GetWeekDay() (string, string) {
+	now := time.Now()
+	offset := int(time.Monday - now.Weekday())
+	//周日做特殊判断 因为time.Monday = 0
+	if offset > 0 {
+		offset = -6
+	}
+
+	lastoffset := int(time.Saturday - now.Weekday())
+	//周日做特殊判断 因为time.Monday = 0
+	if lastoffset == 6 {
+		lastoffset = -1
+	}
+
+	firstOfWeek := time.Date(now.Year(), now.Month(), now.Day(), 0, 0, 0, 0, time.Local).AddDate(0, 0, offset)
+	lastOfWeeK := time.Date(now.Year(), now.Month(), now.Day(), 0, 0, 0, 0, time.Local).AddDate(0, 0, lastoffset+1)
+	f := firstOfWeek.Unix()
+	l := lastOfWeeK.Unix()
+	return time.Unix(f, 0).Format("2006-01-02") + " 00:00:00", time.Unix(l, 0).Format("2006-01-02") + " 23:59:59"
+}