* Further improvements to generate PackList
This commit is contained in:
@@ -22,5 +22,19 @@ namespace FaKrosnoApi.Controllers
|
||||
CustomerOrderDto? scheduleOrder = await service.GetByOrderNumber(customerOrderNumber);
|
||||
return scheduleOrder != null ? Ok(scheduleOrder) : NotFound();
|
||||
}
|
||||
|
||||
[HttpGet("by-co-number")]
|
||||
public async Task<ActionResult<CustomerOrderDto?>> GetByCoNumber([FromQuery] string customerOrderNumber)
|
||||
{
|
||||
CustomerOrderDto? scheduleOrder = await service.GetByCoNumber(customerOrderNumber);
|
||||
return scheduleOrder != null ? Ok(scheduleOrder) : NotFound();
|
||||
}
|
||||
|
||||
[HttpGet("items-by-co-number")]
|
||||
public async Task<ActionResult<CustomerOrderDto?>> GetItemsByCoNumber([FromQuery] string customerOrderNumber)
|
||||
{
|
||||
var customerOrderLineItems = await service.GetItemsByCoNumber(customerOrderNumber);
|
||||
return customerOrderLineItems != null ? Ok(customerOrderLineItems) : NotFound();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,154 +17,154 @@ public class HangfireJobsController(
|
||||
ITaskSchedulerService service) : Controller
|
||||
{
|
||||
|
||||
public async Task<ActionResult<IEnumerable<JobModel>>> GetJobsToRun()
|
||||
{
|
||||
IList<JobModel> jobsToRun = new List<JobModel>();
|
||||
|
||||
using (IStorageConnection? connection = jobStorage.GetConnection())
|
||||
{
|
||||
IList<RecurringJobDto>? recurringJobs = connection.GetRecurringJobs();
|
||||
IList<TaskSchedulerDto>? taskSchedulers = (await service.GetTaskSchedulers()).ToList();
|
||||
|
||||
foreach (var recurringJob in recurringJobs)
|
||||
{
|
||||
TaskSchedulerDto? taskScheduler = taskSchedulers?.FirstOrDefault(ts => ts.Name == recurringJob.Id);
|
||||
|
||||
if (taskScheduler != null)
|
||||
{
|
||||
jobsToRun.Add(new JobModel(recurringJob.Id, recurringJob.Cron, taskScheduler.Path,
|
||||
recurringJob.LastExecution, recurringJob.NextExecution, recurringJob.Job));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return Ok(jobsToRun);
|
||||
}
|
||||
|
||||
[HttpPost("run")]
|
||||
public async Task<IActionResult> RunJobs()
|
||||
{
|
||||
var jobsToRun = (await GetJobsToRun()).Value?.ToList();
|
||||
|
||||
if (jobsToRun == null || jobsToRun.Count == 0)
|
||||
{
|
||||
return BadRequest("Nie udało się pobrać zadań do uruchomienia.");
|
||||
}
|
||||
|
||||
foreach (var job in jobsToRun)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(job.Path))
|
||||
{
|
||||
recurringJobManager.AddOrUpdate(job.JobId, () => RunConsoleApplication(job.Path), job.Cron,
|
||||
new RecurringJobOptions { TimeZone = TimeZoneInfo.Local });
|
||||
}
|
||||
}
|
||||
|
||||
return Ok("Zadania zostały zaplanowane do uruchamiania zgodnie z ich CRON.");
|
||||
}
|
||||
|
||||
[HttpPost("add")]
|
||||
public async Task<IActionResult> AddTask([FromBody] TaskSchedulerDto taskSchedulerDto)
|
||||
{
|
||||
var taskScheduler = new OrdersManagementDataModel.Entities.TaskScheduler
|
||||
{
|
||||
Name = taskSchedulerDto.Name,
|
||||
Path = taskSchedulerDto.Path,
|
||||
CronOptions = taskSchedulerDto.CronOptions,
|
||||
CreateDate = DateTime.UtcNow
|
||||
};
|
||||
|
||||
int result = await service.AddTaskScheduler(taskSchedulerDto);
|
||||
|
||||
if (result == 0)
|
||||
{
|
||||
return BadRequest("Nie udało się dodać zadania.");
|
||||
}
|
||||
|
||||
recurringJobManager.AddOrUpdate(taskScheduler.Name, () => RunConsoleApplication(taskScheduler.Path),
|
||||
taskScheduler.CronOptions, new RecurringJobOptions { TimeZone = TimeZoneInfo.Local });
|
||||
|
||||
return Ok("Zadanie zostało dodane.");
|
||||
}
|
||||
|
||||
[HttpPost("delete")]
|
||||
public async Task<IActionResult> DeleteTask([FromBody] TaskSchedulerDto taskSchedulerDto)
|
||||
{
|
||||
int result = await service.DeleteTaskScheduler(taskSchedulerDto.RowPointer);
|
||||
|
||||
if (result == 0)
|
||||
{
|
||||
return BadRequest("Nie udało się usunąć zadania.");
|
||||
}
|
||||
|
||||
recurringJobManager.RemoveIfExists(taskSchedulerDto.Name);
|
||||
|
||||
return Ok("Zadanie zostało usunięte.");
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public async Task<ActionResult<IEnumerable<TaskSchedulerDto>>> GetTasks()
|
||||
{
|
||||
var tasks = await service.GetTaskSchedulers();
|
||||
|
||||
foreach (TaskSchedulerDto taskSchedulerDto in tasks)
|
||||
{
|
||||
var job = GetJob(taskSchedulerDto.Name);
|
||||
taskSchedulerDto.LastExecution = job?.LastExecution;
|
||||
taskSchedulerDto.NextExecution = job?.NextExecution;
|
||||
}
|
||||
|
||||
return Ok(tasks);
|
||||
}
|
||||
|
||||
[HttpGet("by-name")]
|
||||
public async Task<ActionResult<TaskSchedulerDto>> GetTaskSchedulerByTaskName([FromQuery] string name)
|
||||
{
|
||||
var taskSchedulerDto = await service.GetTaskSchedulerByTaskName(name);
|
||||
|
||||
if (taskSchedulerDto == null) return NotFound();
|
||||
|
||||
var job = GetJob(taskSchedulerDto.Name);
|
||||
taskSchedulerDto.LastExecution = job?.LastExecution;
|
||||
taskSchedulerDto.NextExecution = job?.NextExecution;
|
||||
|
||||
return Ok(taskSchedulerDto);
|
||||
}
|
||||
|
||||
private RecurringJobDto? GetJob(string jobId)
|
||||
{
|
||||
using IStorageConnection? connection = jobStorage.GetConnection();
|
||||
IList<RecurringJobDto>? recurringJobs = connection.GetRecurringJobs();
|
||||
return recurringJobs.FirstOrDefault(x => x.Id == jobId);
|
||||
}
|
||||
|
||||
public void RunConsoleApplication(string pathToApp)
|
||||
{
|
||||
try
|
||||
{
|
||||
var process = new Process
|
||||
{
|
||||
StartInfo = new ProcessStartInfo
|
||||
{
|
||||
FileName = pathToApp,
|
||||
UseShellExecute = false,
|
||||
RedirectStandardOutput = true,
|
||||
RedirectStandardError = true,
|
||||
CreateNoWindow = true,
|
||||
WorkingDirectory = Path.GetDirectoryName(pathToApp)
|
||||
}
|
||||
};
|
||||
process.Start();
|
||||
string output = process.StandardOutput.ReadToEnd();
|
||||
string error = process.StandardError.ReadToEnd();
|
||||
process.WaitForExit();
|
||||
|
||||
Console.WriteLine($"Output: {output}");
|
||||
Console.WriteLine($"Error: {error}");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine($"Error executing console application: {ex.Message}");
|
||||
}
|
||||
}
|
||||
// public async Task<ActionResult<IEnumerable<JobModel>>> GetJobsToRun()
|
||||
// {
|
||||
// IList<JobModel> jobsToRun = new List<JobModel>();
|
||||
//
|
||||
// using (IStorageConnection? connection = jobStorage.GetConnection())
|
||||
// {
|
||||
// IList<RecurringJobDto>? recurringJobs = connection.GetRecurringJobs();
|
||||
// IList<TaskSchedulerDto>? taskSchedulers = (await service.GetTaskSchedulers()).ToList();
|
||||
//
|
||||
// foreach (var recurringJob in recurringJobs)
|
||||
// {
|
||||
// TaskSchedulerDto? taskScheduler = taskSchedulers?.FirstOrDefault(ts => ts.Name == recurringJob.Id);
|
||||
//
|
||||
// if (taskScheduler != null)
|
||||
// {
|
||||
// jobsToRun.Add(new JobModel(recurringJob.Id, recurringJob.Cron, taskScheduler.Path,
|
||||
// recurringJob.LastExecution, recurringJob.NextExecution, recurringJob.Job));
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// return Ok(jobsToRun);
|
||||
// }
|
||||
//
|
||||
// [HttpPost("run")]
|
||||
// public async Task<IActionResult> RunJobs()
|
||||
// {
|
||||
// var jobsToRun = (await GetJobsToRun()).Value?.ToList();
|
||||
//
|
||||
// if (jobsToRun == null || jobsToRun.Count == 0)
|
||||
// {
|
||||
// return BadRequest("Nie udało się pobrać zadań do uruchomienia.");
|
||||
// }
|
||||
//
|
||||
// foreach (var job in jobsToRun)
|
||||
// {
|
||||
// if (!string.IsNullOrEmpty(job.Path))
|
||||
// {
|
||||
// recurringJobManager.AddOrUpdate(job.JobId, () => RunConsoleApplication(job.Path), job.Cron,
|
||||
// new RecurringJobOptions { TimeZone = TimeZoneInfo.Local });
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// return Ok("Zadania zostały zaplanowane do uruchamiania zgodnie z ich CRON.");
|
||||
// }
|
||||
//
|
||||
// [HttpPost("add")]
|
||||
// public async Task<IActionResult> AddTask([FromBody] TaskSchedulerDto taskSchedulerDto)
|
||||
// {
|
||||
// var taskScheduler = new OrdersManagementDataModel.Entities.TaskScheduler
|
||||
// {
|
||||
// Name = taskSchedulerDto.Name,
|
||||
// Path = taskSchedulerDto.Path,
|
||||
// CronOptions = taskSchedulerDto.CronOptions,
|
||||
// CreateDate = DateTime.UtcNow
|
||||
// };
|
||||
//
|
||||
// int result = await service.AddTaskScheduler(taskSchedulerDto);
|
||||
//
|
||||
// if (result == 0)
|
||||
// {
|
||||
// return BadRequest("Nie udało się dodać zadania.");
|
||||
// }
|
||||
//
|
||||
// recurringJobManager.AddOrUpdate(taskScheduler.Name, () => RunConsoleApplication(taskScheduler.Path),
|
||||
// taskScheduler.CronOptions, new RecurringJobOptions { TimeZone = TimeZoneInfo.Local });
|
||||
//
|
||||
// return Ok("Zadanie zostało dodane.");
|
||||
// }
|
||||
//
|
||||
// [HttpPost("delete")]
|
||||
// public async Task<IActionResult> DeleteTask([FromBody] TaskSchedulerDto taskSchedulerDto)
|
||||
// {
|
||||
// int result = await service.DeleteTaskScheduler(taskSchedulerDto.RowPointer);
|
||||
//
|
||||
// if (result == 0)
|
||||
// {
|
||||
// return BadRequest("Nie udało się usunąć zadania.");
|
||||
// }
|
||||
//
|
||||
// recurringJobManager.RemoveIfExists(taskSchedulerDto.Name);
|
||||
//
|
||||
// return Ok("Zadanie zostało usunięte.");
|
||||
// }
|
||||
//
|
||||
// [HttpGet]
|
||||
// public async Task<ActionResult<IEnumerable<TaskSchedulerDto>>> GetTasks()
|
||||
// {
|
||||
// var tasks = await service.GetTaskSchedulers();
|
||||
//
|
||||
// foreach (TaskSchedulerDto taskSchedulerDto in tasks)
|
||||
// {
|
||||
// var job = GetJob(taskSchedulerDto.Name);
|
||||
// taskSchedulerDto.LastExecution = job?.LastExecution;
|
||||
// taskSchedulerDto.NextExecution = job?.NextExecution;
|
||||
// }
|
||||
//
|
||||
// return Ok(tasks);
|
||||
// }
|
||||
//
|
||||
// [HttpGet("by-name")]
|
||||
// public async Task<ActionResult<TaskSchedulerDto>> GetTaskSchedulerByTaskName([FromQuery] string name)
|
||||
// {
|
||||
// var taskSchedulerDto = await service.GetTaskSchedulerByTaskName(name);
|
||||
//
|
||||
// if (taskSchedulerDto == null) return NotFound();
|
||||
//
|
||||
// var job = GetJob(taskSchedulerDto.Name);
|
||||
// taskSchedulerDto.LastExecution = job?.LastExecution;
|
||||
// taskSchedulerDto.NextExecution = job?.NextExecution;
|
||||
//
|
||||
// return Ok(taskSchedulerDto);
|
||||
// }
|
||||
//
|
||||
// private RecurringJobDto? GetJob(string jobId)
|
||||
// {
|
||||
// using IStorageConnection? connection = jobStorage.GetConnection();
|
||||
// IList<RecurringJobDto>? recurringJobs = connection.GetRecurringJobs();
|
||||
// return recurringJobs.FirstOrDefault(x => x.Id == jobId);
|
||||
// }
|
||||
//
|
||||
// public void RunConsoleApplication(string pathToApp)
|
||||
// {
|
||||
// try
|
||||
// {
|
||||
// var process = new Process
|
||||
// {
|
||||
// StartInfo = new ProcessStartInfo
|
||||
// {
|
||||
// FileName = pathToApp,
|
||||
// UseShellExecute = false,
|
||||
// RedirectStandardOutput = true,
|
||||
// RedirectStandardError = true,
|
||||
// CreateNoWindow = true,
|
||||
// WorkingDirectory = Path.GetDirectoryName(pathToApp)
|
||||
// }
|
||||
// };
|
||||
// process.Start();
|
||||
// string output = process.StandardOutput.ReadToEnd();
|
||||
// string error = process.StandardError.ReadToEnd();
|
||||
// process.WaitForExit();
|
||||
//
|
||||
// Console.WriteLine($"Output: {output}");
|
||||
// Console.WriteLine($"Error: {error}");
|
||||
// }
|
||||
// catch (Exception ex)
|
||||
// {
|
||||
// Console.WriteLine($"Error executing console application: {ex.Message}");
|
||||
// }
|
||||
// }
|
||||
}
|
||||
16
FaKrosnoApi/Controllers/ItemCustController.cs
Normal file
16
FaKrosnoApi/Controllers/ItemCustController.cs
Normal file
@@ -0,0 +1,16 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using SytelineSaAppEfDataModel.Dtos;
|
||||
using SytelineSaAppEfDataModel.Services;
|
||||
|
||||
namespace FaKrosnoApi.Controllers;
|
||||
|
||||
[ApiController]
|
||||
[Route("api/[controller]")]
|
||||
public class ItemCustController(IItemCustService service) : Controller
|
||||
{
|
||||
public async Task<ActionResult<ItemCustDto>> GetItem([FromQuery] string itemNumber, [FromQuery] string customerNumber)
|
||||
{
|
||||
ItemCustDto item = await service.GetItem(itemNumber, customerNumber);
|
||||
return item != null ? Ok(item) : NotFound();
|
||||
}
|
||||
}
|
||||
@@ -26,4 +26,23 @@ public class WzRowMeyleController(IWzRowMeyleService service) : Controller
|
||||
await service.CreateRows(rows);
|
||||
return CreatedAtAction(nameof(GetAll), new { count = rows.Count() }, rows);
|
||||
}
|
||||
|
||||
[HttpGet("by-wz-header-id")]
|
||||
public async Task<ActionResult<IEnumerable<WzRowMeyleDto>>> GetByWzHeaderId(Guid wzHeaderId)
|
||||
{
|
||||
IEnumerable<WzRowMeyleDto> wzRows = await service.GetByWzHeaderId(wzHeaderId);
|
||||
return Ok(wzRows);
|
||||
}
|
||||
|
||||
[HttpPut]
|
||||
public async Task<ActionResult> UpdateRows([FromBody] IEnumerable<WzRowMeyleDto> rows)
|
||||
{
|
||||
if (rows == null || !rows.Any())
|
||||
{
|
||||
return BadRequest("No rows provided.");
|
||||
}
|
||||
|
||||
await service.UpdateRows(rows);
|
||||
return NoContent();
|
||||
}
|
||||
}
|
||||
@@ -69,19 +69,19 @@ builder.Services.AddOpenApiDocument(config =>
|
||||
config.OperationProcessors.Add(new OperationSecurityScopeProcessor("Bearer"));
|
||||
});
|
||||
|
||||
builder.Services.AddHangfire(config => config
|
||||
.SetDataCompatibilityLevel(CompatibilityLevel.Version_170)
|
||||
.UseSimpleAssemblyNameTypeSerializer()
|
||||
.UseRecommendedSerializerSettings()
|
||||
.UseSqlServerStorage(builder.Configuration.GetConnectionString("OrdersManagementConnection"), new SqlServerStorageOptions
|
||||
{
|
||||
CommandBatchMaxTimeout = TimeSpan.FromMinutes(5),
|
||||
SlidingInvisibilityTimeout = TimeSpan.FromMinutes(5),
|
||||
QueuePollInterval = TimeSpan.Zero,
|
||||
UseRecommendedIsolationLevel = true,
|
||||
DisableGlobalLocks = true
|
||||
}));
|
||||
builder.Services.AddHangfireServer();
|
||||
// builder.Services.AddHangfire(config => config
|
||||
// .SetDataCompatibilityLevel(CompatibilityLevel.Version_170)
|
||||
// .UseSimpleAssemblyNameTypeSerializer()
|
||||
// .UseRecommendedSerializerSettings()
|
||||
// .UseSqlServerStorage(builder.Configuration.GetConnectionString("OrdersManagementConnection"), new SqlServerStorageOptions
|
||||
// {
|
||||
// CommandBatchMaxTimeout = TimeSpan.FromMinutes(5),
|
||||
// SlidingInvisibilityTimeout = TimeSpan.FromMinutes(5),
|
||||
// QueuePollInterval = TimeSpan.Zero,
|
||||
// UseRecommendedIsolationLevel = true,
|
||||
// DisableGlobalLocks = true
|
||||
// }));
|
||||
// builder.Services.AddHangfireServer();
|
||||
|
||||
builder.Services.AddAutoMapper(typeof(FaKrosnoMappingProfile), typeof(SytelineSaAppMappingProfile),
|
||||
typeof(OrdersManagementMappingProfile));
|
||||
@@ -104,6 +104,7 @@ builder.Services.AddScoped<IMaterialTransactionService, MaterialTransactionServi
|
||||
builder.Services.AddScoped<IWzClientService, WzClientService>();
|
||||
builder.Services.AddScoped<IWzHeaderService, WzHeaderService>();
|
||||
builder.Services.AddScoped<IWzRowMeyleService, WzRowMeyleService>();
|
||||
builder.Services.AddScoped<IItemCustService, ItemCustService>();
|
||||
|
||||
builder.Services.AddHostedService<TimedHostedService>();
|
||||
|
||||
@@ -119,6 +120,6 @@ app.UseAuthorization();
|
||||
|
||||
app.MapControllers();
|
||||
|
||||
app.UseHangfireDashboard();
|
||||
// app.UseHangfireDashboard();
|
||||
|
||||
app.Run();
|
||||
|
||||
Reference in New Issue
Block a user