From ac5d5081710abd09350ec2efb33afe43a2df6b54 Mon Sep 17 00:00:00 2001 From: douxu Date: Mon, 6 Jan 2025 17:00:58 +0800 Subject: [PATCH] add demo test sql and fix bug of modelRT running --- config/config.go | 5 +- config/config.yaml | 2 +- database/query_page.go | 2 +- main.go | 2 +- orm/circuit_diagram_component.go | 2 +- orm/circuit_diagram_page.go | 2 +- sql/demo/demo.sql | 161 +++++++++++++++++++++++++++++++ 7 files changed, 168 insertions(+), 8 deletions(-) create mode 100644 sql/demo/demo.sql diff --git a/config/config.go b/config/config.go index 7fcf590..4e36ae5 100644 --- a/config/config.go +++ b/config/config.go @@ -81,12 +81,11 @@ func ReadAndInitConfig(configDir, configName, configType string) (modelRTConfig panic(err) } - modelRTconf := ModelRTConfig{} if err := config.Unmarshal(&modelRTConfig); err != nil { panic(fmt.Sprintf("unmarshal modelRT config failed:%s\n", err.Error())) } - modelRTConfig.PostgresDBURI = fmt.Sprintf("host=%s port=%d user=%s password=%s dbname=%s", modelRTconf.PostgresConfig.Host, modelRTconf.PostgresConfig.Port, modelRTconf.PostgresConfig.User, modelRTconf.PostgresConfig.Password, modelRTconf.PostgresConfig.DataBase) - + // init postgres db uri + modelRTConfig.PostgresDBURI = fmt.Sprintf("host=%s port=%d user=%s password=%s dbname=%s", modelRTConfig.PostgresConfig.Host, modelRTConfig.PostgresConfig.Port, modelRTConfig.PostgresConfig.User, modelRTConfig.PostgresConfig.Password, modelRTConfig.PostgresConfig.DataBase) return modelRTConfig } diff --git a/config/config.yaml b/config/config.yaml index 7f77f0d..e01a5ba 100644 --- a/config/config.yaml +++ b/config/config.yaml @@ -1,7 +1,7 @@ postgres: host: "192.168.2.156" port: 5432 - database: "circuit_diagram" + database: "demo" user: "postgres" password: "coslight" diff --git a/database/query_page.go b/database/query_page.go index 43cc812..57e886b 100644 --- a/database/query_page.go +++ b/database/query_page.go @@ -18,7 +18,7 @@ func QueryAllPages(ctx context.Context, logger *zap.Logger, gridID, zoneID, stat cancelCtx, cancel := context.WithTimeout(ctx, 5*time.Second) defer cancel() - 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) + 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 { logger.Error("query circuit diagram pages by gridID and zoneID and stationID failed", zap.Int64("grid_id", gridID), zap.Int64("zone_id", zoneID), zap.Int64("station_id", stationID), zap.Error(result.Error)) diff --git a/main.go b/main.go index 5851833..5961298 100644 --- a/main.go +++ b/main.go @@ -100,7 +100,7 @@ func main() { // TODO 完成订阅数据分析 // TODO 暂时屏蔽完成 swagger 启动测试 - go realtimedata.RealTimeDataComputer(ctx, nil, []string{}, "") + // go realtimedata.RealTimeDataComputer(ctx, nil, []string{}, "") engine := gin.Default() engine.Use(limiter.Middleware) diff --git a/orm/circuit_diagram_component.go b/orm/circuit_diagram_component.go index 677f5c5..b626d00 100644 --- a/orm/circuit_diagram_component.go +++ b/orm/circuit_diagram_component.go @@ -25,5 +25,5 @@ type Component struct { // TableName func respresent return table name of Component func (c *Component) TableName() string { - return "Component" + return "component" } diff --git a/orm/circuit_diagram_page.go b/orm/circuit_diagram_page.go index d0b4a51..d99f05d 100644 --- a/orm/circuit_diagram_page.go +++ b/orm/circuit_diagram_page.go @@ -18,5 +18,5 @@ type Page struct { // TableName func respresent return table name of Page func (p *Page) TableName() string { - return "Page" + return "page" } diff --git a/sql/demo/demo.sql b/sql/demo/demo.sql new file mode 100644 index 0000000..9676ec6 --- /dev/null +++ b/sql/demo/demo.sql @@ -0,0 +1,161 @@ +insert into + public."component" ( + tag, + grid, + zone, + station, + page_id, + type, + name, + context, + op, + ts + ) +values + ( + 'Demo1', + 1, + 1, + 1, + 1, + 3, + 'demo1', + '{"left":"1.2","right":"13.5","buttom":"0.2","top":"5.4"}', + 1, + '2021-01-01 00:00:00' + ); + +insert into + public."bus_stability" ( + component_id, + resistance, + anchor_v, + uv_alarm, + ov_alarm, + anchor_i, + ui_alarm, + oi_alarm, + op, + ts + ) +values + ( + 1, + 100, + false, + 90, + 110, + true, + 90, + 110, + 1, + '2021-01-01 00:00:00' + ); + +insert into + public."component" ( + tag, + grid, + zone, + station, + page_id, + type, + name, + context, + op, + ts + ) +values + ( + 'Demo2', + 1, + 1, + 1, + 1, + 3, + 'demo2', + '{"left":"3.2","right":"3.5","buttom":"1.2","top":"7.4"}', + 1, + '2021-01-01 00:00:00' + ); + +insert into + public."bus_stability" ( + component_id, + resistance, + anchor_v, + uv_alarm, + ov_alarm, + anchor_i, + ui_alarm, + oi_alarm, + op, + ts + ) +values + ( + 2, + 100, + false, + 90, + 110, + true, + 90, + 110, + 1, + '2021-01-01 00:00:00' + ); + +insert into + public."component" ( + tag, + grid, + zone, + station, + page_id, + type, + name, + context, + op, + ts + ) +values + ( + 'Demo3', + 1, + 1, + 1, + 1, + 3, + 'demo3', + '{"left":"1.2","right":"1.5","buttom":"4.2","top":"9.5"}', + 1, + '2021-01-01 00:00:00' + ); + +insert into + public."bus_stability" ( + component_id, + resistance, + anchor_v, + uv_alarm, + ov_alarm, + anchor_i, + ui_alarm, + oi_alarm, + op, + ts + ) +values + ( + 3, + 100, + false, + 90, + 110, + true, + 90, + 110, + 1, + '2021-01-01 00:00:00' + ); \ No newline at end of file