开始

parent aead617a
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.SignalR;
using Performance.Services;
using System;
using System.Collections.Generic;
using System.Linq;
......@@ -11,11 +13,19 @@ namespace Performance.Api.Controllers
[ApiController]
public class ValuesController : ControllerBase
{
private readonly IHubContext<AllotLogHub> hubContext;
public ValuesController(IHubContext<AllotLogHub> hubContext)
{
this.hubContext = hubContext;
}
// GET api/values
[HttpGet]
[AllowAnonymous]
public ActionResult<IEnumerable<string>> Get()
{
hubContext.Clients.Group("aaaa").SendAsync("ReceiveMessage", "绩效开始执行", "绩效开始执行");
//var excel = _excelService.Analyze(@"C:\Users\ry\Desktop\文件\测试.xlsx");
return new string[] { "value1", "value2" };
}
......
......@@ -14,12 +14,16 @@
<ItemGroup>
<Compile Remove="aaa\**" />
<Compile Remove="Files\**" />
<Compile Remove="Hubs\**" />
<Content Remove="aaa\**" />
<Content Remove="Files\**" />
<Content Remove="Hubs\**" />
<EmbeddedResource Remove="aaa\**" />
<EmbeddedResource Remove="Files\**" />
<EmbeddedResource Remove="Hubs\**" />
<None Remove="aaa\**" />
<None Remove="Files\**" />
<None Remove="Hubs\**" />
</ItemGroup>
<ItemGroup>
......@@ -41,6 +45,7 @@
<PackageReference Include="NLog.Extensions.Logging" Version="1.4.0" />
<PackageReference Include="NLog.Web.AspNetCore" Version="4.8.0" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="4.0.1" />
<PackageReference Include="Microsoft.AspNet.SignalR" Version="2.4.1" />
</ItemGroup>
<ItemGroup>
......
......@@ -147,6 +147,16 @@ public void ConfigureServices(IServiceCollection services)
});
#endregion
services.AddSignalR();
services.AddCors(options =>
{
options.AddPolicy("SignalrCore", policy =>
{
policy.SetIsOriginAllowed(origin => true).AllowAnyHeader().AllowAnyMethod().AllowCredentials();
});
});
#region //ef配置
services.AddDbContext<PerformanceDbContext>(options =>
{
......@@ -219,6 +229,10 @@ public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerF
app.UseHangfireDashboard("/hangfire", new DashboardOptions { Authorization = new[] { new HangfireAuthorizationFilter() } });
#endregion
app.UseCors("SignalrCore");
app.UseSignalR(routes => routes.MapHub<AllotLogHub>("/allotLogHub"));
loggerFactory.CreateLogger<Startup>().LogDebug(env.EnvironmentName);
app.UseMvc();
}
......
using AutoMapper;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.SignalR;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using Performance.DtoModels;
......@@ -34,6 +35,7 @@ public class AllotService : IAutoInjection
private PerforPeragainallotRepository _againallotRepository;
private PerforLogcheckRepository perforLogcheckRepository;
private readonly PerforHospitalRepository perforHospitalRepository;
private readonly IHubContext<AllotLogHub> hubContext;
public AllotService(PerforPerallotRepository allotRepository,
BaiscNormService baiscNormService,
......@@ -48,7 +50,8 @@ public class AllotService : IAutoInjection
IOptions<Application> options,
PerforPeragainallotRepository againallotRepository,
PerforLogcheckRepository perforLogcheckRepository,
PerforHospitalRepository perforHospitalRepository)
PerforHospitalRepository perforHospitalRepository,
IHubContext<AllotLogHub> hubContext)
{
_allotRepository = allotRepository;
_againallotRepository = againallotRepository;
......@@ -65,6 +68,7 @@ public class AllotService : IAutoInjection
this.logdbug = logdbug;
this.perforLogcheckRepository = perforLogcheckRepository;
this.perforHospitalRepository = perforHospitalRepository;
this.hubContext = hubContext;
}
#region 基础功能
......@@ -197,6 +201,7 @@ public void UpdateAllotStates(int allotId, int states, string remark)
{
_allotRepository.UpdateAllotStates(allotId, states, remark);
}
/// <summary>
/// 生成绩效
/// </summary>
......@@ -207,6 +212,7 @@ public void Generate(per_allot allot, string mail)
DateTime time = DateTime.Now;
try
{
hubContext.Clients.Group("aaaa").SendAsync("ReceiveMessage", "绩效开始执行", "绩效开始执行");
logdbug.Add(allot.ID, "绩效开始执行", JsonHelper.Serialize(allot));
configService.Clear(allot.ID);
UpdateAllotStates(allot.ID, (int)AllotStates.InCheckData, EnumHelper.GetDescription(AllotStates.InCheckData));
......
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.SignalR;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace Performance.Services
{
public class AllotLogHub : Hub
{
public override Task OnConnectedAsync()
{
return base.OnConnectedAsync();
}
public override Task OnDisconnectedAsync(Exception exception)
{
//1 查询用户分组信息
var groupName = "aaaa";
//2 删除数据库中用户分组数据
//3 分组中删除用户
Groups.RemoveFromGroupAsync(Context.ConnectionId, groupName);
return base.OnDisconnectedAsync(exception);
}
public async Task AddGroup(string token, string groupName)
{
//1 向数据库中插入用户及分组信息
//2 将用户插入分组
await Groups.AddToGroupAsync(Context.ConnectionId, groupName);
}
}
}
......@@ -13,6 +13,7 @@
<ItemGroup>
<PackageReference Include="CSRedisCore" Version="3.0.45" />
<PackageReference Include="DotNetCore.NPOI" Version="1.2.1" />
<PackageReference Include="Microsoft.AspNetCore.SignalR" Version="1.1.0" />
</ItemGroup>
<ItemGroup>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment