From 99b5d3d7c950a8332f81d3ca07be9f2d5957f58c Mon Sep 17 00:00:00 2001
From: 南骏 池 <chiffly@163.com>
Date: 星期六, 29 三月 2025 16:26:44 +0800
Subject: [PATCH] 1.期初入库优化
---
service/Warehouse/MesItemTblManager.cs | 205 ++++++++++++++++++++++++++++++++++++++++----------
1 files changed, 163 insertions(+), 42 deletions(-)
diff --git a/service/Warehouse/MesItemTblManager.cs b/service/Warehouse/MesItemTblManager.cs
index 10fbaac..0bd989f 100644
--- a/service/Warehouse/MesItemTblManager.cs
+++ b/service/Warehouse/MesItemTblManager.cs
@@ -1,9 +1,11 @@
锘縰sing Masuit.Tools;
+using MES.Service.Modes;
using NewPdaSqlServer.DB;
using NewPdaSqlServer.Dto.service;
using NewPdaSqlServer.entity;
using NewPdaSqlServer.util;
using SqlSugar;
+using System.Security.Cryptography;
namespace NewPdaSqlServer.service.Warehouse;
@@ -32,7 +34,7 @@
/// </summary>
/// <param name="query">浠撳簱鏌ヨ鍙傛暟</param>
/// <returns>鐗╂枡鏄庣粏鍒楄〃</returns>
- public List<MesItemTblDetail> GetMesItemTblDetailByBillNo(
+ public ProductionPickDto GetMesItemTblDetailByBillNo(
WarehouseQuery query)
{
// 鍏宠仈鏌ヨ鐗╂枡琛ㄣ�佺墿鏂欐槑缁嗚〃鍜岀墿鏂欏熀纭�淇℃伅琛�
@@ -43,23 +45,32 @@
a.Id == b.Tlmid,
JoinType.Left,
b.Tld009 == c.Id)
- ).Where((a, b, c) => a.BillNo == query.billNo)
- .Select<MesItemTblDetail>((a, b, c) => new MesItemTblDetail
+ ).Where((a, b, c) => a.BillNo == query.billNo && (a.Tbl013 ?? 0) == 1)
+ .Select<ItemDetailModel>((a, b, c) => new ItemDetailModel
{
- BillNo = a.BillNo,
- Tlid = b.Tlid,
- Tlmid = b.Tlmid,
- Tld005 = b.Tld005 ?? 0, // 寰呴��鏁伴噺
- Tld006 = b.Tld006 ?? 0, // 宸查��鏁伴噺
- Tld009 = b.Tld009,
+ FQty = b.Tld005 ?? 0, // 寰呴��鏁伴噺
+ SQty = b.Tld006 ?? 0, // 宸查��鏁伴噺
+ DSQty = (b.Tld005 ?? 0) - (b.Tld006 ?? 0),
ItemNo = c.ItemNo, // 鐗╂枡缂栧彿
ItemName = c.ItemName, // 鐗╂枡鍚嶇О
ItemModel = c.ItemModel // 鐗╂枡鍨嬪彿
}).ToList();
- // 绛涢�夊嚭寰呴��鏁伴噺澶т簬宸查��鏁伴噺鐨勮褰�
- var itemTblDetails = mesItemTblDetails
- .Where(s => (s.Tld005 ?? 0) - (s.Tld006 ?? 0) > 0).ToList();
+
+ if (mesItemTblDetails.Count<1)
+ throw new Exception("璇ョ敵璇峰崟銆�" + query.billNo + "銆� 鏄庣粏涓嶅瓨鍦紝璇风‘璁わ紒");
+
+ var DS_list = mesItemTblDetails.Where(s => s.DSQty > 0).ToList();
+
+ var YS_list = mesItemTblDetails.Where(s => s.SQty > 0).ToList();
+
+ var itemTblDetails = new ProductionPickDto
+ {
+ items = DS_list,
+ Ysitems = YS_list
+ // yisao = mesInvItemOutCDetailsList
+ };
+
return itemTblDetails;
}
@@ -162,18 +173,56 @@
.Where(a => a.BillNo == c_mes_inv_item_barcodes.BillNo
&& (a.Tbl013 ?? 0) == 1).First();
+ // 鑾峰彇閫�鏂欏崟淇℃伅
+ var tbWOMDAA = Db.Queryable<Womdaa>()
+ .Where(a => a.Guid.ToString() == C_MES_ITEM_TBL.Tbl002).First();
+
+
+
if (C_MES_ITEM_TBL == null) throw new Exception("鐢宠鍗曞凡鎾ゅ洖,鏃犳硶鎵爜!");
if (C_MES_ITEM_TBL.Tbl020 == 1) throw new Exception("鎵爜瀹屾垚,鐢宠鍗曞凡瀹岀粨!");
// 鑾峰彇閫�鏂欏崟鏄庣粏
var C_MES_ITEM_TBL_DETAIL = Db.Queryable<MesItemTblDetail>()
- .Where(a => a.Tlmid == C_MES_ITEM_TBL.Id
- && a.Tld010 == c_mes_inv_item_barcodes.WorkLine)
+ .Where(a => a.Tlid == c_mes_inv_item_barcodes.AboutGuid)
.First();
if (C_MES_ITEM_TBL_DETAIL == null)
throw new Exception("鏉$爜涓嶅睘浜庤鐢宠鍗曟槑缁�,鏃犳硶鎵爜!");
+
+ var CABerpid = Db.Queryable<Womdab>().Where(womdab => womdab.Guid.ToString() == C_MES_ITEM_TBL_DETAIL.Tld013).Select(womdab => womdab.Erpid).First();
+
+ var ownerId = Db.Queryable<Womcab>().Where(womcab => womcab.Erpid == CABerpid.Value).Select(womcab => womcab.OwnerId).First();
+
+ if (ownerId == null) throw new Exception("鐢ㄦ枡娓呭崟璐т富淇℃伅涓嶅瓨鍦�,鏃犳硶鎵爜锛岃鑱旂郴绠$悊鍛�!");
+
+ var owner_type = "";
+ if (Db.Queryable<SysOrganization>().Any(x => x.Fid == ownerId))
+ {
+ owner_type = "BD_OwnerOrg";
+ }
+ else
+ {
+ // 绗簩灞傚垽鏂細妫�鏌� MES_CUSTOMER
+ if (Db.Queryable<MesCustomer>().Any(x => x.Id == Convert.ToInt32(ownerId)))
+ {
+ owner_type = "BD_Customer";
+ }
+ else
+ {
+ // 绗笁灞傚垽鏂細妫�鏌� MES_SUPPLIER
+ if (Db.Queryable<MesSupplier>().Any(x => x.Id == Convert.ToInt32(ownerId)))
+ {
+ owner_type = "BD_Supplier";
+ }
+ else
+ {
+ throw new Exception("鍏ュ簱澶辫触,鐢ㄦ枡娓呭崟璐т富淇℃伅瀛樺湪闂锛岃鑱旂郴绠$悊鍛樿В鍐筹紒");
+ }
+ }
+ }
+
var c_quantity = c_mes_inv_item_barcodes.Quantity;
@@ -188,7 +237,7 @@
.Where(d =>
d.Status == 0 && d.TransctionNo ==
p_transction_no.ToString()
- && d.CbillNo == c_mes_inv_item_barcodes.BillNo
+ && d.TaskNo == c_mes_inv_item_barcodes.BillNo
&& d.DepotsId == c_depot_code
&& d.InsDate.Value.ToString("yyyyMMdd") ==
DateTime.Now.ToString("yyyyMMdd")).First();
@@ -198,7 +247,7 @@
// 濡傛灉鍏ュ簱鍗曚笉瀛樺湪鍒欏垱寤烘柊鐨勫叆搴撳崟
if (mesInvItemIns == null)
{
- c_bill_no = BillNo.GetBillNo("IN(鍏ュ簱鍗�)");
+ c_bill_no = BillNo.GetBillNo("SCTL(鐢熶骇閫�鏂�)");
c_id = Guid.NewGuid();
@@ -207,19 +256,26 @@
Guid = c_id,
BillNo = c_bill_no,
BillTypeId = p_bill_type_id,
+ InsDate = DateTime.Now,
+ DepotsId = c_depot_code,
UserNoBack = c_user,
Reason = C_MES_ITEM_TBL.Tbl005,
Remark = C_MES_ITEM_TBL.Tbl006,
- InsDate = DateTime.Now,
- // DepotsCode = c_depot_code,
- DepotsId = c_depot_code,
+ //InsDate = DateTime.Now,
+ DepotsCode = c_mes_depots.DepotCode,
+ TaskNo = c_mes_inv_item_barcodes.BillNo,
+ //DepotsId = c_depot_code,
TransctionNo = p_transction_no.ToString(),
CreateBy = c_user,
CreateDate = DateTime.Now,
LastupdateBy = c_user,
LastupdateDate = DateTime.Now,
- CbillNo = C_MES_ITEM_TBL.BillNo,
- RbillNo = C_MES_ITEM_TBL.Tbl002
+ CbillNo = tbWOMDAA.Daa001,
+ InType = "鐢熶骇閫�鏂�",
+ ReceiveOrgId = c_mes_depots.FSubsidiary,
+ Fstatus = 0,
+ Status = 0,
+ WorkNo = tbWOMDAA.Daa021
}).IgnoreColumns(true).ExecuteCommand();
}
else
@@ -232,24 +288,73 @@
var hbdy = c_mes_inv_item_barcodes.Hbdy ?? 0;
if (hbdy == 1) throw new Exception("涓嶆敮鎸佸悎骞舵墦鍗扮殑鏉$爜:" + p_item_barcode);
- // 鎻掑叆鍏ュ簱鍗曟槑缁�
+
+ // 妫�鏌ユ槸鍚﹀瓨鍦ㄤ簬 MES_INV_ITEM_IN_C_ITEMS 琛�
+ var existingCount = db.Queryable<MesInvItemInCItems>()
+ .Where(it =>
+ it.ItemInId == c_id &&
+ it.ItemId == C_MES_ITEM_TBL_DETAIL.Tld009 &&
+ it.DepotId == c_depot_code.ToString())
+ .Count();
+
+ if (existingCount == 0)
+ // 涓嶅瓨鍦ㄦ椂鎻掑叆鏂拌褰�
+ db.Insertable(new MesInvItemInCItems
+ {
+ ItemInId = c_id,
+ Quantity = c_mes_inv_item_barcodes.Quantity,
+ CreateBy = c_user,
+ CreateDate = DateTime.Now,
+ ItemNo = c_mes_inv_item_barcodes.ItemNo,
+ //DepotCode = mesDepost.DepotCode,
+ ItemSname = c_mes_inv_item_barcodes.ItemSname,
+ Unit = c_mes_inv_item_barcodes.Unit,
+ Ebeln = c_mes_inv_item_barcodes.WorkNo,
+ BillNo = c_bill_no,
+ WorkNo = c_mes_inv_item_barcodes.WorkNo,
+ EbelnLineNo = c_mes_inv_item_barcodes.WorkLine,
+ CbillNo = c_mes_inv_item_barcodes.BillNo,
+ WorkLine = c_mes_inv_item_barcodes.WorkLine,
+ SuppId = c_mes_inv_item_barcodes.SuppId,
+ SuppNo = c_mes_inv_item_barcodes.SuppNo,
+ Remark = c_mes_inv_item_barcodes.Memo,
+ EbelnK3id = c_mes_inv_item_barcodes.EbelnK3id,
+ LineK3id = c_mes_inv_item_barcodes.LineK3id,
+ ItemId = c_mes_inv_item_barcodes.ItemId,
+ DepotCode = c_mes_depots.DepotCode,
+ DepotId = c_depot_code.ToString(),
+ itemDabid = C_MES_ITEM_TBL_DETAIL.Tlid.ToString()
+ }).IgnoreColumns(true).ExecuteCommand();
+ else
+ // 瀛樺湪鏃舵洿鏂版暟閲�
+ db.Updateable<MesInvItemInCItems>()
+ .SetColumns(it => new MesInvItemInCItems
+ {
+ Quantity = SqlFunc.IsNull(it.Quantity, 0) + c_mes_inv_item_barcodes.Quantity // 纭繚 Quantity 涓嶄负 null
+ })
+ .Where(it =>
+ it.ItemInId == c_id &&
+ it.ItemId == C_MES_ITEM_TBL_DETAIL.Tld009 &&
+ it.DepotId == c_depot_code.ToString())
+ //.IgnoreColumns(true) // 淇濈暀 IgnoreColumns
+ .ExecuteCommand();
+
+
+ // 鎻掑叆 mes_inv_item_in_c_details 琛�
totalResult += db.Insertable(new MesInvItemInCDetails
{
- Guid = Guid.NewGuid(),
ItemInId = c_id,
BillNo = c_bill_no,
ItemBarcode = p_item_barcode,
- Quantity = c_quantity,
+ Quantity = c_mes_inv_item_barcodes.Quantity,
BarcodeFlag = true,
EpFlag = true,
WorkType = 1,
- ItemId = c_mes_inv_item_barcodes.ItemId,
ItemNo = c_mes_inv_item_barcodes.ItemNo,
- LotNo = c_mes_inv_item_barcodes.LotNo,
+ //LotNo = cgddDetails.BatchNumber,--鎵瑰彿锛岄��鏂欎笉璁剧疆鎵瑰彿
SuppId = c_mes_inv_item_barcodes.SuppId,
SuppNo = c_mes_inv_item_barcodes.SuppNo,
- DepotId = c_mes_depots.DepotId,
- DepotCode = c_mes_depots.DepotCode,
+ //DepotCode = mesDepost.DepotCode,
DepotSectionCode = p_section_code,
ItemSname = c_mes_inv_item_barcodes.ItemSname,
Unit = c_mes_inv_item_barcodes.Unit,
@@ -266,7 +371,16 @@
UrgentFlag = c_mes_inv_item_barcodes.UrgentFlag,
BoardStyle = c_mes_inv_item_barcodes.BoardStyle,
TaskNo = c_mes_inv_item_barcodes.TaskNo,
- RbillNo = C_MES_ITEM_TBL.Tbl002
+ EbelnK3id = c_mes_inv_item_barcodes.EbelnK3id,
+ LineK3id = c_mes_inv_item_barcodes.LineK3id,
+ ItemId = c_mes_inv_item_barcodes.ItemId,
+ Ischeck = true,
+ //CheckDate = C_MES_ITEM_TBL_DETAIL.CheckDate,
+ //CheckRes = C_MES_ITEM_TBL_DETAIL.CheckRes,
+ //CheckStates = C_MES_ITEM_TBL_DETAIL.CheckStates,--妫�楠屼俊鎭�
+ ReceiveOrgId = c_mes_depots.FSubsidiary,
+ DepotCode = c_mes_depots.DepotCode,
+ DepotId = Convert.ToInt64(c_depot_code)
}).IgnoreColumns(true).ExecuteCommand();
// 鎻掑叆涓氬姟璁板綍
@@ -308,9 +422,9 @@
ItemNo = c_mes_inv_item_barcodes.ItemNo,
LotNo = c_mes_inv_item_barcodes.LotNo,
Quantity = c_mes_inv_item_barcodes.Quantity,
- EpFlag = c_mes_inv_item_barcodes.EpFlag.Value
- ? (byte)1
- : (byte)0,
+ //EpFlag = c_mes_inv_item_barcodes.EpFlag.Value
+ // ? (byte)1
+ // : (byte)0,
DepotId = c_mes_depots.DepotId,
DepotsCode = c_mes_depots.DepotCode,
DepotSectionsCode = p_section_code,
@@ -320,7 +434,13 @@
WorkNo = c_mes_inv_item_barcodes.WorkNo,
WorkLine = c_mes_inv_item_barcodes.WorkLine,
SuppNo = c_mes_inv_item_barcodes.SuppNo,
- ItemId = c_mes_inv_item_barcodes.ItemId
+ ItemId = c_mes_inv_item_barcodes.ItemId,
+ BillNo = c_mes_inv_item_barcodes.BillNo,
+ //DepotId = Convert.ToInt32(c_depot_code),
+ OwnerId = ownerId,
+ OwnerType = owner_type,
+ StockOrgId = c_mes_depots.FSubsidiary,
+ IndepUserCode = c_user
}).IgnoreColumns(true).ExecuteCommand();
// 鏍规嵁閫�鏂欑被鍨�(鑹搧閫�鏂欍�佹潵鏂欎笉鑹��鏂欍�佷綔涓氫笉鑹��鏂�)鏇存柊鐩稿叧鏁版嵁
@@ -376,10 +496,8 @@
Tld006 = (it.Tld006 ?? 0) +
(int)c_mes_inv_item_barcodes.Quantity // 澧炲姞宸查��鏁伴噺
})
- .Where(it => it.Tlmid == C_MES_ITEM_TBL.Id
- && it.Tld009 == c_mes_inv_item_barcodes.ItemId
- && it.Tld010 ==
- c_mes_inv_item_barcodes.WorkLine)
+ .Where(it => it.Tlmid == C_MES_ITEM_TBL.Id &&
+ it.Tlid == c_mes_inv_item_barcodes.AboutGuid)
.ExecuteCommand();
}
// 浣滀笟涓嶈壇閫�鏂� - 鏇存柊宸ュ崟琛ㄥ拰閫�鏂欏崟鏄庣粏琛�
@@ -410,10 +528,8 @@
Tld006 = (it.Tld006 ?? 0) +
(int)c_mes_inv_item_barcodes.Quantity // 澧炲姞宸查��鏁伴噺
})
- .Where(it => it.Tlmid == C_MES_ITEM_TBL.Id
- && it.Tld009 == c_mes_inv_item_barcodes.ItemId
- && it.Tld010 ==
- c_mes_inv_item_barcodes.WorkLine)
+ .Where(it => it.Tlmid == C_MES_ITEM_TBL.Id &&
+ it.Tlid == c_mes_inv_item_barcodes.AboutGuid)
.ExecuteCommand();
}
@@ -423,7 +539,7 @@
c_mes_inv_item_barcodes.Quantity)
totalResult += Db.Updateable<MesItemTblDetail>()
.SetColumns(it => new MesItemTblDetail
- { Tld008 = 1 }) // 璁剧疆瀹屾垚鏍囧織
+ { Tld008 = 1 }) // 璁剧疆瀹屾垚鏍囧織
.Where(it => it.Tlid == C_MES_ITEM_TBL_DETAIL.Tlid)
.ExecuteCommand();
@@ -449,6 +565,11 @@
throw new Exception(
$"鍏抽敭鏁版嵁鎻掑叆澶辫触锛岄鏈熻嚦灏憑minimumExpectedOperations}涓搷浣滐紝瀹為檯鎵ц{totalResult}涓搷浣�");
+ // 鍒涘缓 鎻掑叆鏃ュ織
+ var logService = new LogService();
+ var LogMsg = "[PDA]鐢熶骇閫�鏂欍�傛潯鐮併��" + query.barcode + "銆� 閫�鏂欏崟鍙枫��" + c_bill_no + "銆�";
+ logService.CreateLog(db, query.userName, tbWOMDAA.Guid.ToString(), "WOMDAA", LogMsg, tbWOMDAA.Daa001);
+
return totalResult;
});
--
Gitblit v1.9.3