paramConfig method

String paramConfig({
  1. required String deviceId,
  2. required CalendarType type,
  3. DateTime? monthDateTime,
  4. DateTime? startTime,
  5. DateTime? endTime,
  6. int? channel,
  7. String? userId,
  8. String? mUserid,
  9. bool needAuth = true,
})

Implementation

String paramConfig({
  required String deviceId,
  required CalendarType type,
  DateTime? monthDateTime,
  DateTime? startTime,
  DateTime? endTime,
  int? channel,
  String? userId,
  String? mUserid,
  bool needAuth = true,
}) {
  final Map<String, dynamic> jsonMap = {
    'sn': deviceId,
  };
  if (type == CalendarType.alarmMessage) {
    ///消息日历无需鉴权
    jsonMap['msg'] = 'alendar'; //服务器拼写错误,不要改
    jsonMap['ty'] = 'MSG';
  } else {
    jsonMap['msg'] = needAuth ? 'alendar_user' : 'alendar'; //服务器拼写错误,不要改
    jsonMap['ty'] = 'VIDEO';
  }

  ///配置时间
  if (monthDateTime != null) {
    jsonMap['dt'] =
        '${monthDateTime.year}-${monthDateTime.month.toString().padLeft(2, '0')}';
  } else {
    List<Map<String, String>> dateRange = [];
    DateTime currentDate = startTime!;
    while (currentDate.isBefore(endTime!) || currentDate == endTime) {
      String formattedDate =
          "${currentDate.year}-${currentDate.month.toString().padLeft(2, '0')}-${currentDate.day.toString().padLeft(2, '0')}";
      dateRange.add({'tm': formattedDate});
      currentDate = currentDate.add(const Duration(days: 1));
    }
    jsonMap['dt'] = dateRange;
  }

  if (channel != null) {
    jsonMap['ch'] = channel;
  }
  if (userId != null) {
    jsonMap['userid'] = userId;
  }
  if (mUserid != null) {
    jsonMap['muserid'] = mUserid;
  }

  return jsonEncode(jsonMap);
}