live.java 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366
  1. package com.cnd3b.restcontroller.customer.live;
  2. import com.alibaba.fastjson.JSONArray;
  3. import com.alibaba.fastjson.JSONObject;
  4. import com.cnd3b.common.Controller;
  5. import com.cnd3b.common.data.Row;
  6. import com.cnd3b.common.data.Rows;
  7. import com.cnd3b.common.data.SQLFactory;
  8. import com.cnd3b.common.data.db.DataPool;
  9. import com.cnd3b.utility.polyv.Polyv;
  10. import p2.common.parse.A;
  11. import p2.pao.PaoRemote;
  12. import p2.pao.PaoSetRemote;
  13. import p2.util.P2Exception;
  14. import java.util.HashMap;
  15. public class live extends Controller {
  16. public live(JSONObject content) {
  17. super(content);
  18. }
  19. /**
  20. * 获取频道分类列表
  21. *
  22. * @return
  23. */
  24. public String getLiveCategory() {
  25. Polyv polyv = new Polyv();
  26. HashMap<Integer, String> map = polyv.listCategory();
  27. JSONArray array = new JSONArray();
  28. for (int id : map.keySet()) {
  29. JSONObject object = new JSONObject();
  30. object.put("categoryId", id);
  31. object.put("categoryName", map.get(id));
  32. array.add(object);
  33. }
  34. return getSucReturnObject().setData(array).toString();
  35. }
  36. /**
  37. * 直播列表查询
  38. *
  39. * @return
  40. */
  41. public String queryChannelList() {
  42. /**
  43. *排序条件设置
  44. */
  45. String[] sortfield = {"t1.createdate desc"};
  46. String sort = getSort(sortfield, "t1.createdate desc");
  47. /**
  48. * 过滤条件设置
  49. */
  50. StringBuffer where = new StringBuffer(" 1=1 ");
  51. if (content.containsKey("where")) {
  52. JSONObject whereObject = content.getJSONObject("where");
  53. if (whereObject.containsKey("condition") && !"".equals(whereObject.getString("condition"))) {
  54. where.append(" and(");
  55. where.append("t1.channelname like'%").append(whereObject.getString("condition")).append("%' ");
  56. where.append("or t2.fagentname like'%").append(whereObject.getString("condition")).append("%' ");
  57. where.append(")");
  58. }
  59. if (whereObject.containsKey("categoryid") && !"".equals(whereObject.getString("categoryid"))) {
  60. where.append(" and(");
  61. where.append("t1.categoryid ='").append(whereObject.getString("categoryid")).append("' ");
  62. where.append(")");
  63. }
  64. }
  65. SQLFactory costhead = new SQLFactory(this, "直播列表查询", pageSize, pageNumber, sort);
  66. costhead.addParameter("siteid", siteid);
  67. costhead.addParameter("tagentsid", tagentsid);
  68. costhead.addParameter_SQL("where", where);
  69. Rows rows = dbConnect.runSqlQuery(costhead.getSQL());
  70. return getSucReturnObject().setDataByPaging(rows, sortfield).setFinalDo(DataPool.defaultdatalife, 1);
  71. }
  72. /**
  73. * 直播详情查询
  74. *
  75. * @return
  76. */
  77. public String queryChannelMain() {
  78. long tliveid = content.getLong("tliveid");
  79. SQLFactory sqlFactory = new SQLFactory(this, "直播详情查询");
  80. sqlFactory.addParameter("siteid", siteid);
  81. sqlFactory.addParameter("tliveid", tliveid);
  82. Rows rows = dbConnect.runSqlQuery(sqlFactory.getSQL());
  83. return getSucReturnObject().setData(rows).toString();
  84. }
  85. /**
  86. * 展会直播详情
  87. *
  88. * @return
  89. */
  90. public String getLiveInfo() throws P2Exception {
  91. SQLFactory sqlFactory = new SQLFactory(this, "展会直播详情");
  92. sqlFactory.addParameter("siteid", siteid);
  93. sqlFactory.addParameter("tagentsid", tagentsid);
  94. Rows rows = dbConnect.runSqlQuery(sqlFactory.getSQL());
  95. if (rows.isEmpty()) {
  96. PaoSetRemote paoSetRemote = getP2ServerSystemPaoSet("tliveapply", "siteid = '" + siteid + "' AND fissecret = 0 AND fstatus = '申请'");
  97. if (paoSetRemote.isEmpty()) {
  98. return getErrReturnObject().setErrCode(3).setErrMsg("无直播间信息").toString();
  99. } else {
  100. return getErrReturnObject().setErrCode(2).setErrMsg("直播申请中").toString();
  101. }
  102. } else {
  103. return getSucReturnObject().setData(rows).toString();
  104. }
  105. }
  106. /**
  107. * 直播数据统计(频道)
  108. *
  109. * @return
  110. */
  111. public String getLiveDataCount() {
  112. String channelid = content.getString("channelid");
  113. JSONObject resultObject = new JSONObject();
  114. //观看次数(次)
  115. double viewCounts = getCount("观看次数", "num", channelid);
  116. resultObject.put("viewCounts", String.format("%.2f", viewCounts));
  117. //观看时长(分钟)
  118. double viewDuration = getCount("观看时长", "num", channelid);
  119. resultObject.put("viewDuration", String.format("%.2f", viewDuration));
  120. //观看人数(人)
  121. double viewers = getCount("观看人数", "num", channelid);
  122. resultObject.put("viewers", String.format("%.2f", viewers));
  123. //人均观看次数(次)
  124. resultObject.put("viewCountsAvg", String.format("%.2f", viewers == 0.0 ? 0 : viewCounts / viewers));
  125. //人均观看时长(分钟)
  126. resultObject.put("viewDurationAvg", String.format("%.2f", viewers == 0.0 ? 0 : viewDuration / viewers));
  127. return getSucReturnObject().setData(resultObject).toString();
  128. }
  129. /**
  130. * 直播数据统计(场次)
  131. *
  132. * @return
  133. * @throws P2Exception
  134. */
  135. public String getLiveDataCountForSession() throws P2Exception {
  136. String sessionid = content.getString("sessionid");
  137. double livepv = 0;
  138. double liveuv = 0;
  139. double duration = 0;
  140. PaoSetRemote paoSetRemote = getP2ServerSystemPaoSet("tlive_sessiondata", "sessionid = '" + sessionid + "'");
  141. if (!paoSetRemote.isEmpty()) {
  142. PaoRemote paoRemote = paoSetRemote.getPao(0);
  143. //人数
  144. livepv = paoRemote.getDouble("livepv");
  145. //人次
  146. liveuv = paoRemote.getDouble("liveuv");
  147. //时长
  148. duration = paoRemote.getDouble("duration");
  149. }
  150. JSONObject resultObject = new JSONObject();
  151. resultObject.put("livepv", String.format("%.2f", livepv));
  152. resultObject.put("liveuv", String.format("%.2f", liveuv));
  153. resultObject.put("duration", String.format("%.2f", duration));
  154. resultObject.put("liveuvAvg", String.format("%.2f", livepv == 0 ? 0 : liveuv / livepv));
  155. resultObject.put("durationAvg", String.format("%.2f", livepv == 0 ? 0 : duration / livepv));
  156. return getSucReturnObject().setData(resultObject).toString();
  157. }
  158. /**
  159. * 直播用户观看列表
  160. *
  161. * @return
  162. */
  163. public String getLiveUserList() {
  164. String channelid = content.getString("channelid");
  165. String sessionid = content.getString("sessionid");
  166. SQLFactory sqlFactory = new SQLFactory(this, "直播用户观看列表");
  167. sqlFactory.addParameter("channelid", channelid);
  168. sqlFactory.addParameter("sessionid", sessionid);
  169. Rows rows = dbConnect.runSqlQuery(sqlFactory.getSQL());
  170. return getSucReturnObject().setData(rows).toString();
  171. }
  172. /**
  173. * 直播场次列表查询
  174. *
  175. * @return
  176. */
  177. public String getLiveSessionList() {
  178. String channelid = content.getString("channelid");
  179. SQLFactory sqlFactory = new SQLFactory(this, "直播场次列表查询", pageSize, pageNumber, "createdate");
  180. sqlFactory.addParameter("channelid", channelid);
  181. Rows rows = dbConnect.runSqlQuery(sqlFactory.getSQL());
  182. return getSucReturnObject().setDataByPaging(rows).preloading(1).toString();
  183. }
  184. /**
  185. * 私域直播详情
  186. *
  187. * @return
  188. */
  189. public String getSYLiveInfo() throws P2Exception {
  190. SQLFactory sqlFactory = new SQLFactory(this, "私域直播详情");
  191. sqlFactory.addParameter("siteid", siteid);
  192. sqlFactory.addParameter("tagentsid", tagentsid);
  193. Rows rows = dbConnect.runSqlQuery(sqlFactory.getSQL());
  194. if (rows.isEmpty()) {
  195. PaoSetRemote paoSetRemote = getP2ServerSystemPaoSet("tliveapply", "siteid = '" + siteid + "' and tagentsid='" + tagentsid + "' AND fissecret = 1 AND fstatus = '申请'");
  196. if (paoSetRemote.isEmpty()) {
  197. return getErrReturnObject().setErrCode(3).setErrMsg("无直播间信息").toString();
  198. } else {
  199. return getErrReturnObject().setErrCode(2).setErrMsg("直播申请中").toString();
  200. }
  201. } else {
  202. return getSucReturnObject().setData(rows).toString();
  203. }
  204. }
  205. /**
  206. * 私域直播数据统计(频道)
  207. *
  208. * @return
  209. */
  210. public String getSYLiveDataCount() {
  211. String channelid = content.getString("channelid");
  212. JSONObject resultObject = new JSONObject();
  213. //观看次数(次)
  214. double viewCounts = getCount("观看次数", "num", channelid);
  215. resultObject.put("viewCounts", String.format("%.2f", viewCounts));
  216. //观看时长(分钟)
  217. double viewDuration = getCount("观看时长", "num", channelid);
  218. resultObject.put("viewDuration", String.format("%.2f", viewDuration));
  219. //观看人数(人)
  220. double viewers = getCount("观看人数", "num", channelid);
  221. resultObject.put("viewers", String.format("%.2f", viewers));
  222. System.err.println(viewCounts + "," + viewDuration + "," + viewers);
  223. //人均观看次数(次)
  224. resultObject.put("viewCountsAvg", String.format("%.2f", viewers == 0.0 ? 0 : viewCounts / viewers));
  225. //人均观看时长(分钟)
  226. resultObject.put("viewDurationAvg", String.format("%.2f", viewers == 0.0 ? 0 : viewDuration / viewers));
  227. return getSucReturnObject().setData(resultObject).toString();
  228. }
  229. /**
  230. * 私域直播数据统计(场次)
  231. *
  232. * @return
  233. * @throws P2Exception
  234. */
  235. public String getSYLiveDataCountForSession() throws P2Exception {
  236. String sessionid = content.getString("sessionid");
  237. double livepv = 0;
  238. double liveuv = 0;
  239. double duration = 0;
  240. PaoSetRemote paoSetRemote = getP2ServerSystemPaoSet("tlive_sessiondata", "sessionid = '" + sessionid + "'");
  241. if (!paoSetRemote.isEmpty()) {
  242. PaoRemote paoRemote = paoSetRemote.getPao(0);
  243. //人数
  244. livepv = paoRemote.getDouble("livepv");
  245. //人次
  246. liveuv = paoRemote.getDouble("liveuv");
  247. //时长
  248. duration = paoRemote.getDouble("duration");
  249. }
  250. JSONObject resultObject = new JSONObject();
  251. resultObject.put("livepv", String.format("%.2f", livepv));
  252. resultObject.put("liveuv", String.format("%.2f", liveuv));
  253. resultObject.put("duration", String.format("%.2f", duration));
  254. resultObject.put("liveuvAvg", String.format("%.2f", livepv == 0 ? 0 : liveuv / livepv));
  255. resultObject.put("durationAvg", String.format("%.2f", livepv == 0 ? 0 : duration / livepv));
  256. return getSucReturnObject().setData(resultObject).toString();
  257. }
  258. /**
  259. * 私域直播用户观看列表
  260. *
  261. * @return
  262. */
  263. public String getSYLiveUserList() {
  264. String channelid = content.getString("channelid");
  265. String sessionid = content.getString("sessionid");
  266. SQLFactory sqlFactory = new SQLFactory(this, "私域直播用户观看列表");
  267. sqlFactory.addParameter("channelid", channelid);
  268. sqlFactory.addParameter("sessionid", sessionid);
  269. Rows rows = dbConnect.runSqlQuery(sqlFactory.getSQL());
  270. return getSucReturnObject().setData(rows).toString();
  271. }
  272. /**
  273. * 私域直播申请
  274. *
  275. * @return
  276. */
  277. public String applySYLive() throws P2Exception {
  278. PaoSetRemote paoSetRemote = getP2ServerSystemPaoSet("tliveapply", "siteid = '" + siteid + "' AND fissecret = 1 AND fstatus = '申请'");
  279. if (paoSetRemote.isEmpty()) {
  280. PaoRemote paoRemote = paoSetRemote.addAtEnd();
  281. paoRemote.setValue("CHANGEBY", username, 11L);
  282. paoRemote.setValue("CHANGEDATE", getDateTime_Str(), 11L);
  283. paoRemote.setValue("CREATEBY", username, 11L);
  284. paoRemote.setValue("CREATEDATE", getDateTime_Str(), 11L);
  285. paoRemote.setValue("FISSECRET", true, 11L);
  286. paoRemote.setValue("FSTATUS", "申请", 11L);
  287. paoRemote.setValue("FNOTES", "私域直播申请", 11L);
  288. paoRemote.setValue("SITEID", siteid);
  289. paoRemote.setValue("TAGENTSID", tagentsid);
  290. paoSetRemote.save();
  291. return getSucReturnObject().setData("私域直播申请成功").toString();
  292. } else {
  293. return getErrReturnObject().setErrMsg("私域直播已申请").toString();
  294. }
  295. }
  296. /**
  297. * 私域直播场次列表查询
  298. *
  299. * @return
  300. */
  301. public String getSYLiveSessionList() {
  302. String channelid = content.getString("channelid");
  303. SQLFactory sqlFactory = new SQLFactory(this, "私域直播场次列表查询", pageSize, pageNumber, "createdate");
  304. sqlFactory.addParameter("channelid", channelid);
  305. Rows rows = dbConnect.runSqlQuery(sqlFactory.getSQL());
  306. return getSucReturnObject().setDataByPaging(rows).preloading(1).toString();
  307. }
  308. /**
  309. * 获取数量
  310. *
  311. * @param SQLMODELNAME SQL名称
  312. * @param fieldname 取数据的字段名称
  313. * @return
  314. */
  315. public double getCount(String SQLMODELNAME, String fieldname, String channelid) {
  316. SQLFactory sqlFactory = new SQLFactory(this, SQLMODELNAME);
  317. sqlFactory.addParameter("channelid", channelid);
  318. System.err.println(sqlFactory.getSQL());
  319. Rows rows = sqlFactory.runSqlQuery();
  320. return rows.isEmpty() ? 0 : rows.get(0).getDouble(fieldname);
  321. }
  322. }