log.info("新增一筆設備上傳記錄:" + JSON.toJSONString(du));
// 直接新增message info到db
// 並直接把message content發給相關的devices
JSONObject retJson = new JSONObject();
CarTracePushNotificationAPI ctpn_api = new CarTracePushNotificationAPI();
if (null != cr) {
String carID = cr.getEncodedKey();
String title = "設備上傳記錄";
String message = String.format("設備於%s上傳圖片", du.getAddTime());
JSONObject rowdata = new JSONObject();
rowdata.put("carID", carID);
rowdata.put("addTime", du.getAddTime());
JSONObject cpJson = new JSONObject();
cpJson.put("carID", carID);
cpJson.put("title", title);
cpJson.put("message", message);
cpJson.put("rowdata", rowdata);
retJson = ctpn_api.postCPPushNotification(cpJson);
String messageID = retJson.getString("messageID");
// JSONArray phoneArray = retJson.getJSONArray("phoneArray");
retJson = ctpn_api.postCPPushNotificationSend(carID, messageID);
} else if (null != pr) {
String phoneID = pr.getEncodedKey();
String title = "設備上傳記錄";
String message = String.format("設備於%s上傳圖片", du.getAddTime());
JSONObject rowdata = new JSONObject();
rowdata.put("phoneID", phoneID);
rowdata.put("addTime", du.getAddTime());
JSONObject cpJson = new JSONObject();
cpJson.put("phoneID", phoneID);
cpJson.put("title", title);
cpJson.put("message", message);
cpJson.put("rowdata", rowdata);
retJson = ctpn_api.postPCPushNotification(cpJson);
String messageID = retJson.getString("messageID");
// JSONArray phoneArray = retJson.getJSONArray("phoneArray");
retJson = ctpn_api.postPCPushNotificationSend(phoneID, messageID);
}
json.put("uploadKey", du.getEncodedKey());
json.put("addTime", du.getAddTime());
json.put("result", retJson);