feat(region):增加获取全部级别行政区划的功能。

This commit is contained in:
徐涛
2022-08-14 16:14:25 +08:00
parent f4f8b97ad3
commit 6e9779bd93
3 changed files with 58 additions and 0 deletions

24
repository/region.go Normal file
View File

@@ -0,0 +1,24 @@
package repository
import (
"electricity_bill_calc/cache"
"electricity_bill_calc/global"
"electricity_bill_calc/model"
)
type _RegionRepository struct{}
var RegionRepository _RegionRepository
func (_RegionRepository) FetchRegion(code string) (*model.Region, error) {
cachedRegion, _ := cache.RetreiveData[model.Region]("region", code)
if cachedRegion != nil {
return cachedRegion, nil
}
region := new(model.Region)
has, err := global.DBConn.ID(code).NoAutoCondition().Get(region)
if has {
cache.CacheData(region, "region", code)
}
return _postProcessSingle(region, has, err)
}