Browse Source

数据导入问题修改,

huangyan 1 year ago
parent
commit
69fd172469
5 changed files with 58 additions and 30 deletions
  1. 9 13
      controllers/DataController.go
  2. 1 1
      lastupdate.tmp
  3. 25 0
      logs/logx/logx.log
  4. 23 13
      models/Device/DeviceData.go
  5. 0 3
      views/Data/GeneratorData2.html

+ 9 - 13
controllers/DataController.go

@@ -239,16 +239,9 @@ func (c *DataController) ImportData() {
 		panic(any(fmt.Sprintf("%s 打开上传文件excel错误", err.Error())))
 	}
 	data := Device.ImportDeviceData(reader, sn)
-	if data == "" {
-		c.Data["json"] = lib.JSONS{200, "操作成功", nil}
-		c.ServeJSON()
-		return
-	} else {
-		c.Data["json"] = lib.JSONS{201, data, nil}
-		c.ServeJSON()
-		return
-	}
-
+	c.Data["json"] = lib.JSONS{200, "操作成功", data}
+	c.ServeJSON()
+	return
 }
 
 // 导出传感器数据列表
@@ -277,11 +270,13 @@ func (c *DataController) Device_Sensor_Data_Excel() {
 	f.SetCellValue("Sheet1", "A1", "探头编号")
 	f.SetCellValue("Sheet1", "B1", "温度")
 	f.SetCellValue("Sheet1", "C1", "湿度℃")
-	f.SetCellValue("Sheet1", "D1", "记录时间")
+	f.SetCellValue("Sheet1", "D1", "坐标")
+	f.SetCellValue("Sheet1", "E1", "记录时间")
 	// 设置列宽
 	f.SetColWidth("Sheet1", "A", "A", 10)
 	f.SetColWidth("Sheet1", "B", "B", 15)
 	f.SetColWidth("Sheet1", "C", "D", 20)
+	f.SetColWidth("Sheet1", "E", "E", 20)
 
 	line := 1
 
@@ -293,7 +288,7 @@ func (c *DataController) Device_Sensor_Data_Excel() {
 		&excelize.Style{
 			Font: &excelize.Font{Size: 11, Color: "#ff8585", Family: "arial"},
 		})
-
+	// 定义时间格式
 	// 循环写入数据
 	for _, v := range DeviceSensor_data {
 		line++
@@ -307,11 +302,12 @@ func (c *DataController) Device_Sensor_Data_Excel() {
 			f.SetCellStyle("Sheet1", fmt.Sprintf("A%d", line), fmt.Sprintf("G%d", line), headStyleLower)
 		}
 
-		f.SetCellValue("Sheet1", fmt.Sprintf("D%d", line), v.T_time)
+		f.SetCellValue("Sheet1", fmt.Sprintf("D%d", line), v.T_site)
 		//f.SetCellValue("Sheet1", fmt.Sprintf("F%d", line), strconv.FormatFloat(float64(v.T_rhl), 'f', 2, 64)+"~"+strconv.FormatFloat(float64(v.T_rhu), 'f', 2, 64))
 		if v.T_rh < v.T_rhl || v.T_rh > v.T_rhu {
 			f.SetCellStyle("Sheet1", fmt.Sprintf("A%d", line), fmt.Sprintf("G%d", line), headStyleUpper)
 		}
+		f.SetCellValue("Sheet1", fmt.Sprintf("E%d", line), v.T_time)
 
 	}
 	//timeStr := time.Now().Format("20060102150405")

+ 1 - 1
lastupdate.tmp

@@ -1 +1 @@
-{"E:\\WebstormProjects\\ColdP_server\\controllers":1718957767121319600}
+{"E:\\WebstormProjects\\ColdP_server\\controllers":1719208890113581100}

+ 25 - 0
logs/logx/logx.log

@@ -4936,3 +4936,28 @@
 2024/06/21 17:24:51.756 [D] [DataGeneratorController.go:255]  时间间隔: 180
 2024/06/21 17:24:51.756 [D] [DataGeneratorController.go:255]  时间间隔: 180
 2024/06/21 17:24:51.756 [D] [DataGeneratorController.go:255]  时间间隔: 180
+2024/06/24 09:13:48.266 [I] [WarningType.go:193]  =========== 初始化报警类型 =========
+2024/06/24 10:22:32.269 [I] [WarningType.go:193]  =========== 初始化报警类型 =========
+2024/06/24 10:41:00.438 [I] [WarningType.go:193]  =========== 初始化报警类型 =========
+2024/06/24 10:43:05.541 [I] [WarningType.go:193]  =========== 初始化报警类型 =========
+2024/06/24 10:46:43.531 [I] [WarningType.go:193]  =========== 初始化报警类型 =========
+2024/06/24 10:47:54.921 [I] [WarningType.go:193]  =========== 初始化报警类型 =========
+2024/06/24 10:58:19.267 [I] [WarningType.go:193]  =========== 初始化报警类型 =========
+2024/06/24 11:01:18.955 [I] [WarningType.go:193]  =========== 初始化报警类型 =========
+2024/06/24 11:12:06.555 [I] [WarningType.go:193]  =========== 初始化报警类型 =========
+2024/06/24 11:19:51.363 [I] [WarningType.go:193]  =========== 初始化报警类型 =========
+2024/06/24 11:21:48.868 [I] [WarningType.go:193]  =========== 初始化报警类型 =========
+2024/06/24 11:28:24.788 [I] [WarningType.go:193]  =========== 初始化报警类型 =========
+2024/06/24 11:35:13.918 [I] [WarningType.go:193]  =========== 初始化报警类型 =========
+2024/06/24 11:36:37.318 [I] [WarningType.go:193]  =========== 初始化报警类型 =========
+2024/06/24 11:42:40.071 [I] [WarningType.go:193]  =========== 初始化报警类型 =========
+2024/06/24 12:50:24.233 [E] [WarningType.go:202]  ColdP_server/models/Warning.Read_WarningType_All_Maps invalid connection
+2024/06/24 13:43:17.336 [I] [WarningType.go:193]  =========== 初始化报警类型 =========
+2024/06/24 13:43:56.222 [I] [WarningType.go:193]  =========== 初始化报警类型 =========
+2024/06/24 13:48:42.620 [I] [WarningType.go:193]  =========== 初始化报警类型 =========
+2024/06/24 13:53:29.563 [I] [WarningType.go:193]  =========== 初始化报警类型 =========
+2024/06/24 13:57:43.037 [I] [WarningType.go:193]  =========== 初始化报警类型 =========
+2024/06/24 14:01:38.129 [I] [WarningType.go:193]  =========== 初始化报警类型 =========
+2024/06/24 14:09:40.582 [I] [WarningType.go:193]  =========== 初始化报警类型 =========
+2024/06/24 14:12:13.981 [I] [WarningType.go:193]  =========== 初始化报警类型 =========
+2024/06/24 14:15:16.284 [I] [WarningType.go:193]  =========== 初始化报警类型 =========

+ 23 - 13
models/Device/DeviceData.go

@@ -378,44 +378,54 @@ func ImportDeviceData(reader *excelize.File, sn string) string {
 			//跳过第一条头部描述
 			continue
 		}
+		// 定义匹配的解析格式
+		format := row[4]
+		_, err := time.Parse("2006-01-02 15:04:05", row[4])
+		if err != nil {
+			layout := "1/2/06 15:04"
+			parsedTime, _ := time.Parse(layout, row[4])
+			year := parsedTime.Year()
+			if year < 100 {
+				year += 2000
+			}
+			parsedTime = time.Date(year, parsedTime.Month(), parsedTime.Day(), parsedTime.Hour(), parsedTime.Minute(), parsedTime.Second(), parsedTime.Nanosecond(), time.UTC)
+			format = parsedTime.Format("2006-01-02 15:04:05")
 
+		}
+		isrepeat := Read_DeviceData_Execl_ISREPEAT(sn, format, row[0])
 		t_sp := Read_device_sensor_parameter(sn, row[0])
 		if t_sp == "" {
 			sprintf := fmt.Sprintf("当前sn或探头参数ID不存在:%s,%s", sn, row[0])
 			return sprintf
 		}
-		isrepeat := Read_DeviceData_Execl_ISREPEAT(sn, row[3], row[0])
 		if isrepeat {
 			//如果重复就用更新数据
-			sql := fmt.Sprintf("UPDATE z_device_data_%s SET t_t=%s,t_rh=%s WHERE t_time='%s' AND t_id=%s", sn, row[1], row[2], row[3], row[0])
+			sql := fmt.Sprintf("UPDATE z_device_data_%s SET t_t=%s,t_rh=%s  WHERE t_time='%s' AND t_id=%s ", sn, row[1], row[2], format, row[0])
 			_, err := o.Raw(sql).Exec()
 			if err != nil {
 				fmt.Println(err.Error())
-				return err.Error()
-			} else {
-				return "导入成功"
+				return "更新失败"
 			}
 		} else {
 			// t_id,t_t,t_rh,t_time
 			//传感器	传感器参数ID	温度	湿度	GPS	采集时间	创建时间
-			values[i-1] = fmt.Sprintf("(%s,%s,%s,%s,'','%s')", row[0], t_sp, row[1], row[2], row[3])
-			sprintf := fmt.Sprintf("insert into z_device_data_%s  (t_id,t_sp,t_t,t_rh,t_site,t_time) values (%s,%s,%s,%s,'','%s')", sn, row[0], t_sp, row[1], row[2], row[3])
+			parse, _ := time.Parse("2006-01-02 15:04:05", format)
+			parse = parse.Add(time.Millisecond * 8000)
+			parse.Format("2006-01-02 15:04:05")
+			values[i-1] = fmt.Sprintf("(%s,%s,%s,%s,'','%s')", row[0], t_sp, row[1], row[2], format)
+			sprintf := fmt.Sprintf("insert into z_device_data_%s  (t_id,t_sp,t_t,t_rh,t_site,t_time,create_time) values (%s,%s,%s,%s,'%s','%s','%s')", sn, row[0], t_sp, row[1], row[2], row[3], format, parse.Format("2006-01-02 15:04:05"))
 			log.Println(sprintf)
 			//执行SQL
-			exec, err := o.Raw(sprintf).Exec()
+			_, err := o.Raw(sprintf).Exec()
 			if err != nil {
 				fmt.Println("执行失败")
 				return "请检查表格是否具有重复数据!!!"
-			} else {
-				rowsAffected, _ := exec.RowsAffected()
-				fmt.Println("插入", rowsAffected, "条数据")
-				return "导入成功"
 			}
 		}
 	}
 	//sqlStatement := fmt.Sprintf("insert into z_device_data_%s(t_id,t_sp,t_t,t_rh,t_site,t_time) values %s", sn, strings.Join(values, ","))
 	//fmt.Println("执行批量导入SQL:", sqlStatement)
-	return "导入失败"
+	return "导入成功"
 
 }
 func Read_DeviceData_Execl_ISREPEAT(sn, t_time, t_id string) bool {

+ 0 - 3
views/Data/GeneratorData2.html

@@ -624,12 +624,9 @@
             }]
         });
         console.log("后:",myChar.getOption())
-
     }
 
 
-
-
     //温湿度偏移
     function offset() {
         if (timeRange.length === 0) {