Commit 33ad0b56 by lcx

抽取列名修改

parent 738cc72f
...@@ -55,6 +55,10 @@ public string Execture(int allotId) ...@@ -55,6 +55,10 @@ public string Execture(int allotId)
logger.LogInformation("医生收入文件: " + filepath); logger.LogInformation("医生收入文件: " + filepath);
return filepath; return filepath;
} }
catch (PerformanceException ex)
{
throw ex;
}
catch (Exception ex) catch (Exception ex)
{ {
logger.LogError(ex.ToString()); logger.LogError(ex.ToString());
...@@ -65,10 +69,10 @@ public string Execture(int allotId) ...@@ -65,10 +69,10 @@ public string Execture(int allotId)
private Dictionary<string, List<IncomeDataDto>> GetIncomeData(per_allot allot) private Dictionary<string, List<IncomeDataDto>> GetIncomeData(per_allot allot)
{ {
var configs = hospitalconfigRepository.GetEntities(t => t.HospitalId == allot.HospitalId); var configs = hospitalconfigRepository.GetEntities(t => t.HospitalId == allot.HospitalId);
if (configs == null || !configs.Any()) return null; if (configs == null || !configs.Any()) throw new PerformanceException("未添加医院提取配置");
var types = extypeRepository.GetEntities(t => t.Source == 100); var types = extypeRepository.GetEntities(t => t.Source == 100);
if (types == null || !types.Any()) return null; if (types == null || !types.Any()) throw new PerformanceException("未配置数据提取内容");
Dictionary<string, List<IncomeDataDto>> pairs = new Dictionary<string, List<IncomeDataDto>>(); Dictionary<string, List<IncomeDataDto>> pairs = new Dictionary<string, List<IncomeDataDto>>();
foreach (var item in types) foreach (var item in types)
...@@ -107,26 +111,38 @@ private IEnumerable<IncomeDataDto> QueryData(sys_hospitalconfig config, per_allo ...@@ -107,26 +111,38 @@ private IEnumerable<IncomeDataDto> QueryData(sys_hospitalconfig config, per_allo
private string CreateExcel(int hospitalId, Dictionary<string, List<IncomeDataDto>> dataDict) private string CreateExcel(int hospitalId, Dictionary<string, List<IncomeDataDto>> dataDict)
{ {
if (dataDict == null || !dataDict.Any()) throw new PerformanceException("未查询到数据!"); if (dataDict == null || !dataDict.Any(t => t.Value != null && t.Value.Any())) throw new PerformanceException("未查询到数据!");
IWorkbook workbook = new XSSFWorkbook(); IWorkbook workbook = new XSSFWorkbook();
ICellStyle cellStyle = getCellStyle.Invoke(workbook); ICellStyle cellStyle = getCellStyle.Invoke(workbook);
foreach (var dict in dataDict) foreach (var dict in dataDict.Where(t => t.Value != null && t.Value.Any()))
{ {
ISheet sheet = workbook.CreateSheet(dict.Key); ISheet sheet = workbook.CreateSheet(dict.Key);
CreateHeader(sheet, cellStyle); var columns = memberDict.Keys.ToList();
var categories = dict.Value.Select(s => s.Category).Distinct().OrderBy(t => t);
columns.AddRange(categories);
CreateHeader(sheet, cellStyle, columns);
int rowIndex = sheet.LastRowNum + 1; int rowIndex = sheet.LastRowNum + 1;
foreach (var data in dict.Value) var groupData = dict.Value.GroupBy(t => new { t.EmpCode, t.EmpName, t.DeptName, t.ExecDeptName });
foreach (var data in groupData)
{ {
IRow row = sheet.CreateRow(rowIndex); IRow row = sheet.CreateRow(rowIndex);
int index = 0; int index = 0;
foreach (var field in memberDict.Values) foreach (var field in columns)
{ {
ICell cell = row.CreateCell(index); ICell cell = row.CreateCell(index);
OutToExcelCell(cell, field?.Invoke(data)); if (memberDict.ContainsKey(field))
OutToExcelCell(cell, memberDict[field]?.Invoke(data.Key));
else
{
var value = data.FirstOrDefault(t => t.Category == field)?.Fee;
if (value.HasValue)
OutToExcelCell(cell, value.Value);
}
cell.CellStyle = cellStyle; cell.CellStyle = cellStyle;
index++; index++;
} }
...@@ -149,13 +165,13 @@ private string CreateExcel(int hospitalId, Dictionary<string, List<IncomeDataDto ...@@ -149,13 +165,13 @@ private string CreateExcel(int hospitalId, Dictionary<string, List<IncomeDataDto
return filepath; return filepath;
} }
private void CreateHeader(ISheet sheet, ICellStyle cellStyle) private void CreateHeader(ISheet sheet, ICellStyle cellStyle, List<string> columns)
{ {
IRow row = sheet.CreateRow(0); IRow row = sheet.CreateRow(0);
if (row == null) return; if (row == null) return;
int index = 0; int index = 0;
foreach (var col in memberDict.Keys) foreach (var col in columns)
{ {
ICell cell = row.CreateCell(index); ICell cell = row.CreateCell(index);
cell.SetCellValue(col); cell.SetCellValue(col);
...@@ -163,7 +179,7 @@ private void CreateHeader(ISheet sheet, ICellStyle cellStyle) ...@@ -163,7 +179,7 @@ private void CreateHeader(ISheet sheet, ICellStyle cellStyle)
index++; index++;
} }
sheet.CreateFreezePane(0, 1); //首行冻结 sheet.CreateFreezePane(memberDict.Count, 1); //首行冻结
} }
private Dictionary<string, string> GetParameters(per_allot allot) private Dictionary<string, string> GetParameters(per_allot allot)
...@@ -234,9 +250,14 @@ public void OutToExcelCell(ICell cell, object obj) ...@@ -234,9 +250,14 @@ public void OutToExcelCell(ICell cell, object obj)
} }
} }
private readonly Dictionary<string, Func<IncomeDataDto, object>> memberDict = new Dictionary<string, Func<IncomeDataDto, object>> private readonly Dictionary<string, Func<dynamic, object>> memberDict = new Dictionary<string, Func<dynamic, object>>
{ {
{ "医生工号", (t) => t.EmpCode }, { "医生姓名", (t) => t.EmpName }, { "开单科室", (t) => t.DeptName }, {"执行科室", (t) => t.ExecDeptName }, {"费用类型", (t) => t.Category }, {"费用", (t) => t.Fee } { "医生工号", (t) => t.EmpCode },
{ "医生姓名", (t) => t.EmpName },
{ "开单科室", (t) => t.DeptName },
{ "执行科室", (t) => t.ExecDeptName },
//{ "费用类型", (t) => t.Category },
//{ "费用", (t) => t.Fee }
}; };
private readonly Func<IWorkbook, ICellStyle> getCellStyle = (workbook) => private readonly Func<IWorkbook, ICellStyle> getCellStyle = (workbook) =>
......
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