Commit 03c1e62f by 李承祥

抽取数据修改

parent d8184d59
......@@ -113,6 +113,9 @@ public ApiResponse ExtractData([CustomizeValidator(RuleSet = "Template"), FromBo
var allot = allotService.GetAllot(request.ID);
if (allot == null)
return new ApiResponse(ResponseType.Fail, "该绩效无效");
allot.IsExtracting = allot.IsExtracting ?? 0;
if (allot.IsExtracting == 1)
return new ApiResponse(ResponseType.Fail, "正在提取数据,请稍等。");
var hospital = hospitalService.GetHopital(request.HospitalId.Value);
if (hospital == null)
......@@ -125,7 +128,10 @@ public ApiResponse ExtractData([CustomizeValidator(RuleSet = "Template"), FromBo
mail = user.Mail,
hospitalId = hospital.ID
});
HttpHelper.HttpPost(url.ExtractData, param, true);
allot.IsExtracting = 1;
allotService.Update(allot);
HttpHelper.HttpPostNoRequest(url.ExtractData, param, true);
//extractService.ExtractData(request.ID, user.Mail, hospital);
//BackgroundJob.Enqueue(() => extractService.ExtractData(request.ID, user.Mail, hospital));
return new ApiResponse(ResponseType.OK, "HIS绩效数据提取任务正在执行,稍后我们将以邮件的通知您!");
......@@ -183,6 +189,7 @@ public ApiResponse SaveFile([FromForm] IFormCollection form, int allotId, int ho
}
var allot = allotService.GetAllot(allotId);
allot.ExtractPath = path;
allot.IsExtracting = 2;
if (!string.IsNullOrEmpty(path) && allotService.Update(allot))
return new ApiResponse(ResponseType.OK, "上传成功!");
else
......
......@@ -75,5 +75,10 @@ public class per_allot
/// 提取绩效数据文件生成路径
/// </summary>
public string ExtractPath { get; set; }
/// <summary>
/// 是否在抽取数据0 否、1 是、2 抽取成功、3 抽取失败
/// </summary>
public Nullable<int> IsExtracting { get; set; }
}
}
......@@ -35,6 +35,8 @@ public class ExtractController : Controller
[Route("index")]
public void Index([FromBody]AllotRequest request)
{
var token = Guid.NewGuid().ToString("N");
logger.LogInformation(token + ",开始提取数据,请求参数:" + JsonHelper.Serialize(request));
var hospital = hospitalService.GetHopital(request.HospitalId.Value);
var filepath = extractService.ExtractData(request.ID, request.Mail, hospital);
if (!string.IsNullOrEmpty(filepath) && FileHelper.IsExistFile(filepath))
......@@ -51,6 +53,7 @@ public void Index([FromBody]AllotRequest request)
i++;
}
}
logger.LogInformation(token + ",提取结束,请求参数:" + JsonHelper.Serialize(request));
}
}
}
\ No newline at end of file
......@@ -11,6 +11,7 @@
<PackageReference Include="Microsoft.AspNetCore.Razor.Design" Version="2.2.0" PrivateAssets="All" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="2.2.0" />
<PackageReference Include="NLog.Extensions.Logging" Version="1.5.1" />
<PackageReference Include="NLog.Web.AspNetCore" Version="4.8.0" />
</ItemGroup>
<ItemGroup>
......
......@@ -17,6 +17,7 @@
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using NLog.Extensions.Logging;
using NLog.Web;
using Performance.DtoModels.AppSettings;
using Performance.DtoModels.AutoMapper;
using Performance.EntityModels;
......@@ -27,8 +28,9 @@ namespace Performance.Extract.Api
{
public class Startup
{
public Startup(IConfiguration configuration)
public Startup(IConfiguration configuration, IHostingEnvironment env)
{
env.ConfigureNLog("nlog.config");
Configuration = configuration;
}
......
<?xml version="1.0" encoding="utf-8"?>
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
autoReload="true"
internalLogLevel="info"
internalLogFile="c:\Temp\GrapefruitVuCore\internal-nlog.txt">
<!-- enable asp.net core and mongodb layout renderers -->
<extensions>
<add assembly="NLog.Web.AspNetCore"/>
<add assembly="NLog.Mongo"/>
</extensions>
<!--internal-nlog:NLog启动及加载config信息-->
<!--nlog-all:所有日志记录信息-->
<!--nlog-own:自定义日志记录信息-->
<!-- the targets to write to -->
<targets>
<!-- write logs to file -->
<target xsi:type="File" name="allfile" fileName="${basedir}/Logs/${shortdate}/${level}.log"
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}" />
<!-- write log to mongodb-->
<!--<target xsi:type="Mongo"
name="mongo" databaseName="nlog"
collectionName="Logs"
connectionString="mongodb://172.31.216.37:27017/nlog"
cappedCollectionSize="26214400">
<property name="LongDate" layout="${longdate}" bsonType="DateTime" />
<property name="Level" layout="${level}" />
<property name="Logger" layout="${logger}"/>
<property name="Message" layout="${message}" />
<property name="Exception" layout="${exception:format=tostring}" />
<property name="Url" layout="${aspnet-request-url}" />
<property name="Action" layout="${aspnet-mvc-action}" />
<property name="UserName" layout="${windows-identity}" />
</target>-->
</targets>
<!-- rules to map from logger name to target -->
<rules>
<!--All logs, including from Microsoft-->
<logger name="*" minlevel="Trace" writeTo="allfile" />
<!--Skip non-critical Microsoft logs and so log only own logs-->
<logger name="Microsoft.*" maxLevel="Info" final="true" />
<!-- BlackHole without writeTo -->
<logger name="*" minlevel="Trace" writeTo="ownFile-web" />
<!--Add logs to mongodb-->
<!--<logger name="*" minlevel="Trace" writeTo="mongo"/>-->
</rules>
</nlog>
\ No newline at end of file
......@@ -6,6 +6,7 @@
using System.Net.Security;
using System.Security.Cryptography.X509Certificates;
using System.Text;
using System.Threading;
namespace Performance.Infrastructure
{
......@@ -108,6 +109,59 @@ public static bool CheckValidationResult(object sender, X509Certificate certific
return true;
}
#region 发送post请求
/// <summary>
/// 发送post请求
/// </summary>
/// <param name="Url"></param>
/// <param name="postDataStr"></param>
/// <returns></returns>
public static void HttpPostNoRequest(string Url, string postDataStr, bool IsJson = false)
{
HttpWebResponse response = null;
HttpWebRequest request = null;
if (Url.ToLower().StartsWith("https"))
ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(CheckValidationResult);//验证服务器证书回调自动验证
try
{
//ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3;
System.GC.Collect();
request = (HttpWebRequest)WebRequest.Create(Url);
request.Method = "POST";
request.KeepAlive = false;
request.ProtocolVersion = HttpVersion.Version10;
if (IsJson)
request.ContentType = "application/json";
else
request.ContentType = "application/x-www-form-urlencoded";
byte[] bData = (Encoding.UTF8.GetBytes(postDataStr));
request.ContentLength = bData.Length;
Stream writeStream = request.GetRequestStream();
writeStream.Write(bData, 0, bData.Length);
writeStream.Close();
request.GetResponseAsync();
Thread.Sleep(1000);
}
catch (Exception ex)
{
throw ex;
}
finally
{
if (request != null)
request.Abort();
if (response != null)
response.Close();
}
}
#endregion 发送post请求
/// <summary>
/// 请求文件 post file
/// </summary>
......
......@@ -144,6 +144,12 @@ public string ExtractData(int allotId, string mail, sys_hospital hospital)
logger.LogError(ex.ToString());
LogHelper.Error(ex.ToString(), "提取绩效数据", "异常");
SendEmail(mail, "", $"{hospital.HosName}HIS数据提取失败", $"{hospital.HosName}提取数据失败,{ex.Message}!");
var allot = perforPerallotRepository.GetEntity(t => t.ID == allotId);
if (allot != null)
{
allot.IsExtracting = 3;
perforPerallotRepository.Update(allot);
}
throw ex;
}
catch (Exception ex)
......@@ -151,6 +157,12 @@ public string ExtractData(int allotId, string mail, sys_hospital hospital)
logger.LogError(ex.ToString());
LogHelper.Error(ex.ToString(), "提取绩效数据", "异常");
SendEmail(mail, "", $"{hospital.HosName}HIS数据提取失败", $"{hospital.HosName}提取数据过程中出现异常情况,我们将尽快解决问题。给您带来的不便我们深感歉意!");
var allot = perforPerallotRepository.GetEntity(t => t.ID == allotId);
if (allot != null)
{
allot.IsExtracting = 3;
perforPerallotRepository.Update(allot);
}
throw ex;
}
}
......
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