namespace IStation.Application
|
{
|
/// <summary>
|
/// 调度
|
/// </summary>
|
[Route("ChenHang/Dispatch")]
|
[ApiDescriptionSettings("Web", Name = "优化调度", Order = 3)]
|
public class OptimalSchedule_Controller : IDynamicApiController
|
{
|
private readonly Service.ScheduleRequest _service_schedule_request = new();
|
private readonly Service.ScheduleConclusion _service_schedule_conclusion = new();
|
private readonly Service.SchedulePump _service_schedule_pump = new();
|
|
/// <summary>
|
///获取泵站列表
|
/// </summary>
|
[Route("GetStationList@V1.0")]
|
[HttpGet]
|
public List<StationTreeItemOutput> GetStationList()
|
{
|
var station1 = new StationTreeItemOutput()
|
{
|
ID = 1,
|
Name = "陈行1输",
|
SortCode = 1
|
};
|
|
var station2 = new StationTreeItemOutput()
|
{
|
ID = 2,
|
Name = "陈行2输",
|
SortCode = 2
|
};
|
return new List<StationTreeItemOutput>() { station1, station2 };
|
}
|
|
/// <summary>
|
/// 调度
|
/// </summary>
|
[AllowAnonymous]
|
[Route("Calculate@V1.0")]
|
[HttpPost]
|
public OptScheduleOutput Calculate([Required] OptScheduleStationInput input)
|
{
|
var stationId = input.StationID;
|
var e_station = stationId == 1 ? IStation.eDockingStation.Ch1s : IStation.eDockingStation.Ch2s;
|
var receipt_time = DateTime.Now;
|
var request_id = Yw.YitIdHelper.NextId();
|
var log_title = string.Empty;
|
|
var station = new Service.Station().Get();
|
|
|
var water_level = input.WaterLevel;
|
var target_flow = input.TargetFlow;
|
var target_pressure = input.TargetPressure;
|
var target_head = Curve.PumpCalculateHelper.Mpa2M(target_pressure) - water_level;
|
|
log_title = "需水请求";
|
Log.Info(request_id, log_title, $"water_level:{water_level},target_flow:{target_flow},target_pressure:{target_pressure},target_head:{target_head}");
|
Log.Debug(request_id, log_title, JsonHelper.Object2Json(input));
|
|
List<Model.Pump> pumps = null;
|
List<int> flags_part1 = null, flags_part2 = null, current_open_pump_flags = null;
|
|
if (e_station == IStation.eDockingStation.Ch1s)
|
{
|
pumps = station.S1;
|
flags_part1 = station.S1FlagsPart1;
|
flags_part2 = station.S1FlagsPart2;
|
}
|
else
|
{
|
pumps = station.S2;
|
flags_part1 = station.S2FlagsPart1;
|
flags_part2 = station.S2FlagsPart2;
|
}
|
|
var helper = new IStation.Algorithm.ScheduleHelper();
|
var optimal_combine = helper.Calc(pumps, flags_part1, flags_part2, target_flow, target_head);
|
|
var schedule_request = new Model.ScheduleRequest();
|
schedule_request.ID = request_id;
|
if (stationId == 1)
|
{
|
schedule_request.WaterLevel1 = water_level;
|
schedule_request.TargetFlow1 = target_flow;
|
schedule_request.TargetPressure1 = target_pressure;
|
schedule_request.ScheduleStatus1 = optimal_combine != null;
|
}
|
else
|
{
|
schedule_request.WaterLevel2 = water_level;
|
schedule_request.TargetFlow2 = target_flow;
|
schedule_request.TargetPressure2 = target_pressure;
|
schedule_request.ScheduleStatus2 = optimal_combine != null;
|
}
|
|
schedule_request.TotalTimeSpent = (DateTime.Now - receipt_time).TotalSeconds;
|
schedule_request.ReceptionTime = receipt_time;
|
|
Model.ScheduleConclusion schedule_solution = null;
|
List<Model.SchedulePump> schedule_pump_list = null;
|
OptScheduleOutput output = null;
|
|
var msg = "计算成功";
|
log_title = "调度返回";
|
if (optimal_combine == null)
|
{
|
Log.Info(request_id, log_title, $"{stationId}:调度计算失败,无法满足目标流量:{target_flow},目标压力:{target_pressure}!");
|
Yw.Dto.YOops.Oh(Yw.Dto.eResultCode.Error, Yw.Dto.InternalErrorCodes.A001, $"{stationId}:调度计算失败,无法满足目标流量:{target_flow},目标压力:{target_pressure}!");
|
}
|
else
|
{
|
|
schedule_solution = new Model.ScheduleConclusion();
|
schedule_solution.ID = Yw.YitIdHelper.NextId();
|
schedule_solution.RequestID = request_id;
|
schedule_solution.Station = e_station;
|
schedule_solution.TotalFlow = optimal_combine.Flow;
|
schedule_solution.TotalHead = optimal_combine.Head;
|
schedule_solution.TotalPower = optimal_combine.Power;
|
schedule_solution.TotalEfficiency = optimal_combine.Efficiency;
|
schedule_solution.WP = optimal_combine.WP;
|
schedule_solution.UWP = optimal_combine.UWP;
|
schedule_solution.Flags = IntListHelper.ToString(optimal_combine.Flags);
|
schedule_solution.MeritRatio = optimal_combine.MeritRatio;
|
schedule_pump_list = new List<Model.SchedulePump>();
|
|
output = new OptScheduleOutput();
|
output.Station = new OptScheduleStationOutput();
|
output.Station.TotalFlow = optimal_combine.Flow;
|
output.Station.TotalPressure = Math.Round(Curve.PumpCalculateHelper.M2Mpa(optimal_combine.Head), 4);
|
output.Station.TotalPower = optimal_combine.Power;
|
output.Station.TotalEfficiency = optimal_combine.Efficiency;
|
output.Station.WP = optimal_combine.WP;
|
output.Station.UWP = optimal_combine.UWP;
|
output.Pumps = new List<OptSchedulePumpOutput>();
|
|
|
foreach (var combine in optimal_combine.Combines)
|
{
|
foreach (var fre_pump in combine.FrePumps)
|
{
|
var flag = fre_pump.Flag;
|
var chPump = new OptSchedulePumpOutput();
|
chPump.ID = flag;
|
chPump.Name = flag + "#";
|
chPump.Flow = fre_pump.Flow;
|
chPump.Head = fre_pump.Head;
|
chPump.Power = fre_pump.Power;
|
chPump.Efficiency = fre_pump.Efficiency;
|
chPump.Frequency = fre_pump.Frequency;
|
chPump.Speed = fre_pump.Speed;
|
chPump.Status = 1;
|
output.Pumps.Add(chPump);
|
|
var schedule_pump = new Model.SchedulePump();
|
schedule_pump.RequestID = request_id;
|
schedule_pump.Station = e_station;
|
schedule_pump.Flag = flag;
|
schedule_pump.Flow = fre_pump.Flow;
|
schedule_pump.Head = fre_pump.Head;
|
schedule_pump.Power = fre_pump.Power;
|
schedule_pump.Efficiency = fre_pump.Efficiency;
|
schedule_pump.Frequency = fre_pump.Frequency;
|
schedule_pump.Speed = fre_pump.Speed;
|
schedule_pump_list.Add(schedule_pump);
|
}
|
}
|
}
|
|
|
Log.Info(request_id, log_title, msg);
|
try
|
{
|
log_title = "存储方案";
|
var bol = false;
|
bol = _service_schedule_request.Insert(schedule_request) > 0;
|
if (!bol)
|
{
|
Log.Info(request_id, log_title, "schedule_request 插入异常");
|
Log.Debug(request_id, log_title, JsonHelper.Object2Json(schedule_request));
|
}
|
|
if (schedule_solution != null)
|
{
|
bol = _service_schedule_conclusion.Insert(schedule_solution) > 0;
|
if (!bol)
|
{
|
Log.Info(request_id, log_title, "schedule_solution 插入异常");
|
Log.Debug(request_id, log_title, JsonHelper.Object2Json(schedule_solution));
|
}
|
}
|
|
|
if (schedule_pump_list != null)
|
{
|
bol = _service_schedule_pump.Inserts(schedule_pump_list);
|
if (!bol)
|
{
|
Log.Info(request_id, log_title, "schedule_pump_list 插入异常");
|
Log.Debug(request_id, log_title, JsonHelper.Object2Json(schedule_pump_list));
|
}
|
}
|
}
|
catch (Exception ex)
|
{
|
Log.Error(request_id, log_title, "数据库异常!", ex);
|
}
|
return output;
|
}
|
|
|
|
}
|
}
|