using Quartz;
|
|
namespace IStation.Server
|
{
|
/// <summary>
|
/// 调度验证辅助类
|
/// </summary>
|
[DisallowConcurrentExecution]//此特性标识 必须等待这次任务执行完成后,才能执行下次任务
|
public class ScheduleValidationHelperJob : IJob
|
{
|
private static readonly Service.ScheduleRequest _service_schedule_request = new();
|
private static readonly Service.ScheduleScada _service_schedule_scada = new();
|
private static readonly Service.ScheduleRule _service_schedule_rule = new();
|
private static readonly Service.ScheduleConclusion _service_schedule_conclusion = new();
|
private static readonly Service.SchedulePump _service_schedule_pump = new();
|
|
private static readonly Service.Station _service_station = new();
|
private static readonly Service.ScheduleConfig _service_schedule_config = new();
|
|
|
public Task Execute(IJobExecutionContext context)
|
{
|
return Task.Run(() =>
|
{
|
var resuest_id = Yw.YitIdHelper.NextId();
|
var resuest_time = DateTime.Now;
|
|
try
|
{
|
var station_info = _service_station.Get();
|
if (station_info == null)
|
{
|
Log.Info(resuest_id, "调度验证计划任务中,Station文件缺失!");
|
return;
|
}
|
|
|
GlobalHelper.GetRealTimeZyScadaList(out List<Model.ZyScada> zy_scada_list);
|
if (zy_scada_list == null || !zy_scada_list.Any())
|
{
|
Log.Info(resuest_id, "调度验证计划任务中,接收Scada数据为空,自动跳过当前数据!");
|
return;
|
}
|
|
Log.Debug(resuest_id, Yw.JsonHelper.Object2Json(zy_scada_list));
|
|
var zy_scada_jd1_flow = zy_scada_list.Find(x => x.Code == GlobalHelper.嘉定1线_瞬时流量_长江管网图)?.Value ?? 0;
|
var zy_scada_jd2_flow = zy_scada_list.Find(x => x.Code == GlobalHelper.嘉定2线_瞬时流量_长江管网图)?.Value ?? 0;
|
var zy_scada_jd3_flow = zy_scada_list.Find(x => x.Code == GlobalHelper.嘉定3线_瞬时流量_长江管网图)?.Value ?? 0;
|
|
var zy_scada_jd1_pressure = zy_scada_list.Find(x => x.Code == GlobalHelper.嘉定1线_压力_长江管网图)?.Value ?? 0;
|
var zy_scada_jd2_pressure = zy_scada_list.Find(x => x.Code == GlobalHelper.嘉定2线_压力_长江管网图)?.Value ?? 0;
|
var zy_scada_jd3_pressure = zy_scada_list.Find(x => x.Code == GlobalHelper.嘉定3线_压力_长江管网图)?.Value ?? 0;
|
|
var zy_scada_dn2400_flow = zy_scada_list.Find(x => x.Code == GlobalHelper.DN2400总管_瞬时流量_长江管网图)?.Value ?? 0;
|
var zy_scada_dn2700_flow = zy_scada_list.Find(x => x.Code == GlobalHelper.DN2700总管_瞬时流量_长江管网图)?.Value ?? 0;
|
|
var zy_scada_dn2400_pressure = zy_scada_list.Find(x => x.Code == GlobalHelper.DN2400_出厂压力_长江管网图)?.Value ?? 0;
|
var zy_scada_dn2700_pressure = zy_scada_list.Find(x => x.Code == GlobalHelper.DN2700_出厂压力_长江管网图)?.Value ?? 0;
|
|
|
var pressure_list1 = new List<double?>() { zy_scada_jd1_pressure, zy_scada_jd2_pressure, zy_scada_jd3_pressure };
|
var pressure_list2 = new List<double?>() { zy_scada_dn2400_pressure, zy_scada_dn2700_pressure };
|
|
var target_flow1 = zy_scada_jd1_flow + zy_scada_jd2_flow + zy_scada_jd3_flow;
|
var target_pressure1 = (pressure_list1.Max() ?? 0) / 1000;
|
|
var target_flow2 = zy_scada_dn2400_flow + zy_scada_dn2700_flow;
|
var target_pressure2 = pressure_list2.Max() ?? 0;
|
Log.Info(resuest_id, $"target_flow1:{target_flow1},target_pressure1:{target_pressure1},target_flow2:{target_flow2},target_pressure2:{target_pressure2}");
|
|
|
var target_head1 = Curve.PumpCalculateHelper.Mpa2M(target_pressure1);
|
var target_head2 = Curve.PumpCalculateHelper.Mpa2M(target_pressure2);
|
|
|
var station1 = station_info.Station1;
|
var station2 = station_info.Station2;
|
var station1_same_type_flag_group_first = GlobalHelper.Station1SameTypeFlagGroupFirst;
|
var station2_same_type_flag_group_first = GlobalHelper.Station2SameTypeFlagGroupFirst;
|
var station1_schedule_config = _service_schedule_config.GetStation1();
|
var station2_schedule_config = _service_schedule_config.GetStation2();
|
var station1_flag_list = GlobalHelper.Station1FlagList;
|
var station2_flag_list = GlobalHelper.Station2FlagList;
|
|
GlobalHelper.GetStationOpenFlagList(zy_scada_list, out List<int> station1_open_flag_list, out List<int> station2_open_flag_list);
|
GlobalHelper.GetStationMaintenanceFlagList(zy_scada_list, out List<int> station1_maintenance_flag_list, out List<int> station2_maintenance_flag_list);
|
GlobalHelper.GetFlagInletWaterLevelDict(zy_scada_list, out Dictionary<int, double> station1_flag_inlet_water_level_dict, out Dictionary<int, double> station2_flag_inlet_water_level_dict);
|
|
if (station1_maintenance_flag_list != null && station1_maintenance_flag_list.Any())
|
{
|
Log.Info(resuest_id, $"调度验证计划任务中,1输水:{Yw.Untity.IntListHelper.ToString(station1_maintenance_flag_list)}");
|
station1_schedule_config.MustCloseFlagList.AddRange(station1_maintenance_flag_list);
|
}
|
|
if (station2_maintenance_flag_list != null && station2_maintenance_flag_list.Any())
|
{
|
Log.Info(resuest_id, $"调度验证计划任务中,2输水:{Yw.Untity.IntListHelper.ToString(station2_maintenance_flag_list)}");
|
station2_schedule_config.MustCloseFlagList.AddRange(station2_maintenance_flag_list);
|
}
|
|
var msg = "调度验证计划任务中,计算结束!";
|
var helper = new Algorithm.ScheduleHelper();
|
|
helper.Initial(station1_open_flag_list, station1_schedule_config);
|
var optimal_combine1 = helper.GetOptAnaCombine(station1, station1_same_type_flag_group_first, station1_flag_inlet_water_level_dict, target_flow1, target_head1);
|
|
|
helper.Initial(station2_open_flag_list, station2_schedule_config);
|
var optimal_combine2 = helper.GetOptAnaCombine(station2, station2_same_type_flag_group_first, station2_flag_inlet_water_level_dict, target_flow2, target_head2);
|
|
var schedule_request = new Model.ScheduleRequest
|
{
|
ID = resuest_id,
|
TargetFlow1 = target_flow1,
|
TargetPressure1 = target_pressure1,
|
TargetFlow2 = target_flow2,
|
TargetPressure2 = target_pressure2,
|
ScheduleStatus1 = optimal_combine1 != null,
|
ScheduleStatus2 = optimal_combine2 != null,
|
TotalTimeSpent = (DateTime.Now - resuest_time).TotalSeconds,
|
ReceptionTime = resuest_time
|
};
|
|
Model.ScheduleConclusion schedule_conclusion1 = null;
|
Model.ScheduleConclusion schedule_conclusion2 = null;
|
List<Model.SchedulePump> schedule_pump_list1 = null;
|
List<Model.SchedulePump> schedule_pump_list2 = null;
|
|
if (optimal_combine1 == null && optimal_combine2 == null)
|
{
|
Log.Info(resuest_id, "调度验证计划任务中,厂内调度方案无法计算!");
|
}
|
else
|
{
|
if (optimal_combine1 != null)
|
{
|
optimal_combine1.Round();
|
schedule_conclusion1 = new Model.ScheduleConclusion
|
{
|
ID = Yw.YitIdHelper.NextId(),
|
RequestID = resuest_id,
|
Station = IStation.eDockingStation.Ch1s,
|
TotalFlow = optimal_combine1.TotalFlow,
|
TotalHead = optimal_combine1.TotalHead,
|
TotalPower = optimal_combine1.TotalPower,
|
TotalEfficiency = optimal_combine1.TotalEfficiency,
|
WP = optimal_combine1.WP,
|
UWP = optimal_combine1.UWP,
|
Flags = Yw.Untity.IntListHelper.ToString(optimal_combine1.Flags),
|
MeritRatio = optimal_combine1.MeritRatio
|
};
|
schedule_pump_list1 = new List<Model.SchedulePump>();
|
foreach (var fre_pump in optimal_combine1.AnaFrePumps)
|
{
|
var schedule_pump = new Model.SchedulePump
|
{
|
RequestID = resuest_id,
|
Station = IStation.eDockingStation.Ch1s,
|
Flag = fre_pump.Flag,
|
Flow = fre_pump.Flow,
|
Head = fre_pump.Head,
|
Power = fre_pump.Power,
|
Efficiency = fre_pump.Efficiency,
|
Frequency = fre_pump.Frequency,
|
Speed = fre_pump.Speed
|
};
|
schedule_pump_list1.Add(schedule_pump);
|
|
}
|
|
}
|
else
|
{
|
msg += $" 1输水调度计算失败,无法满足目标流量:{target_flow1},目标压力:{target_pressure1}!";
|
}
|
|
if (optimal_combine2 != null)
|
{
|
optimal_combine2.Round();
|
schedule_conclusion2 = new Model.ScheduleConclusion
|
{
|
ID = Yw.YitIdHelper.NextId(),
|
RequestID = resuest_id,
|
Station = IStation.eDockingStation.Ch2s,
|
TotalFlow = optimal_combine2.TotalFlow,
|
TotalHead = optimal_combine2.TotalHead,
|
TotalPower = optimal_combine2.TotalPower,
|
TotalEfficiency = optimal_combine2.TotalEfficiency,
|
WP = optimal_combine2.WP,
|
UWP = optimal_combine2.UWP,
|
Flags = Yw.Untity.IntListHelper.ToString(optimal_combine2.Flags),
|
MeritRatio = optimal_combine2.MeritRatio
|
};
|
schedule_pump_list2 = new List<Model.SchedulePump>();
|
|
foreach (var fre_pump in optimal_combine2.AnaFrePumps)
|
{
|
|
var flag = fre_pump.Flag;
|
var schedule_pump = new Model.SchedulePump
|
{
|
RequestID = resuest_id,
|
Station = IStation.eDockingStation.Ch2s,
|
Flag = flag,
|
Flow = fre_pump.Flow,
|
Head = fre_pump.Head,
|
Power = fre_pump.Power,
|
Efficiency = fre_pump.Efficiency,
|
Frequency = fre_pump.Frequency,
|
Speed = fre_pump.Speed
|
};
|
schedule_pump_list2.Add(schedule_pump);
|
}
|
|
}
|
else
|
{
|
msg += $" 2输水调度计算失败,无法满足目标流量:{target_flow2},目标压力:{target_pressure2}!";
|
}
|
}
|
|
Log.Info(resuest_id, msg);
|
|
var bol = false;
|
bol = _service_schedule_request.Insert(schedule_request) > 0;
|
if (!bol)
|
{
|
Log.Info(resuest_id, "调度验证计划任务中,schedule_request 插入异常");
|
Log.Debug(resuest_id, Yw.JsonHelper.Object2Json(schedule_request));
|
}
|
|
if (station1_schedule_config != null)
|
{
|
var schedule_rule1 = new Model.ScheduleRule
|
{
|
RequestID = resuest_id,
|
Station = eDockingStation.Ch1s,
|
Config = Yw.JsonHelper.Object2Json(station1_schedule_config)
|
};
|
bol = _service_schedule_rule.Insert(schedule_rule1) > 0;
|
if (!bol)
|
{
|
Log.Info(resuest_id, "调度验证计划任务中,schedule_config1 插入异常");
|
Log.Debug(resuest_id, Yw.JsonHelper.Object2Json(schedule_rule1));
|
}
|
}
|
|
if (station2_schedule_config != null)
|
{
|
var schedule_rule2 = new Model.ScheduleRule
|
{
|
RequestID = resuest_id,
|
Station = eDockingStation.Ch2s,
|
Config = Yw.JsonHelper.Object2Json(station2_schedule_config)
|
};
|
bol = _service_schedule_rule.Insert(schedule_rule2) > 0;
|
if (!bol)
|
{
|
Log.Info(resuest_id, "调度验证计划任务中,schedule_config2 插入异常");
|
Log.Debug(resuest_id, Yw.JsonHelper.Object2Json(schedule_rule2));
|
}
|
}
|
|
if (zy_scada_list != null && zy_scada_list.Any())
|
{
|
var scada_list = zy_scada_list
|
.OrderBy(x => x.Code)
|
.Select(x => new Model.ScheduleScada()
|
{
|
RequestID = resuest_id,
|
Time = x.Time,
|
Code = x.Code,
|
Tag = x.Tag,
|
Value = x.Value,
|
|
}).ToList();
|
bol = _service_schedule_scada.Inserts(scada_list);
|
if (!bol)
|
{
|
Log.Info(resuest_id, "调度验证计划任务中,scada_list 插入异常");
|
Log.Debug(resuest_id, Yw.JsonHelper.Object2Json(scada_list));
|
}
|
}
|
if (schedule_conclusion1 != null)
|
{
|
bol = _service_schedule_conclusion.Insert(schedule_conclusion1) > 0;
|
if (!bol)
|
{
|
Log.Info(resuest_id, "调度验证计划任务中,schedule_conclusion1 插入异常");
|
Log.Debug(resuest_id, Yw.JsonHelper.Object2Json(schedule_conclusion1));
|
}
|
}
|
if (schedule_conclusion2 != null)
|
{
|
bol = _service_schedule_conclusion.Insert(schedule_conclusion2) > 0;
|
if (!bol)
|
{
|
Log.Info(resuest_id, "调度验证计划任务中,schedule_conclusion2 插入异常");
|
Log.Debug(resuest_id, Yw.JsonHelper.Object2Json(schedule_conclusion2));
|
}
|
}
|
|
if (schedule_pump_list1 != null)
|
{
|
bol = _service_schedule_pump.Inserts(schedule_pump_list1);
|
if (!bol)
|
{
|
Log.Info(resuest_id, "调度验证计划任务中,schedule_pump_list1 插入异常");
|
Log.Debug(resuest_id, Yw.JsonHelper.Object2Json(schedule_pump_list1));
|
}
|
}
|
|
if (schedule_pump_list2 != null)
|
{
|
bol = _service_schedule_pump.Inserts(schedule_pump_list2);
|
if (!bol)
|
{
|
Log.Info(resuest_id, "调度验证计划任务中,schedule_pump_list2 插入异常");
|
Log.Debug(resuest_id, Yw.JsonHelper.Object2Json(schedule_pump_list2));
|
}
|
}
|
|
Log.Info(resuest_id, $"调度验证计划任务中,调度验证,[{resuest_time:G}]验证成功!");
|
|
}
|
catch (Exception ex)
|
{
|
Log.Error(resuest_id, "调度验证计划任务中,出错", ex);
|
var e = new JobExecutionException(ex);
|
throw e;
|
}
|
|
});
|
}
|
|
|
|
}
|
}
|