use serde::{Deserialize, Serialize};
use std::collections::HashMap;
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct KeyValue {
pub key: String,
pub value: String,
}
pub type ExtensionMap = HashMap<String, serde_json::Value>;
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct DeviceBase {
pub device_id: String,
pub device_name: String,
pub device_type: String,
pub status: String,
pub create_time: crate::models::Timestamp,
pub update_time: crate::models::Timestamp,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct UserBase {
pub user_id: String,
pub name: String,
pub status: crate::models::Status,
pub department_ids: Vec<String>,
pub create_time: crate::models::Timestamp,
pub update_time: crate::models::Timestamp,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct PermissionBase {
pub permission_id: String,
pub name: String,
pub description: Option<String>,
pub status: crate::models::Status,
pub create_time: crate::models::Timestamp,
pub update_time: crate::models::Timestamp,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct OperationResponse {
pub success: bool,
pub operation_id: Option<String>,
pub message: Option<String>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct BatchOperationRequest<T> {
pub items: Vec<T>,
pub skip_error: Option<bool>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct BatchOperationResponse<T> {
pub success_items: Vec<T>,
pub failed_items: Vec<BatchOperationError<T>>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct BatchOperationError<T> {
pub item: T,
pub error_code: i32,
pub error_message: String,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum QueryCondition {
Eq(String, serde_json::Value),
Ne(String, serde_json::Value),
Gt(String, serde_json::Value),
Gte(String, serde_json::Value),
Lt(String, serde_json::Value),
Lte(String, serde_json::Value),
Contains(String, serde_json::Value),
In(String, Vec<serde_json::Value>),
NotIn(String, Vec<serde_json::Value>),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct SortCondition {
pub field: String,
pub direction: SortDirection,
}
#[derive(Debug, Clone, Copy, Serialize, Deserialize)]
#[serde(rename_all = "lowercase")]
pub enum SortDirection {
Asc,
Desc,
}
#[derive(Debug, Clone, Copy, Serialize, Deserialize)]
pub struct TimeRange {
pub start_time: crate::models::Timestamp,
pub end_time: crate::models::Timestamp,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct GeoLocation {
pub latitude: f64,
pub longitude: f64,
pub address: Option<String>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct FileUploadResponse {
pub file_id: String,
pub file_url: String,
pub file_size: i64,
pub file_type: String,
pub upload_time: crate::models::Timestamp,
}
#[cfg(test)]
mod tests {
use serde_json;
#[test]
fn test_serialization_roundtrip() {
let json = r#"{"test": "value"}"#;
assert!(serde_json::from_str::<serde_json::Value>(json).is_ok());
}
#[test]
fn test_deserialization_from_json() {
let json = r#"{"field": "data"}"#;
let value: serde_json::Value = serde_json::from_str(json).expect("JSON 反序列化失败");
assert_eq!(value["field"], "data");
}
}