Bladeren bron

优化数据刷新

longyu 2 jaren geleden
bovenliggende
commit
557724161c
4 gewijzigde bestanden met toevoegingen van 64 en 26 verwijderingen
  1. 1 7
      init_serve/task.go
  2. 1 1
      models/index/index.go
  3. 49 14
      services/index.go
  4. 13 4
      watch/watch.go

+ 1 - 7
init_serve/task.go

@@ -30,13 +30,6 @@ func InitTask() {
 	//	panic("DownloadCvTask err" + err.Error())
 	//}
 
-	//其他指标刷新
-	_, err = c.AddFunc("0 30 12 * * *", services.IndexRefreshAll)
-	if err != nil {
-		global.LOG.Info("DownloadCvTask err" + err.Error())
-		panic("DownloadCvTask err" + err.Error())
-	}
-
 	_, err = c.AddFunc("0 00 17 * * *", services.IndexRefreshAll)
 	if err != nil {
 		global.LOG.Info("DownloadCvTask err" + err.Error())
@@ -79,6 +72,7 @@ func InitTask() {
 	//services.DataAnalysis(filePath)
 
 	//services.Merge()
+
 	fmt.Println("end services.Merge")
 }
 

+ 1 - 1
models/index/index.go

@@ -96,7 +96,7 @@ func (d *BaseFromMysteelChemicalIndex) GetIndexRefreshAll() (item []*BaseFromMys
 
 // GetIndexRefreshAllByMergeFile 根据合并文件去分组查询需要刷新的文件
 func (d *BaseFromMysteelChemicalIndex) GetIndexRefreshAllByMergeFile() (item []*BaseFromMysteelChemicalIndex, err error) {
-	err = global.MYSQL["hzdata"].WithContext(context.TODO()).Model(d).Where("merge_file_path != ? ", "").
+	err = global.MYSQL["hzdata"].WithContext(context.TODO()).Model(d).Where("merge_file_path != ? AND base_from_mysteel_chemical_classify_id NOT IN(54,55,56,57) ", "").
 		Group("merge_file_path").Find(&item).Error
 	return
 }

+ 49 - 14
services/index.go

@@ -185,15 +185,33 @@ func IndexRefreshAll() {
 		return
 	}
 	now := time.Now()
+	month := int(now.Month())
+	day := now.Day()
+	week := int(now.Weekday())
+
 	for _, v := range list {
-		time.Sleep(1 * time.Second)
-		if v.Frequency == "年度" && int(now.Month()) > 3 {
-			continue
-		}
-		if v.Frequency == "季度" {
-			continue
+		time.Sleep(3 * time.Second)
+		if v.Frequency == "年度" {
+			if month == 1 && day == 1 {
+				MysteelChemicalRefresh(v.MergeFilePath)
+			}
+		} else if v.Frequency == "季度" {
+			if (month == 1 || month == 4 || month == 7 || month == 10) && day == 1 {
+				MysteelChemicalRefresh(v.MergeFilePath)
+			}
+		} else if v.Frequency == "月度" {
+			if day == 1 {
+				MysteelChemicalRefresh(v.MergeFilePath)
+			}
+		} else if v.Frequency == "周度" {
+			if week > 2 && week < 6 {
+				MysteelChemicalRefresh(v.MergeFilePath)
+			}
+		} else {
+			if week < 6 {
+				MysteelChemicalRefresh(v.MergeFilePath)
+			}
 		}
-		MysteelChemicalRefresh(v.MergeFilePath)
 	}
 	return
 }
@@ -211,15 +229,32 @@ func IndexRefreshMethanol() {
 		return
 	}
 	now := time.Now()
+	month := int(now.Month())
+	day := now.Day()
+	week := int(now.Weekday())
 	for _, v := range list {
-		time.Sleep(1 * time.Second)
-		if v.Frequency == "年度" && int(now.Month()) > 3 {
-			continue
-		}
-		if v.Frequency == "季度" {
-			continue
+		time.Sleep(3 * time.Second)
+		if v.Frequency == "年度" {
+			if month == 1 && day == 1 {
+				MysteelChemicalRefresh(v.MergeFilePath)
+			}
+		} else if v.Frequency == "季度" {
+			if (month == 1 || month == 4 || month == 7 || month == 10) && day == 1 {
+				MysteelChemicalRefresh(v.MergeFilePath)
+			}
+		} else if v.Frequency == "月度" {
+			if day == 1 {
+				MysteelChemicalRefresh(v.MergeFilePath)
+			}
+		} else if v.Frequency == "周度" {
+			if week > 2 && week < 6 {
+				MysteelChemicalRefresh(v.MergeFilePath)
+			}
+		} else {
+			if week < 6 {
+				MysteelChemicalRefresh(v.MergeFilePath)
+			}
 		}
-		MysteelChemicalRefresh(v.MergeFilePath)
 	}
 	return
 }

+ 13 - 4
watch/watch.go

@@ -4,8 +4,8 @@ import (
 	"encoding/json"
 	"fmt"
 	"hongze/mysteel_watch/global"
-	"hongze/mysteel_watch/models/index"
 	"hongze/mysteel_watch/models"
+	"hongze/mysteel_watch/models/index"
 	"hongze/mysteel_watch/utils"
 	"io/ioutil"
 	"log"
@@ -141,7 +141,7 @@ func WatchIndexFile(filePath string) {
 		sheetList := f.GetSheetList()
 		for _, sv := range sheetList {
 
-			var indexName, indexCode, unit, source, frequency, startDate, endDate, describe string
+			var indexName, indexCode, unit, source, frequency, startDate, endDate, describe, updateDate string
 			var indexId int64
 			rows, err := f.GetRows(sv)
 			if err != nil {
@@ -186,6 +186,10 @@ func WatchIndexFile(filePath string) {
 								if rk == 7 {
 									describe = colCell
 								}
+
+								if rk == 9 {
+									updateDate = colCell
+								}
 							}
 						}
 
@@ -320,6 +324,7 @@ func WatchIndexFile(filePath string) {
 							dataItem.IndexCode = indexCode
 							dataItem.DataTime = dateTime
 							dataItem.Value = value
+							dataItem.UpdateDate = updateDate
 							dataItem.CreateTime = time.Now()
 							dataItem.ModifyTime = time.Now()
 							dataList = append(dataList, *dataItem)
@@ -388,6 +393,7 @@ func WatchIndexFileMergeRelease(filePath string) {
 			startDateMap := make(map[int]string)
 			endDateMap := make(map[int]string)
 			describeMap := make(map[int]string)
+			updateDateMap := make(map[int]string)
 
 			rows, err := f.GetRows(sv)
 			if err != nil {
@@ -434,6 +440,8 @@ func WatchIndexFileMergeRelease(filePath string) {
 							}
 						case 7: //备注
 							describeMap[k-1] = colCell
+						case 9:
+							updateDateMap[k-1] = colCell
 						}
 					}
 				} else {
@@ -455,7 +463,7 @@ func WatchIndexFileMergeRelease(filePath string) {
 			}
 
 			for k, excelDataMap := range indexExcelDataList {
-				mysteelIndexHandle(runMode, indexNameMap[k], indexCodeMap[k], unitMap[k], sourceMap[k], frequencyMap[k], startDateMap[k], endDateMap[k], describeMap[k], excelDataMap)
+				mysteelIndexHandle(runMode, indexNameMap[k], indexCodeMap[k], unitMap[k], sourceMap[k], frequencyMap[k], startDateMap[k], endDateMap[k], describeMap[k], updateDateMap[k], excelDataMap)
 			}
 		}
 
@@ -465,7 +473,7 @@ func WatchIndexFileMergeRelease(filePath string) {
 }
 
 // mysteelIndexHandle 钢联数据处理
-func mysteelIndexHandle(runMode, indexName, indexCode, unit, source, frequency, startDate, endDate, describe string, excelDataMap map[string]string) {
+func mysteelIndexHandle(runMode, indexName, indexCode, unit, source, frequency, startDate, endDate, describe, updateDate string, excelDataMap map[string]string) {
 	var err error
 
 	//return
@@ -574,6 +582,7 @@ func mysteelIndexHandle(runMode, indexName, indexCode, unit, source, frequency,
 			dataItem.IndexCode = indexCode
 			dataItem.DataTime = dateTime
 			dataItem.Value = value
+			dataItem.UpdateDate = updateDate
 			dataItem.CreateTime = time.Now()
 			dataItem.ModifyTime = time.Now()
 			addDataList = append(addDataList, *dataItem)