| | |
| | | using Castle.Core.Resource; |
| | | using MES.Service.DB; |
| | | using MES.Service.DB; |
| | | using MES.Service.Dto.webApi; |
| | | using MES.Service.Modes; |
| | | using SqlSugar; |
| | |
| | | if (UpdateItemStatus(db, entity.Id, "B")) |
| | | return 1; |
| | | break; |
| | | case "2": |
| | | if (InsertItem(db, entity)) |
| | | return 1; |
| | | break; |
| | | case "3": |
| | | if (DeleteItem(db, entity.Id)) |
| | | return 1; |
| | | break; |
| | | case "2": |
| | | case "4": |
| | | if (InsertOrUpdate(db, entity)) |
| | | return 1; |
| | |
| | | if (!UpdateItemStatusBatch(db, itemGroup.Value, "B")) |
| | | throw new NotImplementedException("禁用失败"); |
| | | break; |
| | | case "2": |
| | | if (!InsertItemBatch(db, itemGroup.Value)) |
| | | 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("同步失败"); |
| | |
| | | |
| | | private bool DeleteItem(SqlSugarScope db, decimal itemId) |
| | | { |
| | | var deleteById = db.Deleteable<MesItems>().In(itemId).ExecuteCommand(); |
| | | var deleteById = db.Deleteable<MesItems>() |
| | | .Where(s => s.Id == itemId).ExecuteCommand(); |
| | | if (deleteById > 0) |
| | | return true; |
| | | |
| | |
| | | return new MesItems |
| | | { |
| | | Id = Convert.ToDecimal(item.Id), |
| | | Type = item.Type, |
| | | ItemNo = item.FNumber, |
| | | ItemName = item.FName, |
| | | ItemModel = item.FSpecification, |
| | | ItemUnit = item.FBaseUnitId, |
| | | Lowlimit = item.FSafeStock, |
| | | Highlimit = item.FMaxStock, |
| | | PrdPack = item.FMinPackCount, |
| | | Lowlimit = Convert.ToDouble(item.FSafeStock), |
| | | Highlimit = Convert.ToDouble(item.FMaxStock), |
| | | PrdPack = Convert.ToDouble(item.FMinPackCount), |
| | | DepotCode = item.FStockId, |
| | | Fmaterialgroup = item.FMaterialGroup, |
| | | Remarks = item.FDescription, |
| | | Ffinishreceiptoverrate = item.FFinishReceiptOverRate, |
| | | Ffinishreceiptoverrate = |
| | | Convert.ToDecimal(item.FFinishReceiptOverRate), |
| | | Fissuetype = item.FIssueType, |
| | | Fisbatchmanage = item.FIsBatchManage, |
| | | Fisbatchmanage = Convert.ToInt32(item.FIsBatchManage), |
| | | Fpurchaserid = item.FPurchaserId, |
| | | Fpurchaseunitid = Convert.ToDecimal(item.FPurchaseUnitId), |
| | | Storeunit = item.FStoreUnitID, |
| | |
| | | SubconUnit = item.FSUBCONUNITID, |
| | | FSubsidiary = item.FUseOrgId, |
| | | Fumbrella = item.FCreateOrgId, |
| | | FLOSSPERCENT = item.FLOSSPERCENT, |
| | | FMnemonicCode = item.FMnemonicCode, |
| | | FExpPeriod = item.FExpPeriod, |
| | | LastupdateDate = DateTime.Now, |
| | | CreateDate = DateTime.Now, |
| | | Company = "1000", |
| | | Factory = "1000", |
| | | ColorName = item.FColor |
| | | Factory = "1000" |
| | | }; |
| | | } |
| | | |
| | |
| | | private bool DeleteItemBatch(SqlSugarScope db, List<MesItems> itemList) |
| | | { |
| | | var ids = itemList.Select(it => it.Id).ToArray(); |
| | | var deleteByIds = db.Deleteable<MesItems>().In(ids).ExecuteCommand(); |
| | | var deleteByIds = db.Deleteable<MesItems>() |
| | | .Where(s => ids.Contains(s.Id)).ExecuteCommand(); |
| | | if (deleteByIds > 0) |
| | | return true; |
| | | |
| | |
| | | |
| | | private bool InsertOrUpdate(SqlSugarScope db, MesItems entity) |
| | | { |
| | | var exists = db.Queryable<MesItems>().Any(e => e.Id == entity.Id); |
| | | 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; |
| | | } |
| | | db.Deleteable<MesItems>().Where(s => s.Id == entity.Id) |
| | | .ExecuteCommand(); |
| | | |
| | | return false; |
| | | var insert = db.Insertable(entity).ExecuteCommand(); |
| | | return insert > 0; |
| | | } |
| | | |
| | | private bool InsertOrUpdateBatch(SqlSugarScope db, List<MesItems> itemList) |
| | | { |
| | | foreach (var entity in itemList) |
| | | if (!InsertOrUpdate(db, entity)) |
| | | return false; |
| | | |
| | | return true; |
| | | return itemList.All(entity => InsertOrUpdate(db, entity)); |
| | | } |
| | | } |