From b0ed419ede8bd1829e670891ffe878630ba517e2 Mon Sep 17 00:00:00 2001
From: yanjinhui <3306209981@qq.com>
Date: 星期一, 03 十一月 2025 17:57:32 +0800
Subject: [PATCH] 优化
---
新建文件夹/WIDESEA_WMSServer/ClassLibrary2/Inventory_BatchServices.cs.cs | 136 ++++++++++++++++++++++++++++++++++++++++++++-
1 files changed, 133 insertions(+), 3 deletions(-)
diff --git "a/\346\226\260\345\273\272\346\226\207\344\273\266\345\244\271/WIDESEA_WMSServer/ClassLibrary2/Inventory_BatchServices.cs.cs" "b/\346\226\260\345\273\272\346\226\207\344\273\266\345\244\271/WIDESEA_WMSServer/ClassLibrary2/Inventory_BatchServices.cs.cs"
index 5a10030..c7757c3 100644
--- "a/\346\226\260\345\273\272\346\226\207\344\273\266\345\244\271/WIDESEA_WMSServer/ClassLibrary2/Inventory_BatchServices.cs.cs"
+++ "b/\346\226\260\345\273\272\346\226\207\344\273\266\345\244\271/WIDESEA_WMSServer/ClassLibrary2/Inventory_BatchServices.cs.cs"
@@ -1,9 +1,15 @@
-锘縰sing System;
+锘縰sing SqlSugar.Extensions;
+using System;
using System.Collections.Generic;
+using System.Drawing.Drawing2D;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WIDESEA_Common;
+using WIDESEA_Common.OrderEnum;
+using WIDESEA_Common.StockEnum;
+using WIDESEA_Common.TaskEnum;
+using WIDESEA_Common.WareHouseEnum;
using WIDESEA_Core;
using WIDESEA_Core.BaseRepository;
using WIDESEA_Core.BaseServices;
@@ -16,13 +22,137 @@
public class Inventory_BatchServices : ServiceBase<Dt_Inventory_Batch, IRepository<Dt_Inventory_Batch>>, IInventory_BatchServices
{
private IMessageInfoService _messageInfoService;
- public Inventory_BatchServices(IRepository<Dt_Inventory_Batch> BaseDal, IMessageInfoService messageInfoService) : base(BaseDal)
+ private IMaterielInfoService _materielInfoService;
+ private IInventoryInfoService _inventoryInfoService;
+ private ISupplyTaskService _supplyTaskService;
+ public Inventory_BatchServices(IRepository<Dt_Inventory_Batch> BaseDal, IMessageInfoService messageInfoService, IMaterielInfoService materielInfoService, IInventoryInfoService inventoryInfoService, ISupplyTaskService supplyTaskService) : base(BaseDal)
{
_messageInfoService = messageInfoService;
+ _materielInfoService = materielInfoService;
+ _inventoryInfoService = inventoryInfoService;
+ _supplyTaskService = supplyTaskService;
}
public IRepository<Dt_Inventory_Batch> Repository => BaseDal;
-
+ public override WebResponseContent UpdateData(SaveModel saveModel)
+ {
+ try
+ {
+ string WareCode = WarehouseEnum.澶т欢搴�.ObjToInt().ToString("000");
+ var qty = saveModel.MainData["availableQuantity"].ObjToInt();
+ var id = saveModel.MainData["id"].ObjToInt();
+ var materielCode = saveModel.MainData["materielCode"].ToString();
+ var batchNo = saveModel.MainData["batchNo"].ToString();
+ //var Inventory_Batch = BaseDal.QueryFirst(x => x.Id == id);
+ //if (qty > Inventory_Batch.AvailableQuantity) throw new Exception("璋冩嫧鏁伴噺涓嶅彲澶т簬鍙敤鏁伴噺");
+ var materielInfo = _materielInfoService.Repository.QueryFirst(x => x.MaterielCode == materielCode);
+ if (materielInfo == null) return WebResponseContent.Instance.Error($"璇风淮鎶よ嵂鍝佺紪鍙枫�恵materielCode}銆戠殑淇℃伅");
+ if (!Enum.IsDefined(typeof(MaterielSourceTypeEnum), materielInfo.MaterielSourceType))
+ return WebResponseContent.Instance.Error($"璇疯缃嵂鍝佺紪鍙枫�恵materielCode}銆戠殑灞炴�у垎绫�");
+ if (materielInfo.MaterielSourceType == MaterielSourceTypeEnum.PurchasePart)
+ return WebResponseContent.Instance.Error($"鑽搧缂栧彿銆恵materielCode}銆戠殑灞炴�у垎绫讳负澶т欢,涓嶅彲璋冩嫧");
+ List<Dt_InventoryInfo> dt_InventoryInfos = _inventoryInfoService.Repository.QueryData(x => x.MaterielCode == materielInfo.MaterielCode && x.BatchNo == batchNo && x.StockStatus == StockStatusEmun.鍏ュ簱瀹屾垚.ObjToInt() && x.AvailableQuantity > 0 && x.WarehouseCode == WareCode).OrderBy(x => x.InDate).ToList();
+ if (dt_InventoryInfos.Count < 1) return WebResponseContent.Instance.Error($"鐗╂枡缂栧彿銆恵materielInfo.MaterielCode}銆戝ぇ浠跺簱鏃犲簱瀛橈紒璇峰強鏃惰ˉ鍏呭簱瀛橈紒");
+ var StockQty = dt_InventoryInfos.Sum(x => x.AvailableQuantity);
+ if (StockQty < qty) return WebResponseContent.Instance.Error($"璋冩嫧鏁伴噺涓嶅彲澶т簬澶т欢搴撳彲鐢ㄦ暟閲�,澶т欢搴撳彲鐢ㄦ暟閲忎负銆恵StockQty}銆�");
+ var zx = (qty / materielInfo.BoxQty).ObjToInt();
+ var ys = qty % materielInfo.BoxQty;
+ if (ys > 0) zx++;
+ decimal Qty = 0;
+ List<Dt_SupplyTask> supplyTasks = new List<Dt_SupplyTask>();
+ Dt_DeliveryOrder deliveryOrder = new Dt_DeliveryOrder()
+ {
+ Out_no = DateTime.Now.ToString("yyMMddHHmmss"),
+ Warehouse_no = WareCode,
+ Out_type = OutOrderTypeEnum.Allocate.ObjToInt().ToString(),
+ OutStatus = "鏂板缓",
+ Details = new List<Dt_DeliveryOrderDetail>()
+ };
+ foreach (var item in dt_InventoryInfos)
+ {
+ decimal taskQty = 0;
+ if (zx < 1) break;
+ while (item.AvailableQuantity > 0 && zx > 0)
+ {
+ zx--;
+ Qty += materielInfo.BoxQty;
+ taskQty += materielInfo.BoxQty;
+ materielInfo.Business_qty += materielInfo.BoxQty;
+ item.OutboundQuantity += materielInfo.BoxQty;
+ item.AvailableQuantity -= materielInfo.BoxQty;
+ }
+ #region 娣诲姞璋冩嫧鍑哄簱浠诲姟
+ Dt_SupplyTask supplyTask = new Dt_SupplyTask()
+ {
+ WarehouseCode = item.WarehouseCode,
+ BatchNo = item.BatchNo,
+ MaterielName = item.MaterielName,
+ MaterielCode = item.MaterielCode,
+ MaterielSpec = item.MaterielSpec,
+ TaskStatus = SupplyStatusEnum.NewOut.ObjToInt(),
+ TaskType = TaskTypeEnum.AllocatOut.ObjToInt(),
+ CreateDate = DateTime.Now,
+ Creater = App.User.UserName ?? "System",
+ LocationCode = item.LocationCode,
+ OrderNo = deliveryOrder.Out_no,
+ StockQuantity = taskQty,
+ SupplyQuantity = 0,
+ Remark = "璋冩嫧鍑哄簱"
+ };
+ supplyTasks.Add(supplyTask);
+ #endregion
+ }
+ Dt_DeliveryOrderDetail deliveryOrderDetail = new Dt_DeliveryOrderDetail()
+ {
+ Batch_num = batchNo,
+ Order_Outqty = 0,
+ Order_qty = Qty,
+ CreateDate = DateTime.Now,
+ Creater = App.User.UserName ?? "System",
+ Goods_no = materielCode,
+ OotDetailStatus = "鏂板缓",
+ Status = 2,
+ Reservoirarea = WareCode
+ };
+ deliveryOrder.Details.Add(deliveryOrderDetail);
+ #region 娣诲姞璋冩嫧鍏ュ簱鍗�
+ Dt_CabinOrder cabinOrder = new Dt_CabinOrder()
+ {
+ Order_no = deliveryOrder.Out_no,
+ Order_type = InOrderTypeEnum.Allocat.ObjToInt().ToString(),
+ Warehouse_no = "001",
+ OdrderStatus = "鏂板缓",
+ Details = new List<Dt_CabinOrderDetail>()
+ };
+ foreach (var item in deliveryOrder.Details)
+ {
+ Dt_CabinOrderDetail orderDetail = new Dt_CabinOrderDetail()
+ {
+ Reservoirarea = cabinOrder.Warehouse_no,
+ Goods_no = item.Goods_no,
+ Order_qty = item.Order_qty,
+ Batch_num = item.Batch_num,
+ OrderDetailStatus = "鏂板缓",
+ Status = 0
+ };
+ cabinOrder.Details.Add(orderDetail);
+ }
+ #endregion
+ Db.Ado.BeginTran();
+ _materielInfoService.UpdateData(materielInfo);
+ _inventoryInfoService.Repository.UpdateData(dt_InventoryInfos);
+ _supplyTaskService.AddData(supplyTasks);
+ if (deliveryOrder.Details.Count > 0) Db.InsertNav(deliveryOrder).Include(x => x.Details).ExecuteCommand();
+ if (cabinOrder.Details.Count > 0) Db.InsertNav(cabinOrder).Include(x => x.Details).ExecuteCommand();
+ Db.Ado.CommitTran();
+ return WebResponseContent.Instance.OK("璋冩嫧鍑哄叆搴撳崟鐢熸垚鎴愬姛,璇锋搷浣滆皟鎷ㄥ崟");
+ }
+ catch (Exception ex)
+ {
+ Db.Ado.RollbackTran();
+ return WebResponseContent.Instance.Error(ex.Message);
+ }
+ }
public WebResponseContent GetExpiredAndlow()
{
WebResponseContent content = new WebResponseContent();
--
Gitblit v1.9.3