lixiaojun
2023-03-20 14801a2e40bc79833c41151a37fe4cb0acbc5c7f
Application/IStation.Application.DataFile/eta_day_report/Eta_Day_Report_Controller.cs
@@ -15,16 +15,15 @@
namespace IStation.Application
{
    #region 报表生成
    /// <summary>
    /// Report
    /// </summary>
    [AllowAnonymous]
    [Route("DataFile/Report ")]
    [ApiDescriptionSettings("DataFile", Name = "报表", Order = 999)]
    public class Eta_Day_Report_Controller : IDynamicApiController, ITransient
    public class Eta_Day_Report_Controller : IDynamicApiController
    {
        private readonly Service.EtaMultiRealRecord _service = new Service.EtaMultiRealRecord();
        /// <summary>
        /// 泵站能效日报表
        /// </summary> 
@@ -33,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 (!File.Exists(etaPdfFilePath))
            {
                return turePath;
                LogHelper.Info("文件不存在,生成文件");
                if (!pdf.Create4Stream(station, pumpPipeLineList, etaSumSingleDayRecordList,input.CorpID, input.DateTime, etaPdfFilePath))
                {
                    LogHelper.Info("生成失败");
                    return null;
                }
            }
            else
            {
                if (!File.Exists(etaPdfFilePath))
                if (File.Exists(etaPdfFilePath))
                {
                    if (!pdf.Create4Stream(station, pumpPipeLineList, etaSumSingleDayRecordList, input.DateTime, etaPdfFilePath))
                    {
                        LogHelper.Error("10");
                        throw Oops.Oh(ErrorCodes.D002, $"[{etaPdfFileName}]文件生成失败!");
                    }
                    File.Create(etaPdfFilePath).Close();
                    LogHelper.Info("文件存在返回路径");
                    return turePath;
                }
            }
            LogHelper.Info("文件返回路径");
            return turePath;
        }
    }
#endregion
}