package com.newvideo.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.newvideo.domain.LoginUser;
|
import com.newvideo.domain.push.VideoPushHistory;
|
import com.newvideo.service.imp.AttentionService;
|
import com.newvideo.service.imp.SystemService;
|
import com.newvideo.service.imp.push.PushService;
|
import com.newvideo.util.Constant;
|
import com.newvideo.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<String>();
|
List<String> iosUserList = new ArrayList<String>();
|
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);
|
}
|
|
}
|
|
}
|