From c02ff3f682398f022488f98b87a79d4a8e04b5dd Mon Sep 17 00:00:00 2001 From: 啊鑫 <t2856754968@163.com> Date: 星期三, 30 十月 2024 11:00:11 +0800 Subject: [PATCH] 接口更新 --- MES.Service/service/BasicData/MesPositionManager.cs | 42 +++++++++++++----------------------------- 1 files changed, 13 insertions(+), 29 deletions(-) diff --git a/MES.Service/service/BasicData/MesPositionManager.cs b/MES.Service/service/BasicData/MesPositionManager.cs index 5cd83e4..60725e1 100644 --- a/MES.Service/service/BasicData/MesPositionManager.cs +++ b/MES.Service/service/BasicData/MesPositionManager.cs @@ -1,5 +1,4 @@ -锘縰sing Castle.Core.Resource; -using MES.Service.DB; +锘縰sing MES.Service.DB; using MES.Service.Dto.webApi; using MES.Service.Modes; using SqlSugar; @@ -26,14 +25,11 @@ if (UpdatePositionStatus(db, entity.Id, "B")) // 绂佺敤宀椾綅 return 1; break; - case "2": - if (InsertOrUpdatePosition(db, entity)) // 鎻掑叆鎴栨洿鏂板矖浣� - return 1; - break; case "3": if (DeletePosition(db, entity.Id)) // 鍒犻櫎宀椾綅 return 1; break; + case "2": case "4": if (InsertOrUpdatePosition(db, entity)) // 鎻掑叆鎴栨洿鏂板矖浣� return 1; @@ -64,28 +60,17 @@ // 鎻掑叆鎴栨洿鏂板矖浣嶇殑鏂规硶 private bool InsertOrUpdatePosition(SqlSugarScope db, MesPosition entity) { - var exists = db.Queryable<MesPosition>().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; - } - - return false; + db.Deleteable<MesPosition>() + .Where(s => s.Id == entity.Id).ExecuteCommand(); + var insert = db.Insertable(entity).ExecuteCommand(); + return insert > 0; } // 鍒犻櫎宀椾綅鐨勬柟娉� private bool DeletePosition(SqlSugarScope db, decimal positionId) { - var deleteById = db.Deleteable<MesPosition>().In(positionId) - .ExecuteCommand(); + var deleteById = db.Deleteable<MesPosition>() + .Where(s => s.Id == positionId).ExecuteCommand(); if (deleteById > 0) return true; @@ -200,7 +185,10 @@ List<MesPosition> positionList) { var ids = positionList.Select(it => it.Id).ToArray(); - var deleteByIds = db.Deleteable<MesPosition>().In(ids).ExecuteCommand(); + + var deleteByIds = db.Deleteable<MesPosition>() + .Where(s => ids.Contains(s.Id)).ExecuteCommand(); + if (deleteByIds > 0) return true; @@ -211,10 +199,6 @@ private bool InsertOrUpdatePositionBatch(SqlSugarScope db, List<MesPosition> positionList) { - foreach (var entity in positionList) - if (!InsertOrUpdatePosition(db, entity)) - return false; - - return true; + return positionList.All(entity => InsertOrUpdatePosition(db, entity)); } } \ No newline at end of file -- Gitblit v1.9.3