更新项目配置,新增设备同步模块,优化WebSocket和Swagger配置,增强SCADA系统的免登录接口,支持数据字典项和登录日志的免登录查询与记录。调整Java编译设置,确保更好的开发体验。
This commit is contained in:
@@ -0,0 +1,48 @@
|
||||
using SqlSugar;
|
||||
|
||||
namespace YY.Admin.Infrastructure.Storage;
|
||||
|
||||
public class TokenStore
|
||||
{
|
||||
private const string TokenKey = "DeviceToken";
|
||||
private readonly ISqlSugarClient _db;
|
||||
|
||||
public TokenStore(ISqlSugarClient db)
|
||||
{
|
||||
_db = db;
|
||||
}
|
||||
|
||||
public async Task UpdateTokenAsync(string token, CancellationToken cancellationToken = default)
|
||||
{
|
||||
var value = token ?? string.Empty;
|
||||
await EnsureTableAsync(cancellationToken).ConfigureAwait(false);
|
||||
var sql = "INSERT INTO app_config(config_key,config_value,updated_at) VALUES(@key,@val,@ts) " +
|
||||
"ON CONFLICT(config_key) DO UPDATE SET config_value=@val, updated_at=@ts;";
|
||||
var now = DateTime.UtcNow.ToString("yyyy-MM-dd HH:mm:ss");
|
||||
await _db.Ado.ExecuteCommandAsync(sql, new[]
|
||||
{
|
||||
new SugarParameter("@key", TokenKey),
|
||||
new SugarParameter("@val", value),
|
||||
new SugarParameter("@ts", now)
|
||||
}).ConfigureAwait(false);
|
||||
_ = cancellationToken;
|
||||
}
|
||||
|
||||
public async Task<string> GetTokenAsync(CancellationToken cancellationToken = default)
|
||||
{
|
||||
await EnsureTableAsync(cancellationToken).ConfigureAwait(false);
|
||||
var sql = "SELECT config_value FROM app_config WHERE config_key=@key LIMIT 1;";
|
||||
var token = await _db.Ado.GetStringAsync(sql, new[] { new SugarParameter("@key", TokenKey) }).ConfigureAwait(false);
|
||||
return token ?? string.Empty;
|
||||
}
|
||||
|
||||
private async Task EnsureTableAsync(CancellationToken cancellationToken)
|
||||
{
|
||||
const string sql = "CREATE TABLE IF NOT EXISTS app_config(" +
|
||||
"config_key TEXT PRIMARY KEY," +
|
||||
"config_value TEXT NULL," +
|
||||
"updated_at TEXT NULL);";
|
||||
await _db.Ado.ExecuteCommandAsync(sql).ConfigureAwait(false);
|
||||
_ = cancellationToken;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user