NYTools.m 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. //
  2. // NYTools.m
  3. // jiaPei
  4. //
  5. // Created by Ning.ge on 2024/3/22.
  6. // Copyright © 2024 JCZ. All rights reserved.
  7. //
  8. #import "NYTools.h"
  9. @implementation NYTools
  10. /**
  11. *记录-题目-对错
  12. *userKey 用户id
  13. *carType 车辆类型
  14. *subject 科目几
  15. *exerciseType 题目类型
  16. */
  17. +(void)saveExerciseModel:(RQExerciseModel*)exercise userKey:(NSString*)userKey carType:(RQHomePageCarType)carType subject:(RQHomePageSubjectType)subject exerciseType:(NSUInteger)exerciseType{
  18. NSString *NYCocheName = [NSString stringWithFormat:@"NYExercise_%@",userKey];
  19. YYCache *yyCache = [YYCache cacheWithName:NYCocheName];
  20. NSString *NYCocheNameKey = [NSString stringWithFormat:@"NYExerciseKey_%zd_%zd_%zd",carType,subject,exerciseType];
  21. //记录——用户做的题目-答题
  22. NSArray *userAnswer = exercise.userAnswer.copy;
  23. NSDictionary *exer_dic = @{
  24. @"ID":@(exercise.ydtQuestionModel.ID),//题目id
  25. @"type":@(exercise.ydtQuestionModel.Type),//题目类型
  26. @"answerResultsType":@(exercise.answerResultsType),//是否做对
  27. @"userAnswer":userAnswer,//用户选项
  28. };
  29. NSArray *array = [self readExerciseListUserKey:userKey carType:carType subject:subject exerciseType:exerciseType];
  30. NSMutableArray *value = [NSMutableArray arrayWithArray:array];
  31. [value addObject:exer_dic];
  32. //根据key写入缓存value
  33. [yyCache setObject:value forKey:NYCocheNameKey withBlock:^{
  34. NSLog(@"setObject sucess");
  35. }];
  36. }
  37. //读取-题目对错
  38. +(NSArray*)readExerciseListUserKey:(NSString*)userKey carType:(RQHomePageCarType)carType subject:(RQHomePageSubjectType)subject exerciseType:(NSUInteger)exerciseType{
  39. NSString *NYCocheName = [NSString stringWithFormat:@"NYExercise_%@",userKey];
  40. YYCache *yyCache = [YYCache cacheWithName:NYCocheName];
  41. NSString *NYCocheNameKey = [NSString stringWithFormat:@"NYExerciseKey_%zd_%zd_%zd",carType,subject,exerciseType];
  42. id object = [yyCache objectForKey:NYCocheNameKey];
  43. if ([object isKindOfClass:[NSMutableArray class]]) {
  44. return (NSArray *)object;
  45. } else {
  46. // 返回一个空数组或者其他默认值,视情况而定
  47. return @[];
  48. }
  49. }
  50. //删除-题目
  51. +(void)delateUserKey:(NSString*)userKey{
  52. NSString *NYCocheName = [NSString stringWithFormat:@"NYExercise_%@",userKey];
  53. YYCache *yyCache = [YYCache cacheWithName:NYCocheName];
  54. [yyCache removeAllObjects];
  55. }
  56. @end