String filter = String.format("carID=='%s' && messageID=='%s'", carID, messageID);
List<CarPhonePushNotification> cppn_list = cppn_service.getPaginationData(filter).getResultList();
if (null == cppn_list || cppn_list.size() == 0)
throw new Error("該messageID無法與carID對應");
PushNotificationMessage pnm = pnm_service.getDataByID(messageID);
if (null == pnm)
throw new Error("該messageID不合法");
// 產生phoneRegIDList
List<String> devices = new ArrayList<String>();
for (CarPhonePushNotification o : cppn_list) {
// 判斷是否傳送過
if (!o.getIsSend()) {
PhoneReg pr = pr_service.getDataByID(o.getPhoneID());
devices.add(pr.getRegisterID());
o.setIsSend(true);
o.setSendTime(CTCommon.getNowTime());
cppn_service.modify(o);
}
}
if (devices.size() == 0) {
throw new Error("該carID的所有的message都已傳送過");
}
// 取得message的內容
String title = pnm.getTitle();
String message = pnm.getMessage();
String rowdata = pnm.getRowdata();
Map<String, String> extraMap = new HashMap<String, String>();
extraMap.put("rowdata", rowdata);
// Create a GCM sender
MulticastResult result = sendMessageToDevice(CTCommon.API_KEY, devices, title, message, extraMap);