live.java 9.4 KB

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