Commit e36acb62 by lcx

修改返回日志方式

parent 9182833f
......@@ -3,6 +3,7 @@
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Http.Internal;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Caching.Memory;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Performance.DtoModels;
......@@ -235,13 +236,13 @@ public ApiResponse Generate([CustomizeValidator(RuleSet = "Delete"), FromBody] A
if (allot.States == (int)AllotStates.Wait)
return new ApiResponse(ResponseType.OK, "当前绩效正在等待生成");
int userId = _claim.GetUserId();
var uuid = Guid.NewGuid().ToString("N");
_notificationsService.SendGenerateMessage(userId, allot.ID, $"准备生成{allot.Year}-{allot.Month.ToString().PadLeft(2, '0')}月份绩效,请稍等!");
string key = NotificationsService.AllotGenerateKeyPrefix + allot.ID;
_notificationsService.SetCache(key, new SingleData(Guid.NewGuid().ToString("N"), _claim.GetUserId()));
_notificationsService.SendGenerateMessage(allot.ID, $"准备生成{allot.Year}-{allot.Month.ToString().PadLeft(2, '0')}月份绩效,请稍等!");
_allotService.UpdateAllotStates(allot.ID, (int)AllotStates.Wait, EnumHelper.GetDescription(AllotStates.Wait), allot.Generate);
if (_evn.IsEnvironment("Localhost"))
{
_allotService.Generate(allot, email, uuid, userId);
_allotService.Generate(allot, email);
}
else
{
......@@ -252,13 +253,13 @@ public ApiResponse Generate([CustomizeValidator(RuleSet = "Delete"), FromBody] A
using (var scope = _serviceScopeFactory.CreateScope())
{
var scopedServices = scope.ServiceProvider.GetRequiredService<AllotService>();
scopedServices.Generate(allot, email, uuid, userId);
scopedServices.Generate(allot, email);
await Task.Delay(TimeSpan.FromSeconds(5), token);
}
});
}
_notificationsService.SendGenerateMessage(userId, allot.ID, $"等待绩效生成{allot.Year}-{allot.Month.ToString().PadLeft(2, '0')}月份绩效,请稍等!");
_notificationsService.SendGenerateMessage(allot.ID, $"等待绩效生成{allot.Year}-{allot.Month.ToString().PadLeft(2, '0')}月份绩效,请稍等!");
//_allotService.Generate(allot, email);
////BackgroundJob.Enqueue(() => _allotService.Generate(allot, email));
return new ApiResponse(ResponseType.OK);
......
......@@ -35,7 +35,7 @@ public class TemplateController : Controller
private readonly ExConfigService configService;
private readonly HospitalService hospitalService;
private readonly AllotService allotService;
private readonly LogManageService logService;
private readonly NotificationsService notificationsService;
private readonly IServiceScopeFactory serviceScopeFactory;
public TemplateController(
......@@ -49,7 +49,7 @@ public class TemplateController : Controller
ExConfigService configService,
HospitalService hospitalService,
AllotService allotService,
LogManageService logService,
NotificationsService notificationsService,
IServiceScopeFactory serviceScopeFactory)
{
this.logger = logger;
......@@ -62,7 +62,7 @@ public class TemplateController : Controller
this.configService = configService;
this.hospitalService = hospitalService;
this.allotService = allotService;
this.logService = logService;
this.notificationsService = notificationsService;
this.serviceScopeFactory = serviceScopeFactory;
}
......@@ -365,18 +365,10 @@ public ApiResponse SaveFile()
/// <param name="request"></param>
[Route("returnlog")]
[HttpPost]
[AllowAnonymous]
public void ReturnLog([FromBody] SignalrLogRequest request)
public void ReturnLog([FromBody] MessageInfo request)
{
logger.LogInformation("返回日志:" + JsonHelper.Serialize(request));
if (request.Type == 3)
{
logService.Schedule(request.GroupName, ConvertHelper.To<decimal>(request.Message), request.Level);
}
else
{
logService.ExtractLog(request.GroupName, request.Tag, request.Message, request.Level);
}
notificationsService.SendMessage(claim.GetUserId(), request);
}
/// <summary>
......
using System;
using System.Collections.Generic;
using System.Text;
namespace Performance.DtoModels
{
public class SingleData
{
public string Uuid { get; set; }
public int UserId { get; set; }
public SingleData()
{
}
public SingleData(string uuid, int userId)
{
Uuid = uuid;
UserId = userId;
}
}
}
......@@ -30,8 +30,7 @@ public class ImportDataService : IAutoInjection
private PerforImspecialunitRepository perforImspecialunitRepository;
private PerforImemployeeclinicRepository perforImemployeeclinicRepository;
private PerforImemployeelogisticsRepository perforImemployeelogisticsRepository;
//private PerforLogdbugRepository logdbug;
private readonly LogManageService logManageService;
private readonly NotificationsService notificationsService;
private ILogger<ImportDataService> logger;
public ImportDataService(PerSheetService perSheetService,
......@@ -44,8 +43,7 @@ public class ImportDataService : IAutoInjection
PerforImspecialunitRepository perforImspecialunitRepository,
PerforImemployeeclinicRepository perforImemployeeclinicRepository,
PerforImemployeelogisticsRepository perforImemployeelogisticsRepository,
//PerforLogdbugRepository logdbug
LogManageService logManageService,
NotificationsService notificationsService,
ILogger<ImportDataService> logger)
{
this.perSheetService = perSheetService;
......@@ -58,8 +56,7 @@ public class ImportDataService : IAutoInjection
this.perforImspecialunitRepository = perforImspecialunitRepository;
this.perforImemployeeclinicRepository = perforImemployeeclinicRepository;
this.perforImemployeelogisticsRepository = perforImemployeelogisticsRepository;
//this.logdbug = logdbug;
this.logManageService = logManageService;
this.notificationsService = notificationsService;
this.logger = logger;
}
......@@ -111,7 +108,7 @@ private PerExcel Import(per_allot allot)
}
if (SheetType.Unidentifiable != sheetType)
{
logManageService.WriteMsg("开始读取excel文件", $"开始读取sheet -- {sheet.SheetName}", 1, allot.ID, "ReceiveMessage", true);
notificationsService.SendGenerateMessage(allot.ID, $"开始读取excel文件:开始读取sheet -- {sheet.SheetName}");
try
{
var st = perSheetService.Sheet(sheet, isnew);
......@@ -119,7 +116,7 @@ private PerExcel Import(per_allot allot)
}
catch (Exception ex)
{
logManageService.WriteMsg("读取excel文件", ex.Message.ToString(), 4, allot.ID, "ReceiveMessage", true);
notificationsService.SendGenerateMessage(allot.ID, $"读取excel文件:{ex.Message}。", ComponentType.error);
throw ex;
}
}
......@@ -129,7 +126,7 @@ private PerExcel Import(per_allot allot)
isnew = true;
}
}
logManageService.WriteMsg("开始读取excel文件", $"excel文件基础数据读取完成!", 1, allot.ID, "ReceiveMessage", true);
notificationsService.SendGenerateMessage(allot.ID, $"开始读取excel文件:excel文件基础数据读取完成!");
return excel;
}
}
......@@ -391,7 +388,7 @@ private bool Save(PerExcel excel, int allotId)
{
foreach (var sheet in excel.PerSheet)
{
logManageService.WriteMsg("保存基础数据", $"开始保存数据 -- {sheet.SheetName}", 1, allotId, "ReceiveMessage", true);
notificationsService.SendGenerateMessage(allotId, $"保存基础数据:开始保存数据 -- {sheet.SheetName}。");
if (sheet.SheetType == SheetType.Employee)
{
var imsheetid = SaveEmployee(sheet, allotId);
......@@ -423,7 +420,7 @@ private bool Save(PerExcel excel, int allotId)
SaveHeader(sheet, allotId, imsheetid);
}
}
logManageService.WriteMsg("保存基础数据", $"基础数据保存完成!", 1, allotId, "ReceiveMessage", true);
notificationsService.SendGenerateMessage(allotId, $"保存基础数据:基础数据保存完成!");
return true;
}
}
......
......@@ -27,7 +27,7 @@ public class ProcessComputService : IAutoInjection
private PerforCofdrugtypeRepository perforCofdrugtypeRepository;
private PerforCofworkitemRepository perforCofworkitemRepository;
private readonly PerforRescomputeRepository perforRescomputeRepository;
private readonly LogManageService logManageService;
private readonly NotificationsService notificationsService;
private readonly GuaranteeService guaranteeService;
private readonly PerforHospitalRepository hospitalRepository;
private readonly PerforPerallotRepository perallotRepository;
......@@ -44,7 +44,7 @@ public class ProcessComputService : IAutoInjection
PerforCofdrugtypeRepository perforCofdrugtypeRepository,
PerforCofworkitemRepository perforCofworkitemRepository,
PerforRescomputeRepository perforRescomputeRepository,
LogManageService logManageService,
NotificationsService notificationsService,
GuaranteeService guaranteeService,
PerforHospitalRepository hospitalRepository,
PerforPerallotRepository perallotRepository)
......@@ -60,7 +60,7 @@ public class ProcessComputService : IAutoInjection
this.perforCofdrugtypeRepository = perforCofdrugtypeRepository;
this.perforCofworkitemRepository = perforCofworkitemRepository;
this.perforRescomputeRepository = perforRescomputeRepository;
this.logManageService = logManageService;
this.notificationsService = notificationsService;
this.guaranteeService = guaranteeService;
this.hospitalRepository = hospitalRepository;
this.perallotRepository = perallotRepository;
......@@ -162,7 +162,7 @@ public void Save(List<PerSheet> perSheets, int allotId)
{
foreach (var sheet in perSheets)
{
logManageService.WriteMsg("正在生成绩效", $"保存核算数据 - {sheet.SheetName}", 1, allotId, "ReceiveMessage");
notificationsService.SendGenerateMessage(allotId, $"正在生成绩效:保存核算数据 - {sheet.SheetName}");
if (sheet.SheetType == SheetType.ComputeDoctorAccount || sheet.SheetType == SheetType.ComputeNurseAccount)
{
SaveComputeAccount(sheet, allotId);
......
......@@ -17,7 +17,6 @@ public class ConfigService : IAutoInjection
{
#region
private PerforCofdirectorRepository _directorRepository;
//private PerforCofdrugpropRepository _drugpropRepository;
private PerforCofworkitemRepository _workitemRepository;
private PerforCofagainRepository _againRepository;
private PerforCofdrugtypeRepository _drugtypeRepository;
......@@ -27,14 +26,12 @@ public class ConfigService : IAutoInjection
private PerforImheaderRepository perforImheaderRepository;
private PerforCofdepttypeRepository perforCofdepttypeRepository;
private PerforPerapramountRepository perapramountRepository;
//private PerforCofcmiRepository perforCofcmiRepository;
private PerforCofHrpDeptRepository perforCofHrpDeptRepository;
private PersonService personService;
private LogManageService logManageService;
private NotificationsService notificationsService;
private ILogger<ConfigService> logger;
public ConfigService(PerforCofdirectorRepository cofdirectorRepository,
//PerforCofdrugpropRepository cofdrugpropRepository,
PerforCofagainRepository againRepository,
PerforCofdrugtypeRepository drugtypeRepository,
PerforPerallotRepository perforPerAllotRepository,
......@@ -44,14 +41,12 @@ public class ConfigService : IAutoInjection
PerforImheaderRepository perforImheaderRepository,
PerforCofdepttypeRepository perforCofdepttypeRepository,
PerforPerapramountRepository perapramountRepository,
//PerforCofcmiRepository perforCofcmiRepository,
PerforCofHrpDeptRepository perforCofHrpDeptRepository,
PersonService personService,
LogManageService logManageService,
NotificationsService notificationsService,
ILogger<ConfigService> logger)
{
this._directorRepository = cofdirectorRepository;
//this._drugpropRepository = cofdrugpropRepository;
this._workitemRepository = workitemRepository;
this._againRepository = againRepository;
this._drugtypeRepository = drugtypeRepository;
......@@ -64,7 +59,7 @@ public class ConfigService : IAutoInjection
//this.perforCofcmiRepository = perforCofcmiRepository;
this.perforCofHrpDeptRepository = perforCofHrpDeptRepository;
this.personService = personService;
this.logManageService = logManageService;
this.notificationsService = notificationsService;
this.logger = logger;
}
......@@ -753,7 +748,7 @@ public void Copy(per_allot allot)
public void Clear(int allotId)
{
var count = _directorRepository.DeleteData(allotId);
logManageService.WriteMsg("清理无效数据", $"清理无效数据,受影响行数:{count}", 1, allotId, "ReceiveMessage", true);
notificationsService.SendGenerateMessage(allotId, $"清理无效数据:清理无效数据,受影响行数:{count}。");
}
/// <summary>
......@@ -763,7 +758,7 @@ public void Clear(int allotId)
public void ClearAllotData(int allotId)
{
var count = _directorRepository.DeleteAllotData(allotId);
logManageService.WriteMsg("清理无效数据", $"清理无效数据,受影响行数:{count}", 1, allotId, "ReceiveMessage", true);
notificationsService.SendGenerateMessage(allotId, $"清理无效数据:清理无效数据,受影响行数:{count}。");
}
/// <summary>
......@@ -773,7 +768,7 @@ public void ClearAllotData(int allotId)
public void ClearResData(int allotId)
{
var count = _directorRepository.DeleteResData(allotId);
logManageService.WriteMsg("清理无效数据", $"清理无效数据,受影响行数:{count}", 1, allotId, "ReceiveMessage", true);
notificationsService.SendGenerateMessage(allotId, $"清理无效数据:清理无效数据,受影响行数:{count}。");
}
/// <summary>
......@@ -783,7 +778,7 @@ public void ClearResData(int allotId)
public void ClearAgain(int againId)
{
var count = _directorRepository.DelAgain(againId);
logManageService.WriteMsg("清理无效数据", $"清除二次绩效中无效数据,受影响行数:{count}", 1, againId, "ReceiveMessage", true);
//notificationsService.SendGenerateMessage(againId, $"清理无效数据:清除二次绩效中无效数据,受影响行数:{count}。");
}
#endregion
......@@ -838,7 +833,7 @@ private void CopyAprData(int prevAllotId, int allotId)
}
}
public HandsonTable GetHrpDeptHands(int HospitalId,int AllotId)
public HandsonTable GetHrpDeptHands(int HospitalId, int AllotId)
{
var result = new HandsonTable((int)SheetType.Unidentifiable, HrpDept.Select(t => t.Value).ToArray(), HrpDept.Select(t => new collect_permission
{
......@@ -866,9 +861,9 @@ public HandsonTable GetHrpDeptHands(int HospitalId,int AllotId)
return result;
}
public void SaveDepttypeHands(int hospitalId, int allotId,SaveCollectData request)
public void SaveDepttypeHands(int hospitalId, int allotId, SaveCollectData request)
{
var dicData = CreateDataRow(hospitalId,allotId, request, HrpDept);
var dicData = CreateDataRow(hospitalId, allotId, request, HrpDept);
List<cof_hrp_department> depts = new List<cof_hrp_department>();
foreach (var item in dicData)
......@@ -884,7 +879,7 @@ public void SaveDepttypeHands(int hospitalId, int allotId,SaveCollectData reques
}
perforCofHrpDeptRepository.Execute("delete from cof_hrp_department where HospitalId=@hospitalId and allotid = @allotid"
, new {hospitalId, allotId });
, new { hospitalId, allotId });
perforCofHrpDeptRepository.AddRange(depts.ToArray());
}
......@@ -897,7 +892,7 @@ public void SaveDepttypeHands(int hospitalId, int allotId,SaveCollectData reques
// 创建固定数据列
Dictionary<string, string> baseData = CreateBaseData(request, config, r);
baseData.Add(nameof(cof_hrp_department.AllotId), allotId.ToString());
baseData.Add(nameof(cof_hrp_department.HospitalId),hospitalId.ToString());
baseData.Add(nameof(cof_hrp_department.HospitalId), hospitalId.ToString());
allData.Add(baseData);
}
......
......@@ -13,29 +13,22 @@ namespace Performance.Services
[Authorize]
public class AllotLogHub : Hub
{
private readonly IMemoryCache cache;
private readonly ILogger<AllotLogHub> logger;
private readonly NotificationsService service;
public AllotLogHub(
IMemoryCache cache,
ILogger<AllotLogHub> logger
ILogger<AllotLogHub> logger,
NotificationsService service
)
{
this.cache = cache;
this.logger = logger;
this.service = service;
}
public override Task OnConnectedAsync()
{
string key = Context.User.Claims.FirstOrDefault(t => t.Type == "id")?.Value;
if (!string.IsNullOrEmpty(key))
{
if (cache.TryGetValue(key, out _))
{
cache.Remove(key);
}
cache.Set(key, Context.ConnectionId);
}
service.SetCache(key, Context.ConnectionId);
logger.LogInformation($"用户在{DateTime.Now.ToString("yyyy年MM月dd日 hh时mm分ss秒")}创建连接");
return base.OnConnectedAsync();
}
......@@ -43,13 +36,7 @@ public override Task OnConnectedAsync()
public override Task OnDisconnectedAsync(Exception exception)
{
string key = Context.User.Claims.FirstOrDefault(t => t.Type == "id")?.Value;
if (!string.IsNullOrEmpty(key))
{
if (cache.TryGetValue(key, out _))
{
cache.Remove(key);
}
}
service.RemoveCache(key);
logger.LogInformation($"用户在{DateTime.Now.ToString("yyyy年MM月dd日 hh时mm分ss秒")}断开连接");
return base.OnDisconnectedAsync(exception);
}
......
......@@ -32,18 +32,30 @@ PerforLogdsignalrRepository repository
this.repository = repository;
}
public void SendGenerateMessage(int userId, int allotId, string message, ComponentType type = ComponentType.info)
public const string AllotGenerateKeyPrefix = "Allot-Generate-";
public void SendGenerateMessage(int allotId, string message, ComponentType type = ComponentType.info)
{
var info = new MessageInfo("", allotId, "生成绩效", message, Component.Notification, type);
SendMessage(userId, info);
}
var data = GetCache<SingleData>(AllotGenerateKeyPrefix + allotId);
if (data == null || data.UserId == 0)
return;
var info = new MessageInfo(data.Uuid, allotId, "生成绩效", message, Component.Notification, type);
SendMessage(data.UserId, info);
}
public void SendMessage(int userId, MessageInfo data)
{
string key = userId.ToString();
if (cache.TryGetValue(key, out string connectionId) && !string.IsNullOrEmpty(connectionId))
{
if (data.Component == Component.Progress)
{
var percentage = ConvertHelper.To<decimal>(data.Message);
data.Message = (data.Status == ComponentType.success
? 100
: (data.Status != ComponentType.success && percentage >= 100) ? 99 : percentage).ToString();
}
SendMessageToClient(connectionId, data);
}
}
......@@ -57,5 +69,64 @@ private void SendMessageToClient(string connectionId, MessageInfo data, string m
{
hubContext.Clients.Client(connectionId).SendAsync(method, data.Title, data);
}
#region 缓存
/// <summary>
/// 添加缓存
/// </summary>
/// <param name="key">缓存Key</param>
/// <param name="value">缓存Value</param>
public void SetCache(string key, object value)
{
if (!string.IsNullOrEmpty(key))
{
if (cache.TryGetValue(key, out _))
{
cache.Remove(key);
}
cache.Set(key, value);
}
}
/// <summary>
/// 删除缓存
/// </summary>
/// <param name="key">缓存Key</param>
public void RemoveCache(string key)
{
if (!string.IsNullOrEmpty(key))
{
cache.Remove(key);
}
}
/// <summary>
/// 获取缓存
/// </summary>
/// <param name="key">缓存Key</param>
/// <returns></returns>
public T GetCache<T>(string key) where T : class
{
if (key == null)
throw new ArgumentNullException(nameof(key));
return cache.Get(key) as T;
}
/// <summary>
/// 获取缓存
/// </summary>
/// <param name="key">缓存Key</param>
/// <returns></returns>
public object GetCache(string key)
{
if (key == null)
throw new ArgumentNullException(nameof(key));
return cache.Get(key);
}
#endregion
}
}
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