代码整理

This commit is contained in:
jianzhichu
2026-01-23 22:24:00 +08:00
parent 60f6e3847d
commit 3f6b1874eb
60 changed files with 348 additions and 991 deletions
+10 -10
View File
@@ -38,8 +38,8 @@ namespace dy.net.repository
var newpassword = loginUser.Password.Md5();
user.Password = newpassword;
user.UserName = loginUser.UserName;
var res = await this.UpdateAsync(user);
return (res?0:-1,res ?"更新成功" : "更新失败");
var res = await this.UpdateAsync(user);
return (res ? 0 : -1, res ? "更新成功" : "更新失败");
}
}
else
@@ -50,11 +50,11 @@ namespace dy.net.repository
}
public async Task<AdminUserInfo> GetUser(string userName=null)
public async Task<AdminUserInfo> GetUser(string userName = null)
{
if (string.IsNullOrWhiteSpace(userName))
{
return await this.GetFirstAsync(x=>!string.IsNullOrWhiteSpace(x.Id));
return await this.GetFirstAsync(x => !string.IsNullOrWhiteSpace(x.Id));
}
else
{
@@ -80,7 +80,7 @@ namespace dy.net.repository
{
user.Avatar = avatar;
var update = await UpdateAsync(user);
return update ;
return update;
}
}
@@ -89,10 +89,10 @@ namespace dy.net.repository
/// </summary>
/// <param name="userInfo"></param>
/// <returns></returns>
public (int code, string erro) InitUser(AdminUserInfo userInfo)
public (int code, string erro) InitUser(AdminUserInfo userInfo)
{
var isInit = this.GetFirst(x=>!string.IsNullOrWhiteSpace(x.Id));
if (isInit!=null)
var isInit = this.GetFirst(x => !string.IsNullOrWhiteSpace(x.Id));
if (isInit != null)
{
return (-1, "系统用户已存在");
}
@@ -102,8 +102,8 @@ namespace dy.net.repository
userInfo.CreateTime = DateTime.Now;
userInfo.Password = Md5Util.Md5(userInfo.Password);
var res = this.Insert(userInfo);
return (res ? 0 : -1, res ? "初始用户成功" : "初始化用户失败");
var res = this.Insert(userInfo);
return (res ? 0 : -1, res ? "初始用户成功" : "初始化用户失败");
}
}
}
+1 -1
View File
@@ -311,7 +311,7 @@ namespace dy.net.repository
{
return await Db.Queryable<T>().Where(whereExpression).ToListAsync();
}
/// <summary>
/// 分页查询
/// </summary>
+2 -4
View File
@@ -3,8 +3,6 @@ using dy.net.model.dto;
using dy.net.model.entity;
using dy.net.utils;
using SqlSugar;
using System;
using System.Linq.Expressions;
namespace dy.net.repository
{
@@ -24,7 +22,7 @@ namespace dy.net.repository
public async Task<(List<DouyinCollectCate> list, int totalCount)> GetPagedAsync(DouyinCollectCateRequestDto dto)
{
var where = this.Db.Queryable<DouyinCollectCate>()
.Where(x=>x.CateType==dto.cateType)
.Where(x => x.CateType == dto.cateType)
.WhereIF(!string.IsNullOrWhiteSpace(dto.cookieId), x => x.CookieId == dto.cookieId);
var totalCount = await where.CountAsync();
@@ -174,7 +172,7 @@ namespace dy.net.repository
{
var videoCounts = await Db.Queryable<DouyinVideo>().Where(x => x.CateId == cate.Id && x.CateXId == cate.XId && x.ViedoType == cate.CateType).CountAsync();
cate.IsEnd = videoCounts == cate.Total;
var update = await Db.Updateable(cate).UpdateColumns(x => new { x.IsEnd }).ExecuteCommandAsync();
return update > 0;
}
+5 -5
View File
@@ -17,7 +17,7 @@ namespace dy.net.repository
// 1. 初始化查询:先加固定条件 Status == 1
var query = Db.Queryable<DouyinCookie>()
.Where(x => x.Status == 1)
.Where(x=>!string.IsNullOrWhiteSpace(x.Cookies)); // 固定条件(必选)
.Where(x => !string.IsNullOrWhiteSpace(x.Cookies)); // 固定条件(必选)
// 2. 若传入自定义条件,叠加 Where(自动 AND 组合)
if (whereExpression != null)
@@ -38,16 +38,16 @@ namespace dy.net.repository
return (list, totalCount);
}
public DouyinCookie GetDefault()
public DouyinCookie GetDefault()
{
return Db.Queryable<DouyinCookie>()
return Db.Queryable<DouyinCookie>()
.First();
}
public async Task<bool> SwitchAsync(DouyinCookieSwitchDto dto)
{
var res =await Db.Updateable<DouyinCookie>().SetColumns(x => new DouyinCookie { Status = dto.Status }).Where(x => x.Id == dto.Id).ExecuteCommandAsync();
var res = await Db.Updateable<DouyinCookie>().SetColumns(x => new DouyinCookie { Status = dto.Status }).Where(x => x.Id == dto.Id).ExecuteCommandAsync();
return res > 0;
}
@@ -60,7 +60,7 @@ namespace dy.net.repository
return res > 0;
}
return false;
}
}
}
+1 -2
View File
@@ -1,5 +1,4 @@
using ClockSnowFlake;
using dy.net.extension;
using dy.net.model.dto;
using dy.net.model.entity;
using dy.net.model.response;
@@ -84,7 +83,7 @@ namespace dy.net.repository
public async Task<List<DouyinFollowed>> GetSyncFollows(string userId)
{
return await this.Db.Queryable<DouyinFollowed>()
.Where(x => x.OpenSync == true).Where(x => x.mySelfId == userId).Where(x=>!string.IsNullOrWhiteSpace(x.SecUid))
.Where(x => x.OpenSync == true).Where(x => x.mySelfId == userId).Where(x => !string.IsNullOrWhiteSpace(x.SecUid))
.ToListAsync();
}
+10 -12
View File
@@ -1,9 +1,7 @@
using dy.net.extension;
using dy.net.model.dto;
using dy.net.model.entity;
using Quartz.Util;
using SqlSugar;
using System.Linq;
namespace dy.net.repository
{
@@ -15,11 +13,11 @@ namespace dy.net.repository
}
public async Task<List<DouyinVideoTopDto>> GetTopsOrderBySyncTime(int top)
{
return await Db.Queryable<DouyinVideo>().Select(x=>new DouyinVideoTopDto {Id=x.Id, Title=x.VideoTitle,Time=x.SyncTime.ToString("yyyy-MM-dd HH:mm:ss")}).Take(top).OrderByDescending(x=>x.Time).ToListAsync();
return await Db.Queryable<DouyinVideo>().Select(x => new DouyinVideoTopDto { Id = x.Id, Title = x.VideoTitle, Time = x.SyncTime.ToString("yyyy-MM-dd HH:mm:ss") }).Take(top).OrderByDescending(x => x.Time).ToListAsync();
}
/// <summary>
///
@@ -36,16 +34,16 @@ namespace dy.net.repository
VideoTypeEnum? enumviedoType = null;
if (!string.IsNullOrEmpty(dto.ViedoType) && dto.ViedoType != "*" && dto.ViedoType != "4")
if (!string.IsNullOrEmpty(dto.ViedoType) && dto.ViedoType != "*" && dto.ViedoType != "4")
{
enumviedoType = dto.ViedoType.ToVideoTypeEnum();
}
var where = this.Db.Queryable<DouyinVideo>()
//.WhereIF(!string.IsNullOrWhiteSpace(title), x => x.VideoTitle.Contains(title))
.WhereIF(!string.IsNullOrWhiteSpace(dto.Title), x => x.VideoTitle.Contains(dto.Title))
.WhereIF(!string.IsNullOrWhiteSpace(dto.Author), x => x.Author.Contains(dto.Author))
.WhereIF(!string.IsNullOrWhiteSpace(dto.Tag), x => x.Tag1==dto.Tag)
.WhereIF(!string.IsNullOrWhiteSpace(dto.Tag), x => x.Tag1 == dto.Tag)
.WhereIF(start.HasValue, x => x.SyncTime >= start.Value)
.WhereIF(end.HasValue, x => x.SyncTime <= end.Value)
.WhereIF(start2.HasValue, x => x.CreateTime >= start2.Value)
@@ -56,8 +54,8 @@ namespace dy.net.repository
var totalCount = await where.CountAsync();
List<DouyinVideo> list = new List<DouyinVideo>();
if(string.IsNullOrWhiteSpace(dto.SortField))
list = await where.OrderByDescending(x => x.SyncTime).Skip((dto.PageIndex - 1) * dto.PageSize).Take(dto.PageSize).ToListAsync();
if (string.IsNullOrWhiteSpace(dto.SortField))
list = await where.OrderByDescending(x => x.SyncTime).Skip((dto.PageIndex - 1) * dto.PageSize).Take(dto.PageSize).ToListAsync();
else
{
@@ -100,10 +98,10 @@ namespace dy.net.repository
/// <param name="AuthorId"></param>
/// <param name="ViedoNameSimplify"></param>
/// <returns></returns>
public (string, string) GetUperLastViedoFileName(string AuthorId, string ViedoNameSimplify)
public (string, string) GetUperLastViedoFileName(string AuthorId, string ViedoNameSimplify)
{
var video = this.Db.Queryable<DouyinVideo>().Where(x => x.AuthorId == AuthorId && x.ViedoType == VideoTypeEnum.dy_follows)
var video = this.Db.Queryable<DouyinVideo>().Where(x => x.AuthorId == AuthorId && x.ViedoType == VideoTypeEnum.dy_follows)
.Where(x => x.VideoTitleSimplify == ViedoNameSimplify)
.OrderByDescending(x => x.CreateTime).First();
@@ -157,7 +155,7 @@ namespace dy.net.repository
{
if (downs != null)
{
return Db.Insertable(downs).ExecuteCommand() > 0;
return Db.Insertable(downs).ExecuteCommand() > 0;
}
else