lixiaojun
2023-03-20 14801a2e40bc79833c41151a37fe4cb0acbc5c7f
Application/IStation.Application.DataFile/eta_month_report/Eta_Month_Report_Controller.cs
@@ -21,62 +21,96 @@
    [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();
    public class Eta_Month_Report_Controller : IDynamicApiController
    {
        /// <summary>
        /// 泵站能效月报表
        /// </summary> 
        [Route("StationEtaMonthReport@V1.0")]
        [HttpPost]
        [HttpGet]
        public string StationEtaMonthReport([FromQuery][Required] Month_DataFileTestInput input)
        {
            var station = new Service.Station().GetByID(input.CorpID, input.ObjectID);
            LogHelper.Info("已获取泵站信息" + station);
            if (station==null)
            {
                return null;
            }
            LogHelper.Info("已获取泵站信息" + station);
            var etaSumRecord = new Service.EtaSumMultiRecord().GetMonthByObjectOfMonth(input.CorpID, IStation.ObjectType.Station, input.ObjectID, input.Year, input.Month);
            if (station == null)
            if (etaSumRecord==null)
            {
                throw Oops.Oh(ErrorCodes.D001, $"泵站不存在!!");
                return null;
            }
            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("已获取泵站能效信息" + etaSumRecord);
            var pumpPipeLineList = new Service.PipeLine().GetByBelongTypeAndBelongID(input.CorpID, IStation.ObjectType.PipeLine, input.ObjectID).FindAll(x => x.Catalog == IStation.Product.Catalog_JiBeng);
            if (pumpPipeLineList.Count<1&&pumpPipeLineList==null)
            {
                throw Oops.Oh(ErrorCodes.D001, $"机泵不存在!");
                return null;
            }
            LogHelper.Info("已获管路信息");
            var etaSumSingleDayRecordList = new List<Model.EtaSumSingleMonthRecord>();
            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);
                var etaSumSingleRecord = etaSumSingleService.GetMonthByObjectOfMonth(pipeLineitem.CorpID, IStation.ObjectType.PipeLine, pipeLineitem.ID, input.Year, input.Month);
                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.Year+input.Month}]");
                return null;
            }
            var pdf = new Eta_Month_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.Info("已创建根目录");
            var EtaPathName = "Eta-Month";
            var EtaPath = Path.Combine(ReportPath, EtaPathName);
            if (!Directory.Exists(EtaPath))
                Directory.CreateDirectory(EtaPath);
            string dateTimePathName = input.Year+"-"+input.Month;
            LogHelper.Info("已创建日期文件夹");
            string dateTimePathName = input.Year + "-" + input.Month;
            var pdfPath = Path.Combine(EtaPath, dateTimePathName);
            if (!Directory.Exists(pdfPath))
                Directory.CreateDirectory(pdfPath);
            LogHelper.Info("已创建最终日期文件夹");
            var etaPdfFileName = $"Station_Eta_{station.ID}_{dateTimePathName}.pdf";
            var etaPdfFilePath = Path.Combine(pdfPath, etaPdfFileName);
            LogHelper.Info("已拼接最终文件路径");
            if (File.Exists(etaPdfFilePath))
                File.Delete(etaPdfFilePath);
            if (!pdf.Create4Stream(station, etaSumRecord, pumpPipeLineList, etaSumSingleDayRecordList, dateTimePathName, etaPdfFilePath))
            var turePath = Path.Combine(@"Report", EtaPathName, dateTimePathName, etaPdfFileName);
            turePath = turePath.Replace(@"\\", @"/");
            LogHelper.Info("已拼接最终返回路径");
            if (!File.Exists(etaPdfFilePath))
            {
                throw Oops.Oh(ErrorCodes.D002, $"[{etaPdfFileName}]文件生成失败!");
                if (!pdf.Create4Stream(station, etaSumRecord, pumpPipeLineList, etaSumSingleDayRecordList, dateTimePathName,input.CorpID, etaPdfFilePath))
                {
                    LogHelper.Info("10");
                    return null;
                }
                LogHelper.Info("文件已创建");
            }
            var turePath = Path.Combine("/" + Settings.DataFile.PdfFolder, EtaPathName, dateTimePathName, etaPdfFileName);
            turePath = turePath.Replace("\\", "/");
            else
            {
                if (File.Exists(etaPdfFilePath))
                {
                    LogHelper.Info("文件已存在,返回文件路径");
                    return turePath;
                }
            }
            LogHelper.Info("返回文件路径");
            return turePath;
        }