JLChen
2021-05-18 a869383e163a18cdedcf587383c1eca043129754
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
//
//  Copyright © 2020 dahua. All rights reserved.
//
 
#import "LCVideotapeInterface.h"
#import "LCNetworkRequestManager.h"
#import "TextDefine.h"
#import <LCBaseModule/LCError.h>
 
@implementation LCVideotapeInterface
 
+(void)queryCloudRecordsForDevice:(NSString *)deviceId channelId:(NSString *)channelId day:(NSDate *)day From:(int)start To:(int)end success:(void (^)(NSMutableArray<LCCloudVideotapeInfo *> * _Nonnull))success failure:(void (^)(LCError * _Nonnull))failure{
    //起始条数
    NSString * query = [NSString stringWithFormat:@"%d-%d",start,end];
    NSDateFormatter * dataFormatter = [[NSDateFormatter alloc] init];
    dataFormatter.dateFormat = @"yyyy-MM-dd";
    //开始时间
    NSString * startStr = [NSString stringWithFormat:@"%@ 00:00:00",[dataFormatter stringFromDate:day]];
    NSString * endStr = @"";
    
    if (![[NSCalendar currentCalendar] isDateInToday:day]) {
        //如果不是今天
        endStr = [NSString stringWithFormat:@"%@ 23:59:59",[dataFormatter stringFromDate:day]];
    }else{
        //否则搜索时间为当前时间
        NSDateFormatter * dataFormatterEnd = [[NSDateFormatter alloc] init];
        dataFormatterEnd.dateFormat = @"yyyy-MM-dd HH:mm:ss";
        endStr = [dataFormatterEnd stringFromDate:day];
    }
    [[LCNetworkRequestManager manager] lc_POST:@"/queryCloudRecords" parameters:@{KEY_TOKEN:[LCApplicationDataManager token],KEY_DEVICE_ID:deviceId,KEY_CHANNEL_ID:channelId,KEY_BEGIN_TIME:startStr,KEY_END_TIME:endStr,KEY_QUERYRANGE:query} success:^(id  _Nonnull objc) {
         NSMutableArray <LCCloudVideotapeInfo *> *infos = [LCCloudVideotapeInfo mj_objectArrayWithKeyValuesArray:[objc objectForKey:@"records"]];
        if (success) {
            success(infos);
        }
    } failure:^(LCError * _Nonnull error) {
        if (failure) {
            failure(error);
        }
    }];
}
 
+(void)queryLocalRecordsForDevice:(NSString *)deviceId channelId:(NSString *)channelId day:(NSDate *)day From:(int)start To:(int)end success:(void (^)(NSMutableArray<LCLocalVideotapeInfo *> * _Nonnull))success failure:(void (^)(LCError * _Nonnull))failure{
    //起始条数
    NSString * query = [NSString stringWithFormat:@"%d-%d",start,end];
    NSDateFormatter * dataFormatter = [[NSDateFormatter alloc] init];
    dataFormatter.dateFormat = @"yyyy-MM-dd";
    //开始时间
    NSString * startStr = [NSString stringWithFormat:@"%@ 00:00:00",[dataFormatter stringFromDate:day]];
    NSString * endStr = @"";
    if (![[NSCalendar currentCalendar] isDateInToday:day]) {
        //如果不是今天
        endStr = [NSString stringWithFormat:@"%@ 23:59:59",[dataFormatter stringFromDate:day]];
    }else{
        //否则搜索时间为当前时间
        NSDateFormatter * dataFormatterEnd = [[NSDateFormatter alloc] init];
        dataFormatterEnd.dateFormat = @"yyyy-MM-dd HH:mm:ss";
        endStr = [dataFormatterEnd stringFromDate:[NSDate new]];
    }
    [[LCNetworkRequestManager manager] lc_POST:@"/queryLocalRecords" parameters:@{KEY_TOKEN:[LCApplicationDataManager token],KEY_DEVICE_ID:deviceId,KEY_CHANNEL_ID:channelId,KEY_BEGIN_TIME:startStr,KEY_END_TIME:endStr,KEY_QUERYRANGE:query} success:^(id  _Nonnull objc) {
        NSMutableArray <LCLocalVideotapeInfo *> *infos = [LCLocalVideotapeInfo mj_objectArrayWithKeyValuesArray:[objc objectForKey:@"records"]];
        if (success) {
            success(infos);
        }
    } failure:^(LCError * _Nonnull error) {
        if (failure) {
            failure(error);
        }
    }];
}
 
+(void)getCloudRecordsForDevice:(NSString *)deviceId channelId:(NSString *)channelId day:(NSDate *)day From:(long)nextRecordId Count:(long)count success:(void (^)(NSMutableArray<LCCloudVideotapeInfo *> * _Nonnull))success failure:(void (^)(LCError * _Nonnull))failure{
      //起始条数
      NSDateFormatter * dataFormatter = [[NSDateFormatter alloc] init];
      dataFormatter.dateFormat = @"yyyy-MM-dd";
      //开始时间
      NSString * startStr = [NSString stringWithFormat:@"%@ 00:00:00",[dataFormatter stringFromDate:day]];
      NSString * endStr = @"";
      
      if (![[NSCalendar currentCalendar] isDateInToday:day]) {
          //如果不是今天
          endStr = [NSString stringWithFormat:@"%@ 23:59:59",[dataFormatter stringFromDate:day]];
      }else{
          //否则搜索时间为当前时间
          NSDateFormatter * dataFormatterEnd = [[NSDateFormatter alloc] init];
          dataFormatterEnd.dateFormat = @"yyyy-MM-dd HH:mm:ss";
          endStr = [dataFormatterEnd stringFromDate:day];
      }
    [[LCNetworkRequestManager manager] lc_POST:@"/getCloudRecords" parameters:@{KEY_TOKEN:[LCApplicationDataManager token],KEY_DEVICE_ID:deviceId,KEY_CHANNEL_ID:channelId,KEY_BEGIN_TIME:startStr,KEY_END_TIME:endStr,@"nextRecordId":@(nextRecordId),KEY_COUNT:@(count)} success:^(id  _Nonnull objc) {
           NSMutableArray <LCCloudVideotapeInfo *> *infos = [LCCloudVideotapeInfo mj_objectArrayWithKeyValuesArray:[objc objectForKey:@"records"]];
          if (success) {
              success(infos);
          }
      } failure:^(LCError * _Nonnull error) {
          if (failure) {
              failure(error);
          }
      }];
}
 
+(void)deleteCloudRecords:(NSString *)recordRegionId success:(void (^)(void))success failure:(void (^)(LCError * _Nonnull))failure{
    [[LCNetworkRequestManager manager] lc_POST:@"/deleteCloudRecords" parameters:@{KEY_TOKEN:[LCApplicationDataManager token],@"recordRegionId":recordRegionId} success:^(id  _Nonnull objc) {
        if (success) {
            success();
        }
    } failure:^(LCError * _Nonnull error) {
        if (failure) {
            failure(error);
        }
    }];
}
 
@end