123
ningshuxia
2023-04-13 eb32b4263f6901bb7ac1915b400e4fe28db20ef0
Application/IStation.Application.DataFile/eta_day_report/Eta_Day_Report_Controller.cs
@@ -15,6 +15,7 @@
namespace IStation.Application
{
    #region 报表生成
    /// <summary>
    /// Report
    /// </summary>
@@ -31,72 +32,76 @@
        public string StationEtaDayReport([FromQuery][Required] Day_DataFileTestInput input)
        {
            var station = new Service.Station().GetByID(input.CorpID, input.ObjectID);
            if (station == null)
            if (station==null)
            {
                throw Oops.Oh(ErrorCodes.D001, $"未获取到泵站数据!!");
                return null;
            }
            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)
            LogHelper.Info("已获取泵站");
            var pumpPipeLineList = new Service.PipeLine().GetByBelongTypeAndBelongID(input.CorpID, input.ObjectType, input.ObjectID).FindAll(x => x.Catalog == IStation.Product.Catalog_JiBeng);
            if (pumpPipeLineList == null&&pumpPipeLineList.Count<1)
            {
                throw Oops.Oh(ErrorCodes.D001, $"未获取到机泵数据!");
                return null;
            }
            LogHelper.Error("2");
            LogHelper.Info("已获取管路");
            var etaSumSingleDayRecordList = new List<Model.EtaSumSingleDayRecord>();
            var etaSumSingleService = new Service.EtaSumSingleRecord();
            foreach (var pipeLineitem in pumpPipeLineList)
            {
                var etaSumSingleRecord = etaSumSingleService.GetDayByObjectOfDay(pipeLineitem.CorpID, IStation.ObjectType.PipeLine, pipeLineitem.ID, input.DateTime);
                etaSumSingleDayRecordList.Add(etaSumSingleRecord);
                if (etaSumSingleRecord != null)
                    etaSumSingleDayRecordList.Add(etaSumSingleRecord);
            }
            if (etaSumSingleDayRecordList == null || etaSumSingleDayRecordList.Count < 1)
            LogHelper.Info("已获取能效信息");
            if (etaSumSingleDayRecordList == null && etaSumSingleDayRecordList.Count < 1)
            {
                throw Oops.Oh(ErrorCodes.D001, $"能效数据不存在!-日期:[{input.DateTime}]");
                return null;
            }
            LogHelper.Error("3");
            LogHelper.Info("生成根目录");
            var pdf = new Eta_Day_ReportPdf();
            var ReportPath = Path.Combine(ConfigHelper.DataPath, Settings.DataFile.PdfFolder);
            var ReportPath = Path.Combine(ConfigHelper.DataPath, @"Report");
            if (!Directory.Exists(ReportPath))
                Directory.CreateDirectory(ReportPath);
            LogHelper.Error("4");
            LogHelper.Info("拼接日期文件夹");
            var EtaPathName = "Eta-Day";
            var EtaPath = Path.Combine(ReportPath, EtaPathName);
            if (!Directory.Exists(EtaPath))
                Directory.CreateDirectory(EtaPath);
            LogHelper.Error("5");
            LogHelper.Info("拼接时间");
            var dateTimePathName = input.DateTime.ToString("yyyy-MM");
            var pdfPath = Path.Combine(EtaPath, dateTimePathName);
            if (!Directory.Exists(pdfPath))
                Directory.CreateDirectory(pdfPath);
            LogHelper.Error("6");
            LogHelper.Info("拼接文件最终路径");
            var etaPdfFileName = $"Station_Eta_{station.ID}_{input.DateTime.ToString("MM-dd")}.pdf";
            var etaPdfFilePath = Path.Combine(pdfPath, etaPdfFileName);
            var turePath = Path.Combine("/" + Settings.DataFile.PdfFolder, EtaPathName, dateTimePathName, etaPdfFileName);
            turePath = turePath.Replace("\\", "/");
            LogHelper.Error("7");
            var turePath = Path.Combine(@"Report", EtaPathName, dateTimePathName, etaPdfFileName);
            turePath = turePath.Replace(@"\\", @"/");
            LogHelper.Info("拼接最终路径");
            if (!File.Exists(etaPdfFilePath))
            {
                if (!pdf.Create4Stream(station, pumpPipeLineList, etaSumSingleDayRecordList, input.DateTime, etaPdfFilePath))
                LogHelper.Info("文件不存在,生成文件");
                if (!pdf.Create4Stream(station, pumpPipeLineList, etaSumSingleDayRecordList,input.CorpID, input.DateTime, etaPdfFilePath))
                {
                    LogHelper.Error("10");
                    throw Oops.Oh(ErrorCodes.D002, $"[{etaPdfFileName}]文件生成失败!");
                    LogHelper.Info("生成失败");
                    return null;
                }
            }
            else
            {
                if (File.Exists(etaPdfFilePath))
                {
                    LogHelper.Error("7");
                    LogHelper.Info("文件存在返回路径");
                    return turePath;
                }
            }
            LogHelper.Info("文件返回路径");
            return turePath;
        }
    }
#endregion
}