修改节点分配方式

This commit is contained in:
2025-09-10 18:26:59 +08:00
parent 7e7d706f84
commit 1900f5e82d
13 changed files with 191 additions and 239 deletions

View File

@@ -37,16 +37,18 @@ func FindCitiesWithEdgesCount(tx *gorm.DB) ([]model.City, error) {
return cities, nil
}
func UpdateCityOffset(tx *gorm.DB, city int, offset int) error {
if offset < 0 {
return fmt.Errorf("offset must be non-negative")
func UpdateCitiesOffset(tx *gorm.DB, updates []model.City) error {
if len(updates) == 0 {
return nil
}
err := tx.Model(&model.City{}).
Where("id = ?", city).
Update("offset", offset).Error
if err != nil {
return fmt.Errorf("failed to update cities offset: %w", err)
for _, city := range updates {
err := tx.Model(new(model.City)).
Where("id = ?", city.Id).
Update("offset", city.Offset).Error
if err != nil {
return fmt.Errorf("failed to update city id %d offset: %w", city.Id, err)
}
}
return nil