Browse Source

等比缩放

huangyan 1 ngày trước cách đây
mục cha
commit
580d9a8b6f

+ 1 - 2
conf/app.conf

@@ -32,8 +32,7 @@ Mqtt_username = coldp
 Mqtt_password = EHM5PpXDD579gmp
 Mqtt_UrlMqttjxit = "tcp://mqttjxit.coldbaozhida.com:1883"
 Mqtt_UrlMqttlodr = "tcp://mqttlodr.coldbaozhida.com:1883"
-#只有一个项目运行协程
-isRun = true
+
 #corn
 Cron = "0 */2 * * * *"
 

+ 44 - 0
controllers/DataGeneratorController.go

@@ -108,6 +108,50 @@ func (c *DataGeneratorController) UpdateFix() {
 	c.ServeJSON()
 }
 
+// ProportionalScaling 等比缩放
+func (c *DataGeneratorController) ProportionalScaling() {
+	b_, _ := 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
+	}
+	//1.解析数据
+	var body = c.Ctx.Request.Body
+	defer body.Close()
+	type T struct {
+		FixTemperature string      `json:"fixTemperature"`
+		FixHumidity    string      `json:"fixHumidity"`
+		Sns            [][2]string `json:"sns"`
+		Data           []int64     `json:"data"`
+	}
+	var temp = T{}
+	bytes, _ := io.ReadAll(body)
+	json.Unmarshal(bytes, &temp)
+	fmt.Println("解析后:", temp.Data[0])
+
+	//2.得到数据进行统一设置访问修改
+	humidity, _ := strconv.ParseFloat(temp.FixHumidity, 64)
+	temperature, _ := strconv.ParseFloat(temp.FixTemperature, 64)
+	if temperature == 0 || humidity == 0 {
+		temperature = 1
+		humidity = 1
+	}
+	//开始时间到结束时间
+	startTime := time.UnixMilli(temp.Data[0]).Format("2006-01-02 15:04:05")
+	endTime := time.UnixMilli(temp.Data[1]).Format("2006-01-02 15:04:05")
+
+	//3.循环更新数据
+	for _, v := range temp.Sns {
+		sn := v[0]
+		tId := v[1]
+		Device.ProportionalScaling(sn, tId, startTime, endTime, temperature, humidity)
+	}
+	//4.反馈成功
+	c.Data["json"] = lib.JSONS{200, "调整固定偏移值成功!", nil}
+	c.ServeJSON()
+}
+
 // Delete 删除
 func (c *DataGeneratorController) Delete() {
 	b_, _ := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))

+ 1 - 1
lastupdate.tmp

@@ -1 +1 @@
-{"E:\\WebstormProjects\\ColdP_server\\controllers":1744938641913989300}
+{"E:\\WebstormProjects\\ColdP_server\\controllers":1751446913231313600}

+ 4 - 0
logs/logx/logx.log

@@ -652,3 +652,7 @@
 2025/04/18 12:21:59.120 [E] [Mqtt.go:452]  查询参数失败
 2025/04/18 12:51:00.019 [E] [Mqtt.go:452]  查询参数失败
 2025/04/18 13:33:54.137 [E] [Mqtt.go:452]  查询参数失败
+2025/07/02 16:15:28.039 [I] [WarningType.go:193]  =========== 初始化报警类型 =========
+2025/07/02 16:27:58.876 [I] [WarningType.go:193]  =========== 初始化报警类型 =========
+2025/07/02 17:14:04.477 [I] [WarningType.go:193]  =========== 初始化报警类型 =========
+2025/07/02 17:16:39.818 [I] [WarningType.go:193]  =========== 初始化报警类型 =========

+ 19 - 0
models/Device/DeviceSensor.go

@@ -963,6 +963,25 @@ func UpdateDeviceSensorDataTemperatureAndHumidity(sn, id, startTime, endTime str
 	fmt.Printf("影响了%d行\n", affected)
 }
 
+// 比例缩放
+func ProportionalScaling(sn, id, startTime, endTime string, temperature, humidity float64) {
+	sqlStatement := fmt.Sprintf("update z_device_data_%s set t_t = t_t * %f , t_rh = t_rh * %f where t_id = '%s'", sn, temperature, humidity, id)
+	if len(startTime) > 0 && len(endTime) > 0 {
+		sqlStatement += " AND t_time BETWEEN '" + startTime + "' AND '" + endTime + "'"
+	}
+	o := orm.NewOrm()
+
+	exec, err := o.Raw(sqlStatement).Exec()
+	if err != nil {
+		fmt.Println(err.Error())
+	}
+	affected, err := exec.RowsAffected()
+	if err != nil {
+		fmt.Println(err.Error())
+	}
+	fmt.Printf("影响了%d行\n", affected)
+}
+
 // SelectDeviceSensorDataListByTimeRange 搜索设备列表通过时间
 func SelectDeviceSensorDataListByTimeRange(sn, tId, startTime, endTime string) (list []DeviceSensorData) {
 	//sqlStatement := fmt.Sprintf("select t_id,t_sp,DATE_FORMAT(t_time,'%%Y-%%m-%%d %%k:%%i:%%s') as t_time,t_t,t_rh,t_site,DATE_FORMAT(create_time,'%%Y-%%m-%%d %%k:%%i:%%s') as create_time from z_device_data_%s where t_id = %s and t_time BETWEEN '%s' AND '%s' ORDER BY t_time ASC", sn, tId, startTime, endTime)

+ 1 - 0
routers/DataRouter.go

@@ -34,6 +34,7 @@ func init() {
 	beego.Router("/Data/DeviceSensorData", &controllers.DataGeneratorController{}, "POST:DeviceSensorData")
 	//固定值偏移
 	beego.Router("/Data/UpdateFix", &controllers.DataGeneratorController{}, "POST:UpdateFix")
+	beego.Router("/Data/ProportionalScaling", &controllers.DataGeneratorController{}, "POST:ProportionalScaling")
 	// 删除数据
 	beego.Router("/Data/Delete", &controllers.DataGeneratorController{}, "POST:Delete")
 	//随机偏移值

+ 65 - 0
views/Data/GeneratorData2.html

@@ -136,6 +136,7 @@
                     <div class="layui-clear" style="margin-left: 15px">
                         <button onclick="offset()" class="layui-btn layui-btn-normal layui-btn-sm">偏移(固定)</button>
                         <button onclick="offsetRandom()" class="layui-btn layui-btn-normal layui-btn-sm">偏移(随机)
+                        <button onclick="ProportionalScaling()" class="layui-btn layui-btn-normal layui-btn-sm">等比缩放
                         </button>
 <!--                        <button onclick="copyFrom()" class="layui-btn layui-btn-normal layui-btn-sm">复制到</button>-->
                         <button onclick="repair()" class="layui-btn layui-btn-normal layui-btn-sm">补漏</button>
@@ -169,6 +170,20 @@
         </div>
     </div>
 </div>
+<div style="display: none;padding: 20px" id="ProportionalScaling">
+    <div class="layui-form">
+        <div class="layui-form-item">
+            温度:
+            <input type="number" class="layui-input" lay-verify="number" placeholder="固定下调温度" id="Temperature"
+                   value="0">
+        </div>
+        <div class="layui-form-item">
+            湿度:
+            <input type="number" class="layui-input" lay-verify="number" placeholder="固定下调湿度" id="Humidity"
+                   value="0">
+        </div>
+    </div>
+</div>
 <!--随机偏移-->
 <div style="display: none;padding: 20px;justify-content: center" id="offsetRand">
     <div class="layui-form">
@@ -677,6 +692,56 @@
             }
         })
     }
+    //等比缩放
+    function ProportionalScaling() {
+        if (timeRange.length === 0) {
+            layui.layer.msg('请在图中选择要操作数据的区域!')
+            return
+        }
+        //2.layer 打开一个窗口设置要统一设置下移的数据
+        layui.layer.open({
+            type: 1,
+            area: ['300px', '270px'],
+            content: $('#ProportionalScaling'),
+            btn: '确定',
+            btnAlign: 'c',
+            yes: function (index, elem) {
+                let Temperature = $('#Temperature').val();
+                let Humidity = $('#Humidity').val();
+                if (Humidity === "" || Temperature === "") {
+                    //提示消息
+                    layui.layer.msg("没有设置固定温湿度偏移")
+                    return
+                }
+                //3.发送修改数据区域进行循环对值进行统一下调
+                let index2 = loading();
+                $.ajax({
+                    type: 'POST',
+                    url: '/Data/ProportionalScaling',
+                    data: JSON.stringify({
+                        fixTemperature: Temperature,
+                        fixHumidity: Humidity,
+                        sns: getSelectedSn(),
+                        data: timeRange
+                    }),
+                    contentType: 'application/json;charset=utf-8',
+                    processData: false,
+                    success: function (rlt) {
+                        layui.layer.close(index2)
+                        if (rlt.Code === 200) {
+                            //3.1判断是否处理成功
+                            //3.1.1成功更新该设备的数据
+                            timeRange = []
+                            loadEcharts()
+                            layui.layer.close(index)
+                        }
+                        //提示消息
+                        layui.layer.msg(rlt.Msg)
+                    }
+                })
+            }
+        })
+    }
     //删除
     function Delete() {
         if (timeRange.length === 0) {