Esempio n. 1
0
        private static CacheResult CalculateCacheState(CalResult rt, PanelInfo pinfo, List <LableCode> layerLabels, Action <string> onlog)
        {
            // debug 2017.97.24
            if (rt == null)
            {
                throw new Exception("rt空值。");
            }
            if (rt.CodeCome == null)
            {
                throw new Exception("rt.codecome空值。");
            }

            var cre = new CacheResult {
                SideState = new SideFullState(SideFullState.NO_FULL, null)
            };

            if (layerLabels != null && layerLabels.Count > 0)
            {
                // 最近一层没满。
                cre.SideState    = IsPanelFullPro(layerLabels, rt.CodeCome);
                rt.CodeFromCache = cre.SideState.fromCache;

                if (cre.SideState.state == SideFullState.FULL)
                {
                    // rt.CodeFromCache可能是null.
                    var cachedRollDiameter = rt.CodeFromCache != null ? rt.CodeFromCache.Diameter : 0;
                    if (rt.CodeFromCache == null)
                    {
                        rt.state = CacheState.Go;
                    }
                    else if (rt.CodeCome.Diameter > cachedRollDiameter + clsSetting.CacheIgnoredDiff)
                    {
                        rt.state = CacheState.GetThenGo;
                    }
                    else
                    {
                        rt.state = CacheState.GoThenGet;
                    }
                }
                else if (cre.SideState.state == SideFullState.NO_FULL)
                {
                    var cr = CalculateCache(pinfo, rt.CodeCome);
                    rt.CodeFromCache = cr.CodeFromCache;
                    rt.state         = cr.state;
                }
                else if (cre.SideState.state == SideFullState.EXCEED)
                {
                    if (rt.CodeFromCache == null)
                    {
                        onlog($"布卷exceed状态时,codefromcache空值。");
                    }                                                                         // debug 2017.97.24
                    var cachedRollDiameter = rt.CodeFromCache != null ? rt.CodeFromCache.Diameter : 0;
                    if (rt.CodeCome.Diameter + clsSetting.CacheIgnoredDiff > cachedRollDiameter)
                    {
                        rt.CodeFromCache = null;
                        rt.state         = CacheState.Go;
                    }
                    else
                    {
                        rt.state = CacheState.GetThenCache;
                    }
                    pinfo.HasExceed = true;
                }
            }
            cre.CResult = rt;

            if (cre.CResult.CodeFromCache != null && cre.CResult.CodeCome.PanelNo != cre.CResult.CodeFromCache.PanelNo)
            {
                cre.CResult.CodeFromCache.PanelNo = cre.CResult.CodeCome.PanelNo;
                cre.CResult.CodeFromCache.Floor   = cre.CResult.CodeCome.Floor;
            }

            if (cre.CResult.CodeFromCache != null && cre.CResult.CodeFromCache.Floor != cre.CResult.CodeCome.Floor)
            {
                cre.CResult.CodeFromCache.Floor = cre.CResult.CodeCome.Floor;
            }

            return(cre);
        }
Esempio n. 2
0
        public static CalResult AreaBCalculate(LableCode lc, string dateShiftNo, IEnumerable <LableCode> cacheq, Action <string> onlog)
        {
            var cre = new CacheResult {
                CResult = new CalResult(CacheState.Cache, lc, null)
            };

            // 创建新板号
            var pinfo = GetPanelNo(cre.CResult.CodeCome, dateShiftNo);

            var fp = FloorPerformance.None;
            List <LableCode> layerLabels;

            // 解决在缓存位,同一交地出现多个不同板号的情况.
            if (pinfo == null)
            {
                pinfo = new PanelInfo(cre.CResult.CodeCome.PanelNo);
                cre.CResult.CodeCome.PanelNo = pinfo.PanelNo;
                cre.CResult.CodeCome.Floor   = pinfo.CurrFloor;
            }
            #region 缓存布卷板号和层号的修正
            var cachedRolls = FrmMain.taskQ.CacheSide.Where(x => x.labelcode != null && x.labelcode.ToLocation == lc.ToLocation)
                              .Select(x => x.labelcode)
                              .ToList();
            foreach (LableCode tmp in cachedRolls)
            {
                tmp.PanelNo = pinfo.PanelNo;
                tmp.Floor   = pinfo.CurrFloor;
            }
            #endregion

            // 取当前交地、当前板、当前层所有标签。
            layerLabels = LableCode.GetLableCodesOfRecentFloor(cre.CResult.CodeCome.ToLocation, pinfo.PanelNo, pinfo.CurrFloor);
            cre         = CalculateCacheState(cre.CResult, pinfo, layerLabels, onlog);

            if (cre.SideState.state == SideFullState.FULL || cre.SideState.state == SideFullState.EXCEED)
            {
                fp = SetFullFlag(CalculateFloorIndex(layerLabels), pinfo);
            }

            var msg = $"";
            switch (cre.CResult.state)
            {
            case CacheState.Go:
                CalculatePosition(layerLabels, cre.CResult.CodeCome, cre.SideState == null ? SideFullState.NO_FULL : cre.SideState.state);
                break;

            case CacheState.GetThenCache:
            case CacheState.CacheAndGet:
                CalculatePosition(layerLabels, cre.CResult.CodeFromCache, cre.SideState == null ? SideFullState.NO_FULL : cre.SideState.state);
                break;

            case CacheState.GoThenGet:
                //计算位置坐标, 赋予层号
                cre.CResult.CodeCome.Floor = cre.CResult.CodeFromCache.Floor;
                CalculatePosition(layerLabels, cre.CResult.CodeCome, cre.CResult.CodeFromCache, cre.SideState == null ? SideFullState.NO_FULL : cre.SideState.state);
                break;

            case CacheState.GetThenGo:
                cre.CResult.CodeCome.Floor = cre.CResult.CodeFromCache.Floor;
                CalculatePosition(layerLabels, cre.CResult.CodeFromCache, cre.CResult.CodeCome, cre.SideState == null ? SideFullState.NO_FULL : cre.SideState.state);
                break;

            case CacheState.Cache:
                var cancachesum = (pinfo.OddStatus ? 0 : 1) + (pinfo.EvenStatus ? 0 : 1);
                var cachelcs    = FrmMain.taskQ.CacheSide.Count(x => x.labelcode != null && x.labelcode.ToLocation == lc.ToLocation);

                var go = CanIgo(cacheq, cre.CResult, cancachesum - cachelcs);
                if (go)
                {
                    cre.CResult.state = CacheState.Go;
                    bool isfull = IsPanelFull(cre.CResult.CodeCome);
                    CalculatePosition(layerLabels, cre.CResult.CodeCome, isfull ? SideFullState.FULL : SideFullState.NO_FULL);

                    if (isfull)
                    {
                        fp = SetFullFlag(cre.CResult.CodeCome.FloorIndex, pinfo);
                    }

                    msg = $"cache change go";
                }
                break;

            default:
                break;
            }

            // 记录层最后一卷
            if (fp == FloorPerformance.BothFinish)
            {
                if (cre.CResult.state == CacheState.Go)
                {
                    // 在没有缓存的情况下满板。
                    cre.CResult.CodeCome.Status = (int)LableState.FloorLastRoll;
                    cre.CResult.CodeCome.Remark = $"{cre.CResult.CodeCome.Remark} floor last roll";
                }
                else if (cre.CResult.state == CacheState.GetThenGo)
                {
                    cre.CResult.CodeCome.Status = (int)LableState.FloorLastRoll;
                    cre.CResult.CodeCome.Remark = $"{cre.CResult.CodeCome.Remark} floor last roll";
                }
                else if (cre.SideState.state == SideFullState.EXCEED)
                {
                    if (cre.CResult.CodeFromCache != null)
                    {
                        cre.CResult.CodeFromCache.Status = (int)LableState.FloorLastRoll;
                        cre.CResult.CodeFromCache.Remark = $"{cre.CResult.CodeFromCache.Remark} floor last roll";
                    }
                    else
                    {
                        cre.CResult.CodeCome.Status = (int)LableState.FloorLastRoll;
                        cre.CResult.CodeCome.Remark = $"{cre.CResult.CodeCome.Remark} floor last roll*{cre.CResult.state}";
                    }
                }
                else
                {
                    cre.CResult.CodeFromCache.Status = (int)LableState.FloorLastRoll;
                    cre.CResult.CodeFromCache.Remark = $"{cre.CResult.CodeFromCache.Remark} floor last roll";
                }
            }

            if (!PanelGen.HasPanelNo(pinfo.PanelNo))
            {
                LableCode.Update(cre.CResult.CodeCome);
            }

            if (cre.SideState.state == SideFullState.EXCEED)
            {
                msg             = $"{msg} EXCEED";
                pinfo.HasExceed = true;
            }

            if (cre.CResult.CodeFromCache != null)
            {
                if (fp == FloorPerformance.BothFinish && cre.SideState.state == SideFullState.EXCEED)  //层满上超出处理
                {
                    LableCode.UpdateEdgeExceed(fp, pinfo, cre.CResult.CodeCome, cre.CResult.CodeFromCache);
                }
                else
                {
                    LableCode.Update(fp, pinfo, cre.CResult.CodeCome, cre.CResult.CodeFromCache);
                }
            }
            else
            {
                LableCode.Update(fp, pinfo, cre.CResult.CodeCome);
            }

            cre.CResult.message = msg;
            return(cre.CResult);
        }