services: allianzdirectcall: update process logic
* return value: usize * import: fill HashMap from source record * import: fill in vector PolicyData Signed-off-by: Ralf Zerres <ralf.zerres@networkx.de>
This commit is contained in:
@@ -8,10 +8,11 @@
|
|||||||
use chrono::{Local, DateTime};
|
use chrono::{Local, DateTime};
|
||||||
use locales::t;
|
use locales::t;
|
||||||
use std::error::Error;
|
use std::error::Error;
|
||||||
|
use std::collections::HashMap;
|
||||||
use tracing::trace;
|
use tracing::trace;
|
||||||
|
|
||||||
//use crate::db::redis;
|
//use crate::db::redis;
|
||||||
use crate::data;
|
use crate::data::{PolicyCode, PolicyDataList, PolicyData};
|
||||||
|
|
||||||
/// export as csv format
|
/// export as csv format
|
||||||
/// https://docs.rs/csv/1.1.3/csv/cookbook/index.html
|
/// https://docs.rs/csv/1.1.3/csv/cookbook/index.html
|
||||||
@@ -43,7 +44,9 @@ pub fn export(p: &mut String, lang: &String) -> Result<(), Box<dyn Error>> {
|
|||||||
/// save records to redis backend
|
/// save records to redis backend
|
||||||
/// https://docs.rs/csv/1.1.3/csv/cookbook/index.html
|
/// https://docs.rs/csv/1.1.3/csv/cookbook/index.html
|
||||||
/// https://blog.burntsushi.net/csv/
|
/// https://blog.burntsushi.net/csv/
|
||||||
pub fn import(p: &mut String, lang: &String) -> Result<u32, Box<dyn Error>> {
|
pub fn import(p: &mut String, data_list: &mut PolicyDataList,
|
||||||
|
policy_numbers: &mut HashMap<usize, PolicyCode>, lang: &String)
|
||||||
|
-> Result<usize, Box<dyn Error>> {
|
||||||
use std::fs::File;
|
use std::fs::File;
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
use std::ffi::OsStr;
|
use std::ffi::OsStr;
|
||||||
@@ -87,33 +90,28 @@ pub fn import(p: &mut String, lang: &String) -> Result<u32, Box<dyn Error>> {
|
|||||||
for result in csv_reader.deserialize() {
|
for result in csv_reader.deserialize() {
|
||||||
// The iterator yields Result<StringRecord, Error>, so we check the
|
// The iterator yields Result<StringRecord, Error>, so we check the
|
||||||
// error here.
|
// error here.
|
||||||
//let record = result?;
|
let record: PolicyData = result?;
|
||||||
let _record: data::AllianzPolicyNumber = result?;
|
//let record: data::AllianzPolicyNumber = result?;
|
||||||
//println!("{:?}", record);
|
//println!("{:?}", record);
|
||||||
|
|
||||||
// WIP: write to redis backend
|
// WIP: write to redis backend
|
||||||
// policy_data.push(PolicyData {
|
// append the policy_number to the HashMap
|
||||||
// date_inserted: Some(Utc::now().naive_utc()),
|
policy_numbers.insert(record.policy_number, record.policy_code);
|
||||||
// dion: 1,
|
|
||||||
// policy_code: PolicyCode::AS,
|
// push record as new vector elements
|
||||||
// policy_number,
|
data_list.push(record);
|
||||||
// status: Status::Active,
|
|
||||||
// });
|
|
||||||
|
|
||||||
count +=1;
|
count +=1;
|
||||||
}
|
}
|
||||||
|
|
||||||
let dt_end: DateTime<Local> = Local::now();
|
let dt_end: DateTime<Local> = Local::now();
|
||||||
let duration = dt_end.signed_duration_since(dt_start);
|
let duration = dt_end.signed_duration_since(dt_start);
|
||||||
println!("Duration: {:#?}", duration);
|
|
||||||
//let seconds = duration.secs;
|
|
||||||
//println!("Seconds: {:#?}", seconds);
|
|
||||||
trace!(target: "advotrackerd", record_count = ?count, duration = ?duration);
|
trace!(target: "advotrackerd", record_count = ?count, duration = ?duration);
|
||||||
|
|
||||||
state = t!("state.finished", lang);
|
state = t!("state.finished", lang);
|
||||||
res = t!("csv.import.finished", lang);
|
res = t!("csv.import.finished", lang);
|
||||||
trace!(target: "advotrackerd", process = ?res, state = ?state, date_stop = ?dt_end.to_string());
|
trace!(target: "advotrackerd", process = ?res, state = ?state, date_stop = ?dt_end.to_string());
|
||||||
|
|
||||||
//Ok(count, duration.seconds())
|
|
||||||
Ok(count)
|
Ok(count)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user