添加项目文件。

master
wenjy 1 year ago
parent 45261a6588
commit 4dcec627e9

@ -0,0 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Nancy" Version="2.0.0" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.2" />
</ItemGroup>
</Project>

@ -0,0 +1,80 @@
using Nancy.Json;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
namespace Aucma.Scada.Api.Common
{
public class JsonChange
{
/// <summary>
/// Model 实体转json
/// </summary>
/// <param name="Model">可以是单个实体也可是实体集ToList()</param>
/// <returns></returns>
public string ModeToJson(object Model)
{
string str = "";
JavaScriptSerializer serializer = new JavaScriptSerializer();
str = serializer.Serialize(Model);
return str;
}
/// <summary>
/// json实体转Model
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="jsonStr"></param>
/// <returns></returns>
public T JsonToMode<T>(string jsonStr)
{
T info = default(T);
JavaScriptSerializer serializer = new JavaScriptSerializer();
info = serializer.Deserialize<T>(jsonStr);
return info;
}
/// <summary>
/// object转dictionary
/// </summary>
/// <param name="jsonData"></param>
/// <returns></returns>
public Dictionary<string, object> objectToDictionary(string jsonData)
{
Dictionary<string, object> result = new Dictionary<string, object>();
var inf = JsonConvert.DeserializeObject<Dictionary<string, object>>(jsonData);
foreach (KeyValuePair<string, object> item in inf)
{
if (item.Value != null)
{
var type = item.Value.GetType();
if (type == typeof(JObject))
{
var info = objectToDictionary(JsonConvert.SerializeObject(item.Value));
foreach (KeyValuePair<string, object> ite in info)
{
result.Add(ite.Key, ite.Value);
}
continue;
}
else if (type == typeof(JArray))
{
JArray array = (JArray)item.Value;
var info = objectToDictionary(JsonConvert.SerializeObject(array[0]));
foreach (KeyValuePair<string, object> ite in info)
{
result.Add(item.Key + ite.Key, ite.Value);
}
continue;
}
}
result.Add(item.Key, item.Value);
}
return result;
}
}
}

@ -0,0 +1,27 @@
using Microsoft.Extensions.Options;
namespace Aucma.Scada.Api.Config
{
/// <summary>
/// 系统配置
/// </summary>
public class AppConfig : IOptions<AppConfig>
{
/// <summary>
/// 日志文件路径
/// </summary>
public string logPath { get; set; }
/// <summary>
/// MES 数据库连接字符串
/// </summary>
public string mesConnStr { get; set; }
/// <summary>
/// MCS 数据库连接字符串
/// </summary>
public string mcsConnStr { get; set; }
public AppConfig Value => this;
}
}

@ -0,0 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Options" Version="7.0.1" />
</ItemGroup>
</Project>

@ -0,0 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="SqlSugarCore" Version="5.1.4.114" />
</ItemGroup>
</Project>

@ -0,0 +1,50 @@
using SqlSugar;
using System.Runtime.Serialization;
using System.Xml.Linq;
namespace Aucma.Scada.Api.Model
{
/// <summary>
/// 电检数据明细
///</summary>
[SugarTable("DETAIL_ELECTRICALINSPECTION"), TenantAttribute("scada")]
[DataContract(Name = "DetailElectricalinspection 电检数据明细")]
public class DetailElectricalinspection
{
/// <summary>
/// 标识
///</summary>
[SugarColumn(ColumnName = "UUID")]
public string Uuid { get; set; }
/// <summary>
/// 序号
///</summary>
[SugarColumn(ColumnName = "SERIALNUMBER")]
public decimal? Serialnumber { get; set; }
/// <summary>
/// 项目名称
///</summary>
[SugarColumn(ColumnName = "PROJECTNAME")]
public string Projectname { get; set; }
/// <summary>
/// 测试条件
///</summary>
[SugarColumn(ColumnName = "TESTCONDITION")]
public string Testcondition { get; set; }
/// <summary>
/// 测试值
///</summary>
[SugarColumn(ColumnName = "TESTVALUE")]
public string Testvalue { get; set; }
/// <summary>
/// 测试结果
///</summary>
[SugarColumn(ColumnName = "TESTRESULT")]
public string Testresult { get; set; }
/// <summary>
/// 记录时间
///</summary>
[SugarColumn(ColumnName = "RECORDTIME")]
public DateTime? Recordtime { get; set; }
}
}

@ -0,0 +1,50 @@
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Linq;
namespace Aucma.Scada.Api.Model
{
/// <summary>
/// 电检数据记录
///</summary>
[SugarTable("RECORD_ELECTRICALINSPECTION"), TenantAttribute("scada")]
[DataContract(Name = "RecordElectricalinspection 电检数据记录")]
public class RecordElectricalinspection
{
/// <summary>
/// 唯一标识
///</summary>
[SugarColumn(ColumnName = "UUID")]
public string Uuid { get; set; }
/// <summary>
/// 测试总结果
///</summary>
[SugarColumn(ColumnName = "RESULT")]
public string Result { get; set; }
/// <summary>
/// 产品条码
///</summary>
[SugarColumn(ColumnName = "BARCODE")]
public string Barcode { get; set; }
/// <summary>
/// 测试时间
///</summary>
[SugarColumn(ColumnName = "TESTTIME")]
public string Testtime { get; set; }
/// <summary>
/// 测试数据
///</summary>
[SugarColumn(ColumnName = "TESTDATA")]
public string Testdata { get; set; }
/// <summary>
/// 记录时间
///</summary>
[SugarColumn(ColumnName = "RECORDTIME")]
public DateTime? Recordtime { get; set; }
}
}

@ -0,0 +1,18 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="7.0.1" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Aucma.Scada.Api.Config\Aucma.Scada.Api.Config.csproj" />
<ProjectReference Include="..\Aucma.Scada.Api.Model\Aucma.Scada.Api.Model.csproj" />
</ItemGroup>
</Project>

@ -0,0 +1,24 @@
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Aucma.Scada.Api.Repository
{
public class Repository<T> : SimpleClient<T> where T : class, new()
{
public ITenant itenant = null;//多租户事务、GetConnection、IsAnyConnection等功能
public Repository(ISqlSugarClient db)
{
itenant = db.AsTenant();//用来处理事务
base.Context = db.AsTenant().GetConnectionScopeWithAttr<T>();//获取子Db
//如果不想通过注入多个仓储
//用到ChangeRepository或者Db.GetMyRepository需要看标题4写法
}
}
}

@ -0,0 +1,60 @@
using Aucma.Scada.Api.Config;
using Aucma.Scada.Api.Repository.service;
using Aucma.Scada.Api.Repository.service.Impl;
using Microsoft.Extensions.DependencyInjection;
using SqlSugar;
namespace Aucma.Scada.Api.Repository
{
public static class SqlsugarSetup
{
/// <summary>
/// 注册SqlSugar
/// </summary>
/// <param name="services"></param>
public static void AddSqlSugarSetup(this IServiceCollection services)
{
services.AddSingleton<ISqlSugarClient>(x =>
{
var appConfig = x.GetService<AppConfig>();
SqlSugarScope Db = new SqlSugarScope(new List<ConnectionConfig>()
{
new ConnectionConfig()
{
ConfigId = "mes",
DbType = DbType.SqlServer,
ConnectionString = appConfig.mesConnStr,
InitKeyType = InitKeyType.Attribute,
IsAutoCloseConnection = true,
},
new ConnectionConfig()
{
ConfigId = "scada",
DbType = DbType.Oracle,
ConnectionString = appConfig.mcsConnStr,
InitKeyType = InitKeyType.Attribute,
IsAutoCloseConnection = true,
}
},
db =>
{
db.Aop.OnLogExecuting = (sql, pars) => { };
});
return Db;
});
}
/// <summary>
/// 注册Repository、Service服务
/// </summary>
/// <param name="services"></param>
public static void AddServices(this IServiceCollection services)
{
services.AddSingleton(typeof(Repository<>));
services.AddSingleton<IRecordElectricalinspectionService, RecordElectricalinspectionServiceImpl>();
services.AddSingleton<IDetailElectricalinspectionService, DetailElectricalinspectionServiceImpl>();
}
}
}

@ -0,0 +1,19 @@
using Aucma.Scada.Api.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Aucma.Scada.Api.Repository.service
{
public interface IDetailElectricalinspectionService
{
/// <summary>
/// 保存电检明细数据
/// </summary>
/// <param name="detailElectricalinspections"></param>
/// <returns></returns>
bool InsertRangeDetailElectricalinspection(List<DetailElectricalinspection> detailElectricalinspections);
}
}

@ -0,0 +1,23 @@
using Aucma.Scada.Api.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Aucma.Scada.Api.Repository.service
{
/// <summary>
/// 电检数据记录
/// </summary>
public interface IRecordElectricalinspectionService
{
/// <summary>
/// 保存电检数据
/// </summary>
/// <param name="electricalinspection"></param>
/// <returns></returns>
bool InsertRecordElectricalinspection(RecordElectricalinspection electricalinspection);
}
}

@ -0,0 +1,39 @@
using Aucma.Scada.Api.Model;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Aucma.Scada.Api.Repository.service.Impl
{
public class DetailElectricalinspectionServiceImpl : IDetailElectricalinspectionService
{
private Repository<DetailElectricalinspection> _repository;
private ILogger<DetailElectricalinspectionServiceImpl> _logger;
public DetailElectricalinspectionServiceImpl(Repository<DetailElectricalinspection> repository, ILogger<DetailElectricalinspectionServiceImpl> logger)
{
_repository = repository;
_logger = logger;
}
public bool InsertRangeDetailElectricalinspection(List<DetailElectricalinspection> detailElectricalinspections)
{
bool result = false;
try
{
result = _repository.InsertRange(detailElectricalinspections);
}
catch (Exception ex)
{
_logger.LogError($"电检明细数据保存异常:{ex.Message}");
}
return result;
}
}
}

@ -0,0 +1,38 @@
using Aucma.Scada.Api.Model;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Aucma.Scada.Api.Repository.service.Impl
{
internal class RecordElectricalinspectionServiceImpl : IRecordElectricalinspectionService
{
private Repository<RecordElectricalinspection> _repository;
private ILogger<RecordElectricalinspectionServiceImpl> _logger;
public RecordElectricalinspectionServiceImpl(Repository<RecordElectricalinspection> repository, ILogger<RecordElectricalinspectionServiceImpl> logger)
{
_repository = repository;
_logger = logger;
}
public bool InsertRecordElectricalinspection(RecordElectricalinspection electricalinspection)
{
bool result = false;
try
{
result = _repository.Insert(electricalinspection);
}catch(Exception ex)
{
_logger.LogError($"电检数据保存异常:{ex.Message}");
}
return result;
}
}
}

@ -0,0 +1,49 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.5.33502.453
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Aucma.Scada.Api", "Aucma.Scada.Api\Aucma.Scada.Api.csproj", "{F509601C-5E2D-4F06-ACEC-2AAB7E591E15}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Aucma.Scada.Api.Model", "Aucma.Scada.Api.Model\Aucma.Scada.Api.Model.csproj", "{4F05A3C3-DCD4-4071-9F64-3936274CE011}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Aucma.Scada.Api.Config", "Aucma.Scada.Api.Config\Aucma.Scada.Api.Config.csproj", "{A9FA0950-3380-441E-9E52-ADA7A8872610}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Aucma.Scada.Api.Repository", "Aucma.Scada.Api.Repository\Aucma.Scada.Api.Repository.csproj", "{95BB1153-E37F-4F06-8289-C4388B966F5B}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Aucma.Scada.Api.Common", "Aucma.Scada.Api.Common\Aucma.Scada.Api.Common.csproj", "{740D0F39-3D9D-4758-B35A-11F1F9513A0A}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{F509601C-5E2D-4F06-ACEC-2AAB7E591E15}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{F509601C-5E2D-4F06-ACEC-2AAB7E591E15}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F509601C-5E2D-4F06-ACEC-2AAB7E591E15}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F509601C-5E2D-4F06-ACEC-2AAB7E591E15}.Release|Any CPU.Build.0 = Release|Any CPU
{4F05A3C3-DCD4-4071-9F64-3936274CE011}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{4F05A3C3-DCD4-4071-9F64-3936274CE011}.Debug|Any CPU.Build.0 = Debug|Any CPU
{4F05A3C3-DCD4-4071-9F64-3936274CE011}.Release|Any CPU.ActiveCfg = Release|Any CPU
{4F05A3C3-DCD4-4071-9F64-3936274CE011}.Release|Any CPU.Build.0 = Release|Any CPU
{A9FA0950-3380-441E-9E52-ADA7A8872610}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{A9FA0950-3380-441E-9E52-ADA7A8872610}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A9FA0950-3380-441E-9E52-ADA7A8872610}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A9FA0950-3380-441E-9E52-ADA7A8872610}.Release|Any CPU.Build.0 = Release|Any CPU
{95BB1153-E37F-4F06-8289-C4388B966F5B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{95BB1153-E37F-4F06-8289-C4388B966F5B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{95BB1153-E37F-4F06-8289-C4388B966F5B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{95BB1153-E37F-4F06-8289-C4388B966F5B}.Release|Any CPU.Build.0 = Release|Any CPU
{740D0F39-3D9D-4758-B35A-11F1F9513A0A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{740D0F39-3D9D-4758-B35A-11F1F9513A0A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{740D0F39-3D9D-4758-B35A-11F1F9513A0A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{740D0F39-3D9D-4758-B35A-11F1F9513A0A}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {41FD12F4-B3E2-45F2-98E6-BE4B1EB38DFA}
EndGlobalSection
EndGlobal

@ -0,0 +1,22 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<GenerateDocumentationFile>True</GenerateDocumentationFile>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Serilog" Version="3.0.1" />
<PackageReference Include="Serilog.AspNetCore" Version="7.0.0" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.2.3" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Aucma.Scada.Api.Common\Aucma.Scada.Api.Common.csproj" />
<ProjectReference Include="..\Aucma.Scada.Api.Config\Aucma.Scada.Api.Config.csproj" />
<ProjectReference Include="..\Aucma.Scada.Api.Repository\Aucma.Scada.Api.Repository.csproj" />
</ItemGroup>
</Project>

@ -0,0 +1,97 @@
using Aucma.Scada.Api.Common;
using Aucma.Scada.Api.Config;
using Aucma.Scada.Api.Model;
using Aucma.Scada.Api.Repository.service;
using Microsoft.AspNetCore.Mvc;
using Newtonsoft.Json;
namespace Aucma.Scada.Api.Controllers
{
/// <summary>
/// 电检数据接口
/// </summary>
[ApiController]
[Route("[controller]")]
public class ElectricalinspectionController : ControllerBase
{
private readonly ILogger<ElectricalinspectionController> _logger;
private IRecordElectricalinspectionService _recordElectricalinspectionService;
private IDetailElectricalinspectionService _detailElectricalinspectionService;
private JsonChange _jsonChange;
public ElectricalinspectionController(ILogger<ElectricalinspectionController> logger, IRecordElectricalinspectionService recordElectricalinspectionService, IDetailElectricalinspectionService detailElectricalinspectionService, JsonChange jsonChange)
{
_logger = logger;
_recordElectricalinspectionService = recordElectricalinspectionService;
_detailElectricalinspectionService = detailElectricalinspectionService;
_jsonChange = jsonChange;
}
/// <summary>
/// 保存电检数据
/// </summary>
/// <param name="electricalinspection"></param>
/// <returns></returns>
[HttpPost]
public IActionResult save([FromBody]RecordElectricalinspection electricalinspection)
{
_logger.LogInformation($"收到电检数据:{_jsonChange.ModeToJson(electricalinspection)}");
if (electricalinspection == null)
{
return BadRequest();
}
try
{
electricalinspection.Recordtime = DateTime.Now;
var testDataStr = electricalinspection.Testdata;
electricalinspection.Testdata = System.Guid.NewGuid().ToString();
#region 解析TestData
string[] str = testDataStr.ToString().Split(";");
List<DetailElectricalinspection> detailElectricalinspections = new List<DetailElectricalinspection>();
foreach (string item in str)
{
if (!string.IsNullOrEmpty(item))
{
string[] items = item.Split("|");
if (items.Length == 5)
{
DetailElectricalinspection detailElectricalinspection = new DetailElectricalinspection();
detailElectricalinspection.Uuid = electricalinspection.Testdata;
detailElectricalinspection.Serialnumber = Convert.ToDecimal(items[0]);
detailElectricalinspection.Projectname = items[1].ToString();
detailElectricalinspection.Testcondition = items[2].ToString();
detailElectricalinspection.Testvalue = items[3].ToString();
detailElectricalinspection.Testresult = items[4].ToString();
detailElectricalinspection.Recordtime = DateTime.Now;
detailElectricalinspections.Add(detailElectricalinspection);
}
}
}
#endregion
_logger.LogInformation($"电检明细解析完成:{_jsonChange.ModeToJson(detailElectricalinspections)}");
_recordElectricalinspectionService.InsertRecordElectricalinspection(electricalinspection);
_detailElectricalinspectionService.InsertRangeDetailElectricalinspection(detailElectricalinspections);
}
catch(Exception ex)
{
_logger.LogError($"电检数据处理异常:{ex.Message}");
}
return Ok();
}
}
}

@ -0,0 +1,23 @@
using Aucma.Scada.Api.Config;
using Serilog.Events;
using Serilog;
using Microsoft.AspNetCore.Hosting;
namespace Aucma.Scada.Api
{
public class Program
{
public static void Main(string[] args)
{
CreateHostBuilder(args).Build().Run();
}
public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.UseSerilog()
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.UseStartup<StartUp>();
});
}
}

@ -0,0 +1,31 @@
{
"$schema": "http://json.schemastore.org/launchsettings.json",
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:32147",
"sslPort": 44302
}
},
"profiles": {
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
//"launchUrl": "swagger",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"Aucma.Scada.Api": {
"commandName": "Project",
"launchBrowser": true,
//"launchUrl": "swagger",
"applicationUrl": "http://localhost:5000",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
}

@ -0,0 +1,113 @@
using Aucma.Scada.Api.Config;
using Microsoft.Extensions.Configuration;
using Microsoft.OpenApi.Models;
using Serilog.Events;
using Serilog;
using System.Runtime.Serialization;
using Aucma.Scada.Api.Repository;
using Aucma.Scada.Api.Common;
namespace Aucma.Scada.Api
{
public class StartUp
{
public IConfiguration Configuration { get; }
public StartUp(IConfiguration configuration)
{
Configuration = configuration;
}
public void ConfigureServices(IServiceCollection services)
{
services.AddControllers();
//配置Swagger
services.AddSwaggerGen(swagger =>
{
//自定义接口信息
swagger.SwaggerDoc("V1.0", new OpenApiInfo
{
Title = "MES Web Api",
Version = "V1.0",
Description = $"API版本V1.0",
Contact = new OpenApiContact
{
Name = "MES Web Api",
Email = "wenjy@mesnac.com"
}
});
//自定义实体别名
swagger.CustomSchemaIds(type => type.GetCustomAttributes(typeof(DataContractAttribute), true)
.Cast<DataContractAttribute>()
.FirstOrDefault()?.Name);
//配置Action名称
var path = Path.Combine(AppContext.BaseDirectory, "Aucma.Scada.Api.xml");
swagger.IncludeXmlComments(path, true); // true : 显示控制器层注释
swagger.OrderActionsBy(o => o.RelativePath); // 对action的名称进行排序如果有多个就可以看见效果了。
});
//注册配置类
services.AddSingleton<AppConfig>(provider =>
{
var configuration = provider.GetService<IConfiguration>();
return configuration.GetSection("AppConfig").Get<AppConfig>();
});
services.AddSingleton<JsonChange>();
//注册SqlSugar
services.AddSqlSugarSetup();
//注册Repository、Service
services.AddServices();
}
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
//启用Swagger中间件
app.UseSwagger();
app.UseSwaggerUI(c =>
{
c.SwaggerEndpoint("/swagger/V1.0/swagger.json", "MES Web Api V1.0");
c.RoutePrefix = "";
});
//启用Serilog中间件
app.UseSerilogRequestLogging();
#region 通过配置文件读取日志存放位置
var appConfig = app.ApplicationServices.GetService<AppConfig>();
var logPath = $"{appConfig.logPath}/Logs/{DateTime.UtcNow:yyyy-MM-dd}/";
#endregion
Log.Logger = new LoggerConfiguration().MinimumLevel.Information().WriteTo.Console()
.WriteTo.File(Path.Combine(logPath, "Info.log"), LogEventLevel.Information, fileSizeLimitBytes: 5 * 1024)
.WriteTo.File(Path.Combine(logPath, "Error.log"), LogEventLevel.Error, fileSizeLimitBytes: 5 * 1024)
.WriteTo.File(Path.Combine(logPath, "Warn.log"), LogEventLevel.Warning, fileSizeLimitBytes: 5 * 1024)
.WriteTo.File(Path.Combine(logPath, "Trace.log"), LogEventLevel.Verbose, fileSizeLimitBytes: 5 * 1024)
.CreateLogger();
//app.UseHttpsRedirection();
app.UseRouting();
app.UseAuthorization();
app.UseEndpoints(endpoints =>
{
endpoints.MapControllers();
});
Log.Information($"项目初始化完成,日志存放路径:{appConfig.logPath}");
}
}
}

@ -0,0 +1,8 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
}
}

@ -0,0 +1,14 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
},
"AllowedHosts": "*",
"AppConfig": {
"logPath": "E:\\桌面\\澳柯玛MES项目\\日志信息",
"mesConnStr": "server=.;uid=sa;pwd=123456;database=JiangYinMENS",
"mcsConnStr": "Data Source=175.27.215.92/helowin;User ID=aucma_scada;Password=aucma"
}
}
Loading…
Cancel
Save