| MES.Service/Dto/webApi/ErpCAA.cs | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
| MES.Service/Dto/webApi/ErpCAB.cs | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
| MES.Service/Dto/webApi/ErpRohIn.cs | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
| MES.Service/Dto/webApi/ErpRohinData.cs | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
| MES.Service/service/BasicData/MesRohInManager.cs | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
| MES.Service/service/WomcaaManager.cs | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
| MESApplication/Controllers/BasicData/MesRohInController.cs | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 |
MES.Service/Dto/webApi/ErpCAA.cs
@@ -2,11 +2,11 @@ public class ErpCAA { public string Id { get; set; } public string? Id { get; set; } public string? Type { get; set; } public string? FBILLTYPE { get; set; } public string? FBillNo { get; set; } public string FBillNo { get; set; }//工单单号 public string? FWorkShopID { get; set; } public string? FRoutingId { get; set; } public string? FREMWorkShopId { get; set; } @@ -29,7 +29,7 @@ public string? FLot { get; set; } public string? FBomId { get; set; } public string? FCreateType { get; set; } public string? FSrcBillType { get; set; } public string FSrcBillType { get; set; }//工单单别 public string? FSrcBillNo { get; set; } public string? FSrcBillEntrySeq { get; set; } public string? FSaleOrderNo { get; set; } @@ -37,7 +37,7 @@ public string? FForceCloserId { get; set; } public string? FCloseType { get; set; } public string? FSrcSplitBillNo { get; set; } public string? FDESCRIPTION { get; set; } public string? FMemoItem { get; set; }//备注 public string? PLAN_ID { get; set; } public string? PLAN_SEQ { get; set; } public string? PLAN_NUM { get; set; } @@ -48,4 +48,17 @@ public string? TypeA { get; set; } public string? FDocumentStatus { get; set; } public string? FWorkShopID0 { get; set; }//工作中心 public string? F_UNW_Text_xsddh { get; set; }//订单单号 public string? xsddh_type { get; set; }//订单单别 //表里没有 public string? FCustno { get; set; }//客户单号--订单单头表 public string? FCustitemno { get; set; }//客户品号--订单单身表 public string? DemandDate { get; set; }//需求日期 public string? CustNumber { get; set; }//客户编号 public string? ModelType { get; set; }//机型 public string? FSuppno { get; set; }//委外供应商 } MES.Service/Dto/webApi/ErpCAB.cs
@@ -2,8 +2,8 @@ public class ErpCAB { public string? FBillNo { get; set; } public string? FMaterialID { get; set; } public string FBillNo { get; set; }//工单单号 public string FMaterialID2 { get; set; }//材料品号 public string? FNeedQty { get; set; } public string? FPickedQty { get; set; } public string? FPositionNO { get; set; } @@ -22,7 +22,7 @@ public string? FDenominator { get; set; } public string? PID { get; set; } public string Id { get; set; } public string? Id { get; set; } public string? FSeq { get; set; } @@ -38,4 +38,7 @@ public string? TypeB { get; set; } public string? F_UNW_QTY_YFSL { get; set; } public string? F_UNW_Text_tpgy { get; set; }//工艺 public string FBillNoType { get; set; }//单别 } MES.Service/Dto/webApi/ErpRohIn.cs
@@ -6,7 +6,7 @@ public string? Type { get; set; } public string FBillNo { get; set; }//采购单号 public string? FDocumentStatus { get; set; } public string? FBillTypeID { get; set; }//单据类型 public string FBillTypeID { get; set; }//单据类型 public string? FBusinessType { get; set; } public string? FDate { get; set; } public string? FSupplierId { get; set; } MES.Service/Dto/webApi/ErpRohinData.cs
@@ -43,7 +43,7 @@ public string? FStockInQty { get; set; } //累计入库数 public string? FCHECKRETQTY { get; set; } //收料可退数 public string? FSTOCKRETQTY { get; set; } //库存可退数 public string? FBillTypeID { get; set; }//采购单别 public string FBillTypeID { get; set; }//采购单别 public string? FSrcBillNo { get; set; } public string? FReqTraceNo { get; set; } public string? FMtoNo { get; set; } @@ -51,7 +51,7 @@ public string? FDEMANDTYPE { get; set; } public string? FDEMANDBILLENTRYSEQ { get; set; }// 采购订单行号 public string FDEMANDBILLENTRYSEQ { get; set; }// 采购订单行号 public string? FUrgent_Material { get; set; }//急料 public string? DELIVERY_DATE { get; set; }//交货日期 MES.Service/service/BasicData/MesRohInManager.cs
@@ -1,4 +1,5 @@ using Masuit.Tools; using AngleSharp.Dom; using Masuit.Tools; using MES.Service.DB; using MES.Service.Dto.webApi; using MES.Service.Modes; @@ -70,17 +71,17 @@ // 插入或更新数据的方法 private bool SaveOrUpdateData(SqlSugarScope db, MesRohIn mesRohIn,List<MesRohInData> mesRohInDatas, string type) { ////传什么,c就改成什么 //传什么,c就改成什么 //if (type == "3" || (mesRohIn.DocumentStatus != null && mesRohIn.DocumentStatus != "C"))//C表示已审核状态 //{ // mesRohIn.BillNo = mesRohIn.BillNo + "F" + mesRohIn.EbelnK3id.ToString(); //} //传什么,c就改成什么 if (type == "3" || (mesRohIn.DocumentStatus != null && mesRohIn.DocumentStatus != "Y"))//Y表示已审核状态 { mesRohIn.BillNo = mesRohIn.BillNo + "Y" + 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) @@ -138,13 +139,31 @@ 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); //供应商编码转ID var mesRohInSupplier = Db.Queryable<MesSupplier>() @@ -177,10 +196,6 @@ if (!string.IsNullOrWhiteSpace(mesRohInPurchaseDept)) { mesRohIn.PurchaseDept = mesRohInPurchaseDept; } else if (!string.IsNullOrWhiteSpace(rohIn.FPurchaseDeptId)) { mesRohIn.PurchaseDept = rohIn.FPurchaseDeptId; } else { @@ -330,6 +345,21 @@ 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) @@ -338,10 +368,6 @@ if (!string.IsNullOrWhiteSpace(entityPurchaseUnit)) { entity.PurchaseUnit = entityPurchaseUnit; } else if (!string.IsNullOrWhiteSpace(s.FUnitId)) { entity.PurchaseUnit = s.FUnitId; } else { @@ -357,10 +383,6 @@ { entity.PricingUnit = entityPricingUnit; } else if (!string.IsNullOrWhiteSpace(s.FPriceUnitId)) { entity.PricingUnit = s.FPriceUnitId; } else { entity.PricingUnit = "0"; @@ -374,10 +396,6 @@ if (!string.IsNullOrWhiteSpace(entityItemId)) { entity.ItemId = entityItemId; } else if (!string.IsNullOrWhiteSpace(s.FMaterialId)) { entity.ItemId = s.FMaterialId; } else { @@ -414,7 +432,7 @@ } //查询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; @@ -446,14 +464,29 @@ { 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; } @@ -474,6 +507,8 @@ /// <returns>被删除的单号</returns> public (int outSum, string outMsg) Delete(string FBillNo, string FBillTypeID) { try { var outMsg = string.Empty; var outSum = 0; @@ -488,9 +523,13 @@ 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); } } MES.Service/service/WomcaaManager.cs
@@ -65,10 +65,30 @@ if (StringUtil.CheckGuid(mesWomcaa.Guid)) base.DeleteById(mesWomcaa.Guid); //if (mesWomcabs.Count > 0) // db.Deleteable<Womcab>() // .Where(s => s.Pid == mesWomcaa.Erpid).ExecuteCommand(); // 在插入 mesWomcabs 之前,先删除所有 Guid 已存在的记录 //var guids = mesWomcabs.Select(x => x.Guid).ToList(); //if (guids.Count > 0) //{ // db.Deleteable<Womcab>().In(x => x.Guid, guids).ExecuteCommand(); //} if (mesWomcabs.Count > 0) { // 先按 Pid 删除 db.Deleteable<Womcab>() .Where(s => s.Pid == mesWomcaa.Erpid).ExecuteCommand(); // // 再按 Guid 删除,彻底避免主键冲突 // var guids = mesWomcabs.Select(x => x.Guid).ToList(); // db.Deleteable<Womcab>().In(x => x.Guid, guids).ExecuteCommand(); } //// 检查 Guid 是否唯一 //if (mesWomcabs.Select(x => x.Guid).Distinct().Count() != mesWomcabs.Count) // throw new Exception("即将插入的Womcab数据中存在重复的Guid,请检查数据生成逻辑。"); //单条插入忽略空字段 var orUpdate = db.Insertable(mesWomcaa) @@ -119,12 +139,17 @@ var entity = new Womcaa { Erpid = Convert.ToInt32(dto.Id), /// ERPID Caa001 = PPBOMNO, /// 单号 Caa021 = dto.FWorkShopID, /// 工作车间 SrcBillType = dto.FSrcBillType, /// 工单单别 Caa001=dto.FBillNo, /// 工单单号 //Caa001 = PPBOMNO, /// 单号 Caa021 = dto.FWorkShopID0, /// 工作中心 //Caa021 = dto.FWorkShopID, /// 工作车间 RoutingId = dto.FRoutingId, /// 工艺路线 WorkShopId = dto.FREMWorkShopId, /// 产线 DepotCode = dto.FStockId, /// 仓库 CreateDate = dto.FDate, /// 单据日期 Caa004 = dto.FBILLTYPE, /// 单据类型 Caa023 = dto.FStatus, /// 状态 完工,未完工 Caa006 = dto.FMaterialId, /// 产品编码 @@ -144,17 +169,9 @@ Mtono = dto.FMTONO, /// 计划跟踪号 Lot = dto.FLot, /// 批号 Caa013 = dto.FBomId, /// BOM版次 Caa015 = dto.F_UNW_Text_xsddh, /// 订单单号 Caa015Head = dto.xsddh_type, /// 订单单别 CreateType = dto.FCreateType, /// 生成方式 SrcBillType = dto.FSrcBillType, /// 源单类型 SrcBillNo = dto.FSrcBillNo, /// 源单编号 SrcBillentryseq = dto.FSrcBillEntrySeq, /// 源单分录行号 SaleOrderNo = dto.FSaleOrderNo, /// 需求单据号 SaleOrderEntryseq = dto.FSaleOrderEntrySeq, /// 需求单据行号 ForceCloserid = dto.FForceCloserId, /// 结案人 CloseType = dto.FCloseType, /// 结案类型 SrcSplitBillno = dto.FSrcSplitBillNo, /// 源拆分订单编号 Caa016 = dto.FDESCRIPTION, /// 备注 Caa018 = !string.IsNullOrEmpty(dto.PLAN_ID) ? Convert.ToInt32(dto.PLAN_ID) @@ -163,11 +180,23 @@ ? Convert.ToInt32(dto.PLAN_SEQ) : null, /// ERP源单行号 Caa020 = dto.PLAN_NUM, /// ERP源单单号(任务单号) //Caa015 = dto.F_UNW_Text_xsddh, /// 销售订单号 ForceCloserid = dto.FForceCloserId, /// 结案人 CloseType = dto.FCloseType, /// 结案类型 SrcSplitBillno = dto.FSrcSplitBillNo, /// 源拆分订单编号 Caa016 = dto.FMemoItem, /// 备注 SrcBillNo = dto.FSrcBillNo, /// 源单编号 SrcBillentryseq = dto.FSrcBillEntrySeq, /// 源单分录行号 SaleOrderNo = dto.FSaleOrderNo, /// 需求单据号 SaleOrderEntryseq = dto.FSaleOrderEntrySeq, /// 需求单据行号 ErpSczz = Convert.ToInt32(dto.FPrdOrgId), /// 生产组织ID ErpWtzz = Convert.ToInt32(dto.FEnTrustOrgId), /// 委托组织ID Btbz = dto.Btbz, /// 委托组织ID //Caa015Head = dto.F_XIFG_Integer_tzk, /// 销售订单行号 //MainProductNo = dto.F_XIFG_Base_w5c, /// 主产品编码 // MainProductQty = // Convert.ToInt32(dto.F_XIFG_Qty_yrr), /// 主产品生产数量 @@ -175,12 +204,31 @@ // PackingListNumber = dto.F_XIFG_Text_yrr, /// 包装单号 // CustomerName = dto.F_XIFG_Text_qtr1, /// 客户名称 // Customer = dto.F_XIFG_Base_83g1, /// 客户 Caa0111 = dto.FPlanFinishDate, /// 预计完工时间备份 Typea = dto.TypeA, /// 预计完工时间备份 //Caa0111 = dto.FPlanFinishDate, /// 预计完工时间备份 //Typea = dto.TypeA, /// 预计完工时间备份 //Typeb = dto.TypeB /// 预计完工时间备份 SynchronousDate = DateTime.Now, DocumentStatus = dto.FDocumentStatus }; //根据单号+单别,获取对应的id var singleId = Db.Queryable<Womcaa>() .Where(x => x.SrcBillType == dto.FSrcBillType && x.Caa001 == dto.FBillNo) .Select(x => x.Erpid) .First(); //如果没有则生成一个新的id if (singleId == null || string.IsNullOrWhiteSpace(singleId.ToString())) { entity.Erpid = (int)GenerateNewId(); //entity.Erpid = GenerateNewId().ToString(); //rohIn.id = GenerateNewId().ToString("0"); } else//如果有则使用已有的id { entity.Erpid = Convert.ToInt32(singleId); //entity.Erpid = singleId.ToString(); } var single = base.GetSingle(it => it.Erpid == entity.Erpid); if (single != null) entity.Guid = single.Guid; @@ -198,8 +246,9 @@ { Erpid = Convert.ToInt32(dto.Id), /// ERPID Cab001 = dto.FBillNo, /// 工单单号 Cab002 = Convert.ToInt32(dto.FSeq), /// 序号 Cab003 = dto.FMaterialID, /// 材料编码 //Cab002 = Convert.ToInt32(dto.FSeq), /// 序号 Cab002 = Convert.ToInt32(dto.FBillNoType), /// 序号 Cab003 = dto.FMaterialID2, /// 材料编码 Cab006 = !string.IsNullOrEmpty(dto.FNeedQty) ? Convert.ToDecimal(dto.FNeedQty) : null, /// 需领用量 @@ -214,7 +263,7 @@ Lot = dto.FLot, /// 批号 DepotCode = dto.FStockID, /// 仓库 IssueType = dto.FIssueType, /// 发料方式 // Cab008 = dto.F_UNW_Text_tpgy, /// 工艺 Cab008 = dto.F_UNW_Text_tpgy, /// 工艺 Cab009 = dto.FUnitID, /// 单位 SupplyType = dto.FSupplyType, /// 供应类型(C采购 Z自制 W委外) Cab012 = !string.IsNullOrEmpty(dto.FStdQty) @@ -244,13 +293,80 @@ // ParentItemName = dto.F_XIFG_Base_apv /// 父项物料名称 }; //根据单号+单别+材料品号,获取对应的id var singleId = Db.Queryable<Womcab>() .Where(x => x.Cab001 == dto.FBillNo && x.Cab003 == dto.FMaterialID2 && x.Cab002 == Convert.ToInt32(dto.FBillNoType)) .Select(x => x.Erpid) .First(); if (singleId == null)//如果没有则生成一个新的id { //entity.EbelnK3id = GenerateNewId2().ToString(); womcab.Erpid = (int)GenerateNewId2(); } else//如果有则使用已有的id { //entity.EbelnK3id = singleId.EbelnK3id; womcab.Erpid = singleId; } var entity = Db.Queryable<Womcab>() .Where(s => s.Eid == womcab.Eid).Single(); if (entity != null) womcab.Guid = entity.Guid; .Where(s => s.Cab001 == womcab.Cab001 && s.Cab002 == womcab.Cab002 && s.Cab003 == womcab.Cab003) .Single(); if (entity != null) womcab.Guid = entity.Guid; else womcab.Guid = Guid.NewGuid(); // 确保每条新数据唯一 womcabList.Add(womcab); } return womcabList; } /// <summary> /// 生成新的主表ID,确保不重复 /// </summary> private decimal GenerateNewId() { // 处理空表的情况,从1开始 var maxId = Db.Queryable<Womcaa>().Max(x => (decimal?)x.Erpid) ?? 0; var newId = maxId + 1; // 双重检查,确保生成的ID不存在 while (Db.Queryable<Womcaa>().Where(x => x.Erpid == newId).Any()) { newId++; } return newId; } /// <summary> /// 生成新的子表ID,通过数据库序列获取唯一ID /// </summary> private decimal GenerateNewId2() { try { // 替换为: var sequenceValueObj = Db.Ado.GetScalar("SELECT NEXT VALUE FOR MES_WOMCAB_IN_DATA_seq"); var sequenceValue = Convert.ToDecimal(sequenceValueObj); // 验证序列值是否有效 if (sequenceValue <= 0) { throw new InvalidOperationException($"数据库序列 MES_WOMCAB_IN_DATA_seq 返回了无效的值: {sequenceValue}"); } return sequenceValue; } catch (Exception ex) { // 记录异常信息 Console.WriteLine($"调用数据库序列 MES_WOMCAB_IN_DATA_seq 失败: {ex.Message}"); // 向上层抛出明确的异常信息 throw new InvalidOperationException($"生成子表ID失败,无法获取数据库序列值: {ex.Message}", ex); } } } MESApplication/Controllers/BasicData/MesRohInController.cs
@@ -263,6 +263,13 @@ [HttpPost("Delete")] public ResponseResult Delete([FromBody] DeleteRequestDto data) { var entity = new MessageCenter(); entity.TableName = TableName; entity.Url = URL + "Delete"; entity.Method = METHOD; entity.Data = JsonConvert.SerializeObject(data); entity.Status = 1; entity.CreateBy = "PL017"; try { dynamic resultInfos = new ExpandoObject(); @@ -270,14 +277,30 @@ var (outSum, outMsg) = m.Delete(data.FBillNo,data.FBillTypeID); resultInfos.OutSum = outSum; resultInfos.OutMsg = outMsg; entity.Result = 0; if (resultInfos.OutSum==1) entity.Result = 1; entity.DealWith = 1; _manager.save(entity); return new ResponseResult { status = outSum, //status = outSum, status = 0, message = outMsg, }; } catch (Exception ex) { entity.Result = 0; entity.DealWith = 0; entity.ResultData = ex.Message; _manager.save(entity); return ResponseResult.ResponseError(ex); } }