From e450964cd88ee01fbb9176faa6fda112f315a63e Mon Sep 17 00:00:00 2001 From: zlzw <583819556@qq.com> Date: Fri, 29 Nov 2024 17:56:02 +0800 Subject: [PATCH] =?UTF-8?q?add=20=E6=96=B0=E5=A2=9E=E6=9F=A5=E7=9C=8B?= =?UTF-8?q?=E7=A4=BC=E7=89=A9=E8=AF=A6=E6=83=85=E5=88=97=E8=A1=A8=20fix=20?= =?UTF-8?q?=E8=B0=83=E6=95=B4=E7=A4=BC=E7=89=A9=E9=87=91=E9=A2=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Web/html/body/config.html | 31 ++++++++ Web/html/body/user.html | 2 +- Web/html/body/video.html | 76 ++++++++++++------- Web/html/ui/videoGiftItem.html | 68 +++++++++++++++++ .../live/database/LiveGiftDatabaseBean.java | 6 +- .../bean/websocket/live/WSSendGift.java | 2 +- .../biliapi/databases/BiliLiveDatabase.java | 9 ++- .../bilibili/Controllers/LiveController.java | 7 +- .../Controllers/VideoFileController.java | 2 +- .../yutou/bilibili/services/LiveService.java | 38 ++++++++++ 10 files changed, 205 insertions(+), 36 deletions(-) create mode 100644 Web/html/body/config.html create mode 100644 Web/html/ui/videoGiftItem.html diff --git a/Web/html/body/config.html b/Web/html/body/config.html new file mode 100644 index 0000000..aa9b80b --- /dev/null +++ b/Web/html/body/config.html @@ -0,0 +1,31 @@ + + + + + + + 系统设置 + + + + + + 不想做了,鸽 + + + + + + + + + + + \ No newline at end of file diff --git a/Web/html/body/user.html b/Web/html/body/user.html index c3e9b2d..e1273ba 100644 --- a/Web/html/body/user.html +++ b/Web/html/body/user.html @@ -222,7 +222,7 @@ }); } }); - + diff --git a/Web/html/body/video.html b/Web/html/body/video.html index 7545fdb..e7e2316 100644 --- a/Web/html/body/video.html +++ b/Web/html/body/video.html @@ -249,38 +249,60 @@ var lables = []; var values = []; data.data.guardInfo.forEach(item => { - lables.push(item.gift_name + "\n" + item.total_price / 100 + "¥") + lables.push(item.gift_name + "\n" + item.total_price + "¥") values.push(item.total_num) }); data.data.giftInfo.forEach(item => { - lables.push(item.gift_name + "\n" + item.total_price / 100 + "¥") + lables.push(item.gift_name + "\n" + item.total_price + "¥") values.push(item.total_gift_num) }); - if (chartView !== null) { - chartView.destroy() - } - chartView = new Chart($('#giftChart').get(0), { - type: 'pie', - data: { - labels: lables, - datasets: [{ - label: '礼物(总额:' + data.data.price / 100 + "¥)", - data: values, - borderWidth: 1 - } - ] - }, - options: { - scales: { - y: { - beginAtZero: true - } - } - } - }); + setChart(lables, values, data) }) } + function setChart(lables, values, data) { + if (chartView !== null) { + chartView.destroy() + } + chartView = new Chart($('#giftChart').get(0), { + type: 'pie', + data: { + labels: lables, + datasets: [{ + label: '礼物(总额:' + data.data.price + "¥)", + data: values, + borderWidth: 1 + } + ] + }, + options: { + scales: { + y: { + beginAtZero: true + } + }, + onClick: (e) => { + var giftName=e.chart.tooltip.title[0] + console.log(e.chart.tooltip.title) + + layer.open({ + type: 2, // page 层类型 + area: ['650px', '400px'], + title: '礼物详情', + shade: 0.6, // 遮罩透明度 + shadeClose: false, // 点击遮罩区域,关闭弹层 + maxmin: true, // 允许全屏最小化 + anim: 1, // 0-6 的动画形式,-1 不开启 + // btn: ['确定', '取消'], + content: '/html/ui/videoGiftItem.html?roomId=' + roomId + "&videoId=" + videoId + "&giftName=" + giftName, + yes: function (index, layero) { + + } + }); + } + } + }); + } function initMenu(data) { var view = $("#menuView").get(0); laytpl($('#menulist').get(0).innerHTML).render(data, function (html) { @@ -345,11 +367,11 @@ initSC(data.data.superChat) $('#danmuSize').get(0).innerHTML = data.data.danmuCount; barrageRenderer.setBarrages(data.data.danmu) - }else{ + } else { barrageRenderer.barrageLayoutCalculate.allBarrageInstances.push(...data.data.danmu); } - if(data.data.nextDanmu){ - loadDanmu(page+1) + if (data.data.nextDanmu) { + loadDanmu(page + 1) } // barrageRenderer.setBarrages(data.data.danmu); }) diff --git a/Web/html/ui/videoGiftItem.html b/Web/html/ui/videoGiftItem.html new file mode 100644 index 0000000..8ac4f77 --- /dev/null +++ b/Web/html/ui/videoGiftItem.html @@ -0,0 +1,68 @@ + + + + + + + +
+ + + + + + + + + + + \ No newline at end of file diff --git a/src/main/java/com/yutou/biliapi/bean/live/database/LiveGiftDatabaseBean.java b/src/main/java/com/yutou/biliapi/bean/live/database/LiveGiftDatabaseBean.java index cb5f6b3..fb448c8 100644 --- a/src/main/java/com/yutou/biliapi/bean/live/database/LiveGiftDatabaseBean.java +++ b/src/main/java/com/yutou/biliapi/bean/live/database/LiveGiftDatabaseBean.java @@ -12,7 +12,7 @@ public class LiveGiftDatabaseBean extends AbsDatabasesBean { @JSONField(name = "id") int id; @JSONField(name = "gift_id") - private int giftId; + private long giftId; @JSONField(name = "gift_name") private String giftName; @JSONField(name = "price") @@ -22,9 +22,9 @@ public class LiveGiftDatabaseBean extends AbsDatabasesBean { @JSONField(name = "icon") private String icon; @JSONField(name = "gift_num") - private int giftNum; + private long giftNum; @JSONField(name = "sender_uid") - private long senderUid; + private String senderUid; @JSONField(name = "sender_name") private String senderName; @JSONField(name = "sender_face") diff --git a/src/main/java/com/yutou/biliapi/bean/websocket/live/WSSendGift.java b/src/main/java/com/yutou/biliapi/bean/websocket/live/WSSendGift.java index ed4a062..899f8b6 100644 --- a/src/main/java/com/yutou/biliapi/bean/websocket/live/WSSendGift.java +++ b/src/main/java/com/yutou/biliapi/bean/websocket/live/WSSendGift.java @@ -182,7 +182,7 @@ public class WSSendGift extends WSData { @JSONField(name = "base") private Base base; @JSONField(name = "uid") - private long uid; + private String uid; } @lombok.Data diff --git a/src/main/java/com/yutou/biliapi/databases/BiliLiveDatabase.java b/src/main/java/com/yutou/biliapi/databases/BiliLiveDatabase.java index fd3ce2f..a7e6501 100644 --- a/src/main/java/com/yutou/biliapi/databases/BiliLiveDatabase.java +++ b/src/main/java/com/yutou/biliapi/databases/BiliLiveDatabase.java @@ -125,7 +125,7 @@ public class BiliLiveDatabase extends SQLiteManager { "SUM(`gift_num`) AS `total_gift_num`," + "CASE " + "WHEN `coin_type` = 'silver' THEN 0 " + - "ELSE SUM(`price` * `gift_num`) " + + "ELSE SUM(`price` / 100 * `gift_num`) " + "END AS `total_price`" + "FROM " + "`gift` " + @@ -144,7 +144,7 @@ public class BiliLiveDatabase extends SQLiteManager { "filtered_gifts " + "GROUP BY " + "`gift_name`, `icon`;"; - String guardSql = "SELECT `gift_name`, SUM(`num`) AS `total_num`,SUM(`price`*`num`) as `total_price`" + + String guardSql = "SELECT `gift_name`, SUM(`num`) AS `total_num`,SUM(`price` /100 *`num`) as `total_price`" + "FROM `guardBuy` where `sql_time` >= '" + startTimeLong + "' and `sql_time` <= '" + endTimeLong + "'" + "GROUP BY `gift_name`;"; String superChatSql = "SELECT SUM(`price`*100) as `total_price`, count(`price`) as `total_count`" + @@ -233,6 +233,11 @@ public class BiliLiveDatabase extends SQLiteManager { return super.get(tableName, where, clazz); } + @Override + public List get(String table, String where, Class tClass) { + return super.get(table, where, tClass); + } + @Override public int getCount(String table) { return super.getCount(table); diff --git a/src/main/java/com/yutou/bilibili/Controllers/LiveController.java b/src/main/java/com/yutou/bilibili/Controllers/LiveController.java index c0f6655..cf5ba45 100644 --- a/src/main/java/com/yutou/bilibili/Controllers/LiveController.java +++ b/src/main/java/com/yutou/bilibili/Controllers/LiveController.java @@ -49,7 +49,12 @@ public class LiveController { @RequestMapping("/live/gift/info") @ResponseBody - public JSONObject download(String roomId, String videoId) { + public JSONObject info(String roomId, String videoId) { return ResultData.success(liveService.getGiftInfo(roomId, videoId)); } + @RequestMapping("/live/gift/info/item") + @ResponseBody + public JSONObject infoItem(String roomId,String videoId,String giftName) { + return ResultData.success(liveService.getGiftItemInfo(roomId, videoId, giftName)); + } } diff --git a/src/main/java/com/yutou/bilibili/Controllers/VideoFileController.java b/src/main/java/com/yutou/bilibili/Controllers/VideoFileController.java index be5b03f..a7a47fe 100644 --- a/src/main/java/com/yutou/bilibili/Controllers/VideoFileController.java +++ b/src/main/java/com/yutou/bilibili/Controllers/VideoFileController.java @@ -58,7 +58,7 @@ public class VideoFileController { try { length = new URL(url).openConnection().getContentLength(); } catch (IOException e) { - throw new RuntimeException(e); + return Tools.getFile(new File("Web"+ File.separator+"assets"+File.separator+"def.png")); } if (img.exists()&&length==img.length()) { return Tools.getFile(img); diff --git a/src/main/java/com/yutou/bilibili/services/LiveService.java b/src/main/java/com/yutou/bilibili/services/LiveService.java index a3b0c3a..43632a3 100644 --- a/src/main/java/com/yutou/bilibili/services/LiveService.java +++ b/src/main/java/com/yutou/bilibili/services/LiveService.java @@ -5,11 +5,14 @@ import com.alibaba.fastjson2.JSONObject; import com.yutou.biliapi.api.LiveApi; import com.yutou.biliapi.bean.live.LiveAnchorInfo; import com.yutou.biliapi.bean.live.database.LiveConfigDatabaseBean; +import com.yutou.biliapi.bean.live.database.LiveGiftDatabaseBean; +import com.yutou.biliapi.bean.live.database.LiveGuardBuyBean; import com.yutou.biliapi.bean.live.database.LiveVideoDatabaseBean; import com.yutou.biliapi.databases.BiliLiveDatabase; import com.yutou.biliapi.net.BiliLiveNetApiManager; import com.yutou.bilibili.Tools.DateFormatUtils; import com.yutou.bilibili.datas.web.LiveData; +import com.yutou.common.databases.AbsDatabasesBean; import com.yutou.common.okhttp.HttpLoggingInterceptor; import jakarta.annotation.Resource; import org.springframework.stereotype.Service; @@ -111,6 +114,41 @@ public class LiveService { return database.getGiftInfo(startTime, endTime); } + public JSONArray getGiftItemInfo(String roomId, String videoId, String giftName) { + BiliLiveDatabase database = databasesService.getLiveDatabase(roomId); + LiveVideoDatabaseBean videoBean = database.getVideo(videoId); + if (videoBean == null) { + return new JSONArray(); + } + long startTime = videoBean.getStartTime().getTime(); + long endTime = videoBean.getStopTime() == null ? System.currentTimeMillis() : videoBean.getStopTime().getTime(); + String where = " `sql_time` >= " + "\"" + startTime + "\"" + + " and " + " `sql_time` <= " + "\"" + endTime + "\"" + + " and " + " `gift_name` = " + "\"" + giftName + "\""; + List list = database.get(new LiveGiftDatabaseBean().getTableName(), where, LiveGiftDatabaseBean.class); + List list2 = database.get(new LiveGuardBuyBean().getTableName(), where, LiveGuardBuyBean.class); + JSONArray array = new JSONArray(); + array.addAll(list); + array.addAll( + list2.stream().map(it->{ + LiveGiftDatabaseBean tmp=new LiveGiftDatabaseBean(); + tmp.setGiftId(it.getGiftID()); + tmp.setGiftName(it.getGiftName()); + tmp.setGiftNum(it.getNum()); + tmp.setPrice(it.getPrice()); + tmp.setIcon("/assets/def.png"); + tmp.setSenderUid(it.getUid()); + tmp.setSenderName(it.getUsername()); + tmp.setSenderFace("/assets/def.png"); + tmp.setSql_time(it.getSql_time()); + return tmp; + }).toList() + ); + + return array; + + } + public static void main(String[] args) { HttpLoggingInterceptor.setLog(true); LiveService service = new LiveService();