P2PDataManager.m 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. //
  2. // P2PDataManager.m
  3. // VclustersGemini
  4. //
  5. // Created by APPLE on 2019/9/25.
  6. // Copyright © 2019 APPLE. All rights reserved.
  7. //
  8. #import "P2PDataManager.h"
  9. #import "UseAccountManage.h"
  10. #import "FMDB.h"
  11. static P2PDataManager *shareInstance = nil;
  12. @interface P2PDataManager ()
  13. {
  14. ;
  15. }
  16. @end
  17. @implementation P2PDataManager
  18. +(P2PDataManager *)shareInstance;
  19. {
  20. static dispatch_once_t onceToken;
  21. dispatch_once(&onceToken, ^{
  22. shareInstance = [[P2PDataManager alloc]init];
  23. });
  24. return shareInstance;
  25. }
  26. - (void)saveOrUpdateRecoderWithModel:(PhoneP2PModel *)model{
  27. NSDictionary *dictLogin = [[UseAccountManage shareInstance] getLoginInfo];
  28. if (dictLogin && [[dictLogin allKeys] containsObject:@"userName"])
  29. {
  30. /*判断数据库中有没有对应phoneid*/
  31. NSString* username = [dictLogin objectForKey:@"userName"];
  32. NSString *bg_tableName = P2PModelList_bg_tableName(username);
  33. model.bg_tableName = bg_tableName;
  34. [model bg_saveOrUpdateAsync:^(BOOL isSuccess) {
  35. ;
  36. }];
  37. }
  38. }
  39. - (PhoneP2PModel *)findRecoderWithPhoneID:(NSInteger)phoneId{
  40. NSDictionary *dictLogin = [[UseAccountManage shareInstance] getLoginInfo];
  41. if (dictLogin && [[dictLogin allKeys] containsObject:@"userName"])
  42. {
  43. /*判断数据库中有没有对应phoneid*/
  44. NSString* username = [dictLogin objectForKey:@"userName"];
  45. NSString * bg_tableName = P2PModelList_bg_tableName(username);
  46. /*查询单个数据*/
  47. NSString *where = [NSString stringWithFormat:@"where %@=%@",bg_sqlKey(@"phoneId"),bg_sqlValue([NSNumber numberWithInteger:phoneId])];
  48. NSArray *temp = [PhoneP2PModel bg_find:bg_tableName where:where];
  49. NSArray *temp1 = [PhoneP2PModel bg_findAll:bg_tableName];
  50. if (temp && temp.count > 0) {
  51. return [temp firstObject];
  52. }
  53. }
  54. return nil;
  55. }
  56. - (void)findRecoderWithPhoneID:(NSInteger)phoneId complete:(bg_complete_A)complete{
  57. NSDictionary *dictLogin = [[UseAccountManage shareInstance] getLoginInfo];
  58. if (dictLogin && [[dictLogin allKeys] containsObject:@"userName"])
  59. {
  60. /*判断数据库中有没有对应phoneid*/
  61. NSString* username = [dictLogin objectForKey:@"userName"];
  62. NSString * bg_tableName = P2PModelList_bg_tableName(username);
  63. /*查询单个数据*/
  64. NSString *where = [NSString stringWithFormat:@"where %@=%@",bg_sqlKey(@"phoneId"),bg_sqlValue([NSNumber numberWithInteger:phoneId])];
  65. [PhoneP2PModel bg_findAsync:bg_tableName where:where complete:^(NSArray * _Nullable array) {
  66. complete(array);
  67. }];
  68. }else{
  69. complete(nil);
  70. }
  71. }
  72. - (void)deleteRecoderWithPhoneID:(NSInteger)phoneId{
  73. NSDictionary *dictLogin = [[UseAccountManage shareInstance] getLoginInfo];
  74. if (dictLogin && [[dictLogin allKeys] containsObject:@"userName"])
  75. {
  76. /*判断数据库中有没有对应phoneid*/
  77. NSString* username = [dictLogin objectForKey:@"userName"];
  78. NSString * bg_tableName = P2PModelList_bg_tableName(username);
  79. /*查询单个数据*/
  80. NSString *where = [NSString stringWithFormat:@"where %@=%@",bg_sqlKey(@"phoneId"),bg_sqlValue([NSNumber numberWithInteger:phoneId])];
  81. [PhoneP2PModel bg_deleteAsync:bg_tableName where:where complete:^(BOOL isSuccess) {
  82. ;
  83. }];
  84. }else{
  85. }
  86. }
  87. - (void)deleteAllRecoder{
  88. NSDictionary *dictLogin = [[UseAccountManage shareInstance] getLoginInfo];
  89. if (dictLogin && [[dictLogin allKeys] containsObject:@"userName"])
  90. {
  91. /*判断数据库中有没有对应phoneid*/
  92. NSString* username = [dictLogin objectForKey:@"userName"];
  93. NSString * bg_tableName = P2PModelList_bg_tableName(username);
  94. [PhoneP2PModel bg_clear:bg_tableName];
  95. }else{
  96. }
  97. }
  98. @end