Commit ae932817 by 李承祥

数据抽取

parent 2c120c9b
......@@ -109,32 +109,55 @@ public ApiResponse Import([FromForm] IFormCollection form)
[HttpPost]
public ApiResponse ExtractData([CustomizeValidator(RuleSet = "Template"), FromBody]AllotRequest request)
{
try
{
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)
return new ApiResponse(ResponseType.Fail, "医院无效");
var user = claim.At(request.Token);
allot.IsExtracting = 1;
allotService.Update(allot);
string path = extractService.GetFilepath(hospital.ID, out int type);
if (!string.IsNullOrEmpty(path) && type != 0)
{
//发送请求,返回路径
string retJson = HttpHelper.HttpClient(url.ImportFirst + $"?type={type}&hospitalId={hospital.ID}&year={allot.Year}&month={allot.Month}", path);
var ret = JsonHelper.Deserialize<ApiResponse>(retJson);
if ((int)ret.State != 1)
return new ApiResponse(ResponseType.Fail, "首次模板地址无效!");
}
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)
return new ApiResponse(ResponseType.Fail, "医院无效");
var user = claim.At(request.Token);
string param = JsonHelper.Serialize(new
string param = JsonHelper.Serialize(new
{
id = request.ID,
hospitalId = hospital.ID,
mail = user.Mail,
path = path
});
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绩效数据提取任务正在执行,稍后我们将以邮件的通知您!");
}
catch (Exception ex)
{
id = request.ID,
mail = user.Mail,
hospitalId = hospital.ID
});
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绩效数据提取任务正在执行,稍后我们将以邮件的通知您!");
var allot = allotService.GetAllot(request.ID);
if (allot != null)
{
allot.IsExtracting = 3;
allotService.Update(allot);
}
throw ex;
}
}
/// <summary>
......
......@@ -24,7 +24,8 @@
"HttpPath": "http://testjx.suvalue.com:81"
},
"WebapiUrl": {
"ImportFirst": "http://localhost:50997/api/extract/import",
"ExtractData": "http://localhost:50997/api/extract/index",
"ImportFile": "http://localhost:5001/api/template/savefile"
"ImportFile": ""
}
}
......@@ -39,6 +39,7 @@
"HttpPath": "http://testjx.suvalue.com:81"
},
"WebapiUrl": {
"ImportFirst": "http://localhost:50997/api/extract/import",
"ExtractData": "http://localhost:50997/api/extract/index",
"ImportFile": "http://localhost:5001/api/template/savefile"
}
......
......@@ -7,9 +7,15 @@ namespace Performance.DtoModels.AppSettings
public class WebapiUrl
{
/// <summary>
/// 上传首次模板文件
/// </summary>
public string ImportFirst { get; set; }
/// <summary>
/// 抽取数据地址
/// </summary>
public string ExtractData { get; set; }
/// <summary>
/// 上传文件地址
/// </summary>
......
......@@ -28,6 +28,11 @@ public class AllotRequest : ApiRequest
/// 邮箱
/// </summary>
public string Mail { get; set; }
/// <summary>
/// 路径
/// </summary>
public string Path { get; set; }
}
public class AllotRequestValidator : AbstractValidator<AllotRequest>
......
......@@ -4,6 +4,9 @@
using System.Linq;
using System.Threading.Tasks;
using FluentValidation.AspNetCore;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Http.Internal;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.StaticFiles;
using Microsoft.Extensions.Logging;
......@@ -22,15 +25,57 @@ public class ExtractController : Controller
private readonly HospitalService hospitalService;
private readonly WebapiUrl url;
private readonly ILogger<ExtractController> logger;
private IHostingEnvironment evn;
public ExtractController(ExtractService extractService, HospitalService hospitalService,
IOptions<WebapiUrl> url, ILogger<ExtractController> logger)
IOptions<WebapiUrl> url, ILogger<ExtractController> logger,
IHostingEnvironment evn)
{
this.extractService = extractService;
this.hospitalService = hospitalService;
this.url = url.Value;
this.logger = logger;
this.evn = evn;
}
/// <summary>
/// 保存首次文件
/// </summary>
/// <param name="form"></param>
/// <param name="type">1、历史绩效文件 2、首次模板文件</param>
/// <param name="hospitalId"></param>
/// <returns></returns>
[Route("import")]
[HttpPost]
public ApiResponse Import([FromForm] IFormCollection form, int type, int hospitalId, int year, int month)
{
var file = ((FormFileCollection)form.Files).FirstOrDefault();
if (file == null)
return new ApiResponse(ResponseType.Error, "上传文件无效");
var dpath = Path.Combine(evn.ContentRootPath, "Files", $"{hospitalId}", "first");
if (type == 1)
dpath = Path.Combine(evn.ContentRootPath, "Files", $"{hospitalId}", $"{year}{month.ToString().PadLeft(2, '0')}");
FileHelper.CreateDirectory(dpath);
var path = Path.Combine(dpath, FileHelper.GetFileName(file.FileName));
using (var stream = file.OpenReadStream())
{
byte[] bytes = new byte[stream.Length];
stream.Read(bytes, 0, bytes.Length);
if (!FileHelper.CreateFile(path, bytes))
return new ApiResponse(ResponseType.Error, "保存失败");
}
if (!string.IsNullOrEmpty(path) && FileHelper.IsExistFile(path))
return new ApiResponse(ResponseType.OK, path);
else
return new ApiResponse(ResponseType.Error, "获取首次文件失败!");
}
/// <summary>
/// 提取数据
/// </summary>
/// <param name="request"></param>
[HttpPost]
[Route("index")]
public void Index([FromBody]AllotRequest request)
......@@ -38,7 +83,7 @@ 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);
var filepath = extractService.ExtractData(request.ID, request.Mail, hospital, request.Path);
if (!string.IsNullOrEmpty(filepath) && FileHelper.IsExistFile(filepath))
{
int i = 1;
......
......@@ -7,7 +7,8 @@
"AllowedHosts": "*",
//连接字符串
"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;",
//"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;",
"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=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"
},
......@@ -36,7 +37,8 @@
"HttpPath": "http://testjx.suvalue.com:81"
},
"WebapiUrl": {
"ExtractData": "http://localhost:50997/api/extract/index",
"ImportFirst": "",
"ExtractData": "",
"ImportFile": "http://localhost:5001/api/template/savefile"
}
}
......@@ -70,7 +70,38 @@ public class ExtractService : IAutoInjection
this.perforHospitalconfigRepository = perforHospitalconfigRepository;
}
public string ExtractData(int allotId, string mail, sys_hospital hospital)
/// <summary>
/// 获得首次模板路径
/// </summary>
/// <param name="hospitalId"></param>
/// <param name="type">1、历史绩效文件 2、首次模板文件</param>
/// <returns></returns>
public string GetFilepath(int hospitalId, out int type)
{
try
{
var firstList = perforPerfirstRepository.GetEntities(t => t.HospitalId == hospitalId);
var allotList = perforPerallotRepository.GetEntities(t => t.HospitalId == hospitalId);
type = 2;
if ((allotList == null || !allotList.Any(t => t.States > 0)) && (firstList != null || !firstList.Any()))
return firstList.OrderByDescending(t => t.CreateDate).FirstOrDefault().Path;
else
{
type = 1;
var allot = allotList.Where(t => t.Path != null && t.Path != "").OrderByDescending(t => t.Year).ThenByDescending(t => t.Month).First();
return allot.Path;
}
}
catch (Exception ex)
{
LogHelper.Error(ex.ToString(), "获取提取模板文件路径", "异常");
type = 0;
return "";
}
}
public string ExtractData(int allotId, string mail, sys_hospital hospital, string firstPath)
{
LogHelper.Information($"开始执行绩效数据提取任务{new { allotId, mail, hospital }}", "提取绩效数据");
List<PerSheet> sheetList = new List<PerSheet>();
......@@ -100,10 +131,10 @@ public string ExtractData(int allotId, string mail, sys_hospital hospital)
if ((allotList == null || !allotList.Any(t => t.States > 0)) && (firstList != null || !firstList.Any()))
{
LogHelper.Information($"当前绩效为首次提取,从EXCEL中获取信息", "提取绩效数据");
var first = firstList.OrderByDescending(t => t.CreateDate).FirstOrDefault();
//var first = firstList.OrderByDescending(t => t.CreateDate).FirstOrDefault();
//首次 从excel中获取人员信息,SHEET页信息,列头信息
sheetList = GetFileData(first.Path);
originalPath = first.Path;
sheetList = GetFileData(firstPath);
originalPath = firstPath;
}
else
{
......@@ -113,7 +144,7 @@ public string ExtractData(int allotId, string mail, sys_hospital hospital)
{
var allot = allotList.Where(t => t.Path != null && t.Path != "").OrderByDescending(t => t.Year).ThenByDescending(t => t.Month).First();
sheetList = GetRepositoryData(allot.ID);
originalPath = allot.Path;
originalPath = firstPath;
}
else
{
......@@ -581,7 +612,7 @@ public dynamic Verify(string obj)
return obj;
}
}
#endregion
#endregion
#region 获取列头
/// <summary>
......
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