莫海杰 2 months ago
parent
commit
ea53a512c6

+ 7 - 0
SCADA_DAQ/Customer/Controllers/WmsController.cs

@@ -44,5 +44,12 @@ namespace SCADA_DAQ.Customer.Controllers
             return Ok(res);
         }
 
+        [Route("api/low/cancel")]
+        [HttpPost]
+        public async Task<IHttpActionResult> CancelLow([FromBody] List<CancelLowBo> cancellowList)
+        {
+            var res = await Task.Run(() => _wcsService.WmsCancelLow(cancellowList));
+            return Ok(res);
+        }
     }
 }

+ 17 - 0
SCADA_DAQ/Customer/Models/CancelLowBo.cs

@@ -0,0 +1,17 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace SCADA_DAQ.Customer.Models
+{
+    public class CancelLowBo
+    {
+        public string No { get; set; }
+        public decimal Qty { get; set; }
+        public string WarehouseCode { get; set; }
+        public string SourceLocation { get; set; }
+        public string ItemCode { get; set; }
+    }
+}

+ 3 - 1
SCADA_DAQ/Customer/Service/Wcs_ItemTaskInventoryService.cs

@@ -30,7 +30,7 @@ namespace SCADA_DAQ.Customer.Service
                 }
             }
             var filter = $" TaskNo_Str in ({taskNosStr}) and State_Int = 0";
-            var itemTaskList = Env.DAL.App_BC_ItemTask.GetData<AppBCItemTaskVo>(filter);
+            var itemTaskList = Env.DAL.App_BC_ItemTask.GetData<AppBCItemTaskVo>(filter).GroupBy(t => t.TaskNo).Select(t => t.FirstOrDefault()).ToList();
             var message = "";
             var itemTaskUpList = new List<AppBCItemTaskModel>();
             var successItemTaskQty = new List<AppBCItemTaskVo>();
@@ -46,6 +46,7 @@ namespace SCADA_DAQ.Customer.Service
                         itemTaskUpList.Add(new AppBCItemTaskModel
                         {
                             TaskNo = itemTaskList[i].TaskNo,
+                            EndDate = DateTime.Now,
                             ErrorMsg = wmsRes.Message
                         });
                     }
@@ -56,6 +57,7 @@ namespace SCADA_DAQ.Customer.Service
                         itemTaskUpList.Add(new AppBCItemTaskModel
                         {
                             TaskNo = itemTaskList[i].TaskNo,
+                            EndDate = DateTime.Now,
                             ErrorMsg = wmsRes.Result.Error
                         });
                     }

+ 53 - 21
SCADA_DAQ/Customer/Service/Wcs_WebOperationService.cs

@@ -144,6 +144,12 @@ namespace SCADA_DAQ.Customer.Service
                 };
                 return taskIdDic[(int)taskId];
             }
+            var crane1NowCL = $"{Machine?.GetListenReg("1#CraneBay").Value}-{Machine?.GetListenReg("1#CraneLevel").Value}";
+            var crane1StartRCL = $"{Machine?.GetListenReg("1#CraneFrom_Row").Value}-{Machine?.GetListenReg("1#CraneFrom_Bay").Value}-{Machine?.GetListenReg("1#CraneFrom_Level").Value}";
+            var crane1EndRCL = $"{Machine?.GetListenReg("1#CraneTo_Row").Value}-{Machine?.GetListenReg("1#CraneTo_Bay").Value}-{Machine?.GetListenReg("1#CraneTo_Level").Value}";
+            var crane2NowCL = $"{Machine?.GetListenReg("2#CraneBay").Value}-{Machine?.GetListenReg("2#CraneLevel").Value}";
+            var crane2StartRCL = $"{Machine?.GetListenReg("2#CraneFrom_Row").Value}-{Machine?.GetListenReg("2#CraneFrom_Bay").Value}-{Machine?.GetListenReg("2#CraneFrom_Level").Value}";
+            var crane2EndRCL = $"{Machine?.GetListenReg("2#CraneTo_Row").Value}-{Machine?.GetListenReg("2#CraneTo_Bay").Value}-{Machine?.GetListenReg("2#CraneTo_Level").Value}";
             return new RpcResponse<object>()
             {
                 Data = new
@@ -173,17 +179,27 @@ namespace SCADA_DAQ.Customer.Service
                     {
                         ["堆垛机1准备"] = Machine?.GetListenReg("1#CraneReady").Value,
                     },
-                    IntCrane1 = new Dictionary<string, string>()
+                    StartEndCrane1 = new Dictionary<string, string>()
                     {
-                        ["堆垛机1起点排"] = Machine?.GetListenReg("1#CraneFrom_Row").Value.ToString(),
-                        ["堆垛机1起点列"] = Machine?.GetListenReg("1#CraneFrom_Bay").Value.ToString(),
-                        ["堆垛机1起点层"] = Machine?.GetListenReg("1#CraneFrom_Level").Value.ToString(),
-                        ["堆垛机1终点排"] = Machine?.GetListenReg("1#CraneTo_Row").Value.ToString(),
-                        ["堆垛机1终点列"] = Machine?.GetListenReg("1#CraneTo_Bay").Value.ToString(),
-                        ["堆垛机1终点层"] = Machine?.GetListenReg("1#CraneTo_Level").Value.ToString(),
-                        ["堆垛机1当前列"] = Machine?.GetListenReg("1#CraneBay").Value.ToString(),
-                        ["堆垛机1当前层"] = Machine?.GetListenReg("1#CraneLevel").Value.ToString(),
+                        ["堆垛机1起终"] = $"{crane1StartRCL}_{crane1EndRCL}",
+                        ["堆垛机1当前列层"] = crane1NowCL,
                     },
+                    StartEndCrane2 = new Dictionary<string, string>()
+                    {
+                        ["堆垛机2起终"] = $"{crane2StartRCL}_{crane2EndRCL}",
+                        ["堆垛机2当前列层"] = crane2NowCL,
+                    },
+                    //IntCrane1 = new Dictionary<string, string>()
+                    //{
+                    //    ["堆垛机1起点排"] = Machine?.GetListenReg("1#CraneFrom_Row").Value.ToString(),
+                    //    ["堆垛机1起点列"] = Machine?.GetListenReg("1#CraneFrom_Bay").Value.ToString(),
+                    //    ["堆垛机1起点层"] = Machine?.GetListenReg("1#CraneFrom_Level").Value.ToString(),
+                    //    ["堆垛机1终点排"] = Machine?.GetListenReg("1#CraneTo_Row").Value.ToString(),
+                    //    ["堆垛机1终点列"] = Machine?.GetListenReg("1#CraneTo_Bay").Value.ToString(),
+                    //    ["堆垛机1终点层"] = Machine?.GetListenReg("1#CraneTo_Level").Value.ToString(),
+                    //    ["堆垛机1当前列"] = Machine?.GetListenReg("1#CraneBay").Value.ToString(),
+                    //    ["堆垛机1当前层"] = Machine?.GetListenReg("1#CraneLevel").Value.ToString(),
+                    //},
                     BoolLine3 = new Dictionary<string, int?>()
                     {
                         ["输送线3准备"] = Machine?.GetListenReg("3#LineReady").Value,
@@ -208,18 +224,18 @@ namespace SCADA_DAQ.Customer.Service
                     {
                         ["堆垛机2准备"] = Machine?.GetListenReg("2#CraneReady").Value,
                     },
-                    IntCrane2 = new Dictionary<string, string>()
-                    {
-                        ["堆垛机2起点排"] = Machine?.GetListenReg("2#CraneFrom_Row").Value.ToString(),
-                        ["堆垛机2起点列"] = Machine?.GetListenReg("2#CraneFrom_Bay").Value.ToString(),
-                        ["堆垛机2起点层"] = Machine?.GetListenReg("2#CraneFrom_Level").Value.ToString(),
-                        ["堆垛机2终点排"] = Machine?.GetListenReg("2#CraneTo_Row").Value.ToString(),
-                        ["堆垛机2终点列"] = Machine?.GetListenReg("2#CraneTo_Bay").Value.ToString(),
-                        ["堆垛机2终点层"] = Machine?.GetListenReg("2#CraneTo_Level").Value.ToString(),
-                        ["堆垛机2当前列"] = Machine?.GetListenReg("2#CraneBay").Value.ToString(),
-                        ["堆垛机2当前层"] = Machine?.GetListenReg("2#CraneLevel").Value.ToString(),
-                        //["堆垛机2起终点"] = $"{Machine?.GetListenReg("2#CraneFrom_Row").Value.ToString()}-{Machine?.GetListenReg("2#CraneFrom_Bay").Value.ToString()}-{Machine?.GetListenReg("2#CraneFrom_Level").Value.ToString()}_{Machine?.GetListenReg("2#CraneTo_Row").Value.ToString()}-{Machine?.GetListenReg("2#CraneTo_Bay").Value.ToString()}-{Machine?.GetListenReg("2#CraneTo_Level").Value.ToString()}"
-                    }
+                    //IntCrane2 = new Dictionary<string, string>()
+                    //{
+                    //    ["堆垛机2起点排"] = Machine?.GetListenReg("2#CraneFrom_Row").Value.ToString(),
+                    //    ["堆垛机2起点列"] = Machine?.GetListenReg("2#CraneFrom_Bay").Value.ToString(),
+                    //    ["堆垛机2起点层"] = Machine?.GetListenReg("2#CraneFrom_Level").Value.ToString(),
+                    //    ["堆垛机2终点排"] = Machine?.GetListenReg("2#CraneTo_Row").Value.ToString(),
+                    //    ["堆垛机2终点列"] = Machine?.GetListenReg("2#CraneTo_Bay").Value.ToString(),
+                    //    ["堆垛机2终点层"] = Machine?.GetListenReg("2#CraneTo_Level").Value.ToString(),
+                    //    ["堆垛机2当前列"] = Machine?.GetListenReg("2#CraneBay").Value.ToString(),
+                    //    ["堆垛机2当前层"] = Machine?.GetListenReg("2#CraneLevel").Value.ToString(),
+                    //    //["堆垛机2起终点"] = $"{Machine?.GetListenReg("2#CraneFrom_Row").Value.ToString()}-{Machine?.GetListenReg("2#CraneFrom_Bay").Value.ToString()}-{Machine?.GetListenReg("2#CraneFrom_Level").Value.ToString()}_{Machine?.GetListenReg("2#CraneTo_Row").Value.ToString()}-{Machine?.GetListenReg("2#CraneTo_Bay").Value.ToString()}-{Machine?.GetListenReg("2#CraneTo_Level").Value.ToString()}"
+                    //}
                 }
             };
         }
@@ -386,6 +402,22 @@ namespace SCADA_DAQ.Customer.Service
         }
         #endregion
 
+        #region 清空两个列表所有任务
+        public RpcResponse<object> ClearOperateCraneList()
+        {
+            var res = new RpcResponse<object>();
+            CustomerEnv.OperationCrane1List.Clear();
+            CustomerEnv.OperationCrane2List.Clear();
+            if (CustomerEnv.OperationCrane2List.Count == 0 && CustomerEnv.OperationCrane1List.Count == 0)
+            {
+                res.Message = "清除成功";
+                return res;
+            }
+            res.IsSucceed = false;
+            res.Message = "清除失败";
+            return res;
+        }
+        #endregion
 
         /// <summary>
         /// 下发堆垛机任务

+ 74 - 12
SCADA_DAQ/Customer/Service/Wcs_WmsService.cs

@@ -18,12 +18,68 @@ using System.Linq;
 using System.Runtime.Remoting;
 using System.Text;
 using System.Threading.Tasks;
-
+using System.Web;
+using System.Windows.Shell;
 
 namespace SCADA_DAQ.Customer.Service
 {
     public partial class WcsService
     {
+        public ApiResult<object> WmsCancelLow(List<CancelLowBo> cancelLowList)
+        {
+            var res = new ApiResult<object>();
+            if (cancelLowList.Count == 0)
+            {
+                res.IsSucceed = false;
+                return res;
+            }
+            List<AppBCItemTaskModel> appBCItemTaskModels = new List<AppBCItemTaskModel>();
+            cancelLowList.ForEach(item => {
+                appBCItemTaskModels.Add(new AppBCItemTaskModel
+                {
+                    TaskNo = item.No,
+                    ErrorMsg = "取消发货",
+                    State = TaskStateEnum.Close,
+                    EndDate = DateTime.Now,
+                }) ;
+            });
+            var taskDbRes =  Env.DAL.BatchUpdateOrInsert(
+                appBCItemTaskModels,
+                t => new { t.TaskNo },   //更新条件
+                null,
+                t => new { t.ErrorMsg,t.State, t.EndDate }   //更新字段
+             );   //批量更新
+            var cancelQtySumList = cancelLowList.GroupBy(t => new { t.WarehouseCode, t.ItemCode })
+                                              .Select(group => new AppBCInventoryModel { WarehouseCode = group.Key.WarehouseCode, ItemCode = group.Key.ItemCode, Qty = group.Sum(it => it.Qty) })
+                                              .ToList();
+            var sqlStr = "";
+            cancelQtySumList.ForEach(item =>
+            {
+                if (sqlStr == "")
+                {
+                    sqlStr = $"(WarehouseCode_Str= '{item.WarehouseCode}' and ItemCode_Str = '{item.ItemCode}')";
+                }
+                else
+                {
+                    sqlStr = $"{sqlStr} or (WarehouseCode_Str='{item.WarehouseCode}' and ItemCode_Str = '{item.ItemCode}')";
+                }
+            });
+            List<AppBCInventoryModel> appBCInventoryList= Env.DAL.App_BC_Inventory.GetData<AppBCInventoryModel>(sqlStr);
+            var sumQtyInventoryList = cancelQtySumList.Concat(appBCInventoryList).GroupBy(t => new { t.WarehouseCode, t.ItemCode }).Select(group => new AppBCInventoryModel { WarehouseCode = group.Key.WarehouseCode, ItemCode = group.Key.ItemCode, Qty = group.Sum(it => it.Qty) })
+                                          .ToList();
+            var inventoryDbRes = Env.DAL.BatchUpdateOrInsert(
+                sumQtyInventoryList,
+                t => new { t.ItemCode, t.WarehouseCode },   //更新条件
+                null,
+                t => new { t.Qty }   //更新字段
+             );   //批量更新
+            if (inventoryDbRes == false || taskDbRes == false)
+            {
+                res.IsSucceed = false;
+                res.Message = "失败";
+            }
+            return res;
+        }
         /// <summary>
         /// 更改任务状态
         /// </summary>
@@ -260,7 +316,7 @@ namespace SCADA_DAQ.Customer.Service
             var taskNos = "接收下架任务";
             taskList.ForEach(task =>
             {
-                var inventory = inventoryList.Where(i => i.ItemCode == task.ItemCode && i.WarehouseCode == task.WarehouseCode && i.Qty > 0).FirstOrDefault();
+                var inventory = inventoryList.Where(i => i.ItemCode == task.ItemCode && i.WarehouseCode == task.WarehouseCode && i.Qty >= 0).FirstOrDefault();
                 decimal? actualQty = 0m;
                 if (inventory != null && inventory?.Qty >= task.Qty)
                 {
@@ -272,7 +328,6 @@ namespace SCADA_DAQ.Customer.Service
                     actualQty = inventory?.Qty;
                     inventory.Qty -= actualQty;
                 }
-                taskNos = $"{taskNos} {task.No} ";
                 var newTask = new AppBCItemTaskModel
                 {
                     BillNo = task.BillNo,
@@ -314,20 +369,25 @@ namespace SCADA_DAQ.Customer.Service
                     CreateTime = DateTime.Now.ToString(),
                 };
                 wmsTasks.Add(newTask);
-                //wmsHaveSourceLocationTask.Add(newTask.SourceLocation != "" ? newTask : null);
-                if (newTask.SourceLocation != null && newTask.ActualQty != 0m)
+                if (newTask.SourceLocation != null)
                 {
+                    taskNos = $"{taskNos} {task.No} ";
                     wmsHaveSourceLocationTask.Add(newTask);
                 }
+                if (newTask.SourceLocation == null)
+                {
+                    taskNos = $"{taskNos} {task.No}无库位 ";
+                }
             });
             wmsTasks.Sort((item1, item2) => item1.TaskNo.CompareTo(item2.TaskNo)); //排序
             var dbRes = Env.DAL.Insert(wmsTasks);
             Log.Info(taskNos);
+            //wmsHaveSourceLocationTask = wmsHaveSourceLocationTask.Where(t=>!t.WoNo.StartsWith("CS12")).ToList();
             AddDeviceTaskList(wmsHaveSourceLocationTask);
-            wmsUpLoad(wmsHaveSourceLocationTask);
+            //UpLoadWms(wmsHaveSourceLocationTask);
             if (dbRes.IsSucceed == true)
             {
-                res.Message = $"下架任务已接收";
+                res.Message = $"{taskNos}";
                 return res;
             }
             res.IsSucceed = false;
@@ -339,7 +399,7 @@ namespace SCADA_DAQ.Customer.Service
         /// 回传任务信息
         /// </summary>
         /// <param name="task"></param>
-        public static void wmsUpLoad(List<AppBCItemTaskModel> task)
+        public void UpLoadWms(List<AppBCItemTaskModel> task)
         {
             var message = "";
             var itemTaskUpList = new List<AppBCItemTaskModel>();   //更新任务状态
@@ -356,6 +416,7 @@ namespace SCADA_DAQ.Customer.Service
                         itemTaskUpList.Add(new AppBCItemTaskModel
                         {
                             TaskNo = task[i].TaskNo,
+                            EndDate = DateTime.Now,
                             ErrorMsg = wmsRes.Message
                         });
                     }
@@ -366,6 +427,7 @@ namespace SCADA_DAQ.Customer.Service
                         itemTaskUpList.Add(new AppBCItemTaskModel
                         {
                             TaskNo = task[i].TaskNo,
+                            EndDate = DateTime.Now,
                             ErrorMsg = wmsRes.Result.Error
                         });
                     }
@@ -459,10 +521,10 @@ namespace SCADA_DAQ.Customer.Service
             {
                 Env.DAL.BatchUpdateOrInsert(
                  updateInventoryQtyList,
-                 t => new { t.ItemCode, t.SourceLocation, t.WarehouseCode },   //更新条件
+                 t => new { t.ItemCode, t.SourceLocation, t.WarehouseCode },   
                  null,
-                 t => new { t.Qty, t.ItemCode, t.SourceLocation, t.ItemName, t.OnhandState, t.UnitCode, t.WarehouseCode }   //更新字段
-               );   //批量更新
+                 t => new { t.Qty, t.ItemCode, t.SourceLocation, t.ItemName, t.OnhandState, t.UnitCode, t.WarehouseCode }   
+               );   
             }
         }
 
@@ -470,7 +532,7 @@ namespace SCADA_DAQ.Customer.Service
         /// 自动下发堆垛机任务
         /// </summary>
         /// <param name="sourceLocations"></param>
-        public static void AddDeviceTaskList(List<AppBCItemTaskModel> sourceLocations)
+        public void AddDeviceTaskList(List<AppBCItemTaskModel> sourceLocations)
         {
             var sourceLocationGroupBy = sourceLocations.GroupBy(i => i.SourceLocation).Select(j => j.FirstOrDefault()).ToList();
             var sourceLocationList = new List<OperationBo>();