Package org.luke.ct.model

Examples of org.luke.ct.model.PhoneReg


    // 設定5/100的機率下,會去清除過期的資料
    Random random = new Random(System.currentTimeMillis());
    if (random.nextDouble() < 0.05)
      CleanOutOfDate();

    PhoneReg pr = pr_service.getDataByID(phoneID);
    // 該phoneID已註冊
    if (null != pr) {
      log.info("該phoneID已註冊:" + phoneID);
      log.info("使用randomID進行連結:" + randomID);
      String filter = String.format("randomID=='%s'", randomID);
View Full Code Here


    System.out.println("get phoneID = " + phoneID);
    System.out.println("get carID = " + carID);

    // 檢查phoneID是否合法
    PhoneReg pr = pr_service.getDataByID(phoneID);
    if (null == pr)
      throw new Error("該phoneID尚未註冊");

    // 找出和該phoneID連結的carID list
    String filter = String.format("phoneID=='%s'", phoneID);
View Full Code Here

  @ApiMethod(name = "pcpn.send", httpMethod = HttpMethod.POST)
  public JSONObject postPCPushNotificationSend(@Named("phoneID") String phoneID, @Named("messageID") String messageID) {
    JSONObject retJson = null;
    // 檢查phoneID是否合法
    PhoneReg pr = pr_service.getDataByID(phoneID);
    if (null == pr)
      throw new Error("該phoneID尚未註冊");

    // 找出和該phoneID連結的message
    String filter = String.format("phoneID=='%s' && messageID=='%s'", phoneID, messageID);
View Full Code Here

    // 產生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);
      }
    }
View Full Code Here

    log.info("get phoneID = " + phoneID);
    log.info("get carID = " + carID);
    log.info("get lastTime = " + lastTime);

    // 檢查phoneID是否合法
    PhoneReg pr = pr_service.getDataByID(phoneID);
    if (null == pr)
      throw new Error("該phoneID尚未註冊");

    // 檢查carID是否合法
    CarReg cr = cr_service.getDataByID(carID);
View Full Code Here

    int i = 0;
    log.info("count=" + list.size());
    for (PhoneReg o : list) {
      log.info("index:" + (++i) + ", PhoneReg=" + JSON.toJSONString(o));
    }
    PhoneReg reg = pr_service.getDataByID(id);
    return reg;
  }
View Full Code Here

    return pr_service.getPaginationData().getResultList();
  }

  @ApiMethod(name = "preg.merge", httpMethod = HttpMethod.POST)
  public PhoneReg postPhoneRegisterMerge(PhoneReg cr, HttpServletRequest req) {
    PhoneReg retPR = null;
    // check deviceID, appVersion
    if (StringUtils.isNotBlank(cr.getDeviceID()) && StringUtils.isNotBlank(cr.getAppVersion())) {
      String dateStr = CTCommon.getNowTime();
      String filter = String.format("deviceID=='%s' && appVersion=='%s'", cr.getDeviceID(), cr.getAppVersion());
      QueryResult<PhoneReg> qr = pr_service.getPaginationData(filter);
      // 第一次註冊,新增資料
      if (qr.getTotalRecord() == 0) {
        retPR = new PhoneReg();
        retPR.setAddTime(dateStr);
        retPR.setAppVersion(cr.getAppVersion());
        retPR.setDeviceID(cr.getDeviceID());
        retPR.setDeviceIP(req.getRemoteAddr());
        retPR.setModTime(dateStr);
        retPR.setRegisterID(cr.getRegisterID());
        retPR.setSenderID(cr.getSenderID());
        pr_service.add(retPR);
        log.info("新增一筆手機註冊記錄:" + JSON.toJSONString(retPR));
      } else if (qr.getTotalRecord() == 1) {
        retPR = qr.getResultList().get(0);
        retPR.setAppVersion(cr.getAppVersion());
        retPR.setDeviceID(cr.getDeviceID());
        retPR.setDeviceIP(req.getRemoteAddr());
        retPR.setModTime(dateStr);
        retPR.setRegisterID(cr.getRegisterID());
        retPR.setSenderID(cr.getSenderID());
        pr_service.modify(retPR);
        log.info("修改一筆手機註冊記錄:" + JSON.toJSONString(retPR));
      } else {
        log.severe("手機記錄數目異常,不處理");
      }
View Full Code Here

    JSONObject retJson = null;
    // 檢查是否為合法的carID
    CarReg cr = cr_service.getDataByID(devID);
    if (null == cr) {
      // 檢查是否為合法的phoneID
      PhoneReg pr = pr_service.getDataByID(devID);
      if (null == pr)
        throw new Error("提供的ID尚未註冊, devID = " + devID);
    }

    retJson = new JSONObject();
View Full Code Here

      return;
    }

    // 檢查是否為合法的carID
    CarReg cr = null;
    PhoneReg pr = null;
    cr = cr_service.getDataByID(devID);
    if (null == cr) {
      // 檢查是否為合法的phoneID
      pr = pr_service.getDataByID(devID);
      if (null == pr) {
        sendError(res, "提供的ID尚未註冊, devID = " + devID);
        return;
      }
    }

    List<BlobKey> blobs = blobstoreService.getUploads(req).get("myFile");
    BlobKey blobKey = blobs.get(0);
    if (null == blobKey) {
      sendError(res, "無法正常儲存上傳的檔案");
      return;
    }

    ImagesService imagesService = ImagesServiceFactory.getImagesService();
    ServingUrlOptions servingOptions = ServingUrlOptions.Builder.withBlobKey(blobKey);

    String servingUrl = imagesService.getServingUrl(servingOptions);

    res.setStatus(HttpServletResponse.SC_OK);
    res.setContentType("application/json");

    // 二種方式都能存取上傳的圖檔
    JSONObject json = new JSONObject();
    // json.put("serving_url", servingUrl);
    // json.put("blob_key", blobKey.getKeyString());
    // json.put("direct_url", "/serve?blob_key=" + blobKey.getKeyString());

    // 儲存在db的動作
    DeviceUpload du = new DeviceUpload();
    du.setDevID(devID);
    du.setMySerial(mySerial);
    du.setServing_url(servingUrl);
    du.setBlob_key(blobKey.getKeyString());
    du.setAddTime(CTCommon.getNowTime());
    du_service.add(du);
    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());
View Full Code Here

TOP

Related Classes of org.luke.ct.model.PhoneReg

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.