Browse Source

报表

bjmzak
vaining01 2 years ago
parent
commit
55e9a7f62d
  1. 15
      src/Shentun.Peis.Application.Contracts/Reports/PrintReportDto.cs
  2. 15
      src/Shentun.Peis.Application.Contracts/Reports/UploadPdfDto.cs
  3. 45
      src/Shentun.Peis.Application/ReportFormatTemplates/ReportFormatTemplateAppService.cs
  4. 78
      src/Shentun.Peis.Application/Reports/ReportAppService.cs
  5. 42
      src/Shentun.Peis.Domain/FileHelper.cs

15
src/Shentun.Peis.Application.Contracts/Reports/PrintReportDto.cs

@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
using System.Text;
using Shentun.Peis.ReportFormatTemplates;
using Shentun.Peis.ReportPrinters;
namespace Shentun.Peis.Reports
{
public class PrintReportDto
{
public ReportFormatTemplateDto reportFormatTemplate { get; set; }
public ReportPrinterDto reportPrinter { get; set; }
}
}

15
src/Shentun.Peis.Application.Contracts/Reports/UploadPdfDto.cs

@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace Shentun.Peis.Reports
{
public class UploadPdfDto
{
public string File { get; set; }
public string ReportId { get; set; }
public string PatientId { get; set; }
}
}

45
src/Shentun.Peis.Application/ReportFormatTemplates/ReportFormatTemplateAppService.cs

@ -1,6 +1,8 @@
using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using Shentun.Peis.Models; using Shentun.Peis.Models;
using Shentun.Peis.PeisReports;
using Shentun.Peis.ReportFormats; using Shentun.Peis.ReportFormats;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
@ -26,17 +28,56 @@ namespace Shentun.Peis.ReportFormatTemplates
UpdateReportFormatTemplateDto> UpdateReportFormatTemplateDto>
{ {
private readonly IRepository<IdentityUser, Guid> _userRepository; private readonly IRepository<IdentityUser, Guid> _userRepository;
private readonly IRepository<Report, string> _reportRepository;
private readonly IRepository<ReportFormat, string> _reportFormatRepository;
private readonly IRepository<ReportFormatTemplate, string> _reportFormatTemplateRepository;
private readonly ReportFormatTemplateManager _manager; private readonly ReportFormatTemplateManager _manager;
public ReportFormatTemplateAppService( public ReportFormatTemplateAppService(
IRepository<ReportFormatTemplate, string> repository, IRepository<ReportFormatTemplate, string> repository,
IRepository<IdentityUser, Guid> userRepository, IRepository<IdentityUser, Guid> userRepository,
ReportFormatTemplateManager manager)
IRepository<Report, string> reportRepository,
IRepository<ReportFormat, string> reportFormatRepository,
ReportFormatTemplateManager manager)
: base(repository) : base(repository)
{ {
_userRepository = userRepository; _userRepository = userRepository;
_manager = manager; _manager = manager;
_reportFormatTemplateRepository = repository;
_reportFormatRepository = reportFormatRepository;
_reportRepository = reportRepository;
}
public async Task<List<ReportFormatTemplateDto>> GetReportTemplateAsync()
{
var query = from a in await _reportFormatRepository.GetQueryableAsync()
join b in await _reportRepository.GetQueryableAsync() on a.ReportId equals b.Id into bb
from ab in bb.DefaultIfEmpty()
join c in await _reportFormatTemplateRepository.GetQueryableAsync() on a.Id equals c.ReportFormatId into cc
from ac in cc.DefaultIfEmpty()
where (a.IsDefault=='Y' &&ab.IsActive=='Y'&&ac.IsDefault== 'Y')
select new
{
a,
ab,
ac
};
//query = query.Where(p=>p.a.IsDefault.Equals("Y") && p.ab.IsActive.Equals("Y") && p.ac.IsDefault.Equals("Y"));
//var ss = query.ToQueryString();
var entlist = query.Select(s => new ReportFormatTemplateDto
{
Id = s.ab.Id,
ReportFormatId = s.ac.ReportFormatId,
DisplayName = s.ac.DisplayName,
TemplateFileType = s.ac.TemplateFileType,
TemplateFile = s.ac.TemplateFile,
DataSetJson = s.ac.DataSetJson,
IsSystem = s.ac.IsSystem,
IsDefault = s.ac.IsDefault,
LastModificationTime = s.ac.LastModificationTime,
}).ToList();
return entlist;
} }
/// <summary> /// <summary>
/// 获取通过主键 /// 获取通过主键
/// </summary> /// </summary>

78
src/Shentun.Peis.Application/Reports/ReportAppService.cs

@ -20,6 +20,9 @@ using TencentCloud.Mrs.V20200910.Models;
using System.IO; using System.IO;
using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Volo.Abp.ObjectMapping;
using Shentun.Peis.ReportPrinters;
using Microsoft.Extensions.Configuration;
namespace Shentun.Peis.Reports namespace Shentun.Peis.Reports
{ {
@ -35,19 +38,25 @@ namespace Shentun.Peis.Reports
private readonly IRepository<IdentityUser, Guid> _userRepository; private readonly IRepository<IdentityUser, Guid> _userRepository;
private readonly IRepository<ReportFormat, string> _reportFormatRepository; private readonly IRepository<ReportFormat, string> _reportFormatRepository;
private readonly IRepository<ReportFormatTemplate,string> _reportFormatTemplateRepository; private readonly IRepository<ReportFormatTemplate,string> _reportFormatTemplateRepository;
private readonly IRepository<ReportPrinter, string> _reportPrinterRespository;
private readonly IConfiguration _configuration;
private readonly ReportManager _manager; private readonly ReportManager _manager;
public ReportAppService( public ReportAppService(
IRepository<Report,string> repository, IRepository<Report,string> repository,
IRepository<IdentityUser, Guid> userRepository, IRepository<IdentityUser, Guid> userRepository,
ReportManager manager,
IRepository<ReportFormat, string> reportFormatRepository, IRepository<ReportFormat, string> reportFormatRepository,
IRepository<ReportFormatTemplate, string> reportFormatTemplateRepository)
IRepository<ReportFormatTemplate, string> reportFormatTemplateRepository,
IRepository<ReportPrinter, string> reportPrinterRespository,
IConfiguration configuration,
ReportManager manager)
: base(repository) : base(repository)
{ {
_userRepository = userRepository; _userRepository = userRepository;
_manager = manager;
_reportFormatRepository = reportFormatRepository; _reportFormatRepository = reportFormatRepository;
_reportFormatTemplateRepository = reportFormatTemplateRepository; _reportFormatTemplateRepository = reportFormatTemplateRepository;
_reportPrinterRespository = reportPrinterRespository;
_manager = manager;
_configuration = configuration;
} }
/// <summary> /// <summary>
@ -85,51 +94,54 @@ namespace Shentun.Peis.Reports
}; };
return entdto; return entdto;
} }
/*
public async Task<ReportFileDto> GetPrintReport(GetReportInFilterDto input)
public async Task<PrintReportDto> GetPrintReport(string reportId,string computerName)
{ {
var entity = await base.GetAsync(input.ReportId);
PrintReportDto printReportDto = new PrintReportDto();
var entity = await base.GetEntityByIdAsync(reportId);
if (entity == null) return null; if (entity == null) return null;
if (!entity.IsActive.Equals('Y')) if (!entity.IsActive.Equals('Y'))
throw new Volo.Abp.UserFriendlyException($"报表:'{entity.DisplayName}'未启用,请启用后再操作");
throw new Volo.Abp.UserFriendlyException($"报表:'{entity.DisplayName}'未启用,请启用后再操作");
var dtoformat = await _reportFormatRepository.GetAsync(p => p.ReportId.Equals(entity.Id) && p.IsDefault.Equals('Y'));
var dtoformat = await _reportFormatRepository.FirstOrDefaultAsync(p => p.ReportId.Equals(entity.Id) && p.IsDefault.Equals('Y'));
if (dtoformat == null) if (dtoformat == null)
throw new Volo.Abp.UserFriendlyException($"报表:'{entity.DisplayName}'的格式中未找到默认格式,请设置默认后再操作");
throw new Volo.Abp.UserFriendlyException($"报表:'{entity.DisplayName}'的格式中未找到默认格式,请设置默认后再操作");
var dtotmp = await _reportFormatTemplateRepository.GetAsync(p => p.ReportFormatId.Equals(dtoformat.Id) && p.IsDefault.Equals('Y'));
var dtotmp = await _reportFormatTemplateRepository.FirstOrDefaultAsync(p => p.ReportFormatId.Equals(dtoformat.Id) && p.IsDefault.Equals('Y'));
if (dtotmp == null) if (dtotmp == null)
throw new Volo.Abp.UserFriendlyException($"报表:'{entity.DisplayName}'的模板中未找到默认模板,请设置默认后再操作");
throw new Volo.Abp.UserFriendlyException($"报表:'{entity.DisplayName}'的模板中未找到默认模板,请设置默认后再操作");
if (string.IsNullOrEmpty(dtotmp.TemplateFile)) if (string.IsNullOrEmpty(dtotmp.TemplateFile))
throw new Volo.Abp.UserFriendlyException($"模板:'{dtotmp.DisplayName}'的报表模板未设置,请设置后再操作");
throw new Volo.Abp.UserFriendlyException($"模板:'{dtotmp.DisplayName}'的报表模板未设置,请设置后再操作");
if (string.IsNullOrEmpty(dtotmp.DataSetJson)) if (string.IsNullOrEmpty(dtotmp.DataSetJson))
throw new Volo.Abp.UserFriendlyException($"模板:'{dtotmp.DisplayName}'的数据集未设置,请设置后再操作");
FastReport.Report report = new FastReport.Report();
report.LoadFromString(dtotmp.TemplateFile);
DataSet ds = JsonConvert.DeserializeObject<DataSet>(input.DataSetJson);
report.RegisterData(ds);
PrintParameterDto para = JsonConvert.DeserializeObject<PrintParameterDto>(input.ParameterJson);
Dictionary<string, string> dict = new Dictionary<string, string>();
foreach (var item in para.Parameters)
throw new Volo.Abp.UserFriendlyException($"模板:【'{dtotmp.DisplayName}'】的数据集未设置,请设置后再操作");
var userList = await _userRepository.GetListAsync();
var dto = ObjectMapper.Map<ReportFormatTemplate, ReportFormatTemplateDto>(dtotmp);
dto.IsDefaulted = dtotmp.IsDefault.Equals('Y');
dto.IsSystemed= dtotmp.IsSystem.Equals('Y');
dto.CreatorName = EntityHelper.GetUserNameNoSql(userList, entity.CreatorId);
dto.LastModifierName = EntityHelper.GetUserNameNoSql(userList, entity.LastModifierId);
printReportDto.reportFormatTemplate = dto;
var printerEntity = await _reportPrinterRespository.FirstOrDefaultAsync(p => p.ReportId.Equals(reportId) && p.ComputerName.Equals(computerName));
if (printerEntity != null)
{ {
report.SetParameterValue(item.Name, item.Value);
var printer = ObjectMapper.Map<ReportPrinter, ReportPrinterDto>(printerEntity);
printer.CreatorName = EntityHelper.GetUserNameNoSql(userList, printerEntity.CreatorId);
printer.LastModifierName = EntityHelper.GetUserNameNoSql(userList, printerEntity.LastModifierId);
printReportDto.reportPrinter = printer;
} }
return printReportDto;
}
report.Prepare();
MemoryStream ms = new MemoryStream();
PDFSimpleExport pdfExport = new PDFSimpleExport();
pdfExport.Export(report, ms);
ms.Flush();
return null;
public async Task Upload(UploadPdfDto upload)
{
var PeisReportPdfPath = string.Format("{0}{1}\\{2}.pdf", _configuration.GetValue<string>("PeisReportPdfPath"),upload.ReportId,upload.PatientId);
await FileHelper.Base64StringConvertPDF(upload.File, PeisReportPdfPath);
} }
*/
/// <summary> /// <summary>
/// 获取列表 项目 可以带名称搜索 /// 获取列表 项目 可以带名称搜索
/// </summary> /// </summary>

42
src/Shentun.Peis.Domain/FileHelper.cs

@ -0,0 +1,42 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Resources;
using System.Text;
using System.Threading.Tasks;
using static OpenIddict.Abstractions.OpenIddictConstants;
namespace Shentun.Peis
{
public class FileHelper
{
public static bool IsBase64String(string input)
{
input = input.Trim();
return (input.Length % 4 == 0) &&
System.Text.RegularExpressions.Regex.IsMatch(input, @"^[a-zA-Z0-9\+/]*={0,2}$", System.Text.RegularExpressions.RegexOptions.None);
}
public static async Task<string> Base64StringConvertPDF(string file,string fileName)
{
Task<String> task = Task.Factory.StartNew<String>(() =>
{
string base64BinaryStr = file;
if (!IsBase64String(base64BinaryStr)) return "非法字符串,不是BASE64";
byte[] bytes = Convert.FromBase64String(base64BinaryStr);
using (var stream = new FileStream(fileName, FileMode.CreateNew))
{
using (var writer = new BinaryWriter(stream))
{
writer.Write(bytes, 0, bytes.Length);
}
}
return "Success";
});
String result= await task;
return result;
}
}
}
Loading…
Cancel
Save