From 52dc7d05ee0f1343b11638a64a91f7560f0a6921 Mon Sep 17 00:00:00 2001 From: ningshuxia <ningshuxia0927@outlook.com> Date: 星期五, 12 八月 2022 15:26:37 +0800 Subject: [PATCH] 修改 泵曲线批量操作接口 --- Application/IStation.Application4Product/pump_curve/mapping/PumpCurveMapping_Controller.cs | 34 ++++++++++------ DAL/IStation.DAL4Product/pump_curve/PumpCurveMapping.cs | 17 +++++++- Service/IStation.Service4Product/pump_curve/pump_curve_mapping/PumpCurveMapping.cs | 50 ++++++++++++++++-------- 3 files changed, 69 insertions(+), 32 deletions(-) diff --git a/Application/IStation.Application4Product/pump_curve/mapping/PumpCurveMapping_Controller.cs b/Application/IStation.Application4Product/pump_curve/mapping/PumpCurveMapping_Controller.cs index 9a72644..1a40597 100644 --- a/Application/IStation.Application4Product/pump_curve/mapping/PumpCurveMapping_Controller.cs +++ b/Application/IStation.Application4Product/pump_curve/mapping/PumpCurveMapping_Controller.cs @@ -261,23 +261,31 @@ /// <summary> /// 璁剧疆 /// </summary> - [Route("SetOfCurveID@V1.0")] + [Route("SetByCurveID@V1.0")] [HttpPost] - public bool SetOfCurveID([Required] SetObjectPumpCurveMappingInput input) + public bool SetByCurveID([Required] SetObjectPumpCurveMappingInput input) { - var list = input.Items?.Select(x => new Model.PumpCurveMapping() + var list = new List<Model.PumpCurveMapping>(); + if (input.Items != null && input.Items.Count > 0) { - CorpID = input.CorpID, - CurveID = input.CorpID, - ID = x.ID, - PumpID = x.PumpID, - OtherName = x.OtherName, - IsWorking = x.IsWorking, - SortCode = x.SortCode, - }).ToList(); - var bol = _service.SetOfCurveID(input.CorpID, input.CurveID, list); + if (input.Items.GroupBy(x => x.PumpID).Count() > 1) + { + throw new Exception("PumpID瀛樺湪閲嶅椤�"); + } + list = input.Items.Select(x => new Model.PumpCurveMapping() + { + CorpID = input.CorpID, + CurveID = input.CorpID, + ID = x.ID, + PumpID = x.PumpID, + OtherName = x.OtherName, + IsWorking = x.IsWorking, + SortCode = x.SortCode, + }).ToList(); + } + var bol = _service.SetByCurveID(input.CorpID, input.CurveID, list); return bol; - } + } #endregion diff --git a/DAL/IStation.DAL4Product/pump_curve/PumpCurveMapping.cs b/DAL/IStation.DAL4Product/pump_curve/PumpCurveMapping.cs index d064efe..426ded4 100644 --- a/DAL/IStation.DAL4Product/pump_curve/PumpCurveMapping.cs +++ b/DAL/IStation.DAL4Product/pump_curve/PumpCurveMapping.cs @@ -160,6 +160,19 @@ } /// <summary> + /// 閫氳繃 CurveIds 鑾峰彇 + /// </summary> + public List<Entity.PumpCurveMapping> GetByCurveIds(long CorpID, List<long> CurveIds) + { + if (CurveIds == null || CurveIds.Count < 1) + return default; + using (var db = new SqlSugarClient(ConnectionConfig)) + { + return db.Queryable<Entity.PumpCurveMapping>().Where(x => x.CorpID == CorpID && CurveIds.Contains(x.CurveID)).ToList(); + } + } + + /// <summary> /// 鏇存柊 IsWorking /// </summary> public bool UpdateIsWorking(long CorpID, long ID, bool IsWorking) @@ -282,7 +295,7 @@ /// <summary> /// 閫氳繃 CurveID 璁剧疆 /// </summary> - public bool SetOfCurveID(long CorpID, long CurveID, List<Entity.PumpCurveMapping> list) + public bool SetByCurveID(long CorpID, long CurveID, List<Entity.PumpCurveMapping> list) { if (list == null || list.Count() < 1) { @@ -301,7 +314,7 @@ db.BeginTran(); var add_list = list.Where(x => x.ID < 1).ToList(); var update_list = list.Where(x => x.ID > 0).ToList(); - var ids_exist = update_list.Select(x => x.ID).Distinct().ToList(); + var ids_exist = update_list.Where(x=>x.CurveID==CurveID).Select(x => x.ID).Distinct().ToList(); db.Deleteable<Entity.PumpCurveMapping>().Where(x => x.CorpID == CorpID && x.CurveID == CurveID && !ids_exist.Contains(x.ID)).ExecuteCommand(); if (add_list.Count > 0) { diff --git a/Service/IStation.Service4Product/pump_curve/pump_curve_mapping/PumpCurveMapping.cs b/Service/IStation.Service4Product/pump_curve/pump_curve_mapping/PumpCurveMapping.cs index f9ffa7b..0df4c3f 100644 --- a/Service/IStation.Service4Product/pump_curve/pump_curve_mapping/PumpCurveMapping.cs +++ b/Service/IStation.Service4Product/pump_curve/pump_curve_mapping/PumpCurveMapping.cs @@ -128,6 +128,22 @@ } } + //閫氳繃 CurveIds 鏇存柊缂撳瓨 + internal void UpdateCorpCacheByCurveID(long CorpID, List<long> CurveIds) + { + if (CurveIds == null || CurveIds.Count < 1) + return; + var dal = new DAL.PumpCurveMapping(); + var entity_list = dal.GetByCurveIds(CorpID, CurveIds); + var model_list = Entity2Models(entity_list); + var all = GetCorpCache(CorpID); + all.RemoveAll(x => CurveIds.Contains(x.CurveID)); + if (model_list != null && model_list.Count > 0) + { + all.AddRange(model_list); + } + } + //閫氳繃 CurveID 绉婚櫎缂撳瓨 internal void RemoveCorpCacheByCurveID(long CorpID, long CurveID) { @@ -203,6 +219,7 @@ var all = GetByCorpID(CorpID); return all?.Where(x => x.CurveID == CurveID).OrderBy(x => x.SortCode).ToList(); } + /// <summary> /// 閫氳繃 CurveIds 鑾峰彇 @@ -473,37 +490,36 @@ /// <summary> /// 璁剧疆 CurveID 娉垫洸绾挎槧灏� /// </summary> - public bool SetOfCurveID(long CorpID, long CurveID, List<Model.PumpCurveMapping> list) + public bool SetByCurveID(long CorpID, long CurveID, List<Model.PumpCurveMapping> list) { var dal = new DAL.PumpCurveMapping(); if (list != null && list.Count > 0) { - var update_working_list = list.FindAll(x => x.IsWorking).ToList(); - if (update_working_list != null && update_working_list.Count > 0) + if (list.GroupBy(x => x.PumpID).Count() > 0) + return false; + var allCurveMappingList = GetCorpCache(CorpID); + var updateWorkingList = list.FindAll(x => x.IsWorking).ToList(); + if (updateWorkingList != null && updateWorkingList.Count > 0) { - foreach (var working_curve in update_working_list) + foreach (var workingMapping in updateWorkingList) { - var relevant_pump_curve_list = GetByPumpID(CorpID, working_curve.PumpID); - if (relevant_pump_curve_list == null || relevant_pump_curve_list.Count < 1) + var relevantPumpCurveMappingList = allCurveMappingList.Where(x => x.PumpID == workingMapping.PumpID).ToList(); + if (relevantPumpCurveMappingList == null || relevantPumpCurveMappingList.Count < 1) continue; - var exist_working_curve_list = relevant_pump_curve_list.FindAll(x => x.IsWorking); - if (exist_working_curve_list == null || exist_working_curve_list.Count < 1) + var existWorkingMappingList = relevantPumpCurveMappingList.Where(x => x.IsWorking && x.ID != workingMapping.ID).ToList(); + if (existWorkingMappingList == null || existWorkingMappingList.Count < 1) continue; - exist_working_curve_list.ForEach(x => x.IsWorking = false); - list.AddRange(exist_working_curve_list); + existWorkingMappingList.ForEach(x => x.IsWorking = false); + list.AddRange(existWorkingMappingList); } } } var entity_list = Model2Entities(list.ToList()); - var bol = dal.SetOfCurveID(CorpID, CurveID, entity_list); + var bol = dal.SetByCurveID(CorpID, CurveID, entity_list); if (bol) { - UpdateCorpCacheByCurveID(CorpID, CurveID); - var other_pump_curve_list = entity_list.Where(x => x.CurveID != CurveID).ToList(); - if (other_pump_curve_list != null && other_pump_curve_list.Count > 0) - { - UpdateCorpCache(CorpID, other_pump_curve_list.Select(x => x.ID).ToList()); - } + var curveIds = list.Select(x => x.CurveID).Distinct().ToList(); + UpdateCorpCacheByCurveID(CorpID, curveIds); } return bol; } -- Gitblit v1.9.3