forked from ddrilling/AsbCloudServer
Add DrillingProgramCreateError
This commit is contained in:
parent
cee68bf4ee
commit
f286410eff
@ -11,8 +11,15 @@ namespace AsbCloudApp.Data
|
||||
/// 3 - готова
|
||||
/// </summary>
|
||||
public int IdState { get; set; }
|
||||
public DrillingProgramCreateError Error { get; set; }
|
||||
public FileInfoDto Program { get; set; }
|
||||
public bool PermissionToEdit { get; set; }
|
||||
public IEnumerable<DrillingProgramPartDto> Parts { get; set; }
|
||||
}
|
||||
|
||||
public class DrillingProgramCreateError
|
||||
{
|
||||
public string Message { get; set; }
|
||||
public string Exception { get; set; }
|
||||
}
|
||||
}
|
||||
|
@ -19,5 +19,6 @@ namespace AsbCloudApp.Services
|
||||
Task<int> RemoveUserAsync(int idWell, int idFileCategory, int idUser, int idUserRole, CancellationToken token = default);
|
||||
Task<int> AddOrReplaceFileMarkAsync(FileMarkDto fileMarkDto, int idUser, CancellationToken token);
|
||||
Task<int> MarkAsDeletedFileMarkAsync(int idFileMark, CancellationToken token);
|
||||
void ClearError(int idWell);
|
||||
}
|
||||
}
|
@ -16,10 +16,13 @@ namespace AsbCloudInfrastructure.Services.DrillingProgram
|
||||
{
|
||||
public class DrillingProgramService : IDrillingProgramService
|
||||
{
|
||||
private static Dictionary<string, DrillingProgramCreateError> drillingProgramCreateErrors = new Dictionary<string, DrillingProgramCreateError>();
|
||||
|
||||
private readonly IAsbCloudDbContext context;
|
||||
private readonly IFileService fileService;
|
||||
private readonly IUserService userService;
|
||||
private readonly IWellService wellService;
|
||||
private readonly IConfiguration configuration;
|
||||
private readonly IBackgroundWorkerService backgroundWorker;
|
||||
private readonly string connectionString;
|
||||
|
||||
@ -41,6 +44,7 @@ namespace AsbCloudInfrastructure.Services.DrillingProgram
|
||||
private const int idStateApproving = 1;
|
||||
private const int idStateCreating = 2;
|
||||
private const int idStateReady = 3;
|
||||
private const int idStateError = 4;
|
||||
|
||||
public DrillingProgramService(
|
||||
IAsbCloudDbContext context,
|
||||
@ -54,6 +58,7 @@ namespace AsbCloudInfrastructure.Services.DrillingProgram
|
||||
this.fileService = fileService;
|
||||
this.userService = userService;
|
||||
this.wellService = wellService;
|
||||
this.configuration = configuration;
|
||||
this.backgroundWorker = backgroundWorker;
|
||||
this.connectionString = configuration.GetConnectionString("DefaultConnection");
|
||||
}
|
||||
@ -125,9 +130,20 @@ namespace AsbCloudInfrastructure.Services.DrillingProgram
|
||||
if(parts.All(p=>p.IdState == idPartStateApproved))
|
||||
{
|
||||
if (state.Program is not null)
|
||||
{
|
||||
state.IdState = idStateReady;
|
||||
else
|
||||
state.IdState = idStateCreating;
|
||||
}
|
||||
else
|
||||
{
|
||||
var workId = MakeWorkId(idWell);
|
||||
if (drillingProgramCreateErrors.ContainsKey(workId))
|
||||
{
|
||||
state.IdState = idStateError;
|
||||
state.Error = drillingProgramCreateErrors[workId];
|
||||
}
|
||||
else
|
||||
state.IdState = idStateCreating;
|
||||
}
|
||||
}
|
||||
else
|
||||
state.IdState = idStateApproving;
|
||||
@ -355,6 +371,7 @@ namespace AsbCloudInfrastructure.Services.DrillingProgram
|
||||
var well = await wellService.GetAsync(idWell, token);
|
||||
var resultFileName = $"Программа бурения {well.Cluster} {well.Caption}.xlsx";
|
||||
var tempResultFilePath = Path.Combine(Path.GetTempPath(), "drillingProgram", resultFileName);
|
||||
var mailService = new EmailService(backgroundWorker, configuration);
|
||||
async Task funcProgramMake(string id, CancellationToken token)
|
||||
{
|
||||
var contextOptions = new DbContextOptionsBuilder<AsbCloudDbContext>()
|
||||
@ -367,11 +384,26 @@ namespace AsbCloudInfrastructure.Services.DrillingProgram
|
||||
await fileService.MoveAsync(idWell, null, idFileCategoryDrillingProgram, resultFileName, tempResultFilePath, token);
|
||||
}
|
||||
|
||||
backgroundWorker.Enqueue(funcProgramMake);
|
||||
Task funcOnErrorProgramMake(string workId, Exception exception, CancellationToken token) {
|
||||
var message = $"Не удалось сформировать программу бурения по скважине {well?.Caption}";
|
||||
drillingProgramCreateErrors[workId] = new() {
|
||||
Message = message,
|
||||
Exception = exception.Message,
|
||||
};
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
backgroundWorker.Enqueue(workId, funcProgramMake, funcOnErrorProgramMake);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void ClearError(int idWell)
|
||||
{
|
||||
var workId = MakeWorkId(idWell);
|
||||
drillingProgramCreateErrors.Remove(workId);
|
||||
}
|
||||
|
||||
private async Task<int> RemoveDrillingProgramAsync(int idWell, CancellationToken token)
|
||||
{
|
||||
var workId = MakeWorkId(idWell);
|
||||
|
@ -4,11 +4,8 @@ using AsbCloudApp.Services;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
@ -70,7 +67,7 @@ namespace AsbCloudWebApi.Controllers
|
||||
|
||||
var idUser = User.GetUserId();
|
||||
|
||||
if (idCompany is null || idUser is null ||
|
||||
if (idCompany is null || idUser is null ||
|
||||
!await wellService.IsCompanyInvolvedInWellAsync((int)idCompany,
|
||||
idWell, token).ConfigureAwait(false))
|
||||
return Forbid();
|
||||
@ -79,6 +76,19 @@ namespace AsbCloudWebApi.Controllers
|
||||
return Ok(result);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Сброс ошибки формирования ПБ
|
||||
/// </summary>
|
||||
/// <param name="idWell"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost("ClearError")]
|
||||
[Permission]
|
||||
public IActionResult ClearError(int idWell)
|
||||
{
|
||||
drillingProgramService.ClearError(idWell);
|
||||
return Ok();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Загрузка файла для части программы бурения
|
||||
/// </summary>
|
||||
|
Loading…
Reference in New Issue
Block a user