Commit e73d4b6a by lcx

提取数据含有历史绩效时,保留科室,补充数据

parent 6b98dbdb
...@@ -136,6 +136,8 @@ public void ExtractData([FromForm] IFormCollection form, int allotId, int hospit ...@@ -136,6 +136,8 @@ public void ExtractData([FromForm] IFormCollection form, int allotId, int hospit
path = Path.Combine(dpath, FileHelper.GetFileName(file.FileName)); path = Path.Combine(dpath, FileHelper.GetFileName(file.FileName));
logger.LogInformation($"保存历史绩效文件保存路径:" + path); logger.LogInformation($"保存历史绩效文件保存路径:" + path);
if (!string.IsNullOrEmpty(path) && FileHelper.IsExistFile(path))
FileHelper.DeleteFile(path);
using (var stream = file.OpenReadStream()) using (var stream = file.OpenReadStream())
{ {
...@@ -152,14 +154,15 @@ public void ExtractData([FromForm] IFormCollection form, int allotId, int hospit ...@@ -152,14 +154,15 @@ public void ExtractData([FromForm] IFormCollection form, int allotId, int hospit
//string filePath = newExtractService.ExtractData(allotId, request.Email, hospitalId); //string filePath = newExtractService.ExtractData(allotId, request.Email, hospitalId);
string filePath = dfExtractService.ExtractData(allotId, email, hospitalId, path); //抽取 string filePath = dfExtractService.ExtractData(allotId, email, hospitalId, path); //抽取
if (!string.IsNullOrEmpty(path) && FileHelper.IsExistFile(path))
FileHelper.DeleteFile(path);
#region 保存文件到网站下 #region 保存文件到网站下
if (!string.IsNullOrEmpty(filePath) && FileHelper.IsExistFile(filePath)) if (!string.IsNullOrEmpty(filePath) && FileHelper.IsExistFile(filePath))
{ {
logger.LogInformation("请求路径:" + url.ImportFile + ",请求参数" + JsonHelper.Serialize(new { allotId, hospitalId })); logger.LogInformation("请求路径:" + url.ImportFile + ",请求参数" + JsonHelper.Serialize(new
{
allotId,
hospitalId
}));
int i = 1; int i = 1;
while (i <= 5) while (i <= 5)
{ {
......
...@@ -114,7 +114,8 @@ public string ExtractData(int allotId, string email, int hospitalId, string file ...@@ -114,7 +114,8 @@ public string ExtractData(int allotId, string email, int hospitalId, string file
extractIds = extractIds.Distinct().ToList(); extractIds = extractIds.Distinct().ToList();
var extracts = perforModextractRepository.GetEntities(t => extractIds.Contains(t.Id)); var extracts = perforModextractRepository.GetEntities(t => extractIds.Contains(t.Id));
return lastAllot == null ? TemplateExecute(email, lastAllot, hospital, configs, modules, items, specials, extracts) : AlllotExecute(email, lastAllot, hospital, configs, modules, items, specials, extracts, filePath); return lastAllot == null ? TemplateExecute(email, hospital, configs, modules, items, specials, extracts)
: AlllotExecute(email, hospital, configs, modules, items, specials, extracts, lastAllot, filePath);
} }
catch (Exception ex) catch (Exception ex)
{ {
...@@ -145,7 +146,7 @@ public string ExtractData(int allotId, string email, int hospitalId, string file ...@@ -145,7 +146,7 @@ public string ExtractData(int allotId, string email, int hospitalId, string file
/// <param name="specials"></param> /// <param name="specials"></param>
/// <param name="extracts"></param> /// <param name="extracts"></param>
/// <returns></returns> /// <returns></returns>
public string TemplateExecute(string email, per_allot lastAllot, sys_hospital hospital, List<sys_hospitalconfig> configs, List<mod_module> modules, List<mod_item> items, List<mod_special> specials, List<mod_extract> extracts) public string TemplateExecute(string email, sys_hospital hospital, List<sys_hospitalconfig> configs, List<mod_module> modules, List<mod_item> items, List<mod_special> specials, List<mod_extract> extracts)
{ {
string originalPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Template", "东方医院绩效模板.xlsx"); string originalPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Template", "东方医院绩效模板.xlsx");
var (tempPath, newPath) = CopyOriginalFile(hospital.ID, originalPath); var (tempPath, newPath) = CopyOriginalFile(hospital.ID, originalPath);
...@@ -156,8 +157,6 @@ public string TemplateExecute(string email, per_allot lastAllot, sys_hospital ho ...@@ -156,8 +157,6 @@ public string TemplateExecute(string email, per_allot lastAllot, sys_hospital ho
style = CellStyle.CreateCellStyle(workbook, StyleType.数据); style = CellStyle.CreateCellStyle(workbook, StyleType.数据);
List<AccountUnitEntity> unitList = new List<AccountUnitEntity>(); List<AccountUnitEntity> unitList = new List<AccountUnitEntity>();
if (lastAllot != null)
unitList = perforImdataRepository.GetAccountUnit(lastAllot.ID).ToList();
for (int i = 0; i < workbook.NumberOfSheets; i++) for (int i = 0; i < workbook.NumberOfSheets; i++)
{ {
...@@ -207,7 +206,7 @@ public string TemplateExecute(string email, per_allot lastAllot, sys_hospital ho ...@@ -207,7 +206,7 @@ public string TemplateExecute(string email, per_allot lastAllot, sys_hospital ho
/// <param name="specials"></param> /// <param name="specials"></param>
/// <param name="extracts"></param> /// <param name="extracts"></param>
/// <returns></returns> /// <returns></returns>
public string AlllotExecute(string email, per_allot lastAllot, sys_hospital hospital, List<sys_hospitalconfig> configs, List<mod_module> modules, List<mod_item> items, List<mod_special> specials, List<mod_extract> extracts, string path) public string AlllotExecute(string email, sys_hospital hospital, List<sys_hospitalconfig> configs, List<mod_module> modules, List<mod_item> items, List<mod_special> specials, List<mod_extract> extracts, per_allot lastAllot, string path)
{ {
if (string.IsNullOrEmpty(path)) throw new PerformanceException("历史绩效文件不存在!"); if (string.IsNullOrEmpty(path)) throw new PerformanceException("历史绩效文件不存在!");
...@@ -226,29 +225,28 @@ public string AlllotExecute(string email, per_allot lastAllot, sys_hospital hosp ...@@ -226,29 +225,28 @@ public string AlllotExecute(string email, per_allot lastAllot, sys_hospital hosp
{ {
var sheet = workbook.GetSheetAt(i); var sheet = workbook.GetSheetAt(i);
var sheetType = perSheetService.GetSheetType(sheet.SheetName); var sheetType = perSheetService.GetSheetType(sheet.SheetName);
if (sheetType == SheetType.Unidentifiable) continue;
var sheetRead = PerSheetDataFactory.GetDataRead(sheetType); var sheetRead = PerSheetDataFactory.GetDataRead(sheetType);
switch (sheetType) switch (sheetType)
{ {
case SheetType.OtherIncome: case SheetType.OtherIncome:
ClearData(sheet, 5); ClearData(sheet, 5, 4);
WriteOtherIncome(sheet, sheetRead, unitList, configs, modules, items, extracts, false); WriteOtherIncome(sheet, sheetRead, unitList, configs, modules, items, extracts, false);
break; break;
case SheetType.Income: case SheetType.Income:
ClearData(sheet, 5); ClearData(sheet, 5, 4, true);
WriteIncome(sheet, sheetRead, unitList, configs, modules, items, extracts, false); WriteIncome(sheet, sheetRead, unitList, configs, modules, items, extracts, false);
break; break;
case SheetType.Expend: case SheetType.Expend:
ClearData(sheet, 5); ClearData(sheet, 5, 4);
WriteExpend(sheet, sheetRead, unitList, configs, modules, items, extracts, false); WriteExpend(sheet, sheetRead, unitList, configs, modules, items, extracts, false);
break; break;
case SheetType.Workload: case SheetType.Workload:
ClearData(sheet, 3); ClearData(sheet, 3, 2);
WriteWorkload(sheet, sheetRead, unitList, configs, modules, items, extracts, false); WriteWorkload(sheet, sheetRead, unitList, configs, modules, items, extracts, false);
break; break;
case SheetType.SpecialUnit: case SheetType.SpecialUnit:
ClearData(sheet, 2); ClearData(sheet, 2, 0);
WriteSpecialUnit(sheet, sheetRead, configs, specials, extracts, false, lastAllot); WriteSpecialUnit(sheet, sheetRead, configs, specials, extracts, false, lastAllot);
break; break;
} }
...@@ -308,7 +306,7 @@ private static void CreateNotExistSheet(List<mod_module> modulesList, IWorkbook ...@@ -308,7 +306,7 @@ private static void CreateNotExistSheet(List<mod_module> modulesList, IWorkbook
} }
} }
private void ClearData(ISheet sheet, int beginRowNum) private void ClearData(ISheet sheet, int beginRowNum, int beginCellNum, bool isIncome = false)
{ {
if (sheet == null) if (sheet == null)
return; return;
...@@ -318,10 +316,11 @@ private void ClearData(ISheet sheet, int beginRowNum) ...@@ -318,10 +316,11 @@ private void ClearData(ISheet sheet, int beginRowNum)
var row = sheet.GetRow(i); var row = sheet.GetRow(i);
if (row != null) if (row != null)
{ {
for (int j = 0; j < row.LastCellNum + 1; j++) //跳过核算单元和科室
for (int j = beginCellNum; j < row.LastCellNum; j++)
{ {
var cell = row.GetCell(j); var cell = row.GetCell(j);
if (cell != null && cell.CellType != CellType.Formula) if (cell != null && (cell.CellType != CellType.Formula || isIncome))
{ {
cell.RemoveCellComment(); cell.RemoveCellComment();
row.RemoveCell(cell); row.RemoveCell(cell);
...@@ -356,7 +355,7 @@ private ICell GetOrCreate(IRow row, int index) ...@@ -356,7 +355,7 @@ private ICell GetOrCreate(IRow row, int index)
#region SheetData #region SheetData
private void WriteOtherIncome(ISheet sheet, IPerSheetDataRead sheetRead, List<AccountUnitEntity> unitList, List<sys_hospitalconfig> configs, List<mod_module> modules, List<mod_item> items, List<mod_extract> extracts, bool IsWriteHead = true) private void WriteOtherIncome(ISheet sheet, IPerSheetDataRead sheetRead, List<AccountUnitEntity> unitList, List<sys_hospitalconfig> configs, List<mod_module> modules, List<mod_item> items, List<mod_extract> extracts, bool isNewTemp = true)
{ {
logger.LogInformation($"{sheet.SheetName}开始提取."); logger.LogInformation($"{sheet.SheetName}开始提取.");
var module = modules.FirstOrDefault(t => t.SheetType == (int)SheetType.OtherIncome); var module = modules.FirstOrDefault(t => t.SheetType == (int)SheetType.OtherIncome);
...@@ -366,8 +365,7 @@ private void WriteOtherIncome(ISheet sheet, IPerSheetDataRead sheetRead, List<Ac ...@@ -366,8 +365,7 @@ private void WriteOtherIncome(ISheet sheet, IPerSheetDataRead sheetRead, List<Ac
logger.LogInformation($"item有{itemList?.Count ?? 0}个."); logger.LogInformation($"item有{itemList?.Count ?? 0}个.");
if (itemList == null || !itemList.Any()) return; if (itemList == null || !itemList.Any()) return;
if (IsWriteHead) WriteHeaderAndFactor(sheet, sheetRead, itemList, isNewTemp);
WriteHeaderAndFactor(sheet, sheetRead, itemList);
//查询数据 //查询数据
var extractIdList = itemList.Select(t => t.ExtractId).Distinct().ToList(); var extractIdList = itemList.Select(t => t.ExtractId).Distinct().ToList();
...@@ -392,11 +390,11 @@ private void WriteOtherIncome(ISheet sheet, IPerSheetDataRead sheetRead, List<Ac ...@@ -392,11 +390,11 @@ private void WriteOtherIncome(ISheet sheet, IPerSheetDataRead sheetRead, List<Ac
} }
} }
WriteSheetData(sheet, sheetRead, unitList, allExtract, itemList.Select(t => t.ItemName)); WriteSheetData(sheet, sheetRead, unitList, allExtract, itemList.Select(t => t.ItemName), isNewTemp);
logger.LogInformation($"{sheet.SheetName}提取结束."); logger.LogInformation($"{sheet.SheetName}提取结束.");
} }
private void WriteIncome(ISheet sheet, IPerSheetDataRead sheetRead, List<AccountUnitEntity> unitList, List<sys_hospitalconfig> configs, List<mod_module> modules, List<mod_item> items, List<mod_extract> extracts, bool IsWriteHead = true) private void WriteIncome(ISheet sheet, IPerSheetDataRead sheetRead, List<AccountUnitEntity> unitList, List<sys_hospitalconfig> configs, List<mod_module> modules, List<mod_item> items, List<mod_extract> extracts, bool isNewTemp = true)
{ {
logger.LogInformation($"{sheet.SheetName}开始提取."); logger.LogInformation($"{sheet.SheetName}开始提取.");
var module = modules.FirstOrDefault(t => t.ModuleName.Replace(" ", "") == sheet.SheetName.Replace(" ", "")); var module = modules.FirstOrDefault(t => t.ModuleName.Replace(" ", "") == sheet.SheetName.Replace(" ", ""));
...@@ -406,8 +404,7 @@ private void WriteIncome(ISheet sheet, IPerSheetDataRead sheetRead, List<Account ...@@ -406,8 +404,7 @@ private void WriteIncome(ISheet sheet, IPerSheetDataRead sheetRead, List<Account
logger.LogInformation($"item有{itemList?.Count ?? 0}个."); logger.LogInformation($"item有{itemList?.Count ?? 0}个.");
if (itemList == null || !itemList.Any()) return; if (itemList == null || !itemList.Any()) return;
if (IsWriteHead) WriteHeaderAndFactor(sheet, sheetRead, itemList, isNewTemp);
WriteHeaderAndFactor(sheet, sheetRead, itemList);
//查询数据 //查询数据
var extractList = extracts.Where(t => module.ExtractId == t.Id).ToList(); var extractList = extracts.Where(t => module.ExtractId == t.Id).ToList();
...@@ -426,11 +423,11 @@ private void WriteIncome(ISheet sheet, IPerSheetDataRead sheetRead, List<Account ...@@ -426,11 +423,11 @@ private void WriteIncome(ISheet sheet, IPerSheetDataRead sheetRead, List<Account
allExtract.AddRange(result); allExtract.AddRange(result);
} }
WriteSheetData(sheet, sheetRead, unitList, allExtract, itemList.Select(t => t.ItemName), true); WriteSheetData(sheet, sheetRead, unitList, allExtract, itemList.Select(t => t.ItemName), isNewTemp, true);
logger.LogInformation($"{sheet.SheetName}提取结束."); logger.LogInformation($"{sheet.SheetName}提取结束.");
} }
private void WriteExpend(ISheet sheet, IPerSheetDataRead sheetRead, List<AccountUnitEntity> unitList, List<sys_hospitalconfig> configs, List<mod_module> modules, List<mod_item> items, List<mod_extract> extracts, bool IsWriteHead = true) private void WriteExpend(ISheet sheet, IPerSheetDataRead sheetRead, List<AccountUnitEntity> unitList, List<sys_hospitalconfig> configs, List<mod_module> modules, List<mod_item> items, List<mod_extract> extracts, bool isNewTemp = true)
{ {
logger.LogInformation($"{sheet.SheetName}开始提取."); logger.LogInformation($"{sheet.SheetName}开始提取.");
var module = modules.FirstOrDefault(t => t.SheetType == (int)SheetType.Expend); var module = modules.FirstOrDefault(t => t.SheetType == (int)SheetType.Expend);
...@@ -440,8 +437,7 @@ private void WriteExpend(ISheet sheet, IPerSheetDataRead sheetRead, List<Account ...@@ -440,8 +437,7 @@ private void WriteExpend(ISheet sheet, IPerSheetDataRead sheetRead, List<Account
logger.LogInformation($"item有{itemList?.Count ?? 0}个."); logger.LogInformation($"item有{itemList?.Count ?? 0}个.");
if (itemList == null || !itemList.Any()) return; if (itemList == null || !itemList.Any()) return;
if (IsWriteHead) WriteHeaderAndFactor(sheet, sheetRead, itemList, isNewTemp);
WriteHeaderAndFactor(sheet, sheetRead, itemList);
//查询数据 //查询数据
var extractIdList = itemList.Select(t => t.ExtractId).Distinct().ToList(); var extractIdList = itemList.Select(t => t.ExtractId).Distinct().ToList();
...@@ -466,11 +462,11 @@ private void WriteExpend(ISheet sheet, IPerSheetDataRead sheetRead, List<Account ...@@ -466,11 +462,11 @@ private void WriteExpend(ISheet sheet, IPerSheetDataRead sheetRead, List<Account
} }
} }
WriteSheetData(sheet, sheetRead, unitList, allExtract, itemList.Select(t => t.ItemName)); WriteSheetData(sheet, sheetRead, unitList, allExtract, itemList.Select(t => t.ItemName), isNewTemp);
logger.LogInformation($"{sheet.SheetName}提取结束."); logger.LogInformation($"{sheet.SheetName}提取结束.");
} }
private void WriteWorkload(ISheet sheet, IPerSheetDataRead sheetRead, List<AccountUnitEntity> unitList, List<sys_hospitalconfig> configs, List<mod_module> modules, List<mod_item> items, List<mod_extract> extracts, bool IsWriteHead = true) private void WriteWorkload(ISheet sheet, IPerSheetDataRead sheetRead, List<AccountUnitEntity> unitList, List<sys_hospitalconfig> configs, List<mod_module> modules, List<mod_item> items, List<mod_extract> extracts, bool isNewTemp = true)
{ {
logger.LogInformation($"{sheet.SheetName}开始提取."); logger.LogInformation($"{sheet.SheetName}开始提取.");
var module = modules.FirstOrDefault(t => t.ModuleName.Replace(" ", "") == sheet.SheetName.Replace(" ", "")); var module = modules.FirstOrDefault(t => t.ModuleName.Replace(" ", "") == sheet.SheetName.Replace(" ", ""));
...@@ -480,27 +476,7 @@ private void WriteWorkload(ISheet sheet, IPerSheetDataRead sheetRead, List<Accou ...@@ -480,27 +476,7 @@ private void WriteWorkload(ISheet sheet, IPerSheetDataRead sheetRead, List<Accou
logger.LogInformation($"item有{itemList?.Count ?? 0}个."); logger.LogInformation($"item有{itemList?.Count ?? 0}个.");
if (itemList == null || !itemList.Any()) return; if (itemList == null || !itemList.Any()) return;
var head = GetOrCreate(sheet, sheetRead.Point.HeaderFirstRowNum.Value + 0); WriteWorkHeader(sheet, sheetRead, itemList, isNewTemp);
var factor = GetOrCreate(sheet, sheetRead.Point.HeaderFirstRowNum.Value + 1);
if (IsWriteHead)
{
logManageService.WriteMsg("提取绩效数据", $"写入列头信息 -- {module.ModuleName}", 1, Allot.ID, "ReceiveMessage");
logger.LogInformation($"提取绩效数据 写入列头信息 -- {module.ModuleName}");
//写入列头信息
int cellStartIndex = sheetRead.Point.HeaderFirstCellNum.Value + 2;
foreach (var item in itemList)
{
var headcell = GetOrCreate(head, cellStartIndex);
headcell.SetCellValue(item.ItemName);
headcell.CellStyle = CellStyle.CreateCellStyle(workbook, StyleType.列头);
var doctorcell = GetOrCreate(factor, cellStartIndex);
doctorcell.SetCellValue(item.FactorValue1 != null ? (double)item.FactorValue1 : 0);
doctorcell.CellStyle = CellStyle.CreateCellStyle(workbook, StyleType.列头, CellFormat.数字2);
cellStartIndex++;
}
}
//查询数据 //查询数据
var extractIdList = itemList.Select(t => t.ExtractId).Distinct().ToList(); var extractIdList = itemList.Select(t => t.ExtractId).Distinct().ToList();
...@@ -535,36 +511,7 @@ private void WriteWorkload(ISheet sheet, IPerSheetDataRead sheetRead, List<Accou ...@@ -535,36 +511,7 @@ private void WriteWorkload(ISheet sheet, IPerSheetDataRead sheetRead, List<Accou
logManageService.WriteMsg("提取绩效数据", $"填充数据 -- {module.ModuleName}", 1, Allot.ID, "ReceiveMessage"); logManageService.WriteMsg("提取绩效数据", $"填充数据 -- {module.ModuleName}", 1, Allot.ID, "ReceiveMessage");
logger.LogInformation($"提取绩效数据 填充数据 -- {module.ModuleName}"); logger.LogInformation($"提取绩效数据 填充数据 -- {module.ModuleName}");
//写入数据 //写入数据
var rowIndex = sheetRead.Point.HeaderFirstRowNum.Value + 2; WriteWorkData(sheet, sheetRead, unitList, allExtract, specialHead, isNewTemp);
foreach (var department in allExtract.Select(t => t.Department).Distinct())
{
var row = GetOrCreate(sheet, rowIndex);
for (int i = head.FirstCellNum; i < head.LastCellNum; i++)
{
var headName = head.GetCell(i).StringCellValue;
var newCell = GetOrCreate(row, i);
if (headName == "核算单元")
{
var dept = unitList.FirstOrDefault(t => t.SheetName == sheet.SheetName && t.Department == department)?.AccountingUnit;
newCell.SetCellValue(dept ?? "");
newCell.CellStyle = CellStyle.CreateCellStyle(workbook, StyleType.默认);
}
else if (headName == "科室名称")
{
newCell.SetCellValue(department ?? "");
newCell.CellStyle = CellStyle.CreateCellStyle(workbook, StyleType.默认);
}
else if (newCell.CellType != CellType.Formula)
{
var extract = allExtract.FirstOrDefault(t => t.Department == department && t.Category == headName);
var value = extract?.Value == 0 ? null : extract?.Value;
OutToExcelCell(newCell, value);
if (specialHead != null && specialHead.Contains(headName))
newCell.CellStyle = style;
}
}
rowIndex++;
}
logger.LogInformation($"{sheet.SheetName}提取结束."); logger.LogInformation($"{sheet.SheetName}提取结束.");
} }
...@@ -737,7 +684,15 @@ private void WriteSpecialUnit(ISheet sheet, IPerSheetDataRead sheetRead, List<sy ...@@ -737,7 +684,15 @@ private void WriteSpecialUnit(ISheet sheet, IPerSheetDataRead sheetRead, List<sy
logger.LogInformation($"{sheet.SheetName}提取结束."); logger.LogInformation($"{sheet.SheetName}提取结束.");
} }
private void WriteHeaderAndFactor(ISheet sheet, IPerSheetDataRead sheetRead, List<mod_item> items) #region 写入数据
/// <summary>
/// 写入列头
/// </summary>
/// <param name="sheet"></param>
/// <param name="sheetRead"></param>
/// <param name="items">列头数据(列名、系数)</param>
/// <param name="isNewTemp">是否为空白模板</param>
private void WriteHeaderAndFactor(ISheet sheet, IPerSheetDataRead sheetRead, List<mod_item> items, bool isNewTemp)
{ {
var nurseFactor = sheet.GetRow(sheetRead.Point.AccountingUnit.First(t => t.UnitType == "护理组").FactorRow.Value); var nurseFactor = sheet.GetRow(sheetRead.Point.AccountingUnit.First(t => t.UnitType == "护理组").FactorRow.Value);
var doctorFactor = sheet.GetRow(sheetRead.Point.AccountingUnit.First(t => t.UnitType == "医生组").FactorRow.Value); var doctorFactor = sheet.GetRow(sheetRead.Point.AccountingUnit.First(t => t.UnitType == "医生组").FactorRow.Value);
...@@ -746,43 +701,118 @@ private void WriteHeaderAndFactor(ISheet sheet, IPerSheetDataRead sheetRead, Lis ...@@ -746,43 +701,118 @@ private void WriteHeaderAndFactor(ISheet sheet, IPerSheetDataRead sheetRead, Lis
logManageService.WriteMsg("提取绩效数据", $"写入列头信息 -- {sheet.SheetName}", 1, Allot.ID, "ReceiveMessage"); logManageService.WriteMsg("提取绩效数据", $"写入列头信息 -- {sheet.SheetName}", 1, Allot.ID, "ReceiveMessage");
logger.LogInformation($"提取绩效数据 提取绩效数据 写入列头信息 -- {sheet.SheetName}"); logger.LogInformation($"提取绩效数据 提取绩效数据 写入列头信息 -- {sheet.SheetName}");
//写入列头信息
int cellStartIndex = sheetRead.Point.HeaderFirstCellNum.Value + 4; var cellItems = items;
foreach (var item in items) if (!isNewTemp)
{
#region 过滤历史模板中已有的列头
//写入列头信息
int cellStartIndex = sheetRead.Point.HeaderFirstCellNum.Value + 4;
for (int i = cellStartIndex; i < head.LastCellNum; i++)
{
var cellvalue = head.GetCell(i)?.ToString();
if (string.IsNullOrEmpty(cellvalue)) continue;
cellItems.RemoveAll(t => t.ItemName == cellvalue);
}
#endregion
}
if (cellItems == null || !cellItems.Any()) return;
#region 新增模板中不存在的列头
var lastcellIndex = head.LastCellNum;
foreach (var item in cellItems)
{ {
var headcell = GetOrCreate(head, cellStartIndex); var headcell = GetOrCreate(head, lastcellIndex);
headcell.SetCellValue(item.ItemName); headcell.SetCellValue(item.ItemName);
headcell.CellStyle = CellStyle.CreateCellStyle(workbook, StyleType.列头); headcell.CellStyle = CellStyle.CreateCellStyle(workbook, StyleType.列头);
var doctorcell = GetOrCreate(doctorFactor, cellStartIndex); var doctorcell = GetOrCreate(doctorFactor, lastcellIndex);
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.百分比);
var nursecell = GetOrCreate(nurseFactor, cellStartIndex); var nursecell = GetOrCreate(nurseFactor, lastcellIndex);
nursecell.SetCellValue(item.FactorValue2 != null ? (double)item.FactorValue2 : 0); nursecell.SetCellValue(item.FactorValue2 != null ? (double)item.FactorValue2 : 0);
nursecell.CellStyle = CellStyle.CreateCellStyle(workbook, StyleType.系数, CellFormat.百分比); nursecell.CellStyle = CellStyle.CreateCellStyle(workbook, StyleType.系数, CellFormat.百分比);
var techniciancell = GetOrCreate(technicianFactor, cellStartIndex); var techniciancell = GetOrCreate(technicianFactor, lastcellIndex);
techniciancell.SetCellValue(item.FactorValue3 != null ? (double)item.FactorValue3 : 0); techniciancell.SetCellValue(item.FactorValue3 != null ? (double)item.FactorValue3 : 0);
techniciancell.CellStyle = CellStyle.CreateCellStyle(workbook, StyleType.系数, CellFormat.百分比); techniciancell.CellStyle = CellStyle.CreateCellStyle(workbook, StyleType.系数, CellFormat.百分比);
cellStartIndex++; lastcellIndex++;
} }
#endregion
} }
private void WriteSheetData(ISheet sheet, IPerSheetDataRead sheetRead, List<AccountUnitEntity> unitList, List<ExtractDto> allExtract, IEnumerable<string> header, bool isIncom = false) /// <summary>
/// 写入数据
/// </summary>
/// <param name="sheet"></param>
/// <param name="sheetRead"></param>
/// <param name="unitList">核算单元</param>
/// <param name="allExtract">抽取的数据(科室、列头、数据)</param>
/// <param name="header">设定抽取的列头</param>
/// <param name="isNewTemp">是否为空白模板</param>
/// <param name="isIncom">是否是开单、执行收入</param>
private void WriteSheetData(ISheet sheet, IPerSheetDataRead sheetRead, List<AccountUnitEntity> unitList, List<ExtractDto> allExtract, IEnumerable<string> header, bool isNewTemp, bool isIncom = false)
{ {
logManageService.WriteMsg("提取绩效数据", $"填充数据 -- {sheet.SheetName}", 1, Allot.ID, "ReceiveMessage"); logManageService.WriteMsg("提取绩效数据", $"填充数据 -- {sheet.SheetName}", 1, Allot.ID, "ReceiveMessage");
logger.LogInformation($"提取绩效数据 填充数据 -- {sheet.SheetName}"); logger.LogInformation($"提取绩效数据 填充数据 -- {sheet.SheetName}");
//写入数据 //写入数据
var head = GetOrCreate(sheet, sheetRead.Point.HeaderFirstRowNum.Value); var head = GetOrCreate(sheet, sheetRead.Point.HeaderFirstRowNum.Value);
var rowIndex = sheetRead.Point.HeaderFirstRowNum.Value + 1; var rowIndex = sheetRead.Point.HeaderFirstRowNum.Value + 1;
foreach (var department in allExtract.Select(t => t.Department).Distinct())
if (!isNewTemp)
{
#region 给历史模板已有科室补充数据
for (int i = rowIndex; i < sheet.LastRowNum + 1; i++)
{
var row = sheet.GetRow(i);
if (row != null)
{
var department = row.GetCell(3)?.ToString();
if (string.IsNullOrEmpty(department)) continue;
var deptData = allExtract.Where(t => t.Department == department);
if (deptData == null || !deptData.Any()) continue;
for (int j = rowIndex; j < head.LastCellNum; j++)
{
var headName = head.GetCell(j).StringCellValue;
var newCell = GetOrCreate(row, j);
if (newCell == null) continue;
var value = deptData.FirstOrDefault(t => t.Category == headName)?.Value;
if (isIncom)
{
value = value == 0 ? null : value;
OutToExcelCell(newCell, value);
newCell.CellStyle = style;
}
else if (newCell.CellType != CellType.Formula)
{
value = value == 0 ? null : value;
OutToExcelCell(newCell, value);
if (header != null && header.Contains(headName))
newCell.CellStyle = style;
}
}
allExtract.RemoveAll(t => t.Department == department);
}
}
#endregion
}
if (allExtract == null || !allExtract.Any()) return;
#region 补充新的科室及数据
var lastrowIndex = sheet.LastRowNum + 1;
foreach (var department in allExtract.Select(t => t.Department).Where(t => !string.IsNullOrEmpty(t)).Distinct())
{ {
var row = GetOrCreate(sheet, rowIndex); var row = sheet.CreateRow(lastrowIndex);
for (int i = head.FirstCellNum; i < head.LastCellNum; i++) for (int i = head.FirstCellNum; i < head.LastCellNum; i++)
{ {
var headName = head.GetCell(i).StringCellValue; var headName = head.GetCell(i).StringCellValue;
var newCell = GetOrCreate(row, i); var newCell = row.CreateCell(i);
if (headName.Replace("\n", "") == "核算单元(医生组)") if (headName.Replace("\n", "") == "核算单元(医生组)")
{ {
var dept = unitList.FirstOrDefault(t => t.SheetName == sheet.SheetName && t.Department == department && t.UnitType == 1)?.AccountingUnit; var dept = unitList.FirstOrDefault(t => t.SheetName == sheet.SheetName && t.Department == department && t.UnitType == 1)?.AccountingUnit;
...@@ -815,18 +845,150 @@ private void WriteSheetData(ISheet sheet, IPerSheetDataRead sheetRead, List<Acco ...@@ -815,18 +845,150 @@ private void WriteSheetData(ISheet sheet, IPerSheetDataRead sheetRead, List<Acco
OutToExcelCell(newCell, value); OutToExcelCell(newCell, value);
newCell.CellStyle = style; newCell.CellStyle = style;
} }
else if (newCell.CellType != CellType.Formula) else if (header != null && header.Contains(headName))
{ {
value = value == 0 ? null : value; value = value == 0 ? null : value;
OutToExcelCell(newCell, value); OutToExcelCell(newCell, value);
if (header != null && header.Contains(headName)) newCell.CellStyle = style;
newCell.CellStyle = style; }
}
}
lastrowIndex++;
}
#endregion
}
/// <summary>
/// 写入工作量列头
/// </summary>
/// <param name="sheet"></param>
/// <param name="sheetRead"></param>
/// <param name="items"></param>
/// <param name="isNewTemp"></param>
private void WriteWorkHeader(ISheet sheet, IPerSheetDataRead sheetRead, List<mod_item> items, bool isNewTemp)
{
var head = GetOrCreate(sheet, sheetRead.Point.HeaderFirstRowNum.Value + 0);
var factor = GetOrCreate(sheet, sheetRead.Point.HeaderFirstRowNum.Value + 1);
var cellItems = items;
if (!isNewTemp)
{
#region 过滤历史模板中已有的列头
//写入列头信息
int cellStartIndex = sheetRead.Point.HeaderFirstCellNum.Value + 4;
for (int i = cellStartIndex; i < head.LastCellNum; i++)
{
var cellvalue = head.GetCell(i)?.ToString();
if (string.IsNullOrEmpty(cellvalue)) continue;
cellItems.RemoveAll(t => t.ItemName == cellvalue);
}
#endregion
}
if (cellItems == null || !cellItems.Any()) return;
#region 新增模板中不存在的列头
var lastcellIndex = head.LastCellNum;
foreach (var item in cellItems)
{
var headcell = GetOrCreate(head, lastcellIndex);
headcell.SetCellValue(item.ItemName);
headcell.CellStyle = CellStyle.CreateCellStyle(workbook, StyleType.列头);
var doctorcell = GetOrCreate(factor, lastcellIndex);
doctorcell.SetCellValue(item.FactorValue1 != null ? (double)item.FactorValue1 : 0);
doctorcell.CellStyle = CellStyle.CreateCellStyle(workbook, StyleType.列头, CellFormat.数字2);
lastcellIndex++;
}
#endregion
}
/// <summary>
/// 写入工作量数据
/// </summary>
/// <param name="sheet"></param>
/// <param name="sheetRead"></param>
/// <param name="unitList"></param>
/// <param name="allExtract"></param>
/// <param name="header"></param>
/// <param name="isNewTemp"></param>
private void WriteWorkData(ISheet sheet, IPerSheetDataRead sheetRead, List<AccountUnitEntity> unitList, List<ExtractDto> allExtract, IEnumerable<string> header, bool isNewTemp)
{
var head = GetOrCreate(sheet, sheetRead.Point.HeaderFirstRowNum.Value + 0);
var rowIndex = sheetRead.Point.HeaderFirstRowNum.Value + 2;
if (!isNewTemp)
{
#region 给历史模板已有科室补充数据
for (int i = rowIndex; i < sheet.LastRowNum + 1; i++)
{
var row = sheet.GetRow(i);
if (row != null)
{
var department = row.GetCell(1)?.ToString();
if (string.IsNullOrEmpty(department)) continue;
var deptData = allExtract.Where(t => t.Department == department);
if (deptData == null || !deptData.Any()) continue;
for (int j = rowIndex; j < head.LastCellNum; j++)
{
var headName = head.GetCell(j).StringCellValue;
var newCell = GetOrCreate(row, j);
if (newCell == null) continue;
if (newCell.CellType != CellType.Formula)
{
var extract = deptData.FirstOrDefault(t => t.Category == headName);
var value = extract?.Value == 0 ? null : extract?.Value;
OutToExcelCell(newCell, value);
if (header != null && header.Contains(headName))
newCell.CellStyle = style;
}
} }
allExtract.RemoveAll(t => t.Department == department);
}
}
#endregion
}
if (allExtract == null || !allExtract.Any()) return;
#region 补充新的科室及数据
var lastrowIndex = sheet.LastRowNum + 1;
foreach (var department in allExtract.Select(t => t.Department).Where(t => !string.IsNullOrEmpty(t)).Distinct())
{
var row = sheet.CreateRow(lastrowIndex);
for (int i = head.FirstCellNum; i < head.LastCellNum; i++)
{
var headName = head.GetCell(i).StringCellValue;
var newCell = row.CreateCell(i);
if (headName == "核算单元")
{
var dept = unitList.FirstOrDefault(t => t.SheetName == sheet.SheetName
&& t.Department == department)?.AccountingUnit;
newCell.SetCellValue(dept ?? "");
newCell.CellStyle = CellStyle.CreateCellStyle(workbook, StyleType.默认);
}
else if (headName == "科室名称")
{
newCell.SetCellValue(department ?? "");
newCell.CellStyle = CellStyle.CreateCellStyle(workbook, StyleType.默认);
}
else
{
var extract = allExtract.FirstOrDefault(t => t.Department == department && t.Category == headName);
var value = extract?.Value == 0 ? null : extract?.Value;
OutToExcelCell(newCell, value);
if (header != null && header.Contains(headName))
newCell.CellStyle = style;
} }
} }
rowIndex++; lastrowIndex++;
} }
#endregion
} }
#endregion
#endregion #endregion
......
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