Commit 1806cc52 by 纪旭 韦

预留金额下载,添加绩效报错提示修复

parent 120066ee
......@@ -8,6 +8,7 @@
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json;
using Performance.DtoModels;
using Performance.EntityModels.Entity;
using Performance.Infrastructure;
......@@ -534,6 +535,69 @@ public ApiResponse Reserved([FromBody] ReservedRequest request)
}
/// <summary>
/// 预留金额下载
/// </summary>
/// <param name="request"></param>
/// <returns></returns>
[Route("reservedDownload")]
[HttpPost]
public IActionResult ReservedDownload([FromBody] ReservedRequest request)
{
try
{
List<ExcelDownloadHeads> excelDownloadHeads = new List<ExcelDownloadHeads>
{
new ExcelDownloadHeads(){ Alias="年份",Name = nameof(EmployeeReservedDto.Year) },
new ExcelDownloadHeads(){ Alias="来源",Name = nameof(EmployeeReservedDto.Source) },
new ExcelDownloadHeads(){ Alias="核算单元组别",Name = nameof(EmployeeReservedDto.UnitType) },
new ExcelDownloadHeads(){ Alias="核算单元",Name = nameof(EmployeeReservedDto.AccountingUnit) },
new ExcelDownloadHeads(){ Alias="人员姓名",Name = nameof(EmployeeReservedDto.EmployeeName) },
new ExcelDownloadHeads(){ Alias="人员工号",Name = nameof(EmployeeReservedDto.JobNumber) },
new ExcelDownloadHeads(){ Alias="预留金额总计",Name = nameof(EmployeeReservedDto.TotalReseFee) },
new ExcelDownloadHeads(){ Alias="实发金额总计",Name = nameof(EmployeeReservedDto.TotalGiveFee) },
};
var userid = _claim.GetUserId();
var result = _allotService.GetReserved(request, userid);
var ser = JsonConvert.SerializeObject(result);
var rows = JsonConvert.DeserializeObject<List<Dictionary<string, object>>>(ser);
string name;
string[] ignoreColumns;
if (request.Source == 1)
{
name = "预留金额(按人员字典)";
ignoreColumns = new string[] { "hospitalid","source","newunittype","newaccountingunit"};
}
else
{
name = "预留金额(按发放科室)";
ignoreColumns = new string[]{ "hospitalid", "newunittype", "newaccountingunit" };
}
var filepath = _allotService.ExcelDownload(rows, name , excelDownloadHeads, ignoreColumns);
var memoryStream = new MemoryStream();
using (var stream = new FileStream(filepath, FileMode.Open))
{
stream.CopyToAsync(memoryStream).Wait();
}
memoryStream.Seek(0, SeekOrigin.Begin);
var provider = new FileExtensionContentTypeProvider();
FileInfo fileInfo = new FileInfo(filepath);
var memi = provider.Mappings[".xlsx"];
return File(memoryStream, memi, Path.GetFileName(fileInfo.Name));
}
catch (Exception ex)
{
_logger.LogError(new EventId(10000), ex, "下载异常");
throw;
}
}
/// <summary>
/// 下载当前测算表
/// </summary>
/// <param name="allotid"></param>
......@@ -610,7 +674,7 @@ private void LogAllotAction(int allotId, string path, string actionName)
AllotId = allotId,
CreateDate = DateTime.Now,
CreateUser = _claim.GetUserId(),
FilePath = path,
FilePath = path??"",
ActionName = actionName
};
......
......@@ -254,6 +254,13 @@
<param name="request"></param>
<returns></returns>
</member>
<member name="M:Performance.Api.Controllers.AllotController.ReservedDownload(Performance.DtoModels.ReservedRequest)">
<summary>
预留金额下载
</summary>
<param name="request"></param>
<returns></returns>
</member>
<member name="M:Performance.Api.Controllers.AllotController.DownloadCurrentCalculationTable(System.Int32)">
<summary>
下载当前测算表
......
......@@ -2,6 +2,9 @@
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using Newtonsoft.Json;
using OfficeOpenXml;
using OfficeOpenXml.Style;
using Performance.DtoModels;
using Performance.DtoModels.AppSettings;
using Performance.EntityModels;
......@@ -11,6 +14,7 @@
using Performance.Services.ExtractExcelService;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.IO;
using System.Linq;
......@@ -672,6 +676,118 @@ public List<EmployeeReservedDto> GetReserved(ReservedRequest request, int userid
}
return reserveds;
}
/// <summary>
/// 预留金额下载
/// </summary>
/// <param name="rows"></param>
/// <param name="name"></param>
/// <param name="allotId"></param>
/// <param name="headList"></param>
/// <returns></returns>
public string ExcelDownload(List<Dictionary<string, object>> rows, string name, List<ExcelDownloadHeads> excelDownloadHeads, params string[] ignoreColumns)
{
var dpath = Path.Combine(_evn.ContentRootPath, "Files", "PerformanceRelease");
FileHelper.CreateDirectory(dpath);
string filepath = Path.Combine(dpath, $"{name}-{DateTime.Now:yyyyMMdd}");
FileHelper.DeleteFile(filepath);
string[] notSum = new string[] { "year", "month", "jobnumber", "source", "unittype", "accountingunit", "newunittype", "newaccountingunit", "employeename" };
using (FileStream fs = new FileStream(filepath, FileMode.OpenOrCreate))
using (ExcelPackage package = new ExcelPackage(fs))
{
var worksheet = package.Workbook.Worksheets.Add(name);
if (rows != null && rows.Count() > 0)
{
worksheet.SetValue(1, 1, name);
var headList = rows.FirstOrDefault().Where(w => !ignoreColumns.Contains(w.Key.ToLower())).ToList();
for (int col = 0; col < headList.Count; col++)
{
string headKey = headList[col].Key;
string head;
head = headKey.Contains("ReseFee") ? "预留金额" : headKey.Contains("GiveFee") ? "实发金额" : headKey;
foreach (var item in excelDownloadHeads)
{
if (headKey == item.Name)
{
head = item.Alias;
break;
}
};
worksheet.SetValue(3, col + 1, head);
}
for (int col = 0; col < headList.Count; col++)
{
for (int row = 0; row < rows.Count(); row++)
{
var temp = rows.ElementAt(row);
var value = temp[headList[col].Key] ?? "";
worksheet.Cells[row + 4, col + 1].Value = value;
}
if (col == 0)
worksheet.SetValue(rows.Count() + 4, col + 1, "合计");
else if (!notSum.Contains(headList[col].Key.ToLower()))
worksheet.Cells[rows.Count() + 4, col + 1].Formula = string.Format("SUM({0})", new ExcelAddress(4, col + 1, rows.Count() + 3, col + 1).Address);
}
#region 样式设置
int num = name.Contains("科室") ? 6 : 5;
for (int i = 1; i <= num; i++)
{
worksheet.SetValue(2, i, worksheet.GetValue(3, i));
worksheet.Cells[2, i, 3, i].Merge = true;
}
int month = 1;
for (int i = num + 1; i <= headList.Count; i += 2)
{
worksheet.SetValue(2, i, month + "月");
if (month == 13)
worksheet.SetValue(2, i, "合计");
worksheet.Cells[2, i, 2, i + 1].Merge = true;
month++;
}
for (int row = worksheet.Dimension.Start.Row; row <= worksheet.Dimension.End.Row; row++)
{
worksheet.Row(row).Height = 20;
for (int col = worksheet.Dimension.Start.Column; col <= worksheet.Dimension.End.Column; col++)
{
if (col <= headList.Count && !notSum.Contains(headList[col - 1].Key.ToLower()))
{
worksheet.Cells[row, col].Style.Numberformat.Format = "#,##0.00";
}
worksheet.Cells[row, col].Style.VerticalAlignment = ExcelVerticalAlignment.Center;
worksheet.Cells[row, col].Style.HorizontalAlignment = ExcelHorizontalAlignment.Center;
worksheet.Cells[row, col].Style.Border.BorderAround(ExcelBorderStyle.Thin);
}
}
worksheet.Cells[1, 1, 1, headList.Count].Merge = true;
worksheet.Cells[1, 1, 1, headList.Count].Style.VerticalAlignment = ExcelVerticalAlignment.Center;
worksheet.Cells[1, 1, 1, headList.Count].Style.HorizontalAlignment = ExcelHorizontalAlignment.Center;
worksheet.Cells[1, 1, 1, headList.Count].Style.Font.Bold = true;
worksheet.Cells[1, 1, 1, headList.Count].Style.Font.Size = 16;
worksheet.Row(1).Height = 24;
worksheet.Cells[2, 1, 2, headList.Count].Style.Font.Bold = true;
worksheet.View.FreezePanes(4, 1);
worksheet.Cells.AutoFitColumns();
for (int col = worksheet.Dimension.Start.Column; col <= worksheet.Dimension.End.Column; col++)
{
worksheet.Column(col).Width = worksheet.Column(col).Width > 20 ? 20 : worksheet.Column(col).Width;
}
#endregion
}
package.Save();
}
return filepath;
}
/// <summary>
/// 查询个人绩效
/// </summary>
......
......@@ -268,7 +268,6 @@ public string AllComputerDown(sys_hospital hospital, List<dynamic> dynamics, str
worksheet.Cells[row, col].Style.VerticalAlignment = ExcelVerticalAlignment.Center;
}
}
worksheet.Cells[1, 1, 1, headList.Count].Merge = true;
worksheet.Cells[1, 1, 1, headList.Count].Style.VerticalAlignment = ExcelVerticalAlignment.Center;
worksheet.Cells[1, 1, 1, headList.Count].Style.HorizontalAlignment = ExcelHorizontalAlignment.Center;
worksheet.Cells[1, 1, 1, headList.Count].Style.Font.Bold = true;
......
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