From 22bd4e4fef55fa22e1a843d5488d77e837da760d Mon Sep 17 00:00:00 2001 From: 啊鑫 <t2856754968@163.com> Date: 星期六, 11 一月 2025 12:53:05 +0800 Subject: [PATCH] 11 --- service/Warehouse/MesItemBlManager.cs | 4 service/Warehouse/MesItemTblManager.cs | 367 ---------------- service/Wom/WwGdManager.cs | 840 ++++++++++++++++++++++++++++++++++++++ Controllers/Warehouse/MesItemBlController.cs | 6 Controllers/Wom/WwGdController.cs | 103 ++++ 5 files changed, 946 insertions(+), 374 deletions(-) diff --git a/Controllers/Warehouse/MesItemBlController.cs b/Controllers/Warehouse/MesItemBlController.cs index b196f79..e0972b8 100644 --- a/Controllers/Warehouse/MesItemBlController.cs +++ b/Controllers/Warehouse/MesItemBlController.cs @@ -297,13 +297,13 @@ /// </remarks> /// <response code="200">鎵弿鎴愬姛</response> /// <response code="400">鎵弿澶辫触锛岃繑鍥炲叿浣撻敊璇俊鎭�</response> - [HttpPost("SctlScanBarcode")] - public ResponseResult SctlScanBarcode([FromBody] WarehouseQuery query) + [HttpPost("ScblScanBarcode")] + public ResponseResult ScblScanBarcode([FromBody] WarehouseQuery query) { try { dynamic resultInfos = new ExpandoObject(); - var (success, pendingList) = _manager.SctlScanBarcode(query); + var (success, pendingList) = _manager.ScblScanBarcode(query); resultInfos.success = success; resultInfos.pendingList = pendingList; return new ResponseResult diff --git a/Controllers/Wom/WwGdController.cs b/Controllers/Wom/WwGdController.cs index 2f9e7bb..e643409 100644 --- a/Controllers/Wom/WwGdController.cs +++ b/Controllers/Wom/WwGdController.cs @@ -121,9 +121,9 @@ } /// <summary> - /// 濮斿宸ュ崟閫�鏂欐壂鐮� + /// 濮斿宸ュ崟琛ユ枡鎵爜 /// </summary> - /// <param name="barcode">鏉″舰鐮佸彿</param> + /// <param name="query">鏉″舰鐮佸彿</param> /// <returns>ResponseResult瀵硅薄锛屽寘鍚姸鎬併�佹秷鎭拰鏁版嵁</returns> // Demo Request: // POST /api/WwGd/WwblScanBarcode @@ -158,6 +158,105 @@ } /// <summary> + /// 鐢熶骇琛ユ枡鍗曟潯鐮佹媶鍒� + /// </summary> + /// <param name="query">鏌ヨ鍙傛暟</param> + /// <returns>鎷嗗垎缁撴灉鍜屽緟澶勭悊鍒楄〃</returns> + /// <remarks> + /// 璇锋眰绀轰緥: + /// POST /api/WwGd/SplitBarcode + /// { + /// "billNo": "WO202401010001", // 宸ュ崟鍙�(蹇呭~) + /// "barcode": "BC001", // 鏉$爜鍙�(蹇呭~) + /// "userName": "admin", // 鐢ㄦ埛鍚�(蹇呭~) + /// "blNo": "BL202401010001", // 琛ユ枡鍗曞彿(蹇呭~) + /// "Num": 10 // 鎷嗗垎鏁伴噺(蹇呭~,蹇呴』澶т簬0) + /// } + /// 涓氬姟澶勭悊锛� + /// - 楠岃瘉琛ユ枡鍗曠姸鎬� + /// - 楠岃瘉鏉$爜搴撳瓨淇℃伅 + /// - 楠岃瘉鎷嗗垎鏁伴噺鏄惁鍚堢悊 + /// - 鎵ц鏉$爜鎷嗗垎浜嬪姟澶勭悊 + /// - 鏇存柊宸ュ崟鍜岃ˉ鏂欏崟鐩稿叧鏁伴噺 + /// 杩斿洖鏁版嵁鍖呭惈锛� + /// - success: 鎷嗗垎鏄惁鎴愬姛 + /// - pendingList: 寰呭鐞嗘槑缁嗗垪琛紝鍖呭惈锛� + /// * Bld012: 鐗╂枡ID + /// * Bld002: 鐗╂枡缂栧彿 + /// * Bld003: 鐗╂枡鍚嶇О + /// * Bld004: 鐗╂枡瑙勬牸 + /// * Bld007: 璁″垝鏁伴噺 + /// * Bld008: 宸茶ˉ鏁伴噺 + /// </remarks> + /// <response code="200">鎷嗗垎鎴愬姛</response> + /// <response code="400">鎷嗗垎澶辫触锛岃繑鍥炲叿浣撻敊璇俊鎭�</response> + [HttpPost("SplitBarcode")] + public ResponseResult SplitBarcode([FromBody] WarehouseQuery query) + { + try + { + dynamic resultInfos = new ExpandoObject(); + var (success, pendingList) = m.SplitBarcode(query); + resultInfos.success = success; + resultInfos.pendingList = pendingList; + return new ResponseResult + { + status = 0, + message = "OK", + data = resultInfos + }; + } + catch (Exception ex) + { + return ResponseResult.ResponseError(ex); + } + } + + /// <summary> + /// 鎵弿鏉$爜 + /// </summary> + /// <param name="query">鏌ヨ瀵硅薄</param> + /// <returns>ResponseResult瀵硅薄锛屽寘鍚姸鎬併�佹秷鎭拰鏁版嵁</returns> + /// <remarks> + /// 璇锋眰绀轰緥: + /// POST /api/WwGd/WwtlScanBarcode + /// { + /// "barcode": "BC001", // 鏉$爜鍙�(蹇呭~) + /// "userName": "admin", // 鐢ㄦ埛鍚�(蹇呭~) + /// } + /// 涓氬姟澶勭悊锛� + /// - 楠岃瘉鏉$爜鏄惁瀛樺湪 + /// - 楠岃瘉鐢ㄦ埛鏄惁鏈夋潈闄� + /// - 鎵ц鏉$爜鎵弿浜嬪姟澶勭悊 + /// - 鏇存柊鐩稿叧璁板綍 + /// 杩斿洖鏁版嵁鍖呭惈锛� + /// - success: 鎵弿鏄惁鎴愬姛 + /// - message: 鎵弿缁撴灉淇℃伅 + /// </remarks> + /// <response code="200">鎵弿鎴愬姛</response> + /// <response code="400">鎵弿澶辫触锛岃繑鍥炲叿浣撻敊璇俊鎭�</response> + [HttpPost("WwtlScanBarcode")] + public ResponseResult WwtlScanBarcode([FromBody] WarehouseQuery query) + { + try + { + dynamic resultInfos = new ExpandoObject(); + var wwtlScanBarcode = m.WwtlScanBarcode(query); + resultInfos.tbBillList = wwtlScanBarcode; + return new ResponseResult + { + status = 0, + message = "OK", + data = resultInfos + }; + } + catch (Exception ex) + { + return ResponseResult.ResponseError(ex); + } + } + + /// <summary> /// 鑾峰彇鎵�鏈� /// </summary> /// <returns></returns> diff --git a/service/Warehouse/MesItemBlManager.cs b/service/Warehouse/MesItemBlManager.cs index a5480b9..b8f5a7a 100644 --- a/service/Warehouse/MesItemBlManager.cs +++ b/service/Warehouse/MesItemBlManager.cs @@ -68,7 +68,7 @@ } /// <summary> - /// 鐢熶骇宸ュ崟閫�鏂欐壂鐮� + /// 鐢熶骇宸ュ崟琛ユ枡鎵爜 /// 鎵弿鏉$爜 prc_rf_pda_scan_zout_barcode3 /// </summary> /// <param name="query">鏌ヨ鍙傛暟</param> @@ -81,7 +81,7 @@ /// - blNo: 琛ユ枡鍗曞彿(蹇呭~) /// </remarks> public (WarehouseQuery item, List<MesItemBlDetail> pendingList) - SctlScanBarcode( + ScblScanBarcode( WarehouseQuery query) { if (string.IsNullOrEmpty(query.billNo)) diff --git a/service/Warehouse/MesItemTblManager.cs b/service/Warehouse/MesItemTblManager.cs index 0df7b9a..10fbaac 100644 --- a/service/Warehouse/MesItemTblManager.cs +++ b/service/Warehouse/MesItemTblManager.cs @@ -456,371 +456,4 @@ query.Num = c_quantity.Value; return query; } - - - /// <summary> - /// 濮斿閫�鏂欐壂鎻忔潯鐮�(鐢熶骇閫�鏂欑殑閫昏緫锛屽彧鏄皟鏁翠簡鍑犱釜瀛楁) - /// </summary> - /// <param name="query">浠撳簱鏌ヨ鍙傛暟</param> - /// <returns>澶勭悊缁撴灉</returns> - public WarehouseQuery WwtlScanBarcode(WarehouseQuery query) - { - var p_item_barcode = query.barcode; // 鐗╂枡鏉$爜 - var p_bill_no = query.billNo; // 鍗曟嵁鍙� - var p_section_code = query.DepotCode; // 搴撲綅缂栫爜 - var c_user = query.userName; // 鐢ㄦ埛鍚� - - var p_bill_type_id = 100; // 鍗曟嵁绫诲瀷ID - var p_transction_no = 104; // 浜ゆ槗缂栧彿 - - // 楠岃瘉搴撲綅鏉$爜 - if (p_section_code.IsNullOrEmpty()) throw new Exception("璇锋壂搴撲綅鏉$爜锛�"); - - // 鑾峰彇搴撲綅淇℃伅 - var c_depot_code = Db.Queryable<MesDepotSections, MesDepots>((a, b) => - new JoinQueryInfos(JoinType.Inner, a.DepotGuid == b.Guid)) - .Where((a, b) => a.DepotSectionCode == p_section_code) - .Select((a, b) => b.DepotId).First(); - - if (!c_depot_code.HasValue) - throw new Exception("搴撲綅缂栫爜" + p_section_code + " 涓嶅瓨鍦紝璇风‘璁わ紒"); - - // 鑾峰彇搴撲綅鍒嗗尯淇℃伅 - var mesDepotSections = Db.Queryable<MesDepotSections>() - .Where(a => a.DepotSectionCode == p_section_code).First(); - - if (mesDepotSections == null) - throw new Exception("搴撲綅缂栫爜" + p_section_code + " 涓嶅瓨鍦紝璇风‘璁わ紒"); - - // 鑾峰彇搴撲綅鍩虹淇℃伅 - var c_mes_depots = Db.Queryable<MesDepots>() - .Where(b => b.Guid == mesDepotSections.DepotGuid).First(); - - if (c_mes_depots == null) - throw new Exception("搴撲綅缂栫爜" + p_section_code + " 涓嶅瓨鍦紝璇风‘璁わ紒"); - - // 妫�鏌ユ潯鐮佹槸鍚﹀凡鍏ュ簱 - var c_num = Db.Queryable<MesInvItemIns, MesInvItemInCDetails>((a, b) => - new JoinQueryInfos(JoinType.Inner, a.Guid == b.ItemInId)) - .Where((a, b) => b.ItemBarcode == p_item_barcode - && a.BillTypeId == p_bill_type_id && - a.TransctionNo == p_transction_no.ToString()) - .Count(); - - if (c_num > 0) throw new Exception("姝ゆ潯鐮佸凡鎵叆搴擄紝鍕块噸澶嶆壂鎻忥紒"); - - c_num = Db.Queryable<MesInvItemStocks>() - .Where(t => t.ItemBarcode == p_item_barcode).Count(); - - if (c_num > 0) throw new Exception("姝ゆ潯鐮佸凡鎵叆搴擄紝鍕块噸澶嶆壂鎻忥紒"); - - // 鑾峰彇鏉$爜淇℃伅 - var c_mes_inv_item_barcodes = Db.Queryable<MesInvItemBarcodes>() - .Where(t => t.ItemBarcode == p_item_barcode).First(); - - if (c_mes_inv_item_barcodes == null) - throw new Exception("姝ゆ潯鐮佷笉灞炰簬璇ラ��鏂欏崟锛岃鏍稿锛�"); - - // if (c_mes_inv_item_barcodes.Memo != "鐢熶骇閫�鏂�") - // throw new Exception("姝ゆ潯鐮佷笉鏄敓浜ч��鏂欐潯鐮侊紝涓嶅彲浣跨敤鐢熶骇閫�鏂欐ā鍧楋紒"); - - // 鑾峰彇閫�鏂欏崟淇℃伅 - var C_MES_ITEM_TBL = Db.Queryable<MesItemTbl>() - .Where(a => a.BillNo == c_mes_inv_item_barcodes.BillNo - && (a.Tbl013 ?? 0) == 1).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) - .First(); - - if (C_MES_ITEM_TBL_DETAIL == null) - throw new Exception("鏉$爜涓嶅睘浜庤鐢宠鍗曟槑缁�,鏃犳硶鎵爜!"); - - var c_quantity = c_mes_inv_item_barcodes.Quantity; - - var c_bill_no = ""; - var c_id = Guid.Empty; - - // 浣跨敤浜嬪姟澶勭悊鏁版嵁鏇存柊 - UseTransaction(db => - { - // 鏌ヨ鍏ュ簱鍗� - var mesInvItemIns = db.Queryable<MesInvItemIns>() - .Where(d => - d.Status == 0 && d.TransctionNo == - p_transction_no.ToString() - && d.CbillNo == c_mes_inv_item_barcodes.BillNo - && d.DepotsId == c_depot_code - && d.InsDate.Value.ToString("yyyyMMdd") == - DateTime.Now.ToString("yyyyMMdd")).First(); - - var totalResult = 0; - - // 濡傛灉鍏ュ簱鍗曚笉瀛樺湪鍒欏垱寤烘柊鐨勫叆搴撳崟 - if (mesInvItemIns == null) - { - c_bill_no = BillNo.GetBillNo("IN(鍏ュ簱鍗�)"); - - c_id = Guid.NewGuid(); - - totalResult += db.Insertable(new MesInvItemIns - { - Guid = c_id, - BillNo = c_bill_no, - BillTypeId = p_bill_type_id, - 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, - 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 - }).IgnoreColumns(true).ExecuteCommand(); - } - else - { - c_id = mesInvItemIns.Guid; - c_bill_no = mesInvItemIns.BillNo; - } - - // 妫�鏌ユ槸鍚︿负鍚堝苟鎵撳嵃鏉$爜 - var hbdy = c_mes_inv_item_barcodes.Hbdy ?? 0; - if (hbdy == 1) throw new Exception("涓嶆敮鎸佸悎骞舵墦鍗扮殑鏉$爜:" + p_item_barcode); - - // 鎻掑叆鍏ュ簱鍗曟槑缁� - totalResult += db.Insertable(new MesInvItemInCDetails - { - Guid = Guid.NewGuid(), - ItemInId = c_id, - BillNo = c_bill_no, - ItemBarcode = p_item_barcode, - Quantity = c_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, - SuppId = c_mes_inv_item_barcodes.SuppId, - SuppNo = c_mes_inv_item_barcodes.SuppNo, - DepotId = c_mes_depots.DepotId, - DepotCode = c_mes_depots.DepotCode, - DepotSectionCode = p_section_code, - ItemSname = c_mes_inv_item_barcodes.ItemSname, - Unit = c_mes_inv_item_barcodes.Unit, - CreateBy = c_user, - CreateDate = DateTime.Now, - LastupdateBy = c_user, - LastupdateDate = DateTime.Now, - Remark = c_mes_inv_item_barcodes.Memo, - Ebeln = c_mes_inv_item_barcodes.Mblnr, - EbelnLineNo = c_mes_inv_item_barcodes.Zeile, - WorkNo = c_mes_inv_item_barcodes.WorkNo, - WorkLine = c_mes_inv_item_barcodes.WorkLine, - CbillNo = c_mes_inv_item_barcodes.BillNo, - 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 - }).IgnoreColumns(true).ExecuteCommand(); - - // 鎻掑叆涓氬姟璁板綍 - totalResult += db.Insertable(new MesInvBusiness2 - { - Guid = Guid.NewGuid(), - Status = 1, - BillTypeId = p_bill_type_id, - TransactionCode = p_transction_no.ToString(), - BusinessType = 1, - ItemBarcode = p_item_barcode, - ItemNo = c_mes_inv_item_barcodes.ItemNo, - LotNo = c_mes_inv_item_barcodes.LotNo, - EpFlag = true, - Quantity = c_mes_inv_item_barcodes.Quantity, - ToInvDepotsCode = c_mes_depots.DepotCode, - InvDepotId = c_depot_code, - ToInvDepotSectionsCode = p_section_code, - Description = "濮斿閫�鏂�", - CreateBy = c_user, - CreateDate = DateTime.Now, - LastupdateBy = c_user, - LastupdateDate = DateTime.Now, - TaskNo = c_mes_inv_item_barcodes.TaskNo, - BillNo = c_bill_no, - WorkNo = c_mes_inv_item_barcodes.WorkNo, - WorkLine = c_mes_inv_item_barcodes.WorkLine, - SuppId = c_mes_inv_item_barcodes.SuppId, - SuppNo = c_mes_inv_item_barcodes.SuppNo, - ItemId = c_mes_inv_item_barcodes.ItemId - }).IgnoreColumns(true).ExecuteCommand(); - - // 鎻掑叆搴撳瓨璁板綍 - totalResult += db.Insertable(new MesInvItemStocks - { - Guid = Guid.NewGuid(), - TaskNo = c_mes_inv_item_barcodes.TaskNo, - ItemBarcode = p_item_barcode, - 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, - DepotId = c_mes_depots.DepotId, - DepotsCode = c_mes_depots.DepotCode, - DepotSectionsCode = p_section_code, - CheckDate = c_mes_inv_item_barcodes.CreateDate, - IndepDate = DateTime.Now, - BoardStyle = c_mes_inv_item_barcodes.BoardStyle, - 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 - }).IgnoreColumns(true).ExecuteCommand(); - - // 鏍规嵁閫�鏂欑被鍨�(鑹搧閫�鏂欍�佹潵鏂欎笉鑹��鏂欍�佷綔涓氫笉鑹��鏂�)鏇存柊鐩稿叧鏁版嵁 - if (C_MES_ITEM_TBL.Tbl005 is "鑹搧閫�鏂�" or "鏉ユ枡涓嶈壇閫�鏂�") - { - // 鑹搧閫�鏂� - 鏇存柊宸ュ崟琛�(WOMDAB)鐩稿叧鏁伴噺 - if (C_MES_ITEM_TBL.Tbl005 == "鑹搧閫�鏂�") - totalResult += Db.Updateable<Womdab>() - .SetColumns(it => new Womdab - { - Dab007 = it.Dab007 - - c_mes_inv_item_barcodes.Quantity, // 鍑忓皯宸ュ崟鏁伴噺 - Dab022 = (it.Dab022 ?? 0) + - c_mes_inv_item_barcodes.Quantity, // 澧炲姞閫�鏂欐暟閲� - LpTl = (it.LpTl ?? 0) + - (int)c_mes_inv_item_barcodes - .Quantity, // 澧炲姞鑹搧閫�鏂欐暟閲� - Dab020 = (it.Dab020 ?? 0) - - c_mes_inv_item_barcodes.Quantity // 鍑忓皯宸插彂鏂欐暟閲� - }) - .Where(it => it.Dab001 == c_mes_inv_item_barcodes.WorkNo - && it.Dab002 == c_mes_inv_item_barcodes - .WorkLine - && it.Dab003 == c_mes_inv_item_barcodes - .ItemId.ToString()) - .ExecuteCommand(); - // 鏉ユ枡涓嶈壇閫�鏂� - 鏇存柊宸ュ崟琛�(WOMDAB)鐩稿叧鏁伴噺 - else if (C_MES_ITEM_TBL.Tbl005 == "鏉ユ枡涓嶈壇閫�鏂�") - totalResult += Db.Updateable<Womdab>() - .SetColumns(it => new Womdab - { - Dab007 = it.Dab007 - - c_mes_inv_item_barcodes.Quantity, // 鍑忓皯宸ュ崟鏁伴噺 - Dab022 = (it.Dab022 ?? 0) + - c_mes_inv_item_barcodes.Quantity, // 澧炲姞閫�鏂欐暟閲� - LlBl = (it.LlBl ?? 0) + - (int)c_mes_inv_item_barcodes - .Quantity, // 澧炲姞鏉ユ枡涓嶈壇鏁伴噺 - Dab020 = (it.Dab020 ?? 0) - - c_mes_inv_item_barcodes.Quantity // 鍑忓皯宸插彂鏂欐暟閲� - }) - .Where(it => it.Dab001 == c_mes_inv_item_barcodes.WorkNo - && it.Dab002 == c_mes_inv_item_barcodes - .WorkLine - && it.Dab003 == c_mes_inv_item_barcodes - .ItemId.ToString()) - .ExecuteCommand(); - - // 鏇存柊閫�鏂欏崟鏄庣粏琛ㄥ凡閫�鏁伴噺 - totalResult += Db.Updateable<MesItemTblDetail>() - .SetColumns(it => new MesItemTblDetail - { - 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) - .ExecuteCommand(); - } - // 浣滀笟涓嶈壇閫�鏂� - 鏇存柊宸ュ崟琛ㄥ拰閫�鏂欏崟鏄庣粏琛� - else if (C_MES_ITEM_TBL.Tbl005 == "浣滀笟涓嶈壇閫�鏂�") - { - totalResult += Db.Updateable<Womdab>() - .SetColumns(it => new Womdab - { - Dab022 = (it.Dab022 ?? 0) + - c_mes_inv_item_barcodes.Quantity, // 澧炲姞閫�鏂欐暟閲� - ZyBl = (it.ZyBl ?? 0) + - (int)c_mes_inv_item_barcodes - .Quantity, // 澧炲姞浣滀笟涓嶈壇鏁伴噺 - Dab020 = (it.Dab020 ?? 0) - - c_mes_inv_item_barcodes.Quantity // 鍑忓皯宸插彂鏂欐暟閲� - }) - .Where(it => it.Dab001 == c_mes_inv_item_barcodes.WorkNo - && it.Dab002 == - c_mes_inv_item_barcodes.WorkLine - && it.Dab003 == c_mes_inv_item_barcodes.ItemId - .ToString()) - .ExecuteCommand(); - - // 鏇存柊閫�鏂欏崟鏄庣粏琛ㄥ凡閫�鏁伴噺 - totalResult += Db.Updateable<MesItemTblDetail>() - .SetColumns(it => new MesItemTblDetail - { - 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) - .ExecuteCommand(); - } - - // 濡傛灉寰呴��鏁伴噺绛変簬鏈閫�鏂欐暟閲忥紝鍒欐洿鏂版槑缁嗗畬鎴愮姸鎬� - if ((C_MES_ITEM_TBL_DETAIL.Tld005 ?? 0) - - (C_MES_ITEM_TBL_DETAIL.Tld006 ?? 0) == - c_mes_inv_item_barcodes.Quantity) - totalResult += Db.Updateable<MesItemTblDetail>() - .SetColumns(it => new MesItemTblDetail - { Tld008 = 1 }) // 璁剧疆瀹屾垚鏍囧織 - .Where(it => it.Tlid == C_MES_ITEM_TBL_DETAIL.Tlid) - .ExecuteCommand(); - - // 妫�鏌ラ��鏂欏崟鏄惁鎵�鏈夋槑缁嗛兘宸插畬鎴� - var remainingCount = Db.Queryable<MesItemTbl, MesItemTblDetail>( - (a, b) => - new JoinQueryInfos(JoinType.Left, a.Id == b.Tlmid)) - .Where((a, b) => - a.BillNo == p_bill_no && - (b.Tld005 ?? 0) - (b.Tld006 ?? 0) > 0) - .Count(); - - // 濡傛灉鎵�鏈夋槑缁嗛兘宸插畬鎴愶紝鍒欐洿鏂伴��鏂欏崟鐘舵�佷负宸插畬鎴� - if (remainingCount < 1) - totalResult += Db.Updateable<MesItemTbl>() - .SetColumns(it => it.Tbl020 == 1) // 璁剧疆瀹屾垚鏍囧織 - .Where(it => it.BillNo == p_bill_no) - .ExecuteCommand(); - - // 妫�鏌ュ繀瑕佺殑鎻掑叆鎿嶄綔鏄惁閮芥垚鍔熸墽琛� - var minimumExpectedOperations = 3; // 鑷冲皯闇�瑕佹墽琛岀殑鎻掑叆鎿嶄綔鏁� - if (totalResult < minimumExpectedOperations) - throw new Exception( - $"鍏抽敭鏁版嵁鎻掑叆澶辫触锛岄鏈熻嚦灏憑minimumExpectedOperations}涓搷浣滐紝瀹為檯鎵ц{totalResult}涓搷浣�"); - - return totalResult; - }); - - query.itemNo = c_mes_inv_item_barcodes.ItemNo; - query.Num = c_quantity.Value; - return query; - } } \ No newline at end of file diff --git a/service/Wom/WwGdManager.cs b/service/Wom/WwGdManager.cs index 7a64858..a1a244d 100644 --- a/service/Wom/WwGdManager.cs +++ b/service/Wom/WwGdManager.cs @@ -218,6 +218,376 @@ return dto; } + #region 濮斿閫�鏂� + + /// <summary> + /// 濮斿閫�鏂欐壂鎻忔潯鐮�(鐢熶骇閫�鏂欑殑閫昏緫锛屽彧鏄皟鏁翠簡鍑犱釜瀛楁) + /// </summary> + /// <param name="query">浠撳簱鏌ヨ鍙傛暟</param> + /// <returns>澶勭悊缁撴灉</returns> + public WarehouseQuery WwtlScanBarcode(WarehouseQuery query) + { + var p_item_barcode = query.barcode; // 鐗╂枡鏉$爜 + var p_bill_no = query.billNo; // 鍗曟嵁鍙� + var p_section_code = query.DepotCode; // 搴撲綅缂栫爜 + var c_user = query.userName; // 鐢ㄦ埛鍚� + + var p_bill_type_id = 100; // 鍗曟嵁绫诲瀷ID + var p_transction_no = 104; // 浜ゆ槗缂栧彿 + + // 楠岃瘉搴撲綅鏉$爜 + if (p_section_code.IsNullOrEmpty()) throw new Exception("璇锋壂搴撲綅鏉$爜锛�"); + + // 鑾峰彇搴撲綅淇℃伅 + var c_depot_code = Db.Queryable<MesDepotSections, MesDepots>((a, b) => + new JoinQueryInfos(JoinType.Inner, a.DepotGuid == b.Guid)) + .Where((a, b) => a.DepotSectionCode == p_section_code) + .Select((a, b) => b.DepotId).First(); + + if (!c_depot_code.HasValue) + throw new Exception("搴撲綅缂栫爜" + p_section_code + " 涓嶅瓨鍦紝璇风‘璁わ紒"); + + // 鑾峰彇搴撲綅鍒嗗尯淇℃伅 + var mesDepotSections = Db.Queryable<MesDepotSections>() + .Where(a => a.DepotSectionCode == p_section_code).First(); + + if (mesDepotSections == null) + throw new Exception("搴撲綅缂栫爜" + p_section_code + " 涓嶅瓨鍦紝璇风‘璁わ紒"); + + // 鑾峰彇搴撲綅鍩虹淇℃伅 + var c_mes_depots = Db.Queryable<MesDepots>() + .Where(b => b.Guid == mesDepotSections.DepotGuid).First(); + + if (c_mes_depots == null) + throw new Exception("搴撲綅缂栫爜" + p_section_code + " 涓嶅瓨鍦紝璇风‘璁わ紒"); + + // 妫�鏌ユ潯鐮佹槸鍚﹀凡鍏ュ簱 + var c_num = Db.Queryable<MesInvItemIns, MesInvItemInCDetails>((a, b) => + new JoinQueryInfos(JoinType.Inner, a.Guid == b.ItemInId)) + .Where((a, b) => b.ItemBarcode == p_item_barcode + && a.BillTypeId == p_bill_type_id && + a.TransctionNo == p_transction_no.ToString()) + .Count(); + + if (c_num > 0) throw new Exception("姝ゆ潯鐮佸凡鎵叆搴擄紝鍕块噸澶嶆壂鎻忥紒"); + + c_num = Db.Queryable<MesInvItemStocks>() + .Where(t => t.ItemBarcode == p_item_barcode).Count(); + + if (c_num > 0) throw new Exception("姝ゆ潯鐮佸凡鎵叆搴擄紝鍕块噸澶嶆壂鎻忥紒"); + + // 鑾峰彇鏉$爜淇℃伅 + var c_mes_inv_item_barcodes = Db.Queryable<MesInvItemBarcodes>() + .Where(t => t.ItemBarcode == p_item_barcode).First(); + + if (c_mes_inv_item_barcodes == null) + throw new Exception("姝ゆ潯鐮佷笉灞炰簬璇ラ��鏂欏崟锛岃鏍稿锛�"); + + // if (c_mes_inv_item_barcodes.Memo != "鐢熶骇閫�鏂�") + // throw new Exception("姝ゆ潯鐮佷笉鏄敓浜ч��鏂欐潯鐮侊紝涓嶅彲浣跨敤鐢熶骇閫�鏂欐ā鍧楋紒"); + + // 鑾峰彇閫�鏂欏崟淇℃伅 + var C_MES_ITEM_TBL = Db.Queryable<MesItemTbl>() + .Where(a => a.BillNo == c_mes_inv_item_barcodes.BillNo + && (a.Tbl013 ?? 0) == 1).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) + .First(); + + if (C_MES_ITEM_TBL_DETAIL == null) + throw new Exception("鏉$爜涓嶅睘浜庤鐢宠鍗曟槑缁�,鏃犳硶鎵爜!"); + + var c_quantity = c_mes_inv_item_barcodes.Quantity; + + var c_bill_no = ""; + var c_id = Guid.Empty; + + // 浣跨敤浜嬪姟澶勭悊鏁版嵁鏇存柊 + UseTransaction(db => + { + // 鏌ヨ鍏ュ簱鍗� + var mesInvItemIns = db.Queryable<MesInvItemIns>() + .Where(d => + d.Status == 0 && d.TransctionNo == + p_transction_no.ToString() + && d.CbillNo == c_mes_inv_item_barcodes.BillNo + && d.DepotsId == c_depot_code + && d.InsDate.Value.ToString("yyyyMMdd") == + DateTime.Now.ToString("yyyyMMdd")).First(); + + var totalResult = 0; + + // 濡傛灉鍏ュ簱鍗曚笉瀛樺湪鍒欏垱寤烘柊鐨勫叆搴撳崟 + if (mesInvItemIns == null) + { + c_bill_no = BillNo.GetBillNo("IN(鍏ュ簱鍗�)"); + + c_id = Guid.NewGuid(); + + totalResult += db.Insertable(new MesInvItemIns + { + Guid = c_id, + BillNo = c_bill_no, + BillTypeId = p_bill_type_id, + 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, + 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 + }).IgnoreColumns(true).ExecuteCommand(); + } + else + { + c_id = mesInvItemIns.Guid; + c_bill_no = mesInvItemIns.BillNo; + } + + // 妫�鏌ユ槸鍚︿负鍚堝苟鎵撳嵃鏉$爜 + var hbdy = c_mes_inv_item_barcodes.Hbdy ?? 0; + if (hbdy == 1) throw new Exception("涓嶆敮鎸佸悎骞舵墦鍗扮殑鏉$爜:" + p_item_barcode); + + // 鎻掑叆鍏ュ簱鍗曟槑缁� + totalResult += db.Insertable(new MesInvItemInCDetails + { + Guid = Guid.NewGuid(), + ItemInId = c_id, + BillNo = c_bill_no, + ItemBarcode = p_item_barcode, + Quantity = c_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, + SuppId = c_mes_inv_item_barcodes.SuppId, + SuppNo = c_mes_inv_item_barcodes.SuppNo, + DepotId = c_mes_depots.DepotId, + DepotCode = c_mes_depots.DepotCode, + DepotSectionCode = p_section_code, + ItemSname = c_mes_inv_item_barcodes.ItemSname, + Unit = c_mes_inv_item_barcodes.Unit, + CreateBy = c_user, + CreateDate = DateTime.Now, + LastupdateBy = c_user, + LastupdateDate = DateTime.Now, + Remark = c_mes_inv_item_barcodes.Memo, + Ebeln = c_mes_inv_item_barcodes.Mblnr, + EbelnLineNo = c_mes_inv_item_barcodes.Zeile, + WorkNo = c_mes_inv_item_barcodes.WorkNo, + WorkLine = c_mes_inv_item_barcodes.WorkLine, + CbillNo = c_mes_inv_item_barcodes.BillNo, + 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 + }).IgnoreColumns(true).ExecuteCommand(); + + // 鎻掑叆涓氬姟璁板綍 + totalResult += db.Insertable(new MesInvBusiness2 + { + Guid = Guid.NewGuid(), + Status = 1, + BillTypeId = p_bill_type_id, + TransactionCode = p_transction_no.ToString(), + BusinessType = 1, + ItemBarcode = p_item_barcode, + ItemNo = c_mes_inv_item_barcodes.ItemNo, + LotNo = c_mes_inv_item_barcodes.LotNo, + EpFlag = true, + Quantity = c_mes_inv_item_barcodes.Quantity, + ToInvDepotsCode = c_mes_depots.DepotCode, + InvDepotId = c_depot_code, + ToInvDepotSectionsCode = p_section_code, + Description = "濮斿閫�鏂�", + CreateBy = c_user, + CreateDate = DateTime.Now, + LastupdateBy = c_user, + LastupdateDate = DateTime.Now, + TaskNo = c_mes_inv_item_barcodes.TaskNo, + BillNo = c_bill_no, + WorkNo = c_mes_inv_item_barcodes.WorkNo, + WorkLine = c_mes_inv_item_barcodes.WorkLine, + SuppId = c_mes_inv_item_barcodes.SuppId, + SuppNo = c_mes_inv_item_barcodes.SuppNo, + ItemId = c_mes_inv_item_barcodes.ItemId + }).IgnoreColumns(true).ExecuteCommand(); + + // 鎻掑叆搴撳瓨璁板綍 + totalResult += db.Insertable(new MesInvItemStocks + { + Guid = Guid.NewGuid(), + TaskNo = c_mes_inv_item_barcodes.TaskNo, + ItemBarcode = p_item_barcode, + 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, + DepotId = c_mes_depots.DepotId, + DepotsCode = c_mes_depots.DepotCode, + DepotSectionsCode = p_section_code, + CheckDate = c_mes_inv_item_barcodes.CreateDate, + IndepDate = DateTime.Now, + BoardStyle = c_mes_inv_item_barcodes.BoardStyle, + 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 + }).IgnoreColumns(true).ExecuteCommand(); + + // 鏍规嵁閫�鏂欑被鍨�(鑹搧閫�鏂欍�佹潵鏂欎笉鑹��鏂欍�佷綔涓氫笉鑹��鏂�)鏇存柊鐩稿叧鏁版嵁 + if (C_MES_ITEM_TBL.Tbl005 is "鑹搧閫�鏂�" or "鏉ユ枡涓嶈壇閫�鏂�") + { + // 鑹搧閫�鏂� - 鏇存柊宸ュ崟琛�(WOMDAB)鐩稿叧鏁伴噺 + if (C_MES_ITEM_TBL.Tbl005 == "鑹搧閫�鏂�") + totalResult += Db.Updateable<Womdab>() + .SetColumns(it => new Womdab + { + Dab007 = it.Dab007 - + c_mes_inv_item_barcodes.Quantity, // 鍑忓皯宸ュ崟鏁伴噺 + Dab022 = (it.Dab022 ?? 0) + + c_mes_inv_item_barcodes.Quantity, // 澧炲姞閫�鏂欐暟閲� + LpTl = (it.LpTl ?? 0) + + (int)c_mes_inv_item_barcodes + .Quantity, // 澧炲姞鑹搧閫�鏂欐暟閲� + Dab020 = (it.Dab020 ?? 0) - + c_mes_inv_item_barcodes.Quantity // 鍑忓皯宸插彂鏂欐暟閲� + }) + .Where(it => it.Dab001 == c_mes_inv_item_barcodes.WorkNo + && it.Dab002 == c_mes_inv_item_barcodes + .WorkLine + && it.Dab003 == c_mes_inv_item_barcodes + .ItemId.ToString()) + .ExecuteCommand(); + // 鏉ユ枡涓嶈壇閫�鏂� - 鏇存柊宸ュ崟琛�(WOMDAB)鐩稿叧鏁伴噺 + else if (C_MES_ITEM_TBL.Tbl005 == "鏉ユ枡涓嶈壇閫�鏂�") + totalResult += Db.Updateable<Womdab>() + .SetColumns(it => new Womdab + { + Dab007 = it.Dab007 - + c_mes_inv_item_barcodes.Quantity, // 鍑忓皯宸ュ崟鏁伴噺 + Dab022 = (it.Dab022 ?? 0) + + c_mes_inv_item_barcodes.Quantity, // 澧炲姞閫�鏂欐暟閲� + LlBl = (it.LlBl ?? 0) + + (int)c_mes_inv_item_barcodes + .Quantity, // 澧炲姞鏉ユ枡涓嶈壇鏁伴噺 + Dab020 = (it.Dab020 ?? 0) - + c_mes_inv_item_barcodes.Quantity // 鍑忓皯宸插彂鏂欐暟閲� + }) + .Where(it => it.Dab001 == c_mes_inv_item_barcodes.WorkNo + && it.Dab002 == c_mes_inv_item_barcodes + .WorkLine + && it.Dab003 == c_mes_inv_item_barcodes + .ItemId.ToString()) + .ExecuteCommand(); + + // 鏇存柊閫�鏂欏崟鏄庣粏琛ㄥ凡閫�鏁伴噺 + totalResult += Db.Updateable<MesItemTblDetail>() + .SetColumns(it => new MesItemTblDetail + { + 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) + .ExecuteCommand(); + } + // 浣滀笟涓嶈壇閫�鏂� - 鏇存柊宸ュ崟琛ㄥ拰閫�鏂欏崟鏄庣粏琛� + else if (C_MES_ITEM_TBL.Tbl005 == "浣滀笟涓嶈壇閫�鏂�") + { + totalResult += Db.Updateable<Womdab>() + .SetColumns(it => new Womdab + { + Dab022 = (it.Dab022 ?? 0) + + c_mes_inv_item_barcodes.Quantity, // 澧炲姞閫�鏂欐暟閲� + ZyBl = (it.ZyBl ?? 0) + + (int)c_mes_inv_item_barcodes + .Quantity, // 澧炲姞浣滀笟涓嶈壇鏁伴噺 + Dab020 = (it.Dab020 ?? 0) - + c_mes_inv_item_barcodes.Quantity // 鍑忓皯宸插彂鏂欐暟閲� + }) + .Where(it => it.Dab001 == c_mes_inv_item_barcodes.WorkNo + && it.Dab002 == + c_mes_inv_item_barcodes.WorkLine + && it.Dab003 == c_mes_inv_item_barcodes.ItemId + .ToString()) + .ExecuteCommand(); + + // 鏇存柊閫�鏂欏崟鏄庣粏琛ㄥ凡閫�鏁伴噺 + totalResult += Db.Updateable<MesItemTblDetail>() + .SetColumns(it => new MesItemTblDetail + { + 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) + .ExecuteCommand(); + } + + // 濡傛灉寰呴��鏁伴噺绛変簬鏈閫�鏂欐暟閲忥紝鍒欐洿鏂版槑缁嗗畬鎴愮姸鎬� + if ((C_MES_ITEM_TBL_DETAIL.Tld005 ?? 0) - + (C_MES_ITEM_TBL_DETAIL.Tld006 ?? 0) == + c_mes_inv_item_barcodes.Quantity) + totalResult += Db.Updateable<MesItemTblDetail>() + .SetColumns(it => new MesItemTblDetail + { Tld008 = 1 }) // 璁剧疆瀹屾垚鏍囧織 + .Where(it => it.Tlid == C_MES_ITEM_TBL_DETAIL.Tlid) + .ExecuteCommand(); + + // 妫�鏌ラ��鏂欏崟鏄惁鎵�鏈夋槑缁嗛兘宸插畬鎴� + var remainingCount = Db.Queryable<MesItemTbl, MesItemTblDetail>( + (a, b) => + new JoinQueryInfos(JoinType.Left, a.Id == b.Tlmid)) + .Where((a, b) => + a.BillNo == p_bill_no && + (b.Tld005 ?? 0) - (b.Tld006 ?? 0) > 0) + .Count(); + + // 濡傛灉鎵�鏈夋槑缁嗛兘宸插畬鎴愶紝鍒欐洿鏂伴��鏂欏崟鐘舵�佷负宸插畬鎴� + if (remainingCount < 1) + totalResult += Db.Updateable<MesItemTbl>() + .SetColumns(it => it.Tbl020 == 1) // 璁剧疆瀹屾垚鏍囧織 + .Where(it => it.BillNo == p_bill_no) + .ExecuteCommand(); + + // 妫�鏌ュ繀瑕佺殑鎻掑叆鎿嶄綔鏄惁閮芥垚鍔熸墽琛� + var minimumExpectedOperations = 3; // 鑷冲皯闇�瑕佹墽琛岀殑鎻掑叆鎿嶄綔鏁� + if (totalResult < minimumExpectedOperations) + throw new Exception( + $"鍏抽敭鏁版嵁鎻掑叆澶辫触锛岄鏈熻嚦灏憑minimumExpectedOperations}涓搷浣滐紝瀹為檯鎵ц{totalResult}涓搷浣�"); + + return totalResult; + }); + + query.itemNo = c_mes_inv_item_barcodes.ItemNo; + query.Num = c_quantity.Value; + return query; + } + + #endregion + #region 濮斿琛ユ枡 @@ -572,5 +942,475 @@ return (query, finalPendingList); } + /// <summary> + /// 鐢熶骇琛ユ枡鍗曟潯鐮佹媶鍒� prc_rf_pda_prnt_zout_barcode2 + /// </summary> + /// <param name="query">鏌ヨ鍙傛暟</param> + /// <returns>(鎴愬姛鏍囧織, 寰呭鐞嗗垪琛�)</returns> + /// <remarks> + /// 鍓嶅彴闇�瑕佷紶鍏ョ殑鍙傛暟: + /// - userName: 鐢ㄦ埛鍚�(蹇呭~) + /// - billNo: 宸ュ崟鍙�(蹇呭~) + /// - barcode: 鐗╂枡鏉$爜(蹇呭~) + /// - Num: 鍙戞枡鏁伴噺(蹇呭~,蹇呴』澶т簬0) + /// - blNo: 琛ユ枡鍗曞彿(蹇呭~) + /// </remarks> + public (bool success, List<MesItemBlDetail> pendingList) SplitBarcode( + WarehouseQuery query) + { + if (string.IsNullOrEmpty(query.userName)) + throw new Exception("鐢ㄦ埛鍚嶄笉鑳戒负绌猴紒"); + + if (string.IsNullOrEmpty(query.billNo)) + throw new Exception("璇烽�夊彇鍗曟嵁鍙凤紒"); + + if (string.IsNullOrEmpty(query.barcode)) + throw new Exception("璇锋壂鎻忔潯鐮侊紒"); + + if (query.Num <= 0) + throw new Exception("璇疯緭鍏ユ纭殑鍙戞枡鏁伴噺锛�"); + + if (string.IsNullOrEmpty(query.blNo)) + throw new Exception("琛ユ枡鍗曞彿涓嶈兘涓虹┖锛�"); + + + // 妫�楠屾槸鍚﹂噸澶嶆壂鎻� + var exists = Db.Queryable<MesInvItemOutCDetails>() + .Where(b => b.ItemBarcode == query.barcode) + .Any(); + + if (exists) + throw new Exception("姝ゆ潯鐮佸凡鎵弿,鍕块噸澶嶆壂鐮侊紒"); + + // 鏌ヨ鏉$爜搴撳瓨淇℃伅 + var stockBarcode = Db.Queryable<MesInvItemStocks>() + .Where(t => t.ItemBarcode == query.barcode && t.Quantity > 0) + .First(); + + if (stockBarcode == null) + throw new Exception($"搴撳瓨涓棤姝ゆ潯鐮�,璇锋牳瀵癸紒{query.barcode}"); + + var totalQty = stockBarcode.Quantity; + string newBarcode = null; + + // 寮�鍚簨鍔″鐞� + var success = UseTransaction(db => + { + var executeCommand = 0; + + // 鎷嗗垎鏉$爜 + if (totalQty > query.Num) + { + var mesItems = db.Queryable<MesItems>() + .Where(s => s.Id == stockBarcode.ItemId).First(); + + // 鐢熸垚鏂版潯鐮佸彿 + newBarcode = BillNo.GetBillNo("TMBH(鏉$爜缂栧彿)", mesItems.ItemNo); + + // 鍐欏叆鏂版潯鐮� + executeCommand += db.Insertable(new MesInvItemBarcodes + { + Guid = Guid.NewGuid(), + ItemBarcode = newBarcode, + CustNo = stockBarcode.CustomerNo, + // ProductCode = stockBarcode.ProductCode, + // ItemBarcode2 = stockBarcode.ItemBarcode2, + // ItemCode = stockBarcode.ItemCode, + ItemNo = stockBarcode.ItemNo, + LotNo = stockBarcode.LotNo, + Quantity = query.Num, + EpFlag = true, + TaskNo = stockBarcode.TaskNo, + CreateBy = query.userName, + CreateDate = DateTime.Now, + LastupdateBy = query.userName, + LastupdateDate = DateTime.Now, + OldItemBarcode = query.barcode, + // Mblnr = stockBarcode.Mblnr, + // Zeile = stockBarcode.Zeile, + // RohInId = stockBarcode.RohInId, + Barcodestatus = false, + Oldqty = query.Num as long?, + // Unit = stockBarcode.Unit, + // WeightUnit = stockBarcode.WeightUnit, + Factory = stockBarcode.Factory, + Company = stockBarcode.Company, + BillNo = stockBarcode.BillNo, + BoardStyle = stockBarcode.BoardStyle, + // ColorName = stockBarcode.ColorName, + WorkNo = stockBarcode.WorkNo, + WorkLine = stockBarcode.WorkLine, + // MemoBad = stockBarcode.MemoBad, + ComeFlg = 5, + // Memo = stockBarcode.Memo, + SuppId = stockBarcode.SuppId, + SuppNo = stockBarcode.SuppNo, + InsDate = stockBarcode.IndepDate, // Added InsDate + ItemId = stockBarcode.ItemId + // ItemUnit = stockBarcode.ItemUnit // Added ItemUnit + }).IgnoreColumns(true).ExecuteCommand(); + + // 鏇存柊鍘熸潯鐮佹暟閲� + executeCommand += db.Updateable<MesInvItemBarcodes>() + .SetColumns(it => it.Quantity == totalQty - query.Num) + .Where(it => it.ItemBarcode == query.barcode) + .ExecuteCommand(); + + // 鍒犻櫎鍘熸潯鐮佸簱瀛樿褰� + executeCommand += db.Deleteable<MesInvItemStocks>() + .Where(it => it.ItemBarcode == query.barcode) + .ExecuteCommand(); + + // 鎻掑叆鍓╀綑鏉$爜鏁伴噺鐨勬柊搴撳瓨璁板綍 + executeCommand += db.Insertable(new MesInvItemStocks + { + Guid = Guid.NewGuid(), + TaskNo = stockBarcode.TaskNo, + ItemBarcode = stockBarcode.ItemBarcode, + ItemNo = stockBarcode.ItemNo, + LotNo = stockBarcode.LotNo, + Quantity = totalQty - query.Num, + EpFlag = stockBarcode.EpFlag, + CustomerNo = stockBarcode.CustomerNo, + ItemWt = stockBarcode.ItemWt, + DepotsCode = stockBarcode.DepotsCode, + DepotsId = stockBarcode.DepotsId, + DepotSectionsCode = stockBarcode.DepotSectionsCode, + CheckDate = stockBarcode.CheckDate, + ItemType = stockBarcode.ItemType, + IndepDate = stockBarcode.IndepDate, + Factory = stockBarcode.Factory, + Company = stockBarcode.Company, + IqcStatus = stockBarcode.IqcStatus, + BoardStyle = stockBarcode.BoardStyle, + WorkNo = stockBarcode.WorkNo, + WorkLine = stockBarcode.WorkLine, + SuppNo = stockBarcode.SuppNo, + ItemId = stockBarcode.ItemId + // UnitId = stockBarcode.ItemUnit + }).IgnoreColumns(true).ExecuteCommand(); + + // 鍐欏叆鏂版潯鐮佺殑浜ゆ槗璁板綍 + executeCommand += db.Insertable(new MesInvBusiness2 + { + Guid = Guid.NewGuid(), + Status = 1, + BillTypeId = 200, // p_bill_type_id + TransactionCode = "209", // p_transaction_no + BusinessType = -1, + ItemBarcode = newBarcode, + ItemNo = stockBarcode.ItemNo, + LotNo = stockBarcode.LotNo, + EpFlag = true, + Quantity = query.Num, + FromInvDepotsCode = null, + FromInvDepotSectionsCode = null, + ToInvDepotsCode = stockBarcode.DepotsCode, + ToInvDepotSectionsCode = stockBarcode.DepotSectionsCode, + Description = null, + CreateBy = query.userName, + CreateDate = DateTime.Now, + LastupdateBy = query.userName, + LastupdateDate = DateTime.Now, + Factory = stockBarcode.Factory, + Company = stockBarcode.Company, + TaskNo = stockBarcode.TaskNo, + BillNo = stockBarcode.BillNo, + WorkNo = stockBarcode.WorkNo, + WorkLine = stockBarcode.WorkLine, + SuppNo = stockBarcode.SuppNo, + SuppId = stockBarcode.SuppId, + ItemId = stockBarcode.ItemId + // CkDepot = stockBarcode.DepotsId + }).IgnoreColumns(true).ExecuteCommand(); + } + else if (totalQty < query.Num) + { + throw new Exception("鍙戞枡鏁伴噺澶т簬鏉$爜鏁�,璇锋牳瀵癸紒"); + } + + if (string.IsNullOrEmpty(newBarcode)) newBarcode = query.barcode; + + // 妫�鏌ヨˉ鏂欏崟鐘舵�� + var mesItemBl = Db.Queryable<MesItemBl>() + .Where(a => a.BlNo == query.blNo && (a.Bl018 ?? false) == false) + .First(); + + if (mesItemBl == null) + throw new Exception($"鐢宠鍗� {query.blNo} 宸叉挙鍥烇紒"); + + if (mesItemBl.Bl018 != true) + throw new Exception($"鐢宠鍗� {query.blNo} 鏈鏍革紒"); + + if (mesItemBl.Bl019 == true) + throw new Exception($"鐢宠鍗� {query.blNo} 宸插畬缁擄紒"); + + // 鑾峰彇琛ユ枡鍗曟槑缁嗗苟鏍¢獙 + var blDetail = Db.Queryable<MesItemBlDetail>() + .Where(b => + b.Mid == mesItemBl.Id && b.Bld012 == stockBarcode.ItemId) + .First(); + + if (blDetail == null) + throw new Exception($"鐢宠鍗曚笉瀛樺湪姝ょ墿鏂� {stockBarcode.ItemNo} 璇风‘璁わ紒"); + + var remainingQty = (blDetail.Bld007 ?? 0) - (blDetail.Bld008 ?? 0); + if (remainingQty == 0) + throw new Exception("鐗╂枡宸叉壂鐮佸畬鎴愶紝璇锋牳瀵癸紒"); + + if (query.Num > remainingQty) + throw new Exception( + $"鎷嗗垎鏁伴噺锛歿query.Num} 澶т簬寰呭彂鏂欐暟閲忥細{remainingQty}锛岃鏍稿锛�"); + + // 妫�鏌ュ伐鍗曚俊鎭� + var womdaa = Db.Queryable<WwGd>() + .Where(a => a.Daa001 == query.billNo) + .First(); + + if (womdaa == null) + throw new Exception($"宸ュ崟 {query.billNo} 涓嶅瓨鍦紝璇风‘璁わ紒"); + + var womdab = Db.Queryable<WwGdDetail>() + .Where(b => + b.Dab001 == query.billNo && b.Erpid == blDetail.Bld014) + .First(); + + if (womdab == null) + throw new Exception($"澶囨枡鏄庣粏涓嶅瓨鍦ㄦ鐗╂枡 {stockBarcode.ItemNo} 璇风‘璁わ紒"); + + // 妫�鏌ュ凡鍙戞枡鏁伴噺鏄惁瓒呰繃寰呭彂鏂欐暟閲� + var sumQty = db.Queryable<MesInvItemOutCDetails>() + .Where(it => + it.TaskNo == query.blNo && it.ItemId == stockBarcode.ItemId) + .Sum(it => it.Quantity); + + if (sumQty > remainingQty) + throw new Exception( + $"鎷嗗垎鏁伴噺锛歿sumQty} 澶т簬寰呭彂鏂欐暟閲忥細{remainingQty}锛岃鏍稿锛�"); + + // 鑾峰彇鎴栧垱寤哄嚭搴撳崟 + var itemOut = db.Queryable<MesInvItemOuts>() + .Where(a => a.BbillNo == query.blNo + && a.DepotCode == womdab.Dab017 + && a.OutDate.Value.Date.ToString("yyyy-MM-dd") == + DateTime.Now.Date.ToString("yyyy-MM-dd") + && a.BillTypeId == 200 + && a.TransactionNo == 209 + && a.Status == 0) + .First(); + + if (itemOut == null) + { + // 鍒涘缓鏂扮殑鍑哄簱鍗� + var outId = Guid.NewGuid(); + var outNo = BillNo.GetBillNo("BL(宸ュ崟琛ユ枡)"); + + // 鎻掑叆鍑哄簱鍗曚富琛� + executeCommand += db.Insertable(new MesInvItemOuts + { + Guid = outId, + ItemOutNo = outNo, + TaskNo = query.blNo, + CreateBy = query.userName, + CreateDate = DateTime.Now, + LastupdateBy = query.userName, + LastupdateDate = DateTime.Now, + BillTypeId = 200, + TransactionNo = 209, + Remark = mesItemBl.Bl007, + DepotCode = womdab.Dab017, + OutPart = womdaa.Daa013.ToString(), + FType = 0, + Factory = stockBarcode.Factory, + Company = stockBarcode.Company, + // WorkNo = womdaa.Daa021, + // BoardItem = womdaa.Daa002, + PbillNo = womdaa.Daa001, + OutDate = DateTime.Now, + Status = 0, + BbillNo = query.blNo + }).IgnoreColumns(true).ExecuteCommand(); + } + + // 妫�鏌ユ槸鍚﹀凡瀛樺湪鍑哄簱鍗曟槑缁� + var itemOutItemCount = db.Queryable<MesInvItemOutItems>() + .Where(it => + it.ItemOutId == itemOut.Guid && + it.ItemId == stockBarcode.ItemId) + .Count(); + + if (itemOutItemCount == 0) + // 鎻掑叆鏂扮殑鍑哄簱鍗曟槑缁� + executeCommand += db.Insertable(new MesInvItemOutItems + { + Guid = Guid.NewGuid(), + ItemOutId = itemOut.Guid, + ItemNo = blDetail.Bld002, + Quantity = query.Num, + CreateBy = query.userName, + CreateDate = DateTime.Now, + LastupdateBy = query.userName, + LastupdateDate = DateTime.Now, + Factory = stockBarcode.Factory, + Company = stockBarcode.Company, + DepotCode = womdab.Dab017, + TaskNo = query.blNo, + // WorkNo = womdaa.Daa021, + WorkLine = blDetail.Bld013, + ErpItemNo = womdab.Dab003.ToString(), + ErpId = womdab.Eid, + ErpAutoid = womdab.Erpid, + PbillNo = query.billNo, + ItemId = blDetail.Bld012 + // Unit = blDetail.Bld009, + // DepotId = (int)stockBarcode.DepotsId + }).IgnoreColumns(true).ExecuteCommand(); + else + // 鏇存柊宸叉湁鍑哄簱鍗曟槑缁嗘暟閲� + executeCommand += db.Updateable<MesInvItemOutItems>() + .SetColumns(it => it.Quantity == it.Quantity + query.Num) + .Where(it => + it.ItemOutId == itemOut.Guid && + it.ItemId == stockBarcode.ItemId) + .ExecuteCommand(); + + // 鎻掑叆鍑哄簱鏉$爜鏄庣粏 + executeCommand += db.Insertable(new MesInvItemOutCDetails + { + Guid = Guid.NewGuid(), + ItemOutId = itemOut.Guid, + ItemBarcode = newBarcode ?? query.barcode, + ItemNo = stockBarcode.ItemNo, + LotNo = stockBarcode.LotNo, + Quantity = query.Num, + ForceOutFlag = 0, + CreateBy = query.userName, + CreateDate = DateTime.Now, + LastupdateBy = query.userName, + LastupdateDate = DateTime.Now, + DepotCode = stockBarcode.DepotsCode, + DepotSectionCode = stockBarcode.DepotSectionsCode, + Remark = blDetail.Bld010, + Factory = stockBarcode.Factory, + Company = stockBarcode.Company, + TaskNoy = mesItemBl.Bl013, + BoardStyle = mesItemBl.Bl002, + TaskNo = query.blNo, + WorkNo = blDetail.Bld001, + WorkLine = blDetail.Bld013, + SuppNo = stockBarcode.SuppNo, + PbillNo = query.billNo, + ItemId = blDetail.Bld012, + Unit = blDetail.Bld009, + DepotId = (int)stockBarcode.DepotsId + }).IgnoreColumns(true).ExecuteCommand(); + + // 鎻掑叆涓氬姟娴佹按 + executeCommand += db.Insertable(new MesInvBusiness2 + { + Guid = Guid.NewGuid(), + Status = 1, + BillTypeId = 200, // p_bill_type_id + TransactionCode = "210", // p_transaction_no + BusinessType = 1, + ItemBarcode = newBarcode ?? query.barcode, + ItemNo = stockBarcode.ItemNo, + LotNo = stockBarcode.LotNo, + EpFlag = true, + Quantity = query.Num, + FromInvDepotsCode = stockBarcode.DepotsCode, + FromInvDepotSectionsCode = stockBarcode.DepotSectionsCode, + Description = null, + CreateBy = query.userName, + CreateDate = DateTime.Now, + LastupdateBy = query.userName, + LastupdateDate = DateTime.Now, + Factory = stockBarcode.Factory, + Company = stockBarcode.Company, + TaskNo = mesItemBl.Bl012, + BillNo = query.blNo, + WorkNo = blDetail.Bld001, + WorkLine = blDetail.Bld013, + SuppNo = stockBarcode.SuppNo, + ItemId = stockBarcode.ItemId + // CkDepot = stockBarcode.DepotsId + }).IgnoreColumns(true).ExecuteCommand(); + + // 鏇存柊宸ュ崟琛ㄦ暟閲� + executeCommand += db.Updateable<WwGdDetail>() + .SetColumns(it => new WwGdDetail + { + Dab007 = (it.Dab007 ?? 0) + (int)query.Num, // 宸ュ崟鏁伴噺 + Dab020 = (it.Dab020 ?? 0) + (int)query.Num, // 宸插彂鏂欐暟閲� + Dab021 = (it.Dab021 ?? 0) + (int)query.Num // 宸插彂鏂欐暟閲� + }) + .Where(it => it.Id == womdab.Id && it.Dab003 == womdab.Dab003) + .IgnoreColumns(true) + .ExecuteCommand(); + + // 鏇存柊琛ユ枡鍗曟槑缁嗗凡琛ユ暟閲� + executeCommand += db.Updateable<MesItemBlDetail>() + .SetColumns(it => new MesItemBlDetail + { + Bld008 = (it.Bld008 ?? 0) + (int)query.Num + }) + .Where(it => it.Id == blDetail.Id) + .ExecuteCommand(); + + // 鑾峰彇鏇存柊鍚庣殑琛ユ枡鍗曟槑缁嗘暟閲� + var updatedDetail = db.Queryable<MesItemBlDetail>() + .Where(it => it.Id == blDetail.Id) + .Select(it => new { it.Bld007, it.Bld008 }) + .First(); + + if ((updatedDetail.Bld007 ?? 0) <= (updatedDetail.Bld008 ?? 0)) + // 鏇存柊鏄庣粏瀹屾垚鐘舵�� + executeCommand += db.Updateable<MesItemBlDetail>() + .SetColumns(it => new MesItemBlDetail { Bld011 = 1 }) + .Where(it => it.Id == blDetail.Id) + .ExecuteCommand(); + + // 妫�鏌ユ槸鍚﹁繕鏈夋湭瀹屾垚鐨勬槑缁� + + var unfinishedDetail = db.Queryable<MesItemBlDetail>() + .Where(it => it.Mid == mesItemBl.Id && (it.Bld011 ?? 0) == 0) + .First(); + + if (unfinishedDetail == null) + // 濡傛灉娌℃湁鎵惧埌鏈畬鎴愭槑缁嗭紝鍒欐洿鏂拌ˉ鏂欏崟鐘舵�佷负宸插畬鎴� + executeCommand += db.Updateable<MesItemBl>() + .SetColumns(it => new MesItemBl + { + Bl019 = true, + WcUser = query.userName, + WcTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + }) + .Where(it => it.Id == mesItemBl.Id) + .ExecuteCommand(); + + if (executeCommand <= 1) throw new Exception("鏇存柊澶辫触"); + + return executeCommand; + }) > 0; + + // 鑾峰彇鏈�缁堢殑寰呭彂鏂欐槑缁嗗垪琛� + var pendingList = Db.Queryable<MesItemBl, MesItemBlDetail>((a, b) => + new JoinQueryInfos(JoinType.Left, a.Id == b.Mid)) + .Where((a, b) => a.BlNo == query.blNo + && (b.Bld007 ?? 0) - (b.Bld008 ?? 0) > 0) + .Select((a, b) => new MesItemBlDetail + { + Bld012 = b.Bld012, + Bld002 = b.Bld002, + Bld003 = b.Bld003, + Bld004 = b.Bld004, + Bld007 = b.Bld007, + Bld008 = b.Bld008 + }) + .ToList(); + + return (success, pendingList); + } + #endregion } \ No newline at end of file -- Gitblit v1.9.3