123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123 |
- //
- // P2PDataManager.m
- // VclustersGemini
- //
- // Created by APPLE on 2019/9/25.
- // Copyright © 2019 APPLE. All rights reserved.
- //
- #import "P2PDataManager.h"
- #import "UseAccountManage.h"
- #import "FMDB.h"
- static P2PDataManager *shareInstance = nil;
- @interface P2PDataManager ()
- {
- ;
- }
- @end
- @implementation P2PDataManager
- +(P2PDataManager *)shareInstance;
- {
- static dispatch_once_t onceToken;
-
- dispatch_once(&onceToken, ^{
- shareInstance = [[P2PDataManager alloc]init];
-
- });
-
- return shareInstance;
- }
- - (void)saveOrUpdateRecoderWithModel:(PhoneP2PModel *)model{
- NSDictionary *dictLogin = [[UseAccountManage shareInstance] getLoginInfo];
- if (dictLogin && [[dictLogin allKeys] containsObject:@"userName"])
- {
- /*判断数据库中有没有对应phoneid*/
- NSString* username = [dictLogin objectForKey:@"userName"];
- NSString *bg_tableName = P2PModelList_bg_tableName(username);
-
- model.bg_tableName = bg_tableName;
- [model bg_saveOrUpdateAsync:^(BOOL isSuccess) {
- ;
- }];
- }
- }
- - (PhoneP2PModel *)findRecoderWithPhoneID:(NSInteger)phoneId{
- NSDictionary *dictLogin = [[UseAccountManage shareInstance] getLoginInfo];
- if (dictLogin && [[dictLogin allKeys] containsObject:@"userName"])
- {
- /*判断数据库中有没有对应phoneid*/
- NSString* username = [dictLogin objectForKey:@"userName"];
- NSString * bg_tableName = P2PModelList_bg_tableName(username);
-
- /*查询单个数据*/
- NSString *where = [NSString stringWithFormat:@"where %@=%@",bg_sqlKey(@"phoneId"),bg_sqlValue([NSNumber numberWithInteger:phoneId])];
- NSArray *temp = [PhoneP2PModel bg_find:bg_tableName where:where];
- NSArray *temp1 = [PhoneP2PModel bg_findAll:bg_tableName];
- if (temp && temp.count > 0) {
- return [temp firstObject];
- }
- }
-
- return nil;
- }
- - (void)findRecoderWithPhoneID:(NSInteger)phoneId complete:(bg_complete_A)complete{
- NSDictionary *dictLogin = [[UseAccountManage shareInstance] getLoginInfo];
- if (dictLogin && [[dictLogin allKeys] containsObject:@"userName"])
- {
- /*判断数据库中有没有对应phoneid*/
- NSString* username = [dictLogin objectForKey:@"userName"];
- NSString * bg_tableName = P2PModelList_bg_tableName(username);
-
- /*查询单个数据*/
- NSString *where = [NSString stringWithFormat:@"where %@=%@",bg_sqlKey(@"phoneId"),bg_sqlValue([NSNumber numberWithInteger:phoneId])];
- [PhoneP2PModel bg_findAsync:bg_tableName where:where complete:^(NSArray * _Nullable array) {
- complete(array);
- }];
- }else{
- complete(nil);
- }
- }
- - (void)deleteRecoderWithPhoneID:(NSInteger)phoneId{
- NSDictionary *dictLogin = [[UseAccountManage shareInstance] getLoginInfo];
- if (dictLogin && [[dictLogin allKeys] containsObject:@"userName"])
- {
- /*判断数据库中有没有对应phoneid*/
- NSString* username = [dictLogin objectForKey:@"userName"];
- NSString * bg_tableName = P2PModelList_bg_tableName(username);
-
- /*查询单个数据*/
- NSString *where = [NSString stringWithFormat:@"where %@=%@",bg_sqlKey(@"phoneId"),bg_sqlValue([NSNumber numberWithInteger:phoneId])];
- [PhoneP2PModel bg_deleteAsync:bg_tableName where:where complete:^(BOOL isSuccess) {
- ;
- }];
- }else{
- }
- }
- - (void)deleteAllRecoder{
- NSDictionary *dictLogin = [[UseAccountManage shareInstance] getLoginInfo];
- if (dictLogin && [[dictLogin allKeys] containsObject:@"userName"])
- {
- /*判断数据库中有没有对应phoneid*/
- NSString* username = [dictLogin objectForKey:@"userName"];
- NSString * bg_tableName = P2PModelList_bg_tableName(username);
-
- [PhoneP2PModel bg_clear:bg_tableName];
- }else{
- }
- }
- @end
|