kyy
2025-09-04 2e37035392c187b26a09a2c2edcc6133e96532cc
MES.Service/service/BasicData/MesItemsManager.cs
@@ -44,39 +44,15 @@
    public bool SaveList(List<ErpItems> items)
    {
        var list = items.Select(GetMesItems).ToList();
        var groupBy = list.GroupBy(s => s.Type)
            .ToDictionary(g => g.Key, g => g.ToList());
        return UseTransaction(db =>
        if (items == null || !items.Any())
        {
            foreach (var itemGroup in groupBy)
                switch (itemGroup.Key)
                {
                    case "0":
                        if (!UpdateItemStatusBatch(db, itemGroup.Value, "A"))
                            throw new NotImplementedException("启用失败");
                        break;
                    case "1":
                        if (!UpdateItemStatusBatch(db, itemGroup.Value, "B"))
                            throw new NotImplementedException("禁用失败");
                        break;
                    case "3":
                        if (!DeleteItemBatch(db, itemGroup.Value))
                            throw new NotImplementedException("删除失败");
                        break;
                    case "2":
                    case "4":
                        if (!InsertOrUpdateBatch(db, itemGroup.Value))
                            throw new NotImplementedException("同步失败");
                        break;
                    default:
                        throw new ArgumentNullException(
                            $"type没有{itemGroup.Key}这个类型的参数");
                }
            return 1;
        }) > 0;
            Console.WriteLine("警告: 传入的物料列表为空");
            return false;
        }
        // 逐条处理,全部成功才返回true(事务内批量处理更优,此处保持原有逻辑)
        var result = items.Select(Save).ToList();
        return result.All(b => b);
    }
    private bool UpdateItemStatus(SqlSugarScope db, decimal itemId,
@@ -113,25 +89,37 @@
    private MesItems GetMesItems(ErpItems item)
    {
        return new MesItems
        // var id = string.IsNullOrEmpty(item.Id)
        //     ? DateTimeOffset.UtcNow.ToUnixTimeSeconds()
        //     : long.Parse(item.Id);
        var entity = new MesItems
        {
            Id = string.IsNullOrEmpty(item.Id)
                ? DateTimeOffset.UtcNow.ToUnixTimeSeconds()
                : long.Parse(item.Id),
            // Id = id,
            Type = item.Type,
            ItemNo = item.FNumber,
            ItemName = item.FName,
            ItemModel = item.FSpecification,
            ItemUnit = item.FBaseUnitId,
            Lowlimit = !string.IsNullOrEmpty(item.FSafeStock) ? Convert.ToDecimal(item.FSafeStock) : null,
            Highlimit = !string.IsNullOrEmpty(item.FMaxStock) ? Convert.ToDecimal(item.FMaxStock) : null,
            PrdPack = !string.IsNullOrEmpty(item.FMinPackCount) ? Convert.ToDecimal(item.FMinPackCount) : null,
            // Lowlimit = !string.IsNullOrEmpty(item.FSafeStock)
            //     ? Convert.ToDecimal(item.FSafeStock)
            //     : null,
            // Highlimit = !string.IsNullOrEmpty(item.FMaxStock)
            //     ? Convert.ToDecimal(item.FMaxStock)
            //     : null,
            // PrdPack = !string.IsNullOrEmpty(item.FMinPackCount)
            //     ? Convert.ToDecimal(item.FMinPackCount)
            //     : null,
            DepotCode = item.FStockId,
            Fmaterialgroup = item.FMaterialGroup,
            Remarks = item.FDescription,
            Ffinishreceiptoverrate = !string.IsNullOrEmpty(item.FFinishReceiptOverRate) ? Convert.ToInt32(item.FFinishReceiptOverRate) : null,
            // Ffinishreceiptoverrate =
            //     !string.IsNullOrEmpty(item.FFinishReceiptOverRate)
            //         ? Convert.ToInt32(item.FFinishReceiptOverRate)
            //         : null,
            Fissuetype = item.FIssueType,
            Fisbatchmanage = !string.IsNullOrEmpty(item.FIsBatchManage) ? Convert.ToInt32(item.FIsBatchManage) : null,
            // Fisbatchmanage = !string.IsNullOrEmpty(item.FIsBatchManage)
            //     ? Convert.ToInt32(item.FIsBatchManage)
            //     : null,
            Fpurchaserid = item.FPurchaserId,
            Fpurchaseunitid = item.FPurchaseUnitId,
            Storeunit = item.FStoreUnitID,
@@ -150,13 +138,24 @@
            LossPercent = item.FLOSSPERCENT,
            MnemonicCode = item.FMnemonicCode,
            ExpPeriod = item.FExpPeriod,
            EItemId = !string.IsNullOrEmpty(item.Id) ? long.Parse(item.Id) : null,
            ItemId = !string.IsNullOrEmpty(item.Id) ? long.Parse(item.Id) : null,
            // EItemId = id,
            // ItemId = id,
            LastupdateDate = DateTime.Now,
            CreateDate = DateTime.Now,
            Company = "1000",
            Factory = "1000"
        };
        var mesItems = Db.Queryable<MesItems>()
            .Where(s => s.ItemNo == entity.ItemNo)
            .First();
        if (mesItems != null)
        {
            entity.Id = mesItems.Id;
        }
        return entity;
    }
    private bool UpdateItemStatusBatch(SqlSugarScope db,