From 7883316c61d4f8fa70fe6cde0c0f53e9e3d8d1d0 Mon Sep 17 00:00:00 2001 From: 南骏 池 <chiffly@163.com> Date: 星期四, 15 五月 2025 14:22:40 +0800 Subject: [PATCH] 1.OA->MES审批接口开发。 2.OA->MES退回接口开发。 3.MES->OA由同步调整为异步。 --- service/Wom/WwGdManager.cs | 242 +++++++++++++++++++++++++++++++++++++++-------- 1 files changed, 199 insertions(+), 43 deletions(-) diff --git a/service/Wom/WwGdManager.cs b/service/Wom/WwGdManager.cs index 2254eb1..09de0e9 100644 --- a/service/Wom/WwGdManager.cs +++ b/service/Wom/WwGdManager.cs @@ -1,5 +1,6 @@ 锘縰sing System.Data; using System.Data.SqlClient; +using System.Threading.Tasks.Dataflow; using Masuit.Tools; using NewPdaSqlServer.DB; using NewPdaSqlServer.Dto.service; @@ -58,7 +59,9 @@ daa001 = query.daa001, barcodeNum = barcodeNum, splitNum = splitNum, - barcode = query.barcode + barcode = query.barcode, + strMsg = _strMsg, + result = _intSum }; return dto; @@ -147,7 +150,7 @@ var wwgd = Db.Queryable<WwGd, MesItems>((a, i) => new JoinQueryInfos(JoinType.Left, a.Daa003 == i.ItemId)) - .Where((a, i) => a.Daa001 == query.daa001) + .Where((a, i) => a.Daa001 == query.daa001 && (a.PcSh ?? 0) == 1) .Select((a, i) => new { a.Daa001, a.RwdGuid @@ -162,8 +165,7 @@ JoinType.Left, a.Id == b.Pid, JoinType.Inner, - c.Id == - b.Dab003, + c.Id == b.Dab003, JoinType.Inner, b.Erpid.ToString() == d.ErpId )) .Where((a, b, c, d) => @@ -283,6 +285,8 @@ if (c_mes_inv_item_barcodes == null) throw new Exception("姝ゆ潯鐮佷笉灞炰簬璇ラ��鏂欏崟锛岃鏍稿锛�"); + + // if (c_mes_inv_item_barcodes.Memo != "鐢熶骇閫�鏂�") // throw new Exception("姝ゆ潯鐮佷笉鏄敓浜ч��鏂欐潯鐮侊紝涓嶅彲浣跨敤鐢熶骇閫�鏂欐ā鍧楋紒"); @@ -295,14 +299,59 @@ if (C_MES_ITEM_TBL.Tbl020 == 1) throw new Exception("鎵爜瀹屾垚,鐢宠鍗曞凡瀹岀粨!"); + // 妫�鏌ュ伐鍗曚俊鎭� + var wwgd = Db.Queryable<WwGd>() + .Where(a => a.Id.ToString() == C_MES_ITEM_TBL.Tbl002) + .First(); + + if (wwgd == null) throw new Exception("鐢宠鍗曞搴旂殑宸ュ崟涓嶅瓨鍦ㄦ垨宸插垹闄�,鏃犳硶鎵爜!"); + + // 妫�鏌ュ伐鍗曚俊鎭� + var WWRWD = Db.Queryable<ProductionOrder>() + .Where(a => a.OrderNo == wwgd.Daa014) + .First(); + // 鑾峰彇閫�鏂欏崟鏄庣粏 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<WwGdDetail>().Where(womdab => womdab.Id.ToString() == C_MES_ITEM_TBL_DETAIL.Tld013).Select(womdab => womdab.Erpid).First(); + + var WWCAB = Db.Queryable<ProductionOrderSub>().Where(womcab => womcab.ErpId == CABerpid.Value.ToString()).First(); + + + if ( String.IsNullOrEmpty(WWCAB.Owner)) 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; @@ -317,7 +366,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(); @@ -327,7 +376,7 @@ // 濡傛灉鍏ュ簱鍗曚笉瀛樺湪鍒欏垱寤烘柊鐨勫叆搴撳崟 if (mesInvItemIns == null) { - c_bill_no = BillNo.GetBillNo("IN(鍏ュ簱鍗�)"); + c_bill_no = BillNo.GetBillNo("WWTL(濮斿閫�鏂�)"); c_id = Guid.NewGuid(); @@ -336,19 +385,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 = wwgd.Daa001, + InType = "濮斿閫�鏂�", + ReceiveOrgId = c_mes_depots.FSubsidiary, + Fstatus = 0, + Status = 0, + WorkNo = WWRWD.ErpProductionOrderNo }).IgnoreColumns(true).ExecuteCommand(); } else @@ -360,6 +416,57 @@ // 妫�鏌ユ槸鍚︿负鍚堝苟鎵撳嵃鏉$爜 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_inv_item_barcodes.AboutGuid.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(); // 鎻掑叆鍏ュ簱鍗曟槑缁� totalResult += db.Insertable(new MesInvItemInCDetails @@ -395,7 +502,11 @@ 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 + RbillNo = C_MES_ITEM_TBL.Tbl002, + ReceiveOrgId = c_mes_depots.FSubsidiary, + EbelnK3id = c_mes_inv_item_barcodes.EbelnK3id, + LineK3id = c_mes_inv_item_barcodes.LineK3id, + Ischeck = true, }).IgnoreColumns(true).ExecuteCommand(); // 鎻掑叆涓氬姟璁板綍 @@ -437,9 +548,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, @@ -449,7 +560,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 = WWCAB.Owner, + OwnerType = WWCAB.OwnerType, + StockOrgId = c_mes_depots.FSubsidiary, + IndepUserCode = c_user }).IgnoreColumns(true).ExecuteCommand(); // 鏍规嵁閫�鏂欑被鍨�(鑹搧閫�鏂欍�佹潵鏂欎笉鑹��鏂欍�佷綔涓氫笉鑹��鏂�)鏇存柊鐩稿叧鏁版嵁 @@ -506,9 +623,9 @@ (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) + && it.Tld009 == c_mes_inv_item_barcodes.ItemId) + //&& it.Tld010 == + //c_mes_inv_item_barcodes.WorkLine) .ExecuteCommand(); } // 浣滀笟涓嶈壇閫�鏂� - 鏇存柊宸ュ崟琛ㄥ拰閫�鏂欏崟鏄庣粏琛� @@ -540,9 +657,9 @@ (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) + && it.Tld009 == c_mes_inv_item_barcodes.ItemId) + //&& it.Tld010 == + //c_mes_inv_item_barcodes.WorkLine) .ExecuteCommand(); } @@ -577,6 +694,11 @@ if (totalResult < minimumExpectedOperations) throw new Exception( $"鍏抽敭鏁版嵁鎻掑叆澶辫触锛岄鏈熻嚦灏憑minimumExpectedOperations}涓搷浣滐紝瀹為檯鎵ц{totalResult}涓搷浣�"); + + // 鍒涘缓 鎻掑叆鏃ュ織 + var logService = new LogService(); + var LogMsg = "[PDA]濮斿閫�鏂欍�傛潯鐮併��" + query.barcode + "銆� 閫�鏂欏崟鍙枫��" + c_bill_no + "銆�"; + logService.CreateLog(db, query.userName, wwgd.Id.ToString(), "WW_GD", LogMsg, wwgd.Daa001); return totalResult; }); @@ -652,7 +774,7 @@ // 鑾峰彇琛ユ枡鍗曟槑缁嗗苟鏍¢獙 var blDetail = Db.Queryable<MesItemBlDetail>() .Where(b => - b.Mid == mesItemBl.Id && b.Bld012 == stockBarcode.ItemId) + b.Mid == mesItemBl.Id && b.Bld012 == stockBarcode.ItemId && b.Bld007 > b.Bld008) .First(); if (blDetail == null) @@ -668,6 +790,11 @@ .Where(a => a.Daa001 == query.billNo) .First(); + // 妫�鏌ュ伐鍗曚俊鎭� + var WWRWD = Db.Queryable<ProductionOrder>() + .Where(a => a.OrderNo == wwgd.Daa014) + .First(); + if (wwgd == null) throw new Exception($"宸ュ崟 {query.billNo} 涓嶅瓨鍦紝璇风‘璁わ紒"); @@ -678,6 +805,11 @@ if (womdab == null) throw new Exception($"澶囨枡鏄庣粏涓嶅瓨鍦ㄦ鐗╂枡 {stockBarcode.ItemNo} 璇风‘璁わ紒"); + + + var depots = Db.Queryable<MesDepots>() + .Where(t => t.DepotId == stockBarcode.DepotId) + .First(); if (stockBarcode.Quantity > quantity) { @@ -707,13 +839,24 @@ // 寮�鍚簨鍔″鐞� var success = UseTransaction(db => { + //query.Type = "濮斿琛ユ枡"; + var outNoType = "WWBL(濮斿琛ユ枡)"; + if (query.Type == "濮斿琛ユ枡") + { + outNoType = "WWBL(濮斿琛ユ枡)"; + } + else + { + outNoType = "WWCL(濮斿瓒呴)"; + } + //outNoType = "WWBL(濮斿琛ユ枡)"; // 鑾峰彇鎴栧垱寤哄嚭搴撳崟 var outId = Guid.NewGuid(); - var outNo = BillNo.GetBillNo("BL(宸ュ崟琛ユ枡)"); + var outNo = BillNo.GetBillNo(outNoType); var existingOut = db.Queryable<MesInvItemOuts>() - .Where(a => a.BbillNo == query.blNo - && a.DepotCode == womdab.Dab017 + .Where(a => a.TaskNo == query.blNo + && a.DepotId == stockBarcode.DepotId && a.OutDate.Value.Date.ToString("yyyy-MM-dd") == DateTime.Now.Date.ToString("yyyy-MM-dd") && a.BillTypeId == 200 @@ -741,33 +884,36 @@ BillTypeId = 200, TransactionNo = 209, Remark = mesItemBl.Bl007, - DepotCode = womdab.Dab017, - OutPart = wwgd.Daa013.ToString(), + DepotCode = depots.DepotCode, + OutPart = wwgd.DepartId.ToString(), + OutType = query.Type, FType = 0, Factory = stockBarcode.Factory, Company = stockBarcode.Company, - // WorkNo = wwgd.Daa021, - // BoardItem = wwgd.Daa002, + WorkNo = WWRWD.ErpProductionOrderNo, + BoardItem = wwgd.Daa003.ToString(), PbillNo = wwgd.Daa001, OutDate = DateTime.Now, Status = 0, - BbillNo = query.blNo + DepotId = stockBarcode.DepotId, + THORGID = stockBarcode.StockOrgId, + //BbillNo = query.billNo }).IgnoreColumns(true).ExecuteCommand(); } // 妫�鏌ュ苟鏇存柊鍑哄簱鍗曠墿鏂欐槑缁� var itemCount = db.Queryable<MesInvItemOutItems>() .Where(i => - i.ItemOutId == outId && i.ItemId == stockBarcode.ItemId) + i.ItemOutId == outId && i.ItemId == stockBarcode.ItemId && i.ItemOutId == outId && i.DepotId == stockBarcode.DepotsId.ToString()) .Count(); if (itemCount > 0) // 鏇存柊宸插瓨鍦ㄧ殑鐗╂枡鏄庣粏鏁伴噺 db.Updateable<MesInvItemOutItems>() .SetColumns(i => - i.Quantity == i.Quantity + stockBarcode.Quantity) + i.TlQty == i.TlQty + stockBarcode.Quantity) .Where(i => - i.ItemOutId == outId && i.ItemId == stockBarcode.ItemId) + i.ItemOutId == outId && i.ItemId == stockBarcode.ItemId && i.ItemOutId == outId && i.DepotId == stockBarcode.DepotsId.ToString()) .ExecuteCommand(); else // 鎻掑叆鏂扮殑鐗╂枡鏄庣粏璁板綍 @@ -777,21 +923,25 @@ ItemOutId = outId, ItemNo = blDetail.Bld002, Quantity = stockBarcode.Quantity, + TlQty = stockBarcode.Quantity, CreateBy = query.userName, CreateDate = DateTime.Now, LastupdateBy = query.userName, LastupdateDate = DateTime.Now, Factory = stockBarcode.Factory, Company = stockBarcode.Company, - DepotCode = womdab.Dab017, + DepotCode = depots.DepotCode, TaskNo = query.blNo, - // WorkNo = wwgd.Daa021, + WorkNo = WWRWD.ErpProductionOrderNo, WorkLine = blDetail.Bld013, ErpItemNo = womdab.Dab003.ToString(), ErpId = womdab.Eid, ErpAutoid = womdab.Erpid, PbillNo = query.billNo, - ItemId = blDetail.Bld012 + ItemId = blDetail.Bld012, + DepotId = stockBarcode.DepotsId.ToString(), + ItemDabid = blDetail.Id, + //AboutGuid = womdab.Id // Unit = blDetail.Bld009, // DepotId = (int)stockBarcode.DepotsId }).IgnoreColumns(true).ExecuteCommand(); @@ -810,7 +960,7 @@ CreateDate = DateTime.Now, LastupdateBy = query.userName, LastupdateDate = DateTime.Now, - DepotCode = stockBarcode.DepotsCode, + DepotCode = depots.DepotCode, DepotSectionCode = stockBarcode.DepotSectionsCode, Remark = blDetail.Bld010, Factory = stockBarcode.Factory, @@ -824,7 +974,7 @@ PbillNo = query.billNo, ItemId = blDetail.Bld012, Unit = blDetail.Bld009, - DepotId = (int)stockBarcode.DepotsId, + DepotId = (int)stockBarcode.DepotId, EbelnK3id = womdab.Eid, LineK3id = womdab.Erpid }).IgnoreColumns(true).ExecuteCommand(); @@ -835,7 +985,7 @@ Guid = Guid.NewGuid(), Status = 1, BillTypeId = 200, // p_bill_type_id - TransactionCode = "210", // p_transaction_no + TransactionCode = "209", // p_transaction_no BusinessType = -1, ItemBarcode = stockBarcode.ItemBarcode, ItemNo = stockBarcode.ItemNo, @@ -870,6 +1020,7 @@ }) .Where(it => it.Id == womdab.Id && it.Dab003 == womdab.Dab003) .ExecuteCommand(); + // 鏇存柊琛ユ枡鍗曟槑缁嗗凡琛ユ暟閲� db.Updateable<MesItemBlDetail>() @@ -917,6 +1068,11 @@ }) .Where(it => it.Id == mesItemBl.Id) .ExecuteCommand(); + + // 鍒涘缓 鎻掑叆鏃ュ織 + var logService = new LogService(); + var LogMsg = "[PDA]"+query.Type + "銆傛潯鐮併��" +query.barcode+"銆� 鍑哄簱鍗曞彿銆�"+ outNo +"銆�"; + logService.CreateLog(db,query.userName,wwgd.Id.ToString(), "WW_GD", LogMsg,wwgd.Daa001); return 1; }); @@ -1004,7 +1160,7 @@ .Where(s => s.Id == stockBarcode.ItemId).First(); // 鐢熸垚鏂版潯鐮佸彿 - newBarcode = BillNo.GetBillNo("TMBH(鏉$爜缂栧彿)", mesItems.ItemNo); + newBarcode = BillNo.GetBillNo("TM(鏉$爜)", mesItems.ItemNo); // 鍐欏叆鏂版潯鐮� executeCommand += db.Insertable(new MesInvItemBarcodes -- Gitblit v1.9.3