开始

parent aead617a
using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.SignalR;
using Performance.Services;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
...@@ -11,11 +13,19 @@ namespace Performance.Api.Controllers ...@@ -11,11 +13,19 @@ namespace Performance.Api.Controllers
[ApiController] [ApiController]
public class ValuesController : ControllerBase public class ValuesController : ControllerBase
{ {
private readonly IHubContext<AllotLogHub> hubContext;
public ValuesController(IHubContext<AllotLogHub> hubContext)
{
this.hubContext = hubContext;
}
// GET api/values // GET api/values
[HttpGet] [HttpGet]
[AllowAnonymous] [AllowAnonymous]
public ActionResult<IEnumerable<string>> Get() public ActionResult<IEnumerable<string>> Get()
{ {
hubContext.Clients.Group("aaaa").SendAsync("ReceiveMessage", "绩效开始执行", "绩效开始执行");
//var excel = _excelService.Analyze(@"C:\Users\ry\Desktop\文件\测试.xlsx"); //var excel = _excelService.Analyze(@"C:\Users\ry\Desktop\文件\测试.xlsx");
return new string[] { "value1", "value2" }; return new string[] { "value1", "value2" };
} }
......
...@@ -14,12 +14,16 @@ ...@@ -14,12 +14,16 @@
<ItemGroup> <ItemGroup>
<Compile Remove="aaa\**" /> <Compile Remove="aaa\**" />
<Compile Remove="Files\**" /> <Compile Remove="Files\**" />
<Compile Remove="Hubs\**" />
<Content Remove="aaa\**" /> <Content Remove="aaa\**" />
<Content Remove="Files\**" /> <Content Remove="Files\**" />
<Content Remove="Hubs\**" />
<EmbeddedResource Remove="aaa\**" /> <EmbeddedResource Remove="aaa\**" />
<EmbeddedResource Remove="Files\**" /> <EmbeddedResource Remove="Files\**" />
<EmbeddedResource Remove="Hubs\**" />
<None Remove="aaa\**" /> <None Remove="aaa\**" />
<None Remove="Files\**" /> <None Remove="Files\**" />
<None Remove="Hubs\**" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
...@@ -41,6 +45,7 @@ ...@@ -41,6 +45,7 @@
<PackageReference Include="NLog.Extensions.Logging" Version="1.4.0" /> <PackageReference Include="NLog.Extensions.Logging" Version="1.4.0" />
<PackageReference Include="NLog.Web.AspNetCore" Version="4.8.0" /> <PackageReference Include="NLog.Web.AspNetCore" Version="4.8.0" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="4.0.1" /> <PackageReference Include="Swashbuckle.AspNetCore" Version="4.0.1" />
<PackageReference Include="Microsoft.AspNet.SignalR" Version="2.4.1" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
......
...@@ -147,6 +147,16 @@ public void ConfigureServices(IServiceCollection services) ...@@ -147,6 +147,16 @@ public void ConfigureServices(IServiceCollection services)
}); });
#endregion #endregion
services.AddSignalR();
services.AddCors(options =>
{
options.AddPolicy("SignalrCore", policy =>
{
policy.SetIsOriginAllowed(origin => true).AllowAnyHeader().AllowAnyMethod().AllowCredentials();
});
});
#region //ef配置 #region //ef配置
services.AddDbContext<PerformanceDbContext>(options => services.AddDbContext<PerformanceDbContext>(options =>
{ {
...@@ -219,6 +229,10 @@ public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerF ...@@ -219,6 +229,10 @@ public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerF
app.UseHangfireDashboard("/hangfire", new DashboardOptions { Authorization = new[] { new HangfireAuthorizationFilter() } }); app.UseHangfireDashboard("/hangfire", new DashboardOptions { Authorization = new[] { new HangfireAuthorizationFilter() } });
#endregion #endregion
app.UseCors("SignalrCore");
app.UseSignalR(routes => routes.MapHub<AllotLogHub>("/allotLogHub"));
loggerFactory.CreateLogger<Startup>().LogDebug(env.EnvironmentName); loggerFactory.CreateLogger<Startup>().LogDebug(env.EnvironmentName);
app.UseMvc(); app.UseMvc();
} }
......
using AutoMapper; using AutoMapper;
using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.SignalR;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options; using Microsoft.Extensions.Options;
using Performance.DtoModels; using Performance.DtoModels;
...@@ -34,6 +35,7 @@ public class AllotService : IAutoInjection ...@@ -34,6 +35,7 @@ public class AllotService : IAutoInjection
private PerforPeragainallotRepository _againallotRepository; private PerforPeragainallotRepository _againallotRepository;
private PerforLogcheckRepository perforLogcheckRepository; private PerforLogcheckRepository perforLogcheckRepository;
private readonly PerforHospitalRepository perforHospitalRepository; private readonly PerforHospitalRepository perforHospitalRepository;
private readonly IHubContext<AllotLogHub> hubContext;
public AllotService(PerforPerallotRepository allotRepository, public AllotService(PerforPerallotRepository allotRepository,
BaiscNormService baiscNormService, BaiscNormService baiscNormService,
...@@ -48,7 +50,8 @@ public class AllotService : IAutoInjection ...@@ -48,7 +50,8 @@ public class AllotService : IAutoInjection
IOptions<Application> options, IOptions<Application> options,
PerforPeragainallotRepository againallotRepository, PerforPeragainallotRepository againallotRepository,
PerforLogcheckRepository perforLogcheckRepository, PerforLogcheckRepository perforLogcheckRepository,
PerforHospitalRepository perforHospitalRepository) PerforHospitalRepository perforHospitalRepository,
IHubContext<AllotLogHub> hubContext)
{ {
_allotRepository = allotRepository; _allotRepository = allotRepository;
_againallotRepository = againallotRepository; _againallotRepository = againallotRepository;
...@@ -65,6 +68,7 @@ public class AllotService : IAutoInjection ...@@ -65,6 +68,7 @@ public class AllotService : IAutoInjection
this.logdbug = logdbug; this.logdbug = logdbug;
this.perforLogcheckRepository = perforLogcheckRepository; this.perforLogcheckRepository = perforLogcheckRepository;
this.perforHospitalRepository = perforHospitalRepository; this.perforHospitalRepository = perforHospitalRepository;
this.hubContext = hubContext;
} }
#region 基础功能 #region 基础功能
...@@ -197,6 +201,7 @@ public void UpdateAllotStates(int allotId, int states, string remark) ...@@ -197,6 +201,7 @@ public void UpdateAllotStates(int allotId, int states, string remark)
{ {
_allotRepository.UpdateAllotStates(allotId, states, remark); _allotRepository.UpdateAllotStates(allotId, states, remark);
} }
/// <summary> /// <summary>
/// 生成绩效 /// 生成绩效
/// </summary> /// </summary>
...@@ -207,6 +212,7 @@ public void Generate(per_allot allot, string mail) ...@@ -207,6 +212,7 @@ public void Generate(per_allot allot, string mail)
DateTime time = DateTime.Now; DateTime time = DateTime.Now;
try try
{ {
hubContext.Clients.Group("aaaa").SendAsync("ReceiveMessage", "绩效开始执行", "绩效开始执行");
logdbug.Add(allot.ID, "绩效开始执行", JsonHelper.Serialize(allot)); logdbug.Add(allot.ID, "绩效开始执行", JsonHelper.Serialize(allot));
configService.Clear(allot.ID); configService.Clear(allot.ID);
UpdateAllotStates(allot.ID, (int)AllotStates.InCheckData, EnumHelper.GetDescription(AllotStates.InCheckData)); 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 @@ ...@@ -13,6 +13,7 @@
<ItemGroup> <ItemGroup>
<PackageReference Include="CSRedisCore" Version="3.0.45" /> <PackageReference Include="CSRedisCore" Version="3.0.45" />
<PackageReference Include="DotNetCore.NPOI" Version="1.2.1" /> <PackageReference Include="DotNetCore.NPOI" Version="1.2.1" />
<PackageReference Include="Microsoft.AspNetCore.SignalR" Version="1.1.0" />
</ItemGroup> </ItemGroup>
<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