Pārlūkot izejas kodu

添加筛选报警数据功能

huangyan 10 mēneši atpakaļ
vecāks
revīzija
77d2175e86

+ 14 - 3
controllers/DeviceController.go

@@ -329,9 +329,10 @@ func (c *DeviceController) DeviceWarning_List_html() {
 	pageSize := c.GetString("pageSize", "100")
 	pageSizeInt, _ := strconv.Atoi(pageSize)
 	//atoi, _ := strconv.Atoi(pageSizes.PageSize)
-
+	getString := c.GetString("t_tp")
+	t_tp, _ := strconv.Atoi(getString)
 	var cnt int64
-	DeviceWarning_List, cnt := Warning.Read_Warning_List(admin_r.T_pid, bindSN, tpList, Time_start, Time_end, page, pageSizeInt)
+	DeviceWarning_List, cnt := Warning.Read_Warning_List(admin_r.T_pid, bindSN, tpList, Time_start, Time_end, t_tp, page, pageSizeInt)
 	c.Data["List"] = DeviceWarning_List
 	page_size := math.Ceil(float64(cnt) / float64(pageSizeInt))
 	c.Data["Page"] = page
@@ -354,7 +355,6 @@ func (c *DeviceController) GetWarningtype() {
 		if k, ok := key.(int); ok {
 			if v, ok := value.(string); ok {
 				// 创建匿名结构体实例并添加到切片
-				// 注意:确保结构体定义与切片元素类型匹配,且无需在字面量中重复标签
 				results = append(results, struct {
 					Key   int
 					Value string
@@ -607,3 +607,14 @@ func (c *DeviceController) DeviceWarningAdd() {
 	c.ServeJSON()
 	return
 }
+
+// SiftWarningType 根据报警类型筛选
+func (c *DeviceController) SiftWarningType() {
+	// 验证登录
+	b_, _ := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
+	if !b_ {
+		c.Ctx.Redirect(302, "Login")
+		return
+	}
+
+}

+ 1 - 1
lastupdate.tmp

@@ -1 +1 @@
-{"E:\\WebstormProjects\\ColdP_server\\controllers":1721701261750472300}
+{"E:\\WebstormProjects\\ColdP_server\\controllers":1723182702409342100}

+ 6 - 0
logs/logx/logx.log

@@ -7831,3 +7831,9 @@
 2024/07/23 10:20:05.446 [D] [DataGeneratorController.go:260]  时间间隔: 10500
 2024/07/23 10:20:22.593 [D] [DataGeneratorController.go:260]  时间间隔: 300
 2024/07/23 10:21:10.084 [I] [WarningType.go:193]  =========== 初始化报警类型 =========
+2024/07/23 10:23:52.053 [I] [WarningType.go:193]  =========== 初始化报警类型 =========
+2024/07/23 10:24:30.267 [D] [DataGeneratorController.go:260]  时间间隔: 10500
+2024/07/23 10:24:31.088 [D] [DataGeneratorController.go:260]  时间间隔: 300
+2024/08/09 09:24:21.675 [I] [WarningType.go:193]  =========== 初始化报警类型 =========
+2024/08/09 13:41:55.352 [E] [WarningType.go:202]  ColdP_server/models/Warning.Read_WarningType_All_Maps dial tcp 127.0.0.1:40306: connectex: No connection could be made because the target machine actively refused it.
+2024/08/09 14:48:07.968 [I] [WarningType.go:193]  =========== 初始化报警类型 =========

+ 4 - 1
models/Warning/Warning.go

@@ -382,7 +382,7 @@ func Update_Warning_Backups(r Warning, T_year string, T_month string) bool {
 }
 
 // 获取列表
-func Read_Warning_List(T_pid int, bindSN, tpList []string, Time_start_ string, Time_end_ string, page int, page_z int) (r []Warning_R, cnt int64) {
+func Read_Warning_List(T_pid int, bindSN, tpList []string, Time_start_ string, Time_end_ string, t_tp, page int, page_z int) (r []Warning_R, cnt int64) {
 	o := orm.NewOrm()
 	// 也可以直接使用 Model 结构体作为表名
 	var map_r []Warning
@@ -412,6 +412,9 @@ func Read_Warning_List(T_pid int, bindSN, tpList []string, Time_start_ string, T
 	if len(Time_end_) > 0 {
 		cond1 = cond1.And("T_Ut__lte", Time_end_)
 	}
+	if t_tp > 0 {
+		cond1 = cond1.And("T_tp", t_tp)
+	}
 
 	var err error
 	if page_z == 9999 {

+ 73 - 22
views/Device/DeviceWarning.html

@@ -117,6 +117,13 @@
                             <button class="layui-btn layui-btn-sm" id="invertSelect">反选</button>
                             <button class="layui-btn layui-btn-sm layui-btn-danger" id="batchDelete">批量删除</button>
                         </div>
+                        <div>
+                            <div class="siftWarning" style="width: 100px; margin-left: 260px; margin-top: -45px;">
+                                <select>
+                                    <option value="">类型筛选</option>
+                                </select>
+                            </div>
+                        </div>
                     </table>
                 </div>
                 <div class="layui-card-body ">
@@ -217,21 +224,8 @@
         var snValue = document.getElementsByName('T_sn')[0].value;
 
         const url = `?page=1&T_sn=${encodeURIComponent(snValue)}&Time_start=${encodeURIComponent(startTime)}&Time_end=${encodeURIComponent(endTime)}&pageSize=${encodeURIComponent(pageSize)}`; // 将pageSize作为查询参数添加到URL
-        // console.log("发送的URL:", url);
         window.location.href = url;
-        // fetch(url, { // 使用调整后的URL
-        //     method: 'GET', // 保持GET方法,既然这是根据需求设定的
-        // })
-        //     .then(response => {
-        //         if (!response.ok) {
-        //             throw new Error(`网络响应异常: ${response.statusText}`);
-        //         }
-        //         // 可能需要处理响应数据,这里假设不需要返回数据处理
-        //     })
-        //     .catch(error => {
-        //         console.error('发送pageSize至后端时发生错误:', error);
-        //         // 可能还需要通知用户发生了错误
-        //     });
+
     }
 
     layui.use(['layer', 'laydate', 'form'],
@@ -272,7 +266,6 @@
 
                     var seventhColumnValue = row.find('td:eq(6)').text();
                     console.log(seventhColumnValue);
-                    // 现在您可以根据需要使用 seventhColumnValue,例如将其与ID一起存储
 
                     selectedIds.push({
                         id: this.value,
@@ -346,7 +339,7 @@
                 // 发送POST请求到后端
                 $.ajax({
                     type: "POST",
-                    url: "/Device/DeviceWarningAdd", // 替换为您的后端接口地址
+                    url: "/Device/DeviceWarningAdd",
                     data: JSON.stringify(rowData),
                     contentType: "application/json;charset=utf-8",
                     dataType: "json",
@@ -436,6 +429,64 @@
 
             });
 
+            $('.siftWarning').on('click', function () {
+                $.ajax({
+                    type: "GET",
+                    url: "/Device/DeviceWarning_waraning",
+                    contentType: "application/json;charset=utf-8",
+                    dataType: "json",
+                    success: function (response) {
+                        if (response.Code === 200) {
+                            const data = response.Data;
+                            // 获取select元素
+                            const selectElement = document.querySelector('select');
+                            // 清空原有的选项(除了第一个默认选项)
+                            for (let i = selectElement.options.length - 1; i >= 1; i--) {
+                                selectElement.remove(i);
+                            }
+                            // 遍历数据并添加新的选项
+                            data.forEach(item => {
+                                const option = document.createElement('option');
+                                option.value = item.Key;
+                                option.textContent = item.Value;
+                                selectElement.appendChild(option);
+                            });
+                        } else {
+                            layer.msg('获取类型失败', {icon: 5, time: 2000});
+                        }
+                    },
+                    error: function (xhr, status, error) {
+                        layer.msg('请求错误,请检查网络连接!', {icon: 5, time: 2000});
+                    }
+                });
+                const selectElement = document.querySelector('select');
+                // 添加change事件监听器
+                selectElement.addEventListener('change', function() {
+                    // 在这里写你需要执行的方法或逻辑
+                    console.log('选中的值:', this.value); // 打印选中的值
+                    // 可以在这里调用其他方法或执行其他操作
+                    const t_tp=this.value;
+                    getWarningType(t_tp)
+                });
+
+
+            })
+            function getWarningType (t_tp) {
+                var pageSize = localStorage.getItem('pageSize') || 100;
+                // 获取输入框的值
+                const startTime = document.getElementById('Time_start').value;
+                const endTime = document.getElementById('Time_end').value;
+                const sn = document.querySelector('input[name="T_sn"]').value;
+                // 在这里处理这些值,例如发送到服务器或进行其他操作
+                console.log('开始时间:', startTime);
+                console.log('结束时间:', endTime);
+                console.log('SN:', sn);
+                console.log('page:', pageSize);
+                console.log('t_tp:', t_tp);
+                const url = `?page=1&T_sn=${encodeURIComponent(sn)}&Time_start=${encodeURIComponent(startTime)}&Time_end=${encodeURIComponent(endTime)}&pageSize=${encodeURIComponent(pageSize)}&t_tp=${encodeURIComponent(t_tp)}`;
+                window.location.href = url;
+
+            }
             // 定义提交更新到后端的函数
             function submitUpdate(rowId, columnName, newValue, T_Ut_value,attr) {
                 var dataToSubmit = {
@@ -474,7 +525,7 @@
                         fetch("/Device/DeviceWarning_waraning")
                             .then(response => {
                                 if (!response.ok) {
-                                    throw new Error('Network response was not ok');
+                                    throw new Error('网络连接失败');
                                 }
                                 return response.json();
                             })
@@ -485,7 +536,7 @@
                                 });
                             })
                             .catch(error => {
-                                console.error('There has been a problem with your fetch operation:', error);
+                                console.error( error);
                             });
                         break;
                     case 't__state':
@@ -498,7 +549,7 @@
                         fetch("/Device/DeviceWarning_ALL_SN")
                             .then(response => {
                                 if (!response.ok) {
-                                    throw new Error('Network response was not ok');
+                                    throw new Error('网络连接失败');
                                 }
                                 return response.json();
                             })
@@ -508,7 +559,7 @@
                                 });
                             })
                             .catch(error => {
-                                console.error('There has been a problem with your fetch operation:', error);
+                                console.error(error);
                             });
                         break;
                     case 't_id':
@@ -517,7 +568,7 @@
                         fetch(url)
                             .then(response => {
                                 if (!response.ok) {
-                                    throw new Error('Network response was not ok');
+                                    throw new Error('连接失败');
                                 }
                                 return response.json();
                             })
@@ -528,7 +579,7 @@
                                 });
                             })
                             .catch(error => {
-                                console.error('There has been a problem with your fetch operation:', error);
+                                console.error(error);
                             });
                         break;
                     default: