Commit 6f7cc4b3 by 1391696987

下载人员标签

parent d89b7803
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.AspNetCore.StaticFiles;
using Performance.DtoModels; using Performance.DtoModels;
using Performance.EntityModels; using Performance.EntityModels;
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.Collections.Generic;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
...@@ -166,6 +168,36 @@ public ApiResponse GetReportPersonTag(int hospitalId, int allotId) ...@@ -166,6 +168,36 @@ public ApiResponse GetReportPersonTag(int hospitalId, int allotId)
relust.Data relust.Data
}); });
} }
/// <summary>
/// 下载人员标签配置
/// </summary>
/// <param name="hospitalId"></param>
/// <param name="allotId"></param>
/// <returns></returns>
[Route("DownloadReportPersonTag")]
[HttpPost]
public ActionResult DownloadReportPersonTag(int hospitalId, int allotId)
{
var result = reportGlobalService.GetReportPersonTag(hospitalId, allotId).Data;
var ser = JsonHelper.Serialize(result);
var rows = JsonHelper.Deserialize<List<Dictionary<string, object>>>(ser);
var filepath = reportGlobalService.ReportPersonTagDownload(rows, "人员标签");
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));
}
/// <summary> /// <summary>
/// 保存科室标签配置 /// 保存科室标签配置
......
...@@ -2016,6 +2016,14 @@ ...@@ -2016,6 +2016,14 @@
<param name="allotId"></param> <param name="allotId"></param>
<returns></returns> <returns></returns>
</member> </member>
<member name="M:Performance.Api.Controllers.ReportGlobalController.DownloadReportPersonTag(System.Int32,System.Int32)">
<summary>
下载人员标签配置
</summary>
<param name="hospitalId"></param>
<param name="allotId"></param>
<returns></returns>
</member>
<member name="M:Performance.Api.Controllers.ReportGlobalController.SaveReportPersonTag(System.Int32,System.Int32,Performance.DtoModels.SaveCollectData)"> <member name="M:Performance.Api.Controllers.ReportGlobalController.SaveReportPersonTag(System.Int32,System.Int32,Performance.DtoModels.SaveCollectData)">
<summary> <summary>
保存科室标签配置 保存科室标签配置
......
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using NPOI.SS.UserModel; using NPOI.SS.UserModel;
using OfficeOpenXml;
using OfficeOpenXml.Style;
using Performance.DtoModels; using Performance.DtoModels;
using Performance.EntityModels; using Performance.EntityModels;
using Performance.Infrastructure; using Performance.Infrastructure;
...@@ -8,6 +10,7 @@ ...@@ -8,6 +10,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics; using System.Diagnostics;
using System.IO;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
...@@ -629,6 +632,80 @@ select new ...@@ -629,6 +632,80 @@ select new
return result; return result;
} }
public string ReportPersonTagDownload(List<Dictionary<string, object>> rows, string title)
{
var data = new List<Dictionary<string, object>>();
foreach (var obj in rows)
{
Dictionary<string, object> nobj = new Dictionary<string, object>();
foreach (var item in obj)
{
nobj[item.Key.ToLower()] = item.Value;
}
data.Add(nobj);
}
var dpath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Files");
if (!Directory.Exists(dpath)) Directory.CreateDirectory(dpath);
string filepath = Path.Combine(dpath, $"{title}{DateTime.Now:yyyyMMdd}");
if (File.Exists(filepath)) File.Delete(filepath);
using (FileStream fs = new FileStream(filepath, FileMode.OpenOrCreate))
using (ExcelPackage package = new ExcelPackage(fs))
{
var worksheet = package.Workbook.Worksheets.Add(title);
if (rows != null && rows.Count() > 0)
{
worksheet.SetValue(1, 1, title);
var headList = data.FirstOrDefault().ToList();
for (int col = 0; col < headList.Count; col++)
{
worksheet.SetValue(2, col + 1, headList[col].Key);
}
for (int col = 0; col < headList.Count; col++)
{
for (int row = 0; row < data.Count(); row++)
{
var temp = data.ElementAt(row);
var value = temp[headList[col].Key] != null ? temp[headList[col].Key].ToString() : temp[headList[col].Key];
worksheet.Cells[row + 3, col + 1].Value = value;
}
}
#region 样式设置
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++)
{
worksheet.Cells[row, col].Style.Border.BorderAround(ExcelBorderStyle.Thin);
worksheet.Cells[row, col].Style.VerticalAlignment = ExcelVerticalAlignment.Center;
worksheet.Cells[row, col].Style.HorizontalAlignment = ExcelHorizontalAlignment.Center;
}
}
worksheet.Cells[1, 1, 1, headList.Count].Merge = true;
worksheet.Cells[1, 1, 1, headList.Count].Style.Font.Bold = true;
worksheet.Cells[1, 1, 1, headList.Count].Style.Font.Size = 16;
worksheet.Cells[2, 1, 2, headList.Count].Style.Font.Bold = true;
worksheet.Row(1).Height = 24;
worksheet.View.FreezePanes(3, 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;
}
public ApiResponse SaveReportPersonTag(int hospitalId, int allotId, int userId, SaveCollectData request) public ApiResponse SaveReportPersonTag(int hospitalId, int allotId, int userId, SaveCollectData request)
{ {
var hos = _hospitalRepository.GetEntity(t => t.ID == hospitalId); var hos = _hospitalRepository.GetEntity(t => t.ID == hospitalId);
......
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