|
@@ -129,6 +129,8 @@ namespace SCADA_DAQ.Customer.Service
|
|
|
return res;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+
|
|
|
/// <summary>
|
|
|
/// WMS新增下架任务
|
|
|
/// </summary>
|
|
@@ -242,5 +244,289 @@ namespace SCADA_DAQ.Customer.Service
|
|
|
return res;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// WMS新增下架任务-自动
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="taskList"></param>
|
|
|
+ /// <returns></returns>
|
|
|
+ public ApiResult<object> WmsLowAutoShelfTask(List<LowShelfTaskBo> taskList)
|
|
|
+ {
|
|
|
+ var res = new ApiResult<object>();
|
|
|
+ //taskList.Sort((item1, item2) => item1.Qty.CompareTo(item2.Qty)); //按数量排序,先出数量少的
|
|
|
+ var wmsTasks = new List<AppBCItemTaskModel>();
|
|
|
+ var wmsHaveSourceLocationTask = new List<AppBCItemTaskModel>();
|
|
|
+ var inventoryList = Env.DAL.App_BC_Inventory.GetData<AppBCInventoryModel>();
|
|
|
+ var taskNos = "接收下架任务";
|
|
|
+ taskList.ForEach(task =>
|
|
|
+ {
|
|
|
+ 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)
|
|
|
+ {
|
|
|
+ actualQty = task.Qty;
|
|
|
+ inventory.Qty -= actualQty;
|
|
|
+ }
|
|
|
+ taskNos = $"{taskNos} {task.No} ";
|
|
|
+ var newTask = new AppBCItemTaskModel
|
|
|
+ {
|
|
|
+ BillNo = task.BillNo,
|
|
|
+ ItemCode = task.ItemCode,
|
|
|
+ ItemName = task.ItemName,
|
|
|
+ OrgID = task.InvOrg,
|
|
|
+ TaskNo = task.No,
|
|
|
+ State = task.State,
|
|
|
+ OnhandState = task.OnhandState,
|
|
|
+ UnitCode = task.UnitCode,
|
|
|
+ TaskGroupNo = task.TaskGroupNo,
|
|
|
+ TechStation = task.TechStation,
|
|
|
+ ItemExtPropName = task.ItemExtPropName,
|
|
|
+ WarehouseCode = task.WarehouseCode,
|
|
|
+ PlannedQty = task.Qty,
|
|
|
+ ActualQty = (decimal)actualQty,
|
|
|
+ SourceLocation = inventory?.SourceLocation != null ? inventory?.SourceLocation : null,
|
|
|
+ Lot = task.SuggestFromLot,
|
|
|
+ Lpn = task.SuggestFromLpn,
|
|
|
+ TaskType = false, //false为下架,上架为true
|
|
|
+ LotAtt01 = task.LotAtt01,
|
|
|
+ LotAtt02 = task.LotAtt02,
|
|
|
+ LotAtt03 = task.LotAtt03,
|
|
|
+ LotAtt04 = task.LotAtt04,
|
|
|
+ LotAtt05 = task.LotAtt05,
|
|
|
+ LotAtt06 = task.LotAtt06,
|
|
|
+ LotAtt07 = task.LotAtt07,
|
|
|
+ LotAtt08 = task.LotAtt08,
|
|
|
+ LotAtt09 = task.LotAtt09,
|
|
|
+ LotAtt10 = task.LotAtt10,
|
|
|
+ LotAtt11 = task.LotAtt11,
|
|
|
+ LotAtt12 = task.LotAtt12,
|
|
|
+ Remark = "1",
|
|
|
+ WoNo = task.WO_NO,
|
|
|
+ WorkCenter = task.WORK_CENTER,
|
|
|
+ SourceLocationTag = task.SourceLocationTag,
|
|
|
+ SourceLocationGroup = task.SourceLocationTag.Split('-')[0],
|
|
|
+ StorageArea = CustomerEnv.WareHouseAreaDic[task.WarehouseCode],
|
|
|
+ CreateTime = DateTime.Now.ToString(),
|
|
|
+ };
|
|
|
+ wmsTasks.Add(newTask);
|
|
|
+ //wmsHaveSourceLocationTask.Add(newTask.SourceLocation != "" ? newTask : null);
|
|
|
+ if (newTask.SourceLocation != null && newTask.ActualQty != 0m)
|
|
|
+ {
|
|
|
+ wmsHaveSourceLocationTask.Add(newTask);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ wmsTasks.Sort((item1, item2) => item1.TaskNo.CompareTo(item2.TaskNo)); //排序
|
|
|
+ var dbRes = Env.DAL.Insert(wmsTasks);
|
|
|
+ Log.Info(taskNos);
|
|
|
+ wmsUpLoad(wmsHaveSourceLocationTask);
|
|
|
+ if (dbRes.IsSucceed == true)
|
|
|
+ {
|
|
|
+ res.Message = $"下架任务已接收";
|
|
|
+ return res;
|
|
|
+ }
|
|
|
+ res.IsSucceed = false;
|
|
|
+ res.Message = dbRes.ErrorMessage;
|
|
|
+ return res;
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 回传任务信息
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="task"></param>
|
|
|
+ public static void wmsUpLoad(List<AppBCItemTaskModel> task)
|
|
|
+ {
|
|
|
+ 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>
|
|
|
+ /// 自动下发堆垛机任务
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="sourceLocations"></param>
|
|
|
+ public static void AddDeviceTaskList(List<string> sourceLocations)
|
|
|
+ {
|
|
|
+ var sourceLocationList = new List<OperationBo>();
|
|
|
+ var endLine1 = 1;
|
|
|
+ var endLine2 = 3;
|
|
|
+ foreach (var item in sourceLocations)
|
|
|
+ {
|
|
|
+ var sourceLocation = item.Split('-');
|
|
|
+ var crane = 2;
|
|
|
+ var endCol = 65;
|
|
|
+ var endRow = endLine2;
|
|
|
+ if (Convert.ToInt32(sourceLocation[1]) == 1 || Convert.ToInt32(sourceLocation[1]) == 2)
|
|
|
+ {
|
|
|
+ crane = 1;
|
|
|
+ endCol = 47;
|
|
|
+ endRow = endLine1;
|
|
|
+ }
|
|
|
+ sourceLocationList.Add(new OperationBo()
|
|
|
+ {
|
|
|
+ StartRow = Convert.ToInt32(sourceLocation[1]),
|
|
|
+ StartCol = Convert.ToInt32(sourceLocation[2]),
|
|
|
+ StartLayer = Convert.ToInt32(sourceLocation[3]),
|
|
|
+ IsStart = false,
|
|
|
+ OperateNo = Guid.NewGuid().ToString(),
|
|
|
+ MachineTaskId = 5,
|
|
|
+ Crane = crane,
|
|
|
+ Line = endRow,
|
|
|
+ EndRow = endRow,
|
|
|
+ EndCol = endCol,
|
|
|
+ EndLayer = 1,
|
|
|
+ });
|
|
|
+ if ((Convert.ToInt32(sourceLocation[1]) == 01 || Convert.ToInt32(sourceLocation[1]) == 02) && endLine1 == 1)
|
|
|
+ {
|
|
|
+ endLine1 = 2;
|
|
|
+ }
|
|
|
+ else if ((Convert.ToInt32(sourceLocation[1]) == 01 || Convert.ToInt32(sourceLocation[1]) == 02) && endLine1 == 2)
|
|
|
+ {
|
|
|
+ endLine1 = 1;
|
|
|
+ }
|
|
|
+ if ((Convert.ToInt32(sourceLocation[1]) == 03 || Convert.ToInt32(sourceLocation[1]) == 04) && endLine2 == 3)
|
|
|
+ {
|
|
|
+ endLine2 = 4;
|
|
|
+ }
|
|
|
+ else if ((Convert.ToInt32(sourceLocation[1]) == 03 || Convert.ToInt32(sourceLocation[1]) == 04) && endLine2 == 4)
|
|
|
+ {
|
|
|
+ endLine2 = 3;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ var operationCrane1List = sourceLocationList.Where(i => i.Crane == 1).ToList();
|
|
|
+ var operationCrane2List = sourceLocationList.Where(i => i.Crane == 2).ToList();
|
|
|
+ operationCrane1List.ForEach(t =>
|
|
|
+ {
|
|
|
+ if (!CustomerEnv.OperationCrane1List.Any(i => i.StartLayer == t.StartLayer && i.StartCol == t.StartCol && i.StartRow == t.StartRow))
|
|
|
+ {
|
|
|
+ CustomerEnv.OperationCrane1List.Add(t);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ operationCrane2List.ForEach(t =>
|
|
|
+ {
|
|
|
+ if (!CustomerEnv.OperationCrane2List.Any(i => i.StartLayer == t.StartLayer && i.StartCol == t.StartCol && i.StartRow == t.StartRow))
|
|
|
+ {
|
|
|
+ CustomerEnv.OperationCrane2List.Add(t);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
}
|
|
|
}
|