zyf
2025-06-18 91489875fc8c9fd2b44c3791ca6f67dcf559675f
MES.Service/service/BasicData/ProductionOrderManager.cs
@@ -1,8 +1,11 @@
using System.Globalization;
using System.Data;
using System.Globalization;
using MES.Service.DB;
using MES.Service.Dto.webApi;
using MES.Service.Modes;
using SqlSugar;
using static Microsoft.EntityFrameworkCore.DbLoggerCategory;
using DbType = System.Data.DbType;
namespace MES.Service.service.BasicData;
@@ -35,7 +38,7 @@
                    return UpdateData(db, mesRohIn, mesRohInDatas) ? 1 : 0;
                case "2":
                case "4":
                    return SaveOrUpdateData(db, mesRohIn, mesRohInDatas)
                    return SaveOrUpdateData(db, mesRohIn, mesRohInDatas, erpProductionOrderDto.Type)
                        ? 1
                        : 0;
                default:
@@ -51,7 +54,7 @@
        var decimals = mesRohInDatas.Select(s => s.Id).ToArray();
        var update = base.DeleteById(mesRohIn.Id);
        var insertOrUpdate = db
            .Deleteable<MesRohInData>().In(decimals)
            .Deleteable<ProductionOrderSub>().In(decimals)
            .ExecuteCommand() > 0;
        if (update && insertOrUpdate) return true;
@@ -60,7 +63,7 @@
    // 插入或更新数据的方法
    private bool SaveOrUpdateData(SqlSugarScope db, ProductionOrder mesRohIn,
        List<ProductionOrderSub> mesRohInDatas)
        List<ProductionOrderSub> mesRohInDatas,string type)
    {
        if (mesRohIn.Id != null) base.DeleteById(mesRohIn.Id);
@@ -70,7 +73,52 @@
        var orUpdate = base.Insert(mesRohIn);
        var baOrUpdate = _productionOrderSubManager.InsertRange(mesRohInDatas);
        if (orUpdate && baOrUpdate) return true;
        if (orUpdate && baOrUpdate)
        {
            if ("4".Equals(type)||"3".Equals(type)||"2".Equals(type))
            {
                //调用存储过程
                try
                {
                    // 定义输出参数
                    var outputResult = new SugarParameter("C_RESULT", null,
                        DbType.Int32, ParameterDirection.Output,
                        4000);
                    var outputMessage = new SugarParameter("MSG", null, DbType.String,
                        ParameterDirection.Output, 4000);
                    // 定义输入参数
                    var parameters = new List<SugarParameter>
                {
                    new("P_ID",mesRohIn.ErpId , DbType.String,
                        ParameterDirection.Input),
                    outputResult,
                    outputMessage
                };
                    // 使用 SqlSugar 执行存储过程
                    Db.Ado.ExecuteCommand(
                        "BEGIN PRC_MES_WW_UPDATE_BS(:P_ID, :C_RESULT, :MSG); END;",
                        parameters.ToArray());
                    // 获取输出参数的值
                    var resultValue = outputResult.Value?.ToString();
                    var messageValue = outputMessage.Value?.ToString();
                    if ("1".Equals(resultValue)) throw new Exception("更新失败");
                    return true;
                }
                catch (Exception ex)
                {
                    throw new Exception(ex.Message);
                }
            }
            return true;
        }
        throw new NotImplementedException("插入或更新失败");
    }
@@ -86,10 +134,10 @@
    {
        DateTime parsedDate;
        // 时间格式转换函数,ERP时间格式为 "yyyy-MM-dd HH:mm:ss.fff"
        // 时间格式转换函数,ERP时间格式为 "yyyy-MM-dd HH:mm:ss"
        DateTime? ParseDateTime(string dateStr)
        {
            if (DateTime.TryParseExact(dateStr, "yyyy-MM-dd HH:mm:ss.fff",
            if (DateTime.TryParseExact(dateStr, "yyyy-MM-dd HH:mm:ss",
                    CultureInfo.InvariantCulture,
                    DateTimeStyles.None,
                    out parsedDate))
@@ -108,15 +156,15 @@
            BusinessStatus = erpDto.FStatus,
            ProductCode = erpDto.FMaterialId,
            Unit = erpDto.FUnitID,
            WorkOrderQty = Convert.ToDecimal(erpDto.FQty),
            WorkOrderQty = Convert.ToDouble(erpDto.FQty),
            PlanningGroup = erpDto.FWorkGroupId,
            Planner = erpDto.FPlannerID,
            EstimatedStartTime =
            PlanStartDate =
                ParseDateTime(erpDto.FPlanStartDate) ?? null,
            EstimatedEndTime =
            PlanFinishDate =
                ParseDateTime(erpDto.FPlanFinishDate) ?? null,
            StorageUpperLimit = Convert.ToDecimal(erpDto.FStockInLimitH),
            StorageLowerLimit = Convert.ToDecimal(erpDto.FStockInLimitL),
            StorageUpperLimit = Convert.ToDouble(erpDto.FStockInLimitH),
            StorageLowerLimit = Convert.ToDouble(erpDto.FStockInLimitL),
            TrackingNo = erpDto.FMTONO,
            BatchNo = erpDto.FLot,
            BomVersion = erpDto.FBomId,
@@ -137,13 +185,14 @@
            ErpProductionEntryCode = erpDto.FSUBENTRYID,
            PurchaseOrderNo = erpDto.FPurOrderNo,
            PurchaseOrderEntrySeq = long.Parse(erpDto.FPurOrderEntrySeq),
            StandardPoints =
                Convert.ToDecimal(erpDto.F_UNW_BaseProperty_bzds),
            PricingPoints =
                Convert.ToDecimal(erpDto.F_UNW_BaseProperty_jjds),
            // StandardPoints =
            //     Convert.ToDecimal(erpDto.F_UNW_BaseProperty_bzds),
            // PricingPoints =
            //     Convert.ToDecimal(erpDto.F_UNW_BaseProperty_jjds),
            StockInQty = Convert.ToDecimal(erpDto.FBaseStockInQty),
            NoStockInQty = Convert.ToDecimal(erpDto.FBaseNoStockInQty),
            StockOwner = erpDto.FInStockOwnerId
            NoStockInQty = Convert.ToDouble(erpDto.FBaseNoStockInQty),
            StockOwner = erpDto.FInStockOwnerId,
            SUPPLIER = erpDto.FSUPPLIERID
        };
        var single = base.GetSingle(it => it.ErpId == erpDto.FPPOMID);
@@ -164,7 +213,7 @@
            {
                SequenceNo = long.Parse(erpDto.FSEQ),
                MaterialCode = erpDto.FMaterialID2,
                RequiredQty = Convert.ToDecimal(erpDto.FMustQty),
                RequiredQty = Convert.ToDouble(erpDto.FMustQty),
                IssuedQty = Convert.ToDecimal(erpDto.FPickedQty),
                LocationNo = erpDto.FPositionNO,
                StockOwner = erpDto.FOwnerID,
@@ -175,8 +224,8 @@
                Process = erpDto.F_UNW_Text_tpgy_Z,
                Unit = erpDto.FUnitID2,
                SupplyingType = erpDto.FSupplyType,
                Numerator = long.Parse(erpDto.FNumerator),
                Denominator = long.Parse(erpDto.FDenominator),
                Numerator = Convert.ToDouble(erpDto.FNumerator),
                Denominator = Convert.ToDouble(erpDto.FDenominator),
                ErpId = erpDto.FPPOMENTRYID,
                ErpHeaderId = erpDto.FPPOMID,
                FixedLoss = Convert.ToDecimal(erpDto.FFixScrapQty),