diff --git a/src/Shentun.Peis.Application.Contracts/Reports/PrintReportDto.cs b/src/Shentun.Peis.Application.Contracts/Reports/PrintReportDto.cs new file mode 100644 index 0000000..2df9129 --- /dev/null +++ b/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; } + } +} diff --git a/src/Shentun.Peis.Application.Contracts/Reports/UploadPdfDto.cs b/src/Shentun.Peis.Application.Contracts/Reports/UploadPdfDto.cs new file mode 100644 index 0000000..1ba2221 --- /dev/null +++ b/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; } + } +} diff --git a/src/Shentun.Peis.Application/ReportFormatTemplates/ReportFormatTemplateAppService.cs b/src/Shentun.Peis.Application/ReportFormatTemplates/ReportFormatTemplateAppService.cs index 9e6a82c..5bf2de9 100644 --- a/src/Shentun.Peis.Application/ReportFormatTemplates/ReportFormatTemplateAppService.cs +++ b/src/Shentun.Peis.Application/ReportFormatTemplates/ReportFormatTemplateAppService.cs @@ -1,6 +1,8 @@ using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; +using Microsoft.EntityFrameworkCore; using Shentun.Peis.Models; +using Shentun.Peis.PeisReports; using Shentun.Peis.ReportFormats; using System; using System.Collections.Generic; @@ -26,17 +28,56 @@ namespace Shentun.Peis.ReportFormatTemplates UpdateReportFormatTemplateDto> { private readonly IRepository _userRepository; + private readonly IRepository _reportRepository; + private readonly IRepository _reportFormatRepository; + private readonly IRepository _reportFormatTemplateRepository; private readonly ReportFormatTemplateManager _manager; public ReportFormatTemplateAppService( IRepository repository, IRepository userRepository, - ReportFormatTemplateManager manager) + IRepository reportRepository, + IRepository reportFormatRepository, + ReportFormatTemplateManager manager) : base(repository) { _userRepository = userRepository; _manager = manager; + _reportFormatTemplateRepository = repository; + _reportFormatRepository = reportFormatRepository; + _reportRepository = reportRepository; + } + public async Task> 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; } - /// /// 获取通过主键 /// diff --git a/src/Shentun.Peis.Application/Reports/ReportAppService.cs b/src/Shentun.Peis.Application/Reports/ReportAppService.cs index 2399059..2efcb93 100644 --- a/src/Shentun.Peis.Application/Reports/ReportAppService.cs +++ b/src/Shentun.Peis.Application/Reports/ReportAppService.cs @@ -20,6 +20,9 @@ using TencentCloud.Mrs.V20200910.Models; using System.IO; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; +using Volo.Abp.ObjectMapping; +using Shentun.Peis.ReportPrinters; +using Microsoft.Extensions.Configuration; namespace Shentun.Peis.Reports { @@ -35,19 +38,25 @@ namespace Shentun.Peis.Reports private readonly IRepository _userRepository; private readonly IRepository _reportFormatRepository; private readonly IRepository _reportFormatTemplateRepository; + private readonly IRepository _reportPrinterRespository; + private readonly IConfiguration _configuration; private readonly ReportManager _manager; public ReportAppService( IRepository repository, IRepository userRepository, - ReportManager manager, IRepository reportFormatRepository, - IRepository reportFormatTemplateRepository) + IRepository reportFormatTemplateRepository, + IRepository reportPrinterRespository, + IConfiguration configuration, + ReportManager manager) : base(repository) { _userRepository = userRepository; - _manager = manager; _reportFormatRepository = reportFormatRepository; _reportFormatTemplateRepository = reportFormatTemplateRepository; + _reportPrinterRespository = reportPrinterRespository; + _manager = manager; + _configuration = configuration; } /// @@ -85,51 +94,54 @@ namespace Shentun.Peis.Reports }; return entdto; } - /* - public async Task GetPrintReport(GetReportInFilterDto input) + + public async Task 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.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) - 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) - throw new Volo.Abp.UserFriendlyException($"报表:'{entity.DisplayName}'的模板中未找到默认模板,请设置默认后再操作"); + throw new Volo.Abp.UserFriendlyException($"报表:【'{entity.DisplayName}'】的模板中未找到默认模板,请设置默认后再操作"); if (string.IsNullOrEmpty(dtotmp.TemplateFile)) - throw new Volo.Abp.UserFriendlyException($"模板:'{dtotmp.DisplayName}'的报表模板未设置,请设置后再操作"); + throw new Volo.Abp.UserFriendlyException($"模板:【'{dtotmp.DisplayName}'】的报表模板未设置,请设置后再操作"); 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(input.DataSetJson); - report.RegisterData(ds); - - PrintParameterDto para = JsonConvert.DeserializeObject(input.ParameterJson); - Dictionary dict = new Dictionary(); - foreach (var item in para.Parameters) + throw new Volo.Abp.UserFriendlyException($"模板:【'{dtotmp.DisplayName}'】的数据集未设置,请设置后再操作"); + var userList = await _userRepository.GetListAsync(); + var dto = ObjectMapper.Map(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(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("PeisReportPdfPath"),upload.ReportId,upload.PatientId); + await FileHelper.Base64StringConvertPDF(upload.File, PeisReportPdfPath); } - */ + /// /// 获取列表 项目 可以带名称搜索 /// diff --git a/src/Shentun.Peis.Domain/FileHelper.cs b/src/Shentun.Peis.Domain/FileHelper.cs new file mode 100644 index 0000000..f870b45 --- /dev/null +++ b/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 Base64StringConvertPDF(string file,string fileName) + { + Task task = Task.Factory.StartNew(() => + { + 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; + } + } +} diff --git a/src/Shentun.Peis.HttpApi.Host/appsettings.json b/src/Shentun.Peis.HttpApi.Host/appsettings.json index c8707f9..a1ce9e9 100644 --- a/src/Shentun.Peis.HttpApi.Host/appsettings.json +++ b/src/Shentun.Peis.HttpApi.Host/appsettings.json @@ -32,5 +32,6 @@ "RequestPath": "/CheckPictureImg", "Alias": "CheckPictureImg" }, - "AdminId": "3a0c4180-107c-0c89-b25b-0bd34666dcec" + "AdminId": "3a0c4180-107c-0c89-b25b-0bd34666dcec", + "PeisReportPdfPath": "E:\\mypeis\\PeisReportPdf\\" } \ No newline at end of file