From a9a3f943efb083de8ed88b293897886b3ef612a2 Mon Sep 17 00:00:00 2001
From: helongyang <647556386@qq.com>
Date: 星期一, 11 八月 2025 17:37:09 +0800
Subject: [PATCH] 功能增添优化
---
代码管理/WMS/WIDESEA_WMSServer/WIDESEA_InboundService/TakeStockOrderService.cs | 256 ++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 254 insertions(+), 2 deletions(-)
diff --git "a/\344\273\243\347\240\201\347\256\241\347\220\206/WMS/WIDESEA_WMSServer/WIDESEA_InboundService/TakeStockOrderService.cs" "b/\344\273\243\347\240\201\347\256\241\347\220\206/WMS/WIDESEA_WMSServer/WIDESEA_InboundService/TakeStockOrderService.cs"
index a34d6f6..6c21a1a 100644
--- "a/\344\273\243\347\240\201\347\256\241\347\220\206/WMS/WIDESEA_WMSServer/WIDESEA_InboundService/TakeStockOrderService.cs"
+++ "b/\344\273\243\347\240\201\347\256\241\347\220\206/WMS/WIDESEA_WMSServer/WIDESEA_InboundService/TakeStockOrderService.cs"
@@ -16,6 +16,13 @@
using WIDESEA_Common.CommonEnum;
using WIDESEA_Core.Helper;
using Microsoft.AspNetCore.Mvc.RazorPages;
+using WIDESEA_External.ERPService;
+using WIDESEA_InboundRepository;
+using WIDESEA_IStockRepository;
+using WIDESEA_Common.StockEnum;
+using WIDESEA_Core.Enums;
+using WIDESEA_External.Model;
+using SqlSugar;
namespace WIDESEA_InboundService
{
@@ -24,10 +31,18 @@
public ITakeStockOrderRepository Repository => BaseDal;
private readonly IUnitOfWorkManage _unitOfWorkManage;
private readonly IBasicRepository _basicRepository;
- public TakeStockOrderService(ITakeStockOrderRepository BaseDal, IUnitOfWorkManage unitOfWorkManage, IBasicRepository basicRepository) : base(BaseDal)
+ private readonly IInvokeERPService _invokeERPService;
+ private readonly ITakeStockOrderDetailRepository _takeStockOrderDetailRepository;
+ private readonly IStockInfoRepository _stockInfoRepository;
+ private readonly IStockInfoDetailRepository _stockInfoDetailRepository;
+ public TakeStockOrderService(ITakeStockOrderRepository BaseDal, IUnitOfWorkManage unitOfWorkManage, IBasicRepository basicRepository,IInvokeERPService invokeERPService,ITakeStockOrderDetailRepository takeStockOrderDetailRepository,IStockInfoRepository stockInfoRepository,IStockInfoDetailRepository stockInfoDetailRepository) : base(BaseDal)
{
_unitOfWorkManage = unitOfWorkManage;
_basicRepository = basicRepository;
+ _invokeERPService = invokeERPService;
+ _takeStockOrderDetailRepository= takeStockOrderDetailRepository;
+ _stockInfoRepository= stockInfoRepository;
+ _stockInfoDetailRepository= stockInfoDetailRepository;
}
/// <summary>
/// 鏂板
@@ -88,12 +103,249 @@
}
return content;
}
+ /// <summary>
+ /// 閫氳繃鐩樼偣鍗曞彿+妗嗗彿鑾峰彇鐩樼偣淇℃伅璇︽儏
+ /// </summary>
+ /// <param name="saveModel"></param>
+ /// <returns></returns>
+ public WebResponseContent GetTakeDetailInfo(SaveModel saveModel)
+ {
+ WebResponseContent content = new WebResponseContent();
+ try
+ {
+ string? orderNo = saveModel.MainData["orderNo"].ToString();
+ string? takePalletCode = saveModel.MainData["takePalletCode"].ToString();
+ Dt_TakeStockOrderDetail takeStockOrderDetail=new Dt_TakeStockOrderDetail();
+ if (!string.IsNullOrEmpty(orderNo) && !string.IsNullOrEmpty(takePalletCode))
+ {
+ //鑾峰彇鐩樼偣鏄庣粏
+ takeStockOrderDetail = BaseDal.Db.Queryable<Dt_TakeStockOrder, Dt_TakeStockOrderDetail>((master, detail) => master.Id == detail.TakeStockId)
+ .Where((master, detail) => master.OrderNo == orderNo && detail.TakePalletCode== takePalletCode)
+ .Select((master, detail) => detail).First();
+ if (takeStockOrderDetail==null)
+ {
+ return content.Error($"鐩樼偣鍗晎orderNo}涓湭鎵惧埌{takePalletCode}鐩樼偣鏄庣粏");
+ }
+ if (takeStockOrderDetail.TakeDetalStatus != TakeStockDetailStatusEnum.鐩樼偣鍑哄簱瀹屾垚.ObjToInt())
+ {
+ return content.Error($"鐩樼偣鍗晎orderNo}涓湭鎵惧埌{takePalletCode}鍙洏鐘舵��");
+ }
+ Dt_StockInfo stockInfo = _stockInfoRepository.Db.Queryable<Dt_StockInfo>().Where(x=>x.PalletCode== takePalletCode && x.StockStatus==StockStatusEmun.鐩樼偣鍑哄簱瀹屾垚.ObjToInt()).Includes(x=>x.Details).First();
+ if (stockInfo == null)
+ {
+ return content.Error($"鏈壘鍒皗takePalletCode}鐩樼偣搴撳瓨鐘舵��");
+ }
+ content.OK(data: takeStockOrderDetail);
+ }
+ else
+ {
+ return content.Error("璇锋眰淇℃伅涓虹┖");
+ }
+ }
+ catch (Exception ex)
+ {
+ content.Error(ex.Message);
+ }
+ return content;
+ }
+ /// <summary>
+ /// 鐩樼偣鎿嶄綔
+ /// </summary>
+ /// <param name="saveModel"></param>
+ /// <returns></returns>
public WebResponseContent MatPicking(SaveModel saveModel)
{
WebResponseContent content = new WebResponseContent();
try
{
-
+ int id = saveModel.MainData["id"].ObjToInt();
+ decimal stockNum =saveModel.MainData["num"].ObjToDecimal();
+ if (stockNum<0)
+ {
+ return content.Error("鐩樹簭涓嶈兘涓鸿礋");
+ }
+ if (id>0)
+ {
+ //鑾峰彇鐩樼偣璇︽儏
+ Dt_TakeStockOrderDetail takeStockOrderDetail = _takeStockOrderDetailRepository.QueryFirst(x=>x.Id== id);
+ if (takeStockOrderDetail.TakeDetalStatus != TakeStockDetailStatusEnum.鐩樼偣鍑哄簱瀹屾垚.ObjToInt())
+ {
+ return content.Error("闈炲彲鐩樼偣鐘舵��");
+ }
+ Dt_TakeStockOrder takeStockOrder = BaseDal.Db.Queryable<Dt_TakeStockOrder>().Where(x => x.Id == takeStockOrderDetail.TakeStockId).Includes(x => x.Details).First();
+ if (takeStockOrder.TakeStockStatus != TakeStockStatusEnum.鐩樼偣涓�.ObjToInt())
+ {
+ return content.Error("闈炲彲鐩樼偣鐘舵��");
+ }
+ //鑾峰彇搴撳瓨
+ Dt_StockInfo stockInfo = _stockInfoRepository.Db.Queryable<Dt_StockInfo>().Where(x => x.PalletCode == takeStockOrderDetail.TakePalletCode && x.StockStatus == StockStatusEmun.鐩樼偣鍑哄簱瀹屾垚.ObjToInt()).Includes(x => x.Details).First();
+ List<Dt_StockInfoDetail> addStockDetails = new List<Dt_StockInfoDetail>();
+ List<Dt_StockInfoDetail> delStockDetails = new List<Dt_StockInfoDetail>();
+ List<Dt_StockInfoDetail> updateStockDetails = new List<Dt_StockInfoDetail>();
+ if (stockInfo == null || stockInfo.Details.Count<=0 || stockInfo.Details==null)
+ {
+ return content.Error("鏈壘鍒板簱瀛�");
+ }
+ takeStockOrderDetail.Qty = (float)stockNum;
+ takeStockOrderDetail.TakeDetalStatus = TakeStockDetailStatusEnum.鐩樼偣瀹屾垚.ObjToInt();
+ int stockCount=stockInfo.Details.Count;
+ //鍒ゆ柇鏄惁鐩樿耽杩樻槸鐩樹簭
+ if (takeStockOrderDetail.SysQty< takeStockOrderDetail.Qty) //鐩樿耽
+ {
+ //float stockMaxQty = stockInfo.Details.Max(x => x.StockQuantity);
+ //float stockMinQty = stockInfo.Details.Min(x => x.StockQuantity);
+ Dt_StockInfoDetail? addstockInfoDetail = stockInfo.Details?.FirstOrDefault();
+ addstockInfoDetail.Id = 0;
+ addstockInfoDetail.StockQuantity = (takeStockOrderDetail.Qty - takeStockOrderDetail.SysQty);
+ addStockDetails.Add(addstockInfoDetail);
+ }
+ else if (takeStockOrderDetail.Qty==0) //鐩樹簭
+ {
+ delStockDetails.AddRange(stockInfo.Details);
+ }
+ else if(takeStockOrderDetail.SysQty > takeStockOrderDetail.Qty) //鐩樹簭
+ {
+ decimal totalQty = (takeStockOrderDetail.SysQty - takeStockOrderDetail.Qty).ObjToDecimal();
+ while (totalQty>0)
+ {
+ Dt_StockInfoDetail addstockInfoDetail=stockInfo.Details.OrderByDescending(x => x.Id).FirstOrDefault();
+ decimal stockQty = addstockInfoDetail.StockQuantity.ObjToDecimal();
+ if (stockQty < totalQty)
+ {
+ delStockDetails.Add(addstockInfoDetail);
+ stockInfo.Details.Remove(addstockInfoDetail);
+ totalQty -= stockQty;
+ }
+ else if (stockQty >= totalQty)
+ {
+ stockQty-=totalQty;
+ if (stockQty==0)
+ {
+ delStockDetails.Add(addstockInfoDetail);
+ stockInfo.Details.Remove(addstockInfoDetail);
+ }
+ else
+ {
+ addstockInfoDetail.StockQuantity = (float)stockQty;
+ updateStockDetails.Add(addstockInfoDetail);
+ stockInfo.Details.Remove(addstockInfoDetail);
+ }
+ totalQty = 0;
+ }
+
+ }
+ }
+ List<Dt_TakeStockOrderDetail> takeStockOrderDetails=new List<Dt_TakeStockOrderDetail>();
+ Dt_Warehouse warehouse = _basicRepository.WarehouseRepository.QueryFirst(x=>x.WarehouseId==takeStockOrder.WarehouseId);
+ List<Dt_TakeStockOrderDetail> overTakeStockOrderDetails = takeStockOrder.Details.Where(x => x.TakeDetalStatus == TakeStockDetailStatusEnum.鐩樼偣瀹屾垚.ObjToInt()).ToList();
+ if ((overTakeStockOrderDetails.Count + 1) == takeStockOrder.Details.Count)
+ {
+ takeStockOrder.TakeStockStatus = TakeStockStatusEnum.鐩樼偣瀹屾垚.ObjToInt();
+ takeStockOrderDetails.AddRange(overTakeStockOrderDetails);
+ takeStockOrderDetails.Add(takeStockOrderDetail);
+ }
+ //鏁版嵁鎿嶄綔
+ _unitOfWorkManage.BeginTran();
+ if (stockCount== delStockDetails.Count)
+ {
+ _stockInfoRepository.DeleteAndMoveIntoHty(stockInfo, App.User.UserId == 0 ? OperateTypeEnum.鑷姩瀹屾垚 : OperateTypeEnum.浜哄伐瀹屾垚);
+ }
+ else
+ {
+ stockInfo.StockStatus = StockStatusEmun.鐩樼偣搴撳瓨瀹屾垚.ObjToInt();
+ _stockInfoRepository.UpdateData(stockInfo);
+ if (stockInfo.Details!=null && stockInfo.Details.Count>0)
+ {
+ stockInfo.Details.ForEach(x =>
+ {
+ x.Status = StockStatusEmun.鐩樼偣搴撳瓨瀹屾垚.ObjToInt();
+ });
+ }
+ }
+ if (delStockDetails.Count>0)
+ {
+ _stockInfoDetailRepository.DeleteAndMoveIntoHty(delStockDetails, App.User.UserId == 0 ? OperateTypeEnum.鑷姩瀹屾垚 : OperateTypeEnum.浜哄伐瀹屾垚);
+ }
+ if (addStockDetails.Count>0)
+ {
+ addStockDetails.ForEach(x =>
+ {
+ x.Status = StockStatusEmun.鐩樼偣搴撳瓨瀹屾垚.ObjToInt();
+ });
+ _stockInfoDetailRepository.AddData(addStockDetails);
+ }
+ if (updateStockDetails.Count>0)
+ {
+ updateStockDetails.ForEach(x =>
+ {
+ x.Status = StockStatusEmun.鐩樼偣搴撳瓨瀹屾垚.ObjToInt();
+ });
+ _stockInfoDetailRepository.UpdateData(updateStockDetails);
+ }
+ _takeStockOrderDetailRepository.UpdateData(takeStockOrderDetail);
+ BaseDal.UpdateData(takeStockOrder);
+ //鎻愪氦ERP閫昏緫
+ //if (takeStockOrder.TakeStockStatus== TakeStockStatusEnum.鐩樼偣瀹屾垚.ObjToInt())
+ //{
+ // ERPTakeStockModel eRPTakeStock = new ERPTakeStockModel()
+ // {
+ // Way = 1,
+ // UniqueTag = takeStockOrder.Id.ToString(),
+ // Code = takeStockOrder.OrderNo,
+ // FiscalPeriotime = takeStockOrder.CreateDate.ToString("yyyy-MM-dd"),
+ // Name=takeStockOrder.OrderNo,
+ // WarehouseCode= warehouse.WarehouseCode,
+ // Createuser=takeStockOrder.Creater,
+ // Createtime= takeStockOrder.CreateDate.ToString("yyyy-MM-dd HH:mm:ss"),
+ // Details=new List<TakeDetailsItem>()
+ // };
+ // foreach (var item in takeStockOrderDetails)
+ // {
+ // TakeDetailsItem takeDetailsItem = new TakeDetailsItem()
+ // {
+ // MaterialsCode=item.MaterielCode,
+ // LocationCode=item.LocationCode,
+ // Lotno=item.BatchNo,
+ // Sysqty=item.SysQty.ObjToDecimal(),
+ // Qty=item.Qty.ObjToDecimal()
+ // };
+ // eRPTakeStock.Details.Add(takeDetailsItem);
+ // }
+ // string response = _invokeERPService.InvokeTakeStockApi(eRPTakeStock);
+ // ErpRequestContent erpRequestContent = response.DeserializeObject<ErpRequestContent>();
+ // if (erpRequestContent.res != 1)
+ // {
+ // throw new Exception("鍚屾ERP澶辫触,閿欒淇℃伅:" + erpRequestContent.Data);
+ // }
+ //}
+ _unitOfWorkManage.CommitTran();
+ content.OK("鐩樼偣鎴愬姛");
+ }
+ else
+ {
+ return content.Error("璇锋眰淇℃伅涓虹┖");
+ }
+ }
+ catch (Exception ex)
+ {
+ _unitOfWorkManage.RollbackTran();
+ content.Error(ex.Message);
+ }
+ return content;
+ }
+ public WebResponseContent DisEnableTakeOrder(int id)
+ {
+ WebResponseContent content = new WebResponseContent();
+ try
+ {
+ //鑾峰彇鐩樼偣鍗�
+ Dt_TakeStockOrder takeStockOrder = BaseDal.QueryFirst(x=>x.Id==id);
+ if (takeStockOrder!=null)
+ {
+ takeStockOrder.TakeStockStatus = TakeStockStatusEnum.鐩樼偣鍏抽棴.ObjToInt();
+ BaseDal.UpdateData(takeStockOrder);
+ content.OK("鍏抽棴鐩樼偣鎴愬姛!");
+ }
}
catch (Exception ex)
{
--
Gitblit v1.9.3