From 7688834261de1dd9711a4a175989b75dd00906cc Mon Sep 17 00:00:00 2001
From: heshaofeng <heshaofeng@hnkhzn.com>
Date: 星期二, 02 十二月 2025 19:42:22 +0800
Subject: [PATCH] 提交
---
项目代码/WMS无仓储版/WIDESEA_WMSServer/WIDESEA_OutboundService/OutStockLockInfoService.cs | 234 ++++++++++++++++++++++++++++++++++++++++++++++++++++++----
1 files changed, 217 insertions(+), 17 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_OutboundService/OutStockLockInfoService.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_OutboundService/OutStockLockInfoService.cs"
index a48a488..e583f96 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_OutboundService/OutStockLockInfoService.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_OutboundService/OutStockLockInfoService.cs"
@@ -1,4 +1,5 @@
-锘縰sing System;
+锘縰sing Microsoft.AspNetCore.Http;
+using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
@@ -10,6 +11,7 @@
using WIDESEA_Core.BaseServices;
using WIDESEA_Core.Enums;
using WIDESEA_Core.Helper;
+using WIDESEA_DTO.Outbound;
using WIDESEA_IRecordService;
using WIDESEA_IStockService;
using WIDESEA_Model.Models;
@@ -32,31 +34,229 @@
_recordService = recordService;
}
- public Dt_OutStockLockInfo GetOutStockLockInfo(Dt_OutboundOrder outboundOrder, Dt_OutboundOrderDetail outboundOrderDetail, Dt_StockInfo outStock, decimal assignQuantity, int? taskNum = null)
- {
- Dt_OutStockLockInfo outStockLockInfo = new Dt_OutStockLockInfo()
+ /// <summary>
+ /// 鍒涘缓鍑哄簱閿佸畾
+ /// </summary>
+ public Dt_OutStockLockInfo GetOutStockLockInfo(
+ Dt_OutboundOrder outboundOrder,
+ Dt_OutboundOrderDetail outboundOrderDetail,
+ Dt_StockInfo outStock,
+ decimal assignQuantity,
+ string barcode = null,string outboundBatchNo = "")
+ {
+ // 鑾峰彇搴撳瓨鏄庣粏淇℃伅
+ var stockDetails = outStock.Details
+ .Where(x => x.MaterielCode == outboundOrderDetail.MaterielCode)
+ .ToList();
+
+ if (!stockDetails.Any())
{
+ throw new Exception($"鏈壘鍒扮墿鏂橻{outboundOrderDetail.MaterielCode}]鐨勫簱瀛樻槑缁�");
+ }
+
+ // 纭畾鏉$爜
+ string targetBarcode;
+ var firstAvailableDetail=new Dt_StockInfoDetail();
+ if (!string.IsNullOrEmpty(barcode))
+ {
+ // 楠岃瘉鎸囧畾鐨勬潯鐮佹槸鍚﹀瓨鍦�
+ firstAvailableDetail = stockDetails.FirstOrDefault(x => x.Barcode == barcode);
+ if (firstAvailableDetail == null)
+ {
+ throw new Exception($"鎸囧畾鐨勬潯鐮乕{barcode}]鍦ㄥ簱瀛樹腑涓嶅瓨鍦�");
+ }
+
+ targetBarcode = barcode;
+ }
+ else
+ {
+ // 浣跨敤绗竴涓彲鐢ㄦ潯鐮�
+ firstAvailableDetail = stockDetails
+ .Where(x => x.StockQuantity > x.OutboundQuantity)
+ .OrderByDescending(x => x.CreateDate)
+ .FirstOrDefault();
+
+ if (firstAvailableDetail == null)
+ {
+ throw new Exception($"鐗╂枡[{outboundOrderDetail.MaterielCode}]娌℃湁鍙敤搴撳瓨");
+ }
+ targetBarcode = firstAvailableDetail.Barcode;
+ }
+
+ return new Dt_OutStockLockInfo()
+ {
PalletCode = outStock.PalletCode,
- AssignQuantity = assignQuantity,
- MaterielCode = outboundOrderDetail.MaterielCode,
- BatchNo = outboundOrderDetail.BatchNo ?? outStock.Details.FirstOrDefault()?.BatchNo,
+ AssignQuantity = assignQuantity,
LocationCode = outStock.LocationCode,
MaterielName = outboundOrderDetail.MaterielName,
OrderDetailId = outboundOrderDetail.Id,
OrderNo = outboundOrder.OrderNo,
- OrderType = outboundOrder.OrderType,
- OriginalQuantity = outStock.Details.Where(x => x.MaterielCode == outboundOrderDetail.MaterielCode).Sum(x => x.StockQuantity),
- Status = taskNum == null ? OutLockStockStatusEnum.宸插垎閰�.ObjToInt() : OutLockStockStatusEnum.鍑哄簱涓�.ObjToInt(),
- StockId = outStock.Id,
- TaskNum = taskNum,
OrderQuantity = outboundOrderDetail.OrderQuantity,
- Unit = outboundOrderDetail.Unit,
- //ProductionDate = outStock.Details.Where(x => x.MaterielCode == outboundOrderDetail.MaterielCode).FirstOrDefault()?.ProductionDate,
- //EffectiveDate = outStock.Details.Where(x => x.MaterielCode == outboundOrderDetail.MaterielCode).FirstOrDefault()?.EffectiveDate
+ OriginalQuantity = outStock.Details
+ .Where(x => x.MaterielCode == outboundOrderDetail.MaterielCode)
+ .Sum(x => x.StockQuantity),
+ Status = (int)OutLockStockStatusEnum.宸插垎閰�,
+ StockId = outStock.Id,
+ OrderType=outboundOrder.OrderType,
+ SupplyCode = firstAvailableDetail.SupplyCode,
+ WarehouseCode = firstAvailableDetail.WarehouseCode,
+ // 鏂板瀛楁
+ CurrentBarcode = targetBarcode,
+ OriginalLockQuantity = assignQuantity,
+ IsSplitted = 0,
+ MaterielCode = outboundOrderDetail.MaterielCode,
+ BatchNo = firstAvailableDetail.BatchNo,
+ Unit = firstAvailableDetail.Unit,
+ BarcodeQty = firstAvailableDetail.BarcodeQty,
+ BarcodeUnit = firstAvailableDetail.BarcodeUnit,
+ FactoryArea = firstAvailableDetail.FactoryArea,
+ lineNo = outboundOrderDetail.lineNo,
+ OutboundBatchNo= outboundBatchNo
};
-
- return outStockLockInfo;
}
+
+
+ public List<Dt_OutStockLockInfo> GetOutStockLockInfos(Dt_OutboundOrder outboundOrder, Dt_OutboundOrderDetail outboundOrderDetail, List<Dt_StockInfo> outStocks, int? taskNum = null)
+ {
+ List<Dt_OutStockLockInfo> outStockLockInfos = new List<Dt_OutStockLockInfo>();
+
+ foreach (var item in outStocks)
+ {
+ Dt_OutStockLockInfo outStockLockInfo = new Dt_OutStockLockInfo()
+ {
+ PalletCode = item.PalletCode,
+ AssignQuantity = item.Details.Where(x => x.MaterielCode == outboundOrderDetail.MaterielCode).Sum(x => x.OutboundQuantity),
+ MaterielCode = outboundOrderDetail.MaterielCode,
+ BatchNo = outboundOrderDetail.BatchNo,
+ LocationCode = item.LocationCode,
+ MaterielName = outboundOrderDetail.MaterielName,
+ OrderDetailId = outboundOrderDetail.Id,
+ OrderNo = outboundOrder.OrderNo,
+ OrderType = outboundOrder.OrderType,
+ OriginalQuantity = item.Details.Where(x => x.MaterielCode == outboundOrderDetail.MaterielCode).Sum(x => x.StockQuantity),
+ Status = taskNum == null ? OutLockStockStatusEnum.宸插垎閰�.ObjToInt() : OutLockStockStatusEnum.鍑哄簱涓�.ObjToInt(),
+ StockId = item.Id,
+ TaskNum = taskNum,
+
+
+ };
+ outStockLockInfos.Add(outStockLockInfo);
+ }
+
+ return outStockLockInfos;
+ }
+
+ /// <summary>
+ /// 鏍规嵁璁㈠崟鏄庣粏ID鑾峰彇鍑哄簱閿佸畾淇℃伅
+ /// </summary>
+ public async Task<List<Dt_OutStockLockInfo>> GetByOrderDetailId(int orderDetailId)
+ {
+ return await Db.Queryable<Dt_OutStockLockInfo>()
+ .Where(x => x.OrderDetailId == orderDetailId)
+ .OrderBy(x => x.Id)
+ .ToListAsync();
+ }
+
+ public async Task<LockInfoDetailDto> GetLockInfoDetail(int lockInfoId)
+ {
+ var lockInfo = await Db.Queryable<Dt_OutStockLockInfo>()
+ .LeftJoin<Dt_OutboundOrderDetail>((lockInfo, detail) => lockInfo.OrderDetailId == detail.Id)
+ .Where((lockInfo, detail) => lockInfo.Id == lockInfoId)
+ .Select((lockInfo, detail) => new LockInfoDetailDto
+ {
+ Id = lockInfo.Id,
+ OrderNo = lockInfo.OrderNo,
+ OrderDetailId = lockInfo.OrderDetailId,
+ BatchNo = lockInfo.BatchNo,
+ MaterielCode = lockInfo.MaterielCode,
+ StockId = lockInfo.StockId,
+ OrderQuantity = lockInfo.OrderQuantity,
+ OriginalQuantity = lockInfo.OriginalQuantity,
+ AssignQuantity = lockInfo.AssignQuantity,
+ PickedQty = lockInfo.PickedQty,
+ LocationCode = lockInfo.LocationCode,
+ PalletCode = lockInfo.PalletCode,
+ Status = lockInfo.Status,
+ IsSplitted = lockInfo.IsSplitted,
+ ParentLockId = lockInfo.ParentLockId,
+
+ MaterielName = detail.MaterielName,
+ Unit = detail.Unit
+ })
+ .FirstAsync();
+
+ return lockInfo;
+ }
+
+ /// <summary>
+ /// 鏍规嵁鎵樼洏缂栧彿鑾峰彇鍑哄簱閿佸畾淇℃伅
+ /// </summary>
+ public async Task<List<Dt_OutStockLockInfo>> GetByPalletCode(string palletCode, int? status = null)
+ {
+ var query = Db.Queryable<Dt_OutStockLockInfo>()
+ .Where(x => x.PalletCode == palletCode);
+
+ if (status.HasValue)
+ {
+ query = query.Where(x => x.Status == status.Value);
+ }
+
+ return await query.OrderBy(x => x.Id).ToListAsync();
+ }
+
+ /// <summary>
+ /// 鑾峰彇鎵樼洏鐨勯攣瀹氫俊鎭�
+ /// </summary>
+ public async Task<List<Dt_OutStockLockInfo>> GetPalletLockInfos(string palletCode)
+ {
+ return await Db.Queryable<Dt_OutStockLockInfo>()
+ .Where(x => x.PalletCode == palletCode && x.Status == (int)OutLockStockStatusEnum.鍑哄簱涓�)
+ .ToListAsync();
+ }
+
+ /// <summary>
+ /// 鏇存柊鍑哄簱閿佸畾淇℃伅鐨勬潯鐮侊紙鐢ㄤ簬鎷嗗寘鎿嶄綔锛�
+ /// </summary>
+ public async Task<WebResponseContent> UpdateLockInfoBarcode(int lockInfoId, string newBarcode)
+ {
+ try
+ {
+ var lockInfo = await Db.Queryable<Dt_OutStockLockInfo>()
+ .Where(x => x.Id == lockInfoId)
+ .FirstAsync();
+
+ if (lockInfo == null)
+ return WebResponseContent.Instance.Error("鏈壘鍒板嚭搴撻攣瀹氫俊鎭�");
+
+ // 楠岃瘉鏂版潯鐮佹槸鍚﹀瓨鍦�
+ var stockDetail = await Db.Queryable<Dt_StockInfoDetail>()
+ .Where(x => x.Barcode == newBarcode &&
+ x.StockId == lockInfo.StockId &&
+ x.MaterielCode == lockInfo.MaterielCode)
+ .FirstAsync();
+
+ if (stockDetail == null)
+ return WebResponseContent.Instance.Error("鏂版潯鐮佸湪搴撳瓨涓笉瀛樺湪");
+
+ // 鏇存柊鏉$爜鍜屾媶鍖呯姸鎬�
+ lockInfo.CurrentBarcode = newBarcode;
+ lockInfo.IsSplitted = 1;
+
+ await Db.Updateable(lockInfo).ExecuteCommandAsync();
+
+ return WebResponseContent.Instance.OK("鏇存柊鏉$爜鎴愬姛");
+ }
+ catch (Exception ex)
+ {
+ return WebResponseContent.Instance.Error($"鏇存柊鏉$爜澶辫触: {ex.Message}");
+ }
+ }
+
+ public List<Dt_OutStockLockInfo> GetByOrderDetailId(int orderDetailId, OutLockStockStatusEnum? outStockStatus)
+ {
+ return BaseDal.QueryData(x => x.OrderDetailId == orderDetailId );
+ }
+
}
}
--
Gitblit v1.9.3