tina-core 0.0.2

Tina platform
Documentation
//! 操作日志

/// 操作状态
#[derive(Debug, Copy, Clone)]
pub enum BusinessStatus {
    /// 成功
    SUCCESS,
    /// 失败
    FAIL,
}

impl BusinessStatus {
    /// 状态
    pub fn ordinal(&self) -> i32 {
        match self {
            BusinessStatus::SUCCESS => 0,
            BusinessStatus::FAIL => 1,
        }
    }
}

/// 业务操作类型
#[derive(Debug, Copy, Clone)]
pub enum BusinessType {
    /// 其它
    OTHER(i32),
    /// 新增
    INSERT,
    /// 修改
    UPDATE,
    /// 删除
    DELETE,
    /// 授权
    GRANT,
    /// 导出
    EXPORT,
    /// 导入
    IMPORT,
    /// 强退
    FORCE,
    /// 生成代码
    GENCODE,
    /// 清空数据
    CLEAN,
}

impl BusinessType {
    /// 状态
    pub fn ordinal(&self) -> i32 {
        match self {
            BusinessType::OTHER(v) => *v,
            BusinessType::INSERT => 1,
            BusinessType::UPDATE => 2,
            BusinessType::DELETE => 3,
            BusinessType::GRANT => 4,
            BusinessType::EXPORT => 5,
            BusinessType::IMPORT => 6,
            BusinessType::FORCE => 7,
            BusinessType::GENCODE => 8,
            BusinessType::CLEAN => 9,
        }
    }
}

/// 操作人类别
#[derive(Debug, Copy, Clone)]
pub enum OperatorType {
    /// 其它
    OTHER(i32),
    /// 后台用户
    MANAGE,
    /// 手机端用户
    MOBILE,
}

impl OperatorType {
    /// 状态
    pub fn ordinal(&self) -> i32 {
        match self {
            OperatorType::OTHER(v) => *v,
            OperatorType::MANAGE => 1,
            OperatorType::MOBILE => 2,
        }
    }
}

/// 自定义操作日志记录
#[derive(Debug, Clone)]
pub struct OperationLog {
    /// 模块
    pub title: String,
    /// 功能
    pub business_type: BusinessType,
    /// 操作人类别
    pub operator_type: OperatorType,
    /// 是否保存请求的参数
    pub save_request_data: bool,
    /// 是否保存响应的参数
    pub save_response_data: bool,
}

impl Default for OperationLog {
    fn default() -> Self {
        Self::new()
    }
}

impl OperationLog {
    /// 构建
    pub fn new() -> Self {
        Self {
            title: "".to_string(),
            business_type: BusinessType::OTHER(0),
            operator_type: OperatorType::MANAGE,
            save_request_data: true,
            save_response_data: true,
        }
    }
    /// 设置模块
    pub fn title(mut self, title: &str) -> Self {
        self.title = title.to_string();
        self
    }
    /// 设置功能
    pub fn business_type(mut self, business_type: BusinessType) -> Self {
        self.business_type = business_type;
        self
    }
    /// 设置操作人类别
    pub fn operator_type(mut self, operator_type: OperatorType) -> Self {
        self.operator_type = operator_type;
        self
    }
    /// 设置是否保存请求的参数
    pub fn save_request_data(mut self, save_request_data: bool) -> Self {
        self.save_request_data = save_request_data;
        self
    }
    /// 设置是否保存响应的参数
    pub fn save_response_data(mut self, save_response_data: bool) -> Self {
        self.save_response_data = save_response_data;
        self
    }
}