From fb885c8bff26484f2bb21e697f182cc35bc4fa63 Mon Sep 17 00:00:00 2001
From: yujian <yujian@163.com>
Date: 星期二, 12 五月 2020 15:27:08 +0800
Subject: [PATCH] 2.1.1 新需求
---
fanli/src/main/java/com/yeshi/fanli/controller/admin/PushController.java | 212 ++++++++++++++++++++++-------------------------------
1 files changed, 88 insertions(+), 124 deletions(-)
diff --git a/fanli/src/main/java/com/yeshi/fanli/controller/admin/PushController.java b/fanli/src/main/java/com/yeshi/fanli/controller/admin/PushController.java
index 4d914e2..2e12654 100644
--- a/fanli/src/main/java/com/yeshi/fanli/controller/admin/PushController.java
+++ b/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;
@@ -11,9 +12,11 @@
import org.yeshi.utils.HttpUtil;
import org.yeshi.utils.JsonUtil;
+import com.google.gson.Gson;
+import com.google.gson.reflect.TypeToken;
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.exception.push.PushException;
import com.yeshi.fanli.service.inter.msg.UserSystemMsgService;
import com.yeshi.fanli.service.inter.push.PushService;
import com.yeshi.fanli.util.StringUtil;
@@ -24,15 +27,6 @@
@Controller(value = "adminPushController")
@RequestMapping("admin/new/api/v1/push")
public class PushController {
-
- public final static int GOODS = 1; // 鍟嗗搧鎺ㄩ��
- public final static int URL = 2; // 缃戦〉鎺ㄩ��
- public final static int DETAIL = 3; // 璇︽儏鎺ㄩ��
- public final static int ZNX = 4; // 绔欏唴鎺ㄩ��
- public final static int WEEX = 5; // 绔欏唴鎺ㄩ��
- public final static int BAICHUAN = 6; // 绔欏唴鎺ㄩ��
- public final static int WELFARE_CENTER = 7; // 绂忓埄涓績
-
@Resource
private PushService pushService;
@@ -70,78 +64,6 @@
}
}
- /**
- * 鍟嗗搧鎺ㄩ�� -(鏂板悗鍙�)
- *
- * @param uId
- * -鐢ㄦ埛ID 鍙负绌�
- * @param url
- * -鍟嗗搧閾炬帴
- * @param title
- * -鎺ㄩ�佹爣棰�
- * @param content
- * -鎺ㄩ�佸唴瀹�
- * @param out
- * @throws Exception
- */
- @RequestMapping(value = "newPushGoodsAll")
- public void newPushGoodsAll(String callback, String url, String title, String content, String uids, String versions, 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=", "");
- }
- }
-
- if (StringUtil.isNullOrEmpty(auctionId)) {
- JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("鎻愬彇鍟嗗搧ID澶辫触"));
- return;
- }
-
- JSONObject json = IOSPushFactory.createGoodsPush(Long.parseLong(auctionId), title, content);
- if (json.toString().getBytes().length > 256) {
- JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("鏍囬鎴栧唴瀹硅繃闀匡紝璇峰垹鍑忓悗鍐嶈瘯"));
- return;
- }
-
- 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(","));
- }
-
- if (uidArray == null) {
- // 鍏ㄦ帹
- pushService.pushGoods(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.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()));
- } catch (Exception e) {
- JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("鎺ㄩ�佸け璐�"));
- e.printStackTrace();
- }
- }
/**
* 缃戦〉鎺ㄩ�� -(鏂板悗鍙�)
@@ -154,7 +76,7 @@
*/
@RequestMapping(value = "newPushUrlAll")
public void newPushUrlAll(String callback, String url, String title, String content, String uids,
- String versions, PrintWriter out) {
+ String arrayIOS, String arrayAndroid, PrintWriter out) {
if (StringUtil.isNullOrEmpty(url) || StringUtil.isNullOrEmpty(title) || StringUtil.isNullOrEmpty(content)) {
JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("璇峰~鍐欓摼鎺ワ紝鏍囬涓庡唴瀹�"));
@@ -169,26 +91,32 @@
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) {
+ if ((arrayIOS == null || arrayIOS.trim().length() == 0)
+ && (arrayAndroid == null || arrayAndroid.trim().length() == 0)) {
+ JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("鎺ㄩ�佺増鏈笉鑳戒负绌�"));
+ return;
+ }
+
+ List<String> listIOS = convertList(arrayIOS);
+ List<String> listAndroid = convertList(arrayAndroid);
+
+ if (listuid == null) {
// 鍏ㄦ帹
- pushService.pushUrl(null, title, content, url, listVersion);
+ pushService.pushUrl(null, title, content, url, listIOS, listAndroid);
} 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.pushUrl(Long.parseLong(str_uid), url, title, content, listVersion);
+ pushService.pushUrl(Long.parseLong(str_uid), title, content, url, listIOS, listAndroid);
}
}
}
@@ -212,7 +140,8 @@
* @throws Exception
*/
@RequestMapping(value = "newPushFanZNX")
- public void newPushFanZNX(String callback, String uids, String title, String content, String versions, PrintWriter out) {
+ public void newPushFanZNX(String callback, String uids, String title, String content, String arrayIOS,
+ String arrayAndroid, PrintWriter out) {
if (StringUtil.isNullOrEmpty(title) || StringUtil.isNullOrEmpty(content)) {
JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("璇峰~鍐欐爣棰樹笌鍐呭"));
@@ -221,25 +150,33 @@
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(","));
- }
+
+ if ((arrayIOS == null || arrayIOS.trim().length() == 0)
+ && (arrayAndroid == null || arrayAndroid.trim().length() == 0)) {
+ JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("鎺ㄩ�佺増鏈笉鑳戒负绌�"));
+ return;
+ }
- if (uidArray == null) {
+ List<String> listIOS = convertList(arrayIOS);
+ List<String> listAndroid = convertList(arrayAndroid);
+
+ if (listuid == null) {
// 鍏ㄦ帹
- pushService.pushZNX(null, title, content, listVersion);
+ pushService.pushZNX(null, title, content, listIOS, listAndroid);
} 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);
+ pushService.pushZNX(Long.parseLong(str_uid), title, content, listIOS, listAndroid);
userSystemMsgService.addUserSystemMsg(Long.parseLong(str_uid), UserSystemMsgTypeEnum.question,
title, content, UserSystemMsg.TIME_TAG_EMERGENT, null);
@@ -265,7 +202,8 @@
* @throws Exception
*/
@RequestMapping(value = "pushBaiChuan")
- public void pushBaiChuan(String callback, String uids, String title, String content, String url, String versions, PrintWriter out) {
+ public void pushBaiChuan(String callback, String uids, String title, String content, String url, String arrayIOS,
+ String arrayAndroid, PrintWriter out) {
if (StringUtil.isNullOrEmpty(title) || StringUtil.isNullOrEmpty(content)) {
JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("璇峰~鍐欐爣棰樹笌鍐呭"));
@@ -274,25 +212,32 @@
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) {
+ if ((arrayIOS == null || arrayIOS.trim().length() == 0)
+ && (arrayAndroid == null || arrayAndroid.trim().length() == 0)) {
+ JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("鎺ㄩ�佺増鏈笉鑳戒负绌�"));
+ return;
+ }
+
+ List<String> listIOS = convertList(arrayIOS);
+ List<String> listAndroid = convertList(arrayAndroid);
+
+ if (listuid == null) {
// 鍏ㄦ帹
- pushService.pushBaiChuanUrl(null, title, content, url, listVersion);
+ pushService.pushBaiChuanUrl(null, title, content, url, listIOS, listAndroid);
} 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);
+ pushService.pushBaiChuanUrl(Long.parseLong(str_uid), title, content, url, listIOS, listAndroid);
}
}
}
@@ -306,4 +251,23 @@
}
}
+
+ /**
+ * 鐗堟湰澶勭悊
+ * @param array
+ * @return
+ */
+ public List<String> convertList (String array) {
+ Gson gson = new Gson();
+ List<String> list = null;
+ if (array == null || array.trim().length() == 0) {
+ list = new ArrayList<String>(); // 闀垮害涓�0 涓嶆帹閫�
+ } else {
+ list = gson.fromJson(array, new TypeToken<ArrayList<String>>() {}.getType());
+ if (list != null && list.size() > 0 && list.contains("鍏ㄦ帹")) {
+ list = null; // 鍏ㄦ帹
+ }
+ }
+ return list;
+ }
}
--
Gitblit v1.8.0