From 744594ef1a2f530fc3e86ea9dc48b62247f79420 Mon Sep 17 00:00:00 2001 From: admin <weikou2014> Date: 星期二, 19 五月 2020 17:13:23 +0800 Subject: [PATCH] 饿了么绘图,添加口碑 --- fanli/src/main/java/com/yeshi/fanli/service/impl/push/IOSPushServiceImpl.java | 207 ++++++++++++++++++++++++++------------------------- 1 files changed, 104 insertions(+), 103 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 648d0c5..2f90f03 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,22 +8,21 @@ import javax.annotation.Resource; +import org.springframework.scheduling.annotation.Async; 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.AppVersionInfo; +import com.yeshi.fanli.dto.push.PushTypeEnum; 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.exception.push.PushException; import com.yeshi.fanli.log.PushLogHelper; -import com.yeshi.fanli.service.inter.config.AppVersionService; import com.yeshi.fanli.service.inter.push.IOSPushService; import com.yeshi.fanli.service.inter.user.UserCustomSettingsService; import com.yeshi.fanli.util.CMQManager; @@ -44,13 +43,11 @@ @Resource private UserCustomSettingsService userCustomSettingsService; - - @Resource - private AppVersionService appVersionService; - + @Async("pushExecutor") @Override - public void pushGoods(Long uid, Long auctionId, String title, String content, List<String> listVersion) 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,14 +66,14 @@ PushRecord pushRecord = new PushRecord(); pushRecord.setState(1); - pushRecord.setType(PushController.GOODS); // 閮芥垚鍔� + pushRecord.setType(PushTypeEnum.goodsdetail.getCode()); // 閮芥垚鍔� pushRecord.setUrl(url); pushRecord.setTitle(title); pushRecord.setAppName(Constant.systemCommonConfig.getProjectChineseName()); if (uid == null || uid == 0) { - addPushIOSQueue(info, url, PushController.GOODS, listVersion); + addPushIOSQueue(info, url, PushTypeEnum.goodsdetail.getCode(), versionCodes); /* * // 鏌ヨIOS鎵�鏈夎澶囧彿 // TODO 闇�瑕佸叏鎺� List<String> deviceTokenList = @@ -96,7 +93,8 @@ } // IOS 鍗曟帹 - List<DeviceTokenIOS> deviceTokenIosList = getDeviceTokenListByUid(uid, listVersion); + List<DeviceTokenIOS> deviceTokenIosList = getDeviceTokenListByUid(uid, versionCodes); + List<String> deviceTokenList = new ArrayList<>(); if (deviceTokenIosList != null) for (DeviceTokenIOS ios : deviceTokenIosList) { @@ -104,7 +102,7 @@ } try { - IOSPushUtil.allPushIOS(deviceTokenList, info, url, PushController.GOODS); + IOSPushUtil.allPushIOS(deviceTokenList, info, url, PushTypeEnum.goodsdetail.getCode()); } catch (Exception e) { PushLogHelper.iosError(e); } @@ -112,8 +110,9 @@ } } + @Async("pushExecutor") @Override - public void pushUrl(Long uid, String url, String title, String content, List<String> listVersion) 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"); @@ -135,7 +134,7 @@ if (uid == null || uid == 0) { // TODO 闇�瑕佸叏鎺� - addPushIOSQueue(info, url, PushController.URL, listVersion); + addPushIOSQueue(info, url, PushTypeEnum.url.getCode(), versionCodes); /* * List<String> deviceTokenList = getDeviceTokenList(1, 1000); @@ -153,22 +152,23 @@ return; // 閫氱煡鍏嶆墦鎵�(20:00-24:00 / 00:00 -08:00) } - List<DeviceTokenIOS> deviceTokenIosList = getDeviceTokenListByUid(uid, listVersion); + 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, PushController.URL); + IOSPushUtil.allPushIOS(deviceTokenList, info, url, PushTypeEnum.url.getCode()); } catch (Exception e) { PushLogHelper.iosError(e); } } } + @Async("pushExecutor") @Override - public void pushZNX(Long uId, AccountMessage msg, SystemZnx systemZNX, List<String> listVersion) throws PushException { + public void pushZNX(Long uId, AccountMessage msg, SystemZnx systemZNX, String versionCodes) throws PushException { MessageInfo info = new MessageInfo(); info.setPackageName(Constant.systemCommonConfig.getAndroidPackageName()); @@ -198,7 +198,7 @@ // TODO 闇�瑕佸叏鎺� - addPushIOSQueue(info, id + "", PushController.ZNX, listVersion); + addPushIOSQueue(info, id + "", PushTypeEnum.ZNX.getCode(), versionCodes); /* * List<String> deviceTokenList = getDeviceTokenList(1, 1000); @@ -241,7 +241,7 @@ json.put("miPushUrl", String.format("%s.ui.mine.AppMailDetailActivity", Constant.systemCommonConfig.getAndroidBaseactivityName())); - List<DeviceTokenIOS> deviceTokenIosList = getDeviceTokenListByUid(msg.getUserInfo().getId(), listVersion); + List<DeviceTokenIOS> deviceTokenIosList = getDeviceTokenListByUid(msg.getUserInfo().getId(), versionCodes); List<String> deviceTokenList = new ArrayList<>(); if (deviceTokenIosList != null) for (DeviceTokenIOS ios : deviceTokenIosList) { @@ -250,7 +250,7 @@ // IOS 鍗曟帹 try { - IOSPushUtil.allPushIOS(deviceTokenList, info, "0", PushController.ZNX); + IOSPushUtil.allPushIOS(deviceTokenList, info, "0", PushTypeEnum.ZNX.getCode()); } catch (Exception e) { PushLogHelper.iosError(e); } @@ -265,7 +265,7 @@ return; // 鍒ゆ柇device鏄惁瀛樺湪 - DeviceTokenIOS deviceTokenIos = deviceTokenIOSMapper.selectByDevice(device); + DeviceTokenIOS deviceTokenIos = deviceTokenIOSMapper.selectByDeviceForUpdate(device); if (deviceTokenIos == null) { deviceTokenIos = new DeviceTokenIOS(); deviceTokenIos.setCreateTime(new Date()); @@ -289,17 +289,8 @@ } @Override - public List<DeviceTokenIOS> getDeviceTokenListByUid(Long uid, List<String> listVersion) throws PushException { - List<Integer> listCode = null; - if (listVersion != null && listVersion.size() > 0) { - // 鐗堟湰鍙锋帹閫侀檺鍒� - listCode = appVersionService.listVersionCodeByVersions(AppVersionInfo.PLATFORM_IOS,listVersion); - if (listCode == null || listCode.size() == 0) { - throw new PushException(1, "IOS鎺ㄩ�佸け璐ワ紝鎺ㄩ�佺増鏈笉瀛樺湪锛�"); - } - } - - return deviceTokenIOSMapper.selectByUid(uid, listCode); + public List<DeviceTokenIOS> getDeviceTokenListByUid(Long uid, String versionCodes) throws PushException { + return deviceTokenIOSMapper.selectByUid(uid, convertVersionType(versionCodes)); } @Override @@ -335,8 +326,11 @@ * * @param json */ - @Transactional - public void addPushIOSQueue(MessageInfo info, String url, int type, List<String> listVersion) throws PushException { + @Transactional(rollbackFor=Exception.class) + public void addPushIOSQueue(MessageInfo info, String url, int type, String versionCodes) throws PushException { + + if (Constant.IS_TEST) + return; try { @@ -351,30 +345,6 @@ // 姣忔鎵ц鏉$洰 int pushNum = 50; - String versionCodes = ""; - - if (listVersion != null && listVersion.size() > 0) { - // 鍔犲叆鐗堟湰鎺ㄩ�侀檺鍒� - List<Integer> listCode = appVersionService.listVersionCodeByVersions(AppVersionInfo.PLATFORM_IOS,listVersion); - - if (listCode != null && listCode.size() > 0) { - for (Integer code: listCode) { - versionCodes = versionCodes + code + ","; - } - - // 鍘婚櫎鏈熬閫楀彿 - if (versionCodes.endsWith(",")) { - versionCodes = versionCodes.substring(0, versionCodes.length() - 1); - } - } - - if (versionCodes == null || versionCodes.trim().length() == 0) { - throw new PushException(1, "IOS鎺ㄩ�佸け璐ワ紝鎺ㄩ�佺増鏈笉瀛樺湪锛�"); - } - - } - - for (long i = 0; i < tokenCount + totalCount;) { PushQueueRecord pushQueueRecord = new PushQueueRecord(); @@ -390,7 +360,6 @@ pushQueueRecord.setType(1); // 鐗堟湰鍙� pushQueueRecord.setVersions(versionCodes); - if (tokenCount - i < totalCount) { // 璧峰娓告爣 @@ -441,33 +410,15 @@ Long startCursor = pushQueueRecord.getStartCursor(); // 缁撴潫浣嶇疆 Long endCursor = pushQueueRecord.getEndCursor(); - + if (startCursor == null && endCursor == null) { return; } - // 鎺ㄩ�佺殑鐗堟湰鍙� String versions = pushQueueRecord.getVersions(); - List<Integer> listVersionCode = null; - if (versions != null && versions.trim().length() > 0) { - - List<String> listVersion = Arrays.asList(versions.split(",")); - if (listVersion != null && listVersion.size() > 0) { - listVersionCode = new ArrayList<Integer>(); - for (String version: listVersion) { - if (version != null && version.trim().length() > 0) { - listVersionCode.add(Integer.parseInt(version)); - } - } - } - - if (listVersionCode == null || listVersionCode.size() == 0) { - return; //鐗堟湰鍙峰瓨鍦ㄥ紓甯� - } - } - - + List<Integer> listCode = convertVersionType(versions); + int total = (int) (endCursor - startCursor); // 姣忔鎺ㄩ�佹�绘潯鏁� @@ -482,12 +433,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, listVersionCode); + List<DeviceTokenIOS> list = deviceTokenIOSMapper.selectList(startCursor, moveNum, listCode); recordCursor = endCursor; if (list != null) { @@ -501,7 +451,7 @@ // System.out.println("recordCursorend:" +recordCursor); moveNum = (int) (endCursor - recordCursor); // System.out.println(moveNum); - List<DeviceTokenIOS> list = deviceTokenIOSMapper.selectList(recordCursor, moveNum, listVersionCode); + List<DeviceTokenIOS> list = deviceTokenIOSMapper.selectList(recordCursor, moveNum, listCode); if (list != null) { executePushIOS(list, pushQueueRecord, endCursor); PushLogHelper.iosInfo("鎺ㄩ�佹父鏍�:" + recordCursor + "锛�" + moveNum); @@ -509,7 +459,7 @@ recordCursor = endCursor; } else { - List<DeviceTokenIOS> list = deviceTokenIOSMapper.selectList(recordCursor, moveNum, listVersionCode); + List<DeviceTokenIOS> list = deviceTokenIOSMapper.selectList(recordCursor, moveNum, listCode); recordCursor = recordCursor + 50; if (list != null) { @@ -533,11 +483,13 @@ Calendar now = Calendar.getInstance(); int hour = now.get(Calendar.HOUR_OF_DAY); - if (hour >= 8 && hour < 20) { - ispush = true; // 鍙帹閫� - } else { - listNotPushId = validateNotDisturb(); - } +// if (hour >= 8 && hour < 20) { +// ispush = true; // 鍙帹閫� +// } else { +// listNotPushId = validateNotDisturb(); +// } + + ispush=true;//TODO 澶勭悊娑堟伅鍏嶆墦鎵� for (DeviceTokenIOS ios : list) { @@ -580,48 +532,52 @@ } } + @Async("pushExecutor") @Override - public void pushWEEX(Long uid, String title, String content, String weexUrl, List<String> listVersion) 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, listVersion); + addPushIOSQueue(info, weexUrl, PushTypeEnum.weex.getCode(), versionCodes); } else { - List<DeviceTokenIOS> deviceTokenIosList = getDeviceTokenListByUid(uid, listVersion); + 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, PushController.WEEX); + IOSPushUtil.allPushIOS(deviceTokenList, info, weexUrl, PushTypeEnum.weex.getCode()); } catch (Exception e) { PushLogHelper.iosError(e); } } } + @Async("pushExecutor") @Override - public void pushBaiChuanUrl(Long uid, String title, String content, String url, List<String> listVersion) 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, listVersion); + addPushIOSQueue(info, url, PushTypeEnum.baichuan.getCode(), versionCodes); } else { - List<DeviceTokenIOS> deviceTokenIosList = getDeviceTokenListByUid(uid, listVersion); + 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, PushController.BAICHUAN); + IOSPushUtil.allPushIOS(deviceTokenList, info, url, PushTypeEnum.baichuan.getCode()); } catch (Exception e) { PushLogHelper.iosError(e); } @@ -652,27 +608,72 @@ return ispush; } + @Async("pushExecutor") @Override - public void pushWelfareCenter(Long uid, String title, String content, List<String> listVersion) throws PushException { + 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, listVersion); + addPushIOSQueue(info, "", PushTypeEnum.welfare.getCode(), versionCodes); } else { if (!validateNotDisturbSingle(uid)) { return; } - List<DeviceTokenIOS> deviceTokenIosList = getDeviceTokenListByUid(uid, listVersion); + 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); + IOSPushUtil.allPushIOS(deviceTokenList, info, "", PushTypeEnum.welfare.getCode()); + } 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) + 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); } -- Gitblit v1.8.0