Browse Source

数据管理增加排序功能

huangyan 4 months ago
parent
commit
e4ba7c0d42
5 changed files with 32 additions and 11 deletions
  1. 4 3
      controllers/DataController.go
  2. 1 1
      lastupdate.tmp
  3. 4 0
      logs/logx/logx.log
  4. 4 4
      models/Device/DeviceData.go
  5. 19 3
      views/Data/DataList.html

+ 4 - 3
controllers/DataController.go

@@ -131,10 +131,11 @@ func (c *DataController) Device_Sensor_Data_More() {
 		c.ServeJSON()
 		return
 	}
-
+	sort := c.GetString("sort")
+	log.Println(sort, "排序==========================")
 	var cnt int64
 	var pageHelper = lib.PageHelper{}
-	pageHelper.List, cnt = Device.Read_DeviceData_By_T_snid_List(T_snid, Time_start, Time_end, page, page_z)
+	pageHelper.List, cnt = Device.Read_DeviceData_By_T_snid_List(T_snid, Time_start, Time_end, page, page_z, sort)
 	pageSize := math.Ceil(float64(cnt) / float64(page_z))
 	pageHelper.CurrentPage = page
 	pageHelper.TotalPage = int(pageSize)
@@ -301,7 +302,7 @@ func (c *DataController) Device_Sensor_Data_Excel() {
 	}
 	var DeviceSensor_data []Device.DeviceData_R
 
-	DeviceSensor_data, _ = Device.Read_DeviceData_By_T_snid_List(T_snid, Time_start, Time_end, 0, 9999)
+	DeviceSensor_data, _ = Device.Read_DeviceData_By_T_snid_List(T_snid, Time_start, Time_end, 0, 9999, "DESC")
 
 	f := excelize.NewFile() // 设置单元格的值
 	// 这里设置表头

+ 1 - 1
lastupdate.tmp

@@ -1 +1 @@
-{"E:\\WebstormProjects\\ColdP_server\\controllers":1727073730927050000}
+{"E:\\WebstormProjects\\ColdP_server\\controllers":1727080032150933800}

+ 4 - 0
logs/logx/logx.log

@@ -105241,3 +105241,7 @@
 2024/09/23 14:40:52.234 [I] [WarningType.go:193]  =========== 初始化报警类型 =========
 2024/09/23 14:41:42.654 [I] [WarningType.go:193]  =========== 初始化报警类型 =========
 2024/09/23 14:53:09.933 [I] [WarningType.go:193]  =========== 初始化报警类型 =========
+2024/09/23 16:11:21.292 [I] [WarningType.go:193]  =========== 初始化报警类型 =========
+2024/09/23 16:13:19.348 [I] [WarningType.go:193]  =========== 初始化报警类型 =========
+2024/09/23 16:26:04.621 [I] [WarningType.go:193]  =========== 初始化报警类型 =========
+2024/09/23 16:27:33.314 [I] [WarningType.go:193]  =========== 初始化报警类型 =========

+ 4 - 4
models/Device/DeviceData.go

@@ -233,7 +233,7 @@ func Add_DeviceData(SN string, v DeviceData_T) bool {
 //	T_time    time.Time `orm:"column(t_time);type(timestamp);null;"` // 采集时间
 //}
 
-func Read_DeviceData_ById_List(SN string, T_id int, Time_start_ string, Time_end_ string, page int, page_z int, SParamMap map[int]DeviceSensorParameter_M) ([]DeviceData_R, int) {
+func Read_DeviceData_ById_List(SN string, T_id int, Time_start_ string, Time_end_ string, page int, page_z int, SParamMap map[int]DeviceSensorParameter_M, sort string) ([]DeviceData_R, int) {
 	o := orm.NewOrm()
 	var maps []DeviceData_
 	var maps_z []orm2.ParamsList
@@ -269,7 +269,7 @@ func Read_DeviceData_ById_List(SN string, T_id int, Time_start_ string, Time_end
 	}
 	//fmt.Println("maps_z;",maps_z[0][0])
 	//t_tl,t_tu,t_rhl,t_rhu,
-	sql = "SELECT t_id,t_sp,t_t,t_rh,t_site,DATE_FORMAT(t_time,'%Y-%m-%d %H:%i:%s') AS t_time,DATE_FORMAT(create_time,'%Y-%m-%d %H:%i:%s') AS create_time  FROM z_device_data_" + SN + " WHERE " + sql_time + " t_id = " + strconv.Itoa(T_id) + " ORDER BY t_time DESC "
+	sql = "SELECT t_id,t_sp,t_t,t_rh,t_site,DATE_FORMAT(t_time,'%Y-%m-%d %H:%i:%s') AS t_time,DATE_FORMAT(create_time,'%Y-%m-%d %H:%i:%s') AS create_time  FROM z_device_data_" + SN + " WHERE " + sql_time + " t_id = " + strconv.Itoa(T_id) + " ORDER BY t_time  " + sort
 	if page_z != 9999 {
 		sql = sql + " LIMIT " + strconv.Itoa(offset) + "," + strconv.Itoa(page_z)
 	}
@@ -309,7 +309,7 @@ func Read_SqlRawL(T_SQL string, T_data []string) (string, []orm2.Params) {
 	return "", lists
 }
 
-func Read_DeviceData_By_T_snid_List(T_snid string, Time_start_ string, Time_end_ string, page int, page_z int) ([]DeviceData_R, int64) {
+func Read_DeviceData_By_T_snid_List(T_snid string, Time_start_ string, Time_end_ string, page int, page_z int, sort string) ([]DeviceData_R, int64) {
 	T_snid_list := strings.Split(T_snid, "|")
 	var maps []DeviceData_R
 	var maps_num int64
@@ -320,7 +320,7 @@ func Read_DeviceData_By_T_snid_List(T_snid string, Time_start_ string, Time_end_
 
 		if len(sn_id) == 2 {
 			SParamMap := Read_DeviceSensorParameter_Map_All(sn_id[0], lib.To_int(sn_id[1]))
-			r_maps, r_maps_num := Read_DeviceData_ById_List(sn_id[0], lib.To_int(sn_id[1]), Time_start_, Time_end_, 0, 9999, SParamMap)
+			r_maps, r_maps_num := Read_DeviceData_ById_List(sn_id[0], lib.To_int(sn_id[1]), Time_start_, Time_end_, 0, 9999, SParamMap, sort)
 			//for i, _ := range r_maps {
 			//	r_maps[i].T_sn = sn_id[0]
 			//}

+ 19 - 3
views/Data/DataList.html

@@ -162,6 +162,7 @@
                         <button class="layui-btn layui-btn-danger" onclick="deleteSelect()">删除</button>
                         <button class="layui-btn layui-btn-danger" onclick="deleteSelectTime()">删除选择时间范围
                         </button>
+
                     </div>
                 </div>
 
@@ -180,7 +181,14 @@
                         <thead>
                         <tr>
                             <th>选择</th>
-                            <th>采集时间</th>
+                            <th style="width: 120px;">采集时间
+                                <button type="button" class="layui-btn-primary layui-btn-xs layui-btn-radius sort" onclick="SortButton()">
+                                    <i class="layui-icon layui-icon-up"></i>
+                                </button>
+                                <button type="button" class="layui-btn-primary layui-btn-xs layui-btn-radius sort" onclick="SortButton()">
+                                    <i class="layui-icon layui-icon-down"></i>
+                                </button>
+                            </th>
                             <th>温度℃</th>
                             <th>湿度%</th>
                             <th>GPS</th>
@@ -393,7 +401,7 @@
     var T_sn_T_id = ""
     var Time_start = ""
     var Time_end = ""
-
+    var sort = "DESC"
     var DeviceSensor_lite = []
     var DeviceSensor_data = []
     var DeviceSensor_snid_list = ""
@@ -441,6 +449,11 @@
         }
     }
 
+    function SortButton(){
+        sort = sort === "DESC"? "ASC" : "DESC"
+        get_DeviceSensor_data(0)
+    }
+
     function get_DeviceSensor_list(page) {
         T_sn = $("#D_T_sn").val();
         T_name = $("#D_Name").val();
@@ -609,7 +622,7 @@
         e = $(e).parent().prevAll()
         e = e[e.length - 1]
         e = $(e).children()[0]
-        console.log(e, "==============")
+        // console.log(e, "==============")
         let t = {
             t_sn: $(e).attr('data-sn'),
             t_id: Number.parseInt($(e).attr('data-id')),
@@ -703,6 +716,8 @@
             shade: false,
             time: 99 * 1000
         });
+
+
         $.ajax({
             type: 'POST',
             url: 'Device_Sensor_Data_More',//发送请求
@@ -711,6 +726,7 @@
                 Time_start: Time_start,
                 Time_end: Time_end,
                 T_snid: DeviceSensor_snid_list,
+                sort: sort,
                 page: page,
                 page_z: itemsPerPage,
             },