建立仓库

This commit is contained in:
2025-08-05 10:51:35 +08:00
commit 4bbc05fe1f
36 changed files with 1946 additions and 0 deletions

43
actions/cities.go Normal file
View File

@@ -0,0 +1,43 @@
package actions
import (
"fmt"
"gorm.io/gorm"
"zzman/model"
)
func FindCities(tx *gorm.DB) ([]model.City, error) {
var cities []model.City
if err := tx.Find(&cities, "label is not null").Error; err != nil {
return nil, fmt.Errorf("failed to find cities: %w", err)
}
return cities, nil
}
func FindCitiesWithEdgesCount(tx *gorm.DB) ([]model.City, error) {
var cities []model.City
err := tx.Debug().
Select("cities.*, COUNT(edges.id) AS edges_count").
Joins("LEFT JOIN edges ON edges.city_id = cities.id").
Group("cities.id").
Find(&cities).Error
if err != nil {
return nil, fmt.Errorf("failed to find cities with edges count: %w", err)
}
return cities, nil
}
func AppendCityOffset(tx *gorm.DB, city int, offset int) error {
if offset < 0 {
return fmt.Errorf("offset must be non-negative")
}
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)
}
return nil
}