|
@@ -6,6 +6,7 @@ import (
|
|
|
"ColdVerify_local/conf"
|
|
|
"ColdVerify_local/lib"
|
|
|
"ColdVerify_local/logs"
|
|
|
+ "ColdVerify_local/models/Certificate"
|
|
|
"ColdVerify_local/models/System"
|
|
|
"ColdVerify_local/models/Task"
|
|
|
"errors"
|
|
@@ -18,7 +19,6 @@ import (
|
|
|
"gonum.org/v1/plot/plotter"
|
|
|
"gonum.org/v1/plot/vg"
|
|
|
"gonum.org/v1/plot/vg/draw"
|
|
|
- "image/color"
|
|
|
"math"
|
|
|
"os"
|
|
|
"strconv"
|
|
@@ -442,6 +442,7 @@ func (c *TaskDataController) TaskData_Add() {
|
|
|
}
|
|
|
if len(sn) > 0 && sn != T_sn {
|
|
|
c.Data["json"] = lib.JSONS{Code: 202, Msg: fmt.Sprintf("编号[%s]已被sn[%s]关联,请修改后重试!", T_id, sn)}
|
|
|
+ c.Data["json"] = lib.JSONS{Code: 202, Msg: fmt.Sprintf("编号[%s]已被sn[%s]关联,请修改后重试!", T_id, sn)}
|
|
|
c.ServeJSON()
|
|
|
return
|
|
|
}
|
|
@@ -2076,9 +2077,9 @@ func TaskDataJPG(StartTime, EndTime, T_task_id, snList string, TemperatureMin, T
|
|
|
p.Y.Label.Text = "温度"
|
|
|
|
|
|
// 添加最高,最低标准线 用红色虚线标识
|
|
|
- p.Add(horizontalLine(xmin, xmax, TemperatureMin))
|
|
|
+ p.Add(lib.HorizontalLine(xmin, xmax, TemperatureMin))
|
|
|
|
|
|
- p.Add(horizontalLine(xmin, xmax, TemperatureMax))
|
|
|
+ p.Add(lib.HorizontalLine(xmin, xmax, TemperatureMax))
|
|
|
|
|
|
var chData = make(chan int, 10)
|
|
|
var jobGroup sync.WaitGroup
|
|
@@ -2116,7 +2117,7 @@ func TaskDataJPG(StartTime, EndTime, T_task_id, snList string, TemperatureMin, T
|
|
|
if err != nil {
|
|
|
return
|
|
|
}
|
|
|
- line.Color = randomColor(index)
|
|
|
+ line.Color = lib.RandomColor(index)
|
|
|
p.Add(line)
|
|
|
}(i)
|
|
|
}
|
|
@@ -2131,9 +2132,9 @@ func TaskDataJPG(StartTime, EndTime, T_task_id, snList string, TemperatureMin, T
|
|
|
p.Y.Min, p.Y.Max = ymin, ymax
|
|
|
|
|
|
p.X.Min, p.X.Max = xmin, xmax
|
|
|
- p.Y.Tick.Marker = commaTicks{}
|
|
|
+ p.Y.Tick.Marker = lib.CommaTicks{}
|
|
|
//p.X.Tick.Marker = plot.TimeTicks{Format: "2006-01-02 15:04:05"}
|
|
|
- p.X.Tick.Marker = timeTicks{}
|
|
|
+ p.X.Tick.Marker = lib.TimeTicks{}
|
|
|
p.X.Tick.Label.Rotation = math.Pi / 5
|
|
|
p.X.Tick.Label.YAlign = draw.YCenter
|
|
|
p.X.Tick.Label.XAlign = draw.XRight
|
|
@@ -2165,213 +2166,32 @@ func TaskDataJPG(StartTime, EndTime, T_task_id, snList string, TemperatureMin, T
|
|
|
|
|
|
}
|
|
|
|
|
|
-func (c *TaskDataController) DeviceData_JPG() {
|
|
|
- StartTime := c.GetString("StartTime")
|
|
|
- if len(StartTime) > 0 {
|
|
|
- _, ok := lib.TimeStrToTime(StartTime)
|
|
|
- if !ok {
|
|
|
- c.Data["json"] = lib.JSONS{Code: 202, Msg: "时间格式错误!"}
|
|
|
- c.ServeJSON()
|
|
|
- return
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- EndTime := c.GetString("EndTime")
|
|
|
- if len(EndTime) > 0 {
|
|
|
- _, ok := lib.TimeStrToTime(EndTime)
|
|
|
- if !ok {
|
|
|
- c.Data["json"] = lib.JSONS{Code: 202, Msg: "时间格式错误!"}
|
|
|
- c.ServeJSON()
|
|
|
- return
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- TemperatureMin, _ := c.GetFloat("TemperatureMin") // 最低温度
|
|
|
- TemperatureMax, _ := c.GetFloat("TemperatureMax") // 最高温度
|
|
|
- if TemperatureMin == 0 {
|
|
|
- TemperatureMin = 2
|
|
|
- }
|
|
|
- if TemperatureMax == 0 {
|
|
|
- TemperatureMax = 8
|
|
|
- }
|
|
|
-
|
|
|
- T_sn := c.GetString("T_sn")
|
|
|
- T_id := c.GetString("T_id")
|
|
|
+func (c *TaskDataController) Certificate_List() {
|
|
|
|
|
|
- //jpg, is := Task.Redis_TaskDataJPG_Get(T_sn)
|
|
|
- //if !is {
|
|
|
- // // 生成图片
|
|
|
- // go DeviceDataJPG(StartTime, EndTime, T_sn, T_id, TemperatureMin, TemperatureMax)
|
|
|
- // c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: Task.TaskDataJPG{State: 1}}
|
|
|
- // c.ServeJSON()
|
|
|
- // return
|
|
|
- //}
|
|
|
- //if jpg.State == 3 {
|
|
|
- // Task.Redis_TaskDataJPG_Del(T_sn)
|
|
|
- // c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: jpg}
|
|
|
- // c.ServeJSON()
|
|
|
- // return
|
|
|
- //}
|
|
|
+ var r_jsons lib.R_JSONS
|
|
|
|
|
|
- url, err := DeviceDataJPG(StartTime, EndTime, T_sn, T_id, TemperatureMin, TemperatureMax)
|
|
|
+ T_task_id := c.GetString("T_task_id")
|
|
|
+ Task_r, err := NatsServer.Read_Task(T_task_id)
|
|
|
if err != nil {
|
|
|
- c.Data["json"] = lib.JSONS{Code: 202, Msg: err.Error()}
|
|
|
+ c.Data["json"] = lib.JSONS{Code: 202, Msg: "T_task_id 错误!"}
|
|
|
c.ServeJSON()
|
|
|
return
|
|
|
}
|
|
|
- c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: url}
|
|
|
- c.ServeJSON()
|
|
|
- return
|
|
|
-}
|
|
|
-
|
|
|
-// 存档生成图片
|
|
|
-func DeviceDataJPG(StartTime, EndTime, T_sn, T_id string, TemperatureMin, TemperatureMax float64) (url string, err error) {
|
|
|
- //Task.Redis_TaskDataJPG_Set(T_sn, Task.TaskDataJPG{
|
|
|
- // State: 1,
|
|
|
- // Url: "",
|
|
|
- //})
|
|
|
- //
|
|
|
- //state := 2
|
|
|
-
|
|
|
- if TemperatureMin == 0 {
|
|
|
- TemperatureMin = 2
|
|
|
- }
|
|
|
- if TemperatureMax == 0 {
|
|
|
- TemperatureMax = 8
|
|
|
- }
|
|
|
-
|
|
|
- ymin, ymax, minTime, maxTime := Task.Read_DeviceData_T_Min_Max_Time_Min_Max(T_sn, T_id, StartTime, EndTime)
|
|
|
- xmin, xmax := float64(minTime.Unix()), float64(maxTime.Unix())
|
|
|
- // 创建一个新的绘图
|
|
|
- p := plot.New()
|
|
|
-
|
|
|
- // 设置绘图标题和标签
|
|
|
- p.Title.Text = "温度折线图"
|
|
|
- //p.Legend.ThumbnailWidth = 5 * vg.Inch
|
|
|
- p.X.Label.Text = "时间"
|
|
|
- p.Y.Label.Text = "温度"
|
|
|
-
|
|
|
- // 添加最高,最低标准线 用红色虚线标识
|
|
|
- p.Add(horizontalLine(xmin, xmax, TemperatureMin))
|
|
|
-
|
|
|
- p.Add(horizontalLine(xmin, xmax, TemperatureMax))
|
|
|
-
|
|
|
- list := Task.Read_DeviceData_ById_List(T_sn, T_id, StartTime, EndTime)
|
|
|
-
|
|
|
- pts := make(plotter.XYs, len(list))
|
|
|
- for j, d := range list {
|
|
|
- t, _ := lib.TimeStrToTime(d.T_time)
|
|
|
- pts[j].X = float64(t.Unix())
|
|
|
- pts[j].Y = float64(d.T_t)
|
|
|
+ if Task_r.T_collection_state == 2 {
|
|
|
+ c.Data["json"] = lib.JSONS{Code: 202, Msg: "数据采集中,请稍后!"}
|
|
|
+ c.ServeJSON()
|
|
|
+ return
|
|
|
}
|
|
|
|
|
|
- line, err := plotter.NewLine(pts)
|
|
|
+ List, err := Certificate.Read_Certificate_List(T_task_id)
|
|
|
if err != nil {
|
|
|
+ c.Data["json"] = lib.JSONS{Code: 202, Msg: "查询失败!"}
|
|
|
+ c.ServeJSON()
|
|
|
return
|
|
|
}
|
|
|
- line.Color = randomColor(0)
|
|
|
- p.Add(line)
|
|
|
-
|
|
|
- if ymax < 8 {
|
|
|
- ymax = 8
|
|
|
- }
|
|
|
- if ymin > 0 {
|
|
|
- ymin = 0
|
|
|
- }
|
|
|
- p.Y.Min, p.Y.Max = ymin, ymax
|
|
|
-
|
|
|
- p.X.Min, p.X.Max = xmin, xmax
|
|
|
- p.Y.Tick.Marker = commaTicks{}
|
|
|
- //p.X.Tick.Marker = plot.TimeTicks{Format: "2006-01-02 15:04:05"}
|
|
|
- p.X.Tick.Marker = timeTicks{}
|
|
|
- p.X.Tick.Label.Rotation = math.Pi / 5
|
|
|
- p.X.Tick.Label.YAlign = draw.YCenter
|
|
|
- p.X.Tick.Label.XAlign = draw.XRight
|
|
|
+ r_jsons.List = List
|
|
|
|
|
|
- filename := "jpg" + time.Now().Format("20060102150405")
|
|
|
- // 保存文件
|
|
|
- if err := p.Save(10*vg.Inch, 4*vg.Inch, "ofile/"+filename+".jpg"); err != nil {
|
|
|
- logs.Error(lib.FuncName(), "生成图片失败", err)
|
|
|
- }
|
|
|
- if !lib.Pload_qiniu("ofile/"+filename+".jpg", "ofile/"+filename+".jpg") {
|
|
|
- logs.Error(lib.FuncName(), "上传七牛云失败")
|
|
|
- }
|
|
|
- //删除目录
|
|
|
- os.Remove("ofile/" + filename + ".jpg")
|
|
|
- url = "https://bzdcoldverifyoss.baozhida.cn/" + "ofile/" + filename + ".jpg"
|
|
|
+ c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: r_jsons}
|
|
|
+ c.ServeJSON()
|
|
|
return
|
|
|
-
|
|
|
- //Task.Redis_TaskDataJPG_Set(T_sn, Task.TaskDataJPG{
|
|
|
- // State: state,
|
|
|
- // Url: "https://bzdcoldverifyoss.baozhida.cn/" + "ofile/" + filename + ".jpg",
|
|
|
- //})
|
|
|
-
|
|
|
-}
|
|
|
-
|
|
|
-func horizontalLine(xmin, xmax, y float64) *plotter.Line {
|
|
|
- pts := make(plotter.XYs, 2)
|
|
|
- pts[0].X = xmin
|
|
|
- pts[0].Y = y
|
|
|
- pts[1].X = xmax
|
|
|
- pts[1].Y = y
|
|
|
- line, err := plotter.NewLine(pts)
|
|
|
- if err != nil {
|
|
|
- panic(err)
|
|
|
- }
|
|
|
- line.LineStyle.Dashes = []vg.Length{vg.Points(8), vg.Points(5), vg.Points(1), vg.Points(5)}
|
|
|
- line.Color = color.RGBA{R: 255, A: 255}
|
|
|
- return line
|
|
|
-}
|
|
|
-
|
|
|
-type timeTicks struct{}
|
|
|
-
|
|
|
-func (timeTicks) Ticks(min, max float64) []plot.Tick {
|
|
|
- tks := plot.TimeTicks{}.Ticks(min, max)
|
|
|
- for i, t := range tks {
|
|
|
- //if t.Label == "" { // Skip minor ticks, they are fine.
|
|
|
- // continue
|
|
|
- //}
|
|
|
- tks[i].Label = time.Unix(int64(t.Value), 0).Format("2006-01-02 15:04:05")
|
|
|
- }
|
|
|
-
|
|
|
- return tks
|
|
|
-}
|
|
|
-
|
|
|
-type commaTicks struct{}
|
|
|
-
|
|
|
-// Ticks computes the default tick marks, but inserts commas
|
|
|
-// into the labels for the major tick marks.
|
|
|
-func (commaTicks) Ticks(min, max float64) []plot.Tick {
|
|
|
- tks := plot.DefaultTicks{}.Ticks(min, max)
|
|
|
- for i, t := range tks {
|
|
|
- //if t.Label == "" { // Skip minor ticks, they are fine.
|
|
|
- // continue
|
|
|
- //}
|
|
|
- tks[i].Label = fmt.Sprintf("%.0f", t.Value)
|
|
|
- }
|
|
|
-
|
|
|
- return tks
|
|
|
-}
|
|
|
-
|
|
|
-// 生成随机颜色的辅助函数
|
|
|
-func randomColor(i int) color.RGBA {
|
|
|
- var colors []color.RGBA
|
|
|
- colors = append(colors,
|
|
|
- color.RGBA{R: 52, G: 152, B: 219, A: 255},
|
|
|
- color.RGBA{R: 230, G: 126, B: 34, A: 255},
|
|
|
- color.RGBA{R: 142, G: 68, B: 173, A: 255},
|
|
|
- color.RGBA{R: 211, G: 84, B: 0, A: 255},
|
|
|
- color.RGBA{R: 231, G: 76, B: 60, A: 255},
|
|
|
- color.RGBA{R: 26, G: 188, B: 156, A: 255},
|
|
|
- color.RGBA{R: 243, G: 156, B: 18, A: 255},
|
|
|
- color.RGBA{R: 22, G: 160, B: 133, A: 255},
|
|
|
- color.RGBA{R: 46, G: 204, B: 113, A: 255},
|
|
|
- color.RGBA{R: 39, G: 174, B: 96, A: 255},
|
|
|
- color.RGBA{R: 41, G: 128, B: 185, A: 255},
|
|
|
- color.RGBA{R: 155, G: 89, B: 182, A: 255},
|
|
|
- color.RGBA{R: 192, G: 57, B: 43, A: 255},
|
|
|
- color.RGBA{R: 241, G: 196, B: 15, A: 255},
|
|
|
- )
|
|
|
-
|
|
|
- return colors[i%len(colors)]
|
|
|
}
|