123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263 |
- //
- // NYTools.m
- // jiaPei
- //
- // Created by Ning.ge on 2024/3/22.
- // Copyright © 2024 JCZ. All rights reserved.
- //
- #import "NYTools.h"
- @implementation NYTools
- /**
- *记录-题目-对错
- *userKey 用户id
- *carType 车辆类型
- *subject 科目几
- *exerciseType 题目类型
- */
- +(void)saveExerciseModel:(RQExerciseModel*)exercise userKey:(NSString*)userKey carType:(RQHomePageCarType)carType subject:(RQHomePageSubjectType)subject exerciseType:(NSUInteger)exerciseType{
- NSString *NYCocheName = [NSString stringWithFormat:@"NYExercise_%@",userKey];
- YYCache *yyCache = [YYCache cacheWithName:NYCocheName];
- NSString *NYCocheNameKey = [NSString stringWithFormat:@"NYExerciseKey_%zd_%zd_%zd",carType,subject,exerciseType];
- //记录——用户做的题目-答题
- NSArray *userAnswer = exercise.userAnswer.copy;
- NSDictionary *exer_dic = @{
- @"ID":@(exercise.ydtQuestionModel.ID),//题目id
- @"type":@(exercise.ydtQuestionModel.Type),//题目类型
- @"answerResultsType":@(exercise.answerResultsType),//是否做对
- @"userAnswer":userAnswer,//用户选项
- };
- NSArray *array = [self readExerciseListUserKey:userKey carType:carType subject:subject exerciseType:exerciseType];
- NSMutableArray *value = [NSMutableArray arrayWithArray:array];
- [value addObject:exer_dic];
- //根据key写入缓存value
- [yyCache setObject:value forKey:NYCocheNameKey withBlock:^{
- NSLog(@"setObject sucess");
- }];
-
- }
- //读取-题目对错
- +(NSArray*)readExerciseListUserKey:(NSString*)userKey carType:(RQHomePageCarType)carType subject:(RQHomePageSubjectType)subject exerciseType:(NSUInteger)exerciseType{
- NSString *NYCocheName = [NSString stringWithFormat:@"NYExercise_%@",userKey];
- YYCache *yyCache = [YYCache cacheWithName:NYCocheName];
- NSString *NYCocheNameKey = [NSString stringWithFormat:@"NYExerciseKey_%zd_%zd_%zd",carType,subject,exerciseType];
- id object = [yyCache objectForKey:NYCocheNameKey];
- if ([object isKindOfClass:[NSMutableArray class]]) {
- return (NSArray *)object;
- } else {
- // 返回一个空数组或者其他默认值,视情况而定
- return @[];
- }
- }
- //删除-题目
- +(void)delateUserKey:(NSString*)userKey{
- NSString *NYCocheName = [NSString stringWithFormat:@"NYExercise_%@",userKey];
- YYCache *yyCache = [YYCache cacheWithName:NYCocheName];
- [yyCache removeAllObjects];
- }
- @end
|