admin
2019-03-15 3cf41feae65a864fc00d72fdd09a676372fc3b27
fanli/src/main/java/com/yeshi/fanli/controller/admin/PushController.java
@@ -1,6 +1,7 @@
package com.yeshi.fanli.controller.admin;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
@@ -8,23 +9,16 @@
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.yeshi.utils.HttpUtil;
import org.yeshi.utils.JsonUtil;
import com.yeshi.fanli.entity.bus.msg.UserSystemMsg;
import com.yeshi.fanli.entity.bus.msg.UserSystemMsgTypeEnum;
import com.yeshi.fanli.exception.PushException;
import com.yeshi.fanli.service.inter.config.ConfigService;
import com.yeshi.fanli.service.inter.config.SystemService;
import com.yeshi.fanli.service.inter.msg.UserSystemMsgService;
import com.yeshi.fanli.service.inter.push.PushRecordService;
import com.yeshi.fanli.service.inter.push.PushService;
import com.yeshi.fanli.service.inter.user.AccountMessageService;
import com.yeshi.fanli.service.inter.user.SystemZnxService;
import com.yeshi.fanli.util.StringUtil;
import com.yeshi.fanli.util.factory.IOSPushFactory;
import org.yeshi.utils.HttpUtil;
import org.yeshi.utils.JsonUtil;
import net.sf.json.JSONObject;
@@ -40,147 +34,13 @@
   public final static int BAICHUAN = 6; // 站内推送
   public final static int WELFARE_CENTER = 7; // 福利中心
   @Resource
   private PushRecordService pushRecordService;
   @Resource
   private ConfigService configService;
   @Resource
   private SystemZnxService systemZnxService;
   @Resource
   private AccountMessageService accountMessageService;
   @Resource
   private SystemService systemService;
   @Resource
   private PushService pushService;
   @Resource
   private UserSystemMsgService userSystemMsgService;
   /**
    * 商品推送
    *
    * @param uId
    *            -用户ID 可为空
    * @param url
    *            -商品链接
    * @param title
    *            -推送标题
    * @param content
    *            -推送内容
    * @param out
    * @throws Exception
    */
   @RequestMapping(value = "pushGoodsAll_f", method = RequestMethod.POST)
   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;
         }
         JSONObject json = IOSPushFactory.createGoodsPush(Long.parseLong(auctionId), title, content);
         if (json.toString().getBytes().length > 256) {
            out.print(JsonUtil.loadFalseResult("标题或内容过长,请删减后再试"));
            return;
         }
         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();
      }
   }
   /**
    * 网页推送
    *
    * @param url
    * @param title
    * @param content
    * @param out
    * @throws Exception
    */
   @RequestMapping(value = "pushUrlAll_f", method = RequestMethod.POST)
   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;
      }
      JSONObject json = IOSPushFactory.createURLPush(HttpUtil.getShortLink(url), title, content);
      if (json.toString().getBytes().length > 256) {
         out.print(JsonUtil.loadFalseResult("标题或内容过长,请删减后再试"));
         return;
      }
      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();
      }
   }
   /**
    *
    * 方法说明: 站内信推送
    *
    * @author mawurui createTime 2018年3月12日 下午5:45:00
    * @param uId
    * @param title
    * @param content
    * @throws Exception
    */
   @RequestMapping(value = "pushFanZNX_f", method = RequestMethod.POST)
   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();
      }
   }
   /**
    * 短链接转换
@@ -226,7 +86,7 @@
    * @throws Exception
    */
   @RequestMapping(value = "newPushGoodsAll")
   public void newPushGoodsAll(String callback, Long uid, String url, String title, String content, String versions, PrintWriter out)
   public void newPushGoodsAll(String callback, String url, String title, String content, String uids, String versions, PrintWriter out)
         throws Exception {
      String auctionId = null;
@@ -250,12 +110,48 @@
      }
      try {
         List<String> listVersion = null;
         if (versions != null && versions.trim().length() > 0) {
            listVersion  = Arrays.asList(versions.split(","));
         List<String> listuid = null;
         if (uids != null && uids.trim().length() > 0) {
            listuid = Arrays.asList(uids.split(","));
            if (listuid == null || listuid.size() == 0) {
               JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("用户id格式不正确"));
               return;
            }
         }
         
         pushService.pushGoods(uid, url, title, content, listVersion);
         List<String> listVersion = null;
         if (versions != null && versions.trim().length() > 0) {
            List<String> list = Arrays.asList(versions.split(","));
            if (list != null && list.size() > 0) {
               listVersion = new ArrayList<String>();
               for (String version: list) {
                  if (version != null && version.trim().length() > 0) {
                     listVersion.add(version.trim());
                  }
               }
            }
            if (listVersion == null || listVersion.size() == 0) {
               JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("版本号格式不正确"));
               return;
            }
         }
         if (listuid == null) {
            // 全推
            pushService.pushGoods(null, title, content, url, listVersion);
         } else {
            // 部分用户推送
            for (String str_uid: listuid) {
               if (str_uid != null && str_uid.trim().length() > 0) {
                  pushService.pushGoods(Long.parseLong(str_uid), url, title, content, listVersion);
               }
            }
         }
         JsonUtil.printMode(out, callback, JsonUtil.loadTrueResult("推送成功"));
      } catch (PushException e) {
         JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult(e.getMsg()));
@@ -275,7 +171,8 @@
    * @throws Exception
    */
   @RequestMapping(value = "newPushUrlAll")
   public void newPushUrlAll(String callback, String url, String title, String content, String versions, PrintWriter out) {
   public void newPushUrlAll(String callback, String url, String title, String content, String uids,
         String versions, PrintWriter out) {
      if (StringUtil.isNullOrEmpty(url) || StringUtil.isNullOrEmpty(title) || StringUtil.isNullOrEmpty(content)) {
         JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("请填写链接,标题与内容"));
@@ -289,12 +186,47 @@
      }
      try {
         List<String> listVersion = null;
         if (versions != null && versions.trim().length() > 0) {
            listVersion  = Arrays.asList(versions.split(","));
         List<String> listuid = null;
         if (uids != null && uids.trim().length() > 0) {
            listuid = Arrays.asList(uids.split(","));
            if (listuid == null || listuid.size() == 0) {
               JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("用户id格式不正确"));
               return;
            }
         }
         
         pushService.pushUrl(null, url, title, content, listVersion);
         List<String> listVersion = null;
         if (versions != null && versions.trim().length() > 0) {
            List<String> list = Arrays.asList(versions.split(","));
            if (list != null && list.size() > 0) {
               listVersion = new ArrayList<String>();
               for (String version: list) {
                  if (version != null && version.trim().length() > 0) {
                     listVersion.add(version.trim());
                  }
               }
            }
            if (listVersion == null || listVersion.size() == 0) {
               JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("版本号格式不正确"));
               return;
            }
         }
         if (listuid == null) {
            // 全推
            pushService.pushUrl(null, title, content, url, listVersion);
         } else {
            // 部分推送
            for (String str_uid: listuid) {
               if (str_uid != null && str_uid.trim().length() > 0) {
                  pushService.pushUrl(Long.parseLong(str_uid), url, title, content, listVersion);
               }
            }
         }
         JsonUtil.printMode(out, callback, JsonUtil.loadTrueResult("推送成功"));
      } catch (PushException e) {
         JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult(e.getMsg()));
@@ -323,21 +255,40 @@
      try {
         String[] uidArray = null;
         if (uids != null) {
            uidArray = uids.split(",");
         List<String> listuid = null;
         if (uids != null && uids.trim().length() > 0) {
            listuid = Arrays.asList(uids.split(","));
            if (listuid == null || listuid.size() == 0) {
               JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("用户id格式不正确"));
               return;
            }
         }
         
         List<String> listVersion = null;
         if (versions != null && versions.trim().length() > 0) {
            listVersion  = Arrays.asList(versions.split(","));
            List<String> list = Arrays.asList(versions.split(","));
            if (list != null && list.size() > 0) {
               listVersion = new ArrayList<String>();
               for (String version: list) {
                  if (version != null && version.trim().length() > 0) {
                     listVersion.add(version.trim());
                  }
               }
            }
            if (listVersion == null || listVersion.size() == 0) {
               JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("版本号格式不正确"));
               return;
            }
         }
         
         if (uidArray == null) {
         if (listuid == null) {
            // 全推
            pushService.pushZNX(null, title, content, listVersion);
         } else {
            for (int i = 0; i < uidArray.length; i++) {
               String str_uid = uidArray[i];
            // 部分推送
            for (String str_uid: listuid) {
               if (str_uid != null && str_uid.trim().length() > 0) {
                  pushService.pushZNX(Long.parseLong(str_uid), title, content, listVersion);
@@ -374,21 +325,40 @@
      try {
         String[] uidArray = null;
         if (uids != null) {
            uidArray = uids.split(",");
         }
         List<String> listVersion = null;
         if (versions != null && versions.trim().length() > 0) {
            listVersion  = Arrays.asList(versions.split(","));
         List<String> listuid = null;
         if (uids != null && uids.trim().length() > 0) {
            listuid = Arrays.asList(uids.split(","));
            if (listuid == null || listuid.size() == 0) {
               JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("用户id格式不正确"));
               return;
            }
         }
         
         if (uidArray == null) {
         List<String> listVersion = null;
         if (versions != null && versions.trim().length() > 0) {
            List<String> list = Arrays.asList(versions.split(","));
            if (list != null && list.size() > 0) {
               listVersion = new ArrayList<String>();
               for (String version: list) {
                  if (version != null && version.trim().length() > 0) {
                     listVersion.add(version.trim());
                  }
               }
            }
            if (listVersion == null || listVersion.size() == 0) {
               JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("版本号格式不正确"));
               return;
            }
         }
         if (listuid == null) {
            // 全推
            pushService.pushBaiChuanUrl(null, title, content, url, listVersion);
         } else {
            for (int i = 0; i < uidArray.length; i++) {
               String str_uid = uidArray[i];
            // 部分推送
            for (String str_uid: listuid) {
               if (str_uid != null && str_uid.trim().length() > 0) {
                  pushService.pushBaiChuanUrl(Long.parseLong(str_uid), title, content, url, listVersion);
               }