feat 餐补接收

This commit is contained in:
2024-03-14 16:35:38 +08:00
parent d17b20365a
commit 16be030748
15 changed files with 411 additions and 3 deletions

View File

@@ -0,0 +1,24 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<Nullable>disable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
<DockerfileContext>..\..</DockerfileContext>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Kurisu.AspNetCore" Version="0.7.1" />
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.19.5" />
</ItemGroup>
<ItemGroup>
<Folder Include="MealSupplement\Response\" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Dlhis.Entity\Dlhis.Entity.csproj" />
</ItemGroup>
</Project>

View File

@@ -0,0 +1,24 @@
#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:6.0 AS base
WORKDIR /app
EXPOSE 80
FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build
ARG BUILD_CONFIGURATION=Release
WORKDIR /src
COPY ["Src/Dlhis.External/Dlhis.External.csproj", "Src/Dlhis.External/"]
COPY ["Src/Dlhis.Entity/Dlhis.Entity.csproj", "Src/Dlhis.Entity/"]
RUN dotnet restore "./Src/Dlhis.External/./Dlhis.External.csproj"
COPY . .
WORKDIR "/src/Src/Dlhis.External"
RUN dotnet build "./Dlhis.External.csproj" -c $BUILD_CONFIGURATION -o /app/build
FROM build AS publish
ARG BUILD_CONFIGURATION=Release
RUN dotnet publish "./Dlhis.External.csproj" -c $BUILD_CONFIGURATION -o /app/publish /p:UseAppHost=false
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "Dlhis.External.dll"]

View File

@@ -0,0 +1,37 @@
using Dlhis.Entity.Basic.Entity;
using Dlhis.External.MealSupplement.Request;
using Kurisu.AspNetCore.EventBus.Abstractions;
using Kurisu.AspNetCore.EventBus.Abstractions.Handler;
using Kurisu.SqlSugar.Services;
using Mapster;
namespace Dlhis.External.MealSupplement.Channel;
public class MealSupplementHandler : IAsyncChannelHandler<MealSupplementMessage>
{
private readonly IServiceProvider _serviceProvider;
public MealSupplementHandler(IServiceProvider serviceProvider)
{
_serviceProvider = serviceProvider;
}
public async Task InvokeAsync(MealSupplementMessage message)
{
using (var scope = _serviceProvider.CreateScope())
{
var db = scope.ServiceProvider.GetService<IDbContext>();
var existsIds = await db.Queryable<MealSupplementRecordEntity>().Select(x => x.UniqueId).ToListAsync();
var items = message.Items.Where(x => !existsIds.Contains(x.UniqueId)).ToList();
var entities = items.Adapt<List<MealSupplementRecordEntity>>();
await db.InsertAsync(entities);
}
}
}
public class MealSupplementMessage : IAsyncChannelMessage
{
public List<MealSupplementReceiveReuqest> Items { get; set; }
}

View File

@@ -0,0 +1,27 @@
using Dlhis.External.MealSupplement.Request;
using Dlhis.External.MealSupplement.Services;
using Microsoft.AspNetCore.Mvc;
namespace Dlhis.External.MealSupplement.Controller;
[Route("api/[controller]")]
[ApiController]
public class MealSupplementsController : ControllerBase
{
private readonly IMealSupplementService _mealSupplementService;
public MealSupplementsController(IMealSupplementService mealSupplementService)
{
_mealSupplementService = mealSupplementService;
}
/// <summary>
/// 接受餐补
/// </summary>
/// <returns></returns>
[HttpPost("receive")]
public async Task DoSupplements(List<MealSupplementReceiveReuqest> reuqests)
{
await _mealSupplementService.DoSupplementsAsync(reuqests);
}
}

View File

@@ -0,0 +1,45 @@
using System.ComponentModel.DataAnnotations;
namespace Dlhis.External.MealSupplement.Request;
public class MealSupplementReceiveReuqest
{
/// <summary>
/// 唯一号
/// </summary>
[Required(ErrorMessage = "唯一号必填")]
public string UniqueId { get; set; }
/// <summary>
/// 工号
/// </summary>
[Required(ErrorMessage = "工号必填")]
public string Code { get; set; }
/// <summary>
/// 考勤日期
/// </summary>
public DateTime Date { get; set; }
/// <summary>
/// 工作地
/// </summary>
[Required(ErrorMessage = "工作地")]
public string Workplace { get; set; }
/// <summary>
/// 厂区
/// </summary>
[Required(ErrorMessage = "厂区")]
public string Factory { get; set; }
/// <summary>
/// 备注
/// </summary>
public string Remark { get; set; }
/// <summary>
/// 餐补
/// </summary>
public decimal Amount { get; set; }
}

View File

@@ -0,0 +1,8 @@
using Dlhis.External.MealSupplement.Request;
namespace Dlhis.External.MealSupplement.Services;
public interface IMealSupplementService : IScopeDependency
{
Task DoSupplementsAsync(List<MealSupplementReceiveReuqest> reuqests);
}

View File

@@ -0,0 +1,23 @@
using Dlhis.External.MealSupplement.Channel;
using Dlhis.External.MealSupplement.Request;
using Kurisu.AspNetCore.EventBus.Abstractions;
using Kurisu.SqlSugar.Services;
namespace Dlhis.External.MealSupplement.Services.Implements;
public class MealSupplementService : IMealSupplementService
{
private readonly IEventBus _eventBus;
private readonly IDbContext _dbContext;
public MealSupplementService(IEventBus eventBus , IDbContext dbContext)
{
_eventBus = eventBus;
_dbContext = dbContext;
}
public async Task DoSupplementsAsync(List<MealSupplementReceiveReuqest> reuqests)
{
await _eventBus.PublishAsync(new MealSupplementMessage { Items = reuqests });
}
}

View File

@@ -0,0 +1,29 @@
using Kurisu.AspNetCore.EventBus.Extensions;
using Kurisu.AspNetCore.Startup;
using Kurisu.SqlSugar.Extensions;
using Kurisu.Startup;
using Microsoft.IdentityModel.Logging;
class Program
{
static void Main(string[] args)
{
KurisuHost.Run<Startup>(true, args);
}
}
public class Startup : DefaultStartup
{
public Startup(IConfiguration configuration) : base(configuration)
{
IdentityModelEventSource.ShowPII = true;
}
public override void ConfigureServices(IServiceCollection services)
{
base.ConfigureServices(services);
services.AddSqlSugar();
services.AddEventBus();
}
}

View File

@@ -0,0 +1,13 @@
{
"profiles": {
"Dlhis.External": {
"commandName": "Project",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
},
"dotnetRunMessages": true,
"applicationUrl": "http://localhost:5020"
}
},
"$schema": "https://json.schemastore.org/launchsettings.json"
}

View File

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

View File

@@ -0,0 +1,72 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
},
"AllowedHosts": "*",
"SqlSugarOptions": {
"DefaultConnectionString": "server=192.168.199.124;port=3306;userid=root;password=dlhis123;database=yikatong;charset=utf8mb4;",
"SlaveConnectionString": [],
"Timeout": 30,
"SlowSqlTime": 1,
"EnableSqlLog": false
},
"SwaggerOptions": {
"Enable": true,
"Authority": "http://identity.oauth.svc.cluster.local",
"ClientId": "4fb184324eac4180",
"ClientSecret": "8ac8f235152f1524",
"Scopes": {
"openid": "openid",
"profile": "profile",
"yikatong": "yikatong"
}
},
"IdentityServerOptions": {
"Authority": "http://identity.oauth.svc.cluster.local",
"RequireHttpsMetadata": false,
"Issuer": "identity.isawesome.cn",
"Audience": "",
"Pat": {
"Enable": false,
"Scheme": "token",
"ClientId": "reference",
"ClientSecret": "123456"
}
},
"Serilog": {
"MinimumLevel": {
"Default": "Information",
"Override": {
"System": "Warning",
"Microsoft": "Warning",
"Microsoft.Hosting.Lifetime": "Information"
}
},
"WriteTo": [
{
"Name": "Async",
"Args": {
"configure": [
{
"Name": "Console",
"Args": {
"outputTemplate": "[{Timestamp:HH:mm:ss} {Level:u3}] [{SourceContext}] {Message:lj}{NewLine}{Exception}"
}
},
{
"Name": "MySQL",
"Args": {
"connectionString": "server=192.168.199.124;port=3306;userid=root;password=dlhis123;database=log;charset=utf8mb4;",
"tableName": "Logs",
"autoCreateSqlTable": true
}
}
]
}
}
]
}
}