package com.cnd3b.restcontroller.publicmethod.live; import com.alibaba.fastjson.JSONObject; import com.cnd3b.common.Controller; import com.cnd3b.common.data.Row; import com.cnd3b.common.data.Rows; import com.cnd3b.common.data.RowsMap; import com.cnd3b.common.data.SQLFactory; public class live extends Controller { public live(JSONObject content) { super(content); } /** * 获取当前直播商户数 * * @return */ public String getLiveChannelData() { String tactivityid = content.getString("tactivityid"); String saleprodclass = content.getString("saleprodclass"); if (saleprodclass == null) { saleprodclass = ""; } JSONObject resultObject = new JSONObject(); //参展商 SQLFactory agentcountSql = new SQLFactory(this, "活动直播间总数查询"); agentcountSql.addParameter("tactivityid", tactivityid); agentcountSql.addParameter("siteid", siteid); Rows agentCountRows = agentcountSql.runSqlQuery(); resultObject.put("fagentcount", agentCountRows.isEmpty() ? 0 : agentCountRows.get(0).getInteger("fcount")); //观众总人数 SQLFactory custcountSql = new SQLFactory(this, "活动直播间观众总数查询"); custcountSql.addParameter("tactivityid", tactivityid); custcountSql.addParameter("siteid", siteid); Rows totalcustCountrows = custcountSql.runSqlQuery(); resultObject.put("ftotalcustcount", totalcustCountrows.isEmpty() ? 0 : totalcustCountrows.get(0).getInteger("fcount")); SQLFactory livecustcount = new SQLFactory(this, "当前线上观众人数查询"); livecustcount.addParameter("tactivityid", tactivityid); livecustcount.addParameter("siteid", siteid); livecustcount.addParameter("saleprodclass", "%" + saleprodclass + "%"); Rows liverows = dbConnect.runSqlQuery(livecustcount.getSQL()); String sql = livecustcount.getSQL(); SQLFactory brandcustcount = new SQLFactory(this, "商户观众总数排行"); brandcustcount.addParameter("tactivityid", tactivityid); brandcustcount.addParameter("siteid", siteid); Rows brandcustcountrows = dbConnect.runSqlQuery(brandcustcount.getSQL()); int flivecount = liverows.size(); //正在直播数 resultObject.put("flivecount", flivecount); //当前在线观众人数 resultObject.put("fcustcount", liverows.isEmpty() ? 0 : liverows.sum("fcustcount")); for (Row row : liverows) { //观看次数(次) String channelid = row.getString("channelid"); //观看人数(人) long viewers = getCount("直播观看人数", "num", channelid); row.put("viewers", viewers); } //直播列表 int pageSize = content.getIntValue("pageSize"); int pageNumber = content.getIntValue("pageNumber"); if (pageSize == 0 || pageNumber == 0) { resultObject.put("tlivelist", liverows); } else { Rows newliverows = new Rows(); double pageTotal = Math.ceil((double) flivecount / (double) pageSize);//总页数 int startindex = (pageNumber - 1) * pageSize; int endindex = (pageNumber) * pageSize - 1; // if (pageNumber >= pageTotal) { // startindex = flivecount - pageSize; // endindex = flivecount - 1; // } for (int i = 0; i < flivecount; i++) { if (startindex <= i && i <= endindex) { newliverows.add(liverows.get(i)); } } //限制在2022-03-17,2022-03-19 Long timeStart = getTimestamp("2022-03-17"); Long timeEnd = getTimestamp("2022-03-19"); Long timeNow = System.currentTimeMillis(); if (timeNow >= timeStart && timeNow <= timeEnd) { resultObject.put("tlivelist", newliverows); } else { resultObject.put("tlivelist", new Rows()); } resultObject.put("pageSize", pageSize); resultObject.put("pageNumber", pageNumber); resultObject.put("total", flivecount); resultObject.put("pageTotal", pageTotal); } //商户观众总数排行 resultObject.put("brandcustcount", brandcustcountrows); //参展商户总数 Rows fagentcountrows = dbConnect.runSqlQuery("select tagentsid from tactivity_agentmsg where siteid='" + siteid + "' and tactivityid='" + tactivityid + "' "); resultObject.put("fagentcount", fagentcountrows.size()); return getSucReturnObject().setData(resultObject).toString(); } /** * 通过直播状态获取门户直播列表 * * @return */ public String getHomeLive() { //直播状态 unStart:未开始 live:直播中 end:已结束 waiting:等待中 playback:回放中 String livestatus = content.getString("livestatus"); SQLFactory sqlFactory = new SQLFactory(this, "门户直播列表", pageSize, pageNumber, "t1.createdate"); sqlFactory.addParameter("siteid", siteid); sqlFactory.addParameter("livestatus", "%" + livestatus + "%"); Rows agentRows = dbConnect.runSqlQuery(sqlFactory.getSQL()); for (Row row : agentRows) { //观看次数(次) String channelid = row.getString("channelid"); //观看人数(人) long viewers = getCount("直播观看人数", "num", channelid); row.put("viewers", viewers); } return getSucReturnObject().setDataByPaging(agentRows).preloading(1).toString(); } public long getCount(String SQLMODELNAME, String fieldname, String channelid) { SQLFactory sqlFactory = new SQLFactory(this, SQLMODELNAME); sqlFactory.addParameter("channelid", channelid); Rows rows = sqlFactory.runSqlQuery(); return rows.isEmpty() ? 0 : rows.get(0).getLong(fieldname); } /** * 热门展商 * * @return */ public String agentList() { String tactivityid = content.getString("tactivityid"); SQLFactory agentlistSql = new SQLFactory(this, "热门展商"); agentlistSql.addParameter("tactivityid", tactivityid); agentlistSql.addParameter("siteid", siteid); Rows rows = agentlistSql.runSqlQuery(); RowsMap map = getAttachmentUrl("tagents", rows.toArrayList("tagentsid")); for (Row row : rows) { row.put("attinfos", map.get(row.getString("tagentsid"))); } return getSucReturnObject().setData(rows).saveToDataPool(10).toString(); } /** * 热门展品 * * @return */ public String prodList() { String tactivityid = content.getString("tactivityid"); SQLFactory prodlistSql = new SQLFactory(this, "热门展品"); prodlistSql.addParameter("tactivityid", tactivityid); prodlistSql.addParameter("siteid", siteid); Rows rows = prodlistSql.runSqlQuery(); RowsMap map = getAttachmentUrl("tagents_product", rows.toArrayList("tagents_productid")); for (Row row : rows) { row.put("attinfos", map.get(row.getString("tagents_productid"))); } return getSucReturnObject().setData(rows).saveToDataPool(10).toString(); } /** * 线上观众人数趋势(今日) * * @return */ public String getLiveData() { String tactivityid = content.getString("tactivityid"); SQLFactory sql1 = new SQLFactory(this, "线上观众人数趋势"); sql1.addParameter("tactivityid", tactivityid); sql1.addParameter("siteid", siteid); Rows rows1 = sql1.runSqlQuery(); SQLFactory sql2 = new SQLFactory(this, "观看直播地区人数占比"); sql2.addParameter("tactivityid", tactivityid); sql2.addParameter("siteid", siteid); Rows rows2 = sql2.runSqlQuery(); SQLFactory sql3 = new SQLFactory(this, "观看渠道人数占比"); sql3.addParameter("tactivityid", tactivityid); sql3.addParameter("siteid", siteid); Rows rows3 = sql3.runSqlQuery(); SQLFactory sql4 = new SQLFactory(this, "品类观众人数占比"); sql4.addParameter("tactivityid", tactivityid); sql4.addParameter("siteid", siteid); Rows rows4 = sql4.runSqlQuery(); JSONObject object = new JSONObject(); object.put("custcount", rows1); object.put("citycount", rows2); object.put("channelcount", rows3); object.put("saleprodclasscount", rows4); return getSucReturnObject().setData(object).saveToDataPool(1).toString(); } public String getPolyvSoftUrl() { JSONObject object = new JSONObject(); object.put("MAC", "http://soft.polyv.net/custom/macCloud/04de51d4c1/4.5.4/Live-Setup.dmg"); object.put("WIN", "http://live.polyv.net/clients/winClient/04de51d4c1/Live-Setup.exe"); return getSucReturnObject().setData(object).toString(); } }