添加项目文件。
This commit is contained in:
27
Print.Forum.HttpApi.Host/Dockerfile
Normal file
27
Print.Forum.HttpApi.Host/Dockerfile
Normal file
@ -0,0 +1,27 @@
|
||||
#See https://aka.ms/customizecontainer to learn how to customize your debug container and how Visual Studio uses this Dockerfile to build your images for faster debugging.
|
||||
|
||||
FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS base
|
||||
USER app
|
||||
WORKDIR /app
|
||||
EXPOSE 8080
|
||||
EXPOSE 8081
|
||||
|
||||
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
|
||||
ARG BUILD_CONFIGURATION=Release
|
||||
WORKDIR /src
|
||||
COPY ["Print.Forum.HttpApi.Host/Print.Forum.HttpApi.Host.csproj", "Print.Forum.HttpApi.Host/"]
|
||||
COPY ["Print.Application/Print.Application.csproj", "Print.Application/"]
|
||||
COPY ["Print.Forum.Application.Contracts/Print.Forum.Application.Contracts.csproj", "Print.Forum.Application.Contracts/"]
|
||||
RUN dotnet restore "./Print.Forum.HttpApi.Host/Print.Forum.HttpApi.Host.csproj"
|
||||
COPY . .
|
||||
WORKDIR "/src/Print.Forum.HttpApi.Host"
|
||||
RUN dotnet build "./Print.Forum.HttpApi.Host.csproj" -c $BUILD_CONFIGURATION -o /app/build
|
||||
|
||||
FROM build AS publish
|
||||
ARG BUILD_CONFIGURATION=Release
|
||||
RUN dotnet publish "./Print.Forum.HttpApi.Host.csproj" -c $BUILD_CONFIGURATION -o /app/publish /p:UseAppHost=false
|
||||
|
||||
FROM base AS final
|
||||
WORKDIR /app
|
||||
COPY --from=publish /app/publish .
|
||||
ENTRYPOINT ["dotnet", "Print.Forum.HttpApi.Host.dll"]
|
73
Print.Forum.HttpApi.Host/ForumHttpApiHostModule.cs
Normal file
73
Print.Forum.HttpApi.Host/ForumHttpApiHostModule.cs
Normal file
@ -0,0 +1,73 @@
|
||||
using Print.Application;
|
||||
using Volo.Abp.Autofac;
|
||||
using Volo.Abp.Modularity;
|
||||
using Volo.Abp;
|
||||
using Volo.Abp.AspNetCore.Mvc;
|
||||
|
||||
namespace Print.Forum.HttpApi.Host
|
||||
{
|
||||
|
||||
[DependsOn(typeof(AbpAspNetCoreMvcModule), typeof(AbpAutofacModule))]
|
||||
[DependsOn(typeof(ForumApplicationModule)
|
||||
)]
|
||||
public class ForumHttpApiHostModule : AbpModule
|
||||
{
|
||||
public override void ConfigureServices(ServiceConfigurationContext context)
|
||||
{
|
||||
var services = context.Services;
|
||||
var configuration = services.GetConfiguration();
|
||||
|
||||
// 跨域
|
||||
context.Services.AddCors(options =>
|
||||
{
|
||||
options.AddPolicy("AllowAll", builder =>
|
||||
{
|
||||
builder.AllowAnyOrigin()
|
||||
.SetIsOriginAllowedToAllowWildcardSubdomains()
|
||||
.AllowAnyHeader()
|
||||
.AllowAnyMethod();
|
||||
});
|
||||
});
|
||||
|
||||
// 自动生成控制器
|
||||
Configure<AbpAspNetCoreMvcOptions>(options =>
|
||||
{
|
||||
options.ConventionalControllers.Create(typeof(ForumApplicationModule).Assembly);
|
||||
});
|
||||
|
||||
// swagger
|
||||
services.AddSwaggerGen(options =>
|
||||
{
|
||||
options.SwaggerDoc("v1", new Microsoft.OpenApi.Models.OpenApiInfo()
|
||||
{
|
||||
Title = "ForumApi",
|
||||
Version = "v0.1"
|
||||
});
|
||||
options.DocInclusionPredicate((docName, predicate) => true);
|
||||
options.CustomSchemaIds(type => type.FullName);
|
||||
});
|
||||
}
|
||||
|
||||
public override void OnApplicationInitialization(ApplicationInitializationContext context)
|
||||
{
|
||||
var env = context.GetEnvironment();
|
||||
var app = context.GetApplicationBuilder();
|
||||
var configuration = context.GetConfiguration();
|
||||
|
||||
if (env.IsDevelopment())
|
||||
{
|
||||
app.UseDeveloperExceptionPage();
|
||||
}
|
||||
|
||||
app.UseCors("AllowAll");
|
||||
app.UseSwagger();
|
||||
app.UseSwaggerUI(options =>
|
||||
{
|
||||
options.SwaggerEndpoint("/swagger/v1/swagger.json", "ForumApi");
|
||||
});
|
||||
|
||||
app.UseRouting();
|
||||
app.UseConfiguredEndpoints();
|
||||
}
|
||||
}
|
||||
}
|
132
Print.Forum.HttpApi.Host/GoDEXPrintController.cs
Normal file
132
Print.Forum.HttpApi.Host/GoDEXPrintController.cs
Normal file
@ -0,0 +1,132 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Print.Application;
|
||||
using Volo.Abp.AspNetCore.Mvc;
|
||||
using Volo.Abp.Domain.Repositories;
|
||||
using Volo.Abp.MultiTenancy;
|
||||
using Volo.Abp;
|
||||
using Print.Forum.Application.Contracts.JingGong.Abp.MES;
|
||||
using Print.Forum.Application.Contracts;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace Print.Forum.HttpApi.Host
|
||||
{
|
||||
/// <summary>
|
||||
/// 打印实现
|
||||
/// </summary>
|
||||
[RemoteService]
|
||||
[Area("Print")]
|
||||
[Route("api/MES/[Controller]")]
|
||||
public class GoDEXPrintController : AbpController
|
||||
{
|
||||
private readonly ILogger<GoDEXPrintController> _logger;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 构造方法
|
||||
/// </summary>
|
||||
/// <param name="logger"></param>
|
||||
public GoDEXPrintController(ILogger<GoDEXPrintController> logger, ICurrentTenant currentTenant)
|
||||
{
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 打印图片文件
|
||||
/// </summary>
|
||||
/// <param name="goDEXPrintImageFile"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
[Route("PrintImageFile")]
|
||||
public ResultDto PrintImageFile(GoDEXPrintImageFile goDEXPrintImageFile)
|
||||
{
|
||||
if (goDEXPrintImageFile == null)
|
||||
return new ResultDto(false, $"参数{nameof(goDEXPrintImageFile)}不可为空!");
|
||||
|
||||
try
|
||||
{
|
||||
var godex = new GoDEXPrint();
|
||||
|
||||
godex.Print(goDEXPrintImageFile);
|
||||
|
||||
return new ResultDto(true);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, $"打印失败:{goDEXPrintImageFile}");
|
||||
|
||||
return new ResultDto(false, $"打印失败:{nameof(ex.Message)}");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 打印base64格式图片
|
||||
/// </summary>
|
||||
/// <param name="goDEXPrintBase64Image"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
[Route("PrintBase64Image")]
|
||||
public ResultDto PrintBase64Image(GoDEXPrintBase64Image goDEXPrintBase64Image)
|
||||
{
|
||||
if (goDEXPrintBase64Image == null)
|
||||
return new ResultDto(false, $"参数{nameof(goDEXPrintBase64Image)}不可为空!");
|
||||
|
||||
try
|
||||
{
|
||||
var godex = new GoDEXPrint();
|
||||
|
||||
godex.Print(goDEXPrintBase64Image);
|
||||
|
||||
return new ResultDto(true);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
||||
return new ResultDto(false, $"打印失败:{nameof(ex.Message)}");
|
||||
}
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
[Route("PrintBase64Imagenew")]
|
||||
public async Task<ResultDto> PrintBase64Imagenew(PrintPictureDto input)
|
||||
{
|
||||
_logger.LogInformation("1.进入打印接口");
|
||||
//切换业务所属的租户
|
||||
|
||||
GoDEXPrintBase64Image goDEXPrintBase64Image = new GoDEXPrintBase64Image();
|
||||
goDEXPrintBase64Image.Communication = new GoDEXCommunication();
|
||||
goDEXPrintBase64Image.Communication.Host = input.ip;
|
||||
goDEXPrintBase64Image.Communication.Port = 9100;
|
||||
goDEXPrintBase64Image.LabelSetup = new GoDEXPrintSetup();
|
||||
goDEXPrintBase64Image.LabelSetup.Height = 70;
|
||||
goDEXPrintBase64Image.LabelSetup.Speed = 3;
|
||||
goDEXPrintBase64Image.LabelSetup.Width = 100;
|
||||
goDEXPrintBase64Image.LabelSetup.Dark = 10;
|
||||
goDEXPrintBase64Image.PosX = 3;
|
||||
goDEXPrintBase64Image.PosY = 3;
|
||||
goDEXPrintBase64Image.Width = 97;
|
||||
goDEXPrintBase64Image.Height = 67;
|
||||
goDEXPrintBase64Image.ImageBase64 = input.Base64Data.First();
|
||||
|
||||
if (goDEXPrintBase64Image == null)
|
||||
return new ResultDto(false, $"参数{nameof(goDEXPrintBase64Image)}不可为空!");
|
||||
|
||||
try
|
||||
{
|
||||
var godex = new GoDEXPrint();
|
||||
|
||||
godex.Print(goDEXPrintBase64Image);
|
||||
|
||||
return new ResultDto(true);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, $"打印失败:{JsonConvert.SerializeObject(goDEXPrintBase64Image)}");
|
||||
|
||||
return new ResultDto(false, $"打印失败:{nameof(ex.Message)}");
|
||||
}
|
||||
return new ResultDto(false, "");
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
25
Print.Forum.HttpApi.Host/Print.Forum.HttpApi.Host.csproj
Normal file
25
Print.Forum.HttpApi.Host/Print.Forum.HttpApi.Host.csproj
Normal file
@ -0,0 +1,25 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<UserSecretsId>be372b4a-f87d-477c-bf6d-7468c93527cd</UserSecretsId>
|
||||
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="8.0.6" />
|
||||
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.20.1" />
|
||||
<PackageReference Include="Serilog.AspNetCore" Version="9.0.0" />
|
||||
<PackageReference Include="Serilog.Sinks.Async" Version="2.1.0" />
|
||||
<PackageReference Include="Swashbuckle.AspNetCore" Version="9.0.3" />
|
||||
<PackageReference Include="Volo.Abp.AspNetCore.Mvc" Version="8.1.1" />
|
||||
<PackageReference Include="Volo.Abp.Autofac" Version="8.1.1" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Print.Application\Print.Application.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
6
Print.Forum.HttpApi.Host/Print.Forum.HttpApi.Host.http
Normal file
6
Print.Forum.HttpApi.Host/Print.Forum.HttpApi.Host.http
Normal file
@ -0,0 +1,6 @@
|
||||
@Print.Forum.HttpApi.Host_HostAddress = http://localhost:5090
|
||||
|
||||
GET {{Print.Forum.HttpApi.Host_HostAddress}}/weatherforecast/
|
||||
Accept: application/json
|
||||
|
||||
###
|
30
Print.Forum.HttpApi.Host/Program.cs
Normal file
30
Print.Forum.HttpApi.Host/Program.cs
Normal file
@ -0,0 +1,30 @@
|
||||
using Print.Forum.HttpApi.Host;
|
||||
using Serilog.Events;
|
||||
using Serilog;
|
||||
|
||||
Log.Logger = new LoggerConfiguration()
|
||||
#if DEBUG
|
||||
.MinimumLevel.Debug()
|
||||
#else
|
||||
.MinimumLevel.Information()
|
||||
#endif
|
||||
.MinimumLevel.Override("Microsoft", LogEventLevel.Information)
|
||||
.MinimumLevel.Override("Microsoft.EntityFrameworkCore", LogEventLevel.Warning)
|
||||
.Enrich.FromLogContext()
|
||||
.WriteTo.Async(c => c.File("logs/logs.log"))
|
||||
#if DEBUG
|
||||
.WriteTo.Async(c => c.Console())
|
||||
#endif
|
||||
.CreateLogger();
|
||||
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
builder.Host.AddAppSettingsSecretsJson()
|
||||
.UseAutofac()
|
||||
.UseSerilog();
|
||||
// Add services to the container.
|
||||
await builder.AddApplicationAsync<ForumHttpApiHostModule>();
|
||||
|
||||
var app = builder.Build();
|
||||
// Configure the HTTP request pipeline.
|
||||
await app.InitializeApplicationAsync();
|
||||
await app.RunAsync();
|
52
Print.Forum.HttpApi.Host/Properties/launchSettings.json
Normal file
52
Print.Forum.HttpApi.Host/Properties/launchSettings.json
Normal file
@ -0,0 +1,52 @@
|
||||
{
|
||||
"profiles": {
|
||||
"http": {
|
||||
"commandName": "Project",
|
||||
"launchBrowser": true,
|
||||
"launchUrl": "swagger",
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||
},
|
||||
"dotnetRunMessages": true,
|
||||
"applicationUrl": "http://localhost:5090"
|
||||
},
|
||||
"https": {
|
||||
"commandName": "Project",
|
||||
"launchBrowser": true,
|
||||
"launchUrl": "swagger",
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||
},
|
||||
"dotnetRunMessages": true,
|
||||
"applicationUrl": "https://localhost:7005;http://localhost:5090"
|
||||
},
|
||||
"IIS Express": {
|
||||
"commandName": "IISExpress",
|
||||
"launchBrowser": true,
|
||||
"launchUrl": "swagger",
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||
}
|
||||
},
|
||||
"Container (Dockerfile)": {
|
||||
"commandName": "Docker",
|
||||
"launchBrowser": true,
|
||||
"launchUrl": "{Scheme}://{ServiceHost}:{ServicePort}/swagger",
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_HTTPS_PORTS": "8081",
|
||||
"ASPNETCORE_HTTP_PORTS": "8080"
|
||||
},
|
||||
"publishAllPorts": true,
|
||||
"useSSL": true
|
||||
}
|
||||
},
|
||||
"$schema": "http://json.schemastore.org/launchsettings.json",
|
||||
"iisSettings": {
|
||||
"windowsAuthentication": false,
|
||||
"anonymousAuthentication": true,
|
||||
"iisExpress": {
|
||||
"applicationUrl": "http://localhost:20399",
|
||||
"sslPort": 44333
|
||||
}
|
||||
}
|
||||
}
|
8
Print.Forum.HttpApi.Host/appsettings.Development.json
Normal file
8
Print.Forum.HttpApi.Host/appsettings.Development.json
Normal file
@ -0,0 +1,8 @@
|
||||
{
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
"Default": "Information",
|
||||
"Microsoft.AspNetCore": "Warning"
|
||||
}
|
||||
}
|
||||
}
|
9
Print.Forum.HttpApi.Host/appsettings.json
Normal file
9
Print.Forum.HttpApi.Host/appsettings.json
Normal file
@ -0,0 +1,9 @@
|
||||
{
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
"Default": "Information",
|
||||
"Microsoft.AspNetCore": "Warning"
|
||||
}
|
||||
},
|
||||
"AllowedHosts": "*"
|
||||
}
|
Reference in New Issue
Block a user