|
|
@@ -1,4 +1,7 @@
|
|
|
+use std::str::FromStr;
|
|
|
use chrono::NaiveDateTime;
|
|
|
+use rust_decimal::Decimal;
|
|
|
+use rust_decimal_macros::dec;
|
|
|
use crate::export_template::template_columnar;
|
|
|
use crate::utils::utils;
|
|
|
use crate::utils::utils::{ColumnarConfigInfo};
|
|
|
@@ -19,21 +22,38 @@ pub async fn export_columnar(config_info: ColumnarConfigInfo) {
|
|
|
let mut time_list = time_slicer.clone();
|
|
|
let mut over_list = vec![];
|
|
|
let mut save_value: Vec<String> = vec![];
|
|
|
+ let mut total = dec!(0);
|
|
|
for (index, item) in balance_list.iter().enumerate() {
|
|
|
+ if index == 0 {
|
|
|
+ total = Decimal::from_str(item[4].as_str().unwrap()).unwrap();
|
|
|
+ }
|
|
|
+ if index != 0 && item[5] == "transfer" {
|
|
|
+ total = total + (Decimal::from_str(item[4].as_str().unwrap()).unwrap() - Decimal::from_str(balance_list.clone()[index - 1][4].as_str().unwrap()).unwrap());
|
|
|
+ }
|
|
|
let time: i64 = item[1].as_str().unwrap().parse().unwrap();
|
|
|
+ let mut new_value: Vec<String> = vec![];
|
|
|
if time_list[0] < time {
|
|
|
- save_value[1] = time_list[0].to_string();
|
|
|
- over_list.push(save_value.clone());
|
|
|
+ new_value.push(time_list[0].to_string());
|
|
|
+ new_value.push((Decimal::from_str(item[4].as_str().unwrap()).unwrap() - total).to_string());
|
|
|
+ over_list.push(new_value.clone());
|
|
|
time_list.remove(0);
|
|
|
}
|
|
|
save_value = item.as_array().unwrap().iter().map(|value| value.as_str().unwrap().to_string()).collect();
|
|
|
- if index == balance_list.len() - 1 {
|
|
|
- if time <= time_list[0] {
|
|
|
- save_value[1] = time_list[0].to_string();
|
|
|
- over_list.push(save_value.clone());
|
|
|
- time_list.remove(0);
|
|
|
- }
|
|
|
+ if index == balance_list.len() - 1 && time <= time_list[0] {
|
|
|
+ new_value.push(time_list[0].to_string());
|
|
|
+ new_value.push((Decimal::from_str(item[4].as_str().unwrap()).unwrap() - total).to_string());
|
|
|
+ save_value[1] = time_list[0].to_string();
|
|
|
+ over_list.push(new_value.clone());
|
|
|
+ time_list.remove(0);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ let mut over_value_list: Vec<Vec<String>> = vec![];
|
|
|
+ for (index, item) in over_list.iter().enumerate() {
|
|
|
+ if index == 0 {
|
|
|
+ over_value_list.push(vec![item[0].clone(), "0".to_string()]);
|
|
|
+ continue;
|
|
|
}
|
|
|
+ over_value_list.push(vec![item[0].clone(), (Decimal::from_str(&item[1]).unwrap() - Decimal::from_str(&over_list[index - 1][1]).unwrap()).to_string()])
|
|
|
}
|
|
|
- template_columnar::export_html(config_info, over_list);
|
|
|
+ template_columnar::export_html(config_info, over_value_list);
|
|
|
}
|