fix bug of circuit diagram load handler

This commit is contained in:
douxu 2025-01-08 16:37:18 +08:00
parent f48b527708
commit 655acf8e1e
5 changed files with 8 additions and 6 deletions

View File

@ -1,5 +1,5 @@
postgres:
host: "192.168.2.156"
host: "192.168.2.100"
port: 5432
database: "demo"
user: "postgres"
@ -25,7 +25,7 @@ kafka:
logger:
mode: "development"
level: "debug"
filepath: "/home/douxu/log/wave_record-%s.log"
filepath: "/home/douxu/log/modelRT-%s.log"
maxsize: 1
maxbackups: 5
maxage: 30

View File

@ -22,6 +22,7 @@ func QueryCircuitDiagramComponentFromDB(ctx context.Context, pool *ants.PoolWith
// ctx超时判断
cancelCtx, cancel := context.WithTimeout(ctx, 5*time.Second)
defer cancel()
// TODO 将 for update 操作放到事务中
result := _globalPostgresClient.WithContext(cancelCtx).Clauses(clause.Locking{Strength: "UPDATE"}).Find(&Components)
if result.Error != nil {
logger.Error("query circuit diagram component info failed", zap.Error(result.Error))

View File

@ -17,7 +17,7 @@ func QueryAllPages(ctx context.Context, logger *zap.Logger, gridID, zoneID, stat
// ctx超时判断
cancelCtx, cancel := context.WithTimeout(ctx, 5*time.Second)
defer cancel()
// TODO 将 for update 操作放到事务中
result := _globalPostgresClient.Model(&orm.Page{}).WithContext(cancelCtx).Clauses(clause.Locking{Strength: "UPDATE"}).Select(`"page".id, "page".Name, "page".status,"page".context`).Joins(`inner join "station" on "station".id = "page".station_id`).Joins(`inner join "zone" on "zone".id = "station".zone_id`).Joins(`inner join "grid" on "grid".id = "zone".grid_id`).Where(`"grid".id = ? and "zone".id = ? and "station".id = ?`, gridID, zoneID, stationID).Scan(&pages)
if result.Error != nil {

View File

@ -20,6 +20,7 @@ func QueryTopologicByPageID(ctx context.Context, logger *zap.Logger, pageID int6
// ctx超时判断
cancelCtx, cancel := context.WithTimeout(ctx, 5*time.Second)
defer cancel()
// TODO 将 for update 操作放到事务中
result := _globalPostgresClient.WithContext(cancelCtx).Clauses(clause.Locking{Strength: "UPDATE"}).Raw(sql.RecursiveSQL, pageID).Scan(&topologics)
if result.Error != nil {
logger.Error("query circuit diagram topologic info by pageID failed", zap.Int64("pageID", pageID), zap.Error(result.Error))

View File

@ -32,18 +32,18 @@ func GetGraphMap(pageID int64) (*Graph, error) {
// UpdateGrapMap define func of update circuit diagram data by pageID and topologic info
func UpdateGrapMap(pageID int64, graphInfo *Graph) bool {
_, result := diagramsOverview.Swap(pageID, graphInfo)
_, result := graphOverview.Swap(pageID, graphInfo)
return result
}
// StoreGraphMap define func of store circuit diagram topologic data with pageID and topologic info
func StoreGraphMap(pageID int64, graphInfo *Graph) {
diagramsOverview.Store(pageID, graphInfo)
graphOverview.Store(pageID, graphInfo)
return
}
// DeleteGraphMap define func of delete circuit diagram topologic data with pageID
func DeleteGraphMap(pageID int64) {
diagramsOverview.Delete(pageID)
graphOverview.Delete(pageID)
return
}