|
@@ -0,0 +1,93 @@
|
|
|
+package services
|
|
|
+
|
|
|
+import (
|
|
|
+ "encoding/json"
|
|
|
+ "fmt"
|
|
|
+ "github.com/xuri/excelize/v2"
|
|
|
+ "hongze/mysteel_watch/global"
|
|
|
+ "hongze/mysteel_watch/models/index"
|
|
|
+ "hongze/mysteel_watch/services/alarm_msg"
|
|
|
+ "hongze/mysteel_watch/utils"
|
|
|
+ "os"
|
|
|
+ "strings"
|
|
|
+ "time"
|
|
|
+)
|
|
|
+
|
|
|
+func IndexCreateCheck() (err error) {
|
|
|
+ fmt.Println("IndexCreateCheck")
|
|
|
+ indexObj := new(index.BaseFromMysteelChemicalIndex)
|
|
|
+ list, err := indexObj.GetIndexCreate()
|
|
|
+ if err != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ fmt.Println("listLen:", len(list))
|
|
|
+ if len(list) <= 0 {
|
|
|
+ return nil
|
|
|
+ }
|
|
|
+ var indexCode []string
|
|
|
+ for _, v := range list {
|
|
|
+ indexCode = append(indexCode, v.IndexCode)
|
|
|
+ }
|
|
|
+ indexCodeStr := strings.Join(indexCode, ";")
|
|
|
+ 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)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return nil
|
|
|
+}
|
|
|
+
|
|
|
+func IndexCreate(item *index.BaseFromMysteelChemicalIndex) (err error) {
|
|
|
+ item.UpdateWeek = utils.GetUpdateWeekEn(item.UpdateWeek)
|
|
|
+ global.LOG.Info("task IndexCreate:" + time.Now().Format(utils.FormatDateTime))
|
|
|
+
|
|
|
+ if utils.FileIsExist(item.FilePath) {
|
|
|
+ os.Remove(item.FilePath)
|
|
|
+ }
|
|
|
+ runMode := "release"
|
|
|
+ //fileName := req.IndexName + "_" + req.IndexCode + ".xlsx"
|
|
|
+ var fileName string
|
|
|
+ if item.UpdateWeek != "" {
|
|
|
+ fileName = item.IndexCode + "_" + item.UpdateWeek + "_" + runMode + ".xlsx" //保存的文件名称
|
|
|
+ } else {
|
|
|
+ fileName = item.IndexCode + "_" + runMode + ".xlsx" //保存的文件名称
|
|
|
+ }
|
|
|
+ filePath := utils.IndexSaveDir + fileName
|
|
|
+
|
|
|
+ templatePath := utils.IndexSaveDir + "index_template.xlsx"
|
|
|
+ templateFile, err := excelize.OpenFile(templatePath)
|
|
|
+ if err != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ defer func() {
|
|
|
+ templateFile.Close()
|
|
|
+ }()
|
|
|
+
|
|
|
+ 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}
|
|
|
+`
|
|
|
+ commentMap := make(map[string]interface{})
|
|
|
+ commentMap["author"] = "{"
|
|
|
+ commentMap["text"] = commentStr
|
|
|
+ //commentMap["text"] = commentItem
|
|
|
+
|
|
|
+ commentJson, err := json.Marshal(commentMap)
|
|
|
+ if err != nil {
|
|
|
+ fmt.Println("json.Marshal err:" + err.Error())
|
|
|
+ return err
|
|
|
+ }
|
|
|
+
|
|
|
+ fmt.Println("commentJson")
|
|
|
+ fmt.Println(string(commentJson))
|
|
|
+ templateFile.DeleteComment("Sheet1", "A1")
|
|
|
+ templateFile.AddComment("Sheet1", "A1", string(commentJson))
|
|
|
+ if err := templateFile.SaveAs(filePath); err != nil {
|
|
|
+ fmt.Println(err)
|
|
|
+ return err
|
|
|
+ }
|
|
|
+ time.Sleep(1 * time.Minute)
|
|
|
+ return
|
|
|
+}
|