Commit 2c127487 authored by honghuiliu's avatar honghuiliu 💬

日常提交

parent 0a0b243c
......@@ -42,3 +42,18 @@ func GetHistoryDataList(c *gin.Context) {
}, c)
}
func GetDeviceData(c *gin.Context) {
var arg request.GetDeviceData
if err := c.ShouldBindJSON(&arg); err != nil {
response.FailWithMessage(err.Error(), c)
return
}
list, err := DataService.GetDeviceData(arg)
if err != nil {
response.FailWithMessage(err.Error(), c)
return
}
response.OkWithData(list, c)
}
......@@ -11,7 +11,7 @@ require (
github.com/beego/beego/v2 v2.0.5
github.com/casbin/casbin/v2 v2.11.0
github.com/casbin/gorm-adapter/v3 v3.0.2
github.com/eclipse/paho.mqtt.golang v1.4.2 // indirect
github.com/eclipse/paho.mqtt.golang v1.4.2
github.com/flipped-aurora/ws v1.0.2
github.com/fsnotify/fsnotify v1.4.9
github.com/fvbock/endless v0.0.0-20170109170031-447134032cb6
......
package main
import (
"fmt"
"github.com/flipped-aurora/gin-vue-admin/server/core"
"github.com/flipped-aurora/gin-vue-admin/server/global"
"github.com/flipped-aurora/gin-vue-admin/server/initialize"
......@@ -50,9 +48,10 @@ func main() {
// 净化设施服务
if global.GVA_VP.GetBool("mqttServer.enable") {
server.OnMqttMessage(func(data server.JingHuaData) error {
service := new(web.DataService)
// {301022041237 {"MBR池溶氧值":0,"出水池PH值":4,"出水池流量值":0,"厌氧池PH值":4,"好氧池PH值":4.0,"好氧池溶氧值":0,"调节池流量值":0.1}}
fmt.Println(data)
return nil
//fmt.Println(data)
return service.DataInJingHua(data)
})
go server.InitJinghuaServer(global.GVA_VP.GetString("mqttServer.addr"))
}
......
......@@ -14,3 +14,7 @@ type GetHistoryDataList struct {
EndTime string `json:"end_time"`
ToiletID int `json:"toilet_id"`
}
type GetDeviceData struct {
ToiletID int `json:"toilet_id"`
}
......@@ -32,6 +32,7 @@ func InitWebRouter(router *gin.Engine) {
{
data.POST("getHistoryDataList", web.GetHistoryDataList)
data.POST("getYewei", web.GetYewei)
data.POST("getDeviceData", web.GetDeviceData)
}
typeData := webRouter.Group("type")
......
......@@ -6,6 +6,7 @@ import (
"github.com/flipped-aurora/gin-vue-admin/server/model/admin"
"github.com/flipped-aurora/gin-vue-admin/server/request"
"github.com/flipped-aurora/gin-vue-admin/server/server"
"github.com/songzhibin97/gkit/tools/gjson"
"gorm.io/gorm"
)
......@@ -29,6 +30,33 @@ func (s *DataService) DataInYeWei(arg server.YeWeiData) error {
}).Error
}
func (s *DataService) DataInJingHua(arg server.JingHuaData) error {
//先查询设备绑定厕所
var toiletInfo admin.QshToilet
err := global.GVA_DB.Model(admin.QshToilet{}).Where("jinghua_device_id = ?", arg.JinghuaDeviceId).First(&toiletInfo).Error
if err != nil {
return errors.New("设备ID未绑定公厕信息!")
}
var need = [][]string{{"MBR池溶氧值", "mg/l"}, {"出水池PH值", ""}, {"出水池流量值", "m3/h"}, {"厌氧池PH值", ""}, {"好氧池PH值", ""}, {"好氧池溶氧值", "mg/l"}, {"调节池流量值", "m3/h"}}
var data []admin.QshMonitorData
for _, v := range need {
if gjson.Get(arg.Data, v[0]).Exists() {
data = append(data, admin.QshMonitorData{
RawDeviceId: arg.JinghuaDeviceId,
ToiletId: int(toiletInfo.ID),
TypeName: v[0],
Unit: v[1],
Value: gjson.Get(arg.Data, v[0]).String(),
})
}
}
return global.GVA_DB.Create(&data).Error
}
func (s *DataService) getData() {
}
//GetYewei 获取液位
func (s *DataService) GetYewei(arg request.GetYewei) (admin.QshMonitorData, error) {
var data admin.QshMonitorData
......@@ -67,3 +95,15 @@ func (s *DataService) GetHistoryDataList(arg request.GetHistoryDataList) ([]admi
}
return data, count, nil
}
func (s *DataService) GetDeviceData(arg request.GetDeviceData) ([]admin.QshMonitorData, error) {
var data []admin.QshMonitorData
var need = []string{"液位", "MBR池溶氧值", "出水池PH值", "出水池流量值", "厌氧池PH值", "好氧池PH值", "好氧池溶氧值", "调节池流量值"}
err := global.GVA_DB.Debug().Select("max(id) id,type_name,toilet_id,raw_device_id,value,unit,created_at,updated_at,deleted_at").
Model(admin.QshMonitorData{}).Where("toilet_id = ?", arg.ToiletID).Where("type_name IN ?", need).Group("type_name").Find(&data).Error
if err != nil {
return data, err
}
return data, nil
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment