1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#[macro_use]
extern crate lazy_static;
#[macro_use]
extern crate log;
use std::{env, thread};
use std::str::FromStr;
use actix_web::{App, HttpResponse, HttpServer, web};
use actix_web::dev::Server;
use actix_web::web::Json;
use reqwest::Client;
use nature_common::{ConverterParameter, ConverterReturned, Instance, Result};
use crate::emall::send_to_warehouse_thread;
lazy_static! {
pub static ref CLIENT : Client = Client::new();
pub static ref CALLBACK_ADDRESS: String = "http://localhost:8080/callback".to_string();
pub static ref GET_BY_META: String = "http://localhost:8080/get_by_key_range".to_string();
}
async fn send_to_warehouse(para: Json<ConverterParameter>) -> HttpResponse {
thread::spawn(move || send_to_warehouse_thread(para.0));
HttpResponse::Ok().json(ConverterReturned::Delay(60))
}
async fn add_score(para: Json<Vec<Instance>>) -> HttpResponse {
let mut rtn = para.0;
rtn.iter_mut().for_each(|one| {
if one.para.contains("subject2") {
let points = u16::from_str(&one.content).unwrap();
let content = (points + 4).to_string();
one.data.content = content;
}
});
HttpResponse::Ok().json(Ok(rtn) as Result<Vec<Instance>>)
}
pub fn start_actrix() -> Server {
let port = env::var("DEMO_CONVERTER_PORT").unwrap_or_else(|_| "8082".to_string());
HttpServer::new(
|| App::new()
.route("/send_to_warehouse", web::post().to(send_to_warehouse))
.route("/add_score", web::post().to(add_score))
).bind("127.0.0.1:".to_owned() + &port).unwrap()
.run()
}
pub mod emall;
pub mod tool;