Procházet zdrojové kódy

update:优化数据展示、图表展示下载pdf

zoie před 2 měsíci
rodič
revize
10ba5b803e
1 změnil soubory, kde provedl 103 přidání a 63 odebrání
  1. 103 63
      controllers/Data.go

+ 103 - 63
controllers/Data.go

@@ -632,6 +632,7 @@ func (c *DataController) Device_Sensor_Data_PDF() {
 	T_snid := c.GetString("T_snid")
 	Time_start := c.GetString("Time_start")
 	Time_end := c.GetString("Time_end")
+	T_ish, _ := c.GetInt("T_ish") // 展示湿度
 
 	if len(T_snid) < 10 {
 		c.Data["json"] = lib.JSONS{Code: 202, Msg: "T_snid Err!"}
@@ -640,48 +641,49 @@ func (c *DataController) Device_Sensor_Data_PDF() {
 	}
 	//T_ist   // 温度   1开启   2关闭
 	//T_ish   // 湿度   1开启   2关闭
-	T_ist_list := make([]int, 0)
-	T_ish_list := make([]int, 0)
-	T_snid_list := strings.Split(strings.Trim(T_snid, "|"), "|")
-	for _, v := range T_snid_list {
-		sn_id := strings.Split(v, ",")
-		if len(sn_id) == 2 {
-			device, _ := Device.Read_Device_ByT_sn(sn_id[0])
-			T_ist_list = append(T_ist_list, device.T_ist)
-			T_ish_list = append(T_ish_list, device.T_ish)
-		}
-	}
-	istHasOne := false
-	istHasTwo := false
 	T_ist := 1
-	for _, v := range T_ist_list {
-		if v == 1 {
-			istHasOne = true
-		}
-		if v == 2 {
-			istHasTwo = true
-		}
-	}
-	// 全部都为2 则不显示温度
-	if !istHasOne && istHasTwo {
-		T_ist = 2
-	}
-
-	ishHasOne := false
-	ishHasTwo := false
-	T_ish := 1
-	for _, v := range T_ish_list {
-		if v == 1 {
-			ishHasOne = true
-		}
-		if v == 2 {
-			ishHasTwo = true
-		}
-	}
-	// 全部都为2 则不显示湿度
-	if !ishHasOne && ishHasTwo {
-		T_ish = 2
-	}
+	//T_ist_list := make([]int, 0)
+	//T_ish_list := make([]int, 0)
+	//T_snid_list := strings.Split(strings.Trim(T_snid, "|"), "|")
+	//for _, v := range T_snid_list {
+	//	sn_id := strings.Split(v, ",")
+	//	if len(sn_id) == 2 {
+	//		device, _ := Device.Read_Device_ByT_sn(sn_id[0])
+	//		T_ist_list = append(T_ist_list, device.T_ist)
+	//		T_ish_list = append(T_ish_list, device.T_ish)
+	//	}
+	//}
+	//istHasOne := false
+	//istHasTwo := false
+	//
+	//for _, v := range T_ist_list {
+	//	if v == 1 {
+	//		istHasOne = true
+	//	}
+	//	if v == 2 {
+	//		istHasTwo = true
+	//	}
+	//}
+	//// 全部都为2 则不显示温度
+	//if !istHasOne && istHasTwo {
+	//	T_ist = 2
+	//}
+	//
+	//ishHasOne := false
+	//ishHasTwo := false
+	//T_ish := 1
+	//for _, v := range T_ish_list {
+	//	if v == 1 {
+	//		ishHasOne = true
+	//	}
+	//	if v == 2 {
+	//		ishHasTwo = true
+	//	}
+	//}
+	//// 全部都为2 则不显示湿度
+	//if !ishHasOne && ishHasTwo {
+	//	T_ish = 2
+	//}
 
 	var DeviceSensor_data []Device.DeviceData_R
 
@@ -872,13 +874,26 @@ func (c *DataController) Device_Sensor_Data_PDF() {
 	}
 	y += 5
 	lib.RectFillColor(pdf, "序号", 12, 22, y, 30, 20, 255, 255, 255, lib.AlignCenter, lib.ValignMiddle)
-	lib.RectFillColor(pdf, "传感器名称", 12, 52, y, 100, 20, 255, 255, 255, lib.AlignCenter, lib.ValignMiddle)
-	lib.RectFillColor(pdf, "温度℃", 12, 152, y, 50, 20, 255, 255, 255, lib.AlignCenter, lib.ValignMiddle)
 
-	lib.RectFillColor(pdf, "湿度%", 12, 202, y, 50, 20, 255, 255, 255, lib.AlignCenter, lib.ValignMiddle)
+	if T_ish == 1 {
+		lib.RectFillColor(pdf, "传感器名称", 12, 52, y, 100, 20, 255, 255, 255, lib.AlignCenter, lib.ValignMiddle)
+
+		lib.RectFillColor(pdf, "温度℃", 12, 152, y, 50, 20, 255, 255, 255, lib.AlignCenter, lib.ValignMiddle)
+		lib.RectFillColor(pdf, "湿度%", 12, 202, y, 50, 20, 255, 255, 255, lib.AlignCenter, lib.ValignMiddle)
+	}
+	if T_ish == 0 {
+		lib.RectFillColor(pdf, "传感器名称", 12, 52, y, 140, 20, 255, 255, 255, lib.AlignCenter, lib.ValignMiddle)
+		lib.RectFillColor(pdf, "温度℃", 12, 192, y, 100, 20, 255, 255, 255, lib.AlignCenter, lib.ValignMiddle)
+	}
+
+	if T_ish == 1 {
+		lib.RectFillColor(pdf, "温度范围", 12, 252, y, 80, 20, 255, 255, 255, lib.AlignCenter, lib.ValignMiddle)
+		lib.RectFillColor(pdf, "湿度范围", 12, 332, y, 80, 20, 255, 255, 255, lib.AlignCenter, lib.ValignMiddle)
+	}
+	if T_ish == 0 {
+		lib.RectFillColor(pdf, "温度范围", 12, 292, y, 120, 20, 255, 255, 255, lib.AlignCenter, lib.ValignMiddle)
+	}
 
-	lib.RectFillColor(pdf, "温度范围", 12, 252, y, 80, 20, 255, 255, 255, lib.AlignCenter, lib.ValignMiddle)
-	lib.RectFillColor(pdf, "湿度范围", 12, 332, y, 80, 20, 255, 255, 255, lib.AlignCenter, lib.ValignMiddle)
 	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)
 
@@ -898,13 +913,25 @@ func (c *DataController) Device_Sensor_Data_PDF() {
 		// newY = 20
 		if y < 30 {
 			lib.RectFillColor(pdf, "序号", 12, 22, y, 30, 20, 255, 255, 255, lib.AlignCenter, lib.ValignMiddle)
-			lib.RectFillColor(pdf, "传感器名称", 12, 52, y, 100, 20, 255, 255, 255, lib.AlignCenter, lib.ValignMiddle)
-			lib.RectFillColor(pdf, "温度℃", 12, 152, y, 50, 20, 255, 255, 255, lib.AlignCenter, lib.ValignMiddle)
 
-			lib.RectFillColor(pdf, "湿度%", 12, 202, y, 50, 20, 255, 255, 255, lib.AlignCenter, lib.ValignMiddle)
+			if T_ish == 1 {
+				lib.RectFillColor(pdf, "传感器名称", 12, 52, y, 100, 20, 255, 255, 255, lib.AlignCenter, lib.ValignMiddle)
+				lib.RectFillColor(pdf, "温度℃", 12, 152, y, 50, 20, 255, 255, 255, lib.AlignCenter, lib.ValignMiddle)
+				lib.RectFillColor(pdf, "湿度%", 12, 202, y, 50, 20, 255, 255, 255, lib.AlignCenter, lib.ValignMiddle)
+			}
+			if T_ish == 0 {
+				lib.RectFillColor(pdf, "传感器名称", 12, 52, y, 140, 20, 255, 255, 255, lib.AlignCenter, lib.ValignMiddle)
+				lib.RectFillColor(pdf, "温度℃", 12, 192, y, 100, 20, 255, 255, 255, lib.AlignCenter, lib.ValignMiddle)
+			}
+
+			if T_ish == 1 {
+				lib.RectFillColor(pdf, "温度范围", 12, 252, y, 80, 20, 255, 255, 255, lib.AlignCenter, lib.ValignMiddle)
+				lib.RectFillColor(pdf, "湿度范围", 12, 332, y, 80, 20, 255, 255, 255, lib.AlignCenter, lib.ValignMiddle)
+			}
+			if T_ish == 0 {
+				lib.RectFillColor(pdf, "温度范围", 12, 292, y, 120, 20, 255, 255, 255, lib.AlignCenter, lib.ValignMiddle)
+			}
 
-			lib.RectFillColor(pdf, "温度范围", 12, 252, y, 80, 20, 255, 255, 255, lib.AlignCenter, lib.ValignMiddle)
-			lib.RectFillColor(pdf, "湿度范围", 12, 332, y, 80, 20, 255, 255, 255, lib.AlignCenter, lib.ValignMiddle)
 			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)
 			y += 20
@@ -921,23 +948,36 @@ func (c *DataController) Device_Sensor_Data_PDF() {
 		T_Rlu := fmt.Sprintf(" %.1f ~ %.1f ", v.T_rhl, v.T_rhu)
 		T_time := fmt.Sprintf("%s", v.T_time)
 
-		if v.T_ist == 1 {
+		//if v.T_ist == 1 {
+		//	lib.RectFillColor(pdf, T_t, 10, 152, y, 50, 20, 255, 255, 255, lib.AlignCenter, lib.ValignMiddle)
+		//	lib.RectFillColor(pdf, T_Tlu, 10, 252, y, 80, 20, 255, 255, 255, lib.AlignCenter, lib.ValignMiddle)
+		//} else {
+		//	lib.RectFillColor(pdf, "", 10, 152, y, 50, 20, 255, 255, 255, lib.AlignCenter, lib.ValignMiddle)
+		//	lib.RectFillColor(pdf, "", 10, 252, y, 80, 20, 255, 255, 255, lib.AlignCenter, lib.ValignMiddle)
+		//}
+		//if v.T_ish == 1 {
+		//	lib.RectFillColor(pdf, T_rh, 10, 202, y, 50, 20, 255, 255, 255, lib.AlignCenter, lib.ValignMiddle)
+		//	lib.RectFillColor(pdf, T_Rlu, 10, 332, y, 80, 20, 255, 255, 255, lib.AlignCenter, lib.ValignMiddle)
+		//} else {
+		//	lib.RectFillColor(pdf, "", 10, 202, y, 50, 20, 255, 255, 255, lib.AlignCenter, lib.ValignMiddle)
+		//	lib.RectFillColor(pdf, "", 10, 332, y, 80, 20, 255, 255, 255, lib.AlignCenter, lib.ValignMiddle)
+		//}
+
+		if T_ish == 1 {
 			lib.RectFillColor(pdf, T_t, 10, 152, y, 50, 20, 255, 255, 255, lib.AlignCenter, lib.ValignMiddle)
 			lib.RectFillColor(pdf, T_Tlu, 10, 252, y, 80, 20, 255, 255, 255, lib.AlignCenter, lib.ValignMiddle)
-		} else {
-			lib.RectFillColor(pdf, "", 10, 152, y, 50, 20, 255, 255, 255, lib.AlignCenter, lib.ValignMiddle)
-			lib.RectFillColor(pdf, "", 10, 252, y, 80, 20, 255, 255, 255, lib.AlignCenter, lib.ValignMiddle)
-		}
-		if v.T_ish == 1 {
 			lib.RectFillColor(pdf, T_rh, 10, 202, y, 50, 20, 255, 255, 255, lib.AlignCenter, lib.ValignMiddle)
 			lib.RectFillColor(pdf, T_Rlu, 10, 332, y, 80, 20, 255, 255, 255, lib.AlignCenter, lib.ValignMiddle)
-		} else {
-			lib.RectFillColor(pdf, "", 10, 202, y, 50, 20, 255, 255, 255, lib.AlignCenter, lib.ValignMiddle)
-			lib.RectFillColor(pdf, "", 10, 332, y, 80, 20, 255, 255, 255, lib.AlignCenter, lib.ValignMiddle)
+			lib.RectFillColor(pdf, v.T_name, 10, 52, y, 100, 20, 255, 255, 255, lib.AlignCenter, lib.ValignMiddle)
+
 		}
+		if T_ish == 0 {
+			lib.RectFillColor(pdf, v.T_name, 10, 52, y, 140, 20, 255, 255, 255, lib.AlignCenter, lib.ValignMiddle)
+			lib.RectFillColor(pdf, T_t, 10, 192, y, 100, 20, 255, 255, 255, lib.AlignCenter, lib.ValignMiddle)
+			lib.RectFillColor(pdf, T_Tlu, 10, 292, y, 120, 20, 255, 255, 255, lib.AlignCenter, lib.ValignMiddle)
 
+		}
 		lib.RectFillColor(pdf, text, 10, 22, y, 30, 20, 255, 255, 255, lib.AlignCenter, lib.ValignMiddle)
-		lib.RectFillColor(pdf, v.T_name, 10, 52, y, 100, 20, 255, 255, 255, lib.AlignCenter, lib.ValignMiddle)
 
 		lib.RectFillColor(pdf, T_time, 10, 412, y, 120, 20, 255, 255, 255, lib.AlignCenter, lib.ValignMiddle)
 		lib.RectFillColor(pdf, v.T_remark, 10, 532, y, 40, 20, 255, 255, 255, lib.AlignCenter, lib.ValignMiddle)
@@ -1128,7 +1168,7 @@ func Device_Sensor_Data_ChartShow_PDF1(companyName, T_snid, Time_start, Time_end
 	pdf.SetMargins(0, 20, 0, 20)
 	pdf.AddPage()
 
-	title := companyName + "冷链记录"
+	title := companyName + "温湿度记录"
 
 	var y float64 = 40
 	textw, _ := pdf.MeasureTextWidth(title)
@@ -1587,7 +1627,7 @@ func Device_Sensor_Data_ChartShow_PDF0(companyName, T_snid, Time_start, Time_end
 	pdf.SetMargins(0, 20, 0, 20)
 	pdf.AddPage()
 
-	title := companyName + "冷链记录"
+	title := companyName + "温湿度记录"
 
 	var y float64 = 40
 	textw, _ := pdf.MeasureTextWidth(title)