| | |
| | | using Castle.Core.Resource; |
| | | using MES.Service.DB; |
| | | using MES.Service.DB; |
| | | using MES.Service.Dto.webApi; |
| | | using MES.Service.Modes; |
| | | using SqlSugar; |
| | |
| | | if (UpdateDepotStatus(db, entity.DepotId, "B")) return 1; |
| | | |
| | | break; |
| | | case "2": |
| | | if (InsertDepot(db, entity)) return 1; |
| | | |
| | | break; |
| | | case "3": |
| | | if (DeleteDepot(db, entity.DepotId)) return 1; |
| | | |
| | | break; |
| | | case "2": |
| | | case "4": |
| | | if (InsertOrUpdate(db, entity)) return 1; |
| | | |
| | |
| | | // 删除仓库的方法 |
| | | private bool DeleteDepot(SqlSugarScope db, decimal depotId) |
| | | { |
| | | var deleteById = db.Deleteable<MesDepots>().In(depotId) |
| | | .ExecuteCommand(); |
| | | var deleteById = db.Deleteable<MesDepots>() |
| | | .Where(s => s.DepotId == depotId).ExecuteCommand(); |
| | | if (deleteById > 0) |
| | | return true; |
| | | |
| | |
| | | // 插入或更新仓库的方法 |
| | | private bool InsertOrUpdate(SqlSugarScope db, MesDepots entity) |
| | | { |
| | | var exists = db.Queryable<MesDepots>() |
| | | .Any(e => e.DepotId == entity.DepotId); |
| | | if (exists) |
| | | { |
| | | var update = db.Updateable(entity).ExecuteCommand(); |
| | | if (update > 0) |
| | | return true; |
| | | } |
| | | else |
| | | { |
| | | var insert = db.Insertable(entity).ExecuteCommand(); |
| | | if (insert > 0) |
| | | return true; |
| | | } |
| | | |
| | | return false; |
| | | db.Deleteable<MesDepots>() |
| | | .Where(s => s.DepotId == entity.DepotId) |
| | | .ExecuteCommand(); |
| | | var insert = db.Insertable(entity).ExecuteCommand(); |
| | | return insert > 0; |
| | | } |
| | | |
| | | // 将 ErpDepots 对象转换为 MesDepots 对象的方法 |
| | |
| | | { |
| | | return new MesDepots |
| | | { |
| | | Guid = depots.Id, |
| | | DepotCode = depots.FNumber, |
| | | DepotName = depots.FName, |
| | | DepotId = Convert.ToDecimal(depots.Id), |
| | |
| | | Zuid = depots.FGroup, |
| | | FSubsidiary = depots.FUseOrgId, |
| | | Fumbrella = depots.FCreateOrgId, |
| | | |
| | | CreateDate = DateTime.Now, |
| | | LastupdateDate = DateTime.Now, |
| | | SupplierId = depots.FSUPPLIERID, |
| | | ClientId = depots.ClientId, |
| | | Department = depots.Fdeptid, |
| | | Phone = depots.Phone, |
| | | Company = "1000", |
| | | Factory = "1000" |
| | | }; |
| | |
| | | "B")) // 批量禁用仓库 |
| | | throw new NotImplementedException("禁用失败"); |
| | | break; |
| | | case "2": |
| | | if (!InsertDepotBatch(db, |
| | | depotsGroup.Value)) // 批量插入仓库 |
| | | throw new NotImplementedException("插入失败"); |
| | | break; |
| | | case "3": |
| | | if (!DeleteDepotBatch(db, |
| | | depotsGroup.Value)) // 批量删除仓库 |
| | | throw new NotImplementedException("删除失败"); |
| | | break; |
| | | case "2": |
| | | case "4": |
| | | if (!InsertOrUpdateBatch(db, |
| | | depotsGroup.Value)) // 批量插入或更新仓库 |
| | |
| | | { |
| | | var ids = depotList.Select(it => it.DepotId).ToArray(); |
| | | var deleteByIds = |
| | | db.Deleteable<MesDepots>().In(ids).ExecuteCommand(); |
| | | db.Deleteable<MesDepots>() |
| | | .Where(s => ids.Contains(s.DepotId)).ExecuteCommand(); |
| | | if (deleteByIds > 0) |
| | | return true; |
| | | |
| | |
| | | private bool InsertOrUpdateBatch(SqlSugarScope db, |
| | | List<MesDepots> depotList) |
| | | { |
| | | foreach (var entity in depotList) |
| | | if (!InsertOrUpdate(db, entity)) |
| | | return false; |
| | | |
| | | return true; |
| | | return depotList.All(entity => InsertOrUpdate(db, entity)); |
| | | } |
| | | } |