Browse Source

新增甲醇指标刷新

longyu 2 years ago
parent
commit
ae161664bc
3 changed files with 47 additions and 0 deletions
  1. 7 0
      init_serve/task.go
  2. 7 0
      models/index/index.go
  3. 33 0
      services/index.go

+ 7 - 0
init_serve/task.go

@@ -43,6 +43,13 @@ func InitTask() {
 		panic("DownloadCvTask err" + err.Error())
 		panic("DownloadCvTask err" + err.Error())
 	}
 	}
 
 
+	//单独刷新甲醇指标
+	_, err = c.AddFunc("0 00 18 * * *", services.IndexRefreshMethanol)
+	if err != nil {
+		global.LOG.Info("DownloadCvTask err" + err.Error())
+		panic("DownloadCvTask err" + err.Error())
+	}
+
 	_, err = c.AddFunc("0 */10 * * * *", services.Merge)
 	_, err = c.AddFunc("0 */10 * * * *", services.Merge)
 	if err != nil {
 	if err != nil {
 		global.LOG.Info("DownloadCvTask err" + err.Error())
 		global.LOG.Info("DownloadCvTask err" + err.Error())

+ 7 - 0
models/index/index.go

@@ -182,3 +182,10 @@ func (d *BaseFromMysteelChemicalIndex) GetMaxFileIndex(frequency string) (item *
 type IndexRefreshReq struct {
 type IndexRefreshReq struct {
 	MergeFilePath string `json:"MergeFilePath" binding:"required"` //指标编码
 	MergeFilePath string `json:"MergeFilePath" binding:"required"` //指标编码
 }
 }
+
+// GetIndexRefreshAllByMergeFile 根据合并文件去分组查询需要刷新的文件
+func (d *BaseFromMysteelChemicalIndex) GetIndexRefreshMethanolByMergeFile() (item []*BaseFromMysteelChemicalIndex, err error) {
+	err = global.MYSQL["hzdata"].WithContext(context.TODO()).Model(d).Where("merge_file_path != ? AND base_from_mysteel_chemical_classify_id IN(54,55,56,57) ", "").
+		Group("merge_file_path").Find(&item).Error
+	return
+}

+ 33 - 0
services/index.go

@@ -184,8 +184,41 @@ func IndexRefreshAll() {
 	if len(list) <= 0 {
 	if len(list) <= 0 {
 		return
 		return
 	}
 	}
+	now := time.Now()
 	for _, v := range list {
 	for _, v := range list {
 		time.Sleep(1 * time.Second)
 		time.Sleep(1 * time.Second)
+		if v.Frequency == "年度" && int(now.Month()) > 3 {
+			continue
+		}
+		if v.Frequency == "季度" {
+			continue
+		}
+		MysteelChemicalRefresh(v.MergeFilePath)
+	}
+	return
+}
+
+func IndexRefreshMethanol() {
+	fmt.Println("IndexRefreshMethanol")
+	indexObj := new(index.BaseFromMysteelChemicalIndex)
+	list, err := indexObj.GetIndexRefreshMethanolByMergeFile()
+	if err != nil {
+		fmt.Println("GetIndexRefreshAll Err:" + err.Error())
+		return
+	}
+	fmt.Println("listLen:", len(list))
+	if len(list) <= 0 {
+		return
+	}
+	now := time.Now()
+	for _, v := range list {
+		time.Sleep(1 * time.Second)
+		if v.Frequency == "年度" && int(now.Month()) > 3 {
+			continue
+		}
+		if v.Frequency == "季度" {
+			continue
+		}
 		MysteelChemicalRefresh(v.MergeFilePath)
 		MysteelChemicalRefresh(v.MergeFilePath)
 	}
 	}
 	return
 	return