From bd5e0f950340b020cdf6fecf1977992e1c6e845f Mon Sep 17 00:00:00 2001
From: heshaofeng <heshaofeng@hnkhzn.com>
Date: 星期一, 01 十二月 2025 09:23:56 +0800
Subject: [PATCH] 提交代码
---
项目代码/WMS无仓储版/WIDESEA_WMSServer/WIDESEA_TaskInfoService/TaskService.cs | 525 ++++++++++++++++++++++++++++++++++++++++++++++++++++-----
1 files changed, 472 insertions(+), 53 deletions(-)
diff --git "a/\351\241\271\347\233\256\344\273\243\347\240\201/WMS\346\227\240\344\273\223\345\202\250\347\211\210/WIDESEA_WMSServer/WIDESEA_TaskInfoService/TaskService.cs" "b/\351\241\271\347\233\256\344\273\243\347\240\201/WMS\346\227\240\344\273\223\345\202\250\347\211\210/WIDESEA_WMSServer/WIDESEA_TaskInfoService/TaskService.cs"
index 27d5101..3bea184 100644
--- "a/\351\241\271\347\233\256\344\273\243\347\240\201/WMS\346\227\240\344\273\223\345\202\250\347\211\210/WIDESEA_WMSServer/WIDESEA_TaskInfoService/TaskService.cs"
+++ "b/\351\241\271\347\233\256\344\273\243\347\240\201/WMS\346\227\240\344\273\223\345\202\250\347\211\210/WIDESEA_WMSServer/WIDESEA_TaskInfoService/TaskService.cs"
@@ -16,6 +16,7 @@
#endregion << 鐗� 鏈� 娉� 閲� >>
using AutoMapper;
+using Dm.filter;
using MailKit.Search;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json;
@@ -37,9 +38,12 @@
using WIDESEA_Core.BaseServices;
using WIDESEA_Core.Enums;
using WIDESEA_Core.Helper;
+using WIDESEA_DTO.Allocate;
using WIDESEA_DTO.Basic;
using WIDESEA_DTO.Inbound;
+using WIDESEA_DTO.Outbound;
using WIDESEA_DTO.Task;
+using WIDESEA_IAllocateService;
using WIDESEA_IBasicService;
using WIDESEA_IInboundService;
using WIDESEA_IOutboundService;
@@ -47,6 +51,7 @@
using WIDESEA_IStockService;
using WIDESEA_ITaskInfoService;
using WIDESEA_Model.Models;
+using WIDESEA_Model.Models.Outbound;
namespace WIDESEA_TaskInfoService
{
@@ -61,6 +66,7 @@
private readonly IInboundOrderService _inboundOrderService;
private readonly IInboundOrderDetailService _inboundOrderDetailService;
+ private readonly IRepository<Dt_OutboundBatch> _OutboundBatchRepository;
private readonly IOutboundOrderService _outboundOrderService;
private readonly IOutboundOrderDetailService _outboundOrderDetailService;
private readonly IOutStockLockInfoService _outStockLockInfoService;
@@ -68,7 +74,7 @@
private readonly IESSApiService _eSSApiService;
private readonly IStockService _stockService;
private readonly IRecordService _recordService;
-
+ private readonly IAllocateService _allocateService;
private readonly IInvokeMESService _invokeMESService;
public IRepository<Dt_Task> Repository => BaseDal;
@@ -89,7 +95,7 @@
public List<int> TaskOutboundTypes => typeof(TaskTypeEnum).GetEnumIndexList();
- public TaskService(IRepository<Dt_Task> BaseDal, IMapper mapper, IUnitOfWorkManage unitOfWorkManage, IRepository<Dt_StockInfo> stockRepository, ILocationInfoService locationInfoService, IInboundOrderService inboundOrderService, ILocationStatusChangeRecordService locationStatusChangeRecordService, IESSApiService eSSApiService, ILogger<TaskService> logger, IStockService stockService, IRecordService recordService, IInboundOrderDetailService inboundOrderDetailService, IOutboundOrderService outboundOrderService, IOutboundOrderDetailService outboundOrderDetailService, IInvokeMESService invokeMESService, IOutStockLockInfoService outStockLockInfoService) : base(BaseDal)
+ public TaskService(IRepository<Dt_Task> BaseDal, IMapper mapper, IUnitOfWorkManage unitOfWorkManage, IRepository<Dt_StockInfo> stockRepository, ILocationInfoService locationInfoService, IInboundOrderService inboundOrderService, ILocationStatusChangeRecordService locationStatusChangeRecordService, IESSApiService eSSApiService, ILogger<TaskService> logger, IStockService stockService, IRecordService recordService, IInboundOrderDetailService inboundOrderDetailService, IOutboundOrderService outboundOrderService, IOutboundOrderDetailService outboundOrderDetailService, IInvokeMESService invokeMESService, IOutStockLockInfoService outStockLockInfoService, IAllocateService allocateService, IRepository<Dt_OutboundBatch> outboundBatchRepository) : base(BaseDal)
{
_mapper = mapper;
_unitOfWorkManage = unitOfWorkManage;
@@ -106,6 +112,8 @@
_outboundOrderDetailService = outboundOrderDetailService;
_invokeMESService = invokeMESService;
_outStockLockInfoService = outStockLockInfoService;
+ _allocateService = allocateService;
+ _OutboundBatchRepository = outboundBatchRepository;
}
@@ -122,7 +130,7 @@
if (int.TryParse(taskNum, out var newTaskNum))
{
- task = BaseDal.QueryFirst(x => x.TaskNum == newTaskNum);
+ task = await BaseDal.QueryFirstAsync(x => x.TaskNum == newTaskNum);
if (task == null)
{
return WebResponseContent.Instance.Error("鏈壘鍒颁换鍔′俊鎭�");
@@ -137,10 +145,28 @@
MethodInfo? methodInfo = GetType().GetMethod(((TaskTypeEnum)task.TaskType) + "TaskCompleted");
if (methodInfo != null)
{
- WebResponseContent? responseContent = (WebResponseContent?)methodInfo.Invoke(this, new object[] { task });
- if (responseContent != null)
+ object? taskResult = methodInfo.Invoke(this, new object[] { task });
+ if (taskResult is Task<WebResponseContent> asyncTask)
{
- return responseContent;
+ try
+ {
+ // 3. 寮傛绛夊緟 Task 瀹屾垚锛岃嚜鍔ㄨВ鏋愬嚭 WebResponseContent
+ WebResponseContent responseContent = await asyncTask;
+ if (responseContent != null)
+ {
+ return responseContent;
+ }
+ }
+ catch (AggregateException ex)
+ {
+ _logger.LogError($"TaskService TaskCompleted taskResult: {ex.Message} ");
+ return WebResponseContent.Instance.Error(ex.Message);
+ }
+ catch (Exception ex)
+ {
+ _logger.LogError(ex, $"Unexpected error in {task.TaskType}");
+ return WebResponseContent.Instance.Error(ex.Message);
+ }
}
}
return WebResponseContent.Instance.Error("鏈壘鍒颁换鍔$被鍨嬪搴斾笟鍔″鐞嗛�昏緫");
@@ -156,7 +182,7 @@
/// </summary>
/// <param name="task"></param>
/// <returns></returns>
- public WebResponseContent InboundTaskCompleted(Dt_Task task)
+ public async Task<WebResponseContent> InboundTaskCompleted(Dt_Task task)
{
decimal beforeQuantity = 0;
@@ -247,41 +273,106 @@
{
foreach (var inboundOrder in inboundOrders)
{
- if (inboundOrder != null && inboundOrder.OrderStatus == InOrderStatusEnum.鍏ュ簱瀹屾垚.ObjToInt())
+ if (inboundOrder.OrderType == InOrderTypeEnum.AllocatInbound.ObjToInt())//璋冩嫧鍏ュ簱
{
- var feedmodel = new FeedbackInboundRequestModel
+ if (inboundOrder != null && inboundOrder.OrderStatus == InOrderStatusEnum.鍏ュ簱瀹屾垚.ObjToInt())
{
- reqCode = Guid.NewGuid().ToString(),
- reqTime = DateTime.Now.ToString(),
- business_type = inboundOrder.BusinessType,
- factoryArea = inboundOrder.FactoryArea,
- operationType = 1,
- Operator = inboundOrder.Operator,
- orderNo = inboundOrder.UpperOrderNo,
- status = inboundOrder.OrderStatus,
- details = new List<FeedbackInboundDetailsModel>()
+ var allocate = _allocateService.Repository.QueryData(x => x.OrderNo == inboundOrder.InboundOrderNo).First();
+ var allocatefeedmodel = new AllocateDto
+ {
+ ReqCode = Guid.NewGuid().ToString(),
+ ReqTime = DateTime.Now.ToString(),
+ BusinessType = "2",
+ FactoryArea = inboundOrder.FactoryArea,
+ OperationType = 1,
+ Operator = inboundOrder.Operator,
+ OrderNo = inboundOrder.UpperOrderNo,
+ fromWarehouse = allocate?.FromWarehouse ?? "",
+ toWarehouse = allocate?.ToWarehouse ?? "",
+ Details = new List<AllocateDtoDetail>()
- };
+ };
- var groupedData = inboundOrder.Details.GroupBy(item => new { item.MaterielCode, item.SupplyCode, item.BatchNo, item.lineNo, item.BarcodeUnit, item.WarehouseCode })
- .Select(group => new FeedbackInboundDetailsModel
- {
- materialCode = group.Key.MaterielCode,
- supplyCode = group.Key.SupplyCode,
- batchNo = group.Key.BatchNo,
- lineNo = group.Key.lineNo,
- warehouseCode = group.Key.WarehouseCode,
- // warehouseCode= "1072",
- unit = group.Key.BarcodeUnit,
- barcodes = group.Select(row => new FeedbackBarcodesModel
+ var groupedData = inboundOrder.Details.GroupBy(item => new { item.MaterielCode, item.SupplyCode, item.BatchNo, item.lineNo, item.BarcodeUnit, item.WarehouseCode })
+ .Select(group => new AllocateDtoDetail
{
- barcode = row.Barcode,
- qty = row.BarcodeQty
- }).ToList()
- }).ToList();
- feedmodel.details = groupedData;
+ MaterialCode = group.Key.MaterielCode,
+ LineNo = group.Key.lineNo,
+ WarehouseCode = group.Key.WarehouseCode,
+ Qty = group.Sum(x => x.BarcodeQty),
+ // warehouseCode= "1072",
+ Unit = group.Key.BarcodeUnit,
+ Barcodes = group.Select(row => new BarcodeInfo
+ {
+ Barcode = row.Barcode,
+ Qty = row.BarcodeQty,
+ BatchNo = row.BatchNo,
+ SupplyCode = row.SupplyCode,
+ Unit = row.Unit
+ }).ToList()
+ }).ToList();
+ allocatefeedmodel.Details = groupedData;
- _invokeMESService.FeedbackInbound(feedmodel);
+ var result = await _invokeMESService.FeedbackAllocate(allocatefeedmodel);
+ if (result != null && result.code == 200)
+ {
+ _inboundOrderService.Db.Updateable<Dt_InboundOrder>().SetColumns(it => new Dt_InboundOrder { ReturnToMESStatus = 1 })
+ .Where(it => it.Id == inboundOrder.Id).ExecuteCommand();
+ _inboundOrderDetailService.Db.Updateable<Dt_InboundOrderDetail>().SetColumns(it => new Dt_InboundOrderDetail { ReturnToMESStatus = 1 })
+ .Where(it => it.OrderId == inboundOrder.Id).ExecuteCommand();
+ }
+ }
+ }
+ else if (inboundOrder.OrderType == InOrderTypeEnum.ReCheck.ObjToInt()) //閲嶆鍏ュ簱
+ {
+
+ }
+ else
+ {
+ if (inboundOrder != null && inboundOrder.OrderStatus == InOrderStatusEnum.鍏ュ簱瀹屾垚.ObjToInt())
+ {
+ var feedmodel = new FeedbackInboundRequestModel
+ {
+ reqCode = Guid.NewGuid().ToString(),
+ reqTime = DateTime.Now.ToString(),
+ business_type = inboundOrder.BusinessType,
+ factoryArea = inboundOrder.FactoryArea,
+ operationType = 1,
+ Operator = inboundOrder.Operator,
+ orderNo = inboundOrder.UpperOrderNo,
+ status = inboundOrder.OrderStatus,
+ details = new List<FeedbackInboundDetailsModel>()
+
+ };
+
+ var groupedData = inboundOrder.Details.GroupBy(item => new { item.MaterielCode, item.SupplyCode, item.BatchNo, item.lineNo, item.BarcodeUnit, item.WarehouseCode })
+ .Select(group => new FeedbackInboundDetailsModel
+ {
+ materialCode = group.Key.MaterielCode,
+ supplyCode = group.Key.SupplyCode,
+ batchNo = group.Key.BatchNo,
+ lineNo = group.Key.lineNo,
+ warehouseCode = group.Key.WarehouseCode,
+ qty = group.Sum(x => x.BarcodeQty),
+ // warehouseCode= "1072",
+ unit = group.Key.BarcodeUnit,
+ barcodes = group.Select(row => new FeedbackBarcodesModel
+ {
+ barcode = row.Barcode,
+ qty = row.BarcodeQty
+ }).ToList()
+ }).ToList();
+ feedmodel.details = groupedData;
+
+ var result = await _invokeMESService.FeedbackInbound(feedmodel);
+ if (result != null && result.code == 200)
+ {
+ _inboundOrderService.Db.Updateable<Dt_InboundOrder>().SetColumns(it => new Dt_InboundOrder { ReturnToMESStatus = 1 })
+ .Where(it => it.Id == inboundOrder.Id).ExecuteCommand();
+ _inboundOrderDetailService.Db.Updateable<Dt_InboundOrderDetail>().SetColumns(it => new Dt_InboundOrderDetail { ReturnToMESStatus = 1 })
+ .Where(it => it.OrderId == inboundOrder.Id).ExecuteCommand();
+ }
+ }
}
}
@@ -294,7 +385,14 @@
return WebResponseContent.Instance.OK();
}
- public WebResponseContent OutboundTaskCompleted(Dt_Task task)
+
+ public async Task<WebResponseContent> OutAllocateTaskCompleted(Dt_Task task)
+ {
+ _logger.LogInformation($"TaskService OutAllocateTaskCompleted: {task.TaskNum}");
+
+ return await OutboundTaskCompleted(task);
+ }
+ public async Task<WebResponseContent> OutboundTaskCompleted(Dt_Task task)
{
_logger.LogInformation($"TaskService OutboundTaskCompleted: {task.TaskNum}");
//鏌ヨ揣浣�
@@ -306,19 +404,26 @@
locationInfo.LocationStatus = LocationStatusEnum.Free.ObjToInt();
_locationInfoService.Repository.UpdateData(locationInfo);
- var outloks = _outStockLockInfoService.Db.Queryable<Dt_OutStockLockInfo>().Where(x => x.TaskNum == task.TaskNum).ToList();
- outloks.ForEach(o =>
- {
- o.Status = OutLockStockStatusEnum.宸插嚭搴�.ObjToInt();
- });
- _outStockLockInfoService.Db.Updateable(outloks).ExecuteCommand();
+ var outloks = await _outStockLockInfoService.Db.Queryable<Dt_OutStockLockInfo>().Where(x => x.TaskNum == task.TaskNum).ToListAsync();
- var locationCodes = outloks.Select(it => it.LocationCode).Distinct().ToList();
+ var stockids = outloks.Select(x => x.StockId).ToList();
- //_stockRepository.Db.Updateable<Dt_StockInfo>()
- // .SetColumns(it => new Dt_StockInfo { StockStatus = StockStatusEmun.})
- // .Where(it => locationCodes.Contains(it.LocationCode))
- // .ExecuteCommand();
+ _stockService.StockInfoService.Db.Updateable<Dt_StockInfo>()
+ .SetColumns(it => new Dt_StockInfo
+ {
+ StockStatus = StockStatusEmun.鍑哄簱閿佸畾.ObjToInt()
+ })
+ .Where(it => stockids.Contains(it.Id))
+ .ExecuteCommand();
+
+ _stockService.StockInfoDetailService.Db.Updateable<Dt_StockInfoDetail>()
+ .SetColumns(it => new Dt_StockInfoDetail
+ {
+ Status = StockStatusEmun.鍑哄簱閿佸畾.ObjToInt()
+ })
+ .Where(it => stockids.Contains(it.StockId))
+ .ExecuteCommand();
+
return WebResponseContent.Instance.OK();
@@ -363,12 +468,22 @@
stockInfo.StockStatus = StockStatusEmun.鍏ュ簱瀹屾垚.ObjToInt();
_stockRepository.UpdateData(stockInfo);
+ var outboundOrder = _outboundOrderService.Db.Queryable<Dt_OutboundOrder>().First(x => x.OrderNo == task.OrderNo);
+
task.TaskStatus = TaskStatusEnum.Finish.ObjToInt();
BaseDal.DeleteAndMoveIntoHty(task, App.User.UserId == 0 ? WIDESEA_Core.Enums.OperateTypeEnum.鑷姩瀹屾垚 : OperateTypeEnum.浜哄伐瀹屾垚);
_locationStatusChangeRecordService.AddLocationStatusChangeRecord(locationInfo, beforelocationStatus, StockChangeType.Inbound.ObjToInt(), "", task.TaskNum);
+ if (outboundOrder != null)
+ {
+ await HandleOutboundOrderToMESCompletion(outboundOrder, outboundOrder.OrderNo);
+ }
+ else
+ {
+ _logger.LogInformation($"TaskService InEmptyTaskCompleted: {task.TaskNum} ,鏈壘鍒板嚭搴撳崟銆� ");
+ }
return content;
}
@@ -378,14 +493,318 @@
}
}
- public WebResponseContent InPickTaskCompleted(Dt_Task task)
+ public async Task<WebResponseContent> InPickTaskCompleted(Dt_Task task)
{
_logger.LogInformation($"TaskService InPickTaskCompleted: {task.TaskNum}");
+ try
+ {
+ //鏌ュ簱瀛�
+ Dt_StockInfo stockInfo = await _stockRepository.Db.Queryable<Dt_StockInfo>().Includes(x => x.Details).Where(x => x.PalletCode == task.PalletCode).FirstAsync();
+ if (stockInfo == null)
+ {
+ _logger.LogInformation($"TaskService InPickTaskCompleted: 鏈壘鍒版墭鐩樺搴旂殑缁勭洏淇℃伅.{task.TaskNum}");
+ return WebResponseContent.Instance.Error($"鏈壘鍒版墭鐩樺搴旂殑缁勭洏淇℃伅");
+ }
+ if (stockInfo.Details.Count == 0 && stockInfo.PalletType != PalletTypeEnum.Empty.ObjToInt())
+ {
+ _logger.LogInformation($"TaskService InPickTaskCompleted: 鏈壘鍒拌鎵樼洏搴撳瓨鏄庣粏淇℃伅.{task.TaskNum}");
+ return WebResponseContent.Instance.Error($"鏈壘鍒拌鎵樼洏搴撳瓨鏄庣粏淇℃伅");
+ }
+ //鏌ヨ揣浣�
+ Dt_LocationInfo locationInfo = _locationInfoService.Repository.QueryFirst(x => x.LocationCode == task.TargetAddress);
+ if (locationInfo == null)
+ {
+ _logger.LogInformation($"TaskService InPickTaskCompleted: 鏈壘鍒板搴旂殑缁堢偣璐т綅淇℃伅 {task.TaskNum}.");
+ return WebResponseContent.Instance.Error($"鏈壘鍒板搴旂殑缁堢偣璐т綅淇℃伅");
+ }
+ var beforelocationStatus = locationInfo.LocationStatus;
+ // 鑾峰彇鎵�鏈夊洖搴撲腑鐨勫嚭搴撻攣瀹氳褰�
+ var returnLocks = await _outStockLockInfoService.Db.Queryable<Dt_OutStockLockInfo>()
+ .Where(it => it.OrderNo == task.OrderNo && it.PalletCode == task.PalletCode && it.Status == (int)OutLockStockStatusEnum.鍥炲簱涓�)
+ .ToListAsync();
+ // 鏇存柊鍑哄簱閿佸畾璁板綍鐘舵�佷负鍥炲簱瀹屾垚
+ foreach (var lockInfo in returnLocks)
+ {
+ lockInfo.Status = (int)OutLockStockStatusEnum.宸插洖搴�;
+ }
+ _outStockLockInfoService.Db.Updateable(returnLocks).ExecuteCommand();
- return WebResponseContent.Instance.OK();
+ stockInfo.LocationCode = task.TargetAddress;
+ stockInfo.StockStatus = StockStatusEmun.鍏ュ簱瀹屾垚.ObjToInt();
+ if (stockInfo.Details != null && stockInfo.Details.Any())
+ {
+ stockInfo.Details.ForEach(x =>
+ {
+ x.Status = StockStatusEmun.鍏ュ簱瀹屾垚.ObjToInt();
+ });
+ _stockService.StockInfoDetailService.Repository.UpdateData(stockInfo.Details);
+ }
+
+ _stockService.StockInfoService.Repository.UpdateData(stockInfo);
+
+ await ProcessStockDetailsForReturn(task, stockInfo.Id);
+
+ await DeleteZeroQuantityStockDetails(stockInfo.Id);
+
+ if (stockInfo.PalletType == PalletTypeEnum.Empty.ObjToInt())
+ {
+ locationInfo.LocationStatus = LocationStatusEnum.Pallet.ObjToInt();
+ }
+ else
+ {
+ locationInfo.LocationStatus = LocationStatusEnum.InStock.ObjToInt();
+ }
+ _locationInfoService.Repository.UpdateData(locationInfo);
+ var outboundOrder = _outboundOrderService.Db.Queryable<Dt_OutboundOrder>().First(x => x.OrderNo == task.OrderNo);
+ task.TaskStatus = TaskStatusEnum.Finish.ObjToInt();
+
+ BaseDal.DeleteAndMoveIntoHty(task, App.User.UserId == 0 ? OperateTypeEnum.鑷姩瀹屾垚 : OperateTypeEnum.浜哄伐瀹屾垚);
+ BaseDal.DeleteData(task);
+ _locationStatusChangeRecordService.AddLocationStatusChangeRecord(locationInfo, beforelocationStatus, StockChangeType.Inbound.ObjToInt(), "", task.TaskNum);
+
+ if (outboundOrder != null)
+ {
+ await HandleOutboundOrderToMESCompletion(outboundOrder, outboundOrder.OrderNo);
+ }
+ else
+ {
+ _logger.LogInformation($"TaskService InPickTaskCompleted: {task.TaskNum} ,鏈壘鍒板嚭搴撳崟銆� ");
+ }
+ }
+ catch (Exception ex)
+ {
+ _logger.LogInformation($"TaskService InPickTaskCompleted: {task.TaskNum} , {ex.Message}");
+ }
+ return await Task.FromResult(WebResponseContent.Instance.OK());
}
+
+ private async Task HandleOutboundOrderToMESCompletion(Dt_OutboundOrder outboundOrder, string orderNo)
+ {
+ try
+ {
+ var orderDetails = await _outboundOrderDetailService.Db.Queryable<Dt_OutboundOrderDetail>()
+ .LeftJoin<Dt_OutboundOrder>((o, item) => o.OrderId == item.Id)
+ .Where((o, item) => item.OrderNo == orderNo)
+ .Select((o, item) => o)
+ .ToListAsync();
+
+ bool allCompleted = true;
+ foreach (var detail in orderDetails)
+ {
+ _logger.LogInformation($"TaskService HandleOutboundOrderToMESCompletion: {outboundOrder.OrderNo} , {detail.NeedOutQuantity}");
+ if (detail.OverOutQuantity < detail.NeedOutQuantity)
+ {
+ allCompleted = false;
+ break;
+ }
+ }
+ _logger.LogInformation($"TaskService HandleOutboundOrderToMESCompletion: {outboundOrder.OrderNo} , {allCompleted}");
+ int newStatus = allCompleted ? (int)OutOrderStatusEnum.鍑哄簱瀹屾垚 : (int)OutOrderStatusEnum.鍑哄簱涓�;
+
+ if (outboundOrder.OrderStatus != newStatus)
+ {
+ await _outboundOrderService.Db.Updateable<Dt_OutboundOrder>()
+ .SetColumns(x => x.OrderStatus == newStatus)
+ .Where(x => x.OrderNo == orderNo)
+ .ExecuteCommandAsync();
+
+ }
+ //鍙湁姝e父鍒嗘嫞瀹屾垚鏃舵墠鍚慚ES鍙嶉
+ if (allCompleted && newStatus == (int)OutOrderStatusEnum.鍑哄簱瀹屾垚)
+ {
+
+ if (outboundOrder.OrderType == OutOrderTypeEnum.Allocate.ObjToInt())
+ {
+ var allocate = _allocateService.Repository.QueryData(x => x.UpperOrderNo == outboundOrder.UpperOrderNo).First();
+ var allocatefeedmodel = new AllocateDto
+ {
+ ReqCode = Guid.NewGuid().ToString(),
+ ReqTime = DateTime.Now.ToString(),
+ BusinessType = "3",
+ FactoryArea = outboundOrder.FactoryArea,
+ OperationType = 1,
+ Operator = outboundOrder.Operator,
+ OrderNo = outboundOrder.UpperOrderNo,
+ // documentsNO = outboundOrder.OrderNo,
+ // status = outboundOrder.OrderStatus,
+ fromWarehouse = allocate?.FromWarehouse ?? "",
+ toWarehouse = allocate?.ToWarehouse ?? "",
+ Details = new List<AllocateDtoDetail>()
+
+ };
+ foreach (var detail in orderDetails)
+ {
+ // 鑾峰彇璇ユ槑缁嗗搴旂殑鏉$爜淇℃伅锛堜粠閿佸畾璁板綍锛�
+ var detailLocks = await _outStockLockInfoService.Db.Queryable<Dt_OutStockLockInfo>()
+ .Where(x => x.OrderNo == orderNo &&
+ x.OrderDetailId == detail.Id &&
+ x.Status == (int)OutLockStockStatusEnum.鎷i�夊畬鎴�)
+ .ToListAsync();
+
+ var detailModel = new AllocateDtoDetail
+ {
+ MaterialCode = detail.MaterielCode,
+ LineNo = detail.lineNo, // 娉ㄦ剰锛氳繖閲屽彲鑳介渶瑕佽皟鏁村瓧娈靛悕
+ WarehouseCode = detail.WarehouseCode,
+ Qty = detail.OverOutQuantity, // 浣跨敤璁㈠崟鏄庣粏鐨勫凡鍑哄簱鏁伴噺
+ //currentDeliveryQty = detail.OverOutQuantity,
+ Unit = detail.Unit,
+ Barcodes = detailLocks.Select(lockInfo => new BarcodeInfo
+ {
+ Barcode = lockInfo.CurrentBarcode,
+ SupplyCode = lockInfo.SupplyCode,
+ BatchNo = lockInfo.BatchNo,
+ Unit = lockInfo.Unit,
+ Qty = lockInfo.PickedQty // 鏉$爜绾у埆鐨勬暟閲忎粛鐢ㄩ攣瀹氳褰�
+ }).ToList()
+ };
+
+ allocatefeedmodel.Details.Add(detailModel);
+ }
+ var result = await _invokeMESService.FeedbackAllocate(allocatefeedmodel);
+ if (result != null && result.code == 200)
+ {
+ await _outboundOrderDetailService.Db.Updateable<Dt_OutboundOrderDetail>()
+ .SetColumns(x => x.ReturnToMESStatus == 1)
+ .Where(x => x.OrderId == outboundOrder.Id).ExecuteCommandAsync();
+
+ await _outboundOrderService.Db.Updateable<Dt_OutboundOrder>()
+ .SetColumns(x => new Dt_OutboundOrder
+ {
+ ReturnToMESStatus = 1,
+ Operator = App.User.UserName,
+ }).Where(x => x.OrderNo == orderNo).ExecuteCommandAsync();
+ }
+ }
+ else if (outboundOrder.OrderType == OutOrderTypeEnum.ReCheck.ObjToInt())
+ {
+ //涓嶇敤鍥炰紶
+ }
+ else
+ {
+ var feedmodel = new FeedbackOutboundRequestModel
+ {
+ reqCode = Guid.NewGuid().ToString(),
+ reqTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
+ business_type = outboundOrder.BusinessType,
+ factoryArea = outboundOrder.FactoryArea,
+ operationType = 1,
+ Operator = outboundOrder.Operator,
+ orderNo = outboundOrder.UpperOrderNo,
+ documentsNO = outboundOrder.OrderNo,
+ status = outboundOrder.OrderStatus,
+ details = new List<FeedbackOutboundDetailsModel>()
+ };
+
+
+ foreach (var detail in orderDetails)
+ {
+ // 鑾峰彇璇ユ槑缁嗗搴旂殑鏉$爜淇℃伅锛堜粠閿佸畾璁板綍锛�
+ var detailLocks = await _outStockLockInfoService.Db.Queryable<Dt_OutStockLockInfo>()
+ .Where(x => x.OrderNo == orderNo &&
+ x.OrderDetailId == detail.Id &&
+ x.Status == (int)OutLockStockStatusEnum.鎷i�夊畬鎴�)
+ .ToListAsync();
+
+ var detailModel = new FeedbackOutboundDetailsModel
+ {
+ materialCode = detail.MaterielCode,
+ lineNo = detail.lineNo, // 娉ㄦ剰锛氳繖閲屽彲鑳介渶瑕佽皟鏁村瓧娈靛悕
+ warehouseCode = detail.WarehouseCode,
+ qty = detail.OverOutQuantity, // 浣跨敤璁㈠崟鏄庣粏鐨勫凡鍑哄簱鏁伴噺
+ currentDeliveryQty = detail.OverOutQuantity,
+ unit = detail.Unit,
+ barcodes = detailLocks.Select(lockInfo => new WIDESEA_DTO.Outbound.BarcodesModel
+ {
+ barcode = lockInfo.CurrentBarcode,
+ supplyCode = lockInfo.SupplyCode,
+ batchNo = lockInfo.BatchNo,
+ unit = lockInfo.Unit,
+ qty = lockInfo.PickedQty // 鏉$爜绾у埆鐨勬暟閲忎粛鐢ㄩ攣瀹氳褰�
+ }).ToList()
+ };
+
+ feedmodel.details.Add(detailModel);
+ }
+ var result = await _invokeMESService.FeedbackOutbound(feedmodel);
+ if (result != null && result.code == 200)
+ {
+ await _outboundOrderDetailService.Db.Updateable<Dt_OutboundOrderDetail>()
+ .SetColumns(x => x.ReturnToMESStatus == 1)
+ .Where(x => x.OrderId == outboundOrder.Id)
+ .ExecuteCommandAsync();
+
+ await _outboundOrderService.Db.Updateable<Dt_OutboundOrder>()
+ .SetColumns(x => x.ReturnToMESStatus == 1)
+ .Where(x => x.OrderNo == orderNo)
+ .ExecuteCommandAsync();
+ }
+ }
+ }
+ }
+ catch (Exception ex)
+ {
+ _logger.LogError($"CheckAndUpdateOrderStatus澶辫触 - OrderNo: {orderNo}, Error: {ex.Message}");
+ }
+
+ }
+
+ /// <summary>
+ /// 鍒犻櫎搴撳瓨鏁颁负0鐨勫簱瀛樻槑缁嗚褰�
+ /// </summary>
+ private async Task DeleteZeroQuantityStockDetails(int stockId)
+ {
+ try
+ {
+ // 鍒犻櫎搴撳瓨鏁伴噺涓�0鐨勮褰�
+ var deleteCount = await _stockService.StockInfoDetailService.Db.Deleteable<Dt_StockInfoDetail>()
+ .Where(x => x.StockId == stockId &&
+ x.StockQuantity == 0 &&
+ (x.Status == StockStatusEmun.鍑哄簱瀹屾垚.ObjToInt() || x.Status ==
+ StockStatusEmun.鍏ュ簱瀹屾垚.ObjToInt())) // 鍙垹闄ゅ凡瀹屾垚鐘舵�佺殑闆跺簱瀛�
+ .ExecuteCommandAsync();
+
+ if (deleteCount > 0)
+ {
+ _logger.LogInformation($"鍒犻櫎{deleteCount}鏉¢浂搴撳瓨鏄庣粏璁板綍 - StockId: {stockId}");
+ }
+ }
+ catch (Exception ex)
+ {
+ _logger.LogWarning($"鍒犻櫎闆跺簱瀛樿褰曞け璐� - StockId: {stockId}, Error: {ex.Message}");
+ // 娉ㄦ剰锛氬垹闄ゅけ璐ヤ笉搴旇褰卞搷涓绘祦绋嬶紝璁板綍鏃ュ織鍚庣户缁�
+ }
+ }
+ /// <summary>
+ /// 澶勭悊鍥炲簱鐩稿叧鐨勬墍鏈夊簱瀛樻槑缁嗙姸鎬佸彉鏇�
+ /// </summary>
+ private async Task ProcessStockDetailsForReturn(Dt_Task returnTask, int stockId)
+ {
+ // 鑾峰彇璇ユ墭鐩樹笅鎵�鏈夐渶瑕佸洖搴撶殑搴撳瓨鏄庣粏
+ var stockDetails = await _stockService.StockInfoDetailService.Db.Queryable<Dt_StockInfoDetail>()
+ .Where(x => x.StockId == stockId &&
+ x.StockQuantity > 0 &&
+ (x.Status == StockStatusEmun.鍑哄簱閿佸畾.ObjToInt() || x.Status ==
+ StockStatusEmun.鍏ュ簱纭.ObjToInt())) // 鍖呮嫭鍑哄簱閿佸畾鍜屽叆搴撶‘璁ょ殑
+ .ToListAsync();
+
+ foreach (var detail in stockDetails)
+ {
+
+ detail.Status = StockStatusEmun.鍏ュ簱瀹屾垚.ObjToInt();
+ detail.OutboundQuantity = 0; // 娓呯┖鍑哄簱鏁伴噺
+
+ _logger.LogInformation($"鏇存柊搴撳瓨鏄庣粏鐘舵�� - 鏉$爜: {detail.Barcode}, 鏁伴噺: {detail.StockQuantity}");
+ }
+
+ if (stockDetails.Any())
+ {
+ await _stockService.StockInfoDetailService.Db.Updateable(stockDetails).ExecuteCommandAsync();
+ _logger.LogInformation($"鍏辨洿鏂皗stockDetails.Count}涓簱瀛樻槑缁嗙姸鎬佷负鍏ュ簱瀹屾垚");
+ }
+ }
public async Task<WebResponseContent> OutEmptyTaskCompleted(Dt_Task task)
{
WebResponseContent content = new WebResponseContent();
@@ -414,11 +833,11 @@
task.TaskStatus = TaskStatusEnum.Finish.ObjToInt();
BaseDal.DeleteAndMoveIntoHty(task, App.User.UserId == 0 ? OperateTypeEnum.鑷姩瀹屾垚 : OperateTypeEnum.浜哄伐瀹屾垚);
_stockService.StockInfoService.Repository.DeleteAndMoveIntoHty(stockInfo, App.User.UserId == 0 ? OperateTypeEnum.鑷姩瀹屾垚 : OperateTypeEnum.浜哄伐瀹屾垚);
- _stockRepository.Db.Deleteable(stockInfo).ExecuteCommand();
-
+ //_stockRepository.Db.Deleteable(stockInfo).ExecuteCommand();
+ _stockService.StockInfoService.DeleteData(stockInfo);
_locationStatusChangeRecordService.AddLocationStatusChangeRecord(locationInfo, beforeStatus, StockChangeType.Outbound.ObjToInt(), stockInfo.Details.FirstOrDefault()?.OrderNo ?? "", task.TaskNum);
- return WebResponseContent.Instance.OK();
+ return await Task.FromResult(WebResponseContent.Instance.OK());
}
catch (Exception ex)
--
Gitblit v1.9.3