From 4f5a5b0a00c01491f009074351089f086f950d3e Mon Sep 17 00:00:00 2001 From: admin <weikou2014> Date: 星期二, 01 六月 2021 19:09:48 +0800 Subject: [PATCH] 系统配置改为数据库 --- fanli/src/main/java/com/yeshi/fanli/service/impl/push/IOSPushServiceImpl.java | 1086 ++++++++++++++++++++++++++++---------------------------- 1 files changed, 547 insertions(+), 539 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 29f629e..2c5919c 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 @@ -8,6 +8,9 @@ import javax.annotation.Resource; +import com.yeshi.fanli.entity.SystemEnum; +import com.yeshi.fanli.entity.config.SystemConfigKeyEnum; +import com.yeshi.fanli.service.inter.config.SystemConfigService; import org.springframework.scheduling.annotation.Async; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -35,649 +38,654 @@ @Service public class IOSPushServiceImpl implements IOSPushService { - @Resource - private DeviceTokenIOSMapper deviceTokenIOSMapper; + @Resource + private DeviceTokenIOSMapper deviceTokenIOSMapper; - @Resource - private PushQueueRecordMapper pushQueueRecordMapper; + @Resource + private PushQueueRecordMapper pushQueueRecordMapper; - @Resource - private UserCustomSettingsService userCustomSettingsService; + @Resource + private UserCustomSettingsService userCustomSettingsService; - @Async("pushExecutor") - @Override - public void pushGoods(Long uid, Long auctionId, String title, String content, String versionCodes) - throws PushException { + @Resource + private SystemConfigService systemConfigService; - 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())); + @Async("pushExecutor") + @Override + public void pushGoods(Long uid, Long auctionId, String title, String content, String versionCodes, SystemEnum system) + throws PushException { - PushRecord pushRecord = new PushRecord(); - pushRecord.setState(1); - pushRecord.setType(PushTypeEnum.goodsdetail.getCode()); // 閮芥垚鍔� - pushRecord.setUrl(url); - pushRecord.setTitle(title); - pushRecord.setAppName(Constant.systemCommonConfig.getProjectChineseName()); + 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))); - if (uid == null || uid == 0) { + 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))); - addPushIOSQueue(info, url, PushTypeEnum.goodsdetail.getCode(), versionCodes); + PushRecord pushRecord = new PushRecord(); + pushRecord.setState(1); + pushRecord.setType(PushTypeEnum.goodsdetail.getCode()); // 閮芥垚鍔� + pushRecord.setUrl(url); + pushRecord.setTitle(title); + pushRecord.setAppName(Constant.systemCommonConfig.getProjectChineseName()); - /* - * // 鏌ヨ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) - } + if (uid == null || uid == 0) { - // IOS 鍗曟帹 - List<DeviceTokenIOS> deviceTokenIosList = getDeviceTokenListByUid(uid, versionCodes); + addPushIOSQueue(info, url, PushTypeEnum.goodsdetail.getCode(), versionCodes,system); - List<String> deviceTokenList = new ArrayList<>(); - if (deviceTokenIosList != null) - for (DeviceTokenIOS ios : deviceTokenIosList) { - deviceTokenList.add(ios.getDeviceToken()); - } + /* + * // 鏌ヨ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) + } - try { - IOSPushUtil.allPushIOS(deviceTokenList, info, url, PushTypeEnum.goodsdetail.getCode()); - } catch (Exception e) { - PushLogHelper.iosError(e); - } + // IOS 鍗曟帹 + List<DeviceTokenIOS> deviceTokenIosList = getDeviceTokenListByUid(uid, versionCodes); - } - } + List<String> deviceTokenList = new ArrayList<>(); + if (deviceTokenIosList != null) + for (DeviceTokenIOS ios : deviceTokenIosList) { + deviceTokenList.add(ios.getDeviceToken()); + } - @Async("pushExecutor") - @Override - 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"); - json.put("webUrl", url); - json.put("miPushUrl", - String.format("%s.ui.BrowserActivity", Constant.systemCommonConfig.getAndroidBaseactivityName())); + try { + IOSPushUtil.allPushIOS(deviceTokenList, info, url, PushTypeEnum.goodsdetail.getCode(),systemConfigService.getValueCache(SystemConfigKeyEnum.iosPushCertPwd,system)); + } catch (Exception e) { + PushLogHelper.iosError(e); + } - 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 闇�瑕佸叏鎺� + @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))); - addPushIOSQueue(info, url, PushTypeEnum.url.getCode(), versionCodes); + 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))); - /* - * 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) - } + PushRecord pushRecord = new PushRecord(); + // IOS 鍏ㄦ帹 + if (uid == null || uid == 0) { + // TODO 闇�瑕佸叏鎺� - 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()); - } catch (Exception e) { - PushLogHelper.iosError(e); - } - } - } + addPushIOSQueue(info, url, PushTypeEnum.url.getCode(), versionCodes,system); - @Async("pushExecutor") - @Override - public void pushZNX(Long uId, AccountMessage msg, SystemZnx systemZNX, String versionCodes) throws PushException { - MessageInfo info = new MessageInfo(); - info.setPackageName(Constant.systemCommonConfig.getAndroidPackageName()); + /* + * 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) + } - JSONObject contentJson = new JSONObject(); - contentJson.put("isOpen", 0); - contentJson.put("createTime", java.lang.System.currentTimeMillis()); + 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); + } + } + } - /* 鏃爑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()); + @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)); - // 灏忕背寮�濮嬪叏鎺� - long id = systemZNX.getId(); - contentJson.put("id", id); + JSONObject contentJson = new JSONObject(); + contentJson.put("isOpen", 0); + contentJson.put("createTime", java.lang.System.currentTimeMillis()); - JSONObject json = new JSONObject(); - json.put("type", "ZNX"); - json.put("content", contentJson); - json.put("miPushUrl", String.format("%s.ui.mine.AppMailDetailActivity", - Constant.systemCommonConfig.getAndroidBaseactivityName())); + /* 鏃爑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()); - PushRecord pushRecord = new PushRecord(); + // 灏忕背寮�濮嬪叏鎺� + long id = systemZNX.getId(); + contentJson.put("id", id); - // TODO 闇�瑕佸叏鎺� + 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))); - addPushIOSQueue(info, id + "", PushTypeEnum.ZNX.getCode(), versionCodes); + PushRecord pushRecord = new PushRecord(); - /* - * 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) { + // TODO 闇�瑕佸叏鎺� - if (uId != null) { - if (!validateNotDisturbSingle(uId)) { - return; // 閫氱煡鍏嶆墦鎵�(20:00-24:00 / 00:00 -08:00) - } - } + addPushIOSQueue(info, id + "", PushTypeEnum.ZNX.getCode(), versionCodes,system); - // 鎻掑叆鎺ㄩ�佽褰� - 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()); + /* + * 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) { - info.setAlias(uId + ""); - info.setPackageName(Constant.systemCommonConfig.getAndroidPackageName()); - info.setActivty( - String.format("%s.ui.BrowserActivity", Constant.systemCommonConfig.getAndroidBaseactivityName())); + if (uId != null) { + if (!validateNotDisturbSingle(uId)) { + return; // 閫氱煡鍏嶆墦鎵�(20:00-24:00 / 00:00 -08:00) + } + } - contentJson.put("id", msg.getId() + ""); + // 鎻掑叆鎺ㄩ�佽褰� + 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()); - JSONObject json = new JSONObject(); - json.put("type", "ZNX"); - json.put("content", contentJson); - json.put("miPushUrl", String.format("%s.ui.mine.AppMailDetailActivity", - Constant.systemCommonConfig.getAndroidBaseactivityName())); + info.setAlias(uId + ""); + info.setPackageName(systemConfigService.getValueCache(SystemConfigKeyEnum.androidPackageNames,system)); + info.setActivty( + String.format("%s.ui.BrowserActivity",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()); - } + contentJson.put("id", msg.getId() + ""); - // IOS 鍗曟帹 - try { - IOSPushUtil.allPushIOS(deviceTokenList, info, "0", PushTypeEnum.ZNX.getCode()); - } catch (Exception e) { - PushLogHelper.iosError(e); - } - } - } + 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; + @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); - } + // 鍒ゆ柇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<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 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 long getDeviceTokenCount() { + return deviceTokenIOSMapper.selectCount(); + } - @Override - public void updateDeviceToken(DeviceTokenIOS deviceTokenIos) { - if (deviceTokenIos != null) { - deviceTokenIos.setUpdateTime(new Date()); - deviceTokenIOSMapper.updateByPrimaryKey(deviceTokenIos); - } - } + @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); - } + @Override + public DeviceTokenIOS getDeviceTokenByDeviceToken(String deviceToken) { + return deviceTokenIOSMapper.selectByDeviceToken(deviceToken); + } - /** - * 淇濆瓨鎺ㄩ�佸唴瀹瑰彧闃熷垪涓� - * - * @param json - */ - @Transactional(rollbackFor=Exception.class) - public void addPushIOSQueue(MessageInfo info, String url, int type, String versionCodes) throws PushException { + /** + * 淇濆瓨鎺ㄩ�佸唴瀹瑰彧闃熷垪涓� + * + * @param json + */ + @Transactional(rollbackFor = Exception.class) + public void addPushIOSQueue(MessageInfo info, String url, int type, String versionCodes,SystemEnum system) throws PushException { - if (Constant.IS_TEST) - return; + if (Constant.IS_TEST) + return; - try { + try { - JSONObject json = IOSPushUtil.getJSONObject(info, url, type); + JSONObject json = IOSPushUtil.getJSONObject(info, url, type); - // 鎬绘潯鐩� - long tokenCount = getDeviceTokenCount(); + // 鎬绘潯鐩� + long tokenCount = getDeviceTokenCount(); - // 涓�涓槦鍒� 1000 鏉� - long totalCount = 1000; + // 涓�涓槦鍒� 1000 鏉� + long totalCount = 1000; - // 姣忔鎵ц鏉$洰 - int pushNum = 50; + // 姣忔鎵ц鏉$洰 + int pushNum = 50; - for (long i = 0; i < tokenCount + totalCount;) { + 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); - // 鐗堟湰鍙� - pushQueueRecord.setVersions(versionCodes); + 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); + if (tokenCount - i < totalCount) { + // 璧峰娓告爣 + pushQueueRecord.setStartCursor(i); + // 缁撴潫娓告爣 + pushQueueRecord.setEndCursor(tokenCount); - // 瀛樺叆鏁版嵁搴� - pushQueueRecordMapper.insert(pushQueueRecord); + // 瀛樺叆鏁版嵁搴� + pushQueueRecordMapper.insert(pushQueueRecord); - // 鍔犲叆闃熷垪 - CMQManager.getInstance().addIOSPushMsg(pushQueueRecord); + // 鍔犲叆闃熷垪 + CMQManager.getInstance().addIOSPushMsg(pushQueueRecord); - break; + break; - } else { + } else { - // 璧峰娓告爣 - pushQueueRecord.setStartCursor(i); + // 璧峰娓告爣 + pushQueueRecord.setStartCursor(i); - long endCursor = (i + totalCount) - 1; + long endCursor = (i + totalCount) - 1; - // 缁撴潫娓告爣 - pushQueueRecord.setEndCursor(endCursor); + // 缁撴潫娓告爣 + pushQueueRecord.setEndCursor(endCursor); - // 瀛樺叆鏁版嵁搴� - pushQueueRecordMapper.insert(pushQueueRecord); - // 鍔犲叆闃熷垪 - CMQManager.getInstance().addIOSPushMsg(pushQueueRecord); - } + // 瀛樺叆鏁版嵁搴� + pushQueueRecordMapper.insert(pushQueueRecord); + // 鍔犲叆闃熷垪 + CMQManager.getInstance().addIOSPushMsg(pushQueueRecord); + } - i += totalCount; - } + i += totalCount; + } - } catch (Exception e) { - e.printStackTrace(); - } + } catch (Exception e) { + e.printStackTrace(); + } - } + } - /** - * 闃熷垪鎵ц鎺ㄩ�佹搷浣� - */ - @Override - public void readyPushIOS(PushQueueRecord pushQueueRecord) throws Exception { + /** + * 闃熷垪鎵ц鎺ㄩ�佹搷浣� + */ + @Override + public void readyPushIOS(PushQueueRecord pushQueueRecord) throws Exception { - // 璧峰浣嶇疆 - Long startCursor = pushQueueRecord.getStartCursor(); - // 缁撴潫浣嶇疆 - Long endCursor = pushQueueRecord.getEndCursor(); + // 璧峰浣嶇疆 + Long startCursor = pushQueueRecord.getStartCursor(); + // 缁撴潫浣嶇疆 + Long endCursor = pushQueueRecord.getEndCursor(); - if (startCursor == null && endCursor == null) { - return; - } + if (startCursor == null && endCursor == null) { + return; + } - // 鎺ㄩ�佺殑鐗堟湰鍙� - String versions = pushQueueRecord.getVersions(); - List<Integer> listCode = convertVersionType(versions); + // 鎺ㄩ�佺殑鐗堟湰鍙� + String versions = pushQueueRecord.getVersions(); + List<Integer> listCode = convertVersionType(versions); - int total = (int) (endCursor - startCursor); + int total = (int) (endCursor - startCursor); - // 姣忔鎺ㄩ�佹�绘潯鏁� - int moveNum = pushQueueRecord.getPushNum(); + // 姣忔鎺ㄩ�佹�绘潯鏁� + int moveNum = pushQueueRecord.getPushNum(); - int count = total / moveNum; + int count = total / moveNum; - if (total % moveNum > 0) { - count += 1; - } + if (total % moveNum > 0) { + count += 1; + } - long recordCursor = startCursor; + long recordCursor = startCursor; - for (int i = 0; i < count; i++) { + 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; + // 涓嶈冻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); - PushLogHelper.iosInfo("鎺ㄩ�佹父鏍�:" + startCursor + "锛�" + moveNum); - } + if (list != null) { + executePushIOS(list, pushQueueRecord, recordCursor,pushQueueRecord.getSystem()); + PushLogHelper.iosInfo("鎺ㄩ�佹父鏍�:" + startCursor + "锛�" + moveNum); + } - } else { + } 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); - PushLogHelper.iosInfo("鎺ㄩ�佹父鏍�:" + recordCursor + "锛�" + moveNum); - } - recordCursor = endCursor; + 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; + } else { + List<DeviceTokenIOS> list = deviceTokenIOSMapper.selectList(recordCursor, moveNum, listCode); + recordCursor = recordCursor + 50; - if (list != null) { - executePushIOS(list, pushQueueRecord, recordCursor - 1); - PushLogHelper.iosInfo("鎺ㄩ�佹父鏍�:" + recordCursor + "锛�" + moveNum); - } - } - } - } - } + if (list != null) { + executePushIOS(list, pushQueueRecord, recordCursor - 1,pushQueueRecord.getSystem()); + PushLogHelper.iosInfo("鎺ㄩ�佹父鏍�:" + recordCursor + "锛�" + moveNum); + } + } + } + } + } - public void executePushIOS(List<DeviceTokenIOS> list, PushQueueRecord pushQueueRecord, long recordCursor) { + public void executePushIOS(List<DeviceTokenIOS> list, PushQueueRecord pushQueueRecord, long recordCursor,SystemEnum system) { - String jsonContent = pushQueueRecord.getJsonContent(); - JSONObject json = JSONObject.fromObject(jsonContent); + String jsonContent = pushQueueRecord.getJsonContent(); + JSONObject json = JSONObject.fromObject(jsonContent); - List<String> tokenList = new ArrayList<>(); + List<String> tokenList = new ArrayList<>(); - boolean ispush = false; - List<Long> listNotPushId = null; + boolean ispush = false; + List<Long> listNotPushId = null; - Calendar now = Calendar.getInstance(); - int hour = now.get(Calendar.HOUR_OF_DAY); + 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) { + ispush = true;//TODO 澶勭悊娑堟伅鍏嶆墦鎵� - 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()); - } - } + for (DeviceTokenIOS ios : list) { - if (tokenList.size() > 0) { - // 鎵ц鎺ㄩ�� - try { - IOSPushUtil.executePushIOS(tokenList, json); - } catch (Exception e) { - e.printStackTrace(); - } - } - pushQueueRecord.setState(1); - pushQueueRecord.setEndtime(new Date()); - pushQueueRecord.setRecordCursor(recordCursor); + 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()); + } + } - // 鏇存柊鏁版嵁搴� - pushQueueRecordMapper.updateByPrimaryKeySelective(pushQueueRecord); - } + 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); - @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); - } - } + // 鏇存柊鏁版嵁搴� + pushQueueRecordMapper.updateByPrimaryKeySelective(pushQueueRecord); + } - @Async("pushExecutor") - @Override - 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, PushTypeEnum.weex.getCode(), versionCodes); - } 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()); - } catch (Exception e) { - PushLogHelper.iosError(e); - } - } - } + @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 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, PushTypeEnum.baichuan.getCode(), versionCodes); - } 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()); - } catch (Exception e) { - PushLogHelper.iosError(e); - } - } - } + @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); + } + } + } - /** - * 閫氱煡鍏嶆墦鎵�(20:00-8:00) - */ - public List<Long> validateNotDisturb() { - return userCustomSettingsService.getCancelNoticeUsers(); - } + @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 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); - } + /** + * 閫氱煡鍏嶆墦鎵�(20:00-8:00) + */ + public List<Long> validateNotDisturb() { + return userCustomSettingsService.getCancelNoticeUsers(); + } - return ispush; - } + /** + * 閫氱煡鍏嶆墦鎵�(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); + } - @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, "", PushTypeEnum.welfare.getCode(), 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, "", PushTypeEnum.welfare.getCode()); - } catch (Exception e) { - PushLogHelper.iosError(e); - } - } - } + return ispush; + } - private List<Integer> convertVersionType(String versionCodes) { - List<Integer> listVersionCode = null; + @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); + } + } + } - if (versionCodes != null && versionCodes.trim().length() > 0) { - List<String> listVersion = Arrays.asList(versionCodes.split(",")); - if (listVersion != null && listVersion.size() > 0) { + private List<Integer> convertVersionType(String versionCodes) { + List<Integer> listVersionCode = null; - listVersionCode = new ArrayList<Integer>(); - // 杞崲鎴愬姛鏁村瀷 - for (String version : listVersion) { - if (version != null && version.trim().length() > 0) { - listVersionCode.add(Integer.parseInt(version)); - } - } - } - } - return listVersionCode; - } + if (versionCodes != null && versionCodes.trim().length() > 0) { + List<String> listVersion = Arrays.asList(versionCodes.split(",")); + if (listVersion != null && listVersion.size() > 0) { - @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); - } - } - } + 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