From f12af5485a50736494ca034c5fae753386587412 Mon Sep 17 00:00:00 2001
From: 647556386 <647556386@qq.com>
Date: 星期四, 18 十二月 2025 22:17:29 +0800
Subject: [PATCH] 1
---
项目代码/WMS无仓储版/WIDESEA_WMSServer/WIDESEA_TaskInfoService/TaskService.cs | 511 ++++++++++++++++++++++++++++++++++++++++++++++----------
1 files changed, 419 insertions(+), 92 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 80aec45..61ec000 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"
@@ -41,10 +41,13 @@
using WIDESEA_Core.BaseServices;
using WIDESEA_Core.Enums;
using WIDESEA_Core.Helper;
+using WIDESEA_Core.Util;
using WIDESEA_DTO.Allocate;
+using WIDESEA_DTO.Base;
using WIDESEA_DTO.Basic;
using WIDESEA_DTO.Inbound;
using WIDESEA_DTO.Outbound;
+using WIDESEA_DTO.ReturnMES;
using WIDESEA_DTO.Task;
using WIDESEA_IAllocateService;
using WIDESEA_IBasicService;
@@ -56,6 +59,7 @@
using WIDESEA_Model.Models;
using WIDESEA_Model.Models.Check;
using WIDESEA_Model.Models.Outbound;
+using static HslCommunication.Profinet.Knx.KnxCode;
namespace WIDESEA_TaskInfoService
{
@@ -85,6 +89,10 @@
private readonly IAllocateService _allocateService;
private readonly IInvokeMESService _invokeMESService;
private readonly ITask_HtyService _task_HtyService;
+ private readonly IRepository<Dt_AllocateMaterialInfo> _allocateMaterialInfo;
+ private readonly IRepository<Dt_AllocateMaterialInfo_Hty> _allocateMaterialInfo_Hty;
+ private readonly HttpClientHelper _httpClientHelper;
+ private readonly IBasicService _basicService;
public IRepository<Dt_Task> Repository => BaseDal;
private Dictionary<string, SqlSugar.OrderByType> _taskOrderBy = new()
@@ -104,7 +112,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, IAllocateService allocateService, IRepository<Dt_OutboundBatch> outboundBatchRepository, IRepository<Dt_ReCheckOrder> reCheckOrderRepository, IRepository<Dt_AllocateOrderDetail> allocateOrderDetailRepository, IRepository<Dt_AllocateOrder> allocateOrderRepository, IMaterialUnitService materialUnitService, ITask_HtyService task_HtyService) : 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, IRepository<Dt_ReCheckOrder> reCheckOrderRepository, IRepository<Dt_AllocateOrderDetail> allocateOrderDetailRepository, IRepository<Dt_AllocateOrder> allocateOrderRepository, IMaterialUnitService materialUnitService, ITask_HtyService task_HtyService, IRepository<Dt_AllocateMaterialInfo> allocateMaterialInfo, IRepository<Dt_AllocateMaterialInfo_Hty> allocateMaterialInfo_Hty, HttpClientHelper httpClientHelper, IBasicService basicService) : base(BaseDal)
{
_mapper = mapper;
_unitOfWorkManage = unitOfWorkManage;
@@ -128,6 +136,10 @@
_allocateOrderRepository = allocateOrderRepository;
_materialUnitService = materialUnitService;
_task_HtyService = task_HtyService;
+ _allocateMaterialInfo = allocateMaterialInfo;
+ _allocateMaterialInfo_Hty = allocateMaterialInfo_Hty;
+ _httpClientHelper = httpClientHelper;
+ _basicService = basicService;
}
public async Task TaskStatusChange(string taskNum, TaskStatusEnum taskStatusEnum)
@@ -292,14 +304,21 @@
task.TaskStatus = TaskStatusEnum.Finish.ObjToInt();
// BaseDal.DeleteAndMoveIntoHty(task, App.User.UserId == 0 ? OperateTypeEnum.鑷姩瀹屾垚 : OperateTypeEnum.浜哄伐瀹屾垚);
- var result = _task_HtyService.DeleteAndMoveIntoHty(task, OperateTypeEnum.浜哄伐鍒犻櫎);
+ var result = _task_HtyService.DeleteAndMoveIntoHty(task, OperateTypeEnum.鑷姩瀹屾垚);
if (!result)
{
await Db.Deleteable(task).ExecuteCommandAsync();
}
- _locationStatusChangeRecordService.AddLocationStatusChangeRecord(locationInfo, beforeStatus, StockChangeType.Inbound.ObjToInt(), "", task.TaskNum);
+ try
+ {
+ _locationStatusChangeRecordService.AddLocationStatusChangeRecord(locationInfo, beforeStatus, StockChangeType.Inbound.ObjToInt(), "", task.TaskNum);
- _recordService.StockQuantityChangeRecordService.AddStockChangeRecord(stockInfo, stockInfo.Details, beforeQuantity, stockInfo.Details.Sum(x => x.StockQuantity) + beforeQuantity, WIDESEA_Common.StockEnum.StockChangeType.MaterielGroup);
+ _recordService.StockQuantityChangeRecordService.AddStockChangeRecord(stockInfo, stockInfo.Details, beforeQuantity, stockInfo.Details.Sum(x => x.StockQuantity) + beforeQuantity, WIDESEA_Common.StockEnum.StockChangeType.MaterielGroup);
+ }
+ catch (Exception ex)
+ {
+ _logger.LogInformation($"InboundTaskCompleted AddLocationStatusChangeRecord : {ex.Message} ");
+ }
try
{
foreach (var inboundOrder in inboundOrders)
@@ -344,8 +363,10 @@
}).ToList();
allocatefeedmodel.Details = groupedData;
- var feedbackresult = await _invokeMESService.FeedbackAllocate(allocatefeedmodel);
- if (feedbackresult != null && feedbackresult.code == 200)
+ //var feedbackresult = await _invokeMESService.FeedbackAllocate(allocatefeedmodel);
+
+ var response = responseModel(inboundOrder, 3, null, allocatefeedmodel);
+ if (response != null && response.IsSuccess)
{
_inboundOrderService.Db.Updateable<Dt_InboundOrder>().SetColumns(it => new Dt_InboundOrder { ReturnToMESStatus = 1 })
.Where(it => it.Id == inboundOrder.Id).ExecuteCommand();
@@ -448,8 +469,11 @@
}).ToList();
feedmodel.details = groupedData;
- var feedbackresult = await _invokeMESService.FeedbackInbound(feedmodel);
- if (feedbackresult != null && feedbackresult.code == 200)
+ //var feedbackresult = await _invokeMESService.FeedbackInbound(feedmodel);
+
+ var response= responseModel(inboundOrder,2, feedmodel);
+
+ if (response != null && response.IsSuccess)
{
_inboundOrderService.Db.Updateable<Dt_InboundOrder>().SetColumns(it => new Dt_InboundOrder { ReturnToMESStatus = 1, Remark = "" })
.Where(it => it.Id == inboundOrder.Id).ExecuteCommand();
@@ -458,7 +482,7 @@
}
else
{
- _inboundOrderService.Db.Updateable<Dt_InboundOrder>().SetColumns(it => new Dt_InboundOrder { ReturnToMESStatus = 2, Remark = feedbackresult.message })
+ _inboundOrderService.Db.Updateable<Dt_InboundOrder>().SetColumns(it => new Dt_InboundOrder { ReturnToMESStatus = 2, Remark = response.ErrorMessage })
.Where(it => it.Id == inboundOrder.Id).ExecuteCommand();
_inboundOrderDetailService.Db.Updateable<Dt_InboundOrderDetail>().SetColumns(it => new Dt_InboundOrderDetail { ReturnToMESStatus = 2 })
.Where(it => it.OrderId == inboundOrder.Id).ExecuteCommand();
@@ -474,6 +498,61 @@
}
return WebResponseContent.Instance.OK();
+ }
+
+ public HttpResponseResult<MesResponseDTO> responseModel(Dt_InboundOrder order, int InterfaceType, FeedbackInboundRequestModel model = null, AllocateDto allocateDto = null)
+ {
+ HttpResponseResult<MesResponseDTO> httpResponseResult = new HttpResponseResult<MesResponseDTO>();
+ string reqCode = Guid.NewGuid().ToString();
+ string reqTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
+ string requestData = string.Empty;
+ string apiUrl = string.Empty;
+ if (model != null)
+ {
+ apiUrl = AppSettings.GetValue("AldMaterialWarehousing");
+ httpResponseResult = _httpClientHelper.Post<MesResponseDTO>(apiUrl, model.Serialize());
+ requestData = model.Serialize();
+ }
+ else
+ {
+ apiUrl = AppSettings.GetValue("AldAllocationOperation");
+ httpResponseResult = _httpClientHelper.Post<MesResponseDTO>(apiUrl, allocateDto.Serialize());
+ requestData = allocateDto.Serialize();
+ }
+ httpResponseResult.ApiUrl = apiUrl;
+ bool isSuccess = httpResponseResult.IsSuccess && httpResponseResult.Data.Code == "200";
+ string message = "鎴愬姛";
+ if (!isSuccess)
+ {
+ if (!httpResponseResult.IsSuccess)
+ {
+ message = $"MES鎺ュ彛杩斿洖閿欒锛孒TTP浠g爜锛歿httpResponseResult.StatusCode}锛屼俊鎭細{httpResponseResult.ErrorMessage}";
+ }
+ else if (httpResponseResult?.Data?.Code != "200")
+ {
+ message = $"璋冪敤MES鎺ュ彛澶辫触锛屼唬鐮侊細{httpResponseResult?.Data?.Code}锛屼俊鎭細{httpResponseResult?.Data?.Message}";
+ }
+ }
+ Dt_MesReturnRecord mesReturnRecord = new Dt_MesReturnRecord()
+ {
+ ApiUrl = httpResponseResult.ApiUrl,
+ InterfaceType = InterfaceType,
+ OrderId = order.Id,
+ OrderNo = order.InboundOrderNo,
+ RequestCode = reqCode,
+ RequestData = requestData,
+ FailureReason = message,
+ LastReturnTime = DateTime.Now,
+ HttpStatusCode = httpResponseResult.StatusCode.ObjToInt(),
+ ResponseData = httpResponseResult.Content,
+ ReturnType = 0,
+ ReturnCount = 1,
+ ReturnStatus = httpResponseResult.IsSuccess ? 1 : 2,
+ SuccessTime = httpResponseResult.IsSuccess ? DateTime.Now : null
+ };
+ _unitOfWorkManage.Db.Insertable(mesReturnRecord).ExecuteCommand();
+
+ return httpResponseResult;
}
@@ -495,27 +574,27 @@
locationInfo.LocationStatus = LocationStatusEnum.Free.ObjToInt();
_locationInfoService.Repository.UpdateData(locationInfo);
- var outloks = await _outStockLockInfoService.Db.Queryable<Dt_OutStockLockInfo>().Where(x => x.TaskNum == task.TaskNum).ToListAsync();
-
- var stockids = outloks.Select(x => x.StockId).ToList();
-
- _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();
+ var stock = _stockService.StockInfoService.Db.Queryable<Dt_StockInfo>()
+ .Includes(x => x.Details)
+ .Where(x => x.PalletCode == task.PalletCode)
+ .First();
+ stock.StockStatus = StockStatusEmun.鍑哄簱瀹屾垚.ObjToInt();
+ stock.LocationCode = "";
+
+ stock.Details.ForEach(x =>
+ {
+ x.Status = StockStatusEmun.鍑哄簱瀹屾垚.ObjToInt();
+ });
+
+ _stockService.StockInfoService.Db.UpdateNav(stock).IncludesAllFirstLayer().ExecuteCommand();
+
+ var result = _task_HtyService.DeleteAndMoveIntoHty(task, OperateTypeEnum.鑷姩瀹屾垚);
+ if (!result)
+ {
+ await Db.Deleteable(task).ExecuteCommandAsync();
+ }
return WebResponseContent.Instance.OK();
@@ -559,32 +638,199 @@
stockInfo.StockStatus = StockStatusEmun.鍏ュ簱瀹屾垚.ObjToInt();
_stockRepository.UpdateData(stockInfo);
- var outboundOrder = _outboundOrderService.Db.Queryable<Dt_OutboundOrder>().First(x => x.OrderNo == task.OrderNo);
+ //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.浜哄伐瀹屾垚);
var result = _task_HtyService.DeleteAndMoveIntoHty(task, OperateTypeEnum.浜哄伐鍒犻櫎);
if (!result)
{
await Db.Deleteable(task).ExecuteCommandAsync();
}
- _locationStatusChangeRecordService.AddLocationStatusChangeRecord(locationInfo, beforelocationStatus, StockChangeType.Inbound.ObjToInt(), "", task.TaskNum);
-
-
- if (outboundOrder != null)
+ try
{
- await HandleOutboundOrderToMESCompletion(outboundOrder, outboundOrder.OrderNo);
+ _locationStatusChangeRecordService.AddLocationStatusChangeRecord(locationInfo, beforelocationStatus, StockChangeType.Inbound.ObjToInt(), "", task.TaskNum);
}
- else
+ catch (Exception ex)
{
- _logger.LogInformation($"TaskService InEmptyTaskCompleted: {task.TaskNum} ,鏈壘鍒板嚭搴撳崟銆� ");
+ _logger.LogInformation($"InEmptyTaskCompleted AddLocationStatusChangeRecord : {ex.Message} ");
}
+
+ //if (outboundOrder != null)
+ //{
+ // await HandleOutboundOrderToMESCompletion(outboundOrder, outboundOrder.OrderNo);
+ //}
+ //else
+ //{
+ // _logger.LogInformation($"TaskService InEmptyTaskCompleted: {task.TaskNum} ,鏈壘鍒板嚭搴撳崟銆� ");
+ //}
return content;
}
catch (Exception ex)
{
return await Task.FromResult(WebResponseContent.Instance.Error(ex.Message));
+ }
+ }
+ /// <summary>
+ /// 鏅轰粨璋冨叆鏅轰粨瀹屾垚
+ /// </summary>
+ /// <param name="task"></param>
+ /// <returns></returns>
+ public async Task<WebResponseContent> AllocateInWarehouseTaskCompleted(Dt_Task task)
+ {
+
+ WebResponseContent content = new WebResponseContent();
+ try
+ {
+
+ Dt_StockInfo stockInfo = await _stockRepository.Db.Queryable<Dt_StockInfo>()
+ .Includes(x => x.Details)
+ .Where(x => x.PalletCode == task.PalletCode)
+ .FirstAsync();
+
+ if (stockInfo == null)
+ {
+ 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)
+ {
+ return content.Error($"鏈壘鍒板搴旂殑缁堢偣璐т綅淇℃伅");
+ }
+
+ if (!string.IsNullOrEmpty(stockInfo.LocationCode))
+ {
+ return WebResponseContent.Instance.Error($"璇ユ墭鐩樺凡缁戝畾璐т綅");
+ }
+ if (locationInfo.LocationStatus == LocationStatusEnum.InStock.ObjToInt())
+ {
+ return WebResponseContent.Instance.Error($"璐т綅鐘舵�佷笉姝g‘");
+ }
+ List<Dt_AllocateMaterialInfo> allocateMaterialInfos = _allocateMaterialInfo.QueryData(x => x.OrderNo == stockInfo.Details.FirstOrDefault().OrderNo);
+ if(allocateMaterialInfos == null)
+ {
+ return content.Error("鏈壘鍒板叆鏅轰粨鐨勭墿鏂欎俊鎭�");
+ }
+ _unitOfWorkManage.BeginTran();
+ var alldelete = _allocateMaterialInfo.DeleteAndMoveIntoHty(allocateMaterialInfos ,OperateTypeEnum.鑷姩鍒犻櫎);
+ if (!alldelete)
+ {
+ await Db.Deleteable(task).ExecuteCommandAsync();
+ }
+
+ var beforelocationStatus = locationInfo.LocationStatus;
+ locationInfo.LocationStatus = LocationStatusEnum.InStock.ObjToInt();
+ _locationInfoService.Repository.UpdateData(locationInfo);
+
+ stockInfo.LocationCode = locationInfo.LocationCode;
+ stockInfo.PalletCode = task.PalletCode;
+ stockInfo.LocationCode = task.TargetAddress;
+ stockInfo.StockStatus = StockStatusEmun.鍏ュ簱瀹屾垚.ObjToInt();
+ _stockRepository.UpdateData(stockInfo);
+
+ task.TaskStatus = TaskStatusEnum.Finish.ObjToInt();
+ var result = _task_HtyService.DeleteAndMoveIntoHty(task, OperateTypeEnum.鑷姩瀹屾垚);
+ _unitOfWorkManage.CommitTran();
+ if (!result)
+ {
+ await Db.Deleteable(task).ExecuteCommandAsync();
+ }
+ Dt_OutboundOrder outboundOrder = _outboundOrderService.Db.Queryable<Dt_OutboundOrder>().Where(x => x.OrderNo == stockInfo.Details.FirstOrDefault().OrderNo).Includes(x=>x.Details).First();
+
+ if(outboundOrder.OrderStatus == OutOrderStatusEnum.鍑哄簱瀹屾垚.ObjToInt())
+ {
+ HttpResponseResult<MesResponseDTO> httpResponseResult = new HttpResponseResult<MesResponseDTO>();
+ string reqCode = Guid.NewGuid().ToString();
+ string reqTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
+ string requestData = string.Empty;
+ List<string> lineNos = new List<string>();
+ Dt_AllocateOrder allocateOrder = _allocateOrderRepository.QueryFirst(x => x.OrderNo == outboundOrder.OrderNo);
+ if (allocateOrder == null)
+ {
+ return WebResponseContent.Instance.Error($"鏈壘鍒板搴旂殑璋冩嫧鍗�");
+ }
+ AllocationReturnDTO? returnDTO = BuildAllocationFeedbackData(outboundOrder, allocateOrder.FromWarehouse, allocateOrder.ToWarehouse);
+ if (returnDTO == null)
+ {
+ return WebResponseContent.Instance.Error($"鏋勫缓鍥炶皟瀵硅薄澶辫触");
+ }
+ string apiUrl = AppSettings.GetValue("AllocationFeedbackUrl"); ;
+ returnDTO.ReqCode = reqCode;
+ returnDTO.ReqTime = reqTime;
+ requestData = returnDTO.Serialize();
+ lineNos = returnDTO.Details.Select(x => x.LineNo).ToList();
+ httpResponseResult = _httpClientHelper.Post<MesResponseDTO>(apiUrl, requestData);
+ httpResponseResult.ApiUrl = apiUrl;
+ }
+ try
+ {
+ _locationStatusChangeRecordService.AddLocationStatusChangeRecord(locationInfo, beforelocationStatus, StockChangeType.Inbound.ObjToInt(), "", task.TaskNum);
+ }
+ catch (Exception ex)
+ {
+ _logger.LogInformation($"InEmptyTaskCompleted AddLocationStatusChangeRecord : {ex.Message} ");
+ }
+ return content;
+ }
+ catch (Exception ex)
+ {
+ _unitOfWorkManage.RollbackTran();
+ return await Task.FromResult(WebResponseContent.Instance.Error(ex.Message));
+ }
+ }
+
+ public AllocationReturnDTO? BuildAllocationFeedbackData(Dt_OutboundOrder outboundOrder, string fromWarehouse, string toWarehouse)
+ {
+ try
+ {
+ List<Dt_OutboundOrderDetail> details = outboundOrder.Details;
+
+ List<AllocationDetail> returnDetails = new List<AllocationDetail>();
+
+ foreach (var detail in details)
+ {
+ List<Barcodes>? barcodes = JsonConvert.DeserializeObject<List<Barcodes>>(detail.ReturnJsonData);
+ if (barcodes != null && barcodes.Any())
+ {
+ UnitConvertResultDTO currentResult = _basicService.UnitQuantityConvert(detail.MaterielCode, detail.Unit, detail.BarcodeUnit, detail.CurrentDeliveryQty);
+ UnitConvertResultDTO totalResult = _basicService.UnitQuantityConvert(detail.MaterielCode, detail.Unit, detail.BarcodeUnit, detail.OrderQuantity);
+
+ returnDetails.Add(new AllocationDetail
+ {
+ Barcodes = barcodes,
+ BatchNo = detail.BatchNo,
+ LineNo = detail.lineNo,
+ MaterialCode = detail.MaterielCode,
+ Qty = totalResult.ToQuantity,
+ WarehouseCode = detail.WarehouseCode,
+ Unit = detail.BarcodeUnit
+ });
+ }
+ }
+
+ AllocationReturnDTO outboundReturnDTO = new AllocationReturnDTO()
+ {
+ Business_type = outboundOrder.BusinessType,
+ Details = returnDetails,
+ FactoryArea = outboundOrder.FactoryArea,
+ OperationType = 1,
+ OrderNo = outboundOrder.OrderNo,
+ FromWarehouse = fromWarehouse,
+ ToWarehouse = toWarehouse
+ };
+
+ return outboundReturnDTO;
+
+ }
+ catch (Exception ex)
+ {
+ return null;
}
}
@@ -623,23 +869,23 @@
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();
+ //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.宸插洖搴�;
- }
+ //foreach (var lockInfo in returnLocks)
+ //{
+ // lockInfo.Status = (int)OutLockStockStatusEnum.宸插洖搴�;
+ //}
- if (returnLocks.Any())
- {
- await _outStockLockInfoService.Db.Updateable(returnLocks).ExecuteCommandAsync();
- _logger.LogInformation($"鏇存柊{returnLocks.Count}鏉¢攣瀹氳褰曚负宸插洖搴撶姸鎬�");
- }
+ //if (returnLocks.Any())
+ //{
+ // await _outStockLockInfoService.Db.Updateable(returnLocks).ExecuteCommandAsync();
+ // _logger.LogInformation($"鏇存柊{returnLocks.Count}鏉¢攣瀹氳褰曚负宸插洖搴撶姸鎬�");
+ //}
// 鏇存柊搴撳瓨淇℃伅
stockInfo.LocationCode = task.TargetAddress;
@@ -651,7 +897,7 @@
foreach (var detail in stockInfo.Details)
{
detail.Status = StockStatusEmun.鍏ュ簱瀹屾垚.ObjToInt();
- detail.OutboundQuantity = 0; // 鍏ュ簱瀹屾垚鏃跺嚭搴撴暟閲忔竻闆�
+ detail.OutboundQuantity = 0;
}
_stockService.StockInfoDetailService.Repository.UpdateData(stockInfo.Details);
}
@@ -660,7 +906,7 @@
// 鍒犻櫎闆跺簱瀛樻暟鎹�
await DeleteZeroQuantityStockDetails(stockInfo.Id);
- await UpdateAffectedOrderDetails(task.OrderNo, returnLocks);
+ //await UpdateAffectedOrderDetails(task.OrderNo, returnLocks);
// 鏇存柊璐т綅鐘舵��
if (stockInfo.PalletType == PalletTypeEnum.Empty.ObjToInt())
{
@@ -683,43 +929,50 @@
{
await Db.Deleteable(task).ExecuteCommandAsync();
}
- // 璁板綍璐т綅鐘舵�佸彉鏇�
- _locationStatusChangeRecordService.AddLocationStatusChangeRecord(
- locationInfo,
- beforelocationStatus,
- StockChangeType.Inbound.ObjToInt(),
- "",
- task.TaskNum
- );
- await RecalculateOrderStatus(task.OrderNo);
-
- _logger.LogInformation($"鎵樼洏鍥炲簱瀹屾垚澶勭悊鎴愬姛 - 浠诲姟鍙�: {task.TaskNum}, 鎵樼洏: {task.PalletCode}, 璁㈠崟: {task.OrderNo}");
- _ = Task.Run(async () =>
+ //await RecalculateOrderStatus(task.OrderNo);
+ try
{
- try
- {
- var outboundOrder = await _outboundOrderService.Db.Queryable<Dt_OutboundOrder>()
- .FirstAsync(x => x.OrderNo == task.OrderNo);
+ // 璁板綍璐т綅鐘舵�佸彉鏇�
+ _locationStatusChangeRecordService.AddLocationStatusChangeRecord(
+ locationInfo,
+ beforelocationStatus,
+ StockChangeType.Inbound.ObjToInt(),
+ "",
+ task.TaskNum
+ );
+ }
+ catch (Exception ex)
+ {
+ _logger.LogInformation($"InPickTaskCompleted AddLocationStatusChangeRecord : {ex.Message} ");
+ }
- if (outboundOrder != null)
- {
- // 妫�鏌ヨ鍗曟槸鍚﹀凡瀹屾垚锛屽彧鏈夊畬鎴愭椂鎵嶅悜MES鍙嶉
- if (outboundOrder.OrderStatus == (int)OutOrderStatusEnum.鍑哄簱瀹屾垚)
- {
- await HandleOutboundOrderToMESCompletion(outboundOrder, outboundOrder.OrderNo);
- }
- else
- {
- _logger.LogInformation($"璁㈠崟{task.OrderNo}鐘舵�佷负{outboundOrder.OrderStatus}锛屾殏涓嶅悜MES鍙嶉");
- }
- }
- }
- catch (Exception ex)
- {
- _logger.LogError($"寮傛MES鍙嶉澶勭悊澶辫触 - OrderNo: {task.OrderNo}, Error: {ex.Message}");
- }
- });
+ //_logger.LogInformation($"鎵樼洏鍥炲簱瀹屾垚澶勭悊鎴愬姛 - 浠诲姟鍙�: {task.TaskNum}, 鎵樼洏: {task.PalletCode}, 璁㈠崟: {task.OrderNo} 璐т綅鐘舵�侊細{locationInfo.LocationStatus}");
+ //_ = Task.Run(async () =>
+ //{
+ // try
+ // {
+ // var outboundOrder = await _outboundOrderService.Db.Queryable<Dt_OutboundOrder>()
+ // .FirstAsync(x => x.OrderNo == task.OrderNo);
+
+ // if (outboundOrder != null)
+ // {
+ // // 妫�鏌ヨ鍗曟槸鍚﹀凡瀹屾垚锛屽彧鏈夊畬鎴愭椂鎵嶅悜MES鍙嶉
+ // if (outboundOrder.OrderStatus == (int)OutOrderStatusEnum.鍑哄簱瀹屾垚)
+ // {
+ // await HandleOutboundOrderToMESCompletion(outboundOrder, outboundOrder.OrderNo);
+ // }
+ // else
+ // {
+ // _logger.LogInformation($"璁㈠崟{task.OrderNo}鐘舵�佷负{outboundOrder.OrderStatus}锛屾殏涓嶅悜MES鍙嶉");
+ // }
+ // }
+ // }
+ // catch (Exception ex)
+ // {
+ // _logger.LogError($"寮傛MES鍙嶉澶勭悊澶辫触 - OrderNo: {task.OrderNo}, Error: {ex.Message}");
+ // }
+ //});
}
catch (Exception ex)
{
@@ -737,8 +990,8 @@
{
try
{
-
-
+
+
// 鑾峰彇鍙楀奖鍝嶇殑璁㈠崟鏄庣粏ID锛堝幓閲嶏級
//var affectedDetailIds = returnLocks
// .Select(x => x.OrderDetailId)
@@ -979,7 +1232,7 @@
_logger.LogInformation($"鏇存柊璁㈠崟鐘舵�� - OrderNo: {orderNo}, 鏃х姸鎬�: {outboundOrder.OrderStatus}, 鏂扮姸鎬�: {newStatus}");
}
-
+
}
catch (Exception ex)
{
@@ -1116,6 +1369,34 @@
allocatefeedmodel.Details.Add(detailModel);
}
+ var groupedResult = allocatefeedmodel.Details
+ .GroupBy(item => new { item.WarehouseCode, item.MaterialCode, item.Unit, item.LineNo })
+ .Select(group =>
+ {
+
+ var deduplicatedBarcodes = group.SelectMany(x => x.Barcodes)
+ .GroupBy(b => b.Barcode)
+ .Select(b => new BarcodeInfo
+ {
+ Barcode = b.Key,
+ BatchNo = b.First().BatchNo,
+ SupplyCode = b.First().SupplyCode,
+ Qty = b.Max(x => x.Qty),
+ Unit = b.First().Unit
+ }).ToList();
+ return new AllocateDtoDetail
+ {
+ WarehouseCode = group.Key.WarehouseCode,
+ MaterialCode = group.Key.MaterialCode,
+ LineNo = group.Key.LineNo,
+ Qty = deduplicatedBarcodes.Sum(b => b.Qty),
+ Unit = group.Key.Unit,
+ Barcodes = deduplicatedBarcodes
+ };
+ }).ToList();
+
+ allocatefeedmodel.Details = groupedResult;
+
var result = await _invokeMESService.FeedbackAllocate(allocatefeedmodel);
if (result != null && result.code == 200)
@@ -1130,6 +1411,19 @@
ReturnToMESStatus = 1,
}).Where(x => x.OrderNo == orderNo).ExecuteCommandAsync();
}
+ else
+ {
+ await _outboundOrderDetailService.Db.Updateable<Dt_OutboundOrderDetail>()
+ .SetColumns(x => x.ReturnToMESStatus == 2)
+ .Where(x => x.OrderId == outboundOrder.Id)
+ .ExecuteCommandAsync();
+
+ await _outboundOrderService.Db.Updateable<Dt_OutboundOrder>()
+ .SetColumns(it => new Dt_OutboundOrder { ReturnToMESStatus = 2, Remark = result.message })
+ .Where(x => x.OrderNo == orderNo)
+ .ExecuteCommandAsync();
+ }
+
}
}
else if (outboundOrder.OrderType == OutOrderTypeEnum.ReCheck.ObjToInt())
@@ -1202,6 +1496,33 @@
}
feedmodel.details.Add(detailModel);
}
+
+ var groupedResult = feedmodel.details
+ .GroupBy(item => new { item.warehouseCode, item.materialCode, item.unit, item.lineNo })
+ .Select(group =>
+ {
+ var deduplicatedBarcodes = group.SelectMany(x => x.barcodes)
+ .GroupBy(b => b.barcode)
+ .Select(b => new WIDESEA_DTO.Outbound.BarcodesModel
+ {
+ barcode = b.Key,
+ batchNo = b.First().batchNo,
+ supplyCode = b.First().supplyCode,
+ qty = b.Max(x => x.qty),
+ unit = b.First().unit
+ }).ToList();
+ return new FeedbackOutboundDetailsModel
+ {
+ warehouseCode = group.Key.warehouseCode,
+ materialCode = group.Key.materialCode,
+ lineNo = group.Key.lineNo,
+ qty = deduplicatedBarcodes.Sum(b => b.qty),
+ unit = group.Key.unit,
+ barcodes = deduplicatedBarcodes
+ };
+ }).ToList();
+
+ feedmodel.details = groupedResult;
var result = await _invokeMESService.FeedbackOutbound(feedmodel);
if (result != null && result.code == 200)
@@ -1284,8 +1605,14 @@
_stockRepository.Db.Deleteable(stockInfo).ExecuteCommand();
}
_stockService.StockInfoService.DeleteData(stockInfo);
- _locationStatusChangeRecordService.AddLocationStatusChangeRecord(locationInfo, beforeStatus, StockChangeType.Outbound.ObjToInt(), stockInfo.Details.FirstOrDefault()?.OrderNo ?? "", task.TaskNum);
-
+ try
+ {
+ _locationStatusChangeRecordService.AddLocationStatusChangeRecord(locationInfo, beforeStatus, StockChangeType.Outbound.ObjToInt(), stockInfo?.Details.FirstOrDefault()?.OrderNo ?? "", task.TaskNum);
+ }
+ catch (Exception ex)
+ {
+ _logger.LogError($"TaskService OutEmptyTaskCompleted AddLocationStatusChangeRecord: {ex.Message} ");
+ }
return await Task.FromResult(WebResponseContent.Instance.OK());
}
--
Gitblit v1.9.3