|
@@ -3,12 +3,9 @@ package watch
|
|
|
import (
|
|
|
"fmt"
|
|
|
"hongze/mysteel_watch/global"
|
|
|
- "hongze/mysteel_watch/models"
|
|
|
- "hongze/mysteel_watch/models/index"
|
|
|
"hongze/mysteel_watch/utils"
|
|
|
"log"
|
|
|
"os"
|
|
|
- "path/filepath"
|
|
|
"strings"
|
|
|
"sync"
|
|
|
"time"
|
|
@@ -49,8 +46,8 @@ func ListenFolderNew() {
|
|
|
}
|
|
|
}
|
|
|
}()
|
|
|
- fmt.Println("watch dir:" + utils.IndexSaveDir)
|
|
|
- err = watcher.Add(utils.IndexSaveDir)
|
|
|
+ fmt.Println("watch dir:" + global.CONFIG.Serve.IndexSaveDir)
|
|
|
+ err = watcher.Add(global.CONFIG.Serve.IndexSaveDir)
|
|
|
if err != nil {
|
|
|
fmt.Println("watcher.Add:" + err.Error())
|
|
|
log.Fatal(err)
|
|
@@ -86,7 +83,7 @@ func ListenFolderNewMerge() {
|
|
|
}
|
|
|
}
|
|
|
}()
|
|
|
- err = watcher.Add(utils.IndexMsergeSaveDir)
|
|
|
+ err = watcher.Add(global.CONFIG.Serve.IndexMergeSaveDir)
|
|
|
if err != nil {
|
|
|
log.Fatal(err)
|
|
|
}
|
|
@@ -124,14 +121,15 @@ func WatchIndexFile(filePath string) {
|
|
|
}
|
|
|
}
|
|
|
}()
|
|
|
- var runMode string
|
|
|
- if strings.Contains(filePath, "debug") {
|
|
|
- runMode = "debug"
|
|
|
- } else {
|
|
|
- runMode = "release"
|
|
|
- }
|
|
|
+ //var runMode string
|
|
|
+ //if strings.Contains(filePath, "debug") {
|
|
|
+ // runMode = "debug"
|
|
|
+ //} else {
|
|
|
+ // runMode = "release"
|
|
|
+ //}
|
|
|
|
|
|
- dir, fp := filepath.Split(filePath)
|
|
|
+ reqList := make([]*HandleMysteelIndex, 0)
|
|
|
+ //dir, fp := filepath.Split(filePath)
|
|
|
|
|
|
var wg = sync.WaitGroup{}
|
|
|
wg.Add(1)
|
|
@@ -139,232 +137,107 @@ func WatchIndexFile(filePath string) {
|
|
|
sheetList := f.GetSheetList()
|
|
|
for _, sv := range sheetList {
|
|
|
|
|
|
- var indexName, indexCode, unit, source, frequency, startDate, endDate, describe, updateDate string
|
|
|
- var indexId int64
|
|
|
+ lenRow := 0 //指标数
|
|
|
+
|
|
|
+ // excel表的指标数据
|
|
|
+ indexExcelDataList := make([]map[string]string, 0)
|
|
|
+
|
|
|
+ indexNameMap := make(map[int]string)
|
|
|
+ indexCodeMap := make(map[int]string)
|
|
|
+ unitMap := make(map[int]string)
|
|
|
+ sourceMap := make(map[int]string)
|
|
|
+ frequencyMap := make(map[int]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 {
|
|
|
- fmt.Println("f.GetRows:err:" + err.Error())
|
|
|
+ fmt.Println("GetRows Err:", err)
|
|
|
return
|
|
|
}
|
|
|
|
|
|
- indexObj := new(index.BaseFromMysteelChemicalIndex)
|
|
|
- dataList := make([]index.BaseFromMysteelChemicalData, 0)
|
|
|
-
|
|
|
- dataMap := make(map[string]string)
|
|
|
- for rk, row := range rows {
|
|
|
- if rk > 0 {
|
|
|
- if rk < 10 {
|
|
|
- for ck, colCell := range row {
|
|
|
- if ck == 1 {
|
|
|
- if rk == 1 {
|
|
|
- indexName = colCell
|
|
|
- }
|
|
|
- if rk == 2 {
|
|
|
- unit = colCell
|
|
|
- }
|
|
|
- if rk == 3 {
|
|
|
- source = colCell
|
|
|
- }
|
|
|
- if rk == 4 {
|
|
|
- indexCode = colCell
|
|
|
- }
|
|
|
- if rk == 5 {
|
|
|
- frequency = colCell
|
|
|
- if !strings.Contains(frequency, "度") {
|
|
|
- frequency = frequency + "度"
|
|
|
- }
|
|
|
- }
|
|
|
- if rk == 6 {
|
|
|
- dateArr := strings.Split(colCell, "~")
|
|
|
- if len(dateArr) >= 2 {
|
|
|
- startDate = dateArr[0]
|
|
|
- endDate = dateArr[1]
|
|
|
- }
|
|
|
- }
|
|
|
- if rk == 7 {
|
|
|
- describe = colCell
|
|
|
- }
|
|
|
-
|
|
|
- if rk == 9 {
|
|
|
- updateDate = colCell
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- if rk == 9 {
|
|
|
- if indexName == "" {
|
|
|
- global.LOG.Info("未刷新到指标数据:filePath:" + filePath)
|
|
|
- break
|
|
|
- }
|
|
|
- //判断指标是否存在
|
|
|
- var isAdd int
|
|
|
- item, err := indexObj.GetIndexItem(runMode, indexCode)
|
|
|
- if err != nil {
|
|
|
- if err.Error() == "record not found" {
|
|
|
- isAdd = 1
|
|
|
- } else {
|
|
|
- isAdd = -1
|
|
|
- fmt.Println("GetIndexItem Err:" + err.Error())
|
|
|
- return
|
|
|
- }
|
|
|
- }
|
|
|
- if item != nil && item.BaseFromMysteelChemicalIndexId > 0 {
|
|
|
- fmt.Println("item:", item)
|
|
|
- isAdd = 2
|
|
|
- } else {
|
|
|
- isAdd = 1
|
|
|
- }
|
|
|
-
|
|
|
- fmt.Println("isAdd:", isAdd)
|
|
|
- if !strings.Contains(frequency, "度") {
|
|
|
- frequency = frequency + "度"
|
|
|
- }
|
|
|
+ for row, cols := range rows {
|
|
|
+ if row == 0 {
|
|
|
+ // 第一行是 钢联数据的备注
|
|
|
+ continue
|
|
|
+ }
|
|
|
+ // 指标名称
|
|
|
+ if row == 1 {
|
|
|
+ lenRow = len(cols) - 1
|
|
|
+ for i := 1; i <= lenRow; i++ {
|
|
|
+ tmpIndexExcelDataList := make(map[string]string, 0)
|
|
|
+ indexExcelDataList = append(indexExcelDataList, tmpIndexExcelDataList)
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
- var frequencyStr string
|
|
|
- if strings.Contains(frequency, "日") {
|
|
|
- frequencyStr = "day"
|
|
|
- } else if strings.Contains(frequency, "周") {
|
|
|
- frequencyStr = "week"
|
|
|
- } else if strings.Contains(frequency, "月") || strings.Contains(frequency, "旬") {
|
|
|
- frequencyStr = "month"
|
|
|
- } else if strings.Contains(frequency, "年") {
|
|
|
- frequencyStr = "year"
|
|
|
- }
|
|
|
- frequencyStr = "_" + frequencyStr
|
|
|
- if !strings.Contains(filePath, frequencyStr) {
|
|
|
- fpArr := strings.Split(fp, "_")
|
|
|
- for k, v := range fpArr {
|
|
|
- if k == 0 {
|
|
|
- newFilePath = v + frequencyStr
|
|
|
- } else {
|
|
|
- newFilePath = newFilePath + "_" + v
|
|
|
- }
|
|
|
- }
|
|
|
- newFilePath = dir + newFilePath
|
|
|
- } else {
|
|
|
- newFilePath = filePath
|
|
|
+ if row < 10 {
|
|
|
+ for k, colCell := range cols {
|
|
|
+ switch row {
|
|
|
+ case 1: //指标名称
|
|
|
+ indexNameMap[k-1] = colCell
|
|
|
+ case 2: //单位
|
|
|
+ unitMap[k-1] = colCell
|
|
|
+ case 3: //数据来源
|
|
|
+ sourceMap[k-1] = colCell
|
|
|
+ case 4: //指标编码
|
|
|
+ indexCodeMap[k-1] = colCell
|
|
|
+ case 5: //频度
|
|
|
+ tmpFrequency := colCell
|
|
|
+ if !strings.Contains(tmpFrequency, "度") {
|
|
|
+ tmpFrequency = tmpFrequency + "度"
|
|
|
}
|
|
|
-
|
|
|
- fmt.Println("isAdd:", isAdd)
|
|
|
- if isAdd == 1 {
|
|
|
- indexObj.IndexCode = indexCode
|
|
|
- indexObj.IndexName = indexName
|
|
|
- indexObj.Unit = unit
|
|
|
- indexObj.Source = source
|
|
|
- indexObj.Describe = describe
|
|
|
- indexObj.StartDate, _ = time.ParseInLocation(utils.FormatDate, startDate, time.Local)
|
|
|
- indexObj.EndDate, _ = time.ParseInLocation(utils.FormatDate, endDate, time.Local)
|
|
|
- indexObj.Frequency = frequency
|
|
|
- indexObj.FilePath = newFilePath
|
|
|
- indexObj.UpdateDate = updateDate
|
|
|
- if updateDate != "" {
|
|
|
- updateDateT, err := time.Parse(utils.FormatDate, updateDate)
|
|
|
- if err == nil {
|
|
|
- week := utils.GetWeekZn(updateDateT.Weekday().String())
|
|
|
- indexObj.MergeUpdateWeek = week
|
|
|
- }
|
|
|
- }
|
|
|
- err = indexObj.Add(runMode)
|
|
|
- if err != nil {
|
|
|
- fmt.Println("add err:" + err.Error())
|
|
|
- return
|
|
|
- }
|
|
|
- indexId = indexObj.BaseFromMysteelChemicalIndexId
|
|
|
- } else if isAdd == 2 {
|
|
|
- indexObj.IndexCode = indexCode
|
|
|
- indexObj.IndexName = indexName
|
|
|
- indexObj.Unit = unit
|
|
|
- indexObj.Source = source
|
|
|
- indexObj.Describe = describe
|
|
|
- indexObj.StartDate, _ = time.ParseInLocation(utils.FormatDate, startDate, time.Local)
|
|
|
- indexObj.EndDate, _ = time.ParseInLocation(utils.FormatDate, endDate, time.Local)
|
|
|
- indexObj.Frequency = frequency
|
|
|
- indexObj.FilePath = newFilePath
|
|
|
- indexObj.ModifyTime = time.Now()
|
|
|
- if updateDate != "" {
|
|
|
- updateDateT, err := time.Parse(utils.FormatDate, updateDate)
|
|
|
- if err == nil {
|
|
|
- week := utils.GetWeekZn(updateDateT.Weekday().String())
|
|
|
- indexObj.MergeUpdateWeek = week
|
|
|
- }
|
|
|
- indexObj.UpdateDate = updateDate
|
|
|
- }
|
|
|
- indexId = item.BaseFromMysteelChemicalIndexId
|
|
|
- //修改数据
|
|
|
- updateColsArr := make([]string, 0)
|
|
|
- updateColsArr = append(updateColsArr, "index_name")
|
|
|
- updateColsArr = append(updateColsArr, "unit")
|
|
|
- updateColsArr = append(updateColsArr, "source")
|
|
|
- updateColsArr = append(updateColsArr, "frequency")
|
|
|
- updateColsArr = append(updateColsArr, "start_date")
|
|
|
- updateColsArr = append(updateColsArr, "end_date")
|
|
|
- updateColsArr = append(updateColsArr, "describe")
|
|
|
- updateColsArr = append(updateColsArr, "end_date")
|
|
|
- updateColsArr = append(updateColsArr, "modify_time")
|
|
|
- updateColsArr = append(updateColsArr, "file_path")
|
|
|
- updateColsArr = append(updateColsArr, "update_date")
|
|
|
- updateColsArr = append(updateColsArr, "merge_update_week")
|
|
|
-
|
|
|
- err = indexObj.Update(runMode, updateColsArr)
|
|
|
- if err != nil {
|
|
|
- fmt.Println("indexObj.Update err:" + err.Error())
|
|
|
- }
|
|
|
-
|
|
|
- dataObj := new(index.BaseFromMysteelChemicalData)
|
|
|
- //获取已存在的所有数据
|
|
|
- dataList, err := dataObj.GetIndexDataList(runMode, indexCode)
|
|
|
- if err != nil {
|
|
|
- fmt.Println("GetIndexDataList Err:" + err.Error())
|
|
|
- return
|
|
|
- }
|
|
|
- fmt.Println("dataListLen:", len(dataList))
|
|
|
- for _, v := range dataList {
|
|
|
- dateStr := v.DataTime.Format(utils.FormatDate)
|
|
|
- dataMap[dateStr] = v.Value
|
|
|
- }
|
|
|
+ frequencyMap[k-1] = tmpFrequency
|
|
|
+ case 6: //时间区间
|
|
|
+ dateArr := strings.Split(colCell, "~")
|
|
|
+ if len(dateArr) >= 2 {
|
|
|
+ startDateMap[k-1] = dateArr[0]
|
|
|
+ endDateMap[k-1] = dateArr[1]
|
|
|
}
|
|
|
+ case 7: //备注
|
|
|
+ describeMap[k-1] = colCell
|
|
|
+ case 9:
|
|
|
+ updateDateMap[k-1] = colCell
|
|
|
}
|
|
|
- } else {
|
|
|
- var date, value string
|
|
|
- for ck, colCell := range row {
|
|
|
- if ck == 0 {
|
|
|
- date = colCell
|
|
|
- } else {
|
|
|
- value = colCell
|
|
|
- }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ date := ``
|
|
|
+ for k, col := range cols {
|
|
|
+ if k == 0 {
|
|
|
+ date = col
|
|
|
+ continue
|
|
|
}
|
|
|
- if _, ok := dataMap[date]; !ok {
|
|
|
- dateTime, err := time.ParseInLocation(utils.FormatDate, date, time.Local)
|
|
|
- if err != nil {
|
|
|
- fmt.Println("time.ParseInLocation Err:" + err.Error())
|
|
|
- return
|
|
|
- }
|
|
|
- if !strings.Contains(value, "#N/A") {
|
|
|
- dataItem := new(index.BaseFromMysteelChemicalData)
|
|
|
- dataItem.BaseFromMysteelChemicalIndexId = indexId
|
|
|
- dataItem.IndexCode = indexCode
|
|
|
- dataItem.DataTime = dateTime
|
|
|
- dataItem.Value = value
|
|
|
- dataItem.UpdateDate = updateDate
|
|
|
- dataItem.CreateTime = time.Now()
|
|
|
- dataItem.ModifyTime = time.Now()
|
|
|
- dataList = append(dataList, *dataItem)
|
|
|
- }
|
|
|
+ if date == `` {
|
|
|
+ continue
|
|
|
+ }
|
|
|
+ if col != `` {
|
|
|
+ indexExcelDataList[k-1][date] = col
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
}
|
|
|
|
|
|
- if len(dataList) > 0 {
|
|
|
- fmt.Println("dataObj.Add")
|
|
|
- dataObj := new(index.BaseFromMysteelChemicalData)
|
|
|
- err = dataObj.Add(runMode, dataList)
|
|
|
- if err != nil {
|
|
|
- fmt.Println("dataObj.Add() Err:" + err.Error())
|
|
|
- }
|
|
|
- } else {
|
|
|
- fmt.Println("dataObj.Add:", len(dataList))
|
|
|
+ for k, excelDataMap := range indexExcelDataList {
|
|
|
+ indexItem := new(HandleMysteelIndex)
|
|
|
+ indexItem.IndexName = indexNameMap[k]
|
|
|
+ indexItem.IndexCode = indexCodeMap[k]
|
|
|
+ indexItem.Unit = unitMap[k]
|
|
|
+ indexItem.Source = sourceMap[k]
|
|
|
+ indexItem.Frequency = frequencyMap[k]
|
|
|
+ indexItem.StartDate = startDateMap[k]
|
|
|
+ indexItem.EndDate = endDateMap[k]
|
|
|
+ indexItem.Describe = describeMap[k]
|
|
|
+ indexItem.UpdateDate = updateDateMap[k]
|
|
|
+ indexItem.ExcelDataMap = excelDataMap
|
|
|
+ reqList = append(reqList, indexItem)
|
|
|
+ //mysteelIndexHandle(runMode, indexNameMap[k], indexCodeMap[k], unitMap[k], sourceMap[k], frequencyMap[k], startDateMap[k], endDateMap[k], describeMap[k], updateDateMap[k], excelDataMap)
|
|
|
}
|
|
|
+
|
|
|
+ resp := new(HandleMysteelIndexReq)
|
|
|
+ resp.List = reqList
|
|
|
+ postHandleMysteelIndex(resp)
|
|
|
}
|
|
|
wg.Done()
|
|
|
}()
|
|
@@ -532,176 +405,181 @@ type HandleMysteelIndexReq struct {
|
|
|
}
|
|
|
|
|
|
// mysteelIndexHandle 钢联数据处理
|
|
|
-func mysteelIndexHandle(runMode, indexName, indexCode, unit, source, frequency, startDate, endDate, describe, updateDate string, excelDataMap map[string]string) {
|
|
|
- var err error
|
|
|
-
|
|
|
- //return
|
|
|
- indexObj := new(index.BaseFromMysteelChemicalIndex)
|
|
|
- var indexId int64
|
|
|
-
|
|
|
- addDataList := make([]index.BaseFromMysteelChemicalData, 0)
|
|
|
-
|
|
|
- exitDataMap := make(map[string]*index.BaseFromMysteelChemicalData)
|
|
|
-
|
|
|
- // 修改指标信息
|
|
|
- if indexName == "" {
|
|
|
- global.LOG.Info("未刷新到指标数据:indexName:" + indexName)
|
|
|
- return
|
|
|
- }
|
|
|
- //判断指标是否存在
|
|
|
- var isAdd int
|
|
|
- item, err := indexObj.GetIndexItem(runMode, indexCode)
|
|
|
- if err != nil {
|
|
|
- if err.Error() == "record not found" {
|
|
|
- isAdd = 1
|
|
|
- } else {
|
|
|
- isAdd = -1
|
|
|
- fmt.Println("GetIndexItem Err:" + err.Error())
|
|
|
- return
|
|
|
- }
|
|
|
- }
|
|
|
- if item != nil && item.BaseFromMysteelChemicalIndexId > 0 {
|
|
|
- fmt.Println("item:", item)
|
|
|
- isAdd = 2
|
|
|
- } else {
|
|
|
- isAdd = 1
|
|
|
- }
|
|
|
-
|
|
|
- fmt.Println("isAdd:", isAdd)
|
|
|
- if !strings.Contains(frequency, "度") {
|
|
|
- frequency = frequency + "度"
|
|
|
- }
|
|
|
-
|
|
|
- if isAdd == 1 {
|
|
|
- indexObj.IndexCode = indexCode
|
|
|
- indexObj.IndexName = indexName
|
|
|
- indexObj.Unit = unit
|
|
|
- indexObj.Source = source
|
|
|
- indexObj.Describe = describe
|
|
|
- indexObj.StartDate, _ = time.ParseInLocation(utils.FormatDate, startDate, time.Local)
|
|
|
- indexObj.EndDate, _ = time.ParseInLocation(utils.FormatDate, endDate, time.Local)
|
|
|
- indexObj.Frequency = frequency
|
|
|
- err = indexObj.Add(runMode)
|
|
|
- if err != nil {
|
|
|
- fmt.Println("add err:" + err.Error())
|
|
|
- return
|
|
|
- }
|
|
|
- indexId = indexObj.BaseFromMysteelChemicalIndexId
|
|
|
- } else if isAdd == 2 {
|
|
|
- indexObj.IndexCode = indexCode
|
|
|
- indexObj.IndexName = indexName
|
|
|
- indexObj.Unit = unit
|
|
|
- indexObj.Source = source
|
|
|
- indexObj.Describe = describe
|
|
|
- indexObj.StartDate, _ = time.ParseInLocation(utils.FormatDate, startDate, time.Local)
|
|
|
- indexObj.EndDate, _ = time.ParseInLocation(utils.FormatDate, endDate, time.Local)
|
|
|
- indexObj.Frequency = frequency
|
|
|
- indexObj.ModifyTime = time.Now()
|
|
|
- indexId = item.BaseFromMysteelChemicalIndexId
|
|
|
- //修改数据
|
|
|
- updateColsArr := make([]string, 0)
|
|
|
- updateColsArr = append(updateColsArr, "index_name")
|
|
|
- updateColsArr = append(updateColsArr, "unit")
|
|
|
- updateColsArr = append(updateColsArr, "source")
|
|
|
- updateColsArr = append(updateColsArr, "frequency")
|
|
|
- updateColsArr = append(updateColsArr, "start_date")
|
|
|
- updateColsArr = append(updateColsArr, "end_date")
|
|
|
- updateColsArr = append(updateColsArr, "describe")
|
|
|
- updateColsArr = append(updateColsArr, "end_date")
|
|
|
- updateColsArr = append(updateColsArr, "modify_time")
|
|
|
-
|
|
|
- indexObj.Update(runMode, updateColsArr)
|
|
|
-
|
|
|
- dataObj := new(index.BaseFromMysteelChemicalData)
|
|
|
-
|
|
|
- //获取已存在的所有数据
|
|
|
- exitDataList, err := dataObj.GetIndexDataList(runMode, indexCode)
|
|
|
- if err != nil {
|
|
|
- fmt.Println("GetIndexDataList Err:" + err.Error())
|
|
|
- return
|
|
|
- }
|
|
|
- fmt.Println("exitDataListLen:", len(exitDataList))
|
|
|
- for _, v := range exitDataList {
|
|
|
- dateStr := v.DataTime.Format(utils.FormatDate)
|
|
|
- exitDataMap[dateStr] = v
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- dataObj := new(index.BaseFromMysteelChemicalData)
|
|
|
- // 遍历excel数据,然后跟现有的数据做校验,不存在则入库
|
|
|
- for date, value := range excelDataMap {
|
|
|
- if findData, ok := exitDataMap[date]; !ok {
|
|
|
- dateTime, err := time.ParseInLocation(utils.FormatDate, date, time.Local)
|
|
|
- if err != nil {
|
|
|
- fmt.Println("time.ParseInLocation Err:" + err.Error())
|
|
|
- return
|
|
|
- }
|
|
|
- if !strings.Contains(value, "#N/A") {
|
|
|
- dataItem := new(index.BaseFromMysteelChemicalData)
|
|
|
- dataItem.BaseFromMysteelChemicalIndexId = indexId
|
|
|
- dataItem.IndexCode = indexCode
|
|
|
- dataItem.DataTime = dateTime
|
|
|
- dataItem.Value = value
|
|
|
- dataItem.UpdateDate = updateDate
|
|
|
- dataItem.CreateTime = time.Now()
|
|
|
- dataItem.ModifyTime = time.Now()
|
|
|
- addDataList = append(addDataList, *dataItem)
|
|
|
- }
|
|
|
- } else {
|
|
|
- if findData != nil && findData.Value != value && !strings.Contains(value, "#N/A") { //修改数据
|
|
|
- dataObj.Value = value
|
|
|
- dataObj.ModifyTime = time.Now()
|
|
|
- dataObj.BaseFromMysteelChemicalDataId = findData.BaseFromMysteelChemicalDataId
|
|
|
-
|
|
|
- updateDataColsArr := make([]string, 0)
|
|
|
- updateDataColsArr = append(updateDataColsArr, "value")
|
|
|
- updateDataColsArr = append(updateDataColsArr, "modify_time")
|
|
|
- dataObj.Update(runMode, updateDataColsArr)
|
|
|
- global.LOG.Info(findData.IndexCode + " " + findData.Value + "-" + value)
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- if len(addDataList) > 0 {
|
|
|
- err = dataObj.Add(runMode, addDataList)
|
|
|
- if err != nil {
|
|
|
- fmt.Println("dataObj.Add() Err:" + err.Error())
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- go syncEdbDataMysteelChemical(runMode, indexCode)
|
|
|
-}
|
|
|
-
|
|
|
-func syncEdbDataMysteelChemical(runMode, indexCode string) {
|
|
|
- indexObj := new(models.EdbInfo)
|
|
|
- var isAdd int
|
|
|
- item, err := indexObj.GetEdbInfoItem(runMode, indexCode)
|
|
|
- if err != nil {
|
|
|
- if err.Error() == "record not found" {
|
|
|
- isAdd = 1
|
|
|
- } else {
|
|
|
- isAdd = -1
|
|
|
- fmt.Println("GetEdbInfoItem Err:" + err.Error())
|
|
|
- return
|
|
|
- }
|
|
|
- }
|
|
|
- if item != nil && item.EdbInfoId > 0 {
|
|
|
- fmt.Println("item:", item)
|
|
|
- isAdd = 2
|
|
|
- } else {
|
|
|
- isAdd = 1 //
|
|
|
- }
|
|
|
-
|
|
|
- if isAdd == 1 { //新增
|
|
|
- return
|
|
|
- }
|
|
|
-
|
|
|
- param := make(map[string]interface{})
|
|
|
- param["EdbCode"] = indexCode
|
|
|
- param["EdbInfoId"] = item.EdbInfoId
|
|
|
- param["StartDate"] = item.EndDate
|
|
|
- postRefreshEdbData(param)
|
|
|
-}
|
|
|
+//func mysteelIndexHandle(runMode, indexName, indexCode, unit, source, frequency, startDate, endDate, describe, updateDate string, excelDataMap map[string]string) {
|
|
|
+// var err error
|
|
|
+//
|
|
|
+// //return
|
|
|
+// indexObj := new(index.BaseFromMysteelChemicalIndex)
|
|
|
+// var indexId int64
|
|
|
+//
|
|
|
+// addDataList := make([]index.BaseFromMysteelChemicalData, 0)
|
|
|
+//
|
|
|
+// exitDataMap := make(map[string]*index.BaseFromMysteelChemicalData)
|
|
|
+//
|
|
|
+// // 修改指标信息
|
|
|
+// if indexName == "" {
|
|
|
+// global.LOG.Info("未刷新到指标数据:indexName:" + indexName)
|
|
|
+// return
|
|
|
+// }
|
|
|
+// //判断指标是否存在
|
|
|
+// var isAdd int
|
|
|
+// //req := GetIndexByIndexCodeReq{
|
|
|
+// // IndexCode: indexCode,
|
|
|
+// //}
|
|
|
+// //item, err := indexObj.GetIndexItem(runMode, indexCode)
|
|
|
+// item, e := GetIndexByIndexCode(indexCode)
|
|
|
+// if e != nil {
|
|
|
+// //if err.Error() == "record not found" {
|
|
|
+// // isAdd = 1
|
|
|
+// //} else {
|
|
|
+// isAdd = -1
|
|
|
+// fmt.Println("GetIndexItem Err:" + err.Error())
|
|
|
+// return
|
|
|
+// //}
|
|
|
+// }
|
|
|
+// if item.BaseFromMysteelChemicalIndexId > 0 {
|
|
|
+// fmt.Println("item:", item)
|
|
|
+// isAdd = 2
|
|
|
+// } else {
|
|
|
+// isAdd = 1
|
|
|
+// }
|
|
|
+//
|
|
|
+// fmt.Println("isAdd:", isAdd)
|
|
|
+// if !strings.Contains(frequency, "度") {
|
|
|
+// frequency = frequency + "度"
|
|
|
+// }
|
|
|
+//
|
|
|
+// if isAdd == 1 {
|
|
|
+// indexObj.IndexCode = indexCode
|
|
|
+// indexObj.IndexName = indexName
|
|
|
+// indexObj.Unit = unit
|
|
|
+// indexObj.Source = source
|
|
|
+// indexObj.Describe = describe
|
|
|
+// indexObj.StartDate, _ = time.ParseInLocation(utils.FormatDate, startDate, time.Local)
|
|
|
+// indexObj.EndDate, _ = time.ParseInLocation(utils.FormatDate, endDate, time.Local)
|
|
|
+// indexObj.Frequency = frequency
|
|
|
+// //err = indexObj.Add(runMode)
|
|
|
+// err = CreateIndex(indexObj)
|
|
|
+// if err != nil {
|
|
|
+// fmt.Println("add err:" + err.Error())
|
|
|
+// return
|
|
|
+// }
|
|
|
+// indexId = indexObj.BaseFromMysteelChemicalIndexId
|
|
|
+// } else if isAdd == 2 {
|
|
|
+// indexObj.IndexCode = indexCode
|
|
|
+// indexObj.IndexName = indexName
|
|
|
+// indexObj.Unit = unit
|
|
|
+// indexObj.Source = source
|
|
|
+// indexObj.Describe = describe
|
|
|
+// indexObj.StartDate, _ = time.ParseInLocation(utils.FormatDate, startDate, time.Local)
|
|
|
+// indexObj.EndDate, _ = time.ParseInLocation(utils.FormatDate, endDate, time.Local)
|
|
|
+// indexObj.Frequency = frequency
|
|
|
+// indexObj.ModifyTime = time.Now()
|
|
|
+// indexId = item.BaseFromMysteelChemicalIndexId
|
|
|
+// //修改数据
|
|
|
+// updateColsArr := make([]string, 0)
|
|
|
+// updateColsArr = append(updateColsArr, "index_name")
|
|
|
+// updateColsArr = append(updateColsArr, "unit")
|
|
|
+// updateColsArr = append(updateColsArr, "source")
|
|
|
+// updateColsArr = append(updateColsArr, "frequency")
|
|
|
+// updateColsArr = append(updateColsArr, "start_date")
|
|
|
+// updateColsArr = append(updateColsArr, "end_date")
|
|
|
+// updateColsArr = append(updateColsArr, "describe")
|
|
|
+// updateColsArr = append(updateColsArr, "end_date")
|
|
|
+// updateColsArr = append(updateColsArr, "modify_time")
|
|
|
+//
|
|
|
+// indexObj.Update(runMode, updateColsArr)
|
|
|
+//
|
|
|
+// dataObj := new(index.BaseFromMysteelChemicalData)
|
|
|
+//
|
|
|
+// //获取已存在的所有数据
|
|
|
+// exitDataList, err := dataObj.GetIndexDataList(runMode, indexCode)
|
|
|
+// if err != nil {
|
|
|
+// fmt.Println("GetIndexDataList Err:" + err.Error())
|
|
|
+// return
|
|
|
+// }
|
|
|
+// fmt.Println("exitDataListLen:", len(exitDataList))
|
|
|
+// for _, v := range exitDataList {
|
|
|
+// dateStr := v.DataTime.Format(utils.FormatDate)
|
|
|
+// exitDataMap[dateStr] = v
|
|
|
+// }
|
|
|
+// }
|
|
|
+//
|
|
|
+// dataObj := new(index.BaseFromMysteelChemicalData)
|
|
|
+// // 遍历excel数据,然后跟现有的数据做校验,不存在则入库
|
|
|
+// for date, value := range excelDataMap {
|
|
|
+// if findData, ok := exitDataMap[date]; !ok {
|
|
|
+// dateTime, err := time.ParseInLocation(utils.FormatDate, date, time.Local)
|
|
|
+// if err != nil {
|
|
|
+// fmt.Println("time.ParseInLocation Err:" + err.Error())
|
|
|
+// return
|
|
|
+// }
|
|
|
+// if !strings.Contains(value, "#N/A") {
|
|
|
+// dataItem := new(index.BaseFromMysteelChemicalData)
|
|
|
+// dataItem.BaseFromMysteelChemicalIndexId = indexId
|
|
|
+// dataItem.IndexCode = indexCode
|
|
|
+// dataItem.DataTime = dateTime
|
|
|
+// dataItem.Value = value
|
|
|
+// dataItem.UpdateDate = updateDate
|
|
|
+// dataItem.CreateTime = time.Now()
|
|
|
+// dataItem.ModifyTime = time.Now()
|
|
|
+// addDataList = append(addDataList, *dataItem)
|
|
|
+// }
|
|
|
+// } else {
|
|
|
+// if findData != nil && findData.Value != value && !strings.Contains(value, "#N/A") { //修改数据
|
|
|
+// dataObj.Value = value
|
|
|
+// dataObj.ModifyTime = time.Now()
|
|
|
+// dataObj.BaseFromMysteelChemicalDataId = findData.BaseFromMysteelChemicalDataId
|
|
|
+//
|
|
|
+// updateDataColsArr := make([]string, 0)
|
|
|
+// updateDataColsArr = append(updateDataColsArr, "value")
|
|
|
+// updateDataColsArr = append(updateDataColsArr, "modify_time")
|
|
|
+// dataObj.Update(runMode, updateDataColsArr)
|
|
|
+// global.LOG.Info(findData.IndexCode + " " + findData.Value + "-" + value)
|
|
|
+// }
|
|
|
+// }
|
|
|
+// }
|
|
|
+//
|
|
|
+// if len(addDataList) > 0 {
|
|
|
+// err = dataObj.Add(runMode, addDataList)
|
|
|
+// if err != nil {
|
|
|
+// fmt.Println("dataObj.Add() Err:" + err.Error())
|
|
|
+// }
|
|
|
+// }
|
|
|
+//
|
|
|
+// go syncEdbDataMysteelChemical(runMode, indexCode)
|
|
|
+//}
|
|
|
+
|
|
|
+//func syncEdbDataMysteelChemical(runMode, indexCode string) {
|
|
|
+// indexObj := new(models.EdbInfo)
|
|
|
+// var isAdd int
|
|
|
+// item, err := indexObj.GetEdbInfoItem(runMode, indexCode)
|
|
|
+// if err != nil {
|
|
|
+// if err.Error() == "record not found" {
|
|
|
+// isAdd = 1
|
|
|
+// } else {
|
|
|
+// isAdd = -1
|
|
|
+// fmt.Println("GetEdbInfoItem Err:" + err.Error())
|
|
|
+// return
|
|
|
+// }
|
|
|
+// }
|
|
|
+// if item != nil && item.EdbInfoId > 0 {
|
|
|
+// fmt.Println("item:", item)
|
|
|
+// isAdd = 2
|
|
|
+// } else {
|
|
|
+// isAdd = 1 //
|
|
|
+// }
|
|
|
+//
|
|
|
+// if isAdd == 1 { //新增
|
|
|
+// return
|
|
|
+// }
|
|
|
+//
|
|
|
+// param := make(map[string]interface{})
|
|
|
+// param["EdbCode"] = indexCode
|
|
|
+// param["EdbInfoId"] = item.EdbInfoId
|
|
|
+// param["StartDate"] = item.EndDate
|
|
|
+// postRefreshEdbData(param)
|
|
|
+//}
|
|
|
|
|
|
/*
|
|
|
CREATE动作即临时文件的创建
|