|
@@ -15,6 +15,9 @@
|
|
#import "XSTTNetworkManager.h"
|
|
#import "XSTTNetworkManager.h"
|
|
#import "XSTTAppProfileModel.h"
|
|
#import "XSTTAppProfileModel.h"
|
|
#import "XSTTConstantProfile.h"
|
|
#import "XSTTConstantProfile.h"
|
|
|
|
+#import <JXHSystemShortcut.h>
|
|
|
|
+#import <objc/runtime.h>
|
|
|
|
+#import <JXHFMDBManager.h>
|
|
|
|
|
|
@implementation AppDelegate (XSTTHandleData)
|
|
@implementation AppDelegate (XSTTHandleData)
|
|
|
|
|
|
@@ -22,7 +25,7 @@
|
|
NSString *orginaPath;
|
|
NSString *orginaPath;
|
|
NSString *targetPath;
|
|
NSString *targetPath;
|
|
NSFileManager *fileManager = [NSFileManager defaultManager];;
|
|
NSFileManager *fileManager = [NSFileManager defaultManager];;
|
|
- NSArray *tableNameArray = @[@"t_xstt_location_cache_data"];
|
|
|
|
|
|
+ NSArray *tableNameArray = @[@"t_xstt_location_cache_data", @"t_xstt_city_data"];
|
|
for (NSInteger i = 0; i < tableNameArray.count; i ++) {
|
|
for (NSInteger i = 0; i < tableNameArray.count; i ++) {
|
|
orginaPath = [[NSBundle mainBundle] pathForResource:tableNameArray[i] ofType:@"db"];
|
|
orginaPath = [[NSBundle mainBundle] pathForResource:tableNameArray[i] ofType:@"db"];
|
|
targetPath = [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, true) objectAtIndex:0] stringByAppendingPathComponent:[NSString stringWithFormat:@"%@.db", tableNameArray[i]]];
|
|
targetPath = [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, true) objectAtIndex:0] stringByAppendingPathComponent:[NSString stringWithFormat:@"%@.db", tableNameArray[i]]];
|
|
@@ -59,9 +62,55 @@
|
|
} else if (update) {
|
|
} else if (update) {
|
|
|
|
|
|
}
|
|
}
|
|
|
|
+ if (![jxh_userDefaults() objectForKey:XSTTCityRefreshTime] || [[jxh_userDefaults() objectForKey:XSTTCityRefreshTime] integerValue] != model.xstt_districtVersion.integerValue) {
|
|
|
|
+ self.tempCityRefreshTime = model.xstt_districtVersion;
|
|
|
|
+ [self getCityList];
|
|
|
|
+
|
|
|
|
+ }
|
|
}];
|
|
}];
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+#pragma mark - 获取城市列表
|
|
|
|
+- (void)getCityList {
|
|
|
|
+ @weakify(self)
|
|
|
|
+ [xstt_globalNetworkManager() networkUseMethod:XSTTNetworkMethodGET isLogin:false signKey:XSTTNetworkSignKeyApp url:xstt_appUrl(XSTTUrlGetCity) urlParameters:nil parameters:nil completion:^(NSError * _Nonnull error, id _Nullable data) {
|
|
|
|
+ if (error.code == XSTTNetworkCallbackSuccessCode && [data[@"data"][@"provinceList"] isKindOfClass:[NSArray class]] && [data[@"data"][@"cityList"] isKindOfClass:[NSArray class]] && [data[@"data"][@"districtList"] isKindOfClass:[NSArray class]]) {
|
|
|
|
+ @strongify(self)
|
|
|
|
+ [self handleCityWithData:data[@"data"]];
|
|
|
|
+ }
|
|
|
|
+ }];
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+- (void)handleCityWithData:(NSDictionary *)data {
|
|
|
|
+ dispatch_async(dispatch_get_global_queue(0, 0), ^{
|
|
|
|
+ NSString *provinceStr = [self appendSqlStrWithArray:data[@"provinceList"] tableName:@"t_xstt_city_province"];
|
|
|
|
+ NSString *cityStr = [self appendSqlStrWithArray:data[@"cityList"] tableName:@"t_xstt_city_city"];
|
|
|
|
+ NSString *districtStr = [self appendSqlStrWithArray:data[@"districtList"] tableName:@"t_xstt_city_district"];
|
|
|
|
+ dispatch_async(dispatch_get_main_queue(), ^{
|
|
|
|
+ [JXHFMDBManager updateWithPath:XSTTCityCacheDataSQL condition:^id(FMDatabase *database) {
|
|
|
|
+ return @([database executeUpdate:@"delete from t_xstt_city_province"] && [database executeUpdate:@"delete from t_xstt_city_city"] && [database executeUpdate:@"delete from t_xstt_city_district"]);
|
|
|
|
+ }];
|
|
|
|
+ [JXHFMDBManager updateWithPath:XSTTCityCacheDataSQL condition:^id(FMDatabase *database) {
|
|
|
|
+ return @([database executeUpdate:provinceStr] && [database executeUpdate:cityStr] && [database executeUpdate:districtStr]);
|
|
|
|
+ }];
|
|
|
|
+ [jxh_userDefaults() setObject:self.tempCityRefreshTime forKey:XSTTCityRefreshTime];
|
|
|
|
+ [jxh_userDefaults() synchronize];
|
|
|
|
+ });
|
|
|
|
+ });
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+- (NSString *)appendSqlStrWithArray:(NSArray *)array tableName:(NSString *)tableName {
|
|
|
|
+ NSMutableString *sqlStr = [NSMutableString stringWithFormat:@"insert into %@ (id, pid, name) values", tableName];
|
|
|
|
+ for (NSInteger i = 0; i < array.count; i ++) {
|
|
|
|
+ [sqlStr appendFormat:@"('%@', '%@', '%@'),", array[i][@"districtId"], array[i][@"pid"], array[i][@"districtName"]];
|
|
|
|
+ if (i == array.count - 1) {
|
|
|
|
+ [sqlStr replaceCharactersInRange:NSMakeRange(sqlStr.length - 1, 1) withString:@""];
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return sqlStr;
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+
|
|
- (void)loadCache {
|
|
- (void)loadCache {
|
|
XSTTPersonalInformationModel *personalInformationModel = [XSTTCacheManager getPersonalInformationCache];
|
|
XSTTPersonalInformationModel *personalInformationModel = [XSTTCacheManager getPersonalInformationCache];
|
|
if (!personalInformationModel) {
|
|
if (!personalInformationModel) {
|
|
@@ -72,4 +121,13 @@
|
|
// xstt_setAccountWallet(XSTTAccountWalletModel.new);
|
|
// xstt_setAccountWallet(XSTTAccountWalletModel.new);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+- (void)setTempCityRefreshTime:(NSString *)tempCityRefreshTime {
|
|
|
|
+ objc_setAssociatedObject(self, _cmd, tempCityRefreshTime, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+- (NSString *)tempCityRefreshTime {
|
|
|
|
+ NSString *object = objc_getAssociatedObject(self, @selector(setTempCityRefreshTime:));
|
|
|
|
+ return object;
|
|
|
|
+}
|
|
|
|
+
|
|
@end
|
|
@end
|