fix: 'province' & AreaInfo add parent
This commit is contained in:
@@ -17,7 +17,7 @@ import (
|
|||||||
// @Param sort path string false "data sorted by" Enums(today, total, now, default)
|
// @Param sort path string false "data sorted by" Enums(today, total, now, default)
|
||||||
func ProvinceDataHandler(c *gin.Context) {
|
func ProvinceDataHandler(c *gin.Context) {
|
||||||
sort := c.Param("sort")
|
sort := c.Param("sort")
|
||||||
data := service.GetAllProvienceData(sort)
|
data := service.GetAllProvinceData(sort)
|
||||||
utils.Succ(c, data)
|
utils.Succ(c, data)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package models
|
|||||||
|
|
||||||
type AreaInfo struct {
|
type AreaInfo struct {
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
|
Parent string `json:"parent"`
|
||||||
Today AreaToday `json:"today"`
|
Today AreaToday `json:"today"`
|
||||||
Total AreaTotal `json:"total"`
|
Total AreaTotal `json:"total"`
|
||||||
Children []AreaInfo `json:"children"`
|
Children []AreaInfo `json:"children"`
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ import (
|
|||||||
func statisticRouter(router *gin.RouterGroup) {
|
func statisticRouter(router *gin.RouterGroup) {
|
||||||
statisticsRouter := router.Group("/statistics")
|
statisticsRouter := router.Group("/statistics")
|
||||||
{
|
{
|
||||||
statisticsRouter.GET("/provience/:sort", handler.ProvinceDataHandler)
|
statisticsRouter.GET("/province/:sort", handler.ProvinceDataHandler)
|
||||||
statisticsRouter.GET("/city/:sort", handler.CityDataHandler)
|
statisticsRouter.GET("/city/:sort", handler.CityDataHandler)
|
||||||
statisticsRouter.GET("/country/child", handler.CountryDataHandler)
|
statisticsRouter.GET("/country/child", handler.CountryDataHandler)
|
||||||
statisticsRouter.GET("/country", handler.CountryDataHandler)
|
statisticsRouter.GET("/country", handler.CountryDataHandler)
|
||||||
|
|||||||
@@ -17,10 +17,10 @@ const (
|
|||||||
rds_CHINA_ADD_KEY = "chinaAdd"
|
rds_CHINA_ADD_KEY = "chinaAdd"
|
||||||
rds_COUNTRY_LEVEL_KEY = "countryLevel"
|
rds_COUNTRY_LEVEL_KEY = "countryLevel"
|
||||||
rds_COUNTRY_LEVEL_CHILD_KEY = "countryLevelChild"
|
rds_COUNTRY_LEVEL_CHILD_KEY = "countryLevelChild"
|
||||||
rds_PROVIENCE_LEVEL_CHILD_KEY = "provienceLevelChild"
|
rds_PROVINCE_LEVEL_CHILD_KEY = "provinceLevelChild"
|
||||||
rds_PROVIENCE_LEVEL_NOW_CONFIRM_KEY = "provienceLevelNowConfirm"
|
rds_PROVINCE_LEVEL_NOW_CONFIRM_KEY = "provinceLevelNowConfirm"
|
||||||
rds_PROVIENCE_LEVEL_TODAY_CONFIRM_KEY = "provienceLevelTodayConfirm"
|
rds_PROVINCE_LEVEL_TODAY_CONFIRM_KEY = "provinceLevelTodayConfirm"
|
||||||
rds_PROVIENCE_LEVEL_TOTAL_CONFIRM_KEY = "provienceLevelTotalConfirm"
|
rds_PROVINCE_LEVEL_TOTAL_CONFIRM_KEY = "provinceLevelTotalConfirm"
|
||||||
rds_CITY_LEVEL_CHILD_KEY = "cityLevelChild"
|
rds_CITY_LEVEL_CHILD_KEY = "cityLevelChild"
|
||||||
rds_CITY_LEVEL_NOW_CONFIRM_KEY = "cityLevelNowConfirm"
|
rds_CITY_LEVEL_NOW_CONFIRM_KEY = "cityLevelNowConfirm"
|
||||||
rds_CITY_LEVEL_TODAY_CONFIRM_KEY = "cityLevelTodayConfirm"
|
rds_CITY_LEVEL_TODAY_CONFIRM_KEY = "cityLevelTodayConfirm"
|
||||||
@@ -80,8 +80,8 @@ func cacheLevelInfo(data map[string]interface{}) {
|
|||||||
// Get Every Level's Info
|
// Get Every Level's Info
|
||||||
var countryLevels []models.AreaInfo
|
var countryLevels []models.AreaInfo
|
||||||
json.Unmarshal(areaTree, &countryLevels)
|
json.Unmarshal(areaTree, &countryLevels)
|
||||||
provienceLevels := children(countryLevels)
|
provinceLevels := children(countryLevels)
|
||||||
cityLevels := children(provienceLevels)
|
cityLevels := children(provinceLevels)
|
||||||
|
|
||||||
// Country Level Area Info With Child
|
// Country Level Area Info With Child
|
||||||
cacheList(rds_COUNTRY_LEVEL_CHILD_KEY, areaInfoToJson(countryLevels)...)
|
cacheList(rds_COUNTRY_LEVEL_CHILD_KEY, areaInfoToJson(countryLevels)...)
|
||||||
@@ -89,34 +89,34 @@ func cacheLevelInfo(data map[string]interface{}) {
|
|||||||
areaInfoChildNil(&countryLevels)
|
areaInfoChildNil(&countryLevels)
|
||||||
cacheList(rds_COUNTRY_LEVEL_KEY, areaInfoToJson(countryLevels)...)
|
cacheList(rds_COUNTRY_LEVEL_KEY, areaInfoToJson(countryLevels)...)
|
||||||
|
|
||||||
// Provience Level Area Info With Child
|
// Province Level Area Info With Child
|
||||||
cacheList(rds_PROVIENCE_LEVEL_CHILD_KEY, areaInfoToJson(provienceLevels)...)
|
cacheList(rds_PROVINCE_LEVEL_CHILD_KEY, areaInfoToJson(provinceLevels)...)
|
||||||
areaInfoChildNil(&provienceLevels)
|
areaInfoChildNil(&provinceLevels)
|
||||||
// City Level Area Info With Child
|
// City Level Area Info With Child
|
||||||
cacheList(rds_CITY_LEVEL_CHILD_KEY, areaInfoToJson(cityLevels)...)
|
cacheList(rds_CITY_LEVEL_CHILD_KEY, areaInfoToJson(cityLevels)...)
|
||||||
areaInfoChildNil(&provienceLevels)
|
areaInfoChildNil(&provinceLevels)
|
||||||
|
|
||||||
// Provience Level Area Info Sorted by Now Confirm
|
// Province Level Area Info Sorted by Now Confirm
|
||||||
provienceLevelsSlice := AreaSlice(provienceLevels)
|
provinceLevelsSlice := AreaSlice(provinceLevels)
|
||||||
sort.Sort(provienceLevelsSlice)
|
sort.Sort(provinceLevelsSlice)
|
||||||
cacheList(rds_PROVIENCE_LEVEL_NOW_CONFIRM_KEY, areaInfoToJson(provienceLevelsSlice)...)
|
cacheList(rds_PROVINCE_LEVEL_NOW_CONFIRM_KEY, areaInfoToJson(provinceLevelsSlice)...)
|
||||||
// City Level Area Info Sorted By Now Confirm
|
// City Level Area Info Sorted By Now Confirm
|
||||||
cityLevelsSlice := AreaSlice(cityLevels)
|
cityLevelsSlice := AreaSlice(cityLevels)
|
||||||
sort.Sort(cityLevelsSlice)
|
sort.Sort(cityLevelsSlice)
|
||||||
cacheList(rds_CITY_LEVEL_NOW_CONFIRM_KEY, areaInfoToJson(cityLevelsSlice)...)
|
cacheList(rds_CITY_LEVEL_NOW_CONFIRM_KEY, areaInfoToJson(cityLevelsSlice)...)
|
||||||
|
|
||||||
sortBy = SORT_TODAY_CONFIRM
|
sortBy = SORT_TODAY_CONFIRM
|
||||||
// Provience Level Area Info Sorted by Today Confirm
|
// Province Level Area Info Sorted by Today Confirm
|
||||||
sort.Sort(provienceLevelsSlice)
|
sort.Sort(provinceLevelsSlice)
|
||||||
cacheList(rds_PROVIENCE_LEVEL_TODAY_CONFIRM_KEY, areaInfoToJson(provienceLevelsSlice)...)
|
cacheList(rds_PROVINCE_LEVEL_TODAY_CONFIRM_KEY, areaInfoToJson(provinceLevelsSlice)...)
|
||||||
// City Level Area Info Sorted by Today Confirm
|
// City Level Area Info Sorted by Today Confirm
|
||||||
sort.Sort(cityLevelsSlice)
|
sort.Sort(cityLevelsSlice)
|
||||||
cacheList(rds_CITY_LEVEL_TODAY_CONFIRM_KEY, areaInfoToJson(cityLevelsSlice)...)
|
cacheList(rds_CITY_LEVEL_TODAY_CONFIRM_KEY, areaInfoToJson(cityLevelsSlice)...)
|
||||||
|
|
||||||
sortBy = SORT_TOTAL_CONFIRM
|
sortBy = SORT_TOTAL_CONFIRM
|
||||||
// Provience Level Area Info Sorted by Total Confirm
|
// Province Level Area Info Sorted by Total Confirm
|
||||||
sort.Sort(provienceLevelsSlice)
|
sort.Sort(provinceLevelsSlice)
|
||||||
cacheList(rds_PROVIENCE_LEVEL_TOTAL_CONFIRM_KEY, areaInfoToJson(provienceLevelsSlice)...)
|
cacheList(rds_PROVINCE_LEVEL_TOTAL_CONFIRM_KEY, areaInfoToJson(provinceLevelsSlice)...)
|
||||||
// City Level Area Info Sorted by Total Confirm
|
// City Level Area Info Sorted by Total Confirm
|
||||||
sort.Sort(cityLevelsSlice)
|
sort.Sort(cityLevelsSlice)
|
||||||
cacheList(rds_CITY_LEVEL_TOTAL_CONFIRM_KEY, areaInfoToJson(cityLevelsSlice)...)
|
cacheList(rds_CITY_LEVEL_TOTAL_CONFIRM_KEY, areaInfoToJson(cityLevelsSlice)...)
|
||||||
@@ -136,6 +136,7 @@ func children(parents []models.AreaInfo) []models.AreaInfo {
|
|||||||
}
|
}
|
||||||
for _, item := range parent.Children {
|
for _, item := range parent.Children {
|
||||||
name := item.Name
|
name := item.Name
|
||||||
|
item.Parent = parent.Name
|
||||||
if !strings.Contains(name, json_FOREIGN_CITY) && !strings.Contains(name, json_FOREIGN_COUNTRY) && !strings.Contains(name, json_TO_BE_CONFIRM) {
|
if !strings.Contains(name, json_FOREIGN_CITY) && !strings.Contains(name, json_FOREIGN_COUNTRY) && !strings.Contains(name, json_TO_BE_CONFIRM) {
|
||||||
areaInfos = append(areaInfos, item)
|
areaInfos = append(areaInfos, item)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,18 +7,18 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
func GetAllProvienceData(sort string) []interface{} {
|
func GetAllProvinceData(sort string) []interface{} {
|
||||||
checkCache()
|
checkCache()
|
||||||
if sort == SORT_TODAY_CONFIRM {
|
if sort == SORT_TODAY_CONFIRM {
|
||||||
return getEntireRedisList(rds_PROVIENCE_LEVEL_TODAY_CONFIRM_KEY)
|
return getEntireRedisList(rds_PROVINCE_LEVEL_TODAY_CONFIRM_KEY)
|
||||||
}
|
}
|
||||||
if sort == SORT_TOTAL_CONFIRM {
|
if sort == SORT_TOTAL_CONFIRM {
|
||||||
return getEntireRedisList(rds_PROVIENCE_LEVEL_TOTAL_CONFIRM_KEY)
|
return getEntireRedisList(rds_PROVINCE_LEVEL_TOTAL_CONFIRM_KEY)
|
||||||
}
|
}
|
||||||
if sort == SORT_NOW_CONFIRM {
|
if sort == SORT_NOW_CONFIRM {
|
||||||
return getEntireRedisList(rds_PROVIENCE_LEVEL_NOW_CONFIRM_KEY)
|
return getEntireRedisList(rds_PROVINCE_LEVEL_NOW_CONFIRM_KEY)
|
||||||
}
|
}
|
||||||
return getEntireRedisList(rds_PROVIENCE_LEVEL_CHILD_KEY)
|
return getEntireRedisList(rds_PROVINCE_LEVEL_CHILD_KEY)
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetAllCityData(sort string) []interface{} {
|
func GetAllCityData(sort string) []interface{} {
|
||||||
|
|||||||
Reference in New Issue
Block a user