Skip to content

Commit

Permalink
Optimize performance
Browse files Browse the repository at this point in the history
  • Loading branch information
guanguans committed Apr 29, 2022
1 parent 496f77b commit 7ff3edb
Showing 1 changed file with 37 additions and 38 deletions.
75 changes: 37 additions & 38 deletions data/address_code_timeline.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,58 +5,57 @@
package data

import (
"github.com/spf13/cast"
"math"
)

// AddressCodeTimeline 行政区划代码(地址码)更新时间线
// 中华人民共和国民政部权威数据
// 注1:台湾省、香港特别行政区和澳门特别行政区暂缺地市和区县信息
// 注2:每月发布的区划变更表是根据区划变更地的统计人员在统计信息系统更新后的情况所绘制,与区划变更文件发布的时间有一定的延迟性,但在每年的最后一次发布变更情况后与区划全年变更文件保持一致。
// Data Source: http://www.mca.gov.cn/article/sj/xzqh/

var provinceAddressCodeTimelinePluck = map[string]func() map[int][]map[string]string{
"11": getAddressCodeTimelineBeiJing,
"12": getAddressCodeTimelineTianJin,
"13": getAddressCodeTimelineHeBei,
"14": getAddressCodeTimelineShanXi14,
"15": getAddressCodeTimelineNeiMengGu,
"21": getAddressCodeTimelineLiaoNing,
"22": getAddressCodeTimelineJiLin,
"23": getAddressCodeTimelineHeiLongJiang,
"31": getAddressCodeTimelineShangHai,
"32": getAddressCodeTimelineJiangSu,
"33": getAddressCodeTimelineZheJiang,
"34": getAddressCodeTimelineAnHui,
"35": getAddressCodeTimelineFuJian,
"36": getAddressCodeTimelineJiangXi,
"37": getAddressCodeTimelineShanDong,
"41": getAddressCodeTimelineHeNan,
"42": getAddressCodeTimelineHuBei,
"43": getAddressCodeTimelineHuNan,
"44": getAddressCodeTimelineGuangDong,
"45": getAddressCodeTimelineGuangXi,
"46": getAddressCodeTimelineHaiNan,
"50": getAddressCodeTimelineChongQing,
"51": getAddressCodeTimelineSiChuan,
"52": getAddressCodeTimelineGuiZhou,
"53": getAddressCodeTimelineYunNan,
"54": getAddressCodeTimelineXiZang,
"61": getAddressCodeTimelineShanXi61,
"62": getAddressCodeTimelineGanSu,
"63": getAddressCodeTimelineQingHai,
"64": getAddressCodeTimelineNingXia,
"65": getAddressCodeTimelineXinJiang,
"81": getAddressCodeTimelineXiangGang,
"82": getAddressCodeTimelineAoMen,
"83": getAddressCodeTimelineTaiWan,
var provinceAddressCodeTimelinePluck = map[int8]func() map[int][]map[string]string{
11: getAddressCodeTimelineBeiJing,
12: getAddressCodeTimelineTianJin,
13: getAddressCodeTimelineHeBei,
14: getAddressCodeTimelineShanXi14,
15: getAddressCodeTimelineNeiMengGu,
21: getAddressCodeTimelineLiaoNing,
22: getAddressCodeTimelineJiLin,
23: getAddressCodeTimelineHeiLongJiang,
31: getAddressCodeTimelineShangHai,
32: getAddressCodeTimelineJiangSu,
33: getAddressCodeTimelineZheJiang,
34: getAddressCodeTimelineAnHui,
35: getAddressCodeTimelineFuJian,
36: getAddressCodeTimelineJiangXi,
37: getAddressCodeTimelineShanDong,
41: getAddressCodeTimelineHeNan,
42: getAddressCodeTimelineHuBei,
43: getAddressCodeTimelineHuNan,
44: getAddressCodeTimelineGuangDong,
45: getAddressCodeTimelineGuangXi,
46: getAddressCodeTimelineHaiNan,
50: getAddressCodeTimelineChongQing,
51: getAddressCodeTimelineSiChuan,
52: getAddressCodeTimelineGuiZhou,
53: getAddressCodeTimelineYunNan,
54: getAddressCodeTimelineXiZang,
61: getAddressCodeTimelineShanXi61,
62: getAddressCodeTimelineGanSu,
63: getAddressCodeTimelineQingHai,
64: getAddressCodeTimelineNingXia,
65: getAddressCodeTimelineXinJiang,
81: getAddressCodeTimelineXiangGang,
82: getAddressCodeTimelineAoMen,
83: getAddressCodeTimelineTaiWan,
}

func GetAddressCodeTimeline(code int) ([]map[string]string, bool) {
if code < 110000 || code > 830000 {
return []map[string]string{}, false
}

f, ok := provinceAddressCodeTimelinePluck[cast.ToString(code)[:2]]
f, ok := provinceAddressCodeTimelinePluck[int8(math.Floor(float64(code)/10000))]
if !ok {
timeline, ok := getAddressCodeTimelineAdditional()[code]
return timeline, ok
Expand Down

0 comments on commit 7ff3edb

Please sign in to comment.