From b3d001c65da02bdc83e92308cd23ed1525c98070 Mon Sep 17 00:00:00 2001 From: yujian <yujian> Date: 星期二, 19 三月 2019 17:29:05 +0800 Subject: [PATCH] 删除 RecommendSectionGoods相关+推送版本调整 --- fanli/src/main/java/com/yeshi/fanli/service/impl/push/PushServiceImpl.java | 343 ++++++++++++++++++++++++++++++++++++++++++++++---------- 1 files changed, 281 insertions(+), 62 deletions(-) diff --git a/fanli/src/main/java/com/yeshi/fanli/service/impl/push/PushServiceImpl.java b/fanli/src/main/java/com/yeshi/fanli/service/impl/push/PushServiceImpl.java index 482a9b5..17b462c 100644 --- a/fanli/src/main/java/com/yeshi/fanli/service/impl/push/PushServiceImpl.java +++ b/fanli/src/main/java/com/yeshi/fanli/service/impl/push/PushServiceImpl.java @@ -4,17 +4,18 @@ import javax.annotation.Resource; -import org.springframework.scheduling.annotation.Async; import org.springframework.stereotype.Service; import com.yeshi.fanli.controller.admin.PushController; import com.yeshi.fanli.dao.mybatis.AccountMessageMapper; import com.yeshi.fanli.dao.mybatis.push.PushRecordMapper; +import com.yeshi.fanli.entity.AppVersionInfo; import com.yeshi.fanli.entity.bus.user.AccountMessage; import com.yeshi.fanli.entity.bus.user.UserInfo; import com.yeshi.fanli.entity.system.SystemZnx; import com.yeshi.fanli.entity.xinge.PushRecord; import com.yeshi.fanli.exception.PushException; +import com.yeshi.fanli.service.inter.config.AppVersionService; import com.yeshi.fanli.service.inter.push.DeviceTokenHWService; import com.yeshi.fanli.service.inter.push.HWPushService; import com.yeshi.fanli.service.inter.push.IOSPushService; @@ -59,10 +60,14 @@ @Resource private AccountMessageMapper accountMessageMapper; - - @Async("pushExecutor") + + @Resource + private AppVersionService appVersionService; + + @Override - public void pushGoods(Long uid, String url, String title, String content, List<String> listVersion) throws PushException { + public void pushGoods(Long uid, String url, String title, String content, List<String> listIOS, + List<String> listAndroid) throws PushException { String gids = url.split("id=")[1]; String gid = gids.split("&")[0]; if (StringUtil.isNullOrEmpty(gid)) @@ -71,7 +76,27 @@ throw new PushException(1, "璇峰~鍐欐帹閫佹爣棰�"); if (StringUtil.isNullOrEmpty(content)) throw new PushException(1, "璇峰~鍐欐帹閫佸唴瀹�"); - + + + /* IOS绔帹閫� (娉ㄦ槑锛歭ist绛変簬 'null' 鏃跺叏鎺紝 size绛変簬0 涓嶅仛鎺ㄩ��) */ + if (listIOS == null || listIOS.size() > 0) { + // 闄愬埗鎺ㄩ�佺増鏈彿锛�0 + String codes = getEffectiveVersionCodes(0, AppVersionInfo.PLATFORM_IOS, listIOS); + if(listIOS == null || (listIOS.size() > 0 && codes != null && codes.trim().length() > 0)) { + iosPushService.pushGoods(uid, Long.parseLong(gid), title, content, codes); + } + } + + /* Android绔帹閫� (娉ㄦ槑锛歭ist绛変簬 'null' 鏃跺叏鎺紝 size绛変簬0 涓嶅仛鎺ㄩ��) */ + if (listAndroid == null || listAndroid.size() > 0) { + // 闄愬埗鎺ㄩ�佺増鏈彿锛�0 + String versions = getEffectiveVersions(0, AppVersionInfo.PLATFORM_ANDROID, listAndroid); + if(listAndroid == null || (listAndroid.size() > 0 && versions != null && versions.trim().length() > 0)) { + xmPushService.pushGoods(uid, Long.parseLong(gid), title, content, versions); + } + } + + PushRecord pushRecord = new PushRecord(); pushRecord.setState(1); pushRecord.setType(PushController.GOODS); // 閮芥垚鍔� @@ -80,17 +105,13 @@ pushRecord.setAppName(Constant.systemCommonConfig.getProjectChineseName()); pushRecord.setAccount(1); pushRecord.setCreatetime(java.lang.System.currentTimeMillis()); - - xmPushService.pushGoods(uid, Long.parseLong(gid), title, content, listVersion); - iosPushService.pushGoods(uid, Long.parseLong(gid), title, content, listVersion); - // hwPushService.pushGoods(uid, Long.parseLong(gid), title, content); - pushRecordMapper.insertSelective(pushRecord); } - @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, List<String> listIOS, + List<String> listAndroid) throws PushException { if (StringUtil.isNullOrEmpty(url)) throw new PushException(1, "鏃犳帹閫侀摼鎺�"); @@ -98,7 +119,28 @@ throw new PushException(1, "鏃犳帹閫佹爣棰�"); if (StringUtil.isNullOrEmpty(content)) throw new PushException(1, "鏃犳帹閫佸唴瀹�"); - + + + /* IOS绔帹閫� (娉ㄦ槑锛歭ist绛変簬 'null' 鏃跺叏鎺紝 size绛変簬0 涓嶅仛鎺ㄩ��) */ + if (listIOS == null || listIOS.size() > 0) { + // 闄愬埗鎺ㄩ�佺増鏈彿锛�0 + String codes = getEffectiveVersionCodes(0, AppVersionInfo.PLATFORM_IOS, listIOS); + if(listIOS == null || (listIOS.size() > 0 && codes != null && codes.trim().length() > 0)) { + iosPushService.pushUrl(uid, url, title, content, codes); + } + } + + /* Android绔帹閫� (娉ㄦ槑锛歭ist绛変簬 'null' 鏃跺叏鎺紝 size绛変簬0 涓嶅仛鎺ㄩ��) */ + if (listAndroid == null || listAndroid.size() > 0) { + // 闄愬埗鎺ㄩ�佺増鏈彿锛�0 + String versions = getEffectiveVersions(0, AppVersionInfo.PLATFORM_ANDROID, listAndroid); + if(listAndroid == null || (listAndroid.size() > 0 && versions != null && versions.trim().length() > 0)) { + xmPushService.pushUrl(uid, url, title, content, versions); + hwPushService.pushUrl(uid, url, title, content, versions); + } + } + + PushRecord pushRecord = new PushRecord(); pushRecord.setState(1); pushRecord.setType(PushController.URL); @@ -106,98 +148,275 @@ pushRecord.setTitle(title); pushRecord.setAppName(Constant.systemCommonConfig.getProjectChineseName()); pushRecord.setCreatetime(java.lang.System.currentTimeMillis()); - - xmPushService.pushUrl(uid, url, title, content, listVersion); - iosPushService.pushUrl(uid, url, title, content, listVersion); - hwPushService.pushUrl(uid, url, title, content, listVersion); pushRecordMapper.insertSelective(pushRecord); } - @Async("pushExecutor") + @Override - public void pushZNX(Long uId, String title, String content, List<String> listVersion) throws PushException { + public void pushZNX(Long uId, String title, String content, List<String> listIOS, + List<String> listAndroid) throws PushException { if (StringUtil.isNullOrEmpty(title)) throw new PushException(1, "鏃犳帹閫佹爣棰�"); if (StringUtil.isNullOrEmpty(content)) throw new PushException(1, "鏃犳帹閫佸唴瀹�"); + SystemZnx systemZnx = null; + AccountMessage accountMessage = null; + /* 鏃爑id , 骞挎挱 鏁版嵁鎻掑叆绯荤粺琛� */ if (uId == null || uId == 0) { // 鎻掑叆鏁版嵁搴擄紙绯荤粺绔欏唴淇℃暟鎹級 - SystemZnx systemZnx = new SystemZnx(); + systemZnx = new SystemZnx(); systemZnx.setTitle(title); systemZnx.setContent(content); systemZnx.setCreateTime(System.currentTimeMillis()); systemZnxService.save(systemZnx); - - PushRecord pushRecord = new PushRecord(); - pushRecord.setTitle(title); - pushRecord.setState(1); // 鎴愬姛 - pushRecord.setType(4); // 绫诲瀷锛氱珯鍐呬俊 - pushRecord.setAppName(Constant.systemCommonConfig.getProjectChineseName()); - pushRecord.setCreatetime(java.lang.System.currentTimeMillis()); - - xmPushService.pushZNX(uId, null, systemZnx, listVersion); - iosPushService.pushZNX(uId, null, systemZnx, listVersion); - hwPushService.pushZNX(uId, null, systemZnx, listVersion); - // 鎻掑叆鎺ㄩ�佽褰� - pushRecordMapper.insertSelective(pushRecord); } else { - AccountMessage accountMessage = new AccountMessage(); + accountMessage = new AccountMessage(); accountMessage.setCreateTime(System.currentTimeMillis()); accountMessage.setIsOpen(false); accountMessage.setUserInfo(new UserInfo(uId)); accountMessage.setTitle(title); accountMessage.setContent(content); accountMessageMapper.insertSelective(accountMessage); - - xmPushService.pushZNX(uId, accountMessage, null, listVersion); - iosPushService.pushZNX(uId, accountMessage, null, listVersion); - hwPushService.pushZNX(uId, accountMessage, null, listVersion); - - // 鎻掑叆鎺ㄩ�佽褰� - PushRecord pushRecord = new PushRecord(); - pushRecord.setTitle(title); - pushRecord.setUid(uId); - pushRecord.setState(1); // 鎴愬姛 - pushRecord.setType(PushController.ZNX); // 绫诲瀷锛氱珯鍐呬俊 - pushRecord.setAppName(Constant.systemCommonConfig.getProjectChineseName()); - pushRecord.setCreatetime(java.lang.System.currentTimeMillis()); - - pushRecordMapper.insertSelective(pushRecord); } + + + /* IOS绔帹閫� (娉ㄦ槑锛歭ist绛変簬 'null' 鏃跺叏鎺紝 size绛変簬0 涓嶅仛鎺ㄩ��) */ + if (listIOS == null || listIOS.size() > 0) { + // 闄愬埗鎺ㄩ�佺増鏈彿锛�0 + String codes = getEffectiveVersionCodes(0, AppVersionInfo.PLATFORM_IOS, listIOS); + if(listIOS == null || (listIOS.size() > 0 && codes != null && codes.trim().length() > 0)) { + iosPushService.pushZNX(uId, accountMessage, systemZnx, codes); + } + } + + /* Android绔帹閫� (娉ㄦ槑锛歭ist绛変簬 'null' 鏃跺叏鎺紝 size绛変簬0 涓嶅仛鎺ㄩ��) */ + if (listAndroid == null || listAndroid.size() > 0) { + // 闄愬埗鎺ㄩ�佺増鏈彿锛�0 + String versions = getEffectiveVersions(0, AppVersionInfo.PLATFORM_ANDROID, listAndroid); + if(listAndroid == null || (listAndroid.size() > 0 && versions != null && versions.trim().length() > 0)) { + xmPushService.pushZNX(uId, accountMessage, systemZnx, versions); + hwPushService.pushZNX(uId, accountMessage, systemZnx, versions); + } + } + + + // 鎻掑叆鎺ㄩ�佽褰� + PushRecord pushRecord = new PushRecord(); + pushRecord.setUid(uId); + pushRecord.setTitle(title); + pushRecord.setState(1); // 鎴愬姛 + pushRecord.setType(PushController.ZNX); // 绫诲瀷锛氱珯鍐呬俊 + pushRecord.setAppName(Constant.systemCommonConfig.getProjectChineseName()); + pushRecord.setCreatetime(java.lang.System.currentTimeMillis()); + pushRecordMapper.insertSelective(pushRecord); } + @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, List<String> listIOS, + List<String> listAndroid) throws PushException { if (StringUtil.isNullOrEmpty(title)) throw new PushException(1, "鏃犳帹閫佹爣棰�"); if (StringUtil.isNullOrEmpty(content)) throw new PushException(1, "鏃犳帹閫佸唴瀹�"); - iosPushService.pushWEEX(uid, title, content, weexUrl, listVersion); - } - - @Override - public void pushBaiChuanUrl(Long uid, String title, String content, String url, List<String> listVersion) throws PushException { - iosPushService.pushBaiChuanUrl(uid, title, content, url, listVersion); - xmPushService.pushBaiChuanUrl(uid, title, content, url, listVersion); + + // 閫傜敤鐗堟湰 1.4.8鍙婁互鍚� 鎺ㄩ�亀eex椤甸潰 + + /* IOS绔帹閫� (娉ㄦ槑锛歭ist绛変簬 'null' 鏃跺叏鎺紝 size绛変簬0 涓嶅仛鎺ㄩ��) */ + if (listIOS == null || listIOS.size() > 0) { + // 闄愬埗鎺ㄩ�佺増鏈彿锛�0 + String codes = getEffectiveVersionCodes(0, AppVersionInfo.PLATFORM_IOS, listIOS); + if(listIOS == null || (listIOS.size() > 0 && codes != null && codes.trim().length() > 0)) { + iosPushService.pushWEEX(uid, title, content, weexUrl, codes); + } + } + + /* Android绔帹閫� (娉ㄦ槑锛歭ist绛変簬 'null' 鏃跺叏鎺紝 size绛変簬0 涓嶅仛鎺ㄩ��) */ + if (listAndroid == null || listAndroid.size() > 0) { + // 闄愬埗鎺ㄩ�佺増鏈彿锛�31 + String versions = getEffectiveVersions(0, AppVersionInfo.PLATFORM_ANDROID, listAndroid); + if(listAndroid == null || (listAndroid.size() > 0 && versions != null && versions.trim().length() > 0)) { + xmPushService.pushWEEX(uid, title, content, weexUrl, versions); + } + } + // 鎻掑叆鎺ㄩ�佽褰� PushRecord pushRecord = new PushRecord(); pushRecord.setTitle(title); pushRecord.setUid(uid); pushRecord.setState(1); // 鎴愬姛 - pushRecord.setType(PushController.BAICHUAN); // 绫诲瀷锛氱櫨宸� + pushRecord.setType(PushController.WEEX); // 绫诲瀷锛歐EEX pushRecord.setAppName(Constant.systemCommonConfig.getProjectChineseName()); pushRecord.setCreatetime(java.lang.System.currentTimeMillis()); - pushRecordMapper.insertSelective(pushRecord); } + @Override - public void pushWelfareCenter(Long uid, String title, String content, List<String> listVersion) throws PushException { - iosPushService.pushWelfareCenter(uid, title, content, listVersion); - xmPushService.pushWelfareCenter(uid, title, content, listVersion); + public void pushBaiChuanUrl(Long uid, String title, String content, String url, List<String> listIOS, + List<String> listAndroid) throws PushException { + + if (StringUtil.isNullOrEmpty(title)) + throw new PushException(1, "鏃犳帹閫佹爣棰�"); + if (StringUtil.isNullOrEmpty(content)) + throw new PushException(1, "鏃犳帹閫佸唴瀹�"); + + // 閫傜敤鐗堟湰 1.4.8鍙婁互鍚� 鎺ㄩ�佺櫨宸濈綉椤� + + /* IOS绔帹閫� (娉ㄦ槑锛歭ist绛変簬 'null' 鏃跺叏鎺紝 size绛変簬0 涓嶅仛鎺ㄩ��) */ + if (listIOS == null || listIOS.size() > 0) { + // 闄愬埗鎺ㄩ�佺増鏈彿锛�0 + String codes = getEffectiveVersionCodes(0, AppVersionInfo.PLATFORM_IOS, listIOS); + if(listIOS == null || (listIOS.size() > 0 && codes != null && codes.trim().length() > 0)) { + iosPushService.pushBaiChuanUrl(uid, title, content, url, codes); + } + } + + /* Android绔帹閫� (娉ㄦ槑锛歭ist绛変簬 'null' 鏃跺叏鎺紝 size绛変簬0 涓嶅仛鎺ㄩ��) */ + if (listAndroid == null || listAndroid.size() > 0) { + // 闄愬埗鎺ㄩ�佺増鏈彿锛�31 + String versions = getEffectiveVersions(31, AppVersionInfo.PLATFORM_ANDROID, listAndroid); + if(listAndroid == null || (listAndroid.size() > 0 && versions != null && versions.trim().length() > 0)) { + xmPushService.pushBaiChuanUrl(uid, title, content, url, versions); + } + } + + + // 鎻掑叆鎺ㄩ�佽褰� + PushRecord pushRecord = new PushRecord(); + pushRecord.setUrl(url); + pushRecord.setTitle(title); + pushRecord.setUid(uid); + pushRecord.setState(1); // 鎴愬姛 + pushRecord.setType(PushController.BAICHUAN); // 绫诲瀷锛氱櫨宸� + pushRecord.setAppName(Constant.systemCommonConfig.getProjectChineseName()); + pushRecord.setCreatetime(java.lang.System.currentTimeMillis()); + pushRecordMapper.insertSelective(pushRecord); } + + @Override + public void pushWelfareCenter(Long uid, String title, String content, List<String> listIOS, + List<String> listAndroid) throws PushException { + + if (StringUtil.isNullOrEmpty(title)) + throw new PushException(1, "鏃犳帹閫佹爣棰�"); + if (StringUtil.isNullOrEmpty(content)) + throw new PushException(1, "鏃犳帹閫佸唴瀹�"); + + + /* IOS绔帹閫� (娉ㄦ槑锛歭ist绛変簬 'null' 鏃跺叏鎺紝 size绛変簬0 涓嶅仛鎺ㄩ��) */ + if (listIOS == null || listIOS.size() > 0) { + // 闄愬埗鎺ㄩ�佺増鏈彿锛�0 + String codes = getEffectiveVersionCodes(0, AppVersionInfo.PLATFORM_IOS, listIOS); + if(listIOS == null || (listIOS.size() > 0 && codes != null && codes.trim().length() > 0)) { + iosPushService.pushWelfareCenter(uid, title, content, codes); + } + } + + /* Android绔帹閫� (娉ㄦ槑锛歭ist绛変簬 'null' 鏃跺叏鎺紝 size绛変簬0 涓嶅仛鎺ㄩ��) */ + if (listAndroid == null || listAndroid.size() > 0) { + // 闄愬埗鎺ㄩ�佺増鏈彿锛�36 + String versions = getEffectiveVersions(36, AppVersionInfo.PLATFORM_ANDROID, listAndroid); + if(listAndroid == null || (listAndroid.size() > 0 && versions != null && versions.trim().length() > 0)) { + xmPushService.pushWelfareCenter(uid, title, content, versions); + } + } + + + // 鎻掑叆鎺ㄩ�佽褰� + PushRecord pushRecord = new PushRecord(); + pushRecord.setTitle(title); + pushRecord.setUid(uid); + pushRecord.setState(1); // 鎴愬姛 + pushRecord.setType(PushController.WELFARE_CENTER); // 绫诲瀷锛氱櫨宸� + pushRecord.setAppName(Constant.systemCommonConfig.getProjectChineseName()); + pushRecord.setCreatetime(java.lang.System.currentTimeMillis()); + pushRecordMapper.insertSelective(pushRecord); + } + + + + /** + * 鏌ヨ鑳芥帹閫佺増鏈彿 + * @param versionCode + * @param listVersion + * @return + */ + private String getEffectiveVersions(int minCode, String type, List<String> listVersion) throws PushException{ + + if (minCode == 0 && listVersion == null) { + return null; + } + + String versions = ""; + if (listVersion == null) { + List<AppVersionInfo> list = appVersionService.listByPlatformAndMinVersionCode(type, minCode); + if (list != null) { + for (AppVersionInfo appVersion : list) { + versions += appVersion.getVersion() + ","; + } + } + } else { + List<AppVersionInfo> list = appVersionService.listByVersions(type, listVersion); + if (list != null) { + for (AppVersionInfo appVersion : list) { + Integer code = appVersion.getVersionCode(); + if (code != null && code >= minCode) { + versions += appVersion.getVersion() + ","; + } + } + } + } + + if (versions.endsWith(",")) { + versions = versions.substring(0, versions.length() - 1); + } + + return versions; + } + + + /** + * 鏌ヨ鑳芥帹閫佺増鏈彿code + * @param versionCode + * @param listVersion + * @return + */ + private String getEffectiveVersionCodes(int minCode, String type, List<String> listVersion) throws PushException{ + + if (minCode == 0 && listVersion == null) { + return null; + } + + String versionCodes = ""; + if (listVersion == null) { + List<AppVersionInfo> list = appVersionService.listByPlatformAndMinVersionCode(type, minCode); + if (list != null) { + for (AppVersionInfo appVersion : list) { + versionCodes += appVersion.getVersionCode() + ","; + } + } + } else { + List<AppVersionInfo> list = appVersionService.listByVersions(type, listVersion); + if (list != null) { + for (AppVersionInfo appVersion : list) { + Integer code = appVersion.getVersionCode(); + if (code != null && code >= minCode) { + versionCodes += appVersion.getVersionCode() + ","; + } + } + } + } + + if (versionCodes.endsWith(",")) { + versionCodes = versionCodes.substring(0, versionCodes.length() - 1); + } + + return versionCodes; + } + } -- Gitblit v1.8.0