write id_card test
This commit is contained in:
2
.idea/serv.iml
generated
2
.idea/serv.iml
generated
@@ -6,6 +6,8 @@
|
||||
<sourceFolder url="file://$MODULE_DIR$/packages/home-api/src" isTestSource="false" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/packages/serv/src" isTestSource="false" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/packages/model/lib" isTestSource="false" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/packages/src" isTestSource="false" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/target" />
|
||||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
[workspace]
|
||||
resolver = "2"
|
||||
members = ["packages/gotify-ws", "packages/serv"]
|
||||
default-members = ["packages/gotify-ws"]
|
||||
members = ["packages/gotify-ws", "packages/model", "packages/serv"]
|
||||
#default-members = ["packages/gotify-ws"]
|
||||
|
||||
[workspace.dependencies]
|
||||
gotify-ws = { path = "./packages/gotify-ws" }
|
||||
|
||||
13
packages/model/Cargo.toml
Normal file
13
packages/model/Cargo.toml
Normal file
@@ -0,0 +1,13 @@
|
||||
[package]
|
||||
name = "model"
|
||||
version = "0.1.0"
|
||||
edition = "2024"
|
||||
|
||||
[lib]
|
||||
name = "model"
|
||||
path = "lib/mod.rs"
|
||||
|
||||
[dependencies]
|
||||
serde.workspace = true
|
||||
sea-orm.workspace = true
|
||||
chrono.workspace = true
|
||||
31
packages/model/lib/id_card/mod.rs
Normal file
31
packages/model/lib/id_card/mod.rs
Normal file
@@ -0,0 +1,31 @@
|
||||
use sea_orm::entity::prelude::*;
|
||||
use sea_orm::{ActiveModelBehavior, DeriveActiveEnum, DeriveEntityModel, DerivePrimaryKey, DeriveRelation, EnumIter};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(DeriveEntityModel, Clone, Debug, PartialEq, Serialize, Deserialize)]
|
||||
#[sea_orm(table_name = "id_card")]
|
||||
pub struct Model {
|
||||
#[sea_orm(primary_key)]
|
||||
pub id: String,
|
||||
pub name: String,
|
||||
pub gender: Gender,
|
||||
pub birth: String,
|
||||
pub address: Option<String>,
|
||||
pub nation: String,
|
||||
pub create_at: DateTime,
|
||||
}
|
||||
pub type IDCardModel = Model;
|
||||
|
||||
#[derive(Debug, DeriveRelation, EnumIter)]
|
||||
pub enum Relation {}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug, Clone, EnumIter, PartialEq, DeriveActiveEnum)]
|
||||
#[sea_orm(rs_type = "String", db_type = "Enum", enum_name = "gender")]
|
||||
pub enum Gender {
|
||||
#[sea_orm(string_value = "female")]
|
||||
Female,
|
||||
#[sea_orm(string_value = "male")]
|
||||
Male,
|
||||
}
|
||||
|
||||
impl ActiveModelBehavior for ActiveModel {}
|
||||
1
packages/model/lib/mod.rs
Normal file
1
packages/model/lib/mod.rs
Normal file
@@ -0,0 +1 @@
|
||||
pub mod id_card;
|
||||
@@ -6,5 +6,6 @@ edition = "2024"
|
||||
[dependencies]
|
||||
tokio.workspace = true
|
||||
gotify-ws.workspace = true
|
||||
log = "0.4.27"
|
||||
env_logger = "0.11.8"
|
||||
log.workspace = true
|
||||
sea-orm.workspace = true
|
||||
regex.workspace = true
|
||||
|
||||
74
packages/serv/src/test/id_card.rs
Normal file
74
packages/serv/src/test/id_card.rs
Normal file
@@ -0,0 +1,74 @@
|
||||
use regex::Regex;
|
||||
use std::env;
|
||||
use std::fs::File;
|
||||
use std::io::{BufRead, BufReader};
|
||||
use std::path::Path;
|
||||
use std::sync::OnceLock;
|
||||
|
||||
static ID_REG: OnceLock<Regex> = OnceLock::new();
|
||||
#[test]
|
||||
fn test_split() {
|
||||
let str = "朱春艳----320681197904304224";
|
||||
if let Some((name, id)) = split_str(str) {
|
||||
println!("name: {}, id: {}", name, id);
|
||||
get_id_info(id)
|
||||
}
|
||||
}
|
||||
|
||||
fn split_str(str: &str) -> Option<(&str, &str)> {
|
||||
let regex = ID_REG.get_or_init(|| Regex::new(r"(.*?)-+(\d+)").expect("正则创建失败"));
|
||||
let mut value = None;
|
||||
|
||||
if let Some(res) = regex.captures(str) {
|
||||
value = Some((res.get(1)?.as_str(), res.get(2)?.as_str()));
|
||||
}
|
||||
|
||||
value
|
||||
}
|
||||
|
||||
fn get_id_info(id: &str) {
|
||||
let location = &id[0..6];
|
||||
println!("location: {}", location);
|
||||
let born = &id[6..14];
|
||||
println!("born: {}", born);
|
||||
let born_year = &id[6..10];
|
||||
println!("born: {}", born_year);
|
||||
let born_month = &id[10..12];
|
||||
println!("born month: {}", born_month);
|
||||
let born_day = &id[12..14];
|
||||
println!("born day: {}", born_day);
|
||||
let count = &id[14..18];
|
||||
println!("born count: {}", count);
|
||||
let validate = &id[18..19];
|
||||
println!("validate number: {validate}")
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_get_file() {
|
||||
get_id_file();
|
||||
}
|
||||
|
||||
fn get_id_file() {
|
||||
let _ = env::current_dir().unwrap();
|
||||
println!("当前的路径 {:#?}", env::current_dir().unwrap());
|
||||
let path = Path::new("resources/ID/id.txt");
|
||||
// let path = Path::new("resources/id.txt");
|
||||
let file = File::open(path).expect("打开文件失败");
|
||||
let buffer = BufReader::new(file);
|
||||
|
||||
for line in buffer.lines() {
|
||||
// println!("line {}", line.unwrap());
|
||||
if let Some((name, id)) = split_str(line.unwrap().as_str()) {
|
||||
// println!("name: {}, id: {}", name, id);
|
||||
|
||||
if id.len() != 18 {
|
||||
// println!("name: {}, id: {}", name, id);
|
||||
continue;
|
||||
// if id.len() != 17 {
|
||||
// println!("name: {}, id: {}", name, id);
|
||||
// continue;
|
||||
// }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,2 +1,3 @@
|
||||
#[cfg(test)]
|
||||
mod base_api;
|
||||
mod id_card;
|
||||
|
||||
Reference in New Issue
Block a user