| | |
| | | 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.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.push.IOSPushService;
|
| | | import com.yeshi.fanli.service.inter.user.UserCustomSettingsService;
|
| | |
| | |
|
| | | @Async("pushExecutor")
|
| | | @Override
|
| | | public void pushGoods(Long uid, Long auctionId, String title, String content, String versionCodes) 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();
|
| | |
| | |
|
| | | 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, versionCodes);
|
| | | addPushIOSQueue(info, url, PushTypeEnum.goodsdetail.getCode(), versionCodes);
|
| | |
|
| | | /*
|
| | | * // 查询IOS所有设备号 // TODO 需要全推 List<String> deviceTokenList =
|
| | |
| | | if (!validateNotDisturbSingle(uid)) {
|
| | | return; // 通知免打扰(20:00-24:00 / 00:00 -08:00)
|
| | | }
|
| | | |
| | |
|
| | | // IOS 单推
|
| | | List<DeviceTokenIOS> deviceTokenIosList = getDeviceTokenListByUid(uid, versionCodes);
|
| | | |
| | |
|
| | | List<String> deviceTokenList = new ArrayList<>();
|
| | | if (deviceTokenIosList != null)
|
| | | for (DeviceTokenIOS ios : deviceTokenIosList) {
|
| | |
| | | }
|
| | |
|
| | | try {
|
| | | IOSPushUtil.allPushIOS(deviceTokenList, info, url, PushController.GOODS);
|
| | | IOSPushUtil.allPushIOS(deviceTokenList, info, url, PushTypeEnum.goodsdetail.getCode());
|
| | | } catch (Exception e) {
|
| | | PushLogHelper.iosError(e);
|
| | | }
|
| | |
| | | if (uid == null || uid == 0) {
|
| | | // TODO 需要全推
|
| | |
|
| | | addPushIOSQueue(info, url, PushController.URL, versionCodes);
|
| | | addPushIOSQueue(info, url, PushTypeEnum.url.getCode(), versionCodes);
|
| | |
|
| | | /*
|
| | | * List<String> deviceTokenList = getDeviceTokenList(1, 1000);
|
| | |
| | | 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, String versionCodes) throws PushException {
|
| | |
| | |
|
| | | // TODO 需要全推
|
| | |
|
| | | addPushIOSQueue(info, id + "", PushController.ZNX, versionCodes);
|
| | | addPushIOSQueue(info, id + "", PushTypeEnum.ZNX.getCode(), versionCodes);
|
| | |
|
| | | /*
|
| | | * List<String> deviceTokenList = getDeviceTokenList(1, 1000);
|
| | |
| | |
|
| | | // IOS 单推
|
| | | try {
|
| | | IOSPushUtil.allPushIOS(deviceTokenList, info, "0", PushController.ZNX);
|
| | | IOSPushUtil.allPushIOS(deviceTokenList, info, "0", PushTypeEnum.ZNX.getCode());
|
| | | } catch (Exception e) {
|
| | | PushLogHelper.iosError(e);
|
| | | }
|
| | |
| | | return;
|
| | |
|
| | | // 判断device是否存在
|
| | | DeviceTokenIOS deviceTokenIos = deviceTokenIOSMapper.selectByDevice(device);
|
| | | DeviceTokenIOS deviceTokenIos = deviceTokenIOSMapper.selectByDeviceForUpdate(device);
|
| | | if (deviceTokenIos == null) {
|
| | | deviceTokenIos = new DeviceTokenIOS();
|
| | | deviceTokenIos.setCreateTime(new Date());
|
| | |
| | | *
|
| | | * @param json
|
| | | */
|
| | | @Transactional
|
| | | @Transactional(rollbackFor=Exception.class)
|
| | | public void addPushIOSQueue(MessageInfo info, String url, int type, String versionCodes) throws PushException {
|
| | |
|
| | | if (Constant.IS_TEST)
|
| | | return;
|
| | |
|
| | | try {
|
| | |
|
| | |
| | |
|
| | | // 每次执行条目
|
| | | int pushNum = 50;
|
| | | |
| | |
|
| | | for (long i = 0; i < tokenCount + totalCount;) {
|
| | |
|
| | | PushQueueRecord pushQueueRecord = new PushQueueRecord();
|
| | |
| | | pushQueueRecord.setType(1);
|
| | | // 版本号
|
| | | pushQueueRecord.setVersions(versionCodes);
|
| | | |
| | |
|
| | | if (tokenCount - i < totalCount) {
|
| | | // 起始游标
|
| | |
| | | Long startCursor = pushQueueRecord.getStartCursor();
|
| | | // 结束位置
|
| | | Long endCursor = pushQueueRecord.getEndCursor();
|
| | | |
| | |
|
| | | if (startCursor == null && endCursor == null) {
|
| | | return;
|
| | | }
|
| | |
|
| | | |
| | | // 推送的版本号
|
| | | String versions = pushQueueRecord.getVersions();
|
| | | List<Integer> listCode = convertVersionType(versions);
|
| | | |
| | | |
| | |
|
| | | int total = (int) (endCursor - startCursor);
|
| | |
|
| | | // 每次推送总条数
|
| | |
| | | long recordCursor = startCursor;
|
| | |
|
| | | for (int i = 0; i < count; i++) {
|
| | | |
| | |
|
| | | // 不足50个数据
|
| | | if (moveNum > total) {
|
| | | moveNum = (int) (endCursor - startCursor);
|
| | |
| | |
|
| | | 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) {
|
| | |
|
| | |
| | |
|
| | | @Async("pushExecutor")
|
| | | @Override
|
| | | public void pushWEEX(Long uid, String title, String content, String weexUrl,String versionCodes) 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, versionCodes);
|
| | | addPushIOSQueue(info, weexUrl, PushTypeEnum.weex.getCode(), versionCodes);
|
| | | } else {
|
| | | List<DeviceTokenIOS> deviceTokenIosList = getDeviceTokenListByUid(uid, versionCodes);
|
| | | List<String> deviceTokenList = new ArrayList<>();
|
| | |
| | | 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, String versionCodes) 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, versionCodes);
|
| | | addPushIOSQueue(info, url, PushTypeEnum.baichuan.getCode(), versionCodes);
|
| | | } else {
|
| | | List<DeviceTokenIOS> deviceTokenIosList = getDeviceTokenListByUid(uid, versionCodes);
|
| | | List<String> deviceTokenList = new ArrayList<>();
|
| | |
| | | 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);
|
| | | }
|
| | |
| | | info.setDescription(content);
|
| | | // IOS 全推
|
| | | if (uid == null || uid == 0) {
|
| | | addPushIOSQueue(info, "", PushController.WELFARE_CENTER, versionCodes);
|
| | | addPushIOSQueue(info, "", PushTypeEnum.welfare.getCode(), versionCodes);
|
| | | } else {
|
| | | if (!validateNotDisturbSingle(uid)) {
|
| | | return;
|
| | |
| | | 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);
|
| | | }
|
| | |
| | | }
|
| | | 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);
|
| | | }
|
| | | }
|
| | | }
|
| | |
|
| | | }
|