add demo test sql and fix bug of modelRT running

This commit is contained in:
douxu 2025-01-06 17:00:58 +08:00
parent 2b4ad06b71
commit ac5d508171
7 changed files with 168 additions and 8 deletions

View File

@ -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
}

View File

@ -1,7 +1,7 @@
postgres:
host: "192.168.2.156"
port: 5432
database: "circuit_diagram"
database: "demo"
user: "postgres"
password: "coslight"

View File

@ -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))

View File

@ -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)

View File

@ -25,5 +25,5 @@ type Component struct {
// TableName func respresent return table name of Component
func (c *Component) TableName() string {
return "Component"
return "component"
}

View File

@ -18,5 +18,5 @@ type Page struct {
// TableName func respresent return table name of Page
func (p *Page) TableName() string {
return "Page"
return "page"
}

161
sql/demo/demo.sql Normal file
View File

@ -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'
);