ef5e314214ef4da8d8231f0a6f31c25c98afbd2f.svn-base
5.65 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
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
package com.bjivt.showtime.api.service.impl;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.TimeZone;
import org.apache.commons.beanutils.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.bjivt.showtime.api.dao.LiveDao;
import com.bjivt.showtime.api.entity.ChatRoom;
import com.bjivt.showtime.api.entity.Live;
import com.bjivt.showtime.api.entity.ParticipantEntity;
import com.bjivt.showtime.api.entity.User;
import com.bjivt.showtime.api.service.LiveService;
import com.bjivt.showtime.api.utils.Pager;
import com.bjivt.showtime.api.utils.PropertiesUtil;
import com.bjivt.showtime.api.utils.RestUtil;
import com.bjivt.showtime.api.utils.RestUtil.Method;
import com.thoughtworks.xstream.XStream;
import com.thoughtworks.xstream.converters.basic.DateConverter;
import com.thoughtworks.xstream.io.xml.DomDriver;
@Service
public class LiveServiceImpl extends BaseServiceImpl<Live, Integer> implements LiveService {
@Autowired
private LiveDao _livedao;
@Autowired
public void setBaseDao(LiveDao _livedao) {
super.setBaseDao(_livedao);
}
public Map<String, Object> getLiveRoomInfoById(Integer id,Integer type) {
return _livedao.getLiveRoomInfoById( id, type);
}
@Override
public void startLive() {
}
public Live getLiveByUserId(Integer userId, Integer type) {
return _livedao.getLiveByUserId(userId, type);
}
public List<Map<String, Object>> getFollowerLiveList(Integer userId, Pager page) {
return _livedao.getFollowerLiveList(userId, page);
}
public List<Map<String, Object>> getHotLiveList(Pager page) {
return _livedao.getHotLiveList(page);
}
public List<Map<String, Object>> getUserLiveList(Integer userId,Pager page) {
return _livedao.getUserLiveList(userId, page);
}
public List<Map<String, Object>> requestFollowerVideoLiveList(Integer userId,Pager page) {
return _livedao.requestFollowerVideoLiveList(userId, page);
}
public List<Map<String, Object>> getUserGiftList(Integer userId, Pager page) {
return _livedao.getUserGiftList(userId,page);
}
public List<Map<String, Object>> getLiveGiftList(Integer liveId, Pager page) {
return _livedao.getLiveGiftList(liveId,page);
}
public List<Map<String, Object>> requestNewLiveList(Pager page) {
return _livedao.requestNewLiveList(page);
}
public List<Map<String, Object>> getStarLiveList(Pager page) {
return _livedao.getStarLiveList(page);
}
public void getLiveRoom() {
List<Map<String,Object>> list = _livedao.getLiveRoom();
for (Map<String, Object> map : list) {
Live live = new Live();
try {
BeanUtils.populate(live, map);
if(live != null && live.getHeartbeat() != null && (System.currentTimeMillis()/1000 - live.getHeartbeat()) > 90){
live.setType(2);
_livedao.update(live);
//System.out.println("------关闭非正常直播------");
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
public List<Map<String, Object>> getHotLiveList() {
return _livedao.getHotLiveList();
}
public List<Map<String, Object>> getRecordListByUserId(Integer userId) {
return _livedao.getRecordListByUserId(userId);
}
public List<Map<String, Object>> getLocationLLiveList(Float maxlongitude,Float maxlatitude, Float minlongitude, Float minlatitude, Pager page) {
return _livedao.getLocationLLiveList(maxlongitude, maxlatitude, minlongitude, minlatitude, page);
}
@Override
public List<Map<String, Object>> getUserGiftToOtherList(Integer userId, Pager page) {
return _livedao.getUserGiftToOtherList(userId, page);
}
@Override
public List<Map<String, Object>> getRecordListByUserId(Integer userId, Pager pager) {
// TODO Auto-generated method stub
return _livedao.getRecordListByUserId(userId, pager);
}
/**
* @see 查询某个房间的所有观看用户信息
*/
@Override
public List<Map<String, Object>> getLiveUserList(Integer liveId, Pager page) {
return _livedao.getLiveUserList(liveId,page);
}
@Override
public ChatRoom getChatRoomInfo(String roomName) {
if (roomName.contains("@")) {
roomName = roomName.substring(0, roomName.indexOf("@"));
}
try {
// 调用Openfire接口
Map<String, String> headers = new HashMap<String, String>();
headers.put("Authorization", PropertiesUtil.config.get("openfire.restapi.secret"));
RestUtil rest = new RestUtil(headers);
String result = rest.load(
String.format("%s/plugins/restapi/v1/chatrooms/%s",
PropertiesUtil.config.get("openfire.restapi.url"),roomName),
Method.GET, null);
if (result != null) {
XStream xstream = new XStream(new DomDriver());
xstream .autodetectAnnotations(true);
xstream.registerConverter(new DateConverter("yyyy-MM-dd'T'HH:mm:ss", null, TimeZone.getTimeZone("GMT+8")));
xstream.alias("chatRoom", ChatRoom.class);
xstream.alias("currUsers", Integer.class);
xstream.alias("broadcastPresenceRole", String.class);
xstream.alias("owner", String.class);
xstream.alias("ownerGroup", String.class);
xstream.alias("admin", String.class);
xstream.alias("adminGroup", String.class);
xstream.alias("member", String.class);
xstream.alias("memberGroup", String.class);
xstream.alias("outcast", String.class);
xstream.alias("outcastGroup", String.class);
xstream.alias("participants", ParticipantEntity.class);
ChatRoom room = (ChatRoom) xstream.fromXML(result);
return room;
}
} catch (Exception ex) {
ex.printStackTrace();
}
return null;
}
@Override
public int getUserLiveCount(int userId, Pager pager) {
return _livedao.getUserLiveCount(userId, pager);
}
@Override
public User getUserByLiveId(Integer liveId) {
return _livedao.getUserByLiveId(liveId);
}
}