lixiaojun
2022-11-23 b5c20e5143555a1bdd450a1e660216b90c93b6f1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
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
{
    /// <summary>
    /// Report
    /// </summary>
    [AllowAnonymous]
    [Route("DataFile/Report ")]
    [ApiDescriptionSettings("DataFile", Name = "报表", Order = 999)]
    public class Eta_Month_Report_Controller : IDynamicApiController
    {
 
        /// <summary>
        /// 泵站能效月报表
        /// </summary> 
        [Route("StationEtaMonthReport@V1.0")]
        [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 (etaSumRecord==null)
            {
                return 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)
            {
                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);
                if(etaSumSingleRecord!=null)
                etaSumSingleDayRecordList.Add(etaSumSingleRecord);
            }
            LogHelper.Info("已获管路能效信息");
            if (etaSumSingleDayRecordList == null && etaSumSingleDayRecordList.Count < 1)
            {
                return null;
            }
 
            var pdf = new Eta_Month_ReportPdf();
            var ReportPath = Path.Combine(ConfigHelper.DataPath, Settings.DataFile.PdfFolder);
            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);
            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("已拼接最终文件路径");
 
            var turePath = Path.Combine("/" + Settings.DataFile.PdfFolder, EtaPathName, dateTimePathName, etaPdfFileName);
            turePath = turePath.Replace("\\", "/");
            LogHelper.Info("已拼接最终返回路径");
 
            if (!File.Exists(etaPdfFilePath))
            {
                if (!pdf.Create4Stream(station, etaSumRecord, pumpPipeLineList, etaSumSingleDayRecordList, dateTimePathName,input.CorpID, etaPdfFilePath))
                {
                    LogHelper.Info("10");
                    return null;
                }
                LogHelper.Info("文件已创建");
            }
            else
            {
                if (File.Exists(etaPdfFilePath))
                {
                    LogHelper.Info("文件已存在,返回文件路径");
                    return turePath;
                }
            }
            LogHelper.Info("返回文件路径");
            return turePath;
        }
 
 
    }
}