Commit 0ee51efa by lcx

特殊科室微调

parent b96457b9
...@@ -76,27 +76,27 @@ public List<ex_result> Handler(int hospitalId, per_allot allot, ref Dictionary<E ...@@ -76,27 +76,27 @@ public List<ex_result> Handler(int hospitalId, per_allot allot, ref Dictionary<E
ClearHistoryData(allot.ID); ClearHistoryData(allot.ID);
var data = new List<ex_result>(); var data = new List<ex_result>();
var scripts = exscriptRepository.GetEntities(t => extypeIds.Contains(t.TypeId)); //var scripts = exscriptRepository.GetEntities(t => extypeIds.Contains(t.TypeId));
if (scripts != null && scripts.Any()) //if (scripts != null && scripts.Any())
{ //{
var allmodules = dict[ExDataDict.ExModule] as List<ex_module>; // var allmodules = dict[ExDataDict.ExModule] as List<ex_module>;
foreach (var pair in dict) // foreach (var pair in dict)
{ // {
switch (pair.Key) // switch (pair.Key)
{ // {
case ExDataDict.ExModule: // case ExDataDict.ExModule:
data.AddRange(ExtractModuleData(allot, scripts, configs, pair.Value)); // data.AddRange(ExtractModuleData(allot, scripts, configs, pair.Value));
break; // break;
case ExDataDict.ExItem: // case ExDataDict.ExItem:
data.AddRange(ExtractItemData(allot, scripts, configs, allmodules, pair.Value)); // data.AddRange(ExtractItemData(allot, scripts, configs, allmodules, pair.Value));
break; // break;
case ExDataDict.ExSpecial: // case ExDataDict.ExSpecial:
data.AddRange(ExtractSpecialData(allot, scripts, configs, pair.Value)); // data.AddRange(ExtractSpecialData(allot, scripts, configs, pair.Value));
break; // break;
} // }
} // }
} //}
return data; return data;
} }
catch (Exception ex) catch (Exception ex)
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text.RegularExpressions;
namespace Performance.Services.ExtractExcelService.SheetDataWrite namespace Performance.Services.ExtractExcelService.SheetDataWrite
{ {
...@@ -35,7 +35,7 @@ public void WriteSheetData(ISheet sheet, PerSheetPoint point, SheetType sheetTyp ...@@ -35,7 +35,7 @@ public void WriteSheetData(ISheet sheet, PerSheetPoint point, SheetType sheetTyp
SupplyMergedRegionData(sheet, style, mergedRegions); SupplyMergedRegionData(sheet, style, mergedRegions);
var index = columns.IndexOf(SpecialUnitColumns.Department); var index = columns.IndexOf(SpecialUnitColumns.Department);
var needMergedRegions = mergedRegions.Where(t => t.FirstColumn == index && t.LastColumn == index)?.ToList(); var needMergedRegions = mergedRegions.Where(t => t.FirstColumn == index && t.LastColumn == index)?.ToList() ?? new List<SpecialCellRange>();
var specials = exSpecials.GroupJoin(extractDto, outer => new { outer.Department, outer.Target }, inner => new { inner.Department, Target = inner.Category }, var specials = exSpecials.GroupJoin(extractDto, outer => new { outer.Department, outer.Target }, inner => new { inner.Department, Target = inner.Category },
(outer, inner) => new SpecialDto (outer, inner) => new SpecialDto
...@@ -47,9 +47,9 @@ public void WriteSheetData(ISheet sheet, PerSheetPoint point, SheetType sheetTyp ...@@ -47,9 +47,9 @@ public void WriteSheetData(ISheet sheet, PerSheetPoint point, SheetType sheetTyp
Quantity = inner.FirstOrDefault()?.Value Quantity = inner.FirstOrDefault()?.Value
}).ToList(); }).ToList();
SupplySpecialQuantity(sheet, style, specials, columns, ref dataFirstRowNum); SupplySpecialQuantity(sheet, style, specials, needMergedRegions, columns, ref dataFirstRowNum);
AddNewSpecialConfig(sheet, style, specials, needMergedRegions, columns, dataFirstRowNum); //AddNewSpecialConfig(sheet, style, specials, needMergedRegions, columns, dataFirstRowNum);
AddMergedRegion(sheet, needMergedRegions, columns); //AddMergedRegion(sheet, needMergedRegions, columns);
} }
catch (Exception ex) catch (Exception ex)
{ {
...@@ -121,14 +121,14 @@ private void SupplyMergedRegionData(ISheet sheet, ExcelStyle style, List<Special ...@@ -121,14 +121,14 @@ private void SupplyMergedRegionData(ISheet sheet, ExcelStyle style, List<Special
{ {
var cell = row.GetCell(cellIndex); var cell = row.GetCell(cellIndex);
if (cell == null) cell = row.CreateCell(cellIndex); if (cell == null) cell = row.CreateCell(cellIndex);
if (!string.IsNullOrEmpty(value)) SetCellValue(cell, cellType, value); if (!string.IsNullOrEmpty(value)) SetCellValue(cell, value);
} }
row.SetRowStyle(basicStyle); row.SetRowStyle(basicStyle);
} }
} }
} }
private void SupplySpecialQuantity(ISheet sheet, ExcelStyle style, List<SpecialDto> specials, List<string> columns, ref int dataFirstRowNum) private void SupplySpecialQuantity(ISheet sheet, ExcelStyle style, List<SpecialDto> specials, List<SpecialCellRange> ranges, List<string> columns, ref int dataFirstRowNum)
{ {
if (sheet == null) return; if (sheet == null) return;
...@@ -160,6 +160,8 @@ private void SupplySpecialQuantity(ISheet sheet, ExcelStyle style, List<SpecialD ...@@ -160,6 +160,8 @@ private void SupplySpecialQuantity(ISheet sheet, ExcelStyle style, List<SpecialD
var department = row.GetCell(dict[SpecialUnitColumns.Department]).GetDecodeEscapes(); var department = row.GetCell(dict[SpecialUnitColumns.Department]).GetDecodeEscapes();
var target = row.GetCell(dict[SpecialUnitColumns.Target]).GetDecodeEscapes(); var target = row.GetCell(dict[SpecialUnitColumns.Target]).GetDecodeEscapes();
CheckMergedRegions(rowIndex, department, ranges);
var special = specials.FirstOrDefault(t => t.Department == department && t.Target == target); var special = specials.FirstOrDefault(t => t.Department == department && t.Target == target);
if (special != null) if (special != null)
{ {
...@@ -175,6 +177,28 @@ private void SupplySpecialQuantity(ISheet sheet, ExcelStyle style, List<SpecialD ...@@ -175,6 +177,28 @@ private void SupplySpecialQuantity(ISheet sheet, ExcelStyle style, List<SpecialD
} }
} }
private void CheckMergedRegions(int rowIndex, string department, List<SpecialCellRange> ranges)
{
var range = ranges.FirstOrDefault(t => t.FirstRow <= rowIndex && t.LastRow >= rowIndex);
if (range == null)
{
if (rowIndex == 0) return;
int prevRowIndex = rowIndex - 1;
range = ranges.FirstOrDefault(t => t.FirstRow <= prevRowIndex && t.LastRow >= prevRowIndex);
if (range != null && range.Single == department)
range.LastRow = rowIndex;
else
{
var columnIndex = ranges.First().FirstColumn;
ranges.Add(new SpecialCellRange(new CellRangeAddress(rowIndex, rowIndex, columnIndex, columnIndex))
{
Single = department
});
}
}
}
private void AddNewSpecialConfig(ISheet sheet, ExcelStyle style, List<SpecialDto> specials, List<SpecialCellRange> ranges, List<string> columns, int dataFirstRowNum) private void AddNewSpecialConfig(ISheet sheet, ExcelStyle style, List<SpecialDto> specials, List<SpecialCellRange> ranges, List<string> columns, int dataFirstRowNum)
{ {
if (specials == null || !specials.Any()) return; if (specials == null || !specials.Any()) return;
...@@ -241,6 +265,7 @@ private void WriteSpecialData(IRow row, ICellStyle style, SpecialDto special, Li ...@@ -241,6 +265,7 @@ private void WriteSpecialData(IRow row, ICellStyle style, SpecialDto special, Li
private void AddMergedRegion(ISheet sheet, List<SpecialCellRange> ranges, List<string> columns) private void AddMergedRegion(ISheet sheet, List<SpecialCellRange> ranges, List<string> columns)
{ {
if (columns == null || !columns.Any()) return; if (columns == null || !columns.Any()) return;
if (ranges == null || !ranges.Any()) return;
var columnIndexs = new string[] { SpecialUnitColumns.Department, SpecialUnitColumns.PeopleNumber, SpecialUnitColumns.AdjustFactor }.Select(t => columns.IndexOf(t)); var columnIndexs = new string[] { SpecialUnitColumns.Department, SpecialUnitColumns.PeopleNumber, SpecialUnitColumns.AdjustFactor }.Select(t => columns.IndexOf(t));
if (columnIndexs == null || !columnIndexs.Any(t => t > -1)) return; if (columnIndexs == null || !columnIndexs.Any(t => t > -1)) return;
...@@ -258,30 +283,18 @@ private void AddMergedRegion(ISheet sheet, List<SpecialCellRange> ranges, List<s ...@@ -258,30 +283,18 @@ private void AddMergedRegion(ISheet sheet, List<SpecialCellRange> ranges, List<s
} }
} }
private void SetCellValue(ICell cell, CellType cellType, string value) public void SetCellValue(ICell cell, string value)
{ {
if (string.IsNullOrEmpty(value)) switch (value)
{ {
cell.SetCellValue(""); case string reg when Regex.IsMatch(reg, @"^[+-]?\d*[.]?\d*$"):
return;
}
switch (cellType)
{
case CellType.Numeric:
cell.SetCellValue(ConvertHelper.To<double>(value)); cell.SetCellValue(ConvertHelper.To<double>(value));
break; break;
case CellType.String: case string reg when Regex.IsMatch(reg, @"^[+-]?\d*$"):
cell.SetCellValue(value.ToString());
break;
case CellType.Boolean:
cell.SetCellValue(ConvertHelper.To<int>(value)); cell.SetCellValue(ConvertHelper.To<int>(value));
break; break;
case CellType.Unknown:
case CellType.Blank:
case CellType.Error:
case CellType.Formula:
default: default:
cell.SetCellValue(value);
break; break;
} }
} }
......
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