district

package module
v0.0.7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 8, 2024 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Overview

Package district Wrote by yijian on 2024/03/09

Package district Wrote by yijian on 2024/03/09

Package district Wrote by yijian on 2024/03/09

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CacheMetricFPrintf

func CacheMetricFPrintf(w io.Writer)

func GenerateCsv

func GenerateCsv(districtTable *Table, csvFilepath, csvDelimiter string, withCode bool) error

func GenerateJson

func GenerateJson(districtTable *Table, jsonFilepath string, withIndent bool, indent, prefix string) error

func GenerateSql

func GenerateSql(districtTable *Table, sqlFilepath, tableName string) error

func IsCityDistrictCode added in v0.0.6

func IsCityDistrictCode(code uint32) bool

func IsCountyDistrictCode added in v0.0.6

func IsCountyDistrictCode(code uint32) bool

func IsHongKongMacauTaiwan added in v0.0.6

func IsHongKongMacauTaiwan(name string) bool

IsHongKongMacauTaiwan 判断是否为香港/澳门/台湾

func IsMunicipalityCode added in v0.0.6

func IsMunicipalityCode(code uint32) bool

IsMunicipalityCode 是否为直辖市

func IsProvinceDistrictCode added in v0.0.6

func IsProvinceDistrictCode(code uint32) bool

func Md5Sum

func Md5Sum(data string) string

func PerfectNameOfProvincialAdminRegion

func PerfectNameOfProvincialAdminRegion(name string) string

PerfectNameOfProvincialAdminRegion 完美省级行政区名 name 省级行政区全名或者简名(非简称) 数据参考:https://www.gov.cn/test/2006-04/04/content_244716.htm

Types

type CacheMetric

type CacheMetric struct {
	EntryCount        int64   `json:"entry_count"`
	ExpiredCount      int64   `json:"expired_count"`
	EvacuateCount     int64   `json:"evacuate_count"`
	LookupCount       int64   `json:"lookup_count"`
	AverageAccessTime int64   `json:"average_access_time"`
	HitCount          int64   `json:"hit_count"`
	MissCount         int64   `json:"miss_count"`
	OverwriteCount    int64   `json:"overwrite_count"`
	TouchedCount      int64   `json:"touched_count"`
	HitRate           float64 `json:"hit_rate"`
}

CacheMetric 缓存的度量数据

func GetCacheMetric

func GetCacheMetric() *CacheMetric

func (*CacheMetric) String

func (c *CacheMetric) String() (string, error)

type CityDistrict

type CityDistrict struct {
	Code                uint32              `json:"code"`
	Name                string              `json:"name"`        // 行政区名称
	Level               uint32              `json:"level"`       // 行政区级别(1 省/自治区/直辖市,2 市/州/盟,3 县/县级市/旗)
	CountyCity          bool                `json:"county_city"` // 县级市
	CountyDistrictTable map[uint32]District `json:"-"`
	Counties            []District          `json:"counties,omitempty"`
}

CityDistrict 市/州/盟

type Code

type Code struct {
	ProvinceCode uint32 `gorm:"column:f_province_code" json:"province_code,omitempty"`
	CityCode     uint32 `gorm:"column:f_city_code" json:"city_code,omitempty"`
	CountyCode   uint32 `gorm:"column:f_county_code" json:"county_code,omitempty"`
}

func (*Code) Md5Sum

func (d *Code) Md5Sum() string

type District

type District struct {
	Code        uint32 `json:"code"`        // 行政区代码
	Name        string `json:"name"`        // 行政区名称
	Level       uint32 `json:"level"`       // 行政区级别(1 省/自治区/直辖市,2 市/州/盟,3 县/县级市/旗)
	Parent      uint32 `json:"parent"`      // 父行政区代码
	Grandparent uint32 `json:"grandparent"` // 父父行政区代码
}

type Name

type Name struct {
	ProvinceName string `gorm:"column:f_province_name" json:"province_name,omitempty"`
	CityName     string `gorm:"column:f_city_name" json:"city_name,omitempty"`
	CountyName   string `gorm:"column:f_county_name" json:"county_name,omitempty"`
}

Name 行政区名(字符集需同 DB 等保持一致)

func (*Name) Md5Sum

func (d *Name) Md5Sum() string

type ProvinceDistrict

type ProvinceDistrict struct {
	Code              uint32                  `json:"code"`
	Name              string                  `json:"name"`         // 行政区名称
	Level             uint32                  `json:"level"`        // 行政区级别(1 省/自治区/直辖市,2 市/州/盟,3 县/县级市/旗)
	Municipality      bool                    `json:"municipality"` // 直辖市
	CityDistrictTable map[uint32]CityDistrict `json:"-"`
	Cities            []CityDistrict          `json:"cities,omitempty"`
}

ProvinceDistrict 省/自治区/直辖市

type Query

type Query struct {
	Db            *gorm.DB
	TableName     string
	ExpireSeconds int
}

Query 行政区查询器

func NewQuery

func NewQuery(db *gorm.DB, tableName string, expireSeconds int) *Query

func (*Query) GetCountyCount added in v0.0.7

func (q *Query) GetCountyCount(ctx context.Context, provinceName, cityName string) (int, error)

GetCountyCount 取得县/县级市/旗数,像东莞市没有

func (*Query) GetDistrictCode

func (q *Query) GetDistrictCode(ctx context.Context, name *Name) (*Code, error)

GetDistrictCode 通过行政区名取得行政区代码 返回值: 1)成功返回非 nil 的 DistrictCode,同时 error 值为 nil ; 2)不存在返回 nil 的 DistrictCode,同时 error 值为 nil ; 3)出错返回 nil 的 DistrictCode,同时 error 值不为 nil 。

func (*Query) GetDistrictName

func (q *Query) GetDistrictName(ctx context.Context, code *Code) (*Name, error)

GetDistrictName 通过行政区代码取得行政区名 返回值: 1)成功返回非 nil 的 DistrictName,同时 error 值为 nil ; 2)不存在返回 nil 的 DistrictName,同时 error 值为 nil ; 3)出错返回 nil 的 DistrictName,同时 error 值不为 nil 。

type Table

type Table struct {
	ProvinceDistrictTable map[uint32]ProvinceDistrict `json:"-"`
	Provinces             []ProvinceDistrict          `json:"provinces,omitempty"`
}

func LoadDistrict

func LoadDistrict(ctx context.Context, filepath string) (*Table, error)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL