Commit 446b121e by lcx

新抽取方法调整

parent 67333612
...@@ -1805,6 +1805,11 @@ ...@@ -1805,6 +1805,11 @@
ExTypeId ExTypeId
</summary> </summary>
</member> </member>
<member name="P:Performance.EntityModels.ex_script.ConfigId">
<summary>
配置Id
</summary>
</member>
<member name="P:Performance.EntityModels.ex_script.IsEnable"> <member name="P:Performance.EntityModels.ex_script.IsEnable">
<summary> <summary>
是否可用 1 可用 2 不可用 是否可用 1 可用 2 不可用
......
...@@ -25,6 +25,10 @@ public class PerSheetPoint ...@@ -25,6 +25,10 @@ public class PerSheetPoint
/// 数据开始行 /// 数据开始行
/// </summary> /// </summary>
public int? DataFirstRowNum { get; set; } public int? DataFirstRowNum { get; set; }
/// <summary>
/// 数据开始列
/// </summary>
public int? DataFirstCellNum { get; set; }
public List<AccountingUnit> AccountingUnit { get; set; } public List<AccountingUnit> AccountingUnit { get; set; }
/// <summary> /// <summary>
......
...@@ -35,6 +35,11 @@ public class ex_script ...@@ -35,6 +35,11 @@ public class ex_script
/// ExTypeId /// ExTypeId
/// </summary> /// </summary>
public int TypeId { get; set; } public int TypeId { get; set; }
/// <summary>
/// 配置Id
/// </summary>
public int ConfigId { get; set; }
/// <summary> /// <summary>
/// 是否可用 1 可用 2 不可用 /// 是否可用 1 可用 2 不可用
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
namespace Performance.Services.ExtractExcelService.ExtractHelper namespace Performance.Services.ExtractExcelService
{ {
public static class ExcelHelper public static class ExcelHelper
{ {
......
using System;
using System.Collections.Generic;
using System.Text;
namespace Performance.Services.ExtractExcelService.ExtractHelper
{
class ExtractDataHelper
{
}
}
using NPOI.SS.UserModel;
using Performance.DtoModels;
using Performance.EntityModels;
using Performance.Infrastructure;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
namespace Performance.Services.ExtractExcelService
{
public class ExtractHelper
{
public static (string template, string filepath) GetExtractFile(int hospitalId, string allotFilePath = "")
{
string originalPath = string.IsNullOrEmpty(allotFilePath)
? Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Template", "医院绩效模板.xls")
: allotFilePath;
return CopyOriginalFile(hospitalId, originalPath);
}
private static (string TempPath, string FilePath) CopyOriginalFile(int hospitalId, string originalPath)
{
var ext = FileHelper.GetExtension(originalPath);
var dpath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Files", $"{hospitalId}", "autoextract");
FileHelper.CreateDirectory(dpath);
string tempPath = Path.Combine(dpath, $"Template{DateTime.Now.ToString("yyyyMMddHHmmssfff")}{ext}");
FileHelper.Copy(originalPath, tempPath);
string filePath = Path.Combine(dpath, $"绩效提取数据{DateTime.Now.ToString("yyyyMMddHHmmssfff")}.xls");
return (tempPath, filePath);
}
public static void CreateNotExistSheet(List<ex_module> modulesList, IWorkbook workbook)
{
SortedDictionary<string, int> pairs = new SortedDictionary<string, int>();
for (int i = 0; i < workbook.NumberOfSheets; i++)
{
var sheetname = workbook.GetSheetAt(i).SheetName;
if (!pairs.Keys.Contains(sheetname))
pairs.Add(workbook.GetSheetAt(i).SheetName, i);
}
int sheetIndex = 0;
int newSheetCount = 0;
foreach (var module in modulesList.Where(t => t.SheetType == (int)SheetType.Income)?.OrderBy(t => t.ModuleName))
{
var sheet = workbook.GetSheet(module.ModuleName);
if (sheet == null)
{
string[] keyArray = new string[] { "开单", "执行" };
if (keyArray.Any(key => module.ModuleName.Contains(key)))
{
var item = pairs.Where(t => t.Key.StartsWith("1.")).OrderByDescending(t => t.Key).First();
if (sheetIndex == 0)
sheetIndex = item.Value + 1;
var copysheet = workbook.GetSheet(item.Key);
var newSheet = copysheet.CopySheet(item.Key + Guid.NewGuid().ToString("N"), true);
workbook.SetSheetOrder(newSheet.SheetName, sheetIndex);
workbook.SetSheetName(sheetIndex, module.ModuleName);
sheetIndex++; newSheetCount++;
}
}
}
sheetIndex = 0;
foreach (var module in modulesList.Where(t => t.SheetType == (int)SheetType.Workload)?.OrderBy(t => t.ModuleName))
{
var sheet = workbook.GetSheet(module.ModuleName);
if (sheet == null)
{
string key = "工作量";
if (module.ModuleName.Contains(key))
{
var item = pairs.Where(t => t.Key.StartsWith("3.")).OrderByDescending(t => t.Key).First();
if (sheetIndex == 0)
sheetIndex = item.Value + newSheetCount + 1;
var copysheet = workbook.GetSheet(item.Key);
var newSheet = copysheet.CopySheet(item.Key + Guid.NewGuid().ToString("N"), true);
workbook.SetSheetOrder(newSheet.SheetName, sheetIndex);
workbook.SetSheetName(sheetIndex, module.ModuleName);
sheetIndex++;
}
}
}
}
public static void ClearSheetPartialData(ISheet sheet, PerSheetPoint point, SheetType sheetType)
{
if (sheet == null)
return;
for (int i = point.DataFirstRowNum.Value; i < sheet.LastRowNum + 1; i++)
{
var row = sheet.GetRow(i);
if (row != null)
{
int dataFirstCellRowNum = point.DataFirstCellNum.Value;
//跳过核算单元和科室
for (int j = dataFirstCellRowNum; j < row.LastCellNum; j++)
{
var cell = row.GetCell(j);
if (cell != null && (cell.CellType != CellType.Formula || sheetType == SheetType.Income))
{
cell.RemoveCellComment();
row.RemoveCell(cell);
}
}
}
}
}
}
}
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
using System.Linq; using System.Linq;
using System.Text; using System.Text;
namespace Performance.Services.ExtractExcelService.ExtractHelper namespace Performance.Services.ExtractExcelService
{ {
public class WriteDataHelper public class WriteDataHelper
{ {
...@@ -16,7 +16,7 @@ public enum UnitType ...@@ -16,7 +16,7 @@ public enum UnitType
医技组 医技组
} }
public void WriteSheetHeader(ISheet sheet, PerSheetPoint point, SheetType sheetType, int fixedCount, List<ExcelHeader> headers) public void WriteSheetHeader(ISheet sheet, PerSheetPoint point, SheetType sheetType, List<ExcelHeader> headers)
{ {
if (headers == null || !headers.Any()) return; if (headers == null || !headers.Any()) return;
...@@ -32,8 +32,8 @@ public void WriteSheetHeader(ISheet sheet, PerSheetPoint point, SheetType sheetT ...@@ -32,8 +32,8 @@ public void WriteSheetHeader(ISheet sheet, PerSheetPoint point, SheetType sheetT
var workloadFactor = sheet.GetOrCreate(point.HeaderFirstRowNum.Value + 1); var workloadFactor = sheet.GetOrCreate(point.HeaderFirstRowNum.Value + 1);
// 去除excel中已存在的列 // 去除excel中已存在的列
int headerFirstCellNum = point.HeaderFirstCellNum.Value + fixedCount; int headerFirstCellNum = point.DataFirstCellNum.Value;
if (columnHeader.LastCellNum > point.HeaderFirstCellNum + fixedCount) if (columnHeader.LastCellNum > point.DataFirstCellNum)
{ {
for (int index = headerFirstCellNum; index < columnHeader.LastCellNum; index++) for (int index = headerFirstCellNum; index < columnHeader.LastCellNum; index++)
{ {
...@@ -75,37 +75,37 @@ public void WriteSheetHeader(ISheet sheet, PerSheetPoint point, SheetType sheetT ...@@ -75,37 +75,37 @@ public void WriteSheetHeader(ISheet sheet, PerSheetPoint point, SheetType sheetT
} }
} }
public void WriteSheetData(ISheet sheet, PerSheetPoint point, SheetType sheetType, int fixedCount, List<string> headers, List<ExtractTransDto> data) public void WriteSheetData(ISheet sheet, PerSheetPoint point, SheetType sheetType, List<string> headers, List<ExtractTransDto> data)
{ {
var columnHeader = sheet.GetOrCreate(point.HeaderFirstRowNum.Value); var columnHeader = sheet.GetOrCreate(point.HeaderFirstRowNum.Value);
int headerFirstRowNum = point.HeaderFirstRowNum.Value + 1; int headerFirstRowNum = point.HeaderFirstRowNum.Value + 1;
WriteSheetDataExistent(sheet, columnHeader, point, sheetType, fixedCount, headers, data, ref headerFirstRowNum); WriteSheetDataExistent(sheet, columnHeader, point, sheetType, headers, data, ref headerFirstRowNum);
if (data == null || !data.Any(t => !string.IsNullOrEmpty(t.Department))) return; if (data == null || !data.Any(t => !string.IsNullOrEmpty(t.Department))) return;
WriteSheetDataNonexistent(sheet, columnHeader, point, sheetType, fixedCount, headers, data, headerFirstRowNum); WriteSheetDataNonexistent(sheet, columnHeader, point, sheetType, headers, data, headerFirstRowNum);
} }
private void WriteSheetDataExistent(ISheet sheet, IRow columnHeader, PerSheetPoint point, SheetType sheetType, private void WriteSheetDataExistent(ISheet sheet, IRow columnHeader, PerSheetPoint point, SheetType sheetType,
int fixedCount, List<string> headers, List<ExtractTransDto> data, ref int headerFirstRowNum) List<string> headers, List<ExtractTransDto> data, ref int headerFirstRowNum)
{ {
if (sheet.LastRowNum > headerFirstRowNum) if (sheet.LastRowNum > headerFirstRowNum)
{ {
int headerFirstCellNum = point.HeaderFirstCellNum.Value + fixedCount; int dataFirstCellNum = point.DataFirstCellNum.Value;
for (int rowIndex = headerFirstRowNum; rowIndex < sheet.LastRowNum + 1; rowIndex++) for (int rowIndex = headerFirstRowNum; rowIndex < sheet.LastRowNum + 1; rowIndex++)
{ {
var row = sheet.GetRow(rowIndex); var row = sheet.GetRow(rowIndex);
if (row == null) continue; if (row == null) continue;
string department = row.GetOrCreate(headerFirstCellNum - 1).GetDecodeEscapes(); string department = row.GetOrCreate(dataFirstCellNum - 1).GetDecodeEscapes();
if (string.IsNullOrEmpty(department)) continue; if (string.IsNullOrEmpty(department)) continue;
var deptData = data.Where(t => t.Department == department); var deptData = data.Where(t => t.Department == department);
if (deptData == null || !deptData.Any()) continue; if (deptData == null || !deptData.Any()) continue;
for (int cellIndex = headerFirstCellNum; cellIndex < columnHeader.LastCellNum; cellIndex++) for (int cellIndex = dataFirstCellNum; cellIndex < columnHeader.LastCellNum; cellIndex++)
{ {
var column = columnHeader.GetOrCreate(cellIndex).GetDecodeEscapes(); var column = columnHeader.GetOrCreate(cellIndex).GetDecodeEscapes();
var cell = row.GetOrCreate(cellIndex); var cell = row.GetOrCreate(cellIndex);
...@@ -134,7 +134,7 @@ public void WriteSheetData(ISheet sheet, PerSheetPoint point, SheetType sheetTyp ...@@ -134,7 +134,7 @@ public void WriteSheetData(ISheet sheet, PerSheetPoint point, SheetType sheetTyp
} }
private void WriteSheetDataNonexistent(ISheet sheet, IRow columnHeader, PerSheetPoint point, SheetType sheetType, private void WriteSheetDataNonexistent(ISheet sheet, IRow columnHeader, PerSheetPoint point, SheetType sheetType,
int fixedCount, List<string> headers, List<ExtractTransDto> data, int headerFirstRowNum) List<string> headers, List<ExtractTransDto> data, int headerFirstRowNum)
{ {
var departments = data.Select(s => s.Department).Where(w => !string.IsNullOrEmpty(w)).Distinct().ToList(); var departments = data.Select(s => s.Department).Where(w => !string.IsNullOrEmpty(w)).Distinct().ToList();
...@@ -212,7 +212,7 @@ public void WriteSheetData(ISheet sheet, PerSheetPoint point, SheetType sheetTyp ...@@ -212,7 +212,7 @@ public void WriteSheetData(ISheet sheet, PerSheetPoint point, SheetType sheetTyp
/// </summary> /// </summary>
/// <param name="list"></param> /// <param name="list"></param>
/// <returns></returns> /// <returns></returns>
public string HasValue(params string[] list) public static string HasValue(params string[] list)
{ {
if (list == null || !list.Any()) return null; if (list == null || !list.Any()) return null;
......
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using Performance.DtoModels; using Performance.DtoModels;
using Performance.EntityModels;
using Performance.Repository; using Performance.Repository;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
...@@ -12,6 +13,8 @@ public class ExtractService : IAutoInjection ...@@ -12,6 +13,8 @@ public class ExtractService : IAutoInjection
{ {
private readonly ILogger logger; private readonly ILogger logger;
private readonly LogManageService logService; private readonly LogManageService logService;
private readonly QueryService queryService;
private readonly PersonService personService;
private readonly PerSheetService perSheetService; private readonly PerSheetService perSheetService;
private readonly PerforHospitalRepository hospitalRepository; private readonly PerforHospitalRepository hospitalRepository;
private readonly PerforPerallotRepository perallotRepository; private readonly PerforPerallotRepository perallotRepository;
...@@ -20,6 +23,8 @@ public class ExtractService : IAutoInjection ...@@ -20,6 +23,8 @@ public class ExtractService : IAutoInjection
public ExtractService( public ExtractService(
ILogger<ExtractService> logger, ILogger<ExtractService> logger,
LogManageService logService, LogManageService logService,
QueryService queryService,
PersonService personService,
PerSheetService perSheetService, PerSheetService perSheetService,
PerforHospitalRepository hospitalRepository, PerforHospitalRepository hospitalRepository,
PerforPerallotRepository perallotRepository, PerforPerallotRepository perallotRepository,
...@@ -28,6 +33,8 @@ PerforcollectdataRepository perforcollectdataRepository ...@@ -28,6 +33,8 @@ PerforcollectdataRepository perforcollectdataRepository
{ {
this.logger = logger; this.logger = logger;
this.logService = logService; this.logService = logService;
this.queryService = queryService;
this.personService = personService;
this.perSheetService = perSheetService; this.perSheetService = perSheetService;
this.hospitalRepository = hospitalRepository; this.hospitalRepository = hospitalRepository;
this.perallotRepository = perallotRepository; this.perallotRepository = perallotRepository;
...@@ -55,6 +62,10 @@ public string Main(int allotId, int hospitalId, string email, string groupName = ...@@ -55,6 +62,10 @@ public string Main(int allotId, int hospitalId, string email, string groupName =
if (allots == null || !allots.Any(t => t.ID == allotId)) throw new Exception("绩效不存在"); if (allots == null || !allots.Any(t => t.ID == allotId)) throw new Exception("绩效不存在");
var allot = allots.First(t => t.ID == allotId); var allot = allots.First(t => t.ID == allotId);
var dict = new Dictionary<ExDataDict, object>();
var data = queryService.Handler(hospitalId, allot, ref dict);
var standData = StandDataFormat(hospitalId, data);
var statesArray = new int[] { (int)AllotStates.GenerateSucceed, (int)AllotStates.Archive }; var statesArray = new int[] { (int)AllotStates.GenerateSucceed, (int)AllotStates.Archive };
var lastAllot = allots.Where(t => statesArray.Contains(t.States))?.OrderByDescending(t => t.Year)?.ThenByDescending(t => t.Month)?.First(); var lastAllot = allots.Where(t => statesArray.Contains(t.States))?.OrderByDescending(t => t.Year)?.ThenByDescending(t => t.Month)?.First();
...@@ -72,5 +83,81 @@ public string Main(int allotId, int hospitalId, string email, string groupName = ...@@ -72,5 +83,81 @@ public string Main(int allotId, int hospitalId, string email, string groupName =
return extractFilePath; return extractFilePath;
} }
private void WriteToTemplate()
{ }
private void WriteToAllotFile()
{
}
/// <summary>
/// 标准数据格式, 匹配科室字典
/// </summary>
/// <param name="hospitalId"></param>
/// <param name="results"></param>
/// <returns></returns>
private List<ExtractTransDto> StandDataFormat(int hospitalId, List<ex_result> results)
{
if (results == null || !results.Any()) return new List<ExtractTransDto>();
var dict = personService.GetDepartments(hospitalId)?.ToList();
if (dict == null || !dict.Any())
return results.Select(t => new ExtractTransDto
{
SheetName = t.Source,
DoctorName = t.DoctorName,
PersonnelNumber = t.PersonnelNumber,
Department = t.Department,
Category = t.Category,
Value = (t.Fee ?? 0) == 0 ? null : t.Fee
}).ToList();
dict.ForEach(t =>
{
t.HISDeptName = WriteDataHelper.HasValue(t.HISDeptName, t.Department);
});
var data = results.GroupJoin(dict, outer => new { Department = outer.Department }, inner => new { Department = inner.HISDeptName }, (outer, inner) => new { outer, inner })
.Select(t =>
{
var dept = !string.IsNullOrEmpty(t.inner.FirstOrDefault()?.Department) ? t.inner.FirstOrDefault()?.Department : t.outer.Department;
return new ExtractTransDto
{
SheetName = t.outer.Source,
Department = dept,
Category = t.outer.Category,
DoctorName = t.outer.DoctorName,
PersonnelNumber = t.outer.PersonnelNumber,
Value = t.outer.Fee ?? 0,
OutDoctorAccounting = t.inner.FirstOrDefault(f => f.Department == dept)?.OutDoctorAccounting?.AccountingUnit,
OutNurseAccounting = t.inner.FirstOrDefault(f => f.Department == dept)?.OutNurseAccounting?.AccountingUnit,
OutTechnicAccounting = t.inner.FirstOrDefault(f => f.Department == dept)?.OutTechnicAccounting?.AccountingUnit,
InpatDoctorAccounting = t.inner.FirstOrDefault(f => f.Department == dept)?.InpatDoctorAccounting?.AccountingUnit,
InpatNurseAccounting = t.inner.FirstOrDefault(f => f.Department == dept)?.InpatNurseAccounting?.AccountingUnit,
InpatTechnicAccounting = t.inner.FirstOrDefault(f => f.Department == dept)?.InpatTechnicAccounting?.AccountingUnit,
};
});
var groupdata = data.GroupBy(t => new { t.Department, t.Category, t.SheetName }).Select(t => new ExtractTransDto
{
SheetName = t.Key.SheetName,
Department = t.Key.Department,
Category = t.Key.Category,
Value = t.Sum(group => group.Value) == 0 ? null : t.Sum(group => group.Value),
OutDoctorAccounting = t.First().OutDoctorAccounting,
OutNurseAccounting = t.First().OutNurseAccounting,
OutTechnicAccounting = t.First().OutTechnicAccounting,
InpatDoctorAccounting = t.First().InpatDoctorAccounting,
InpatNurseAccounting = t.First().InpatNurseAccounting,
InpatTechnicAccounting = t.First().InpatTechnicAccounting,
});
return groupdata.ToList();
}
} }
} }
using Dapper;
using Microsoft.Extensions.Logging;
using Performance.DtoModels;
using Performance.EntityModels;
using Performance.Repository;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
namespace Performance.Services.ExtractExcelService
{
public enum ExDataDict
{
ExModule = 1,
ExItem = 2,
ExSpecial = 3,
}
public class QueryService : IAutoInjection
{
private readonly ILogger logger;
private readonly PerforExmoduleRepository exmoduleRepository;
private readonly PerforExitemRepository exitemRepository;
private readonly PerforExspecialRepository exspecialRepository;
private readonly PerforExscriptRepository exscriptRepository;
private readonly PerforExresultRepository exresultRepository;
private readonly PerforHospitalconfigRepository hosconfigRepository;
private readonly PerforPerallotRepository perallotRepository;
public QueryService(
ILogger<QueryService> logger,
PerforExmoduleRepository exmoduleRepository,
PerforExitemRepository exitemRepository,
PerforExspecialRepository exspecialRepository,
PerforExscriptRepository exscriptRepository,
PerforExresultRepository exresultRepository,
PerforHospitalconfigRepository hosconfigRepository,
PerforPerallotRepository perallotRepository
)
{
this.logger = logger;
this.exmoduleRepository = exmoduleRepository;
this.exitemRepository = exitemRepository;
this.exspecialRepository = exspecialRepository;
this.exscriptRepository = exscriptRepository;
this.exresultRepository = exresultRepository;
this.hosconfigRepository = hosconfigRepository;
this.perallotRepository = perallotRepository;
}
private readonly DateTime CreateTime = DateTime.Now;
/// <summary>
/// 获取抽取数据
/// </summary>
/// <param name="hospitalId"></param>
/// <param name="allot"></param>
/// <returns></returns>
public List<ex_result> Handler(int hospitalId, per_allot allot, ref Dictionary<ExDataDict, object> dict)
{
try
{
var configs = hosconfigRepository.GetEntities(t => t.HospitalId == hospitalId);
if (configs == null || !configs.Any()) throw new Exception("医院未配置绩效抽取信息");
dict = new Dictionary<ExDataDict, object>();
var extypeIds = GetQueryScriptIds(hospitalId, ref dict);
ClearHistoryData(allot.ID);
var data = new List<ex_result>();
var scripts = exscriptRepository.GetEntities(t => extypeIds.Contains(t.TypeId));
if (scripts != null && scripts.Any())
{
var allmodules = new List<ex_module>();
if (dict.ContainsKey(ExDataDict.ExModule)) allmodules = dict[ExDataDict.ExModule] as List<ex_module>;
foreach (var pair in dict)
{
switch (pair.Key)
{
case ExDataDict.ExModule:
data.AddRange(ExtractModuleData(allot, scripts, configs, pair.Value));
break;
case ExDataDict.ExItem:
data.AddRange(ExtractItemData(allot, scripts, configs, allmodules, pair.Value));
break;
case ExDataDict.ExSpecial:
data.AddRange(ExtractSpecialData(allot, scripts, configs, pair.Value));
break;
}
}
}
return data;
}
catch (Exception ex)
{
logger.LogError("获取数据时发生异常");
throw ex;
}
}
/// <summary>
/// 获取医院抽取项配置
/// </summary>
/// <param name="hospitalId"></param>
/// <param name="dict"></param>
/// <returns></returns>
private List<int> GetQueryScriptIds(int hospitalId, ref Dictionary<ExDataDict, object> dict)
{
var extypeIds = new List<int>();
var modules = exmoduleRepository.GetEntities(t => t.HospitalId == hospitalId);
var items = new List<ex_item>();
if (modules != null && modules.Any())
{
dict.Add(ExDataDict.ExModule, modules);
extypeIds.AddRange(modules.Select(t => t.TypeId ?? 0));
items = exitemRepository.GetEntities(t => t.ModuleId.HasValue && modules.Select(m => m.Id).Contains(t.ModuleId.Value));
if (items != null && items.Any(t => t.TypeId.HasValue))
{
dict.Add(ExDataDict.ExItem, items);
extypeIds.AddRange(items.Select(t => t.TypeId ?? 0));
}
}
var specials = exspecialRepository.GetEntities(t => t.HospitalId == hospitalId);
if (specials != null && specials.Any())
{
dict.Add(ExDataDict.ExSpecial, specials);
extypeIds.AddRange(specials.Select(t => t.TypeId ?? 0));
}
var exids = extypeIds.Where(t => t > 0);
if (exids == null || !exids.Any()) return new List<int>();
return exids.Distinct().ToList();
}
/// <summary>
/// 清除历史抽取数据
/// </summary>
/// <param name="allotId"></param>
private void ClearHistoryData(int allotId)
{
logger.LogInformation($"开始清除历史提取数据");
perallotRepository.ClearResultData(allotId);
logger.LogInformation($"清除历史提取数据已完成");
}
#region ExResultData
/// <summary>
/// 获取收入费用
/// </summary>
/// <param name="allot"></param>
/// <param name="scripts"></param>
/// <param name="configs"></param>
/// <param name="dictValue"></param>
/// <returns></returns>
private List<ex_result> ExtractModuleData(per_allot allot, List<ex_script> scripts, List<sys_hospitalconfig> configs, object dictValue)
{
var data = new List<ex_result>();
if (dictValue is List<ex_module> modules && modules != null && modules.Any(t => t.TypeId.HasValue && t.TypeId > 0))
{
var typeIds = modules.Where(t => t.TypeId.HasValue && t.TypeId > 0).Select(t => t.TypeId.Value).Distinct().ToList();
if (typeIds == null || typeIds.Count == 0) return new List<ex_result>();
foreach (var typeId in typeIds)
{
foreach (var script in scripts.Where(t => t.TypeId == typeId))
{
var config = configs.FirstOrDefault(t => t.Id == script.ConfigId);
if (config == null) continue;
var querydata = QueryData(config, allot, script.ExecScript);
if (querydata != null && querydata.Any())
{
var thisModules = modules.Where(t => t.TypeId == typeId).ToList();
thisModules.ForEach(f =>
{
var result = querydata.Select(t => new ex_result
{
Department = t.Department,
Category = t.Category?.Trim(),
Fee = t.Value,
DoctorName = t.DoctorName,
PersonnelNumber = t.PersonnelNumber,
Source = f.ModuleName,
DatabaseType = config.DataBaseType,
ConfigId = config.Id,
AllotId = allot.ID,
CreateTime = CreateTime,
}).ToList();
exresultRepository.AddRange(result.ToArray());
data.AddRange(result);
});
}
}
}
}
return data;
}
/// <summary>
/// 获取工作量、成本等费用
/// </summary>
/// <param name="allot"></param>
/// <param name="scripts"></param>
/// <param name="configs"></param>
/// <param name="modules"></param>
/// <param name="dictValue"></param>
/// <returns></returns>
private List<ex_result> ExtractItemData(per_allot allot, List<ex_script> scripts, List<sys_hospitalconfig> configs, List<ex_module> modules, object dictValue)
{
var data = new List<ex_result>();
if (dictValue is List<ex_item> items && items != null && items.Any(t => t.TypeId.HasValue && t.TypeId > 0))
{
var typeIds = items.Where(t => t.TypeId.HasValue && t.TypeId > 0).Select(t => t.TypeId.Value).Distinct().ToList();
foreach (var typeId in typeIds)
{
foreach (var script in scripts.Where(t => t.TypeId == typeId))
{
var config = configs.FirstOrDefault(t => t.Id == script.ConfigId);
if (config == null) continue;
var querydata = QueryData(config, allot, script.ExecScript);
if (querydata != null && querydata.Any())
{
var thisItems = items.Where(t => t.TypeId == typeId).ToList();
var modulename = modules.FirstOrDefault(t => t.Id == thisItems.First().ModuleId)?.ModuleName;
thisItems.ForEach(f =>
{
var result = querydata.Select(t => new ex_result
{
Department = t.Department,
Category = f.ItemName,
Fee = t.Value,
DoctorName = t.DoctorName,
PersonnelNumber = t.PersonnelNumber,
Source = modulename,
DatabaseType = config.DataBaseType,
ConfigId = config.Id,
AllotId = allot.ID,
CreateTime = CreateTime,
}).ToList();
exresultRepository.AddRange(result.ToArray());
data.AddRange(result);
});
}
}
}
}
return data;
}
/// <summary>
/// 获取特殊核算费用
/// </summary>
/// <param name="allot"></param>
/// <param name="scripts"></param>
/// <param name="configs"></param>
/// <param name="dictValue"></param>
/// <returns></returns>
private List<ex_result> ExtractSpecialData(per_allot allot, List<ex_script> scripts, List<sys_hospitalconfig> configs, object dictValue)
{
var data = new List<ex_result>();
if (dictValue is List<ex_special> specials && specials != null && specials.Any(t => t.TypeId.HasValue && t.TypeId > 0))
{
var typeIds = specials.Where(t => t.TypeId.HasValue && t.TypeId > 0).Select(t => t.TypeId.Value).Distinct().ToList();
foreach (var typeId in typeIds)
{
foreach (var script in scripts.Where(t => t.TypeId == typeId))
{
var config = configs.FirstOrDefault(t => t.Id == script.ConfigId);
if (config == null) continue;
var querydata = QueryData(config, allot, script.ExecScript);
if (querydata != null && querydata.Any())
{
var thisSpecials = specials.Where(t => t.TypeId == typeId).ToList();
thisSpecials.ForEach(f =>
{
var result = querydata.Select(t => new ex_result
{
Department = f.Department,
Category = f.Target,
Fee = t.Value,
DoctorName = t.DoctorName,
PersonnelNumber = t.PersonnelNumber,
Source = "4.2 特殊核算单元绩效测算表",
DatabaseType = config.DataBaseType,
ConfigId = config.Id,
AllotId = allot.ID,
CreateTime = CreateTime,
}).ToList();
exresultRepository.AddRange(result.ToArray());
data.AddRange(result);
});
}
}
}
}
return data;
}
#endregion
#region QueryData
/// <summary>
/// 查询数据
/// </summary>
/// <param name="config"></param>
/// <param name="allot"></param>
/// <param name="execsql"></param>
/// <param name="source"></param>
/// <param name="category"></param>
/// <returns></returns>
private IEnumerable<ExtractDto> QueryData(sys_hospitalconfig config, per_allot allot, string execsql)
{
var parameters = GetParameters(allot);
using (var connection = ConnectionBuilder.Create((DatabaseType)config.DataBaseType, config.DbSource, config.DbName, config.DbUser, config.DbPassword))
{
foreach (var item in parameters)
{
execsql = Regex.Replace(execsql, item.Key, item.Value, RegexOptions.IgnoreCase);
}
logger.LogInformation($"提取绩效数据SQL脚本{execsql}");
var result = connection.Query<ExtractDto>(execsql, commandTimeout: 20000);
logger.LogInformation($"提取绩效数据执行脚本获取数据{result?.Count() ?? 0}条记录");
return result;
}
}
/// <summary>
/// 获取参数
/// </summary>
/// <param name="allot"></param>
/// <returns></returns>
private Dictionary<string, string> GetParameters(per_allot allot)
{
DateTime beginTime = new DateTime(allot.Year, allot.Month, 1);
Dictionary<string, string> pairs = new Dictionary<string, string>
{
{ "@beginTime", $"'{beginTime.ToString("yyyy-MM-dd")}'" },
{ "@endTime", $"'{beginTime.AddMonths(1).ToString("yyyy-MM-dd")}'"},
};
return pairs;
}
#endregion
}
}
...@@ -4,7 +4,8 @@ ...@@ -4,7 +4,8 @@
namespace Performance.Services.ExtractExcelService.SheetDataWrite namespace Performance.Services.ExtractExcelService.SheetDataWrite
{ {
class ISheetDataWrite public interface ISheetDataWrite
{ {
void WriteSheetData();
} }
} }
...@@ -19,6 +19,7 @@ public class PerSheetDataReadIncome : IPerSheetDataRead ...@@ -19,6 +19,7 @@ public class PerSheetDataReadIncome : IPerSheetDataRead
HeaderLastRowNum = 4, HeaderLastRowNum = 4,
HeaderFirstCellNum = 3, HeaderFirstCellNum = 3,
DataFirstRowNum = 5, DataFirstRowNum = 5,
DataFirstCellNum = 7,
AccountingUnit = new List<AccountingUnit> AccountingUnit = new List<AccountingUnit>
{ {
//核算单元(医技组) //核算单元(医技组)
......
...@@ -19,6 +19,7 @@ public class PerSheetDataReadOtherIncome : IPerSheetDataRead ...@@ -19,6 +19,7 @@ public class PerSheetDataReadOtherIncome : IPerSheetDataRead
HeaderLastRowNum = 4, HeaderLastRowNum = 4,
HeaderFirstCellNum = 3, HeaderFirstCellNum = 3,
DataFirstRowNum = 5, DataFirstRowNum = 5,
DataFirstCellNum = 7,
AccountingUnit = new List<AccountingUnit> AccountingUnit = new List<AccountingUnit>
{ {
//核算单元(医技组) //核算单元(医技组)
......
...@@ -19,6 +19,7 @@ public class PerSheetDataReadWorkload : IPerSheetDataRead ...@@ -19,6 +19,7 @@ public class PerSheetDataReadWorkload : IPerSheetDataRead
HeaderLastRowNum = 1, HeaderLastRowNum = 1,
HeaderFirstCellNum = 1, HeaderFirstCellNum = 1,
DataFirstRowNum = 3, DataFirstRowNum = 3,
DataFirstCellNum = 3,
AccountingUnit = new List<AccountingUnit> AccountingUnit = new List<AccountingUnit>
{ {
new AccountingUnit new AccountingUnit
......
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