Browse Source

优化数据库服务和包材重量管理代码

在 `DBService.cs` 中调整了类定义格式,新增多个数据库初始化方法,并优化了初始化注释。

在 `SXService.cs` 中添加了静态字段表示包材重量,优化了变量定义和条件判断,提高了代码可读性。

在 `BillPboxrule.cs` 中调整了属性定义格式,添加了新属性 `PackWeight` 和 `BaoCaiWeight`,并更新了现有属性的注释。
林豪 左 1 month ago
parent
commit
9af0391fa1
3 changed files with 332 additions and 280 deletions
  1. 9 10
      wms.service/Service/DBService.cs
  2. 242 197
      wms.service/Service/SXService.cs
  3. 81 73
      wms.sqlsugar/model/sx/BillPboxrule.cs

+ 9 - 10
wms.service/Service/DBService.cs

@@ -6,15 +6,14 @@ using wms.service.IService;
 using wms.sqlsugar;
 using wms.sqlsugar.model.sx;
 
-
 namespace wms.service.Service
 {
-    public class DBService: IDBService
+    public class DBService : IDBService
     {
         public void InitPtDB()
         {
-
         }
+
         public void InitHjDB()
         {
             //var db1 = SqlSugarHelper.Db.GetConnectionScopeWithAttr<BillPushinfo>();
@@ -65,19 +64,19 @@ namespace wms.service.Service
             //db1.CodeFirst.InitTables<SysJob>();
             //db1.CodeFirst.InitTables<SysJobApiRelation>();
         }
+
         public void InitFjDB()
         {
-           
-        
         }
+
         public void InitSxDB()
         {
             var db1 = SqlSugarHelper.Db.GetConnectionScopeWithAttr<BaseSuppinfo>();
             db1.DbMaintenance.CreateDatabase();
-            db1.CodeFirst.InitTables<BillTimeOutRecord>();
+            //db1.CodeFirst.InitTables<BillTimeOutRecord>();
             //db1.CodeFirst.InitTables<BillSkuInfo>();
-            
-            //db1.CodeFirst.InitTables<BaseMatgrp>();
+
+            db1.CodeFirst.InitTables<BillPboxrule>();
             //db1.CodeFirst.InitTables<BaseMatinfo>();
             //db1.CodeFirst.InitTables<BaseSuppinfo>();
             //db1.CodeFirst.InitTables<BaseUnitgrp>();
@@ -100,9 +99,9 @@ namespace wms.service.Service
             //db1.CodeFirst.InitTables<WCS_TaskOld>();
             //db1.CodeFirst.InitTables<WCSPlcdata>();
         }
+
         public void InitCpDB()
         {
-         
         }
     }
-}
+}

+ 242 - 197
wms.service/Service/SXService.cs

@@ -43,6 +43,27 @@ namespace wms.service.Service
         private readonly ISXDataService _sxtDataService;
         private static object lockerPalletizingPackTask = new object();
         private static object lockerApplyLoc = new object();
+
+        /// <summary>
+        /// 包材-托盘重量
+        /// </summary>
+        private static decimal TuoPan { get => 12.6M; }
+
+        /// <summary>
+        /// 包材-塑料袋重量
+        /// </summary>
+        private static decimal SuLiaoDai { get => 1.03M; }
+
+        /// <summary>
+        /// 包材-隔板重量
+        /// </summary>
+        private static decimal GeBan { get => 0.77M; }
+
+        /// <summary>
+        /// 包材-纸箱重量
+        /// </summary>
+        private static decimal ZhiXiang { get => 1.09M; }
+
         //static object lockerMoveTake = new object();
 
         public SXService(IMapper mapper, ILogger<SXService> logger, ISXDataService sxtDataService)
@@ -754,7 +775,7 @@ namespace wms.service.Service
                 foreach (var item in reqDto.listinfo)
                 {
                     var boxrule = _boxrulerepository.AsQueryable().Where(x => x.DocsNo.Contains(item)).ToList();
-                    var boxruleId= boxrule.Where(x => x.ZXStateCode == 0).Select(x=>x.Id).ToList();
+                    var boxruleId = boxrule.Where(x => x.ZXStateCode == 0).Select(x => x.Id).ToList();
                     if (boxruleId.Any())
                     {
                         _db.BeginTran();
@@ -3263,39 +3284,43 @@ namespace wms.service.Service
             }
             var packinfo = _packInforepository.GetList(p => p.MatCode == boxcode.TrayCode).First();
             var packlist = _packInforepository.GetList(p => p.PackCode == boxcode.Dryer);
-            decimal wqty = 0;
-            if (packlist.Any())
-            {
-                decimal tuopanqty = 0;
-                decimal packsqty = 0;
-                decimal dituoqty = 0;
-                decimal gebanqty = 0;
-                if (packlist.Any(p => p.MatCode == "C06-02-09-0043"))
-                {
-                    var tuopan = packlist.Where(p => p.MatCode == "C06-02-09-0043").FirstOrDefault();
-                    tuopanqty = tuopan.Count * tuopan.Weight / 1000;
-                }
-                if (packlist.Any(p => p.MatCode == "C12-01-08-0004"))
-                {
-                    var packs = packlist.Where(p => p.MatCode == "C12-01-08-0004").FirstOrDefault();
-                    packsqty = packs.Count * packs.Weight / 1000;
-                }
-                if (packlist.Any(p => p.MatCode == "C12-01-10-0003"))
-                {
-                    var dituo = packlist.Where(p => p.MatCode == "C12-01-10-0003").FirstOrDefault();
-                    dituoqty = dituo.Count * dituo.Weight / 1000;
-                }
-                if (packlist.Any(p => p.MatCode == "C12-01-09-0003"))
-                {
-                    var geban = packlist.Where(p => p.MatCode == "C12-01-09-0003").FirstOrDefault();
-                    gebanqty = 1 * geban.Weight / 1000;
-                }
-                wqty = tuopanqty + packsqty + dituoqty + gebanqty;
-            }
-            if (wqty == 0)
+            decimal wqty = boxcode.BaoCaiWeight;
+            if (wqty == null || wqty <= 0)
             {
-                wqty = 16;
+                wqty = TuoPan + SuLiaoDai + GeBan + ZhiXiang;
             }
+            //if (packlist.Any())
+            //{
+            //    decimal tuopanqty = 0;
+            //    decimal packsqty = 0;
+            //    decimal dituoqty = 0;
+            //    decimal gebanqty = 0;
+            //    if (packlist.Any(p => p.MatCode == "C06-02-09-0043"))
+            //    {
+            //        var tuopan = packlist.Where(p => p.MatCode == "C06-02-09-0043").FirstOrDefault();
+            //        tuopanqty = tuopan.Count * tuopan.Weight / 1000;
+            //    }
+            //    if (packlist.Any(p => p.MatCode == "C12-01-08-0004"))
+            //    {
+            //        var packs = packlist.Where(p => p.MatCode == "C12-01-08-0004").FirstOrDefault();
+            //        packsqty = packs.Count * packs.Weight / 1000;
+            //    }
+            //    if (packlist.Any(p => p.MatCode == "C12-01-10-0003"))
+            //    {
+            //        var dituo = packlist.Where(p => p.MatCode == "C12-01-10-0003").FirstOrDefault();
+            //        dituoqty = dituo.Count * dituo.Weight / 1000;
+            //    }
+            //    if (packlist.Any(p => p.MatCode == "C12-01-09-0003"))
+            //    {
+            //        var geban = packlist.Where(p => p.MatCode == "C12-01-09-0003").FirstOrDefault();
+            //        gebanqty = 1 * geban.Weight / 1000;
+            //    }
+            //    wqty = tuopanqty + packsqty + dituoqty + gebanqty;
+            //}
+            //if (wqty == 0)
+            //{
+            //    wqty = 16;
+            //}
 
             //判断托盘号是否一致
             //var wcstask = _wcstaskoldrepository.AsQueryable().Where(p => p.Id == palletizing.TaskNum).SplitTable(tabs => tabs.Take(2)).First(); ;
@@ -5324,7 +5349,8 @@ namespace wms.service.Service
                             if (solcount <= 0)
                             {
                                 solcount = 0;
-                            };
+                            }
+                            ;
                             solderinvlist = invlist2.Where(p => p.SolderCount <= rule.PerSolderMaxCount && p.SolderCount > 0).OrderBy(p => p.ProductTime).ThenByDescending(p => p.SolderCount).Take(solcount).ToList();
                             invlist2 = invlist2.Where(p => p.SolderCount == 0);
                         }
@@ -6427,7 +6453,7 @@ namespace wms.service.Service
                 //判断缓存工位2是否有空余,并且缓存工位1的托盘要到位
                 var equlist = HttpUtil.PostRequest("http://10.30.43.1:8080/api/Wcs/GetDevicePalletizingEquip", JsonConvert.SerializeObject(""));
                 var devices1 = JsonConvert.DeserializeObject<List<DevincePh1>>(equlist);
-                var huancun1list = new List<string>() { "8089", "8091", "8095", "8097","8306" };
+                var huancun1list = new List<string>() { "8089", "8091", "8095", "8097", "8306" };
                 if (!devices1.Where(p => huancun1list.Contains(p.deviceCode) && p.TaskCode > 0).Any())
                 {
                     RedisHelper.Set("Sx:WMSErrorInfo:ControlOut4", new RedisErrorInfo() { Equip = "ControlOut4", Con = "没有空闲的码垛工位及缓存工位", Time = DateTime.Now });
@@ -6502,7 +6528,7 @@ namespace wms.service.Service
                         continue;
                     }
 
-                    var robotlist = new List<string>() { "Robot1", "Robot2","Robot3" };
+                    var robotlist = new List<string>() { "Robot1", "Robot2", "Robot3" };
                     sxSysConfig palletequip = null;
                     foreach (var robot in robotlist)
                     {
@@ -7175,7 +7201,8 @@ namespace wms.service.Service
                             if (solcount <= 0)
                             {
                                 solcount = 0;
-                            };
+                            }
+                            ;
                             solderinvlist = invlist2.Where(p => p.SolderCount <= rule.PerSolderMaxCount && p.SolderCount > 0).OrderBy(p => p.ProductTime).ThenByDescending(p => p.SolderCount).Take(solcount).ToList();
                             invlist2 = invlist2.Where(p => p.SolderCount == 0);
                         }
@@ -7708,80 +7735,80 @@ namespace wms.service.Service
 
                     #region 重绕盘老规则
 
-//找到重绕盘,拼接进去,重绕盘不需要扭转
-//var invlistchongrao = from loc in _basewarecellrepository.GetList(p => p.IsStop == LocationStop.LocationInvoke.GetHashCode() && p.StateNum == LocationState.LocationState_Full)
-//                      join stock in _billInvnowrepository.GetList(p => p.InvStateCode == InvState.InvEcecState_In.ToString() && p.ExecStateCode == InvLockState.InvState_Normal.ToString() && p.Grade == "A" && (p.InDocsNo.StartsWith("CHA")) && string.IsNullOrEmpty(p.PreStock) && p.ContUsageQty <= 0
-//                      && item.Key.StartsWith(p.MatCode) && p.Wind == rule.Wind && (DateTime.Now - p.OneInTime).TotalHours < timeOutHoldHours)
-//                      on loc.ContGrpBarCode equals stock.ContGrpBarCode
-//                      where rule.SkuCode.StartsWith(stock.MatCode) && stock.HWTypeCode == rule.SpoolType
-//                      select new StockTemp
-//                      {
-//                          MatCode = stock.MatCode,
-//                          InvBarCode = stock.InvBarCode,
-//                          Grade = stock.Grade,
-//                          InvStateCode = stock.InvStateCode,
-//                          ProductTime = stock.ProductTime,
-//                          WbGroupCode = stock.WbGroupCode,
-//                          IsTorsChk = stock.IsTorsChk,
-//                          TorsChkQty = stock.TorsChkQty,
-//                          TorsChkValue = stock.TorsChkValue,
-//                          HoldTime = stock.HoldTime,
-//                          InDocsNo = stock.InDocsNo,
-//                          ProductMachCode = stock.ProductMachCode,
-//                          IsControlpanel = stock.IsControlpanel,
-//                          HWTypeCode = stock.HWTypeCode,
-//                          SolderCount = stock.SolderCount,
-//                          IsRework = stock.IsRework,
-//                          IsBlack = stock.IsBlack,
-//                          Col = loc.Col,
-//                          Layer = loc.Layer,
-//                          Shelf = loc.Shelf,
-//                          Depth = loc.Depth,
-//                          Code = loc.Code,
-//                          Tunnel = loc.Tunnel,
-//                          SCRel = loc.SCRel,
-//                          Floor = loc.Floor,
-//                          WarehouseCode = loc.WarehouseCode,
-//                          ContGrpBarCode = loc.ContGrpBarCode,
-//                          ContGrpId = loc.ContGrpId,
-//                          Id = loc.Id,
-//                          StateNum = loc.StateNum,
-//                          SkuCode = "",
-//                          Wind = stock.Wind
-//                      };
-//过滤重饶盘被禁用的巷道
-//invlistchongrao = invlistchongrao.Distinct();
-//if (tunlist.Any())
-//{
-//    if (tunlist.Where(p => p.Default2 == "1").Any())
-//    {
-//        var inv1 = invlistchongrao.Where(p => p.Floor == 1 && tunlist.Where(x => x.Default2 == "1").Select(x => x.Default1).ToList().Contains(p.Tunnel.ToString()));
-//        var inv2 = inv1.Select(p => p.ContGrpBarCode).ToList();
-//        invlistchongrao = invlistchongrao.Where(p => !inv2.Contains(p.ContGrpBarCode)); //过滤1层被禁用的出库巷道
-//    }
-//    if (tunlist.Where(p => p.Default2 == "2").Any())
-//    {
-//        var inv1 = invlistchongrao.Where(p => p.Floor == 2 && tunlist.Where(x => x.Default2 == "2").Select(x => x.Default1).ToList().Contains(p.Tunnel.ToString()));
-//        var inv2 = inv1.Select(p => p.ContGrpBarCode).ToList();
-//        invlistchongrao = invlistchongrao.Where(p => !inv2.Contains(p.ContGrpBarCode)); //过滤2层被禁用的出库巷道
-//    }
-//    if (tunlist.Where(p => p.Default2 == "3").Any())
-//    {
-//        var inv1 = invlistchongrao.Where(p => p.Floor == 3 && tunlist.Where(x => x.Default2 == "3").Select(x => x.Default1).ToList().Contains(p.Tunnel.ToString()));
-//        var inv2 = inv1.Select(p => p.ContGrpBarCode).ToList();
-//        invlistchongrao = invlistchongrao.Where(p => !inv2.Contains(p.ContGrpBarCode)); //过滤3层被禁用的出库巷道
-//    }
-//}
-
-//重绕盘数量限制BS80  10个(30%);BS60 21个(30%);BS40 21个(30%)
-//if (rule.SpoolType == "BS60" || rule.SpoolType == "BS40")
-//{
-//    invlistchongrao = invlistchongrao.Take(21);
-//}
-//else
-//{
-//    invlistchongrao = invlistchongrao.Take(10);
-//}
+                    //找到重绕盘,拼接进去,重绕盘不需要扭转
+                    //var invlistchongrao = from loc in _basewarecellrepository.GetList(p => p.IsStop == LocationStop.LocationInvoke.GetHashCode() && p.StateNum == LocationState.LocationState_Full)
+                    //                      join stock in _billInvnowrepository.GetList(p => p.InvStateCode == InvState.InvEcecState_In.ToString() && p.ExecStateCode == InvLockState.InvState_Normal.ToString() && p.Grade == "A" && (p.InDocsNo.StartsWith("CHA")) && string.IsNullOrEmpty(p.PreStock) && p.ContUsageQty <= 0
+                    //                      && item.Key.StartsWith(p.MatCode) && p.Wind == rule.Wind && (DateTime.Now - p.OneInTime).TotalHours < timeOutHoldHours)
+                    //                      on loc.ContGrpBarCode equals stock.ContGrpBarCode
+                    //                      where rule.SkuCode.StartsWith(stock.MatCode) && stock.HWTypeCode == rule.SpoolType
+                    //                      select new StockTemp
+                    //                      {
+                    //                          MatCode = stock.MatCode,
+                    //                          InvBarCode = stock.InvBarCode,
+                    //                          Grade = stock.Grade,
+                    //                          InvStateCode = stock.InvStateCode,
+                    //                          ProductTime = stock.ProductTime,
+                    //                          WbGroupCode = stock.WbGroupCode,
+                    //                          IsTorsChk = stock.IsTorsChk,
+                    //                          TorsChkQty = stock.TorsChkQty,
+                    //                          TorsChkValue = stock.TorsChkValue,
+                    //                          HoldTime = stock.HoldTime,
+                    //                          InDocsNo = stock.InDocsNo,
+                    //                          ProductMachCode = stock.ProductMachCode,
+                    //                          IsControlpanel = stock.IsControlpanel,
+                    //                          HWTypeCode = stock.HWTypeCode,
+                    //                          SolderCount = stock.SolderCount,
+                    //                          IsRework = stock.IsRework,
+                    //                          IsBlack = stock.IsBlack,
+                    //                          Col = loc.Col,
+                    //                          Layer = loc.Layer,
+                    //                          Shelf = loc.Shelf,
+                    //                          Depth = loc.Depth,
+                    //                          Code = loc.Code,
+                    //                          Tunnel = loc.Tunnel,
+                    //                          SCRel = loc.SCRel,
+                    //                          Floor = loc.Floor,
+                    //                          WarehouseCode = loc.WarehouseCode,
+                    //                          ContGrpBarCode = loc.ContGrpBarCode,
+                    //                          ContGrpId = loc.ContGrpId,
+                    //                          Id = loc.Id,
+                    //                          StateNum = loc.StateNum,
+                    //                          SkuCode = "",
+                    //                          Wind = stock.Wind
+                    //                      };
+                    //过滤重饶盘被禁用的巷道
+                    //invlistchongrao = invlistchongrao.Distinct();
+                    //if (tunlist.Any())
+                    //{
+                    //    if (tunlist.Where(p => p.Default2 == "1").Any())
+                    //    {
+                    //        var inv1 = invlistchongrao.Where(p => p.Floor == 1 && tunlist.Where(x => x.Default2 == "1").Select(x => x.Default1).ToList().Contains(p.Tunnel.ToString()));
+                    //        var inv2 = inv1.Select(p => p.ContGrpBarCode).ToList();
+                    //        invlistchongrao = invlistchongrao.Where(p => !inv2.Contains(p.ContGrpBarCode)); //过滤1层被禁用的出库巷道
+                    //    }
+                    //    if (tunlist.Where(p => p.Default2 == "2").Any())
+                    //    {
+                    //        var inv1 = invlistchongrao.Where(p => p.Floor == 2 && tunlist.Where(x => x.Default2 == "2").Select(x => x.Default1).ToList().Contains(p.Tunnel.ToString()));
+                    //        var inv2 = inv1.Select(p => p.ContGrpBarCode).ToList();
+                    //        invlistchongrao = invlistchongrao.Where(p => !inv2.Contains(p.ContGrpBarCode)); //过滤2层被禁用的出库巷道
+                    //    }
+                    //    if (tunlist.Where(p => p.Default2 == "3").Any())
+                    //    {
+                    //        var inv1 = invlistchongrao.Where(p => p.Floor == 3 && tunlist.Where(x => x.Default2 == "3").Select(x => x.Default1).ToList().Contains(p.Tunnel.ToString()));
+                    //        var inv2 = inv1.Select(p => p.ContGrpBarCode).ToList();
+                    //        invlistchongrao = invlistchongrao.Where(p => !inv2.Contains(p.ContGrpBarCode)); //过滤3层被禁用的出库巷道
+                    //    }
+                    //}
+
+                    //重绕盘数量限制BS80  10个(30%);BS60 21个(30%);BS40 21个(30%)
+                    //if (rule.SpoolType == "BS60" || rule.SpoolType == "BS40")
+                    //{
+                    //    invlistchongrao = invlistchongrao.Take(21);
+                    //}
+                    //else
+                    //{
+                    //    invlistchongrao = invlistchongrao.Take(10);
+                    //}
 
                     #endregion 重绕盘老规则
 
@@ -7822,7 +7849,8 @@ namespace wms.service.Service
                             if (solcount <= 0)
                             {
                                 solcount = 0;
-                            };
+                            }
+                            ;
                             solderinvlist = invlist2.Where(p => p.SolderCount <= rule.PerSolderMaxCount && p.SolderCount > 0).OrderBy(p => p.ProductTime).ThenByDescending(p => p.SolderCount).Take(solcount).ToList();
                             invlist2 = invlist2.Where(p => p.SolderCount == 0);
                         }
@@ -13166,134 +13194,151 @@ namespace wms.service.Service
         public SRes<int> TorsChkFloor(TorsChkFloorRequest reqDto)
         {
             var res = new SRes<int>();
-            if (reqDto.Count <= 0)
+            try
             {
-                res.ResCode = ResponseStatusCodeEnum.ErrParam.GetHashCode();
-                res.ResMsg = ResponseStatusCodeEnum.ErrParam.GetDescription() + "任务数量不能为0";
-                RedisHelper.Set("Sx:WMSErrorInfo:TorsChkEquip6", new RedisErrorInfo() { Equip = "TorsChkEquip6", Con = "参数错误,请求任务数量不能为0", Time = DateTime.Now });
-                return res;
-            }
-            var floorTaskCount = int.Parse(_sysconfigrepository.GetFirst(p => p.Code == "FloorTaskCount").SContent);
-            var bar = _taskrepository.AsQueryable().With(SqlWith.NoLock).Where(p => p.Type == TaskType.EnterDepot && p.Status < TaskStatus.Finish && p.BusType == "扭转回库").OrderByDescending(p => p.AddTime).First();
-            var stock = _billInvnowrepository.AsQueryable().With(SqlWith.NoLock).Where(p => p.ContGrpBarCode == bar.BarCode && p.InvStateCode == "InvEcecState_BuildUp").First();
-            var currentTime = stock.ProductTime;
+                if (reqDto.Count <= 0)
+                {
+                    res.ResCode = ResponseStatusCodeEnum.ErrParam.GetHashCode();
+                    res.ResMsg = ResponseStatusCodeEnum.ErrParam.GetDescription() + "任务数量不能为0";
+                    RedisHelper.Set("Sx:WMSErrorInfo:TorsChkEquip6", new RedisErrorInfo() { Equip = "TorsChkEquip6", Con = "参数错误,请求任务数量不能为0", Time = DateTime.Now });
+                    return res;
+                }
+                var floorTaskCount = int.Parse(_sysconfigrepository.GetFirst(p => p.Code == "FloorTaskCount").SContent);
+                var bar = _taskrepository.AsQueryable().With(SqlWith.NoLock).Where(p => p.Type == TaskType.EnterDepot && p.Status < TaskStatus.Finish && p.BusType == "扭转回库").OrderByDescending(p => p.AddTime).First();
+                if (bar == null)
+                {
+                    res.ResCode = ResponseStatusCodeEnum.Fail.GetHashCode();
+                    res.ResMsg = "没有扭转回库任务需要分配楼层";
+                    RedisHelper.Set("Sx:WMSErrorInfo:TorsChkEquip6", new RedisErrorInfo() { Equip = "TorsChkEquip6", Con = "没有扭转回库任务需要分配楼层,请检查扭转回库位置任务实际是否有货", Time = DateTime.Now });
+                    return res;
+                }
+                var stock = _billInvnowrepository.AsQueryable().With(SqlWith.NoLock).Where(p => p.ContGrpBarCode == bar.BarCode && p.InvStateCode == "InvEcecState_BuildUp").First();
+                var currentTime = stock.ProductTime;
 
-            var startTime = currentTime.Hour >= 13 ? currentTime.Date.AddHours(13) : currentTime.Date.AddDays(-1).AddHours(13);
-            var endTime = currentTime.Hour >= 13 ? currentTime.Date.AddDays(1).AddHours(8) : currentTime.Date.AddHours(8);
+                var startTime = currentTime.Hour >= 13 ? currentTime.Date.AddHours(13) : currentTime.Date.AddDays(-1).AddHours(13);
+                var endTime = currentTime.Hour >= 13 ? currentTime.Date.AddDays(1).AddHours(8) : currentTime.Date.AddHours(8);
 
-            //今天这一批次的扭转入库的分配楼层数量
-            var existstock = _billInvnowrepository.AsQueryable().With(SqlWith.NoLock).Where(p => p.InvStateCode == InvState.InvEcecState_In.ToString() && p.IsTorsChk == true && p.TorsChkQty == 1 && p.ProductTime >= startTime && p.ProductTime <= endTime).ToList();
-            int row = 8;
-            var cellfloor1stockcount = existstock.Where(p => p.PutLayer >= 1 && p.PutLayer <= 4 && p.PutRow > row).Count();  //1楼层同规格数量
-            var cellfloor2stockcount = existstock.Where(p => p.PutLayer >= 5 && p.PutLayer <= 8 && p.PutRow > row).Count();  //2楼层同规格数量
-            var cellfloor3stockcount = existstock.Where(p => p.PutLayer >= 9 && p.PutLayer <= 12 && p.PutRow > row).Count();  //3楼层同规格数量
+                //今天这一批次的扭转入库的分配楼层数量
+                var existstock = _billInvnowrepository.AsQueryable().With(SqlWith.NoLock).Where(p => p.InvStateCode == InvState.InvEcecState_In.ToString() && p.IsTorsChk == true && p.TorsChkQty == 1 && p.ProductTime >= startTime && p.ProductTime <= endTime).ToList();
+                int row = 8;
+                var cellfloor1stockcount = existstock.Where(p => p.PutLayer >= 1 && p.PutLayer <= 4 && p.PutRow > row).Count();  //1楼层同规格数量
+                var cellfloor2stockcount = existstock.Where(p => p.PutLayer >= 5 && p.PutLayer <= 8 && p.PutRow > row).Count();  //2楼层同规格数量
+                var cellfloor3stockcount = existstock.Where(p => p.PutLayer >= 9 && p.PutLayer <= 12 && p.PutRow > row).Count();  //3楼层同规格数量
 
-            //bool isTobeTors = false;
-            int tun = 2;
-            //int row = 8;
-            var cell = _basewarecellrepository.AsQueryable().With(SqlWith.NoLock).Where(p => p.IsStop == LocationStop.LocationInvoke.GetHashCode() && p.StateNum == LocationState.LocationState_Empty).ToList();
+                //bool isTobeTors = false;
+                int tun = 2;
+                //int row = 8;
+                var cell = _basewarecellrepository.AsQueryable().With(SqlWith.NoLock).Where(p => p.IsStop == LocationStop.LocationInvoke.GetHashCode() && p.StateNum == LocationState.LocationState_Empty).ToList();
 
-            var disabletunnels = _sysconfigrepository.GetList(p => p.SType == "InStop" && !string.IsNullOrEmpty(p.SContent));
-            if (disabletunnels != null && disabletunnels.Any())
-            {
-                foreach (var item in disabletunnels)
+                var disabletunnels = _sysconfigrepository.GetList(p => p.SType == "InStop" && !string.IsNullOrEmpty(p.SContent));
+                if (disabletunnels != null && disabletunnels.Any())
                 {
-                    var distun = int.Parse(item.Default1);
-                    var disfloor = int.Parse(item.Default2);
-                    var disids = cell.Where(p => p.Floor == disfloor && p.Tunnel == distun).Select(p => p.Id);
-                    cell = cell.Where(p => !disids.Contains(p.Id)).ToList();
+                    foreach (var item in disabletunnels)
+                    {
+                        var distun = int.Parse(item.Default1);
+                        var disfloor = int.Parse(item.Default2);
+                        var disids = cell.Where(p => p.Floor == disfloor && p.Tunnel == distun).Select(p => p.Id);
+                        cell = cell.Where(p => !disids.Contains(p.Id)).ToList();
+                    }
                 }
-            }
 
-            var cellfloor1count = cell.Where(p => p.Floor == 1 && p.Tunnel > tun).Count();  //1楼层可用的货位数
-            var cellfloor2count = cell.Where(p => p.Floor == 2 && p.Tunnel > tun).Count();  //2楼层可用的货位数
-            var cellfloor3count = cell.Where(p => p.Floor == 3 && p.Tunnel > tun).Count();  //3楼层可用的货位数
+                var cellfloor1count = cell.Where(p => p.Floor == 1 && p.Tunnel > tun).Count();  //1楼层可用的货位数
+                var cellfloor2count = cell.Where(p => p.Floor == 2 && p.Tunnel > tun).Count();  //2楼层可用的货位数
+                var cellfloor3count = cell.Where(p => p.Floor == 3 && p.Tunnel > tun).Count();  //3楼层可用的货位数
 
-            var forbidlayer = wms.util.AppSettings.GetConfig("ForbidLayer");//禁用的楼层
-            if (!string.IsNullOrEmpty(forbidlayer))
-            {
-                if (forbidlayer.Contains("1")) cellfloor1count = 0;
-                if (forbidlayer.Contains("2")) cellfloor2count = 0;
-                if (forbidlayer.Contains("3")) cellfloor3count = 0;
-            }
+                var forbidlayer = wms.util.AppSettings.GetConfig("ForbidLayer");//禁用的楼层
+                if (!string.IsNullOrEmpty(forbidlayer))
+                {
+                    if (forbidlayer.Contains("1")) cellfloor1count = 0;
+                    if (forbidlayer.Contains("2")) cellfloor2count = 0;
+                    if (forbidlayer.Contains("3")) cellfloor3count = 0;
+                }
 
-            var tempcells = new List<Tuple<int, int, double>>() {
+                var tempcells = new List<Tuple<int, int, double>>() {
              new Tuple<int, int,double>(1,cellfloor1count,cellfloor1stockcount / (cellfloor1count * 1.0)),
              new Tuple<int, int,double>(2,cellfloor2count,cellfloor2stockcount / (cellfloor2count * 1.0)),
              new Tuple<int, int,double>(3,cellfloor3count,cellfloor3stockcount / (cellfloor3count * 1.0)),
             };
-            //tempcells = tempcells.OrderByDescending(p => p.Item2).ToList();
-            tempcells = tempcells.OrderBy(p => p.Item3).ToList();//按照同规则物料少的排序
+                //tempcells = tempcells.OrderByDescending(p => p.Item2).ToList();
+                tempcells = tempcells.OrderBy(p => p.Item3).ToList();//按照同规则物料少的排序
 
-            //每个扫码固定楼层,如果固定楼层设备坏了或者库存满了,再换楼层
-            var taskcount = _taskrepository.AsQueryable().With(SqlWith.NoLock).Where(p => p.Type == TaskType.EnterDepot && p.Status < TaskStatus.Finish && p.Floor != 0).ToList();
+                //每个扫码固定楼层,如果固定楼层设备坏了或者库存满了,再换楼层
+                var taskcount = _taskrepository.AsQueryable().With(SqlWith.NoLock).Where(p => p.Type == TaskType.EnterDepot && p.Status < TaskStatus.Finish && p.Floor != 0).ToList();
 
-            if (tempcells[0].Item2 > (reqDto.Count + 10))
-            {
-                if (taskcount.Where(p => p.Floor == tempcells[0].Item1).Count() > floorTaskCount || tempcells[0].Item2 == 0)
+                if (tempcells[0].Item2 > (reqDto.Count + 10))
                 {
-                    if (taskcount.Where(p => p.Floor == tempcells[1].Item1).Count() > floorTaskCount || tempcells[1].Item2 == 0)
+                    if (taskcount.Where(p => p.Floor == tempcells[0].Item1).Count() > floorTaskCount || tempcells[0].Item2 == 0)
                     {
-                        if (taskcount.Where(p => p.Floor == tempcells[2].Item1).Count() > floorTaskCount || tempcells[2].Item2 == 0)
+                        if (taskcount.Where(p => p.Floor == tempcells[1].Item1).Count() > floorTaskCount || tempcells[1].Item2 == 0)
                         {
-                            res.ResCode = ResponseStatusCodeEnum.Fail.GetHashCode();
-                            res.ResMsg = reqDto.Count + "扭转回库申请楼层失败,当前环线三个楼层执行中的任务数已满,不允许分配楼层";
-                            res.ResData = 0;
-                            return res;
+                            if (taskcount.Where(p => p.Floor == tempcells[2].Item1).Count() > floorTaskCount || tempcells[2].Item2 == 0)
+                            {
+                                res.ResCode = ResponseStatusCodeEnum.Fail.GetHashCode();
+                                res.ResMsg = reqDto.Count + "扭转回库申请楼层失败,当前环线三个楼层执行中的任务数已满,不允许分配楼层";
+                                res.ResData = 0;
+                                return res;
+                            }
+                            else
+                            {
+                                res.ResData = tempcells[2].Item1;
+                            }
                         }
                         else
                         {
-                            res.ResData = tempcells[2].Item1;
+                            res.ResData = tempcells[1].Item1;
                         }
                     }
                     else
                     {
-                        res.ResData = tempcells[1].Item1;
+                        res.ResData = tempcells[0].Item1;
                     }
                 }
                 else
                 {
-                    res.ResData = tempcells[0].Item1;
-                }
-            }
-            else
-            {
-                if (tempcells[1].Item2 > (reqDto.Count + 10))
-                {
-                    if (taskcount.Where(p => p.Floor == tempcells[1].Item1).Count() > floorTaskCount || tempcells[1].Item2 == 0)
+                    if (tempcells[1].Item2 > (reqDto.Count + 10))
                     {
-                        if (taskcount.Where(p => p.Floor == tempcells[2].Item1).Count() > floorTaskCount || tempcells[2].Item2 == 0)
+                        if (taskcount.Where(p => p.Floor == tempcells[1].Item1).Count() > floorTaskCount || tempcells[1].Item2 == 0)
                         {
-                            res.ResCode = ResponseStatusCodeEnum.Fail.GetHashCode();
-                            res.ResMsg = reqDto.Count + "扭转回库申请楼层失败,当前环线三个楼层执行中的任务数已满,不允许分配楼层";
-                            res.ResData = 0;
-                            return res;
+                            if (taskcount.Where(p => p.Floor == tempcells[2].Item1).Count() > floorTaskCount || tempcells[2].Item2 == 0)
+                            {
+                                res.ResCode = ResponseStatusCodeEnum.Fail.GetHashCode();
+                                res.ResMsg = reqDto.Count + "扭转回库申请楼层失败,当前环线三个楼层执行中的任务数已满,不允许分配楼层";
+                                res.ResData = 0;
+                                return res;
+                            }
+                            else
+                            {
+                                res.ResData = tempcells[2].Item1;
+                            }
                         }
                         else
                         {
-                            res.ResData = tempcells[2].Item1;
+                            res.ResData = tempcells[1].Item1;
                         }
                     }
                     else
                     {
-                        res.ResData = tempcells[1].Item1;
-                    }
-                }
-                else
-                {
-                    if (taskcount.Where(p => p.Floor == tempcells[2].Item1).Count() < floorTaskCount && tempcells[2].Item2 > 30)
-                    {
-                        res.ResData = tempcells[2].Item1;
-                    }
-                    else
-                    {
-                        res.ResCode = ResponseStatusCodeEnum.Fail.GetHashCode();
-                        res.ResMsg = reqDto.Count + "扭转回库申请楼层失败,当前环线三个楼层执行中的任务数已满,不允许分配楼层";
-                        res.ResData = 0;
-                        return res;
+                        if (taskcount.Where(p => p.Floor == tempcells[2].Item1).Count() < floorTaskCount && tempcells[2].Item2 > 30)
+                        {
+                            res.ResData = tempcells[2].Item1;
+                        }
+                        else
+                        {
+                            res.ResCode = ResponseStatusCodeEnum.Fail.GetHashCode();
+                            res.ResMsg = reqDto.Count + "扭转回库申请楼层失败,当前环线三个楼层执行中的任务数已满,不允许分配楼层";
+                            res.ResData = 0;
+                            return res;
+                        }
                     }
                 }
             }
+            catch (Exception ex)
+            {
+                res.ResCode = ResponseStatusCodeEnum.Fail.GetHashCode();
+                res.ResMsg = ex.StackTrace;
+                res.ResData = 0;
+                return res;
+            }
             return res;
         }
 

+ 81 - 73
wms.sqlsugar/model/sx/BillPboxrule.cs

@@ -1,6 +1,4 @@
-using System; 
-using System.Collections.Generic;
-using SqlSugar;
+using SqlSugar;
 
 namespace wms.sqlsugar.model.sx
 {
@@ -9,62 +7,62 @@ namespace wms.sqlsugar.model.sx
     /// </summary>
     [Tenant("sx")]
     [SugarTable("Bill_PBoxRule")]
-    public partial class BillPboxrule:BaseModel
-    { 
-    
-        /// <summary> 
+    public partial class BillPboxrule : BaseModel
+    {
+        /// <summary>
         /// WarehouseId
-        /// </summary> 
-        [SugarColumn(ColumnDataType ="bigint" ,  IsNullable = false )]
+        /// </summary>
+        [SugarColumn(ColumnDataType = "bigint", IsNullable = false)]
         public long WarehouseId { get; set; }
 
-        /// <summary> 
+        /// <summary>
         /// IsStop
-        /// </summary> 
-        [SugarColumn(ColumnDataType ="int" ,  IsNullable = false )]
+        /// </summary>
+        [SugarColumn(ColumnDataType = "int", IsNullable = false)]
         public int IsStop { get; set; }
 
-        /// <summary> 
+        /// <summary>
         /// DocsNo
-        /// </summary> 
-        [SugarColumn(ColumnDataType ="nvarchar" , Length = 50  , IsNullable = false )]
+        /// </summary>
+        [SugarColumn(ColumnDataType = "nvarchar", Length = 50, IsNullable = false)]
         public string DocsNo { get; set; }
 
-        /// <summary> 
+        /// <summary>
         /// Sku编号
-        /// </summary> 
+        /// </summary>
         [SugarColumn(ColumnDataType = "nvarchar", Length = 50, IsNullable = false)]
         public string SkuCode { get; set; }
 
-        /// <summary> 
+        /// <summary>
         /// 箱号
-        /// </summary> 
-        [SugarColumn(ColumnDataType ="nvarchar" , Length = 50  , IsNullable = false )]
+        /// </summary>
+        [SugarColumn(ColumnDataType = "nvarchar", Length = 50, IsNullable = false)]
         public string PBoxCode { get; set; }
 
-        /// <summary> 
+        /// <summary>
         /// 装箱规则(1:层配;2:SPC)
-        /// </summary> 
-        [SugarColumn(ColumnDataType ="nvarchar" , Length = 50  , IsNullable = false )]
+        /// </summary>
+        [SugarColumn(ColumnDataType = "nvarchar", Length = 50, IsNullable = false)]
         public string PackRule { get; set; }
 
-        /// <summary> 
+        /// <summary>
         /// 每箱满轮子数
-        /// </summary> 
-        [SugarColumn(ColumnDataType ="int" ,  IsNullable = false )]
+        /// </summary>
+        [SugarColumn(ColumnDataType = "int", IsNullable = false)]
         public int FullCountQty { get; set; }
 
-        /// <summary> 
+        /// <summary>
         /// 每箱空轮子数
-        /// </summary> 
-        [SugarColumn(ColumnDataType ="int" ,  IsNullable = false )]
+        /// </summary>
+        [SugarColumn(ColumnDataType = "int", IsNullable = false)]
         public int EmptyCountQty { get; set; }
 
-        /// <summary> 
+        /// <summary>
         /// 是否允许焊点盘
-        /// </summary> 
-        [SugarColumn(ColumnDataType ="int" ,  IsNullable = false )]
+        /// </summary>
+        [SugarColumn(ColumnDataType = "int", IsNullable = false)]
         public int IsSolder { get; set; }
+
         /// <summary>
         /// 每箱允许最大焊点盘数量
         /// </summary>
@@ -77,108 +75,118 @@ namespace wms.sqlsugar.model.sx
         [SugarColumn(ColumnDataType = "int", IsNullable = false)]
         public int PerSolderMaxCount { get; set; }
 
-
-
-        /// <summary> 
+        /// <summary>
         /// 24小时目标扭转值
-        /// </summary> 
-        [SugarColumn(ColumnDataType ="decimal" , Length = 18  , DecimalDigits = 2, IsNullable = false )]
+        /// </summary>
+        [SugarColumn(ColumnDataType = "decimal", Length = 18, DecimalDigits = 2, IsNullable = false)]
         public decimal Torsion24Qty { get; set; }
 
-        /// <summary> 
+        /// <summary>
         /// 48小时目标扭转值
-        /// </summary> 
-        [SugarColumn(ColumnDataType ="decimal" , Length = 18, DecimalDigits = 2, IsNullable = false )]
+        /// </summary>
+        [SugarColumn(ColumnDataType = "decimal", Length = 18, DecimalDigits = 2, IsNullable = false)]
         public decimal Torsion48Qty { get; set; }
 
-        /// <summary> 
+        /// <summary>
         /// 72小时目标扭转值
-        /// </summary> 
+        /// </summary>
         [SugarColumn(ColumnDataType = "decimal", Length = 18, DecimalDigits = 2, IsNullable = false)]
         public decimal Torsion72Qty { get; set; }
 
-
-        /// <summary> 
+        /// <summary>
         /// 扭转目标范围
-        /// </summary> 
+        /// </summary>
         [SugarColumn(ColumnDataType = "decimal", Length = 18, DecimalDigits = 2, IsNullable = false)]
         public decimal TorsionErrRange { get; set; }
 
-        /// <summary> 
+        /// <summary>
         /// 子托盘编码
-        /// </summary> 
-        [SugarColumn(ColumnDataType ="nvarchar" , Length = 50  , IsNullable = false )]
+        /// </summary>
+        [SugarColumn(ColumnDataType = "nvarchar", Length = 50, IsNullable = false)]
         public string TrayCode { get; set; }
 
-
-        /// <summary> 
+        /// <summary>
         /// 装箱状态(0未装箱/1装箱中/2装箱完成/3控制箱预占/4非控制预占)
-        /// </summary> 
+        /// </summary>
         [SugarColumn(ColumnDataType = "int", IsNullable = false)]
         public int ZXStateCode { get; set; }
 
-        /// <summary> 
+        /// <summary>
         /// 每箱黑盘数量
-        /// </summary> 
+        /// </summary>
         [SugarColumn(ColumnDataType = "int", IsNullable = false)]
         public int BlackCount { get; set; }
 
-        /// <summary> 
+        /// <summary>
         /// 返工盘数量
-        /// </summary> 
+        /// </summary>
         [SugarColumn(ColumnDataType = "int", IsNullable = false)]
         public int ReturnCount { get; set; }
 
-        /// <summary> 
+        /// <summary>
         /// 扭转目标时间
-        /// </summary> 
+        /// </summary>
         [SugarColumn(ColumnDataType = "decimal", Length = 18, DecimalDigits = 2, IsNullable = false)]
         public decimal HoldTime { get; set; }
+
         /// <summary>
         ///  是否控制盘
         /// </summary>
         [SugarColumn(ColumnDataType = "bit", IsNullable = false)]
         public bool IsControlpanel { get; set; }
-        /// <summary> 
+
+        /// <summary>
         /// 包装信息
-        /// </summary> 
+        /// </summary>
         [SugarColumn(ColumnDataType = "nvarchar", IsNullable = true)]
         public string PackJsonContent { get; set; }
-        /// <summary> 
+
+        /// <summary>
         /// 扭转最大数
-        /// </summary> 
+        /// </summary>
         [SugarColumn(ColumnDataType = "decimal", Length = 18, DecimalDigits = 2, IsNullable = false)]
         public decimal TorsionMaxQty { get; set; }
-        /// <summary> 
+
+        /// <summary>
         /// 扭转最小数
-        /// </summary> 
+        /// </summary>
         [SugarColumn(ColumnDataType = "decimal", Length = 18, DecimalDigits = 2, IsNullable = false)]
         public decimal TorsionMinQty { get; set; }
-        /// <summary> 
+
+        /// <summary>
         /// 工字轮型号
-        /// </summary> 
+        /// </summary>
         [SugarColumn(ColumnDataType = "nvarchar", Length = 50, IsNullable = true)]
         public string SpoolType { get; set; }
-        /// <summary> 
+
+        /// <summary>
         /// 生产批号
-        /// </summary> 
+        /// </summary>
         [SugarColumn(ColumnDataType = "nvarchar", Length = 50, IsNullable = true)]
         public string BatchNo { get; set; }
-        /// <summary> 
+
+        /// <summary>
         /// 绕向
-        /// </summary> 
+        /// </summary>
         [SugarColumn(ColumnDataType = "nvarchar", Length = 50, IsNullable = false)]
         public string Wind { get; set; }
-        /// <summary> 
+
+        /// <summary>
         /// 包装编码
-        /// </summary> 
+        /// </summary>
         [SugarColumn(ColumnDataType = "nvarchar", Length = 50, IsNullable = true)]
         public string Dryer { get; set; }
+
         /// <summary>
         /// 包材重量
         /// </summary>
         [SugarColumn(ColumnDataType = "decimal", Length = 18, IsNullable = false)]
         public decimal PackWeight { get; set; }
-    }
-}
 
+        /// <summary>
+        /// 计算用包材重量
+        /// </summary>
+        [SugarColumn(ColumnDataType = "decimal", Length = 18, IsNullable = true)]
+        public decimal BaoCaiWeight { get; set; }
+    }
+}