Commit ee267f3d by lcx

划拨收入写入额外收入页

parent e6ad023d
......@@ -4,6 +4,7 @@
using Performance.EntityModels;
using Performance.Infrastructure;
using Performance.Repository;
using Performance.Services.ExtractExcelService.SheetDataWrite;
using System;
using System.Collections.Generic;
using System.IO;
......@@ -18,6 +19,7 @@ public class ExtractService : IAutoInjection
private readonly QueryService queryService;
private readonly PersonService personService;
private readonly PerSheetService perSheetService;
private readonly CostTransferDataWrite costTransfer;
private readonly DictionaryService dictionaryService;
private readonly PerforPerallotRepository perallotRepository;
private readonly PerforCollectdataRepository collectdataRepository;
......@@ -30,6 +32,7 @@ public class ExtractService : IAutoInjection
QueryService queryService,
PersonService personService,
PerSheetService perSheetService,
CostTransferDataWrite costTransfer,
DictionaryService dictionaryService,
PerforPerallotRepository perallotRepository,
PerforCollectdataRepository collectdataRepository,
......@@ -42,6 +45,7 @@ PerforPerdeptdicRepository perdeptdicRepository
this.queryService = queryService;
this.personService = personService;
this.perSheetService = perSheetService;
this.costTransfer = costTransfer;
this.dictionaryService = dictionaryService;
this.perallotRepository = perallotRepository;
this.collectdataRepository = collectdataRepository;
......@@ -204,6 +208,9 @@ private void WriteDataToFile(IWorkbook workbook, per_allot allot, Dictionary<ExD
customer.WriteSheetData(sheet, point, sheetType, style, data, exdict);
}
if (sheetName.StartsWith("1.0.1"))
costTransfer.WriteSheetData(sheet, point, style, allot.ID, allot.HospitalId);
logService.ReturnTheLog(allot.ID, groupName, 2, "写入数据", $"sheet“{sheet.SheetName}”已完成数据写入", 1, isSingle);
}
catch (Exception ex)
......
......@@ -29,6 +29,8 @@ PerforPerdeptdicRepository perdeptdicRepository
this.perdeptdicRepository = perdeptdicRepository;
}
private readonly string[] Unittypes = new string[] { UnitType.护理组.ToString(), UnitType.医生组.ToString(), UnitType.医技组.ToString() };
public void WriteSheetData(ISheet sheet, PerSheetPoint point, ExcelStyle style, int allotId, int hospitalId)
{
try
......@@ -36,42 +38,23 @@ public void WriteSheetData(ISheet sheet, PerSheetPoint point, ExcelStyle style,
var costTransfers = costtransferRepository.GetEntities(t => t.AllotId == allotId);
if (costTransfers == null || !costTransfers.Any()) return;
var costTransferItems = costtransferitemRepository.GetEntities(t => costTransfers.Select(c => c.Id).Contains(t.TransferId) && t.Status == 1 && t.AdminStatus == 1);
var costTransferItems = costtransferitemRepository.GetEntities(t => costTransfers.Select(c => c.Id).Contains(t.TransferId) && t.Status == 1 && t.AdminStatus == 1 && t.IsWrited == 0);
if (costTransferItems == null || !costTransferItems.Any()) return;
var columns = SupplySheetHeader(sheet, point);
if (columns == null || !columns.Any()) return;
var departments = costTransfers.Select(t => t.AdoptedDepartment ?? "").Union(costTransfers.Select(t => t.ApplicantDepartment ?? "")).Distinct().ToList();
var standardDict = perdeptdicRepository.GetEntities(t => t.HospitalId == hospitalId) ?? new List<per_dept_dic>();
var unittypes = new string[] { UnitType.护理组.ToString(), UnitType.医生组.ToString(), UnitType.医技组.ToString() };
for (int i = point.DataFirstRowNum.Value; i < sheet.LastRowNum + 1; i++)
{
var row = sheet.GetOrCreate(i);
var department = row.GetOrCreate(point.DataFirstCellNum.Value - 1).GetDecodeEscapes();
foreach (var unittype in unittypes)
{
var key = columns.Keys.FirstOrDefault(t => t.Contains(unittype.Replace("组", "")));
if (string.IsNullOrEmpty(key)) continue;
var index = columns[key];
var cell = row.GetOrCreate(index);
var score = GetTransfersByDeptAndUnittype(costTransfers, costTransferItems, department, unittype);
cell.SetCellOValue(score);
}
var cellStyle = style.SetBgkColorAndFormat(style.GetCellStyle(), StyleType.数据);
departments.Remove(department);
}
WriteSheetDataExistent(sheet, cellStyle, point, columns, departments, costTransfers, costTransferItems);
if (departments == null || !departments.Any()) return;
foreach (var department in departments)
{
var standardDict = perdeptdicRepository.GetEntities(t => t.HospitalId == hospitalId && departments.Contains(t.Department)) ?? new List<per_dept_dic>();
}
WriteSheetDataNonexistent(sheet, cellStyle, point, columns, departments, standardDict, costTransfers, costTransferItems);
}
catch (Exception ex)
{
......@@ -85,7 +68,7 @@ public void WriteSheetData(ISheet sheet, PerSheetPoint point, ExcelStyle style,
var header = sheet.GetRow(point.HeaderFirstRowNum.Value);
if (header == null) return pairs;
List<string> fixedColumns = new List<string> { "划拨收入(医技)", "划拨收入(医生)", "划拨收入(护理)" };
List<string> fixedColumns = new List<string> { $"划拨收入({UnitType.医技组})", $"划拨收入({UnitType.医生组})", $"划拨收入({UnitType.护理组})" };
for (int i = point.HeaderFirstCellNum.Value; i < header.LastCellNum; i++)
{
......@@ -116,6 +99,69 @@ public void WriteSheetData(ISheet sheet, PerSheetPoint point, ExcelStyle style,
return pairs;
}
private void WriteSheetDataExistent(ISheet sheet, ICellStyle style, PerSheetPoint point, Dictionary<string, int> columns, List<string> departments,
List<cost_transfer> costTransfers, List<cost_transfer_item> costTransferItems)
{
for (int i = point.DataFirstRowNum.Value; i < sheet.LastRowNum + 1; i++)
{
var row = sheet.GetOrCreate(i);
var department = row.GetOrCreate(point.DataFirstCellNum.Value - 1).GetDecodeEscapes();
foreach (var unittype in Unittypes)
{
var key = columns.Keys.FirstOrDefault(t => t.Contains(unittype));
if (string.IsNullOrEmpty(key)) continue;
var index = columns[key];
var cell = row.GetOrCreate(index);
var score = GetTransfersByDeptAndUnittype(costTransfers, costTransferItems, department, unittype);
cell.SetCellOValue(score);
cell.CellStyle = style;
}
departments.Remove(department);
}
}
private void WriteSheetDataNonexistent(ISheet sheet, ICellStyle style, PerSheetPoint point, Dictionary<string, int> columns, List<string> departments,
List<per_dept_dic> standardDict, List<cost_transfer> costTransfers, List<cost_transfer_item> costTransferItems)
{
int indexrow = sheet.LastRowNum + 1;
Dictionary<string, int> accountingUnits = new Dictionary<string, int>
{
{ UnitType.护理组.ToString(), 2 } ,{ UnitType.医生组.ToString(), 3 } ,{ UnitType.医技组.ToString(), 4 },
};
foreach (var department in departments)
{
var row = sheet.GetOrCreate(indexrow);
foreach (var unittype in Unittypes)
{
var key = columns.Keys.FirstOrDefault(t => t.Contains(unittype));
if (!string.IsNullOrEmpty(key) && columns.ContainsKey(key))
{
var index = columns[key];
var cell = row.GetOrCreate(index);
var score = GetTransfersByDeptAndUnittype(costTransfers, costTransferItems, department, unittype);
cell.SetCellOValue(score);
cell.CellStyle = style;
}
if (accountingUnits.ContainsKey(unittype))
{
var cell = row.GetOrCreate(point.DataFirstRowNum.Value - accountingUnits[unittype]);
var value = standardDict.Where(t => t.Department == department && t.UnitType == unittype)
?.Select(t => t.AccountingUnit).FirstOrDefault(t => !string.IsNullOrEmpty(t)) ?? "";
cell.SetCellValue(value);
cell.CellStyle = style;
}
}
indexrow++;
}
}
private decimal GetTransfersByDeptAndUnittype(List<cost_transfer> costTransfers, List<cost_transfer_item> costTransferItems, string department, string unittype)
{
if (costTransfers == null || !costTransfers.Any()) return 0;
......@@ -128,10 +174,10 @@ private decimal GetTransfersByDeptAndUnittype(List<cost_transfer> costTransfers,
? costTransfers.Where(t => t.ApplicantDepartment == department && t.ApplicantUnitType == unittype)?.ToList()
: costTransfers.Where(t => t.AdoptedDepartment == department && t.AdoptedUnitType == unittype)?.ToList();
if (data == null || !data.Any()) return 0;
if (data == null || !data.Any()) continue;
var items = costTransferItems.Where(t => data.Select(s => s.Id).Contains(t.TransferId))?.ToList();
if (items == null || !items.Any()) return 0;
if (items == null || !items.Any()) continue;
items.ForEach(t => t.IsWrited = 1);
costtransferitemRepository.UpdateRange(items.ToArray());
......
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