This commit is contained in:
lijianyou
2025-10-22 16:13:40 +08:00
parent 807e8f9ab3
commit 1b989df796
17 changed files with 2532 additions and 948 deletions
+86 -12
View File
@@ -1,6 +1,8 @@
using dy.net.dto;
using ClockSnowFlake;
using dy.net.dto;
using dy.net.model;
using SqlSugar;
using System.Reflection;
using System.Threading.Tasks;
namespace dy.net.service
@@ -14,39 +16,49 @@ namespace dy.net.service
this.sqlSugarClient = sqlSugarClient;
}
public AppConfig GetConfig()
public AppConfig GetConfig()
{
return sqlSugarClient.Queryable<AppConfig>().First();
return sqlSugarClient.Queryable<AppConfig>().First();
}
public AppConfig InitConfig(AppConfig config)
public AppConfig InitConfig()
{
var conf = GetConfig();
if (conf != null)
return conf;
else
{
var add = sqlSugarClient.Insertable<AppConfig>(config).ExecuteCommand();
AppConfig config = new AppConfig
{
Id = IdGener.GetLong().ToString(),
Cron = "30",
BatchCount = 10
};
sqlSugarClient.Insertable<AppConfig>(config).ExecuteCommand();
return config;
}
}
public async Task<bool> UpdateConfig(AppConfig config) {
public async Task<bool> UpdateConfig(AppConfig config)
{
var cc = await sqlSugarClient.Queryable<AppConfig>().FirstAsync(x=>x.Id== config.Id);
var cc = await sqlSugarClient.Queryable<AppConfig>().FirstAsync(x => x.Id == config.Id);
if (cc == null)
return false;
else {
else
{
cc.Cron = config.Cron;
cc.BatchCount = config.BatchCount;
}
var update = await sqlSugarClient.Updateable<AppConfig>(cc).ExecuteCommandAsync();
return update > 0 ;
return update > 0;
}
/// <summary>
@@ -54,11 +66,12 @@ namespace dy.net.service
/// </summary>
public void UpdateCollectViedoType()
{
var collectViedos= sqlSugarClient.Queryable<DyCollectVideo>().Where(x=>string.IsNullOrWhiteSpace(x.ViedoType)).ToList();
var collectViedos = sqlSugarClient.Queryable<DyCollectVideo>().Where(x => string.IsNullOrWhiteSpace(x.ViedoType)).ToList();
if (collectViedos.Any())
{
collectViedos.ForEach(x => {
collectViedos.ForEach(x =>
{
x.ViedoType = "2";
});
sqlSugarClient.Updateable(collectViedos).ExecuteCommand();
@@ -72,7 +85,7 @@ namespace dy.net.service
{
//var sql = "update dy_cookie set CollHasSyncd=0,FavHasSyncd=0,UperSyncd=0";
// sqlSugarClient.Ado.ExecuteCommand(sql) > 0;
var cookies= sqlSugarClient.Queryable<DyUserCookies>().ToList();
var cookies = sqlSugarClient.Queryable<DyUserCookies>().ToList();
foreach (var cookie in cookies)
{
@@ -97,6 +110,67 @@ namespace dy.net.service
return sqlSugarClient.Updateable(cookies).ExecuteCommand() > 0;
}
#region 测试创建数据库
///// <summary>
///// 创建SQLite数据库连接字符串
///// </summary>
//private string CreateSqliteDBConn()
//{
// var dbFolder = Path.Combine(Environment.CurrentDirectory, "db");
// Directory.CreateDirectory(dbFolder); // 不存在则创建,无需判断
// var dbPath = Path.Combine(dbFolder, "dy.sqlite");
// if (!File.Exists(dbPath))
// {
// using (File.Create(dbPath)) { } // 使用using确保文件流关闭
// }
// return $"DataSource={dbPath}";
//}
///// <summary>
///// 初始化数据库
///// </summary>
//public ISqlSugarClient InitDataBase(DbType dbType, string connString)
//{
// // 处理SQLite连接字符串
// if (dbType == DbType.Sqlite)
// {
// connString = CreateSqliteDBConn();
// }
// if (string.IsNullOrWhiteSpace(connString))
// {
// return null;
// }
// return new SqlSugarClient(new ConnectionConfig
// {
// ConnectionString = connString,
// InitKeyType = InitKeyType.Attribute,
// DbType = dbType,
// IsAutoCloseConnection = true
// }, db =>
// {
// // 日志配置
// db.Aop.OnLogExecuting = (sql, pars) => Serilog.Log.Debug(sql);
// db.Aop.OnError = e =>
// {
// Serilog.Log.Error(e.Message);
// Serilog.Log.Error(e.Sql);
// };
// // 创建数据库和表
// db.DbMaintenance.CreateDatabase();
// var modelTypes = Assembly.GetExecutingAssembly()
// .GetTypes()
// .Where(t => t.Namespace?.StartsWith("dy.net.model") ?? false)
// .ToArray();
// db.CodeFirst.InitTables(modelTypes);
// });
//}
#endregion
}
}
+15 -8
View File
@@ -59,26 +59,33 @@ namespace dy.net.service
List<DyCollectVideo> list = await this._dyCollectVideoRepository.GetAllAsync();
if (!list.Any())
return new VideoStaticsDto();
var Categories = list.GroupBy(x => x.Tag1).Select(x => new VideoStaticsItemDto { Name = x.Key, Count = x.LongCount() }).OrderByDescending(p=>p.Count).ToList();
var Categories = list.GroupBy(x => x.Tag1).Select(x => new VideoStaticsItemDto { Name = x.Key, Count = x.LongCount() }).OrderByDescending(p => p.Count).ToList();
Categories.Where(x => string.IsNullOrWhiteSpace(x.Name)).ToList().ForEach(x => x.Name = "其他");
var data = new VideoStaticsDto
{
AuthorCount = list.Select(x => x.AuthorId).Distinct().Count(),
CategoryCount=list.Select(x=>x.Tag1).Distinct().Count(),
CategoryCount = list.Select(x => x.Tag1).Distinct().Count(),
VideoCount = list.Count,
Categories= Categories,
FavoriteCount= list.Count(x => x.ViedoType=="1"),
CollectCount= list.Count(x => x.ViedoType=="2"),
ViedoSizeTotal = ByteToGbConverter.ConvertBytesToGb(list.Sum(x=>x.FileSize))
Categories = Categories,
FavoriteCount = list.Count(x => x.ViedoType == "1"),
CollectCount = list.Count(x => x.ViedoType == "2"),
FollowCount = list.Count(x => x.ViedoType == "3"),
VideoSizeTotal = ByteToGbConverter.ConvertBytesToGb(list.Sum(x => x.FileSize)),
VideoFavoriteSize = ByteToGbConverter.ConvertBytesToGb(list.Where(x => x.ViedoType == "1").Sum(x => x.FileSize)),
VideoCollectSize = ByteToGbConverter.ConvertBytesToGb(list.Where(x => x.ViedoType == "2").Sum(x => x.FileSize)),
VideoFollowSize = ByteToGbConverter.ConvertBytesToGb(list.Where(x => x.ViedoType == "3").Sum(x => x.FileSize)),
TotalDiskSize= ByteToGbConverter.GetHostTotalDiskSpaceGB(),
};
data.Authors = list.GroupBy(x => x.Author).Select(x => new VideoStaticsItemDto { Name = x.Key, Count = x.LongCount(), Icon=x.FirstOrDefault().AuthorAvatarUrl }).OrderByDescending(d=>d.Count).ToList();
data.Authors = list.GroupBy(x => x.Author).Select(x => new VideoStaticsItemDto { Name = x.Key, Count = x.LongCount(), Icon = x.FirstOrDefault().AuthorAvatarUrl }).OrderByDescending(d => d.Count).ToList();
return data;
}
//分页查询
public async Task<(List<DyCollectVideo> list, int totalCount)> GetPagedAsync(int pageIndex, int pageSize, string tag = null, string author = null,string viedoType=null,List<string>? dates=null)
public async Task<(List<DyCollectVideo> list, int totalCount)> GetPagedAsync(int pageIndex, int pageSize, string tag = null, string author = null, string viedoType = null, List<string>? dates = null)
{
return await _dyCollectVideoRepository.GetPagedAsync(pageIndex, pageSize, tag, author, viedoType, dates);
}
+19 -4
View File
@@ -26,14 +26,29 @@ namespace dy.net.service
return await _cookieRepository.InsertAsync(dyUserCookies);
}
public bool Init(DyUserCookies dyUserCookies)
public bool Init()
{
var exist = _cookieRepository.GetFirst(x => x.Id == dyUserCookies.Id);
if(exist != null)
var initId= "2026";
var exist = _cookieRepository.GetFirst(x => x.Id == initId);
if (exist != null)
{
return false;
}
return _cookieRepository.Insert(dyUserCookies);
var cookie = new DyUserCookies
{
UserName = "douyin",
Cookies = "--",
Id = initId,
SavePath = "/app/collect",
Status = 0,
SecUserId = "--",
FavSavePath = "/app/favorite",
UpSavePath = "/app/uper",
CollHasSyncd = 0,
FavHasSyncd = 0,
UperSyncd = 0
};
return _cookieRepository.Insert(cookie);
}
// 查询单个
+7 -1
View File
@@ -30,8 +30,14 @@ namespace dy.net.service
return await _userRepository.UpdateAvatar(avatar);
}
public (int code, string erro) InitUser(LoginUserInfo userInfo)
public (int code, string erro) InitUser()
{
LoginUserInfo userInfo = new LoginUserInfo
{
UserName = "douyin",
Password = "douyin2025",
CreateTime = DateTime.Now
};
return _userRepository.InitUser(userInfo);
}
}