From dc8b37ca6e4e7188b9f3338340e0acd918d06014 Mon Sep 17 00:00:00 2001 From: xingheng Date: Sun, 28 Sep 2025 10:43:45 +0800 Subject: [PATCH] TEMP --- .../AppApi/IOModuleApiController.cs | 109 ++++++++++-------- 1 file changed, 62 insertions(+), 47 deletions(-) diff --git a/Learun.Application.Web/AppApi/IOModuleApiController.cs b/Learun.Application.Web/AppApi/IOModuleApiController.cs index 7d3e611a..a0b332ad 100644 --- a/Learun.Application.Web/AppApi/IOModuleApiController.cs +++ b/Learun.Application.Web/AppApi/IOModuleApiController.cs @@ -53,6 +53,9 @@ namespace Learun.Application.Web.AppApi /// private ec_PanelStripEntity CreatePanelStripByProfile2(string projId, string TSname, string panelId, GlobalEnum.IOType iOType) { + var setTb = ProjectSugar.TableName(projId); + var allSettings = SqlSugarHelper.Db.Queryable().AS(setTb).ToList(); + //IO_CardProfile return new ec_PanelStripEntity(); } /// @@ -525,7 +528,16 @@ namespace Learun.Application.Web.AppApi var signalTb = ProjectSugar.TableName(projId); var allSignals = SqlSugarHelper.Db.Queryable().AS(signalTb).ToList(); + + var connTb = ProjectSugar.TableName(projId); + var termTb = ProjectSugar.TableName(projId); + var allConnedTerms = SqlSugarHelper.Db.Queryable().AS(connTb) + .InnerJoin((a, b) => a.TermID == b.TermID).AS(termTb) + .Select((a, b) => b.ChannelID).Distinct().ToList(); + + var allUsedCH = allSignals.Where(x => !string.IsNullOrEmpty(x.ChannelID)).Select(x => x.ChannelID).Distinct().ToList(); + allUsedCH.AddRange(allConnedTerms); //??这里有问题。通道是否被占用,需要看signal和set双重(在io分配界面) //1. 信号有, 电缆set有,占了 //2.信号no,电缆set有,占了 @@ -588,7 +600,11 @@ namespace Learun.Application.Web.AppApi #endregion #region inputNew - var resIn = AutoAssignCore(GlobalEnum.inOrOut.输入, setsIn, setsSpared); + if (setsIn.Count > 0) + { + var resIn = AutoAssignCore(GlobalEnum.inOrOut.输入, setsIn, setsSpared); + } + #endregion #region input //ec_PanelStripEntity curStrip = null; @@ -724,23 +740,19 @@ namespace Learun.Application.Web.AppApi //} #endregion #region output - var resOut = AutoAssignCore(GlobalEnum.inOrOut.输出, setsOut, setsSpared); + if (setsOut.Count > 0) + { + var resOut = AutoAssignCore(GlobalEnum.inOrOut.输出, setsOut, setsSpared); + + } - #endregion + #endregion //in 和 out都会执行这个 bool AutoAssignCore(GlobalEnum.inOrOut inOrOut, List sets, List sets_Spared) { GlobalEnum.IOType ioTypeOnC = default; - ec_PanelStripEntity curStrip = null; - var matchedStrips = curStrips.Where(x => x.IO_TYPE == ioTypeOnC.ToString()).ToList(); - if (matchedStrips != null && lastUsedStrip != null && lastUsedStrip.IO_TYPE == ioTypeOnC.ToString()) - { - //1.2.2 优先使用上一个模块,直到模块满了再用下一个模块。 - matchedStrips.Insert(0, lastUsedStrip); - } - string PanelName = cable.AssignedPanel.TagNumber;//当前电缆预分配的箱子名称 switch (cable.PreAssignIOType.ToLower()) { case "digital": @@ -779,23 +791,22 @@ namespace Learun.Application.Web.AppApi //通讯类 485 422啥的 return false; } + + ec_PanelStripEntity curStrip = null; + var matchedStrips = curStrips.Where(x => x.IO_TYPE == ioTypeOnC.ToString()).ToList(); + if (matchedStrips != null && lastUsedStrip != null && lastUsedStrip.IO_TYPE == ioTypeOnC.ToString()) + { + //1.2.2 优先使用上一个模块,直到模块满了再用下一个模块。 + matchedStrips.Insert(0, lastUsedStrip); + } + string PanelName = cable.AssignedPanel.TagNumber;//当前电缆预分配的箱子名称 if (sets.Count == 0) { //相当于没有 } - //else if (sets.Count + setsSpared.Count() > 10) - //{ - - - //} else { var totalSets = sets.Count + setsSpared.Count(); - //另外如果电缆对数大于10对,即像12*2*0.75这种,无论它预分配了多少根电缆对,永远预留4个以下的空白通道。 - //意思就是一个模块里面够4个或4个以上空白通道就留4个空白通道, - //如果不够4个就留4个以下即可。 - - //1.2 流程图 箱子里是否已经存在端子排(io匹配) bool alreadyInsertNewTs = false; @@ -822,7 +833,7 @@ namespace Learun.Application.Web.AppApi { //1.2.3 (1) 非通讯,如果空的通道大于整个模块的5%,则可以利用,利用到小于5%了则停止利用,如果本身空通道数占的比例就小于5%,则不利用。 - curStrip = FindNextAvailableTS(matchedStrips, allUsedCH); + curStrip = FindNextAvailableTS(cable.Sets.Count,totalSets, matchedStrips, allUsedCH); if (curStrip == null) { @@ -846,7 +857,7 @@ namespace Learun.Application.Web.AppApi return false; } else - { + { //相当于前面5%的判断过了,但是呢放不下所有需要的set var newTS = CreatePanelStripByProfile2(projId, "TS_" + ioTypeOnC.ToString() + "_" + newTSSeq++, curPanelId, ioTypeOnC); alreadyInsertNewTs = true; @@ -862,31 +873,23 @@ namespace Learun.Application.Web.AppApi } } lastUsedStrip = curStrip; - //能放下 - if (cable.Sets.Count > 10) + + for (int i = 0; i < sets.Count; i++) { - //另外如果电缆对数大于10对,即像12*2*0.75这种,无论它预分配了多少根电缆对,永远预留4个以下的空白通道。意思就是一个模块里面够4个或4个以上空白通道就留4个空白通道,如果不够4个就留4个以下即可 - + var set = sets[i]; + var ch = notUsedChs[i]; + set.ConnectionInfo = $"采集箱:{PanelName}/模块(端子排):{curStrip.StripName}/通道:{ch.ChannelName}"; + //更新全局已使用通道 + allUsedCH.Add(ch.ChannelID); } - else + var chOffIdx = sets.Count; + for (int i = 0; i < setsSpared.Count(); i++) { - for (int i = 0; i < sets.Count; i++) - { - var set = sets[i]; - var ch = notUsedChs[i]; - set.ConnectionInfo = $"采集箱:{PanelName}/模块(端子排):{curStrip.StripName}/通道:{ch.ChannelName}"; - //更新全局已使用通道 - allUsedCH.Add(ch.ChannelID); - } - var chOffIdx = sets.Count; - for (int i = 0; i < setsSpared.Count(); i++) - { - var set = setsSpared[i]; - var ch = notUsedChs[chOffIdx + i]; - set.ConnectionInfo = $"采集箱:{PanelName}/模块(端子排):{curStrip.StripName}/通道:{ch.ChannelName}/冗余"; - //更新全局已使用通道 - allUsedCH.Add(ch.ChannelID); - } + var set = setsSpared[i]; + var ch = notUsedChs[chOffIdx + i]; + set.ConnectionInfo = $"采集箱:{PanelName}/模块(端子排):{curStrip.StripName}/通道:{ch.ChannelName}/冗余"; + //更新全局已使用通道 + allUsedCH.Add(ch.ChannelID); } #endregion @@ -908,10 +911,11 @@ namespace Learun.Application.Web.AppApi /// /// 找到下一个可用的端子排 /// + /// 电缆总set /// 所有的端子排 /// 使用过的channelId /// - private ec_PanelStripEntity FindNextAvailableTS(List TSs, List allUsedCH) + private ec_PanelStripEntity FindNextAvailableTS(int setCount,int setPreAssigned, List TSs, List allUsedCH) { foreach (var TS in TSs) { @@ -921,14 +925,25 @@ namespace Learun.Application.Web.AppApi double sparedRate = notUsedChs.Count * 1.0 / validChs.Count * 1.0; - if (sparedRate < 0.05) + if (sparedRate < 0.05 || notUsedChs.Count < setPreAssigned) { //没有空闲通道 next + //或者空闲通道不够放下这个电缆的所有set } else { TS.Channels = validChs.OrderBy(X => X.Channel_Seq).ToList(); var seq = TSs.IndexOf(TS); + + if (setCount > 10) + { + //另外如果电缆对数大于10对,即像12 * 2 * 0.75这种,无论它预分配了多少根电缆对,永远预留4个以下的空白通道。意思就是一个模块里面够4个或4个以上空白通道就留4个空白通道,如果不够4个就留4个以下即可。 + if (notUsedChs.Count < 4) + { + //没有足够的空闲通道 next + continue; + } + } return TS;//找到了 }