Commit aead617a by ruyun.zhang@suvalue.com

Merge remote-tracking branch 'origin/feature/extract' into feature/extract

parents 6c302c21 b9a18025
...@@ -319,20 +319,32 @@ public ApiResponse SaveFile([FromForm] IFormCollection form, int allotId, int ho ...@@ -319,20 +319,32 @@ public ApiResponse SaveFile([FromForm] IFormCollection form, int allotId, int ho
byte[] bytes = new byte[stream.Length]; byte[] bytes = new byte[stream.Length];
stream.Read(bytes, 0, bytes.Length); stream.Read(bytes, 0, bytes.Length);
if (!FileHelper.CreateFile(path, bytes)) if (!FileHelper.CreateFile(path, bytes))
{
LogHelper.Error($"保存失败", "保存提取文件");
return new ApiResponse(ResponseType.Error, "保存失败"); return new ApiResponse(ResponseType.Error, "保存失败");
}
} }
var allot = allotService.GetAllot(allotId); var allot = allotService.GetAllot(allotId);
allot.ExtractPath = path; allot.ExtractPath = path;
allot.IsExtracting = 2; allot.IsExtracting = 2;
if (!string.IsNullOrEmpty(path) && allotService.Update(allot)) if (string.IsNullOrEmpty(path) || !FileHelper.IsExistFile(path))
return new ApiResponse(ResponseType.OK, "上传成功!"); {
LogHelper.Information($"文件未保存成功,保存文件不存在!", "保存提取文件");
return new ApiResponse(ResponseType.Fail, "上传成功!");
}
if (!allotService.Update(allot))
{
LogHelper.Information($"更新文件路径失败!", "保存提取文件");
return new ApiResponse(ResponseType.Fail, "上传成功!");
}
return new ApiResponse(ResponseType.OK, "上传成功!");
} }
catch (Exception ex) catch (Exception ex)
{ {
logger.LogInformation($"保存提取文件异常{ex.ToString()}"); logger.LogInformation($"保存提取文件异常{ex.ToString()}");
LogHelper.Error($"保存失败:" + ex.ToString(), "保存提取文件"); LogHelper.Error($"保存失败:" + ex.ToString(), "保存提取文件");
return new ApiResponse(ResponseType.Error,ex.Message);
} }
return new ApiResponse(ResponseType.Error);
} }
} }
} }
\ No newline at end of file
...@@ -119,23 +119,32 @@ public void ExtractData([CustomizeValidator, FromBody]ExtractRequest request) ...@@ -119,23 +119,32 @@ public void ExtractData([CustomizeValidator, FromBody]ExtractRequest request)
{ {
LogHelper.Information("请求参数:" + JsonHelper.Serialize(request), "提取绩效数据"); LogHelper.Information("请求参数:" + JsonHelper.Serialize(request), "提取绩效数据");
string filePath = newExtractService.ExtractData(request.AllotId, request.Email, request.HospitalId); string filePath = newExtractService.ExtractData(request.AllotId, request.Email, request.HospitalId);
LogHelper.Information("提取文件路径:" + filePath, "提取绩效数据");
if (!string.IsNullOrEmpty(filePath) && FileHelper.IsExistFile(filePath)) if (!string.IsNullOrEmpty(filePath) && FileHelper.IsExistFile(filePath))
{ {
LogHelper.Information("请求路径:" + url.ImportFile + ",请求参数" + JsonHelper.Serialize(new { allotId = request.AllotId, hospitalId = request.HospitalId }), "保存提取文件");
int i = 1; int i = 1;
while (i <= 5) while (i <= 5)
{ {
LogHelper.Information("请求路径:" + url.ImportFile, "保存提取文件"); if (i == 5)
string retJson = HttpHelper.HttpClient(url.ImportFile + $"?allotId={request.AllotId}&hospitalId={request.HospitalId}", filePath); LogHelper.Information($"保存文件失败,已尝试执行五次,请联系开发人员!", "保存提取文件");
else
LogHelper.Information($"正在尝试第{i}次保存!", "保存提取文件");
//保存文件
string retJson = HttpHelper.HttpClient(url.ImportFile + $"?allotId={request.AllotId}&hospitalId={request.HospitalId}", filePath);
LogHelper.Information("返回结果:" + JsonHelper.Serialize(retJson), "保存提取文件"); LogHelper.Information("返回结果:" + JsonHelper.Serialize(retJson), "保存提取文件");
logger.LogInformation(retJson); logger.LogInformation(retJson);
var ret = JsonHelper.Deserialize<ApiResponse>(retJson); var ret = JsonHelper.Deserialize<ApiResponse>(retJson);
if ((int)ret.State == 1) if (ret != null && (int)ret.State == 1)
{
LogHelper.Information("保存成功!", "保存提取文件");
break; break;
}
i++; i++;
} }
} }
else
LogHelper.Information($"提取文件不存在!", "保存提取文件");
} }
#endregion #endregion
......
...@@ -12,6 +12,7 @@ public enum StyleType ...@@ -12,6 +12,7 @@ public enum StyleType
//列头固定, //列头固定,
列头, 列头,
系数, 系数,
数据,
默认, 默认,
} }
public enum CellFormat public enum CellFormat
...@@ -61,7 +62,11 @@ public static ICellStyle CreateCellStyle(IWorkbook wb, StyleType type = StyleTyp ...@@ -61,7 +62,11 @@ public static ICellStyle CreateCellStyle(IWorkbook wb, StyleType type = StyleTyp
cellStyle.FillPattern = FillPattern.SolidForeground; cellStyle.FillPattern = FillPattern.SolidForeground;
break; break;
case StyleType.系数: case StyleType.系数:
cellStyle.FillForegroundColor = HSSFColor.LightGreen.Index; cellStyle.FillForegroundColor = HSSFColor.Green.Index;
cellStyle.FillPattern = FillPattern.SolidForeground;
break;
case StyleType.数据:
cellStyle.FillForegroundColor = HSSFColor.SkyBlue.Index;
cellStyle.FillPattern = FillPattern.SolidForeground; cellStyle.FillPattern = FillPattern.SolidForeground;
break; break;
case StyleType.默认: case StyleType.默认:
......
...@@ -193,9 +193,9 @@ public mod_module EditModule(ModModuleRequest request) ...@@ -193,9 +193,9 @@ public mod_module EditModule(ModModuleRequest request)
throw new PerformanceException("绩效模板已存在!"); throw new PerformanceException("绩效模板已存在!");
entity.ModuleName = request.ModuleName ?? entity.ModuleName; entity.ModuleName = request.ModuleName ?? entity.ModuleName;
entity.SheetType = request.SheetType ?? entity.SheetType; entity.SheetType = request.SheetType;
entity.Description = request.Description ?? entity.Description; entity.Description = request.Description;
entity.ExtractId = request.ExtractId ?? entity.ExtractId; entity.ExtractId = request.ExtractId;
if (!perforModmoduleRepository.Update(entity)) if (!perforModmoduleRepository.Update(entity))
throw new PerformanceException("修改失败!"); throw new PerformanceException("修改失败!");
......
...@@ -113,29 +113,7 @@ public string ExtractData(int allotId, string email, int hospitalId) ...@@ -113,29 +113,7 @@ public string ExtractData(int allotId, string email, int hospitalId)
CreateNotExistSheet(modulesList, workbook); CreateNotExistSheet(modulesList, workbook);
#region 单元格样式 style = CellStyle.CreateCellStyle(workbook, StyleType.数据);
style = workbook.CreateCellStyle();
//字体
IFont titleFont = workbook.CreateFont();
titleFont.FontHeightInPoints = 11;
titleFont.FontName = "微软雅黑";//设置字体大小
titleFont.Color = HSSFColor.Black.Index;//设置字体颜色
style.SetFont(titleFont);
//边框
style.BorderBottom = BorderStyle.Thin;
style.BorderLeft = BorderStyle.Thin;
style.BorderRight = BorderStyle.Thin;
style.BorderTop = BorderStyle.Thin;
//前景色
style.FillForegroundColor = NPOI.HSSF.Util.HSSFColor.SkyBlue.Index;
style.FillPattern = FillPattern.SolidForeground;
//居中
style.Alignment = HorizontalAlignment.Center;//水平居中
style.VerticalAlignment = VerticalAlignment.Center;//垂直居中
#endregion
List<AccountUnitEntity> unitList = new List<AccountUnitEntity>(); List<AccountUnitEntity> unitList = new List<AccountUnitEntity>();
if (allotLast != null) if (allotLast != null)
...@@ -241,7 +219,7 @@ private void WriteOtherIncome(ISheet sheet, int hospitalId, IPerSheetDataRead sh ...@@ -241,7 +219,7 @@ private void WriteOtherIncome(ISheet sheet, int hospitalId, IPerSheetDataRead sh
int cellStartIndex = sheetRead.Point.HeaderFirstCellNum.Value + 4; int cellStartIndex = sheetRead.Point.HeaderFirstCellNum.Value + 4;
LogHelper.Information($"写入额外收入列头信息", "提取绩效数据"); LogHelper.Information($"写入列头信息 -- {module.ModuleName}", "提取绩效数据");
//写入列头信息 //写入列头信息
foreach (var item in itemList) foreach (var item in itemList)
{ {
...@@ -277,7 +255,7 @@ private void WriteIncome(ISheet sheet, int hospitalId, List<AccountUnitEntity> u ...@@ -277,7 +255,7 @@ private void WriteIncome(ISheet sheet, int hospitalId, List<AccountUnitEntity> u
var technicianFactor = sheet.GetRow(sheetRead.Point.AccountingUnit.First(t => t.UnitType == "医技组").FactorRow.Value); var technicianFactor = sheet.GetRow(sheetRead.Point.AccountingUnit.First(t => t.UnitType == "医技组").FactorRow.Value);
var head = GetOrCreate(sheet, sheetRead.Point.HeaderFirstRowNum.Value); var head = GetOrCreate(sheet, sheetRead.Point.HeaderFirstRowNum.Value);
LogHelper.Information($"写入收入列头信息", "提取绩效数据"); LogHelper.Information($"写入列头信息 -- {module.ModuleName}", "提取绩效数据");
//写入列头信息 //写入列头信息
int cellStartIndex = sheetRead.Point.HeaderFirstCellNum.Value + 4; int cellStartIndex = sheetRead.Point.HeaderFirstCellNum.Value + 4;
foreach (var item in itemList) foreach (var item in itemList)
...@@ -306,12 +284,13 @@ private void WriteIncome(ISheet sheet, int hospitalId, List<AccountUnitEntity> u ...@@ -306,12 +284,13 @@ private void WriteIncome(ISheet sheet, int hospitalId, List<AccountUnitEntity> u
List<ExtractDto> allExtract = new List<ExtractDto>(); List<ExtractDto> allExtract = new List<ExtractDto>();
foreach (var item in extractList) foreach (var item in extractList)
{ {
LogHelper.Information($"执行SQL脚本获取数据 -- {module.ModuleName},", "提取绩效数据");
var result = QueryDatabase(hospitalConfigList, item, allot); var result = QueryDatabase(hospitalConfigList, item, allot);
if (result != null) if (result != null)
allExtract.AddRange(result); allExtract.AddRange(result);
} }
LogHelper.Information($"填充收入数据", "提取绩效数据"); LogHelper.Information($"填充数据 -- {module.ModuleName}", "提取绩效数据");
//写入数据 //写入数据
var rowIndex = sheetRead.Point.HeaderFirstRowNum.Value + 1; var rowIndex = sheetRead.Point.HeaderFirstRowNum.Value + 1;
foreach (var department in allExtract.Select(t => t.Department).Distinct()) foreach (var department in allExtract.Select(t => t.Department).Distinct())
...@@ -399,7 +378,7 @@ private void WriteWorkload(ISheet sheet, int hospitalId, List<AccountUnitEntity> ...@@ -399,7 +378,7 @@ private void WriteWorkload(ISheet sheet, int hospitalId, List<AccountUnitEntity>
var head = GetOrCreate(sheet, sheetRead.Point.HeaderFirstRowNum.Value + 0); var head = GetOrCreate(sheet, sheetRead.Point.HeaderFirstRowNum.Value + 0);
var factor = GetOrCreate(sheet, sheetRead.Point.HeaderFirstRowNum.Value + 1); var factor = GetOrCreate(sheet, sheetRead.Point.HeaderFirstRowNum.Value + 1);
LogHelper.Information($"写入工作量列头信息", "提取绩效数据"); LogHelper.Information($"写入列头信息 -- {module.ModuleName}", "提取绩效数据");
//写入列头信息 //写入列头信息
int cellStartIndex = sheetRead.Point.HeaderFirstCellNum.Value + 2; int cellStartIndex = sheetRead.Point.HeaderFirstCellNum.Value + 2;
foreach (var item in itemList) foreach (var item in itemList)
...@@ -410,7 +389,7 @@ private void WriteWorkload(ISheet sheet, int hospitalId, List<AccountUnitEntity> ...@@ -410,7 +389,7 @@ private void WriteWorkload(ISheet sheet, int hospitalId, List<AccountUnitEntity>
var doctorcell = GetOrCreate(factor, cellStartIndex); var doctorcell = GetOrCreate(factor, cellStartIndex);
doctorcell.SetCellValue(item.FactorValue1 != null ? (double)item.FactorValue1 : 0); doctorcell.SetCellValue(item.FactorValue1 != null ? (double)item.FactorValue1 : 0);
doctorcell.CellStyle = CellStyle.CreateCellStyle(workbook, StyleType.系数, CellFormat.百分比); doctorcell.CellStyle = CellStyle.CreateCellStyle(workbook, StyleType.列头, CellFormat.数字2);
cellStartIndex++; cellStartIndex++;
} }
//查询数据 //查询数据
...@@ -425,6 +404,7 @@ private void WriteWorkload(ISheet sheet, int hospitalId, List<AccountUnitEntity> ...@@ -425,6 +404,7 @@ private void WriteWorkload(ISheet sheet, int hospitalId, List<AccountUnitEntity>
if (category == null || category.Count() == 0) continue; if (category == null || category.Count() == 0) continue;
foreach (var moditem in category) foreach (var moditem in category)
{ {
LogHelper.Information($"执行SQL脚本获取数据 -- {module.ModuleName},", "提取绩效数据");
var result = QueryDatabase(hospitalConfigList, item, allot, moditem.ItemName); var result = QueryDatabase(hospitalConfigList, item, allot, moditem.ItemName);
if (result != null) if (result != null)
allExtract.AddRange(result); allExtract.AddRange(result);
...@@ -438,7 +418,7 @@ private void WriteWorkload(ISheet sheet, int hospitalId, List<AccountUnitEntity> ...@@ -438,7 +418,7 @@ private void WriteWorkload(ISheet sheet, int hospitalId, List<AccountUnitEntity>
specialHead = itemList.Select(t => t.ItemName).Intersect(extractHead.Distinct())?.ToList(); specialHead = itemList.Select(t => t.ItemName).Intersect(extractHead.Distinct())?.ToList();
} }
LogHelper.Information($"填充工作量数据", "提取绩效数据"); LogHelper.Information($"填充数据 -- {module.ModuleName}", "提取绩效数据");
//写入数据 //写入数据
var rowIndex = sheetRead.Point.HeaderFirstRowNum.Value + 2; var rowIndex = sheetRead.Point.HeaderFirstRowNum.Value + 2;
foreach (var department in allExtract.Select(t => t.Department).Distinct()) foreach (var department in allExtract.Select(t => t.Department).Distinct())
...@@ -474,7 +454,6 @@ private void WriteWorkload(ISheet sheet, int hospitalId, List<AccountUnitEntity> ...@@ -474,7 +454,6 @@ private void WriteWorkload(ISheet sheet, int hospitalId, List<AccountUnitEntity>
private List<ExtractDto> QueryDatabase(List<sys_hospitalconfig> hospitalConfigList, mod_extract extract, per_allot allot, string category = null) private List<ExtractDto> QueryDatabase(List<sys_hospitalconfig> hospitalConfigList, mod_extract extract, per_allot allot, string category = null)
{ {
LogHelper.Information($"执行SQL脚本获取数据,", "提取绩效数据");
var config = hospitalConfigList.FirstOrDefault(t => t.Type == extract.SourceType); var config = hospitalConfigList.FirstOrDefault(t => t.Type == extract.SourceType);
var executeScript = extract.ExecuteScript; var executeScript = extract.ExecuteScript;
var parameters = GetParameters(allot); var parameters = GetParameters(allot);
...@@ -485,7 +464,6 @@ private List<ExtractDto> QueryDatabase(List<sys_hospitalconfig> hospitalConfigLi ...@@ -485,7 +464,6 @@ private List<ExtractDto> QueryDatabase(List<sys_hospitalconfig> hospitalConfigLi
executeScript = Regex.Replace(executeScript, item.Key, item.Value, RegexOptions.IgnoreCase); executeScript = Regex.Replace(executeScript, item.Key, item.Value, RegexOptions.IgnoreCase);
} }
LogHelper.Information($"SQL脚本{executeScript},", "提取绩效数据"); LogHelper.Information($"SQL脚本{executeScript},", "提取绩效数据");
var result = connection.Query<ExtractDto>(executeScript, commandTimeout: 20000); var result = connection.Query<ExtractDto>(executeScript, commandTimeout: 20000);
if (result != null && result.Count() > 0) if (result != null && result.Count() > 0)
{ {
...@@ -515,7 +493,7 @@ private void WriteExpend(ISheet sheet, int hospitalId, IPerSheetDataRead sheetRe ...@@ -515,7 +493,7 @@ private void WriteExpend(ISheet sheet, int hospitalId, IPerSheetDataRead sheetRe
int cellStartIndex = sheetRead.Point.HeaderFirstCellNum.Value + 4; int cellStartIndex = sheetRead.Point.HeaderFirstCellNum.Value + 4;
LogHelper.Information($"写入成本支出列头信息", "提取绩效数据"); LogHelper.Information($"写入列头信息 -- {module.ModuleName}", "提取绩效数据");
//写入列头信息 //写入列头信息
foreach (var item in itemList) foreach (var item in itemList)
{ {
...@@ -552,7 +530,7 @@ private void WriteExpend(ISheet sheet, int hospitalId, IPerSheetDataRead sheetRe ...@@ -552,7 +530,7 @@ private void WriteExpend(ISheet sheet, int hospitalId, IPerSheetDataRead sheetRe
private void WriteEmployee(ISheet sheet, int allotLastId, IPerSheetDataRead sheetRead) private void WriteEmployee(ISheet sheet, int allotLastId, IPerSheetDataRead sheetRead)
{ {
LogHelper.Information($"填充人员信息", "提取绩效数据"); LogHelper.Information($"填充数据 -- 人员信息", "提取绩效数据");
var dictionary = new Dictionary<string, Func<im_employee, object>> var dictionary = new Dictionary<string, Func<im_employee, object>>
{ {
{ "核算单元", (t) => t.AccountingUnit }, { "核算单元", (t) => t.AccountingUnit },
...@@ -592,7 +570,7 @@ private void WriteEmployee(ISheet sheet, int allotLastId, IPerSheetDataRead shee ...@@ -592,7 +570,7 @@ private void WriteEmployee(ISheet sheet, int allotLastId, IPerSheetDataRead shee
private void WriteSpecialUnit(ISheet sheet, int hospitalId, per_allot allotLast, IPerSheetDataRead sheetRead) private void WriteSpecialUnit(ISheet sheet, int hospitalId, per_allot allotLast, IPerSheetDataRead sheetRead)
{ {
LogHelper.Information($"填充特殊核算单元绩效测算表", "提取绩效数据"); LogHelper.Information($"填充数据 -- 特殊核算单元绩效测算表", "提取绩效数据");
var dictionary = new Dictionary<string, Func<mod_special, List<im_specialunit>, object>> var dictionary = new Dictionary<string, Func<mod_special, List<im_specialunit>, object>>
{ {
{ "科室", (special,lastAllot) => special.Department }, { "科室", (special,lastAllot) => special.Department },
...@@ -672,7 +650,7 @@ private void WriteSpecialUnit(ISheet sheet, int hospitalId, per_allot allotLast, ...@@ -672,7 +650,7 @@ private void WriteSpecialUnit(ISheet sheet, int hospitalId, per_allot allotLast,
private void WriteAccountBasic(ISheet sheet, int allotLastId, IPerSheetDataRead sheetRead) private void WriteAccountBasic(ISheet sheet, int allotLastId, IPerSheetDataRead sheetRead)
{ {
LogHelper.Information($"填充临床科室医护绩效测算表", "提取绩效数据"); LogHelper.Information($"填充数据 -- 临床科室医护绩效测算表", "提取绩效数据");
var dictionary = new Dictionary<string, Func<im_accountbasic, object>> var dictionary = new Dictionary<string, Func<im_accountbasic, object>>
{ {
{ "核算单元类型", (t) => t.UnitType }, { "核算单元类型", (t) => t.UnitType },
...@@ -822,7 +800,7 @@ public string Judge(int allotId, int hospitalId, int useTemplate) ...@@ -822,7 +800,7 @@ public string Judge(int allotId, int hospitalId, int useTemplate)
catch (PerformanceException ex) catch (PerformanceException ex)
{ {
LogHelper.Error(ex.ToString(), "提取绩效数据"); LogHelper.Error(ex.ToString(), "提取绩效数据");
result = ex.ToString(); result = ex.Message;
} }
catch (Exception ex) catch (Exception 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