88
99using System . Collections . Concurrent ;
1010using System . Runtime . CompilerServices ;
11+ using System . Text . Json ;
1112
1213namespace BootstrapBlazor . Components ;
1314
1415class DefaultRegionService : IRegionService
1516{
1617 private static readonly ConcurrentDictionary < string , IReadOnlySet < string > > _citiesCache = new ( ) ;
1718 private static readonly ConcurrentDictionary < string , IReadOnlySet < CountyItem > > _countiesCache = new ( ) ;
19+ private static readonly ConcurrentDictionary < string , IReadOnlySet < string > > _detailCache = new ( ) ;
1820
1921 private static bool _initialized = false ;
2022
@@ -38,9 +40,36 @@ public IReadOnlySet<CountyItem> GetCounties(string city)
3840 return _countiesCache . TryGetValue ( city , out var counties ) ? counties : new HashSet < CountyItem > ( ) ;
3941 }
4042
41- public List < string > GetDetails ( string county )
43+ public IReadOnlySet < string > GetDetails ( string countyCode )
4244 {
43- throw new NotImplementedException ( ) ;
45+ LoadDetailData ( countyCode ) ;
46+ return _detailCache . TryGetValue ( countyCode , out var details ) ? details : new HashSet < string > ( ) ;
47+ }
48+
49+ private static IReadOnlySet < string > LoadDetailData ( string countyCode )
50+ {
51+ if ( _detailCache . TryGetValue ( countyCode , out var detail ) )
52+ {
53+ return detail ;
54+ }
55+
56+ var details = new HashSet < string > ( ) ;
57+ var data = typeof ( DefaultRegionService ) . Assembly . GetManifestResourceStream ( $ "BootstrapBlazor.Components.Data.town.{ countyCode } .json") ;
58+ if ( data != null )
59+ {
60+ var document = JsonDocument . Parse ( data ) ;
61+ var token = document . RootElement . EnumerateObject ( ) ;
62+ foreach ( var t in token )
63+ {
64+ var v = t . Value . GetString ( ) ;
65+ if ( ! string . IsNullOrEmpty ( v ) )
66+ {
67+ details . Add ( v ) ;
68+ }
69+ }
70+ }
71+ _detailCache . TryAdd ( countyCode , details ) ;
72+ return details ;
4473 }
4574
4675 private static void LoadCityData ( )
0 commit comments