Commit 22b147a5 by ruyun.zhang@suvalue.com

Merge branch 'v2020calculate' into fixed/bug

parents 87de3c0a 33ad0b56
......@@ -55,6 +55,10 @@ public string Execture(int allotId)
logger.LogInformation("医生收入文件: " + filepath);
return filepath;
}
catch (PerformanceException ex)
{
throw ex;
}
catch (Exception ex)
{
logger.LogError(ex.ToString());
......@@ -65,10 +69,10 @@ public string Execture(int allotId)
private Dictionary<string, List<IncomeDataDto>> GetIncomeData(per_allot allot)
{
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);
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>>();
foreach (var item in types)
......@@ -107,26 +111,38 @@ private IEnumerable<IncomeDataDto> QueryData(sys_hospitalconfig config, per_allo
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();
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);
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;
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);
int index = 0;
foreach (var field in memberDict.Values)
foreach (var field in columns)
{
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;
index++;
}
......@@ -149,13 +165,13 @@ private string CreateExcel(int hospitalId, Dictionary<string, List<IncomeDataDto
return filepath;
}
private void CreateHeader(ISheet sheet, ICellStyle cellStyle)
private void CreateHeader(ISheet sheet, ICellStyle cellStyle, List<string> columns)
{
IRow row = sheet.CreateRow(0);
if (row == null) return;
int index = 0;
foreach (var col in memberDict.Keys)
foreach (var col in columns)
{
ICell cell = row.CreateCell(index);
cell.SetCellValue(col);
......@@ -163,7 +179,7 @@ private void CreateHeader(ISheet sheet, ICellStyle cellStyle)
index++;
}
sheet.CreateFreezePane(0, 1); //首行冻结
sheet.CreateFreezePane(memberDict.Count, 1); //首行冻结
}
private Dictionary<string, string> GetParameters(per_allot allot)
......@@ -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) =>
......
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