| | |
| | | { |
| | | switch (customer.Type) |
| | | { |
| | | case "0": |
| | | case "2": |
| | | case "4": |
| | | return InsertItemType(entity); |
| | | case "1": |
| | | case "3": |
| | | return DeleteItemType(entity.Id); |
| | | default: |
| | | throw new ArgumentNullException( |
| | |
| | | |
| | | public bool SaveList(List<ErpItemType> departments) |
| | | { |
| | | var list = new List<MesItemType>(); |
| | | departments.ForEach(s => |
| | | if (departments == null || !departments.Any()) |
| | | { |
| | | var entity = GetMesItemType(s); |
| | | entity.Type = s.Type; |
| | | list.Add(entity); |
| | | }); |
| | | |
| | | var groupBy = list.GroupBy(s => s.Type) |
| | | .ToDictionary(g => g.Key, g => g.ToList()); |
| | | var result = new List<bool>(); |
| | | |
| | | foreach (var itemTypeGroup in groupBy) |
| | | try |
| | | { |
| | | switch (itemTypeGroup.Key) |
| | | { |
| | | case "0": |
| | | result.Add(InsertItemTypeBatch(itemTypeGroup.Value)); |
| | | break; |
| | | case "1": |
| | | result.Add(DeleteItemTypeBatch(itemTypeGroup.Value)); |
| | | break; |
| | | default: |
| | | throw new ArgumentNullException( |
| | | $"type没有{itemTypeGroup.Key}这个类型的参数"); |
| | | } |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | throw new ApplicationException($"批量操作失败: {ex.Message}", ex); |
| | | Console.WriteLine("警告: 传入的列表为空"); |
| | | return false; |
| | | } |
| | | |
| | | if (result.All(b => b)) |
| | | return true; |
| | | |
| | | throw new NotImplementedException("接口执行失败"); |
| | | // 逐条处理,全部成功才返回true(事务内批量处理更优,此处保持原有逻辑) |
| | | var result = departments.Select(Save).ToList(); |
| | | return result.All(b => b); |
| | | } |
| | | |
| | | private bool InsertItemTypeBatch(List<MesItemType> itemTypeList) |