| | |
| | | package com.yeshi.fanli.service.impl.push;
|
| | |
|
| | | import java.util.ArrayList;
|
| | | import java.util.Arrays;
|
| | | import java.util.Calendar;
|
| | | import java.util.Date;
|
| | | import java.util.List;
|
| | |
|
| | | 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.entity.bus.user.AccountMessage;
|
| | | import com.yeshi.fanli.entity.push.DeviceTokenIOS;
|
| | | import com.yeshi.fanli.entity.push.PushQueueRecord;
|
| | |
| | | import com.yeshi.fanli.entity.xinge.PushRecord;
|
| | | import com.yeshi.fanli.exception.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;
|
| | |
| | |
|
| | | @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();
|
| | |
| | |
|
| | | if (uid == null || uid == 0) {
|
| | |
|
| | | addPushIOSQueue(info, url, PushController.GOODS, listVersion);
|
| | | addPushIOSQueue(info, url, PushController.GOODS, versionCodes);
|
| | |
|
| | | /*
|
| | | * // 查询IOS所有设备号 // TODO 需要全推 List<String> deviceTokenList =
|
| | |
| | | if (!validateNotDisturbSingle(uid)) {
|
| | | return; // 通知免打扰(20:00-24:00 / 00:00 -08:00)
|
| | | }
|
| | |
|
| | | |
| | | // 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) {
|
| | |
| | | }
|
| | | }
|
| | |
|
| | | @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");
|
| | |
| | | if (uid == null || uid == 0) {
|
| | | // TODO 需要全推
|
| | |
|
| | | addPushIOSQueue(info, url, PushController.URL, listVersion);
|
| | | addPushIOSQueue(info, url, PushController.URL, versionCodes);
|
| | |
|
| | | /*
|
| | | * List<String> deviceTokenList = getDeviceTokenList(1, 1000);
|
| | |
| | | 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) {
|
| | |
| | | }
|
| | | }
|
| | |
|
| | | |
| | | @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());
|
| | |
|
| | |
| | |
|
| | | // TODO 需要全推
|
| | |
|
| | | addPushIOSQueue(info, id + "", PushController.ZNX, listVersion);
|
| | | addPushIOSQueue(info, id + "", PushController.ZNX, versionCodes);
|
| | |
|
| | | /*
|
| | | * List<String> deviceTokenList = getDeviceTokenList(1, 1000);
|
| | |
| | | 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) {
|
| | |
| | | }
|
| | |
|
| | | @Override
|
| | | public List<DeviceTokenIOS> getDeviceTokenListByUid(Long uid, List<String> listVersion) {
|
| | | // 版本号
|
| | | List<Integer> listCode = appVersionService.listVersionCodeByVersions(AppVersionInfo.PLATFORM_IOS,listVersion);
|
| | |
|
| | | return deviceTokenIOSMapper.selectByUid(uid, listCode);
|
| | | public List<DeviceTokenIOS> getDeviceTokenListByUid(Long uid, String versionCodes) throws PushException {
|
| | | return deviceTokenIOSMapper.selectByUid(uid, convertVersionType(versionCodes));
|
| | | }
|
| | |
|
| | | @Override
|
| | |
| | | * @param json
|
| | | */
|
| | | @Transactional
|
| | | public void addPushIOSQueue(MessageInfo info, String url, int type, List<String> listVersion) {
|
| | | public void addPushIOSQueue(MessageInfo info, String url, int type, String versionCodes) throws PushException {
|
| | | |
| | | if(Constant.IS_TEST)
|
| | | return;
|
| | |
|
| | | try {
|
| | |
|
| | |
| | |
|
| | | // 每次执行条目
|
| | | int pushNum = 50;
|
| | |
|
| | | String versionCodes = "";
|
| | | 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);
|
| | | }
|
| | | }
|
| | |
|
| | | for (long i = 0; i < tokenCount + totalCount;) {
|
| | |
|
| | |
| | | Long startCursor = pushQueueRecord.getStartCursor();
|
| | | // 结束位置
|
| | | Long endCursor = pushQueueRecord.getEndCursor();
|
| | | // 版本号
|
| | | String[] versionArray = null;
|
| | | String versions = pushQueueRecord.getVersions();
|
| | | if (versions != null && versions.trim().length() == 0) {
|
| | | versionArray = versions.split(",");
|
| | | }
|
| | |
|
| | | if (startCursor == null && endCursor == null) {
|
| | | return;
|
| | | }
|
| | |
|
| | | |
| | | // 推送的版本号
|
| | | String versions = pushQueueRecord.getVersions();
|
| | | List<Integer> listCode = convertVersionType(versions);
|
| | | |
| | | |
| | | int total = (int) (endCursor - startCursor);
|
| | |
|
| | | // 每次推送总条数
|
| | |
| | |
|
| | | for (int i = 0; i < count; i++) {
|
| | |
|
| | | |
| | | // 不足50个数据
|
| | | if (moveNum > total) {
|
| | | moveNum = (int) (endCursor - startCursor);
|
| | | List<DeviceTokenIOS> list = deviceTokenIOSMapper.selectList(startCursor, moveNum, versionArray);
|
| | | List<DeviceTokenIOS> list = deviceTokenIOSMapper.selectList(startCursor, moveNum, listCode);
|
| | | recordCursor = endCursor;
|
| | |
|
| | | if (list != null) {
|
| | |
| | | // System.out.println("recordCursorend:" +recordCursor);
|
| | | moveNum = (int) (endCursor - recordCursor);
|
| | | // System.out.println(moveNum);
|
| | | List<DeviceTokenIOS> list = deviceTokenIOSMapper.selectList(recordCursor, moveNum, versionArray);
|
| | | List<DeviceTokenIOS> list = deviceTokenIOSMapper.selectList(recordCursor, moveNum, listCode);
|
| | | if (list != null) {
|
| | | executePushIOS(list, pushQueueRecord, endCursor);
|
| | | PushLogHelper.iosInfo("推送游标:" + recordCursor + "," + moveNum);
|
| | |
| | | recordCursor = endCursor;
|
| | |
|
| | | } else {
|
| | | List<DeviceTokenIOS> list = deviceTokenIOSMapper.selectList(recordCursor, moveNum, versionArray);
|
| | | List<DeviceTokenIOS> list = deviceTokenIOSMapper.selectList(recordCursor, moveNum, listCode);
|
| | | recordCursor = recordCursor + 50;
|
| | |
|
| | | if (list != null) {
|
| | |
| | | PushLogHelper.iosInfo("推送游标:" + recordCursor + "," + moveNum);
|
| | | }
|
| | | }
|
| | |
|
| | | // System.out.println("recordCursor:" +recordCursor);
|
| | | }
|
| | | }
|
| | |
|
| | | }
|
| | |
|
| | | public void executePushIOS(List<DeviceTokenIOS> list, PushQueueRecord pushQueueRecord, long recordCursor) {
|
| | |
| | | }
|
| | | }
|
| | |
|
| | | @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, PushController.WEEX, 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) {
|
| | |
| | | }
|
| | | }
|
| | |
|
| | | @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, PushController.BAICHUAN, 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) {
|
| | |
| | | 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, "", PushController.WELFARE_CENTER, 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) {
|
| | |
| | | }
|
| | | }
|
| | |
|
| | | 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;
|
| | | }
|
| | | |
| | | }
|