SystemNoticeThread.java
3.99 KB
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
/**
* @Title: SystemNoticeThread.java
* @Package com.bjivt.web.thread
* @Description: TODO(用一句话描述该文件做什么)
* @author Yh.T
* @date 2016年9月27日 下午3:41:35
* @version
*/
package com.bjivt.web.thread;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.codehaus.jackson.map.ObjectMapper;
import com.alibaba.fastjson.JSONObject;
import com.bjivt.entity.showtime.SystemNotice;
import com.bjivt.service.showtime.SystemNoticeService;
import com.bjivt.service.showtime.UserService;
import com.bjivt.util.JPushUtil;
import com.bjivt.util.Pager;
import com.bjivt.util.PropertiesUtil;
import cn.jpush.api.push.PushResult;
/**
* 项目名称:admin
*
* 类描述: 类名称:com.bjivt.web.thread.SystemNoticeThread Yh.T 创建时间:2016年9月27日
* 下午3:41:35 修改备注:
*
* @version
*/
public class SystemNoticeThread extends Thread {
private boolean isRun = true;
private String appkey = PropertiesUtil.config.get("jpush.appkey");
private String jpushSecret = PropertiesUtil.config.get("jpush.masterSecret");
private JPushUtil client = null;
protected UserService userService;
private int type;
private SystemNotice notice;
public SystemNoticeThread() {
client = new JPushUtil(appkey, jpushSecret, true);
}
@Override
public void run() {
sendMsg();
}
public void sendMsg() {
Map<String, String> extras = new HashMap<String, String>();
ObjectMapper mapper = new ObjectMapper();
try {
List<String> idList = null;
Pager page = new Pager();
page.setSize(500);
Map<String, Object> content = new HashMap<String, Object>();
content.put("content", notice.getContent());
content.put("title", notice.getTitle());
String strCont = mapper.writeValueAsString(content);
if (type == 1) {
page.setCount(userService.loadAnchorUserCount());
page.setPages((int) Math.ceil((float) page.getCount() / page.getSize()));
idList = userService.loadAnchorUserList(page);
for (int i = 1; i <= page.getPages(); i++) {
// PushResult info =
// client.sendToAliasAndroidAndiOS(notice.getTitle(),
// strCont, extras, idList.toArray(new
// String[idList.size()]));
client.sendMsgToAliasAndroidAndiOS(notice.getTitle(), strCont,
idList.toArray(new String[idList.size()]));
page.setPage(i + 1);
page.setFrom((page.getPage() - 1) * page.getSize());
idList = userService.loadAnchorUserList(page);
}
} else if (type == 2) {
page.setCount(userService.loadAllUserCount());
page.setPages((int) Math.ceil((float) page.getCount() / page.getSize()));
idList = userService.loadAllUserList(page);
for (int i = 1; i <= page.getPages(); i++) {
client.sendMsgToAliasAndroidAndiOS(notice.getTitle(), strCont,
idList.toArray(new String[idList.size()]));
// System.out.println(strCont+"============");
// PushResult info = client.sendMsgToAll(strCont);
page.setPage(i + 1);
page.setFrom((page.getPage() - 1) * page.getSize());
idList = userService.loadAllUserList(page);
}
} else if (type == 3) {
page.setCount(userService.loadCommonUserCount());
idList = userService.loadCommonUserList(page);
for (int i = 1; i <= page.getPages(); i++) {
client.sendMsgToAliasAndroidAndiOS(notice.getTitle(), strCont,
idList.toArray(new String[idList.size()]));
page.setPage(i + 1);
page.setFrom((page.getPage() - 1) * page.getSize());
idList = userService.loadCommonUserList(page);
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
public boolean isRun() {
return isRun;
}
public void setRun(boolean isRun) {
this.isRun = isRun;
}
public UserService getUserService() {
return userService;
}
public void setUserService(UserService userService) {
this.userService = userService;
}
public SystemNotice getNotice() {
return notice;
}
public void setNotice(SystemNotice notice) {
this.notice = notice;
}
public int getType() {
return type;
}
public void setType(int type) {
this.type = type;
}
}