diff --git a/config/config.yaml b/config/config.yaml index e01a5ba..693ca3c 100644 --- a/config/config.yaml +++ b/config/config.yaml @@ -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 diff --git a/database/query_component.go b/database/query_component.go index d87b511..dcc8561 100644 --- a/database/query_component.go +++ b/database/query_component.go @@ -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)) diff --git a/database/query_page.go b/database/query_page.go index 57e886b..723ad88 100644 --- a/database/query_page.go +++ b/database/query_page.go @@ -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 { diff --git a/database/query_topologic.go b/database/query_topologic.go index 2224431..1ceb7d2 100644 --- a/database/query_topologic.go +++ b/database/query_topologic.go @@ -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)) diff --git a/diagram/topologic_set.go b/diagram/topologic_set.go index 65be96a..9dbbec3 100644 --- a/diagram/topologic_set.go +++ b/diagram/topologic_set.go @@ -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 }