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
|
{
|
#region 报表生成
|
/// <summary>
|
/// Report
|
/// </summary>
|
[AllowAnonymous]
|
[Route("DataFile/Report ")]
|
[ApiDescriptionSettings("DataFile", Name = "报表", Order = 999)]
|
public class Eta_Day_Report_Controller : IDynamicApiController
|
{
|
/// <summary>
|
/// 泵站能效日报表
|
/// </summary>
|
[Route("StationEtaDayReport@V1.0")]
|
[HttpGet]
|
public string StationEtaDayReport([FromQuery][Required] Day_DataFileTestInput input)
|
{
|
var station = new Service.Station().GetByID(input.CorpID, input.ObjectID);
|
if (station==null)
|
{
|
return 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)
|
{
|
return null;
|
}
|
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);
|
if (etaSumSingleRecord != null)
|
etaSumSingleDayRecordList.Add(etaSumSingleRecord);
|
}
|
LogHelper.Info("已获取能效信息");
|
if (etaSumSingleDayRecordList == null && etaSumSingleDayRecordList.Count < 1)
|
{
|
return null;
|
}
|
LogHelper.Info("生成根目录");
|
var pdf = new Eta_Day_ReportPdf();
|
var ReportPath = Path.Combine(ConfigHelper.DataPath, @"Report");
|
if (!Directory.Exists(ReportPath))
|
Directory.CreateDirectory(ReportPath);
|
LogHelper.Info("拼接日期文件夹");
|
var EtaPathName = "Eta-Day";
|
var EtaPath = Path.Combine(ReportPath, EtaPathName);
|
if (!Directory.Exists(EtaPath))
|
Directory.CreateDirectory(EtaPath);
|
LogHelper.Info("拼接时间");
|
var dateTimePathName = input.DateTime.ToString("yyyy-MM");
|
var pdfPath = Path.Combine(EtaPath, dateTimePathName);
|
if (!Directory.Exists(pdfPath))
|
Directory.CreateDirectory(pdfPath);
|
|
LogHelper.Info("拼接文件最终路径");
|
var etaPdfFileName = $"Station_Eta_{station.ID}_{input.DateTime.ToString("MM-dd")}.pdf";
|
var etaPdfFilePath = Path.Combine(pdfPath, etaPdfFileName);
|
|
var turePath = Path.Combine(@"Report", EtaPathName, dateTimePathName, etaPdfFileName);
|
turePath = turePath.Replace(@"\\", @"/");
|
LogHelper.Info("拼接最终路径");
|
|
if (!File.Exists(etaPdfFilePath))
|
{
|
LogHelper.Info("文件不存在,生成文件");
|
if (!pdf.Create4Stream(station, pumpPipeLineList, etaSumSingleDayRecordList,input.CorpID, input.DateTime, etaPdfFilePath))
|
{
|
LogHelper.Info("生成失败");
|
return null;
|
}
|
}
|
else
|
{
|
if (File.Exists(etaPdfFilePath))
|
{
|
LogHelper.Info("文件存在返回路径");
|
return turePath;
|
}
|
}
|
LogHelper.Info("文件返回路径");
|
return turePath;
|
}
|
|
|
}
|
#endregion
|
}
|