forked from ddrilling/AsbCloudServer
Add WellInfoService
This commit is contained in:
parent
f30c3ce833
commit
d41cff84a9
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
namespace AsbCloudApp.Data
|
namespace AsbCloudApp.Data
|
||||||
{
|
{
|
||||||
|
#nullable enable
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Инфо о скважине для отображения на карте
|
/// Инфо о скважине для отображения на карте
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -22,7 +23,7 @@ namespace AsbCloudApp.Data
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Плановая и текущая глубина
|
/// Плановая и текущая глубина
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public PlanFactDto WellDepth { get; set; }
|
public PlanFactBase<double?> WellDepth { get; set; } = null!;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Отставание от ГГД, %
|
/// Отставание от ГГД, %
|
||||||
@ -32,12 +33,12 @@ namespace AsbCloudApp.Data
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Механическая скорость проходки, последней операции бурения
|
/// Механическая скорость проходки, последней операции бурения
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public PlanFactDto ROP { get; set; }
|
public PlanFactBase<double?> ROP { get; set; } = null!;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Рейсовая скорость проходки, последнего рейса
|
/// Рейсовая скорость проходки, последнего рейса
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public PlanFactDto RaceSpeed { get; set; }
|
public PlanFactBase<double?> RaceSpeed { get; set; } = null!;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Процент использования АКБ
|
/// Процент использования АКБ
|
||||||
@ -49,4 +50,5 @@ namespace AsbCloudApp.Data
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public double SpinUsage { get; set; }
|
public double SpinUsage { get; set; }
|
||||||
}
|
}
|
||||||
|
#nullable disable
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,6 @@
|
|||||||
namespace AsbCloudApp.Requests
|
using System.Collections.Generic;
|
||||||
|
|
||||||
|
namespace AsbCloudApp.Requests
|
||||||
{
|
{
|
||||||
#nullable enable
|
#nullable enable
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -15,6 +17,11 @@
|
|||||||
/// id состояния
|
/// id состояния
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public int? IdState { get; set; }
|
public int? IdState { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Идентификаторы скважин
|
||||||
|
/// </summary>
|
||||||
|
public IEnumerable<int>? Ids { get; set; }
|
||||||
}
|
}
|
||||||
#nullable disable
|
#nullable disable
|
||||||
}
|
}
|
||||||
|
@ -103,7 +103,6 @@ namespace AsbCloudApp.Services
|
|||||||
/// <param name="idCompany"></param>
|
/// <param name="idCompany"></param>
|
||||||
/// <param name="token"></param>
|
/// <param name="token"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
#warning GetWellTreeAsync(..) is dummy. Remove it before pullrequest.
|
|
||||||
Task<IEnumerable<DepositBranchDto>> GetWellTreeAsync(int idCompany, CancellationToken token);
|
Task<IEnumerable<DepositBranchDto>> GetWellTreeAsync(int idCompany, CancellationToken token);
|
||||||
}
|
}
|
||||||
#nullable disable
|
#nullable disable
|
||||||
|
@ -47,6 +47,7 @@ namespace AsbCloudApp.Services.Subsystems
|
|||||||
/// <param name="token"></param>
|
/// <param name="token"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
Task<DatesRangeDto?> GetDateRangeOperationTimeAsync(SubsystemOperationTimeRequest request, CancellationToken token);
|
Task<DatesRangeDto?> GetDateRangeOperationTimeAsync(SubsystemOperationTimeRequest request, CancellationToken token);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Получение статистики по наработке подсистем по активным скважинам
|
/// Получение статистики по наработке подсистем по активным скважинам
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -56,6 +57,14 @@ namespace AsbCloudApp.Services.Subsystems
|
|||||||
/// <param name="token"></param>
|
/// <param name="token"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
Task<IEnumerable<SubsystemActiveWellStatDto>> GetStatByActiveWells(int idCompany, DateTime? gtDate, DateTime? ltDate, CancellationToken token);
|
Task<IEnumerable<SubsystemActiveWellStatDto>> GetStatByActiveWells(int idCompany, DateTime? gtDate, DateTime? ltDate, CancellationToken token);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Получение статистики по наработке подсистем по активным скважинам
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="wellIds"></param>
|
||||||
|
/// <param name="token"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
Task<IEnumerable<SubsystemActiveWellStatDto>> GetStatByActiveWells(IEnumerable<int> wellIds, CancellationToken token);
|
||||||
}
|
}
|
||||||
#nullable disable
|
#nullable disable
|
||||||
}
|
}
|
||||||
|
@ -67,5 +67,8 @@ namespace AsbCloudDb.Model
|
|||||||
|
|
||||||
[InverseProperty(nameof(DrillingProgramPart.Well))]
|
[InverseProperty(nameof(DrillingProgramPart.Well))]
|
||||||
public virtual ICollection<DrillingProgramPart> DrillingProgramParts { get; set; }
|
public virtual ICollection<DrillingProgramPart> DrillingProgramParts { get; set; }
|
||||||
|
|
||||||
|
[InverseProperty(nameof(ProcessMap.Well))]
|
||||||
|
public virtual ICollection<ProcessMap> ProcessMaps { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -188,17 +188,24 @@ namespace AsbCloudInfrastructure.Services.Subsystems
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task<IEnumerable<WellDto>> GetActiveWellsByCompany(int idCompany, CancellationToken token)
|
|
||||||
{
|
|
||||||
var listWell = await wellService.GetAsync(new() { IdCompany = idCompany }, token);
|
|
||||||
var active = listWell.Where(w => w.IdState == 1);
|
|
||||||
return active;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
public async Task<IEnumerable<SubsystemActiveWellStatDto>> GetStatByActiveWells(int idCompany, DateTime? gtDate, DateTime? ltDate, CancellationToken token)
|
public async Task<IEnumerable<SubsystemActiveWellStatDto>> GetStatByActiveWells(int idCompany, DateTime? gtDate, DateTime? ltDate, CancellationToken token)
|
||||||
{
|
{
|
||||||
var wells = await GetActiveWellsByCompany(idCompany, token);
|
var activeWells = await wellService.GetAsync(new() { IdCompany = idCompany, IdState = 1 }, token);
|
||||||
|
var result = await GetStatAsync(activeWells, gtDate, ltDate, token);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc/>
|
||||||
|
public async Task<IEnumerable<SubsystemActiveWellStatDto>> GetStatByActiveWells(IEnumerable<int> wellIds, CancellationToken token)
|
||||||
|
{
|
||||||
|
var activeWells = await wellService.GetAsync(new() { Ids = wellIds, IdState = 1 }, token);
|
||||||
|
var result = await GetStatAsync(activeWells, null, null, token);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task<IEnumerable<SubsystemActiveWellStatDto>> GetStatAsync(IEnumerable<WellDto> wells, DateTime? gtDate, DateTime? ltDate, CancellationToken token)
|
||||||
|
{
|
||||||
if (!wells.Any())
|
if (!wells.Any())
|
||||||
return Enumerable.Empty<SubsystemActiveWellStatDto>();
|
return Enumerable.Empty<SubsystemActiveWellStatDto>();
|
||||||
|
|
||||||
|
154
AsbCloudInfrastructure/Services/WellInfoService.cs
Normal file
154
AsbCloudInfrastructure/Services/WellInfoService.cs
Normal file
@ -0,0 +1,154 @@
|
|||||||
|
using AsbCloudApp.Data;
|
||||||
|
using AsbCloudApp.Data.ProcessMap;
|
||||||
|
using AsbCloudApp.Repositories;
|
||||||
|
using AsbCloudApp.Requests;
|
||||||
|
using AsbCloudApp.Services;
|
||||||
|
using AsbCloudApp.Services.Subsystems;
|
||||||
|
using AsbCloudDb.Model;
|
||||||
|
using AsbCloudInfrastructure.Background;
|
||||||
|
using Mapster;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Threading;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace AsbCloudInfrastructure.Services
|
||||||
|
{
|
||||||
|
#nullable enable
|
||||||
|
public class WellInfoService
|
||||||
|
{
|
||||||
|
class WellMapInfoWithComanies : WellMapInfoDto
|
||||||
|
{
|
||||||
|
public IEnumerable<int> IdsCompanies { get; set; } = null!;
|
||||||
|
}
|
||||||
|
|
||||||
|
private const string workId = "Well statistics update";
|
||||||
|
private static readonly TimeSpan workPeriod = TimeSpan.FromMinutes(30);
|
||||||
|
|
||||||
|
private static IEnumerable<WellMapInfoWithComanies> WellMapInfo = Enumerable.Empty<WellMapInfoWithComanies>();
|
||||||
|
|
||||||
|
public static WorkPeriodic MakeWork()
|
||||||
|
{
|
||||||
|
var workPeriodic = new WorkPeriodic(workId, WorkAction, workPeriod)
|
||||||
|
{
|
||||||
|
Timeout = TimeSpan.FromMinutes(30)
|
||||||
|
};
|
||||||
|
return workPeriodic;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static async Task WorkAction(string workName, IServiceProvider serviceProvider, CancellationToken token)
|
||||||
|
{
|
||||||
|
var db = serviceProvider.GetRequiredService<IAsbCloudDbContext>();
|
||||||
|
var wellService = serviceProvider.GetRequiredService<IWellService>();
|
||||||
|
var operationsStatService = serviceProvider.GetRequiredService<IOperationsStatService>();
|
||||||
|
var processMapRepository = serviceProvider.GetRequiredService<IProcessMapRepository>();
|
||||||
|
var subsystemOperationTimeService = serviceProvider.GetRequiredService<ISubsystemOperationTimeService>();
|
||||||
|
|
||||||
|
var activeWells = await wellService.GetAsync(new() {IdState = 1}, token);
|
||||||
|
|
||||||
|
IEnumerable<int> activeWellsIds = activeWells
|
||||||
|
.Select(w => w.Id);
|
||||||
|
|
||||||
|
var idTelemetries = activeWells
|
||||||
|
.Where(w => w.IdTelemetry != null)
|
||||||
|
.Select(t => t.IdTelemetry);
|
||||||
|
|
||||||
|
var lastTelemetryInfo = await db.TelemetryDataSaub
|
||||||
|
.Where(t => idTelemetries.Contains(t.IdTelemetry))
|
||||||
|
.Select(t => new
|
||||||
|
{
|
||||||
|
t.IdTelemetry,
|
||||||
|
t.WellDepth,
|
||||||
|
t.DateTime,
|
||||||
|
})
|
||||||
|
.GroupBy(t => t.IdTelemetry)
|
||||||
|
.Select(g => g.OrderByDescending(t => t.DateTime)
|
||||||
|
.First()
|
||||||
|
)
|
||||||
|
.AsNoTracking()
|
||||||
|
.ToArrayAsync(token);
|
||||||
|
|
||||||
|
var processMapRequests = activeWellsIds.Select(id => new ProcessMapRequest { IdWell = id });
|
||||||
|
var processMaps = await processMapRepository.GetProcessMapAsync(processMapRequests, token);
|
||||||
|
|
||||||
|
var wellDepthByProcessMap = processMaps
|
||||||
|
.GroupBy(p => p.IdWell)
|
||||||
|
.Select(g => new
|
||||||
|
{
|
||||||
|
Id = g.Key,
|
||||||
|
DepthEnd = g.Max(p => p.DepthEnd)
|
||||||
|
});
|
||||||
|
|
||||||
|
var operationsStat = await operationsStatService.GetWellsStatAsync(activeWellsIds, token);
|
||||||
|
var subsystemStat = await subsystemOperationTimeService.GetStatByActiveWells(activeWellsIds, token);
|
||||||
|
|
||||||
|
WellMapInfo = activeWells.Select(well => {
|
||||||
|
var wellMapInfo = well.Adapt<WellMapInfoWithComanies>();
|
||||||
|
|
||||||
|
// From teltemetryTracker
|
||||||
|
var wellLastTelemetryInfo = lastTelemetryInfo.FirstOrDefault(t => t.IdTelemetry == well.IdTelemetry);
|
||||||
|
|
||||||
|
var wellOperationsStat = operationsStat.FirstOrDefault(s => s.Id == well.Id);
|
||||||
|
var wellLastFactSection = wellOperationsStat?.Sections.LastOrDefault(s => s.Fact is not null);
|
||||||
|
|
||||||
|
var wellSubsystemStat = subsystemStat.FirstOrDefault(s => s.Well.Id == well.Id);
|
||||||
|
|
||||||
|
double currentDepth = wellLastTelemetryInfo?.WellDepth
|
||||||
|
?? wellLastFactSection?.Fact.WellDepthEnd
|
||||||
|
?? 0d;
|
||||||
|
|
||||||
|
var wellProcessMaps = processMaps
|
||||||
|
.Where(p => p.IdWell == well.Id)
|
||||||
|
.OrderBy(p => p.DepthEnd);
|
||||||
|
|
||||||
|
int? idSection = wellLastFactSection?.Id;
|
||||||
|
|
||||||
|
ProcessMapDto? welllProcessMap;
|
||||||
|
if (idSection is not null)
|
||||||
|
{
|
||||||
|
welllProcessMap = wellProcessMaps.FirstOrDefault(p => p.IdWellSectionType == idSection);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
welllProcessMap = wellProcessMaps.FirstOrDefault(p => p.DepthStart <= currentDepth && p.DepthEnd >= currentDepth);
|
||||||
|
idSection ??= welllProcessMap?.IdWellSectionType;
|
||||||
|
}
|
||||||
|
|
||||||
|
wellMapInfo.LastTelemetryDate = wellLastTelemetryInfo?.DateTime.ToRemoteDateTime(5) ?? new DateTime();
|
||||||
|
wellMapInfo.WellDepth = new()
|
||||||
|
{
|
||||||
|
Plan = wellDepthByProcessMap.FirstOrDefault(p => p.Id == well.Id)?.DepthEnd,
|
||||||
|
Fact = currentDepth,
|
||||||
|
};
|
||||||
|
|
||||||
|
wellMapInfo.ROP = new()
|
||||||
|
{
|
||||||
|
Plan = welllProcessMap?.RopPlan,
|
||||||
|
Fact = wellOperationsStat?.Total.Fact?.Rop,
|
||||||
|
};
|
||||||
|
|
||||||
|
wellMapInfo.RaceSpeed = new()
|
||||||
|
{
|
||||||
|
Plan = wellOperationsStat?.Total.Plan?.RouteSpeed,
|
||||||
|
Fact = wellOperationsStat?.Total.Fact?.RouteSpeed,
|
||||||
|
};
|
||||||
|
|
||||||
|
wellMapInfo.SaubUsage = wellSubsystemStat?.SubsystemAKB?.KUsage ?? 0d;
|
||||||
|
wellMapInfo.SpinUsage = wellSubsystemStat?.SubsystemSpinMaster?.KUsage ?? 0d;
|
||||||
|
wellMapInfo.TvdLagPercent = 0;// From WellOperationService?
|
||||||
|
wellMapInfo.IdsCompanies = well.Companies.Select(c => c.Id);
|
||||||
|
return wellMapInfo;
|
||||||
|
}).ToArray();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static IEnumerable<WellMapInfoDto> Where(Func<WellMapInfoDto, bool> predicate)
|
||||||
|
=> WellMapInfo.Where(predicate);
|
||||||
|
|
||||||
|
public static WellMapInfoDto? FirstOrDefault(Func<WellMapInfoDto, bool> predicate)
|
||||||
|
=> WellMapInfo.FirstOrDefault(predicate);
|
||||||
|
}
|
||||||
|
#nullable disable
|
||||||
|
}
|
@ -69,7 +69,7 @@ namespace AsbCloudInfrastructure.Services
|
|||||||
return lastTelemetryDate;
|
return lastTelemetryDate;
|
||||||
}
|
}
|
||||||
|
|
||||||
#warning GetWellTreeAsync(..) is dummy. Remove it before pullrequest.
|
/// <inheritdoc/>
|
||||||
public async Task<IEnumerable<DepositBranchDto>> GetWellTreeAsync(int idCompany, CancellationToken token)
|
public async Task<IEnumerable<DepositBranchDto>> GetWellTreeAsync(int idCompany, CancellationToken token)
|
||||||
{
|
{
|
||||||
var wells = await GetEntitiesAsync(new() { IdCompany = idCompany }, token);
|
var wells = await GetEntitiesAsync(new() { IdCompany = idCompany }, token);
|
||||||
@ -93,15 +93,13 @@ namespace AsbCloudInfrastructure.Services
|
|||||||
Longitude = gCluster.Key.Longitude ?? gDeposit.Key.Longitude,
|
Longitude = gCluster.Key.Longitude ?? gDeposit.Key.Longitude,
|
||||||
Wells = gCluster.Select(well =>
|
Wells = gCluster.Select(well =>
|
||||||
{
|
{
|
||||||
var dto = well.Adapt<WellMapInfoDto>();
|
var dto = WellInfoService.FirstOrDefault(w => w.Id == well.Id);
|
||||||
if (dto.Latitude is null)
|
dto ??= well.Adapt<WellMapInfoDto>();
|
||||||
dto.Latitude = gCluster.Key.Latitude ?? gDeposit.Key.Latitude;
|
dto.Latitude ??= gCluster.Key.Latitude ?? gDeposit.Key.Latitude;
|
||||||
|
dto.Longitude ??= gCluster.Key.Longitude ?? gDeposit.Key.Longitude;
|
||||||
if (dto.Longitude is null)
|
|
||||||
dto.Longitude = gCluster.Key.Longitude ?? gDeposit.Key.Longitude;
|
|
||||||
|
|
||||||
if (well.IdTelemetry is not null)
|
if (well.IdTelemetry is not null)
|
||||||
dto.LastTelemetryDate = telemetryService.GetLastTelemetryDate(well.IdTelemetry.Value);
|
dto.LastTelemetryDate = telemetryService.GetLastTelemetryDate(well.IdTelemetry.Value);
|
||||||
|
|
||||||
return dto;
|
return dto;
|
||||||
}),
|
}),
|
||||||
}),
|
}),
|
||||||
@ -120,10 +118,12 @@ namespace AsbCloudInfrastructure.Services
|
|||||||
{
|
{
|
||||||
var wells = await GetCacheAsync(token);
|
var wells = await GetCacheAsync(token);
|
||||||
|
|
||||||
|
if (request.Ids?.Any() == true)
|
||||||
|
wells = wells.Where(well => request.Ids.Contains(well.Id));
|
||||||
|
|
||||||
if (request.IdCompany.HasValue)
|
if (request.IdCompany.HasValue)
|
||||||
wells = wells.Where(well => well.RelationCompaniesWells.Any(r => r.IdCompany == request.IdCompany.Value));
|
wells = wells.Where(well => well.RelationCompaniesWells.Any(r => r.IdCompany == request.IdCompany.Value));
|
||||||
|
|
||||||
|
|
||||||
if (request.IdState.HasValue)
|
if (request.IdState.HasValue)
|
||||||
wells = wells.Where(well => well.IdState == request.IdState.Value);
|
wells = wells.Where(well => well.IdState == request.IdState.Value);
|
||||||
|
|
||||||
|
@ -27,7 +27,8 @@ namespace AsbCloudInfrastructure
|
|||||||
var wellService = provider.GetRequiredService<IWellService>();
|
var wellService = provider.GetRequiredService<IWellService>();
|
||||||
wellService.EnshureTimezonesIsSetAsync(CancellationToken.None).Wait();// TODO: make this background work
|
wellService.EnshureTimezonesIsSetAsync(CancellationToken.None).Wait();// TODO: make this background work
|
||||||
|
|
||||||
var backgroundWorker = provider.GetRequiredService<Background.BackgroundWorker>();
|
var backgroundWorker = provider.GetRequiredService<BackgroundWorker>();
|
||||||
|
backgroundWorker.Push(WellInfoService.MakeWork());
|
||||||
backgroundWorker.Push(OperationDetectionWorkFactory.MakeWork());
|
backgroundWorker.Push(OperationDetectionWorkFactory.MakeWork());
|
||||||
backgroundWorker.Push(SubsystemOperationTimeCalcWorkFactory.MakeWork());
|
backgroundWorker.Push(SubsystemOperationTimeCalcWorkFactory.MakeWork());
|
||||||
backgroundWorker.Push(LimitingParameterCalcWorkFactory.MakeWork());
|
backgroundWorker.Push(LimitingParameterCalcWorkFactory.MakeWork());
|
||||||
|
@ -1,11 +1,17 @@
|
|||||||
using iTextSharp.text.pdf;
|
using System;
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Document = iTextSharp.text.Document;
|
using AsbCloudApp.Data;
|
||||||
|
using AsbCloudApp.Services;
|
||||||
|
using AsbCloudDb.Model;
|
||||||
|
using AsbCloudInfrastructure;
|
||||||
using CliWrap;
|
using CliWrap;
|
||||||
|
using Mapster;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
|
||||||
namespace ConsoleApp1
|
namespace ConsoleApp1
|
||||||
{
|
{
|
||||||
@ -13,160 +19,20 @@ namespace ConsoleApp1
|
|||||||
{
|
{
|
||||||
static void Main(/*string[] args*/)
|
static void Main(/*string[] args*/)
|
||||||
{
|
{
|
||||||
// string[] fileExtension = { ".xlsx", ".xls", ".ods", ".odt", ".doc", ".docx", ".pdf" };
|
var db = ServiceFactory.Context;
|
||||||
// Console.WriteLine($"start convert");
|
var q = db.TelemetryDataSaub
|
||||||
// var inputFiles = new List<string>();
|
.Select(t => new {
|
||||||
// var resultFile = "C:\\Test\\result.pdf";
|
t.IdTelemetry,
|
||||||
// inputFiles.Add("11112222.docx");
|
t.DateTime,
|
||||||
// inputFiles.Add("11117777.pdf");
|
t.WellDepth,
|
||||||
// inputFiles.Add("22223333.xls");
|
})
|
||||||
// inputFiles.Add("33334444.xlsx");
|
.GroupBy(t => t.IdTelemetry)
|
||||||
// //inputFiles.Add("33334444.tts");
|
.Select(g => new {
|
||||||
|
Id = g.Key,
|
||||||
// var listOutNames = new List<string>();
|
First = g.OrderBy(t => t.DateTime).FirstOrDefault(),
|
||||||
// var filteredFilesNames = inputFiles
|
Last = g.OrderBy(t => t.DateTime).LastOrDefault(),
|
||||||
// .Distinct()
|
|
||||||
// .Where(f => fileExtension.Any(fe => f.ToLower().EndsWith(fe)))
|
|
||||||
// .ToList();
|
|
||||||
// FileInfo fileInfo = new FileInfo(resultFile);
|
|
||||||
|
|
||||||
// //matchesExtensions(inputFiles);
|
|
||||||
// foreach (var FileName in inputFiles)
|
|
||||||
// {
|
|
||||||
// var outputFile = Path.ChangeExtension(FileName, ".pdf");
|
|
||||||
// var outFile = StartConvertProcessAsync(FileName, outputFile);
|
|
||||||
// Console.WriteLine($"convert file - {FileName}");
|
|
||||||
// Console.ReadLine();
|
|
||||||
// listOutNames.Add(outFile.Result.ToString());
|
|
||||||
// }
|
|
||||||
// Console.WriteLine("merged files");
|
|
||||||
// Console.ReadLine();
|
|
||||||
// DoMerged(listOutNames, resultFile);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//static void matchesExtensions(List<string> inputFiles)
|
|
||||||
// {
|
|
||||||
// string[] fileExtension = { ".xlsx", ".xls", ".ods", ".odt", ".doc", ".docx", ".pdf" };
|
|
||||||
// foreach (var file in inputFiles)
|
|
||||||
// {
|
|
||||||
// var fileExt = Path.GetExtension(file);
|
|
||||||
// if (fileExtension.All(fe => fileExt != fe))
|
|
||||||
// {
|
|
||||||
// throw new FileFormatException($"Файл с именем: {file} не может быть добавлен в список файлов для конвертации и слияния в общий файл программы бурения. Не поддерживаемый формат файла");
|
|
||||||
// }
|
|
||||||
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
if (OperatingSystem.IsWindows())
|
|
||||||
{
|
|
||||||
Console.WriteLine("win");
|
|
||||||
Console.ReadLine();
|
|
||||||
}
|
|
||||||
if (OperatingSystem.IsLinux())
|
|
||||||
{
|
|
||||||
Console.WriteLine("linux");
|
|
||||||
Console.ReadLine();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void DoMerged(IEnumerable<string> inputFiles, string outFile)
|
|
||||||
{
|
|
||||||
using var stream = new FileStream(outFile, FileMode.Create);
|
|
||||||
using var doc = new Document();
|
|
||||||
using var pdf = new PdfCopy(doc, stream);
|
|
||||||
doc.Open();
|
|
||||||
var inputFilesList = inputFiles.ToList();
|
|
||||||
foreach (var file in inputFilesList)
|
|
||||||
{
|
|
||||||
var reader = new PdfReader(file);
|
|
||||||
for (int i = 0; i < reader.NumberOfPages; i++)
|
|
||||||
{
|
|
||||||
PdfImportedPage page = pdf.GetImportedPage(reader, i + 1);
|
|
||||||
pdf.AddPage(page);
|
|
||||||
}
|
|
||||||
pdf.FreeReader(reader);
|
|
||||||
reader.Close();
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
private static (string programFile, string programArg) getOptionsStartupProcess(string inputFileName, string resultFileDir)
|
|
||||||
{
|
|
||||||
(string programFile, string programArg) startupOptions;
|
|
||||||
if (OperatingSystem.IsWindows())
|
|
||||||
{
|
|
||||||
startupOptions.programFile = "C:\\Program Files\\LibreOffice\\program\\soffice.exe";
|
|
||||||
startupOptions.programArg = $"-headless -convert-to pdf {inputFileName} --outdir {resultFileDir}";
|
|
||||||
return startupOptions;
|
|
||||||
}
|
|
||||||
if (OperatingSystem.IsLinux())
|
|
||||||
{
|
|
||||||
startupOptions.programFile = "/usr/bin/soffice";
|
|
||||||
startupOptions.programArg = $"--headless --convert-to pdf {inputFileName} --outdir {resultFileDir}";
|
|
||||||
return (startupOptions);
|
|
||||||
}
|
|
||||||
|
|
||||||
throw new NotSupportedException("Вызов процесса в текущей операционной системе не возможен");
|
|
||||||
}
|
|
||||||
|
|
||||||
//public static void StartConvertProcess(string inputFileName, string outFileName)
|
|
||||||
//{
|
|
||||||
// using (Process pdfprocess = new Process())
|
|
||||||
// {
|
|
||||||
// pdfprocess.StartInfo.UseShellExecute = true;
|
|
||||||
// //pdfprocess.StartInfo.LoadUserProfile = true;
|
|
||||||
// pdfprocess.StartInfo.FileName = "soffice";
|
|
||||||
// pdfprocess.StartInfo.Arguments = $"--headless --convert-to pdf {inputFileName} --outdir {outFileName}";
|
|
||||||
// pdfprocess.StartInfo.WorkingDirectory = "/usr/bin";
|
|
||||||
// pdfprocess.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
|
|
||||||
// pdfprocess.Start();
|
|
||||||
// if (!pdfprocess.WaitForExit(1000 * 60 * 1))
|
|
||||||
// {
|
|
||||||
// pdfprocess.Kill();
|
|
||||||
// }
|
|
||||||
// pdfprocess.Close();
|
|
||||||
// }
|
|
||||||
//}
|
|
||||||
private static async Task<string> StartConvertProcessAsync(string inputFileName, string outFileName)
|
|
||||||
{
|
|
||||||
|
|
||||||
var progrAndArg = getOptionsStartupProcess(inputFileName, outFileName);
|
|
||||||
|
|
||||||
//string outPath = "/home/eddie/Test/OutFiles";
|
|
||||||
string outPath = "C:\\Test\\OutFiles";
|
|
||||||
var result = Cli.Wrap("C:\\Program Files\\LibreOffice\\program\\soffice.exe")
|
|
||||||
.WithArguments($"-headless -convert-to pdf C:\\Test\\InFiles\\{inputFileName} -outdir {outPath}");
|
|
||||||
await result.ExecuteAsync();
|
|
||||||
var outFile = $"{outPath}\\{outFileName}";
|
|
||||||
return outFile;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static async Task GetConverteAndMergedFileAsync(IEnumerable<string> filesNames, string resultPath)
|
|
||||||
{
|
|
||||||
string[] fileExtension = { ".xlsx", ".xls", ".ods", ".odt", ".doc", ".docx", ".pdf" };
|
|
||||||
//var filteredFilesNames = filesNames.Distinct();
|
|
||||||
var filteredFilesNames = filesNames
|
|
||||||
.Distinct()
|
|
||||||
.Where(f => fileExtension.Any(fe => f.ToLower().EndsWith(fe)))
|
|
||||||
.ToList();
|
|
||||||
var listFileNames = filteredFilesNames
|
|
||||||
.ToList()
|
|
||||||
.Select(o => new {
|
|
||||||
inputFile = o,
|
|
||||||
convertedFile = Path.ChangeExtension(o, ".pdf")
|
|
||||||
});
|
});
|
||||||
foreach (var excelFileName in listFileNames)
|
var d = q.AsNoTracking().ToArray();
|
||||||
{
|
|
||||||
await StartConvertProcessAsync(excelFileName.inputFile, excelFileName.convertedFile);
|
|
||||||
Console.WriteLine($"convert file - {excelFileName.inputFile}");
|
|
||||||
Console.ReadLine();
|
|
||||||
}
|
|
||||||
|
|
||||||
Console.WriteLine("merged files");
|
|
||||||
Console.ReadLine();
|
|
||||||
DoMerged(listFileNames.Select(c => c.convertedFile), resultPath);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user