Skip to content

Commit 6083913

Browse files
committed
更新1.1.0版本
1 parent 50acaa2 commit 6083913

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+1386
-220
lines changed

Admin.Core.Common/Admin.Core.Common.csproj

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@
55
</PropertyGroup>
66

77
<ItemGroup>
8-
<PackageReference Include="CSRedisCore" Version="3.6.1" />
9-
<PackageReference Include="FreeSql" Version="1.4.0-preview20200410" />
10-
<PackageReference Include="FreeSql.Provider.MySql" Version="1.4.0-preview20200410" />
11-
<PackageReference Include="FreeSql.Provider.Oracle" Version="1.4.0-preview20200410" />
12-
<PackageReference Include="FreeSql.Provider.Sqlite" Version="1.4.0-preview20200410" />
13-
<PackageReference Include="FreeSql.Provider.SqlServer" Version="1.4.0-preview20200410" />
14-
<PackageReference Include="FreeSql.Repository" Version="1.4.0-preview20200410" />
8+
<PackageReference Include="CSRedisCore" Version="3.6.2" />
9+
<PackageReference Include="FreeSql" Version="1.3.6" />
10+
<PackageReference Include="FreeSql.Provider.MySql" Version="1.3.6" />
11+
<PackageReference Include="FreeSql.Provider.Oracle" Version="1.3.6" />
12+
<PackageReference Include="FreeSql.Provider.Sqlite" Version="1.3.6" />
13+
<PackageReference Include="FreeSql.Provider.SqlServer" Version="1.3.6" />
14+
<PackageReference Include="FreeSql.Repository" Version="1.3.6" />
1515
<PackageReference Include="Microsoft.AspNetCore.Http.Abstractions" Version="2.2.0" />
1616
<PackageReference Include="Microsoft.Extensions.Caching.Memory" Version="3.1.3" />
1717
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="3.1.3" />

Admin.Core.Common/Auth/IUser.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ public interface IUser
1616
string Name { get; }
1717

1818
/// <summary>
19-
/// 姓名
19+
/// 昵称
2020
/// </summary>
21-
string RealName { get; }
21+
string NickName { get; }
2222
}
2323
}

Admin.Core.Common/Auth/User.cs

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,13 @@ public string Name
4949
}
5050

5151
/// <summary>
52-
/// 姓名
52+
/// 昵称
5353
/// </summary>
54-
public string RealName
54+
public string NickName
5555
{
5656
get
5757
{
58-
var name = _accessor?.HttpContext?.User?.FindFirst(ClaimAttributes.UserRealName);
58+
var name = _accessor?.HttpContext?.User?.FindFirst(ClaimAttributes.UserNickName);
5959

6060
if (name != null && name.Value.NotNull())
6161
{
@@ -85,11 +85,6 @@ public static class ClaimAttributes
8585
/// <summary>
8686
/// 姓名
8787
/// </summary>
88-
public const string UserRealName = "rna";
89-
90-
/// <summary>
91-
/// 登录日志Id
92-
/// </summary>
93-
public const string UserLoginLogId = "llid";
88+
public const string UserNickName = "nn";
9489
}
9590
}
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
namespace Admin.Core.Common.Configs
2+
{
3+
/// <summary>
4+
/// 上传配置
5+
/// </summary>
6+
public class UploadConfig
7+
{
8+
public AvatarConfig Avatar { get; set; }
9+
public AvatarConfig Document { get; set; }
10+
}
11+
12+
/// <summary>
13+
/// 头像配置
14+
/// </summary>
15+
public class AvatarConfig
16+
{
17+
/// <summary>
18+
/// 路径
19+
/// </summary>
20+
public string Path { get; set; }
21+
22+
/// <summary>
23+
/// 请求路径
24+
/// </summary>
25+
public string RequestPath { get; set; }
26+
27+
/// <summary>
28+
/// 路径格式
29+
/// </summary>
30+
public string Format { get; set; }
31+
/// <summary>
32+
/// 路径日期格式
33+
/// </summary>
34+
public string DateTimeFormat { get; set; }
35+
36+
/// <summary>
37+
/// 图片大小 1M = 1024 * 1024
38+
/// </summary>
39+
public long Size { get; set; }
40+
41+
/// <summary>
42+
/// 图片格式
43+
/// </summary>
44+
public string[] ContentType { get; set; }
45+
}
46+
47+
/// <summary>
48+
/// 文档配置
49+
/// </summary>
50+
public class DocumentConfig
51+
{
52+
/// <summary>
53+
/// 路径
54+
/// </summary>
55+
public string Path { get; set; }
56+
57+
/// <summary>
58+
/// 请求路径
59+
/// </summary>
60+
public string RequestPath { get; set; }
61+
62+
/// <summary>
63+
/// 路径格式
64+
/// </summary>
65+
public string Format { get; set; }
66+
67+
/// <summary>
68+
/// 路径日期格式
69+
/// </summary>
70+
public string DateTimeFormat { get; set; }
71+
72+
/// <summary>
73+
/// 文件大小 10M = 10 * 1024 * 1024
74+
/// </summary>
75+
public long Size { get; set; }
76+
77+
/// <summary>
78+
/// 文件格式
79+
/// </summary>
80+
public string[] ContentType { get; set; }
81+
}
82+
}

Admin.Core.Common/Helpers/ConfigHelper.cs

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
using System;
2-
using System.IO;
1+
using System.IO;
32
using Microsoft.Extensions.Configuration;
43

54
namespace Admin.Core.Common.Helpers
@@ -9,6 +8,17 @@ namespace Admin.Core.Common.Helpers
98
/// </summary>
109
public class ConfigHelper
1110
{
11+
/* 使用热更新
12+
var uploadConfig = new ConfigHelper().Load("uploadconfig", _env.EnvironmentName, true);
13+
services.Configure<UploadConfig>(uploadConfig);
14+
15+
private readonly UploadConfig _uploadConfig;
16+
public ImgController(IOptionsMonitor<UploadConfig> uploadConfig)
17+
{
18+
_uploadConfig = uploadConfig.CurrentValue;
19+
}
20+
*/
21+
1222
/// <summary>
1323
/// 加载配置文件
1424
/// </summary>
@@ -18,7 +28,7 @@ public class ConfigHelper
1828
/// <returns></returns>
1929
public IConfiguration Load(string fileName, string environmentName = "", bool reloadOnChange = false)
2030
{
21-
var filePath = Path.Combine(AppContext.BaseDirectory, "configs");
31+
var filePath = Path.Combine(Directory.GetCurrentDirectory(), "configs");
2232
if (!Directory.Exists(filePath))
2333
return null;
2434

@@ -38,8 +48,8 @@ public IConfiguration Load(string fileName, string environmentName = "", bool re
3848
/// 获得配置信息
3949
/// </summary>
4050
/// <typeparam name="T">配置信息</typeparam>
41-
/// <param name="fileName"></param>
42-
/// <param name="environmentName">文件名称</param>
51+
/// <param name="fileName">文件名称</param>
52+
/// <param name="environmentName">环境名称</param>
4353
/// <param name="reloadOnChange">自动更新</param>
4454
/// <returns></returns>
4555
public T Get<T>(string fileName, string environmentName = "", bool reloadOnChange = false)
@@ -50,5 +60,21 @@ public T Get<T>(string fileName, string environmentName = "", bool reloadOnChang
5060

5161
return configuration.Get<T>();
5262
}
63+
64+
/// <summary>
65+
/// 绑定实例配置信息
66+
/// </summary>
67+
/// <param name="fileName">文件名称</param>
68+
/// <param name="instance">实例配置</param>
69+
/// <param name="environmentName">环境名称</param>
70+
/// <param name="reloadOnChange">自动更新</param>
71+
public void Bind(string fileName, object instance, string environmentName = "", bool reloadOnChange = false)
72+
{
73+
var configuration = Load(fileName, environmentName, reloadOnChange);
74+
if (configuration == null)
75+
return;
76+
77+
configuration.Bind(instance);
78+
}
5379
}
5480
}
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
using System;
2+
3+
namespace Admin.Core.Common.Helpers
4+
{
5+
public class Snowfake
6+
{
7+
public static Snowfake Default { get; } = new Snowfake(0);
8+
9+
//机器ID
10+
private static long workerId;
11+
private static long twepoch = 687888001020L; //唯一时间,这是一个避免重复的随机量,自行设定不要大于当前时间戳
12+
private static long sequence = 0L;
13+
private static int workerIdBits = 4; //机器码字节数。4个字节用来保存机器码(定义为Long类型会出现,最大偏移64位,所以左移64位没有意义)
14+
public static long maxWorkerId = -1L ^ -1L << workerIdBits; //最大机器ID
15+
private static int sequenceBits = 10; //计数器字节数,10个字节用来保存计数码
16+
private static int workerIdShift = sequenceBits; //机器码数据左移位数,就是后面计数器占用的位数
17+
private static int timestampLeftShift = sequenceBits + workerIdBits; //时间戳左移动位数就是机器码和计数器总字节数
18+
public static long sequenceMask = -1L ^ -1L << sequenceBits; //一微秒内可以产生计数,如果达到该值则等到下一微妙在进行生成
19+
private long lastTimestamp = -1L;
20+
21+
/// <summary>
22+
/// 机器码
23+
/// </summary>
24+
/// <param name="workerId"></param>
25+
public Snowfake(long workerId)
26+
{
27+
if (workerId > maxWorkerId || workerId < 0)
28+
throw new Exception(string.Format("worker Id can't be greater than {0} or less than 0 ", workerId));
29+
Snowfake.workerId = workerId;
30+
}
31+
32+
public long nextId()
33+
{
34+
lock (this)
35+
{
36+
long timestamp = timeGen();
37+
if (lastTimestamp == timestamp)
38+
{ //同一微妙中生成ID
39+
sequence = (sequence + 1) & sequenceMask; //用&运算计算该微秒内产生的计数是否已经到达上限
40+
if (sequence == 0)
41+
{
42+
//一微妙内产生的ID计数已达上限,等待下一微妙
43+
timestamp = tillNextMillis(lastTimestamp);
44+
}
45+
}
46+
else
47+
{ //不同微秒生成ID
48+
sequence = 0; //计数清0
49+
}
50+
if (timestamp < lastTimestamp)
51+
{ //如果当前时间戳比上一次生成ID时时间戳还小,抛出异常,因为不能保证现在生成的ID之前没有生成过
52+
throw new Exception(string.Format("Clock moved backwards. Refusing to generate id for {0} milliseconds",
53+
lastTimestamp - timestamp));
54+
}
55+
lastTimestamp = timestamp; //把当前时间戳保存为最后生成ID的时间戳
56+
long nextId = (timestamp - twepoch << timestampLeftShift) | workerId << workerIdShift | sequence;
57+
return nextId;
58+
}
59+
}
60+
61+
/// <summary>
62+
/// 获取下一微秒时间戳
63+
/// </summary>
64+
/// <param name="lastTimestamp"></param>
65+
/// <returns></returns>
66+
private long tillNextMillis(long lastTimestamp)
67+
{
68+
long timestamp = timeGen();
69+
while (timestamp <= lastTimestamp)
70+
{
71+
timestamp = timeGen();
72+
}
73+
return timestamp;
74+
}
75+
76+
/// <summary>
77+
/// 生成当前时间戳
78+
/// </summary>
79+
/// <returns></returns>
80+
private long timeGen()
81+
{
82+
return (long)(DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc)).TotalMilliseconds;
83+
}
84+
}
85+
}

Admin.Core.Model/Admin/ApiEntity.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,31 +19,31 @@ public class ApiEntity : EntityBase
1919
/// <summary>
2020
/// 接口命名
2121
/// </summary>
22-
[MaxLength(50)]
22+
[Column(StringLength = 50)]
2323
public string Name { get; set; }
2424

2525
/// <summary>
2626
/// 接口名称
2727
/// </summary>
28-
[MaxLength(500)]
28+
[Column(StringLength = 500)]
2929
public string Label { get; set; }
3030

3131
/// <summary>
3232
/// 接口地址
3333
/// </summary>
34-
[MaxLength(500)]
34+
[Column(StringLength = 500)]
3535
public string Path { get; set; }
3636

3737
/// <summary>
3838
/// 接口提交方法
3939
/// </summary>
40-
[MaxLength(50)]
40+
[Column(StringLength = 50)]
4141
public string HttpMethods { get; set; }
4242

4343
/// <summary>
4444
/// 说明
4545
/// </summary>
46-
[MaxLength(500)]
46+
[Column(StringLength = 500)]
4747
public string Description { get; set; }
4848

4949
/// <summary>

Admin.Core.Model/Admin/DictionaryEntity.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ namespace Admin.Core.Model.Admin
77
/// 数据字典
88
/// </summary>
99
[Table(Name = "ad_dictionary")]
10-
[Index("uk_role_parentid_name", nameof(ParentId)+","+nameof(Name), true)]
10+
[Index("uk_dictionary_parentid_name", nameof(ParentId)+","+nameof(Name), true)]
1111
public class DictionaryEntity: EntityBase
1212
{
1313
/// <summary>
@@ -18,19 +18,19 @@ public class DictionaryEntity: EntityBase
1818
/// <summary>
1919
/// 字典名称
2020
/// </summary>
21-
[MaxLength(50)]
21+
[Column(StringLength = 50)]
2222
public string Name { get; set; }
2323

2424
/// <summary>
2525
/// 字典编码
2626
/// </summary>
27-
[MaxLength(50)]
27+
[Column(StringLength = 50)]
2828
public string Code { get; set; }
2929

3030
/// <summary>
3131
/// 字典值
3232
/// </summary>
33-
[MaxLength(50)]
33+
[Column(StringLength = 50)]
3434
public string Value { get; set; }
3535

3636
/// <summary>

0 commit comments

Comments
 (0)