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

#import "HomeDBHelper.h"

@implementation HomeDBHelper
+(instancetype)SharedHomeDBHelper{
    static HomeDBHelper *_sharedHomeDBHelper = nil;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken,^{
        _sharedHomeDBHelper = [[HomeDBHelper alloc] init];
    });
    return _sharedHomeDBHelper;
}
#pragma mark -首页数据
// 首页数据存储
-(void)saveHomeHttpInfoModelBannerModel:(HomeHttpInfoModelBannerModel *)selecHomeHttpInfoModelBannerModel callBack:(void (^)(BOOL))block{
    if (selecHomeHttpInfoModelBannerModel == nil) {
        return;
    }
    LKDBHelper* dbHelper = [HomeHttpInfoModelBannerModel getUsingLKDBHelper];
    BOOL __block tranResult = YES;
    [dbHelper executeForTransaction:^(LKDBHelper* helper){
        BOOL result = NO;
        result = [self saveHomeHttpInfoModelBannerModel:selecHomeHttpInfoModelBannerModel];
        if (!result) {
            
        }
        tranResult = result;
        return result;
    }];
    block(tranResult);
}
-(BOOL)saveHomeHttpInfoModelBannerModel:(HomeHttpInfoModelBannerModel *)selecHomeHttpInfoModelBannerModel {
    LKDBHelper* dbHelper = [HomeHttpInfoModelBannerModel getUsingLKDBHelper];
    return [dbHelper insertToDB:selecHomeHttpInfoModelBannerModel];
}

// 是否存储该数据
-(BOOL)hasHomeHttpInfoModelBannerModel{
    LKDBHelper* dbHelper = [HomeHttpInfoModelBannerModel getUsingLKDBHelper];
    NSMutableArray *arr=[dbHelper search:[HomeHttpInfoModelBannerModel class] column:nil where:nil orderBy:nil offset:0 count:0];
    return [arr count]>0 ? true : false ;
}
// 获取所有数据
-(NSMutableArray *)allHomeHttpInfoModelBannerModel{
    LKDBHelper* dbHelper = [HomeHttpInfoModelBannerModel getUsingLKDBHelper];
    return [dbHelper search:[HomeHttpInfoModelBannerModel class] column:nil where:nil orderBy:nil offset:0 count:0];
}
-(void)deleteHomeHttpInfoModelBannerModel:(void (^)(BOOL))block{
    LKDBHelper *dbHelper = [HomeHttpInfoModelBannerModel getUsingLKDBHelper];
    BOOL __block tranResult = YES;
    [dbHelper deleteWithClass:[HomeHttpInfoModelBannerModel class] where:nil callback:^(BOOL result){
        tranResult = result;
    }];
    block(tranResult);
}

// 首页数据存储
-(void)saveHomeHttpInfoModelMenuModel:(HomeHttpInfoModelMenuModel *)selecHomeHttpInfoModelMenuModel callBack:(void (^)(BOOL))block{
    if (selecHomeHttpInfoModelMenuModel == nil) {
        return;
    }
    LKDBHelper* dbHelper = [HomeHttpInfoModelMenuModel getUsingLKDBHelper];
    BOOL __block tranResult = YES;
    [dbHelper executeForTransaction:^(LKDBHelper* helper){
        BOOL result = NO;
        result = [self saveHomeHttpInfoModelMenuModel:selecHomeHttpInfoModelMenuModel];
        if (!result) {
            
        }
        tranResult = result;
        return result;
    }];
    block(tranResult);
}
-(BOOL)saveHomeHttpInfoModelMenuModel:(HomeHttpInfoModelMenuModel *)selecHomeHttpInfoModelMenuModel {
    LKDBHelper* dbHelper = [HomeHttpInfoModelMenuModel getUsingLKDBHelper];
    return [dbHelper insertToDB:selecHomeHttpInfoModelMenuModel];
}
-(BOOL)hasHomeHttpInfoModelMenuModel{
    LKDBHelper* dbHelper = [HomeHttpInfoModelMenuModel getUsingLKDBHelper];
    NSMutableArray *arr=[dbHelper search:[HomeHttpInfoModelMenuModel class] column:nil where:nil orderBy:nil offset:0 count:0];
    return [arr count]>0 ? true : false ;
}
-(NSMutableArray *)allHomeHttpInfoModelMenuModel{
    LKDBHelper* dbHelper = [HomeHttpInfoModelMenuModel getUsingLKDBHelper];
    return [dbHelper search:[HomeHttpInfoModelMenuModel class] column:nil where:nil orderBy:nil offset:0 count:0];
}
-(void)deleteHomeHttpInfoModelMenuModel:(void (^)(BOOL))block{
    LKDBHelper *dbHelper = [HomeHttpInfoModelMenuModel getUsingLKDBHelper];
    BOOL __block tranResult = YES;
    [dbHelper deleteWithClass:[HomeHttpInfoModelMenuModel class] where:nil callback:^(BOOL result){
        tranResult = result;
    }];
    block(tranResult);
}


-(void)saveHomeHttpInfoModelTitleContentModel:(HomeHttpInfoModelTitleContentModel *)selecHomeHttpInfoModelTitleContentModel callBack:(void (^)(BOOL))block{
    if (selecHomeHttpInfoModelTitleContentModel == nil) {
        return;
    }
    LKDBHelper* dbHelper = [HomeHttpInfoModelTitleContentModel getUsingLKDBHelper];
    BOOL __block tranResult = YES;
    [dbHelper executeForTransaction:^(LKDBHelper* helper){
        BOOL result = NO;
        result = [self saveHomeHttpInfoModelTitleContentModel:selecHomeHttpInfoModelTitleContentModel];
        if (!result) {
            
        }
        tranResult = result;
        return result;
    }];
    block(tranResult);
}
-(BOOL)saveHomeHttpInfoModelTitleContentModel:(HomeHttpInfoModelTitleContentModel *)selecHomeHttpInfoModelMenuModel {
    LKDBHelper* dbHelper = [HomeHttpInfoModelTitleContentModel getUsingLKDBHelper];
    return [dbHelper insertToDB:selecHomeHttpInfoModelMenuModel];
}
-(BOOL)hasHomeHttpInfoModelTitleContentModel:(NSString *)homeType{
    LKDBHelper* dbHelper = [HomeHttpInfoModelTitleContentModel getUsingLKDBHelper];
    NSDictionary *where = [NSDictionary dictionaryWithObjectsAndKeys:homeType,@"homeType",nil];
    NSMutableArray *arr=[dbHelper search:[HomeHttpInfoModelTitleContentModel class] column:nil where:where orderBy:nil offset:0 count:0];
    return [arr count]>0 ? true : false ;
}
-(NSMutableArray *)allHomeHttpInfoModelTitleContentModel:(NSString *)homeType{
    LKDBHelper* dbHelper = [HomeHttpInfoModelTitleContentModel getUsingLKDBHelper];
     NSDictionary *where = [NSDictionary dictionaryWithObjectsAndKeys:homeType,@"homeType",nil];
    return [dbHelper search:[HomeHttpInfoModelTitleContentModel class] column:nil where:where orderBy:nil offset:0 count:0];
}
-(void)deleteHomeHttpInfoModelTitleContentModel:(void (^)(BOOL))block{
    LKDBHelper *dbHelper = [HomeHttpInfoModelTitleContentModel getUsingLKDBHelper];
    BOOL __block tranResult = YES;
    [dbHelper deleteWithClass:[HomeHttpInfoModelTitleContentModel class] where:nil callback:^(BOOL result){
        tranResult = result;
    }];
    block(tranResult);
}

@end
