using Microsoft.AspNetCore.Mvc; using System.Net; using System.Net.Http.Headers; using Microsoft.Extensions.Hosting.Internal; using Microsoft.AspNetCore.Http.Extensions; using IStation.Untity; using Furion.DynamicApiController; using System.ComponentModel.DataAnnotations; using Mapster; using Microsoft.AspNetCore.Http; using Furion.DependencyInjection; using Microsoft.AspNetCore.Authorization; using Furion.DataEncryption; using Furion.FriendlyException; namespace IStation.Application { /// /// Report /// [AllowAnonymous] [Route("DataFile/Report ")] [ApiDescriptionSettings("DataFile", Name = "报表", Order = 999)] public class Eta_Month_Report_Controller : IDynamicApiController, ITransient { private readonly Service.EtaSumMultiRecord _service = new Service.EtaSumMultiRecord(); /// /// 泵站能效月报表 /// [Route("StationEtaMonthReport@V1.0")] [HttpGet] public string StationEtaMonthReport([FromQuery][Required] Month_DataFileTestInput input) { var station = new Service.Station().GetByID(input.CorpID, input.ObjectID); var etaSumRecord = new Service.EtaSumMultiRecord().GetMonthByObjectOfMonth(input.CorpID, input.ObjectType, input.ObjectID, input.Year, input.Month); if (station == null) { throw Oops.Oh(ErrorCodes.D001, $"泵站不存在!!"); } if (etaSumRecord == null) { throw Oops.Oh(ErrorCodes.D001, $"泵站不存在!!"); } LogHelper.Info("1"); var pumpPipeLineList = new Service.PipeLine().GetByBelongTypeAndBelongID(input.CorpID, input.ObjectType, input.ObjectID)?.FindAll(x => x.Catalog == IStation.Product.Catalog_JiBeng); if (pumpPipeLineList == null) { throw Oops.Oh(ErrorCodes.D001, $"机泵不存在!"); } LogHelper.Info("2"); var etaSumSingleDayRecordList = new List(); var etaSumSingleService = new Service.EtaSumSingleRecord(); foreach (var pipeLineitem in pumpPipeLineList) { var etaSumSingleRecord = etaSumSingleService.GetMonthByObjectOfMonth(pipeLineitem.CorpID, IStation.ObjectType.PipeLine, pipeLineitem.ID, input.Year, input.Month); etaSumSingleDayRecordList.Add(etaSumSingleRecord); } if (etaSumSingleDayRecordList == null || etaSumSingleDayRecordList.Count < 1) { throw Oops.Oh(ErrorCodes.D001, $"能效数据不存在!-日期:[{input.Year + input.Month}]"); } LogHelper.Info("3"); var pdf = new Eta_Month_ReportPdf(); var ReportPath = Path.Combine(ConfigHelper.DataPath, Settings.DataFile.PdfFolder); if (!Directory.Exists(ReportPath)) Directory.CreateDirectory(ReportPath); LogHelper.Info("4"); var EtaPathName = "Eta-Month"; var EtaPath = Path.Combine(ReportPath, EtaPathName); if (!Directory.Exists(EtaPath)) Directory.CreateDirectory(EtaPath); LogHelper.Info("5"); string dateTimePathName = input.Year + "-" + input.Month; var pdfPath = Path.Combine(EtaPath, dateTimePathName); if (!Directory.Exists(pdfPath)) Directory.CreateDirectory(pdfPath); LogHelper.Info("6"); var etaPdfFileName = $"Station_Eta_{station.ID}_{dateTimePathName}.pdf"; var etaPdfFilePath = Path.Combine(pdfPath, etaPdfFileName); var turePath = Path.Combine("/" + Settings.DataFile.PdfFolder, EtaPathName, dateTimePathName, etaPdfFileName); turePath = turePath.Replace("\\", "/"); if (File.Exists(etaPdfFilePath)) { return turePath; } else { if (!File.Exists(etaPdfFilePath)) { if (!pdf.Create4Stream(station, etaSumRecord, pumpPipeLineList, etaSumSingleDayRecordList, dateTimePathName, etaPdfFilePath)) { LogHelper.Error("10"); throw Oops.Oh(ErrorCodes.D002, $"[{etaPdfFileName}]文件生成失败!"); } File.Create(etaPdfFilePath).Close(); } } return turePath; } } }