Commit e31bbace authored by honghuiliu's avatar honghuiliu 💬

日常提交

parent 793f8753
package web
import "github.com/gin-gonic/gin"
import (
"gitee.com/zjlsliupei/ghelp"
"github.com/flipped-aurora/gin-vue-admin/server/model/common/response"
"github.com/flipped-aurora/gin-vue-admin/server/request"
"github.com/flipped-aurora/gin-vue-admin/server/service/web"
"github.com/gin-gonic/gin"
)
var DataService = new(web.DataService)
func DataIn(c *gin.Context) {
}
//GetYewei 获取液位数据
func GetYewei(c *gin.Context) {
var arg request.GetYewei
_ = c.ShouldBindJSON(&arg)
data, err := DataService.GetYewei(arg)
if err != nil {
response.FailWithMessage(err.Error(), c)
return
}
response.OkWithData(data, c)
}
//GetHistoryDataList 获取历史数据列表
func GetHistoryDataList(c *gin.Context) {
var arg request.GetHistoryDataList
_ = c.ShouldBindJSON(&arg)
list, total, err := DataService.GetHistoryDataList(arg)
if err != nil {
response.FailWithMessage(err.Error(), c)
return
}
response.OkWithData(ghelp.MAP{
"list": list,
"total": total,
}, c)
}
package request
import "github.com/flipped-aurora/gin-vue-admin/server/utils"
type GetYewei struct {
ToiletID int `json:"toilet_id"`
YeweiDeviceID string `json:"yewei_device_id"`
}
type GetHistoryDataList struct {
utils.PageInfo
TypeName string `json:"type_name"`
StartTime string `json:"start_time"`
EndTime string `json:"end_time"`
ToiletID int `json:"toilet_id"`
}
......@@ -27,4 +27,9 @@ func InitWebRouter(router *gin.Engine) {
{
oss.POST("getOssConfig", web.GetOssConfig)
}
data := webRouter.Group("data")
{
data.POST("getHistoryDataList", web.GetHistoryDataList)
data.POST("getYewei", web.GetYewei)
}
}
......@@ -4,12 +4,14 @@ import (
"errors"
"github.com/flipped-aurora/gin-vue-admin/server/global"
"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"
)
type DataService struct {
}
//DataInYeWei 接受液位数据
func (s *DataService) DataInYeWei(arg server.YeWeiData) error {
//先查询设备绑定厕所
var toiletInfo admin.QshToilet
......@@ -18,9 +20,47 @@ func (s *DataService) DataInYeWei(arg server.YeWeiData) error {
return errors.New("设备ID未绑定公厕信息!")
}
return global.GVA_DB.Create(&admin.QshMonitorData{
ToiletId: int(toiletInfo.ID),
TypeName: "液位",
Value: arg.YeWei,
Unit: "m",
ToiletId: int(toiletInfo.ID),
RawDeviceId: arg.DeviceId,
TypeName: "液位",
Value: arg.YeWei,
Unit: "m",
}).Error
}
//GetYewei 获取液位
func (s *DataService) GetYewei(arg request.GetYewei) (admin.QshMonitorData, error) {
var data admin.QshMonitorData
err := global.GVA_DB.Model(admin.QshMonitorData{}).Where("toilet_id = ?", arg.ToiletID).Where("type_name = ?", "液位").Last(&data).Error
if err != nil {
return data, err
}
return data, nil
}
//GetHistoryDataList 获取历史数据
func (s *DataService) GetHistoryDataList(arg request.GetHistoryDataList) ([]admin.QshMonitorData, int64, error) {
var count int64
var data []admin.QshMonitorData
limit := arg.PageSize
offset := (arg.Page - 1) * arg.PageSize
db := global.GVA_DB.Model(admin.QshMonitorData{})
if arg.ToiletID != 0 {
db.Where("toilet_id = ?", arg.ToiletID)
}
if arg.TypeName != "" {
db.Where("type_name = ?", arg.TypeName)
}
if arg.StartTime != "" {
db.Where("created_at >= ?", arg.StartTime)
}
if arg.EndTime != "" {
db.Where("created_at <= ?", arg.EndTime)
}
db.Count(&count)
err := db.Limit(limit).Offset(offset).Find(&data).Error
if err != nil {
return data, count, err
}
return data, count, 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