From 00a72fff219241eb5b0405a066cc859d07cf7735 Mon Sep 17 00:00:00 2001 From: 啊鑫 <t2856754968@163.com> Date: 星期三, 17 九月 2025 10:23:44 +0800 Subject: [PATCH] 1111 --- service/Warehouse/MesCgthSqManager.cs | 304 +++++++++++++++++++++++++++++++++++++++----------- 1 files changed, 234 insertions(+), 70 deletions(-) diff --git a/service/Warehouse/MesCgthSqManager.cs b/service/Warehouse/MesCgthSqManager.cs index 782b894..3640c3b 100644 --- a/service/Warehouse/MesCgthSqManager.cs +++ b/service/Warehouse/MesCgthSqManager.cs @@ -6,80 +6,87 @@ using NewPdaSqlServer.entity; using NewPdaSqlServer.entity.Base; using SqlSugar; +using static Microsoft.EntityFrameworkCore.DbLoggerCategory; namespace NewPdaSqlServer.service.Warehouse; public class MesCgthSqManager : Repository<MesCgthSq> { - public List<MesCgthSq> GetMesCgthSq() + public dynamic GetMesCgthSq(dynamic RequestInfo) { - return Db.Queryable<MesCgthSq>() - // .Where(s => s.Status == true) - .Where(s => s.Status == false) - .OrderByDescending(s => s.CreateDate) - .ToList(); - } + var orgId = RequestInfo.OrgId; - public ProductionPickDto GetSumItem(WarehouseQuery query) - { - // 楠岃瘉鐢宠鍗曞彿鏄惁涓虹┖ - if (string.IsNullOrEmpty(query.billNo)) - throw new Exception("鐢宠鍗曞彿涓虹┖"); + if (orgId == null) + throw new Exception("缁勭粐涓嶅瓨鍦紒"); - // 娉ㄩ噴锛氬師鏌ヨ閫昏緫锛堝凡瀹℃牳鐘舵�侊級 - // var mesInvItemOuts = base.GetSingle(it => it.BillNo == query.billNo && it.Status == true); - // if (mesInvItemOuts == null) throw new Exception("閲囪喘閫�璐х敵璇峰崟涓嶅瓨鍦ㄦ垨鏈鏍�"); - - // 鏌ヨ鏈鏍哥姸鎬佺殑閲囪喘閫�璐х敵璇峰崟 - var mesInvItemOuts = base.GetSingle(it => it.BillNo == query.billNo && it.Status == false); - if (mesInvItemOuts == null) - throw new Exception("閲囪喘閫�璐х敵璇峰崟涓嶅瓨鍦ㄦ垨宸插鏍�"); - - // 鏋勫缓鏌ヨ鏄庣粏鏁版嵁鐨凷QL璇彞 - var sql = string.Format(@" - SELECT - c.item_no ItemNo, - c.item_name ItemName, - c.item_model ItemModel, - ISNULL(A.SQ_NUM, 0) FQty, - ISNULL(A.YS_NUM, 0) SQty, - ISNULL(A.SQ_NUM, 0) - ISNULL(A.YS_NUM, 0) DSQty, - dbo.F_QX_GETRECODEPOTSE(A.ITEM_ID, '', '', '') as RecoKw - FROM - MES_CGTH_SQ_DETAIL A - LEFT JOIN MES_CGTH_SQ B ON A.MID = B.ID - LEFT JOIN MES_ITEMS C ON A.ITEM_ID = C.item_id - WHERE - B.BILL_NO = '{0}'", query.billNo); - - // 鎵цSQL鏌ヨ鑾峰彇鏄庣粏鍒楄〃 - var womdabs = Db.Ado.SqlQuery<ItemDetailModel>(sql); - - // 楠岃瘉鏄庣粏鏁版嵁鏄惁瀛樺湪 - if (womdabs.Count < 1) + // 鑾峰彇鏈畬鎴愮殑閫�鏂欏崟鍙峰垪琛� + var parameters = new[] { - throw new Exception("璇ラ噰璐��璐х敵璇峰崟鏄庣粏涓嶅瓨鍦�"); - } - - // 绛涢�夊緟澶勭悊鏄庣粏锛圖SQty > 0锛� - var DS_list = womdabs.Where(s => s.DSQty > 0).ToList(); - - // 绛涢�夊凡澶勭悊鏄庣粏锛圫Qty > 0锛� - var YS_list = womdabs.Where(s => s.SQty > 0).ToList(); - - // 鏋勫缓骞惰繑鍥濪TO瀵硅薄 - var dto = new ProductionPickDto - { - // 娉ㄩ噴锛氬師璁″垝鍙风浉鍏虫槧灏勶紙褰撳墠鏈娇鐢級 - // daa001 = womdaa.Daa001, - // PlanNo = womcaa.Caa020, - - items = DS_list, - Ysitems = YS_list + new SugarParameter("@pi_orgId", orgId), + new SugarParameter("@inP1", null), + new SugarParameter("@inP2", null), + new SugarParameter("@inP3", null), + new SugarParameter("@inP4", null) }; - - return dto; + try + { + // 杩斿洖鍗曞彿瀛楃涓插垪琛� + var blDetails = Db.Ado.SqlQuery<string>( + "EXEC prc_pda_cgth_list @pi_orgId,@inP1,@inP2,@inP3,@inP4", parameters); + return blDetails; + } + catch (Exception ex) + { + throw new Exception($"{ex.Message}"); + } } + + public dynamic GetSumItem(WarehouseQuery query, dynamic RequestInfo) + { + if (string.IsNullOrEmpty(query.billNo)) + throw new Exception("璇烽�夊崟鎹彿锛�"); + + if (query == null) + throw new ArgumentNullException(nameof(query), "鍙傛暟瀵硅薄涓嶈兘涓簄ull"); + + if (string.IsNullOrEmpty(query.billNo?.ToString())) + throw new ArgumentException("鍗曟嵁鍙蜂笉鑳戒负绌�", nameof(query.billNo)); + + var orgId = RequestInfo.OrgId; + + if (orgId == null) + throw new Exception("缁勭粐涓嶅瓨鍦紒"); + + // 鑾峰彇鏈畬鎴愮殑鍙戣揣閫氱煡鍗曟槑缁� + var parameters = new[] +{ + new SugarParameter("@billNo", query.billNo), + new SugarParameter("@pi_orgId",orgId), + new SugarParameter("@inP1", null), + new SugarParameter("@inP2", null), + new SugarParameter("@inP3", null), + new SugarParameter("@inP4", null) + }; + try + { + List<dynamic>? blDetails = Db.Ado.SqlQuery<dynamic>( + "EXEC prc_pda_cgth_detailList @billNo,@pi_orgId,@inP1,@inP2,@inP3,@inP4", parameters); + var items = blDetails.Where(x => x.DSQty > 0).ToList(); // 寰呮壂鐗╂枡 + var ysitems = blDetails.Where(x => x.SQty > 0).ToList(); // 宸叉壂鐗╂枡 + return new + { + items = items, + ysitems = ysitems, + allList = blDetails + }; + } + catch (Exception ex) + { + // 淇濈暀鍘熸湁寮傚父澶勭悊閫昏緫 + throw new Exception($"{ex.Message}"); + } + } + public List<MesCgthSqDetail> GetItems(WarehouseQuery query) { // 灏濊瘯灏唓uery.id杞崲涓篏uid绫诲瀷锛屽鏋滆浆鎹㈠け璐ワ紝鍒欐姏鍑哄紓甯� @@ -127,8 +134,7 @@ using (var conn = new SqlConnection(DbHelperSQL.strConn)) { if (query.userName.IsNullOrEmpty()) throw new Exception("鐢ㄦ埛鍚嶄笉鍏佽涓虹┖"); - if (query.billNo.IsNullOrEmpty()) throw new Exception("棰嗘枡鍗曞彿涓嶅厑璁镐负绌�"); - if (query.barcode.IsNullOrEmpty()) throw new Exception("鏉$爜涓嶅厑璁镐负绌�"); + if (query.billNo.IsNullOrEmpty()) throw new Exception("鐢宠鍗曞彿涓嶅厑璁镐负绌�"); if (query.barcode.IsNullOrEmpty()) throw new Exception("鏉$爜涓嶅厑璁镐负绌�"); using (var cmd = new SqlCommand("[prc_pda_CGTH]", conn)) { @@ -164,7 +170,7 @@ var dto = new ProductionPickDto { - daa001 = query.daa001, + daa001 = query.billNo, barcodeNum = barcodeNum, splitNum = splitNum, barcode = query.barcode, @@ -189,11 +195,10 @@ public ProductionPickDto ScanCodeCF(WarehouseQuery query) { if (query.userName.IsNullOrEmpty()) throw new Exception("鐢ㄦ埛鍚嶄笉鍏佽涓虹┖"); - // if (query.daa001.IsNullOrEmpty()) throw new Exception("棰嗘枡鍗曞彿涓嶅厑璁镐负绌�"); + if (query.billNo.IsNullOrEmpty()) throw new Exception("鐢宠鍗曞彿涓嶅厑璁镐负绌�"); if (query.barcode.IsNullOrEmpty()) throw new Exception("鏉$爜涓嶅厑璁镐负绌�"); if (query.Num is null or 0) throw new Exception("鏉$爜鎷嗗垎鏁颁笉鍏佽涓虹┖鎴栬�呬负0"); - if (query.billNo.IsNullOrEmpty()) throw new Exception("鐢宠鍗曞彿涓嶅厑璁镐负绌�"); var _strMsg = ""; var _intSum = ""; @@ -212,7 +217,6 @@ new("@outSum", SqlDbType.NVarChar, 300), new("@outCfBar", SqlDbType.NVarChar, 300), new("@c_User", query.userName), - // new("@p_biLL_no", query.daa001), new("@p_biLL_no", query.billNo), new("@p_item_barcode", query.barcode), new("@num", query.Num) @@ -233,7 +237,7 @@ var dto = new ProductionPickDto { - daa001 = query.daa001, + daa001 = query.billNo, barcode = query.barcode,//鍘熸潯鐮� cfBarcode = _cfBar//鎷嗗垎鍚庢潯鐮� }; @@ -251,4 +255,164 @@ } } } + + + /// <summary> + /// 閲囪喘鎵爜楠岄�� + /// </summary> + /// <param name="query"></param> + /// <returns></returns> + /// <exception cref="ArgumentNullException"></exception> + /// <exception cref="ArgumentException"></exception> + /// <exception cref="Exception"></exception> + public dynamic ScanCgyt(dynamic query) + { + if (query == null) throw new ArgumentNullException(nameof(query), "鍙傛暟瀵硅薄涓嶈兘涓� null"); + + // 2. 浣跨敤 string.IsNullOrEmpty 鐩存帴鍒ゆ柇瀛楃涓插睘鎬э紙閬垮厤 NullReferenceException锛� + if (string.IsNullOrEmpty(query.userName?.ToString())) + throw new ArgumentException("鐢ㄦ埛鍚嶄笉鍏佽涓虹┖", nameof(query.userName)); + + if (string.IsNullOrEmpty(query.barcode?.ToString())) + throw new ArgumentException("閲囪喘鐗╂枡鏉$爜涓嶅厑璁镐负绌�", nameof(query.barcode)); + + using (var conn = new SqlConnection(DbHelperSQL.strConn)) + { + using (var cmd = new SqlCommand("prc_pda_scan_CGYT", conn)) + { + cmd.CommandType = CommandType.StoredProcedure; + var parameters = new SqlParameter[] + { + new("@pi_user", SqlDbType.NVarChar, 100) { Value = query.userName }, + new("@pi_barcode", SqlDbType.NVarChar, 100) { Value = query.barcode }, + new("@po_outMsg", SqlDbType.NVarChar, 2000) { Direction = ParameterDirection.Output }, + new("@po_outSum", SqlDbType.Int) { Direction = ParameterDirection.Output }, + new("@po_ygdh", SqlDbType.NVarChar, 200) { Direction = ParameterDirection.Output } + }; + + cmd.Parameters.AddRange(parameters); + conn.Open(); + cmd.ExecuteNonQuery(); + + var result = new + { + result = parameters[3].Value.ToString(), + barcode = query.barcode, + ytdh = parameters[4].Value.ToString(), + msg = parameters[2].Value.ToString() + }; + + if (result.result == "-1") + throw new Exception(parameters[2].Value.ToString()); + + return result; + } + } + } + + /// <summary> + /// 鍒犻櫎楠岄��鍗� + /// </summary> + /// <param name="query"></param> + /// <returns></returns> + /// <exception cref="ArgumentNullException"></exception> + /// <exception cref="ArgumentException"></exception> + /// <exception cref="Exception"></exception> + public dynamic deleteCgyt(dynamic query) + { + if (query == null) throw new ArgumentNullException(nameof(query), "鍙傛暟瀵硅薄涓嶈兘涓� null"); + + // 2. 浣跨敤 string.IsNullOrEmpty 鐩存帴鍒ゆ柇瀛楃涓插睘鎬э紙閬垮厤 NullReferenceException锛� + if (string.IsNullOrEmpty(query.userName?.ToString())) + throw new ArgumentException("鐢ㄦ埛鍚嶄笉鍏佽涓虹┖", nameof(query.userName)); + + if (string.IsNullOrEmpty(query.ytdh?.ToString())) + throw new ArgumentException("杩芥函鐮佷笉鍏佽涓虹┖", nameof(query.ytdh)); + + using (var conn = new SqlConnection(DbHelperSQL.strConn)) + { + using (var cmd = new SqlCommand("prc_pda_delete_CGYT", conn)) + { + cmd.CommandType = CommandType.StoredProcedure; + var parameters = new SqlParameter[] + { + new("@pi_user", SqlDbType.NVarChar, 100) { Value = query.userName }, + new("@pi_ytdh", SqlDbType.NVarChar, 100) { Value = query.ytdh }, + new("@po_outMsg", SqlDbType.NVarChar, 2000) { Direction = ParameterDirection.Output }, + new("@po_outSum", SqlDbType.Int) { Direction = ParameterDirection.Output } + }; + + cmd.Parameters.AddRange(parameters); + conn.Open(); + cmd.ExecuteNonQuery(); + + var result = new + { + result = parameters[3].Value.ToString(), + msg = parameters[2].Value.ToString(), + }; + + if (result.result == "-1") + throw new Exception(parameters[2].Value.ToString()); + + return result; + } + } + } + + /// <summary> + /// 鑾峰彇楠岄��鍗曞凡鎵墿鏂欎俊鎭� + /// </summary> + /// <param name="query"></param> + /// <returns></returns> + public dynamic getYtItem(string ytdh) + { + if (string.IsNullOrEmpty(ytdh?.ToString())) + throw new ArgumentException("楠岄��鍗曞彿涓嶅厑璁镐负绌�", nameof(ytdh)); + + var sqlParams = new List<SugarParameter> { new("@ytdh", ytdh) }; + + var sql1 = @"SELECT C.item_id,C.item_no,C.item_name,C.item_model,A.quantity +FROM MES_INV_ITEM_CGYT_ITEMS A + LEFT JOIN MES_INV_ITEM_CGYT B ON A.item_cgyt_id = B.GUID + LEFT JOIN MES_ITEMS C ON A.item_id = C.item_id +WHERE B.item_cgyt_no = @ytdh"; + + var YtItem = Db.Ado.SqlQuery<dynamic>(sql1, sqlParams); + + //if (YtItem.Count < 1) + //{ + // throw new Exception($"璇ラ獙閫�鍗曞彿{ytdh}鐗╂枡鏄庣粏涓嶅瓨鍦紒"); + //} + + return YtItem; + } + + /// <summary> + /// 鑾峰彇楠岄��鍗曞凡鎵潯鐮佷俊鎭� + /// </summary> + /// <param name="query"></param> + /// <returns></returns> + public dynamic getYtBarInfo(string ytdh) + { + if (string.IsNullOrEmpty(ytdh?.ToString())) + throw new ArgumentException("楠岄��鍗曞彿涓嶅厑璁镐负绌�", nameof(ytdh)); + + var sqlParams = new List<SugarParameter> { new("@ytdh", ytdh) }; + + var sql1 = @"SELECT C.item_id,C.item_no,C.item_name,C.item_model,A.quantity,A.ITEM_BARCODE +FROM MES_INV_ITEM_CGYT_C_DETAILS A + LEFT JOIN MES_INV_ITEM_CGYT B ON A.item_cgyt_id = B.GUID + LEFT JOIN MES_ITEMS C ON A.item_id = C.item_id +WHERE B.item_cgyt_no = @ytdh"; + + var YtBarInfo = Db.Ado.SqlQuery<dynamic>(sql1, sqlParams); + + //if (YtBarInfo.Count < 1) + //{ + // throw new Exception($"璇ラ獙閫�鍗曞彿{ytdh}浠栦滑涓嶅瓨鍦紒"); + //} + + return YtBarInfo; + } } \ No newline at end of file -- Gitblit v1.9.3