| | |
| | | package com.yeshi.fanli.service.impl.push;
|
| | |
|
| | | import java.util.ArrayList;
|
| | | import java.util.Calendar;
|
| | | import java.util.Date;
|
| | | import java.util.List;
|
| | |
|
| | | import javax.annotation.Resource;
|
| | |
|
| | | import net.sf.json.JSONObject;
|
| | |
|
| | | import org.springframework.stereotype.Service;
|
| | | import org.springframework.transaction.annotation.Transactional;
|
| | |
| | | import com.yeshi.fanli.entity.xinge.MessageInfo;
|
| | | import com.yeshi.fanli.entity.xinge.PushRecord;
|
| | | import com.yeshi.fanli.exception.PushException;
|
| | | import com.yeshi.fanli.log.LogHelper;
|
| | | 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;
|
| | | import com.yeshi.fanli.util.ThreadUtil;
|
| | | import com.yeshi.fanli.util.push.IOSPushUtil;
|
| | |
|
| | | import net.sf.json.JSONObject;
|
| | |
|
| | | @Service
|
| | | public class IOSPushServiceImpl implements IOSPushService {
|
| | |
| | |
|
| | | @Resource
|
| | | private PushQueueRecordMapper pushQueueRecordMapper;
|
| | |
|
| | | @Resource
|
| | | private UserCustomSettingsService userCustomSettingsService;
|
| | |
|
| | | @Override
|
| | | public void pushGoods(Long uid, Long auctionId, String title, String content) throws PushException {
|
| | |
| | | * } } });
|
| | | */
|
| | | } else {
|
| | | if (!validateNotDisturbSingle(uid)) {
|
| | | return; // 通知免打扰(20:00-24:00 / 00:00 -08:00)
|
| | | }
|
| | |
|
| | | // IOS 单推
|
| | | List<DeviceTokenIOS> deviceTokenIosList = getDeviceTokenListByUid(uid);
|
| | | List<String> deviceTokenList = new ArrayList<>();
|
| | |
| | | * } 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)
|
| | |
| | | PushLogHelper.iosError(e);
|
| | | }
|
| | | }
|
| | | }
|
| | |
|
| | | @Override
|
| | | public void pushWEEXUrl(Long uid, String weexUrl, String title, String content) throws PushException {
|
| | |
|
| | | }
|
| | |
|
| | | @Override
|
| | |
| | | * } });
|
| | | */
|
| | | } 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());
|
| | |
| | | @Override
|
| | | public void addDeviceToken(Long uid, int version, String deviceToken, String device) {
|
| | | // 如果device为空就返回
|
| | | if (StringUtil.isNullOrEmpty(device))
|
| | | if (StringUtil.isNullOrEmpty(device) || StringUtil.isNullOrEmpty(deviceToken))
|
| | | return;
|
| | |
|
| | | // 判断device是否存在
|
| | |
| | | deviceTokenIos.setUpdateTime(new Date());
|
| | | deviceTokenIos.setDevice(device);
|
| | | deviceTokenIos.setDeviceToken(deviceToken);
|
| | | deviceTokenIos.setDeviceTokenMd5(StringUtil.Md5(deviceToken));
|
| | | deviceTokenIos.setUid(uid);
|
| | | deviceTokenIos.setVersion(version);
|
| | | deviceTokenIOSMapper.insertSelective(deviceTokenIos);
|
| | | } else {// 更新devicetoken
|
| | | DeviceTokenIOS updateDeviceTokenIOS = new DeviceTokenIOS();
|
| | | updateDeviceTokenIOS.setId(deviceTokenIos.getId());
|
| | | updateDeviceTokenIOS.setDeviceToken(deviceToken);
|
| | | updateDeviceTokenIOS.setDeviceTokenMd5(StringUtil.Md5(deviceToken));
|
| | | updateDeviceTokenIOS.setUid(uid);
|
| | | updateDeviceTokenIOS.setUpdateTime(new Date());
|
| | | deviceTokenIOSMapper.updateByPrimaryKeySelective(updateDeviceTokenIOS);
|
| | | }
|
| | |
|
| | | }
|
| | |
| | | }
|
| | |
|
| | | @Override
|
| | | public DeviceTokenIOS getDeviceTokenByDevice(String device) {
|
| | | return deviceTokenIOSMapper.selectByDevice(device);
|
| | | public DeviceTokenIOS getDeviceTokenByDeviceToken(String deviceToken) {
|
| | | return deviceTokenIOSMapper.selectByDeviceToken(deviceToken);
|
| | | }
|
| | |
|
| | | /**
|
| | |
| | | // 结束游标
|
| | | pushQueueRecord.setEndCursor(endCursor);
|
| | |
|
| | | // TODO 存入数据库
|
| | | // 存入数据库
|
| | | pushQueueRecordMapper.insert(pushQueueRecord);
|
| | | // 加入队列
|
| | | CMQManager.getInstance().addIOSPushMsg(pushQueueRecord);
|
| | |
| | | }
|
| | |
|
| | | } catch (Exception e) {
|
| | | // TODO Auto-generated catch block
|
| | | e.printStackTrace();
|
| | | }
|
| | |
|
| | |
| | | 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();
|
| | | }
|
| | | }
|
| | |
| | | pushQueueRecord.setEndtime(new Date());
|
| | | pushQueueRecord.setRecordCursor(recordCursor);
|
| | |
|
| | | // TODO 更新数据库
|
| | | // 更新数据库
|
| | | pushQueueRecordMapper.updateByPrimaryKeySelective(pushQueueRecord);
|
| | | }
|
| | |
|
| | | @Override
|
| | | public void unBindUidAndDevice(String device) {
|
| | | if (StringUtil.isNullOrEmpty(device))
|
| | | return;
|
| | | DeviceTokenIOS deviceTokenIOS = deviceTokenIOSMapper.selectByDevice(device);
|
| | | if (device != null) {
|
| | | deviceTokenIOS.setUpdateTime(new Date());
|
| | | deviceTokenIOS.setUid(null);
|
| | | deviceTokenIOSMapper.updateByPrimaryKey(deviceTokenIOS);
|
| | | }
|
| | | }
|
| | |
|
| | | @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);
|
| | | }
|
| | | }
|
| | | }
|
| | |
|
| | | }
|