Commit bf9ab1bf by ruyun.zhang@suvalue.com

Merge branch 'feature/后台任务' into develop

parents 5745c293 545574cd
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using Performance.Services.Queues;
using System;
using System.Threading;
using System.Threading.Tasks;
namespace Performance.Api
{
public class QueuedHostedService : BackgroundService
{
private readonly ILogger<QueuedHostedService> _logger;
public QueuedHostedService(
IBackgroundTaskQueue taskQueue,
ILogger<QueuedHostedService> logger)
{
TaskQueue = taskQueue;
_logger = logger;
}
public IBackgroundTaskQueue TaskQueue { get; }
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
{
_logger.LogInformation(
$"Queued Hosted Service is running.{Environment.NewLine} {Environment.NewLine}Tap W to add a work item to the background queue.{Environment.NewLine}");
await BackgroundProcessing(stoppingToken);
}
private async Task BackgroundProcessing(CancellationToken stoppingToken)
{
while (!stoppingToken.IsCancellationRequested)
{
var workItem =
await TaskQueue.DequeueAsync(stoppingToken);
try
{
await workItem(stoppingToken);
}
catch (Exception ex)
{
_logger.LogError(ex,
"Error occurred executing {WorkItem}.", nameof(workItem));
}
}
}
public override async Task StopAsync(CancellationToken stoppingToken)
{
_logger.LogInformation("Queued Hosted Service is stopping.");
await base.StopAsync(stoppingToken);
}
}
}
//using Microsoft.Extensions.Hosting;
//using Microsoft.Extensions.Logging;
//using Performance.Services.Queues;
//using System;
//using System.Threading;
//using System.Threading.Tasks;
//namespace Performance.Api
//{
// public class QueuedHostedService : BackgroundService
// {
// private readonly ILogger<QueuedHostedService> _logger;
// public QueuedHostedService(
// IBackgroundTaskQueue taskQueue,
// ILogger<QueuedHostedService> logger)
// {
// TaskQueue = taskQueue;
// _logger = logger;
// }
// public IBackgroundTaskQueue TaskQueue { get; }
// protected override async Task ExecuteAsync(CancellationToken stoppingToken)
// {
// _logger.LogInformation(
// $"Queued Hosted Service is running.{Environment.NewLine} {Environment.NewLine}Tap W to add a work item to the background queue.{Environment.NewLine}");
// await BackgroundProcessing(stoppingToken);
// }
// private async Task BackgroundProcessing(CancellationToken stoppingToken)
// {
// while (!stoppingToken.IsCancellationRequested)
// {
// var workItem =
// await TaskQueue.DequeueAsync(stoppingToken);
// try
// {
// await workItem(stoppingToken);
// }
// catch (Exception ex)
// {
// _logger.LogError(ex,
// "Error occurred executing {WorkItem}.", nameof(workItem));
// }
// }
// }
// public override async Task StopAsync(CancellationToken stoppingToken)
// {
// _logger.LogInformation("Queued Hosted Service is stopping.");
// await base.StopAsync(stoppingToken);
// }
// }
//}
......@@ -23,6 +23,7 @@ public static void AddDatabaseConfiguration(this IServiceCollection services)
optionBuilder =>
{
optionBuilder.EnableStringComparisonTranslations(true);
optionBuilder.EnableRetryOnFailure();
});
}, ServiceLifetime.Transient);
}
......
......@@ -46,8 +46,8 @@ public static void AddDependencyInjectionConfiguration(this IServiceCollection s
#endregion redis
services.AddHostedService<QueuedHostedService>();
services.AddSingleton<IBackgroundTaskQueue, BackgroundTaskQueue>();
//services.AddHostedService<QueuedHostedService>();
//services.AddSingleton<IBackgroundTaskQueue, BackgroundTaskQueue>();
services.AddSingleton<IHubNotificationQueue, HubNotificationQueue>();
services
......
......@@ -34,8 +34,9 @@ public class AllotController : Controller
private ILogger<AllotController> _logger;
private ClaimService _claim;
private LogManageService _logManageService;
private readonly TaskService _taskService;
private readonly CostTransferService costTransferService;
private IBackgroundTaskQueue _backgroundTaskQueue;
//private IBackgroundTaskQueue _backgroundTaskQueue;
private IServiceScopeFactory _serviceScopeFactory;
public AllotController(AllotService allotService,
......@@ -43,10 +44,11 @@ public class AllotController : Controller
ConfigService configService,
ILogger<AllotController> logger,
IWebHostEnvironment evn,
IBackgroundTaskQueue backgroundTaskQueue,
//IBackgroundTaskQueue backgroundTaskQueue,
IServiceScopeFactory serviceScopeFactory,
ClaimService claim,
LogManageService logManageService,
TaskService taskService,
CostTransferService costTransferService)
{
_allotService = allotService;
......@@ -55,9 +57,10 @@ public class AllotController : Controller
_evn = evn;
_claim = claim;
_logManageService = logManageService;
_taskService = taskService;
this.costTransferService = costTransferService;
_configService = configService;
_backgroundTaskQueue = backgroundTaskQueue;
//_backgroundTaskQueue = backgroundTaskQueue;
_serviceScopeFactory = serviceScopeFactory;
}
......@@ -252,28 +255,47 @@ public ApiResponse GenerateAsync([CustomizeValidator(RuleSet = "Delete"), FromBo
var allot = _allotService.GetAllot(request.ID);
if (null == allot || string.IsNullOrEmpty(allot.Path))
throw new PerformanceException("当前绩效记录不存在或没有上传数据文件");
if (allot.States == (int)AllotStates.Wait)
return new ApiResponse(ResponseType.OK, "当前绩效正在等待生成");
_logManageService.WriteMsg("生成绩效准备中", $"准备生成{allot.Year}-{allot.Month.ToString().PadLeft(2, '0')}月份绩效,请稍等!", 1, allot.ID, "ReceiveMessage", true);
_allotService.UpdateAllotStates(allot.ID, (int)AllotStates.Wait, EnumHelper.GetDescription(AllotStates.Wait), allot.Generate);
//if (_evn.IsEnvironment("Localhost"))
//{
// var tasks = _taskService.GetTasks(-1);
// var status = new int[] { (int)Background.Status.等待, (int)Background.Status.执行中 };
// if (tasks.Any(w => w.Argument == allot.ID.ToString() && w.JobType == (int)Background.JobType.生成测算表 && status.Contains(w.Status)))
// return new ApiResponse(ResponseType.OK, "当前绩效正在生成中,请等待生成完成后重新生成");
// if (allot.States == (int)AllotStates.Wait)
// return new ApiResponse(ResponseType.OK, "当前绩效正在等待生成");
// _logManageService.WriteMsg("生成绩效准备中", $"准备生成{allot.Year}-{allot.Month.ToString().PadLeft(2, '0')}月份绩效,请稍等!", 1, allot.ID, "ReceiveMessage", true);
// _allotService.UpdateAllotStates(allot.ID, (int)AllotStates.Wait, EnumHelper.GetDescription(AllotStates.Wait), allot.Generate);
// _allotService.Generate(allot);
//}
//else
//{
_backgroundTaskQueue.QueueBackgroundWorkItem(async token =>
{
using (var scope = _serviceScopeFactory.CreateScope())
{
var scopedServices = scope.ServiceProvider.GetRequiredService<AllotService>();
scopedServices.Generate(allot);
await Task.Delay(TimeSpan.FromSeconds(5), token);
}
});
//_publishEndpoint.Publish(allot).Wait();
var tasks = _taskService.GetTasks(-1);
var status = new int[] { (int)Background.Status.等待, (int)Background.Status.执行中 };
if (tasks.Any(w => w.Argument == allot.ID.ToString() && w.JobType == (int)Background.JobType.生成测算表 && status.Contains(w.Status)))
return new ApiResponse(ResponseType.OK, "当前绩效正在生成中,请等待生成完成后重新生成");
if (allot.States == (int)AllotStates.Wait)
return new ApiResponse(ResponseType.OK, "当前绩效正在等待生成");
_logManageService.WriteMsg("生成绩效准备中", $"准备生成{allot.Year}-{allot.Month.ToString().PadLeft(2, '0')}月份绩效,请稍等!", 1, allot.ID, "ReceiveMessage", true);
_allotService.UpdateAllotStates(allot.ID, (int)AllotStates.Wait, EnumHelper.GetDescription(AllotStates.Wait), allot.Generate);
//_backgroundTaskQueue.QueueBackgroundWorkItem(async token =>
//{
// using (var scope = _serviceScopeFactory.CreateScope())
// {
// var scopedServices = scope.ServiceProvider.GetRequiredService<AllotService>();
// scopedServices.Generate(allot);
// await Task.Delay(TimeSpan.FromSeconds(5), token);
// }
//});
_taskService.Add(Background.JobType.生成测算表, allot.ID.ToString());
//}
_logManageService.WriteMsg("等待绩效生成", $"等待绩效生成{allot.Year}-{allot.Month.ToString().PadLeft(2, '0')}月份绩效!", 1, allot.ID, "ReceiveMessage");
......@@ -297,15 +319,16 @@ public ApiResponse GenerateReport([CustomizeValidator(RuleSet = "Delete"), FromB
if (null == allot || !states.Contains(allot.States))
throw new PerformanceException("当前绩效暂未生成,无法统计报表数据。");
_backgroundTaskQueue.QueueBackgroundWorkItem(async token =>
{
using (var scope = _serviceScopeFactory.CreateScope())
{
var scopedServices = scope.ServiceProvider.GetRequiredService<AllotService>();
scopedServices.GenerateReport(allot);
await Task.Delay(TimeSpan.FromSeconds(5), token);
}
});
//_backgroundTaskQueue.QueueBackgroundWorkItem(async token =>
//{
// using (var scope = _serviceScopeFactory.CreateScope())
// {
// var scopedServices = scope.ServiceProvider.GetRequiredService<AllotService>();
// scopedServices.GenerateReport(allot);
// await Task.Delay(TimeSpan.FromSeconds(5), token);
// }
//});
_taskService.Add(Background.JobType.报表, allot.ID.ToString());
return new ApiResponse(ResponseType.OK, "统计报表数据任务开始");
}
......
......@@ -18,24 +18,27 @@ public class ModExtractController : Controller
{
private readonly ClaimService _claim;
private readonly AllotService _allotService;
private readonly TaskService _taskService;
private readonly CustomExtractService _extractService;
private readonly IServiceScopeFactory _serviceScopeFactory;
private readonly IBackgroundTaskQueue _backgroundTaskQueue;
//private readonly IBackgroundTaskQueue _backgroundTaskQueue;
private readonly IHubNotificationQueue _notificationQueue;
public ModExtractController(
ClaimService claim,
AllotService allotService,
TaskService taskService,
CustomExtractService extractService,
IServiceScopeFactory serviceScopeFactory,
IBackgroundTaskQueue backgroundTaskQueue,
//IBackgroundTaskQueue backgroundTaskQueue,
IHubNotificationQueue notificationQueue)
{
_claim = claim;
_allotService = allotService;
_taskService = taskService;
_extractService = extractService;
_serviceScopeFactory = serviceScopeFactory;
_backgroundTaskQueue = backgroundTaskQueue;
//_backgroundTaskQueue = backgroundTaskQueue;
_notificationQueue = notificationQueue;
}
......@@ -46,27 +49,30 @@ public ApiResponse CustomExtract(int allotId)
if (!_extractService.CheckConfigScript(userId, allotId))
return new ApiResponse(ResponseType.Fail, "未配置自定义抽取,请联系绩效管理人员。");
_backgroundTaskQueue.QueueBackgroundWorkItem(async token =>
{
using (var scope = _serviceScopeFactory.CreateScope())
{
var scopedServices = scope.ServiceProvider.GetRequiredService<CustomExtractService>();
var scopedAllotService = scope.ServiceProvider.GetRequiredService<AllotService>();
var scopedQueue = scope.ServiceProvider.GetRequiredService<IHubNotificationQueue>();
//_backgroundTaskQueue.QueueBackgroundWorkItem(async token =>
//{
// using (var scope = _serviceScopeFactory.CreateScope())
// {
// var scopedServices = scope.ServiceProvider.GetRequiredService<CustomExtractService>();
// var scopedAllotService = scope.ServiceProvider.GetRequiredService<AllotService>();
// var scopedQueue = scope.ServiceProvider.GetRequiredService<IHubNotificationQueue>();
if (scopedServices.ExtractData(userId, allotId, out string resultFilePath))
{
scopedAllotService.UpdateAllotCustomExtractPath(allotId, resultFilePath);
scopedQueue.Send(new Notification(allotId, "CustomDowoload", new CustomDownloadContent("自定义数据提取数据成功,是否立即下载", allotId)));
}
else
{
scopedQueue.Send(new Notification(allotId, "ReceiveMessage", new TextContent("自定义数据提取数据失败", NotificationLevel.ERR)));
}
// if (scopedServices.ExtractData(userId, allotId, out string resultFilePath))
// {
// scopedAllotService.UpdateAllotCustomExtractPath(allotId, resultFilePath);
// scopedQueue.Send(new Notification(allotId, "CustomDowoload", new CustomDownloadContent("自定义数据提取数据成功,是否立即下载", allotId)));
// }
// else
// {
// scopedQueue.Send(new Notification(allotId, "ReceiveMessage", new TextContent("自定义数据提取数据失败", NotificationLevel.ERR)));
// }
// await Task.Delay(TimeSpan.FromSeconds(5), token);
// }
//});
_taskService.Add(Background.JobType.自定义抽取, JsonHelper.Serialize(new { UserId = userId, AllotId = allotId }));
await Task.Delay(TimeSpan.FromSeconds(5), token);
}
});
_notificationQueue.Send(new Notification(allotId, "ReceiveMessage", new TextContent("自定义数据提取任务开始执行")));
......
......@@ -37,6 +37,7 @@ public class TemplateController : Controller
private readonly HospitalService hospitalService;
private readonly AllotService allotService;
private readonly LogManageService logService;
private readonly TaskService _taskService;
private readonly IServiceScopeFactory serviceScopeFactory;
private readonly ExtractService extractService;
......@@ -52,6 +53,7 @@ public class TemplateController : Controller
HospitalService hospitalService,
AllotService allotService,
LogManageService logService,
TaskService taskService,
IServiceScopeFactory serviceScopeFactory,
ExtractService extractService)
{
......@@ -66,6 +68,7 @@ public class TemplateController : Controller
this.hospitalService = hospitalService;
this.allotService = allotService;
this.logService = logService;
_taskService = taskService;
this.serviceScopeFactory = serviceScopeFactory;
this.extractService = extractService;
}
......@@ -209,8 +212,7 @@ public ApiResponse NewExtractData([CustomizeValidator, FromBody] ExtractRequest
if (allot == null)
return new ApiResponse(ResponseType.ParameterError, "AllotID错误");
// 判断是那种抽取
try
{
bool isSingle = false;
string message = configService.Judge(request.AllotId, request.HospitalId, request.UseScheme, ref isSingle, out string filePath);
if (!string.IsNullOrEmpty(message))
......@@ -224,61 +226,13 @@ public ApiResponse NewExtractData([CustomizeValidator, FromBody] ExtractRequest
//检验科室、费用类型是否需要补充
allot.IsExtracting = allot.IsExtracting ?? 0;
if (allot.IsExtracting == 1 && allot.ExtractTime.HasValue && DateTime.Now.AddHours(-3) < allot.ExtractTime)
return new ApiResponse(ResponseType.OK, "正在提取数据,请稍等!", new { IsExtracting = true });
allot.IsExtracting = 1;
allot.ExtractTime = DateTime.Now;
allotService.Update(allot);
// string email = claim.GetUserClaim(JwtClaimTypes.Mail);
string email = "";
if (isSingle)
{
logger.LogInformation("同一项目中进行提取");
Task.Run(() =>
{
Thread.Sleep(1000);
using (var scope = serviceScopeFactory.CreateScope())
{
var scopedServices = scope.ServiceProvider.GetRequiredService<ExtractService>();
logger.LogInformation("提取绩效数据参数:" + JsonHelper.Serialize(new { allotId = allot.ID, hospitalId = allot.HospitalId }));
string extractFilePath = scopedServices.Main(allot.ID, allot.HospitalId, email, allot.ID.ToString(), filePath, isSingle);
}
});
}
else
{
var http = new RestSharpHelper();
var extractUrl = http.SetUrl(url.HttpPost, "extract/extract");
var obj = new ExtractRequest
{
AllotId = request.AllotId,
HospitalId = request.HospitalId,
Email = email
};
_taskService.Add(Background.JobType.提取数据, JsonHelper.Serialize(new { request.AllotId, request.HospitalId, request.UseScheme, isSingle, filePath }));
string json = JsonHelper.Serialize(obj);
logger.LogInformation("提取绩效数据参数:" + json);
var parameter = JsonHelper.Deserialize<Dictionary<string, object>>(json);
var restRequest = string.IsNullOrEmpty(filePath) ? http.CreatePostRequest(json) : http.CreateFileRequest(new string[] { filePath }, parameter);
Task.Run(() => http.GetResponse(extractUrl, restRequest));
}
return new ApiResponse(ResponseType.OK, "HIS绩效数据提取任务正在执行,稍后我们通知您!", new { IsExtracting = false });
return new ApiResponse(ResponseType.OK, "HIS绩效数据提取任务正在执行,稍后我们将以邮件的通知您!", new { IsExtracting = false });
}
catch (Exception ex)
{
if (allot != null)
{
allot.IsExtracting = 3;
allotService.Update(allot);
}
logger.LogError("提取绩效数据:" + ex.ToString());
throw new Exception(ex.Message);
}
// A 使用上传绩效作为模板
// A-1 判断上传绩效是否存在,并执行成功
// A-2 医院人员名单、1.0.1 额外收入(写出列头)、2.1 成本支出统计表(写出列头)、4.1 临床科室医护绩效测算表、4.2 特殊核算单元绩效测算表(数量、考核得分率、奖罚、其他)
......
using FluentScheduler;
using System;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Caching.Memory;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Performance.Repository;
using Performance.DtoModels;
using Performance.Services;
using System;
namespace Performance.Api
{
......@@ -21,6 +13,7 @@ public JobRegistry(IServiceProvider provider)
Schedule(() => provider.GetService<ExtractGenerateJob>()).ToRunEvery(1).Days().At(23, 00);
//Schedule(() => provider.GetService<ClearLoggerJob>()).ToRunNow().AndEvery(60).Seconds();
Schedule(() => provider.GetService<ClearLoggerJob>()).ToRunNow().AndEvery(1).Days().At(3, 00);
Schedule(() => provider.GetService<BackgroundJob>()).ToRunNow().AndEvery(10).Seconds();
}
}
}
......@@ -102,6 +102,7 @@ public void ConfigureServices(IServiceCollection services)
services.AddTransient<ExtractGenerateJob>();
services.AddTransient<ExtractDataJob>();
services.AddTransient<ClearLoggerJob>();
services.AddTransient<BackgroundJob>();
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
......
{
"Logging": {
"LogLevel": {
"Default": "Debug",
"Default": "Information",
"System": "Information",
"Microsoft": "Information"
"Microsoft": "Warning"
}
},
"AppConnection": {
"PerformanceConnectionString": "server=192.168.18.166;database=db_performance;uid=root;pwd=1234qwer;pooling=true;charset=utf8;convert zero datetime=true;port=3306;connection timeout=120;max pool size=512;allow user variables=true;",
"HangfireConnectionString": "server=192.168.18.166;database=db_hangfire;uid=root;pwd=1234qwer;port=3306;allow user variables=true;",
"RedisConnectionString": "116.62.245.55:6379,defaultDatabase=2"
"PerformanceConnectionString": "server=192.168.18.166;database=db_performance;uid=root;pwd=1234qwer;pooling=true;charset=utf8;convert zero datetime=true;port=3306;connection timeout=120;max pool size=512;allow user variables=true;"
},
"Application": {
//登录过期时间
......
{
"Logging": {
"LogLevel": {
"Default": "Debug",
"System": "Information",
"Microsoft": "Information"
"Default": "Information",
"System": "Information"
}
},
"AppConnection": {
//"PerformanceConnectionString": "server=112.124.13.17;database=db_performance;uid=suvalue;pwd=suvalue2016;pooling=true;charset=utf8;convert zero datetime=true;port=3306;connection timeout=120;max pool size=512;allow user variables=true;",
"PerformanceConnectionString": "server=192.168.18.166;database=db_performance_screen;uid=root;pwd=1234qwer;pooling=true;charset=utf8;convert zero datetime=true;port=3306;connection timeout=120;max pool size=512;allow user variables=true;",
"HangfireConnectionString": "server=192.168.18.166;database=db_hangfire;uid=root;pwd=1234qwer;port=3306;allow user variables=true;",
"RedisConnectionString": "116.62.245.55:6379,defaultDatabase=2"
"PerformanceConnectionString": "server=192.168.18.166;database=db_performance_screen;uid=root;pwd=1234qwer;pooling=true;charset=utf8;convert zero datetime=true;port=3306;connection timeout=120;max pool size=512;allow user variables=true;"
},
"Application": {
//登录过期时间
......
......@@ -6,22 +6,7 @@
},
//连接字符串
"AppConnection": {
"PerformanceConnectionString": "server=116.62.245.55;database=db_performance;uid=suvalue;pwd=suvalue2017;pooling=true;charset=utf8;convert zero datetime=true;port=3306;connection timeout=120;max pool size=512;allow user variables=true;",
"HangfireConnectionString": "server=116.62.245.55;database=db_hangfire;uid=suvalue;pwd=suvalue2017;port=3306;allow user variables=true;",
"RedisConnectionString": "116.62.245.55:6379,defaultdatabase=2"
},
//互亿
"HuyiSmsConfig": {
"Url": "http://106.ihuyi.cn/webservice/sms.php?method=Submit",
"Account": "cf_szjk",
"Password": "123456"
},
//阿里邮箱
"EmailOptions": {
"SmtpServer": "smtpdm.aliyun.com",
"Account": "service@email.suvalue.com",
"Password": "SuValue123456",
"IsEnable": false
"PerformanceConnectionString": "server=116.62.245.55;database=db_performance;uid=suvalue;pwd=suvalue2017;pooling=true;charset=utf8;convert zero datetime=true;port=3306;connection timeout=120;max pool size=512;allow user variables=true;"
},
"Application": {
//登录过期时间
......@@ -51,5 +36,16 @@
"ImportFile": "http://localhost:5001/api/",
// 抽取uri
"HttpPost": "http://localhost:50997/api/"
},
"RateLimitingConfig": {
"Endpoints": [
"/api/second/savevalue",
"/api/second/savedata",
"/api/second/other/save",
"/api/second/redistribution/save",
"/api/second/redistribution/submit"
],
"Period": "1", // 单位为秒
"Limit": 1
}
}
......@@ -22,8 +22,8 @@
layout="日志记录时间:${longdate}${newline}日志级别:${uppercase:${level}}${newline}日志来源:${logger}${newline}日志信息:${message}${newline}错误信息:${exception:format=tostring}${newline}==============================================================${newline}" />
<!-- another file log, only own logs. Uses some ASP.NET core renderers -->
<target xsi:type="File" name="ownFile-web" fileName="${basedir}/Logs/${shortdate}/${level}.log"
layout="日志记录时间:${longdate}${newline}日志级别:${uppercase:${level}}${newline}日志来源:${logger}${newline}日志信息:${message}${newline}错误信息:${exception:format=tostring}${newline}url: ${aspnet-request-url}${newline}action: ${aspnet-mvc-action}${newline}==============================================================${newline}" />
<!--<target xsi:type="File" name="ownFile-web" fileName="${basedir}/Logs/${shortdate}/${level}.log"
layout="日志记录时间:${longdate}${newline}日志级别:${uppercase:${level}}${newline}日志来源:${logger}${newline}日志信息:${message}${newline}错误信息:${exception:format=tostring}${newline}url: ${aspnet-request-url}${newline}action: ${aspnet-mvc-action}${newline}==============================================================${newline}" />-->
<!-- write log to mongodb-->
<!--<target xsi:type="Mongo"
......@@ -49,9 +49,9 @@
<logger name="*" minlevel="Trace" writeTo="allfile" />
<!--Skip non-critical Microsoft logs and so log only own logs-->
<logger name="Microsoft.*" maxLevel="Info" final="true" />
<!--<logger name="Microsoft.*" maxLevel="Info" final="true" />-->
<!-- BlackHole without writeTo -->
<logger name="*" minlevel="Trace" writeTo="ownFile-web" />
<!--<logger name="*" minlevel="Trace" writeTo="ownFile-web" />-->
<!--Add logs to mongodb-->
<!--<logger name="*" minlevel="Trace" writeTo="mongo"/>-->
......
......@@ -2165,6 +2165,41 @@
<param name="query"></param>
<returns></returns>
</member>
<member name="M:Performance.Api.BackgroundJob.Execute_Allot_Generate(Performance.Services.TaskService,Performance.EntityModels.bg_task)">
<summary>
生成测算表
</summary>
<param name="service"></param>
<param name="task"></param>
</member>
<member name="M:Performance.Api.BackgroundJob.Execute_Allot_Generate_Report(Performance.Services.TaskService,Performance.EntityModels.bg_task)">
<summary>
生成报表
</summary>
<param name="service"></param>
<param name="task"></param>
</member>
<member name="M:Performance.Api.BackgroundJob.Execute_Allot_CustomExtract(Performance.Services.TaskService,Performance.EntityModels.bg_task)">
<summary>
提取绩效数据
</summary>
<param name="service"></param>
<param name="task"></param>
</member>
<member name="M:Performance.Api.BackgroundJob.Timeout(Performance.Services.TaskService,System.Collections.Generic.List{Performance.EntityModels.bg_task})">
<summary>
超时关闭
</summary>
<param name="service"></param>
<param name="tasks"></param>
</member>
<member name="M:Performance.Api.BackgroundJob.Repeat(Performance.Services.TaskService,System.Collections.Generic.List{Performance.EntityModels.bg_task})">
<summary>
重复任务仅执行最后异常
</summary>
<param name="service"></param>
<param name="tasks"></param>
</member>
<member name="T:Performance.Api.ClearLoggerJob">
<summary>
删除历史日志
......
......@@ -914,11 +914,6 @@
人员工号
</summary>
</member>
<member name="P:Performance.DtoModels.PerData.Annotation">
<summary>
单元格注释
</summary>
</member>
<member name="P:Performance.DtoModels.PerData.Remark">
<summary>
单元格备注
......
......@@ -1595,6 +1595,16 @@
排序
</summary>
</member>
<member name="T:Performance.EntityModels.bg_task">
<summary>
考核类别
</summary>
</member>
<member name="P:Performance.EntityModels.bg_task.ID">
<summary>
</summary>
</member>
<member name="T:Performance.EntityModels.cof_accounting">
<summary>
......
......@@ -135,4 +135,24 @@ public enum Role
护理部审核 = 13,
绩效查询 = 13,
}
public class Background
{
public enum JobType
{
生成测算表 = 1,
提取数据 = 2,
报表 = 3,
自定义抽取 = 4,
}
public enum Status
{
等待 = 1,
执行中 = 2,
完成 = 3,
失败 = 10,
无效 = 88,
超时 = 99,
}
}
}
......@@ -30,10 +30,10 @@ public class PerData : IPerData
/// 人员工号
/// </summary>
public string JobNumber { get; set; }
/// <summary>
/// 单元格注释
/// </summary>
public string Annotation { get; set; }
///// <summary>
///// 单元格注释
///// </summary>
//public string Annotation { get; set; }
/// <summary>
/// 单元格备注
/// </summary>
......
......@@ -74,7 +74,7 @@ public object CellValue
{
get
{
var value = ConvertHelper.To<decimal?>(cellValue);
var value = ConvertHelper.ToDecimalOrNull(cellValue);
if (value.HasValue && value.Value > 0)
return Math.Round(value.Value, 2);
return cellValue;
......
......@@ -57,6 +57,7 @@ public PerformanceDbContext(DbContextOptions<PerformanceDbContext> options)
public virtual DbSet<as_tempassess> as_tempassess { get; set; }
/// <summary> 考核列头 </summary>
public virtual DbSet<as_tempcolumns> as_tempcolumns { get; set; }
public virtual DbSet<bg_task> bg_task { get; set; }
/// <summary> </summary>
public virtual DbSet<cof_accounting> cof_accounting { get; set; }
/// <summary> </summary>
......
//-----------------------------------------------------------------------
// <copyright file=" bg_task.cs">
// * FileName: bg_task.cs
// </copyright>
//-----------------------------------------------------------------------
using System;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
namespace Performance.EntityModels
{
/// <summary>
/// 考核类别
/// </summary>
[Table("bg_task")]
public class bg_task
{
/// <summary>
///
/// </summary>
[Key]
public int ID { get; set; }
public string Name { get; set; }
public int JobType { get; set; }
public DateTime CreateTime { get; set; }
public DateTime? BeginTime { get; set; }
public DateTime? EndTime { get; set; }
public int Status { get; set; }
public string Argument { get; set; }
public string Remark { get; set; }
public double ElapsedTime { get; set; }
}
}
......@@ -30,6 +30,23 @@ public static decimal TryDecimal(string inValue, decimal defaultValue = default(
return ret;
}
/// <summary>
/// 转换为128位可空浮点型,并按指定小数位舍入
/// </summary>
/// <param name="input">输入值</param>
/// <param name="digits">小数位数</param>
public static decimal? ToDecimalOrNull(object input)
{
try
{
return decimal.TryParse(input?.ToString(), out decimal tmpvalue) ? tmpvalue : null;
}
catch (Exception ex)
{
throw;
}
}
public static DateTime TryDateTime(string inValue, DateTime defaultValue = default(DateTime))
{
DateTime ret = defaultValue;
......@@ -46,23 +63,28 @@ public static DateTime TryDateTime(string inValue, DateTime defaultValue = defau
/// <returns></returns>
public static T To<T>(object value, T defaultValue = default(T))
{
try
{
var t = typeof(T);
//兼容可空类型转换
if (t.IsGenericType && t.GetGenericTypeDefinition().Equals(typeof(Nullable<>)))
{
if (value == null)
{
return default(T);
}
return defaultValue;
if (value is string && string.IsNullOrWhiteSpace(value.ToString()))
return defaultValue;
t = Nullable.GetUnderlyingType(t);
}
var t = typeof(T);
var type = Nullable.GetUnderlyingType(t) ?? t;
return (T)Convert.ChangeType(value, t);
var typeName = type.Name.ToLower();
try
{
if (typeName == "string")
return (T)(object)value.ToString();
if (typeName == "guid")
return (T)(object)new Guid(value.ToString());
if (type.IsEnum)
return (T)Enum.Parse(type, value.ToString());
if (value is IConvertible)
return (T)Convert.ChangeType(value, type);
return (T)value;
}
catch
catch (Exception ex)
{
return defaultValue;
}
......
......@@ -483,6 +483,8 @@ public static string FileToString(string filePath, Encoding encoding)
/// <param name="filePath">文件的绝对路径</param>
public static string GetFileName(string filePath)
{
if (string.IsNullOrEmpty(filePath))
return string.Empty;
//获取文件的名称
FileInfo fi = new FileInfo(filePath);
return fi.Name;
......
//-----------------------------------------------------------------------
// <copyright file=" bg_task.cs">
// * FileName: bg_task.cs
// </copyright>
//-----------------------------------------------------------------------
using Performance.EntityModels;
namespace Performance.Repository
{
/// <summary>
/// bg_task Repository
/// </summary>
public partial class PerforBgtaskRepository : PerforRepository<bg_task>
{
public PerforBgtaskRepository(PerformanceDbContext context) : base(context)
{
}
}
}
......@@ -83,10 +83,10 @@ private List<PerAgainData> SlideRowRead(ISheet sheet, PerHeader header, int r, I
{
var athead = header.Children.ElementAt(c);
//var cellValue = NopiSevice.GetCellValue(row.GetCell(athead.PointCell));
var cellValue = ConvertHelper.To<decimal?>(row.GetCell(athead.PointCell).GetValue());
var cellValue = ConvertHelper.ToDecimalOrNull(row.GetCell(athead.PointCell).GetValue());
if (!cellValue.HasValue || cellValue.Value == 0)
continue;
var factorValue = ConvertHelper.To<decimal?>(sheet.GetRow(FactorRow).GetCell(athead.PointCell)?.ToString());
var factorValue = ConvertHelper.ToDecimalOrNull(sheet.GetRow(FactorRow).GetCell(athead.PointCell)?.ToString());
PerAgainData data = new PerAgainData
{
RowNumber = r,
......@@ -117,13 +117,13 @@ private static PerAgainEmployee FixatRowRead(List<PerHeader> perHeader, int r, I
RowNumber = r,
Name = row.GetCell(perHeader.FirstOrDefault(p => p.CellValue == "姓名").PointCell)?.ToString(),
JobTitle = row.GetCell(perHeader.FirstOrDefault(p => p.CellValue == "职务").PointCell)?.ToString(),
JobFactor = ConvertHelper.To<decimal?>(row.GetCell(perHeader.FirstOrDefault(p => p.CellValue == "职称系数").PointCell)?.ToString()),
Attendance = ConvertHelper.To<decimal?>(row.GetCell(perHeader.FirstOrDefault(p => p.CellValue == "出勤").PointCell)?.ToString()),
YearFactor = ConvertHelper.To<decimal?>(row.GetCell(perHeader.FirstOrDefault(p => p.CellValue == "年资").PointCell)?.ToString()),
Award = ConvertHelper.To<decimal?>(row.GetCell(perHeader.FirstOrDefault(p => p.CellValue == "重点奖励").PointCell)?.ToString()),
Allowance = ConvertHelper.To<decimal?>(row.GetCell(perHeader.FirstOrDefault(p => p.CellValue == "管理津贴").PointCell)?.ToString()),
AlonePerfor = ConvertHelper.To<decimal?>(row.GetCell(perHeader.FirstOrDefault(p => p.CellValue == "单独核算人员绩效").PointCell)?.ToString()),
NightShift = ConvertHelper.To<decimal?>(row.GetCell(perHeader.FirstOrDefault(p => p.CellValue == "夜班费").PointCell)?.ToString()),
JobFactor = ConvertHelper.ToDecimalOrNull(row.GetCell(perHeader.FirstOrDefault(p => p.CellValue == "职称系数").PointCell)?.ToString()),
Attendance = ConvertHelper.ToDecimalOrNull(row.GetCell(perHeader.FirstOrDefault(p => p.CellValue == "出勤").PointCell)?.ToString()),
YearFactor = ConvertHelper.ToDecimalOrNull(row.GetCell(perHeader.FirstOrDefault(p => p.CellValue == "年资").PointCell)?.ToString()),
Award = ConvertHelper.ToDecimalOrNull(row.GetCell(perHeader.FirstOrDefault(p => p.CellValue == "重点奖励").PointCell)?.ToString()),
Allowance = ConvertHelper.ToDecimalOrNull(row.GetCell(perHeader.FirstOrDefault(p => p.CellValue == "管理津贴").PointCell)?.ToString()),
AlonePerfor = ConvertHelper.ToDecimalOrNull(row.GetCell(perHeader.FirstOrDefault(p => p.CellValue == "单独核算人员绩效").PointCell)?.ToString()),
NightShift = ConvertHelper.ToDecimalOrNull(row.GetCell(perHeader.FirstOrDefault(p => p.CellValue == "夜班费").PointCell)?.ToString()),
};
}
}
......
......@@ -325,6 +325,7 @@ public void Generate(per_allot allot)
{
logManageService.WriteMsg("绩效开始执行", $"正在生成{allot.Year}-{allot.Month.ToString().PadLeft(2, '0')}月份绩效!", 1, allot.ID, "ReceiveMessage", true);
UpdateAllotStates(allot.ID, (int)AllotStates.InCheckData, EnumHelper.GetDescription(AllotStates.InCheckData));
var excel = new PerExcel();
int generate = allot.Generate;
if (new int[] { (int)AllotGenerate.OriginalDataEdited, (int)AllotGenerate.PersonnelOffice }.Contains(allot.Generate))
......@@ -344,7 +345,6 @@ public void Generate(per_allot allot)
// 导出数据
excel = importDataService.ReadDataAndSave(allot);
UpdateAllotStates(allot.ID, (int)AllotStates.InCheckData, EnumHelper.GetDescription(AllotStates.InCheckData));
//if (!checkDataService.Check(excel, allot))
//{
// UpdateAllotStates(allot.ID, (int)AllotStates.CheckFail, EnumHelper.GetDescription(AllotStates.CheckFail));
......
......@@ -2109,13 +2109,13 @@
// var value = deptData.FirstOrDefault(t => t.TypeName == headName)?.CellValue ?? "0";
// if (isIncom)
// {
// var cellvalue = value == "0" ? null : ConvertHelper.To<decimal?>(value);
// var cellvalue = value == "0" ? null : ConvertHelper.ToDecimalOrNull(value);
// OutToExcelCell<decimal>(newCell, cellvalue);
// newCell.CellStyle = style;
// }
// else if (newCell.CellType != CellType.Formula)
// {
// var cellvalue = value == "0" ? null : ConvertHelper.To<decimal?>(value);
// var cellvalue = value == "0" ? null : ConvertHelper.ToDecimalOrNull(value);
// OutToExcelCell<decimal>(newCell, cellvalue);
// if (header != null && header.Contains(headName))
// newCell.CellStyle = style;
......
......@@ -113,7 +113,7 @@ public string Main(int allotId, int hospitalId, string email, string groupName,
var statesArray = new int[] { (int)AllotStates.GenerateSucceed, (int)AllotStates.Archive };
var templateFilePath = ExtractHelper.GetExtractFile(hospitalId, allot, ref extractFilePath, filePath);
logService.ReturnTheLog(allotId, groupName, 2, "创建文件", $"模板文件: {templateFilePath}", 1, isSingle);
logService.ReturnTheLog(allotId, groupName, 2, "创建文件", $"模板文件: {FileHelper.GetFileName(templateFilePath)}", 1, isSingle);
if (!FileHelper.IsExistFile(templateFilePath)) throw new Exception("抽取文件创建失败");
......
......@@ -45,11 +45,11 @@ public static class NopiSevice
// switch (cell.CellType)
// {
// case CellType.Numeric:
// return ConvertHelper.To<decimal?>(cell.NumericCellValue);
// return ConvertHelper.ToDecimalOrNull(cell.NumericCellValue);
// case CellType.String:
// return ConvertHelper.To<decimal?>(cell.StringCellValue);
// return ConvertHelper.ToDecimalOrNull(cell.StringCellValue);
// case CellType.Formula:
// return ConvertHelper.To<decimal?>(cell.NumericCellValue);
// return ConvertHelper.ToDecimalOrNull(cell.NumericCellValue);
// }
// }
// catch (Exception ex)
......
......@@ -51,7 +51,7 @@ public List<IPerData> ReadData(ISheet sheet, List<PerHeader> perHeader)
{
var athead = vhead.ElementAt(c);
//var cellValue = NopiSevice.GetCellValue(row.GetCell(athead.PointCell));
var cellValue = ConvertHelper.To<decimal?>(row.GetCell(athead.PointCell).GetValue());
var cellValue = ConvertHelper.ToDecimalOrNull(row.GetCell(athead.PointCell).GetValue());
if (!cellValue.HasValue || cellValue.Value == 0)
continue;
......@@ -63,7 +63,7 @@ public List<IPerData> ReadData(ISheet sheet, List<PerHeader> perHeader)
AccountingUnit = row.GetCell(unit.AccountingUnitCellNum.Value).GetValue(),
TypeName = athead?.CellValue,
CellValue = cellValue,
Annotation = row.GetCell(athead.PointCell)?.CellComment?.String?.String,
//Annotation = row.GetCell(athead.PointCell)?.CellComment?.String?.String,
FactorValue = 1,
IsFactor = true,
};
......
......@@ -69,7 +69,7 @@ public List<IPerData> ReadData(ISheet sheet, List<PerHeader> perHeader)
{
var athead = vhead.ElementAt(c);
//var cellValue = NopiSevice.GetCellValue(row.GetCell(athead.PointCell));
var cellValue = ConvertHelper.To<decimal?>(row.GetCell(athead.PointCell).GetValue());
var cellValue = ConvertHelper.ToDecimalOrNull(row.GetCell(athead.PointCell).GetValue());
if (!cellValue.HasValue || cellValue.Value == 0)
continue;
PerData data = new PerData
......@@ -80,9 +80,9 @@ public List<IPerData> ReadData(ISheet sheet, List<PerHeader> perHeader)
Department = row.GetCell(unit.DeptCellNum.Value).GetValue(),
TypeName = athead?.CellValue,
CellValue = cellValue,
Annotation = row.GetCell(athead.PointCell)?.CellComment?.String?.String,
//Annotation = row.GetCell(athead.PointCell)?.CellComment?.String?.String,
UnitType = unit.UnitType, //手动匹配
FactorValue = ConvertHelper.To<decimal?>(sheet.GetRow(unit.FactorRow.Value).GetCell(athead.PointCell).GetValue()),
FactorValue = ConvertHelper.ToDecimalOrNull(sheet.GetRow(unit.FactorRow.Value).GetCell(athead.PointCell).GetValue()),
IsFactor = true,
};
dataList.Add(data);
......@@ -111,9 +111,9 @@ public List<IPerData> ReadData(ISheet sheet, List<PerHeader> perHeader)
Department = cellValue,
TypeName = athead?.CellValue,
CellValue = (dataList.Select(t => (PerData)t)?.Where(t => t.TypeName == athead.CellValue).Sum(t => t.CellValue) ?? 0) / 2,
Annotation = technicianRow.GetCell(athead.PointCell)?.CellComment?.String?.String,
//Annotation = technicianRow.GetCell(athead.PointCell)?.CellComment?.String?.String,
UnitType = tunit.UnitType, //手动匹配
FactorValue = ConvertHelper.To<decimal?>(sheet.GetRow(tunit.FactorRow.Value).GetCell(athead.PointCell)?.ToString()),
FactorValue = ConvertHelper.ToDecimalOrNull(sheet.GetRow(tunit.FactorRow.Value).GetCell(athead.PointCell)?.ToString()),
IsFactor = true,
};
dataList.Add(data);
......
......@@ -44,7 +44,7 @@ public List<IPerData> ReadData(ISheet sheet, List<PerHeader> perHeader)
object @object = row.GetCell(point).GetValue();
if (item.IsNumber)
@object = ConvertHelper.To<decimal?>(@object);
@object = ConvertHelper.ToDecimalOrNull(@object);
if (dic.Keys.Contains(item.Field))
dic[item.Field] = @object;
......
......@@ -46,7 +46,7 @@ public List<IPerData> ReadData(ISheet sheet, List<PerHeader> perHeader)
{
var athead = vhead.ElementAt(c);
//var cellValue = NopiSevice.GetCellValue(row.GetCell(athead.PointCell));
var cellValue = ConvertHelper.To<decimal?>(row.GetCell(athead.PointCell).GetValue());
var cellValue = ConvertHelper.ToDecimalOrNull(row.GetCell(athead.PointCell).GetValue());
if (!cellValue.HasValue || cellValue.Value == 0)
continue;
......@@ -58,7 +58,7 @@ public List<IPerData> ReadData(ISheet sheet, List<PerHeader> perHeader)
//Department = NopiSevice.GetCellStringValue(row.GetCell(unit.DeptCellNum.Value)),
TypeName = athead?.CellValue,
CellValue = cellValue,
Annotation = row.GetCell(athead.PointCell)?.CellComment?.String?.String,
//Annotation = row.GetCell(athead.PointCell)?.CellComment?.String?.String,
UnitType = row.GetCell(0)?.ToString(),
FactorValue = 0,
IsFactor = false,
......
......@@ -41,7 +41,7 @@ public List<IPerData> ReadData(ISheet sheet, List<PerHeader> perHeader)
{
object @object = row.GetCell(point).GetValue();
if (item.IsNumber)
@object = ConvertHelper.To<decimal?>(@object);
@object = ConvertHelper.ToDecimalOrNull(@object);
if (dic.Keys.Contains(item.Field))
dic[item.Field] = @object;
......
......@@ -72,7 +72,7 @@ public List<IPerData> ReadData(ISheet sheet, List<PerHeader> perHeader)
if (!string.IsNullOrEmpty(athead?.CellValue) && athead.CellValue.Contains("备注"))
continue;
//var cellValue = NopiSevice.GetCellValue(row.GetCell(athead.PointCell));
var cellValue = ConvertHelper.To<decimal?>(row.GetCell(athead.PointCell).GetValue());
var cellValue = ConvertHelper.ToDecimalOrNull(row.GetCell(athead.PointCell).GetValue());
if (!cellValue.HasValue || cellValue.Value == 0)
continue;
......@@ -84,9 +84,9 @@ public List<IPerData> ReadData(ISheet sheet, List<PerHeader> perHeader)
Department = row.GetCell(unit.DeptCellNum.Value).GetValue(),
TypeName = athead?.CellValue,
CellValue = cellValue,
Annotation = row.GetCell(athead.PointCell)?.CellComment?.String?.String,
//Annotation = row.GetCell(athead.PointCell)?.CellComment?.String?.String,
UnitType = unit.UnitType, //手动匹配
FactorValue = ConvertHelper.To<decimal?>(sheet.GetRow(unit.FactorRow.Value).GetCell(athead.PointCell)?.NumericCellValue),
FactorValue = ConvertHelper.ToDecimalOrNull(sheet.GetRow(unit.FactorRow.Value).GetCell(athead.PointCell)?.NumericCellValue),
IsFactor = true,
};
var lastcell = vhead.OrderByDescending(t => t.PointCell).First();
......
......@@ -68,7 +68,7 @@ public List<IPerData> ReadData(ISheet sheet, List<PerHeader> perHeader)
{
var athead = vhead.ElementAt(c);
//var cellValue = NopiSevice.GetCellValue(row.GetCell(athead.PointCell));
var cellValue = ConvertHelper.To<decimal?>(row.GetCell(athead.PointCell).GetValue());
var cellValue = ConvertHelper.ToDecimalOrNull(row.GetCell(athead.PointCell).GetValue());
if (!cellValue.HasValue || cellValue.Value == 0)
continue;
PerData data = new PerData
......@@ -79,9 +79,9 @@ public List<IPerData> ReadData(ISheet sheet, List<PerHeader> perHeader)
Department = row.GetCell(unit.DeptCellNum.Value).GetValue(),
TypeName = athead?.CellValue,
CellValue = cellValue,
Annotation = row.GetCell(athead.PointCell)?.CellComment?.String?.String,
//Annotation = row.GetCell(athead.PointCell)?.CellComment?.String?.String,
UnitType = unit.UnitType, //手动匹配
FactorValue = ConvertHelper.To<decimal?>(sheet.GetRow(unit.FactorRow.Value).GetCell(athead.PointCell)?.NumericCellValue),
FactorValue = ConvertHelper.ToDecimalOrNull(sheet.GetRow(unit.FactorRow.Value).GetCell(athead.PointCell)?.NumericCellValue),
IsFactor = true,
};
if (string.IsNullOrEmpty(data.AccountingUnit) && string.IsNullOrEmpty(data.Department))
......
......@@ -41,7 +41,7 @@ public List<IPerData> ReadData(ISheet sheet, List<PerHeader> perHeader)
{
object @object = row.GetCell(point).GetValue();
if (item.IsNumber)
@object = ConvertHelper.To<decimal?>(@object);
@object = ConvertHelper.ToDecimalOrNull(@object);
if (dic.Keys.Contains(item.Field))
dic[item.Field] = @object;
......
......@@ -68,7 +68,7 @@ public List<IPerData> ReadData(ISheet sheet, List<PerHeader> perHeader)
{
var athead = vhead.ElementAt(c);
//var cellValue = NopiSevice.GetCellValue(row.GetCell(athead.PointCell));
var cellValue = ConvertHelper.To<decimal?>(row.GetCell(athead.PointCell).GetValue());
var cellValue = ConvertHelper.ToDecimalOrNull(row.GetCell(athead.PointCell).GetValue());
if (!cellValue.HasValue || cellValue.Value == 0)
continue;
PerData data = new PerData
......@@ -79,9 +79,9 @@ public List<IPerData> ReadData(ISheet sheet, List<PerHeader> perHeader)
Department = row.GetCell(unit.DeptCellNum.Value).GetValue(),
TypeName = athead?.CellValue,
CellValue = cellValue,
Annotation = row.GetCell(athead.PointCell)?.CellComment?.String?.String,
//Annotation = row.GetCell(athead.PointCell)?.CellComment?.String?.String,
UnitType = unit.UnitType, //手动匹配
FactorValue = ConvertHelper.To<decimal?>(sheet.GetRow(unit.FactorRow.Value).GetCell(athead.PointCell)?.NumericCellValue),
FactorValue = ConvertHelper.ToDecimalOrNull(sheet.GetRow(unit.FactorRow.Value).GetCell(athead.PointCell)?.NumericCellValue),
IsFactor = true,
};
if (string.IsNullOrEmpty(data.AccountingUnit) && string.IsNullOrEmpty(data.Department))
......
......@@ -51,7 +51,7 @@ public List<IPerData> ReadData(ISheet sheet, List<PerHeader> perHeader)
{
var athead = vhead.ElementAt(c);
//var cellValue = NopiSevice.GetCellValue(row.GetCell(athead.PointCell));
var cellValue = ConvertHelper.To<decimal?>(row.GetCell(athead.PointCell).GetValue());
var cellValue = ConvertHelper.ToDecimalOrNull(row.GetCell(athead.PointCell).GetValue());
if (!cellValue.HasValue || cellValue.Value == 0)
continue;
......@@ -63,7 +63,7 @@ public List<IPerData> ReadData(ISheet sheet, List<PerHeader> perHeader)
AccountingUnit = row.GetCell(unit.AccountingUnitCellNum.Value).GetValue(),
TypeName = athead?.CellValue,
CellValue = cellValue,
Annotation = row.GetCell(athead.PointCell)?.CellComment?.String?.String,
//Annotation = row.GetCell(athead.PointCell)?.CellComment?.String?.String,
FactorValue = 1,
IsFactor = true,
};
......
......@@ -55,13 +55,13 @@ public List<IPerData> ReadData(ISheet sheet, List<PerHeader> perHeader)
if (NopiSevice.TryGetPoint(perHeader, "量化指标", out point))
specialUnit.QuantitativeIndicators = row.GetCell(point).GetValue();
if (NopiSevice.TryGetPoint(perHeader, "数量", out point))
specialUnit.Quantity = ConvertHelper.To<decimal?>(row.GetCell(point).GetValue());
specialUnit.Quantity = ConvertHelper.ToDecimalOrNull(row.GetCell(point).GetValue());
if (NopiSevice.TryGetPoint(perHeader, "量化指标绩效分值", out point))
specialUnit.QuantitativeIndicatorsValue = ConvertHelper.To<decimal?>(row.GetCell(point).GetValue());
specialUnit.QuantitativeIndicatorsValue = ConvertHelper.ToDecimalOrNull(row.GetCell(point).GetValue());
if (NopiSevice.TryGetPoint(perHeader, "人数", out point))
specialUnit.Number = ConvertHelper.To<decimal?>(row.GetCell(point).GetValue());
specialUnit.Number = ConvertHelper.ToDecimalOrNull(row.GetCell(point).GetValue());
if (NopiSevice.TryGetPoint(perHeader, "实发绩效", out point))
specialUnit.RealGiveFee = ConvertHelper.To<decimal?>(row.GetCell(point).GetValue());
specialUnit.RealGiveFee = ConvertHelper.ToDecimalOrNull(row.GetCell(point).GetValue());
ICell cell = null;
if (NopiSevice.TryGetPoint(perHeader, "科室", out int kspoint))
......@@ -84,10 +84,10 @@ public List<IPerData> ReadData(ISheet sheet, List<PerHeader> perHeader)
specialUnit.AccountingUnit = accountingUnit;
specialUnit.Department = accountingUnit;
//specialUnit.ScoringAverage = ConvertHelper.To<decimal?>(row.GetCell(perHeader.FirstOrDefault(p => p.CellValue == "考核得分率").PointCell)?.NumericCellValue);
//specialUnit.OtherPerfor = ConvertHelper.To<decimal?>(row.GetCell(perHeader.FirstOrDefault(p => p.CellValue == "其他绩效").PointCell)?.NumericCellValue);
//specialUnit.Punishment = ConvertHelper.To<decimal?>(row.GetCell(perHeader.FirstOrDefault(p => p.CellValue == "医院奖罚").PointCell)?.NumericCellValue);
//specialUnit.Adjust = ConvertHelper.To<decimal?>(row.GetCell(perHeader.FirstOrDefault(p => p.CellValue == "调节系数").PointCell)?.NumericCellValue);
//specialUnit.ScoringAverage = ConvertHelper.ToDecimalOrNull(row.GetCell(perHeader.FirstOrDefault(p => p.CellValue == "考核得分率").PointCell)?.NumericCellValue);
//specialUnit.OtherPerfor = ConvertHelper.ToDecimalOrNull(row.GetCell(perHeader.FirstOrDefault(p => p.CellValue == "其他绩效").PointCell)?.NumericCellValue);
//specialUnit.Punishment = ConvertHelper.ToDecimalOrNull(row.GetCell(perHeader.FirstOrDefault(p => p.CellValue == "医院奖罚").PointCell)?.NumericCellValue);
//specialUnit.Adjust = ConvertHelper.ToDecimalOrNull(row.GetCell(perHeader.FirstOrDefault(p => p.CellValue == "调节系数").PointCell)?.NumericCellValue);
//}
if (!string.IsNullOrEmpty(specialUnit.QuantitativeIndicators) && specialUnit.QuantitativeIndicatorsValue != null)
dataList.Add(specialUnit);
......
......@@ -48,7 +48,7 @@ public List<IPerData> ReadData(ISheet sheet, List<PerHeader> perHeader)
{
var athead = vhead.ElementAt(c);
//var cellValue = NopiSevice.GetCellValue(row.GetCell(athead.PointCell));
var cellValue = ConvertHelper.To<decimal?>(row.GetCell(athead.PointCell).GetValue());
var cellValue = ConvertHelper.ToDecimalOrNull(row.GetCell(athead.PointCell).GetValue());
if (!cellValue.HasValue || cellValue.Value == 0)
continue;
......@@ -60,9 +60,9 @@ public List<IPerData> ReadData(ISheet sheet, List<PerHeader> perHeader)
Department = row.GetCell(unit.DeptCellNum.Value).GetValue(),
TypeName = athead?.CellValue,
CellValue = cellValue,
Annotation = row.GetCell(athead.PointCell)?.CellComment?.String?.String,
//Annotation = row.GetCell(athead.PointCell)?.CellComment?.String?.String,
UnitType = unit.UnitType,
FactorValue = ConvertHelper.To<decimal?>(sheet.GetRow(unit.FactorRow.Value).GetCell(athead.PointCell).GetValue()),
FactorValue = ConvertHelper.ToDecimalOrNull(sheet.GetRow(unit.FactorRow.Value).GetCell(athead.PointCell).GetValue()),
IsFactor = true,
};
if (sheet.SheetName.Contains("医生组"))
......
using System;
using System.Collections.Concurrent;
using System.Threading;
using System.Threading.Tasks;
//using System;
//using System.Collections.Concurrent;
//using System.Threading;
//using System.Threading.Tasks;
namespace Performance.Services.Queues
{
public interface IBackgroundTaskQueue
{
void QueueBackgroundWorkItem(Func<CancellationToken, Task> workItem);
//namespace Performance.Services.Queues
//{
// public interface IBackgroundTaskQueue
// {
// void QueueBackgroundWorkItem(Func<CancellationToken, Task> workItem);
Task<Func<CancellationToken, Task>> DequeueAsync(CancellationToken cancellationToken);
}
// Task<Func<CancellationToken, Task>> DequeueAsync(CancellationToken cancellationToken);
// }
public class BackgroundTaskQueue : IBackgroundTaskQueue
{
private readonly ConcurrentQueue<Func<CancellationToken, Task>> _workItems = new ConcurrentQueue<Func<CancellationToken, Task>>();
private readonly SemaphoreSlim _signal = new SemaphoreSlim(0);
// public class BackgroundTaskQueue : IBackgroundTaskQueue
// {
// private readonly ConcurrentQueue<Func<CancellationToken, Task>> _workItems = new ConcurrentQueue<Func<CancellationToken, Task>>();
// private readonly SemaphoreSlim _signal = new SemaphoreSlim(0);
public void QueueBackgroundWorkItem(Func<CancellationToken, Task> workItem)
{
if (workItem == null)
{
throw new ArgumentNullException(nameof(workItem));
}
// public void QueueBackgroundWorkItem(Func<CancellationToken, Task> workItem)
// {
// if (workItem == null)
// {
// throw new ArgumentNullException(nameof(workItem));
// }
_workItems.Enqueue(workItem);
_signal.Release();
}
// _workItems.Enqueue(workItem);
// _signal.Release();
// }
public async Task<Func<CancellationToken, Task>> DequeueAsync(CancellationToken cancellationToken)
{
await _signal.WaitAsync(cancellationToken);
_workItems.TryDequeue(out var workItem);
// public async Task<Func<CancellationToken, Task>> DequeueAsync(CancellationToken cancellationToken)
// {
// await _signal.WaitAsync(cancellationToken);
// _workItems.TryDequeue(out var workItem);
return workItem;
}
}
}
// return workItem;
// }
// }
//}
......@@ -574,8 +574,8 @@ private List<ag_bodysource> LoadEmployees_PrevSecondAllot(per_allot allot, ag_se
new ag_bodysource
{
WorkNumber = row.FirstOrDefault(w => w.ItemName == "人员工号")?.ItemValue,
TitleCoefficient = ConvertHelper.To<decimal?>(row.FirstOrDefault(w => w.ItemName == "职称系数")?.ItemValue),
StaffCoefficient = ConvertHelper.To<decimal?>(row.FirstOrDefault(w => w.ItemName == "人员系数")?.ItemValue),
TitleCoefficient = ConvertHelper.ToDecimalOrNull(row.FirstOrDefault(w => w.ItemName == "职称系数")?.ItemValue),
StaffCoefficient = ConvertHelper.ToDecimalOrNull(row.FirstOrDefault(w => w.ItemName == "人员系数")?.ItemValue),
})
.Distinct().ToList() ?? new List<ag_bodysource>();
......
......@@ -537,7 +537,7 @@ public void SaveSecondAllotHeadData(int secondId, string json)
SecondId = secondId,
FieldId = fieldId,
FieldName = i == 0 ? typeName + "占比" : typeName + "金额",
Value = prefix[i].StartsWith(prefix[0]) ? ConvertHelper.To<decimal?>(dict[fieldId.ToLower()]) : null,
Value = prefix[i].StartsWith(prefix[0]) ? ConvertHelper.ToDecimalOrNull(dict[fieldId.ToLower()]) : null,
};
insertData.Add(source);
......
......@@ -2213,8 +2213,8 @@ public dynamic Print(int secondId)
foreach (var rownumber in rownumbers)
{
var distperfor = ConvertHelper.To<decimal?>(fixaitems.FirstOrDefault(t => t.RowNumber == rownumber && t.ItemName == "可分配绩效")?.ItemValue);
var nightworkperfor = ConvertHelper.To<decimal?>(fixaitems.FirstOrDefault(t => t.RowNumber == rownumber && t.ItemName == "夜班工作量绩效")?.ItemValue);
var distperfor = ConvertHelper.ToDecimalOrNull(fixaitems.FirstOrDefault(t => t.RowNumber == rownumber && t.ItemName == "可分配绩效")?.ItemValue);
var nightworkperfor = ConvertHelper.ToDecimalOrNull(fixaitems.FirstOrDefault(t => t.RowNumber == rownumber && t.ItemName == "夜班工作量绩效")?.ItemValue);
var sec = new SecPrintResponse
{
JobNumber = fixaitems.FirstOrDefault(t => t.RowNumber == rownumber && t.ItemName == "人员工号")?.ItemValue,
......@@ -2223,11 +2223,11 @@ public dynamic Print(int secondId)
RealAmount = (distperfor ?? 0) + (nightworkperfor ?? 0),
};
sec.WorkPost = fixaitems.FirstOrDefault(t => t.RowNumber == rownumber && t.ItemName == "职称")?.ItemValue;
sec.TitlePerfor = ConvertHelper.To<decimal?>(fixaitems.FirstOrDefault(t => t.RowNumber == rownumber && t.ItemName == "职称绩效")?.ItemValue);
sec.WorkPerformance = ConvertHelper.To<decimal?>(fixaitems.FirstOrDefault(t => t.RowNumber == rownumber && t.ItemName == "工作量绩效工资")?.ItemValue);
sec.DeptReward = ConvertHelper.To<decimal?>(fixaitems.FirstOrDefault(t => t.RowNumber == rownumber && t.ItemName == "单项奖励小计")?.ItemValue);
sec.TitlePerfor = ConvertHelper.ToDecimalOrNull(fixaitems.FirstOrDefault(t => t.RowNumber == rownumber && t.ItemName == "职称绩效")?.ItemValue);
sec.WorkPerformance = ConvertHelper.ToDecimalOrNull(fixaitems.FirstOrDefault(t => t.RowNumber == rownumber && t.ItemName == "工作量绩效工资")?.ItemValue);
sec.DeptReward = ConvertHelper.ToDecimalOrNull(fixaitems.FirstOrDefault(t => t.RowNumber == rownumber && t.ItemName == "单项奖励小计")?.ItemValue);
sec.DistPerformance = distperfor;
sec.OtherPerformance = ConvertHelper.To<decimal?>(fixaitems.FirstOrDefault(t => t.RowNumber == rownumber && t.ItemName == "医院其他绩效")?.ItemValue);
sec.OtherPerformance = ConvertHelper.ToDecimalOrNull(fixaitems.FirstOrDefault(t => t.RowNumber == rownumber && t.ItemName == "医院其他绩效")?.ItemValue);
sec.NightWorkPerformance = nightworkperfor;
result.Add(sec);
}
......
using Performance.DtoModels;
using Performance.EntityModels;
using Performance.Repository;
using System;
using System.Collections.Generic;
using System.Linq;
namespace Performance.Services
{
public class TaskService : IAutoInjection
{
private readonly PerforBgtaskRepository _taskRepository;
public TaskService(
PerforBgtaskRepository taskRepository)
{
_taskRepository = taskRepository;
}
/// <summary>
/// 默认返回 最近10小时的任务
/// </summary>
/// <param name="hours"></param>
/// <returns></returns>
public List<bg_task> GetTasks(int hours = -10)
{
return _taskRepository.GetEntities(w => w.CreateTime > DateTime.Now.AddHours(hours));
}
public bool Add(Background.JobType type, string argument = "")
{
return _taskRepository.Add(new bg_task
{
Name = type.ToString(),
JobType = (int)type,
CreateTime = DateTime.Now,
Argument = argument,
Status = (int)Background.Status.等待,
Remark = $"{type} - {Background.Status.等待}"
});
}
public bool Update(int taskId, Background.Status status, string remark = "", double seconds = 0)
{
var task = _taskRepository.GetEntity(w => w.ID == taskId);
if (task == null) return false;
task.Status = (int)status;
if (status == Background.Status.执行中)
task.BeginTime = DateTime.Now;
task.ElapsedTime = seconds;
task.Remark = $"{(Background.JobType)task.JobType} - {status} {remark}";
if (status == Background.Status.完成 || status == Background.Status.失败 || status == Background.Status.超时)
task.EndTime = DateTime.Now;
return _taskRepository.Update(task);
}
}
}
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