提取优化

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