From aad0425e6a103b633aab4c36642cdd34e95ace62 Mon Sep 17 00:00:00 2001
From: admin <weikou2014>
Date: 星期一, 26 八月 2019 09:40:41 +0800
Subject: [PATCH] 推送类型优化

---
 fanli/src/main/java/com/yeshi/fanli/service/impl/push/IOSPushServiceImpl.java |   84 +++++++++++++++++++++++++++---------------
 1 files changed, 54 insertions(+), 30 deletions(-)

diff --git a/fanli/src/main/java/com/yeshi/fanli/service/impl/push/IOSPushServiceImpl.java b/fanli/src/main/java/com/yeshi/fanli/service/impl/push/IOSPushServiceImpl.java
index 5d7bf3e..9222b2b 100644
--- a/fanli/src/main/java/com/yeshi/fanli/service/impl/push/IOSPushServiceImpl.java
+++ b/fanli/src/main/java/com/yeshi/fanli/service/impl/push/IOSPushServiceImpl.java
@@ -12,9 +12,9 @@
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
-import com.yeshi.fanli.controller.admin.PushController;
 import com.yeshi.fanli.dao.mybatis.push.DeviceTokenIOSMapper;
 import com.yeshi.fanli.dao.mybatis.push.PushQueueRecordMapper;
+import com.yeshi.fanli.dto.push.PushTypeEnum;
 import com.yeshi.fanli.entity.bus.user.AccountMessage;
 import com.yeshi.fanli.entity.push.DeviceTokenIOS;
 import com.yeshi.fanli.entity.push.PushQueueRecord;
@@ -46,7 +46,8 @@
 
 	@Async("pushExecutor")
 	@Override
-	public void pushGoods(Long uid, Long auctionId, String title, String content, String versionCodes) throws PushException {
+	public void pushGoods(Long uid, Long auctionId, String title, String content, String versionCodes)
+			throws PushException {
 
 		String url = "https://item.taobao.com/item.htm?id=" + auctionId;
 		JSONObject json = new JSONObject();
@@ -65,14 +66,14 @@
 
 		PushRecord pushRecord = new PushRecord();
 		pushRecord.setState(1);
-		pushRecord.setType(PushController.GOODS); // 閮芥垚鍔�
+		pushRecord.setType(PushTypeEnum.goodsdetail.getCode()); // 閮芥垚鍔�
 		pushRecord.setUrl(url);
 		pushRecord.setTitle(title);
 		pushRecord.setAppName(Constant.systemCommonConfig.getProjectChineseName());
 
 		if (uid == null || uid == 0) {
 
-			addPushIOSQueue(info, url, PushController.GOODS, versionCodes);
+			addPushIOSQueue(info, url, PushTypeEnum.goodsdetail.getCode(), versionCodes);
 
 			/*
 			 * // 鏌ヨIOS鎵�鏈夎澶囧彿 // TODO 闇�瑕佸叏鎺� List<String> deviceTokenList =
@@ -90,10 +91,10 @@
 			if (!validateNotDisturbSingle(uid)) {
 				return; // 閫氱煡鍏嶆墦鎵�(20:00-24:00 / 00:00 -08:00)
 			}
-			
+
 			// IOS 鍗曟帹
 			List<DeviceTokenIOS> deviceTokenIosList = getDeviceTokenListByUid(uid, versionCodes);
-			
+
 			List<String> deviceTokenList = new ArrayList<>();
 			if (deviceTokenIosList != null)
 				for (DeviceTokenIOS ios : deviceTokenIosList) {
@@ -101,7 +102,7 @@
 				}
 
 			try {
-				IOSPushUtil.allPushIOS(deviceTokenList, info, url, PushController.GOODS);
+				IOSPushUtil.allPushIOS(deviceTokenList, info, url, PushTypeEnum.goodsdetail.getCode());
 			} catch (Exception e) {
 				PushLogHelper.iosError(e);
 			}
@@ -133,7 +134,7 @@
 		if (uid == null || uid == 0) {
 			// TODO 闇�瑕佸叏鎺�
 
-			addPushIOSQueue(info, url, PushController.URL, versionCodes);
+			addPushIOSQueue(info, url, PushTypeEnum.url.getCode(), versionCodes);
 
 			/*
 			 * List<String> deviceTokenList = getDeviceTokenList(1, 1000);
@@ -158,14 +159,13 @@
 					deviceTokenList.add(ios.getDeviceToken());
 				}
 			try {
-				IOSPushUtil.allPushIOS(deviceTokenList, info, url, PushController.URL);
+				IOSPushUtil.allPushIOS(deviceTokenList, info, url, PushTypeEnum.url.getCode());
 			} catch (Exception e) {
 				PushLogHelper.iosError(e);
 			}
 		}
 	}
 
-	
 	@Async("pushExecutor")
 	@Override
 	public void pushZNX(Long uId, AccountMessage msg, SystemZnx systemZNX, String versionCodes) throws PushException {
@@ -198,7 +198,7 @@
 
 			// TODO 闇�瑕佸叏鎺�
 
-			addPushIOSQueue(info, id + "", PushController.ZNX, versionCodes);
+			addPushIOSQueue(info, id + "", PushTypeEnum.ZNX.getCode(), versionCodes);
 
 			/*
 			 * List<String> deviceTokenList = getDeviceTokenList(1, 1000);
@@ -250,7 +250,7 @@
 
 			// IOS 鍗曟帹
 			try {
-				IOSPushUtil.allPushIOS(deviceTokenList, info, "0", PushController.ZNX);
+				IOSPushUtil.allPushIOS(deviceTokenList, info, "0", PushTypeEnum.ZNX.getCode());
 			} catch (Exception e) {
 				PushLogHelper.iosError(e);
 			}
@@ -328,8 +328,8 @@
 	 */
 	@Transactional
 	public void addPushIOSQueue(MessageInfo info, String url, int type, String versionCodes) throws PushException {
-		
-		if(Constant.IS_TEST)
+
+		if (Constant.IS_TEST)
 			return;
 
 		try {
@@ -344,7 +344,7 @@
 
 			// 姣忔鎵ц鏉$洰
 			int pushNum = 50;
-			
+
 			for (long i = 0; i < tokenCount + totalCount;) {
 
 				PushQueueRecord pushQueueRecord = new PushQueueRecord();
@@ -360,7 +360,6 @@
 				pushQueueRecord.setType(1);
 				// 鐗堟湰鍙�
 				pushQueueRecord.setVersions(versionCodes);
-				
 
 				if (tokenCount - i < totalCount) {
 					// 璧峰娓告爣
@@ -411,17 +410,15 @@
 		Long startCursor = pushQueueRecord.getStartCursor();
 		// 缁撴潫浣嶇疆
 		Long endCursor = pushQueueRecord.getEndCursor();
-		
+
 		if (startCursor == null && endCursor == null) {
 			return;
 		}
 
-		
 		// 鎺ㄩ�佺殑鐗堟湰鍙�
 		String versions = pushQueueRecord.getVersions();
 		List<Integer> listCode = convertVersionType(versions);
-				
-		
+
 		int total = (int) (endCursor - startCursor);
 
 		// 姣忔鎺ㄩ�佹�绘潯鏁�
@@ -436,7 +433,7 @@
 		long recordCursor = startCursor;
 
 		for (int i = 0; i < count; i++) {
-			
+
 			// 涓嶈冻50涓暟鎹�
 			if (moveNum > total) {
 				moveNum = (int) (endCursor - startCursor);
@@ -535,14 +532,15 @@
 
 	@Async("pushExecutor")
 	@Override
-	public void pushWEEX(Long uid, String title, String content, String weexUrl,String versionCodes) throws PushException {
+	public void pushWEEX(Long uid, String title, String content, String weexUrl, String versionCodes)
+			throws PushException {
 		MessageInfo info = new MessageInfo();
 		info.setTitle(title);
 		info.setContent(content);
 		info.setDescription(content);
 		// IOS 鍏ㄦ帹
 		if (uid == null || uid == 0) {
-			addPushIOSQueue(info, weexUrl, PushController.WEEX, versionCodes);
+			addPushIOSQueue(info, weexUrl, PushTypeEnum.weex.getCode(), versionCodes);
 		} else {
 			List<DeviceTokenIOS> deviceTokenIosList = getDeviceTokenListByUid(uid, versionCodes);
 			List<String> deviceTokenList = new ArrayList<>();
@@ -551,7 +549,7 @@
 					deviceTokenList.add(ios.getDeviceToken());
 				}
 			try {
-				IOSPushUtil.allPushIOS(deviceTokenList, info, weexUrl, PushController.WEEX);
+				IOSPushUtil.allPushIOS(deviceTokenList, info, weexUrl, PushTypeEnum.weex.getCode());
 			} catch (Exception e) {
 				PushLogHelper.iosError(e);
 			}
@@ -560,14 +558,15 @@
 
 	@Async("pushExecutor")
 	@Override
-	public void pushBaiChuanUrl(Long uid, String title, String content, String url, String versionCodes) throws PushException {
+	public void pushBaiChuanUrl(Long uid, String title, String content, String url, String versionCodes)
+			throws PushException {
 		MessageInfo info = new MessageInfo();
 		info.setTitle(title);
 		info.setContent(content);
 		info.setDescription(content);
 		// IOS 鍏ㄦ帹
 		if (uid == null || uid == 0) {
-			addPushIOSQueue(info, url, PushController.BAICHUAN, versionCodes);
+			addPushIOSQueue(info, url, PushTypeEnum.baichuan.getCode(), versionCodes);
 		} else {
 			List<DeviceTokenIOS> deviceTokenIosList = getDeviceTokenListByUid(uid, versionCodes);
 			List<String> deviceTokenList = new ArrayList<>();
@@ -576,7 +575,7 @@
 					deviceTokenList.add(ios.getDeviceToken());
 				}
 			try {
-				IOSPushUtil.allPushIOS(deviceTokenList, info, url, PushController.BAICHUAN);
+				IOSPushUtil.allPushIOS(deviceTokenList, info, url, PushTypeEnum.baichuan.getCode());
 			} catch (Exception e) {
 				PushLogHelper.iosError(e);
 			}
@@ -616,7 +615,7 @@
 		info.setDescription(content);
 		// IOS 鍏ㄦ帹
 		if (uid == null || uid == 0) {
-			addPushIOSQueue(info, "", PushController.WELFARE_CENTER, versionCodes);
+			addPushIOSQueue(info, "", PushTypeEnum.welfare.getCode(), versionCodes);
 		} else {
 			if (!validateNotDisturbSingle(uid)) {
 				return;
@@ -628,7 +627,7 @@
 					deviceTokenList.add(ios.getDeviceToken());
 				}
 			try {
-				IOSPushUtil.allPushIOS(deviceTokenList, info, "", PushController.WELFARE_CENTER);
+				IOSPushUtil.allPushIOS(deviceTokenList, info, "", PushTypeEnum.welfare.getCode());
 			} catch (Exception e) {
 				PushLogHelper.iosError(e);
 			}
@@ -653,5 +652,30 @@
 		}
 		return listVersionCode;
 	}
-	
+
+	@Override
+	public void pushUserSignInNotification(Long uid, String title, String content, String versions)
+			throws PushException {
+		MessageInfo info = new MessageInfo();
+		info.setTitle(title);
+		info.setContent(content);
+		info.setDescription(content);
+		// IOS 鍏ㄦ帹
+		if (uid == null || uid == 0) {
+			addPushIOSQueue(info, "", PushTypeEnum.signin.getCode(), versions);
+		} else {
+			List<DeviceTokenIOS> deviceTokenIosList = getDeviceTokenListByUid(uid, versions);
+			List<String> deviceTokenList = new ArrayList<>();
+			if (deviceTokenIosList != null)
+				for (DeviceTokenIOS ios : deviceTokenIosList) {
+					deviceTokenList.add(ios.getDeviceToken());
+				}
+			try {
+				IOSPushUtil.allPushIOS(deviceTokenList, info, "", PushTypeEnum.signin.getCode());
+			} catch (Exception e) {
+				PushLogHelper.iosError(e);
+			}
+		}
+	}
+
 }

--
Gitblit v1.8.0