From 69bee82b81626b82b7f39f0e459e4f56b1699b51 Mon Sep 17 00:00:00 2001 From: admin <weikou2014> Date: 星期三, 13 三月 2019 12:02:16 +0800 Subject: [PATCH] 正式数据库修改 --- fanli/src/main/java/com/yeshi/fanli/service/impl/push/IOSPushServiceImpl.java | 151 ++++++++++++++++++++++++++++++++++++++++++++++--- 1 files changed, 140 insertions(+), 11 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 17905a7..9576a6e 100644 --- a/fanli/src/main/java/com/yeshi/fanli/service/impl/push/IOSPushServiceImpl.java +++ b/fanli/src/main/java/com/yeshi/fanli/service/impl/push/IOSPushServiceImpl.java @@ -1,6 +1,7 @@ package com.yeshi.fanli.service.impl.push; import java.util.ArrayList; +import java.util.Calendar; import java.util.Date; import java.util.List; @@ -21,6 +22,7 @@ import com.yeshi.fanli.exception.PushException; import com.yeshi.fanli.log.PushLogHelper; import com.yeshi.fanli.service.inter.push.IOSPushService; +import com.yeshi.fanli.service.inter.user.UserCustomSettingsService; import com.yeshi.fanli.util.CMQManager; import com.yeshi.fanli.util.Constant; import com.yeshi.fanli.util.StringUtil; @@ -36,6 +38,9 @@ @Resource private PushQueueRecordMapper pushQueueRecordMapper; + + @Resource + private UserCustomSettingsService userCustomSettingsService; @Override public void pushGoods(Long uid, Long auctionId, String title, String content) throws PushException { @@ -79,6 +84,10 @@ * } } }); */ } else { + if (!validateNotDisturbSingle(uid)) { + return; // 閫氱煡鍏嶆墦鎵�(20:00-24:00 / 00:00 -08:00) + } + // IOS 鍗曟帹 List<DeviceTokenIOS> deviceTokenIosList = getDeviceTokenListByUid(uid); List<String> deviceTokenList = new ArrayList<>(); @@ -133,6 +142,10 @@ * } catch (Exception e) { PushLogHelper.iosError(e); } } }); */ } else { + if (!validateNotDisturbSingle(uid)) { + return; // 閫氱煡鍏嶆墦鎵�(20:00-24:00 / 00:00 -08:00) + } + List<DeviceTokenIOS> deviceTokenIosList = getDeviceTokenListByUid(uid); List<String> deviceTokenList = new ArrayList<>(); if (deviceTokenIosList != null) @@ -145,11 +158,6 @@ PushLogHelper.iosError(e); } } - } - - @Override - public void pushWEEXUrl(Long uid, String weexUrl, String title, String content) throws PushException { - } @Override @@ -198,6 +206,13 @@ * } }); */ } 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()); @@ -358,7 +373,7 @@ // 缁撴潫娓告爣 pushQueueRecord.setEndCursor(endCursor); - // TODO 瀛樺叆鏁版嵁搴� + // 瀛樺叆鏁版嵁搴� pushQueueRecordMapper.insert(pushQueueRecord); // 鍔犲叆闃熷垪 CMQManager.getInstance().addIOSPushMsg(pushQueueRecord); @@ -368,7 +383,6 @@ } } catch (Exception e) { - // TODO Auto-generated catch block e.printStackTrace(); } @@ -450,20 +464,36 @@ 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(); + } + 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()); - // 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(); } } @@ -471,7 +501,7 @@ pushQueueRecord.setEndtime(new Date()); pushQueueRecord.setRecordCursor(recordCursor); - // TODO 鏇存柊鏁版嵁搴� + // 鏇存柊鏁版嵁搴� pushQueueRecordMapper.updateByPrimaryKeySelective(pushQueueRecord); } @@ -487,4 +517,103 @@ } } + @Override + public void pushWEEX(Long uid, String title, String content, String weexUrl) 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); + } 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, weexUrl, PushController.WEEX); + } catch (Exception e) { + PushLogHelper.iosError(e); + } + } + } + + @Override + public void pushBaiChuanUrl(Long uid, String title, String content, String url) 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); + } 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.BAICHUAN); + } 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; + } + + @Override + public void pushWelfareCenter(Long uid, String title, String content) 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); + } else { + if (!validateNotDisturbSingle(uid)) { + return; + } + 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, "", PushController.WELFARE_CENTER); + } catch (Exception e) { + PushLogHelper.iosError(e); + } + } + } + } -- Gitblit v1.8.0