FlightController.java
1.6 KB
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
54
55
56
57
58
59
60
package com.teplot.air.controller;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import com.jfinal.aop.Before;
import com.jfinal.kit.HttpKit;
import com.jfinal.kit.PropKit;
import com.teplot.air.common.AbsController;
import com.teplot.air.validator.FlightValidator;
import com.teplot.common.BaseController;
import com.teplot.common.JsonMap;
import com.teplot.common.Response;
/**
* Depiction:航班动态接口
* <p>
* Modify:
* <p>
* Author: Kevin Lynn
* <p>
* Create Date:2017年4月7日 下午3:31:30
*
*/
public class FlightController extends AbsController {
public final static String API_AIR_HOST = "http://apis.juhe.cn/plan/bc";
private final static String DATA_FORMAT = "json";
@Before(FlightValidator.class)
public void search() {
Response ret = new Response(CODE_FAILURE);
String start = getPara("start");
String end = getPara("end");
String date = getPara("date");
Map<String, String> param = new HashMap<String, String>();
param.put("start", start);
param.put("end", end);
param.put("date", date);
param.put("dtype", DATA_FORMAT);
param.put("key", PropKit.get("juheAppKey"));
String response = HttpKit.post(API_AIR_HOST, param, "");
JsonMap json = JsonMap.parseJson(response);
if (json != null) {
int error_code = json.getInt("error_code");
int resultcode = json.getInt("resultcode");
if (error_code == 0 && resultcode == 200) {
ret = new Response(CODE_SUCCESS);
ret.setMsg(BaseController.MSG_SUCCESS);
List<JsonMap> resultList = json.getListMap("result");
ret.setData(resultList);
} else {
ret.setMsg(json.getString("reason"));
}
}
renderJson(ret);
}
}