提取空行问题处理

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