😎修复通知公告存在逻辑错误
This commit is contained in:
parent
7fec044b16
commit
66faf5c493
@ -40,12 +40,12 @@
|
||||
<PackageReference Include="RabbitMQ.Client" Version="6.8.1" />
|
||||
<PackageReference Include="SixLabors.ImageSharp.Web" Version="3.1.2" />
|
||||
<PackageReference Include="SkiaSharp.NativeAssets.Linux.NoDependencies" Version="2.88.8" />
|
||||
<PackageReference Include="SKIT.FlurlHttpClient.Wechat.Api" Version="3.5.0" />
|
||||
<PackageReference Include="SKIT.FlurlHttpClient.Wechat.Api" Version="3.6.0" />
|
||||
<PackageReference Include="SKIT.FlurlHttpClient.Wechat.TenpayV3" Version="3.8.0" />
|
||||
<PackageReference Include="SqlSugarCore" Version="5.1.4.170" />
|
||||
<PackageReference Include="SSH.NET" Version="2024.1.0" />
|
||||
<PackageReference Include="System.Linq.Dynamic.Core" Version="1.4.8" />
|
||||
<PackageReference Include="TencentCloudSDK.Sms" Version="3.0.1116" />
|
||||
<PackageReference Include="TencentCloudSDK.Sms" Version="3.0.1117" />
|
||||
<PackageReference Include="UAParser" Version="3.1.47" />
|
||||
<PackageReference Include="Yitter.IdGenerator" Version="1.0.14" />
|
||||
</ItemGroup>
|
||||
|
||||
@ -110,7 +110,7 @@ public enum ErrorCodeEnum
|
||||
D1012,
|
||||
|
||||
/// <summary>
|
||||
/// 所属机构不在自己的数据范围内
|
||||
/// 没有权限操作该数据
|
||||
/// </summary>
|
||||
[ErrorCodeItemMetadata("没有权限操作该数据")]
|
||||
D1013,
|
||||
|
||||
@ -72,6 +72,9 @@ public class SysNoticeService : IDynamicApiController, ITransient
|
||||
[DisplayName("更新通知公告")]
|
||||
public async Task UpdateNotice(UpdateNoticeInput input)
|
||||
{
|
||||
if (input.CreateUserId != _userManager.UserId)
|
||||
throw Oops.Oh(ErrorCodeEnum.D7003);
|
||||
|
||||
var notice = input.Adapt<SysNotice>();
|
||||
InitNoticeInfo(notice);
|
||||
await _sysNoticeRep.UpdateAsync(notice);
|
||||
@ -87,6 +90,12 @@ public class SysNoticeService : IDynamicApiController, ITransient
|
||||
[DisplayName("删除通知公告")]
|
||||
public async Task DeleteNotice(DeleteNoticeInput input)
|
||||
{
|
||||
var sysNotice = await _sysNoticeRep.GetByIdAsync(input.Id);
|
||||
if (sysNotice.CreateUserId != _userManager.UserId)
|
||||
throw Oops.Oh(ErrorCodeEnum.D7003);
|
||||
if (sysNotice.Status == NoticeStatusEnum.PUBLIC)
|
||||
throw Oops.Oh(ErrorCodeEnum.D7001);
|
||||
|
||||
await _sysNoticeRep.DeleteAsync(u => u.Id == input.Id);
|
||||
|
||||
await _sysNoticeUserRep.DeleteAsync(u => u.NoticeId == input.Id);
|
||||
@ -100,6 +109,9 @@ public class SysNoticeService : IDynamicApiController, ITransient
|
||||
[DisplayName("发布通知公告")]
|
||||
public async Task Public(NoticeInput input)
|
||||
{
|
||||
if (!(await _sysNoticeRep.IsAnyAsync(u => u.Id == input.Id && u.CreateUserId == _userManager.UserId)))
|
||||
throw Oops.Oh(ErrorCodeEnum.D7003);
|
||||
|
||||
// 更新发布状态和时间
|
||||
await _sysNoticeRep.UpdateAsync(u => new SysNotice() { Status = NoticeStatusEnum.PUBLIC, PublicTime = DateTime.Now }, u => u.Id == input.Id);
|
||||
|
||||
|
||||
@ -4,11 +4,8 @@
|
||||
//
|
||||
// 不得利用本项目从事危害国家安全、扰乱社会秩序、侵犯他人合法权益等法律法规禁止的活动!任何基于本项目二次开发而产生的一切法律纠纷和责任,我们不承担任何责任!
|
||||
|
||||
using Newtonsoft.Json;
|
||||
using System.Security.Cryptography;
|
||||
namespace Admin.NET.Core;
|
||||
|
||||
|
||||
public static class SqlSugarSetup
|
||||
{
|
||||
// 多租户实例
|
||||
@ -338,17 +335,14 @@ public static class SqlSugarSetup
|
||||
entityTypes = entityTypes.Where(u => u.GetCustomAttribute<TenantAttribute>()?.configId.ToString() == config.ConfigId.ToString()).ToList(); // 自定义的库
|
||||
|
||||
int count = 0, sum = entityTypes.Count;
|
||||
TableUpdateCheck.Single(config.ConnectionString, entityTypes).TryUpdate(() =>
|
||||
foreach (var entityType in entityTypes)
|
||||
{
|
||||
foreach (var entityType in entityTypes)
|
||||
{
|
||||
Console.WriteLine($"创建表 {entityType} ({config.ConfigId} - {++count}/{sum})");
|
||||
if (entityType.GetCustomAttribute<SplitTableAttribute>() == null)
|
||||
dbProvider.CodeFirst.InitTables(entityType);
|
||||
else
|
||||
dbProvider.CodeFirst.SplitTables().InitTables(entityType);
|
||||
}
|
||||
});
|
||||
Console.WriteLine($"创建表 {entityType} ({config.ConfigId} - {++count}/{sum})");
|
||||
if (entityType.GetCustomAttribute<SplitTableAttribute>() == null)
|
||||
dbProvider.CodeFirst.InitTables(entityType);
|
||||
else
|
||||
dbProvider.CodeFirst.SplitTables().InitTables(entityType);
|
||||
}
|
||||
}
|
||||
|
||||
// 初始化种子数据
|
||||
@ -545,124 +539,4 @@ public static class SqlSugarSetup
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
public class TableUpdateCheck
|
||||
{
|
||||
public TableUpdateCheck(string sqlConnectionStr = null, List<Type> tableList = null)
|
||||
{
|
||||
this._sqlConnectionStr = sqlConnectionStr;
|
||||
this._tableList = tableList ?? new List<Type>();
|
||||
}
|
||||
|
||||
public string TableName { get; set; }
|
||||
public List<Attribute> AttributeList { get; set; } = new List<Attribute>();
|
||||
|
||||
public List<TableInfColumnM> ColumnList = new List<TableInfColumnM>();
|
||||
|
||||
public class TableInfColumnM
|
||||
{
|
||||
public string ColumnName { get; set; }
|
||||
public List<Attribute> AttributeList { get; set; } = new List<Attribute>();
|
||||
}
|
||||
[JsonIgnore] public List<TableUpdateCheck> ConfigList { get; set; } = new List<TableUpdateCheck>();
|
||||
|
||||
[JsonIgnore] private string _sqlConnectionStr;
|
||||
[JsonIgnore] private string _configFilePath = null;
|
||||
[JsonIgnore]
|
||||
public string ConfigFilePath => _configFilePath ??= _configFilePath =
|
||||
Path.Combine(System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase, @"TableHash\" + calculateHasByStr(calculateHasByStr(_sqlConnectionStr) + "0a") + ".bin");
|
||||
[JsonIgnore] private List<Type> _tableList { get; set; } = null;
|
||||
|
||||
[JsonIgnore] private string _tableHashStr;
|
||||
[JsonIgnore] public string TableHashStr => _tableHashStr ??= _tableHashStr = _tableList.Select(t => Parse(t).ToHash()).Aggregate((a, b) => a + "," + b);
|
||||
|
||||
public bool TryUpdate(Action updateAction)
|
||||
{
|
||||
if (CheckUpdateTable())
|
||||
{
|
||||
updateAction?.Invoke();
|
||||
UpdateTableFinish();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public void UpdateTableFinish()
|
||||
{
|
||||
Directory.CreateDirectory(Path.GetDirectoryName(ConfigFilePath));
|
||||
File.WriteAllText(ConfigFilePath, TableHashStr);
|
||||
}
|
||||
|
||||
public bool CheckUpdateTable()
|
||||
{
|
||||
try
|
||||
{
|
||||
if (!File.Exists(ConfigFilePath))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
var oldHashStr = File.ReadAllText(ConfigFilePath);
|
||||
if (oldHashStr != TableHashStr)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static TableUpdateCheck Parse(Type type)
|
||||
{
|
||||
TableUpdateCheck table = new TableUpdateCheck() { TableName = type.FullName };
|
||||
table.AttributeList = type.GetAttributes<Attribute>(true).ToList();
|
||||
var propertyList = type.GetProperties().Where(t => t.PropertyType.IsPrimitive || t.PropertyType == typeof(string)).ToList();
|
||||
table.ColumnList = propertyList.Select(t => new TableInfColumnM()
|
||||
{
|
||||
ColumnName = t.Name + t.PropertyType.Name,
|
||||
AttributeList = t.GetAttributes<Attribute>(true).ToList(),
|
||||
}).ToList();
|
||||
return table;
|
||||
}
|
||||
|
||||
|
||||
public static TableUpdateCheck Single(string sqlConnectionStr, List<Type> tableList) => new TableUpdateCheck(sqlConnectionStr, tableList);
|
||||
|
||||
public static void CheckUpdateTableFinish(string sqlConnectionStr, IEnumerable<Type> types)
|
||||
{
|
||||
var basePath = System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase;
|
||||
string filePath = Path.Combine(basePath, @"TableHash\" + calculateHasByStr(calculateHasByStr(sqlConnectionStr) + "0a") + ".bin");
|
||||
Directory.CreateDirectory(Path.GetDirectoryName(filePath));
|
||||
var newHashStr = types.Select(t => Parse(t).ToHash()).Aggregate((a, b) => a + "," + b);
|
||||
File.WriteAllText(filePath, newHashStr);
|
||||
}
|
||||
|
||||
public string ToHash()
|
||||
{
|
||||
var js = JsonConvert.SerializeObject(this);
|
||||
var md5 = calculateHasByStr(js);
|
||||
return md5;
|
||||
}
|
||||
|
||||
private static string calculateHasByStr(string str)
|
||||
{
|
||||
using (MD5 md5 = MD5.Create())
|
||||
{
|
||||
byte[] inputBytes = Encoding.UTF8.GetBytes(str);
|
||||
byte[] hashBytes = md5.ComputeHash(inputBytes);
|
||||
|
||||
// 将字节数组转换为十六进制字符串表示的哈希值
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (int i = 0; i < hashBytes.Length; i++)
|
||||
{
|
||||
sb.Append(hashBytes[i].ToString("x2"));
|
||||
}
|
||||
string hash = sb.ToString();
|
||||
return hash;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user