SPSBChooseCityManager.m 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. //
  2. // SPSBChooseCityManager.m
  3. // 我的社保
  4. //
  5. // Created by jiaxian_he on 2021/5/31.
  6. //
  7. #import "SPSBChooseCityManager.h"
  8. #import "SPSBSQLProfile.h"
  9. @interface SPSBChooseCityManager () {
  10. NSArray *_provinceIDArray;
  11. NSArray *_provinceArray;
  12. NSString *_fileName;
  13. }
  14. @end
  15. @implementation SPSBChooseCityManager
  16. + (SPSBChooseCityManager *)shareManagerWithFileName:(NSString *)fileName {
  17. SPSBChooseCityManager *manager = SPSBChooseCityManager.new;
  18. manager->_fileName = fileName;
  19. [manager setProvinceArrayAndProvinceIDArray];
  20. return manager;
  21. }
  22. - (void)setProvinceArrayAndProvinceIDArray {
  23. _provinceIDArray = [JXHFMDBManager searchWithPath:_fileName backKey:@"id" condition:^id(FMDatabase *database) {
  24. return [database executeQuery:@"select * from t_sp_city where parent_id = ?", @"0"];
  25. }];
  26. _provinceArray = [JXHFMDBManager searchWithPath:_fileName backKey:@"name" condition:^id(FMDatabase *database) {
  27. return [database executeQuery:@"select * from t_sp_city where parent_id = ?", @"0"];
  28. }];
  29. }
  30. - (NSArray *)getPrimaryProvinceArrayAndProvinceIDArrayAndIndexsWithSelectedCityArray:(NSArray *)selectedCityArray {
  31. NSInteger provinceIndex = 0;
  32. if (selectedCityArray && [_provinceArray containsObject:selectedCityArray[0]]) {
  33. provinceIndex = [_provinceArray indexOfObject:selectedCityArray[0]];
  34. }
  35. NSArray *cityArray = [self getCityArrayWithProvinceIndex:provinceIndex];
  36. NSInteger cityIndex = 0;
  37. if (selectedCityArray && [cityArray containsObject:selectedCityArray[1]]) {
  38. cityIndex = [cityArray indexOfObject:selectedCityArray[1]];
  39. }
  40. return @[@[_provinceArray, cityArray], @(provinceIndex), @(cityIndex)];
  41. }
  42. - (NSArray *)getProvinceArrayAndProvinceIDArrayWithProvinceIndex:(NSInteger)provinceIndex {
  43. NSArray *cityArray = [self getCityArrayWithProvinceIndex:provinceIndex];
  44. return @[_provinceArray, cityArray];
  45. }
  46. - (NSArray *)getCityArrayWithProvinceIndex:(NSInteger)provinceIndex {
  47. NSArray *cityArray = [JXHFMDBManager searchWithPath:_fileName backKey:@"name" condition:^id(FMDatabase *database) {
  48. return [database executeQuery:@"select * from t_sp_city where parent_id = ?", self->_provinceIDArray[provinceIndex]];
  49. }];
  50. if (cityArray.count == 0) {
  51. cityArray = [NSArray arrayWithObject:_provinceArray[provinceIndex]];
  52. }
  53. return cityArray;
  54. }
  55. - (NSString *)getCityIdWithProvinceIndex:(NSInteger)provinceIndex cityIndex:(NSInteger)cityIndex {
  56. NSArray *cityArray = [JXHFMDBManager searchWithPath:_fileName backKey:@"id" condition:^id(FMDatabase *database) {
  57. return [database executeQuery:@"select * from t_sp_city where parent_id = ?", self->_provinceIDArray[provinceIndex]];
  58. }];
  59. if (cityArray.count > cityIndex) {
  60. return cityArray[cityIndex];
  61. }
  62. return @"";
  63. }
  64. - (NSArray *)getCityArrayWithId:(NSString *)cityId {
  65. NSArray *cityArray = [JXHFMDBManager searchWithPath:_fileName backKey:@"name" condition:^id(FMDatabase *database) {
  66. return [database executeQuery:@"select * from t_sp_city where id = ?", cityId];
  67. }];
  68. return cityArray;
  69. }
  70. - (NSArray *)addSelectedCityArrayCityId:(NSString *)cityId {
  71. NSArray *selectedArray;
  72. NSArray *array = [JXHFMDBManager searchWithPath:_fileName backKey:@"name" condition:^id(FMDatabase *database) {
  73. return [database executeQuery:@"select * from t_sp_city where id = ?", cityId];
  74. }];
  75. if (array.count != 0) {
  76. NSString *city = array[0];
  77. NSString *parentCityId = [JXHFMDBManager searchWithPath:_fileName backKey:@"parent_id" condition:^id(FMDatabase *database) {
  78. return [database executeQuery:@"select * from t_sp_city where id = ?", cityId];
  79. }][0];
  80. array = [JXHFMDBManager searchWithPath:_fileName backKey:@"name" condition:^id(FMDatabase *database) {
  81. return [database executeQuery:@"select * from t_sp_city where id = ?", parentCityId];
  82. }];
  83. if (array.count != 0) {
  84. NSString *provice = array[0];
  85. selectedArray = @[provice, city];
  86. }
  87. }
  88. if (!selectedArray) {
  89. selectedArray = @[@"", @""];
  90. }
  91. return selectedArray;
  92. }
  93. @end