mengshunguo 3 meses atrás
pai
commit
e9f07cf83f

+ 38 - 0
SCADA_DAQ/Customer/Customer_WmsEnv.cs

@@ -17,6 +17,44 @@ namespace SCADA_DAQ.Customer
     {
         public static AutoSaveParameterItem<string> WmsUrl { get; set; } = AutoSaveParameterItem.Create("WmsUrl", "");
 
+        // 回传下架完成给wms
+        public static WmsResVo AutoFinishWmsLowTask(List<AppBCItemTaskModel> wmsLowShelfList)
+        {
+            var wmsUpShelfBoList = new List<WmsLowShelfBo>();
+            for (var i = 0; i < wmsLowShelfList.Count; i++)
+            {
+                wmsUpShelfBoList.Add(new WmsLowShelfBo
+                {
+                    BillNo = wmsLowShelfList[i].BillNo,
+                    No = wmsLowShelfList[i].TaskNo,
+                    EndDate = DateTime.Now,
+                    InvOrg = wmsLowShelfList[i].OrgID,
+                    QTY = wmsLowShelfList[i].ActualQty,
+                    SourceLocation = wmsLowShelfList[i].SourceLocation,
+                    TaskGroupNo = wmsLowShelfList[i].TaskGroupNo,
+                    State = TaskStateEnum.Finish,
+                    LotCode = wmsLowShelfList[i].Lot
+                });
+            }
+            var url = $"http://{WmsUrl.Value}/api/dataportal/invoke";
+            var wmsReqBo = new WmsReqBo<WmsLowShelfBo>();
+            wmsReqBo.ApiType = "ShipmentController";
+            wmsReqBo.Method = "WcsUnGroudingFinish";
+            wmsReqBo.Context = new WmsContext() { InvOrgId = 1, Ticket = "" };
+            wmsReqBo.Parameters = new List<WmsParameterBo<WmsLowShelfBo>>()
+                    {
+                       new WmsParameterBo<WmsLowShelfBo>()
+                       {
+                           Value = wmsUpShelfBoList
+                       }
+                    };
+            var jsonPara = JsonHelper.JsonSerialize(wmsReqBo);
+            var res = CallExternalAPI.HttpPost(url, jsonPara);
+            var objRes = JsonHelper.JsonDeserialize<WmsResVo>(res);
+            return objRes;
+        }
+
+
         // 回传下架完成给wms
         public static WmsResVo FinishWmsLowTask(List<AppBCItemTaskVo> wmsLowShelfList)
         {

+ 122 - 2
SCADA_DAQ/Customer/Service/Wcs_WmsService.cs

@@ -257,7 +257,7 @@ namespace SCADA_DAQ.Customer.Service
             var wmsTasks = new List<AppBCItemTaskModel>();
             var wmsHaveSourceLocationTask = new List<AppBCItemTaskModel>();
             var inventoryList = Env.DAL.App_BC_Inventory.GetData<AppBCInventoryModel>();
-            var taskNos = "";
+            var taskNos = "接收下架任务";
             taskList.ForEach(task =>
             {
                 var inventory = inventoryList.Where(i => i.ItemCode == task.ItemCode && i.WarehouseCode == task.WarehouseCode && i.Qty > 0).FirstOrDefault();
@@ -317,8 +317,8 @@ namespace SCADA_DAQ.Customer.Service
             });
             wmsTasks.Sort((item1, item2) => item1.TaskNo.CompareTo(item2.TaskNo)); //排序
             var dbRes = Env.DAL.Insert(wmsTasks);
-            wmsUpLoad(wmsHaveSourceLocationTask);
             Log.Info(taskNos);
+            wmsUpLoad(wmsHaveSourceLocationTask);
             if (dbRes.IsSucceed == true)
             {
                 res.Message = $"下架任务已接收";
@@ -337,6 +337,126 @@ namespace SCADA_DAQ.Customer.Service
         {
             var sourceLocations = task.ToLookup(i=>i.SourceLocation).Select(j=>j.Key).ToList();
             AddDeviceTaskList(sourceLocations);
+            var message = "";
+            var itemTaskUpList = new List<AppBCItemTaskModel>();   //更新任务状态
+            var successItemTaskQty = new List<AppBCItemTaskModel>();  //更新物料库存
+            if (task != null && task.Count != 0)
+            {
+                for (int i = 0; i < task.Count; i++)
+                {
+                    var wmsRes = CustomerEnv.AutoFinishWmsLowTask(new List<AppBCItemTaskModel> { task[i] });
+                    if (wmsRes.Success == false)
+                    {
+                        message = $@"{wmsRes.Message}";
+                        itemTaskUpList.Add(new AppBCItemTaskModel
+                        {
+                            TaskNo = task[i].TaskNo,
+                            ErrorMsg = wmsRes.Message
+                        });
+                    }
+                    if (wmsRes.Success == true && wmsRes.Result.IsSuccess == false)
+                    {
+                        message = $@"{message} {wmsRes.Result.Error}";
+                        itemTaskUpList.Add(new AppBCItemTaskModel
+                        {
+                            TaskNo = task[i].TaskNo,
+                            ErrorMsg = wmsRes.Result.Error
+                        });
+                    }
+                    if (wmsRes.Success == true && wmsRes.Result.IsSuccess == true)
+                    {
+                        message = $@"{message} {task[i].TaskNo}上传成功";
+                        itemTaskUpList.Add(new AppBCItemTaskModel
+                        {
+                            TaskNo = task[i].TaskNo,
+                            State = TaskStateEnum.Finish,
+                            EndDate = DateTime.Now,
+                            Remark = "1"
+                        });
+                        successItemTaskQty.Add(task[i]);
+                    }
+                }
+            }
+            var updateInventoryQtyList = new List<AppBCInventoryModel>();
+            var updateSumItemQtyList = new List<AppBCInventoryModel>();
+            #region /完成任务更新库存数量逻辑
+            var successItemTaskQtyList = successItemTaskQty.ToLookup(t => new { t.ItemCode, t.SourceLocation, t.WarehouseCode }).ToList();
+            string inventoryFilter = null;
+            foreach (var itemTaskQtyValues in successItemTaskQtyList)
+            {
+                foreach (var itemTaskQtyValue in itemTaskQtyValues)
+                {
+                    if (!updateSumItemQtyList.Any(i => i.ItemCode == itemTaskQtyValue.ItemCode && i.SourceLocation == itemTaskQtyValue.SourceLocation && i.WarehouseCode == itemTaskQtyValue.WarehouseCode))
+                    {
+                        updateSumItemQtyList.Add(new AppBCInventoryModel()
+                        {
+                            ItemCode = itemTaskQtyValue.ItemCode,
+                            SourceLocation = itemTaskQtyValue.SourceLocation,
+                            ItemName = itemTaskQtyValue.ItemName,
+                            OnhandState = 10,
+                            UnitCode = itemTaskQtyValue.UnitCode,
+                            Qty = itemTaskQtyValue.ActualQty,
+                            WarehouseCode = itemTaskQtyValue.WarehouseCode
+                        });
+                    }
+                    else
+                    {
+                        var inventory = updateSumItemQtyList.Where(qty => qty.ItemCode == itemTaskQtyValue.ItemCode && qty.SourceLocation == itemTaskQtyValue.SourceLocation && qty.WarehouseCode == itemTaskQtyValue.WarehouseCode).ToList()[0];
+                        inventory.Qty += itemTaskQtyValue.ActualQty;
+                    }
+                }
+            }
+            //以上foreach为了将相同物料,库区,库位的数量相加
+            for (int j = 0; j < updateSumItemQtyList.Count; j++)
+            {
+                if (inventoryFilter == null)
+                {
+                    inventoryFilter = $" (ItemCode_Str = '{updateSumItemQtyList[j].ItemCode}' and SourceLocation_Str = '{updateSumItemQtyList[j].SourceLocation}' and WarehouseCode_Str = '{updateSumItemQtyList[j].WarehouseCode}') ";
+                }
+                else
+                {
+                    inventoryFilter += $"or (ItemCode_Str = '{updateSumItemQtyList[j].ItemCode}' and SourceLocation_Str = '{updateSumItemQtyList[j].SourceLocation}' and WarehouseCode_Str = '{updateSumItemQtyList[j].WarehouseCode}') ";
+                }
+            }
+            //以上for为了从数据库拿出即将要更新物料库存的所在托盘的当前库存数量
+            var inventoryList = Env.DAL.App_BC_Inventory.GetData<AppBCInventoryModel>(inventoryFilter);
+            for (int i = 0; i < updateSumItemQtyList.Count; i++)
+            {
+                if (inventoryList.Any(j => j.ItemCode == updateSumItemQtyList[i].ItemCode && j.SourceLocation == updateSumItemQtyList[i].SourceLocation && j.WarehouseCode == updateSumItemQtyList[i].WarehouseCode))
+                {
+                    var inventory = inventoryList.Where(qty => qty.ItemCode == updateSumItemQtyList[i].ItemCode && qty.SourceLocation == updateSumItemQtyList[i].SourceLocation && qty.WarehouseCode == updateSumItemQtyList[i].WarehouseCode).ToList()[0];
+                    updateInventoryQtyList.Add(new AppBCInventoryModel()
+                    {
+                        ItemCode = inventory.ItemCode,
+                        SourceLocation = inventory.SourceLocation,
+                        ItemName = inventory.ItemName,
+                        OnhandState = 10,
+                        UnitCode = updateSumItemQtyList[i].UnitCode,
+                        Qty = inventory.Qty - updateSumItemQtyList[i].Qty,
+                        WarehouseCode = inventory.WarehouseCode
+                    });
+                }
+            }
+            //以上for将拿出来的现库存数量减去下架任务得出的数量进行更新库存数量
+            #endregion
+            if (itemTaskUpList.Count != 0)
+            {
+                Env.DAL.BatchUpdateOrInsert(
+                   itemTaskUpList,
+                   t => new { t.TaskNo },
+                   null,
+                   t => new { t.State, t.EndDate, t.Remark, t.ErrorMsg }
+               );
+            }
+            if (updateInventoryQtyList != null && updateInventoryQtyList.Count != 0)
+            {
+                Env.DAL.BatchUpdateOrInsert(
+                 updateInventoryQtyList,
+                 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 }   //更新字段
+               );   //批量更新
+            }
         }
 
         /// <summary>