zoie 1 год назад
Родитель
Сommit
03d194c12a
5 измененных файлов с 65 добавлено и 37 удалено
  1. 1 1
      controllers/Data.go
  2. 5 13
      controllers/User.go
  3. 22 8
      controllers/Warning.go
  4. 19 0
      models/Device/DeviceData.go
  5. 18 15
      models/Device/DeviceSensor.go

+ 1 - 1
controllers/Data.go

@@ -1940,7 +1940,7 @@ func (c *DataController) Docking_Real_Data() {
 
 	type R_JSONS struct {
 		//必须的大写开头
-		Data []Device.DeviceData_R
+		Data []Device.DeviceData_Docking
 	}
 	var r_jsons R_JSONS
 

+ 5 - 13
controllers/User.go

@@ -195,20 +195,12 @@ func (c *UserController) Company_DigitalTwin() {
 	T_v3d := c.GetString("T_v3d")
 	T_warning, _ := c.GetInt("T_warning")
 
-	if len(T_plan) > 0 {
-		Company_r.T_plan = T_plan
-	}
-	if len(T_data) > 0 {
-		Company_r.T_data = T_data
-	}
-	if len(T_v3d) > 0 {
-		Company_r.T_v3d = T_v3d
-	}
-	if T_warning > 0 {
-		Company_r.T_warning = T_warning
-	}
+	Company_r.T_plan = T_plan
+	Company_r.T_data = T_data
+	Company_r.T_v3d = T_v3d
+	Company_r.T_warning = T_warning
 
-	is := Account.Update_Company(Company_r, "T_plan", "T_data", "T_v3d")
+	is := Account.Update_Company(Company_r, "T_plan", "T_data", "T_v3d", "T_warning")
 	if !is {
 		c.Data["json"] = lib.JSONS{Code: 202, Msg: "修改失败!"}
 		c.ServeJSON()

+ 22 - 8
controllers/Warning.go

@@ -312,6 +312,8 @@ func (c *DeviceController) DeviceWarning_Data_Excel() {
 	Time_start := c.GetString("Time_start")
 	Time_end := c.GetString("Time_end")
 	T_handle, _ := c.GetInt("T_handle")
+
+	T_admin, _ := c.GetInt("T_admin")
 	T_history, _ := c.GetInt("T_history")
 	tpCount := Warning.Read_WarningType_Count()
 	var tpList []string
@@ -323,10 +325,19 @@ func (c *DeviceController) DeviceWarning_Data_Excel() {
 		}
 	} else {
 		power, _ := Account.Read_Power_ById(c.Admin_r.T_power)
-		tpList = lib.SplitStringIds(power.T_warning, "W")
+		if power.T_warning != "*" {
+			tpList = lib.SplitStringIds(power.T_warning, "W")
+		}
 	}
 	countRedisKey := fmt.Sprintf("Warning_Count_%d_%s_%s_%s_%s_%d_%d_%d", c.T_pid, T_name, T_tp, Time_start, Time_end, T_handle, 0, T_history)
 
+	bindSN, err := Account.Read_UserDevice_List(*c.Admin_r)
+	if err != nil {
+		c.Data["json"] = lib.JSONS{Code: 202, Msg: "查询失败!"}
+		c.ServeJSON()
+		return
+	}
+
 	var T_year, T_month string
 	if T_history == 1 {
 		date, err := time.Parse("2006-01-02 15:04:05", Time_start)
@@ -338,14 +349,17 @@ func (c *DeviceController) DeviceWarning_Data_Excel() {
 		T_year, T_month = date.Format("2006"), date.Format("01")
 	}
 
-	bindSN, err := Account.Read_UserDevice_List(*c.Admin_r)
-	if err != nil {
-		c.Data["json"] = lib.JSONS{Code: 202, Msg: "查询失败!"}
-		c.ServeJSON()
-		return
-	}
-
 	var Device_data []Warning.Warning_R
+	// 管理员界面
+	if T_admin == 1 {
+		if T_history == 1 {
+			// 获取备份
+			Device_data, _ = Warning.Read_Admin_Warning_Backups(*c.Admin_r, T_year, T_month, tpList, T_name, T_handle, Time_start, Time_end, 0, 9999, countRedisKey)
+		} else {
+			// 获取最新
+			Device_data, _ = Warning.Read_Admin_Warning_List(*c.Admin_r, tpList, T_name, T_handle, Time_start, Time_end, 0, 9999, countRedisKey)
+		}
+	}
 	if T_history == 1 {
 		// 获取备份
 		Device_data, _ = Warning.Read_Warning_Backups(c.T_pid, bindSN, T_year, T_month, tpList, T_name, T_handle, Time_start, Time_end, 0, 9999, countRedisKey)

+ 19 - 0
models/Device/DeviceData.go

@@ -58,6 +58,25 @@ type DeviceData_R struct {
 	T_remark string  // 备注
 }
 
+// 模板
+type DeviceData_Docking struct {
+	T_monitor  int     // 监控状态 0 未监控 1 监控
+	T_online   int     // 在线状态 0 未启用  1 在线  2 离线
+	T_online_s int     // 在线状态-备用  0 未启用  1 在线  2 离线
+	T_sn       string  // sn
+	T_id       int     // 传感器id
+	T_name     string  // 传感器名称
+	T_t        float32 // 温度
+	T_rh       float32 // 湿度
+	T_site     string  // GPS
+	T_tl       float32 // 温度下限
+	T_tu       float32 // 温度上限
+	T_rhl      float32 // 湿度下限
+	T_rhu      float32 // 湿度上限
+	T_time     string  // 采集时间
+	T_sp       int     // 传感器参数id
+}
+
 type DeviceData_Pdf struct {
 	T_time string   // sn
 	T_id1  *float32 // 传感器id1温度

+ 18 - 15
models/Device/DeviceSensor.go

@@ -101,7 +101,7 @@ type DeviceSensor_Applet struct {
 	T_link     int    // 0:断开/故障 1连接 实时数据
 	T_State    int    // 0 屏蔽   1 正常  (屏蔽后 只有内部管理员才能看到,用户 输入SN\名称 搜索时 也能看到)
 
-	T_DeviceSensorData      DeviceData_R            // 传感器最新数据
+	T_DeviceSensorData      DeviceData_R            //  传感器最新数据
 	T_DeviceSensorParameter DeviceSensorParameter_R //  设备参数
 	T_DeviceSensorType      DeviceSensorType_R      //  传感器类型
 	T_Device                Device_R                //  传感器类型
@@ -1657,7 +1657,7 @@ func Read_DeviceSensor_All() (DeviceSensor_r []DeviceSensor) {
 }
 
 // 获取对接电信的实时数据
-func Read_Docking_Real_Data(T_pid int) (DeviceData_r []DeviceData_R) {
+func Read_Docking_Real_Data(T_pid int) (DeviceData_r []DeviceData_Docking) {
 	o := orm.NewOrm()
 	// 也可以直接使用 Model 结构体作为表名
 
@@ -1677,19 +1677,22 @@ func Read_Docking_Real_Data(T_pid int) (DeviceData_r []DeviceData_R) {
 		sp, _ := Read_DeviceSensorParameter(v.T_sn, v.T_id)
 		deviceDate := Read_DeviceData(v.T_sn, v.T_id)
 
-		data := DeviceData_R{
-			T_sn:   v.T_sn,
-			T_id:   v.T_id,
-			T_t:    deviceDate.T_t,
-			T_rh:   deviceDate.T_rh,
-			T_site: deviceDate.T_site,
-			T_time: deviceDate.T_time.Format("2006-01-02 15:04:05"),
-			T_sp:   deviceDate.T_sp,
-			T_name: sp.T_name,
-			T_tl:   sp.T_Tlower,
-			T_tu:   sp.T_Tupper,
-			T_rhl:  sp.T_RHlower,
-			T_rhu:  sp.T_RHupper,
+		data := DeviceData_Docking{
+			T_monitor:  v.T_monitor,
+			T_online:   v.T_online,
+			T_online_s: v.T_online_s,
+			T_sn:       v.T_sn,
+			T_id:       v.T_id,
+			T_t:        deviceDate.T_t,
+			T_rh:       deviceDate.T_rh,
+			T_site:     deviceDate.T_site,
+			T_time:     deviceDate.T_time.Format("2006-01-02 15:04:05"),
+			T_sp:       deviceDate.T_sp,
+			T_name:     sp.T_name,
+			T_tl:       sp.T_Tlower,
+			T_tu:       sp.T_Tupper,
+			T_rhl:      sp.T_RHlower,
+			T_rhu:      sp.T_RHupper,
 		}
 
 		DeviceData_r = append(DeviceData_r, data)