提取优化

parent ec9077c3
......@@ -158,8 +158,7 @@ public static void WriteSheetData(ISheet sheet, PerSheetPoint point, SheetType s
string department = row.GetOrCreate(dataFirstCellNum - 1).GetDecodeEscapes();
if (string.IsNullOrEmpty(department)) continue;
if (rowIndex > dataFirstRowNum) dataFirstRowNum = rowIndex + 1;
if (rowIndex >= dataFirstRowNum) dataFirstRowNum = rowIndex + 1;
var deptData = data.Where(t => t.Department.NoBlank() == department);
if (deptData == null || !deptData.Any(t => t.Value.HasValue && t.Value != 0)) continue;
......@@ -216,7 +215,7 @@ public static void WriteSheetData(ISheet sheet, PerSheetPoint point, SheetType s
filed = sheet.SheetName.Contains("医生") ? fieldDoctor : fieldNurse;
}
var deptStyle = style.GetCellStyle();
//var deptStyle = style.GetCellStyle();
var cellStyle = style.SetBgkColorAndFormat(style.GetCellStyle(), StyleType.数据);
headers = headers.Select(t => t.NoBlank()).ToList();
......@@ -224,24 +223,25 @@ public static void WriteSheetData(ISheet sheet, PerSheetPoint point, SheetType s
foreach (string department in departments)
{
var deptData = data.Where(t => (t.Department ?? "") == department);
if (deptData == null || !deptData.Any()) continue;
var row = sheet.GetOrCreate(dataFirstRowNum);
for (int cellIndex = point.HeaderFirstCellNum.Value; cellIndex < columnHeader.LastCellNum; cellIndex++)
{
var column = columnHeader.GetCell(cellIndex).GetDecodeEscapes();
var column = columnHeader.GetCell(cellIndex).GetDecodeEscapes()?.Replace("(", "(").Replace(")", ")");
var cell = row.CreateCell(cellIndex);
if (filed.ContainsKey(column))
{
cell.SetCellOValue(filed[column]?.Invoke(deptData.First()));
cell.CellStyle = deptStyle;
var value = (deptData != null && deptData.Any()) ? filed[column]?.Invoke(deptData.First()) : "";
cell.SetCellOValue(value);
cell.CellStyle = cellStyle;
}
else if (sheetType == SheetType.Income || (headers != null && headers.Contains(column)))
{
var value = deptData.FirstOrDefault(t => t.Category.NoBlank() == column)?.Value;
if (value.HasValue && value != 0)
cell.SetCellValue<decimal>(value);
var value = (deptData != null && deptData.Any())
? deptData.FirstOrDefault(t => t.Category.NoBlank() == column)?.Value
: 0;
cell.SetCellValue<decimal>(value);
cell.CellStyle = cellStyle;
}
}
......@@ -253,7 +253,7 @@ public static void WriteSheetData(ISheet sheet, PerSheetPoint point, SheetType s
List<ExtractTransDto> data, List<IncomeRow> incomes, int dataFirstRowNum)
{
var cellStyle = style.SetBgkColorAndFormat(style.GetCellStyle(), StyleType.数据);
var deptStyle = style.GetCellStyle();
//var deptStyle = style.GetCellStyle();
headers = headers.Select(t => t.NoBlank()).ToList();
......@@ -264,40 +264,36 @@ public static void WriteSheetData(ISheet sheet, PerSheetPoint point, SheetType s
var row = sheet.GetOrCreate(dataFirstRowNum);
var deptData = data.Where(t => t.Department == item.Department);
if (deptData == null || !deptData.Any()) continue;
var deptContents = new Dictionary<int, string>
{
{ 1, item.Department },
{ 2, (sheet.SheetName.Contains("门诊")
? deptData.FirstOrDefault(t => !string.IsNullOrEmpty(t.OutNurseAccounting))?.OutNurseAccounting
: deptData.FirstOrDefault(t => !string.IsNullOrEmpty(t.InpatNurseAccounting))?.InpatNurseAccounting) ?? item.NurseAccount },
{ 3, (sheet.SheetName.Contains("门诊")
? deptData.FirstOrDefault(t => !string.IsNullOrEmpty(t.OutDoctorAccounting))?.OutDoctorAccounting
: deptData.FirstOrDefault(t => !string.IsNullOrEmpty(t.InpatDoctorAccounting))?.InpatDoctorAccounting) ?? item.DoctorAccount },
{ 4, (sheet.SheetName.Contains("门诊")
? deptData.FirstOrDefault(t => !string.IsNullOrEmpty(t.OutTechnicAccounting))?.OutTechnicAccounting
: deptData.FirstOrDefault(t => !string.IsNullOrEmpty(t.InpatTechnicAccounting))?.InpatTechnicAccounting) ?? item.TechnicAccounting },
};
foreach (var content in deptContents)
if (deptData != null && deptData.Any())
{
var cell = row.GetOrCreate(dataFirstCellNum - content.Key);
cell.SetCellValue(content.Value);
cell.CellStyle = deptStyle;
var deptContents = new Dictionary<int, string>
{
{ 1, item.Department },
{ 2, (sheet.SheetName.Contains("门诊")
? deptData.FirstOrDefault(t => !string.IsNullOrEmpty(t.OutNurseAccounting))?.OutNurseAccounting
: deptData.FirstOrDefault(t => !string.IsNullOrEmpty(t.InpatNurseAccounting))?.InpatNurseAccounting) ?? item.NurseAccount },
{ 3, (sheet.SheetName.Contains("门诊")
? deptData.FirstOrDefault(t => !string.IsNullOrEmpty(t.OutDoctorAccounting))?.OutDoctorAccounting
: deptData.FirstOrDefault(t => !string.IsNullOrEmpty(t.InpatDoctorAccounting))?.InpatDoctorAccounting) ?? item.DoctorAccount },
{ 4, (sheet.SheetName.Contains("门诊")
? deptData.FirstOrDefault(t => !string.IsNullOrEmpty(t.OutTechnicAccounting))?.OutTechnicAccounting
: deptData.FirstOrDefault(t => !string.IsNullOrEmpty(t.InpatTechnicAccounting))?.InpatTechnicAccounting) ?? item.TechnicAccounting },
};
foreach (var content in deptContents)
{
var cell = row.GetOrCreate(dataFirstCellNum - content.Key);
cell.SetCellValue(content.Value);
cell.CellStyle = cellStyle;
}
}
for (int cellIndex = dataFirstCellNum; cellIndex < columnHeader.LastCellNum; cellIndex++)
{
var column = columnHeader.GetOrCreate(cellIndex).GetDecodeEscapes();
var cell = row.GetOrCreate(cellIndex);
var value = deptData.FirstOrDefault(t => t.Category.NoBlank() == column)?.Value;
//if (cell.CellType != CellType.Formula)
//{
// cell.SetCellValue<decimal>(value);
// cell.CellStyle = cellStyle;
//}
if (value.HasValue && value != 0)
cell.SetCellValue<decimal>(value);
cell.CellStyle = cellStyle;
......@@ -355,12 +351,7 @@ public static string HasValue(params string[] list)
private static readonly Dictionary<string, Func<ExtractTransDto, string>> fieldDoctor = new Dictionary<string, Func<ExtractTransDto, string>>
{
{ "科室名称", (dto) => dto.Department },
{ "核算单元", (dto) =>
{
var obj = new string []{ dto.OutDoctorAccounting, dto.InpatDoctorAccounting, dto.OutTechnicAccounting, dto.InpatTechnicAccounting }
.FirstOrDefault(t => !string.IsNullOrEmpty(t));
return obj;
}
{ "核算单元", (dto) => new string []{ dto.OutDoctorAccounting, dto.InpatDoctorAccounting, dto.OutTechnicAccounting, dto.InpatTechnicAccounting }.FirstOrDefault(t => !string.IsNullOrEmpty(t))
},
};
......@@ -464,7 +455,7 @@ public static void WriteCollectData(ISheet sheet, PerSheetPoint point, SheetType
? collectWork
: new SheetType[] { SheetType.OtherIncome, SheetType.Expend }.Contains(sheetType) ? collectIncome : collectDept;
var deptStyle = style.GetCellStyle();
//var deptStyle = style.GetCellStyle();
var cellStyle = style.SetBgkColorAndFormat(style.GetCellStyle(), StyleType.数据);
headers = headers.Select(t => t.NoBlank()).ToList();
......@@ -477,13 +468,13 @@ public static void WriteCollectData(ISheet sheet, PerSheetPoint point, SheetType
var row = sheet.GetOrCreate(dataFirstRowNum);
for (int cellIndex = point.HeaderFirstCellNum.Value; cellIndex < columnHeader.LastCellNum; cellIndex++)
{
var column = columnHeader.GetCell(cellIndex).GetDecodeEscapes();
var column = columnHeader.GetCell(cellIndex).GetDecodeEscapes()?.Replace("(", "(").Replace(")", ")");
var cell = row.CreateCell(cellIndex);
if (filed.ContainsKey(column))
{
cell.SetCellOValue(filed[column]?.Invoke(deptData.First()));
cell.CellStyle = deptStyle;
cell.CellStyle = cellStyle;
}
else if (sheetType == SheetType.Income || (headers != null && headers.Contains(column)))
{
......@@ -500,7 +491,7 @@ public static void WriteCollectData(ISheet sheet, PerSheetPoint point, SheetType
List<collect_data> data, List<IncomeRow> incomes, int dataFirstRowNum)
{
var cellStyle = style.SetBgkColorAndFormat(style.GetCellStyle(), StyleType.数据);
var deptStyle = style.GetCellStyle();
//var deptStyle = style.GetCellStyle();
headers = headers.Select(t => t.NoBlank()).ToList();
......@@ -525,7 +516,7 @@ public static void WriteCollectData(ISheet sheet, PerSheetPoint point, SheetType
{
var cell = row.GetOrCreate(dataFirstCellNum - content.Key);
cell.SetCellValue(content.Value);
cell.CellStyle = deptStyle;
cell.CellStyle = cellStyle;
}
for (int cellIndex = dataFirstCellNum; cellIndex < columnHeader.LastCellNum; cellIndex++)
......
......@@ -309,44 +309,47 @@ private List<ExtractTransDto> StandDataFormat(int hospitalId, int allotId, List<
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 data = new List<ExtractTransDto>();
foreach (var item in results)
{
var firstDic = dict.FirstOrDefault(w => w.HISDeptName == item.Department) ?? dict.FirstOrDefault(w => w.Department == item.Department);
var dept = !string.IsNullOrEmpty(firstDic?.Department) ? firstDic?.Department : item.Department;
var d = new ExtractTransDto
{
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,
SpecialAccounting = t.inner.FirstOrDefault(f => f.Department == dept)?.SpecialAccounting?.AccountingUnit ?? dept,
EName = types.FirstOrDefault(w => w.Id == t.outer.TypeId)?.EName,
};
});
SheetName = item.Source,
Department = dept,
Category = item.Category,
DoctorName = item.DoctorName,
PersonnelNumber = item.PersonnelNumber,
Value = item.Fee ?? 0,
OutDoctorAccounting = firstDic?.OutDoctorAccounting?.AccountingUnit,
OutNurseAccounting = firstDic?.OutNurseAccounting?.AccountingUnit,
OutTechnicAccounting = firstDic?.OutTechnicAccounting?.AccountingUnit,
InpatDoctorAccounting = firstDic?.InpatDoctorAccounting?.AccountingUnit,
InpatNurseAccounting = firstDic?.InpatNurseAccounting?.AccountingUnit,
InpatTechnicAccounting = firstDic?.InpatTechnicAccounting?.AccountingUnit,
SpecialAccounting = firstDic?.SpecialAccounting?.AccountingUnit ?? dept,
EName = types.FirstOrDefault(w => w.Id == item.TypeId)?.EName,
};
data.Add(d);
}
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.FirstOrDefault()?.OutDoctorAccounting,
OutNurseAccounting = t.FirstOrDefault()?.OutNurseAccounting,
OutTechnicAccounting = t.FirstOrDefault()?.OutTechnicAccounting,
InpatDoctorAccounting = t.FirstOrDefault()?.InpatDoctorAccounting,
InpatNurseAccounting = t.FirstOrDefault()?.InpatNurseAccounting,
InpatTechnicAccounting = t.FirstOrDefault()?.InpatTechnicAccounting,
SpecialAccounting = t.FirstOrDefault()?.SpecialAccounting,
EName = t.FirstOrDefault(w => !string.IsNullOrEmpty(w.EName))?.EName
});
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.FirstOrDefault(w => !string.IsNullOrEmpty(w.OutDoctorAccounting))?.OutDoctorAccounting,
OutNurseAccounting = t.FirstOrDefault(w => !string.IsNullOrEmpty(w.OutNurseAccounting))?.OutNurseAccounting,
OutTechnicAccounting = t.FirstOrDefault(w => !string.IsNullOrEmpty(w.OutTechnicAccounting))?.OutTechnicAccounting,
InpatDoctorAccounting = t.FirstOrDefault(w => !string.IsNullOrEmpty(w.InpatDoctorAccounting))?.InpatDoctorAccounting,
InpatNurseAccounting = t.FirstOrDefault(w => !string.IsNullOrEmpty(w.InpatNurseAccounting))?.InpatNurseAccounting,
InpatTechnicAccounting = t.FirstOrDefault(w => !string.IsNullOrEmpty(w.InpatTechnicAccounting))?.InpatTechnicAccounting,
SpecialAccounting = t.FirstOrDefault(w => !string.IsNullOrEmpty(w.SpecialAccounting))?.SpecialAccounting,
EName = t.FirstOrDefault(w => !string.IsNullOrEmpty(w.EName))?.EName
});
return groupdata.ToList();
}
......
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