Skip to content

Commit

Permalink
添加根据视频筛选弹幕功能
Browse files Browse the repository at this point in the history
  • Loading branch information
MonoLogueChi committed Mar 12, 2020
1 parent d12f29a commit cef0ee6
Show file tree
Hide file tree
Showing 16 changed files with 549 additions and 119 deletions.
3 changes: 2 additions & 1 deletion Danmu.sln.DotSettings.user
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@
<s:Boolean x:Key="/Default/UserDictionary/Words/=Danmu/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Danmus/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Dplayer/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Postgre/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Postgre/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=vids/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>
41 changes: 40 additions & 1 deletion Danmu/Controllers/Admin/DanmakuListController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,49 @@ public async Task<WebResult<int>> GetCount()
/// </summary>
/// <returns></returns>
[HttpGet]
public async Task<WebResult<DanmuTable[]>> GetDanmuList(int page, int size, bool descending = true)
public async Task<WebResult<DanmuTable[]>> GetDanmuList(int page = 1, int size = 30, bool descending = true)
{
var allDanmu = await DanmuDao.GetAllDanmuAsync(page, size, descending);
return new WebResult<DanmuTable[]>(allDanmu);
}

/// <summary>
/// 通过vid查询到的弹幕总数
/// </summary>
/// <param name="vid"></param>
/// <returns></returns>
[HttpGet("count" + "by" + "vid")]
public async Task<WebResult<int>> GetCountByVid(string vid)
{
var count = await DanmuDao.GetDanmuByVidAsync(vid);
return new WebResult<int>
{
Code = 0,
Data = count
};
}

/// <summary>
/// 通过vid查询弹幕
/// </summary>
/// <returns></returns>
[HttpGet("query" + "by" + "vid")]
public async Task<WebResult<DanmuTable[]>> GetDanmuListByVid(string vid, int page = 1, int size = 30,
bool descending = true)
{
var danmu = await DanmuDao.GetDanmuByVidAsync(vid, page, size, descending);
return new WebResult<DanmuTable[]>(danmu);
}

/// <summary>
/// 获取vid集合
/// </summary>
/// <returns></returns>
[HttpGet("vids")]
public async Task<WebResult<string[]>> GetVidList()
{
var vids = await VideoDao.GetVidsAsync();
return new WebResult<string[]>(vids);
}
}
}
117 changes: 117 additions & 0 deletions Danmu/Utils/Dao/DanmuDao.Admin.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
using System;
using System.Linq;
using System.Threading.Tasks;
using Danmu.Model.DataTable;
using Microsoft.EntityFrameworkCore;

namespace Danmu.Utils.Dao
{
public partial class DanmuDao
{
/// <summary>
/// 获取全部弹幕的数量
/// </summary>
/// <returns></returns>
public async Task<int> GetAllDanmuAsync()
{
return await _con.Danmu.CountAsync();
}

/// <summary>
/// 分页查询全部弹幕
/// </summary>
/// <param name="page"></param>
/// <param name="size"></param>
/// <param name="descending"></param>
/// <returns></returns>
public async Task<DanmuTable[]> GetAllDanmuAsync(int page, int size, bool descending = true)
{
var allDanmu = _con.Danmu;
var order = descending
? allDanmu.OrderByDescending(b => b.CreateTime)
: allDanmu.OrderBy(b => b.CreateTime);
return await order.Skip(size * (page - 1)).Take(size).ToArrayAsync();
}

/// <summary>
/// 通过id获取相应的弹幕
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
public async Task<DanmuTable> QueryDanmuByIdAsync(string id)
{
if (Guid.TryParse(id, out var guid))
return await _con.Danmu.Where(e => e.Id.Equals(guid)).Include(e => e.Video).FirstOrDefaultAsync();
return new DanmuTable();
}

/// <summary>
/// 编辑弹幕
/// </summary>
/// <param name="id"></param>
/// <param name="time"></param>
/// <param name="mode"></param>
/// <param name="color"></param>
/// <param name="text"></param>
/// <returns></returns>
public async Task<DanmuTable> EditDanmuAsync(Guid id, float time, int mode, int color, string text)
{
var dataBase = await _con.Danmu.Where(e => e.Id.Equals(id)).FirstOrDefaultAsync();
dataBase.Data.Time = time;
dataBase.Data.Mode = mode;
dataBase.Data.Color = color;
dataBase.Data.Text = text ?? dataBase.Data.Text;
dataBase.UpdateTime = DateTime.UtcNow;
_con.Update(dataBase);
if (await _con.SaveChangesAsync() > 0) return dataBase;
return null;
}

/// <summary>
/// 删除弹幕
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
public async Task<bool> DeleteDanmuAsync(string id)
{
if (Guid.TryParse(id, out var guid))
{
var dataBase = await _con.Danmu.Where(e => e.Id == guid).FirstOrDefaultAsync();
dataBase.UpdateTime = DateTime.UtcNow;
dataBase.IsDelete = true;
_con.Danmu.Update(dataBase);
return await _con.SaveChangesAsync() > 0;
}

return false;
}

/// <summary>
/// 通过vid查询到的弹幕总数
/// </summary>
/// <param name="vid"></param>
/// <returns></returns>
public async Task<int> GetDanmuByVidAsync(string vid)
{
return await _con.Danmu.Where(e => e.Vid.Equals(vid)).CountAsync();
}

/// <summary>
/// 通过vid查询弹幕表
/// </summary>
/// <param name="vid"></param>
/// <param name="size"></param>
/// <param name="descending"></param>
/// <param name="page"></param>
/// <returns></returns>
public async Task<DanmuTable[]> GetDanmuByVidAsync(string vid, int page, int size,
bool descending = true)
{
var allDanmu = _con.Danmu.Where(e => e.Vid.Equals(vid));
var order = descending
? allDanmu.OrderByDescending(b => b.CreateTime)
: allDanmu.OrderBy(b => b.CreateTime);
return await order.Skip(size * (page - 1)).Take(size).ToArrayAsync();
}
}
}
80 changes: 1 addition & 79 deletions Danmu/Utils/Dao/DanmuDao.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using System;
using System.Linq;
using System.Threading.Tasks;
using Danmu.Model.Danmu.DanmuData;
Expand All @@ -8,7 +7,7 @@

namespace Danmu.Utils.Dao
{
public class DanmuDao
public partial class DanmuDao
{
private readonly DanmuContext _con;

Expand All @@ -17,42 +16,6 @@ public DanmuDao(DanmuContext con)
_con = con;
}

/// <summary>
/// 获取全部弹幕的数量
/// </summary>
/// <returns></returns>
public async Task<int> GetAllDanmuAsync()
{
return await _con.Danmu.CountAsync();
}

/// <summary>
/// 分页查询全部弹幕
/// </summary>
/// <param name="page"></param>
/// <param name="size"></param>
/// <param name="descending"></param>
/// <returns></returns>
public async Task<DanmuTable[]> GetAllDanmuAsync(int page, int size, bool descending = true)
{
var allDanmu = _con.Danmu;
var order = descending
? allDanmu.OrderByDescending(b => b.CreateTime)
: allDanmu.OrderBy(b => b.CreateTime);
return await order.Skip(size * (page - 1)).Take(size).ToArrayAsync();
}

/// <summary>
/// 通过id获取相应的弹幕
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
public async Task<DanmuTable> QueryDanmuByIdAsync(string id)
{
var guid = Guid.Parse(id);
return await _con.Danmu.Where(e => e.Id.Equals(guid)).Include(e => e.Video).FirstOrDefaultAsync();
}

/// <summary>
/// 通过视频Vid查询弹幕
/// </summary>
Expand All @@ -73,46 +36,5 @@ public async Task<bool> InsertDanmuAsync(DanmuTable danmu)
await _con.Danmu.AddAsync(danmu);
return await _con.SaveChangesAsync() > 0;
}

/// <summary>
/// 编辑弹幕
/// </summary>
/// <param name="id"></param>
/// <param name="time"></param>
/// <param name="mode"></param>
/// <param name="color"></param>
/// <param name="text"></param>
/// <returns></returns>
public async Task<DanmuTable> EditDanmuAsync(Guid id, float time, int mode, int color, string text)
{
var dataBase = await _con.Danmu.Where(e => e.Id.Equals(id)).FirstOrDefaultAsync();
dataBase.Data.Time = time;
dataBase.Data.Mode = mode;
dataBase.Data.Color = color;
dataBase.Data.Text = text ?? dataBase.Data.Text;
dataBase.UpdateTime = DateTime.UtcNow;
_con.Update(dataBase);
if (await _con.SaveChangesAsync() > 0) return dataBase;
return null;
}

/// <summary>
/// 删除弹幕
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
public async Task<bool> DeleteDanmuAsync(string id)
{
if (Guid.TryParse(id, out var guid))
{
var dataBase = await _con.Danmu.Where(e => e.Id == guid).FirstOrDefaultAsync();
dataBase.UpdateTime = DateTime.UtcNow;
dataBase.IsDelete = true;
_con.Danmu.Update(dataBase);
return await _con.SaveChangesAsync() > 0;
}

return false;
}
}
}
9 changes: 9 additions & 0 deletions Danmu/Utils/Dao/VideoDao.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,5 +60,14 @@ public async Task<VideoTable> InsertAsync(VideoTable video)
return a.Entity;
return null;
}

/// <summary>
/// 获取vid列表
/// </summary>
/// <returns></returns>
public async Task<string[]> GetVidsAsync()
{
return await _con.Video.Select(e => e.Vid).Distinct().ToArrayAsync();
}
}
}
6 changes: 6 additions & 0 deletions Danmu/clientapp/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion Danmu/clientapp/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@
"vue-cli-plugin-element": "~1.0.1",
"vue-cookies": "^1.6.1",
"vue-router": "^3.1.5",
"vue-template-compiler": "^2.6.10"
"vue-template-compiler": "^2.6.10",
"vuex": "^3.1.3"
},
"eslintConfig": {
"root": true,
Expand Down
Binary file added Danmu/clientapp/public/favicon.ico
Binary file not shown.
2 changes: 1 addition & 1 deletion Danmu/clientapp/public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width,initial-scale=1.0">
<link rel="icon" href="<%= BASE_URL %>favicon.ico">
<link rel="icon" href="<%= BASE_URL %>favicon.png">
<title>danmu</title>
</head>
<body>
Expand Down
Loading

0 comments on commit cef0ee6

Please sign in to comment.