Skip to main content

easyofd_reader/model/
seal_data_vo.rs

1//! 印章数据视图对象。
2//!
3//! 对应 Java: org.ofdrw.reader.model.SealDataVo
4
5/// 印章数据视图对象,包含印章的基本信息。
6///
7/// 对应 Java: `org.ofdrw.reader.model.SealDataVo`
8#[derive(Debug, Clone)]
9pub struct SealDataVo {
10    /// 印章 ID。
11    pub seal_id: String,
12    /// 印章名称。
13    pub seal_name: Option<String>,
14    /// 印章图片数据。
15    pub img_byte: Vec<u8>,
16    /// 印章图片类型(如 "PNG"、"JPEG")。
17    pub image_type: String,
18}
19
20impl SealDataVo {
21    /// 创建新的印章数据视图对象。
22    #[must_use]
23    pub fn new(seal_id: impl Into<String>) -> Self {
24        Self {
25            seal_id: seal_id.into(),
26            seal_name: None,
27            img_byte: Vec::new(),
28            image_type: String::new(),
29        }
30    }
31
32    /// 设置印章名称。
33    #[must_use]
34    pub fn with_name(mut self, name: impl Into<String>) -> Self {
35        self.seal_name = Some(name.into());
36        self
37    }
38
39    /// 设置印章图片数据。
40    #[must_use]
41    pub fn with_img(mut self, data: Vec<u8>, image_type: impl Into<String>) -> Self {
42        self.img_byte = data;
43        self.image_type = image_type.into();
44        self
45    }
46}
47
48#[cfg(test)]
49mod tests {
50    use super::*;
51
52    #[test]
53    fn test_seal_data_vo_new() {
54        let vo = SealDataVo::new("seal_001");
55        assert_eq!(vo.seal_id, "seal_001");
56        assert!(vo.seal_name.is_none());
57        assert!(vo.img_byte.is_empty());
58    }
59
60    #[test]
61    fn test_seal_data_vo_with_name() {
62        let vo = SealDataVo::new("seal_001").with_name("Company Seal");
63        assert_eq!(vo.seal_name.as_deref(), Some("Company Seal"));
64    }
65
66    #[test]
67    fn test_seal_data_vo_with_img() {
68        let data = vec![0x89, 0x50, 0x4E, 0x47];
69        let vo = SealDataVo::new("seal_001").with_img(data.clone(), "PNG");
70        assert_eq!(vo.img_byte, data);
71        assert_eq!(vo.image_type, "PNG");
72    }
73}