From 37454e625df68d40897112b2e8c2e3cf4d7163e3 Mon Sep 17 00:00:00 2001
From: heshaofeng <heshaofeng@hnkhzn.com>
Date: 星期三, 25 三月 2026 11:43:10 +0800
Subject: [PATCH] 1
---
项目代码/WMS无仓储版/WIDESEA_WMSServer/WIDESEA_InboundService/InboundOrderService.cs | 555 +++++++++++++++++++++++++++++++++++++++++++++++++------
1 files changed, 490 insertions(+), 65 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_InboundService/InboundOrderService.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_InboundService/InboundOrderService.cs"
index c89c12a..418c05f 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_InboundService/InboundOrderService.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_InboundService/InboundOrderService.cs"
@@ -1,9 +1,13 @@
锘縰sing AutoMapper;
using SqlSugar;
+using System.Dynamic;
+using System.Text.RegularExpressions;
using System.Threading.Tasks;
using WIDESEA_Common.CommonEnum;
+using WIDESEA_Common.LocationEnum;
using WIDESEA_Common.OrderEnum;
using WIDESEA_Common.StockEnum;
+using WIDESEA_Common.TaskEnum;
using WIDESEA_Core;
using WIDESEA_Core.BaseRepository;
using WIDESEA_Core.BaseServices;
@@ -13,7 +17,9 @@
using WIDESEA_Core.Helper;
using WIDESEA_Core.Seed;
using WIDESEA_Core.Utilities;
+using WIDESEA_DTO.Base;
using WIDESEA_DTO.Inbound;
+using WIDESEA_DTO.Stock;
using WIDESEA_IBasicService;
using WIDESEA_IInboundService;
using WIDESEA_IRecordService;
@@ -32,15 +38,22 @@
private IStockService _stockService;
private readonly IMaterialUnitService _materialUnitService;
+ private readonly IMaterielInfoService _materielInfoService;
private readonly IInboundOrderDetailService _inboundOrderDetailService;
private readonly IRepository<Dt_InboundOrderDetail> _inboundOrderDetailRepository;
private readonly IRepository<Dt_StockInfoDetail> _stockDetailRepository;
private readonly IRepository<Dt_InboundOrder> _inboundOrderRepository;
private readonly IRepository<Dt_WarehouseArea> _warehouseAreaRepository;
+ private readonly IRepository<Dt_LocationType> _locationTypeRepository;
private readonly IRepository<Dt_StockInfo> _stockRepository;
+ private readonly IRepository<Dt_LocationInfo> _locationInfoRepository;
+ private readonly IBasicService _basicService;
+ private readonly IRepository<Dt_AllocateOrder> _allocateOrderRepository;
+ private readonly IRepository<Dt_OutboundOrder> _outboundOrderRepository;
+ private readonly IRepository<Dt_OutboundOrderDetail> _outboundOrderDetailRepository;
public IRepository<Dt_InboundOrder> Repository => BaseDal;
- public InboundOrderService(IRepository<Dt_InboundOrder> BaseDal, IMapper mapper, IUnitOfWorkManage unitOfWorkManage, IRepository<Dt_InboundOrderDetail> inboundOrderDetailRepository, IRepository<Dt_Task> taskRepository, IStockService stockService, IInboundOrderDetailService inboundOrderDetailService, IMaterialUnitService materialUnitService, IRepository<Dt_StockInfoDetail> stockDetailRepository, IRepository<Dt_InboundOrder> inboundOrderRepository, IRepository<Dt_WarehouseArea> warehouseAreaRepository,IRepository<Dt_StockInfo> stockRepository) : base(BaseDal)
+ public InboundOrderService(IRepository<Dt_InboundOrder> BaseDal, IMapper mapper, IUnitOfWorkManage unitOfWorkManage, IRepository<Dt_InboundOrderDetail> inboundOrderDetailRepository, IRepository<Dt_Task> taskRepository, IStockService stockService, IInboundOrderDetailService inboundOrderDetailService, IMaterialUnitService materialUnitService, IRepository<Dt_StockInfoDetail> stockDetailRepository, IRepository<Dt_InboundOrder> inboundOrderRepository, IRepository<Dt_WarehouseArea> warehouseAreaRepository, IRepository<Dt_StockInfo> stockRepository, IRepository<Dt_LocationType> locationTypeRepository, IMaterielInfoService materielInfoService, IBasicService basicService, IRepository<Dt_LocationInfo> locationInfoRepository, IRepository<Dt_AllocateOrder> allocateOrderRepository, IRepository<Dt_OutboundOrder> outboundOrderRepository, IRepository<Dt_OutboundOrderDetail> outboundOrderDetailRepository) : base(BaseDal)
{
_mapper = mapper;
_unitOfWorkManage = unitOfWorkManage;
@@ -53,6 +66,13 @@
_inboundOrderRepository = inboundOrderRepository;
_warehouseAreaRepository = warehouseAreaRepository;
_stockRepository = stockRepository;
+ _locationTypeRepository = locationTypeRepository;
+ _materielInfoService = materielInfoService;
+ _basicService = basicService;
+ _locationInfoRepository = locationInfoRepository;
+ _allocateOrderRepository = allocateOrderRepository;
+ _outboundOrderRepository = outboundOrderRepository;
+ _outboundOrderDetailRepository = outboundOrderDetailRepository;
}
public async Task<WebResponseContent> ReceiveInboundOrder(List<Dt_InboundOrder> models, int operateType)
@@ -82,20 +102,33 @@
{
if (BaseDal.QueryFirst(x => x.UpperOrderNo == model.UpperOrderNo) != null)
{
- return WebResponseContent.Instance.Error($"鍏ュ簱鍗曞彿閲嶅");
+ return WebResponseContent.Instance.Error($"{model.UpperOrderNo}鍏ュ簱鍗曞彿閲嶅");
}
}
foreach (var model in models)
{
+ var materielCodes = model.Details.Select(x => x.MaterielCode).Distinct().ToList();
+ var materielInfos = _materielInfoService.Db.Queryable<Dt_MaterielInfo>().Where(x => materielCodes.Contains(x.MaterielCode)).ToList();
+
foreach (var item in model.Details)
{
- var purchaseToStockResult = await _materialUnitService.ConvertPurchaseToStockAsync(item.MaterielCode, item.BarcodeQty);
- item.Unit = purchaseToStockResult.Unit;
- item.OrderQuantity = purchaseToStockResult.Quantity;
+ Dt_MaterielInfo materielInfo = materielInfos.First(x => x.MaterielCode == item.MaterielCode);
+ //var purchaseToStockResult = await _materialUnitService.ConvertPurchaseToStockAsync(item.MaterielCode, item.BarcodeQty);
+
+ UnitConvertResultDTO totalResult = _basicService.UnitQuantityConvert(item.MaterielCode, item.Unit, materielInfo.inventoryUOM, item.OrderQuantity);
+ item.Unit = totalResult.ToUnit;
+ item.OrderQuantity = totalResult.ToQuantity;
+ if (materielInfos.Any())
+ {
+ item.MaterielName = materielInfos.FirstOrDefault(x => x.MaterielCode == item.MaterielCode)?.MaterielName ?? "";
+ }
+ }
+ if (model.OrderType != InOrderTypeEnum.AllocatInbound.ObjToInt())
+ {
+ model.InboundOrderNo = CreateCodeByRule(nameof(RuleCodeEnum.InboundOrderRule));
}
- model.InboundOrderNo = CreateCodeByRule(nameof(RuleCodeEnum.InboundOrderRule));
Db.InsertNav(model).Include(x => x.Details).ExecuteCommand();
}
return WebResponseContent.Instance.OK();
@@ -120,16 +153,19 @@
{
return WebResponseContent.Instance.Error($"鏈壘鍒板叆搴撳崟鏄庣粏淇℃伅");
}
+ if (inboundOrder.OrderStatus != InOrderStatusEnum.鏈紑濮�.ObjToInt())
+ {
+ return WebResponseContent.Instance.Error($"璇ヨ鍗曠姸鎬佷笉鍏佽淇敼");
+ }
List<Dt_InboundOrderDetail> inboundOrderDetails = new List<Dt_InboundOrderDetail>();
List<Dt_InboundOrderDetail> updateInboundOrderDetails = new List<Dt_InboundOrderDetail>();
List<int> detailIds = new List<int>();
+ var materielCodes = model.Details.Select(x => x.MaterielCode).Distinct().ToList();
+ var materielInfos = _materielInfoService.Db.Queryable<Dt_MaterielInfo>().Where(x => materielCodes.Contains(x.MaterielCode)).ToList();
+
foreach (var item in model.Details)
{
- if (string.IsNullOrEmpty(item.Barcode))
- {
-
- }
- else
+ if (!string.IsNullOrEmpty(item.Barcode))
{
Dt_InboundOrderDetail? inboundOrderDetail = inboundOrder.Details.FirstOrDefault(x => x.Barcode == item.Barcode);
if (inboundOrderDetail == null)
@@ -152,11 +188,18 @@
var purchaseToStockResult = await _materialUnitService.ConvertPurchaseToStockAsync(item.MaterielCode, item.BarcodeQty);
inboundOrderDetail.Unit = purchaseToStockResult.Unit;
inboundOrderDetail.OrderQuantity = purchaseToStockResult.Quantity;
-
+ if (materielInfos.Any())
+ {
+ inboundOrderDetail.MaterielName = materielInfos.FirstOrDefault(x => x.MaterielCode == item.MaterielCode)?.MaterielName ?? "";
+ }
inboundOrderDetails.Add(inboundOrderDetail);
}
else
{
+ if (materielInfos.Any())
+ {
+ inboundOrderDetail.MaterielName = materielInfos.FirstOrDefault(x => x.MaterielCode == item.MaterielCode)?.MaterielName ?? "";
+ }
inboundOrderDetail.lineNo = item.lineNo;
inboundOrderDetail.MaterielCode = item.MaterielCode;
inboundOrderDetail.SupplyCode = item.SupplyCode;
@@ -223,6 +266,10 @@
if (inboundOrder.Details == null || inboundOrder.Details.Count == 0)
{
return WebResponseContent.Instance.Error($"鏈壘鍒板叆搴撳崟鏄庣粏淇℃伅");
+ }
+ if (inboundOrder.OrderStatus != InOrderStatusEnum.鏈紑濮�.ObjToInt())
+ {
+ return WebResponseContent.Instance.Error($"璇ヨ鍗曠姸鎬佷笉鍏佽鍒犻櫎");
}
//Db.DeleteNav(inboundOrder).Include(x => x.Details).ExecuteCommand();
_unitOfWorkManage.BeginTran();
@@ -328,12 +375,12 @@
if (!result2.Item1) return content = WebResponseContent.Instance.Error(result2.Item2);
// materielGroupDTO.WarehouseCode
- var code = _warehouseAreaRepository.Db.Queryable<Dt_WarehouseArea>().Where(x => x.Code == materielGroupDTO.WarehouseType).Select(x=>x.Code).First();
- if(string.IsNullOrEmpty(code))
+ var code = _warehouseAreaRepository.Db.Queryable<Dt_WarehouseArea>().Where(x => x.Code == materielGroupDTO.WarehouseType).Select(x => x.Code).First();
+ if (string.IsNullOrEmpty(code))
{
return content = WebResponseContent.Instance.Error($"浠撳簱涓病鏈夎{materielGroupDTO.WarehouseType}缂栧彿銆�");
}
-
+
Dt_InboundOrder inboundOrder = GetInboundOrder(materielGroupDTO.OrderNo);
@@ -355,10 +402,10 @@
if (stockInfo == null)
{
- stockInfo = new Dt_StockInfo() { PalletType = (int)PalletTypeEnum.None,LocationType=materielGroupDTO.locationType.ObjToInt() };
+ stockInfo = new Dt_StockInfo() { PalletType = (int)PalletTypeEnum.None, LocationType = materielGroupDTO.locationType.ObjToInt() };
stockInfo.Details = new List<Dt_StockInfoDetail>();
}
-
+
foreach (var item in dbinboundOrderDetails)
{
stockInfo.Details.Add(new Dt_StockInfoDetail
@@ -372,15 +419,15 @@
SupplyCode = item.SupplyCode,
WarehouseCode = materielGroupDTO.WarehouseType,
StockQuantity = item.OrderQuantity,
- BarcodeQty=item.BarcodeQty,
- BarcodeUnit=item.BarcodeUnit,
- FactoryArea= inboundOrder.FactoryArea,
- Status = 0,
+ BarcodeQty = item.BarcodeQty,
+ BarcodeUnit = item.BarcodeUnit,
+ FactoryArea = inboundOrder.FactoryArea,
+ Status = 0,
OrderNo = inboundOrder.InboundOrderNo,
BusinessType = inboundOrder.BusinessType,
-
+
});
-
+
item.ReceiptQuantity = item.BarcodeQty;
item.OrderDetailStatus = OrderDetailStatusEnum.Over.ObjToInt();
item.WarehouseCode = materielGroupDTO.WarehouseType;
@@ -427,17 +474,24 @@
WebResponseContent content = new WebResponseContent();
try
- {
+ {
+
(bool, string, object?) result2 = ModelValidate.ValidateModelData(materielGroupDTO);
if (!result2.Item1) return content = WebResponseContent.Instance.Error(result2.Item2);
- bool code = _warehouseAreaRepository.Db.Queryable<Dt_WarehouseArea>().Where(x => x.Id == materielGroupDTO.WarehouseCode).Any();
+ bool code = _locationTypeRepository.Db.Queryable<Dt_LocationType>().Where(x => x.LocationType == materielGroupDTO.WarehouseCode).Any();
+ bool statu = _locationInfoRepository.Db.Queryable<Dt_LocationInfo>().Where(x => x.LocationType == materielGroupDTO.WarehouseCode && x.LocationStatus == (int)LocationStatusEnum.Free && x.EnableStatus == (int)EnableStatusEnum.Normal).Any();
+ if (!statu)
+ {
+ return content = WebResponseContent.Instance.Error($"璇ュ尯鍩熸棤璐т綅鍙垎閰�");
+ }
if (!code)
{
- return content = WebResponseContent.Instance.Error($"浠撳簱涓病鏈夎{materielGroupDTO.WarehouseCode}缂栧彿銆�");
+ return content = WebResponseContent.Instance.Error($"鍖哄煙涓病鏈夎{materielGroupDTO.WarehouseCode}缂栧彿銆�");
}
- if(_stockRepository.QueryFirst(x=>x.PalletCode == materielGroupDTO.PalletCode)!=null){
+ if (_stockRepository.QueryFirst(x => x.PalletCode == materielGroupDTO.PalletCode) != null)
+ {
return WebResponseContent.Instance.Error("璇ユ墭鐩樺凡缁忕粍杩囩洏");
}
@@ -456,7 +510,7 @@
{
if (stockInfo == null)
{
- stockInfo = new Dt_StockInfo() { PalletType = PalletTypeEnum.Empty.ObjToInt(), StockStatus = StockStatusEmun.缁勭洏鏆傚瓨.ObjToInt(), PalletCode = materielGroupDTO.PalletCode,LocationType= materielGroupDTO.WarehouseCode.ObjToInt() };
+ stockInfo = new Dt_StockInfo() { PalletType = PalletTypeEnum.Empty.ObjToInt(), StockStatus = StockStatusEmun.缁勭洏鏆傚瓨.ObjToInt(), PalletCode = materielGroupDTO.PalletCode, LocationType = materielGroupDTO.WarehouseCode.ObjToInt() };
stockInfo.Details = new List<Dt_StockInfoDetail>();
}
else
@@ -614,15 +668,19 @@
{
resultDTO.UniqueUnit = "";
}
- var validDetails = _stockDetailRepository.Db.Queryable<Dt_StockInfoDetail>().Where(s => s.OrderNo == orderNo).ToList();
- resultDTO.StockSumQuantity = orderDetail.Details.Sum(d => d.OrderQuantity);
- resultDTO.StockCount = orderDetail.Details.Count;
- if (validDetails.Any())
- {
- resultDTO.StockSumQuantity -= validDetails.Sum(d => d.StockQuantity);
- // 鏄庣粏璁板綍鏁帮細绗﹀悎鏉′欢鐨勬湁鏁堣褰曟潯鏁�
- resultDTO.StockCount -= validDetails.Count;
- }
+ var inbound = _inboundOrderRepository.Db.Queryable<Dt_InboundOrder>().Where(x => x.InboundOrderNo == orderNo);
+ var inboundDetails = _inboundOrderDetailRepository.Db.Queryable<Dt_InboundOrderDetail>().Where(x => x.OrderId == inbound.First().Id).ToList();
+ resultDTO.StockSumQuantity = inboundDetails.Where(x => x.ReceiptQuantity == 0).Sum(x => x.OrderQuantity);
+ resultDTO.StockCount = inboundDetails.Where(x => x.ReceiptQuantity == 0).Count();
+ //var validDetails = _stockDetailRepository.Db.Queryable<Dt_StockInfoDetail>().Where(s => s.OrderNo == orderNo).ToList();
+ //resultDTO.StockSumQuantity = orderDetail.Details.Sum(d => d.OrderQuantity);
+ //resultDTO.StockCount = orderDetail.Details.Count;
+ //if (validDetails.Any())
+ //{
+ // resultDTO.StockSumQuantity -= validDetails.Sum(d => d.StockQuantity);
+ // // 鏄庣粏璁板綍鏁帮細绗﹀悎鏉′欢鐨勬湁鏁堣褰曟潯鏁�
+ // resultDTO.StockCount -= validDetails.Count;
+ //}
return content.OK("", resultDTO);
}
catch (Exception ex)
@@ -631,42 +689,409 @@
}
}
- public WebResponseContent UndoPalletGroup(string palletCode)
+ /// <summary>
+ /// 鎾ら攢缁勭洏锛堟櫤鑳借瘑鍒緭鍏ユ槸鎵樼洏鍙锋垨鏉$爜锛�
+ /// </summary>
+ /// <param name="code">鎵樼洏鍙锋垨鏉$爜</param>
+ /// <returns>鎿嶄綔缁撴灉</returns>
+ public WebResponseContent UndoPalletGroup(string code)
{
- if (string.IsNullOrWhiteSpace(palletCode))
+ if (string.IsNullOrWhiteSpace(code))
{
- return WebResponseContent.Instance.Error("鎵樼洏鍙蜂笉鑳戒负绌�");
+ return WebResponseContent.Instance.Error("鎵樼洏鍙锋垨鏉$爜涓嶈兘涓虹┖");
}
- var stock= _stockRepository.Db.Queryable<Dt_StockInfo>().Includes(o=>o.Details).First(x => x.PalletCode == palletCode && x.StockStatus==3);
- if (stock == null)
+
+ try
{
- return WebResponseContent.Instance.Error($"鏈壘鍒版墭鐩樺彿{palletCode}瀵瑰簲鐨勫簱瀛樿褰�");
+ _unitOfWorkManage.BeginTran();
+
+
+ string palletCode = null;
+ string barcode = null;
+ int stockStatus = 0;
+
+ // 1. 鍏堝皾璇曟寜鎵樼洏鍙锋煡璇�
+ var stockByPallet = _stockRepository.Db.Queryable<Dt_StockInfo>()
+ .Includes(o => o.Details)
+ .First(x => x.PalletCode == code
+ && (x.StockStatus == (int)StockStatusEmun.缁勭洏鏆傚瓨
+ || x.StockStatus == StockStatusEmun.鍏ュ簱纭.ObjToInt()));
+
+ if (stockByPallet != null)
+ {
+ // 璇嗗埆涓烘墭鐩樺彿
+ palletCode = code;
+ stockStatus = stockByPallet.StockStatus;
+
+ var task = _taskRepository.Db.Queryable<Dt_Task>().Where(t => t.PalletCode == palletCode).ToList();
+ if (task != null && task.Any())
+ {
+ return WebResponseContent.Instance.Error($"鎵樼洏鍙� {palletCode} 瀛樺湪鏈畬鎴愮殑浠诲姟锛屾棤娉曟挙閿�");
+ }
+
+ if (stockStatus == StockStatusEmun.鍏ュ簱纭.ObjToInt())
+ {
+ return WebResponseContent.Instance.Error($"鎵樼洏鍙� {palletCode} 澶勪簬鍏ュ簱纭鐘舵�侊紝绂佹鏁存墭鐩樻挙閿�锛岃鍗曠嫭鎾ら攢鏉$爜");
+ }
+ }
+ else
+ {
+ var detail = _stockDetailRepository.Db.Queryable<Dt_StockInfoDetail>().Where(d => d.Barcode == code).First();
+
+ if (detail != null)
+ {
+ var stockInfo = _stockRepository
+ .Db.Queryable<Dt_StockInfo>()
+ .Where(s => s.Id == detail.StockId && (s.StockStatus == (int)StockStatusEmun.缁勭洏鏆傚瓨 || s.StockStatus == StockStatusEmun.鍏ュ簱纭.ObjToInt()))
+ .First();
+
+ if (stockInfo != null)
+ {
+ barcode = code;
+ palletCode = stockInfo.PalletCode;
+ stockStatus = stockInfo.StockStatus;
+ }
+ }
+ else
+ {
+ _unitOfWorkManage.RollbackTran();
+ return WebResponseContent.Instance.Error($"鏈壘鍒� {code} 瀵瑰簲鐨勬墭鐩樻垨鏉$爜璁板綍");
+ }
+ }
+
+ // 鏍规嵁璇嗗埆缁撴灉鎵ц鎾ら攢閫昏緫
+ if (!string.IsNullOrWhiteSpace(barcode))
+ {
+ // ===== 鎾ら攢鎸囧畾鏉$爜 =====
+ var stock = _stockRepository.Db.Queryable<Dt_StockInfo>()
+ .Includes(o => o.Details)
+ .First(x => x.PalletCode == palletCode
+ && (x.StockStatus == (int)StockStatusEmun.缁勭洏鏆傚瓨
+ || x.StockStatus == StockStatusEmun.鍏ュ簱纭.ObjToInt()));
+
+ if (stock == null)
+ {
+ _unitOfWorkManage.RollbackTran();
+ return WebResponseContent.Instance.Error($"鏈壘鍒版墭鐩樺彿 {palletCode} 瀵瑰簲鐨勫簱瀛樿褰�");
+ }
+
+ var targetDetail = stock.Details?.FirstOrDefault(x => x.Barcode == barcode);
+ if (targetDetail == null)
+ {
+ _unitOfWorkManage.RollbackTran();
+ return WebResponseContent.Instance.Error($"鎵樼洏 {palletCode} 涓嬫湭鎵惧埌鏉$爜 {barcode} 鐨勬槑缁嗚褰�");
+ }
+
+ if (stockStatus == StockStatusEmun.鍏ュ簱纭.ObjToInt())
+ {
+ var totalDetails = stock.Details?.Count ?? 0;
+ if (totalDetails <= 1)
+ {
+ _unitOfWorkManage.RollbackTran();
+ return WebResponseContent.Instance.Error($"鎵樼洏 {palletCode} 澶勪簬鍏ュ簱纭鐘舵�侊紝褰撳墠浠呭墿浣欐渶鍚�1鏉℃槑缁嗭紝绂佹鎾ら攢锛堝繀椤讳繚鐣欒嚦灏�1鏉″簱瀛樻槑缁嗭級");
+ }
+ }
+
+ ResetInboundOrderStatus(new List<string> { targetDetail.OrderNo }, new List<string> { targetDetail.Barcode });
+ _stockDetailRepository.DeleteData(targetDetail);
+
+ var remainingDetails = _stockDetailRepository.Db.Queryable<Dt_StockInfoDetail>()
+ .Where(x => x.StockId == stock.Id)
+ .ToList();
+
+ if (!remainingDetails.Any())
+ {
+ if (stockStatus == (int)StockStatusEmun.缁勭洏鏆傚瓨)
+ {
+ ResetInboundOrderStatus(stock.Details.Select(d => d.OrderNo).Distinct().ToList());
+ _stockRepository.DeleteData(stock);
+ }
+ _unitOfWorkManage.CommitTran();
+ return WebResponseContent.Instance.OK($"鏉$爜 {barcode} 鎾ら攢鎴愬姛锛屾墭鐩樻棤鍓╀綑鏄庣粏锛屽凡閲嶇疆鍏宠仈鍏ュ簱鍗曠姸鎬�");
+ }
+
+ _unitOfWorkManage.CommitTran();
+ return WebResponseContent.Instance.OK($"鏉$爜 {barcode} 鎾ら攢鎴愬姛锛屾墭鐩樹粛鏈夊墿浣欐槑缁�");
+ }
+ else
+ {
+ var stock = _stockRepository.Db.Queryable<Dt_StockInfo>()
+ .Includes(o => o.Details)
+ .First(x => x.PalletCode == palletCode
+ && (x.StockStatus == (int)StockStatusEmun.缁勭洏鏆傚瓨
+ || x.StockStatus == StockStatusEmun.鍏ュ簱纭.ObjToInt()));
+
+ if (stock == null)
+ {
+ _unitOfWorkManage.RollbackTran();
+ return WebResponseContent.Instance.Error($"鏈壘鍒版墭鐩樺彿 {palletCode} 瀵瑰簲鐨勫簱瀛樿褰�");
+ }
+
+ if (stock.Details == null || !stock.Details.Any())
+ {
+ _stockRepository.DeleteData(stock);
+ _unitOfWorkManage.CommitTran();
+ return WebResponseContent.Instance.OK("鎵樼洏鏃犳槑缁嗚褰曪紝宸茬洿鎺ュ垹闄ゆ墭鐩樹富鏁版嵁");
+ }
+
+ var relatedOrderNos = stock.Details.Select(d => d.OrderNo).Distinct().ToList();
+ if (!relatedOrderNos.Any())
+ {
+ _unitOfWorkManage.RollbackTran();
+ return WebResponseContent.Instance.Error("搴撳瓨鏄庣粏鏈叧鑱斾换浣曞叆搴撳崟鍙凤紝鏃犳硶瀹屾垚鎾ら攢");
+ }
+
+ ResetInboundOrderStatus(relatedOrderNos, stock.Details.Select(d => d.Barcode).ToList());
+ _stockDetailRepository.DeleteData(stock.Details);
+ _stockRepository.DeleteData(stock);
+
+ _unitOfWorkManage.CommitTran();
+ return WebResponseContent.Instance.OK("鎵樼洏鎾ら攢鎴愬姛锛屽凡閲嶇疆鍏宠仈鍏ュ簱鍗曞強鏄庣粏鐘舵��");
+ }
}
- // 鑾峰彇搴撳瓨璇︽儏鍏宠仈鐨勬墍鏈夊叆搴撳崟鍙�
- var relatedOrderNos = stock.Details.Select(d => d.OrderNo).First();
- // 鏌ヨ鎵�鏈夊叧鑱旂殑鍏ュ簱鍗曪紙鍚鎯咃級
- var inboundOrders = _inboundOrderRepository.Db.Queryable<Dt_InboundOrder>()
- .Includes(x => x.Details)
- .Where(x => relatedOrderNos==x.InboundOrderNo)
- .First();
-
- var barcodes = stock.Details.Select(d => d.Barcode).ToList();
-
-
- // 鍖归厤搴撳瓨鏉$爜瀵瑰簲鐨勫叆搴撳崟鏄庣粏
- var matchedInboundDetails = inboundOrders.Details
- ?.Where(d => barcodes.Contains(d.Barcode))
- .ToList();
- foreach (var detail in matchedInboundDetails)
+ catch (Exception ex)
{
- detail.ReceiptQuantity = 0;
- detail.OrderDetailStatus = 0;
- _inboundOrderDetailRepository.UpdateData(detail);
+ _unitOfWorkManage.RollbackTran();
+ return WebResponseContent.Instance.Error($"鎵樼洏鎾ら攢澶辫触锛歿ex.Message}");
}
- _stockDetailRepository.DeleteData(stock.Details);
- _stockRepository.DeleteData(stock);
+ }
- return WebResponseContent.Instance.OK();
+
+ private void ResetInboundOrderStatus(List<string> orderNos, List<string> barcodes = null)
+ {
+ foreach (var orderNo in orderNos)
+ {
+ var inboundOrder = _inboundOrderRepository.Db.Queryable<Dt_InboundOrder>()
+ .Includes(x => x.Details)
+ .First(x => x.InboundOrderNo == orderNo);
+
+ if (inboundOrder == null) continue;
+
+ bool isSingleBarcode = barcodes != null && barcodes.Count == 1;
+ if (!isSingleBarcode)
+ {
+ // 闈炲崟涓潯鐮侊紙鏁村崟/澶氫釜鏉$爜锛夛細閲嶇疆涓昏〃鐘舵�佷负0
+ inboundOrder.OrderStatus = 0;
+ _inboundOrderRepository.UpdateData(inboundOrder);
+ }
+
+ // 閲嶇疆鍏ュ簱鍗曟槑缁嗙姸鎬�
+ if (inboundOrder.Details == null || !inboundOrder.Details.Any()) continue;
+
+ var targetDetails = barcodes == null
+ ? inboundOrder.Details.ToList() // 涓嶄紶鏉$爜鍒欓噸缃暣鍗曟槑缁�
+ : inboundOrder.Details.Where(d => barcodes.Contains(d.Barcode)).ToList();
+
+ foreach (var detail in targetDetails)
+ {
+ detail.ReceiptQuantity = 0;
+ detail.OrderDetailStatus = 0;
+ if(inboundOrder.BusinessType == "11")
+ {
+ detail.WarehouseCode = "";
+ }
+ _inboundOrderDetailRepository.UpdateData(detail);
+ }
+ }
+ }
+
+ public override PageGridData<Dt_InboundOrder> GetPageData(PageDataOptions options)
+ {
+ string wheres = ValidatePageOptions(options);
+
+ string pattern = @"inboundOrderNo like '[^']+'\s*and\s*";
+ wheres = Regex.Replace(wheres, pattern, "", RegexOptions.IgnoreCase);
+
+ //鑾峰彇鎺掑簭瀛楁
+ Dictionary<string, SqlSugar.OrderByType> orderbyDic = GetPageDataSort(options, TProperties);
+ List<OrderByModel> orderByModels = new List<OrderByModel>();
+ foreach (var item in orderbyDic)
+ {
+ OrderByModel orderByModel = new()
+ {
+ FieldName = item.Key,
+ OrderByType = item.Value
+ };
+ orderByModels.Add(orderByModel);
+ }
+ ISugarQueryable<Dt_InboundOrder> sugarQueryable1 = BaseDal.Db.Queryable<Dt_InboundOrder>();
+
+ int totalCount = 0;
+ List<SearchParameters> searchParametersList = new List<SearchParameters>();
+ if (!string.IsNullOrEmpty(options.Wheres))
+ {
+ try
+ {
+ searchParametersList = options.Wheres.DeserializeObject<List<SearchParameters>>();
+ if (searchParametersList.Count > 0)
+ {
+
+ SearchParameters? searchParameters = searchParametersList.FirstOrDefault(x => x.Name == nameof(Dt_InboundOrder.InboundOrderNo).FirstLetterToLower());
+ if (searchParameters != null)
+ {
+ sugarQueryable1 = sugarQueryable1.Where(x => x.InboundOrderNo.Contains(searchParameters.Value.ToString())
+ || x.UpperOrderNo.Contains(searchParameters.Value.ToString()) ||
+ x.Details.Any(d => d.Barcode == searchParameters.Value.ToString()) ||
+ x.Details.Any(d => d.OutBoxbarcodes == searchParameters.Value.ToString()));
+ }
+ searchParameters = searchParametersList.FirstOrDefault(x => x.Name == nameof(Dt_InboundOrder.OrderType).FirstLetterToLower());
+ if (searchParameters != null)
+ {
+ sugarQueryable1 = sugarQueryable1.Where(x => x.OrderType.Equals(searchParameters.Value.ToString()));
+ }
+
+ var detailMaterielCode = searchParametersList.FirstOrDefault(x => x.Name == "materielCode");
+ if(detailMaterielCode!=null && !string.IsNullOrEmpty(detailMaterielCode.Value?.ToString()))
+ {
+ string materielCode = detailMaterielCode.Value.ToString().Trim();
+ sugarQueryable1 = sugarQueryable1.Where(x => x.Details.Any(d => d.MaterielCode.Contains(materielCode)));
+
+ }
+
+ //var dataList = sugarQueryable1.ToPageList(options.Page, options.Rows, ref totalCount);
+ //return new PageGridData<Dt_InboundOrder>(totalCount, dataList);
+ }
+ options.Filter = searchParametersList;
+ }
+ catch { }
+ }
+ var data = sugarQueryable1
+ .WhereIF(!wheres.IsNullOrEmpty(), wheres)
+ .Where(x => x.OrderType == 0)
+ .OrderBy(orderByModels).Includes(x => x.Details)
+ .ToPageList(options.Page, options.Rows, ref totalCount);
+
+ return new PageGridData<Dt_InboundOrder>(totalCount, data);
+ }
+
+ //public override PageGridData<Dt_InboundOrder> GetPageData(PageDataOptions options)
+ //{
+ // //var pageGridData = base.GetPageData(options);
+
+ // ISugarQueryable<Dt_InboundOrder> sugarQueryable1 = BaseDal.Db.Queryable<Dt_InboundOrder>();
+ // if (!string.IsNullOrEmpty(options.Wheres))
+ // {
+
+ // List<SearchParameters> searchParametersList = options.Wheres.DeserializeObject<List<SearchParameters>>();
+ // int totalCount = 0;
+ // if (searchParametersList.Count > 0)
+ // {
+
+ // SearchParameters? searchParameters = searchParametersList.FirstOrDefault(x => x.Name == nameof(Dt_InboundOrder.InboundOrderNo).FirstLetterToLower());
+ // if (searchParameters != null)
+ // {
+ // sugarQueryable1 = sugarQueryable1.Where(x => x.InboundOrderNo.Contains(searchParameters.Value.ToString())
+ // || x.UpperOrderNo.Contains(searchParameters.Value.ToString()) ||
+ // x.Details.Any(d => d.Barcode == searchParameters.Value.ToString()));
+ // }
+ // searchParameters = searchParametersList.FirstOrDefault(x => x.Name == nameof(Dt_InboundOrder.OrderType).FirstLetterToLower());
+ // if (searchParameters != null)
+ // {
+ // sugarQueryable1 = sugarQueryable1.Where(x => x.OrderType.Equals(searchParameters.Value.ToString()));
+ // }
+ // var dataList = sugarQueryable1.ToPageList(options.Page, options.Rows, ref totalCount);
+ // return new PageGridData<Dt_InboundOrder>(totalCount, dataList);
+ // }
+ // }
+ // return new PageGridData<Dt_InboundOrder>();
+ //}
+
+ public WebResponseContent UnPalletGroupBarcode(string orderNo)
+ {
+ WebResponseContent content = new WebResponseContent();
+ var inbound = _inboundOrderRepository.Db.Queryable<Dt_InboundOrder>().Where(x => x.InboundOrderNo == orderNo).First();
+ if (inbound == null)
+ {
+ return content.Error();
+ }
+
+ var details = _inboundOrderDetailRepository.Db.Queryable<Dt_InboundOrderDetail>().Where(x => x.OrderId == inbound.Id && x.ReceiptQuantity == 0).ToList();
+
+ return content.OK(data: details);
+ }
+
+ public WebResponseContent GetLocationType(string code)
+ {
+ var warehouseAreaName = _warehouseAreaRepository.QueryFirst(x => x.Code == code);
+ if(string.IsNullOrWhiteSpace(warehouseAreaName.ToString()))
+ {
+ return WebResponseContent.Instance.Error("鏈壘鍒颁粨搴撳悕绉�");
+ }
+ var locationTypeDesc = _locationTypeRepository.Db.Queryable<Dt_LocationType>().Where(x => string.Equals(x.LocationTypeDesc, warehouseAreaName.Name, StringComparison.OrdinalIgnoreCase)).First();
+
+ return WebResponseContent.Instance.OK(data:locationTypeDesc.LocationType);
+ }
+
+ public WebResponseContent HandCloseOrder(List<string> orderNos)
+ {
+ try
+ {
+ foreach (var orderNo in orderNos)
+ {
+ var inbound = _inboundOrderRepository.QueryFirst(x => x.InboundOrderNo == orderNo);
+ var outbound = _outboundOrderRepository.QueryFirst(x=>x.OrderNo == orderNo);
+
+ if (inbound != null)
+ {
+ if (inbound.OrderStatus != (int)InOrderStatusEnum.鏈紑濮� && inbound.OrderStatus != (int)InOrderStatusEnum.鍏ュ簱涓�)
+ {
+ return WebResponseContent.Instance.Error($"璇ュ崟鎹姸鎬佷笉鍙互鍏抽棴");
+ }
+ inbound.OrderStatus = (int)InOrderStatusEnum.鎵嬪姩鍏抽棴;
+ inbound.Operator = App.User.UserName;
+ _inboundOrderRepository.UpdateData(inbound);
+
+ var inboundItems = _inboundOrderDetailRepository.QueryData(x => x.OrderId == inbound.Id);
+ if(inboundItems.FirstOrDefault().OrderDetailStatus == (int)OrderDetailStatusEnum.New)
+ {
+ foreach (var item in inboundItems)
+ {
+ item.OrderDetailStatus = (int)InOrderStatusEnum.鎵嬪姩鍏抽棴;
+ item.Modifier = App.User.UserName;
+ BaseDal.Db.Updateable<Dt_InboundOrderDetail>(item).ExecuteCommand();
+ }
+ }
+ }
+ else if (outbound != null)
+ {
+ if(outbound.OrderStatus ==(int)OutOrderStatusEnum.鍑哄簱瀹屾垚)
+ {
+ return WebResponseContent.Instance.Error($"璇ュ崟鎹姸鎬佷笉鍙互鍏抽棴");
+ }
+ if(outbound.OrderStatus == (int)OutOrderStatusEnum.鍑哄簱涓�)
+ {
+ var outboundDetails = _outboundOrderDetailRepository.QueryData(x => x.OrderId == outbound.Id);
+ if (outboundDetails == null)
+ {
+ return WebResponseContent.Instance.Error("璇ュ崟鎹姸鎬佷笉鑳藉叧闂�");
+ }
+ var detailStatus = outboundDetails.All(x => x.LockQuantity == x.OverOutQuantity);
+ if (!detailStatus)
+ {
+ return WebResponseContent.Instance.Error("璇ュ崟鎹湁姝e湪鍑哄簱鐨勭墿鏂欙紝涓嶈兘鍏抽棴");
+ }
+ }
+ outbound.OrderStatus = (int)OutOrderStatusEnum.鍏抽棴;
+ outbound.Operator = App.User.UserName;
+ _outboundOrderRepository.UpdateData(outbound);
+
+ var outboundItems = BaseDal.Db.Queryable<Dt_OutboundOrderDetail>().Where(x => x.OrderId == outbound.Id).ToList();
+ if(outboundItems.FirstOrDefault().OrderDetailStatus == (int)OrderDetailStatusEnum.New)
+ foreach(var item in outboundItems)
+ {
+ item.OrderDetailStatus = (int)OutOrderStatusEnum.鍏抽棴;
+ item.Modifier = App.User.UserName;
+ BaseDal.Db.Updateable<Dt_OutboundOrderDetail>(item).ExecuteCommand();
+ }
+ }
+
+ }
+ return WebResponseContent.Instance.OK($"鍗曟嵁鍏抽棴鎴愬姛");
+ }
+ catch (Exception e)
+ {
+ return WebResponseContent.Instance.Error(e.Message);
+ }
}
}
}
--
Gitblit v1.9.3