|
@@ -40,11 +40,19 @@ func IndexCreateCheck() (err error) {
|
|
|
fmt.Println("indexCodeStr:" + indexCodeStr)
|
|
|
go alarm_msg.SendAlarmMsg(utils.APPNAME+" 存在指标数据未生成:"+indexCodeStr, 3)
|
|
|
for _, v := range list {
|
|
|
- //err := IndexCreate(v)
|
|
|
- //if err != nil {
|
|
|
- // go alarm_msg.SendAlarmMsg(utils.APPNAME+" 指标数据未生成检测失败:"+err.Error(), 3)
|
|
|
- //}
|
|
|
- MysteelChemicalRefresh(v.FilePath)
|
|
|
+ if v.FilePath != "" && utils.FileIsExist(v.FilePath) {
|
|
|
+ err = UpdateComment(v.FilePath)
|
|
|
+ if err != nil {
|
|
|
+ go alarm_msg.SendAlarmMsg(utils.APPNAME+" 指标数据未生成检测失败:"+err.Error()+";file:"+v.FilePath, 3)
|
|
|
+ }
|
|
|
+ time.Sleep(1 * time.Second)
|
|
|
+ MysteelChemicalRefresh(v.FilePath)
|
|
|
+ } else {
|
|
|
+ err := IndexCreate(v)
|
|
|
+ if err != nil {
|
|
|
+ go alarm_msg.SendAlarmMsg(utils.APPNAME+" 指标数据未生成检测失败:"+err.Error(), 3)
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
return nil
|
|
|
}
|
|
@@ -76,7 +84,7 @@ func IndexCreate(item *index.BaseFromMysteelChemicalIndex) (err error) {
|
|
|
}()
|
|
|
|
|
|
startDate := "1990-01-01"
|
|
|
- commentStr := `"BlankValue":"0","CanMark":true,"ChartLineType":"0","DateBlock":0,"DateBlockCount":1,"DateFormat":0,"DateTimeTag":"","EndDate":"","ExportType":0,"HasDescription":true,"HasEmptyRows":false,"HasFrequency":true,"HasIndexID":true,"HasLastDate":true,"HasSourceName":true,"HasTimeInterval":true,"HasUnit":true,"HasUpdateDate":true,"IsCreateChart":false,"IsDataSort":true,"IsNewSheet":false,"IsNewWorkbook":false,"Models":[{"DataFormat":0,"DataStartDate":"` + startDate + `","DefineName":"","DefineUnit":"","DisplayIndexCode":"` + item.IndexCode + `","IndexCode":"` + item.IndexCode + `","IndexFormula":"` + item.IndexCode + `","PointValue":0,"UnionStart":""}],"Position":"A1","RangeData":"A2:B280","ShowBlankLines":false,"StartDate":"","Transpose":false,"UpdateMode":0,"lookModel":{"IsLast":false,"LookValue":0,"lookType":0},"ver":3}
|
|
|
+ commentStr := `"BlankValue":"0","CanMark":true,"ChartLineType":"0","DateBlock":0,"DateBlockCount":1,"DateFormat":0,"DateTimeTag":"","EndDate":"","ExportType":0,"HasDescription":true,"HasEmptyRows":false,"HasFrequency":true,"HasIndexID":true,"HasLastDate":true,"HasSourceName":true,"HasTimeInterval":true,"HasUnit":true,"HasUpdateDate":true,"IsCreateChart":false,"IsDataSort":true,"IsNewSheet":false,"IsNewWorkbook":false,"Models":[{"DataFormat":0,"DataStartDate":"` + startDate + `","DefineName":"","DefineUnit":"","DisplayIndexCode":"` + item.IndexCode + `","IndexCode":"` + item.IndexCode + `","IndexFormula":"` + item.IndexCode + `","PointValue":0,"UnionStart":""}],"Position":"A1","RangeData":"A2:B280","ShowBlankLines":false,"StartDate":"","Transpose":false,"UpdateMode":1,"lookModel":{"IsLast":false,"LookValue":0,"lookType":0},"ver":3}
|
|
|
`
|
|
|
commentMap := make(map[string]interface{})
|
|
|
commentMap["author"] = "{"
|
|
@@ -118,6 +126,11 @@ func IndexRefreshAll() {
|
|
|
monthLastDayStr := monthLastDay.Format(utils.FormatDate)
|
|
|
yearLast := strconv.Itoa(time.Now().Year()) + "12-31"
|
|
|
for _, v := range list {
|
|
|
+ err = UpdateComment(v.FilePath)
|
|
|
+ if err != nil {
|
|
|
+ go alarm_msg.SendAlarmMsg(utils.APPNAME+" 指标数据未生成检测失败:"+err.Error()+";file:"+v.FilePath, 3)
|
|
|
+ }
|
|
|
+ time.Sleep(1 * time.Second)
|
|
|
if v.Frequency == "周度" && v.UpdateWeek == "" && v.UpdateTime == "" && v.UpdateTime2 == "" {
|
|
|
MysteelChemicalRefresh(v.FilePath)
|
|
|
} else if (v.Frequency == "月度" || v.Frequency == "旬度") && nowDate == monthLastDayStr {
|
|
@@ -129,7 +142,6 @@ func IndexRefreshAll() {
|
|
|
} else {
|
|
|
global.LOG.Info("无效频度:" + v.IndexCode + ";" + v.Frequency)
|
|
|
}
|
|
|
- time.Sleep(1 * time.Second)
|
|
|
}
|
|
|
return
|
|
|
}
|
|
@@ -168,3 +180,48 @@ func IndexRefreshWeek() {
|
|
|
lock.Unlock()
|
|
|
return
|
|
|
}
|
|
|
+
|
|
|
+// Add 生成指标
|
|
|
+func UpdateComment(filePath string) (err error) {
|
|
|
+ templateFile, err := excelize.OpenFile(filePath)
|
|
|
+ if err != nil {
|
|
|
+ fmt.Println("OpenFile Err:" + err.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+ defer func() {
|
|
|
+ templateFile.Close()
|
|
|
+ }()
|
|
|
+
|
|
|
+ commentArr := templateFile.GetComments()
|
|
|
+ for k, v := range commentArr {
|
|
|
+ fmt.Println(k, v)
|
|
|
+ for _, sv := range v {
|
|
|
+ fmt.Println("text:", sv.Text)
|
|
|
+ if strings.Contains(sv.Text, `"UpdateMode":0`) {
|
|
|
+ newText := strings.Replace(sv.Text, `"UpdateMode":0`, `"UpdateMode":1`, -1)
|
|
|
+ newText = strings.Trim(newText, "{")
|
|
|
+
|
|
|
+ commentMap := make(map[string]interface{})
|
|
|
+ commentMap["author"] = "{"
|
|
|
+ commentMap["text"] = newText
|
|
|
+
|
|
|
+ commentJson, err := json.Marshal(commentMap)
|
|
|
+ if err != nil {
|
|
|
+ fmt.Println("json.Marshal err:" + err.Error())
|
|
|
+ }
|
|
|
+ fmt.Println("add text:" + string(commentJson))
|
|
|
+ templateFile.DeleteComment("Sheet1", "A1")
|
|
|
+ err = templateFile.AddComment("Sheet1", "A1", string(commentJson))
|
|
|
+ if err != nil {
|
|
|
+ fmt.Println("AddComment Err:" + err.Error())
|
|
|
+ return err
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if err := templateFile.SaveAs(filePath); err != nil {
|
|
|
+ fmt.Println("templateFile.SaveAs Err:", err)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ return
|
|
|
+}
|