Skip to content

Commit e41f963

Browse files
committed
Merge remote-tracking branch 'origin/master'
2 parents b36662e + bcb4d17 commit e41f963

25 files changed

Lines changed: 741 additions & 161 deletions

Blog.Core.Api/Blog.Core.xml

Lines changed: 72 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
using System.Text;
2+
using Blog.Core.Common.DB.Extension;
3+
using Blog.Core.Controllers;
4+
using Blog.Core.Model;
5+
using Blog.Core.Model.Models;
6+
using Microsoft.AspNetCore.Authorization;
7+
using Microsoft.AspNetCore.Mvc;
8+
using SqlSugar;
9+
10+
namespace Blog.Core.Api.Controllers;
11+
12+
/// <summary>
13+
/// SqlSugar 相关测试
14+
/// </summary>
15+
[Route("api/[controller]/[action]")]
16+
[ApiController]
17+
[AllowAnonymous]
18+
public class SqlSugarTestController(ISqlSugarClient db) : BaseApiController
19+
{
20+
/// <summary>
21+
/// 测试建表后,SqlSugar缓存
22+
/// </summary>
23+
/// <returns></returns>
24+
[HttpGet]
25+
public MessageModel ClearDbTableCache()
26+
{
27+
var tableName = "BlogArticle_Test";
28+
29+
//先删除表
30+
try
31+
{
32+
db.DbMaintenance.DropTable(tableName);
33+
db.ClearDbTableCache();
34+
}
35+
catch
36+
{
37+
//Ignore
38+
}
39+
40+
StringBuilder sb = new StringBuilder();
41+
42+
//提前检查表是否存在,测试缓存
43+
sb.AppendLine($"表{tableName} 是否存在:{db.DbMaintenance.IsAnyTable(tableName)}");
44+
45+
//创建表
46+
db.CodeFirst.As<BlogArticle>(tableName).InitTables<BlogArticle>();
47+
sb.AppendLine($"表{tableName} 创建成功");
48+
49+
//检查表是否存在
50+
sb.AppendLine($"表{tableName} 是否存在:{db.DbMaintenance.IsAnyTable(tableName)}");
51+
52+
//清除缓存
53+
db.ClearDbTableCache();
54+
sb.AppendLine($"清除缓存后");
55+
56+
//检查表是否存在
57+
sb.AppendLine($"表{tableName} 是否存在:{db.DbMaintenance.IsAnyTable(tableName)}");
58+
59+
return Success(sb.ToString());
60+
}
61+
}
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
using System.ComponentModel;
2+
using Blog.Core.Controllers;
3+
using Microsoft.AspNetCore.Authorization;
4+
using Microsoft.AspNetCore.Mvc;
5+
6+
namespace Blog.Core.Api.Controllers.Test;
7+
8+
/// <summary>
9+
/// 枚举测试
10+
/// </summary>
11+
[Route("api/[Controller]/[Action]")]
12+
[AllowAnonymous]
13+
public class EnumTestController : BaseApiController
14+
{
15+
/// <summary>
16+
/// 获取学生信息
17+
/// </summary>
18+
/// <param name="studentType">学生类型</param>
19+
/// <param name="studentType2"></param>
20+
/// <param name="studentTypes"></param>
21+
/// <returns>学生信息</returns>
22+
[HttpGet]
23+
public Student GetStudent( StudentType studentType, StudentType? studentType2, List<StudentType> studentTypes)
24+
{
25+
return new Student
26+
{
27+
Name = "张三",
28+
Age = 20,
29+
Type = studentType
30+
};
31+
}
32+
}
33+
34+
/// <summary>
35+
/// 学生类型
36+
/// </summary>
37+
[Description("学生类型")]
38+
public enum StudentType
39+
{
40+
/// <summary>
41+
/// 小学生
42+
/// </summary>
43+
[Description("小学生")]
44+
PrimarySchool = 1,
45+
46+
/// <summary>
47+
/// 中学生
48+
/// </summary>
49+
[Description("中学生")]
50+
MiddleSchool = 2,
51+
52+
/// <summary>
53+
/// 大学生
54+
/// </summary>
55+
[Description("大学生")]
56+
University = 3
57+
}
58+
59+
public class Student
60+
{
61+
/// <summary>
62+
/// 学生姓名
63+
/// </summary>
64+
public string Name { get; set; }
65+
66+
/// <summary>
67+
/// 学生年龄
68+
/// </summary>
69+
public int Age { get; set; }
70+
71+
/// <summary>
72+
/// 学生类型
73+
/// </summary>
74+
public StudentType Type { get; set; }
75+
}

Blog.Core.Api/Controllers/ValuesController.cs

Lines changed: 36 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -48,14 +48,17 @@ public class ValuesController : BaseApiController
4848
private readonly SeqOptions _seqOptions;
4949
private readonly ICaching _cache;
5050

51-
public ValuesController(IBlogArticleServices blogArticleServices, IMapper mapper, IAdvertisementServices advertisementServices, Love love,
52-
IRoleModulePermissionServices roleModulePermissionServices, IUser user, IPasswordLibServices passwordLibServices,
53-
IHttpPollyHelper httpPollyHelper, IRabbitMQPersistentConnection persistentConnection, IOptions<SeqOptions> seqOptions, ICaching caching)
51+
public ValuesController(IBlogArticleServices blogArticleServices, IMapper mapper,
52+
IAdvertisementServices advertisementServices, Love love,
53+
IRoleModulePermissionServices roleModulePermissionServices, IUser user,
54+
IPasswordLibServices passwordLibServices,
55+
IHttpPollyHelper httpPollyHelper, IRabbitMQPersistentConnection persistentConnection,
56+
IOptions<SeqOptions> seqOptions, ICaching caching)
5457
{
5558
// 测试 Authorize 和 mapper
56-
_mapper = mapper;
57-
_advertisementServices = advertisementServices;
58-
_love = love;
59+
_mapper = mapper;
60+
_advertisementServices = advertisementServices;
61+
_love = love;
5962
_roleModulePermissionServices = roleModulePermissionServices;
6063
// 测试 Httpcontext
6164
_user = user;
@@ -66,10 +69,10 @@ public ValuesController(IBlogArticleServices blogArticleServices, IMapper mapper
6669
// 测试redis消息队列
6770
_blogArticleServices = blogArticleServices;
6871
// httpPolly
69-
_httpPollyHelper = httpPollyHelper;
72+
_httpPollyHelper = httpPollyHelper;
7073
_persistentConnection = persistentConnection;
71-
_cache = caching;
72-
_seqOptions = seqOptions.Value;
74+
_cache = caching;
75+
_seqOptions = seqOptions.Value;
7376
}
7477

7578
/// <summary>
@@ -84,7 +87,8 @@ public IActionResult TestRabbitMqPublish()
8487
_persistentConnection.TryConnect();
8588
}
8689

87-
_persistentConnection.PublishMessage("Hello, RabbitMQ!", exchangeName: "blogcore", routingKey: "myRoutingKey");
90+
_persistentConnection.PublishMessage("Hello, RabbitMQ!", exchangeName: "blogcore",
91+
routingKey: "myRoutingKey");
8892
return Ok();
8993
}
9094

@@ -104,7 +108,8 @@ public IActionResult TestRabbitMqSubscribe()
104108
return Ok();
105109
}
106110

107-
private async Task<bool> Dealer(string exchange, string routingKey, byte[] msgBody, IDictionary<string, object> headers)
111+
private async Task<bool> Dealer(string exchange, string routingKey, byte[] msgBody,
112+
IDictionary<string, object> headers)
108113
{
109114
await Task.CompletedTask;
110115
Console.WriteLine("我是消费者,这里消费了一条信息是:" + Encoding.UTF8.GetString(msgBody));
@@ -120,7 +125,7 @@ public MessageModel<List<ClaimDto>> MyClaims()
120125
response = (_user.GetClaimsIdentity().ToList()).Select(d =>
121126
new ClaimDto
122127
{
123-
Type = d.Type,
128+
Type = d.Type,
124129
Value = d.Value
125130
}
126131
).ToList()
@@ -194,9 +199,9 @@ await _blogArticleServices.QuerySql(
194199

195200
// 测试多个异步执行时间
196201
var roleModuleTask = _roleModulePermissionServices.Query();
197-
var listTask = _advertisementServices.Query();
198-
var ad = await roleModuleTask;
199-
var list = await listTask;
202+
var listTask = _advertisementServices.Query();
203+
var ad = await roleModuleTask;
204+
var list = await listTask;
200205

201206

202207
// 测试service层返回异常
@@ -290,8 +295,8 @@ public MessageModel<List<string>> GetUserInfo(string ClaimType = "jti")
290295
var getUserInfoByToken = _user.GetUserInfoFromToken(ClaimType);
291296
return new MessageModel<List<string>>()
292297
{
293-
success = _user.IsAuthenticated(),
294-
msg = _user.IsAuthenticated() ? _user.Name.ObjToString() : "未登录",
298+
success = _user.IsAuthenticated(),
299+
msg = _user.IsAuthenticated() ? _user.Name.ObjToString() : "未登录",
295300
response = _user.GetClaimValueByType(ClaimType)
296301
};
297302
}
@@ -353,11 +358,11 @@ public object TestPostPara(string name)
353358
public async Task<object> TestMutiDBAPI()
354359
{
355360
// 从主库中,操作blogs
356-
var blogs = await _blogArticleServices.Query(d => d.bID == 1);
361+
var blogs = await _blogArticleServices.Query(d => d.bID == 1);
357362
var addBlog = await _blogArticleServices.Add(new BlogArticle() { });
358363

359364
// 从从库中,操作pwds
360-
var pwds = await _passwordLibServices.Query(d => d.PLID > 0);
365+
var pwds = await _passwordLibServices.Query(d => d.PLID > 0);
361366
var addPwd = await _passwordLibServices.Add(new PasswordLib() { });
362367

363368
return new
@@ -494,6 +499,18 @@ public async Task<MessageModel<string>> TestCacheAsync()
494499

495500
return Success<string>("");
496501
}
502+
503+
/// <summary>
504+
/// 雪花Id To DateTime
505+
/// </summary>
506+
/// <param name="id"></param>
507+
/// <returns></returns>
508+
[HttpGet]
509+
[AllowAnonymous]
510+
public DateTime SnowflakeIdToDateTime(long id)
511+
{
512+
return YitterSnowflakeHelper.GetDateTime(IdGeneratorUtility.GetOptions(), id);
513+
}
497514
}
498515

499516
public class ClaimDto

Blog.Core.Api/appsettings.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,8 @@
7878
"SeedDBDataEnabled": true, //生成表,并初始化数据
7979
"Author": "Blog.Core",
8080
"SvcName": "", // /svc/blog
81-
"UseLoadTest": false
81+
"UseLoadTest": false,
82+
"CacheDbEnabled": false
8283
},
8384

8485
//优化DB配置、不会再区分单库多库

Blog.Core.Common/Blog.Core.Common.csproj

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,11 @@
3030
<PackageReference Include="Serilog.Sinks.Console" Version="5.0.0" />
3131
<PackageReference Include="Serilog.Sinks.Elasticsearch" Version="9.0.3" />
3232
<PackageReference Include="Serilog.Sinks.File" Version="5.0.0" />
33-
<PackageReference Include="SnowflakeId.AutoRegister" Version="1.0.1" />
34-
<PackageReference Include="SnowflakeId.AutoRegister.SqlServer" Version="1.0.0" />
35-
<PackageReference Include="SnowflakeId.AutoRegister.StackExchangeRedis" Version="1.0.0" />
36-
<PackageReference Include="StackExchange.Redis" Version="2.8.0" />
33+
<PackageReference Include="SnowflakeId.AutoRegister" Version="1.0.4" />
34+
<PackageReference Include="SnowflakeId.AutoRegister.SqlServer" Version="1.0.5" />
35+
<PackageReference Include="SnowflakeId.AutoRegister.StackExchangeRedis" Version="1.0.2" />
36+
<PackageReference Include="StackExchange.Redis" Version="2.8.22" />
37+
<PackageReference Include="Swashbuckle.AspNetCore.SwaggerGen" Version="6.5.0" />
3738
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="7.2.0" />
3839
<PackageReference Include="Serilog.Sinks.RollingFile" Version="3.3.1-dev-00771" />
3940

0 commit comments

Comments
 (0)