Changed path and Changed seconds to Alpha
This commit is contained in:
@ -1,6 +1,5 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using OI.Metrology.Shared.Models.Stateless;
|
||||
using System.Globalization;
|
||||
using System.Text.Json;
|
||||
|
||||
namespace OI.Metrology.Server.ApiControllers;
|
||||
@ -19,35 +18,7 @@ public class ReactorsController : Controller, IReactorsController<IActionResult>
|
||||
Json(even ? _ReactorsRepository.EvenReactors() : _ReactorsRepository.OddReactors(), new JsonSerializerOptions { PropertyNamingPolicy = null, WriteIndented = true });
|
||||
|
||||
[HttpPost()]
|
||||
public IActionResult Post(Shared.DataModels.WorkMaterialOut workMaterialOut)
|
||||
{
|
||||
string? result = null;
|
||||
if (workMaterialOut is null)
|
||||
throw new Exception();
|
||||
if (workMaterialOut.Username is null || workMaterialOut.Username.Length < 2)
|
||||
throw new ArgumentException(nameof(workMaterialOut.Username));
|
||||
if (workMaterialOut.RunDataSheet is null || workMaterialOut.RunDataSheet.Length < 2)
|
||||
throw new ArgumentException(nameof(workMaterialOut.RunDataSheet));
|
||||
string? fileName = null;
|
||||
DateTime dateTime = DateTime.Now;
|
||||
Calendar calendar = new CultureInfo("en-US").Calendar;
|
||||
string json = JsonSerializer.Serialize(workMaterialOut, new JsonSerializerOptions { WriteIndented = true });
|
||||
string weekOfYear = $"{dateTime:yyyy}_Week_{calendar.GetWeekOfYear(dateTime, CalendarWeekRule.FirstDay, DayOfWeek.Sunday):00}";
|
||||
string directory = Path.Combine("D:/Tmp/Metrology", weekOfYear, dateTime.ToString("yyyy-MM-dd"));
|
||||
if (!Directory.Exists(directory))
|
||||
_ = Directory.CreateDirectory(directory);
|
||||
for (int i = 1; i < int.MaxValue; i++)
|
||||
{
|
||||
result = $"{workMaterialOut.Username.ToUpper()[0]}{dateTime:mmss}";
|
||||
fileName = Path.Combine(directory, $"WMO-{result}.json");
|
||||
if (!System.IO.File.Exists(fileName))
|
||||
break;
|
||||
dateTime = dateTime.AddSeconds(i);
|
||||
}
|
||||
if (fileName is null)
|
||||
throw new Exception();
|
||||
System.IO.File.WriteAllText(fileName, json);
|
||||
return Ok(result);
|
||||
}
|
||||
public IActionResult Post(Shared.DataModels.WorkMaterialOut workMaterialOut) =>
|
||||
Ok(_ReactorsRepository.GetKey(workMaterialOut, save: true));
|
||||
|
||||
}
|
Reference in New Issue
Block a user