Commit cacffe87 by Licx

导入数据 下载

parent 11af742c
using FluentValidation.AspNetCore;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.ApiExplorer;
using Microsoft.AspNetCore.StaticFiles;
using Microsoft.Extensions.Caching.Memory;
using Microsoft.Extensions.Options;
using Newtonsoft.Json.Linq;
......@@ -11,6 +12,7 @@
using Performance.Services.ExtractExcelService;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
namespace Performance.Api.Controllers
......@@ -321,7 +323,7 @@ public ApiResponse DrugtypeDelete([CustomizeValidator(RuleSet = "Delete"), FromB
[HttpPost]
public ApiResponse GetDrugtypeDisburseList([CustomizeValidator(RuleSet = "Select"), FromBody] DrugpropRequest request)
{
var list = _configService.GetDrugtypeDisburseList(request.HospitalId, request.AllotID).OrderBy(t=>t.ID);
var list = _configService.GetDrugtypeDisburseList(request.HospitalId, request.AllotID).OrderBy(t => t.ID);
var listpage = list.Skip(request.PageSize * (request.CurrentPage - 1)).Take(request.PageSize).ToList();
return new ApiResponse(ResponseType.OK, "ok", new
{
......@@ -384,7 +386,7 @@ public ApiResponse DrugtypeDisburseDelete([CustomizeValidator(RuleSet = "Delete"
[HttpPost]
public ApiResponse GetAgainList([CustomizeValidator(RuleSet = "Select"), FromBody] CofAgainRequest request)
{
var list = _configService.GetAgainList(request.AllotID).OrderBy(t=>t.ID);
var list = _configService.GetAgainList(request.AllotID).OrderBy(t => t.ID);
var listpage = list.Skip(request.PageSize * (request.CurrentPage - 1)).Take(request.PageSize).ToList();
return new ApiResponse(ResponseType.OK, "ok", new
{
......@@ -447,7 +449,7 @@ public ApiResponse AgainDelete([CustomizeValidator(RuleSet = "Delete"), FromBody
[HttpPost]
public ApiResponse GetWorkItems([CustomizeValidator(RuleSet = "Select"), FromBody] WorkItemRequest request)
{
var list = _configService.GetWorkItems(request.AllotID, request.Type).OrderBy(t=>t.ID);
var list = _configService.GetWorkItems(request.AllotID, request.Type).OrderBy(t => t.ID);
var listpage = list.Skip(request.PageSize * (request.CurrentPage - 1)).Take(request.PageSize).ToList();
return new ApiResponse(ResponseType.OK, "ok", new
{
......@@ -956,5 +958,33 @@ public ApiResponse BatchSaveCustom([FromBody] SaveCustomData request)
return _configService.SaveCustomTable(request);
}
/// <summary>
/// 自定义表显示
/// </summary>
/// <param name="request"></param>
/// <returns></returns>
[HttpPost("customlist/download")]
public IActionResult CustomDownload([FromBody] CustomPagingRequest request)
{
var allot = _allotService.GetAllot(request.AllotId);
if (allot == null)
throw new PerformanceException("AllotID错误");
string filepath = _configService.CustomDownloadFile(_claim.GetUserId(), request, allot);
if (!FileHelper.IsExistFile(filepath))
throw new PerformanceException("获取导入数据失败");
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));
}
}
}
\ No newline at end of file
......@@ -989,6 +989,13 @@
<param name="request"></param>
<returns></returns>
</member>
<member name="M:Performance.Api.Controllers.ConfigController.CustomDownload(Performance.DtoModels.CustomPagingRequest)">
<summary>
自定义表显示
</summary>
<param name="request"></param>
<returns></returns>
</member>
<member name="M:Performance.Api.Controllers.CostTransferController.SubmitApplications(Performance.DtoModels.CostTransferRequest)">
<summary>
申请划拨
......
......@@ -468,7 +468,7 @@ public List<dynamic> QueryComputeByDateAndTotal(string viewName, HospitalGrantSu
}
//sql = $"select {string.Join(",", request.GroupBy)}, {string.Join(",", request.SumBy.Select(t => $"sum({t}) {t}"))} from ({sql}) tab group by {string.Join(",", request.GroupBy)}";
return DapperQuery<dynamic>(sql, new { beginTime = request.BeginTime, endTime = request.EndTime },commandTimeout: 60*10).ToList();
return DapperQuery<dynamic>(sql, new { beginTime = request.BeginTime, endTime = request.EndTime }, commandTimeout: 60 * 10).ToList();
}
public (List<dynamic> list, int count) QueryComputePageData(string query, object param = null)
......@@ -495,6 +495,31 @@ public List<dynamic> QueryComputeByDateAndTotal(string viewName, HospitalGrantSu
/// <param name="allotId"></param>
/// <param name="accountingUnit"></param>
/// <param name="unitType"></param>
/// <returns></returns>
public List<dynamic> QueryCustom(string tableName, int allotId, string accountingUnit, string[] unitType)
{
string querySql = $@"select * from {tableName} where allotid = @allotid ";
if (!string.IsNullOrEmpty(accountingUnit))
querySql += " and accountingunit = @accountingunit";
if (unitType != null && unitType.Any())
querySql += " and unittype in @unittype";
querySql += " order by unittype,accountingunit";
var result = DapperQuery<dynamic>(querySql, new { allotId, accountingUnit, unitType }, commandTimeout: 60 * 10)?.ToList();
return result;
}
/// <summary>
/// 科室
/// </summary>
/// <param name="tableName"></param>
/// <param name="allotId"></param>
/// <param name="accountingUnit"></param>
/// <param name="unitType"></param>
/// <param name="pageIndex"></param>
/// <param name="pageSize"></param>
/// <returns></returns>
......
using AutoMapper;
using Microsoft.AspNetCore.Hosting;
using NPOI.SS.Formula.Functions;
using NPOI.SS.UserModel;
using NPOI.XSSF.UserModel;
using Performance.DtoModels;
using Performance.EntityModels;
using Performance.EntityModels.Other;
......@@ -6,8 +10,10 @@
using Performance.Infrastructure.Models;
using Performance.Repository;
using Performance.Repository.Repository;
using Performance.Services.ExtractExcelService;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Linq.Expressions;
using System.Text.RegularExpressions;
......@@ -41,6 +47,7 @@ public class ConfigService : IAutoInjection
private readonly PerforCofdrugtypeDisburseRepository _drugtypeDisburseRepository;
private readonly PerforExmoduleRepository _perforExmoduleRepository;
private readonly PerforCofdrugtypefactorRepository _cofdrugtypefactorRepository;
private readonly IWebHostEnvironment _evn;
public ConfigService(
IMapper mapper,
......@@ -66,7 +73,8 @@ public class ConfigService : IAutoInjection
PerforCofaliasRepository perforCofaliasRepository,
PerforCofaccountingRepository cofaccountingRepository,
PerforCofdrugtypeDisburseRepository drugtypeDisburseRepository,
PerforCofdrugtypefactorRepository cofdrugtypefactorRepository)
PerforCofdrugtypefactorRepository cofdrugtypefactorRepository,
IWebHostEnvironment evn)
{
_mapper = mapper;
_userService = userService;
......@@ -92,6 +100,7 @@ public class ConfigService : IAutoInjection
_drugtypeDisburseRepository = drugtypeDisburseRepository;
_perforExmoduleRepository = perforExmoduleRepository;
_cofdrugtypefactorRepository = cofdrugtypefactorRepository;
_evn = evn;
}
#endregion
......@@ -1075,17 +1084,17 @@ public SheetExportResponse GetDrugtypeFactor(AllotDeptRequest request)
index++;
}
sheet.Header = new List<Row>
sheet.Header = new List<DtoModels.Row>
{
new Row(0){ Data = mergeCells },
new Row(1){ Data = cells }
new DtoModels.Row(0){ Data = mergeCells },
new DtoModels.Row(1){ Data = cells }
};
#endregion
#region data
List<Row> rows = new List<Row>();
List<DtoModels.Row> rows = new List<DtoModels.Row>();
var querydata = _directorRepository.QueryCategoryFactor(request.HospitalId, request.AllotId)?.ToList();
if (querydata != null && querydata.Any())
{
......@@ -1127,7 +1136,7 @@ public SheetExportResponse GetDrugtypeFactor(AllotDeptRequest request)
}
i++;
}
rows.Add(new Row(index) { Data = rowcells });
rows.Add(new DtoModels.Row(index) { Data = rowcells });
index++;
}
}
......@@ -1515,6 +1524,78 @@ public ApiResponse QueryCustom(int userId, CustomPagingRequest request)
return result;
}
public string CustomDownloadFile(int userId, CustomPagingRequest request, per_allot allot)
{
var dpath = Path.Combine(_evn.ContentRootPath, "Files", "Dictionary", $"{allot.HospitalId}");
FileHelper.CreateDirectory(dpath);
string filename = $"{allot.Year}{allot.Month.ToString().PadLeft(2, '0')}导入数据-{DateTime.Now.ToString("yyyyMMddhhmmss")}.xlsx";
string filepath = Path.Combine(dpath, filename);
FileStream stream = new FileStream(filepath, FileMode.Create);
var user = _userService.GetUser(userId);
var roleType = _roleService.GetUserRole(userId)?.FirstOrDefault()?.Type ?? 0;
var heads = _perforReport.QueryCustomColumn(request.TableName) ?? new List<ColumnEntity>();
if (heads != null && heads.Any(w => string.IsNullOrEmpty(w.Comment)))
heads.RemoveAll(w => string.IsNullOrEmpty(w.Comment));
var unitTypes = UnitTypeUtil.GetMaps(roleType);
var data = _perforReport.QueryCustom(request.TableName, request.AllotId, user?.Department ?? "", unitTypes) ?? new List<dynamic>();
try
{
XSSFWorkbook workbook = new XSSFWorkbook();
ExcelStyle excelStyle = new ExcelStyle(workbook);
var style = excelStyle.SetBgkColorAndFormat(excelStyle.GetCellStyle());
ISheet sheet = workbook.CreateSheet("人员字典");
var header = sheet.CreateRow(0);
int cellIndex = 0;
foreach (var item in heads)
{
var cell = header.CreateCell(cellIndex);
cell.SetCellValue(item.Comment);
cell.CellStyle = style;
cellIndex++;
}
if (data != null && data.Any())
{
var retult = JsonHelper.Deserialize<List<Dictionary<string, object>>>(JsonHelper.Serialize(data));
int startIndex = 1;
foreach (var item in retult)
{
var row = sheet.CreateRow(startIndex);
cellIndex = 0;
foreach (var field in heads.Select(w => w.Name.ToLower()))
{
var cell = row.CreateCell(cellIndex);
cell.CellStyle = style;
cellIndex++;
if (!item.Keys.Contains(field)) continue;
cell.SetCellOValue(item[field]);
}
startIndex++;
}
}
workbook.Write(stream);
}
catch (Exception ex)
{
Console.WriteLine("写入异常" + ex);
}
finally
{
stream.Close();
}
return filepath;
}
#endregion
}
}
......@@ -517,8 +517,6 @@ public UserResponse InsertUser(UserRequest request, int userid)
if (roleArray.Intersect(request.RoleArr).Any() && string.IsNullOrEmpty(request.Department))
throw new PerformanceException("二次绩效管理员科室不能为空");
var user = _mapper.Map<sys_user>(request);
user.CreateDate = DateTime.Now;
user.CreateUser = userid;
......
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