123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186 |
- package index
- import (
- "encoding/json"
- "fmt"
- "github.com/gin-gonic/gin"
- "github.com/go-playground/validator/v10"
- "github.com/xuri/excelize/v2"
- "hongze/mysteel_watch/controller/resp"
- "hongze/mysteel_watch/global"
- "hongze/mysteel_watch/models/index"
- "hongze/mysteel_watch/utils"
- "hongze/mysteel_watch/watch"
- )
- type IndexController struct {
- }
- func (s *IndexController) ServerCheck(c *gin.Context) {
- resp.OkData("检测成功", 1, c)
- return
- }
- // Add 生成指标
- func (s *IndexController) Create(c *gin.Context) {
- req := new(index.IndexAddReq)
- err := c.Bind(&req)
- if err != nil {
- errs, ok := err.(validator.ValidationErrors)
- if !ok {
- resp.FailData("参数解析失败", "Err:"+err.Error(), c)
- return
- }
- resp.FailData("参数解析失败", errs.Translate(global.Trans), c)
- return
- }
- fmt.Println("indexCode:" + req.IndexCode)
- //fileName := req.IndexName + "_" + req.IndexCode + ".xlsx"
- var fileName string
- if req.UpdateWeek != "" {
- fileName = req.IndexCode + "_" + req.UpdateWeek + ".xlsx" //保存的文件名称
- } else {
- fileName = req.IndexCode + ".xlsx" //保存的文件名称
- }
- filePath := utils.IndexSaveDir + fileName
- templatePath := utils.IndexSaveDir + "index_template.xlsx"
- templateFile, err := excelize.OpenFile(templatePath)
- if err != nil {
- resp.FailData("打开文件失败", "打开文件失败,Err:"+err.Error(), c)
- return
- }
- defer func() {
- templateFile.Close()
- }()
- commentStr := `"BlankValue":"0","CanMark":true,"ChartLineType":"0","DateBlock":0,"DateBlockCount":1,"DateFormat":0,"DateTimeTag":"637979007914770000","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":"2011-03-25","DefineName":"","DefineUnit":"","DisplayIndexCode":"ID01027043","IndexCode":"ID01027043","IndexFormula":"ID01027043","PointValue":0,"UnionStart":""}],"Position":"A1","RangeData":"A2:B2791","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())
- }
- 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)
- resp.FailData("保存失败", "保存失败,Err:"+err.Error(), c)
- return
- }
- resp.Ok("保存成功", c)
- return
- }
- func (s *IndexController) Test(c *gin.Context) {
- watch.TestWatch()
- resp.OkData("检测成功", 1, c)
- return
- }
- type IndexComment struct {
- BlankValue string `json:"BlankValue"`
- CanMark bool `json:"CanMark"`
- ChartLineType string `json:"ChartLineType"`
- DateBlock int64 `json:"DateBlock"`
- DateBlockCount int64 `json:"DateBlockCount"`
- DateFormat int64 `json:"DateFormat"`
- DateTimeTag string `json:"DateTimeTag"`
- EndDate string `json:"EndDate"`
- ExportType int64 `json:"ExportType"`
- HasDescription bool `json:"HasDescription"`
- HasEmptyRows bool `json:"HasEmptyRows"`
- HasFrequency bool `json:"HasFrequency"`
- HasIndexID bool `json:"HasIndexID"`
- HasLastDate bool `json:"HasLastDate"`
- HasSourceName bool `json:"HasSourceName"`
- HasTimeInterval bool `json:"HasTimeInterval"`
- HasUnit bool `json:"HasUnit"`
- HasUpdateDate bool `json:"HasUpdateDate"`
- IsCreateChart bool `json:"IsCreateChart"`
- IsDataSort bool `json:"IsDataSort"`
- IsNewSheet bool `json:"IsNewSheet"`
- IsNewWorkbook bool `json:"IsNewWorkbook"`
- Models []ModelsInfo `json:"Models"`
- Position string `json:"Position"`
- RangeData string `json:"RangeData"`
- ShowBlankLines bool `json:"ShowBlankLines"`
- StartDate string `json:"StartDate"`
- Transpose bool `json:"Transpose"`
- UpdateMode int64 `json:"UpdateMode"`
- LookModel struct {
- IsLast bool `json:"IsLast"`
- LookValue int64 `json:"LookValue"`
- LookType int64 `json:"lookType"`
- } `json:"lookModel"`
- Ver int64 `json:"ver"`
- }
- type ModelsInfo struct {
- DataFormat int64 `json:"DataFormat"`
- DataStartDate string `json:"DataStartDate"`
- DefineName string `json:"DefineName"`
- DefineUnit string `json:"DefineUnit"`
- DisplayIndexCode string `json:"DisplayIndexCode"`
- IndexCode string `json:"IndexCode"`
- IndexFormula string `json:"IndexFormula"`
- PointValue int64 `json:"PointValue"`
- UnionStart string `json:"UnionStart"`
- }
- //
- //commentItem := new(IndexComment)
- //commentItem.BlankValue = "0"
- //commentItem.CanMark = true
- //commentItem.ChartLineType = "0"
- //commentItem.DateBlock = 0
- //commentItem.DateBlockCount = 1
- //commentItem.DateFormat = 0
- //commentItem.DateTimeTag = "637979007914770000"
- //commentItem.EndDate = ""
- //commentItem.ExportType = 0
- //commentItem.HasDescription = true
- //commentItem.HasEmptyRows = false
- //commentItem.HasFrequency = true
- //commentItem.HasIndexID = true
- //commentItem.HasSourceName = true
- //commentItem.HasTimeInterval = true
- //commentItem.HasUnit = true
- //commentItem.HasUpdateDate = true
- //commentItem.IsCreateChart = false
- //commentItem.IsDataSort = true
- //commentItem.IsNewSheet = false
- //commentItem.IsNewWorkbook = false
- //
- //model := new(ModelsInfo)
- //model.DataFormat = 0
- //model.DataStartDate = "2011-03-25"
- //model.DefineName = ""
- //model.DefineUnit = ""
- //model.DisplayIndexCode = req.IndexCode
- //model.IndexCode = req.IndexCode
- //model.IndexFormula = req.IndexCode
- //model.PointValue = 0
- //model.UnionStart = ""
- //commentItem.Models = append(commentItem.Models, *model)
- //commentItem.Position = "A1"
- //commentItem.RangeData = "A2:B2791"
- //commentItem.ShowBlankLines = false
- //commentItem.StartDate = ""
- //commentItem.Transpose = false
- //commentItem.UpdateMode = 0
- //commentItem.LookModel.IsLast = false
- //commentItem.LookModel.LookValue = 0
- //commentItem.LookModel.LookType = 0
- //commentItem.Ver = 3
- //8.136.199.33
- //datamysteel.hzinsights.com
|