swagger 配置 以及其他一些配置

master
lxw 7 months ago
parent 20e069a2a8
commit bb778ab42e

@ -0,0 +1,10 @@
namespace Entity.Api.Req;
public class TestReq
{
/// <summary>
/// 序号
/// </summary>
public int Id { get; set; }
}

@ -0,0 +1,27 @@
namespace Entity.Api.Resp;
/// <summary>
///
/// 换电plc模式
/// </summary>
public class PlcSwapModelResp
{
/// <summary>
/// 模式状态[40318]-10001:手动模式;10002:自动模式;10003:维修模式;
/// </summary>
public int ModelState { get; set; }
/// <summary>
/// 遥本控状态[40319]-0:无效值;10000:本地控制;10001:远程控制
/// </summary>
public int ControlModel { get; set; }
/// <summary>
/// 站外灯状态值【40506】1000:绿灯0黄灯1001红灯。
/// </summary>
public int StationInLampSts { get; set; }
/// <summary>
/// 站内灯状态值【40507】0:无颜色1000绿灯1001红灯1002黄灯1003黄灯闪烁。
/// </summary>
public int StationOutLampSts { get; set; }
}

@ -0,0 +1,36 @@
using Microsoft.AspNetCore.Mvc;
namespace Entity.Api.Resp;
/// <summary>
/// 首页大屏
/// </summary>
public class SwapMonitorScreenResp
{
/// <summary>
/// plc模式
/// </summary>
public PlcSwapModelResp? PlcSwapModel { get; set; }
/// <summary>
/// 换电状态
/// </summary>
public SwappingStateInfoResp? StateInfo{ get; set; }
/// <summary>
/// 换电车辆
/// </summary>
public SwapVehicleResp? VehicleInfo{ get; set; }
/// <summary>
/// 蓝牙
/// </summary>
public TboxResp? TboxInfo{ get; set; }
/// <summary>
/// 是否自动
/// </summary>
public bool IsAuto{ get; set; }
/// <summary>
/// 云平台是否连接
/// </summary>
public bool CloudIsConnected{ get; set; }
}

@ -0,0 +1,32 @@
namespace Entity.Api.Resp;
/// <summary>
/// 换电车辆信息
/// </summary>
public class SwapVehicleResp
{
/// <summary>
/// 换电订单号
/// </summary>
public string? OrderNo{ get; set; }
/// <summary>
/// 车辆VIN码
/// </summary>
public string? VelVin{ get; set; }
/// <summary>
/// 车型
/// </summary>
public string? VelType{ get; set; }
/// <summary>
/// 车辆MAC地址
/// </summary>
public string? VelMac{ get; set; }
/// <summary>
/// 车牌号
/// </summary>
public string? VelNo{ get; set; }
}

@ -0,0 +1,21 @@
namespace Entity.Api.Resp;
/// <summary>
/// 实时换电状态
/// </summary>
public class SwappingStateInfoResp
{
/// <summary>
/// 换电步序号
/// </summary>
public int StepNo{ get; set; }
/// <summary>
/// 换电步序名称
/// </summary>
public string? StepName{ get; set; }
/// <summary>
/// 换电步序时刻
/// </summary>
public DateTime StartTime{ get; set; }
}

@ -0,0 +1,51 @@
namespace Entity.Api.Resp;
/// <summary>
/// TBOX
/// </summary>
public class TboxResp
{
/// <summary>
/// 车载电池SN码
/// </summary>
public string? BatteryNo { get; set; }
/// <summary>
/// 车载电池SOC
/// </summary>
public float BatterySoc { get; set; }
/// <summary>
/// 蓝牙连接状态.0:未连接;1:连接
/// </summary>
public int? M2tConnectSts { get; set; }
/// <summary>
/// 上高压状态.1:上高压;0:下高压
/// </summary>
public int MainEegCnctrSts { get; set; }
/// <summary>
/// BMS换电状态.0:空闲;1换电准备;2、换电中;3、换电完成;5、原包安装完成
/// </summary>
public int BmsSwapSts { get; set; }
/// <summary>
/// 车辆状态.0:熄火;1准备;
/// </summary>
public int VehPowerMode { get; set; }
/// <summary>
/// 锁总体状态.0无效1上锁2解锁3异常
/// </summary>
public int PackLockSts { get; set; }
/// <summary>
/// 锁1状态.0无效1上锁2解锁3异常
/// </summary>
public int PackDetailLock1Sts { get; set; }
/// <summary>
/// 锁2状态.0无效1上锁2解锁3异常
/// </summary>
public int PackDetailLock2Sts { get; set; }
/// <summary>
/// 锁3状态.0无效1上锁2解锁3异常
/// </summary>
public int PackDetailLock3Sts { get; set; }
/// <summary>
/// 锁4状态.0无效1上锁2解锁3异常
/// </summary>
public int PackDetailLock4Sts { get; set; }
}

@ -6,6 +6,14 @@
<Nullable>enable</Nullable>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
<DocumentationFile>bin\Debug\Entity.xml</DocumentationFile>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
<DocumentationFile>bin\Release\Entity.xml</DocumentationFile>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="SqlSugarCore" Version="5.1.4.115"/>
</ItemGroup>
@ -14,4 +22,8 @@
<Folder Include="DbModel\Station\" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\HybirdFrameworkCore\HybirdFrameworkCore.csproj" />
</ItemGroup>
</Project>

@ -0,0 +1,27 @@
using System.Text.Json;
using System.Text.Json.Serialization;
namespace HybirdFrameworkCore.Entity;
/// <summary>
/// 序列化
/// </summary>
public class DatetimeJsonConverter : JsonConverter<DateTime>
{
public override DateTime Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
{
if (reader.TokenType == JsonTokenType.String)
{
if (DateTime.TryParse(reader.GetString(), out DateTime date))
return date;
}
return reader.GetDateTime();
}
public override void Write(Utf8JsonWriter writer, DateTime value, JsonSerializerOptions options)
{
writer.WriteStringValue(value.ToString("yyyy-MM-dd HH:mm:ss"));
}
}

@ -0,0 +1,13 @@
namespace HybirdFrameworkCore.Entity;
public class QueryPageModel
{
/// <summary>
///页码
/// </summary>
public int Page { get; set; } = 1;
/// <summary>
/// 页数
/// </summary>
public int PageSize { get; set; } = 10;
}

@ -0,0 +1,104 @@
namespace HybirdFrameworkCore.Entity
{
/// <summary>
/// 通用返回信息类
/// </summary>
public class Result<T>
{
/// <summary>
/// 状态码
/// </summary>
public int Status { get; set; } = 200;
/// <summary>
/// 操作是否成功
/// </summary>
public bool IsSuccess { get; set; } = false;
/// <summary>
/// 返回信息
/// </summary>
public string? Msg { get; set; }
/// <summary>
/// 返回数据集合
/// </summary>
public T? Data { get; set; }
/// <summary>
/// 返回成功
/// </summary>
/// <param name="msg">消息</param>
/// <returns></returns>
public static Result<T> Success(string msg = "成功")
{
return Message(true, msg, default);
}
/// <summary>
/// 返回成功
/// </summary>
/// <param name="data">数据</param>
/// <param name="msg">消息</param>
/// <returns></returns>
public static Result<T> Success(T data, string msg = "成功")
{
return Message(true, msg, data);
}
/// <summary>
/// 返回失败
/// </summary>
/// <param name="msg">消息</param>
/// <returns></returns>
public static Result<T> Fail(string msg = "失败")
{
return Message(false, msg, default);
}
/// <summary>
/// 返回失败
/// </summary>
/// <param name="msg">消息</param>
/// <param name="data">数据</param>
/// <returns></returns>
public static Result<T> Fail(T data, string msg = "失败")
{
return Message(false, msg, data);
}
/// <summary>
/// 返回消息
/// </summary>
/// <param name="success">失败/成功</param>
/// <param name="msg">消息</param>
/// <param name="data">数据</param>
/// <returns></returns>
public static Result<T> Message(bool success, string msg, T data)
{
return new Result<T>() { Msg = msg, Data = data, IsSuccess = success };
}
/// <summary>
/// 返回消息
/// </summary>
/// <param name="success">失败/成功</param>
/// <param name="msg">消息</param>
/// <param name="data">数据</param>
/// <returns></returns>
public static Result<T> Message(bool success, T data)
{
return new Result<T>() { Msg="查询成功", Data = data, IsSuccess = success };
}
}
}

@ -6,6 +6,14 @@
<Nullable>enable</Nullable>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
<DocumentationFile>bin\Debug\HybirdFrameworkCore.xml</DocumentationFile>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
<DocumentationFile>bin\Release\HybirdFrameworkCore.xml</DocumentationFile>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Autofac" Version="7.0.1"/>
<PackageReference Include="log4net" Version="2.0.15"/>
@ -13,6 +21,10 @@
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="7.0.0"/>
<PackageReference Include="Newtonsoft.Json" Version="13.0.3"/>
<PackageReference Include="StackExchange.Redis" Version="2.7.33"/>
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.5.0" />
<PackageReference Include="Swashbuckle.AspNetCore.Swagger" Version="6.5.0" />
<PackageReference Include="Swashbuckle.AspNetCore.SwaggerGen" Version="6.5.0" />
<PackageReference Include="Swashbuckle.AspNetCore.SwaggerUI" Version="6.5.0" />
</ItemGroup>
</Project>

@ -13,6 +13,10 @@
"Microsoft.Extensions.Configuration.Json": "7.0.0",
"Newtonsoft.Json": "13.0.3",
"StackExchange.Redis": "2.7.33",
"Swashbuckle.AspNetCore": "6.5.0",
"Swashbuckle.AspNetCore.Swagger": "6.5.0",
"Swashbuckle.AspNetCore.SwaggerGen": "6.5.0",
"Swashbuckle.AspNetCore.SwaggerUI": "6.5.0",
"log4net": "2.0.15"
},
"runtime": {
@ -41,6 +45,7 @@
}
}
},
"Microsoft.Extensions.ApiDescription.Server/6.0.5": {},
"Microsoft.Extensions.Configuration/7.0.0": {
"dependencies": {
"Microsoft.Extensions.Configuration.Abstractions": "7.0.0",
@ -126,14 +131,7 @@
}
}
},
"Microsoft.Extensions.Logging.Abstractions/6.0.0": {
"runtime": {
"lib/net6.0/Microsoft.Extensions.Logging.Abstractions.dll": {
"assemblyVersion": "6.0.0.0",
"fileVersion": "6.0.21.52210"
}
}
},
"Microsoft.Extensions.Logging.Abstractions/6.0.0": {},
"Microsoft.Extensions.Primitives/7.0.0": {
"dependencies": {
"System.Runtime.CompilerServices.Unsafe": "6.0.0"
@ -146,6 +144,14 @@
}
},
"Microsoft.NETCore.Platforms/2.0.0": {},
"Microsoft.OpenApi/1.2.3": {
"runtime": {
"lib/netstandard2.0/Microsoft.OpenApi.dll": {
"assemblyVersion": "1.2.3.0",
"fileVersion": "1.2.3.0"
}
}
},
"Newtonsoft.Json/13.0.3": {
"runtime": {
"lib/net6.0/Newtonsoft.Json.dll": {
@ -177,6 +183,44 @@
}
}
},
"Swashbuckle.AspNetCore/6.5.0": {
"dependencies": {
"Microsoft.Extensions.ApiDescription.Server": "6.0.5",
"Swashbuckle.AspNetCore.Swagger": "6.5.0",
"Swashbuckle.AspNetCore.SwaggerGen": "6.5.0",
"Swashbuckle.AspNetCore.SwaggerUI": "6.5.0"
}
},
"Swashbuckle.AspNetCore.Swagger/6.5.0": {
"dependencies": {
"Microsoft.OpenApi": "1.2.3"
},
"runtime": {
"lib/net6.0/Swashbuckle.AspNetCore.Swagger.dll": {
"assemblyVersion": "6.5.0.0",
"fileVersion": "6.5.0.0"
}
}
},
"Swashbuckle.AspNetCore.SwaggerGen/6.5.0": {
"dependencies": {
"Swashbuckle.AspNetCore.Swagger": "6.5.0"
},
"runtime": {
"lib/net6.0/Swashbuckle.AspNetCore.SwaggerGen.dll": {
"assemblyVersion": "6.5.0.0",
"fileVersion": "6.5.0.0"
}
}
},
"Swashbuckle.AspNetCore.SwaggerUI/6.5.0": {
"runtime": {
"lib/net6.0/Swashbuckle.AspNetCore.SwaggerUI.dll": {
"assemblyVersion": "6.5.0.0",
"fileVersion": "6.5.0.0"
}
}
},
"System.Configuration.ConfigurationManager/4.5.0": {
"dependencies": {
"System.Security.Cryptography.ProtectedData": "4.5.0",
@ -190,14 +234,7 @@
}
},
"System.Diagnostics.DiagnosticSource/4.7.1": {},
"System.IO.Pipelines/5.0.1": {
"runtime": {
"lib/netcoreapp3.0/System.IO.Pipelines.dll": {
"assemblyVersion": "5.0.0.1",
"fileVersion": "5.0.120.57516"
}
}
},
"System.IO.Pipelines/5.0.1": {},
"System.Runtime.CompilerServices.Unsafe/6.0.0": {},
"System.Security.AccessControl/4.5.0": {
"dependencies": {
@ -290,6 +327,13 @@
"path": "log4net/2.0.15",
"hashPath": "log4net.2.0.15.nupkg.sha512"
},
"Microsoft.Extensions.ApiDescription.Server/6.0.5": {
"type": "package",
"serviceable": true,
"sha512": "sha512-Ckb5EDBUNJdFWyajfXzUIMRkhf52fHZOQuuZg/oiu8y7zDCVwD0iHhew6MnThjHmevanpxL3f5ci2TtHQEN6bw==",
"path": "microsoft.extensions.apidescription.server/6.0.5",
"hashPath": "microsoft.extensions.apidescription.server.6.0.5.nupkg.sha512"
},
"Microsoft.Extensions.Configuration/7.0.0": {
"type": "package",
"serviceable": true,
@ -360,6 +404,13 @@
"path": "microsoft.netcore.platforms/2.0.0",
"hashPath": "microsoft.netcore.platforms.2.0.0.nupkg.sha512"
},
"Microsoft.OpenApi/1.2.3": {
"type": "package",
"serviceable": true,
"sha512": "sha512-Nug3rO+7Kl5/SBAadzSMAVgqDlfGjJZ0GenQrLywJ84XGKO0uRqkunz5Wyl0SDwcR71bAATXvSdbdzPrYRYKGw==",
"path": "microsoft.openapi/1.2.3",
"hashPath": "microsoft.openapi.1.2.3.nupkg.sha512"
},
"Newtonsoft.Json/13.0.3": {
"type": "package",
"serviceable": true,
@ -381,6 +432,34 @@
"path": "stackexchange.redis/2.7.33",
"hashPath": "stackexchange.redis.2.7.33.nupkg.sha512"
},
"Swashbuckle.AspNetCore/6.5.0": {
"type": "package",
"serviceable": true,
"sha512": "sha512-FK05XokgjgwlCI6wCT+D4/abtQkL1X1/B9Oas6uIwHFmYrIO9WUD5aLC9IzMs9GnHfUXOtXZ2S43gN1mhs5+aA==",
"path": "swashbuckle.aspnetcore/6.5.0",
"hashPath": "swashbuckle.aspnetcore.6.5.0.nupkg.sha512"
},
"Swashbuckle.AspNetCore.Swagger/6.5.0": {
"type": "package",
"serviceable": true,
"sha512": "sha512-XWmCmqyFmoItXKFsQSwQbEAsjDKcxlNf1l+/Ki42hcb6LjKL8m5Db69OTvz5vLonMSRntYO1XLqz0OP+n3vKnA==",
"path": "swashbuckle.aspnetcore.swagger/6.5.0",
"hashPath": "swashbuckle.aspnetcore.swagger.6.5.0.nupkg.sha512"
},
"Swashbuckle.AspNetCore.SwaggerGen/6.5.0": {
"type": "package",
"serviceable": true,
"sha512": "sha512-Y/qW8Qdg9OEs7V013tt+94OdPxbRdbhcEbw4NiwGvf4YBcfhL/y7qp/Mjv/cENsQ2L3NqJ2AOu94weBy/h4KvA==",
"path": "swashbuckle.aspnetcore.swaggergen/6.5.0",
"hashPath": "swashbuckle.aspnetcore.swaggergen.6.5.0.nupkg.sha512"
},
"Swashbuckle.AspNetCore.SwaggerUI/6.5.0": {
"type": "package",
"serviceable": true,
"sha512": "sha512-OvbvxX+wL8skxTBttcBsVxdh73Fag4xwqEU2edh4JMn7Ws/xJHnY/JB1e9RoCb6XpDxUF3hD9A0Z1lEUx40Pfw==",
"path": "swashbuckle.aspnetcore.swaggerui/6.5.0",
"hashPath": "swashbuckle.aspnetcore.swaggerui.6.5.0.nupkg.sha512"
},
"System.Configuration.ConfigurationManager/4.5.0": {
"type": "package",
"serviceable": true,

@ -2,5 +2,6 @@
<Project ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ImportGroup Condition=" '$(ExcludeRestorePackageImports)' != 'true' ">
<Import Project="$(NuGetPackageRoot)system.text.json\7.0.0\buildTransitive\net6.0\System.Text.Json.targets" Condition="Exists('$(NuGetPackageRoot)system.text.json\7.0.0\buildTransitive\net6.0\System.Text.Json.targets')" />
<Import Project="$(NuGetPackageRoot)microsoft.extensions.apidescription.server\6.0.5\build\Microsoft.Extensions.ApiDescription.Server.targets" Condition="Exists('$(NuGetPackageRoot)microsoft.extensions.apidescription.server\6.0.5\build\Microsoft.Extensions.ApiDescription.Server.targets')" />
</ImportGroup>
</Project>

@ -0,0 +1,24 @@
using Entity.Api.Req;
using Entity.Api.Resp;
using HybirdFrameworkCore.Entity;
using Microsoft.AspNetCore.Mvc;
namespace WebStarter.Controllers;
/// <summary>
/// 换电控制器
/// </summary>
[ApiController]
[Route("api/[controller]")]
public class SwapMonitorController : ControllerBase
{
/// <summary>
/// 首页换电状态信息
/// </summary>
/// <returns></returns>
[HttpPost("GetSwapMonitorData")]
public async Task<Result<SwapMonitorScreenResp>> GetSwapMonitorData()
{
return Result<SwapMonitorScreenResp>.Success(null);
}
}

@ -0,0 +1,14 @@
using HybirdFrameworkCore.Entity;
using Microsoft.AspNetCore.Mvc;
namespace WebStarter.Controllers;
/**
*
*/
[ApiController]
[Route("[controller]")]
public class SwapOrderController : ControllerBase
{
}

@ -2,7 +2,9 @@ using Autofac;
using Autofac.Extensions.DependencyInjection;
using HybirdFrameworkCore.Autofac;
using HybirdFrameworkCore.Configuration;
using HybirdFrameworkCore.Entity;
using HybirdFrameworkCore.Redis;
using Microsoft.OpenApi.Models;
using SqlSugar;
using SqlSugar.IOC;
@ -43,9 +45,36 @@ if (redisConnectionString != null && instanceName != null)
builder.Services.AddControllers();
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();
builder.Logging.AddLog4Net("log4net.config");
builder.Logging.AddLog4Net("log4net.config");
builder.Services.AddSwaggerGen(c =>
{
var basePath = Path.GetDirectoryName(AppContext.BaseDirectory);
//c.IncludeXmlComments(Path.Combine(basePath, Assembly.GetExecutingAssembly().GetName().Name+".xml"), true);
c.IncludeXmlComments(Path.Combine(basePath, "WebStarter.xml"), true);
c.IncludeXmlComments(Path.Combine(basePath, "Entity.xml"), true);
c.IncludeXmlComments(Path.Combine(basePath, "HybirdFrameworkCore.xml"), true);
});
//跨域
builder.Services.AddCors(options =>
{
options.AddPolicy
(name: "myCors",
builde =>
{
builde.WithOrigins("*", "*", "*")
.AllowAnyOrigin()
.AllowAnyHeader()
.AllowAnyMethod();
}
);
});
builder.Services.AddControllers().AddJsonOptions(configure =>
{
configure.JsonSerializerOptions.Converters.Add(new DatetimeJsonConverter());
});
var app = builder.Build();
@ -54,10 +83,11 @@ if (app.Environment.IsDevelopment())
{
app.UseSwagger();
app.UseSwaggerUI();
app.UseStaticFiles();
}
app.UseAuthorization();
app.UseCors("myCors");
app.MapControllers();
AppInfo.Container = app.Services.GetAutofacRoot();

@ -6,6 +6,14 @@
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
<DocumentationFile>bin\Debug\WebStarter.xml</DocumentationFile>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
<DocumentationFile>bin\Release\WebStarter.xml</DocumentationFile>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Autofac" Version="7.1.0"/>
<PackageReference Include="Autofac.Extensions.DependencyInjection" Version="8.0.0"/>

Loading…
Cancel
Save