using NewPdaSqlServer.DB; using NewPdaSqlServer.Dto.service; using NewPdaSqlServer.entity; using NewPdaSqlServer.util; using Newtonsoft.Json; using SqlSugar; namespace NewPdaSqlServer.service.Warehouse; public class MesInvItemInCDetailsManager : Repository { //当前类已经继承了 Repository 增、删、查、改的方法 public PurchaseInventory SaveBarCodes(WarehouseQuery entity) { string functionName = "采购入库", fieldName = null, inFieldVal = null; string user = entity.userName, sectionCode = entity.sectionCode, itemBarcode = entity.barcode; string transactionNo = "101"; int? billTypeId = 100, num = 0, num2 = 0; int freeze = 0; decimal cSyQty = 0; if (string.IsNullOrEmpty(sectionCode)) throw new Exception("请扫库位条码!"); var itemBarcodeDetails = Db.Queryable() .Where(it => it.ItemBarcode == itemBarcode) .First(); if (itemBarcodeDetails == null) throw new Exception("条码不存在,请核对!"); if (!itemBarcodeDetails.ComeFlg.Value) throw new Exception("此条码不属于到货条码,无法用采购入库!"); var inventory = Db.Queryable() .Where(it => it.BillNo == itemBarcodeDetails.BillNo) .First(); if (inventory == null) throw new Exception("此条码找不到对应收货单!"); var inventoryDetails = Db.Queryable() .Where(it => it.ParentGuid == inventory.Guid && it.ItemId == itemBarcodeDetails.ItemId && it.EbelnLine == itemBarcodeDetails.WorkLine && it.Ebeln == itemBarcodeDetails.WorkNo) .First(); if (inventoryDetails == null) throw new Exception("此条码找不到对应收货单明细!"); var depotCode = Db.Queryable() .Where(it => it.DepotSectionCode == sectionCode) .Select(it => it.DepotGuid) .First(); var depotCode2 = Db.Queryable() .Where(it => it.BillNo == itemBarcodeDetails.BillNo) .Select(it => it.DepotsId) .First(); MesDepots mesDepost = null; var checkGuid = UtilityHelper.CheckGuid(depotCode); if (checkGuid && depotCode2 != null) { mesDepost = Db.Queryable() .Where(s => s.DepotId.ToString() == depotCode2).First(); if (depotCode != mesDepost.Guid) throw new Exception("扫描库位与采购入库库位不一致!"); } else { throw new Exception("库位编码 " + sectionCode + " 不存在,请确认!"); } num = Db.Queryable() .Where(it => it.ItemBarcode == itemBarcode) .Count(); if (num > 0) throw new Exception("此条码已扫码入库完成,请核对!"); num = Db.Queryable() .Where(it => it.ItemBarcode == itemBarcode) .Count(); if (num > 0) throw new Exception("此条码已扫码入库,请核对!"); num = Db.Queryable() .Where(a => a.BillNo == itemBarcodeDetails.BillNo) .InnerJoin((a, b) => b.ParentGuid == a.Guid && b.ItemId == itemBarcodeDetails.ItemId && b.Ischeck == 1) .Count(); num2 = Db.Queryable() .Where(a => a.BillNo == itemBarcodeDetails.BillNo) .InnerJoin((a, b) => b.ParentGuid == a.Guid && b.ItemId == itemBarcodeDetails.ItemId && (b.CheckRes == "合格" || b.CheckStates == "特采直接使用")) .Count(); switch (num) { case 0 when num2 == 0: case > 0 when num2 == 0: freeze = 1; break; case 0 when num2 > 0: throw new Exception("入库失败,到货单据有问题!"); } PurchaseInventory result = new PurchaseInventory(); UseTransaction(db => { var existingRecord = db.Queryable() .Where(it => it.InsDate.Value.Date == DateTime.Now.Date && it.Status == 0 && it.TransctionNo == transactionNo && it.BillNo == itemBarcodeDetails.BillNo && it.DepotsCode == mesDepost.DepotCode) .Select(it => new { it.Guid, it.BillNo }) .First(); Guid cId = Guid.Empty; string cBillNo = null; if (existingRecord != null) { // If record exists, assign values cId = existingRecord.Guid; cBillNo = existingRecord.BillNo; } else { cId = Guid.NewGuid(); cBillNo = BillNo.GetBillNo("IN(入库单)"); var suppNo = db.Queryable() .Where(s => s.Id.ToString() == inventory.SuppId) .Select(s => s.SuppNo).First(); db.Insertable(new MesInvItemIns { Guid = cId, BillNo = cBillNo, BillTypeId = billTypeId, InsDate = DateTime.Now, DepotsCode = mesDepost.DepotCode, TransctionNo = transactionNo, SuppNo = suppNo, CreateBy = user, CreateDate = DateTime.Now, LastupdateBy = user, LastupdateDate = DateTime.Now, UrgentFlag = itemBarcodeDetails.UrgentFlag.Value ? 1 : 0, CbillNo = itemBarcodeDetails.BillNo, Fstatus = 0, Status = 0 }).IgnoreColumns(true).ExecuteCommand(); } cSyQty = itemBarcodeDetails.Quantity.Value; itemBarcodeDetails.Hbdy ??= 0; if (itemBarcodeDetails.Hbdy == 1) { var details = db.Queryable() .Where(d => d.CbillNo == itemBarcodeDetails.BillNo && d.Quantity != d.OkRkqty && d.ItemId == itemBarcodeDetails.ItemId) .ToList(); foreach (var detail in details) { if (cSyQty == 0) break; var remainingQty = detail.Quantity - (detail.OkRkqty ?? 0); if (remainingQty <= cSyQty) { // Update detail db.Updateable() .SetColumns(d => new MesInvItemArnDetail { OkRkqty = (int)d.Quantity, IsdepsIn = true }) .Where(d => d.Guid == detail.Guid) .IgnoreColumns(ignoreAllNullColumns: true) .ExecuteCommand(); // Check if already inserted var count = db.Queryable() .Where(t => t.ItemInId == cId && t.ItemId == detail.ItemId && t.WorkNo == detail.WorkNo && t.WorkLine == detail.WorkLine) .Count(); cSyQty -= remainingQty.Value; if (count == 0) { // Insert new item into MES_INV_ITEM_IN_C_ITEMS db.Insertable(new MesInvItemInCItems { ItemInId = cId, Quantity = remainingQty, CreateBy = user, CreateDate = DateTime.Now, ItemId = detail.ItemId, DepotCode = mesDepost.DepotCode, ItemSname = itemBarcodeDetails.ItemSname, Unit = itemBarcodeDetails.Unit, Ebeln = detail.WorkNo, BillNo = cBillNo, WorkNo = detail.WorkNo, CbillNo = detail.CbillNo, WorkLine = detail.WorkLine, SuppNo = itemBarcodeDetails.SuppNo, Remark = itemBarcodeDetails.Memo, EbelnK3id = detail.EbelnK3id, LineK3id = detail.LineK3id }).IgnoreColumns(true).ExecuteCommand(); } else { db.Updateable() .SetColumns(it => it.Quantity == it.Quantity + remainingQty) .Where(it => it.ItemInId == cId && it.ItemId == detail.ItemId && it.WorkNo == detail.WorkNo && it.WorkLine == detail.WorkLine) .IgnoreColumns(ignoreAllNullColumns: true) .ExecuteCommand(); } // Insert new detail into MES_INV_ITEM_IN_C_DETAILS db.Insertable(new MesInvItemInCDetails { ItemInId = cId, BillNo = cBillNo, ItemBarcode = itemBarcode, Quantity = remainingQty, BarcodeFlag = true, EpFlag = true, WorkType = 1, ItemNo = detail.ItemNo, SuppNo = itemBarcodeDetails.SuppNo, DepotCode = mesDepost.DepotCode, DepotSectionCode = sectionCode, ItemSname = itemBarcodeDetails.ItemSname, Unit = itemBarcodeDetails.Unit, CreateBy = user, CreateDate = DateTime.Now, LastupdateBy = user, LastupdateDate = DateTime.Now, Remark = itemBarcodeDetails.Memo, Ebeln = detail.WorkNo, WorkNo = detail.WorkNo, WorkLine = detail.WorkLine, CbillNo = itemBarcodeDetails.BillNo, UrgentFlag = detail.UrgentFlag, BoardStyle = detail.BoardStyle, TaskNo = detail.WorkNo, EbelnK3id = detail.EbelnK3id, LineK3id = detail.LineK3id, ItemId = detail.ItemId }).IgnoreColumns(true).ExecuteCommand(); } else { // Partially fulfill remaining quantity db.Updateable() .SetColumns(d => new MesInvItemArnDetail { OkRkqty = (int)((d.OkRkqty ?? 0) + cSyQty) }) .Where(d => d.Guid == detail.Guid) .IgnoreColumns(ignoreAllNullColumns: true) .ExecuteCommand(); var count = db.Queryable() .Where(t => t.ItemInId == cId && t.ItemId == detail.ItemId && t.WorkNo == detail.WorkNo && t.WorkLine == detail.WorkLine) .Count(); if (count == 0) { db.Insertable(new MesInvItemInCItems { ItemInId = cId, Quantity = cSyQty, CreateBy = user, CreateDate = DateTime.Now, ItemNo = detail.ItemNo, DepotCode = mesDepost.DepotCode, ItemSname = itemBarcodeDetails.ItemSname, Unit = itemBarcodeDetails.Unit, Ebeln = detail.WorkNo, BillNo = cBillNo, WorkNo = detail.WorkNo, EbelnLineNo = detail.EbelnLine, CbillNo = detail.CbillNo, WorkLine = detail.WorkLine, SuppNo = itemBarcodeDetails.SuppNo, Remark = itemBarcodeDetails.Memo, EbelnK3id = detail.EbelnK3id, LineK3id = detail.LineK3id, ItemId = detail.ItemId }).IgnoreColumns(true).ExecuteCommand(); } else { db.Updateable() .SetColumns(it => it.Quantity == it.Quantity + cSyQty) .Where(it => it.ItemInId == cId && it.ItemId == detail.ItemId && it.WorkNo == detail.WorkNo && it.WorkLine == detail.WorkLine) .IgnoreColumns(ignoreAllNullColumns: true) .ExecuteCommand(); } db.Insertable(new MesInvItemInCDetails { ItemInId = cId, BillNo = cBillNo, ItemBarcode = itemBarcode, Quantity = cSyQty, BarcodeFlag = true, EpFlag = true, WorkType = 1, ItemNo = detail.ItemNo, SuppNo = itemBarcodeDetails.SuppNo, DepotCode = mesDepost.DepotCode, DepotSectionCode = sectionCode, ItemSname = itemBarcodeDetails.ItemSname, Unit = itemBarcodeDetails.Unit, CreateBy = user, CreateDate = DateTime.Now, LastupdateBy = user, LastupdateDate = DateTime.Now, Remark = itemBarcodeDetails.Memo, Ebeln = detail.WorkNo, EbelnLineNo = detail.EbelnLine, WorkNo = detail.WorkNo, WorkLine = detail.WorkLine, CbillNo = itemBarcodeDetails.BillNo, UrgentFlag = detail.UrgentFlag, BoardStyle = detail.BoardStyle, TaskNo = detail.WorkNo, EbelnK3id = detail.EbelnK3id, LineK3id = detail.LineK3id, ItemId = detail.ItemId }).IgnoreColumns(true).ExecuteCommand(); cSyQty = 0; // Remaining quantity fulfilled } } db.Insertable(new MesInvBusiness2 { Status = 1, BillTypeId = billTypeId, TransactionCode = transactionNo, BusinessType = 1, ItemBarcode = itemBarcode, ItemNo = itemBarcodeDetails.ItemNo, LotNo = itemBarcodeDetails.LotNo, EpFlag = true, Quantity = itemBarcodeDetails.Quantity, ToInvDepotsCode = mesDepost.DepotCode, ToInvDepotSectionsCode = sectionCode, Description = "采购入库", CreateBy = user, CreateDate = DateTime.Now, LastupdateBy = user, LastupdateDate = DateTime.Now, TaskNo = itemBarcodeDetails.BillNo, BillNo = cBillNo, WorkNo = itemBarcodeDetails.WorkNo, WorkLine = itemBarcodeDetails.WorkLine, SuppNo = itemBarcodeDetails.SuppNo, EbelnK3id = itemBarcodeDetails.EbelnK3id, LineK3id = itemBarcodeDetails.LineK3id, ItemId = itemBarcodeDetails.ItemId }).IgnoreColumns(true).ExecuteCommand(); // Insert into mes_inv_item_stocks } else { // 检查是否存在于 MES_INV_ITEM_IN_C_ITEMS 表 var existingCount = db.Queryable() .Where(t => t.ItemInId == cId && t.ItemId == itemBarcodeDetails.ItemId && t.WorkNo == itemBarcodeDetails.WorkNo && t.WorkLine == itemBarcodeDetails.WorkLine) .Count(); if (existingCount == 0) { // 不存在时插入新记录 db.Insertable(new MesInvItemInCItems { ItemInId = cId, Quantity = itemBarcodeDetails.Quantity, CreateBy = user, CreateDate = DateTime.Now, ItemNo = itemBarcodeDetails.ItemNo, DepotCode = mesDepost.DepotCode, ItemSname = itemBarcodeDetails.ItemSname, Unit = itemBarcodeDetails.Unit, Ebeln = itemBarcodeDetails.WorkNo, BillNo = cBillNo, WorkNo = itemBarcodeDetails.WorkNo, EbelnLineNo = itemBarcodeDetails.WorkLine, CbillNo = itemBarcodeDetails.BillNo, WorkLine = itemBarcodeDetails.WorkLine, SuppNo = itemBarcodeDetails.SuppNo, Remark = itemBarcodeDetails.Memo, EbelnK3id = itemBarcodeDetails.EbelnK3id, LineK3id = itemBarcodeDetails.LineK3id, ItemId = itemBarcodeDetails.ItemId }).IgnoreColumns(true).ExecuteCommand(); } else { // 存在时更新数量 db.Updateable() .SetColumns(it => it.Quantity == it.Quantity + itemBarcodeDetails.Quantity) .Where(it => it.ItemInId == cId && it.ItemId == itemBarcodeDetails.ItemId && it.WorkNo == itemBarcodeDetails.WorkNo && it.WorkLine == itemBarcodeDetails.WorkLine) .IgnoreColumns(ignoreAllNullColumns: true) .ExecuteCommand(); } // 插入 mes_inv_item_in_c_details 表 db.Insertable(new MesInvItemInCDetails { ItemInId = cId, BillNo = cBillNo, ItemBarcode = itemBarcode, Quantity = itemBarcodeDetails.Quantity, BarcodeFlag = true, EpFlag = true, WorkType = 1, ItemNo = itemBarcodeDetails.ItemNo, LotNo = itemBarcodeDetails.LotNo, SuppNo = itemBarcodeDetails.SuppNo, DepotCode = mesDepost.DepotCode, DepotSectionCode = sectionCode, ItemSname = itemBarcodeDetails.ItemSname, Unit = itemBarcodeDetails.Unit, CreateBy = user, CreateDate = DateTime.Now, LastupdateBy = user, LastupdateDate = DateTime.Now, Remark = itemBarcodeDetails.Memo, Ebeln = itemBarcodeDetails.Mblnr, EbelnLineNo = itemBarcodeDetails.Zeile, WorkNo = itemBarcodeDetails.WorkNo, WorkLine = itemBarcodeDetails.WorkLine, CbillNo = itemBarcodeDetails.BillNo, UrgentFlag = itemBarcodeDetails.UrgentFlag, BoardStyle = itemBarcodeDetails.BoardStyle, TaskNo = itemBarcodeDetails.TaskNo, EbelnK3id = itemBarcodeDetails.EbelnK3id, LineK3id = itemBarcodeDetails.LineK3id, ItemId = itemBarcodeDetails.ItemId, Ischeck = true, CheckDate = inventoryDetails.CheckDate, CheckRes = inventoryDetails.CheckRes, CheckStates = inventoryDetails.CheckStates }).IgnoreColumns(true).ExecuteCommand(); // 插入 mes_inv_business2 表 db.Insertable(new MesInvBusiness2 { Status = 1, BillTypeId = billTypeId, TransactionCode = transactionNo, BusinessType = 1, ItemBarcode = itemBarcode, ItemNo = itemBarcodeDetails.ItemNo, LotNo = itemBarcodeDetails.LotNo, EpFlag = true, Quantity = itemBarcodeDetails.Quantity, FromInvDepotsCode = null, FromInvDepotSectionsCode = null, ToInvDepotsCode = mesDepost.DepotCode, ToInvDepotSectionsCode = sectionCode, Description = "采购入库", CreateBy = user, CreateDate = DateTime.Now, LastupdateBy = user, LastupdateDate = DateTime.Now, TaskNo = itemBarcodeDetails.TaskNo, BillNo = cBillNo, WorkNo = itemBarcodeDetails.WorkNo, WorkLine = itemBarcodeDetails.WorkLine, SuppNo = itemBarcodeDetails.SuppNo, EbelnK3id = itemBarcodeDetails.EbelnK3id, LineK3id = itemBarcodeDetails.LineK3id, ItemId = itemBarcodeDetails.ItemId }).IgnoreColumns(true).ExecuteCommand(); // 插入 mes_inv_item_stocks 表 } db.Insertable(new MesInvItemStocks { TaskNo = itemBarcodeDetails.TaskNo, ItemBarcode = itemBarcode, ItemNo = itemBarcodeDetails.ItemNo, LotNo = itemBarcodeDetails.LotNo, Quantity = itemBarcodeDetails.Quantity, DepotsCode = mesDepost.DepotCode, DepotSectionsCode = sectionCode, CheckDate = inventoryDetails.CheckDate, IndepDate = DateTime.Now, IqcStatus = inventoryDetails.CheckStates, BoardStyle = itemBarcodeDetails.BoardStyle, WorkNo = itemBarcodeDetails.WorkNo, WorkLine = itemBarcodeDetails.WorkLine, SuppNo = itemBarcodeDetails.SuppNo, EbelnK3id = itemBarcodeDetails.EbelnK3id, LineK3id = itemBarcodeDetails.LineK3id, ItemId = itemBarcodeDetails.ItemId, BillNo = itemBarcodeDetails.BillNo }).IgnoreColumns(true).ExecuteCommand(); itemBarcodeDetails.Hbdy ??= 0; if (itemBarcodeDetails.Hbdy != 1) { db.Updateable() .SetColumns(d => new MesInvItemArnDetail { OkRkqty = (int)((d.OkRkqty ?? 0) + cSyQty) }) .Where(d => d.Guid == inventoryDetails.Guid) .ExecuteCommand(); var first = db .Queryable() .Where(b => b.Guid == inventoryDetails.Guid) .Select(b => new { TotalQuantity = SqlFunc.AggregateSum(b.Quantity), TotalOkRkQty = SqlFunc.AggregateSum(b.OkRkqty) }) .First(); var TotalQuantity = first.TotalQuantity ?? 0; var TotalOkRkQty = first.TotalOkRkQty ?? 0; if (TotalQuantity == TotalOkRkQty) { db.Updateable() .SetColumns(s => s.IsdepsIn == true) .Where(s => s.Guid == inventoryDetails.Guid) .ExecuteCommand(); } var totalSummary = db.Queryable() .InnerJoin((b, a) => a.Guid == b.ParentGuid) .Where((b, a) => a.BillNo == inventory.BillNo && b.ReturnFlag == 0) .Select((b, a) => new { TotalQuantity = SqlFunc.AggregateSum(b.Quantity), TotalOkRkQty = SqlFunc.AggregateSum(b.OkRkqty) }) .First(); if ((totalSummary.TotalQuantity ?? 0) == (totalSummary.TotalOkRkQty ?? 0)) { db.Updateable() .SetColumns(it => it.Status == 1) .Where(it => it.BillNo == itemBarcodeDetails.BillNo) .ExecuteCommand(); } var totalCDetailsQuantity = db.Queryable() .Where(it => it.WorkLine == itemBarcodeDetails.WorkLine && it.WorkNo == itemBarcodeDetails.WorkNo && it.CbillNo == itemBarcodeDetails.BillNo) .Sum(it => it.Quantity); var detailSummary = db.Queryable() .Where(it => it.Guid == inventoryDetails.Guid) .Select(it => new { TotalComeQty = SqlFunc.AggregateSum(it.Quantity), TotalInvQty = SqlFunc.AggregateSum(it.OkRkqty) }) .First(); var comeQty = detailSummary.TotalComeQty ?? 0; var invQty = detailSummary.TotalInvQty ?? 0; var diffQty = comeQty - invQty; if (detailSummary == null) { throw new Exception("此条码找不到对应收货单明细!"); } var mesItems = db.Queryable() .Where(s=>s.Id == itemBarcodeDetails.ItemId).First(); result.Message = $"条码数量 {itemBarcodeDetails.Quantity},采购订单 {itemBarcodeDetails.WorkNo} 项次 {itemBarcodeDetails.WorkLine} 物料 {mesItems.ItemNo} 本次入库总数:{totalCDetailsQuantity} 总到 {comeQty} 已入 {invQty} 欠 {diffQty}"; return 1; } else { // Step 1: Check if bill needs to be closed (status update) var totalSummary = db.Queryable() .LeftJoin((b, a) => a.Guid == b.ParentGuid) .Where((b, a) => a.BillNo == inventory.BillNo && b.ReturnFlag == 0) .Select((b, a) => new { TotalQuantity = SqlFunc.AggregateSum(b.Quantity), TotalOkRkQty = SqlFunc.AggregateSum(b.OkRkqty) }) .First(); if ((totalSummary.TotalQuantity ?? 0) == (totalSummary.TotalOkRkQty ?? 0)) { db.Updateable() .SetColumns(it => it.Status == 1) .Where(it => it.BillNo == itemBarcodeDetails.BillNo) .ExecuteCommand(); } // Step 2: Calculate total sum from `mes_inv_item_in_c_details` var totalCDetailsQuantity = db.Queryable() .Where(it => it.CbillNo == itemBarcodeDetails.BillNo && it.ItemId == itemBarcodeDetails.ItemId) .Sum(it => it.Quantity); // Step 3: Calculate comeQty and invQty from `mes_inv_item_arn_detail` var detailSummary = db.Queryable() .Where(it => it.CbillNo == itemBarcodeDetails.BillNo && it.ItemId == itemBarcodeDetails.ItemId) .Select(it => new { TotalComeQty = SqlFunc.AggregateSum(it.Quantity), TotalInvQty = SqlFunc.AggregateSum(it.OkRkqty) }) .First(); if (detailSummary == null) { throw new Exception("此条码找不到对应收货单明细!"); } var comeQty = detailSummary.TotalComeQty ?? 0; var invQty = detailSummary.TotalInvQty ?? 0; var diffQty = comeQty - invQty; var mesItems = db.Queryable() .Where(s=>s.Id == itemBarcodeDetails.ItemId).First(); // Step 5: Combine final result result.Message = $" 条码数量:{itemBarcodeDetails.Quantity},物料 {mesItems.ItemNo} 本次入库总数:{totalCDetailsQuantity} 总到 {comeQty} 已入 {invQty} 欠 {diffQty}"; } var mesInvItemInCDetails = base.GetSingle(it => it.ItemBarcode == entity.barcode); if (mesInvItemInCDetails == null) throw new Exception("物料入库条码明细不存在"); // 抛出异常以供前台处理 // // var itemInId = mesInvItemInCDetails.ItemInId; // entity.id = itemInId; // entity.PageIndex = 1; // entity.Limit = 1; //var inventory = getPurchaseInventory(entity); // inventory.ItemNo = parts[0]; // inventory.SumQuantity = Convert.ToDecimal(parts[1]); //return inventory; return 1; }); return result; } public MessageCenter MesToErpParam(WarehouseQuery query) { var erpParameters = ""; var title = ""; var tableName = "MES_INV_ITEM_INS_" + query.Type; if ("A".Equals(query.Type)) { erpParameters = GetErpParameters(query.billNo); title = "采购入库单" + query.billNo + "审核"; } else if ("B".Equals(query.Type)) { erpParameters = GetDeApprovePam(query.id); title = "采购入库单" + query.billNo + "反审核"; } var ErpUrl = AppsettingsUtility.Settings.ProductionErpUrl; var message = new MessageCenter { TableName = tableName, Url = ErpUrl, Status = 1, CreateBy = query.userName, Route = query.billNo, Title = title, PageName = "Warehouse/PurchaseInventory/Add?id=" + query.id + "&billNo=" + query.billNo, CreateDate = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), Method = "POST", Seq = 1, Data = erpParameters, IsMessage = 0, ContentType = "application/x-www-form-urlencoded" }; return message; } public MessageCenter SaveMessageCenter(WarehouseQuery query) { var message = MesToErpParam(query); var executeReturnIdentity = Db.Insertable(message).ExecuteReturnIdentity(); if (executeReturnIdentity > 0) { //message.Guid = executeReturnIdentity; message.Pid = executeReturnIdentity; return message; } throw new Exception("获取数据失败"); } //audit public bool audit(WarehouseQuery entity) { entity.date = DateTime.Now; entity.status = 1; return Update(entity); } public bool deApprove(WarehouseQuery entity) { entity.date = null; entity.status = 0; return Update(entity); } private bool Update(WarehouseQuery entity) { return Db.Updateable() .SetColumns(x => x.Status == entity.status) .SetColumns(x => x.InsDate == entity.date) .Where(x => x.BillNo == entity.billNo) .IgnoreColumns(ignoreAllNullColumns: true).ExecuteCommand() > 0; } private string GetErpParameters(string? billNo) { var invItemIns = Db.Queryable() .Single(x => x.BillNo == billNo); if (invItemIns == null) throw new Exception("入库单号不存在"); if (invItemIns.Status == 1) throw new Exception("入库单已审核,不能重复推送"); var materials = Db.Queryable( (g, c, d, a) => new JoinQueryInfos( JoinType.Left, g.ItemNo == c.ItemNo && g.Company == c.Company && g.Factory == c.Factory, JoinType.Inner, d.Id == Convert.ToDecimal(c.ItemUnit), JoinType.Inner, a.Ebeln == g.WorkNo && a.WorkLine == g.EbelnLineNo && g.CbillNo == a.CbillNo ) ).Where((g, c, d, a) => g.BillNo == billNo).Select( (g, c, d, a) => new Material { // FstockId = g.DepotCode, // FuintId = d.Fnumber, // FsrcEntryId = a.Id, // FmesEntryId = g.Id, // FmaterialId = a.ItemNo, // DepotSectionCode = g.DepotSectionCode, // WorkNo = g.WorkNo, // Frealqty = g.Quantity }).ToList(); if (materials == null || materials.Count == 0) throw new Exception("没有找到相关数据"); // 抛出异常以供前台处理 // 构造 JSON var jsonEntries = materials.Select(d => new { // FMaterialId = d.FmaterialId, // FUintId = d.FuintId, // FRealQty = d.Frealqty, // FStockId = d.FstockId, // FSRCENTRYID = d.FsrcEntryId.ToString(), // F_MES_ENTRYID = d.FmesEntryId.ToString() }).ToList(); var fdate = DateTime.Now.ToString("yyyy-MM-dd"); var jsonString = JsonConvert.SerializeObject(jsonEntries); var encodedUrl = "taskname=CGRK&mesid=" + invItemIns.Guid + "&optype=create&datajson={\"F_MES_ID\":\"" + invItemIns.Guid + "\",\"FDate\":\"" + fdate + "\",\"cgrkentry\":" + jsonString + "}"; return encodedUrl; } private string GetDeApprovePam(string? id) { var encodedUrl = "taskname=CGRK&mesid=" + id + "&optype=delete&datajson={}"; return encodedUrl; } }