| | |
| | | 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.util.CMQManager;
|
| | |
| | |
|
| | | @Resource
|
| | | private DeviceTokenIOSMapper deviceTokenIOSMapper;
|
| | | |
| | |
|
| | | @Resource
|
| | | private PushQueueRecordMapper pushQueueRecordMapper;
|
| | | |
| | |
|
| | | @Override
|
| | | public void pushGoods(Long uid, Long auctionId, String title, String content) throws PushException {
|
| | |
| | | pushRecord.setAppName(Constant.systemCommonConfig.getProjectChineseName());
|
| | |
|
| | | if (uid == null || uid == 0) {
|
| | | |
| | | addPushIOSQueue(info, url, PushController.GOODS);
|
| | | |
| | | |
| | | /* // 查询IOS所有设备号
|
| | | // TODO 需要全推
|
| | | List<String> deviceTokenList = getDeviceTokenList(1, 20000);
|
| | | // IOS 全推
|
| | | ThreadUtil.run(new Runnable() {
|
| | |
|
| | | @Override
|
| | | public void run() {
|
| | | try {
|
| | | IOSPushUtil.allPushIOS(deviceTokenList, info, url, PushController.GOODS);
|
| | | } catch (Exception e) {
|
| | | PushLogHelper.iosError(e);
|
| | | |
| | | }
|
| | | }
|
| | | });*/
|
| | | addPushIOSQueue(info, url, PushController.GOODS);
|
| | |
|
| | | /*
|
| | | * // 查询IOS所有设备号 // TODO 需要全推 List<String> deviceTokenList =
|
| | | * getDeviceTokenList(1, 20000); // IOS 全推 ThreadUtil.run(new
|
| | | * Runnable() {
|
| | | * |
| | | * @Override public void run() { try {
|
| | | * IOSPushUtil.allPushIOS(deviceTokenList, info, url,
|
| | | * PushController.GOODS); } catch (Exception e) {
|
| | | * PushLogHelper.iosError(e);
|
| | | * |
| | | * } } });
|
| | | */
|
| | | } else {
|
| | | // IOS 单推
|
| | | List<DeviceTokenIOS> deviceTokenIosList = getDeviceTokenListByUid(uid);
|
| | |
| | | // IOS 全推
|
| | | if (uid == null || uid == 0) {
|
| | | // TODO 需要全推
|
| | | |
| | |
|
| | | addPushIOSQueue(info, url, PushController.URL);
|
| | | |
| | | /*List<String> deviceTokenList = getDeviceTokenList(1, 1000);
|
| | | ThreadUtil.run(new Runnable() {
|
| | |
|
| | | @Override
|
| | | public void run() {
|
| | | try {
|
| | |
|
| | | IOSPushUtil.allPushIOS(deviceTokenList, info, url, PushController.URL);
|
| | |
|
| | | } catch (Exception e) {
|
| | | PushLogHelper.iosError(e);
|
| | | }
|
| | | }
|
| | | });*/
|
| | | /*
|
| | | * List<String> deviceTokenList = getDeviceTokenList(1, 1000);
|
| | | * ThreadUtil.run(new Runnable() {
|
| | | * |
| | | * @Override public void run() { try {
|
| | | * |
| | | * IOSPushUtil.allPushIOS(deviceTokenList, info, url,
|
| | | * PushController.URL);
|
| | | * |
| | | * } catch (Exception e) { PushLogHelper.iosError(e); } } });
|
| | | */
|
| | | } else {
|
| | | List<DeviceTokenIOS> deviceTokenIosList = getDeviceTokenListByUid(uid);
|
| | | List<String> deviceTokenList = new ArrayList<>();
|
| | |
| | | PushRecord pushRecord = new PushRecord();
|
| | |
|
| | | // TODO 需要全推
|
| | | |
| | |
|
| | | addPushIOSQueue(info, id + "", PushController.ZNX);
|
| | | |
| | | /*List<String> deviceTokenList = getDeviceTokenList(1, 1000);
|
| | |
|
| | | ThreadUtil.run(new Runnable() {
|
| | | @Override
|
| | | public void run() {
|
| | | try {
|
| | | IOSPushUtil.allPushIOS(deviceTokenList, info, id + "", PushController.ZNX);
|
| | | } catch (Exception e) {
|
| | | PushLogHelper.iosError(e);
|
| | | }
|
| | |
|
| | | }
|
| | | });*/
|
| | | /*
|
| | | * List<String> deviceTokenList = getDeviceTokenList(1, 1000);
|
| | | * |
| | | * ThreadUtil.run(new Runnable() {
|
| | | * |
| | | * @Override public void run() { try {
|
| | | * IOSPushUtil.allPushIOS(deviceTokenList, info, id + "",
|
| | | * PushController.ZNX); } catch (Exception e) {
|
| | | * PushLogHelper.iosError(e); }
|
| | | * |
| | | * } });
|
| | | */
|
| | | } else if (msg != null) {
|
| | | // 插入推送记录
|
| | | PushRecord pushRecord = new PushRecord();
|
| | |
| | |
|
| | | @Transactional
|
| | | @Override
|
| | | public void addDeviceToken(Long uid,int version, String deviceToken, String device) {
|
| | | public void addDeviceToken(Long uid, int version, String deviceToken, String device) {
|
| | | // 如果device为空就返回
|
| | | if (StringUtil.isNullOrEmpty(device))
|
| | | return;
|
| | |
| | | return deviceTokenIOSMapper.selectByDevice(device);
|
| | | }
|
| | |
|
| | | |
| | | /**
|
| | | * 保存推送内容只队列中
|
| | | * |
| | | * @param json
|
| | | */
|
| | | @Transactional
|
| | | public void addPushIOSQueue(MessageInfo info, String url, int type) {
|
| | | |
| | |
|
| | | try {
|
| | | |
| | |
|
| | | JSONObject json = IOSPushUtil.getJSONObject(info, url, type);
|
| | |
|
| | | // 总条目
|
| | |
| | | pushQueueRecord.setCreatetime(new Date());
|
| | | // 每次推送数量
|
| | | pushQueueRecord.setPushNum(pushNum);
|
| | | // 推送端 IOS |
| | | // 推送端 IOS
|
| | | pushQueueRecord.setType(1);
|
| | |
|
| | | if (tokenCount - i < totalCount) {
|
| | |
| | | }
|
| | |
|
| | | }
|
| | | |
| | | |
| | |
|
| | | /**
|
| | | * 队列执行推送操作
|
| | | */
|
| | | @Override
|
| | | public void readyPushIOS(PushQueueRecord pushQueueRecord) throws Exception {
|
| | | |
| | |
|
| | | // 起始位置
|
| | | Long startCursor = pushQueueRecord.getStartCursor();
|
| | | // 结束位置
|
| | | Long endCursor = pushQueueRecord.getEndCursor();
|
| | | |
| | |
|
| | | if (startCursor == null && endCursor == null) {
|
| | | return;
|
| | | }
|
| | | |
| | |
|
| | | int total = (int) (endCursor - startCursor);
|
| | | |
| | |
|
| | | // 每次推送总条数
|
| | | int moveNum = pushQueueRecord.getPushNum();
|
| | | |
| | | int count = total/ moveNum;
|
| | | |
| | |
|
| | | int count = total / moveNum;
|
| | |
|
| | | if (total % moveNum > 0) {
|
| | | count +=1;
|
| | | count += 1;
|
| | | }
|
| | | |
| | |
|
| | | long recordCursor = startCursor;
|
| | | |
| | |
|
| | | for (int i = 0; i < count; i++) {
|
| | | |
| | |
|
| | | // 不足50个数据
|
| | | if (moveNum > total) {
|
| | | moveNum = (int) (endCursor- startCursor);
|
| | | moveNum = (int) (endCursor - startCursor);
|
| | | List<DeviceTokenIOS> list = deviceTokenIOSMapper.selectList(startCursor, moveNum);
|
| | | recordCursor = endCursor;
|
| | | |
| | |
|
| | | if (list != null) {
|
| | | executePushIOS(list, pushQueueRecord, recordCursor);
|
| | | PushLogHelper.iosInfo("推送游标:" + startCursor + "," + moveNum);
|
| | | }
|
| | | |
| | |
|
| | | } else {
|
| | | |
| | |
|
| | | if (recordCursor + moveNum > endCursor) {
|
| | | //System.out.println("recordCursorend:" +recordCursor);
|
| | | moveNum = (int) (endCursor- recordCursor);
|
| | | //System.out.println(moveNum);
|
| | | // System.out.println("recordCursorend:" +recordCursor);
|
| | | moveNum = (int) (endCursor - recordCursor);
|
| | | // System.out.println(moveNum);
|
| | | List<DeviceTokenIOS> list = deviceTokenIOSMapper.selectList(recordCursor, moveNum);
|
| | | if (list != null) {
|
| | | executePushIOS(list, pushQueueRecord, endCursor);
|
| | | PushLogHelper.iosInfo("推送游标:" + recordCursor + "," + moveNum);
|
| | | }
|
| | | recordCursor = endCursor;
|
| | | |
| | |
|
| | | } else {
|
| | | List<DeviceTokenIOS> list = deviceTokenIOSMapper.selectList(recordCursor, moveNum);
|
| | | recordCursor = recordCursor + 50;
|
| | | |
| | |
|
| | | if (list != null) {
|
| | | executePushIOS(list, pushQueueRecord, recordCursor-1);
|
| | | executePushIOS(list, pushQueueRecord, recordCursor - 1);
|
| | | PushLogHelper.iosInfo("推送游标:" + recordCursor + "," + moveNum);
|
| | | }
|
| | | }
|
| | | |
| | | //System.out.println("recordCursor:" +recordCursor);
|
| | |
|
| | | // System.out.println("recordCursor:" +recordCursor);
|
| | | }
|
| | | }
|
| | | |
| | |
|
| | | }
|
| | | |
| | | |
| | | public void executePushIOS(List<DeviceTokenIOS> list ,PushQueueRecord pushQueueRecord, long recordCursor) {
|
| | | |
| | |
|
| | | public void executePushIOS(List<DeviceTokenIOS> list, PushQueueRecord pushQueueRecord, long recordCursor) {
|
| | |
|
| | | String jsonContent = pushQueueRecord.getJsonContent();
|
| | | JSONObject json = JSONObject.fromObject(jsonContent);
|
| | | |
| | |
|
| | | List<String> tokenList = new ArrayList<>();
|
| | | for (DeviceTokenIOS ios : list){
|
| | | if (!StringUtil.isNullOrEmpty(ios.getDeviceToken())){
|
| | | for (DeviceTokenIOS ios : list) {
|
| | | if (!StringUtil.isNullOrEmpty(ios.getDeviceToken())) {
|
| | | tokenList.add(ios.getDeviceToken());
|
| | | //System.out.println(ios.getDeviceToken());
|
| | | // System.out.println(ios.getDeviceToken());
|
| | | }
|
| | | }
|
| | | |
| | |
|
| | | if (tokenList.size() > 0) {
|
| | | //System.out.println(tokenList.size());
|
| | | // System.out.println(tokenList.size());
|
| | | // 执行推送
|
| | | try {
|
| | | IOSPushUtil.executePushIOS(tokenList,json);
|
| | | IOSPushUtil.executePushIOS(tokenList, json);
|
| | | } catch (Exception e) {
|
| | | // TODO Auto-generated catch block
|
| | | e.printStackTrace();
|
| | |
| | | pushQueueRecord.setState(1);
|
| | | pushQueueRecord.setEndtime(new Date());
|
| | | pushQueueRecord.setRecordCursor(recordCursor);
|
| | | |
| | | //TODO 更新数据库
|
| | |
|
| | | // TODO 更新数据库
|
| | | pushQueueRecordMapper.updateByPrimaryKeySelective(pushQueueRecord);
|
| | | }
|
| | |
|
| | | |
| | | }
|