37 Star 391 Fork 118

联犀/物联网iot模块

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
crud.go 1.57 KB
一键复制 编辑 原始数据 按行查看 历史
杨磊 提交于 2025-01-02 23:22 . feat: 支持tdengine可选
package hubLogRepo
import (
"context"
"fmt"
"gitee.com/unitedrhino/share/def"
"gitee.com/unitedrhino/share/stores"
"gitee.com/unitedrhino/things/service/dmsvr/internal/domain/deviceLog"
)
func (h *HubLogRepo) fillFilter(ctx context.Context, db *stores.DB, filter deviceLog.HubFilter) *stores.DB {
db = db.WithContext(ctx)
if len(filter.ProductID) != 0 {
db = db.Where("product_id=?", filter.ProductID)
}
if len(filter.DeviceName) != 0 {
db = db.Where("device_name=?", filter.DeviceName)
}
if len(filter.Content) != 0 {
db = db.Where("content=?", filter.Content)
}
if len(filter.RequestID) != 0 {
db = db.Where("request_id=?", filter.RequestID)
}
if len(filter.Actions) != 0 {
db = db.Where(fmt.Sprintf("action in (%v)", stores.ArrayToSql(filter.Actions)))
}
if len(filter.Topics) != 0 {
db = db.Where(fmt.Sprintf("topic in (%v)", stores.ArrayToSql(filter.Topics)))
}
return db
}
func (h *HubLogRepo) GetCountLog(ctx context.Context, filter deviceLog.HubFilter, page def.PageInfo2) (int64, error) {
db := h.fillFilter(ctx, h.db, filter)
var count int64
err := db.Model(Hub{}).Count(&count).Error
return count, stores.ErrFmt(err)
}
func (h *HubLogRepo) GetDeviceLog(ctx context.Context, filter deviceLog.HubFilter, page def.PageInfo2) (
[]*deviceLog.Hub, error) {
db := h.fillFilter(ctx, h.db, filter)
db = page.FmtSql2(db)
var list []*deviceLog.Hub
err := db.Model(Hub{}).Find(&list).Error
return list, stores.ErrFmt(err)
}
func (h *HubLogRepo) Insert(ctx context.Context, data *deviceLog.Hub) error {
h.asyncInsert.AsyncInsert(&Hub{Hub: data})
return nil
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/unitedrhino/things.git
git@gitee.com:unitedrhino/things.git
unitedrhino
things
物联网iot模块
v1.2.1

搜索帮助