From 461524a7a1def4532b9af4ab40733f899f360db7 Mon Sep 17 00:00:00 2001
From: heshaofeng <heshaofeng@hnkhzn.com>
Date: 星期四, 09 四月 2026 14:39:45 +0800
Subject: [PATCH] Merge branch 'htq20251215' of http://115.159.85.185:8098/r/ZhongRui/ALDbanyunxiangmu into htq20251215
---
项目代码/WMS无仓储版/WIDESEA_WMSServer/WIDESEA_TaskInfoService/TaskService.cs | 1268 +++++++++++++++++++++++++++++++++++++++++++++++++++++----
1 files changed, 1,167 insertions(+), 101 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 9725404..d195df9 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"
@@ -27,6 +27,7 @@
using SqlSugar;
using System.Reflection;
using System.Reflection.Emit;
+using System.Text;
using System.Threading.Tasks;
using System.Xml.Linq;
using WIDESEA_BasicService;
@@ -58,6 +59,7 @@
using WIDESEA_IStockService;
using WIDESEA_ITaskInfoService;
using WIDESEA_Model.Models;
+using WIDESEA_Model.Models.Basic;
using WIDESEA_Model.Models.Check;
using WIDESEA_Model.Models.Outbound;
using static HslCommunication.Profinet.Knx.KnxCode;
@@ -94,6 +96,10 @@
private readonly IRepository<Dt_AllocateMaterialInfo_Hty> _allocateMaterialInfo_Hty;
private readonly HttpClientHelper _httpClientHelper;
private readonly IBasicService _basicService;
+ private readonly IRepository<Dt_TakeStockOrder> _takeStockOrder;
+ public readonly IRepository<Dt_LocationType> _locationTypeRepository;
+ public readonly IRepository<Dt_WarehouseArea> _warehouseAreaRepository;
+ private readonly IRepository<Dt_OutStockLockInfo> _outboundLockInfoRepository;
public IRepository<Dt_Task> Repository => BaseDal;
private Dictionary<string, SqlSugar.OrderByType> _taskOrderBy = new()
@@ -113,7 +119,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, IRepository<Dt_AllocateMaterialInfo> allocateMaterialInfo, IRepository<Dt_AllocateMaterialInfo_Hty> allocateMaterialInfo_Hty, HttpClientHelper httpClientHelper, IBasicService basicService) : 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,IRepository<Dt_TakeStockOrder> takeStockOrder, IRepository<Dt_LocationType> locationTypeRepository, IRepository<Dt_WarehouseArea> warehouseAreaRepository, IRepository<Dt_OutStockLockInfo> outboundLockInfoRepository) : base(BaseDal)
{
_mapper = mapper;
_unitOfWorkManage = unitOfWorkManage;
@@ -141,6 +147,10 @@
_allocateMaterialInfo_Hty = allocateMaterialInfo_Hty;
_httpClientHelper = httpClientHelper;
_basicService = basicService;
+ _takeStockOrder = takeStockOrder;
+ _locationTypeRepository = locationTypeRepository;
+ _warehouseAreaRepository = warehouseAreaRepository;
+ _outboundLockInfoRepository = outboundLockInfoRepository;
}
public async Task TaskStatusChange(string taskNum, TaskStatusEnum taskStatusEnum)
@@ -280,11 +290,28 @@
_inboundOrderService.UpdateData(inboundOrder);
}
}
+ Dt_OutboundOrder outboundOrder = _outboundOrderService.Db.Queryable<Dt_OutboundOrder>().Where(x => x.OrderNo == stockInfo.Details.FirstOrDefault().OrderNo).Includes(x => x.Details).First();
+
+ if (outboundOrder != null)
+ {
+ foreach (var item in stockInfo.Details.Where(x => x.OrderNo == outboundOrder.OrderNo).ToList())
+ {
+ var inbounddetail = _allocateMaterialInfo.QueryFirst(x => x.OrderNo == item.OrderNo && x.Barcode == item.Barcode);
+ if (inbounddetail != null)
+ {
+ var alldelete = _allocateMaterialInfo.DeleteAndMoveIntoHty(inbounddetail, OperateTypeEnum.鑷姩鍒犻櫎);
+ if (!alldelete)
+ {
+ await Db.Deleteable(task).ExecuteCommandAsync();
+ }
+ }
+ }
+ }
stockInfo.LocationCode = task.TargetAddress;
stockInfo.StockStatus = StockStatusEmun.鍏ュ簱瀹屾垚.ObjToInt();
stockInfo.Details.ForEach(x =>
{
- x.Status = StockStatusEmun.鍏ュ簱瀹屾垚.ObjToInt();
+ x.Status = inboundOrders.FirstOrDefault().CreateType == (int)OrderCreateTypeEnum.CreateInSystem ? StockStatusEmun.鍏ュ簱瀹屾垚.ObjToInt():StockStatusEmun.鍏ュ簱纭.ObjToInt();
});
_stockService.StockInfoService.Repository.UpdateData(stockInfo);
_stockService.StockInfoDetailService.Repository.UpdateData(stockInfo.Details);
@@ -313,8 +340,6 @@
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);
}
catch (Exception ex)
{
@@ -343,8 +368,9 @@
Details = new List<AllocateDtoDetail>()
};
-
- var groupedData = inboundOrder.Details.GroupBy(item => new { item.MaterielCode, item.lineNo, item.BarcodeUnit, item.WarehouseCode })
+ var query = inboundOrder.Details.AsQueryable();
+ query = query.Where(item => item.ReturnToMESStatus == 0);
+ var groupedData = query.GroupBy(item => new { item.MaterielCode, item.lineNo, item.BarcodeUnit, item.WarehouseCode })
.Select(group => new AllocateDtoDetail
{
MaterialCode = group.Key.MaterielCode,
@@ -364,15 +390,63 @@
}).ToList();
allocatefeedmodel.Details = groupedData;
- //var feedbackresult = await _invokeMESService.FeedbackAllocate(allocatefeedmodel);
-
var response = responseModel(inboundOrder, 3, null, allocatefeedmodel);
- if (response != null && response.IsSuccess)
+ if (response != null && response.IsSuccess && response.Data.Code =="200")
{
- _inboundOrderService.Db.Updateable<Dt_InboundOrder>().SetColumns(it => new Dt_InboundOrder { ReturnToMESStatus = 1 })
+ var detailStatusList = _inboundOrderDetailService.Db.Queryable<Dt_InboundOrderDetail>()
+ .Where(it => it.OrderId == inboundOrder.Id)
+ .Select(it => it.OrderDetailStatus)
+ .ToList();
+
+ bool isAll = detailStatusList.Any()
+ ? detailStatusList.All(x => x == OrderDetailStatusEnum.Over.ObjToInt())
+ : false;
+
+ if (isAll)
+ {
+ _inboundOrderService.Db.Updateable<Dt_InboundOrder>().SetColumns(it => new Dt_InboundOrder { ReturnToMESStatus = 1, Remark = "" })
.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();
+ _inboundOrderDetailService.Db.Updateable<Dt_InboundOrderDetail>().SetColumns(it => new Dt_InboundOrderDetail { ReturnToMESStatus = 1 })
+ .Where(it => it.OrderId == inboundOrder.Id).ExecuteCommand();
+ }
+ else
+ {
+ _inboundOrderService.Db.Updateable<Dt_InboundOrder>().SetColumns(it => new Dt_InboundOrder { ReturnToMESStatus = 3, Remark = "" })
+ .Where(it => it.Id == inboundOrder.Id).ExecuteCommand();
+ _inboundOrderDetailService.Db.Updateable<Dt_InboundOrderDetail>().SetColumns(it => new Dt_InboundOrderDetail { ReturnToMESStatus = 3 })
+ .Where(it => it.OrderId == inboundOrder.Id).ExecuteCommand();
+ }
+ //鍥炰紶鎴愬姛搴撳瓨鎵嶅彲鐢�
+ _stockRepository.Db.Updateable<Dt_StockInfoDetail>().SetColumns(it => new Dt_StockInfoDetail
+ {
+ Status = StockStatusEmun.鍏ュ簱瀹屾垚.ObjToInt()
+ }).Where(it => it.OrderNo == inboundOrder.InboundOrderNo).ExecuteCommand();
+ }
+ else
+ {
+ var detailStatusList = _inboundOrderDetailService.Db.Queryable<Dt_InboundOrderDetail>()
+ .Where(it => it.OrderId == inboundOrder.Id)
+ .Select(it => it.OrderDetailStatus)
+ .ToList();
+
+ bool isAll = detailStatusList.Any()
+ ? detailStatusList.All(x => x == OrderDetailStatusEnum.Over.ObjToInt())
+ : false;
+
+ if (isAll)
+ {
+ _inboundOrderService.Db.Updateable<Dt_InboundOrder>().SetColumns(it => new Dt_InboundOrder { ReturnToMESStatus = 2, Remark = "" })
+ .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();
+ }
+ else
+ {
+ _inboundOrderService.Db.Updateable<Dt_InboundOrder>().SetColumns(it => new Dt_InboundOrder { ReturnToMESStatus = 4, Remark = "" })
+ .Where(it => it.Id == inboundOrder.Id).ExecuteCommand();
+ _inboundOrderDetailService.Db.Updateable<Dt_InboundOrderDetail>().SetColumns(it => new Dt_InboundOrderDetail { ReturnToMESStatus = 4 })
+ .Where(it => it.OrderId == inboundOrder.Id).ExecuteCommand();
+ }
}
}
}
@@ -380,62 +454,9 @@
{
//涓嶉渶瑕佸洖浼犮�傚崰涓�涓綅缃��
}
- else if (inboundOrder.OrderType == InOrderTypeEnum.InternalAllocat.ObjToInt()) //鏅轰粨璋冩櫤浠�
- {
- _logger.LogInformation($"InboundTaskCompleted 鍥炲啓MES : {inboundOrder.InboundOrderNo} ,ordertype: {InOrderTypeEnum.InternalAllocat.ObjToInt()} ");
- // BusinessTypeEnum.鏅轰粨璋冩櫤浠�
- if (inboundOrder != null && inboundOrder.OrderStatus == InOrderStatusEnum.鍏ュ簱瀹屾垚.ObjToInt())
- {
- var allocate = _allocateService.Repository.QueryData(x => x.OrderNo == inboundOrder.InboundOrderNo).First();
- var allocatefeedmodel = new AllocateDto
- {
- ReqCode = Guid.NewGuid().ToString(),
- ReqTime = DateTime.Now.ToString(),
- BusinessType = BusinessTypeEnum.鏅轰粨璋冩櫤浠�.ObjToInt().ToString(),
- 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.lineNo, item.BarcodeUnit, item.WarehouseCode })
- .Select(group => new AllocateDtoDetail
- {
- 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.BarcodeUnit
- }).ToList()
- }).ToList();
- allocatefeedmodel.Details = groupedData;
-
- var feedbackresult = await _invokeMESService.FeedbackAllocate(allocatefeedmodel);
- if (feedbackresult != null && feedbackresult.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 != null && inboundOrder.OrderStatus == InOrderStatusEnum.鍏ュ簱瀹屾垚.ObjToInt())
+ if (inboundOrder != null && inboundOrder.OrderStatus == InOrderStatusEnum.鍏ュ簱瀹屾垚.ObjToInt() && inboundOrder.CreateType == (int)OrderCreateTypeEnum.UpperSystemPush)
{
var feedmodel = new FeedbackInboundRequestModel
{
@@ -450,8 +471,9 @@
details = new List<FeedbackInboundDetailsModel>()
};
-
- var groupedData = inboundOrder.Details.GroupBy(item => new { item.MaterielCode, item.SupplyCode, item.BatchNo, item.lineNo, item.BarcodeUnit, item.WarehouseCode })
+ var query = inboundOrder.Details.AsQueryable();
+ query = query.Where(item => item.ReturnToMESStatus == 0);
+ var groupedData = query.GroupBy(item => new { item.MaterielCode, item.SupplyCode, item.BatchNo, item.lineNo, item.BarcodeUnit, item.WarehouseCode })
.Select(group => new FeedbackInboundDetailsModel
{
materialCode = group.Key.MaterielCode,
@@ -474,19 +496,63 @@
var response= responseModel(inboundOrder,2, feedmodel);
- if (response != null && response.IsSuccess)
+ if (response != null && response.IsSuccess && response.Data.Code == "200")
{
- _inboundOrderService.Db.Updateable<Dt_InboundOrder>().SetColumns(it => new Dt_InboundOrder { ReturnToMESStatus = 1, Remark = "" })
+ var detailStatusList = _inboundOrderDetailService.Db.Queryable<Dt_InboundOrderDetail>()
+ .Where(it => it.OrderId == inboundOrder.Id)
+ .Select(it => it.OrderDetailStatus)
+ .ToList();
+
+ bool isAll = detailStatusList.Any()
+ ? detailStatusList.All(x => x == OrderDetailStatusEnum.Over.ObjToInt())
+ : false;
+
+ if (isAll)
+ {
+ _inboundOrderService.Db.Updateable<Dt_InboundOrder>().SetColumns(it => new Dt_InboundOrder { ReturnToMESStatus = 1, Remark = "" })
.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();
+ _inboundOrderDetailService.Db.Updateable<Dt_InboundOrderDetail>().SetColumns(it => new Dt_InboundOrderDetail { ReturnToMESStatus = 1 })
+ .Where(it => it.OrderId == inboundOrder.Id).ExecuteCommand();
+ }
+ else
+ {
+ _inboundOrderService.Db.Updateable<Dt_InboundOrder>().SetColumns(it => new Dt_InboundOrder { ReturnToMESStatus = 3, Remark = "" })
+ .Where(it => it.Id == inboundOrder.Id).ExecuteCommand();
+ _inboundOrderDetailService.Db.Updateable<Dt_InboundOrderDetail>().SetColumns(it => new Dt_InboundOrderDetail { ReturnToMESStatus = 3 })
+ .Where(it => it.OrderId == inboundOrder.Id).ExecuteCommand();
+ }
+
+ //鍥炰紶鎴愬姛搴撳瓨鎵嶅彲鐢�
+ _stockRepository.Db.Updateable<Dt_StockInfoDetail>().SetColumns(it => new Dt_StockInfoDetail
+ {
+ Status = StockStatusEmun.鍏ュ簱瀹屾垚.ObjToInt()
+ }).Where(it => it.OrderNo == inboundOrder.InboundOrderNo).ExecuteCommand();
}
else
{
- _inboundOrderService.Db.Updateable<Dt_InboundOrder>().SetColumns(it => new Dt_InboundOrder { ReturnToMESStatus = 2, Remark = response.ErrorMessage })
+ var detailStatusList = _inboundOrderDetailService.Db.Queryable<Dt_InboundOrderDetail>()
+ .Where(it => it.OrderId == inboundOrder.Id)
+ .Select(it => it.OrderDetailStatus)
+ .ToList();
+
+ bool isAll = detailStatusList.Any()
+ ? detailStatusList.All(x => x == OrderDetailStatusEnum.Over.ObjToInt())
+ : false;
+
+ if (isAll)
+ {
+ _inboundOrderService.Db.Updateable<Dt_InboundOrder>().SetColumns(it => new Dt_InboundOrder { ReturnToMESStatus = 2, Remark = "" })
.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();
+ _inboundOrderDetailService.Db.Updateable<Dt_InboundOrderDetail>().SetColumns(it => new Dt_InboundOrderDetail { ReturnToMESStatus = 2 })
+ .Where(it => it.OrderId == inboundOrder.Id).ExecuteCommand();
+ }
+ else
+ {
+ _inboundOrderService.Db.Updateable<Dt_InboundOrder>().SetColumns(it => new Dt_InboundOrder { ReturnToMESStatus = 4, Remark = "" })
+ .Where(it => it.Id == inboundOrder.Id).ExecuteCommand();
+ _inboundOrderDetailService.Db.Updateable<Dt_InboundOrderDetail>().SetColumns(it => new Dt_InboundOrderDetail { ReturnToMESStatus = 4 })
+ .Where(it => it.OrderId == inboundOrder.Id).ExecuteCommand();
+ }
}
}
}
@@ -499,6 +565,299 @@
}
return WebResponseContent.Instance.OK();
+ }
+
+ public async Task<WebResponseContent> RelocationTaskCompleted(Dt_Task task)
+ {
+ WebResponseContent content = new WebResponseContent();
+ try
+ {
+ if (task == null || string.IsNullOrEmpty(task.PalletCode) || string.IsNullOrEmpty(task.TargetAddress))
+ {
+ return WebResponseContent.Instance.Error("绉诲簱浠诲姟淇℃伅涓嶅畬鏁达紙鎵樼洏鍙�/鐩爣璐т綅涓虹┖锛�");
+ }
+
+ // 2. 鏌ヨ鎵樼洏搴撳瓨淇℃伅
+ 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($"鏈壘鍒版墭鐩榌{task.PalletCode}]瀵瑰簲鐨勭粍鐩樹俊鎭�");
+ }
+
+ // 闈炵┖鎵樼洏蹇呴』鏈夋槑缁�
+ if (stockInfo.Details.Count == 0 && stockInfo.PalletType != PalletTypeEnum.Empty.ObjToInt())
+ {
+ _logger.LogInformation($"TaskService RelocationTaskCompleted: 鏈壘鍒拌鎵樼洏搴撳瓨鏄庣粏淇℃伅.{task.TaskNum}");
+ return WebResponseContent.Instance.Error($"鏈壘鍒拌鎵樼洏[{task.PalletCode}]搴撳瓨鏄庣粏淇℃伅");
+ }
+
+ // 3. 鏌ヨ鐩爣璐т綅+鍘熻揣浣嶄俊鎭�
+ Dt_LocationInfo targetLocationInfo = _locationInfoService.Repository.QueryFirst(x => x.LocationCode == task.TargetAddress);
+ if (targetLocationInfo == null)
+ {
+ return content.Error($"鏈壘鍒板搴旂殑缁堢偣璐т綅[{task.TargetAddress}]淇℃伅");
+ }
+
+ // 鍘熻揣浣嶄俊鎭�
+ Dt_LocationInfo oldLocationInfo = null;
+ if (!string.IsNullOrEmpty(stockInfo.LocationCode))
+ {
+ oldLocationInfo = _locationInfoService.Repository.QueryFirst(x => x.LocationCode == stockInfo.LocationCode);
+ if (oldLocationInfo == null)
+ {
+ return content.Error($"鏈壘鍒板師璐т綅[{stockInfo.LocationCode}]淇℃伅");
+ }
+ }
+
+ // 4. 璐т綅鐘舵�佹牎楠�
+ if (targetLocationInfo.LocationStatus == LocationStatusEnum.InStock.ObjToInt())
+ {
+ return WebResponseContent.Instance.Error($"鐩爣璐т綅[{task.TargetAddress}]鐘舵�佷笉姝g‘锛堝綋鍓嶄负宸插崰鐢級");
+ }
+
+ // 5. 寮�鍚簨鍔″鐞嗘牳蹇冮�昏緫
+ _unitOfWorkManage.BeginTran();
+
+ // 5.1 璁板綍鐩爣璐т綅鍘熺姸鎬侊紝鏇存柊涓哄崰鐢�
+ var beforeTargetLocationStatus = targetLocationInfo.LocationStatus;
+ targetLocationInfo.LocationStatus = LocationStatusEnum.InStock.ObjToInt();
+ _locationInfoService.Repository.UpdateData(targetLocationInfo);
+
+ // 5.2 閲婃斁鍘熻揣浣�
+ int beforeOldLocationStatus = 0;
+ if (oldLocationInfo != null)
+ {
+ beforeOldLocationStatus = oldLocationInfo.LocationStatus;
+ // 鍘熻揣浣嶆仮澶嶄负绌洪棽
+ oldLocationInfo.LocationStatus = stockInfo.PalletType == PalletTypeEnum.Empty.ObjToInt()
+ ? LocationStatusEnum.Pallet.ObjToInt()
+ : LocationStatusEnum.Free.ObjToInt();
+ _locationInfoService.Repository.UpdateData(oldLocationInfo);
+ }
+ var stockLockInfo = _outStockLockInfoService.Db.Queryable<Dt_OutboundLockInfo_Hty>().Where(x => x.PalletCode == stockInfo.PalletCode && x.TaskNum == task.TaskNum).First();
+ var allocateOrderToWarehouse = _allocateOrderRepository.Db.Queryable<Dt_AllocateOrder>().Where(x => x.OrderNo == stockLockInfo.OrderNo).First();
+ // 5.3 鏇存柊搴撳瓨鏄庣粏鐘舵�侊紙绉诲簱瀹屾垚锛�
+ stockInfo.Details.ForEach(x =>
+ {
+ x.Status = StockStatusEmun.鍏ュ簱瀹屾垚.ObjToInt();
+ x.WarehouseCode = allocateOrderToWarehouse.ToWarehouse;
+ });
+ _stockService.StockInfoDetailService.Repository.UpdateData(stockInfo.Details);
+
+ // 5.4 鏇存柊搴撳瓨涓讳俊鎭紙缁戝畾鏂拌揣浣嶏級
+ string oldLocationCode = stockInfo.LocationCode; // 璁板綍鍘熻揣浣�
+ stockInfo.LocationCode = targetLocationInfo.LocationCode; // 缁戝畾鐩爣璐т綅
+ stockInfo.PalletCode = task.PalletCode;
+ stockInfo.StockStatus = StockStatusEmun.鍏ュ簱瀹屾垚.ObjToInt();
+
+ var name =_warehouseAreaRepository.Db.Queryable<Dt_WarehouseArea>().Where(x => x.Code == allocateOrderToWarehouse.ToWarehouse).First();
+ var locationType =_locationTypeRepository.QueryFirst(x => x.LocationTypeDesc.Equals(name.Name));
+ if(locationType != null)
+ {
+ stockInfo.LocationType = locationType.LocationType;
+ }
+ _stockRepository.UpdateData(stockInfo);
+
+ // 5.5 鏇存柊浠诲姟鐘舵�佷负瀹屾垚
+ task.TaskStatus = TaskStatusEnum.Finish.ObjToInt();
+ var result = _task_HtyService.DeleteAndMoveIntoHty(task, OperateTypeEnum.鑷姩瀹屾垚);
+
+ // 鎻愪氦浜嬪姟
+ _unitOfWorkManage.CommitTran();
+
+ // 浠诲姟褰掓。澶辫触鍒欑洿鎺ュ垹闄�
+ if (!result)
+ {
+ await Db.Deleteable(task).ExecuteCommandAsync();
+ }
+
+ // 6. 澶勭悊鍑哄簱鍗�+璋冩嫧鐗╂枡淇℃伅
+ Dt_OutboundOrder outboundOrder = null;
+ //var firstDetail = stockInfo.Details.FirstOrDefault();
+ if (stockLockInfo != null && !string.IsNullOrEmpty(stockLockInfo.OrderNo))
+ {
+ outboundOrder = _outboundOrderService.Db.Queryable<Dt_OutboundOrder>()
+ .Where(x => x.OrderNo == stockLockInfo.OrderNo)
+ .Includes(x => x.Details)
+ .First();
+ string Operator = outboundOrder.Modifier;
+ if (outboundOrder != null)
+ {
+ var allocatInfo =_allocateMaterialInfo.Db.Queryable<Dt_AllocateMaterialInfo>().Where(x => x.OrderNo == outboundOrder.OrderNo).ToList();
+ // 鍒犻櫎璋冩嫧鐗╂枡淇℃伅
+ foreach (var item in allocatInfo)
+ {
+ var inbounddetail = _allocateMaterialInfo.QueryFirst(x => x.OrderNo == item.OrderNo && x.Barcode == item.Barcode);
+ if (inbounddetail != null)
+ {
+ var alldelete = _allocateMaterialInfo.DeleteAndMoveIntoHty(inbounddetail, OperateTypeEnum.鑷姩鍒犻櫎);
+ if (!alldelete)
+ {
+ await Db.Deleteable(task).ExecuteCommandAsync();
+ }
+ }
+ }
+
+ if (outboundOrder.Details.All(x => x.OrderDetailStatus == (int)OrderDetailStatusEnum.Over) && !allocatInfo.Any())
+ {
+ outboundOrder.OrderStatus = (int)InOrderStatusEnum.鍏ュ簱瀹屾垚;
+ _outboundOrderService.UpdateData(outboundOrder);
+ }
+
+ // 7. 鍥炶皟MES
+
+ 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_AllocateMaterialInfo allocateMaterialInfo = _allocateMaterialInfo.QueryFirst(x => x.OrderNo == outboundOrder.OrderNo);
+ // 绉诲簱鍦烘櫙锛氬嚭搴撳畬鎴愪笖鏈洖浼燤ES銆佹棤璋冩嫧鐗╂枡淇℃伅鏃跺洖璋�
+ if (outboundOrder.OrderStatus == OutOrderStatusEnum.鍑哄簱瀹屾垚.ObjToInt() && outboundOrder.ReturnToMESStatus == 0 && allocateMaterialInfo == null)
+ {
+ Dt_AllocateOrder allocateOrder = _allocateOrderRepository.QueryFirst(x => x.OrderNo == outboundOrder.OrderNo);
+ if (allocateOrder == null)
+ {
+ return WebResponseContent.Instance.Error($"鏈壘鍒板搴旂殑璋冩嫧鍗昜{outboundOrder.OrderNo}]");
+ }
+
+ // 鏋勫缓绉诲簱鍥炶皟鏁版嵁
+ AllocationReturnDTO? returnDTO = BuildAllocationFeedbackData(
+ outboundOrder,
+ allocateOrder.FromWarehouse,
+ allocateOrder.ToWarehouse,
+ Operator);
+
+ if (returnDTO == null)
+ {
+ return WebResponseContent.Instance.Error($"鏋勫缓绉诲簱鍥炶皟瀵硅薄澶辫触");
+ }
+
+ string apiUrl = AppSettings.GetValue("AllocationFeedbackUrl");
+ returnDTO.ReqCode = reqCode;
+ returnDTO.ReqTime = reqTime;
+ JsonSerializerSettings settings = new JsonSerializerSettings
+ {
+ ContractResolver = new CamelCasePropertyNamesContractResolver()
+ };
+ requestData = JsonConvert.SerializeObject(returnDTO, settings);
+ lineNos = returnDTO.Details.Select(x => x.LineNo).ToList();
+ httpResponseResult = _httpClientHelper.Post<MesResponseDTO>(apiUrl, requestData);
+ httpResponseResult.ApiUrl = apiUrl;
+ }
+
+ // 8. 澶勭悊MES鍥炶皟缁撴灉
+ 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}";
+ }
+ }
+
+ // 9. 璁板綍MES鍥炰紶璁板綍
+ Dt_MesReturnRecord mesReturnRecord = new Dt_MesReturnRecord()
+ {
+ ApiUrl = httpResponseResult.ApiUrl,
+ InterfaceType = outboundOrder.OrderType == 0 ? 1 : 3, // 绉诲簱鎺ュ彛绫诲瀷锛氬鐢ㄨ皟鎷ㄧ被鍨�3
+ OrderId = outboundOrder.Id,
+ OrderNo = outboundOrder.OrderNo,
+ RequestCode = reqCode,
+ RequestData = requestData,
+ FailureReason = message,
+ LastReturnTime = DateTime.Now,
+ HttpStatusCode = httpResponseResult.StatusCode.ObjToInt(),
+ ResponseData = httpResponseResult.Content,
+ ReturnType = 0,
+ ReturnCount = 1,
+ ReturnStatus = isSuccess ? 1 : 2,
+ SuccessTime = isSuccess ? DateTime.Now : null
+ };
+
+ // 寮�鍚簨鍔′繚瀛楳ES璁板綍+鏇存柊鍑哄簱鍗曠姸鎬�
+ _unitOfWorkManage.BeginTran();
+ _unitOfWorkManage.Db.Insertable(mesReturnRecord).ExecuteCommand();
+
+ List<Dt_OutboundOrderDetail> outboundOrderDetails = outboundOrder.Details.Where(x => lineNos.Contains(x.lineNo)).ToList();
+ outboundOrderDetails.ForEach(x =>
+ {
+ if (x.OverOutQuantity == x.OrderQuantity - x.MoveQty)
+ {
+ x.ReturnToMESStatus = isSuccess ? 1 : 2;
+ }
+ else
+ {
+ x.ReturnToMESStatus = isSuccess ? 3 : 4;
+ }
+ x.CurrentDeliveryQty = 0;
+ x.ReturnJsonData = "";
+ });
+
+ mesReturnRecord.ReturnType = outboundOrder.Details.Count == outboundOrderDetails.Count ? 1 : 2;
+
+ if (outboundOrder.Details.Count == outboundOrderDetails.Count && outboundOrderDetails.All(x => x.ReturnToMESStatus == 1 || x.ReturnToMESStatus == 2))
+ {
+ outboundOrder.ReturnToMESStatus = isSuccess ? 1 : 2;
+ }
+ else
+ {
+ outboundOrder.ReturnToMESStatus = isSuccess ? 3 : 4;
+ }
+
+ _outboundOrderService.Db.Updateable(outboundOrderDetails).ExecuteCommand();
+ _outboundOrderService.UpdateData(outboundOrder);
+
+ _unitOfWorkManage.CommitTran();
+ }
+ }
+
+ // 10. 璁板綍璐т綅鐘舵�佸彉鏇达紙鐩爣璐т綅+鍘熻揣浣嶏級
+ try
+ {
+ // 璁板綍鐩爣璐т綅鐘舵�佸彉鏇�
+ _locationStatusChangeRecordService.AddLocationStatusChangeRecord(
+ targetLocationInfo,
+ beforeTargetLocationStatus,
+ StockChangeType.Inbound.ObjToInt(),
+ $"绉诲簱鍏ュ簱锛堝師璐т綅锛歿oldLocationCode}锛�",
+ task.TaskNum);
+
+ // 璁板綍鍘熻揣浣嶇姸鎬佸彉鏇达紙鑻ユ湁锛�
+ if (oldLocationInfo != null)
+ {
+ _locationStatusChangeRecordService.AddLocationStatusChangeRecord(
+ oldLocationInfo,
+ beforeOldLocationStatus,
+ StockChangeType.Outbound.ObjToInt(),
+ $"绉诲簱鍑哄簱锛堢洰鏍囪揣浣嶏細{targetLocationInfo.LocationCode}锛�",
+ task.TaskNum);
+ }
+ }
+ catch (Exception ex)
+ {
+ _logger.LogInformation($"RelocationTaskCompleted AddLocationStatusChangeRecord : {ex.Message} ");
+ }
+
+ return content;
+ }
+ catch (Exception ex)
+ {
+ // 浜嬪姟鍥炴粴
+ _unitOfWorkManage.RollbackTran();
+ _logger.LogError($"RelocationTaskCompleted 澶勭悊澶辫触锛歿ex.Message}", ex);
+ return await Task.FromResult(WebResponseContent.Instance.Error($"绉诲簱浠诲姟澶勭悊澶辫触锛歿ex.Message}"));
+ }
}
public HttpResponseResult<MesResponseDTO> responseModel(Dt_InboundOrder order, int InterfaceType, FeedbackInboundRequestModel model = null, AllocateDto allocateDto = null)
@@ -548,7 +907,7 @@
ResponseData = httpResponseResult.Content,
ReturnType = 0,
ReturnCount = 1,
- ReturnStatus = httpResponseResult.IsSuccess ? 1 : 2,
+ ReturnStatus = isSuccess ? 1 : 2,
SuccessTime = httpResponseResult.IsSuccess ? DateTime.Now : null
};
_unitOfWorkManage.Db.Insertable(mesReturnRecord).ExecuteCommand();
@@ -586,11 +945,16 @@
stock.Details.ForEach(x =>
{
- x.Status = StockStatusEmun.鍑哄簱瀹屾垚.ObjToInt();
+ if (x.Status != StockStatusEmun.鎵嬪姩鍐荤粨.ObjToInt())
+ {
+ x.Status = StockStatusEmun.鍑哄簱瀹屾垚.ObjToInt();
+ }
+
});
_stockService.StockInfoService.Db.UpdateNav(stock).IncludesAllFirstLayer().ExecuteCommand();
+ task.TaskStatus = (int)TaskStatusEnum.Finish;
var result = _task_HtyService.DeleteAndMoveIntoHty(task, OperateTypeEnum.鑷姩瀹屾垚);
if (!result)
{
@@ -713,22 +1077,17 @@
{
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();
- }
+ _unitOfWorkManage.BeginTran();
+
var beforelocationStatus = locationInfo.LocationStatus;
locationInfo.LocationStatus = LocationStatusEnum.InStock.ObjToInt();
_locationInfoService.Repository.UpdateData(locationInfo);
-
+ stockInfo.Details.ForEach(x =>
+ {
+ x.Status = StockStatusEmun.鍏ュ簱瀹屾垚.ObjToInt();
+ });
+ _stockService.StockInfoDetailService.Repository.UpdateData(stockInfo.Details);
stockInfo.LocationCode = locationInfo.LocationCode;
stockInfo.PalletCode = task.PalletCode;
stockInfo.LocationCode = task.TargetAddress;
@@ -744,24 +1103,49 @@
}
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())
+ string Operator = outboundOrder.Modifier;
+ if (outboundOrder != 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;
- List<string> lineNos = new List<string>();
+ foreach (var item in stockInfo.Details.Where(x => x.OrderNo == outboundOrder.OrderNo).ToList())
+ {
+ var inbounddetail = _allocateMaterialInfo.QueryFirst(x => x.OrderNo == item.OrderNo && x.Barcode == item.Barcode);
+ if (inbounddetail != null)
+ {
+ var alldelete = _allocateMaterialInfo.DeleteAndMoveIntoHty(inbounddetail, OperateTypeEnum.鑷姩鍒犻櫎);
+ if (!alldelete)
+ {
+ await Db.Deleteable(task).ExecuteCommandAsync();
+ }
+ }
+ }
+ var allocateMaterialInfos = _allocateMaterialInfo.QueryData(x => x.OrderNo == outboundOrder.OrderNo);
+ if (outboundOrder.Details.All(x => x.OrderDetailStatus == (int)OrderDetailStatusEnum.Over) && !allocateMaterialInfos.Any())
+ {
+ outboundOrder.OrderStatus = (int)InOrderStatusEnum.鍏ュ簱瀹屾垚;
+ _outboundOrderService.UpdateData(outboundOrder);
+ }
+ }
+
+ ///鍥炶皟MES
+ 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_AllocateMaterialInfo allocateMaterialInfo = _allocateMaterialInfo.QueryFirst(x => x.OrderNo == outboundOrder.OrderNo);
+ if (outboundOrder.OrderStatus == OutOrderStatusEnum.鍑哄簱瀹屾垚.ObjToInt() && outboundOrder.ReturnToMESStatus == 0 && allocateMaterialInfo == null)
+ {
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);
+ AllocationReturnDTO? returnDTO = BuildAllocationFeedbackData(outboundOrder, allocateOrder.FromWarehouse, allocateOrder.ToWarehouse, Operator);
if (returnDTO == null)
{
return WebResponseContent.Instance.Error($"鏋勫缓鍥炶皟瀵硅薄澶辫触");
}
- string apiUrl = AppSettings.GetValue("AllocationFeedbackUrl"); ;
+ string apiUrl = AppSettings.GetValue("AllocationFeedbackUrl");
returnDTO.ReqCode = reqCode;
returnDTO.ReqTime = reqTime;
JsonSerializerSettings settings = new JsonSerializerSettings
@@ -773,6 +1157,72 @@
httpResponseResult = _httpClientHelper.Post<MesResponseDTO>(apiUrl, requestData);
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 = outboundOrder.OrderType == 0 ? 1 : 3,
+ OrderId = outboundOrder.Id,
+ OrderNo = outboundOrder.OrderNo,
+ RequestCode = reqCode,
+ RequestData = requestData,
+ FailureReason = message,
+ LastReturnTime = DateTime.Now,
+ HttpStatusCode = httpResponseResult.StatusCode.ObjToInt(),
+ ResponseData = httpResponseResult.Content,
+ ReturnType = 0,
+ ReturnCount = 1,
+ ReturnStatus = isSuccess ? 1 : 2,
+ SuccessTime = isSuccess ? DateTime.Now : null
+ };
+
+ _unitOfWorkManage.BeginTran();
+ _unitOfWorkManage.Db.Insertable(mesReturnRecord).ExecuteCommand();
+
+ List<Dt_OutboundOrderDetail> outboundOrderDetails = outboundOrder.Details.Where(x => lineNos.Contains(x.lineNo)).ToList();
+ outboundOrderDetails.ForEach(x =>
+ {
+ if (x.OverOutQuantity == x.OrderQuantity - x.MoveQty)
+ {
+ x.ReturnToMESStatus = isSuccess ? 1 : 2;
+ }
+ else
+ {
+ x.ReturnToMESStatus = isSuccess ? 3 : 4;
+ }
+ x.CurrentDeliveryQty = 0;
+ x.ReturnJsonData = "";
+ });
+
+ mesReturnRecord.ReturnType = outboundOrder.Details.Count == outboundOrderDetails.Count ? 1 : 2;
+
+ if (outboundOrder.Details.Count == outboundOrderDetails.Count && outboundOrderDetails.All(x => x.ReturnToMESStatus == 1 || x.ReturnToMESStatus == 2))
+ {
+ outboundOrder.ReturnToMESStatus = isSuccess ? 1 : 2;
+ }
+ else
+ {
+ outboundOrder.ReturnToMESStatus = isSuccess ? 3 : 4;
+ }
+
+ _outboundOrderService.Db.Updateable(outboundOrderDetails).ExecuteCommand();
+ _outboundOrderService.UpdateData(outboundOrder);
+
+ _unitOfWorkManage.CommitTran();
+
try
{
_locationStatusChangeRecordService.AddLocationStatusChangeRecord(locationInfo, beforelocationStatus, StockChangeType.Inbound.ObjToInt(), "", task.TaskNum);
@@ -790,7 +1240,7 @@
}
}
- public AllocationReturnDTO? BuildAllocationFeedbackData(Dt_OutboundOrder outboundOrder, string fromWarehouse, string toWarehouse)
+ public AllocationReturnDTO? BuildAllocationFeedbackData(Dt_OutboundOrder outboundOrder, string fromWarehouse, string toWarehouse,string Operator)
{
try
{
@@ -825,10 +1275,10 @@
Details = returnDetails,
FactoryArea = outboundOrder.FactoryArea,
OperationType = 1,
- OrderNo = outboundOrder.OrderNo,
+ OrderNo = outboundOrder.UpperOrderNo,
FromWarehouse = fromWarehouse,
ToWarehouse = toWarehouse,
- Operator = App.User.UserName
+ Operator = Operator
};
return outboundReturnDTO;
@@ -902,7 +1352,10 @@
{
foreach (var detail in stockInfo.Details)
{
- detail.Status = StockStatusEmun.鍏ュ簱瀹屾垚.ObjToInt();
+ if(detail.Status != StockStatusEmun.鎵嬪姩鍐荤粨.ObjToInt()&& detail.Status != StockStatusEmun.閲嶆涓�.ObjToInt())
+ {
+ detail.Status = StockStatusEmun.鍏ュ簱瀹屾垚.ObjToInt();
+ }
detail.OutboundQuantity = 0;
}
_stockService.StockInfoDetailService.Repository.UpdateData(stockInfo.Details);
@@ -1778,5 +2231,618 @@
return TaskCompleted(TaskNum);
}
+ /// <summary>
+ /// 鐩樼偣鍑哄簱瀹屾垚
+ /// </summary>
+ public async Task<WebResponseContent> OutInventoryTaskCompleted(Dt_Task task)
+ {
+ WebResponseContent content = new WebResponseContent();
+ try
+ {
+ task = BaseDal.QueryFirst(x => x.TaskNum == task.TaskNum);
+ if (task == null)
+ {
+ return WebResponseContent.Instance.Error("鏈壘鍒颁换鍔′俊鎭�");
+ }
+ var SourceAddress = task.SourceAddress;
+ Dt_StockInfo stockInfo = _stockService.StockInfoService.Repository.QueryFirst(x=>x.PalletCode == task.PalletCode);
+ Dt_LocationInfo locationInfo = _basicService.LocationInfoService.Repository.QueryFirst(x => x.LocationCode == SourceAddress);
+ if (stockInfo == null) return WebResponseContent.Instance.Error("鏈壘鍒板簱瀛樹俊鎭�");
+ if (locationInfo == null) return WebResponseContent.Instance.Error("鏈壘鍒拌揣浣嶄俊鎭�");
+ //鑾峰彇瀵瑰簲鐩樼偣鍗�
+ Dt_TakeStockOrder takeStockOrder = _takeStockOrder.Db.Queryable<Dt_TakeStockOrder>().Where(x => x.OrderNo == task.OrderNo).Includes(x => x.Details).First();
+ if (takeStockOrder == null)
+ {
+ return content.Error($"鐩樼偣鍗晎task.OrderNo}涓嶅瓨鍦�");
+ }
+ if (takeStockOrder.TakeStockStatus != TakeStockStatusEnum.鐩樼偣涓�.ObjToInt())
+ {
+ return content.Error($"鐩樼偣鍗晎task.OrderNo}鐩樼偣宸插畬鎴愭垨鏈紑濮�");
+ }
+ if (stockInfo.StockStatus != StockStatusEmun.鍑哄簱閿佸畾.ObjToInt())
+ {
+ return content.Error($"{stockInfo.PalletCode}搴撳瓨鐘舵�佷笉姝g‘");
+ }
+ if (locationInfo.LocationStatus != LocationStatusEnum.Lock.ObjToInt())
+ {
+ return content.Error($"{locationInfo.LocationCode}璐т綅鐘舵�佷笉姝g‘");
+ }
+
+ stockInfo.StockStatus = StockStatusEmun.鐩樼偣鍑哄簱瀹屾垚.ObjToInt();
+ stockInfo.LocationCode = "";
+ task.TaskStatus = TaskStatusEnum.Finish.ObjToInt();
+ int beforeStatus = locationInfo.LocationStatus;
+ locationInfo.LocationStatus = LocationStatusEnum.Free.ObjToInt();
+ _unitOfWorkManage.BeginTran();
+ //璐т綅鍙樺姩璁板綍
+ _basicService.LocationInfoService.UpdateData(locationInfo);
+ _recordService.LocationStatusChangeRecordSetvice.AddLocationStatusChangeRecord(locationInfo, beforeStatus, LocationStatusEnum.Free.ObjToInt(), takeStockOrder?.OrderNo ?? "", task.TaskNum);
+ _stockRepository.UpdateData(stockInfo);
+ BaseDal.DeleteAndMoveIntoHty(task, App.User.UserId == 0 ? OperateTypeEnum.鑷姩瀹屾垚 : OperateTypeEnum.浜哄伐瀹屾垚);
+ _unitOfWorkManage.CommitTran();
+ content.OK();
+ }
+ catch (Exception ex)
+ {
+ _unitOfWorkManage.RollbackTran();
+ return await Task.FromResult(WebResponseContent.Instance.Error(ex.Message));
+ }
+ return content;
+ }
+
+ /// <summary>
+ /// 鐩樼偣鍏ュ簱瀹屾垚
+ /// </summary>
+ /// <param name="task"></param>
+ /// <returns></returns>
+ public async Task<WebResponseContent> InInventoryTaskCompleted(Dt_Task task)
+ {
+
+ WebResponseContent content = new WebResponseContent();
+ try
+ {
+
+ Dt_LocationInfo locationInfo = _locationInfoService.Repository.QueryFirst(x => x.LocationCode == task.TargetAddress);
+ if (locationInfo == null)
+ {
+ return content.Error($"鏈壘鍒板搴旂殑缁堢偣璐т綅淇℃伅");
+ }
+ Dt_StockInfo stockInfo = _stockRepository.Db.Queryable<Dt_StockInfo>().Where(x => x.PalletCode == task.PalletCode && x.WarehouseId == task.WarehouseId).First();
+ if (stockInfo == null)
+ {
+ return WebResponseContent.Instance.Error($"鏈壘鍒版墭鐩樺搴旂殑缁勭洏淇℃伅");
+ }
+
+ if (!string.IsNullOrEmpty(stockInfo.LocationCode))
+ {
+ return WebResponseContent.Instance.Error($"璇ユ墭鐩樺凡缁戝畾璐т綅");
+ }
+ if (locationInfo.LocationStatus == LocationStatusEnum.InStock.ObjToInt())
+ {
+ return WebResponseContent.Instance.Error($"璐т綅鐘舵�佷笉姝g‘");
+ }
+
+
+ var beforelocationStatus = locationInfo.LocationStatus;
+ locationInfo.LocationStatus = LocationStatusEnum.InStock.ObjToInt();
+
+
+ stockInfo.LocationCode = locationInfo.LocationCode;
+ stockInfo.PalletCode = task.PalletCode;
+ stockInfo.LocationCode = task.TargetAddress;
+ stockInfo.StockStatus = StockStatusEmun.鍏ュ簱瀹屾垚.ObjToInt();
+ task.TaskStatus = TaskStatusEnum.Finish.ObjToInt();
+
+ _unitOfWorkManage.BeginTran();
+ _locationInfoService.Repository.UpdateData(locationInfo);
+ _stockRepository.UpdateData(stockInfo);
+ var result = _task_HtyService.DeleteAndMoveIntoHty(task, OperateTypeEnum.浜哄伐鍒犻櫎);
+ _unitOfWorkManage.CommitTran();
+
+ if (!result)
+ {
+ await Db.Deleteable(task).ExecuteCommandAsync();
+ }
+ 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));
+ }
+ }
+
+ /// <summary>
+ /// 閲嶆鍏ュ簱瀹屾垚
+ /// </summary>
+ /// <param name="task"></param>
+ /// <returns></returns>
+ public async Task<WebResponseContent> InQualityTaskCompleted(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‘");
+ }
+
+ _unitOfWorkManage.BeginTran();
+
+ 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 != null)
+ {
+ foreach (var item in stockInfo.Details.Where(x => x.OrderNo == outboundOrder.OrderNo).ToList())
+ {
+ var inbounddetail = _allocateMaterialInfo.QueryFirst(x => x.OrderNo == item.OrderNo && x.Barcode == item.Barcode);
+ if (inbounddetail != null)
+ {
+ var alldelete = _allocateMaterialInfo.DeleteAndMoveIntoHty(inbounddetail, OperateTypeEnum.鑷姩鍒犻櫎);
+ if (!alldelete)
+ {
+ await Db.Deleteable(task).ExecuteCommandAsync();
+ }
+ }
+ }
+ }
+ 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));
+ }
+ }
+
+ /// <summary>
+ /// 浠诲姟鍙栨秷
+ /// </summary>
+ /// <param name="taskCodes"></param>
+ /// <returns></returns>
+ /// <summary>
+ public async Task<WebResponseContent> TaskCancel(List<int> taskCodes)
+ {
+ try
+ {
+ if (taskCodes == null || !taskCodes.Any())
+ {
+ return WebResponseContent.Instance.Error("鍙栨秷鐨勪换鍔″彿涓嶈兘涓虹┖");
+ }
+
+ //var taskCancelUrl = AppSettings.GetValue("TaskCancelUrl");
+ //TaskCancelRequest taskc = new TaskCancelRequest();
+ //taskc.TaskCodes = taskCodes.Select(x => x.ToString()).ToList();
+
+ //string json = JsonConvert.SerializeObject(taskc);
+
+ //using var clientHttp = new HttpClient();
+ //var content = new StringContent(json, Encoding.UTF8, "application/json");
+
+ //HttpResponseMessage response = await clientHttp.PostAsync(taskCancelUrl,content);
+
+ //string responseJson = await response.Content.ReadAsStringAsync();
+ //TaskCancelApiResponse apiResponse = JsonConvert.DeserializeObject<TaskCancelApiResponse>(responseJson);
+
+ //if (apiResponse.Code != 0)
+ //{
+ // return WebResponseContent.Instance.Error($"璇锋眰澶辫触锛歿apiResponse.Msg}");
+ //}
+ _unitOfWorkManage.BeginTran();
+
+ var tasks = await Db.Queryable<Dt_Task>()
+ .Where(x => taskCodes.Contains(x.TaskNum))
+ .ToListAsync();
+
+ if (!tasks.Any())
+ {
+ _unitOfWorkManage.RollbackTran();
+ return WebResponseContent.Instance.Error("鏈壘鍒板搴旂殑浠诲姟淇℃伅");
+ }
+
+ int inPickType = TaskTypeEnum.InPick.ObjToInt();
+ var inboundTypes = new List<int>
+ {
+ TaskTypeEnum.InAllocate.ObjToInt(),
+ TaskTypeEnum.InEmpty.ObjToInt(),
+ TaskTypeEnum.Inbound.ObjToInt(),
+ TaskTypeEnum.InInventory.ObjToInt(),
+ TaskTypeEnum.InQuality.ObjToInt()
+ };
+ var outboundTypes = new List<int>
+ {
+ TaskTypeEnum.Outbound.ObjToInt(),
+ TaskTypeEnum.OutAllocate.ObjToInt()
+ };
+
+ foreach (var task in tasks)
+ {
+ if (task.TaskStatus == TaskStatusEnum.Cancel.ObjToInt())
+ continue;
+
+ var stock = await _stockRepository.QueryFirstAsync(x => x.PalletCode == task.PalletCode);
+ if (stock == null)
+ throw new Exception($"鎵樼洏 {task.PalletCode} 鏈壘鍒板簱瀛樹俊鎭�");
+
+ if (task.TaskType == inPickType)
+ {
+ stock.StockStatus = StockStatusEmun.鍑哄簱瀹屾垚.ObjToInt();
+ }
+ else if (inboundTypes.Contains(task.TaskType))
+ {
+ stock.StockStatus = StockStatusEmun.缁勭洏鏆傚瓨.ObjToInt();
+ }
+ else if (outboundTypes.Contains(task.TaskType))
+ {
+ stock.StockStatus = StockStatusEmun.鍏ュ簱瀹屾垚.ObjToInt();
+
+ var outStockLock = await _outStockLockInfoService.Db
+ .Queryable<Dt_OutStockLockInfo>()
+ .Where(x => x.PalletCode == task.PalletCode)
+ .FirstAsync();
+
+ if (outStockLock == null)
+ throw new Exception($"鎵樼洏 {task.PalletCode} 鏈壘鍒板嚭搴撻攣瀹氫俊鎭�");
+
+ int detailId = outStockLock.OrderDetailIds.ObjToInt();
+ var outboundDetail = await _outboundOrderDetailService.Db
+ .Queryable<Dt_OutboundOrderDetail>()
+ .Where(x => x.Id == detailId)
+ .FirstAsync();
+
+ if (outboundDetail == null)
+ throw new Exception($"鍑哄簱鏄庣粏ID {detailId} 涓嶅瓨鍦�");
+
+ if (outboundDetail.LockQuantity < outStockLock.AssignQuantity)
+ throw new Exception($"鍑哄簱鏄庣粏 {detailId} 閿佸畾鏁伴噺涓嶈冻");
+
+ outboundDetail.LockQuantity -= outStockLock.AssignQuantity;
+ _outboundOrderDetailService.UpdateData(outboundDetail);
+
+ _outboundLockInfoRepository.DeleteAndMoveIntoHty(outStockLock, OperateTypeEnum.浜哄伐鍒犻櫎);
+ }
+
+ await _stockRepository.UpdateDataAsync(stock);
+
+ task.TaskStatus = TaskStatusEnum.Cancel.ObjToInt();
+ bool archiveSuccess = _task_HtyService.DeleteAndMoveIntoHty(task, OperateTypeEnum.浜哄伐鍒犻櫎);
+
+ if (!archiveSuccess)
+ {
+ await Db.Deleteable(task).ExecuteCommandAsync();
+ }
+ }
+
+ _unitOfWorkManage.CommitTran();
+ return WebResponseContent.Instance.OK("浠诲姟鍙栨秷鎴愬姛");
+ }
+ catch (Exception ex)
+ {
+ _unitOfWorkManage.RollbackTran();
+ _logger.LogError(ex, "浠诲姟鍙栨秷寮傚父");
+ return WebResponseContent.Instance.Error($"浠诲姟鍙栨秷澶辫触锛歿ex.Message}");
+ }
+ }
+
+ public async Task<WebResponseContent> AreaRelocationTaskCompleted(Dt_Task task)
+ {
+ WebResponseContent content = new WebResponseContent();
+ try
+ {
+ if (task == null || string.IsNullOrEmpty(task.PalletCode) || string.IsNullOrEmpty(task.TargetAddress))
+ {
+ return WebResponseContent.Instance.Error("绉诲簱浠诲姟淇℃伅涓嶅畬鏁达紙鎵樼洏鍙�/鐩爣璐т綅涓虹┖锛�");
+ }
+
+ // 2. 鏌ヨ鎵樼洏搴撳瓨淇℃伅
+ 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($"鏈壘鍒版墭鐩榌{task.PalletCode}]瀵瑰簲鐨勭粍鐩樹俊鎭�");
+ }
+
+ // 闈炵┖鎵樼洏蹇呴』鏈夋槑缁�
+ if (stockInfo.Details.Count == 0 && stockInfo.PalletType != PalletTypeEnum.Empty.ObjToInt())
+ {
+ _logger.LogInformation($"TaskService RelocationTaskCompleted: 鏈壘鍒拌鎵樼洏搴撳瓨鏄庣粏淇℃伅.{task.TaskNum}");
+ return WebResponseContent.Instance.Error($"鏈壘鍒拌鎵樼洏[{task.PalletCode}]搴撳瓨鏄庣粏淇℃伅");
+ }
+
+ // 3. 鏌ヨ鐩爣璐т綅+鍘熻揣浣嶄俊鎭�
+ Dt_LocationInfo targetLocationInfo = _locationInfoService.Repository.QueryFirst(x => x.LocationCode == task.TargetAddress);
+ if (targetLocationInfo == null)
+ {
+ return content.Error($"鏈壘鍒板搴旂殑缁堢偣璐т綅[{task.TargetAddress}]淇℃伅");
+ }
+
+ // 鍘熻揣浣嶄俊鎭�
+ Dt_LocationInfo oldLocationInfo = null;
+ if (!string.IsNullOrEmpty(stockInfo.LocationCode))
+ {
+ oldLocationInfo = _locationInfoService.Repository.QueryFirst(x => x.LocationCode == stockInfo.LocationCode);
+ if (oldLocationInfo == null)
+ {
+ return content.Error($"鏈壘鍒板師璐т綅[{stockInfo.LocationCode}]淇℃伅");
+ }
+ }
+
+ // 4. 璐т綅鐘舵�佹牎楠�
+ if (targetLocationInfo.LocationStatus == LocationStatusEnum.InStock.ObjToInt())
+ {
+ return WebResponseContent.Instance.Error($"鐩爣璐т綅[{task.TargetAddress}]鐘舵�佷笉姝g‘锛堝綋鍓嶄负宸插崰鐢級");
+ }
+
+ // 5. 寮�鍚簨鍔″鐞嗘牳蹇冮�昏緫
+ _unitOfWorkManage.BeginTran();
+
+ // 5.1 璁板綍鐩爣璐т綅鍘熺姸鎬侊紝鏇存柊涓哄崰鐢�
+ var beforeTargetLocationStatus = targetLocationInfo.LocationStatus;
+ targetLocationInfo.LocationStatus = stockInfo.PalletType == PalletTypeEnum.Empty.ObjToInt()
+ ? LocationStatusEnum.Pallet.ObjToInt()
+ : LocationStatusEnum.InStock.ObjToInt();
+ _locationInfoService.Repository.UpdateData(targetLocationInfo);
+
+ // 5.2 閲婃斁鍘熻揣浣�
+ int beforeOldLocationStatus = 0;
+ if (oldLocationInfo != null)
+ {
+ beforeOldLocationStatus = oldLocationInfo.LocationStatus;
+ // 鍘熻揣浣嶆仮澶嶄负绌洪棽
+ oldLocationInfo.LocationStatus = LocationStatusEnum.Free.ObjToInt();
+ _locationInfoService.Repository.UpdateData(oldLocationInfo);
+ }
+ // 5.4 鏇存柊搴撳瓨涓讳俊鎭紙缁戝畾鏂拌揣浣嶏級
+ string oldLocationCode = stockInfo.LocationCode; // 璁板綍鍘熻揣浣�
+ stockInfo.LocationCode = targetLocationInfo.LocationCode; // 缁戝畾鐩爣璐т綅
+ stockInfo.PalletCode = task.PalletCode;
+ stockInfo.StockStatus = StockStatusEmun.鍏ュ簱瀹屾垚.ObjToInt();
+
+ _stockRepository.UpdateData(stockInfo);
+
+ // 5.5 鏇存柊浠诲姟鐘舵�佷负瀹屾垚
+ task.TaskStatus = TaskStatusEnum.Finish.ObjToInt();
+ var result = _task_HtyService.DeleteAndMoveIntoHty(task, OperateTypeEnum.鑷姩瀹屾垚);
+
+ // 鎻愪氦浜嬪姟
+ _unitOfWorkManage.CommitTran();
+
+ // 浠诲姟褰掓。澶辫触鍒欑洿鎺ュ垹闄�
+ if (!result)
+ {
+ await Db.Deleteable(task).ExecuteCommandAsync();
+ }
+ try
+ {
+ // 璁板綍鐩爣璐т綅鐘舵�佸彉鏇�
+ _locationStatusChangeRecordService.AddLocationStatusChangeRecord(
+ targetLocationInfo,
+ beforeTargetLocationStatus,
+ StockChangeType.Inbound.ObjToInt(),
+ $"绉诲簱鍏ュ簱锛堝師璐т綅锛歿oldLocationCode}锛�",
+ task.TaskNum);
+
+ // 璁板綍鍘熻揣浣嶇姸鎬佸彉鏇达紙鑻ユ湁锛�
+ if (oldLocationInfo != null)
+ {
+ _locationStatusChangeRecordService.AddLocationStatusChangeRecord(
+ oldLocationInfo,
+ beforeOldLocationStatus,
+ StockChangeType.Outbound.ObjToInt(),
+ $"绉诲簱鍑哄簱锛堢洰鏍囪揣浣嶏細{targetLocationInfo.LocationCode}锛�",
+ task.TaskNum);
+ }
+ }
+ catch (Exception ex)
+ {
+ _logger.LogInformation($"RelocationTaskCompleted AddLocationStatusChangeRecord : {ex.Message} ");
+ }
+
+ return content.OK();
+ }
+ catch (Exception ex)
+ {
+ // 浜嬪姟鍥炴粴
+ _unitOfWorkManage.RollbackTran();
+ _logger.LogError($"RelocationTaskCompleted 澶勭悊澶辫触锛歿ex.Message}", ex);
+ return await Task.FromResult(WebResponseContent.Instance.Error($"绉诲簱浠诲姟澶勭悊澶辫触锛歿ex.Message}"));
+ }
+ }
+
+
+ /// <summary>
+ /// 璺ㄥ尯鍩熺Щ搴撲换鍔″畬鎴�
+ /// </summary>
+ /// <param name="task"></param>
+ /// <returns></returns>
+ public async Task<WebResponseContent> CrossAreaRelocationTaskCompleted(Dt_Task task)
+ {
+ WebResponseContent content = new WebResponseContent();
+ try
+ {
+ if (task == null || string.IsNullOrEmpty(task.PalletCode) || string.IsNullOrEmpty(task.TargetAddress))
+ {
+ return WebResponseContent.Instance.Error("璺ㄥ尯鍩熺Щ搴撲换鍔′俊鎭笉瀹屾暣锛堟墭鐩樺彿/鐩爣璐т綅涓虹┖锛�");
+ }
+
+ // 2. 鏌ヨ鎵樼洏搴撳瓨淇℃伅
+ 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($"鏈壘鍒版墭鐩榌{task.PalletCode}]瀵瑰簲鐨勫簱瀛樹俊鎭�");
+ }
+
+ // 闈炵┖鎵樼洏蹇呴』鏈夋槑缁�
+ if (stockInfo.Details.Count == 0 && stockInfo.PalletType != PalletTypeEnum.Empty.ObjToInt())
+ {
+ _logger.LogInformation($"CrossAreaRelocationTaskCompleted: 鏈壘鍒拌鎵樼洏搴撳瓨鏄庣粏淇℃伅.{task.TaskNum}");
+ return WebResponseContent.Instance.Error($"鏈壘鍒拌鎵樼洏[{task.PalletCode}]搴撳瓨鏄庣粏淇℃伅");
+ }
+
+ // 3. 鏌ヨ鐩爣璐т綅 + 鍘熻揣浣嶄俊鎭�
+ Dt_LocationInfo targetLocationInfo = _locationInfoService.Repository.QueryFirst(x => x.LocationCode == task.TargetAddress);
+ if (targetLocationInfo == null)
+ {
+ return content.Error($"鏈壘鍒板搴旂殑缁堢偣璐т綅[{task.TargetAddress}]淇℃伅");
+ }
+
+ // 鍘熻揣浣嶄俊鎭�
+ Dt_LocationInfo oldLocationInfo = null;
+ if (!string.IsNullOrEmpty(stockInfo.LocationCode))
+ {
+ oldLocationInfo = _locationInfoService.Repository.QueryFirst(x => x.LocationCode == stockInfo.LocationCode);
+ if (oldLocationInfo == null)
+ {
+ return content.Error($"鏈壘鍒板師璐т綅[{stockInfo.LocationCode}]淇℃伅");
+ }
+ }
+
+ // 4. 璐т綅鐘舵�佹牎楠�
+ if (targetLocationInfo.LocationStatus == LocationStatusEnum.InStock.ObjToInt())
+ {
+ return WebResponseContent.Instance.Error($"鐩爣璐т綅[{task.TargetAddress}]鐘舵�佷笉姝g‘锛堝綋鍓嶄负宸插崰鐢級");
+ }
+
+ // 5. 寮�鍚簨鍔″鐞嗘牳蹇冮�昏緫
+ _unitOfWorkManage.BeginTran();
+
+ // 5.1 鐩爣璐т綅鏇存柊涓哄崰鐢�
+ var beforeTargetLocationStatus = targetLocationInfo.LocationStatus;
+ targetLocationInfo.LocationStatus = stockInfo.PalletType == PalletTypeEnum.Empty.ObjToInt()
+ ? LocationStatusEnum.Pallet.ObjToInt()
+ : LocationStatusEnum.InStock.ObjToInt();
+ _locationInfoService.Repository.UpdateData(targetLocationInfo);
+
+ // 5.2 鍘熻揣浣嶉噴鏀剧┖闂�
+ int beforeOldLocationStatus = 0;
+ if (oldLocationInfo != null)
+ {
+ beforeOldLocationStatus = oldLocationInfo.LocationStatus;
+ oldLocationInfo.LocationStatus = LocationStatusEnum.Free.ObjToInt();
+ _locationInfoService.Repository.UpdateData(oldLocationInfo);
+ }
+
+ // 5.3 鏇存柊搴撳瓨锛氱粦瀹氭柊璐т綅 + 鎭㈠姝e父鐘舵��
+ string oldLocationCode = stockInfo.LocationCode;
+ stockInfo.LocationCode = targetLocationInfo.LocationCode;
+ stockInfo.StockStatus = StockStatusEmun.鍏ュ簱瀹屾垚.ObjToInt();
+ stockInfo.LocationType = targetLocationInfo.LocationType;
+ _stockRepository.UpdateData(stockInfo);
+
+ // 5.4 浠诲姟鏍囪涓哄畬鎴�
+ task.TaskStatus = TaskStatusEnum.Finish.ObjToInt();
+ var result = _task_HtyService.DeleteAndMoveIntoHty(task, OperateTypeEnum.鑷姩瀹屾垚);
+
+ // 鎻愪氦浜嬪姟
+ _unitOfWorkManage.CommitTran();
+
+ // 浠诲姟褰掓。澶辫触鍒欏垹闄�
+ if (!result)
+ {
+ await Db.Deleteable(task).ExecuteCommandAsync();
+ }
+
+ // 璁板綍璐т綅鐘舵�佸彉鏇存棩蹇�
+ try
+ {
+ _locationStatusChangeRecordService.AddLocationStatusChangeRecord(
+ targetLocationInfo,
+ beforeTargetLocationStatus,
+ StockChangeType.Inbound.ObjToInt(),
+ $"璺ㄥ尯鍩熺Щ搴撳叆搴擄紙鍘熻揣浣嶏細{oldLocationCode}锛�",
+ task.TaskNum);
+
+ if (oldLocationInfo != null)
+ {
+ _locationStatusChangeRecordService.AddLocationStatusChangeRecord(
+ oldLocationInfo,
+ beforeOldLocationStatus,
+ StockChangeType.Outbound.ObjToInt(),
+ $"璺ㄥ尯鍩熺Щ搴撳嚭搴擄紙鐩爣璐т綅锛歿targetLocationInfo.LocationCode}锛�",
+ task.TaskNum);
+ }
+ }
+ catch (Exception ex)
+ {
+ _logger.LogInformation($"CrossAreaRelocationTaskCompleted 璁板綍鏃ュ織寮傚父锛歿ex.Message}");
+ }
+
+ return content.OK("璺ㄥ尯鍩熺Щ搴撲换鍔″畬鎴�");
+ }
+ catch (Exception ex)
+ {
+ _unitOfWorkManage.RollbackTran();
+ _logger.LogError($"CrossAreaRelocationTaskCompleted 澶勭悊澶辫触锛歿ex.Message}", ex);
+ return await Task.FromResult(WebResponseContent.Instance.Error($"璺ㄥ尯鍩熺Щ搴撲换鍔″鐞嗗け璐ワ細{ex.Message}"));
+ }
+ }
}
}
+
--
Gitblit v1.9.3