feat: import services and standardize Go 1.26.5
This commit is contained in:
39
apps/base/initial/internal/logic/data/areas_cache.go
Normal file
39
apps/base/initial/internal/logic/data/areas_cache.go
Normal file
@@ -0,0 +1,39 @@
|
||||
package data
|
||||
|
||||
import (
|
||||
"git.apinb.com/bsm-apps/initial/internal/impl"
|
||||
"git.apinb.com/bsm-apps/initial/internal/models"
|
||||
pb "git.apinb.com/bsm-apps/initial/pb"
|
||||
"git.apinb.com/bsm-sdk/core/vars"
|
||||
)
|
||||
|
||||
func GetAreasByCache(in *pb.AreasRequest) ([]*models.InitialAreas, error) {
|
||||
var areas []*models.InitialAreas
|
||||
|
||||
var (
|
||||
key string
|
||||
val any
|
||||
)
|
||||
|
||||
if in.GetCountryCode() != "" {
|
||||
key = "country_code = ?"
|
||||
val = in.GetCountryCode()
|
||||
} else if in.GetCountryId() != 0 {
|
||||
key = "country_id = ?"
|
||||
val = in.GetCountryId()
|
||||
}
|
||||
|
||||
cacheKey := impl.RedisService.BuildKey("areas", key, val, in.ShowTown)
|
||||
|
||||
err := impl.RedisService.Get(cacheKey, &areas)
|
||||
if err == nil {
|
||||
return areas, nil
|
||||
}
|
||||
|
||||
err = impl.DBService.Where("enabled = ?", true).Where(key, val).Where("show_town = ?", in.ShowTown).
|
||||
Order("sort_order ASC, name ASC").
|
||||
Find(&areas).Error
|
||||
|
||||
err = impl.RedisService.Set(cacheKey, areas, vars.DefaultTTL)
|
||||
return areas, err
|
||||
}
|
||||
Reference in New Issue
Block a user