modify the query conditions to tagname and fix building bug
This commit is contained in:
parent
858d02f955
commit
37a1ccaadc
|
|
@ -11,14 +11,14 @@ import (
|
|||
"gorm.io/gorm/clause"
|
||||
)
|
||||
|
||||
// QueryGridByName return the result of query circuit diagram grid info by name from postgresDB
|
||||
func QueryGridByName(ctx context.Context, tx *gorm.DB, name string) (orm.Grid, error) {
|
||||
// QueryGridByName return the result of query circuit diagram grid info by tagName from postgresDB
|
||||
func QueryGridByName(ctx context.Context, tx *gorm.DB, tagName string) (orm.Grid, error) {
|
||||
var grid orm.Grid
|
||||
// ctx超时判断
|
||||
cancelCtx, cancel := context.WithTimeout(ctx, 5*time.Second)
|
||||
defer cancel()
|
||||
|
||||
result := tx.WithContext(cancelCtx).Where("NAME = ? ", name).Clauses(clause.Locking{Strength: "UPDATE"}).Find(&grid)
|
||||
result := tx.WithContext(cancelCtx).Where("TAGNAME = ? ", tagName).Clauses(clause.Locking{Strength: "UPDATE"}).Find(&grid)
|
||||
if result.Error != nil {
|
||||
return orm.Grid{}, result.Error
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,14 +11,14 @@ import (
|
|||
"gorm.io/gorm/clause"
|
||||
)
|
||||
|
||||
// QueryStationByName return the result of query circuit diagram Station info by name from postgresDB
|
||||
func QueryStationByName(ctx context.Context, tx *gorm.DB, name string) (orm.Station, error) {
|
||||
// QueryStationByName return the result of query circuit diagram Station info by tagName from postgresDB
|
||||
func QueryStationByName(ctx context.Context, tx *gorm.DB, tagName string) (orm.Station, error) {
|
||||
var station orm.Station
|
||||
// ctx超时判断
|
||||
cancelCtx, cancel := context.WithTimeout(ctx, 5*time.Second)
|
||||
defer cancel()
|
||||
|
||||
result := tx.WithContext(cancelCtx).Where("NAME = ? ", name).Clauses(clause.Locking{Strength: "UPDATE"}).Find(&station)
|
||||
result := tx.WithContext(cancelCtx).Where("TAGNAME = ? ", tagName).Clauses(clause.Locking{Strength: "UPDATE"}).Find(&station)
|
||||
if result.Error != nil {
|
||||
return orm.Station{}, result.Error
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,14 +11,14 @@ import (
|
|||
"gorm.io/gorm/clause"
|
||||
)
|
||||
|
||||
// QueryZoneByName return the result of query circuit diagram Zone info by name from postgresDB
|
||||
func QueryZoneByName(ctx context.Context, tx *gorm.DB, name string) (orm.Zone, error) {
|
||||
// QueryZoneByName return the result of query circuit diagram Zone info by tagName from postgresDB
|
||||
func QueryZoneByName(ctx context.Context, tx *gorm.DB, tagName string) (orm.Zone, error) {
|
||||
var zone orm.Zone
|
||||
// ctx超时判断
|
||||
cancelCtx, cancel := context.WithTimeout(ctx, 5*time.Second)
|
||||
defer cancel()
|
||||
|
||||
result := tx.WithContext(cancelCtx).Where("NAME = ? ", name).Clauses(clause.Locking{Strength: "UPDATE"}).Find(&zone)
|
||||
result := tx.WithContext(cancelCtx).Where("TAGNAME = ? ", tagName).Clauses(clause.Locking{Strength: "UPDATE"}).Find(&zone)
|
||||
if result.Error != nil {
|
||||
return orm.Zone{}, result.Error
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,18 @@
|
|||
// Package router provides router config
|
||||
package router
|
||||
|
||||
import (
|
||||
"modelRT/handler"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
// registerAttrRoutes define func of register attr routes
|
||||
func registerAttrRoutes(rg *gin.RouterGroup) {
|
||||
g := rg.Group("/attr/")
|
||||
// TODO add attr middleware
|
||||
g.GET("load", handler.AttrGetHandler)
|
||||
g.POST("create", handler.AttrGetHandler)
|
||||
g.POST("update", handler.AttrSetHandler)
|
||||
g.POST("delete", handler.AttrDeleteHandler)
|
||||
}
|
||||
|
|
@ -1,3 +1,4 @@
|
|||
// Package router provides router config
|
||||
package router
|
||||
|
||||
import (
|
||||
|
|
@ -6,7 +7,7 @@ import (
|
|||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
// RegisterRoutes define func of register diagram routes
|
||||
// registerDiagramRoutes define func of register diagram routes
|
||||
func registerDiagramRoutes(rg *gin.RouterGroup) {
|
||||
g := rg.Group("/diagram/")
|
||||
// TODO add diagram middleware
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
// Package router provides router config
|
||||
package router
|
||||
|
||||
import (
|
||||
|
|
@ -14,9 +15,11 @@ func init() {
|
|||
limiter = middleware.NewLimiter(10, 1*time.Minute) // 设置限流器,允许每分钟最多请求10次
|
||||
}
|
||||
|
||||
// RegisterRoutes define func of register all routes
|
||||
func RegisterRoutes(engine *gin.Engine) {
|
||||
// use global middlewares
|
||||
engine.Use(middleware.StartTrace(), limiter.Middleware)
|
||||
routeGroup := engine.Group("")
|
||||
registerDiagramRoutes(routeGroup)
|
||||
registerAttrRoutes(routeGroup)
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue