admin
2025-02-20 f537abe9f3646c739beaf15076246a2f71a347e9
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
package com.yeshi.buwan.job;
 
import java.util.ArrayList;
import java.util.List;
 
import javax.annotation.Resource;
 
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
 
import com.yeshi.buwan.domain.user.LoginUser;
import com.yeshi.buwan.domain.push.VideoPushHistory;
import com.yeshi.buwan.service.imp.AttentionService;
import com.yeshi.buwan.service.imp.SystemService;
import com.yeshi.buwan.service.imp.push.PushService;
import com.yeshi.buwan.util.Constant;
import com.yeshi.buwan.util.XingePushUtil;
 
@Component
public class PushJob {
    @Resource
    PushService pushService;
    @Resource
    AttentionService attentionService;
    @Resource
    SystemService systemService;
 
    // 视频推送任务
    @Scheduled(cron = "0 2/5 * * * ? ")
    public void doJob() {
        if (!Constant.JobTasker)
            return;
        System.out.println("PushJob-doJob");
        List<VideoPushHistory> list = pushService.getUnPushVideoPushHistory();// 获取任务列表
        for (VideoPushHistory vp : list) {
            List<LoginUser> userList = attentionService.getUserListByAttentionVideo(vp.getVideoInfo().getId());
            List<String> androidUserList = new ArrayList<>();
            List<String> iosUserList = new ArrayList<>();
            for (LoginUser lu : userList) {
                // if
                // (systemService.getDetailSystemById(lu.getDetailsystem()).getPlatform()
                // == 1)// Android
                // {
                androidUserList.add(lu.getId());
                // } else// IOS
                // {
                iosUserList.add(lu.getId());
                // }
            }
 
            int maxCount = 1000;
 
            int p = iosUserList.size() % maxCount == 0 ? iosUserList.size() / maxCount
                    : (iosUserList.size() / maxCount + 1);
 
            for (int i = 0; i < p; i++) {
                List<String> subUserList = iosUserList.subList(i * maxCount,
                        iosUserList.size() > i * maxCount + maxCount ? maxCount : iosUserList.size());
                boolean isS = XingePushUtil.pushVideoUpdateByAccount(vp.getResourceId(), vp.getDetailId(),
                        vp.getVideoInfo(), subUserList, null);
            }
 
            p = androidUserList.size() % maxCount == 0 ? androidUserList.size() / maxCount
                    : (androidUserList.size() / maxCount + 1);
 
            for (int i = 0; i < p; i++) {
                List<String> subUserList = androidUserList.subList(i * maxCount,
                        androidUserList.size() > i * maxCount + maxCount ? maxCount : androidUserList.size());
                boolean isS = XingePushUtil.pushVideoUpdateByAccount(vp.getResourceId(), vp.getDetailId(),
                        vp.getVideoInfo(), null, subUserList);
            }
 
            vp.setPushtime(System.currentTimeMillis() + "");
            pushService.updateVideoPushHistory(vp);
        }
 
    }
 
}