添加兼容旧库的桌面端登录设置配置项,确保在缺失时自动补全相关 sys_config 项

This commit is contained in:
geht
2026-05-20 12:29:10 +08:00
parent e5e8341b3e
commit 27c2ed898c
2 changed files with 79 additions and 1 deletions

View File

@@ -1,6 +1,7 @@
using SqlSugar;
using YY.Admin.Core;
using YY.Admin.Core.Const;
using YY.Admin.Core.SeedData;
namespace YY.Admin.Services.Service.Config
{
@@ -41,7 +42,28 @@ namespace YY.Admin.Services.Service.Config
.ExecuteCommandAsync();
if (n <= 0)
return (false, "未找到对应配置项或无需更新");
{
// 旧库可能缺少新增配置项,按种子模板补插后再写入
var seed = new SysConfigSeedData().HasData()
.FirstOrDefault(c => string.Equals(c.Code, code, StringComparison.OrdinalIgnoreCase));
if (seed == null)
return (false, "未找到对应配置项或无需更新");
var row = new SysConfig
{
Id = seed.Id,
Name = seed.Name,
Code = seed.Code,
Value = value,
SysFlag = seed.SysFlag,
GroupCode = seed.GroupCode,
OrderNo = seed.OrderNo,
Remark = seed.Remark,
CreateTime = DateTime.Now,
UpdateTime = DateTime.Now,
};
await _dbContext.Insertable(row).ExecuteCommandAsync();
}
_sysCacheService.Remove($"{CacheConst.KeyConfig}{code}");
return (true, "保存成功");