@RequiresPermissions("cms:article:view")
  @RequestMapping(value = "form")
  public String form(Article article, Model model) {
    // 如果当前传参有子节点,则选择取消传参选择
    if (article.getCategory() != null && StringUtils.isNotBlank(article.getCategory().getId())) {
      List<Category> list =
          categoryService.findByParentId(article.getCategory().getId(), Site.getCurrentSiteId());
      if (list.size() > 0) {
        article.setCategory(null);
      } else {
        article.setCategory(categoryService.get(article.getCategory().getId()));
      }
    }
    article.setArticleData(articleDataService.get(article.getId()));
    model.addAttribute("article", article);
    CmsUtils.addViewConfigAttribute(model, article.getCategory());

    if (0 == article.getMsgType()) {
      return "modules/cms/articleForm";
    } else if (1 == article.getMsgType()) {
      return "modules/cms/articleSingleForm";
    } else if (2 == article.getMsgType()) {
      return "modules/cms/articleManyForm";
    }

    return "modules/cms/articleForm";
  }
 @ModelAttribute
 public Article get(@RequestParam(required = false) String id) {
   if (StringUtils.isNotBlank(id)) {
     return articleService.get(id);
   } else {
     return new Article();
   }
 }
Exemple #3
0
  private String queryKeywords(String rspMsg, List<ArticleF> wML, WeixinMessageF wm) {
    // 判断session是否过期,过期清理表并返回菜单序号
    int menuNo =
        weiXinSessionService.getMenuNo(
            wm.getFromUser(), StringUtils.parseDate2SecondStr(wm.getCreateDate()));
    List<WeiXinSessionPara> listWsp = new ArrayList<WeiXinSessionPara>();

    for (int i = 0; i < wML.size(); i++) {
      WeiXinSessionPara wsp = new WeiXinSessionPara();
      wsp.setOpenId(wm.getFromUser());
      wsp.setMenuNo(menuNo + i);
      if (CF.title_val2.equals(wML.get(i).getTitle())
          || CF.title_val4.equals(wML.get(i).getTitle())) { // 网点查询 和 ATM
        // 特殊处理
        if (wm.getLocX() == null
            || "".equals(wm.getLocX())) { // 判断是否需要用户输入当前位置信息 key值为0 需要用户输入当前地理位置信息
          wsp.setKey("0");
        } else { // 用户已经上传过当前地理位置信息
          wsp.setKey(String.valueOf(wm.getLocX() + "-" + wm.getLocY() + "-" + wm.getLocScale()));
        }
      } else { // 正常处理其他消息
        wsp.setKey(String.valueOf(wML.get(i).getId()));
      }
      wsp.setValue(wML.get(i).getTitle());
      weiXinSessionParaService.save(wsp);
      listWsp.add(wsp);
    }
    WeiXinSession wxs = weiXinSessionService.getByOpenId(wm.getFromUser());
    if (wxs != null) {
      wxs.setNextMenuNo(menuNo + wML.size());
      wxs.setLastVisitTime(StringUtils.parseDate2SecondStr(wm.getCreateDate()));
    } else {
      wxs = new WeiXinSession();
      wxs.setOpenId(wm.getFromUser());
      wxs.setLastVisitTime(StringUtils.parseDate2SecondStr(wm.getCreateDate()));
      wxs.setNextMenuNo(wML.size() + 1);
      wxs.setErrorNum(0);
    }
    weiXinSessionService.save(wxs);

    for (WeiXinSessionPara tmp : listWsp) {
      rspMsg += "\n【" + tmp.getMenuNo() + "】" + tmp.getValue();
    }
    return rspMsg;
  }
  @RequiresPermissions("cms:article:edit")
  @RequestMapping(value = "save")
  public String save(Article article, Model model, RedirectAttributes redirectAttributes) {
    if (!beanValidator(model, article)) {
      return form(article, model);
    }

    article.setDescription(Encodes.unescapeHtml(article.getDescription()));
    article.setDesJson(Encodes.unescapeXml(article.getDesJson()));

    articleService.save(article);
    addMessage(redirectAttributes, "保存消息'" + StringUtils.abbr(article.getTitle(), 50) + "'成功");
    String categoryId = article.getCategory() != null ? article.getCategory().getId() : null;
    return "redirect:"
        + adminPath
        + "/cms/article/?repage&category.id="
        + (categoryId != null ? categoryId : "");
  }
Exemple #5
0
  public String xmlToTextClass(String xml) {
    TextMessage textMsg = null;
    try {
      JAXBContext context = JAXBContext.newInstance(TextMessage.class);
      Unmarshaller um = context.createUnmarshaller();
      ByteArrayInputStream is = new ByteArrayInputStream(xml.getBytes());
      textMsg = (TextMessage) um.unmarshal(is);
    } catch (JAXBException e) {
      e.printStackTrace();
    }
    String rspMsg = "";
    try {
      if (textMsg == null) {
        return null;
      } else {

        /*TradingTips tips = null;
        tradingTipsMessage.pushMsg1(tips);
        System.out.println("xmlToTextClass-OK-------------------->>");
        */

        WeixinMessageF weixinMessage = new WeixinMessageF(textMsg);

        weixinMessage.setContent(textMsg.getContent().trim());
        weiXinMessageFService.save(weixinMessage);
        if (WeiXinUtils.isNumeric(weixinMessage.getContent())) { // 判断用户输入信息是否是数字
          // 首先判断session是否过期
          weiXinSessionService.isSessionOver(
              weixinMessage.getFromUser(),
              StringUtils.parseDate2SecondStr(weixinMessage.getCreateDate()));
          ;
          WeiXinSessionPara wxsp =
              weiXinSessionParaService.findByMenuNo(
                  weixinMessage.getFromUser(), weixinMessage.getContent());
          if (wxsp != null) { // session_para中查询到相应的code
            SubscribeEvent subEvent = new SubscribeEvent();
            subEvent.setEventKey(wxsp.getKey());
            subEvent.setValue(wxsp.getValue());
            subEvent.setCreateTime(StringUtils.parseDate2SecondStr(weixinMessage.getCreateDate()));
            subEvent.setFromUserName(weixinMessage.getFromUser());
            subEvent.setToUserName(weixinMessage.getToUser());
            return webmsg0101.pushClickMessage(subEvent); // 推送信息给用户
          }
        }
        // 用户输入信息不是数字 匹配消息 显示给用户

        List<ArticleF> article = articleFService.findByDescription(weixinMessage.getContent());

        if (article == null || article.size() == 0) { // 未匹配到相关信息
          // error
          rspMsg = CF.error_val;
          return Reply.rspTextMsg(weixinMessage.getFromUser(), weixinMessage.getToUser(), rspMsg);
        } else if (article.size() > 0) { // 匹配到相关信息
          rspMsg += CF.common_val1; // "您要查找的全部消息如下:"
          rspMsg = queryKeywords(rspMsg, article, weixinMessage); // 生成带编号消息
          return Reply.rspTextMsg(weixinMessage.getFromUser(), weixinMessage.getToUser(), rspMsg);
        }
      }
    } catch (Exception e) {
      e.printStackTrace();
    }
    return null;
  }