wangzelong
2022-09-22 d15ed0dc079421dd0f9d26c9d85a1f8801d9cb18
Application/IStation.Application.DataFile/eta_day_report/Eta_Day_Report_Controller.cs
@@ -21,27 +21,27 @@
    [AllowAnonymous]
    [Route("DataFile/Report ")]
    [ApiDescriptionSettings("DataFile", Name = "报表", Order = 999)]
    public class Eta_Day_Report_Controller : IDynamicApiController, ITransient
    {
        private readonly Service.EtaMultiRealRecord _service = new Service.EtaMultiRealRecord();
    public class Eta_Day_Report_Controller : IDynamicApiController
    {
        /// <summary>
        /// 泵站能效日报表
        /// </summary> 
        [Route("StationEtaDayReport@V1.0")]
        [HttpPost]
        [HttpGet]
        public string StationEtaDayReport([FromQuery][Required] Day_DataFileTestInput input)
        {
            var station = new Service.Station().GetByID(input.CorpID, input.ObjectID);
            if (station == null)
            {
                throw Oops.Oh(ErrorCodes.D001, $"泵站不存在!!");
                throw Oops.Oh(ErrorCodes.D001, $"未获取到泵站数据!!");
            }
            LogHelper.Error("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, $"机泵不存在!");
                throw Oops.Oh(ErrorCodes.D001, $"未获取到机泵数据!");
            }
            LogHelper.Error("2");
            var etaSumSingleDayRecordList = new List<Model.EtaSumSingleDayRecord>();
            var etaSumSingleService = new Service.EtaSumSingleRecord();
            foreach (var pipeLineitem in pumpPipeLineList)
@@ -53,29 +53,47 @@
            {
                throw Oops.Oh(ErrorCodes.D001, $"能效数据不存在!-日期:[{input.DateTime}]");
            }
            LogHelper.Error("3");
            var pdf = new Eta_Day_ReportPdf();
            var ReportPath = Path.Combine(ConfigHelper.DataPath, Settings.DataFile.PdfFolder);
            if (!Directory.Exists(ReportPath))
                Directory.CreateDirectory(ReportPath);
            LogHelper.Error("4");
            var EtaPathName = "Eta-Day";
            var EtaPath = Path.Combine(ReportPath, EtaPathName);
            if (!Directory.Exists(EtaPath))
                Directory.CreateDirectory(EtaPath);
            LogHelper.Error("5");
            var dateTimePathName = input.DateTime.ToString("yyyy-MM");
            var pdfPath= Path.Combine(EtaPath, dateTimePathName);
            var pdfPath = Path.Combine(EtaPath, dateTimePathName);
            if (!Directory.Exists(pdfPath))
                Directory.CreateDirectory(pdfPath);
            LogHelper.Error("6");
            var etaPdfFileName = $"Station_Eta_{station.ID}_{input.DateTime.ToString("MM-dd")}.pdf";
            var etaPdfFilePath = Path.Combine(pdfPath, etaPdfFileName);
            if (File.Exists(etaPdfFilePath))
                File.Delete(etaPdfFilePath);
            if (!pdf.Create4Stream(station, pumpPipeLineList, etaSumSingleDayRecordList, input.DateTime, etaPdfFilePath))
            {
                throw Oops.Oh(ErrorCodes.D002, $"[{etaPdfFileName}]文件生成失败!");
            }
            var turePath = Path.Combine("/" + Settings.DataFile.PdfFolder, EtaPathName, dateTimePathName, etaPdfFileName);
            turePath = turePath.Replace("\\", "/");
            LogHelper.Error("7");
            if (!File.Exists(etaPdfFilePath))
            {
                if (!pdf.Create4Stream(station, pumpPipeLineList, etaSumSingleDayRecordList, input.DateTime, etaPdfFilePath))
                {
                    LogHelper.Error("10");
                    throw Oops.Oh(ErrorCodes.D002, $"[{etaPdfFileName}]文件生成失败!");
                }
            }
            else
            {
                if (File.Exists(etaPdfFilePath))
                {
                    LogHelper.Error("7");
                    return turePath;
                }
            }
            return turePath;
        }