live.java 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. package com.cnd3b.restcontroller.publicmethod.live;
  2. import com.alibaba.fastjson.JSONObject;
  3. import com.cnd3b.common.Controller;
  4. import com.cnd3b.common.data.Row;
  5. import com.cnd3b.common.data.Rows;
  6. import com.cnd3b.common.data.RowsMap;
  7. import com.cnd3b.common.data.SQLFactory;
  8. public class live extends Controller {
  9. public live(JSONObject content) {
  10. super(content);
  11. }
  12. /**
  13. * 获取当前直播商户数
  14. *
  15. * @return
  16. */
  17. public String getLiveChannelData() {
  18. String tactivityid = content.getString("tactivityid");
  19. String saleprodclass = content.getString("saleprodclass");
  20. if (saleprodclass == null) {
  21. saleprodclass = "";
  22. }
  23. JSONObject resultObject = new JSONObject();
  24. //参展商
  25. SQLFactory agentcountSql = new SQLFactory(this, "活动直播间总数查询");
  26. agentcountSql.addParameter("tactivityid", tactivityid);
  27. agentcountSql.addParameter("siteid", siteid);
  28. Rows agentCountRows = agentcountSql.runSqlQuery();
  29. resultObject.put("fagentcount", agentCountRows.isEmpty() ? 0 : agentCountRows.get(0).getInteger("fcount"));
  30. //观众总人数
  31. SQLFactory custcountSql = new SQLFactory(this, "活动直播间观众总数查询");
  32. custcountSql.addParameter("tactivityid", tactivityid);
  33. custcountSql.addParameter("siteid", siteid);
  34. Rows totalcustCountrows = custcountSql.runSqlQuery();
  35. resultObject.put("ftotalcustcount", totalcustCountrows.isEmpty() ? 0 : totalcustCountrows.get(0).getInteger("fcount"));
  36. SQLFactory livecustcount = new SQLFactory(this, "当前线上观众人数查询");
  37. livecustcount.addParameter("tactivityid", tactivityid);
  38. livecustcount.addParameter("siteid", siteid);
  39. livecustcount.addParameter("saleprodclass", "%" + saleprodclass + "%");
  40. Rows liverows = dbConnect.runSqlQuery(livecustcount.getSQL());
  41. String sql = livecustcount.getSQL();
  42. SQLFactory brandcustcount = new SQLFactory(this, "商户观众总数排行");
  43. brandcustcount.addParameter("tactivityid", tactivityid);
  44. brandcustcount.addParameter("siteid", siteid);
  45. Rows brandcustcountrows = dbConnect.runSqlQuery(brandcustcount.getSQL());
  46. int flivecount = liverows.size();
  47. //正在直播数
  48. resultObject.put("flivecount", flivecount);
  49. //当前在线观众人数
  50. resultObject.put("fcustcount", liverows.isEmpty() ? 0 : liverows.sum("fcustcount"));
  51. for (Row row : liverows) {
  52. //观看次数(次)
  53. String channelid = row.getString("channelid");
  54. //观看人数(人)
  55. long viewers = getCount("直播观看人数", "num", channelid);
  56. row.put("viewers", viewers);
  57. }
  58. //直播列表
  59. int pageSize = content.getIntValue("pageSize");
  60. int pageNumber = content.getIntValue("pageNumber");
  61. if (pageSize == 0 || pageNumber == 0) {
  62. resultObject.put("tlivelist", liverows);
  63. } else {
  64. Rows newliverows = new Rows();
  65. double pageTotal = Math.ceil((double) flivecount / (double) pageSize);//总页数
  66. int startindex = (pageNumber - 1) * pageSize;
  67. int endindex = (pageNumber) * pageSize - 1;
  68. // if (pageNumber >= pageTotal) {
  69. // startindex = flivecount - pageSize;
  70. // endindex = flivecount - 1;
  71. // }
  72. for (int i = 0; i < flivecount; i++) {
  73. if (startindex <= i && i <= endindex) {
  74. newliverows.add(liverows.get(i));
  75. }
  76. }
  77. //限制在2022-03-17,2022-03-19
  78. Long timeStart = getTimestamp("2022-03-17");
  79. Long timeEnd = getTimestamp("2022-03-19");
  80. Long timeNow = System.currentTimeMillis();
  81. if (timeNow >= timeStart && timeNow <= timeEnd) {
  82. resultObject.put("tlivelist", newliverows);
  83. } else {
  84. resultObject.put("tlivelist", new Rows());
  85. }
  86. resultObject.put("pageSize", pageSize);
  87. resultObject.put("pageNumber", pageNumber);
  88. resultObject.put("total", flivecount);
  89. resultObject.put("pageTotal", pageTotal);
  90. }
  91. //商户观众总数排行
  92. resultObject.put("brandcustcount", brandcustcountrows);
  93. //参展商户总数
  94. Rows fagentcountrows = dbConnect.runSqlQuery("select tagentsid from tactivity_agentmsg where siteid='" + siteid + "' and tactivityid='" + tactivityid + "' ");
  95. resultObject.put("fagentcount", fagentcountrows.size());
  96. return getSucReturnObject().setData(resultObject).toString();
  97. }
  98. /**
  99. * 通过直播状态获取门户直播列表
  100. *
  101. * @return
  102. */
  103. public String getHomeLive() {
  104. //直播状态 unStart:未开始 live:直播中 end:已结束 waiting:等待中 playback:回放中
  105. String livestatus = content.getString("livestatus");
  106. SQLFactory sqlFactory = new SQLFactory(this, "门户直播列表", pageSize, pageNumber, "t1.createdate");
  107. sqlFactory.addParameter("siteid", siteid);
  108. sqlFactory.addParameter("livestatus", "%" + livestatus + "%");
  109. Rows agentRows = dbConnect.runSqlQuery(sqlFactory.getSQL());
  110. for (Row row : agentRows) {
  111. //观看次数(次)
  112. String channelid = row.getString("channelid");
  113. //观看人数(人)
  114. long viewers = getCount("直播观看人数", "num", channelid);
  115. row.put("viewers", viewers);
  116. }
  117. return getSucReturnObject().setDataByPaging(agentRows).preloading(1).toString();
  118. }
  119. public long getCount(String SQLMODELNAME, String fieldname, String channelid) {
  120. SQLFactory sqlFactory = new SQLFactory(this, SQLMODELNAME);
  121. sqlFactory.addParameter("channelid", channelid);
  122. Rows rows = sqlFactory.runSqlQuery();
  123. return rows.isEmpty() ? 0 : rows.get(0).getLong(fieldname);
  124. }
  125. /**
  126. * 热门展商
  127. *
  128. * @return
  129. */
  130. public String agentList() {
  131. String tactivityid = content.getString("tactivityid");
  132. SQLFactory agentlistSql = new SQLFactory(this, "热门展商");
  133. agentlistSql.addParameter("tactivityid", tactivityid);
  134. agentlistSql.addParameter("siteid", siteid);
  135. Rows rows = agentlistSql.runSqlQuery();
  136. RowsMap map = getAttachmentUrl("tagents", rows.toArrayList("tagentsid"));
  137. for (Row row : rows) {
  138. row.put("attinfos", map.get(row.getString("tagentsid")));
  139. }
  140. return getSucReturnObject().setData(rows).saveToDataPool(10).toString();
  141. }
  142. /**
  143. * 热门展品
  144. *
  145. * @return
  146. */
  147. public String prodList() {
  148. String tactivityid = content.getString("tactivityid");
  149. SQLFactory prodlistSql = new SQLFactory(this, "热门展品");
  150. prodlistSql.addParameter("tactivityid", tactivityid);
  151. prodlistSql.addParameter("siteid", siteid);
  152. Rows rows = prodlistSql.runSqlQuery();
  153. RowsMap map = getAttachmentUrl("tagents_product", rows.toArrayList("tagents_productid"));
  154. for (Row row : rows) {
  155. row.put("attinfos", map.get(row.getString("tagents_productid")));
  156. }
  157. return getSucReturnObject().setData(rows).saveToDataPool(10).toString();
  158. }
  159. /**
  160. * 线上观众人数趋势(今日)
  161. *
  162. * @return
  163. */
  164. public String getLiveData() {
  165. String tactivityid = content.getString("tactivityid");
  166. SQLFactory sql1 = new SQLFactory(this, "线上观众人数趋势");
  167. sql1.addParameter("tactivityid", tactivityid);
  168. sql1.addParameter("siteid", siteid);
  169. Rows rows1 = sql1.runSqlQuery();
  170. SQLFactory sql2 = new SQLFactory(this, "观看直播地区人数占比");
  171. sql2.addParameter("tactivityid", tactivityid);
  172. sql2.addParameter("siteid", siteid);
  173. Rows rows2 = sql2.runSqlQuery();
  174. SQLFactory sql3 = new SQLFactory(this, "观看渠道人数占比");
  175. sql3.addParameter("tactivityid", tactivityid);
  176. sql3.addParameter("siteid", siteid);
  177. Rows rows3 = sql3.runSqlQuery();
  178. SQLFactory sql4 = new SQLFactory(this, "品类观众人数占比");
  179. sql4.addParameter("tactivityid", tactivityid);
  180. sql4.addParameter("siteid", siteid);
  181. Rows rows4 = sql4.runSqlQuery();
  182. JSONObject object = new JSONObject();
  183. object.put("custcount", rows1);
  184. object.put("citycount", rows2);
  185. object.put("channelcount", rows3);
  186. object.put("saleprodclasscount", rows4);
  187. return getSucReturnObject().setData(object).saveToDataPool(1).toString();
  188. }
  189. public String getPolyvSoftUrl() {
  190. JSONObject object = new JSONObject();
  191. object.put("MAC", "http://soft.polyv.net/custom/macCloud/04de51d4c1/4.5.4/Live-Setup.dmg");
  192. object.put("WIN", "http://live.polyv.net/clients/winClient/04de51d4c1/Live-Setup.exe");
  193. return getSucReturnObject().setData(object).toString();
  194. }
  195. }