提取空行问题处理

parent 96a24bf5
using FluentValidation.AspNetCore;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Options;
using Performance.DtoModels;
using Performance.DtoModels.AppSettings;
using Performance.Infrastructure;
using Performance.Services;
using Performance.Services.ExtractExcelService;
using System;
using System.IO;
using System.Linq;
// For more information on enabling Web API for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860
namespace Performance.Api.Controllers
{
/// <summary>
/// 科室二次分配
/// </summary>
[Route("api/[controller]")]
public class AgainAllotController : Controller
{
private AgainAllotService againAllotService;
private RoleService roleService;
private ComputeService computeService;
private ClaimService claimService;
private AllotService allotService;
private IWebHostEnvironment env;
private ConfigService configService;
private Application application;
public AgainAllotController(AgainAllotService againAllotService,
RoleService roleService,
ClaimService claimService,
AllotService allotService,
IWebHostEnvironment env,
ConfigService configService,
ComputeService computeService,
IOptions<Application> options)
{
this.againAllotService = againAllotService;
this.roleService = roleService;
this.claimService = claimService;
this.allotService = allotService;
this.env = env;
this.configService = configService;
this.computeService = computeService;
this.application = options.Value;
}
/// <summary>
/// 返回当前用户医院下绩效列表
/// </summary>
/// <returns></returns>
[Route("allotlist")]
[HttpPost]
public ApiResponse AllotList()
{
var userId = claimService.GetUserId();
var list = againAllotService.GetAllotList(userId);
return new ApiResponse(ResponseType.OK, list);
}
/// <summary>
/// 上传文件
/// </summary>
/// <param name="form"></param>
/// <returns></returns>
[Route("import")]
[HttpPost]
public ApiResponse Import([FromForm] IFormCollection form)
{
var againid = form.ToDictionary().GetValue("againid", 0);
if (againid <= 0)
return new ApiResponse(ResponseType.Fail, "参数错误", "againid无效");
var file = ((FormFileCollection)form.Files).FirstOrDefault();
if (file == null)
return new ApiResponse(ResponseType.Fail, "参数错误", "文件无效");
if (!ExtractHelper.IsXlsxFile(file.FileName))
return new ApiResponse(ResponseType.Fail, "文件格式错误", "文件暂只支持xlsx文件");
var again = againAllotService.GetAgainallot(againid);
if (again == null)
return new ApiResponse(ResponseType.Fail, "二次绩效记录不存在");
var allot = allotService.GetAllot(again.AllotID.Value);
if (allot == null)
return new ApiResponse(ResponseType.Fail, "一次绩效记录不存在");
var name = FileHelper.GetFileNameNoExtension(file.FileName) + DateTime.Now.ToString("yyyyMMddHHmmssfff");
var ext = FileHelper.GetExtension(file.FileName);
var dpath = Path.Combine(env.ContentRootPath, "Files", $"{allot.HospitalId}", $"{allot.Year}{allot.Month.ToString().PadLeft(2, '0')}");
FileHelper.CreateDirectory(dpath);
var path = Path.Combine(dpath, $"{name}{ext}");
using (var stream = file.OpenReadStream())
{
byte[] bytes = new byte[stream.Length];
stream.Read(bytes, 0, bytes.Length);
if (!FileHelper.CreateFile(path, bytes))
return new ApiResponse(ResponseType.Fail, $"{file.FileName}上传失败");
allot.Path = path;
allot.Remark = EnumHelper.GetDescription(AllotStates.FileUploaded);
if (!againAllotService.Update(allot, againid))
return new ApiResponse(ResponseType.Fail, $"{file.FileName}上传成功,修改状态失败");
configService.ClearAgain(againid);
}
return new ApiResponse(ResponseType.OK);
}
///// <summary>
///// 查看科室绩效
///// </summary>
///// <param name="request"></param>
///// <returns></returns>
//[Route("departmentdetail")]
//[HttpPost]
//public ApiResponse DepartmentDetail([CustomizeValidator(RuleSet = "Generate"), FromBody]AgainAllotRequest request)
//{
// var userId = claimService.GetUserId();
// var roles = roleService.GetUserRole(userId);
// var department = claimService.GetUserClaim(JwtClaimTypes.Department);
// var again = againAllotService.GetAgainallot(request.AgainAllotID);
// if (again == null)
// return new ApiResponse(ResponseType.Fail, "当前二次绩效ID无效");
// if (roles.First().Type == application.DirectorRole)
// {
// var detail = computeService.GetDepartmentDetail(again.AllotID.Value, department, 1);
// return new ApiResponse(ResponseType.OK, detail);
// }
// else if (roles.First().Type == application.NurseRole)
// {
// var detail = computeService.GetDepartmentDetail(again.AllotID.Value, department, 2);
// return new ApiResponse(ResponseType.OK, detail);
// }
// return new ApiResponse(ResponseType.Fail, "当前用户角色无法识别");
//}
///// <summary>
///// 生成绩效
///// </summary>
///// <param name="request"></param>
///// <returns></returns>
//[Route("generate")]
//[HttpPost]
//public ApiResponse Generate([CustomizeValidator(RuleSet = "Generate"), FromBody]AgainAllotRequest request)
//{
// var userId = claimService.GetUserId();
// var department = claimService.GetUserClaim(JwtClaimTypes.Department);
// var result = againAllotService.Generate(request, userId, department);
// return new ApiResponse(ResponseType.OK);
//}
/// <summary>
/// 查看绩效详情
/// </summary>
/// <param name="request"></param>
/// <returns></returns>
[Route("detail")]
[HttpPost]
public ApiResponse Detail([CustomizeValidator(RuleSet = "Generate"), FromBody] AgainAllotRequest request)
{
var result = againAllotService.Detail(request);
return new ApiResponse(ResponseType.OK, new { result.AgainSituation, result.SheetExport });
}
}
}
//using FluentValidation.AspNetCore;
//using Microsoft.AspNetCore.Hosting;
//using Microsoft.AspNetCore.Http;
//using Microsoft.AspNetCore.Mvc;
//using Microsoft.Extensions.Options;
//using Performance.DtoModels;
//using Performance.DtoModels.AppSettings;
//using Performance.Infrastructure;
//using Performance.Services;
//using Performance.Services.ExtractExcelService;
//using System;
//using System.IO;
//using System.Linq;
//// For more information on enabling Web API for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860
//namespace Performance.Api.Controllers
//{
// /// <summary>
// /// 科室二次分配
// /// </summary>
// [Route("api/[controller]")]
// public class AgainAllotController : Controller
// {
// private AgainAllotService againAllotService;
// private RoleService roleService;
// private ComputeService computeService;
// private ClaimService claimService;
// private AllotService allotService;
// private IWebHostEnvironment env;
// private ConfigService configService;
// private Application application;
// public AgainAllotController(AgainAllotService againAllotService,
// RoleService roleService,
// ClaimService claimService,
// AllotService allotService,
// IWebHostEnvironment env,
// ConfigService configService,
// ComputeService computeService,
// IOptions<Application> options)
// {
// this.againAllotService = againAllotService;
// this.roleService = roleService;
// this.claimService = claimService;
// this.allotService = allotService;
// this.env = env;
// this.configService = configService;
// this.computeService = computeService;
// this.application = options.Value;
// }
// /// <summary>
// /// 返回当前用户医院下绩效列表
// /// </summary>
// /// <returns></returns>
// [Route("allotlist")]
// [HttpPost]
// public ApiResponse AllotList()
// {
// var userId = claimService.GetUserId();
// var list = againAllotService.GetAllotList(userId);
// return new ApiResponse(ResponseType.OK, list);
// }
// /// <summary>
// /// 上传文件
// /// </summary>
// /// <param name="form"></param>
// /// <returns></returns>
// [Route("import")]
// [HttpPost]
// public ApiResponse Import([FromForm] IFormCollection form)
// {
// var againid = form.ToDictionary().GetValue("againid", 0);
// if (againid <= 0)
// return new ApiResponse(ResponseType.Fail, "参数错误", "againid无效");
// var file = ((FormFileCollection)form.Files).FirstOrDefault();
// if (file == null)
// return new ApiResponse(ResponseType.Fail, "参数错误", "文件无效");
// if (!ExtractHelper.IsXlsxFile(file.FileName))
// return new ApiResponse(ResponseType.Fail, "文件格式错误", "文件暂只支持xlsx文件");
// var again = againAllotService.GetAgainallot(againid);
// if (again == null)
// return new ApiResponse(ResponseType.Fail, "二次绩效记录不存在");
// var allot = allotService.GetAllot(again.AllotID.Value);
// if (allot == null)
// return new ApiResponse(ResponseType.Fail, "一次绩效记录不存在");
// var name = FileHelper.GetFileNameNoExtension(file.FileName) + DateTime.Now.ToString("yyyyMMddHHmmssfff");
// var ext = FileHelper.GetExtension(file.FileName);
// var dpath = Path.Combine(env.ContentRootPath, "Files", $"{allot.HospitalId}", $"{allot.Year}{allot.Month.ToString().PadLeft(2, '0')}");
// FileHelper.CreateDirectory(dpath);
// var path = Path.Combine(dpath, $"{name}{ext}");
// using (var stream = file.OpenReadStream())
// {
// byte[] bytes = new byte[stream.Length];
// stream.Read(bytes, 0, bytes.Length);
// if (!FileHelper.CreateFile(path, bytes))
// return new ApiResponse(ResponseType.Fail, $"{file.FileName}上传失败");
// allot.Path = path;
// allot.Remark = EnumHelper.GetDescription(AllotStates.FileUploaded);
// if (!againAllotService.Update(allot, againid))
// return new ApiResponse(ResponseType.Fail, $"{file.FileName}上传成功,修改状态失败");
// configService.ClearAgain(againid);
// }
// return new ApiResponse(ResponseType.OK);
// }
// ///// <summary>
// ///// 查看科室绩效
// ///// </summary>
// ///// <param name="request"></param>
// ///// <returns></returns>
// //[Route("departmentdetail")]
// //[HttpPost]
// //public ApiResponse DepartmentDetail([CustomizeValidator(RuleSet = "Generate"), FromBody]AgainAllotRequest request)
// //{
// // var userId = claimService.GetUserId();
// // var roles = roleService.GetUserRole(userId);
// // var department = claimService.GetUserClaim(JwtClaimTypes.Department);
// // var again = againAllotService.GetAgainallot(request.AgainAllotID);
// // if (again == null)
// // return new ApiResponse(ResponseType.Fail, "当前二次绩效ID无效");
// // if (roles.First().Type == application.DirectorRole)
// // {
// // var detail = computeService.GetDepartmentDetail(again.AllotID.Value, department, 1);
// // return new ApiResponse(ResponseType.OK, detail);
// // }
// // else if (roles.First().Type == application.NurseRole)
// // {
// // var detail = computeService.GetDepartmentDetail(again.AllotID.Value, department, 2);
// // return new ApiResponse(ResponseType.OK, detail);
// // }
// // return new ApiResponse(ResponseType.Fail, "当前用户角色无法识别");
// //}
// ///// <summary>
// ///// 生成绩效
// ///// </summary>
// ///// <param name="request"></param>
// ///// <returns></returns>
// //[Route("generate")]
// //[HttpPost]
// //public ApiResponse Generate([CustomizeValidator(RuleSet = "Generate"), FromBody]AgainAllotRequest request)
// //{
// // var userId = claimService.GetUserId();
// // var department = claimService.GetUserClaim(JwtClaimTypes.Department);
// // var result = againAllotService.Generate(request, userId, department);
// // return new ApiResponse(ResponseType.OK);
// //}
// /// <summary>
// /// 查看绩效详情
// /// </summary>
// /// <param name="request"></param>
// /// <returns></returns>
// [Route("detail")]
// [HttpPost]
// public ApiResponse Detail([CustomizeValidator(RuleSet = "Generate"), FromBody] AgainAllotRequest request)
// {
// var result = againAllotService.Detail(request);
// return new ApiResponse(ResponseType.OK, new { result.AgainSituation, result.SheetExport });
// }
// }
//}
......@@ -149,31 +149,6 @@
</summary>
<returns></returns>
</member>
<member name="T:Performance.Api.Controllers.AgainAllotController">
<summary>
科室二次分配
</summary>
</member>
<member name="M:Performance.Api.Controllers.AgainAllotController.AllotList">
<summary>
返回当前用户医院下绩效列表
</summary>
<returns></returns>
</member>
<member name="M:Performance.Api.Controllers.AgainAllotController.Import(Microsoft.AspNetCore.Http.IFormCollection)">
<summary>
上传文件
</summary>
<param name="form"></param>
<returns></returns>
</member>
<member name="M:Performance.Api.Controllers.AgainAllotController.Detail(Performance.DtoModels.AgainAllotRequest)">
<summary>
查看绩效详情
</summary>
<param name="request"></param>
<returns></returns>
</member>
<member name="M:Performance.Api.Controllers.AllotController.List(Performance.DtoModels.AllotRequest)">
<summary>
绩效列表
......
......@@ -225,6 +225,12 @@ public static string NoBlank(this string @string)
return @string.Replace("\n", "").Replace("\r", "").Replace(" ", "").Trim();
}
public static string GetNo(this string @string)
{
var match = Regex.Match(@string, "^(1.[1-9].[1-9])|(^[1-9]+.[1-9]+)");
return match.Value;
}
public static IWorkbook GetWorkbook(string filePath)
{
IWorkbook workbook = null;
......
......@@ -54,38 +54,38 @@ public static void CreateNotExistSheet(List<ex_module> modulesList, IWorkbook wo
try
{
var sheetNames = workbook.GetAllNames().Select(w => w.SheetName);
foreach (var module in modulesList.Where(t => t.SheetType == (int)SheetType.Income)?.OrderBy(t => t.ModuleName))
{
var sheet = workbook.GetSheet(module.ModuleName) ?? workbook.GetSheet(module.ModuleName.NoBlank());
var no = module.ModuleName.GetNo();
var name = sheetNames.FirstOrDefault(name => name.StartsWith(no)) ?? module.ModuleName;
var sheet = workbook.GetSheet(name) ?? workbook.GetSheet(module.ModuleName);
if (sheet == null)
{
string[] keyArray = new string[] { "开单", "就诊", "执行" };
if (keyArray.Any(key => module.ModuleName.Contains(key)))
if (keyArray.Any(key => name.Contains(key)))
{
var item = pairs.Where(t => t.Key.ToString().NoBlank().StartsWith("1.")).OrderByDescending(t => t.Key).First();
var copysheet = workbook.GetSheet(item.Key);
if (copysheet == null) continue;
try
{
var newSheet = copysheet.CopySheet(module.ModuleName, true);
workbook.SetSheetOrder(newSheet.SheetName, workbook.NumberOfSheets - 1);
}
catch (Exception)
{
}
var newSheet = copysheet.CopySheet(name, true);
workbook.SetSheetOrder(newSheet.SheetName, workbook.NumberOfSheets - 1);
}
}
}
foreach (var module in modulesList.Where(t => new int[] { (int)SheetType.OtherWorkload, (int)SheetType.Assess }.Contains(t.SheetType.Value))?.OrderBy(t => t.ModuleName))
{
var sheet = workbook.GetSheet(module.ModuleName) ?? workbook.GetSheet(module.ModuleName.NoBlank());
var no = module.ModuleName.GetNo();
var name = sheetNames.FirstOrDefault(name => name.StartsWith(no)) ?? module.ModuleName;
var sheet = workbook.GetSheet(name) ?? workbook.GetSheet(module.ModuleName);
if (sheet == null)
{
var item = pairs.Where(t => t.Key.ToString().NoBlank().StartsWith("3.")).OrderByDescending(t => t.Key).First();
var copysheet = workbook.GetSheet(item.Key);
if (copysheet == null) continue;
var newSheet = copysheet.CopySheet(module.ModuleName, true);
var newSheet = copysheet.CopySheet(name, true);
workbook.SetSheetOrder(newSheet.SheetName, workbook.NumberOfSheets - 1);
var point = PerSheetDataFactory.GetDataRead(SheetType.Workload)?.Point;
......
......@@ -157,12 +157,16 @@ public static void WriteSheetData(ISheet sheet, PerSheetPoint point, SheetType s
if (row == null) continue;
string department = row.GetOrCreate(dataFirstCellNum - 1).GetDecodeEscapes();
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);
if (deptData == null || !deptData.Any(t => t.Value.HasValue && t.Value != 0)) continue;
#region 写入数据
if (sheetType == SheetType.Income && !string.IsNullOrEmpty(department))
if (sheetType == SheetType.Income)
{
if (!incomes.Any(t => t.Department == department))
incomes.Add(GetIncomeRowMessage(row, dataFirstCellNum, department, rowIndex));
......@@ -175,24 +179,13 @@ public static void WriteSheetData(ISheet sheet, PerSheetPoint point, SheetType s
var cell = row.GetOrCreate(cellIndex);
if (string.IsNullOrEmpty(column)) continue;
decimal? value = 0m;
if (!string.IsNullOrEmpty(department))
{
var deptData = data.Where(t => t.Department.NoBlank() == department);
if (deptData != null && deptData.Any(t => t.Value.HasValue && t.Value != 0))
value = deptData.FirstOrDefault(t => t.Category.NoBlank() == column)?.Value;
}
var value = deptData.FirstOrDefault(t => t.Category.NoBlank() == column)?.Value;
//数据为空,且单元格值不为空,不写入数据(保留原始值)
// 22.3.29 ry 只要是提取的列头全部覆盖数据
//if (value.HasValue && value != 0)
if (value.HasValue && value != 0)
cell.SetCellValue<decimal>(value);
if (headers != null && headers.Contains(column))
{
cell.SetCellValue<decimal>(value ?? 0);
cell.CellStyle = cellStyle;
}
}
#endregion
......@@ -223,7 +216,7 @@ public static void WriteSheetData(ISheet sheet, PerSheetPoint point, SheetType s
filed = sheet.SheetName.Contains("医生") ? fieldDoctor : fieldNurse;
}
//var deptStyle = style.GetCellStyle();
var deptStyle = style.GetCellStyle();
var cellStyle = style.SetBgkColorAndFormat(style.GetCellStyle(), StyleType.数据);
headers = headers.Select(t => t.NoBlank()).ToList();
......@@ -231,25 +224,24 @@ public static void WriteSheetData(ISheet sheet, PerSheetPoint point, SheetType s
foreach (string department in departments)
{
var deptData = data.Where(t => (t.Department ?? "") == department);
if (deptData == null || !deptData.Any()) continue;
var row = sheet.GetOrCreate(dataFirstRowNum);
for (int cellIndex = point.HeaderFirstCellNum.Value; cellIndex < columnHeader.LastCellNum; cellIndex++)
{
var column = columnHeader.GetCell(cellIndex).GetDecodeEscapes()?.Replace("(", "(").Replace(")", ")"); ;
var column = columnHeader.GetCell(cellIndex).GetDecodeEscapes();
var cell = row.CreateCell(cellIndex);
if (filed.ContainsKey(column))
{
var value = (deptData != null && deptData.Any()) ? filed[column]?.Invoke(deptData.First()) : "";
cell.SetCellOValue(value);
cell.CellStyle = cellStyle;
cell.SetCellOValue(filed[column]?.Invoke(deptData.First()));
cell.CellStyle = deptStyle;
}
else if (sheetType == SheetType.Income || (headers != null && headers.Contains(column)))
{
var value = (deptData != null && deptData.Any())
? deptData.FirstOrDefault(t => t.Category.NoBlank() == column)?.Value
: 0;
cell.SetCellValue<decimal>(value);
var value = deptData.FirstOrDefault(t => t.Category.NoBlank() == column)?.Value;
if (value.HasValue && value != 0)
cell.SetCellValue<decimal>(value);
cell.CellStyle = cellStyle;
}
}
......@@ -261,7 +253,7 @@ public static void WriteSheetData(ISheet sheet, PerSheetPoint point, SheetType s
List<ExtractTransDto> data, List<IncomeRow> incomes, int dataFirstRowNum)
{
var cellStyle = style.SetBgkColorAndFormat(style.GetCellStyle(), StyleType.数据);
//var deptStyle = style.GetCellStyle();
var deptStyle = style.GetCellStyle();
headers = headers.Select(t => t.NoBlank()).ToList();
......@@ -272,45 +264,42 @@ public static void WriteSheetData(ISheet sheet, PerSheetPoint point, SheetType s
var row = sheet.GetOrCreate(dataFirstRowNum);
var deptData = data.Where(t => t.Department == item.Department);
if (deptData != null && deptData.Any())
if (deptData == null || !deptData.Any()) continue;
var deptContents = new Dictionary<int, string>
{
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);
cell.SetCellValue(content.Value);
cell.CellStyle = cellStyle;
}
}
{ 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 = deptStyle;
}
for (int cellIndex = dataFirstCellNum; cellIndex < columnHeader.LastCellNum; cellIndex++)
{
var column = columnHeader.GetOrCreate(cellIndex).GetDecodeEscapes();
var cell = row.GetOrCreate(cellIndex);
var value = (deptData != null && deptData.Any())
? deptData.FirstOrDefault(t => t.Category.NoBlank() == column)?.Value
: 0;
var value = deptData.FirstOrDefault(t => t.Category.NoBlank() == column)?.Value;
//if (cell.CellType != CellType.Formula)
//{
// cell.SetCellValue<decimal>(value);
// cell.CellStyle = cellStyle;
//}
cell.SetCellValue<decimal>(value);
if (value.HasValue && value != 0)
cell.SetCellValue<decimal>(value);
cell.CellStyle = cellStyle;
}
......@@ -366,7 +355,12 @@ public static string HasValue(params string[] list)
private static readonly Dictionary<string, Func<ExtractTransDto, string>> fieldDoctor = new Dictionary<string, Func<ExtractTransDto, string>>
{
{ "科室名称", (dto) => dto.Department },
{ "核算单元", (dto) => new string []{ dto.OutDoctorAccounting, dto.InpatDoctorAccounting, dto.OutTechnicAccounting, dto.InpatTechnicAccounting }.FirstOrDefault(t => !string.IsNullOrEmpty(t))
{ "核算单元", (dto) =>
{
var obj = new string []{ dto.OutDoctorAccounting, dto.InpatDoctorAccounting, dto.OutTechnicAccounting, dto.InpatTechnicAccounting }
.FirstOrDefault(t => !string.IsNullOrEmpty(t));
return obj;
}
},
};
......@@ -470,7 +464,7 @@ public static void WriteCollectData(ISheet sheet, PerSheetPoint point, SheetType
? collectWork
: 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.数据);
headers = headers.Select(t => t.NoBlank()).ToList();
......@@ -483,13 +477,13 @@ public static void WriteCollectData(ISheet sheet, PerSheetPoint point, SheetType
var row = sheet.GetOrCreate(dataFirstRowNum);
for (int cellIndex = point.HeaderFirstCellNum.Value; cellIndex < columnHeader.LastCellNum; cellIndex++)
{
var column = columnHeader.GetCell(cellIndex).GetDecodeEscapes()?.Replace("(", "(").Replace(")", ")");
var column = columnHeader.GetCell(cellIndex).GetDecodeEscapes();
var cell = row.CreateCell(cellIndex);
if (filed.ContainsKey(column))
{
cell.SetCellOValue(filed[column]?.Invoke(deptData.First()));
cell.CellStyle = cellStyle;
cell.CellStyle = deptStyle;
}
else if (sheetType == SheetType.Income || (headers != null && headers.Contains(column)))
{
......@@ -506,7 +500,7 @@ public static void WriteCollectData(ISheet sheet, PerSheetPoint point, SheetType
List<collect_data> data, List<IncomeRow> incomes, int dataFirstRowNum)
{
var cellStyle = style.SetBgkColorAndFormat(style.GetCellStyle(), StyleType.数据);
//var deptStyle = style.GetCellStyle();
var deptStyle = style.GetCellStyle();
headers = headers.Select(t => t.NoBlank()).ToList();
......@@ -531,7 +525,7 @@ public static void WriteCollectData(ISheet sheet, PerSheetPoint point, SheetType
{
var cell = row.GetOrCreate(dataFirstCellNum - content.Key);
cell.SetCellValue(content.Value);
cell.CellStyle = cellStyle;
cell.CellStyle = deptStyle;
}
for (int cellIndex = dataFirstCellNum; cellIndex < columnHeader.LastCellNum; cellIndex++)
......
......@@ -107,13 +107,10 @@ public string Main(int allotId, int hospitalId, string email, string groupName,
var data = exresultRepository.GetEntities(t => t.AllotId == allotId);
data.AddRange(queryService.Handler(hospitalId, allot, groupName, isSingle, ref dict));
logService.ReturnTheLog(allotId, groupName, 2, "提取数据", $"开始格式化数据", 1, isSingle);
var standData = StandDataFormat(hospitalId, data);
logService.ReturnTheLog(allotId, groupName, 2, "提取数据", $"格式化完成", 1, isSingle);
var standData = StandDataFormat(hospitalId, allotId, data);
dictionaryService.Handler(hospitalId, allot, groupName, isSingle);
logService.ReturnTheLog(allotId, groupName, 2, "准备写入", $"数据提取结束准备写入", 1, isSingle);
var statesArray = new int[] { (int)AllotStates.GenerateSucceed, (int)AllotStates.Archive };
var templateFilePath = ExtractHelper.GetExtractFile(hospitalId, allot, ref extractFilePath, filePath);
......@@ -236,10 +233,10 @@ private void WriteDataToFile(IWorkbook workbook, per_allot allot, Dictionary<ExD
var customer = factory.GetWriteData(sheetType, logger);
if (customer != null)
{
var collects = collectData?.Where(t => t.SheetName.NoBlank() == sheetName).ToList();
var collects = collectData?.Where(t => t.SheetName.StartsWith(sheetName.GetNo())).ToList();
customer.WriteCollectData(sheet, point, sheetType, style, collects, exdict);
var exdata = extractDto.Where(t => t.SheetName.NoBlank() == sheetName)?.ToList();
var exdata = extractDto.Where(t => t.SheetName.StartsWith(sheetName.GetNo()))?.ToList();
if (exdata != null)
{
logger.LogInformation($"{sheetName}: 总金额 - {exdata.Sum(s => s.Value ?? 0)}; 科室 - {string.Join(",", exdata.Select(s => s.Department).Distinct())}");
......@@ -278,10 +275,11 @@ private object GetDataBySheetType(int hospitalId, SheetType sheetType, List<Extr
/// <summary>
/// 标准数据格式, 匹配科室字典
/// </summary>
/// <param name="allotId"></param>
/// <param name="hospitalId"></param>
/// <param name="results"></param>
/// <returns></returns>
private List<ExtractTransDto> StandDataFormat(int hospitalId, List<ex_result> results)
private List<ExtractTransDto> StandDataFormat(int hospitalId, int allotId, List<ex_result> results)
{
if (results == null || !results.Any()) return new List<ExtractTransDto>();
......@@ -293,7 +291,7 @@ private List<ExtractTransDto> StandDataFormat(int hospitalId, List<ex_result> re
var types = extypeRepository.GetEntities(w => w.HospitalId == hospitalId) ?? new List<ex_type>();
var dict = personService.GetDepartments(hospitalId)?.ToList();
var dict = personService.GetDepartments(allotId)?.ToList();
if (dict == null || !dict.Any())
{
return results.GroupBy(t => new { t.Department, t.Category, t.Source }).Select(t => new ExtractTransDto
......
......@@ -39,7 +39,8 @@ public void WriteCollectData(ISheet sheet, PerSheetPoint point, SheetType sheetT
public void WriteSheetData(ISheet sheet, PerSheetPoint point, SheetType sheetType, ExcelStyle style, object data, Dictionary<ExDataDict, object> exdict = null)
{
var modules = exdict[ExDataDict.ExModule] as List<ex_module>;
var module = modules?.FirstOrDefault(t => t.SheetType == (int)sheetType && t.ModuleName.NoBlank() == sheet.SheetName.NoBlank());
var no = sheet.SheetName.GetNo();
var module = modules?.FirstOrDefault(t => t.SheetType == (int)sheetType && t.ModuleName.StartsWith(no));
if (module == null) return;
if (data is List<ExtractTransDto> extractDto && extractDto.Any())
......
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