using Masuit.Tools; using MES.Service.Models; using MES.Service.Modes; using NewPdaSqlServer.DB; using NewPdaSqlServer.Dto.service; using NewPdaSqlServer.entity; using NewPdaSqlServer.entity.Base; using NewPdaSqlServer.util; using OracleInternal.Sharding; using SqlSugar; using SqlSugar.Extensions; using System.Data; using System.Data.SqlClient; namespace NewPdaSqlServer.service.Warehouse; public class MesStrkManager : Repository { /// /// 获取受托入库申请列表 /// /// 受托入库申请列表 public List GetStrkBillNo(WarehouseQuery query, dynamic RequestInfo) { var orgId = RequestInfo.OrgId; if (orgId == null) throw new Exception("组织不存在!"); // 获取未完成的退料单号列表 var parameters = new[] { new SugarParameter("@pi_orgId", orgId), new SugarParameter("@inP1", null), new SugarParameter("@inP2", null), new SugarParameter("@inP3", null), new SugarParameter("@inP4", null) }; try { // 返回单号字符串列表Get_Qt_ck_List var list = Db.Ado.SqlQuery( "EXEC prc_pda_strk_list @pi_orgId,@inP1,@inP2,@inP3,@inP4", parameters); return list; } catch (Exception ex) { throw new Exception($"{ex.Message}"); } } /// /// 根据单号获取MES物料表明细 /// /// 仓库查询参数 /// 物料明细列表 public dynamic GetMesItemDetailByBillNo(WarehouseQuery query, dynamic RequestInfo) { if (string.IsNullOrEmpty(query.billNo)) throw new Exception("请选单据号!"); if (query == null) throw new ArgumentNullException(nameof(query), "参数对象不能为null"); 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? blDetails = Db.Ado.SqlQuery( "EXEC prc_pda_strk_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(); // 已扫物料 //// 这里返回所有明细列表 //var result = blDetails.Select(b => new ItemDetailModel //{ // ItemNo = b.ItemNo, // ItemName = b.ItemName, // ItemModel = b.ItemModel, // FQty = b.FQty, // SQty = b.SQty, // DSQty = b.DSQty, // Pid = b.Pid, // FMaterialId = b.FMaterialId, // Id = b.Id, // RecoKw = b.RecoKw, // ItemId = b.FMaterialId //}).ToList(); //return result; return new { //tbBillList = result, blDetails = blDetails.Where(x => x.DSQty > 0).ToList(), ysDetails = blDetails.Where(x => x.SQty > 0).ToList(), Count = items.Count + ysitems.Count }; } catch (Exception ex) { // 保留原有异常处理逻辑 throw new Exception($"{ex.Message}"); } } /// /// 受托入库入库 /// /// /// /// public string XsthScanBarcode(WarehouseQuery unity) { var _strMsg = ""; var _intSum = ""; using (var conn = new SqlConnection(DbHelperSQL.strConn)) { if (unity.userName.IsNullOrEmpty()) throw new Exception("用户名不允许为空"); if (unity.sectionCode.IsNullOrEmpty()) throw new Exception("库位编号不允许为空"); if (unity.barcode.IsNullOrEmpty()) throw new Exception("条码不允许为空"); if (unity.billNo.IsNullOrEmpty()) throw new Exception("申请单号不允许为空"); using (var cmd = new SqlCommand("[prc_pda_inv_strk]", conn)) { try { conn.Open(); cmd.CommandType = CommandType.StoredProcedure; SqlParameter[] parameters = { new("@po_outMsg", SqlDbType.NVarChar, 300), new("@po_outSum", SqlDbType.NVarChar, 300), //new("@po_womInBarSum", SqlDbType.NVarChar, 300), new("@pi_user", unity.userName), new("@pi_barcode", unity.barcode), new("@pi_sectionCode", unity.sectionCode), new("@pi_billno", unity.billNo), }; parameters[0].Direction = ParameterDirection.Output; parameters[1].Direction = ParameterDirection.Output; // parameters[2].Direction = ParameterDirection.Output; foreach (var parameter in parameters) cmd.Parameters.Add(parameter); cmd.ExecuteNonQuery(); _strMsg = parameters[0].Value.ToString(); _intSum = parameters[1].Value.ToString(); var result = Convert.ToInt32(_intSum); if (result <= 0) throw new Exception(_strMsg); return _strMsg; //return 0; } catch (Exception ex) { throw new Exception(ex.Message); } finally { conn.Close(); } } } } }