From 617ee9f1116ff97c3d17070defd21e6d6dc6bbda Mon Sep 17 00:00:00 2001
From: 南骏 池 <chiffly@163.com>
Date: 星期一, 14 四月 2025 10:08:50 +0800
Subject: [PATCH] 1.期初入库优化 2.产品托码绑定,内箱核对 3.不了优化
---
service/Warehouse/MesInvItemInCDetailsManager.cs | 268 +++++++++++++++++++++++++++++++++--------------------
1 files changed, 166 insertions(+), 102 deletions(-)
diff --git a/service/Warehouse/MesInvItemInCDetailsManager.cs b/service/Warehouse/MesInvItemInCDetailsManager.cs
index fb5e185..78c31d2 100644
--- a/service/Warehouse/MesInvItemInCDetailsManager.cs
+++ b/service/Warehouse/MesInvItemInCDetailsManager.cs
@@ -2,9 +2,12 @@
using NewPdaSqlServer.DB;
using NewPdaSqlServer.Dto.service;
using NewPdaSqlServer.entity;
+using NewPdaSqlServer.entity.Base;
+using NewPdaSqlServer.service.@base;
using NewPdaSqlServer.util;
using Newtonsoft.Json;
using SqlSugar;
+using static Microsoft.EntityFrameworkCore.DbLoggerCategory;
namespace NewPdaSqlServer.service.Warehouse;
@@ -12,7 +15,7 @@
{
//褰撳墠绫诲凡缁忕户鎵夸簡 Repository 澧炪�佸垹銆佹煡銆佹敼鐨勬柟娉�
- public PurchaseInventory SaveBarCodes(WarehouseQuery entity)
+ public ItemInBaseModel SaveBarCodes(WarehouseQuery entity)
{
string functionName = "閲囪喘鍏ュ簱", fieldName = null, inFieldVal = null;
string user = entity.userName,
@@ -23,17 +26,17 @@
var freeze = 0;
decimal cSyQty = 0;
- if (string.IsNullOrEmpty(sectionCode))
- throw new Exception("璇锋壂搴撲綅鏉$爜锛�");
+ //if (string.IsNullOrEmpty(sectionCode))
+ // throw new Exception("璇锋壂搴撲綅鏉$爜锛�");
var itemBarcodeDetails = Db.Queryable<MesInvItemBarcodes>()
.Where(it => it.ItemBarcode == itemBarcode)
.First();
- if (itemBarcodeDetails == null)
- throw new Exception("鏉$爜涓嶅瓨鍦紝璇锋牳瀵癸紒");
+ //if (itemBarcodeDetails == null)
+ // throw new Exception("鏉$爜涓嶅瓨鍦紝璇锋牳瀵癸紒");
- if (itemBarcodeDetails.ComeFlg == 0)
+ if (string.IsNullOrEmpty(itemBarcodeDetails.Memo) || itemBarcodeDetails.Memo != "閲囪喘鍏ュ簱")
throw new Exception("姝ゆ潯鐮佷笉灞炰簬鍒拌揣鏉$爜锛屾棤娉曠敤閲囪喘鍏ュ簱锛�");
var inventory = Db.Queryable<MesInvItemArn>()
@@ -60,6 +63,11 @@
if (inventoryDetails == null)
throw new Exception("姝ゆ潯鐮佹壘涓嶅埌瀵瑰簲鏀惰揣鍗曟槑缁嗭紒");
+
+ if (string.IsNullOrEmpty(inventoryDetails.CheckRes) || inventoryDetails.CheckRes != "鍚堟牸")
+ {
+ throw new Exception("璇ユ潯鐮佸搴旂殑鏀舵枡鍗曟楠屼笉鍚堟牸鎴栨湭妫�楠岋紒");
+ }
var depotCode = Db.Queryable<MesDepotSections>()
.Where(it => it.DepotSectionCode == sectionCode)
@@ -88,90 +96,111 @@
}
- num = Db.Queryable<MesInvItemInCDetails>()
- .Where(it => it.ItemBarcode == itemBarcode)
- .Count();
+ //num = Db.Queryable<MesInvItemInCDetails>()
+ // .Where(it => it.ItemBarcode == itemBarcode)
+ // .Count();
- if (num > 0)
- throw new Exception("姝ゆ潯鐮佸凡鎵爜鍏ュ簱瀹屾垚锛岃鏍稿锛�");
+ //if (num > 0)
+ // throw new Exception("姝ゆ潯鐮佸凡鎵爜鍏ュ簱瀹屾垚锛岃鏍稿锛�");
- num = Db.Queryable<MesInvItemStocks>()
- .Where(it => it.ItemBarcode == itemBarcode)
- .Count();
+ //num = Db.Queryable<MesInvItemStocks>()
+ // .Where(it => it.ItemBarcode == itemBarcode)
+ // .Count();
- if (num > 0)
- throw new Exception("姝ゆ潯鐮佸凡鎵爜鍏ュ簱锛岃鏍稿锛�");
+ //if (num > 0)
+ // throw new Exception("姝ゆ潯鐮佸凡鎵爜鍏ュ簱锛岃鏍稿锛�");
- num = Db.Queryable<MesInvItemArn>()
- .Where(a => a.BillNo == itemBarcodeDetails.BillNo)
- .InnerJoin<MesInvItemArnDetail>((a, b) =>
- b.ParentGuid == a.Guid &&
- b.ItemId == itemBarcodeDetails.ItemId && b.Ischeck == 1)
- .Count();
+ var wmsManager = new WmsBaseMangeer();
+ // 鏂板鍏ュ簱鏍¢獙锛堣皟鐢ㄥ瓨鍌ㄨ繃绋嬶級
+ var checkResult = wmsManager.pdaInvJY(
+ db: Db,
+ edtUserNo: entity.userName,
+ barcode: entity.barcode,
+ sectionCode: sectionCode,
+ stockId: mesDepost.DepotId.ToString(),
+ stockOrgId: mesDepost.FSubsidiary,
+ billNo: "", // 鏍规嵁瀹為檯鍗曟嵁鍙蜂紶鍊�
+ transactionNo: "101" // 浜嬪姟绫诲瀷涓庡瓨鍌ㄨ繃绋嬪尮閰�
+ );
- num2 = Db.Queryable<MesInvItemArn>()
- .Where(a => a.BillNo == itemBarcodeDetails.BillNo)
- .InnerJoin<MesInvItemArnDetail>((a, b) => b.ParentGuid == a.Guid
- && b.ItemId == itemBarcodeDetails.ItemId
- && (b.CheckRes == "鍚堟牸" || b.CheckStates == "鐗归噰鐩存帴浣跨敤"))
- .Count();
+ if (Convert.ToInt32(checkResult.result) < 1)
+ throw new Exception($"鍏ュ簱鏍¢獙澶辫触锛歿checkResult.strMsg}");
- switch (num)
- {
- case 0 when num2 == 0:
- case > 0 when num2 == 0:
- freeze = 1;
- break;
- case 0 when num2 > 0:
- throw new Exception("鍏ュ簱澶辫触,鍒拌揣鍗曟嵁鏈夐棶棰橈紒");
- }
- var owner_type = "";
- if (Db.Queryable<SysOrganization>().Any(x => x.Fid == cgddDetails.DemandOrg))
- {
- owner_type = "BD_OwnerOrg";
- }
- else
- {
- // 绗簩灞傚垽鏂細妫�鏌� MES_CUSTOMER
- if (Db.Queryable<MesCustomer>().Any(x => x.Id == Convert.ToInt32(cgddDetails.DemandOrg)))
- {
- owner_type = "BD_Customer";
- }
- else
- {
- // 绗笁灞傚垽鏂細妫�鏌� MES_SUPPLIER
- if (Db.Queryable<MesSupplier>().Any(x => x.Id == Convert.ToInt32(cgddDetails.DemandOrg)))
- {
- owner_type = "BD_Supplier";
- }
- else
- {
- // 绗洓灞傚垽鏂細鍐嶆妫�鏌� SYS_ORGANIZATION
- if (Db.Queryable<SysOrganization>().Any(x => x.Fid == cgddDetails.ReceivingOrg))
- {
- owner_type = "BD_OwnerOrg";
- }
- else
- {
- throw new Exception("鍏ュ簱澶辫触,鍒拌揣鍗曟嵁瀵瑰簲鐨勯渶姹傜粍缁囨湁闂锛�");
- }
- }
- }
- }
+ //num = Db.Queryable<MesInvItemArn>()
+ // .Where(a => a.BillNo == itemBarcodeDetails.BillNo)
+ // .InnerJoin<MesInvItemArnDetail>((a, b) =>
+ // b.ParentGuid == a.Guid &&
+ // b.ItemId == itemBarcodeDetails.ItemId && b.Ischeck == 1)
+ // .Count();
- var result = new PurchaseInventory();
+ //num2 = Db.Queryable<MesInvItemArn>()
+ // .Where(a => a.BillNo == itemBarcodeDetails.BillNo)
+ // .InnerJoin<MesInvItemArnDetail>((a, b) => b.ParentGuid == a.Guid
+ // && b.ItemId == itemBarcodeDetails.ItemId
+ // && (b.CheckRes == "鍚堟牸" || b.CheckStates == "鐗归噰鐩存帴浣跨敤"))
+ // .Count();
+
+ //switch (num)
+ //{
+ // case 0 when num2 == 0:
+ // case > 0 when num2 == 0:
+ // freeze = 1;
+ // break;
+ // case 0 when num2 > 0:
+ // throw new Exception("鍏ュ簱澶辫触,鍒拌揣鍗曟嵁鏈夐棶棰橈紒");
+ //}
+
+
+ // 鍒ゆ柇璐т富绫诲瀷
+ var owner_type = wmsManager.GetOwnerType(cgddDetails.DemandOrg);
+ // if (Db.Queryable<SysOrganization>().Any(x => x.Fid == cgddDetails.DemandOrg))
+ // {
+ // owner_type = "BD_OwnerOrg";
+ // }
+ // else
+ // {
+ // // 绗簩灞傚垽鏂細妫�鏌� MES_CUSTOMER
+ // if (Db.Queryable<MesCustomer>().Any(x => x.Id == Convert.ToInt32(cgddDetails.DemandOrg)))
+ // {
+ // owner_type = "BD_Customer";
+ // }
+ // else
+ // {
+ // // 绗笁灞傚垽鏂細妫�鏌� MES_SUPPLIER
+ // if (Db.Queryable<MesSupplier>().Any(x => x.Id == Convert.ToInt32(cgddDetails.DemandOrg)))
+ // {
+ // owner_type = "BD_Supplier";
+ // }
+ // else
+ // {
+
+ // // 绗洓灞傚垽鏂細鍐嶆妫�鏌� SYS_ORGANIZATION
+ // if (Db.Queryable<SysOrganization>().Any(x => x.Fid == cgddDetails.ReceivingOrg))
+ // {
+ // owner_type = "BD_OwnerOrg";
+ // }
+ // else
+ // {
+ // throw new Exception("鍏ュ簱澶辫触,鍒拌揣鍗曟嵁瀵瑰簲鐨勯渶姹傜粍缁囨湁闂锛�");
+ // }
+ // }
+ // }
+ //}
+
+ var result = new ItemInBaseModel();
UseTransaction(db =>
{
var existingRecord = db.Queryable<MesInvItemIns>()
.Where(it => it.InsDate.Value.ToString("yyyy-MM-dd") == DateTime.Now.ToString("yyyy-MM-dd")
+ && it.TaskNo == itemBarcodeDetails.BillNo
&& it.Status == 0
&& it.TransctionNo == transactionNo
+ && it.CreateBy == entity.userName
&& it.BillTypeId == billTypeId
- && it.TaskNo == itemBarcodeDetails.BillNo
- && it.DepotsCode == mesDepost.DepotCode)
+ && it.DepotsId == mesDepost.DepotId)
.Select(it => new
{
it.Guid,
@@ -488,8 +517,7 @@
it.ItemInId == cId &&
it.ItemId == detailone.ItemId &&
it.DepotId == depotCode2 &&
- it.EbelnK3id == detailone.EbelnK3id &&
- it.LineK3id == detailone.LineK3id)
+ it.itemDabid == itemBarcodeDetails.AboutGuid.ToString())
.Count();
if (existingCount == 0)
@@ -527,11 +555,10 @@
Quantity = SqlFunc.IsNull(it.Quantity, 0) + itemBarcodeDetails.Quantity // 纭繚 Quantity 涓嶄负 null
})
.Where(it =>
- it.ItemInId == cId &&
- it.ItemId == detailone.ItemId &&
- it.DepotId == depotCode2 &&
- it.EbelnK3id == detailone.EbelnK3id &&
- it.LineK3id == detailone.LineK3id)
+ it.ItemInId == cId &&
+ it.ItemId == detailone.ItemId &&
+ it.DepotId == depotCode2 &&
+ it.itemDabid == itemBarcodeDetails.AboutGuid.ToString())
//.IgnoreColumns(true) // 淇濈暀 IgnoreColumns
.ExecuteCommand();
@@ -646,18 +673,19 @@
if (itemBarcodeDetails.Hbdy != 1)
{
+ //鏇存柊鏀舵枡鍗曟槑缁�
db.Updateable<MesInvItemArnDetail>()
.SetColumns(d => new MesInvItemArnDetail
{
OkRkqty = (int)((d.OkRkqty ?? 0) + cSyQty)
})
- .Where(d => d.Guid == inventoryDetails.Guid)
+ .Where(d => d.Guid == itemBarcodeDetails.AboutGuid)
.ExecuteCommand();
var first = db
.Queryable<MesInvItemArnDetail>()
.Where(b =>
- b.Guid == inventoryDetails.Guid)
+ b.Guid == itemBarcodeDetails.AboutGuid)
.Select(b => new
{
TotalQuantity =
@@ -672,7 +700,7 @@
if (TotalQuantity == TotalOkRkQty)
db.Updateable<MesInvItemArnDetail>()
.SetColumns(s => s.IsdepsIn == true)
- .Where(s => s.Guid == inventoryDetails.Guid)
+ .Where(s => s.Guid == itemBarcodeDetails.AboutGuid)
.ExecuteCommand();
@@ -695,9 +723,9 @@
.ExecuteCommand();
var totalCDetailsQuantity = db.Queryable<MesInvItemInCDetails>()
- .Where(it => it.WorkLine == itemBarcodeDetails.WorkLine &&
+ .Where(it => it.ItemId == itemBarcodeDetails.ItemId &&
it.WorkNo == itemBarcodeDetails.WorkNo &&
- it.CbillNo == itemBarcodeDetails.BillNo)
+ it.ItemInId == cId)
.Sum(it => it.Quantity);
var detailSummary = db.Queryable<MesInvItemArnDetail>()
@@ -719,12 +747,50 @@
var mesItems = db.Queryable<MesItems>()
.Where(s => s.Id == itemBarcodeDetails.ItemId).First();
- result.Message =
- $"鏉$爜鏁伴噺 {itemBarcodeDetails.Quantity},閲囪喘璁㈠崟 {itemBarcodeDetails.WorkNo} 椤规 {itemBarcodeDetails.WorkLine} 鐗╂枡 {mesItems.ItemNo} 鏈鍏ュ簱鎬绘暟锛歿totalCDetailsQuantity} 鎬诲埌 {comeQty} 宸插叆 {invQty} 娆� {diffQty}";
+ //result.Message =
+ // $"鏉$爜鏁伴噺 {itemBarcodeDetails.Quantity},閲囪喘璁㈠崟 {itemBarcodeDetails.WorkNo} 椤规 {itemBarcodeDetails.WorkLine} 鐗╂枡 {mesItems.ItemNo} 鏈鍏ュ簱鎬绘暟锛歿totalCDetailsQuantity} 鎬诲埌 {comeQty} 宸插叆 {invQty} 娆� {diffQty}";
+ result.Message = $"鐗╂枡{mesItems.ItemNo}鍏ュ簱鎴愬姛鏁伴噺{itemBarcodeDetails.Quantity.ToString()}";
+
+ result.itemDetail = mesItems;
+
+ result.ItemInDetails = db.Queryable<MesInvItemInCItems,MesItems>(
+ (a, b) => new JoinQueryInfos(
+ JoinType.Left,
+ a.ItemId == b.ItemId)
+ )
+ .Where(a => a.ItemInId == cId && a.ItemId == itemBarcodeDetails.ItemId)
+ .Select<dynamic>((a, b) => new
+ {
+ ItemNo = b.ItemNo,
+ ItemName = b.ItemName,
+ ItemModel = b.ItemModel,
+ FQty = a.Quantity, // 鐢宠鏁伴噺
+ FMaterialId = b.ItemId,
+ Id = b.Guid.ToString()
+ })
+ .ToList();
+
+ result.ItemBarCDetails = db.Queryable<MesInvItemInCDetails, MesItems>(
+ (a, b) => new JoinQueryInfos(
+ JoinType.Left,
+ a.ItemId == b.ItemId)
+ )
+ .Where(a => a.ItemInId == cId && a.ItemId == itemBarcodeDetails.ItemId)
+ .Select<dynamic>((a, b) => new
+ {
+ ItemNo = b.ItemNo,
+ ItemName = b.ItemName,
+ ItemModel = b.ItemModel,
+ FQty = a.Quantity, // 鐢宠鏁伴噺
+ FMaterialId = b.ItemId,
+ Id = a.Guid.ToString(),
+ kw = a.DepotSectionCode
+ })
+ .ToList();
- result.ItemNo = mesItems.ItemNo;
- result.SumQuantity = Convert.ToDecimal(totalCDetailsQuantity);
+ //result.ItemNo = mesItems.ItemNo;
+ result.SumQuantity = Convert.ToDecimal(invQty);
return 1;
}
@@ -751,14 +817,12 @@
// Step 2: Calculate total sum from `mes_inv_item_in_c_details`
var totalCDetailsQuantity = db.Queryable<MesInvItemInCDetails>()
- .Where(it => it.CbillNo == itemBarcodeDetails.BillNo &&
- it.ItemId == itemBarcodeDetails.ItemId)
+ .Where(it => it.Guid == itemBarcodeDetails.AboutGuid)
.Sum(it => it.Quantity);
// Step 3: Calculate comeQty and invQty from `mes_inv_item_arn_detail`
var detailSummary = db.Queryable<MesInvItemArnDetail>()
- .Where(it => it.CbillNo == itemBarcodeDetails.BillNo &&
- it.ItemId == itemBarcodeDetails.ItemId)
+ .Where(it => it.Guid == itemBarcodeDetails.AboutGuid)
.Select(it => new
{
TotalComeQty = SqlFunc.AggregateSum(it.Quantity),
@@ -781,7 +845,7 @@
$" 鏉$爜鏁伴噺:{itemBarcodeDetails.Quantity},鐗╂枡 {mesItems.ItemNo} 鏈鍏ュ簱鎬绘暟锛歿totalCDetailsQuantity} 鎬诲埌 {comeQty} 宸插叆 {invQty} 娆� {diffQty}";
- result.ItemNo = mesItems.ItemNo;
+ //result.ItemNo = mesItems.ItemNo;
result.SumQuantity = Convert.ToDecimal(totalCDetailsQuantity);
}
@@ -796,20 +860,20 @@
var purchaseInventory = getPurchaseInventory(entity);
- result.ItemIns = purchaseInventory.ItemIns;
- result.ItemInDetails = purchaseInventory.ItemInDetails;
- result.InvItemInCDetails = purchaseInventory.InvItemInCDetails;
+
+ //result.ItemInDetails = purchaseInventory.ItemInDetails;
+ //result.InvItemInCDetails = purchaseInventory.InvItemInCDetails;
return result;
}
- public PurchaseInventory getPurchaseInventory(WarehouseQuery query)
+ public ItemInBaseModel getPurchaseInventory(WarehouseQuery query)
{
- return new PurchaseInventory
+ return new ItemInBaseModel
{
- ItemIns = GetInvItemInsList(query).Items[0],
- ItemInDetails = GetItemInDetails(query.id),
- InvItemInCDetails = GetInvItemInCDetails(query.id)
+ //ItemIns = GetInvItemInsList(query).Items[0],
+ //ItemInDetails = GetItemInDetails(query.id),
+ //InvItemInCDetails = GetInvItemInCDetails(query.id)
};
}
--
Gitblit v1.9.3