| | |
| | | using Masuit.Tools; |
| | | using AngleSharp.Dom; |
| | | using Masuit.Tools; |
| | | using MES.Service.DB; |
| | | using MES.Service.Dto.webApi; |
| | | using MES.Service.Modes; |
| | |
| | | using System.Security.AccessControl; |
| | | |
| | | namespace MES.Service.service.BasicData; |
| | | |
| | | /// <summary> |
| | | /// 采购订单 |
| | | /// </summary> |
| | | public class MesRohInManager : Repository<MesRohIn> |
| | | { |
| | | private readonly MesRohInDataManager rohInDataManager = new(); |
| | |
| | | // 插入或更新数据的方法 |
| | | private bool SaveOrUpdateData(SqlSugarScope db, MesRohIn mesRohIn,List<MesRohInData> mesRohInDatas, string type) |
| | | { |
| | | //传什么,c就改成什么 |
| | | //if (type == "3" || (mesRohIn.DocumentStatus != null && mesRohIn.DocumentStatus != "C"))//C表示已审核状态 |
| | | //{ |
| | | // mesRohIn.BillNo = mesRohIn.BillNo + "F" + mesRohIn.EbelnK3id.ToString(); |
| | | //} |
| | | |
| | | if (type == "3" || (mesRohIn.DocumentStatus != null && mesRohIn.DocumentStatus != "C")) |
| | | { |
| | | mesRohIn.BillNo = mesRohIn.BillNo + "F" + mesRohIn.EbelnK3id.ToString(); |
| | | } |
| | | ////传什么,c就改成什么 |
| | | //if (type == "3" || (mesRohIn.DocumentStatus != null && mesRohIn.DocumentStatus != "Y"))//Y表示已审核状态 |
| | | //{ |
| | | // mesRohIn.BillNo = mesRohIn.BillNo + "F" + mesRohIn.EbelnK3id.ToString(); |
| | | //} |
| | | |
| | | if (mesRohIn.Guid != null) |
| | | db.Deleteable<MesRohIn>().Where(s => s.Guid == mesRohIn.Guid) |
| | |
| | | |
| | | mesRohIn.EbelnK3id = eid; |
| | | mesRohIn.BillNo = rohIn.FBillNo; |
| | | mesRohIn.DocumentStatus = rohIn.FDocumentStatus; |
| | | mesRohIn.DocumentType = rohIn.FBillTypeID; |
| | | mesRohIn.BusinessType = rohIn.FBusinessType; |
| | | |
| | | |
| | | ////erp传过来的Y->C,表示审核。N->A。(与金蝶逻辑保持一致) |
| | | //mesRohIn.DocumentStatus = rohIn.FDocumentStatus; |
| | | |
| | | //erp传过来的Y->C,表示审核。N->A。(与金蝶逻辑保持一致) |
| | | if (string.IsNullOrEmpty(rohIn.FDocumentStatus)) |
| | | { |
| | | mesRohIn.DocumentStatus = "A"; |
| | | } |
| | | else |
| | | { |
| | | mesRohIn.DocumentStatus = rohIn.FDocumentStatus == "Y" ? "C" : "A"; |
| | | } |
| | | |
| | | |
| | | |
| | | if (rohIn.FDate != null) |
| | | mesRohIn.PurchaseDate = DateTime.ParseExact(rohIn.FDate, |
| | | "yyyy-MM-dd HH:mm:ss", null); |
| | | |
| | | mesRohIn.Supplier = rohIn.FSupplierId; |
| | | |
| | | |
| | | //供应商编码转ID |
| | | var mesRohInSupplier = Db.Queryable<MesSupplier>() |
| | | .Where(x => x.SuppNo == rohIn.FSupplierId) |
| | | .Select(x => x.Id.ToString()) |
| | | .First(); |
| | | if (!string.IsNullOrWhiteSpace(mesRohInSupplier)) |
| | | { |
| | | mesRohIn.Supplier = mesRohInSupplier; |
| | | } |
| | | else if (!string.IsNullOrWhiteSpace(rohIn.FSupplierId)) |
| | | { |
| | | mesRohIn.Supplier = rohIn.FSupplierId; |
| | | } |
| | | else |
| | | { |
| | | mesRohIn.Supplier = "0"; |
| | | } |
| | | //mesRohIn.Supplier = rohIn.FSupplierId; |
| | | |
| | | mesRohIn.CloseStatus = rohIn.FCloseStatus; |
| | | mesRohIn.PurchaseOrg = rohIn.FPurchaseOrgId; |
| | | mesRohIn.PurchaseDept = rohIn.FPurchaseDeptId; |
| | | //mesRohIn.PurchaseOrg = rohIn.FPurchaseOrgId; |
| | | mesRohIn.PurchaseOrg = string.IsNullOrEmpty(rohIn.FPurchaseOrgId) ? "1" : rohIn.FPurchaseOrgId;//采购组织 |
| | | |
| | | //采购部门编码转ID |
| | | var mesRohInPurchaseDept = Db.Queryable<SysDepartment>() |
| | | .Where(x => x.Departmentcode == rohIn.FPurchaseDeptId) |
| | | .Select(x => x.Departmentid.ToString()) |
| | | .First(); |
| | | if (!string.IsNullOrWhiteSpace(mesRohInPurchaseDept)) |
| | | { |
| | | mesRohIn.PurchaseDept = mesRohInPurchaseDept; |
| | | } |
| | | else |
| | | { |
| | | mesRohIn.PurchaseDept = "0"; |
| | | } |
| | | //mesRohIn.PurchaseDept = rohIn.FPurchaseDeptId; |
| | | |
| | | mesRohIn.PurchaseGroup = rohIn.FPurchaserGroupId; |
| | | mesRohIn.Purchaser = rohIn.FPurchaserId; |
| | | mesRohIn.SettlementParty = rohIn.FSettleId; |
| | |
| | | mesRohIn.FixtureMoldProcurement = rohIn.F_UNW_Combo_zjmj;//治具丶模具加工及采购 |
| | | mesRohIn.urgent_material = rohIn.FUrgent_Material;//急料 |
| | | |
| | | //mesRohIn.DocumentType = rohIn.FBillTypeID; |
| | | mesRohIn.BusinessType = rohIn.FBusinessType;//业务类型 |
| | | mesRohIn.DocumentType = rohIn.FBusinessType;//业务类型 |
| | | |
| | | mesRohIn.MBillNo = $"{rohIn.FBillNo}-{rohIn.FBillTypeID}";//组合单号:组合单号:单号-单别 |
| | | mesRohIn.NumberType= rohIn.FBillTypeID;//单据类型:330:采购单、331:采购补货单、332:手工采购单 |
| | | return mesRohIn; |
| | | } |
| | | |
| | |
| | | ChangeFlag = s.FChangeFlag, |
| | | DemandSource = s.FDEMANDTYPE, |
| | | DemandDocumentId = s.FDEMANDBILLNO, |
| | | DemandDocumentLineId = s.FDEMANDBILLENTRYSEQ, |
| | | DemandOrg = s.FRequireOrgId, |
| | | ReceivingOrg = s.FReceiveOrgId, |
| | | SettlementOrg = s.FEntrySettleOrgId, |
| | | OrderLineId = s.FDEMANDBILLENTRYSEQ, |
| | | //需求组织默认为1 |
| | | DemandOrg = string.IsNullOrEmpty(s.FRequireOrgId) ? "1" : s.FRequireOrgId, |
| | | //DemandOrg = s.FRequireOrgId, |
| | | //收料组织默认为1 |
| | | ReceivingOrg = string.IsNullOrEmpty(s.FEntrySettleOrgId) ? "1" : s.FEntrySettleOrgId, |
| | | //ReceivingOrg = s.FReceiveOrgId, |
| | | //结算组织默认为1 |
| | | SettlementOrg = string.IsNullOrEmpty(s.FEntrySettleOrgId) ? "1" : s.FEntrySettleOrgId, |
| | | //SettlementOrg = s.FEntrySettleOrgId, |
| | | PurchaseOrderLineNumber = s.FSEQ, |
| | | Demand = s.FRequireOrgId, |
| | | Receiving = s.FReceiveOrgId, |
| | |
| | | Remark5 = s.FUrgent_Material, //急料 |
| | | SalesOrderId = s.F_UNW_Text_xsddh |
| | | }; |
| | | |
| | | //库存单位编码转ID |
| | | //InventoryUnit = s.FStockUnitID, |
| | | var entityInventoryUnit = Db.Queryable<MesUnit>() |
| | | .Where(x => x.Fnumber == s.FUnitId) |
| | | .Select(x => x.Id.ToString()) |
| | | .First(); |
| | | if (!string.IsNullOrWhiteSpace(entityInventoryUnit)) |
| | | { |
| | | entity.InventoryUnit = entityInventoryUnit; |
| | | } |
| | | else |
| | | { |
| | | entity.InventoryUnit = "0"; |
| | | } |
| | | |
| | | //采购单位编码转ID |
| | | var entityPurchaseUnit = Db.Queryable<MesUnit>() |
| | | .Where(x => x.Fnumber == s.FUnitId) |
| | | .Select(x => x.Id.ToString()) |
| | | .First(); |
| | | if (!string.IsNullOrWhiteSpace(entityPurchaseUnit)) |
| | | { |
| | | entity.PurchaseUnit = entityPurchaseUnit; |
| | | } |
| | | else |
| | | { |
| | | entity.PurchaseUnit = "0"; |
| | | } |
| | | |
| | | //计价单位编码转ID |
| | | var entityPricingUnit = Db.Queryable<MesUnit>() |
| | | .Where(x => x.Fnumber == s.FPriceUnitId) |
| | | .Select(x => x.Id.ToString()) |
| | | .First(); |
| | | if (!string.IsNullOrWhiteSpace(entityPricingUnit)) |
| | | { |
| | | entity.PricingUnit = entityPricingUnit; |
| | | } |
| | | else |
| | | { |
| | | entity.PricingUnit = "0"; |
| | | } |
| | | |
| | | //物料编码转ID |
| | | var entityItemId = Db.Queryable<MesItems>() |
| | | .Where(x => x.ItemNo == s.FMaterialId) |
| | | .Select(x => x.Id.ToString()) |
| | | .First(); |
| | | if (!string.IsNullOrWhiteSpace(entityItemId)) |
| | | { |
| | | entity.ItemId = entityItemId; |
| | | } |
| | | else |
| | | { |
| | | entity.ItemId = "0"; |
| | | } |
| | | |
| | | if (s.FFreezeDate != null) |
| | | if (!s.FFreezerId.IsNullOrEmpty()) |
| | |
| | | } |
| | | |
| | | //查询EbelnK3id对应的Guid,赋值给entity.Guid。实现主键复用 |
| | | var single = rohInDataManager.GetSingle(it =>it.EbelnK3id == entity.EbelnK3id); |
| | | var single = rohInDataManager.GetSingle(it => it.EbelnK3id == entity.EbelnK3id); |
| | | if (single != null) entity.Guid = single.Guid; |
| | | |
| | | return entity; |
| | | }).ToList(); |
| | | } |
| | | |
| | | ///// <summary> |
| | | ///// 生成新的主表ID,确保不重复 |
| | | ///// </summary> |
| | | //private decimal GenerateNewId() |
| | | //{ |
| | | // // 处理空表的情况,从1开始 |
| | | // var maxId = Db.Queryable<MesRohIn>().Max(x => (decimal?)x.EbelnK3id) ?? 0; |
| | | // var newId = maxId + 1; |
| | | |
| | | // // 双重检查,确保生成的ID不存在 |
| | | // while (Db.Queryable<MesRohIn>().Where(x => x.EbelnK3id == newId).Any()) |
| | | // { |
| | | // newId++; |
| | | // } |
| | | |
| | | // return newId; |
| | | //} |
| | | |
| | | /// <summary> |
| | | /// 生成新的主表ID,确保不重复 |
| | | /// 生成新的主表ID,通过数据库序列获取唯一ID |
| | | /// </summary> |
| | | private decimal GenerateNewId() |
| | | { |
| | | // 处理空表的情况,从1开始 |
| | | var maxId = Db.Queryable<MesRohIn>().Max(x => (decimal?)x.EbelnK3id) ?? 0; |
| | | var newId = maxId + 1; |
| | | |
| | | // 双重检查,确保生成的ID不存在 |
| | | while (Db.Queryable<MesRohIn>().Where(x => x.EbelnK3id == newId).Any()) |
| | | try |
| | | { |
| | | newId++; |
| | | } |
| | | // 替换为: |
| | | var sequenceValueObj = Db.Ado.GetScalar("SELECT NEXT VALUE FOR MES_ROH_IN_seq"); |
| | | var sequenceValue = Convert.ToDecimal(sequenceValueObj); |
| | | // 验证序列值是否有效 |
| | | if (sequenceValue <= 0) |
| | | { |
| | | throw new InvalidOperationException($"数据库序列 MES_ROH_IN_seq 返回了无效的值: {sequenceValue}"); |
| | | } |
| | | |
| | | return newId; |
| | | return sequenceValue; |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | // 记录异常信息 |
| | | Console.WriteLine($"调用数据库序列 MES_ROH_IN_seq 失败: {ex.Message}"); |
| | | |
| | | // 向上层抛出明确的异常信息 |
| | | throw new InvalidOperationException($"生成子表ID失败,无法获取数据库序列值: {ex.Message}", ex); |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | |
| | | { |
| | | try |
| | | { |
| | | // 替换为: |
| | | // 获取当前表中已存在的最大 EBELN_K3ID |
| | | //var maxId = Db.Queryable<MesRohInData>().Max(x => (decimal?)x.EbelnK3id) ?? 0m; |
| | | |
| | | // 先取一个序列值 |
| | | var sequenceValueObj = Db.Ado.GetScalar("SELECT NEXT VALUE FOR MES_ROH_IN_DATA_seq"); |
| | | var sequenceValue = Convert.ToDecimal(sequenceValueObj); |
| | | // 验证序列值是否有效 |
| | | |
| | | if (sequenceValue <= 0) |
| | | { |
| | | throw new InvalidOperationException($"数据库序列 MES_ROH_IN_DATA_seq 返回了无效的值: {sequenceValue}"); |
| | | } |
| | | |
| | | //// 如果序列值落后于当前最大ID,持续获取直到超过 maxId |
| | | //while (sequenceValue <= maxId || Db.Queryable<MesRohInData>().Where(x => x.EbelnK3id == sequenceValue).Any()) |
| | | //{ |
| | | // sequenceValueObj = Db.Ado.GetScalar("SELECT NEXT VALUE FOR MES_ROH_IN_DATA_seq"); |
| | | // sequenceValue = Convert.ToDecimal(sequenceValueObj); |
| | | |
| | | // if (sequenceValue <= 0) |
| | | // { |
| | | // throw new InvalidOperationException($"数据库序列 MES_ROH_IN_DATA_seq 连续返回无效的值: {sequenceValue}"); |
| | | // } |
| | | //} |
| | | |
| | | return sequenceValue; |
| | | } |
| | |
| | | /// <returns>被删除的单号</returns> |
| | | public (int outSum, string outMsg) Delete(string FBillNo, string FBillTypeID) |
| | | { |
| | | try |
| | | { |
| | | var outMsg = string.Empty; |
| | | var outSum = 0; |
| | | |
| | |
| | | Db.Ado.UseStoredProcedure().ExecuteCommand("ERP_DeleteMesRohInByBillNo", parameters); |
| | | |
| | | outMsg = parameters[2].Value?.ToString() ?? ""; |
| | | outSum = parameters[3].Value != null ? Convert.ToInt32(parameters[2].Value) : -1; |
| | | |
| | | return (outSum, outMsg); |
| | | outSum = parameters[3].Value != null ? Convert.ToInt32(parameters[index: 3].Value) : -1; |
| | | return (outSum, outMsg); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | throw new InvalidOperationException($"调用存储过程 ERP_DeleteMesRohInByBillNo 失败: {ex.Message}", ex); |
| | | } |
| | | } |
| | | |
| | | |