parent
bc9e1a8e11
commit
063d8818f6
|
|
@ -57,6 +57,15 @@ namespace OpenAuth.Repository.Domain
|
||||||
/// AI巡检
|
/// AI巡检
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string AIInspection { get; set; }
|
public string AIInspection { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 状态
|
||||||
|
/// </summary>
|
||||||
|
public int Status { get; set; }
|
||||||
|
/// <summary>
|
||||||
|
/// 周期公式
|
||||||
|
/// </summary>
|
||||||
|
public string PeriodicFormula { get; set; }
|
||||||
|
|
||||||
public long CreateId { get; set; }
|
public long CreateId { get; set; }
|
||||||
public DateTime? CreateTime { get; set; }
|
public DateTime? CreateTime { get; set; }
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,7 @@
|
||||||
using Infrastructure;
|
using System.Text;
|
||||||
|
using Infrastructure;
|
||||||
using Infrastructure.Extensions;
|
using Infrastructure.Extensions;
|
||||||
|
using Infrastructure.Helpers;
|
||||||
using Microsoft.AspNetCore.Authorization;
|
using Microsoft.AspNetCore.Authorization;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using OpenAuth.App.ServiceApp;
|
using OpenAuth.App.ServiceApp;
|
||||||
|
|
@ -15,11 +17,16 @@ namespace OpenAuth.WebApi.Controllers.ServiceControllers
|
||||||
public class ManageController : ControllerBase
|
public class ManageController : ControllerBase
|
||||||
{
|
{
|
||||||
private readonly ManageApp _app;
|
private readonly ManageApp _app;
|
||||||
public ManageController(ManageApp app)
|
private readonly MqttClientManager _mqttClientManager;
|
||||||
|
|
||||||
|
public ManageController(ManageApp app, MqttClientManager mqttClientManager)
|
||||||
{
|
{
|
||||||
_app = app;
|
_app = app;
|
||||||
|
_mqttClientManager = mqttClientManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
#region 机场管理
|
#region 机场管理
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 获取机场列表
|
/// 获取机场列表
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
@ -40,11 +47,14 @@ namespace OpenAuth.WebApi.Controllers.ServiceControllers
|
||||||
result.Code = 500;
|
result.Code = 500;
|
||||||
result.Message = ex.Message;
|
result.Message = ex.Message;
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region 无人机管理
|
#region 无人机管理
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 获取无人机列表
|
/// 获取无人机列表
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
@ -65,11 +75,14 @@ namespace OpenAuth.WebApi.Controllers.ServiceControllers
|
||||||
result.Code = 500;
|
result.Code = 500;
|
||||||
result.Message = ex.Message;
|
result.Message = ex.Message;
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region 任务管理
|
#region 任务管理
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 获取任务列表
|
/// 获取任务列表
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
@ -90,6 +103,7 @@ namespace OpenAuth.WebApi.Controllers.ServiceControllers
|
||||||
result.Code = 500;
|
result.Code = 500;
|
||||||
result.Message = ex.Message;
|
result.Message = ex.Message;
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -102,6 +116,7 @@ namespace OpenAuth.WebApi.Controllers.ServiceControllers
|
||||||
{
|
{
|
||||||
return await _app.AddTask(info);
|
return await _app.AddTask(info);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 编辑任务
|
/// 编辑任务
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
@ -111,6 +126,7 @@ namespace OpenAuth.WebApi.Controllers.ServiceControllers
|
||||||
{
|
{
|
||||||
return await _app.EditTask(info);
|
return await _app.EditTask(info);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 删除任务
|
/// 删除任务
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
@ -120,9 +136,11 @@ namespace OpenAuth.WebApi.Controllers.ServiceControllers
|
||||||
{
|
{
|
||||||
return await _app.DeleteTask(id);
|
return await _app.DeleteTask(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region 航线管理
|
#region 航线管理
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 获取航线列表
|
/// 获取航线列表
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
@ -143,6 +161,7 @@ namespace OpenAuth.WebApi.Controllers.ServiceControllers
|
||||||
result.Code = 500;
|
result.Code = 500;
|
||||||
result.Message = ex.Message;
|
result.Message = ex.Message;
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -155,6 +174,7 @@ namespace OpenAuth.WebApi.Controllers.ServiceControllers
|
||||||
{
|
{
|
||||||
return await _app.AddAirLine(info);
|
return await _app.AddAirLine(info);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 编辑航线
|
/// 编辑航线
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
@ -164,6 +184,7 @@ namespace OpenAuth.WebApi.Controllers.ServiceControllers
|
||||||
{
|
{
|
||||||
return await _app.EditAirLine(info);
|
return await _app.EditAirLine(info);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 删除航线
|
/// 删除航线
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
@ -173,6 +194,7 @@ namespace OpenAuth.WebApi.Controllers.ServiceControllers
|
||||||
{
|
{
|
||||||
return await _app.DeleteAirLine(id);
|
return await _app.DeleteAirLine(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 上传航线文件
|
/// 上传航线文件
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
@ -197,6 +219,7 @@ namespace OpenAuth.WebApi.Controllers.ServiceControllers
|
||||||
|
|
||||||
return Ok(new { message = "上传成功", path = filePath });
|
return Ok(new { message = "上传成功", path = filePath });
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpPost("uploadwpmlfile")]
|
[HttpPost("uploadwpmlfile")]
|
||||||
[AllowAnonymous]
|
[AllowAnonymous]
|
||||||
public async Task<IActionResult> UploadWpmlFile(IFormFile xmlFile, string id)
|
public async Task<IActionResult> UploadWpmlFile(IFormFile xmlFile, string id)
|
||||||
|
|
@ -217,9 +240,11 @@ namespace OpenAuth.WebApi.Controllers.ServiceControllers
|
||||||
|
|
||||||
return Ok(new { message = "上传成功", path = filePath });
|
return Ok(new { message = "上传成功", path = filePath });
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region 项目管理
|
#region 项目管理
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 获取项目列表
|
/// 获取项目列表
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
@ -238,6 +263,7 @@ namespace OpenAuth.WebApi.Controllers.ServiceControllers
|
||||||
result.Code = 500;
|
result.Code = 500;
|
||||||
result.Message = ex.Message;
|
result.Message = ex.Message;
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -250,6 +276,7 @@ namespace OpenAuth.WebApi.Controllers.ServiceControllers
|
||||||
{
|
{
|
||||||
return await _app.AddWorkspace(info);
|
return await _app.AddWorkspace(info);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 编辑项目
|
/// 编辑项目
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
@ -259,6 +286,7 @@ namespace OpenAuth.WebApi.Controllers.ServiceControllers
|
||||||
{
|
{
|
||||||
return await _app.EditWorkspace(info);
|
return await _app.EditWorkspace(info);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 删除项目
|
/// 删除项目
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
@ -268,6 +296,22 @@ namespace OpenAuth.WebApi.Controllers.ServiceControllers
|
||||||
{
|
{
|
||||||
return await _app.DeleteWorkspace(id);
|
return await _app.DeleteWorkspace(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
// 航线任务在云端的 共享查看、下发执行、取消以及进度上报等功能。
|
||||||
|
|
||||||
|
[HttpGet]
|
||||||
|
[AllowAnonymous]
|
||||||
|
public async Task Test()
|
||||||
|
{
|
||||||
|
await _mqttClientManager.SubscribeAsync("thing/product/8UUXN5400A079H/osd", async (args) =>
|
||||||
|
{
|
||||||
|
var payload = args.ApplicationMessage.Payload;
|
||||||
|
var message = Encoding.UTF8.GetString(payload);
|
||||||
|
Console.WriteLine($"收到主题 [{args.ApplicationMessage.Topic}] 的消息: {message}");
|
||||||
|
await Task.CompletedTask; // 可选:实际逻辑中可执行更多异步操作
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -0,0 +1,68 @@
|
||||||
|
using MQTTnet;
|
||||||
|
using MQTTnet.Client;
|
||||||
|
using MQTTnet.Protocol;
|
||||||
|
|
||||||
|
namespace OpenAuth.WebApi;
|
||||||
|
|
||||||
|
public class MqttClientManager
|
||||||
|
{
|
||||||
|
private IMqttClient _mqttClient;
|
||||||
|
|
||||||
|
public MqttClientManager()
|
||||||
|
{
|
||||||
|
var mqttFactory = new MqttFactory();
|
||||||
|
_mqttClient = mqttFactory.CreateMqttClient();
|
||||||
|
// 创建配置构建器
|
||||||
|
var builder = new ConfigurationBuilder()
|
||||||
|
.SetBasePath(Directory.GetCurrentDirectory())
|
||||||
|
.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)
|
||||||
|
.AddJsonFile(
|
||||||
|
$"appsettings.{Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT") ?? "Development"}.json",
|
||||||
|
optional: true)
|
||||||
|
.AddEnvironmentVariables();
|
||||||
|
// 构建配置
|
||||||
|
var configuration = builder.Build();
|
||||||
|
// 读取连接字符串
|
||||||
|
var serverIp = configuration["MQTT:Server"];
|
||||||
|
var port = configuration["MQTT:Port"];
|
||||||
|
var username = configuration["MQTT:UserName"];
|
||||||
|
var password = configuration["MQTT:Password"];
|
||||||
|
ConnectAsync(serverIp, int.Parse(port), username, password).Wait();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="server"></param>
|
||||||
|
/// <param name="port"></param>
|
||||||
|
/// <param name="username"></param>
|
||||||
|
/// <param name="password"></param>
|
||||||
|
public async Task ConnectAsync(string server, int port, string username = null, string password = null)
|
||||||
|
{
|
||||||
|
var mqttClientOptions = new MqttClientOptionsBuilder()
|
||||||
|
.WithClientId("client001")
|
||||||
|
.WithTcpServer(server, port)
|
||||||
|
.WithCredentials(username, password)
|
||||||
|
.Build();
|
||||||
|
|
||||||
|
await _mqttClient.ConnectAsync(mqttClientOptions, CancellationToken.None);
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task SubscribeAsync(string topic,
|
||||||
|
Func<MqttApplicationMessageReceivedEventArgs, Task> handler)
|
||||||
|
{
|
||||||
|
await _mqttClient.SubscribeAsync(topic, MqttQualityOfServiceLevel.AtLeastOnce, CancellationToken.None);
|
||||||
|
_mqttClient.ApplicationMessageReceivedAsync += handler;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public async Task PublishAsync(string topic, string message)
|
||||||
|
{
|
||||||
|
var mqttMsg = new MqttApplicationMessageBuilder()
|
||||||
|
.WithTopic(topic)
|
||||||
|
.WithPayload(message)
|
||||||
|
.WithQualityOfServiceLevel(MqttQualityOfServiceLevel.AtLeastOnce)
|
||||||
|
.Build();
|
||||||
|
await _mqttClient.PublishAsync(mqttMsg, CancellationToken.None);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -26,7 +26,6 @@ using SqlSugar;
|
||||||
using Swashbuckle.AspNetCore.SwaggerUI;
|
using Swashbuckle.AspNetCore.SwaggerUI;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
namespace OpenAuth.WebApi
|
namespace OpenAuth.WebApi
|
||||||
{
|
{
|
||||||
public class Startup
|
public class Startup
|
||||||
|
|
@ -46,7 +45,10 @@ namespace OpenAuth.WebApi
|
||||||
public void ConfigureServices(IServiceCollection services)
|
public void ConfigureServices(IServiceCollection services)
|
||||||
{
|
{
|
||||||
services.AddHttpContextAccessor();
|
services.AddHttpContextAccessor();
|
||||||
|
services.AddSingleton<MqttClientManager>(provider => new MqttClientManager());
|
||||||
|
|
||||||
#region log4net
|
#region log4net
|
||||||
|
|
||||||
//在startup中需要强制创建log4net
|
//在startup中需要强制创建log4net
|
||||||
//var loggerFactory = LoggerFactory.Create(builder => { builder.AddLog4Net(); });
|
//var loggerFactory = LoggerFactory.Create(builder => { builder.AddLog4Net(); });
|
||||||
//ILogger logger = loggerFactory.CreateLogger<Startup>();
|
//ILogger logger = loggerFactory.CreateLogger<Startup>();
|
||||||
|
|
@ -56,9 +58,11 @@ namespace OpenAuth.WebApi
|
||||||
loggingBuilder.ClearProviders();
|
loggingBuilder.ClearProviders();
|
||||||
loggingBuilder.AddLog4Net();
|
loggingBuilder.AddLog4Net();
|
||||||
});
|
});
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region identityServer
|
#region identityServer
|
||||||
|
|
||||||
var identityServer =
|
var identityServer =
|
||||||
((ConfigurationSection)Configuration.GetSection("AppSetting:IdentityServerUrl")).Value;
|
((ConfigurationSection)Configuration.GetSection("AppSetting:IdentityServerUrl")).Value;
|
||||||
if (!string.IsNullOrEmpty(identityServer))
|
if (!string.IsNullOrEmpty(identityServer))
|
||||||
|
|
@ -73,9 +77,11 @@ namespace OpenAuth.WebApi
|
||||||
options.Audience = "openauthapi";
|
options.Audience = "openauthapi";
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region MiniProfiler
|
#region MiniProfiler
|
||||||
|
|
||||||
// 添加MiniProfiler服务
|
// 添加MiniProfiler服务
|
||||||
//services.AddMiniProfiler(options =>
|
//services.AddMiniProfiler(options =>
|
||||||
//{
|
//{
|
||||||
|
|
@ -89,13 +95,16 @@ namespace OpenAuth.WebApi
|
||||||
// options.SqlFormatter = new StackExchange.Profiling.SqlFormatters.InlineFormatter();
|
// options.SqlFormatter = new StackExchange.Profiling.SqlFormatters.InlineFormatter();
|
||||||
// // options.IgnoredPaths.Add("/swagger/");
|
// // options.IgnoredPaths.Add("/swagger/");
|
||||||
//}).AddEntityFramework(); //显示SQL语句及耗时
|
//}).AddEntityFramework(); //显示SQL语句及耗时
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region swagger
|
#region swagger
|
||||||
|
|
||||||
//添加swagger
|
//添加swagger
|
||||||
services.AddSwaggerGen(option =>
|
services.AddSwaggerGen(option =>
|
||||||
{
|
{
|
||||||
#region 注释
|
#region 注释
|
||||||
|
|
||||||
//foreach (var controller in GetControllers())
|
//foreach (var controller in GetControllers())
|
||||||
//{
|
//{
|
||||||
// var groupname = GetSwaggerGroupName(controller);
|
// var groupname = GetSwaggerGroupName(controller);
|
||||||
|
|
@ -114,7 +123,9 @@ namespace OpenAuth.WebApi
|
||||||
// option.IncludeXmlComments(name, includeControllerXmlComments: true);
|
// option.IncludeXmlComments(name, includeControllerXmlComments: true);
|
||||||
|
|
||||||
//}
|
//}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
option.CustomSchemaIds(type => type.FullName);
|
option.CustomSchemaIds(type => type.FullName);
|
||||||
option.SwaggerDoc("v1", new OpenApiInfo
|
option.SwaggerDoc("v1", new OpenApiInfo
|
||||||
{
|
{
|
||||||
|
|
@ -147,33 +158,35 @@ namespace OpenAuth.WebApi
|
||||||
|
|
||||||
// option.OperationFilter<GlobalHttpHeaderOperationFilter>(); // 添加httpHeader参数
|
// option.OperationFilter<GlobalHttpHeaderOperationFilter>(); // 添加httpHeader参数
|
||||||
//});
|
//});
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region AppSetting
|
#region AppSetting
|
||||||
|
|
||||||
services.Configure<AppSetting>(Configuration.GetSection("AppSetting"));
|
services.Configure<AppSetting>(Configuration.GetSection("AppSetting"));
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region 限制文件大小
|
#region 限制文件大小
|
||||||
services.Configure<KestrelServerOptions>(options =>
|
|
||||||
{
|
services.Configure<KestrelServerOptions>(options => { options.Limits.MaxRequestBodySize = long.MaxValue; });
|
||||||
options.Limits.MaxRequestBodySize = long.MaxValue;
|
|
||||||
});
|
|
||||||
services.Configure<FormOptions>(x =>
|
services.Configure<FormOptions>(x =>
|
||||||
{
|
{
|
||||||
x.ValueLengthLimit = int.MaxValue;
|
x.ValueLengthLimit = int.MaxValue;
|
||||||
x.MultipartBodyLengthLimit = long.MaxValue;
|
x.MultipartBodyLengthLimit = long.MaxValue;
|
||||||
x.MemoryBufferThreshold = int.MaxValue;
|
x.MemoryBufferThreshold = int.MaxValue;
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Controllers
|
#region Controllers
|
||||||
|
|
||||||
services.AddControllers(option =>
|
services.AddControllers(option =>
|
||||||
{
|
{
|
||||||
option.Filters.Add<OpenAuthFilter>();
|
option.Filters.Add<OpenAuthFilter>();
|
||||||
//option.Filters.Add<TransactionFilter>();
|
//option.Filters.Add<TransactionFilter>();
|
||||||
//option.Filters.Add<GlobalExceptionFilter>();
|
//option.Filters.Add<GlobalExceptionFilter>();
|
||||||
})
|
})
|
||||||
.ConfigureApiBehaviorOptions(options =>
|
.ConfigureApiBehaviorOptions(options =>
|
||||||
{
|
{
|
||||||
// 禁用自动模态验证
|
// 禁用自动模态验证
|
||||||
|
|
@ -194,10 +207,13 @@ namespace OpenAuth.WebApi
|
||||||
//options.SerializerSettings.ContractResolver = new DefaultContractResolver();
|
//options.SerializerSettings.ContractResolver = new DefaultContractResolver();
|
||||||
options.SerializerSettings.DateFormatString = "yyyy-MM-dd HH:mm:ss";
|
options.SerializerSettings.DateFormatString = "yyyy-MM-dd HH:mm:ss";
|
||||||
});
|
});
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region MemoryCache
|
#region MemoryCache
|
||||||
|
|
||||||
services.AddMemoryCache();
|
services.AddMemoryCache();
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Cors
|
#region Cors
|
||||||
|
|
@ -213,89 +229,98 @@ namespace OpenAuth.WebApi
|
||||||
|
|
||||||
options.AddPolicy("SignalR",
|
options.AddPolicy("SignalR",
|
||||||
builder => builder.SetIsOriginAllowed(origin => true)
|
builder => builder.SetIsOriginAllowed(origin => true)
|
||||||
.AllowAnyMethod()
|
.AllowAnyMethod()
|
||||||
.AllowAnyHeader()
|
.AllowAnyHeader()
|
||||||
.AllowCredentials()
|
.AllowCredentials()
|
||||||
);
|
);
|
||||||
|
|
||||||
//options.AddPolicy("CorsPolicy",
|
//options.AddPolicy("CorsPolicy",
|
||||||
// builder => builder.AllowAnyOrigin()
|
// builder => builder.AllowAnyOrigin()
|
||||||
// .AllowAnyMethod()
|
// .AllowAnyMethod()
|
||||||
// .AllowAnyHeader());
|
// .AllowAnyHeader());
|
||||||
});
|
});
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region SqlSugar
|
#region SqlSugar
|
||||||
|
|
||||||
////没有直接 using SqlSugar,因为如果引用命名空间的话,会和Microsoft的一个GetTypeInfo存在二义性,所以就直接这么使用了
|
////没有直接 using SqlSugar,因为如果引用命名空间的话,会和Microsoft的一个GetTypeInfo存在二义性,所以就直接这么使用了
|
||||||
services.AddScoped<ISqlSugarClient>(s =>
|
services.AddScoped<ISqlSugarClient>(s =>
|
||||||
{
|
{
|
||||||
StaticConfig.CustomSnowFlakeFunc = () =>
|
StaticConfig.CustomSnowFlakeFunc = () => { return Yitter.IdGenerator.YitIdHelper.NextId(); };
|
||||||
{
|
|
||||||
return Yitter.IdGenerator.YitIdHelper.NextId();
|
|
||||||
};
|
|
||||||
|
|
||||||
var sqlSugar = new SqlSugarClient(new ConnectionConfig()
|
var sqlSugar = new SqlSugarClient(new ConnectionConfig()
|
||||||
{
|
|
||||||
DbType = SqlSugar.DbType.PostgreSQL,
|
|
||||||
ConnectionString = Configuration.GetConnectionString("OpenAuthDBContext"),
|
|
||||||
IsAutoCloseConnection = true,
|
|
||||||
MoreSettings = new SqlSugar.ConnMoreSettings()
|
|
||||||
{
|
{
|
||||||
PgSqlIsAutoToLower = false,
|
DbType = SqlSugar.DbType.PostgreSQL,
|
||||||
PgSqlIsAutoToLowerCodeFirst = false
|
ConnectionString = Configuration.GetConnectionString("OpenAuthDBContext"),
|
||||||
}
|
IsAutoCloseConnection = true,
|
||||||
},
|
MoreSettings = new SqlSugar.ConnMoreSettings()
|
||||||
|
{
|
||||||
|
PgSqlIsAutoToLower = false,
|
||||||
|
PgSqlIsAutoToLowerCodeFirst = false
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
//var sqlSugar = new SqlSugarClient(new ConnectionConfig()
|
//var sqlSugar = new SqlSugarClient(new ConnectionConfig()
|
||||||
//{
|
//{
|
||||||
// DbType = SqlSugar.DbType.Kdbndp,
|
// DbType = SqlSugar.DbType.Kdbndp,
|
||||||
// ConnectionString = Configuration.GetConnectionString("OpenAuthDBContext"),
|
// ConnectionString = Configuration.GetConnectionString("OpenAuthDBContext"),
|
||||||
// IsAutoCloseConnection = true,
|
// IsAutoCloseConnection = true,
|
||||||
// MoreSettings = new SqlSugar.ConnMoreSettings()
|
// MoreSettings = new SqlSugar.ConnMoreSettings()
|
||||||
// {
|
// {
|
||||||
// //PgSqlIsAutoToLower = false,
|
// //PgSqlIsAutoToLower = false,
|
||||||
// //PgSqlIsAutoToLowerCodeFirst = false,
|
// //PgSqlIsAutoToLowerCodeFirst = false,
|
||||||
// IsAutoToUpper = false,
|
// IsAutoToUpper = false,
|
||||||
|
|
||||||
// DatabaseModel = DbType.PostgreSQL
|
// DatabaseModel = DbType.PostgreSQL
|
||||||
// }
|
// }
|
||||||
//},
|
//},
|
||||||
db =>
|
db =>
|
||||||
{
|
{
|
||||||
NpgsqlConnection.GlobalTypeMapper.UseNetTopologySuite();
|
NpgsqlConnection.GlobalTypeMapper.UseNetTopologySuite();
|
||||||
//单例参数配置,所有上下文生效
|
//单例参数配置,所有上下文生效
|
||||||
db.Aop.OnLogExecuting = (sql, pars) =>
|
db.Aop.OnLogExecuting = (sql, pars) =>
|
||||||
{
|
{
|
||||||
//获取原生SQL推荐 5.1.4.63 性能OK
|
//获取原生SQL推荐 5.1.4.63 性能OK
|
||||||
//UtilMethods.GetNativeSql(sql, pars);
|
//UtilMethods.GetNativeSql(sql, pars);
|
||||||
|
|
||||||
//获取无参数化SQL 影响性能只适合调试
|
//获取无参数化SQL 影响性能只适合调试
|
||||||
//Console.WriteLine(UtilMethods.GetSqlString(DbType.PostgreSQL, sql, pars));
|
//Console.WriteLine(UtilMethods.GetSqlString(DbType.PostgreSQL, sql, pars));
|
||||||
//Console.WriteLine(sql + "\r\n" + db.Utilities.SerializeObject(pars.ToDictionary(it => it.ParameterName, it => it.Value)));
|
//Console.WriteLine(sql + "\r\n" + db.Utilities.SerializeObject(pars.ToDictionary(it => it.ParameterName, it => it.Value)));
|
||||||
//LogHelper.LogInformation(sql + "\r\n" +db.Utilities.SerializeObject(pars.ToDictionary(it => it.ParameterName, it => it.Value)));
|
//LogHelper.LogInformation(sql + "\r\n" +db.Utilities.SerializeObject(pars.ToDictionary(it => it.ParameterName, it => it.Value)));
|
||||||
//Console.WriteLine();
|
//Console.WriteLine();
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
return sqlSugar;
|
return sqlSugar;
|
||||||
});
|
});
|
||||||
services.AddScoped<SqlSugar.ISugarUnitOfWork<SugarDbContext>>(s => new SqlSugar.SugarUnitOfWork<SugarDbContext>(s.GetService<ISqlSugarClient>()));
|
services.AddScoped<SqlSugar.ISugarUnitOfWork<SugarDbContext>>(s =>
|
||||||
|
new SqlSugar.SugarUnitOfWork<SugarDbContext>(s.GetService<ISqlSugarClient>()));
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region HttpClient
|
#region HttpClient
|
||||||
|
|
||||||
services.AddHttpClient();
|
services.AddHttpClient();
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region DataProtection
|
#region DataProtection
|
||||||
|
|
||||||
services.AddDataProtection().PersistKeysToFileSystem(new DirectoryInfo(Configuration["DataProtection"]));
|
services.AddDataProtection().PersistKeysToFileSystem(new DirectoryInfo(Configuration["DataProtection"]));
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Quartz
|
#region Quartz
|
||||||
|
|
||||||
//设置定时启动的任务
|
//设置定时启动的任务
|
||||||
services.AddHostedService<QuartzService>();
|
//services.AddHostedService<QuartzService>();
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region SignalR
|
#region SignalR
|
||||||
|
|
||||||
services.AddSignalR();
|
services.AddSignalR();
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -327,27 +352,28 @@ namespace OpenAuth.WebApi
|
||||||
//可以在这里为静态文件添加其他http头信息,默认添加跨域信息
|
//可以在这里为静态文件添加其他http头信息,默认添加跨域信息
|
||||||
ctx.Context.Response.Headers["Access-Control-Allow-Origin"] = "*";
|
ctx.Context.Response.Headers["Access-Control-Allow-Origin"] = "*";
|
||||||
},
|
},
|
||||||
ContentTypeProvider = new Microsoft.AspNetCore.StaticFiles.FileExtensionContentTypeProvider(new Dictionary<string, string>
|
ContentTypeProvider = new Microsoft.AspNetCore.StaticFiles.FileExtensionContentTypeProvider(
|
||||||
{
|
new Dictionary<string, string>
|
||||||
{ ".amr","audio/AMR" },
|
{
|
||||||
{ ".mp3","audio/mpeg" },
|
{ ".amr", "audio/AMR" },
|
||||||
{ ".mp4","video/mp4" },
|
{ ".mp3", "audio/mpeg" },
|
||||||
{ ".apk","application/vnd.android.package-archive" },
|
{ ".mp4", "video/mp4" },
|
||||||
{ ".cpg","application/vnd.android.package-archive" },
|
{ ".apk", "application/vnd.android.package-archive" },
|
||||||
{ ".dbf","application/vnd.android.package-archive" },
|
{ ".cpg", "application/vnd.android.package-archive" },
|
||||||
{ ".shp","application/vnd.android.package-archive" },
|
{ ".dbf", "application/vnd.android.package-archive" },
|
||||||
{ ".shx","application/vnd.android.package-archive" },
|
{ ".shp", "application/vnd.android.package-archive" },
|
||||||
{ ".zip","application/zip" },
|
{ ".shx", "application/vnd.android.package-archive" },
|
||||||
{ ".jpeg","image/jpeg" },
|
{ ".zip", "application/zip" },
|
||||||
{ ".jpg","image/jpg" },
|
{ ".jpeg", "image/jpeg" },
|
||||||
{ ".png","image/png" },
|
{ ".jpg", "image/jpg" },
|
||||||
{ ".docx","application/msword" },
|
{ ".png", "image/png" },
|
||||||
{ ".doc","application/msword" },
|
{ ".docx", "application/msword" },
|
||||||
{ ".txt","application/octet-stream" },
|
{ ".doc", "application/msword" },
|
||||||
{ ".xlsx","application/octet-stream" },
|
{ ".txt", "application/octet-stream" },
|
||||||
{ ".xls","application/vnd.ms-excel" },
|
{ ".xlsx", "application/octet-stream" },
|
||||||
{ ".pdf","application/pdf"}
|
{ ".xls", "application/vnd.ms-excel" },
|
||||||
})
|
{ ".pdf", "application/pdf" }
|
||||||
|
})
|
||||||
};
|
};
|
||||||
app.UseStaticFiles(staticfile);
|
app.UseStaticFiles(staticfile);
|
||||||
//todo:测试可以允许任意跨域,正式环境要加权限
|
//todo:测试可以允许任意跨域,正式环境要加权限
|
||||||
|
|
@ -399,7 +425,7 @@ namespace OpenAuth.WebApi
|
||||||
{
|
{
|
||||||
c.SwaggerEndpoint("v1/swagger.json", "V1 Docs");
|
c.SwaggerEndpoint("v1/swagger.json", "V1 Docs");
|
||||||
c.DocExpansion(Swashbuckle.AspNetCore.SwaggerUI.DocExpansion.None);
|
c.DocExpansion(Swashbuckle.AspNetCore.SwaggerUI.DocExpansion.None);
|
||||||
c.OAuthClientId("OpenAuth.WebApi"); //oauth客户端名称
|
c.OAuthClientId("OpenAuth.WebApi"); //oauth客户端名称
|
||||||
c.OAuthAppName("开源版webapi认证"); // 描述
|
c.OAuthAppName("开源版webapi认证"); // 描述
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -67,5 +67,11 @@
|
||||||
"TiffStoreNamePrefix": "tiff_store",
|
"TiffStoreNamePrefix": "tiff_store",
|
||||||
"TiffDir": "E:/tiff"
|
"TiffDir": "E:/tiff"
|
||||||
},
|
},
|
||||||
"FlyImageDir": "e:/fly"
|
"FlyImageDir": "e:/fly",
|
||||||
|
"MQTT":{
|
||||||
|
"Server": "175.27.168.120",
|
||||||
|
"Port": 6011,
|
||||||
|
"UserName": "sdhc",
|
||||||
|
"Password": ""
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue