//
//  AdvisoryDBHelper.m
//  MobilePortal
//
//  Created by xiejiangbo on 2019/3/19.
//  Copyright © 2019 yin chen. All rights reserved.
//

#import "AdvisoryDBHelper.h"

@implementation AdvisoryDBHelper
+(instancetype)SharedAdvisoryDBHelper{
    static AdvisoryDBHelper *_advisoryDBHelper = nil;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken,^{
        _advisoryDBHelper = [[AdvisoryDBHelper alloc] init];
    });
    return _advisoryDBHelper;
}
-(void)saveAdvisoryHttpListItemModel:(AdvisoryHttpListItemModel *)selecAdvisoryHttpListItemModel callBack:(void (^)(BOOL))block{
    if (selecAdvisoryHttpListItemModel == nil) {
        return;
    }
    LKDBHelper* dbHelper = [AdvisoryHttpListItemModel getUsingLKDBHelper];
    BOOL __block tranResult = YES;
    [dbHelper executeForTransaction:^(LKDBHelper* helper){
        BOOL result = NO;
        result = [self saveAdvisoryHttpListItemModel:selecAdvisoryHttpListItemModel];
        if (!result) {
            
        }
        tranResult = result;
        return result;
    }];
    block(tranResult);
}
-(BOOL)saveAdvisoryHttpListItemModel:(AdvisoryHttpListItemModel *)selecAdvisoryHttpListItemModel {
    LKDBHelper* dbHelper = [AdvisoryHttpListItemModel getUsingLKDBHelper];
    return [dbHelper insertToDB:selecAdvisoryHttpListItemModel];
}
-(BOOL)hasAdvisoryHttpListItemModel:(NSString *)type{
    LKDBHelper* dbHelper = [AdvisoryHttpListItemModel getUsingLKDBHelper];
    NSDictionary *where = [NSDictionary dictionaryWithObjectsAndKeys:type,@"type",nil];
    NSMutableArray *arr=[dbHelper search:[AdvisoryHttpListItemModel class] column:nil where:where orderBy:nil offset:0 count:0];
    return [arr count]>0 ? true : false ;
}
-(NSMutableArray *)allAdvisoryHttpListItemModel:(NSString *)type{
    LKDBHelper* dbHelper = [AdvisoryHttpListItemModel getUsingLKDBHelper];
    NSDictionary *where = [NSDictionary dictionaryWithObjectsAndKeys:type,@"type",nil];
    return [dbHelper search:[AdvisoryHttpListItemModel class] column:nil where:where orderBy:nil offset:0 count:0];
}
-(void)deleteAdvisoryHttpListItemModel:(NSString *)type AndBlock:(void (^)(BOOL))block{
    LKDBHelper *dbHelper = [AdvisoryHttpListItemModel getUsingLKDBHelper];
    NSDictionary *where = [NSDictionary dictionaryWithObjectsAndKeys:type,@"type",nil];
    BOOL __block tranResult = YES;
    [dbHelper deleteWithClass:[AdvisoryHttpListItemModel class] where:where callback:^(BOOL result){
        tranResult = result;
    }];
    block(tranResult);
}
@end
