Пример #1
0
  /**
   * 保存
   *
   * @param shareHref
   * @param op add:添加、modify:修改
   */
  @RequestMapping(value = "/save")
  public void save(@ModelAttribute ShareHref shareHref, @RequestParam String op) {

    Map<String, Object> map = new HashMap<String, Object>();
    map.put("code", "1");
    map.put("msg", "保存成功!");

    try {
      // 图片路径
      SysDictMain sysDictMain = DictUtil.getMainByCode("shareHref_path");

      if (sysDictMain != null && StringUtils.isNotBlank(sysDictMain.getDictValue())) {

        shareHref.setUnitId(getLoginUnitId());
        shareHref.setUnitType(getLoginUnit().getUnitType());
        shareHref.setZoneCode(getLoginUnit().getZoneCode());

        shareHrefService.save(request, shareHref, op, sysDictMain.getDictValue());
        addSaveLog(op, shareHref, OpRresult.success + "", "分享链接添加成功!");

      } else {
        map.put("code", "0");
        map.put("msg", "请维护推广活动图片上传路径,编码为:promoteActivity_path!");
      }

    } catch (Exception e) {
      logger.error(e.getMessage(), e);
      map.put("code", "0");
      map.put("msg", "保存失败!");
      addSaveLog(op, shareHref, OpRresult.fail + "", "分享链接添加失败!");
    }

    outJson(map);
  }
  /**
   * 消息推送
   *
   * @param findActivity
   */
  public void pushMsg(FindActivity findActivity) {

    String describtion = PushMsgType.xiaoDaNews.text;
    SysDictDetail sysDictDetail =
        DictUtil.getDetailByCode(1, "pushMsgDescModel", "xiaoDaNewsModel");
    if (null != sysDictDetail
        && null != sysDictDetail.getValue()
        && !"".equals(sysDictDetail.getValue())) {
      describtion = sysDictDetail.getValue();
    }

    Map<String, Object> descMap = new HashMap<String, Object>();
    descMap.put("findActivity", findActivity);
    describtion = FreeMarkerUtil.getContentFromStringTemplate(descMap, describtion);

    FindService findService = findServiceDao.getByServiceCode("xiaodakuaibao");

    String pushUrl = SysBaseUtil.XDKB_URL + "?id=" + findActivity.getId();

    String body =
        PushUtil.getBody(PushMsgType.xiaoDaNews.value, 0, pushUrl, findService.getUrlParams());

    String sendDate = "";
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd hh:mm");
    PushMsg pushMsg = new PushMsg();
    PushToData toData = new PushToData();

    SysUnits sysUnits = sysUnitsDao.get(findActivity.getUnitId());
    String tag = ""; // 推送区域
    if (!"1".equals(sysUnits.getZoneCode())) {
      tag = sysUnits.getZoneCode();
      toData.setIsAll(0);
    } else {
      toData.setIsAll(1);
    }

    pushMsg.setTitle(PushMsgType.xiaoDaNews.title);
    pushMsg.setDescribtion(describtion);
    pushMsg.setBody(body);
    pushMsg.setCreateDate(DateUtil.getSystemTime());
    pushMsg.setTag(tag);
    pushMsg.setMto(tag);
    pushMsg.setDatasourceId(String.valueOf(findActivity.getId()));
    pushMsg.setDatasourceType(PushUtil.PushLoginType.datasourceType.value);

    toData.setTag(tag); // 推送区域
    toData.setCreateDate(DateUtil.getSystemTime());
    toData.setDatasourceId(String.valueOf(findActivity.getId()));
    toData.setDatasourceType(PushUtil.PushLoginType.datasourceType.value);
    toData.setMto(tag);

    try {
      if (0 == findActivity.getPushType()) { // 本月每天推送
        java.util.Calendar cal = java.util.Calendar.getInstance();
        // 获取当月共多少天
        int maxDay = cal.getActualMaximum(java.util.Calendar.DAY_OF_MONTH);
        // 获取当天日期
        int currentDay = cal.get(java.util.Calendar.DATE);

        // 获取当前年月
        Date d = new Date();
        SimpleDateFormat sdf2 = new SimpleDateFormat("yyyy-MM");
        String dateNowStr = sdf2.format(d);

        // 计算推送天数
        int pushDay = maxDay - currentDay;
        if (pushDay > 0) { // 剩余推送天数
          for (int i = 1; i <= pushDay; i++) {
            for (int j = 1; j <= findActivity.getPushTimes(); j++) {
              if (j == 1) {
                sendDate = findActivity.getPushDate1();
              } else if (j == 2) {
                sendDate = findActivity.getPushDate2();
              } else if (j == 3) {
                sendDate = findActivity.getPushDate3();
              } else if (j == 4) {
                sendDate = findActivity.getPushDate4();
              } else if (j == 5) {
                sendDate = findActivity.getPushDate5();
              } else if (j == 6) {
                sendDate = findActivity.getPushDate6();
              }

              String toSendDate;
              if ((currentDay + pushDay) < 10) {
                toSendDate =
                    dateNowStr + "-" + "0" + String.valueOf(currentDay + pushDay) + " " + sendDate;
              } else {
                toSendDate =
                    dateNowStr + "-" + String.valueOf(currentDay + pushDay) + " " + sendDate;
              }

              // 设置推送时间
              pushMsg.setSendDate(sdf.parse(toSendDate));
              toData.setSendDate(sdf.parse(toSendDate));

              // 安卓推送
              pushMsg.setType(Integer.valueOf(PushLoginType.androidApp.value));
              toData.setLoginType(PushLoginType.androidApp.value);
              PushUtil.doPush(pushMsg, toData);

              // ios推送
              pushMsg.setType(Integer.valueOf(PushLoginType.iosApp.value));
              toData.setLoginType(PushLoginType.iosApp.value);
              PushUtil.doPush(pushMsg, toData);
            }
          }
        }

      } else if (1 == findActivity.getPushType()) { // 仅推一天
        // 获取当前年月
        Date d = new Date();
        SimpleDateFormat sdf2 = new SimpleDateFormat("yyyy-MM-dd");
        String dateNowStr = sdf2.format(d);

        for (int j = 1; j <= findActivity.getPushTimes(); j++) {
          if (j == 1) {
            sendDate = findActivity.getPushDate1();
          } else if (j == 2) {
            sendDate = findActivity.getPushDate2();
          } else if (j == 3) {
            sendDate = findActivity.getPushDate3();
          } else if (j == 4) {
            sendDate = findActivity.getPushDate4();
          } else if (j == 5) {
            sendDate = findActivity.getPushDate5();
          } else if (j == 6) {
            sendDate = findActivity.getPushDate6();
          }

          String toSendDate = dateNowStr + " " + sendDate;

          // 设置推送时间
          pushMsg.setSendDate(sdf.parse(toSendDate));
          toData.setSendDate(sdf.parse(toSendDate));

          // 安卓推送
          pushMsg.setType(Integer.valueOf(PushLoginType.androidApp.value));
          toData.setLoginType(PushLoginType.androidApp.value);
          PushUtil.doPush(pushMsg, toData);

          // ios推送
          pushMsg.setType(Integer.valueOf(PushLoginType.iosApp.value));
          toData.setLoginType(PushLoginType.iosApp.value);
          PushUtil.doPush(pushMsg, toData);
        }

      } else { // 仅推一次,设置推送时间
        pushMsg.setSendDate(findActivity.getPushDate());
        toData.setSendDate(findActivity.getPushDate());

        // 安卓推送
        pushMsg.setType(Integer.valueOf(PushLoginType.androidApp.value));
        toData.setLoginType(PushLoginType.androidApp.value);
        PushUtil.doPush(pushMsg, toData);

        // ios推送
        pushMsg.setType(Integer.valueOf(PushLoginType.iosApp.value));
        toData.setLoginType(PushLoginType.iosApp.value);
        PushUtil.doPush(pushMsg, toData);
      }

    } catch (ParseException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
  }