From 573c491b4a1ba60e12a5678a01c1546c0077c1ee Mon Sep 17 00:00:00 2001
From: admin <weikou2014>
Date: 星期二, 30 七月 2019 09:07:42 +0800
Subject: [PATCH] Merge remote-tracking branch 'origin/master'

---
 fanli/src/main/java/com/yeshi/fanli/service/impl/push/IOSPushServiceImpl.java |  164 ++++++++++++++++++++++++++++++++++++++----------------
 1 files changed, 114 insertions(+), 50 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 16a4676..5d7bf3e 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,12 +1,14 @@
 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;
 
 import javax.annotation.Resource;
 
+import org.springframework.scheduling.annotation.Async;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
@@ -41,9 +43,10 @@
 
 	@Resource
 	private UserCustomSettingsService userCustomSettingsService;
-	
+
+	@Async("pushExecutor")
 	@Override
-	public void pushGoods(Long uid, Long auctionId, String title, String content) 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();
@@ -69,7 +72,7 @@
 
 		if (uid == null || uid == 0) {
 
-			addPushIOSQueue(info, url, PushController.GOODS);
+			addPushIOSQueue(info, url, PushController.GOODS, versionCodes);
 
 			/*
 			 * // 鏌ヨIOS鎵�鏈夎澶囧彿 // TODO 闇�瑕佸叏鎺� List<String> deviceTokenList =
@@ -85,11 +88,12 @@
 			 */
 		} else {
 			if (!validateNotDisturbSingle(uid)) {
-				return; //閫氱煡鍏嶆墦鎵�(20:00-24:00 / 00:00 -08:00) 
+				return; // 閫氱煡鍏嶆墦鎵�(20:00-24:00 / 00:00 -08:00)
 			}
 			
 			// IOS 鍗曟帹
-			List<DeviceTokenIOS> deviceTokenIosList = getDeviceTokenListByUid(uid);
+			List<DeviceTokenIOS> deviceTokenIosList = getDeviceTokenListByUid(uid, versionCodes);
+			
 			List<String> deviceTokenList = new ArrayList<>();
 			if (deviceTokenIosList != null)
 				for (DeviceTokenIOS ios : deviceTokenIosList) {
@@ -105,8 +109,9 @@
 		}
 	}
 
+	@Async("pushExecutor")
 	@Override
-	public void pushUrl(Long uid, String url, String title, String content) throws PushException {
+	public void pushUrl(Long uid, String url, String title, String content, String versionCodes) throws PushException {
 		JSONObject json = new JSONObject();
 		json.put("url", url);
 		json.put("type", "url");
@@ -128,7 +133,7 @@
 		if (uid == null || uid == 0) {
 			// TODO 闇�瑕佸叏鎺�
 
-			addPushIOSQueue(info, url, PushController.URL);
+			addPushIOSQueue(info, url, PushController.URL, versionCodes);
 
 			/*
 			 * List<String> deviceTokenList = getDeviceTokenList(1, 1000);
@@ -143,10 +148,10 @@
 			 */
 		} else {
 			if (!validateNotDisturbSingle(uid)) {
-				return; //閫氱煡鍏嶆墦鎵�(20:00-24:00 / 00:00 -08:00) 
+				return; // 閫氱煡鍏嶆墦鎵�(20:00-24:00 / 00:00 -08:00)
 			}
-			
-			List<DeviceTokenIOS> deviceTokenIosList = getDeviceTokenListByUid(uid);
+
+			List<DeviceTokenIOS> deviceTokenIosList = getDeviceTokenListByUid(uid, versionCodes);
 			List<String> deviceTokenList = new ArrayList<>();
 			if (deviceTokenIosList != null)
 				for (DeviceTokenIOS ios : deviceTokenIosList) {
@@ -160,8 +165,10 @@
 		}
 	}
 
+	
+	@Async("pushExecutor")
 	@Override
-	public void pushZNX(Long uId, AccountMessage msg, SystemZnx systemZNX) throws PushException {
+	public void pushZNX(Long uId, AccountMessage msg, SystemZnx systemZNX, String versionCodes) throws PushException {
 		MessageInfo info = new MessageInfo();
 		info.setPackageName(Constant.systemCommonConfig.getAndroidPackageName());
 
@@ -191,7 +198,7 @@
 
 			// TODO 闇�瑕佸叏鎺�
 
-			addPushIOSQueue(info, id + "", PushController.ZNX);
+			addPushIOSQueue(info, id + "", PushController.ZNX, versionCodes);
 
 			/*
 			 * List<String> deviceTokenList = getDeviceTokenList(1, 1000);
@@ -206,13 +213,13 @@
 			 * } });
 			 */
 		} else if (msg != null) {
-			
-			if (uId !=null) {
+
+			if (uId != null) {
 				if (!validateNotDisturbSingle(uId)) {
-					return; //閫氱煡鍏嶆墦鎵�(20:00-24:00 / 00:00 -08:00) 
+					return; // 閫氱煡鍏嶆墦鎵�(20:00-24:00 / 00:00 -08:00)
 				}
 			}
-			
+
 			// 鎻掑叆鎺ㄩ�佽褰�
 			PushRecord pushRecord = new PushRecord();
 			info.setTitle(msg.getTitle());
@@ -234,7 +241,7 @@
 			json.put("miPushUrl", String.format("%s.ui.mine.AppMailDetailActivity",
 					Constant.systemCommonConfig.getAndroidBaseactivityName()));
 
-			List<DeviceTokenIOS> deviceTokenIosList = getDeviceTokenListByUid(msg.getUserInfo().getId());
+			List<DeviceTokenIOS> deviceTokenIosList = getDeviceTokenListByUid(msg.getUserInfo().getId(), versionCodes);
 			List<String> deviceTokenList = new ArrayList<>();
 			if (deviceTokenIosList != null)
 				for (DeviceTokenIOS ios : deviceTokenIosList) {
@@ -282,13 +289,13 @@
 	}
 
 	@Override
-	public List<DeviceTokenIOS> getDeviceTokenListByUid(Long uid) {
-		return deviceTokenIOSMapper.selectByUid(uid);
+	public List<DeviceTokenIOS> getDeviceTokenListByUid(Long uid, String versionCodes) throws PushException {
+		return deviceTokenIOSMapper.selectByUid(uid, convertVersionType(versionCodes));
 	}
 
 	@Override
 	public List<String> getDeviceTokenList(int page, int size) {
-		List<DeviceTokenIOS> list = deviceTokenIOSMapper.selectList((long) ((page - 1) * size), size);
+		List<DeviceTokenIOS> list = deviceTokenIOSMapper.selectList((long) ((page - 1) * size), size, null);
 		List<String> tokenList = new ArrayList<>();
 		for (DeviceTokenIOS ios : list)
 			if (!StringUtil.isNullOrEmpty(ios.getDeviceToken()))
@@ -320,7 +327,10 @@
 	 * @param json
 	 */
 	@Transactional
-	public void addPushIOSQueue(MessageInfo info, String url, int type) {
+	public void addPushIOSQueue(MessageInfo info, String url, int type, String versionCodes) throws PushException {
+		
+		if(Constant.IS_TEST)
+			return;
 
 		try {
 
@@ -334,7 +344,7 @@
 
 			// 姣忔鎵ц鏉$洰
 			int pushNum = 50;
-
+			
 			for (long i = 0; i < tokenCount + totalCount;) {
 
 				PushQueueRecord pushQueueRecord = new PushQueueRecord();
@@ -348,6 +358,9 @@
 				pushQueueRecord.setPushNum(pushNum);
 				// 鎺ㄩ�佺 IOS
 				pushQueueRecord.setType(1);
+				// 鐗堟湰鍙�
+				pushQueueRecord.setVersions(versionCodes);
+				
 
 				if (tokenCount - i < totalCount) {
 					// 璧峰娓告爣
@@ -398,11 +411,17 @@
 		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);
 
 		// 姣忔鎺ㄩ�佹�绘潯鏁�
@@ -417,11 +436,11 @@
 		long recordCursor = startCursor;
 
 		for (int i = 0; i < count; i++) {
-
+			
 			// 涓嶈冻50涓暟鎹�
 			if (moveNum > total) {
 				moveNum = (int) (endCursor - startCursor);
-				List<DeviceTokenIOS> list = deviceTokenIOSMapper.selectList(startCursor, moveNum);
+				List<DeviceTokenIOS> list = deviceTokenIOSMapper.selectList(startCursor, moveNum, listCode);
 				recordCursor = endCursor;
 
 				if (list != null) {
@@ -435,7 +454,7 @@
 					// System.out.println("recordCursorend:" +recordCursor);
 					moveNum = (int) (endCursor - recordCursor);
 					// System.out.println(moveNum);
-					List<DeviceTokenIOS> list = deviceTokenIOSMapper.selectList(recordCursor, moveNum);
+					List<DeviceTokenIOS> list = deviceTokenIOSMapper.selectList(recordCursor, moveNum, listCode);
 					if (list != null) {
 						executePushIOS(list, pushQueueRecord, endCursor);
 						PushLogHelper.iosInfo("鎺ㄩ�佹父鏍�:" + recordCursor + "锛�" + moveNum);
@@ -443,7 +462,7 @@
 					recordCursor = endCursor;
 
 				} else {
-					List<DeviceTokenIOS> list = deviceTokenIOSMapper.selectList(recordCursor, moveNum);
+					List<DeviceTokenIOS> list = deviceTokenIOSMapper.selectList(recordCursor, moveNum, listCode);
 					recordCursor = recordCursor + 50;
 
 					if (list != null) {
@@ -451,38 +470,35 @@
 						PushLogHelper.iosInfo("鎺ㄩ�佹父鏍�:" + recordCursor + "锛�" + moveNum);
 					}
 				}
-
-				// System.out.println("recordCursor:" +recordCursor);
 			}
 		}
-
 	}
 
 	public void executePushIOS(List<DeviceTokenIOS> list, PushQueueRecord pushQueueRecord, long recordCursor) {
 
 		String jsonContent = pushQueueRecord.getJsonContent();
 		JSONObject json = JSONObject.fromObject(jsonContent);
-		
+
 		List<String> tokenList = new ArrayList<>();
-		
+
 		boolean ispush = false;
 		List<Long> listNotPushId = null;
-		
+
 		Calendar now = Calendar.getInstance();
 		int hour = now.get(Calendar.HOUR_OF_DAY);
 		if (hour >= 8 && hour < 20) {
 			ispush = true; // 鍙帹閫�
-		}  else {
+		} else {
 			listNotPushId = validateNotDisturb();
 		}
-		
+
 		for (DeviceTokenIOS ios : list) {
-			
+
 			if (!StringUtil.isNullOrEmpty(ios.getDeviceToken())) {
 				if (!ispush && listNotPushId != null && listNotPushId.size() > 0) {
 					Long uid = ios.getUid();
 					if (uid != null && listNotPushId.contains(uid)) {
-						continue;  // 閫氱煡鍏嶆墦鎵�(20:00-24:00 / 00:00 -08:00) 
+						continue; // 閫氱煡鍏嶆墦鎵�(20:00-24:00 / 00:00 -08:00)
 					}
 				}
 				tokenList.add(ios.getDeviceToken());
@@ -517,17 +533,18 @@
 		}
 	}
 
+	@Async("pushExecutor")
 	@Override
-	public void pushWEEX(Long uid, String title, String content, String weexUrl) 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);
+			addPushIOSQueue(info, weexUrl, PushController.WEEX, versionCodes);
 		} else {
-			List<DeviceTokenIOS> deviceTokenIosList = getDeviceTokenListByUid(uid);
+			List<DeviceTokenIOS> deviceTokenIosList = getDeviceTokenListByUid(uid, versionCodes);
 			List<String> deviceTokenList = new ArrayList<>();
 			if (deviceTokenIosList != null)
 				for (DeviceTokenIOS ios : deviceTokenIosList) {
@@ -541,17 +558,18 @@
 		}
 	}
 
+	@Async("pushExecutor")
 	@Override
-	public void pushBaiChuanUrl(Long uid, String title, String content, String url) 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);
+			addPushIOSQueue(info, url, PushController.BAICHUAN, versionCodes);
 		} else {
-			List<DeviceTokenIOS> deviceTokenIosList = getDeviceTokenListByUid(uid);
+			List<DeviceTokenIOS> deviceTokenIosList = getDeviceTokenListByUid(uid, versionCodes);
 			List<String> deviceTokenList = new ArrayList<>();
 			if (deviceTokenIosList != null)
 				for (DeviceTokenIOS ios : deviceTokenIosList) {
@@ -564,16 +582,16 @@
 			}
 		}
 	}
-	
+
 	/**
-	 *  閫氱煡鍏嶆墦鎵�(20:00-8:00) 
+	 * 閫氱煡鍏嶆墦鎵�(20:00-8:00)
 	 */
 	public List<Long> validateNotDisturb() {
 		return userCustomSettingsService.getCancelNoticeUsers();
 	}
-	
+
 	/**
-	 *  閫氱煡鍏嶆墦鎵�(20:00-8:00) 
+	 * 閫氱煡鍏嶆墦鎵�(20:00-8:00)
 	 */
 	public boolean validateNotDisturbSingle(Long uid) {
 		Calendar now = Calendar.getInstance();
@@ -582,12 +600,58 @@
 		if (hour >= 8 && hour < 20) {
 			ispush = true; // 鍙帹閫�
 		} else {
-			// 鑷畾涔夎缃�  閫氱煡鍏嶆墦鎵�(20:00-24:00 / 00:00 -08:00) 
+			// 鑷畾涔夎缃� 閫氱煡鍏嶆墦鎵�(20:00-24:00 / 00:00 -08:00)
 			ispush = userCustomSettingsService.validateCancelNoticeByUid(uid);
 		}
-		
+
 		return ispush;
 	}
-	
 
+	@Async("pushExecutor")
+	@Override
+	public void pushWelfareCenter(Long uid, String title, String content, 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, "", PushController.WELFARE_CENTER, versionCodes);
+		} else {
+			if (!validateNotDisturbSingle(uid)) {
+				return;
+			}
+			List<DeviceTokenIOS> deviceTokenIosList = getDeviceTokenListByUid(uid, versionCodes);
+			List<String> deviceTokenList = new ArrayList<>();
+			if (deviceTokenIosList != null)
+				for (DeviceTokenIOS ios : deviceTokenIosList) {
+					deviceTokenList.add(ios.getDeviceToken());
+				}
+			try {
+				IOSPushUtil.allPushIOS(deviceTokenList, info, "", PushController.WELFARE_CENTER);
+			} catch (Exception e) {
+				PushLogHelper.iosError(e);
+			}
+		}
+	}
+
+	private List<Integer> convertVersionType(String versionCodes) {
+		List<Integer> listVersionCode = null;
+
+		if (versionCodes != null && versionCodes.trim().length() > 0) {
+			List<String> listVersion = Arrays.asList(versionCodes.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));
+					}
+				}
+			}
+		}
+		return listVersionCode;
+	}
+	
 }

--
Gitblit v1.8.0