admin
2019-03-13 df03194e4b0c0737cf84127c4dd69d456e30ed24
fanli/src/main/java/com/yeshi/fanli/controller/admin/PushController.java
@@ -1,6 +1,8 @@
package com.yeshi.fanli.controller.admin;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.List;
import javax.annotation.Resource;
@@ -74,29 +76,41 @@
    * @throws Exception
    */
   @RequestMapping(value = "pushGoodsAll_f", method = RequestMethod.POST)
   public void pushGoods(Long uId, String url, String title, String content, PrintWriter out) throws Exception {
      String auctionId = null;
      if (!StringUtil.isNullOrEmpty(url) && url.contains("id=")) {
         String[] sts = url.split("\\?")[1].split("&");
         for (String st : sts)
            if (st.contains("id=")) {
               auctionId = st.replace("id=", "");
            }
      }
   public void pushGoods(Long uId, String url, String title, String content, String versions, PrintWriter out) throws Exception {
      try {
         String auctionId = null;
         if (!StringUtil.isNullOrEmpty(url) && url.contains("id=")) {
            String[] sts = url.split("\\?")[1].split("&");
            for (String st : sts)
               if (st.contains("id=")) {
                  auctionId = st.replace("id=", "");
               }
         }
      if (StringUtil.isNullOrEmpty(auctionId)) {
         out.print(JsonUtil.loadFalseResult("提取商品ID失败"));
         return;
      }
         if (StringUtil.isNullOrEmpty(auctionId)) {
            out.print(JsonUtil.loadFalseResult("提取商品ID失败"));
            return;
         }
      JSONObject json = IOSPushFactory.createGoodsPush(Long.parseLong(auctionId), title, content);
      if (json.toString().getBytes().length > 256) {
         out.print(JsonUtil.loadFalseResult("标题或内容过长,请删减后再试"));
         return;
      }
         JSONObject json = IOSPushFactory.createGoodsPush(Long.parseLong(auctionId), title, content);
         if (json.toString().getBytes().length > 256) {
            out.print(JsonUtil.loadFalseResult("标题或内容过长,请删减后再试"));
            return;
         }
      pushService.pushGoods(uId, url, title, content);
      out.print(JsonUtil.loadTrueResult("推送成功"));
         List<String> listVersion = null;
         if (versions != null && versions.trim().length() > 0) {
            listVersion  = Arrays.asList(versions.split(","));
         }
         pushService.pushGoods(uId, url, title, content, listVersion);
         out.print(JsonUtil.loadTrueResult("推送成功"));
      } catch (PushException e) {
         out.print(JsonUtil.loadFalseResult(e.getMsg()));
      } catch (Exception e) {
         out.print(JsonUtil.loadFalseResult("推送失败"));
         e.printStackTrace();
      }
   }
   /**
@@ -109,7 +123,7 @@
    * @throws Exception
    */
   @RequestMapping(value = "pushUrlAll_f", method = RequestMethod.POST)
   public void pushUrl(String url, String title, String content, PrintWriter out) throws Exception {
   public void pushUrl(String url, String title, String content, String versions, PrintWriter out) throws Exception {
      if (StringUtil.isNullOrEmpty(url) || StringUtil.isNullOrEmpty(title) || StringUtil.isNullOrEmpty(content)) {
         out.print(JsonUtil.loadFalseResult("请填写链接,标题与内容"));
         return;
@@ -120,8 +134,22 @@
         out.print(JsonUtil.loadFalseResult("标题或内容过长,请删减后再试"));
         return;
      }
      pushService.pushUrl(null, url, title, content);
      out.print(JsonUtil.loadTrueResult("推送成功"));
      try {
         List<String> listVersion = null;
         if (versions != null && versions.trim().length() > 0) {
            listVersion  = Arrays.asList(versions.split(","));
         }
         pushService.pushUrl(null, url, title, content, listVersion);
         out.print(JsonUtil.loadTrueResult("推送成功"));
      } catch (PushException e) {
         out.print(JsonUtil.loadFalseResult(e.getMsg()));
      } catch (Exception e) {
         out.print(JsonUtil.loadFalseResult("推送失败"));
         e.printStackTrace();
      }
   }
   /**
@@ -135,9 +163,23 @@
    * @throws Exception
    */
   @RequestMapping(value = "pushFanZNX_f", method = RequestMethod.POST)
   public void pushSystemZnx(Long uId, String title, String content, PrintWriter out) throws Exception {
      pushService.pushZNX(uId, title, content);
      out.print(JsonUtil.loadTrueResult("推送成功"));
   public void pushSystemZnx(Long uId, String title, String content, String versions, PrintWriter out) throws Exception {
      try {
         List<String> listVersion = null;
         if (versions != null && versions.trim().length() > 0) {
            listVersion  = Arrays.asList(versions.split(","));
         }
         pushService.pushZNX(uId, title, content, listVersion);
         out.print(JsonUtil.loadTrueResult("推送成功"));
      } catch (PushException e) {
         out.print(JsonUtil.loadFalseResult(e.getMsg()));
      } catch (Exception e) {
         out.print(JsonUtil.loadFalseResult("推送失败"));
         e.printStackTrace();
      }
   }
   /**
@@ -184,7 +226,7 @@
    * @throws Exception
    */
   @RequestMapping(value = "newPushGoodsAll")
   public void newPushGoodsAll(String callback, Long uid, String url, String title, String content, PrintWriter out)
   public void newPushGoodsAll(String callback, Long uid, String url, String title, String content, String versions, PrintWriter out)
         throws Exception {
      String auctionId = null;
@@ -208,8 +250,15 @@
      }
      try {
         pushService.pushGoods(uid, url, title, content);
         List<String> listVersion = null;
         if (versions != null && versions.trim().length() > 0) {
            listVersion  = Arrays.asList(versions.split(","));
         }
         pushService.pushGoods(uid, url, title, content, listVersion);
         JsonUtil.printMode(out, callback, JsonUtil.loadTrueResult("推送成功"));
      } catch (PushException e) {
         JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult(e.getMsg()));
      } catch (Exception e) {
         JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("推送失败"));
         e.printStackTrace();
@@ -226,7 +275,7 @@
    * @throws Exception
    */
   @RequestMapping(value = "newPushUrlAll")
   public void newPushUrlAll(String callback, String url, String title, String content, PrintWriter out) {
   public void newPushUrlAll(String callback, String url, String title, String content, String versions, PrintWriter out) {
      if (StringUtil.isNullOrEmpty(url) || StringUtil.isNullOrEmpty(title) || StringUtil.isNullOrEmpty(content)) {
         JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("请填写链接,标题与内容"));
@@ -240,9 +289,16 @@
      }
      try {
         pushService.pushUrl(null, url, title, content);
         List<String> listVersion = null;
         if (versions != null && versions.trim().length() > 0) {
            listVersion  = Arrays.asList(versions.split(","));
         }
         pushService.pushUrl(null, url, title, content, listVersion);
         JsonUtil.printMode(out, callback, JsonUtil.loadTrueResult("推送成功"));
      } catch (PushException e) {
         JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult(e.getMsg()));
      } catch (Exception e) {
         JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("推送失败"));
         e.printStackTrace();
      }
@@ -258,7 +314,7 @@
    * @throws Exception
    */
   @RequestMapping(value = "newPushFanZNX")
   public void newPushFanZNX(String callback, String uids, String title, String content, PrintWriter out) {
   public void newPushFanZNX(String callback, String uids, String title, String content, String versions, PrintWriter out) {
      if (StringUtil.isNullOrEmpty(title) || StringUtil.isNullOrEmpty(content)) {
         JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("请填写标题与内容"));
@@ -271,14 +327,19 @@
         if (uids != null) {
            uidArray = uids.split(",");
         }
         List<String> listVersion = null;
         if (versions != null && versions.trim().length() > 0) {
            listVersion  = Arrays.asList(versions.split(","));
         }
         if (uidArray == null) {
            pushService.pushZNX(null, title, content);
            pushService.pushZNX(null, title, content, listVersion);
         } else {
            for (int i = 0; i < uidArray.length; i++) {
               String str_uid = uidArray[i];
               if (str_uid != null && str_uid.trim().length() > 0) {
                  pushService.pushZNX(Long.parseLong(str_uid), title, content);
                  pushService.pushZNX(Long.parseLong(str_uid), title, content, listVersion);
                  userSystemMsgService.addUserSystemMsg(Long.parseLong(str_uid), UserSystemMsgTypeEnum.question,
                        title, content, UserSystemMsg.TIME_TAG_EMERGENT, null);
@@ -304,7 +365,7 @@
    * @throws Exception
    */
   @RequestMapping(value = "pushBaiChuan")
   public void pushBaiChuan(String callback, String uids, String title, String content, String url, PrintWriter out) {
   public void pushBaiChuan(String callback, String uids, String title, String content, String url, String versions, PrintWriter out) {
      if (StringUtil.isNullOrEmpty(title) || StringUtil.isNullOrEmpty(content)) {
         JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("请填写标题与内容"));
@@ -318,13 +379,18 @@
            uidArray = uids.split(",");
         }
         List<String> listVersion = null;
         if (versions != null && versions.trim().length() > 0) {
            listVersion  = Arrays.asList(versions.split(","));
         }
         if (uidArray == null) {
            pushService.pushBaiChuanUrl(null, title, content, url);
            pushService.pushBaiChuanUrl(null, title, content, url, listVersion);
         } else {
            for (int i = 0; i < uidArray.length; i++) {
               String str_uid = uidArray[i];
               if (str_uid != null && str_uid.trim().length() > 0) {
                  pushService.pushBaiChuanUrl(Long.parseLong(str_uid), title, content, url);
                  pushService.pushBaiChuanUrl(Long.parseLong(str_uid), title, content, url, listVersion);
               }
            }
         }