GetPolyvAnalysisBigData.java 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308
  1. package com.cnd3b.service;
  2. import com.alibaba.fastjson.JSONArray;
  3. import com.alibaba.fastjson.JSONObject;
  4. import com.cnd3b.common.BaseClass;
  5. import com.cnd3b.common.data.Rows;
  6. import com.cnd3b.common.data.SQLFactory;
  7. import com.cnd3b.common.data.db.DBConnect;
  8. import com.cnd3b.common.data.db.SQLiteJDBC;
  9. import com.cnd3b.utility.polyv.Polyv;
  10. import java.util.ArrayList;
  11. import java.util.Calendar;
  12. import java.util.HashMap;
  13. /**
  14. * 保利威统计数据查询,频率5分钟一次
  15. */
  16. public class GetPolyvAnalysisBigData extends BaseClass implements Runnable {
  17. @Override
  18. public void run() {
  19. try {
  20. if (new SQLiteJDBC().checkServicesUsed("GetPolyvAnalysisBigData", false)) {
  21. getLiveData();
  22. getLiveviewLog();
  23. getLiveMessageList();
  24. getSessionStats();
  25. }
  26. } catch (Exception e) {
  27. e.printStackTrace();
  28. }
  29. }
  30. /**
  31. * 获取频道直播概览统计数据表
  32. */
  33. public void getLiveData() {
  34. System.err.println("getLiveData");
  35. DBConnect dbConnect = new DBConnect();
  36. String[] channelids = dbConnect.runSqlQuery("select channelid from tlive where livestatus in('live','waiting') and convert(varchar(10),lastlivedate,120)=convert(varchar(10),getDate(),120) ").toArray("channelid");
  37. Polyv polyv = new Polyv();
  38. ArrayList<String> sqllist = new ArrayList<>();
  39. JSONArray dataArray = polyv.getChannelSummary(channelids, getDate_Str());
  40. System.err.println(dataArray);
  41. if (dataArray == null) {
  42. return;
  43. }
  44. for (Object o : dataArray) {
  45. JSONObject contentsObject = (JSONObject) o;
  46. String userId = contentsObject.getString("userId");
  47. String channelId = contentsObject.getString("channelId");
  48. String name = contentsObject.getString("name");
  49. int pcPlayDuration = contentsObject.getInteger("pcPlayDuration");
  50. long pcFlowSize = contentsObject.getLong("pcFlowSize");
  51. int pcVideoView = contentsObject.getInteger("pcVideoView");
  52. int pcUniqueViewer = contentsObject.getInteger("pcUniqueViewer");
  53. int mobilePlayDuration = contentsObject.getInteger("mobilePlayDuration");
  54. long mobileFlowSize = contentsObject.getLong("mobileFlowSize");
  55. int mobileVideoView = contentsObject.getInteger("mobileVideoView");
  56. int mobileUniqueViewer = contentsObject.getInteger("mobileUniqueViewer");
  57. int livePcPlayDuration = contentsObject.getInteger("livePcPlayDuration");
  58. int playbackPcPlayDuration = contentsObject.getInteger("playbackPcPlayDuration");
  59. int liveMobilePlayDuration = contentsObject.getInteger("liveMobilePlayDuration");
  60. int playbackMobilePlayDuration = contentsObject.getInteger("playbackMobilePlayDuration");
  61. int unknownPcPlayDuration = contentsObject.getInteger("unknownPcPlayDuration");
  62. int unknownMobilePlayDuration = contentsObject.getInteger("unknownMobilePlayDuration");
  63. String creatorName = contentsObject.getString("creatorName");//
  64. SQLFactory sqlFactory = new SQLFactory(this, "频道直播概览统计数据插入");
  65. sqlFactory.addParameter("date", getDate_Str());
  66. sqlFactory.addParameter("userid", userId);
  67. sqlFactory.addParameter("channelid", channelId);
  68. sqlFactory.addParameter("name", name);
  69. sqlFactory.addParameter("pcplayduration", pcPlayDuration);
  70. sqlFactory.addParameter("pcflowsize", pcFlowSize);
  71. sqlFactory.addParameter("pcvideoview", pcVideoView);
  72. sqlFactory.addParameter("pcuniqueviewer", pcUniqueViewer);
  73. sqlFactory.addParameter("mobileplayduration", mobilePlayDuration);
  74. sqlFactory.addParameter("mobileflowsize", mobileFlowSize);
  75. sqlFactory.addParameter("mobilevideoview", mobileVideoView);
  76. sqlFactory.addParameter("mobileuniqueviewer", mobileUniqueViewer);
  77. sqlFactory.addParameter("livepcplayduration", livePcPlayDuration);
  78. sqlFactory.addParameter("playbackpcplayduration", playbackPcPlayDuration);
  79. sqlFactory.addParameter("livemobileplayduration", liveMobilePlayDuration);
  80. sqlFactory.addParameter("playbackmobileplayduratio", playbackMobilePlayDuration);
  81. sqlFactory.addParameter("unknownpcplayduration", unknownPcPlayDuration);
  82. sqlFactory.addParameter("unknownmobileplayduration", unknownMobilePlayDuration);
  83. sqlFactory.addParameter("creatorname", creatorName);
  84. sqllist.add(sqlFactory.getSQL());
  85. }
  86. dbConnect.runSqlUpdate(sqllist);
  87. }
  88. /**
  89. * 查询频道多场次概览统计数据
  90. */
  91. public void getSessionStats() {
  92. System.err.println("getSessionStats");
  93. DBConnect dbConnect = new DBConnect();
  94. String[] channelids = dbConnect.runSqlQuery("select channelid from tlive where livestatus in('live','waiting') and convert(varchar(10),lastlivedate,120)=convert(varchar(10),getDate(),120) ").toArray("channelid");
  95. for (String channelid : channelids) {
  96. Polyv polyv = new Polyv();
  97. ArrayList<String> sqllist = new ArrayList<>();
  98. JSONArray dataArray = polyv.getSessionStats(channelid);
  99. System.err.println(dataArray);
  100. if (dataArray == null) {
  101. return;
  102. }
  103. for (Object o : dataArray) {
  104. JSONObject contentsObject = (JSONObject) o;
  105. String channelId = contentsObject.getString("channelId");
  106. String sessionId = contentsObject.getString("sessionId");
  107. String name = contentsObject.getString("name");
  108. String startTime = contentsObject.getString("startTime");
  109. long duration = contentsObject.getLong("duration");
  110. long liveUV = contentsObject.getLong("liveUV");
  111. long livePV = contentsObject.getLong("livePV");
  112. long playbackPV = contentsObject.getLong("playbackPV");
  113. long playbackUV = contentsObject.getLong("playbackUV");
  114. SQLFactory sqlFactory = new SQLFactory(this, "场次直播概览统计数据插入");
  115. sqlFactory.addParameter("channelid", channelId);
  116. sqlFactory.addParameter("sessionid", sessionId);
  117. sqlFactory.addParameter("name", name);
  118. sqlFactory.addParameter("starttime", startTime);
  119. sqlFactory.addParameter("duration", duration);
  120. sqlFactory.addParameter("liveuv", liveUV);
  121. sqlFactory.addParameter("livepv", livePV);
  122. sqlFactory.addParameter("playbackpv", playbackPV);
  123. sqlFactory.addParameter("playbackuv", playbackUV);
  124. sqllist.add(sqlFactory.getSQL());
  125. }
  126. dbConnect.runSqlUpdate(sqllist);
  127. }
  128. }
  129. /**
  130. * 获取频道直播观看详情数据
  131. */
  132. public void getLiveviewLog() {
  133. System.err.println("getLiveviewLog");
  134. DBConnect dbConnect = new DBConnect();
  135. String[] channelids = dbConnect.runSqlQuery("select channelid from tlive where livestatus in('live','waiting') and convert(varchar(10),lastlivedate,120)=convert(varchar(10),getDate(),120) ").toArray("channelid");
  136. Polyv polyv = new Polyv();
  137. out:
  138. for (String channelid : channelids) {
  139. ArrayList<String> sqllist = new ArrayList<>();
  140. boolean islastpage;
  141. int pageNumber = 1;
  142. do {
  143. JSONObject object = polyv.getPageViewlog(channelid, getDate_Str(), "200", String.valueOf(pageNumber++));
  144. System.err.println(object);
  145. if (object == null) {
  146. continue out;
  147. }
  148. islastpage = object.getBoolean("lastPage");
  149. JSONArray contentsarray = object.getJSONArray("contents");
  150. for (Object o : contentsarray) {
  151. JSONObject contentsObject = (JSONObject) o;
  152. String playId = contentsObject.getString("playId");
  153. String userId = contentsObject.getString("userId");
  154. String channelId = contentsObject.getString("channelId");
  155. int playDuration = contentsObject.getInteger("playDuration");
  156. int stayDuration = contentsObject.getInteger("stayDuration");
  157. long flowSize = contentsObject.getLong("flowSize");
  158. String sessionId = contentsObject.getString("sessionId");
  159. String param1 = contentsObject.getString("param1");
  160. String param2 = contentsObject.getString("param2");
  161. String param3 = contentsObject.getString("param3");
  162. String param4 = contentsObject.getString("param4");
  163. String param5 = contentsObject.getString("param5");
  164. String ipAddress = contentsObject.getString("ipAddress");
  165. String country = contentsObject.getString("country");
  166. String province = contentsObject.getString("province");
  167. String city = contentsObject.getString("city");
  168. String isp = contentsObject.getString("isp");
  169. String referer = contentsObject.getString("referer");
  170. String userAgent = contentsObject.getString("userAgent");
  171. String operatingSystem = contentsObject.getString("operatingSystem");
  172. String browser = contentsObject.getString("browser");
  173. String isMobile = contentsObject.getString("isMobile");
  174. String currentDay = contentsObject.getString("currentDay");
  175. long createdTime = contentsObject.getLong("createdTime");
  176. long lastModified = contentsObject.getLong("lastModified");
  177. int ptype = contentsObject.getInteger("ptype");
  178. SQLFactory sqlFactory = new SQLFactory(this, "频道直播观看详情数据插入");
  179. sqlFactory.addParameter("ptype", ptype);
  180. sqlFactory.addParameter("playid", playId);
  181. sqlFactory.addParameter("userid", userId);
  182. sqlFactory.addParameter("channelid", channelId);
  183. sqlFactory.addParameter("playduration", playDuration);
  184. sqlFactory.addParameter("stayduration", stayDuration);
  185. sqlFactory.addParameter("flowsize", flowSize);
  186. sqlFactory.addParameter("sessionid", sessionId);
  187. sqlFactory.addParameter("param1", param1);
  188. sqlFactory.addParameter("param2", param2);
  189. sqlFactory.addParameter("param3", param3);
  190. sqlFactory.addParameter("param4", param4);
  191. sqlFactory.addParameter("param5", param5);
  192. sqlFactory.addParameter("ipaddress", ipAddress);
  193. sqlFactory.addParameter("country", country);
  194. sqlFactory.addParameter("province", province);
  195. sqlFactory.addParameter("city", city);
  196. sqlFactory.addParameter("isp", isp);
  197. sqlFactory.addParameter("referer", referer);
  198. sqlFactory.addParameter("useragent", userAgent);
  199. sqlFactory.addParameter("operatingsystem", operatingSystem);
  200. sqlFactory.addParameter("browser", browser);
  201. sqlFactory.addParameter("ismobile", isMobile);
  202. sqlFactory.addParameter("currentday", currentDay);
  203. sqlFactory.addParameter("createdtime", createdTime);
  204. sqlFactory.addParameter("lastmodified", lastModified);
  205. sqllist.add(sqlFactory.getSQL());
  206. }
  207. } while (!islastpage);
  208. dbConnect.runSqlUpdate(sqllist);
  209. }
  210. }
  211. /**
  212. * 获取频道直播观众聊天记录
  213. */
  214. public void getLiveMessageList() {
  215. System.err.println("getLiveMessageList");
  216. DBConnect dbConnect = new DBConnect();
  217. String[] channelids = dbConnect.runSqlQuery("select channelid from tlive where livestatus in('live','waiting') and convert(varchar(10),lastlivedate,120)=convert(varchar(10),getDate(),120) ").toArray("channelid");
  218. Polyv polyv = new Polyv();
  219. out:
  220. for (String channelid : channelids) {
  221. String startdate = getDate_Str();
  222. Rows maxtimerows = dbConnect.runSqlQuery("select isnull(max(time),0) as ftime from tlive_usermessages where channelid='" + channelid + "' having isnull(max(time),0)>0");
  223. if (!maxtimerows.isEmpty()) {
  224. Calendar calendar = Calendar.getInstance();
  225. calendar.setTimeInMillis(Long.parseLong(maxtimerows.get(0).getString("ftime")) + 1000);
  226. startdate = getDateTime_Str(calendar.getTime());
  227. }
  228. ArrayList<String> sqllist = new ArrayList<>();
  229. boolean islastpage;
  230. int pageNumber = 1;
  231. do {
  232. JSONObject object = polyv.getPageMessageList(channelid, startdate, getDate_Str(), "200", String.valueOf(pageNumber++));
  233. System.err.println(object);
  234. if (object == null) {
  235. continue out;
  236. }
  237. JSONArray contentsarray = object.getJSONArray("contents");
  238. islastpage = contentsarray.size() == 0;
  239. for (Object o : contentsarray) {
  240. JSONObject contentsObject = (JSONObject) o;
  241. String id = contentsObject.getString("id");
  242. String accountId = contentsObject.getString("accountId");
  243. String clientIP = contentsObject.getString("clientIP");
  244. String content = contentsObject.getString("content");
  245. String event = contentsObject.getString("event");
  246. String image = contentsObject.getString("image");
  247. String msgType = contentsObject.getString("msgType");
  248. String quote = contentsObject.getString("quote");
  249. String sessionId = contentsObject.getString("sessionId");
  250. String roomId = contentsObject.getString("roomId");
  251. String channelId = contentsObject.getString("channelId");
  252. String time = contentsObject.getString("time");
  253. String userType = contentsObject.getString("userType");
  254. String status = contentsObject.getString("status");
  255. String sourceType = contentsObject.getString("sourceType");
  256. JSONObject userObject = contentsObject.getJSONObject("user");
  257. String actor = userObject.getString("actor");
  258. boolean banned = userObject.getBoolean("banned");
  259. String nickname = userObject.getString("nickname");
  260. String pic = userObject.getString("pic");
  261. String uid = userObject.getString("uid");
  262. String userId = userObject.getString("userId");
  263. String userSource = userObject.getString("userSource");
  264. SQLFactory sqlFactory = new SQLFactory(this, "频道直播观众聊天记录数据插入");
  265. sqlFactory.addParameter("id", id);
  266. sqlFactory.addParameter("accountid", accountId);
  267. sqlFactory.addParameter("clientip", clientIP);
  268. sqlFactory.addParameter("content", content);
  269. sqlFactory.addParameter("event", event);
  270. sqlFactory.addParameter("imageurl", image);
  271. sqlFactory.addParameter("msgtype", msgType);
  272. sqlFactory.addParameter("quote", quote);
  273. sqlFactory.addParameter("sessionid", sessionId);
  274. sqlFactory.addParameter("roomid", roomId);
  275. sqlFactory.addParameter("channelid", channelId);
  276. sqlFactory.addParameter("time", time);
  277. sqlFactory.addParameter("usertype", userType);
  278. sqlFactory.addParameter("status", status);
  279. sqlFactory.addParameter("sourcetype", sourceType);
  280. sqlFactory.addParameter("actor", actor);
  281. sqlFactory.addParameter("banned", banned ? 1 : 0);
  282. sqlFactory.addParameter("nickname", nickname);
  283. sqlFactory.addParameter("pic", pic);
  284. sqlFactory.addParameter("uid", uid);
  285. sqlFactory.addParameter("userid", userId);
  286. sqlFactory.addParameter("usersource", userSource);
  287. sqllist.add(sqlFactory.getSQL());
  288. }
  289. } while (!islastpage);
  290. dbConnect.runSqlUpdate(sqllist);
  291. }
  292. }
  293. }