|
@@ -863,6 +863,13 @@ func (c *DataController) Device_Sensor_Data_PDF() {
|
|
|
e_time = fmt.Sprintf("%s", DeviceSensor_data[len(DeviceSensor_data)-1].T_time)
|
|
|
}
|
|
|
lib.RectFillColor(pdf, "历史数据["+e_time+" / "+s_time+"]", 14, 22, 80, 550, 40, 255, 255, 255, lib.AlignCenter, lib.ValignMiddle)
|
|
|
+ pdf.SetFont("wts", "", 10)
|
|
|
+ pages := pdf.GetNumberOfPages()
|
|
|
+ pagenums := fmt.Sprintf("第 %d 页", pages)
|
|
|
+ pagenum, _ := pdf.MeasureTextWidth(pagenums)
|
|
|
+ pdf.SetX((595 / 2) - (pagenum / 2))
|
|
|
+ pdf.SetY(830)
|
|
|
+ pdf.Cell(nil, pagenums)
|
|
|
var y float64 = 120
|
|
|
if T_ist == 1 {
|
|
|
lib.RectFillColor(pdf, fmt.Sprintf("最高温度: %.1f ", maxTemp), 12, 22, y, 183, 20, 255, 255, 255, lib.AlignCenter, lib.ValignMiddle)
|
|
@@ -938,6 +945,12 @@ func (c *DataController) Device_Sensor_Data_PDF() {
|
|
|
|
|
|
lib.RectFillColor(pdf, "记录时间", 12, 412, y, 120, 20, 255, 255, 255, lib.AlignCenter, lib.ValignMiddle)
|
|
|
lib.RectFillColor(pdf, "备注", 12, 532, y, 40, 20, 255, 255, 255, lib.AlignCenter, lib.ValignMiddle)
|
|
|
+ pages := pdf.GetNumberOfPages()
|
|
|
+ pagenums := fmt.Sprintf("第 %d 页", pages)
|
|
|
+ pagenum, _ := pdf.MeasureTextWidth(pagenums)
|
|
|
+ pdf.SetX((595 / 2) - (pagenum / 2))
|
|
|
+ pdf.SetY(830) // 设置页码位置
|
|
|
+ pdf.Cell(nil, pagenums)
|
|
|
y += 20
|
|
|
}
|
|
|
//pdf.SetX(x) // must after pdf.SetNewY() called.
|
|
@@ -988,7 +1001,6 @@ func (c *DataController) Device_Sensor_Data_PDF() {
|
|
|
y += 20
|
|
|
}
|
|
|
timeStr := "ofile/" + time.Now().Format("20060102150405") + ".pdf"
|
|
|
-
|
|
|
err = pdf.WritePdf(timeStr)
|
|
|
if err != nil {
|
|
|
c.Data["json"] = lib.JSONS{Code: 202, Msg: err.Error()}
|
|
@@ -1337,13 +1349,19 @@ func Device_Sensor_Data_ChartShow_PDF1(companyName, T_snid, Time_start, Time_end
|
|
|
pdf.ImageByHolder(imgH, 10, y, &gopdf.Rect{W: 575, H: 315})
|
|
|
y += 315
|
|
|
}
|
|
|
+ pdf.SetFont("wts", "", 10)
|
|
|
+ pages := pdf.GetNumberOfPages()
|
|
|
+ pagenums := fmt.Sprintf("第 %d 页", pages)
|
|
|
+ pagenum, _ := pdf.MeasureTextWidth(pagenums)
|
|
|
+ pdf.SetX((595 / 2) - (pagenum / 2))
|
|
|
+ pdf.SetY(830) // 设置页码位置
|
|
|
+ pdf.Cell(nil, pagenums)
|
|
|
y += 35
|
|
|
if y > 841.89 {
|
|
|
// 图片结束直接分页
|
|
|
pdf.AddPage()
|
|
|
y = 40
|
|
|
}
|
|
|
-
|
|
|
pdf.SetFont("wts", "", 16)
|
|
|
pdf.SetXY(10, y)
|
|
|
pdf.Text("记录数据信息")
|
|
@@ -1374,15 +1392,59 @@ func Device_Sensor_Data_ChartShow_PDF1(companyName, T_snid, Time_start, Time_end
|
|
|
x = x + w
|
|
|
w = 74
|
|
|
lib.RectFillColor(pdf, "T1", 12, x, y, w, 20, 255, 255, 255, lib.AlignCenter, lib.ValignMiddle)
|
|
|
-
|
|
|
+ count := 0
|
|
|
for i, v := range Pdf_data {
|
|
|
+ //y = pdf.GetY()
|
|
|
+ //if y <= 20 {
|
|
|
+ // var x float64 = 19
|
|
|
+ // var w float64 = 112
|
|
|
+ // fmt.Println(pdf.GetY())
|
|
|
+ // lib.RectFillColor(pdf, "时间", 12, x, y, w, 20, 255, 255, 255, lib.AlignCenter, lib.ValignMiddle)
|
|
|
+ // x = x + w
|
|
|
+ // w = 74
|
|
|
+ // lib.RectFillColor(pdf, "T1", 12, x, y, w, 20, 255, 255, 255, lib.AlignCenter, lib.ValignMiddle)
|
|
|
+ // x = x + w
|
|
|
+ // w = 110
|
|
|
+ // lib.RectFillColor(pdf, "时间", 12, x, y, w, 20, 255, 255, 255, lib.AlignCenter, lib.ValignMiddle)
|
|
|
+ // x = x + w
|
|
|
+ // w = 74
|
|
|
+ // lib.RectFillColor(pdf, "T1", 12, x, y, w, 20, 255, 255, 255, lib.AlignCenter, lib.ValignMiddle)
|
|
|
+ // x = x + w
|
|
|
+ // w = 110
|
|
|
+ // lib.RectFillColor(pdf, "时间", 12, x, y, w, 20, 255, 255, 255, lib.AlignCenter, lib.ValignMiddle)
|
|
|
+ // x = x + w
|
|
|
+ // w = 74
|
|
|
+ // lib.RectFillColor(pdf, "T1", 12, x, y, w, 20, 255, 255, 255, lib.AlignCenter, lib.ValignMiddle)
|
|
|
+ // y += 20
|
|
|
+ //}
|
|
|
if i%3 == 0 {
|
|
|
y += 20
|
|
|
x, w = 19, 112
|
|
|
var textH float64 = 25 // if text height is 25px.
|
|
|
pdf.SetNewY(y, textH)
|
|
|
y = pdf.GetY()
|
|
|
-
|
|
|
+ if y <= 20 {
|
|
|
+ var x float64 = 19
|
|
|
+ var w float64 = 112
|
|
|
+ fmt.Println(pdf.GetY())
|
|
|
+ lib.RectFillColor(pdf, "时间", 12, x, y, w, 20, 255, 255, 255, lib.AlignCenter, lib.ValignMiddle)
|
|
|
+ x = x + w
|
|
|
+ w = 74
|
|
|
+ lib.RectFillColor(pdf, "T1", 12, x, y, w, 20, 255, 255, 255, lib.AlignCenter, lib.ValignMiddle)
|
|
|
+ x = x + w
|
|
|
+ w = 110
|
|
|
+ lib.RectFillColor(pdf, "时间", 12, x, y, w, 20, 255, 255, 255, lib.AlignCenter, lib.ValignMiddle)
|
|
|
+ x = x + w
|
|
|
+ w = 74
|
|
|
+ lib.RectFillColor(pdf, "T1", 12, x, y, w, 20, 255, 255, 255, lib.AlignCenter, lib.ValignMiddle)
|
|
|
+ x = x + w
|
|
|
+ w = 110
|
|
|
+ lib.RectFillColor(pdf, "时间", 12, x, y, w, 20, 255, 255, 255, lib.AlignCenter, lib.ValignMiddle)
|
|
|
+ x = x + w
|
|
|
+ w = 74
|
|
|
+ lib.RectFillColor(pdf, "T1", 12, x, y, w, 20, 255, 255, 255, lib.AlignCenter, lib.ValignMiddle)
|
|
|
+ y += 20
|
|
|
+ }
|
|
|
lib.RectFillColor(pdf, v.T_time, 12, x, y, w, 20, 255, 255, 255, lib.AlignCenter, lib.ValignMiddle)
|
|
|
x = x + w
|
|
|
w = 74
|
|
@@ -1404,8 +1466,25 @@ func Device_Sensor_Data_ChartShow_PDF1(companyName, T_snid, Time_start, Time_end
|
|
|
w = 74
|
|
|
lib.RectFillColor(pdf, lib.Float32_to_string(v.T_id1), 12, x, y, w, 20, 255, 255, 255, lib.AlignCenter, lib.ValignMiddle)
|
|
|
}
|
|
|
-
|
|
|
+ if pdf.GetY() >= 804 {
|
|
|
+ count++
|
|
|
+ if count == 3 {
|
|
|
+ count = 0
|
|
|
+ pages := pdf.GetNumberOfPages()
|
|
|
+ pagenums := fmt.Sprintf("第 %d 页", pages)
|
|
|
+ pagenum, _ := pdf.MeasureTextWidth(pagenums)
|
|
|
+ pdf.SetX((595 / 2) - (pagenum / 2))
|
|
|
+ pdf.SetY(830) // 设置页码位置
|
|
|
+ pdf.Cell(nil, pagenums)
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
+ pages := pdf.GetNumberOfPages()
|
|
|
+ pagenums := fmt.Sprintf("第 %d 页", pages)
|
|
|
+ pagenum, _ := pdf.MeasureTextWidth(pagenums)
|
|
|
+ pdf.SetX((595 / 2) - (pagenum / 2))
|
|
|
+ pdf.SetY(830) // 设置页码位置
|
|
|
+ pdf.Cell(nil, pagenums)
|
|
|
}
|
|
|
if len(snidNum) == 2 {
|
|
|
var x float64 = 19
|
|
@@ -1434,13 +1513,42 @@ func Device_Sensor_Data_ChartShow_PDF1(companyName, T_snid, Time_start, Time_end
|
|
|
lib.RectFillColor(pdf, "T1", 12, x, y, w, 20, 255, 255, 255, lib.AlignCenter, lib.ValignMiddle)
|
|
|
x = x + w
|
|
|
lib.RectFillColor(pdf, "T2", 12, x, y, w, 20, 255, 255, 255, lib.AlignCenter, lib.ValignMiddle)
|
|
|
-
|
|
|
+ count := 0
|
|
|
for i, v := range Pdf_data {
|
|
|
if i%3 == 0 {
|
|
|
y += 20
|
|
|
var textH float64 = 25 // if text height is 25px.
|
|
|
pdf.SetNewY(y, textH)
|
|
|
y = pdf.GetY()
|
|
|
+ if y <= 20 {
|
|
|
+ var x float64 = 19
|
|
|
+ var w float64 = 112
|
|
|
+ lib.RectFillColor(pdf, "时间", 12, x, y, w, 20, 255, 255, 255, lib.AlignCenter, lib.ValignMiddle)
|
|
|
+ x = x + w
|
|
|
+ w = 37
|
|
|
+ lib.RectFillColor(pdf, "T1", 12, x, y, w, 20, 255, 255, 255, lib.AlignCenter, lib.ValignMiddle)
|
|
|
+ x = x + w
|
|
|
+ lib.RectFillColor(pdf, "T2", 12, x, y, w, 20, 255, 255, 255, lib.AlignCenter, lib.ValignMiddle)
|
|
|
+
|
|
|
+ x = x + w
|
|
|
+ w = 112
|
|
|
+ lib.RectFillColor(pdf, "时间", 12, x, y, w, 20, 255, 255, 255, lib.AlignCenter, lib.ValignMiddle)
|
|
|
+ x = x + w
|
|
|
+ w = 37
|
|
|
+ lib.RectFillColor(pdf, "T1", 12, x, y, w, 20, 255, 255, 255, lib.AlignCenter, lib.ValignMiddle)
|
|
|
+ x = x + w
|
|
|
+ lib.RectFillColor(pdf, "T2", 12, x, y, w, 20, 255, 255, 255, lib.AlignCenter, lib.ValignMiddle)
|
|
|
+
|
|
|
+ x = x + w
|
|
|
+ w = 112
|
|
|
+ lib.RectFillColor(pdf, "时间", 12, x, y, w, 20, 255, 255, 255, lib.AlignCenter, lib.ValignMiddle)
|
|
|
+ x = x + w
|
|
|
+ w = 37
|
|
|
+ lib.RectFillColor(pdf, "T1", 12, x, y, w, 20, 255, 255, 255, lib.AlignCenter, lib.ValignMiddle)
|
|
|
+ x = x + w
|
|
|
+ lib.RectFillColor(pdf, "T2", 12, x, y, w, 20, 255, 255, 255, lib.AlignCenter, lib.ValignMiddle)
|
|
|
+ y += 20
|
|
|
+ }
|
|
|
x, w = 19, 112
|
|
|
lib.RectFillColor(pdf, v.T_time, 12, x, y, w, 20, 255, 255, 255, lib.AlignCenter, lib.ValignMiddle)
|
|
|
x = x + w
|
|
@@ -1469,8 +1577,25 @@ func Device_Sensor_Data_ChartShow_PDF1(companyName, T_snid, Time_start, Time_end
|
|
|
x = x + w
|
|
|
lib.RectFillColor(pdf, lib.Float32_to_string(v.T_id2), 12, x, y, w, 20, 255, 255, 255, lib.AlignCenter, lib.ValignMiddle)
|
|
|
}
|
|
|
-
|
|
|
+ if pdf.GetY() >= 804 {
|
|
|
+ count++
|
|
|
+ if count == 3 {
|
|
|
+ count = 0
|
|
|
+ pages := pdf.GetNumberOfPages()
|
|
|
+ pagenums := fmt.Sprintf("第 %d 页", pages)
|
|
|
+ pagenum, _ := pdf.MeasureTextWidth(pagenums)
|
|
|
+ pdf.SetX((595 / 2) - (pagenum / 2))
|
|
|
+ pdf.SetY(830) // 设置页码位置
|
|
|
+ pdf.Cell(nil, pagenums)
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
+ pages := pdf.GetNumberOfPages()
|
|
|
+ pagenums := fmt.Sprintf("第 %d 页", pages)
|
|
|
+ pagenum, _ := pdf.MeasureTextWidth(pagenums)
|
|
|
+ pdf.SetX((595 / 2) - (pagenum / 2))
|
|
|
+ pdf.SetY(830) // 设置页码位置
|
|
|
+ pdf.Cell(nil, pagenums)
|
|
|
}
|
|
|
|
|
|
timeStr := "ofile/" + time.Now().Format("20060102150405") + ".pdf"
|
|
@@ -1786,6 +1911,13 @@ func Device_Sensor_Data_ChartShow_PDF0(companyName, T_snid, Time_start, Time_end
|
|
|
y += 315
|
|
|
}
|
|
|
y += 35
|
|
|
+ pdf.SetFont("wts", "", 10)
|
|
|
+ pages := pdf.GetNumberOfPages()
|
|
|
+ pagenums := fmt.Sprintf("第 %d 页", pages)
|
|
|
+ pagenum, _ := pdf.MeasureTextWidth(pagenums)
|
|
|
+ pdf.SetX((595 / 2) - (pagenum / 2))
|
|
|
+ pdf.SetY(830) // 设置页码位置
|
|
|
+ pdf.Cell(nil, pagenums)
|
|
|
if y > 841.89 {
|
|
|
// 图片结束直接分页
|
|
|
pdf.AddPage()
|
|
@@ -1857,6 +1989,65 @@ func Device_Sensor_Data_ChartShow_PDF0(companyName, T_snid, Time_start, Time_end
|
|
|
for i, v := range first_column {
|
|
|
pdf.SetNewY(y, textH)
|
|
|
y = pdf.GetY()
|
|
|
+ if y <= 20 {
|
|
|
+ pages := pdf.GetNumberOfPages()
|
|
|
+ pagenums := fmt.Sprintf("第 %d 页", pages)
|
|
|
+ pagenum, _ := pdf.MeasureTextWidth(pagenums)
|
|
|
+ pdf.SetX((595 / 2) - (pagenum / 2))
|
|
|
+ pdf.SetY(830) // 设置页码位置
|
|
|
+ pdf.Cell(nil, pagenums)
|
|
|
+ var x float64 = 10
|
|
|
+ var w float64 = 112
|
|
|
+ lib.RectFillColor(pdf, "时间", 12, x, y, w, 20, 255, 255, 255, lib.AlignCenter, lib.ValignMiddle)
|
|
|
+ x = x + w
|
|
|
+ w = 101
|
|
|
+ lib.RectFillColor(pdf, "名称", 12, x, y, w, 20, 255, 255, 255, lib.AlignCenter, lib.ValignMiddle)
|
|
|
+
|
|
|
+ if T_temp_show == 1 && T_Humidity_show == 1 {
|
|
|
+ x = x + w
|
|
|
+ w = 37
|
|
|
+ lib.RectFillColor(pdf, "温度℃", 12, x, y, w, 20, 255, 255, 255, lib.AlignCenter, lib.ValignMiddle)
|
|
|
+ x = x + w
|
|
|
+ w = 37
|
|
|
+ lib.RectFillColor(pdf, "湿度%", 12, x, y, w, 20, 255, 255, 255, lib.AlignCenter, lib.ValignMiddle)
|
|
|
+ }
|
|
|
+ if T_temp_show == 1 && T_Humidity_show == 0 {
|
|
|
+ x = x + w
|
|
|
+ w = 74
|
|
|
+ lib.RectFillColor(pdf, "温度℃", 12, x, y, w, 20, 255, 255, 255, lib.AlignCenter, lib.ValignMiddle)
|
|
|
+ }
|
|
|
+ if T_temp_show == 0 && T_Humidity_show == 1 {
|
|
|
+ x = x + w
|
|
|
+ w = 74
|
|
|
+ lib.RectFillColor(pdf, "湿度%", 12, x, y, w, 20, 255, 255, 255, lib.AlignCenter, lib.ValignMiddle)
|
|
|
+ }
|
|
|
+
|
|
|
+ x = x + w
|
|
|
+ w = 112
|
|
|
+ lib.RectFillColor(pdf, "时间", 12, x, y, w, 20, 255, 255, 255, lib.AlignCenter, lib.ValignMiddle)
|
|
|
+ x = x + w
|
|
|
+ w = 101
|
|
|
+ lib.RectFillColor(pdf, "名称", 12, x, y, w, 20, 255, 255, 255, lib.AlignCenter, lib.ValignMiddle)
|
|
|
+ if T_temp_show == 1 && T_Humidity_show == 1 {
|
|
|
+ x = x + w
|
|
|
+ w = 37
|
|
|
+ lib.RectFillColor(pdf, "温度℃", 12, x, y, w, 20, 255, 255, 255, lib.AlignCenter, lib.ValignMiddle)
|
|
|
+ x = x + w
|
|
|
+ w = 37
|
|
|
+ lib.RectFillColor(pdf, "湿度%", 12, x, y, w, 20, 255, 255, 255, lib.AlignCenter, lib.ValignMiddle)
|
|
|
+ }
|
|
|
+ if T_temp_show == 1 && T_Humidity_show == 0 {
|
|
|
+ x = x + w
|
|
|
+ w = 74
|
|
|
+ lib.RectFillColor(pdf, "温度℃", 12, x, y, w, 20, 255, 255, 255, lib.AlignCenter, lib.ValignMiddle)
|
|
|
+ }
|
|
|
+ if T_temp_show == 0 && T_Humidity_show == 1 {
|
|
|
+ x = x + w
|
|
|
+ w = 74
|
|
|
+ lib.RectFillColor(pdf, "湿度%", 12, x, y, w, 20, 255, 255, 255, lib.AlignCenter, lib.ValignMiddle)
|
|
|
+ }
|
|
|
+ y += 20
|
|
|
+ }
|
|
|
x, w = 10, 112
|
|
|
|
|
|
lib.RectFillColor(pdf, v.T_time, 12, x, y, w, 20, 255, 255, 255, lib.AlignCenter, lib.ValignMiddle)
|
|
@@ -1913,14 +2104,79 @@ func Device_Sensor_Data_ChartShow_PDF0(companyName, T_snid, Time_start, Time_end
|
|
|
lib.RectFillColor(pdf, fmt.Sprintf(" %.1f ", second_column[i].T_rh), 12, x, y, w, 20, 255, 255, 255, lib.AlignCenter, lib.ValignMiddle)
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
y += 20
|
|
|
+ if y >= 820 {
|
|
|
+ pages := pdf.GetNumberOfPages()
|
|
|
+ pagenums := fmt.Sprintf("第 %d 页", pages)
|
|
|
+ pagenum, _ := pdf.MeasureTextWidth(pagenums)
|
|
|
+ pdf.SetX((595 / 2) - (pagenum / 2))
|
|
|
+ pdf.SetY(830) // 设置页码位置
|
|
|
+ pdf.Cell(nil, pagenums)
|
|
|
+ }
|
|
|
}
|
|
|
if len(second_column) > len(first_column) {
|
|
|
for i := len(first_column); i < len(second_column); i++ {
|
|
|
-
|
|
|
pdf.SetNewY(y, textH)
|
|
|
y = pdf.GetY()
|
|
|
+ if y <= 20 {
|
|
|
+ pages := pdf.GetNumberOfPages()
|
|
|
+ pagenums := fmt.Sprintf("第 %d 页", pages)
|
|
|
+ pagenum, _ := pdf.MeasureTextWidth(pagenums)
|
|
|
+ pdf.SetX((595 / 2) - (pagenum / 2))
|
|
|
+ pdf.SetY(830) // 设置页码位置
|
|
|
+ pdf.Cell(nil, pagenums)
|
|
|
+ var x float64 = 10
|
|
|
+ var w float64 = 112
|
|
|
+ lib.RectFillColor(pdf, "时间", 12, x, y, w, 20, 255, 255, 255, lib.AlignCenter, lib.ValignMiddle)
|
|
|
+ x = x + w
|
|
|
+ w = 101
|
|
|
+ lib.RectFillColor(pdf, "名称", 12, x, y, w, 20, 255, 255, 255, lib.AlignCenter, lib.ValignMiddle)
|
|
|
+
|
|
|
+ if T_temp_show == 1 && T_Humidity_show == 1 {
|
|
|
+ x = x + w
|
|
|
+ w = 37
|
|
|
+ lib.RectFillColor(pdf, "温度℃", 12, x, y, w, 20, 255, 255, 255, lib.AlignCenter, lib.ValignMiddle)
|
|
|
+ x = x + w
|
|
|
+ w = 37
|
|
|
+ lib.RectFillColor(pdf, "湿度%", 12, x, y, w, 20, 255, 255, 255, lib.AlignCenter, lib.ValignMiddle)
|
|
|
+ }
|
|
|
+ if T_temp_show == 1 && T_Humidity_show == 0 {
|
|
|
+ x = x + w
|
|
|
+ w = 74
|
|
|
+ lib.RectFillColor(pdf, "温度℃", 12, x, y, w, 20, 255, 255, 255, lib.AlignCenter, lib.ValignMiddle)
|
|
|
+ }
|
|
|
+ if T_temp_show == 0 && T_Humidity_show == 1 {
|
|
|
+ x = x + w
|
|
|
+ w = 74
|
|
|
+ lib.RectFillColor(pdf, "湿度%", 12, x, y, w, 20, 255, 255, 255, lib.AlignCenter, lib.ValignMiddle)
|
|
|
+ }
|
|
|
+
|
|
|
+ x = x + w
|
|
|
+ w = 112
|
|
|
+ lib.RectFillColor(pdf, "时间", 12, x, y, w, 20, 255, 255, 255, lib.AlignCenter, lib.ValignMiddle)
|
|
|
+ x = x + w
|
|
|
+ w = 101
|
|
|
+ lib.RectFillColor(pdf, "名称", 12, x, y, w, 20, 255, 255, 255, lib.AlignCenter, lib.ValignMiddle)
|
|
|
+ if T_temp_show == 1 && T_Humidity_show == 1 {
|
|
|
+ x = x + w
|
|
|
+ w = 37
|
|
|
+ lib.RectFillColor(pdf, "温度℃", 12, x, y, w, 20, 255, 255, 255, lib.AlignCenter, lib.ValignMiddle)
|
|
|
+ x = x + w
|
|
|
+ w = 37
|
|
|
+ lib.RectFillColor(pdf, "湿度%", 12, x, y, w, 20, 255, 255, 255, lib.AlignCenter, lib.ValignMiddle)
|
|
|
+ }
|
|
|
+ if T_temp_show == 1 && T_Humidity_show == 0 {
|
|
|
+ x = x + w
|
|
|
+ w = 74
|
|
|
+ lib.RectFillColor(pdf, "温度℃", 12, x, y, w, 20, 255, 255, 255, lib.AlignCenter, lib.ValignMiddle)
|
|
|
+ }
|
|
|
+ if T_temp_show == 0 && T_Humidity_show == 1 {
|
|
|
+ x = x + w
|
|
|
+ w = 74
|
|
|
+ lib.RectFillColor(pdf, "湿度%", 12, x, y, w, 20, 255, 255, 255, lib.AlignCenter, lib.ValignMiddle)
|
|
|
+ }
|
|
|
+ y += 20
|
|
|
+ }
|
|
|
x, w = 297, 112
|
|
|
lib.RectFillColor(pdf, second_column[i].T_time, 12, x, y, w, 20, 255, 255, 255, lib.AlignCenter, lib.ValignMiddle)
|
|
|
x = x + w
|
|
@@ -1946,10 +2202,17 @@ func Device_Sensor_Data_ChartShow_PDF0(companyName, T_snid, Time_start, Time_end
|
|
|
lib.RectFillColor(pdf, fmt.Sprintf(" %.1f ", second_column[i].T_rh), 12, x, y, w, 20, 255, 255, 255, lib.AlignCenter, lib.ValignMiddle)
|
|
|
}
|
|
|
y += 20
|
|
|
+ if y >= 820 {
|
|
|
+ pages := pdf.GetNumberOfPages()
|
|
|
+ pagenums := fmt.Sprintf("第 %d 页", pages)
|
|
|
+ pagenum, _ := pdf.MeasureTextWidth(pagenums)
|
|
|
+ pdf.SetX((595 / 2) - (pagenum / 2))
|
|
|
+ pdf.SetY(830) // 设置页码位置
|
|
|
+ pdf.Cell(nil, pagenums)
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
timeStr := "ofile/" + time.Now().Format("20060102150405") + ".pdf"
|
|
|
-
|
|
|
err = pdf.WritePdf(timeStr)
|
|
|
if err != nil {
|
|
|
return
|
|
@@ -2113,7 +2376,18 @@ func (c *DataController) Device_Sensor_Data_BackUp_PDF() {
|
|
|
lib.RectFillColor(pdf, "温度范围", 12, 272, 120, 100, 20, 255, 255, 255, lib.AlignCenter, lib.ValignMiddle)
|
|
|
lib.RectFillColor(pdf, "湿度范围", 12, 362, 120, 100, 20, 255, 255, 255, lib.AlignCenter, lib.ValignMiddle)
|
|
|
lib.RectFillColor(pdf, "记录时间", 12, 452, 120, 120, 20, 255, 255, 255, lib.AlignCenter, lib.ValignMiddle)
|
|
|
-
|
|
|
+ err = pdf.SetFont("wts", "", 10)
|
|
|
+ if err != nil {
|
|
|
+ c.Data["json"] = lib.JSONS{Code: 202, Msg: err.Error()}
|
|
|
+ c.ServeJSON()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ pages := pdf.GetNumberOfPages()
|
|
|
+ pagenums := fmt.Sprintf("第 %d 页", pages)
|
|
|
+ pagenum, _ := pdf.MeasureTextWidth(pagenums)
|
|
|
+ pdf.SetX((595 / 2) - (pagenum / 2))
|
|
|
+ pdf.SetY(830) // 设置页码位置
|
|
|
+ pdf.Cell(nil, pagenums)
|
|
|
var y float64 = 140
|
|
|
|
|
|
err = pdf.SetFont("wts", "", 10)
|
|
@@ -2360,39 +2634,170 @@ var upgrader = websocket.Upgrader{
|
|
|
},
|
|
|
}
|
|
|
|
|
|
+type DeviceTrajData struct {
|
|
|
+ List []Device.DeviceData_
|
|
|
+ Lists []Device.DeviceData_R2
|
|
|
+}
|
|
|
+
|
|
|
+var deviceTrajDataMap map[string]DeviceTrajData
|
|
|
+
|
|
|
+//func (c *DataController) GetNewLocus_() {
|
|
|
+// ws, err := upgrader.Upgrade(c.Ctx.ResponseWriter, c.Ctx.Request, nil)
|
|
|
+// if err != nil {
|
|
|
+// log.Println("设置websocket升级失败:", err)
|
|
|
+// return
|
|
|
+// }
|
|
|
+// defer ws.Close()
|
|
|
+// deviceTrajDataMap = make(map[string]DeviceTrajData)
|
|
|
+// type Responses struct {
|
|
|
+// Sn string `json:"sn"`
|
|
|
+// Tid int `json:"tid"`
|
|
|
+// }
|
|
|
+//
|
|
|
+// type Response struct {
|
|
|
+// Code int32 `protobuf:"varint,2,opt,name=code,proto3" json:"code,omitempty"`
|
|
|
+// Msg string `protobuf:"bytes,3,opt,name=msg,proto3" json:"msg,omitempty"`
|
|
|
+// Data []Device.DeviceData_R2 `json:"data"`
|
|
|
+// Sn string `json:"sn"`
|
|
|
+// T_name string `json:"t_name"` // 设备名称
|
|
|
+// }
|
|
|
+// _, message, err := ws.ReadMessage()
|
|
|
+// if err != nil {
|
|
|
+// logs.Error(lib.FuncName(), "读取参数失败: %v", err)
|
|
|
+// return
|
|
|
+// }
|
|
|
+// log.Printf("Received: %s", message)
|
|
|
+//
|
|
|
+// var r Responses
|
|
|
+// err = json.Unmarshal(message, &r)
|
|
|
+// if err != nil {
|
|
|
+// logs.Error(lib.FuncName(), "解析参数失败: %v", err)
|
|
|
+// ws.WriteMessage(websocket.TextMessage, []byte("参数解析失败"))
|
|
|
+// return
|
|
|
+// }
|
|
|
+// device, err := Device.Read_Device_ByT_sn(r.Sn)
|
|
|
+// if err != nil {
|
|
|
+// logs.Error(lib.FuncName(), "设备不存在: %v", err)
|
|
|
+// ws.WriteMessage(websocket.TextMessage, []byte("设备不存在"))
|
|
|
+// return
|
|
|
+// }
|
|
|
+// // 根据设备序列号获取对应的数据结构,如果不存在则初始化一个
|
|
|
+// deviceData, ok := deviceTrajDataMap[r.Sn]
|
|
|
+// if !ok {
|
|
|
+// deviceData = DeviceTrajData{
|
|
|
+// List: make([]Device.DeviceData_, 0),
|
|
|
+// Lists: make([]Device.DeviceData_R2, 0),
|
|
|
+// }
|
|
|
+// }
|
|
|
+// for {
|
|
|
+// err = Device.GetNewLocus(r.Sn, r.Tid, &deviceData.List)
|
|
|
+// if err != nil {
|
|
|
+// // 处理获取轨迹失败的情况,构造并发送错误响应给客户端
|
|
|
+// response := Response{
|
|
|
+// Code: 500,
|
|
|
+// Msg: "获取轨迹失败",
|
|
|
+// Data: nil,
|
|
|
+// }
|
|
|
+// data, _ := json.Marshal(response)
|
|
|
+// ws.WriteMessage(websocket.TextMessage, data)
|
|
|
+// continue
|
|
|
+// }
|
|
|
+//
|
|
|
+// updatedLists := make([]Device.DeviceData_R2, 0)
|
|
|
+// for i := range deviceData.List {
|
|
|
+// updatedLists = append(updatedLists, Device.DeviceData_R2{
|
|
|
+// DeviceData_: Device.DeviceData_{
|
|
|
+// T_id: deviceData.List[i].T_id,
|
|
|
+// T_rh: deviceData.List[i].T_rh,
|
|
|
+// T_site: deviceData.List[i].T_site,
|
|
|
+// T_sp: deviceData.List[i].T_sp,
|
|
|
+// T_time: deviceData.List[i].T_time,
|
|
|
+// T_t: deviceData.List[i].T_t,
|
|
|
+// },
|
|
|
+// Sn: r.Sn,
|
|
|
+// T_name: device.T_devName,
|
|
|
+// })
|
|
|
+// }
|
|
|
+// deviceData.Lists = updatedLists
|
|
|
+// deviceTrajDataMap[r.Sn] = deviceData
|
|
|
+//
|
|
|
+// response := Response{
|
|
|
+// Code: 200,
|
|
|
+// Msg: "ok!",
|
|
|
+// Data: deviceData.Lists,
|
|
|
+// Sn: r.Sn,
|
|
|
+// T_name: device.T_devName,
|
|
|
+// }
|
|
|
+// data, _ := json.Marshal(response)
|
|
|
+// ws.WriteMessage(websocket.TextMessage, data)
|
|
|
+// // 检查客户端是否断开连接
|
|
|
+// _, _, err = ws.ReadMessage()
|
|
|
+// if err != nil {
|
|
|
+// if websocket.IsCloseError(err, websocket.CloseNormalClosure, websocket.CloseGoingAway, websocket.CloseNoStatusReceived) {
|
|
|
+// log.Println("客户端已断开连接")
|
|
|
+// break
|
|
|
+// }
|
|
|
+// log.Println("读取消息时发生错误:", err)
|
|
|
+// }
|
|
|
+// // 回复消息
|
|
|
+// time.Sleep(10 * time.Second)
|
|
|
+// }
|
|
|
+//}
|
|
|
+
|
|
|
func (c *DataController) GetNewLocus_() {
|
|
|
ws, err := upgrader.Upgrade(c.Ctx.ResponseWriter, c.Ctx.Request, nil)
|
|
|
if err != nil {
|
|
|
- log.Println("Failed to set websocket upgrade:", err)
|
|
|
+ log.Println("设置websocket升级失败:", err)
|
|
|
return
|
|
|
}
|
|
|
defer ws.Close()
|
|
|
+ deviceTrajDataMap = make(map[string]DeviceTrajData)
|
|
|
type Responses struct {
|
|
|
Sn string `json:"sn"`
|
|
|
Tid int `json:"tid"`
|
|
|
}
|
|
|
- var list []Device.DeviceData_
|
|
|
+
|
|
|
type Response struct {
|
|
|
- Code int32 `protobuf:"varint,2,opt,name=code,proto3" json:"code,omitempty"`
|
|
|
- Msg string `protobuf:"bytes,3,opt,name=msg,proto3" json:"msg,omitempty"`
|
|
|
- Data []Device.DeviceData_ `json:"data"`
|
|
|
+ Code int32 `protobuf:"varint,2,opt,name=code,proto3" json:"code,omitempty"`
|
|
|
+ Msg string `protobuf:"bytes,3,opt,name=msg,proto3" json:"msg,omitempty"`
|
|
|
+ Data []Device.DeviceData_R2 `json:"data"`
|
|
|
+ Sn string `json:"sn"`
|
|
|
+ T_name string `json:"t_name"` // 设备名称
|
|
|
}
|
|
|
_, message, err := ws.ReadMessage()
|
|
|
if err != nil {
|
|
|
logs.Error(lib.FuncName(), "读取参数失败: %v", err)
|
|
|
+ return
|
|
|
}
|
|
|
log.Printf("Received: %s", message)
|
|
|
+
|
|
|
var r Responses
|
|
|
- //var rs Response
|
|
|
err = json.Unmarshal(message, &r)
|
|
|
if err != nil {
|
|
|
logs.Error(lib.FuncName(), "解析参数失败: %v", err)
|
|
|
ws.WriteMessage(websocket.TextMessage, []byte("参数解析失败"))
|
|
|
+ return
|
|
|
}
|
|
|
+ device, err := Device.Read_Device_ByT_sn(r.Sn)
|
|
|
+ if err != nil {
|
|
|
+ logs.Error(lib.FuncName(), "设备不存在: %v", err)
|
|
|
+ ws.WriteMessage(websocket.TextMessage, []byte("设备不存在"))
|
|
|
+ return
|
|
|
+ }
|
|
|
+ // 根据设备序列号获取对应的数据结构,如果不存在则初始化一个
|
|
|
+ deviceData, ok := deviceTrajDataMap[r.Sn]
|
|
|
+ if !ok {
|
|
|
+ deviceData = DeviceTrajData{
|
|
|
+ List: make([]Device.DeviceData_, 0),
|
|
|
+ Lists: make([]Device.DeviceData_R2, 0),
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ isFirstRequest := true // 新增标识,用于判断是否是首次请求
|
|
|
for {
|
|
|
- err = Device.GetNewLocus(r.Sn, r.Tid, &list)
|
|
|
+ err = Device.GetNewLocus(r.Sn, r.Tid, &deviceData.List)
|
|
|
if err != nil {
|
|
|
- logs.Error(lib.FuncName(), "获取轨迹失败s: %v, sn: %s, tid: %d", err, r.Sn, r.Tid)
|
|
|
+ // 处理获取轨迹失败的情况,构造并发送错误响应给客户端
|
|
|
response := Response{
|
|
|
Code: 500,
|
|
|
Msg: "获取轨迹失败",
|
|
@@ -2400,16 +2805,310 @@ func (c *DataController) GetNewLocus_() {
|
|
|
}
|
|
|
data, _ := json.Marshal(response)
|
|
|
ws.WriteMessage(websocket.TextMessage, data)
|
|
|
- break
|
|
|
+ continue
|
|
|
}
|
|
|
+
|
|
|
+ updatedLists := make([]Device.DeviceData_R2, 0)
|
|
|
+ for i := range deviceData.List {
|
|
|
+ updatedLists = append(updatedLists, Device.DeviceData_R2{
|
|
|
+ DeviceData_: Device.DeviceData_{
|
|
|
+ T_id: deviceData.List[i].T_id,
|
|
|
+ T_rh: deviceData.List[i].T_rh,
|
|
|
+ T_site: deviceData.List[i].T_site,
|
|
|
+ T_sp: deviceData.List[i].T_sp,
|
|
|
+ T_time: deviceData.List[i].T_time,
|
|
|
+ T_t: deviceData.List[i].T_t,
|
|
|
+ },
|
|
|
+ Sn: r.Sn,
|
|
|
+ T_name: device.T_devName,
|
|
|
+ })
|
|
|
+ }
|
|
|
+ deviceData.Lists = updatedLists
|
|
|
+ deviceTrajDataMap[r.Sn] = deviceData
|
|
|
+
|
|
|
response := Response{
|
|
|
- Code: 200,
|
|
|
- Msg: "ok!",
|
|
|
- Data: list,
|
|
|
+ Code: 200,
|
|
|
+ Msg: "ok!",
|
|
|
+ Data: deviceData.Lists,
|
|
|
+ Sn: r.Sn,
|
|
|
+ T_name: device.T_devName,
|
|
|
}
|
|
|
data, _ := json.Marshal(response)
|
|
|
ws.WriteMessage(websocket.TextMessage, data)
|
|
|
- // 回复消息
|
|
|
- time.Sleep(10 * time.Second)
|
|
|
+
|
|
|
+ // 检查客户端是否断开连接
|
|
|
+ _, _, err = ws.ReadMessage()
|
|
|
+ if err != nil {
|
|
|
+ if websocket.IsCloseError(err, websocket.CloseNormalClosure, websocket.CloseGoingAway, websocket.CloseNoStatusReceived) {
|
|
|
+ log.Println("客户端已断开连接")
|
|
|
+ break
|
|
|
+ }
|
|
|
+ log.Println("读取消息时发生错误:", err)
|
|
|
+ }
|
|
|
+
|
|
|
+ if isFirstRequest {
|
|
|
+ isFirstRequest = false // 首次请求处理完后,将标识设为false
|
|
|
+ } else {
|
|
|
+ // 非首次请求,按照间隔时间休眠后再进行下一次循环获取数据
|
|
|
+ time.Sleep(10 * time.Second)
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+// func (c *DataController) GetNewLocus_() {
|
|
|
+// ws, err := upgrader.Upgrade(c.Ctx.ResponseWriter, c.Ctx.Request, nil)
|
|
|
+// if err != nil {
|
|
|
+// log.Println("设置websocket升级失败:", err)
|
|
|
+// return
|
|
|
+// }
|
|
|
+// defer ws.Close()
|
|
|
+//
|
|
|
+// type Responses struct {
|
|
|
+// Sn string `json:"sn"`
|
|
|
+// Tid int `json:"tid"`
|
|
|
+// }
|
|
|
+//
|
|
|
+// type Response struct {
|
|
|
+// Code int32 `protobuf:"varint,2,opt,name=code,proto3" json:"code,omitempty"`
|
|
|
+// Msg string `protobuf:"bytes,3,opt,name=msg,proto3" json:"msg,omitempty"`
|
|
|
+// Data []Device.DeviceData_R2 `json:"data"`
|
|
|
+// Sn string `json:"sn"`
|
|
|
+// T_name string `json:"t_name"` // 设备名称
|
|
|
+// }
|
|
|
+//
|
|
|
+// heartbeatInterval := 10 * time.Second
|
|
|
+// timeoutInterval := 20 * time.Second
|
|
|
+// heartbeatTicker := time.NewTicker(heartbeatInterval)
|
|
|
+// defer heartbeatTicker.Stop()
|
|
|
+//
|
|
|
+// for {
|
|
|
+// select {
|
|
|
+// case <-heartbeatTicker.C:
|
|
|
+// // 发送心跳消息
|
|
|
+// if err := ws.WriteMessage(websocket.PingMessage, []byte{}); err != nil {
|
|
|
+// log.Println("发送心跳消息失败:", err)
|
|
|
+// return
|
|
|
+// }
|
|
|
+// // 设置读取超时时间
|
|
|
+// ws.SetReadDeadline(time.Now().Add(timeoutInterval))
|
|
|
+// default:
|
|
|
+// _, message, err := ws.ReadMessage()
|
|
|
+// if err != nil {
|
|
|
+// if websocket.IsCloseError(err, websocket.CloseNormalClosure, websocket.CloseGoingAway, websocket.CloseNoStatusReceived) {
|
|
|
+// log.Println("客户端已断开连接")
|
|
|
+// } else {
|
|
|
+// logs.Error(lib.FuncName(), "读取参数失败: %v", err)
|
|
|
+// }
|
|
|
+// return
|
|
|
+// }
|
|
|
+// log.Printf("Received: %s", message)
|
|
|
+//
|
|
|
+// var r Responses
|
|
|
+// err = json.Unmarshal(message, &r)
|
|
|
+// if err != nil {
|
|
|
+// logs.Error(lib.FuncName(), "解析参数失败: %v", err)
|
|
|
+// ws.WriteMessage(websocket.TextMessage, []byte("参数解析失败"))
|
|
|
+// continue
|
|
|
+// }
|
|
|
+//
|
|
|
+// sn, err := Device.Read_Device_ByT_sn(r.Sn)
|
|
|
+// if err != nil {
|
|
|
+// logs.Error(lib.FuncName(), "设备不存在: %v", err)
|
|
|
+// ws.WriteMessage(websocket.TextMessage, []byte("设备不存在"))
|
|
|
+// continue
|
|
|
+// }
|
|
|
+//
|
|
|
+// var list []Device.DeviceData_
|
|
|
+// var lists []Device.DeviceData_R2
|
|
|
+//
|
|
|
+// err = Device.GetNewLocus(r.Sn, r.Tid, &list)
|
|
|
+// if err != nil {
|
|
|
+// logs.Error(lib.FuncName(), "获取轨迹失败: %v, sn: %s, tid: %d", err, r.Sn, r.Tid)
|
|
|
+// response := Response{
|
|
|
+// Code: 500,
|
|
|
+// Msg: "获取轨迹失败",
|
|
|
+// Data: nil,
|
|
|
+// }
|
|
|
+// data, _ := json.Marshal(response)
|
|
|
+// ws.WriteMessage(websocket.TextMessage, data)
|
|
|
+// continue
|
|
|
+// }
|
|
|
+//
|
|
|
+// for i := range list {
|
|
|
+// lists = append(lists, Device.DeviceData_R2{
|
|
|
+// DeviceData_: Device.DeviceData_{
|
|
|
+// T_id: list[i].T_id,
|
|
|
+// T_rh: list[i].T_rh,
|
|
|
+// T_site: list[i].T_site,
|
|
|
+// T_sp: list[i].T_sp,
|
|
|
+// T_time: list[i].T_time,
|
|
|
+// T_t: list[i].T_t,
|
|
|
+// },
|
|
|
+// Sn: r.Sn,
|
|
|
+// T_name: sn.T_devName,
|
|
|
+// })
|
|
|
+// }
|
|
|
+//
|
|
|
+// response := Response{
|
|
|
+// Code: 200,
|
|
|
+// Msg: "ok!",
|
|
|
+// Data: lists,
|
|
|
+// Sn: r.Sn,
|
|
|
+// T_name: sn.T_devName,
|
|
|
+// }
|
|
|
+// data, _ := json.Marshal(response)
|
|
|
+// ws.WriteMessage(websocket.TextMessage, data)
|
|
|
+//
|
|
|
+// // 设置读取超时时间
|
|
|
+// ws.SetReadDeadline(time.Now().Add(timeoutInterval))
|
|
|
+// }
|
|
|
+// }
|
|
|
+// }
|
|
|
+
|
|
|
+//func (c *DataController) GetNewLocus_() {
|
|
|
+// ws, err := upgrader.Upgrade(c.Ctx.ResponseWriter, c.Ctx.Request, nil)
|
|
|
+// if err != nil {
|
|
|
+// log.Println("设置websocket升级失败:", err)
|
|
|
+// return
|
|
|
+// }
|
|
|
+// defer ws.Close()
|
|
|
+//
|
|
|
+// type Responses struct {
|
|
|
+// Sn string `json:"sn"`
|
|
|
+// Tid int `json:"tid"`
|
|
|
+// }
|
|
|
+//
|
|
|
+// var r Responses
|
|
|
+// _, message, err := ws.ReadMessage()
|
|
|
+// if err != nil {
|
|
|
+// logs.Error(lib.FuncName(), "读取参数失败: %v", err)
|
|
|
+// return
|
|
|
+// }
|
|
|
+// log.Printf("Received: %s", message)
|
|
|
+//
|
|
|
+// err = json.Unmarshal(message, &r)
|
|
|
+// if err != nil {
|
|
|
+// logs.Error(lib.FuncName(), "解析参数失败: %v", err)
|
|
|
+// ws.WriteMessage(websocket.TextMessage, []byte("参数解析失败"))
|
|
|
+// return
|
|
|
+// }
|
|
|
+//
|
|
|
+// devices, err := Device.Read_Device_ByT_sn(r.Sn)
|
|
|
+// if err != nil {
|
|
|
+// logs.Error(lib.FuncName(), "设备不存在: %v", err)
|
|
|
+// ws.WriteMessage(websocket.TextMessage, []byte("设备不存在"))
|
|
|
+// return
|
|
|
+// }
|
|
|
+//
|
|
|
+// ctx, cancel := context.WithCancel(context.Background())
|
|
|
+// defer cancel()
|
|
|
+//
|
|
|
+// // 启动一个新的goroutine来处理每个设备的轨迹数据
|
|
|
+// go func(sn string, tid int, ctx context.Context) {
|
|
|
+// type Response struct {
|
|
|
+// Code int32 `json:"code,omitempty"`
|
|
|
+// Msg string `json:"msg,omitempty"`
|
|
|
+// Data []Device.DeviceData_R2 `json:"data"`
|
|
|
+// Sn string `json:"sn"`
|
|
|
+// T_name string `json:"t_name"` // 设备名称
|
|
|
+// }
|
|
|
+//
|
|
|
+// for {
|
|
|
+// select {
|
|
|
+// case <-ctx.Done():
|
|
|
+// log.Println("goroutine 被取消")
|
|
|
+// return
|
|
|
+// default:
|
|
|
+// // 检查连接是否仍然打开
|
|
|
+// err := pingWebSocket(ws)
|
|
|
+// if err != nil {
|
|
|
+// log.Println("心跳检测失败:", err)
|
|
|
+// cancel()
|
|
|
+// break
|
|
|
+// }
|
|
|
+//
|
|
|
+// var list []Device.DeviceData_
|
|
|
+// err = Device.GetNewLocus(sn, tid, &list)
|
|
|
+// if err != nil {
|
|
|
+// logs.Error(lib.FuncName(), "获取轨迹失败: %v, sn: %s, tid: %d", err, sn, tid)
|
|
|
+// response := Response{
|
|
|
+// Code: 500,
|
|
|
+// Msg: "获取轨迹失败",
|
|
|
+// Data: nil,
|
|
|
+// }
|
|
|
+// data, marshalErr := json.Marshal(response)
|
|
|
+// if marshalErr == nil {
|
|
|
+// sendMessage(ws, data)
|
|
|
+// }
|
|
|
+// cancel()
|
|
|
+// break
|
|
|
+// }
|
|
|
+//
|
|
|
+// lists := make([]Device.DeviceData_R2, len(list))
|
|
|
+// for i, item := range list {
|
|
|
+// lists[i] = Device.DeviceData_R2{
|
|
|
+// DeviceData_: Device.DeviceData_{
|
|
|
+// T_id: item.T_id,
|
|
|
+// T_rh: item.T_rh,
|
|
|
+// T_site: item.T_site,
|
|
|
+// T_sp: item.T_sp,
|
|
|
+// T_time: item.T_time,
|
|
|
+// T_t: item.T_t,
|
|
|
+// },
|
|
|
+// Sn: sn,
|
|
|
+// T_name: devices.T_devName,
|
|
|
+// }
|
|
|
+// }
|
|
|
+//
|
|
|
+// response := Response{
|
|
|
+// Code: 200,
|
|
|
+// Msg: "ok!",
|
|
|
+// Data: lists,
|
|
|
+// Sn: sn,
|
|
|
+// T_name: devices.T_devName,
|
|
|
+// }
|
|
|
+// data, marshalErr := json.Marshal(response)
|
|
|
+// if marshalErr == nil {
|
|
|
+// sendMessage(ws, data)
|
|
|
+// } else {
|
|
|
+// log.Println("JSON 序列化失败:", marshalErr)
|
|
|
+// }
|
|
|
+//
|
|
|
+// time.Sleep(10 * time.Second)
|
|
|
+// }
|
|
|
+// }
|
|
|
+// }(r.Sn, r.Tid, ctx)
|
|
|
+//
|
|
|
+// // 启动一个goroutine用于监听连接关闭事件
|
|
|
+// go func() {
|
|
|
+// for {
|
|
|
+// _, _, err := ws.ReadMessage()
|
|
|
+// if err != nil {
|
|
|
+// if websocket.IsCloseError(err, websocket.CloseNormalClosure, websocket.CloseGoingAway, websocket.CloseNoStatusReceived) {
|
|
|
+// log.Println("客户端已断开连接")
|
|
|
+// } else {
|
|
|
+// log.Println("读取消息时发生错误:", err)
|
|
|
+// }
|
|
|
+// cancel()
|
|
|
+// return
|
|
|
+// }
|
|
|
+// }
|
|
|
+// }()
|
|
|
+//}
|
|
|
+//
|
|
|
+//// pingWebSocket 发送一个ping帧以确认连接是否仍然活跃
|
|
|
+//func pingWebSocket(ws *websocket.Conn) error {
|
|
|
+// err := ws.WriteControl(websocket.PingMessage, []byte{}, time.Now().Add(time.Second*5))
|
|
|
+// if err != nil {
|
|
|
+// return fmt.Errorf("发送心跳失败: %v", err)
|
|
|
+// }
|
|
|
+// return nil
|
|
|
+//}
|
|
|
+//
|
|
|
+//// sendMessage 封装了发送消息的过程,包括错误处理
|
|
|
+//func sendMessage(ws *websocket.Conn, data []byte) {
|
|
|
+// err := ws.WriteMessage(websocket.TextMessage, data)
|
|
|
+// if err != nil {
|
|
|
+// log.Println("发送消息失败:", err)
|
|
|
+// }
|
|
|
+//}
|