yujian
2020-04-02 0ec22dcf4fd9c4496e6f681e7fab89f56c6e4e8a
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
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.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.push.PushException;
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.push.IOSPushUtil;
 
import net.sf.json.JSONObject;
 
@Service
public class IOSPushServiceImpl implements IOSPushService {
 
    @Resource
    private DeviceTokenIOSMapper deviceTokenIOSMapper;
 
    @Resource
    private PushQueueRecordMapper pushQueueRecordMapper;
 
    @Resource
    private UserCustomSettingsService userCustomSettingsService;
 
    @Async("pushExecutor")
    @Override
    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();
        json.put("id", auctionId);
        json.put("type", "goodsdetail");
        json.put("miPushUrl", String.format("%s.ui.recommend.GoodsBrowserActivity",
                Constant.systemCommonConfig.getAndroidBaseactivityName()));
 
        MessageInfo info = new MessageInfo();
        info.setTitle(title);
        info.setContent(content);
        info.setDescription(content);
        info.setPackageName(Constant.systemCommonConfig.getAndroidPackageName());
        info.setActivty(String.format("%s.ui.recommend.GoodsBrowserActivity",
                Constant.systemCommonConfig.getAndroidBaseactivityName()));
 
        PushRecord pushRecord = new PushRecord();
        pushRecord.setState(1);
        pushRecord.setType(PushTypeEnum.goodsdetail.getCode()); // 都成功
        pushRecord.setUrl(url);
        pushRecord.setTitle(title);
        pushRecord.setAppName(Constant.systemCommonConfig.getProjectChineseName());
 
        if (uid == null || uid == 0) {
 
            addPushIOSQueue(info, url, PushTypeEnum.goodsdetail.getCode(), versionCodes);
 
            /*
             * // 查询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 {
            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) {
                    deviceTokenList.add(ios.getDeviceToken());
                }
 
            try {
                IOSPushUtil.allPushIOS(deviceTokenList, info, url, PushTypeEnum.goodsdetail.getCode());
            } catch (Exception e) {
                PushLogHelper.iosError(e);
            }
 
        }
    }
 
    @Async("pushExecutor")
    @Override
    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");
        json.put("webUrl", url);
        json.put("miPushUrl",
                String.format("%s.ui.BrowserActivity", Constant.systemCommonConfig.getAndroidBaseactivityName()));
 
        MessageInfo info = new MessageInfo();
        info.setTitle(title);
        info.setContent(content);
        info.setDescription(content);
        // 小米推送网页
        info.setPackageName(Constant.systemCommonConfig.getAndroidPackageName());
        info.setActivty(
                String.format("%s.ui.BrowserActivity", Constant.systemCommonConfig.getAndroidBaseactivityName()));
 
        PushRecord pushRecord = new PushRecord();
        // IOS 全推
        if (uid == null || uid == 0) {
            // TODO 需要全推
 
            addPushIOSQueue(info, url, PushTypeEnum.url.getCode(), versionCodes);
 
            /*
             * 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 {
            if (!validateNotDisturbSingle(uid)) {
                return; // 通知免打扰(20:00-24:00 / 00:00 -08:00)
            }
 
            List<DeviceTokenIOS> deviceTokenIosList = getDeviceTokenListByUid(uid, versionCodes);
            List<String> deviceTokenList = new ArrayList<>();
            if (deviceTokenIosList != null)
                for (DeviceTokenIOS ios : deviceTokenIosList) {
                    deviceTokenList.add(ios.getDeviceToken());
                }
            try {
                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 {
        MessageInfo info = new MessageInfo();
        info.setPackageName(Constant.systemCommonConfig.getAndroidPackageName());
 
        JSONObject contentJson = new JSONObject();
        contentJson.put("isOpen", 0);
        contentJson.put("createTime", java.lang.System.currentTimeMillis());
 
        /* 无uid , 广播 数据插入系统表 */
        if (systemZNX != null) {
            info.setTitle(systemZNX.getTitle());
            info.setContent(systemZNX.getContent());
            contentJson.put("title", systemZNX.getTitle());
            contentJson.put("content", systemZNX.getContent());
            info.setDescription(systemZNX.getContent());
 
            // 小米开始全推
            long id = systemZNX.getId();
            contentJson.put("id", id);
 
            JSONObject json = new JSONObject();
            json.put("type", "ZNX");
            json.put("content", contentJson);
            json.put("miPushUrl", String.format("%s.ui.mine.AppMailDetailActivity",
                    Constant.systemCommonConfig.getAndroidBaseactivityName()));
 
            PushRecord pushRecord = new PushRecord();
 
            // TODO 需要全推
 
            addPushIOSQueue(info, id + "", PushTypeEnum.ZNX.getCode(), versionCodes);
 
            /*
             * 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) {
 
            if (uId != null) {
                if (!validateNotDisturbSingle(uId)) {
                    return; // 通知免打扰(20:00-24:00 / 00:00 -08:00)
                }
            }
 
            // 插入推送记录
            PushRecord pushRecord = new PushRecord();
            info.setTitle(msg.getTitle());
            info.setContent(msg.getContent());
            contentJson.put("title", msg.getTitle());
            contentJson.put("content", msg.getContent());
            info.setDescription(msg.getContent());
 
            info.setAlias(uId + "");
            info.setPackageName(Constant.systemCommonConfig.getAndroidPackageName());
            info.setActivty(
                    String.format("%s.ui.BrowserActivity", Constant.systemCommonConfig.getAndroidBaseactivityName()));
 
            contentJson.put("id", msg.getId() + "");
 
            JSONObject json = new JSONObject();
            json.put("type", "ZNX");
            json.put("content", contentJson);
            json.put("miPushUrl", String.format("%s.ui.mine.AppMailDetailActivity",
                    Constant.systemCommonConfig.getAndroidBaseactivityName()));
 
            List<DeviceTokenIOS> deviceTokenIosList = getDeviceTokenListByUid(msg.getUserInfo().getId(), versionCodes);
            List<String> deviceTokenList = new ArrayList<>();
            if (deviceTokenIosList != null)
                for (DeviceTokenIOS ios : deviceTokenIosList) {
                    deviceTokenList.add(ios.getDeviceToken());
                }
 
            // IOS 单推
            try {
                IOSPushUtil.allPushIOS(deviceTokenList, info, "0", PushTypeEnum.ZNX.getCode());
            } catch (Exception e) {
                PushLogHelper.iosError(e);
            }
        }
    }
 
    @Transactional
    @Override
    public void addDeviceToken(Long uid, int version, String deviceToken, String device) {
        // 如果device为空就返回
        if (StringUtil.isNullOrEmpty(device) || StringUtil.isNullOrEmpty(deviceToken))
            return;
 
        // 判断device是否存在
        DeviceTokenIOS deviceTokenIos = deviceTokenIOSMapper.selectByDeviceForUpdate(device);
        if (deviceTokenIos == null) {
            deviceTokenIos = new DeviceTokenIOS();
            deviceTokenIos.setCreateTime(new Date());
            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 List<DeviceTokenIOS> getDeviceTokenListByUid(Long uid, String versionCodes) throws PushException {
        return deviceTokenIOSMapper.selectByUid(uid, convertVersionType(versionCodes));
    }
 
    @Override
    public List<String> getDeviceTokenList(int page, int size) {
        List<DeviceTokenIOS> list = deviceTokenIOSMapper.selectList((long) ((page - 1) * size), size, null);
        List<String> tokenList = new ArrayList<>();
        for (DeviceTokenIOS ios : list)
            if (!StringUtil.isNullOrEmpty(ios.getDeviceToken()))
                tokenList.add(ios.getDeviceToken());
        return tokenList;
    }
 
    @Override
    public long getDeviceTokenCount() {
        return deviceTokenIOSMapper.selectCount();
    }
 
    @Override
    public void updateDeviceToken(DeviceTokenIOS deviceTokenIos) {
        if (deviceTokenIos != null) {
            deviceTokenIos.setUpdateTime(new Date());
            deviceTokenIOSMapper.updateByPrimaryKey(deviceTokenIos);
        }
    }
 
    @Override
    public DeviceTokenIOS getDeviceTokenByDeviceToken(String deviceToken) {
        return deviceTokenIOSMapper.selectByDeviceToken(deviceToken);
    }
 
    /**
     * 保存推送内容只队列中
     * 
     * @param json
     */
    @Transactional(rollbackFor=Exception.class)
    public void addPushIOSQueue(MessageInfo info, String url, int type, String versionCodes) throws PushException {
 
        if (Constant.IS_TEST)
            return;
 
        try {
 
            JSONObject json = IOSPushUtil.getJSONObject(info, url, type);
 
            // 总条目
            long tokenCount = getDeviceTokenCount();
 
            // 一个队列 1000 条
            long totalCount = 1000;
 
            // 每次执行条目
            int pushNum = 50;
 
            for (long i = 0; i < tokenCount + totalCount;) {
 
                PushQueueRecord pushQueueRecord = new PushQueueRecord();
                // 初始状态
                pushQueueRecord.setState(0);
                // 发送内容
                pushQueueRecord.setJsonContent(json.toString());
                // 创建时间
                pushQueueRecord.setCreatetime(new Date());
                // 每次推送数量
                pushQueueRecord.setPushNum(pushNum);
                // 推送端 IOS
                pushQueueRecord.setType(1);
                // 版本号
                pushQueueRecord.setVersions(versionCodes);
 
                if (tokenCount - i < totalCount) {
                    // 起始游标
                    pushQueueRecord.setStartCursor(i);
                    // 结束游标
                    pushQueueRecord.setEndCursor(tokenCount);
 
                    // 存入数据库
                    pushQueueRecordMapper.insert(pushQueueRecord);
 
                    // 加入队列
                    CMQManager.getInstance().addIOSPushMsg(pushQueueRecord);
 
                    break;
 
                } else {
 
                    // 起始游标
                    pushQueueRecord.setStartCursor(i);
 
                    long endCursor = (i + totalCount) - 1;
 
                    // 结束游标
                    pushQueueRecord.setEndCursor(endCursor);
 
                    // 存入数据库
                    pushQueueRecordMapper.insert(pushQueueRecord);
                    // 加入队列
                    CMQManager.getInstance().addIOSPushMsg(pushQueueRecord);
                }
 
                i += totalCount;
            }
 
        } catch (Exception e) {
            e.printStackTrace();
        }
 
    }
 
    /**
     * 队列执行推送操作
     */
    @Override
    public void readyPushIOS(PushQueueRecord pushQueueRecord) throws Exception {
 
        // 起始位置
        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);
 
        // 每次推送总条数
        int moveNum = pushQueueRecord.getPushNum();
 
        int count = total / moveNum;
 
        if (total % moveNum > 0) {
            count += 1;
        }
 
        long recordCursor = startCursor;
 
        for (int i = 0; i < count; i++) {
 
            // 不足50个数据
            if (moveNum > total) {
                moveNum = (int) (endCursor - startCursor);
                List<DeviceTokenIOS> list = deviceTokenIOSMapper.selectList(startCursor, moveNum, listCode);
                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);
                    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, listCode);
                    recordCursor = recordCursor + 50;
 
                    if (list != null) {
                        executePushIOS(list, pushQueueRecord, recordCursor - 1);
                        PushLogHelper.iosInfo("推送游标:" + recordCursor + "," + moveNum);
                    }
                }
            }
        }
    }
 
    public void executePushIOS(List<DeviceTokenIOS> list, PushQueueRecord pushQueueRecord, long recordCursor) {
 
        String jsonContent = pushQueueRecord.getJsonContent();
        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();
//        }
        
        ispush=true;//TODO 处理消息免打扰
 
        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());
            }
        }
 
        if (tokenList.size() > 0) {
            // 执行推送
            try {
                IOSPushUtil.executePushIOS(tokenList, json);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        pushQueueRecord.setState(1);
        pushQueueRecord.setEndtime(new Date());
        pushQueueRecord.setRecordCursor(recordCursor);
 
        // 更新数据库
        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);
        }
    }
 
    @Async("pushExecutor")
    @Override
    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, PushTypeEnum.weex.getCode(), versionCodes);
        } else {
            List<DeviceTokenIOS> deviceTokenIosList = getDeviceTokenListByUid(uid, versionCodes);
            List<String> deviceTokenList = new ArrayList<>();
            if (deviceTokenIosList != null)
                for (DeviceTokenIOS ios : deviceTokenIosList) {
                    deviceTokenList.add(ios.getDeviceToken());
                }
            try {
                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 {
        MessageInfo info = new MessageInfo();
        info.setTitle(title);
        info.setContent(content);
        info.setDescription(content);
        // IOS 全推
        if (uid == null || uid == 0) {
            addPushIOSQueue(info, url, PushTypeEnum.baichuan.getCode(), versionCodes);
        } else {
            List<DeviceTokenIOS> deviceTokenIosList = getDeviceTokenListByUid(uid, versionCodes);
            List<String> deviceTokenList = new ArrayList<>();
            if (deviceTokenIosList != null)
                for (DeviceTokenIOS ios : deviceTokenIosList) {
                    deviceTokenList.add(ios.getDeviceToken());
                }
            try {
                IOSPushUtil.allPushIOS(deviceTokenList, info, url, PushTypeEnum.baichuan.getCode());
            } 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;
    }
 
    @Async("pushExecutor")
    @Override
    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, "", PushTypeEnum.welfare.getCode(), versionCodes);
        } else {
            if (!validateNotDisturbSingle(uid)) {
                return;
            }
            List<DeviceTokenIOS> deviceTokenIosList = getDeviceTokenListByUid(uid, versionCodes);
            List<String> deviceTokenList = new ArrayList<>();
            if (deviceTokenIosList != null)
                for (DeviceTokenIOS ios : deviceTokenIosList) {
                    deviceTokenList.add(ios.getDeviceToken());
                }
            try {
                IOSPushUtil.allPushIOS(deviceTokenList, info, "", PushTypeEnum.welfare.getCode());
            } catch (Exception e) {
                PushLogHelper.iosError(e);
            }
        }
    }
 
    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;
    }
 
    @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);
            }
        }
    }
 
}