Răsfoiți Sursa

增加数据管理增加排序功能
增加数据管理可修改温湿度上下限
增加温湿度显示
增加根据设备SN查询公司名称

huangyan 2 luni în urmă
părinte
comite
2c4ffacb15

+ 2 - 2
conf/app.conf

@@ -8,10 +8,10 @@ copyrequestbody = true
 NatsServer_Url = "127.0.0.1:43422"
 
 # Mysql
-MysqlServer_UrlPort = "203.34.49.130:3306"
+MysqlServer_UrlPort = "127.0.0.1:40306"
 MysqlServer_Database = "cold"
 MysqlServer_Username = "cold"
-MysqlServer_Password = "yjwyEckZS7rE5H"
+MysqlServer_Password = "yjwyEckZS7rE5H!"
 MysqlServer_MaxIdleConnections = 100
 MysqlServer_MaxOpenConnections = 200
 

+ 37 - 15
controllers/DataController.go

@@ -132,7 +132,7 @@ func (c *DataController) Device_Sensor_Data_More() {
 		return
 	}
 	sort := c.GetString("sort")
-	log.Println(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, sort)
@@ -211,6 +211,7 @@ func (c *DataController) Device_Sensor_Update() {
 		return
 	}
 	T_sn := c.GetString("t_sn")
+	T_sp := c.GetString("t_sp")
 	T_id, _ := c.GetInt("t_id")
 	T_t, _ := c.GetFloat("t_t")
 	T_rh, _ := c.GetFloat("t_rh")
@@ -218,7 +219,9 @@ func (c *DataController) Device_Sensor_Update() {
 	CreateTime := c.GetString("create_time")
 	fieldName := c.GetString("type")
 	val := c.GetString("value")
+	i, _ := strconv.ParseInt(T_sp, 10, 64)
 	data := Device.DeviceData_R{
+		T_sp:        int(i),
 		T_sn:        T_sn,
 		T_id:        T_id,
 		T_t:         float32(T_t),
@@ -228,8 +231,14 @@ func (c *DataController) Device_Sensor_Update() {
 	}
 	log.Println(T_sn, T_id, T_t, T_rh, T_site, fieldName, val, "修改值")
 	log.Println(data, "修改值")
-	Device.Update_DeviceSensorData(data, fieldName, val)
-
+	err := Device.Update_DeviceSensorData(data, fieldName, val)
+	if err != nil {
+		c.Data["json"] = lib.JSONS{
+			201, "更新失败", nil,
+		}
+		c.ServeJSON()
+		return
+	}
 	c.Data["json"] = lib.JSONS{
 		200, "更新成功", nil,
 	}
@@ -356,20 +365,33 @@ func (c *DataController) Device_Sensor_Data_Excel() {
 		fmt.Println(err)
 	}
 	url := "/ofile/" + filename + ".xlsx"
-	//// 上传 OSS
-	//url, is := NatsServer.Qiniu_UploadFile(lib.GetCurrentDirectory()+"/ofile/"+timeStr+".xlsx", "ofile/"+timeStr+".xlsx")
-	//if !is {
-	//	c.Data["json"] = lib.JSONS{Code: 202, Msg: "oss!"}
-	//	c.ServeJSON()
-	//	return
-	//}
-	//删除目录
-	//err := os.Remove("ofile/" + timeStr + ".xlsx")
-	//if err != nil {
-	//	fmt.Println(err)
-	//}
 
 	c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: url}
 	c.ServeJSON()
 	return
 }
+
+// GetCompanyBySn 根据SN查询对应公司
+func (c *DataController) GetCompanyBySn() {
+	b_, admin := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
+	if !b_ {
+		c.Data["json"] = lib.JSONS{Code: 201, Msg: "User_tokey Err!"}
+		c.ServeJSON()
+		return
+	}
+	if admin.T_name == "魏公梅" {
+		sn := c.GetString("sn")
+		company, err := Device.GetCompanyBySn(sn)
+		if err != nil {
+			c.Data["json"] = lib.JSONS{Code: 201, Msg: "查询失败"}
+			c.ServeJSON()
+			return
+		}
+		log.Println(admin.T_name)
+		c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: company}
+		c.ServeJSON()
+		return
+	}
+	c.Data["json"] = lib.JSONS{Code: 403, Msg: "无权限"}
+	c.ServeJSON()
+}

+ 1 - 1
lastupdate.tmp

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

+ 33 - 0
logs/logx/logx.log

@@ -105245,3 +105245,36 @@
 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]  =========== 初始化报警类型 =========
+2024/09/23 17:00:34.663 [I] [WarningType.go:193]  =========== 初始化报警类型 =========
+2024/09/23 17:07:30.118 [I] [WarningType.go:193]  =========== 初始化报警类型 =========
+2024/09/23 17:09:04.636 [I] [WarningType.go:193]  =========== 初始化报警类型 =========
+2024/09/23 17:09:35.281 [I] [WarningType.go:193]  =========== 初始化报警类型 =========
+2024/09/23 17:10:45.296 [I] [WarningType.go:193]  =========== 初始化报警类型 =========
+2024/09/23 17:25:42.019 [I] [WarningType.go:193]  =========== 初始化报警类型 =========
+2024/09/23 17:30:01.754 [I] [WarningType.go:193]  =========== 初始化报警类型 =========
+2024/09/24 09:09:06.340 [I] [WarningType.go:193]  =========== 初始化报警类型 =========
+2024/09/24 10:03:55.403 [I] [WarningType.go:193]  =========== 初始化报警类型 =========
+2024/09/24 10:07:45.044 [I] [WarningType.go:193]  =========== 初始化报警类型 =========
+2024/09/24 10:08:56.590 [I] [WarningType.go:193]  =========== 初始化报警类型 =========
+2024/09/24 10:41:00.514 [I] [WarningType.go:193]  =========== 初始化报警类型 =========
+2024/09/24 10:52:57.284 [I] [WarningType.go:193]  =========== 初始化报警类型 =========
+2024/09/24 10:54:05.975 [I] [WarningType.go:193]  =========== 初始化报警类型 =========
+2024/09/24 13:34:39.645 [E] [WarningType.go:202]  ColdP_server/models/Warning.Read_WarningType_All_Maps invalid connection
+2024/09/24 14:09:30.374 [I] [WarningType.go:193]  =========== 初始化报警类型 =========
+2024/09/24 14:46:55.907 [I] [WarningType.go:193]  =========== 初始化报警类型 =========
+2024/09/24 14:50:51.389 [I] [WarningType.go:193]  =========== 初始化报警类型 =========
+2024/09/24 14:51:31.887 [I] [WarningType.go:193]  =========== 初始化报警类型 =========
+2024/09/24 14:54:07.844 [I] [WarningType.go:193]  =========== 初始化报警类型 =========
+2024/09/24 14:56:12.454 [I] [WarningType.go:193]  =========== 初始化报警类型 =========
+2024/09/24 15:15:01.417 [I] [WarningType.go:193]  =========== 初始化报警类型 =========
+2024/09/24 15:18:36.641 [I] [WarningType.go:193]  =========== 初始化报警类型 =========
+2024/09/24 15:19:43.054 [I] [WarningType.go:193]  =========== 初始化报警类型 =========
+2024/09/24 15:28:04.003 [I] [WarningType.go:193]  =========== 初始化报警类型 =========
+2024/09/24 15:37:41.388 [I] [WarningType.go:193]  =========== 初始化报警类型 =========
+2024/09/24 15:39:20.497 [I] [WarningType.go:193]  =========== 初始化报警类型 =========
+2024/09/24 15:43:04.695 [I] [WarningType.go:193]  =========== 初始化报警类型 =========
+2024/09/24 15:43:54.276 [I] [WarningType.go:193]  =========== 初始化报警类型 =========
+2024/09/24 15:57:46.401 [I] [WarningType.go:193]  =========== 初始化报警类型 =========
+2024/09/24 16:02:25.734 [I] [WarningType.go:193]  =========== 初始化报警类型 =========
+2024/09/24 16:04:04.775 [I] [WarningType.go:193]  =========== 初始化报警类型 =========
+2024/09/24 16:04:59.582 [I] [WarningType.go:193]  =========== 初始化报警类型 =========

+ 47 - 9
models/Device/DeviceData.go

@@ -45,6 +45,7 @@ type DeviceData_ struct {
 type DeviceData_R struct {
 	T_sn        string  `json:"t_sn"`   //设备
 	T_id        int     `json:"t_id"`   // 传感器id
+	T_sp        int     `json:"t_sp"`   // 传感器参数id
 	T_name      string  `json:"t_name"` // 传感器名称
 	T_t         float32 `json:"t_t"`    // 温度
 	T_rh        float32 `json:"t_rh"`   // 湿度
@@ -84,11 +85,12 @@ func DeviceData_ToDeviceData_R(r DeviceData_, maps map[int]DeviceSensorParameter
 	t.T_time = r.T_time.Format("2006-01-02 15:04:05")
 	t.Create_Time = r.Create_time.Format("2006-01-02 15:04:05")
 	if sp, ok := maps[r.T_sp]; ok {
+		t.T_sp = sp.T_sp
 		t.T_name = sp.T_name
 		t.T_tl = sp.T_Tlower
 		t.T_tu = sp.T_Tupper
 		t.T_rhl = sp.T_RHlower
-		t.T_rhu = sp.T_Tupper
+		t.T_rhu = sp.T_RHupper
 	}
 	return
 }
@@ -274,7 +276,7 @@ func Read_DeviceData_ById_List(SN string, T_id int, Time_start_ string, Time_end
 		sql = sql + " LIMIT " + strconv.Itoa(offset) + "," + strconv.Itoa(page_z)
 	}
 
-	fmt.Println(sql)
+	//fmt.Println(sql)
 	_, err = o.Raw(sql).QueryRows(&maps)
 
 	//value, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", cnt), 64)
@@ -507,14 +509,32 @@ func Read_DeviceData_Execl_ISREPEAT(sn, t_time, t_id string) bool {
 }
 */
 // Update_DeviceSensorData 更新设备数据
-func Update_DeviceSensorData(v DeviceData_R, fieldName, val string) {
+func Update_DeviceSensorData(v DeviceData_R, fieldName, val string) error {
 	o := orm.NewOrm()
-	sqlStatemt := fmt.Sprintf("update z_device_data_%s set %s = ? where t_id = ? and t_t = ? and t_rh = ? and t_site = ? and create_time = ?", v.T_sn, fieldName)
-	log.Println(sqlStatemt)
-	log.Println("创建时间:", v.Create_Time)
-	_, err := o.Raw(sqlStatemt, val, v.T_id, v.T_t, v.T_rh, v.T_site, v.Create_Time).Exec()
-	if err != nil {
-		fmt.Println(err.Error())
+	if fieldName == "t__tlower" {
+		split := strings.Split(val, "|")
+		i := strings.Split(split[0], "~")
+		t__tlower := i[0]
+		t__tupper := i[1]
+		i2 := strings.Split(split[1], "~")
+		t__r_hlower := i2[0]
+		t__r_hupper := i2[1]
+		sqlStatemt := fmt.Sprintf("update device_sensor_parameter set t__tlower =%s , t__tupper = %s , t__r_hlower = %s , t__r_hupper = %s where id =%d ", t__tlower, t__tupper, t__r_hlower, t__r_hupper, v.T_sp)
+		//log.Println(sqlStatemt)
+		_, err := o.Raw(sqlStatemt).Exec()
+		if err != nil {
+			return err
+		}
+		return nil
+	} else {
+		sqlStatemt := fmt.Sprintf("update z_device_data_%s set %s = ? where t_id = ? and t_t = ? and t_rh = ? and t_site = ? and create_time = ?", v.T_sn, fieldName)
+		log.Println(sqlStatemt)
+		log.Println("创建时间:", v.Create_Time)
+		_, err := o.Raw(sqlStatemt, val, v.T_id, v.T_t, v.T_rh, v.T_site, v.Create_Time).Exec()
+		if err != nil {
+			return err
+		}
+		return nil
 	}
 }
 
@@ -616,3 +636,21 @@ func Read_DeviceData_List_GROUP_BY_t_time(SN string, Time_start_ string, Time_en
 	o.Raw(sql).ValuesList(&maps_z)
 	return maps_z
 }
+
+// GetCompanyBySn 根据sn查询公司名称
+func GetCompanyBySn(sn string) (string, error) {
+	o := orm.NewOrm()
+	sqls := fmt.Sprintf("SELECT t_pid FROM `device` WHERE t_sn='%s'", sn)
+	var TPid string
+	err := o.Raw(sqls).QueryRow(&TPid)
+	if err != nil {
+		return "", err
+	}
+	sqlCompany := fmt.Sprintf("SELECT t_name FROM `company` WHERE id='%s'", TPid)
+	var TName string
+	err = o.Raw(sqlCompany).QueryRow(&TName)
+	if err != nil {
+		return "", err
+	}
+	return TName, nil
+}

+ 1 - 0
models/Device/DeviceSensor.go

@@ -550,6 +550,7 @@ func Read_DeviceSensor_List_T_Class(T_pid int, T_Class_id int, T_sn string, T_na
 	for _, v := range r {
 		DeviceSensor_r = append(DeviceSensor_r, DeviceSensorToDeviceSensor_(v))
 	}
+
 	return DeviceSensor_r, cnt
 }
 

+ 4 - 0
models/Device/DeviceSensorParameter.go

@@ -74,6 +74,7 @@ type DeviceSensorParameter_R struct {
 type DeviceSensorParameter_M struct {
 	T_name string // 标题
 	// 报警
+	T_sp      int     // 传感器编号
 	T_Tlower  float32 //  温度下限
 	T_Tupper  float32 //  温度上限
 	T_RHlower float32 //  湿度下限
@@ -234,9 +235,12 @@ func Read_DeviceSensorParameter_Map_All(T_sn string, T_id int) (maps map[int]Dev
 
 	qs.SetCond((*orm2.Condition)(cond)).OrderBy("-Id").All(&list)
 
+	//sql := fmt.Sprintf("SELECT * FROM `device_sensor_parameter` WHERE t_sn='%s' and t_id =%s AND update_time < '2024-09-12 10:00:00' ORDER BY update_time DESC LIMIT 1", T_sn, T_id)
+
 	maps = make(map[int]DeviceSensorParameter_M)
 	for _, v := range list {
 		maps[v.Id] = DeviceSensorParameter_M{
+			T_sp:      v.Id,
 			T_name:    v.T_name,
 			T_Tlower:  v.T_Tlower,
 			T_Tupper:  v.T_Tupper,

+ 3 - 0
routers/DataRouter.go

@@ -23,6 +23,9 @@ func init() {
 	//数据导入
 	beego.Router("/Data/importData", &controllers.DataController{}, "POST:ImportData")
 	beego.Router("/Data/EXportData", &controllers.DataController{}, "*:Device_Sensor_Data_Excel")
+	//获取公司信息
+	beego.Router("/Data/GetCompanyBySn", &controllers.DataController{}, "GET:GetCompanyBySn")
+
 	beego.Router("/Data/Device_Sensor_List_Delete_Time", &controllers.DataController{}, "*:Device_Sensor_List_Delete_Time")
 
 	//数据生成

+ 11 - 2
views/Data/DataList.html

@@ -191,6 +191,7 @@
                             </th>
                             <th>温度℃</th>
                             <th>湿度%</th>
+                            <th>温湿度上下限</th>
                             <th>GPS</th>
                             <th>录入时间</th>
                             <th>操作</th>
@@ -863,10 +864,11 @@
             }
             $('#DeviceSensor_data').append(`
             <tr>
-                <td><input type="checkbox" class="layui-form-checkbox" data-sn="${v.t_sn}" data-id="${v.t_id}" data-tt="${v.t_t}" data-trh="${v.t_rh}" data-site="${v.t_site}" data-createTime="${v.create_time}"/></td>
+                <td><input type="checkbox" class="layui-form-checkbox" data-sn="${v.t_sn}" data-sp="${v.t_sp}" data-id="${v.t_id}" data-tt="${v.t_t}" data-trh="${v.t_rh}" data-site="${v.t_site}" data-createTime="${v.create_time}"/></td>
                 <td ondblclick="changeData(this)" data-type="t_time">${v.t_time}</td>
                 <td ondblclick="changeData(this)" data-type="t_t">${v.t_t}</td>
                 <td ondblclick="changeData(this)" data-type="t_rh">${v.t_rh}</td>
+                <td ondblclick="changeData(this)" data-type="t__tlower">${v.t_tl}~${v.t_tu}|${v.t_rhl}~${v.t_rhu}</td>
                 <td ondblclick="changeData(this)" data-type="t_site">${v.t_site}</td>
                 <td ondblclick="changeData(this)" data-type="create_time">${v.create_time}</td>
                 <td>
@@ -1001,6 +1003,7 @@
 
         let t = {
             t_sn: $(e).attr('data-sn'),
+            t_sp: $(e).attr('data-sp'),
             t_id: Number.parseInt($(e).attr('data-id')),
             create_time: ($(e).attr('data-createtime')),
             t_t: Number.parseFloat($(e).attr('data-tt')),
@@ -1024,10 +1027,16 @@
                     cookie: $.cookie("User_token"),
                     success: function (rlt) {
                         console.log(rlt)
+                        if (rlt.Code===200){
+                            layui.layer.msg('修改成功')
+                            get_DeviceSensor_data(0)
+                        }else {
+                            layui.layer.msg(rlt.Msg)
+                        }
                     }
                 })
             }
-            console.log(t)
+            // console.log(t)
             even.innerHTML = this.value
             $(e).attr(`data-${type}`, $(this).val())
         }

+ 70 - 8
views/home.html

@@ -10,31 +10,52 @@
     <meta http-equiv="Cache-Control" content="no-siteapp"/>
     <link rel="stylesheet" href="/static/css/font.css">
     <link rel="stylesheet" href="/static/css/xadmin.css">
+    <script src="/static/js/jquery.min.js"></script>
+    <script src="/static/js/jquery.cookie.min.js"></script>
+    <script src="/static/lib/layui/layui.js" charset="utf-8"></script>
+    <script type="text/javascript" src="/static/js/xadmin.js"></script>
 </head>
 <body>
 <div class="layui-container">
     <div class="fly-panel">
         <div class="fly-none">
             <h2><i style="font-size: 64px;" class="iconfont">&#xe6af;</i></h2>
-<!--                        <p> 你好,{{.T_name}}</p>-->
-                        <a style="color: #1E9FFF" onclick="window.parent.location.href='/Login'"> 退出登录 </a>
+            <!--                        <p> 你好,{{.T_name}}</p>-->
+            <a style="color: #1E9FFF" onclick="window.parent.location.href='/Login'"> 退出登录 </a>
             <div class="layui-row">
-                <div class="layui-col-md6" onclick="window.parent.xadmin.add_tab('设备管理','/Device/DeviceManager_html')">
+                <div class="layui-col-md6"
+                     onclick="window.parent.xadmin.add_tab('设备管理','/Device/DeviceManager_html')">
                     <i class="layui-icon" style="font-size: 100px;">&#xe610;</i>
                     <H2 style="margin-top: -80px;">设备管理</H2>
                 </div>
                 <div class="layui-col-md6" onclick="window.parent.xadmin.add_tab('数据管理','/Data/DataList_html')">
-                    <i class="layui-icon"style="font-size: 100px;" >&#xe62d;</i>
+                    <i class="layui-icon" style="font-size: 100px;">&#xe62d;</i>
                     <H2 style="margin-top: -80px;">数据管理</H2>
                 </div>
             </div>
+            <div class="layui-row getCompany">
+                <div style="margin-left: 450px; ">
+                    <div class="layui-col-md6" style="width: 200px; ">
+                        <label>
+                            <input type="text" placeholder="根据SN查询公司" class="layui-input layui-clear" id="sn"
+                                   name="sn">
+                        </label>
+                    </div>
+                    <div class="layui-col-md6" style="margin-left: -140px;">
+                        <button type="button" class="layui-btn layui-bg-blue" onclick="GetCompanyBySn()">查询</button>
+                    </div>
+                </div>
+            </div>
+
             <div class="layui-row">
-                <div class="layui-col-md6" onclick="window.parent.xadmin.add_tab('曲线管理','/Data/DataGenerator_html')">
-                    <i class="layui-icon"style="font-size: 100px;" >&#xe629;</i>
+                <div class="layui-col-md6"
+                     onclick="window.parent.xadmin.add_tab('曲线管理','/Data/DataGenerator_html')">
+                    <i class="layui-icon" style="font-size: 100px;">&#xe629;</i>
                     <H2 style="margin-top: -80px;">曲线管理</H2>
                 </div>
-                <div class="layui-col-md6" onclick="window.parent.xadmin.add_tab('报警管理','/Device/DeviceWarning_List_html')">
-                    <i class="layui-icon"style="font-size: 100px;" >&#xe667;</i>
+                <div class="layui-col-md6"
+                     onclick="window.parent.xadmin.add_tab('报警管理','/Device/DeviceWarning_List_html')">
+                    <i class="layui-icon" style="font-size: 100px;">&#xe667;</i>
                     <H2 style="margin-top: -80px;">报警管理</H2>
                 </div>
             </div>
@@ -44,4 +65,45 @@
 </div>
 
 </body>
+<script>
+    window.onload = function () {
+        // 页面加载完成后执行的代码
+        console.log("页面加载完成",token);
+
+    }
+
+    function GetCompanyBySn() {
+        const snid = $("#sn").val();
+        console.log(snid);
+        $.ajax({
+            url: '/Data/GetCompanyBySn',
+            type: 'GET',
+            data: {
+                sn: snid,
+                token: $.cookie("User_token")
+            },
+            success: function (data) {
+                console.log(data.Data);
+                let company = data.Data;
+                if (data.Code === 200) {
+                    layer.open({
+                        type: 1, // page 层类型
+                        area: ['200px', '200px'],
+                        title: '公司名称',
+                        shade: 0.6, // 遮罩透明度
+                        shadeClose: true, // 点击遮罩区域,关闭弹层
+                        maxmin: true, // 允许全屏最小化
+                        anim: 0, // 0-6 的动画形式,-1 不开启
+                        content: company
+                    });
+                    $("#sn").val("");
+                }else{
+                    layui.layer.msg(data.Msg)
+                    $("#sn").val("");
+                }
+            }
+        })
+    }
+
+</script>
 </html>