|
@@ -209,7 +209,6 @@ func (c *TaskDataController) TaskData_AddS() {
|
|
|
var T_Data_list_x = 0
|
|
|
|
|
|
snMaps := make(map[string]string)
|
|
|
- var valueStrings []string
|
|
|
|
|
|
for _, v := range T_Data_list {
|
|
|
// 132|132|23.9|72.1|2023-04-30 07:03:00
|
|
@@ -227,13 +226,9 @@ func (c *TaskDataController) TaskData_AddS() {
|
|
|
c.ServeJSON()
|
|
|
return
|
|
|
}
|
|
|
- t, _ := lib.ReplaceSeconds(v_list[4])
|
|
|
- valueStrings = append(valueStrings, fmt.Sprintf("('%s','%s',%v,%v,'%v')", v_list[0], v_list[1], v_list[2], v_list[3], t))
|
|
|
- T_Data_list_x += 1
|
|
|
}
|
|
|
|
|
|
for T_id, T_sn := range snMaps {
|
|
|
-
|
|
|
sn, err := Task.Read_TaskData_ByT_id(Task_r.T_task_id, T_id)
|
|
|
if err != nil && !errors.Is(err, orm.ErrNoRows) {
|
|
|
continue
|
|
@@ -265,7 +260,6 @@ func (c *TaskDataController) TaskData_AddS() {
|
|
|
}
|
|
|
v_list := strings.Split(v, "|")
|
|
|
t, _ := lib.ReplaceSeconds(v_list[4])
|
|
|
-
|
|
|
is := Task.Add_TaskData(Task_r.T_task_id, v_list[0], v_list[1], v_list[2], v_list[3], t)
|
|
|
if is {
|
|
|
T_Data_list_x += 1
|
|
@@ -1978,6 +1972,21 @@ func (c *TaskDataController) TaskDataCopy_Recover() {
|
|
|
|
|
|
}
|
|
|
|
|
|
+// 查询图片生成状态
|
|
|
+func (c *TaskDataController) TaskData_JPGState() {
|
|
|
+
|
|
|
+ T_task_id := c.GetString("T_task_id")
|
|
|
+ jpg, is := Task.Redis_TaskDataJPG_Get(T_task_id)
|
|
|
+ if !is {
|
|
|
+ c.Data["json"] = lib.JSONS{Code: 202, Msg: "暂无图片正在生成"}
|
|
|
+ c.ServeJSON()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: jpg}
|
|
|
+ c.ServeJSON()
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
func (c *TaskDataController) TaskData_JPG() {
|
|
|
StartTime := c.GetString("StartTime")
|
|
|
if len(StartTime) > 0 {
|
|
@@ -2021,33 +2030,26 @@ func (c *TaskDataController) TaskData_JPG() {
|
|
|
c.ServeJSON()
|
|
|
return
|
|
|
}
|
|
|
- jpg, is := Task.Redis_TaskDataJPG_Get(T_task_id)
|
|
|
- if !is {
|
|
|
- // 生成图片
|
|
|
- go Gen_JPG(StartTime, EndTime, T_task_id, SN_List, 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_task_id)
|
|
|
- c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: jpg}
|
|
|
- c.ServeJSON()
|
|
|
- return
|
|
|
- }
|
|
|
- c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: jpg}
|
|
|
+ Task.Redis_TaskDataJPG_Del(T_task_id)
|
|
|
+
|
|
|
+ // 生成图片
|
|
|
+ go TaskDataJPG(StartTime, EndTime, T_task_id, SN_List, TemperatureMin, TemperatureMax)
|
|
|
+
|
|
|
+ c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
|
|
|
c.ServeJSON()
|
|
|
return
|
|
|
}
|
|
|
|
|
|
// 存档生成图片
|
|
|
-func Gen_JPG(StartTime, EndTime, T_task_id, snList string, TemperatureMin, TemperatureMax float64) {
|
|
|
+func TaskDataJPG(StartTime, EndTime, T_task_id, snList string, TemperatureMin, TemperatureMax float64) {
|
|
|
Task.Redis_TaskDataJPG_Set(T_task_id, Task.TaskDataJPG{
|
|
|
State: 1,
|
|
|
+ Msg: "图片生成中",
|
|
|
Url: "",
|
|
|
})
|
|
|
-
|
|
|
+ msg := ""
|
|
|
state := 2
|
|
|
+ url := ""
|
|
|
|
|
|
if TemperatureMin == 0 {
|
|
|
TemperatureMin = 2
|
|
@@ -2153,22 +2155,172 @@ func Gen_JPG(StartTime, EndTime, T_task_id, snList string, TemperatureMin, Tempe
|
|
|
// 保存文件
|
|
|
if err := p.Save(10*vg.Inch, 4*vg.Inch, "ofile/"+filename+".jpg"); err != nil {
|
|
|
state = 3
|
|
|
+ msg = "图片生成失败"
|
|
|
logs.Error(lib.FuncName(), "生成图片失败", err)
|
|
|
}
|
|
|
if !lib.Pload_qiniu("ofile/"+filename+".jpg", "ofile/"+filename+".jpg") {
|
|
|
state = 3
|
|
|
+ msg = "图片上传七牛云失败"
|
|
|
logs.Error(lib.FuncName(), "上传七牛云失败")
|
|
|
}
|
|
|
//删除目录
|
|
|
os.Remove("ofile/" + filename + ".jpg")
|
|
|
+ if len(msg) == 0 {
|
|
|
+ msg = "图片生成成功"
|
|
|
+ url = "https://bzdcoldverifyoss.baozhida.cn/" + "ofile/" + filename + ".jpg"
|
|
|
+ }
|
|
|
|
|
|
Task.Redis_TaskDataJPG_Set(T_task_id, Task.TaskDataJPG{
|
|
|
State: state,
|
|
|
- Url: "https://bzdcoldverifyoss.baozhida.cn/" + "ofile/" + filename + ".jpg",
|
|
|
+ Msg: msg,
|
|
|
+ Url: url,
|
|
|
})
|
|
|
|
|
|
}
|
|
|
|
|
|
+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")
|
|
|
+
|
|
|
+ //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
|
|
|
+ //}
|
|
|
+
|
|
|
+ url, err := DeviceDataJPG(StartTime, EndTime, T_sn, T_id, TemperatureMin, TemperatureMax)
|
|
|
+ if err != nil {
|
|
|
+ c.Data["json"] = lib.JSONS{Code: 202, Msg: err.Error()}
|
|
|
+ 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)
|
|
|
+ }
|
|
|
+
|
|
|
+ line, err := plotter.NewLine(pts)
|
|
|
+ if err != nil {
|
|
|
+ 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
|
|
|
+
|
|
|
+ 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"
|
|
|
+ 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
|