fix: db. SetMaxOpenConns, gb28181 device do not update Longitude, Latitude when the two param is 0

This commit is contained in:
pggiroro
2025-09-22 22:45:30 +08:00
parent 4e6abef720
commit ae698c7b5a
3 changed files with 19 additions and 5 deletions

View File

@@ -133,6 +133,8 @@ func (gb *GB28181Plugin) List(ctx context.Context, req *pb.GetDevicesRequest) (*
Port: int32(d.Port),
BroadcastPushAfterAck: d.BroadcastPushAfterAck,
SubscribeCatalog: util.Conditional(d.SubscribeCatalog == 0, false, true),
SubscribePosition: util.Conditional(d.SubscribePosition == 0, false, true),
SubscribeAlarm: util.Conditional(d.SubscribeAlarm == 0, false, true),
})
}
@@ -564,7 +566,7 @@ func (gb *GB28181Plugin) UpdateDevice(ctx context.Context, req *pb.Device) (*pb.
d.PositionSubscribeTask.Tick(nil)
} else {
if d.PositionSubscribeTask != nil {
d.CatalogSubscribeTask.Tick(nil)
d.PositionSubscribeTask.Tick(nil)
d.PositionSubscribeTask.Ticker.Reset(time.Hour * 999999)
}
}

View File

@@ -364,8 +364,12 @@ func (d *Device) onMessage(req *sip.Request, tx sip.ServerTransaction, msg *gb28
d.Model = msg.Model
d.Firmware = msg.Firmware
d.UpdateTime = time.Now()
d.Latitude = msg.Latitude
d.Longitude = msg.Longitude
if msg.Latitude != "" {
d.Latitude = msg.Latitude
}
if msg.Longitude != "" {
d.Longitude = msg.Longitude
}
case "Alarm":
// 创建报警记录
alarm := &gb28181.DeviceAlarm{
@@ -766,8 +770,12 @@ func (d *Device) onNotify(req *sip.Request, tx sip.ServerTransaction, msg *gb281
gpsTime = gpsTime.UTC()
// 更新设备的经纬度信息
d.Longitude = fmt.Sprintf("%.6f", posNotify.Longitude)
d.Latitude = fmt.Sprintf("%.6f", posNotify.Latitude)
if posNotify.Longitude != 0 {
d.Longitude = fmt.Sprintf("%.6f", posNotify.Longitude)
}
if posNotify.Latitude != 0 {
d.Latitude = fmt.Sprintf("%.6f", posNotify.Latitude)
}
d.UpdateTime = time.Now()
// 如果需要,可以将更新保存到数据库

View File

@@ -299,6 +299,10 @@ func (s *Server) Start() (err error) {
s.Error("failed to connect database", "error", err, "dsn", s.config.DSN, "type", s.config.DBType)
return
}
sqlDB, _ := s.DB.DB()
sqlDB.SetMaxIdleConns(25)
sqlDB.SetMaxOpenConns(100)
sqlDB.SetConnMaxLifetime(5 * time.Minute)
// Auto-migrate models
if err = s.DB.AutoMigrate(&db.User{}, &PullProxyConfig{}, &PushProxyConfig{}, &StreamAliasDB{}, &AlarmInfo{}); err != nil {
s.Error("failed to auto-migrate models", "error", err)