| | |
| | | using MES.Service.Modes; |
| | | using MES.Service.util; |
| | | using SqlSugar; |
| | | using System.Data; |
| | | |
| | | namespace MES.Service.service; |
| | | |
| | | /// <summary> |
| | | /// 生产订单 |
| | | /// </summary> |
| | | public class WomcaaManager : Repository<Womcaa> |
| | | { |
| | | //当前类已经继承了 Repository 增、删、查、改的方法 |
| | |
| | | SrcBillentryseq = dto.FSrcBillEntrySeq, /// 源单分录行号 |
| | | SaleOrderNo = dto.FSaleOrderNo, /// 需求单据号 |
| | | SaleOrderEntryseq = dto.FSaleOrderEntrySeq, /// 需求单据行号 |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | CustNumber = dto.CustNumber, /// 客户编号 |
| | | ErpSczz = Convert.ToInt32(dto.FPrdOrgId), /// 生产组织ID |
| | | ErpWtzz = Convert.ToInt32(dto.FEnTrustOrgId), /// 委托组织ID |
| | | Btbz = dto.Btbz, /// 委托组织ID |
| | |
| | | SynchronousDate = DateTime.Now, |
| | | DocumentStatus = dto.FDocumentStatus |
| | | }; |
| | | |
| | | //工作中心编码转ID,Caa021 = dto.FWorkShopID0 |
| | | var entityCaa021 = Db.Queryable<SysDepartment>() |
| | | .Where(x => x.Departmentcode == dto.FWorkShopID0) |
| | | .Select(x => x.Id.ToString()) |
| | | .First(); |
| | | if (!string.IsNullOrWhiteSpace(entityCaa021)) |
| | | { |
| | | entity.Caa021 = entityCaa021; |
| | | } |
| | | else |
| | | { |
| | | entity.Caa021 = "0"; |
| | | } |
| | | |
| | | //仓库编码转ID,DepotCode = dto.FStockId, |
| | | var entityDepotCode = Db.Queryable<MesDepots>() |
| | | .Where(x => x.DepotCode == dto.FStockId) |
| | | .Select(x => x.DepotId.ToString()) |
| | | .First(); |
| | | if (!string.IsNullOrWhiteSpace(entityDepotCode)) |
| | | { |
| | | entity.DepotCode = entityDepotCode; |
| | | } |
| | | else |
| | | { |
| | | entity.DepotCode = "0"; |
| | | } |
| | | |
| | | //产品(物料)编码转ID,Caa006 = dto.FMaterialId, /// |
| | | var entityCaa006 = Db.Queryable<MesItems>() |
| | | .Where(x => x.ItemNo == dto.FMaterialId) |
| | | .Select(x => x.Id.ToString()) |
| | | .First(); |
| | | if (!string.IsNullOrWhiteSpace(entityCaa006)) |
| | | { |
| | | entity.Caa006 = entityCaa006; |
| | | } |
| | | else |
| | | { |
| | | entity.Caa006 = "0"; |
| | | } |
| | | |
| | | //单位编码转ID,Caa009 = dto.FUnitId, |
| | | var entityCaa009 = Db.Queryable<MesUnit>() |
| | | .Where(x => x.Fnumber == dto.FUnitId) |
| | | .Select(x => x.Id.ToString()) |
| | | .First(); |
| | | if (!string.IsNullOrWhiteSpace(entityCaa009)) |
| | | { |
| | | entity.Caa009 = entityCaa009; |
| | | } |
| | | else |
| | | { |
| | | entity.Caa009 = "0"; |
| | | } |
| | | |
| | | //计划员编码转ID,PlanId = dto.FPlannerID, |
| | | var entityPlanId = Db.Queryable<MesStaff>() |
| | | .Where(x => x.StaffNo == dto.FPlannerID) |
| | | .Select(x => x.Id.ToString()) |
| | | .First(); |
| | | if (!string.IsNullOrWhiteSpace(entityPlanId)) |
| | | { |
| | | entity.PlanId = entityPlanId; |
| | | } |
| | | else |
| | | { |
| | | entity.PlanId = "0"; |
| | | } |
| | | |
| | | //结案人编码转ID,ForceCloserid = dto.FForceCloserId, |
| | | var entityForceCloserid = Db.Queryable<MesStaff>() |
| | | .Where(x => x.StaffNo == dto.FForceCloserId) |
| | | .Select(x => x.Id.ToString()) |
| | | .First(); |
| | | if (!string.IsNullOrWhiteSpace(entityForceCloserid)) |
| | | { |
| | | entity.ForceCloserid = entityForceCloserid; |
| | | } |
| | | else |
| | | { |
| | | entity.ForceCloserid = "0"; |
| | | } |
| | | |
| | | //客户编码转ID,CustNumber = dto.CustNumber, |
| | | var entityCustNumber = Db.Queryable<MesStaff>() |
| | | .Where(x => x.StaffNo == dto.CustNumber) |
| | | .Select(x => x.Id.ToString()) |
| | | .First(); |
| | | if (!string.IsNullOrWhiteSpace(entityCustNumber)) |
| | | { |
| | | entity.CustNumber = entityCustNumber; |
| | | } |
| | | else |
| | | { |
| | | entity.CustNumber = "0"; |
| | | } |
| | | |
| | | //根据单号+单别,获取对应的id |
| | | var singleId = Db.Queryable<Womcaa>() |
| | |
| | | // ParentItemName = dto.F_XIFG_Base_apv /// 父项物料名称 |
| | | }; |
| | | |
| | | //仓库编码转ID,DepotCode = dto.FStockID, |
| | | var entityDepotCode = Db.Queryable<MesDepots>() |
| | | .Where(x => x.DepotCode == dto.FStockID) |
| | | .Select(x => x.DepotId.ToString()) |
| | | .First(); |
| | | if (!string.IsNullOrWhiteSpace(entityDepotCode)) |
| | | { |
| | | womcab.DepotCode = entityDepotCode; |
| | | } |
| | | else |
| | | { |
| | | womcab.DepotCode = "0"; |
| | | } |
| | | |
| | | //单位编码转ID,Cab009 = dto.FUnitID, |
| | | var entityCab009 = Db.Queryable<MesUnit>() |
| | | .Where(x => x.Fnumber == dto.FUnitID) |
| | | .Select(x => x.Id.ToString()) |
| | | .First(); |
| | | if (!string.IsNullOrWhiteSpace(entityCab009)) |
| | | { |
| | | womcab.Cab009 = entityCab009; |
| | | } |
| | | else |
| | | { |
| | | womcab.Cab009 = "0"; |
| | | } |
| | | |
| | | //根据单号+单别+材料品号,获取对应的id |
| | | var singleId = Db.Queryable<Womcab>() |
| | | .Where(x => x.Cab001 == dto.FBillNo && x.Cab003 == dto.FMaterialID2 && x.Cab002 == Convert.ToInt32(dto.FBillNoType)) |
| | |
| | | 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 |
| | | ///// 生成新的主表ID,确保不重复 |
| | | ///// </summary> |
| | | //private decimal GenerateNewId() |
| | | //{ |
| | | // try |
| | | // { |
| | | // // 替换为: |
| | | // var sequenceValueObj = Db.Ado.GetScalar("SELECT NEXT VALUE FOR MES_WOMCAB_IN_seq"); |
| | | // var sequenceValue = Convert.ToDecimal(sequenceValueObj); |
| | | // // 验证序列值是否有效 |
| | | // if (sequenceValue <= 0) |
| | | // { |
| | | // throw new InvalidOperationException($"数据库序列 MES_WOMCAB_IN_seq 返回了无效的值: {sequenceValue}"); |
| | | // } |
| | | // // 处理空表的情况,从1开始 |
| | | // var maxId = Db.Queryable<Womcaa>().Max(x => (decimal?)x.Erpid) ?? 0; |
| | | // var newId = maxId + 1; |
| | | |
| | | // return sequenceValue; |
| | | // } |
| | | // catch (Exception ex) |
| | | // // 双重检查,确保生成的ID不存在 |
| | | // while (Db.Queryable<Womcaa>().Where(x => x.Erpid == newId).Any()) |
| | | // { |
| | | // // 记录异常信息 |
| | | // Console.WriteLine($"调用数据库序列 MES_WOMCAB_IN_seq 失败: {ex.Message}"); |
| | | |
| | | // // 向上层抛出明确的异常信息 |
| | | // throw new InvalidOperationException($"生成子表ID失败,无法获取数据库序列值: {ex.Message}", ex); |
| | | // newId++; |
| | | // } |
| | | |
| | | // return newId; |
| | | //} |
| | | |
| | | /// <summary> |
| | | /// 生成新的主表ID,通过数据库序列获取唯一ID |
| | | /// </summary> |
| | | private decimal GenerateNewId() |
| | | { |
| | | try |
| | | { |
| | | // 替换为: |
| | | var sequenceValueObj = Db.Ado.GetScalar("SELECT NEXT VALUE FOR MES_WOMCAB_IN_seq"); |
| | | var sequenceValue = Convert.ToDecimal(sequenceValueObj); |
| | | // 验证序列值是否有效 |
| | | if (sequenceValue <= 0) |
| | | { |
| | | throw new InvalidOperationException($"数据库序列 MES_WOMCAB_IN_seq 返回了无效的值: {sequenceValue}"); |
| | | } |
| | | |
| | | return sequenceValue; |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | // 记录异常信息 |
| | | Console.WriteLine($"调用数据库序列 MES_WOMCAB_IN_seq 失败: {ex.Message}"); |
| | | |
| | | // 向上层抛出明确的异常信息 |
| | | throw new InvalidOperationException($"生成子表ID失败,无法获取数据库序列值: {ex.Message}", ex); |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 生成新的子表ID,通过数据库序列获取唯一ID |
| | |
| | | throw new InvalidOperationException($"生成子表ID失败,无法获取数据库序列值: {ex.Message}", ex); |
| | | } |
| | | } |
| | | //唯一键组合:主表就是工单单别+工单单号,子表是工单单号+工单单号+材料品号 |
| | | |
| | | /// <summary> |
| | | /// 整单删除,调用存储过程 |
| | | /// </summary> |
| | | /// <param name="billNo">单号</param> |
| | | /// <returns>被删除的单号</returns> |
| | | public (int outSum, string outMsg) Delete(string FBillNo, string FBillTypeID) |
| | | { |
| | | try |
| | | { |
| | | var outMsg = string.Empty; |
| | | var outSum = 0; |
| | | |
| | | var parameters = new List<SugarParameter> |
| | | { |
| | | new SugarParameter("@FBillNo", FBillNo), |
| | | new SugarParameter("@FBillTypeID", FBillTypeID), |
| | | new SugarParameter("@outMsg", outMsg, typeof(string), ParameterDirection.Output, 2500), |
| | | new SugarParameter("@outSum", outSum, typeof(int), ParameterDirection.Output) |
| | | }; |
| | | |
| | | Db.Ado.UseStoredProcedure().ExecuteCommand("ERP_DeleteWomcaaByBillNo", parameters); |
| | | |
| | | outMsg = parameters[2].Value?.ToString() ?? ""; |
| | | outSum = parameters[3].Value != null ? Convert.ToInt32(parameters[index: 3].Value) : -1; |
| | | return (outSum, outMsg); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | throw new InvalidOperationException($"调用存储过程 ERP_DeleteWomcaaByBillNo 失败: {ex.Message}", ex); |
| | | } |
| | | } |
| | | } |