From 30d8e227e8d823b6c38c3b9c90ac2df03b63befe Mon Sep 17 00:00:00 2001
From: admin <weikou2014>
Date: 星期二, 25 二月 2025 16:41:22 +0800
Subject: [PATCH] 淘宝转链接口更新

---
 fanli/src/main/java/com/yeshi/fanli/service/impl/push/IOSPushServiceImpl.java | 1156 ++++++++++++++++++++++++++++++++++-----------------------
 1 files changed, 685 insertions(+), 471 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 1b8730b..492d218 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,471 +1,685 @@
-package com.yeshi.fanli.service.impl.push;
-
-import java.util.ArrayList;
-import java.util.Date;
-import java.util.List;
-
-import javax.annotation.Resource;
-
-import net.sf.json.JSONObject;
-
-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.entity.bus.user.AccountMessage;
-import com.yeshi.fanli.entity.push.DeviceTokenIOS;
-import com.yeshi.fanli.entity.push.PushQueueRecord;
-import com.yeshi.fanli.entity.system.SystemZnx;
-import com.yeshi.fanli.entity.xinge.MessageInfo;
-import com.yeshi.fanli.entity.xinge.PushRecord;
-import com.yeshi.fanli.exception.PushException;
-import com.yeshi.fanli.log.LogHelper;
-import com.yeshi.fanli.log.PushLogHelper;
-import com.yeshi.fanli.service.inter.push.IOSPushService;
-import com.yeshi.fanli.util.CMQManager;
-import com.yeshi.fanli.util.Constant;
-import com.yeshi.fanli.util.StringUtil;
-import com.yeshi.fanli.util.ThreadUtil;
-import com.yeshi.fanli.util.push.IOSPushUtil;
-
-@Service
-public class IOSPushServiceImpl implements IOSPushService {
-
-	@Resource
-	private DeviceTokenIOSMapper deviceTokenIOSMapper;
-
-	@Resource
-	private PushQueueRecordMapper pushQueueRecordMapper;
-
-	@Override
-	public void pushGoods(Long uid, Long auctionId, String title, String content) throws PushException {
-
-		String url = "https://item.taobao.com/item.htm?id=" + auctionId;
-		JSONObject json = new JSONObject();
-		json.put("id", auctionId);
-		json.put("type", "goodsdetail");
-		json.put("miPushUrl", String.format("%s.ui.recommend.GoodsBrowserActivity",
-				Constant.systemCommonConfig.getAndroidBaseactivityName()));
-
-		MessageInfo info = new MessageInfo();
-		info.setTitle(title);
-		info.setContent(content);
-		info.setDescription(content);
-		info.setPackageName(Constant.systemCommonConfig.getAndroidPackageName());
-		info.setActivty(String.format("%s.ui.recommend.GoodsBrowserActivity",
-				Constant.systemCommonConfig.getAndroidBaseactivityName()));
-
-		PushRecord pushRecord = new PushRecord();
-		pushRecord.setState(1);
-		pushRecord.setType(PushController.GOODS); // 閮芥垚鍔�
-		pushRecord.setUrl(url);
-		pushRecord.setTitle(title);
-		pushRecord.setAppName(Constant.systemCommonConfig.getProjectChineseName());
-
-		if (uid == null || uid == 0) {
-
-			addPushIOSQueue(info, url, PushController.GOODS);
-
-			/*
-			 * // 鏌ヨIOS鎵�鏈夎澶囧彿 // TODO 闇�瑕佸叏鎺� List<String> deviceTokenList =
-			 * getDeviceTokenList(1, 20000); // IOS 鍏ㄦ帹 ThreadUtil.run(new
-			 * Runnable() {
-			 * 
-			 * @Override public void run() { try {
-			 * IOSPushUtil.allPushIOS(deviceTokenList, info, url,
-			 * PushController.GOODS); } catch (Exception e) {
-			 * PushLogHelper.iosError(e);
-			 * 
-			 * } } });
-			 */
-		} else {
-			// IOS 鍗曟帹
-			List<DeviceTokenIOS> deviceTokenIosList = getDeviceTokenListByUid(uid);
-			List<String> deviceTokenList = new ArrayList<>();
-			if (deviceTokenIosList != null)
-				for (DeviceTokenIOS ios : deviceTokenIosList) {
-					deviceTokenList.add(ios.getDeviceToken());
-				}
-
-			try {
-				IOSPushUtil.allPushIOS(deviceTokenList, info, url, PushController.GOODS);
-			} catch (Exception e) {
-				PushLogHelper.iosError(e);
-			}
-
-		}
-	}
-
-	@Override
-	public void pushUrl(Long uid, String url, String title, String content) throws PushException {
-		JSONObject json = new JSONObject();
-		json.put("url", url);
-		json.put("type", "url");
-		json.put("webUrl", url);
-		json.put("miPushUrl",
-				String.format("%s.ui.BrowserActivity", Constant.systemCommonConfig.getAndroidBaseactivityName()));
-
-		MessageInfo info = new MessageInfo();
-		info.setTitle(title);
-		info.setContent(content);
-		info.setDescription(content);
-		// 灏忕背鎺ㄩ�佺綉椤�
-		info.setPackageName(Constant.systemCommonConfig.getAndroidPackageName());
-		info.setActivty(
-				String.format("%s.ui.BrowserActivity", Constant.systemCommonConfig.getAndroidBaseactivityName()));
-
-		PushRecord pushRecord = new PushRecord();
-		// IOS 鍏ㄦ帹
-		if (uid == null || uid == 0) {
-			// TODO 闇�瑕佸叏鎺�
-
-			addPushIOSQueue(info, url, PushController.URL);
-
-			/*
-			 * List<String> deviceTokenList = getDeviceTokenList(1, 1000);
-			 * ThreadUtil.run(new Runnable() {
-			 * 
-			 * @Override public void run() { try {
-			 * 
-			 * IOSPushUtil.allPushIOS(deviceTokenList, info, url,
-			 * PushController.URL);
-			 * 
-			 * } catch (Exception e) { PushLogHelper.iosError(e); } } });
-			 */
-		} else {
-			List<DeviceTokenIOS> deviceTokenIosList = getDeviceTokenListByUid(uid);
-			List<String> deviceTokenList = new ArrayList<>();
-			if (deviceTokenIosList != null)
-				for (DeviceTokenIOS ios : deviceTokenIosList) {
-					deviceTokenList.add(ios.getDeviceToken());
-				}
-			try {
-				IOSPushUtil.allPushIOS(deviceTokenList, info, url, PushController.URL);
-			} catch (Exception e) {
-				PushLogHelper.iosError(e);
-			}
-		}
-	}
-
-	@Override
-	public void pushWEEXUrl(Long uid, String weexUrl, String title, String content) throws PushException {
-
-	}
-
-	@Override
-	public void pushZNX(Long uId, AccountMessage msg, SystemZnx systemZNX) throws PushException {
-		MessageInfo info = new MessageInfo();
-		info.setPackageName(Constant.systemCommonConfig.getAndroidPackageName());
-
-		JSONObject contentJson = new JSONObject();
-		contentJson.put("isOpen", 0);
-		contentJson.put("createTime", java.lang.System.currentTimeMillis());
-
-		/* 鏃爑id , 骞挎挱 鏁版嵁鎻掑叆绯荤粺琛� */
-		if (systemZNX != null) {
-			info.setTitle(systemZNX.getTitle());
-			info.setContent(systemZNX.getContent());
-			contentJson.put("title", systemZNX.getTitle());
-			contentJson.put("content", systemZNX.getContent());
-			info.setDescription(systemZNX.getContent());
-
-			// 灏忕背寮�濮嬪叏鎺�
-			long id = systemZNX.getId();
-			contentJson.put("id", id);
-
-			JSONObject json = new JSONObject();
-			json.put("type", "ZNX");
-			json.put("content", contentJson);
-			json.put("miPushUrl", String.format("%s.ui.mine.AppMailDetailActivity",
-					Constant.systemCommonConfig.getAndroidBaseactivityName()));
-
-			PushRecord pushRecord = new PushRecord();
-
-			// TODO 闇�瑕佸叏鎺�
-
-			addPushIOSQueue(info, id + "", PushController.ZNX);
-
-			/*
-			 * List<String> deviceTokenList = getDeviceTokenList(1, 1000);
-			 * 
-			 * ThreadUtil.run(new Runnable() {
-			 * 
-			 * @Override public void run() { try {
-			 * IOSPushUtil.allPushIOS(deviceTokenList, info, id + "",
-			 * PushController.ZNX); } catch (Exception e) {
-			 * PushLogHelper.iosError(e); }
-			 * 
-			 * } });
-			 */
-		} else if (msg != null) {
-			// 鎻掑叆鎺ㄩ�佽褰�
-			PushRecord pushRecord = new PushRecord();
-			info.setTitle(msg.getTitle());
-			info.setContent(msg.getContent());
-			contentJson.put("title", msg.getTitle());
-			contentJson.put("content", msg.getContent());
-			info.setDescription(msg.getContent());
-
-			info.setAlias(uId + "");
-			info.setPackageName(Constant.systemCommonConfig.getAndroidPackageName());
-			info.setActivty(
-					String.format("%s.ui.BrowserActivity", Constant.systemCommonConfig.getAndroidBaseactivityName()));
-
-			contentJson.put("id", msg.getId() + "");
-
-			JSONObject json = new JSONObject();
-			json.put("type", "ZNX");
-			json.put("content", contentJson);
-			json.put("miPushUrl", String.format("%s.ui.mine.AppMailDetailActivity",
-					Constant.systemCommonConfig.getAndroidBaseactivityName()));
-
-			List<DeviceTokenIOS> deviceTokenIosList = getDeviceTokenListByUid(msg.getUserInfo().getId());
-			List<String> deviceTokenList = new ArrayList<>();
-			if (deviceTokenIosList != null)
-				for (DeviceTokenIOS ios : deviceTokenIosList) {
-					deviceTokenList.add(ios.getDeviceToken());
-				}
-
-			// IOS 鍗曟帹
-			try {
-				IOSPushUtil.allPushIOS(deviceTokenList, info, "0", PushController.ZNX);
-			} catch (Exception e) {
-				PushLogHelper.iosError(e);
-			}
-		}
-	}
-
-	@Transactional
-	@Override
-	public void addDeviceToken(Long uid, int version, String deviceToken, String device) {
-		// 濡傛灉device涓虹┖灏辫繑鍥�
-		if (StringUtil.isNullOrEmpty(device))
-			return;
-
-		// 鍒ゆ柇device鏄惁瀛樺湪
-		DeviceTokenIOS deviceTokenIos = deviceTokenIOSMapper.selectByDevice(device);
-		if (deviceTokenIos == null) {
-			deviceTokenIos = new DeviceTokenIOS();
-			deviceTokenIos.setCreateTime(new Date());
-			deviceTokenIos.setUpdateTime(new Date());
-			deviceTokenIos.setDevice(device);
-			deviceTokenIos.setDeviceToken(deviceToken);
-			deviceTokenIos.setUid(uid);
-			deviceTokenIos.setVersion(version);
-			deviceTokenIOSMapper.insertSelective(deviceTokenIos);
-		}
-
-	}
-
-	@Override
-	public List<DeviceTokenIOS> getDeviceTokenListByUid(Long uid) {
-		return deviceTokenIOSMapper.selectByUid(uid);
-	}
-
-	@Override
-	public List<String> getDeviceTokenList(int page, int size) {
-		List<DeviceTokenIOS> list = deviceTokenIOSMapper.selectList((long) ((page - 1) * size), size);
-		List<String> tokenList = new ArrayList<>();
-		for (DeviceTokenIOS ios : list)
-			if (!StringUtil.isNullOrEmpty(ios.getDeviceToken()))
-				tokenList.add(ios.getDeviceToken());
-		return tokenList;
-	}
-
-	@Override
-	public long getDeviceTokenCount() {
-		return deviceTokenIOSMapper.selectCount();
-	}
-
-	@Override
-	public void updateDeviceToken(DeviceTokenIOS deviceTokenIos) {
-		if (deviceTokenIos != null) {
-			deviceTokenIos.setUpdateTime(new Date());
-			deviceTokenIOSMapper.updateByPrimaryKey(deviceTokenIos);
-		}
-	}
-
-	@Override
-	public DeviceTokenIOS getDeviceTokenByDevice(String device) {
-		return deviceTokenIOSMapper.selectByDevice(device);
-	}
-
-	/**
-	 * 淇濆瓨鎺ㄩ�佸唴瀹瑰彧闃熷垪涓�
-	 * 
-	 * @param json
-	 */
-	@Transactional
-	public void addPushIOSQueue(MessageInfo info, String url, int type) {
-
-		try {
-
-			JSONObject json = IOSPushUtil.getJSONObject(info, url, type);
-
-			// 鎬绘潯鐩�
-			long tokenCount = getDeviceTokenCount();
-
-			// 涓�涓槦鍒� 1000 鏉�
-			long totalCount = 1000;
-
-			// 姣忔鎵ц鏉$洰
-			int pushNum = 50;
-
-			for (long i = 0; i < tokenCount + totalCount;) {
-
-				PushQueueRecord pushQueueRecord = new PushQueueRecord();
-				// 鍒濆鐘舵��
-				pushQueueRecord.setState(0);
-				// 鍙戦�佸唴瀹�
-				pushQueueRecord.setJsonContent(json.toString());
-				// 鍒涘缓鏃堕棿
-				pushQueueRecord.setCreatetime(new Date());
-				// 姣忔鎺ㄩ�佹暟閲�
-				pushQueueRecord.setPushNum(pushNum);
-				// 鎺ㄩ�佺 IOS
-				pushQueueRecord.setType(1);
-
-				if (tokenCount - i < totalCount) {
-					// 璧峰娓告爣
-					pushQueueRecord.setStartCursor(i);
-					// 缁撴潫娓告爣
-					pushQueueRecord.setEndCursor(tokenCount);
-
-					// 瀛樺叆鏁版嵁搴�
-					pushQueueRecordMapper.insert(pushQueueRecord);
-
-					// 鍔犲叆闃熷垪
-					CMQManager.getInstance().addIOSPushMsg(pushQueueRecord);
-
-					break;
-
-				} else {
-
-					// 璧峰娓告爣
-					pushQueueRecord.setStartCursor(i);
-
-					long endCursor = (i + totalCount) - 1;
-
-					// 缁撴潫娓告爣
-					pushQueueRecord.setEndCursor(endCursor);
-
-					// TODO 瀛樺叆鏁版嵁搴�
-					pushQueueRecordMapper.insert(pushQueueRecord);
-					// 鍔犲叆闃熷垪
-					CMQManager.getInstance().addIOSPushMsg(pushQueueRecord);
-				}
-
-				i += totalCount;
-			}
-
-		} catch (Exception e) {
-			// TODO Auto-generated catch block
-			e.printStackTrace();
-		}
-
-	}
-
-	/**
-	 * 闃熷垪鎵ц鎺ㄩ�佹搷浣�
-	 */
-	@Override
-	public void readyPushIOS(PushQueueRecord pushQueueRecord) throws Exception {
-
-		// 璧峰浣嶇疆
-		Long startCursor = pushQueueRecord.getStartCursor();
-		// 缁撴潫浣嶇疆
-		Long endCursor = pushQueueRecord.getEndCursor();
-
-		if (startCursor == null && endCursor == null) {
-			return;
-		}
-
-		int total = (int) (endCursor - startCursor);
-
-		// 姣忔鎺ㄩ�佹�绘潯鏁�
-		int moveNum = pushQueueRecord.getPushNum();
-
-		int count = total / moveNum;
-
-		if (total % moveNum > 0) {
-			count += 1;
-		}
-
-		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);
-				recordCursor = endCursor;
-
-				if (list != null) {
-					executePushIOS(list, pushQueueRecord, recordCursor);
-					PushLogHelper.iosInfo("鎺ㄩ�佹父鏍�:" + startCursor + "锛�" + moveNum);
-				}
-
-			} else {
-
-				if (recordCursor + moveNum > endCursor) {
-					// System.out.println("recordCursorend:" +recordCursor);
-					moveNum = (int) (endCursor - recordCursor);
-					// System.out.println(moveNum);
-					List<DeviceTokenIOS> list = deviceTokenIOSMapper.selectList(recordCursor, moveNum);
-					if (list != null) {
-						executePushIOS(list, pushQueueRecord, endCursor);
-						PushLogHelper.iosInfo("鎺ㄩ�佹父鏍�:" + recordCursor + "锛�" + moveNum);
-					}
-					recordCursor = endCursor;
-
-				} else {
-					List<DeviceTokenIOS> list = deviceTokenIOSMapper.selectList(recordCursor, moveNum);
-					recordCursor = recordCursor + 50;
-
-					if (list != null) {
-						executePushIOS(list, pushQueueRecord, recordCursor - 1);
-						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<>();
-		for (DeviceTokenIOS ios : list) {
-			if (!StringUtil.isNullOrEmpty(ios.getDeviceToken())) {
-				tokenList.add(ios.getDeviceToken());
-				// System.out.println(ios.getDeviceToken());
-			}
-		}
-
-		if (tokenList.size() > 0) {
-			// System.out.println(tokenList.size());
-			// 鎵ц鎺ㄩ��
-			try {
-				IOSPushUtil.executePushIOS(tokenList, json);
-			} catch (Exception e) {
-				// TODO Auto-generated catch block
-				e.printStackTrace();
-			}
-		}
-		pushQueueRecord.setState(1);
-		pushQueueRecord.setEndtime(new Date());
-		pushQueueRecord.setRecordCursor(recordCursor);
-
-		// TODO 鏇存柊鏁版嵁搴�
-		pushQueueRecordMapper.updateByPrimaryKeySelective(pushQueueRecord);
-	}
-
-}
+package com.yeshi.fanli.service.impl.push;
+
+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.SystemEnum;
+import com.yeshi.fanli.entity.bus.user.AccountMessage;
+import com.yeshi.fanli.entity.config.SystemConfigKeyEnum;
+import com.yeshi.fanli.entity.push.DeviceTokenIOS;
+import com.yeshi.fanli.entity.push.PushQueueRecord;
+import com.yeshi.fanli.entity.system.SystemZnx;
+import com.yeshi.fanli.entity.xinge.MessageInfo;
+import com.yeshi.fanli.entity.xinge.PushRecord;
+import com.yeshi.fanli.exception.push.PushException;
+import com.yeshi.fanli.log.PushLogHelper;
+import com.yeshi.fanli.service.inter.config.SystemConfigService;
+import com.yeshi.fanli.service.inter.push.IOSPushService;
+import com.yeshi.fanli.service.inter.user.UserCustomSettingsService;
+import com.yeshi.fanli.util.Constant;
+import com.yeshi.fanli.util.StringUtil;
+import com.yeshi.fanli.util.mq.rabbit.RabbitmqManager;
+import com.yeshi.fanli.util.push.IOSPushUtil;
+import net.sf.json.JSONObject;
+import org.springframework.scheduling.annotation.Async;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+
+import javax.annotation.Resource;
+import java.util.*;
+
+@Service
+public class IOSPushServiceImpl implements IOSPushService {
+
+    @Resource
+    private DeviceTokenIOSMapper deviceTokenIOSMapper;
+
+    @Resource
+    private PushQueueRecordMapper pushQueueRecordMapper;
+
+    @Resource
+    private UserCustomSettingsService userCustomSettingsService;
+
+    @Resource
+    private SystemConfigService systemConfigService;
+
+    @Resource
+    private RabbitmqManager rabbitmqManager;
+
+
+    @Async("pushExecutor")
+    @Override
+    public void pushGoods(Long uid, String auctionId, String title, String content, String versionCodes, SystemEnum system)
+            throws PushException {
+
+        String url = "https://item.taobao.com/item.htm?id=" + auctionId;
+        JSONObject json = new JSONObject();
+        json.put("id", auctionId);
+        json.put("type", "goodsdetail");
+        json.put("miPushUrl", String.format("%s.ui.recommend.GoodsBrowserActivity",
+                systemConfigService.getValueCache(SystemConfigKeyEnum.androidBaseActivityName,system)));
+
+        MessageInfo info = new MessageInfo();
+        info.setTitle(title);
+        info.setContent(content);
+        info.setDescription(content);
+        info.setPackageName(systemConfigService.getValueCache(SystemConfigKeyEnum.androidPackageNames,system));
+        info.setActivty(String.format("%s.ui.recommend.GoodsBrowserActivity",
+                systemConfigService.getValueCache(SystemConfigKeyEnum.androidBaseActivityName,system)));
+
+        PushRecord pushRecord = new PushRecord();
+        pushRecord.setState(1);
+        pushRecord.setType(PushTypeEnum.goodsdetail.getCode()); // 閮芥垚鍔�
+        pushRecord.setUrl(url);
+        pushRecord.setTitle(title);
+        pushRecord.setAppName(Constant.systemCommonConfig.getProjectChineseName());
+
+        if (uid == null || uid == 0) {
+
+            addPushIOSQueue(info, url, PushTypeEnum.goodsdetail.getCode(), versionCodes,system);
+
+            /*
+             * // 鏌ヨIOS鎵�鏈夎澶囧彿 // TODO 闇�瑕佸叏鎺� List<String> deviceTokenList =
+             * getDeviceTokenList(1, 20000); // IOS 鍏ㄦ帹 ThreadUtil.run(new
+             * Runnable() {
+             *
+             * @Override public void run() { try {
+             * IOSPushUtil.allPushIOS(deviceTokenList, info, url,
+             * PushController.GOODS); } catch (Exception e) {
+             * PushLogHelper.iosError(e);
+             *
+             * } } });
+             */
+        } else {
+            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) {
+                    deviceTokenList.add(ios.getDeviceToken());
+                }
+
+            try {
+                IOSPushUtil.allPushIOS(deviceTokenList, info, url, PushTypeEnum.goodsdetail.getCode(),systemConfigService.getValueCache(SystemConfigKeyEnum.iosPushCertPwd,system));
+            } catch (Exception e) {
+                PushLogHelper.iosError(e);
+            }
+
+        }
+    }
+
+    @Async("pushExecutor")
+    @Override
+    public void pushUrl(Long uid, String url, String title, String content, String versionCodes, SystemEnum system) throws PushException {
+        JSONObject json = new JSONObject();
+        json.put("url", url);
+        json.put("type", "url");
+        json.put("webUrl", url);
+        json.put("miPushUrl",
+                String.format("%s.ui.BrowserActivity",systemConfigService.getValueCache(SystemConfigKeyEnum.androidBaseActivityName,system)));
+
+        MessageInfo info = new MessageInfo();
+        info.setTitle(title);
+        info.setContent(content);
+        info.setDescription(content);
+        // 灏忕背鎺ㄩ�佺綉椤�
+        info.setPackageName(systemConfigService.getValueCache(SystemConfigKeyEnum.androidPackageNames,system));
+        info.setActivty(
+                String.format("%s.ui.BrowserActivity", systemConfigService.getValueCache(SystemConfigKeyEnum.androidBaseActivityName,system)));
+
+        PushRecord pushRecord = new PushRecord();
+        // IOS 鍏ㄦ帹
+        if (uid == null || uid == 0) {
+            // TODO 闇�瑕佸叏鎺�
+
+            addPushIOSQueue(info, url, PushTypeEnum.url.getCode(), versionCodes,system);
+
+            /*
+             * List<String> deviceTokenList = getDeviceTokenList(1, 1000);
+             * ThreadUtil.run(new Runnable() {
+             *
+             * @Override public void run() { try {
+             *
+             * IOSPushUtil.allPushIOS(deviceTokenList, info, url,
+             * PushController.URL);
+             *
+             * } catch (Exception e) { PushLogHelper.iosError(e); } } });
+             */
+        } else {
+            if (!validateNotDisturbSingle(uid)) {
+                return; // 閫氱煡鍏嶆墦鎵�(20:00-24:00 / 00:00 -08:00)
+            }
+
+            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, url, PushTypeEnum.url.getCode(),systemConfigService.getValueCache(SystemConfigKeyEnum.iosPushCertPwd,system));
+            } catch (Exception e) {
+                PushLogHelper.iosError(e);
+            }
+        }
+    }
+
+    @Async("pushExecutor")
+    @Override
+    public void pushZNX(Long uId, AccountMessage msg, SystemZnx systemZNX, String versionCodes, SystemEnum system) throws PushException {
+        MessageInfo info = new MessageInfo();
+        info.setPackageName(systemConfigService.getValueCache(SystemConfigKeyEnum.androidPackageNames,system));
+
+        JSONObject contentJson = new JSONObject();
+        contentJson.put("isOpen", 0);
+        contentJson.put("createTime", java.lang.System.currentTimeMillis());
+
+        /* 鏃爑id , 骞挎挱 鏁版嵁鎻掑叆绯荤粺琛� */
+        if (systemZNX != null) {
+            info.setTitle(systemZNX.getTitle());
+            info.setContent(systemZNX.getContent());
+            contentJson.put("title", systemZNX.getTitle());
+            contentJson.put("content", systemZNX.getContent());
+            info.setDescription(systemZNX.getContent());
+
+            // 灏忕背寮�濮嬪叏鎺�
+            long id = systemZNX.getId();
+            contentJson.put("id", id);
+
+            JSONObject json = new JSONObject();
+            json.put("type", "ZNX");
+            json.put("content", contentJson);
+            json.put("miPushUrl", String.format("%s.ui.mine.AppMailDetailActivity",
+                    systemConfigService.getValueCache(SystemConfigKeyEnum.androidBaseActivityName,system)));
+
+            PushRecord pushRecord = new PushRecord();
+
+            // TODO 闇�瑕佸叏鎺�
+
+            addPushIOSQueue(info, id + "", PushTypeEnum.ZNX.getCode(), versionCodes,system);
+
+            /*
+             * List<String> deviceTokenList = getDeviceTokenList(1, 1000);
+             *
+             * ThreadUtil.run(new Runnable() {
+             *
+             * @Override public void run() { try {
+             * IOSPushUtil.allPushIOS(deviceTokenList, info, id + "",
+             * PushController.ZNX); } catch (Exception e) {
+             * PushLogHelper.iosError(e); }
+             *
+             * } });
+             */
+        } else if (msg != null) {
+
+            if (uId != null) {
+                if (!validateNotDisturbSingle(uId)) {
+                    return; // 閫氱煡鍏嶆墦鎵�(20:00-24:00 / 00:00 -08:00)
+                }
+            }
+
+            // 鎻掑叆鎺ㄩ�佽褰�
+            PushRecord pushRecord = new PushRecord();
+            info.setTitle(msg.getTitle());
+            info.setContent(msg.getContent());
+            contentJson.put("title", msg.getTitle());
+            contentJson.put("content", msg.getContent());
+            info.setDescription(msg.getContent());
+
+            info.setAlias(uId + "");
+            info.setPackageName(systemConfigService.getValueCache(SystemConfigKeyEnum.androidPackageNames,system));
+            info.setActivty(
+                    String.format("%s.ui.BrowserActivity",systemConfigService.getValueCache(SystemConfigKeyEnum.androidBaseActivityName,system)));
+
+            contentJson.put("id", msg.getId() + "");
+
+            JSONObject json = new JSONObject();
+            json.put("type", "ZNX");
+            json.put("content", contentJson);
+            json.put("miPushUrl", String.format("%s.ui.mine.AppMailDetailActivity",
+                    systemConfigService.getValueCache(SystemConfigKeyEnum.androidBaseActivityName,system)));
+
+            List<DeviceTokenIOS> deviceTokenIosList = getDeviceTokenListByUid(msg.getUserInfo().getId(), versionCodes);
+            List<String> deviceTokenList = new ArrayList<>();
+            if (deviceTokenIosList != null)
+                for (DeviceTokenIOS ios : deviceTokenIosList) {
+                    deviceTokenList.add(ios.getDeviceToken());
+                }
+
+            // IOS 鍗曟帹
+            try {
+                IOSPushUtil.allPushIOS(deviceTokenList, info, "0", PushTypeEnum.ZNX.getCode(),systemConfigService.getValueCache(SystemConfigKeyEnum.iosPushCertPwd,system));
+            } catch (Exception e) {
+                PushLogHelper.iosError(e);
+            }
+        }
+    }
+
+    @Transactional
+    @Override
+    public void addDeviceToken(Long uid, int version, String deviceToken, String device) {
+        // 濡傛灉device涓虹┖灏辫繑鍥�
+        if (StringUtil.isNullOrEmpty(device) || StringUtil.isNullOrEmpty(deviceToken))
+            return;
+
+        // 鍒ゆ柇device鏄惁瀛樺湪
+        DeviceTokenIOS deviceTokenIos = deviceTokenIOSMapper.selectByDeviceForUpdate(device);
+        if (deviceTokenIos == null) {
+            deviceTokenIos = new DeviceTokenIOS();
+            deviceTokenIos.setCreateTime(new Date());
+            deviceTokenIos.setUpdateTime(new Date());
+            deviceTokenIos.setDevice(device);
+            deviceTokenIos.setDeviceToken(deviceToken);
+            deviceTokenIos.setDeviceTokenMd5(StringUtil.Md5(deviceToken));
+            deviceTokenIos.setUid(uid);
+            deviceTokenIos.setVersion(version);
+            deviceTokenIOSMapper.insertSelective(deviceTokenIos);
+        } else {// 鏇存柊devicetoken
+            DeviceTokenIOS updateDeviceTokenIOS = new DeviceTokenIOS();
+            updateDeviceTokenIOS.setId(deviceTokenIos.getId());
+            updateDeviceTokenIOS.setDeviceToken(deviceToken);
+            updateDeviceTokenIOS.setDeviceTokenMd5(StringUtil.Md5(deviceToken));
+            updateDeviceTokenIOS.setUid(uid);
+            updateDeviceTokenIOS.setUpdateTime(new Date());
+            deviceTokenIOSMapper.updateByPrimaryKeySelective(updateDeviceTokenIOS);
+        }
+
+    }
+
+    @Override
+    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, null);
+        List<String> tokenList = new ArrayList<>();
+        for (DeviceTokenIOS ios : list)
+            if (!StringUtil.isNullOrEmpty(ios.getDeviceToken()))
+                tokenList.add(ios.getDeviceToken());
+        return tokenList;
+    }
+
+    @Override
+    public long getDeviceTokenCount() {
+        return deviceTokenIOSMapper.selectCount();
+    }
+
+    @Override
+    public void updateDeviceToken(DeviceTokenIOS deviceTokenIos) {
+        if (deviceTokenIos != null) {
+            deviceTokenIos.setUpdateTime(new Date());
+            deviceTokenIOSMapper.updateByPrimaryKey(deviceTokenIos);
+        }
+    }
+
+    @Override
+    public DeviceTokenIOS getDeviceTokenByDeviceToken(String deviceToken) {
+        return deviceTokenIOSMapper.selectByDeviceToken(deviceToken);
+    }
+
+    /**
+     * 淇濆瓨鎺ㄩ�佸唴瀹瑰彧闃熷垪涓�
+     */
+    @Transactional(rollbackFor = Exception.class)
+    public void addPushIOSQueue(MessageInfo info, String url, int type, String versionCodes,SystemEnum system) throws PushException {
+
+        if (Constant.IS_TEST)
+            return;
+
+        try {
+
+            JSONObject json = IOSPushUtil.getJSONObject(info, url, type);
+
+            // 鎬绘潯鐩�
+            long tokenCount = getDeviceTokenCount();
+
+            // 涓�涓槦鍒� 1000 鏉�
+            long totalCount = 1000;
+
+            // 姣忔鎵ц鏉$洰
+            int pushNum = 50;
+
+            for (long i = 0; i < tokenCount + totalCount; ) {
+
+                PushQueueRecord pushQueueRecord = new PushQueueRecord();
+                pushQueueRecord.setSystem(system);
+                // 鍒濆鐘舵��
+                pushQueueRecord.setState(0);
+                // 鍙戦�佸唴瀹�
+                pushQueueRecord.setJsonContent(json.toString());
+                // 鍒涘缓鏃堕棿
+                pushQueueRecord.setCreatetime(new Date());
+                // 姣忔鎺ㄩ�佹暟閲�
+                pushQueueRecord.setPushNum(pushNum);
+                // 鎺ㄩ�佺 IOS
+                pushQueueRecord.setType(1);
+                // 鐗堟湰鍙�
+                pushQueueRecord.setVersions(versionCodes);
+
+                if (tokenCount - i < totalCount) {
+                    // 璧峰娓告爣
+                    pushQueueRecord.setStartCursor(i);
+                    // 缁撴潫娓告爣
+                    pushQueueRecord.setEndCursor(tokenCount);
+
+                    // 瀛樺叆鏁版嵁搴�
+                    pushQueueRecordMapper.insert(pushQueueRecord);
+
+                    // 鍔犲叆闃熷垪
+                    rabbitmqManager.addIOSPushMsg(pushQueueRecord);
+
+                    break;
+
+                } else {
+
+                    // 璧峰娓告爣
+                    pushQueueRecord.setStartCursor(i);
+
+                    long endCursor = (i + totalCount) - 1;
+
+                    // 缁撴潫娓告爣
+                    pushQueueRecord.setEndCursor(endCursor);
+
+                    // 瀛樺叆鏁版嵁搴�
+                    pushQueueRecordMapper.insert(pushQueueRecord);
+                    // 鍔犲叆闃熷垪
+                    rabbitmqManager.addIOSPushMsg(pushQueueRecord);
+                }
+
+                i += totalCount;
+            }
+
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+
+    }
+
+    /**
+     * 闃熷垪鎵ц鎺ㄩ�佹搷浣�
+     */
+    @Override
+    public void readyPushIOS(PushQueueRecord pushQueueRecord) throws Exception {
+
+        // 璧峰浣嶇疆
+        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);
+
+        // 姣忔鎺ㄩ�佹�绘潯鏁�
+        int moveNum = pushQueueRecord.getPushNum();
+
+        int count = total / moveNum;
+
+        if (total % moveNum > 0) {
+            count += 1;
+        }
+
+        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, listCode);
+                recordCursor = endCursor;
+
+                if (list != null) {
+                    executePushIOS(list, pushQueueRecord, recordCursor,pushQueueRecord.getSystem());
+                    PushLogHelper.iosInfo("鎺ㄩ�佹父鏍�:" + startCursor + "锛�" + moveNum);
+                }
+
+            } else {
+
+                if (recordCursor + moveNum > endCursor) {
+                    // System.out.println("recordCursorend:" +recordCursor);
+                    moveNum = (int) (endCursor - recordCursor);
+                    // System.out.println(moveNum);
+                    List<DeviceTokenIOS> list = deviceTokenIOSMapper.selectList(recordCursor, moveNum, listCode);
+                    if (list != null) {
+                        executePushIOS(list, pushQueueRecord, endCursor,pushQueueRecord.getSystem());
+                        PushLogHelper.iosInfo("鎺ㄩ�佹父鏍�:" + recordCursor + "锛�" + moveNum);
+                    }
+                    recordCursor = endCursor;
+
+                } else {
+                    List<DeviceTokenIOS> list = deviceTokenIOSMapper.selectList(recordCursor, moveNum, listCode);
+                    recordCursor = recordCursor + 50;
+
+                    if (list != null) {
+                        executePushIOS(list, pushQueueRecord, recordCursor - 1,pushQueueRecord.getSystem());
+                        PushLogHelper.iosInfo("鎺ㄩ�佹父鏍�:" + recordCursor + "锛�" + moveNum);
+                    }
+                }
+            }
+        }
+    }
+
+    public void executePushIOS(List<DeviceTokenIOS> list, PushQueueRecord pushQueueRecord, long recordCursor,SystemEnum system) {
+
+        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 {
+//			listNotPushId = validateNotDisturb();
+//		}
+
+        ispush = true;//TODO 澶勭悊娑堟伅鍏嶆墦鎵�
+
+        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)
+                    }
+                }
+                tokenList.add(ios.getDeviceToken());
+            }
+        }
+
+        if (tokenList.size() > 0) {
+            // 鎵ц鎺ㄩ��
+            try {
+                IOSPushUtil.executePushIOS(tokenList, json,systemConfigService.getValueCache(SystemConfigKeyEnum.iosPushCertPwd,system));
+            } catch (Exception e) {
+                e.printStackTrace();
+            }
+        }
+        pushQueueRecord.setState(1);
+        pushQueueRecord.setEndtime(new Date());
+        pushQueueRecord.setRecordCursor(recordCursor);
+
+        // 鏇存柊鏁版嵁搴�
+        pushQueueRecordMapper.updateByPrimaryKeySelective(pushQueueRecord);
+    }
+
+    @Override
+    public void unBindUidAndDevice(String device) {
+        if (StringUtil.isNullOrEmpty(device))
+            return;
+        DeviceTokenIOS deviceTokenIOS = deviceTokenIOSMapper.selectByDevice(device);
+        if (device != null) {
+            deviceTokenIOS.setUpdateTime(new Date());
+            deviceTokenIOS.setUid(null);
+            deviceTokenIOSMapper.updateByPrimaryKey(deviceTokenIOS);
+        }
+    }
+
+    @Async("pushExecutor")
+    @Override
+    public void pushWEEX(Long uid, String title, String content, String weexUrl, String versionCodes, SystemEnum system)
+            throws PushException {
+        MessageInfo info = new MessageInfo();
+        info.setTitle(title);
+        info.setContent(content);
+        info.setDescription(content);
+        // IOS 鍏ㄦ帹
+        if (uid == null || uid == 0) {
+            addPushIOSQueue(info, weexUrl, PushTypeEnum.weex.getCode(), versionCodes,system);
+        } else {
+            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, weexUrl, PushTypeEnum.weex.getCode(),systemConfigService.getValueCache(SystemConfigKeyEnum.iosPushCertPwd,system));
+            } catch (Exception e) {
+                PushLogHelper.iosError(e);
+            }
+        }
+    }
+
+    @Async("pushExecutor")
+    @Override
+    public void pushBaiChuanUrl(Long uid, String title, String content, String url, String versionCodes, SystemEnum system)
+            throws PushException {
+        MessageInfo info = new MessageInfo();
+        info.setTitle(title);
+        info.setContent(content);
+        info.setDescription(content);
+        // IOS 鍏ㄦ帹
+        if (uid == null || uid == 0) {
+            addPushIOSQueue(info, url, PushTypeEnum.baichuan.getCode(), versionCodes,system);
+        } else {
+            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, url, PushTypeEnum.baichuan.getCode(),systemConfigService.getValueCache(SystemConfigKeyEnum.iosPushCertPwd,system));
+            } catch (Exception e) {
+                PushLogHelper.iosError(e);
+            }
+        }
+    }
+
+    /**
+     * 閫氱煡鍏嶆墦鎵�(20:00-8:00)
+     */
+    public List<Long> validateNotDisturb() {
+        return userCustomSettingsService.getCancelNoticeUsers();
+    }
+
+    /**
+     * 閫氱煡鍏嶆墦鎵�(20:00-8:00)
+     */
+    public boolean validateNotDisturbSingle(Long uid) {
+        Calendar now = Calendar.getInstance();
+        int hour = now.get(Calendar.HOUR_OF_DAY);
+        boolean ispush;
+        if (hour >= 8 && hour < 20) {
+            ispush = true; // 鍙帹閫�
+        } else {
+            // 鑷畾涔夎缃� 閫氱煡鍏嶆墦鎵�(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, SystemEnum system) throws PushException {
+        MessageInfo info = new MessageInfo();
+        info.setTitle(title);
+        info.setContent(content);
+        info.setDescription(content);
+        // IOS 鍏ㄦ帹
+        if (uid == null || uid == 0) {
+            addPushIOSQueue(info, "", PushTypeEnum.welfare.getCode(), versionCodes,system);
+        } 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, "", PushTypeEnum.welfare.getCode(),systemConfigService.getValueCache(SystemConfigKeyEnum.iosPushCertPwd,system));
+            } 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;
+    }
+
+    @Override
+    public void pushUserSignInNotification(Long uid, String title, String content, String versions, SystemEnum system)
+            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,system);
+        } 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(),systemConfigService.getValueCache(SystemConfigKeyEnum.iosPushCertPwd,system));
+            } catch (Exception e) {
+                PushLogHelper.iosError(e);
+            }
+        }
+    }
+
+}

--
Gitblit v1.8.0