From ed035efe19e7f247717afa8448998fd2c8a9eefa Mon Sep 17 00:00:00 2001
From: yujian <yujian>
Date: 星期五, 15 三月 2019 09:45:05 +0800
Subject: [PATCH] 后台推送版本控制优化

---
 fanli/src/main/java/com/yeshi/fanli/service/impl/push/IOSPushServiceImpl.java |   78 +++++++++++++++++++++++++++------------
 1 files changed, 54 insertions(+), 24 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 07c2392..648d0c5 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
@@ -1,6 +1,7 @@
 package com.yeshi.fanli.service.impl.push;
 
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.Calendar;
 import java.util.Date;
 import java.util.List;
@@ -288,10 +289,16 @@
 	}
 
 	@Override
-	public List<DeviceTokenIOS> getDeviceTokenListByUid(Long uid, List<String> listVersion) {
-		// 鐗堟湰鍙�
-		List<Integer> listCode = appVersionService.listVersionCodeByVersions(AppVersionInfo.PLATFORM_IOS,listVersion);
-
+	public List<DeviceTokenIOS> getDeviceTokenListByUid(Long uid, List<String> listVersion) throws PushException {
+		List<Integer> listCode = null;
+		if (listVersion != null && listVersion.size() > 0) {
+			// 鐗堟湰鍙锋帹閫侀檺鍒�	
+			listCode = appVersionService.listVersionCodeByVersions(AppVersionInfo.PLATFORM_IOS,listVersion);
+			if (listCode == null || listCode.size() == 0) {
+				throw new PushException(1, "IOS鎺ㄩ�佸け璐ワ紝鎺ㄩ�佺増鏈笉瀛樺湪锛�");
+			}
+		}
+		
 		return deviceTokenIOSMapper.selectByUid(uid, listCode);
 	}
 
@@ -329,7 +336,7 @@
 	 * @param json
 	 */
 	@Transactional
-	public void addPushIOSQueue(MessageInfo info, String url, int type, List<String> listVersion) {
+	public void addPushIOSQueue(MessageInfo info, String url, int type, List<String> listVersion) throws PushException {
 
 		try {
 
@@ -345,18 +352,28 @@
 			int pushNum = 50;
 
 			String versionCodes = "";
-			List<Integer> listCode = appVersionService.listVersionCodeByVersions(AppVersionInfo.PLATFORM_IOS,listVersion);
 			
-			if (listCode != null && listCode.size() > 0) {
-				for (Integer code: listCode) {
-					versionCodes = versionCodes + code + ",";
+			if (listVersion != null && listVersion.size() > 0) {
+				// 鍔犲叆鐗堟湰鎺ㄩ�侀檺鍒�
+				List<Integer> listCode = appVersionService.listVersionCodeByVersions(AppVersionInfo.PLATFORM_IOS,listVersion);
+				
+				if (listCode != null && listCode.size() > 0) {
+					for (Integer code: listCode) {
+						versionCodes = versionCodes + code + ",";
+					}
+					
+					// 鍘婚櫎鏈熬閫楀彿
+					if (versionCodes.endsWith(",")) {
+						versionCodes = versionCodes.substring(0, versionCodes.length() - 1);
+					}
 				}
 				
-				// 鍘婚櫎鏈熬閫楀彿
-				if (versionCodes.endsWith(",")) {
-					versionCodes = versionCodes.substring(0, versionCodes.length() - 1);
+				if (versionCodes == null || versionCodes.trim().length() == 0) {
+					throw new PushException(1, "IOS鎺ㄩ�佸け璐ワ紝鎺ㄩ�佺増鏈笉瀛樺湪锛�");
 				}
+				
 			}
+			
 			
 			for (long i = 0; i < tokenCount + totalCount;) {
 
@@ -424,17 +441,33 @@
 		Long startCursor = pushQueueRecord.getStartCursor();
 		// 缁撴潫浣嶇疆
 		Long endCursor = pushQueueRecord.getEndCursor();
-		// 鐗堟湰鍙�
-		String[] versionArray = null;
-		String versions = pushQueueRecord.getVersions();
-		if (versions != null && versions.trim().length() == 0) {
-			versionArray = versions.split(",");
-		}
 		
 		if (startCursor == null && endCursor == null) {
 			return;
 		}
 
+		
+		// 鎺ㄩ�佺殑鐗堟湰鍙�
+		String versions = pushQueueRecord.getVersions();
+		List<Integer> listVersionCode = null;
+		if (versions != null && versions.trim().length() > 0) {
+			
+			List<String> listVersion  = Arrays.asList(versions.split(","));
+			if (listVersion != null && listVersion.size() > 0) {
+				listVersionCode = new ArrayList<Integer>();
+				for (String version: listVersion) {
+					if (version != null && version.trim().length() > 0) {
+						listVersionCode.add(Integer.parseInt(version));
+					}
+				}
+			}
+			
+			if (listVersionCode == null || listVersionCode.size() == 0) {
+				return; //鐗堟湰鍙峰瓨鍦ㄥ紓甯�
+			}
+		}
+				
+		
 		int total = (int) (endCursor - startCursor);
 
 		// 姣忔鎺ㄩ�佹�绘潯鏁�
@@ -454,7 +487,7 @@
 			// 涓嶈冻50涓暟鎹�
 			if (moveNum > total) {
 				moveNum = (int) (endCursor - startCursor);
-				List<DeviceTokenIOS> list = deviceTokenIOSMapper.selectList(startCursor, moveNum, versionArray);
+				List<DeviceTokenIOS> list = deviceTokenIOSMapper.selectList(startCursor, moveNum, listVersionCode);
 				recordCursor = endCursor;
 
 				if (list != null) {
@@ -468,7 +501,7 @@
 					// System.out.println("recordCursorend:" +recordCursor);
 					moveNum = (int) (endCursor - recordCursor);
 					// System.out.println(moveNum);
-					List<DeviceTokenIOS> list = deviceTokenIOSMapper.selectList(recordCursor, moveNum, versionArray);
+					List<DeviceTokenIOS> list = deviceTokenIOSMapper.selectList(recordCursor, moveNum, listVersionCode);
 					if (list != null) {
 						executePushIOS(list, pushQueueRecord, endCursor);
 						PushLogHelper.iosInfo("鎺ㄩ�佹父鏍�:" + recordCursor + "锛�" + moveNum);
@@ -476,7 +509,7 @@
 					recordCursor = endCursor;
 
 				} else {
-					List<DeviceTokenIOS> list = deviceTokenIOSMapper.selectList(recordCursor, moveNum, versionArray);
+					List<DeviceTokenIOS> list = deviceTokenIOSMapper.selectList(recordCursor, moveNum, listVersionCode);
 					recordCursor = recordCursor + 50;
 
 					if (list != null) {
@@ -484,11 +517,8 @@
 						PushLogHelper.iosInfo("鎺ㄩ�佹父鏍�:" + recordCursor + "锛�" + moveNum);
 					}
 				}
-
-				// System.out.println("recordCursor:" +recordCursor);
 			}
 		}
-
 	}
 
 	public void executePushIOS(List<DeviceTokenIOS> list, PushQueueRecord pushQueueRecord, long recordCursor) {

--
Gitblit v1.8.0