| | |
| | | // SaveList 方法用于保存多个仓库记录,根据类型批量执行不同的操作 |
| | | public bool SaveList(List<ErpDepots> erpDepots) |
| | | { |
| | | var list = new List<MesDepots>(); |
| | | erpDepots.ForEach(s => |
| | | if (erpDepots == null || !erpDepots.Any()) |
| | | { |
| | | var entity = GetMesDepots(s); // 将 ErpDepots 转换为 MesDepots |
| | | entity.Type = s.Type; |
| | | list.Add(entity); |
| | | }); |
| | | Console.WriteLine("警告: 传入的列表为空"); |
| | | return false; |
| | | } |
| | | |
| | | var groupBy = list.GroupBy(s => s.Type) |
| | | .ToDictionary(g => g.Key, g => g.ToList()); |
| | | return UseTransaction(db => |
| | | { |
| | | foreach (var depotsGroup in groupBy) |
| | | switch (depotsGroup.Key) |
| | | { |
| | | case "0": |
| | | if (!UpdateDepotStatusBatch(db, depotsGroup.Value, |
| | | "A")) // 批量启用仓库 |
| | | throw new NotImplementedException("启用失败"); |
| | | break; |
| | | case "1": |
| | | if (!UpdateDepotStatusBatch(db, depotsGroup.Value, |
| | | "B")) // 批量禁用仓库 |
| | | throw new NotImplementedException("禁用失败"); |
| | | break; |
| | | case "3": |
| | | if (!DeleteDepotBatch(db, |
| | | depotsGroup.Value)) // 批量删除仓库 |
| | | throw new NotImplementedException("删除失败"); |
| | | break; |
| | | case "2": |
| | | case "4": |
| | | if (!InsertOrUpdateBatch(db, |
| | | depotsGroup.Value)) // 批量插入或更新仓库 |
| | | throw new NotImplementedException("同步失败"); |
| | | break; |
| | | default: |
| | | throw new ArgumentNullException( |
| | | $"type没有{depotsGroup.Key}这个类型的参数"); |
| | | } |
| | | |
| | | return 1; |
| | | }) > 0; |
| | | // 逐条处理,全部成功才返回true(事务内批量处理更优,此处保持原有逻辑) |
| | | var result = erpDepots.Select(Save).ToList(); |
| | | return result.All(b => b); |
| | | } |
| | | |
| | | // 批量更新仓库状态的方法 |