namespace IStation.Application
{
///
/// 陈行输水调度配置
///
[AllowAnonymous]
[Route("OpenApi/Dispatch/Config")]
[ApiDescriptionSettings("Schedule", Name = "调度配置", Order = 1)]
public class ScheduleConfig_Controller : IDynamicApiController, ITransient
{
private readonly Service.Station _service_station = new();
private readonly Service.ScheduleConfig _service_schedule_config = new();
///
/// 获取配置
///
[Route("Get")]
[HttpGet]
[NonUnify]
public ChScheduleConfigDto Get()
{
var request_id = Yw.YitIdHelper.NextId();
var log_title = "调度配置";
Log.Info(request_id, log_title, "获取!");
var schedule_config = _service_schedule_config.Get();
if (schedule_config == null)
{
Log.Info(request_id, log_title, "获取:ScheduleConfig文件缺失!");
return default;
}
var dto = schedule_config.Adapt();
return dto;
}
///
/// 更新配置
///
[Route("Update")]
[HttpGet]
[NonUnify]
public SaveChScheduleConfigOutput Update()
{
var update_id = Yw.YitIdHelper.NextId();
var log_title = "调度配置";
Log.Info(update_id, log_title, "更新!");
try
{
var schedule_config = _service_schedule_config.Get();
if (schedule_config == null)
{
Log.Info(update_id, log_title, "更新失败:ScheduleConfig文件缺失!");
return new SaveChScheduleConfigOutput() { Result = false, Msg = "ScheduleConfig文件缺失!" };
}
var msg = GlobalHelper.GetFlagCumulativeRuntimeDict(out Dictionary station1_flag_cumulative_run_time_dict, out Dictionary station2_flag_cumulative_run_time_dict, 35);
if (!string.IsNullOrEmpty(msg))
{
Log.Info(update_id, log_title, $"更新失败:{msg}");
return new SaveChScheduleConfigOutput() { Result = false, Msg = $"更新失败:{msg}" };
}
schedule_config.Station1.FlagCumulativeRuntimeDict = station1_flag_cumulative_run_time_dict;
schedule_config.Station2.FlagCumulativeRuntimeDict = station2_flag_cumulative_run_time_dict;
var bol = _service_schedule_config.Save(schedule_config);
if (!bol)
{
Log.Info(update_id, log_title, $"更新失败:Save()");
return new SaveChScheduleConfigOutput() { Result = false, Msg = "更新失败:Save()" };
}
Log.Info(update_id, log_title, $"更新成功!");
Log.Debug(update_id, log_title, JsonHelper.Object2Json(schedule_config));
}
catch (Exception ex)
{
Log.Error(update_id, log_title, "更新失败!", ex);
return new SaveChScheduleConfigOutput() { Result = false, Msg = ex.Message };
}
return new SaveChScheduleConfigOutput() { Result = true, Msg = "更新成功!" };
}
///
/// 保存配置
///
[AllowAnonymous]
[Route("Save")]
[HttpPost]
[NonUnify]
public SaveChScheduleConfigOutput Save([Required] ChScheduleConfigInput input)
{
if (input == null)
{
return new SaveChScheduleConfigOutput() { Result = false, Msg = "入参不能为空!" };
}
var request_id = Yw.YitIdHelper.NextId();
var log_title = "调度配置";
Log.Info(request_id, log_title, "保存!");
Log.Debug(request_id, log_title, JsonHelper.Object2Json(input));
var schedule_config = input.Adapt();
var bol = _service_schedule_config.Save(schedule_config);
if (!bol)
{
Log.Info(request_id, log_title, $"保存失败:Save()");
return new SaveChScheduleConfigOutput() { Result = false, Msg = "保存失败:Save()" };
}
Log.Info(request_id, log_title, $"保存成功!");
return new SaveChScheduleConfigOutput() { Result = true, Msg = "保存成功!" };
}
}
}