From 62a273ee755729c9f5aec825fc6adb1076f21ec7 Mon Sep 17 00:00:00 2001
From: lixiaojun <1287241240@qq.com>
Date: 星期二, 07 十一月 2023 11:06:24 +0800
Subject: [PATCH] 初版

---
 Yw.Application.Curve.Core/3-pump-curve-extension/1-mgr/PumpCurveExMapping_StandardController.cs |  218 ++++++++++++++++++------------------------------------
 1 files changed, 72 insertions(+), 146 deletions(-)

diff --git a/Yw.Application.Curve.Core/3-pump-curve-extension/1-mgr/PumpCurveExMapping_StandardController.cs b/Yw.Application.Curve.Core/3-pump-curve-extension/1-mgr/PumpCurveExMapping_StandardController.cs
index edf6a5e..bcda611 100644
--- a/Yw.Application.Curve.Core/3-pump-curve-extension/1-mgr/PumpCurveExMapping_StandardController.cs
+++ b/Yw.Application.Curve.Core/3-pump-curve-extension/1-mgr/PumpCurveExMapping_StandardController.cs
@@ -7,112 +7,44 @@
     [ApiDescriptionSettings("Curve", Name = "娉垫洸绾挎槧灏勬嫇灞�", Order = 8000)]
     public partial class PumpCurveExMapping_StandardController : IDynamicApiController
     {
-        private readonly Service.PumpCurveExMapping _service = new Service.PumpCurveExMapping();
+        private readonly Service.PumpCurveExMapping _service = new();
 
         #region Query
 
         /// <summary>
-        /// 閫氳繃 CorpID 鑾峰彇
-        /// </summary>
-        [Route("GetByCorpID@V1.0")]
-        [HttpGet]
-        public List<PumpCurveExMappingDto> GetByCorpID([FromQuery][Required] CorpIDInput input)
-        {
-            var list = _service.GetByCorpID(input.CorpID);
-            var vm_list = list?.Select(x => x.Adapt<Model.PumpCurveExMapping, PumpCurveExMappingDto>()).ToList();
-            return vm_list;
-        }
-
-        /// <summary>
-        /// 閫氳繃 MappingID 鑾峰彇
-        /// </summary>
-        [Route("GetByMappingID@V1.0")]
-        [HttpGet]
-        public PumpCurveExMappingDto GetByMappingID
-            (
-                [Required, Range(1, long.MaxValue, ErrorMessage = "CorpID 蹇呴』澶т簬0")]
-                long CorpID,
-                 [Required, Range(1, long.MaxValue, ErrorMessage = "MappingID 蹇呴』澶т簬0")]
-                long MappingID
-            )
-        {
-            var model = _service.GetByMappingID(CorpID, MappingID);
-            return model?.Adapt<Model.PumpCurveExMapping, PumpCurveExMappingDto>();
-        }
-
-        /// <summary>
-        /// 閫氳繃 MappingIds 鑾峰彇
-        /// </summary>
-        [Route("GetByMappingIds@V1.0")]
-        [HttpGet]
-        public List<PumpCurveExMappingDto> GetByMappingIds([FromQuery][Required] MappingIdsUnderCorpInput input)
-        {
-            var ids = LongListHelper.ToList(input.MappingIds);
-            var list = _service.GetByMappingIds(input.CorpID, ids);
-            var vm_list = list?.Select(x => x.Adapt<Model.PumpCurveExMapping, PumpCurveExMappingDto>()).ToList();
-            return vm_list;
-        }
-
-        /// <summary>
-        ///  閫氳繃 PumpID 鑾峰彇
+        /// 閫氳繃 PumpID 鑾峰彇
         /// </summary>
         [Route("GetByPumpID@V1.0")]
         [HttpGet]
-        public List<PumpCurveExMappingDto> GetByPumpID
-            (
-                [Required, Range(1, long.MaxValue, ErrorMessage = "CorpID 蹇呴』澶т簬0")]
-                long CorpID,
-                 [Required, Range(1, long.MaxValue, ErrorMessage = "PumpID 蹇呴』澶т簬0")]
-                long PumpID
-            )
+        public List<PumpCurveExMappingDto> GetByPumpID([FromQuery][Required] PumpIDInput input)
         {
-            var list = _service.GetByPumpID(CorpID, PumpID);
-            var vm_list = list?.Select(x => x.Adapt<Model.PumpCurveExMapping, PumpCurveExMappingDto>()).ToList();
-            return vm_list;
+            var list = _service.GetByPumpID(input.PumpID);
+            var vmList = list.Select(x => new PumpCurveExMappingDto(x.Item1, x.Item2)).ToList();
+            return vmList;
         }
 
         /// <summary>
-        ///  閫氳繃 PumpIds 鑾峰彇
+        /// 閫氳繃 ID 鑾峰彇
         /// </summary>
-        [Route("GetByPumpIds@V1.0")]
+        [Route("GetByID@V1.0")]
         [HttpGet]
-        public List<PumpCurveExMappingDto> GetByPumpIds([FromQuery][Required] PumpIdsUnderCorpInput input)
+        public PumpCurveExMappingDto GetByID([FromQuery][Required] IDInput input)
         {
-            var ids = LongListHelper.ToList(input.PumpIds);
-            var list = _service.GetByPumpIds(input.CorpID, ids);
-            var vm_list = list?.Select(x => x.Adapt<Model.PumpCurveExMapping, PumpCurveExMappingDto>()).ToList();
-            return vm_list;
+            var model = _service.GetByID(input.ID);
+            return model == null ? null : new PumpCurveExMappingDto(model.Item1, model.Item2);
         }
 
         /// <summary>
-        /// 閫氳繃 CurveID 鑾峰彇
+        /// 閫氳繃 Ids 鑾峰彇
         /// </summary>
-        [Route("GetByCurveID@V1.0")]
+        [Route("GetByIds@V1.0")]
         [HttpGet]
-        public List<PumpCurveExMappingDto> GetByCurveID
-            (
-                [Required, Range(1, long.MaxValue, ErrorMessage = "CorpID 蹇呴』澶т簬0")]
-                long CorpID,
-                 [Required, Range(1, long.MaxValue, ErrorMessage = "CurveID 蹇呴』澶т簬0")]
-                long CurveID
-            )
+        public List<PumpCurveExMappingDto> GetByIds([FromQuery][Required] IdsInput input)
         {
-            var list = _service.GetByCurveID(CorpID, CurveID);
-            var vm_list = list?.Select(x => x.Adapt<Model.PumpCurveExMapping, PumpCurveExMappingDto>()).ToList();
-            return vm_list;
-        }
-
-        /// <summary>
-        ///  閫氳繃 CurveIds 鑾峰彇
-        /// </summary>
-        [Route("GetByCurveIds@V1.0")]
-        [HttpGet]
-        public List<PumpCurveExMappingDto> GetByCurveIds([FromQuery][Required] CurveIdsUnderCorpInput input)
-        {
-            var ids = LongListHelper.ToList(input.CurveIds);
-            var list = _service.GetByCurveIds(input.CorpID, ids);
-            var vm_list = list?.Select(x => x.Adapt<Model.PumpCurveExMapping, PumpCurveExMappingDto>()).ToList();
-            return vm_list;
+            var ids = LongListHelper.ToList(input.Ids);
+            var list = _service.GetByIds(ids);
+            var vmList = list.Select(x => new PumpCurveExMappingDto(x.Item1, x.Item2)).ToList();
+            return vmList;
         }
 
         /// <summary>
@@ -120,61 +52,22 @@
         /// </summary>
         [Route("GetWorkingByPumpID@V1.0")]
         [HttpGet]
-        public PumpCurveExMappingDto GetWorkingByPumpID
-            (
-                [Required, Range(1, long.MaxValue, ErrorMessage = "CorpID 蹇呴』澶т簬0")]
-                long CorpID,
-                 [Required, Range(1, long.MaxValue, ErrorMessage = "PumpID 蹇呴』澶т簬0")]
-                long PumpID
-            )
+        public PumpCurveExMappingDto GetWorkingByPumpID([FromQuery][Required] PumpIDInput input)
         {
-            var model = _service.GetWorkingByPumpID(CorpID, PumpID);
-            return model?.Adapt<Model.PumpCurveExMapping, PumpCurveExMappingDto>();
+            var model = _service.GetWorkingByPumpID(input.PumpID);
+            return model == null ? null : new PumpCurveExMappingDto(model.Item1, model.Item2);
         }
 
         /// <summary>
-        ///  閫氳繃 PumpID 鑾峰彇榛樿宸ヤ綔鏇茬嚎
+        ///  閫氳繃 PumpID 鑾峰彇榛樿鏇茬嚎
         /// </summary>
-        [Route("GetDefaultWorkingByPumpID@V1.0")]
+        [Route("GetDefaultByPumpID@V1.0")]
         [HttpGet]
-        public PumpCurveExMappingDto GetDefaultWorkingByPumpID
-            (
-                [Required, Range(1, long.MaxValue, ErrorMessage = "CorpID 蹇呴』澶т簬0")]
-                long CorpID,
-                 [Required, Range(1, long.MaxValue, ErrorMessage = "PumpID 蹇呴』澶т簬0")]
-                long PumpID
-            )
+        public PumpCurveExMappingDto GetDefaultByPumpID([FromQuery][Required] PumpIDInput input)
         {
-            var model = _service.GetDefaultWorkingByPumpID(CorpID, PumpID);
-            return model?.Adapt<Model.PumpCurveExMapping, PumpCurveExMappingDto>();
+            var model = _service.GetDefaultByPumpID(input.PumpID);
+            return model == null ? null : new PumpCurveExMappingDto(model.Item1, model.Item2);
         }
-
-        /// <summary>
-        ///  閫氳繃 PumpIds 鑾峰彇宸ヤ綔鏇茬嚎
-        /// </summary>
-        [Route("GetWorkingByPumpIds@V1.0")]
-        [HttpGet]
-        public List<PumpCurveExMappingDto> GetWorkingByPumpIds([FromQuery][Required] PumpIdsUnderCorpInput input)
-        {
-            var ids = LongListHelper.ToList(input.PumpIds);
-            var list = _service.GetWorkingByPumpIds(input.CorpID, ids);
-            var vm_list = list?.Select(x => x.Adapt<Model.PumpCurveExMapping, PumpCurveExMappingDto>()).ToList();
-            return vm_list;
-        }
-
-        /// <summary>
-        ///  閫氳繃 PumpIds 鑾峰彇榛樿宸ヤ綔鏇茬嚎
-        /// </summary>
-        [Route("GetDefaultWorkingByPumpIds@V1.0")]
-        [HttpGet]
-        public List<PumpCurveExMappingDto> GetDefaultWorkingByPumpIds([FromQuery][Required] PumpIdsUnderCorpInput input)
-        {
-            var ids = LongListHelper.ToList(input.PumpIds);
-            var list = _service.GetDefaultWorkingByPumpIds(input.CorpID, ids);
-            var vm_list = list?.Select(x => x.Adapt<Model.PumpCurveExMapping, PumpCurveExMappingDto>()).ToList();
-            return vm_list;
-        }
-
 
         #endregion
 
@@ -185,31 +78,64 @@
         /// </summary>
         [Route("Insert@V1.0")]
         [HttpPost]
-        public long Insert(AddPumpCurveExMappingInput input)
+        public long Insert([Required] AddPumpCurveExMappingInput input)
         {
-            if (input == null)
-                return default;
-            var model = input.Adapt<AddPumpCurveExMappingInput, Model.PumpCurveExMapping>();
-            var id = _service.Insert(model);
+            var curve = input.Adapt<AddPumpCurveExMappingInput, Model.PumpCurve>();
+            var mapping = input.Adapt<AddPumpCurveExMappingInput, Model.PumpCurveMapping>();
+            mapping.SortCode = new Service.PumpCurveMapping().GetMaxSortCodeByPumpID(input.PumpID) + 1;
+            var id = _service.Insert(curve, mapping);
             return id;
         }
 
+        #endregion
+
+        #region Update
+
         /// <summary>
-        /// 鎻掑叆澶氭潯
+        /// 鏇存柊涓�鏉�
         /// </summary>
-        [Route("Inserts@V1.0")]
-        [HttpPost]
-        public bool Inserts(List<AddPumpCurveExMappingInput> inputList)
+        [Route("Update@V1.0")]
+        [HttpPut]
+        public bool Update([Required] UpdatePumpCurveExMappingInput input)
         {
-            if (inputList == null || inputList.Count < 1)
-                return false;
-            var list = inputList.Select(x => x.Adapt<AddPumpCurveExMappingInput, Model.PumpCurveExMapping>()).ToList();
-            var bol = _service.Inserts(list);
+            var curveModel = new Service.PumpCurve().GetByID(input.CurveID);
+            if (curveModel == null)
+            {
+                throw YOops.Oh(eResultCode.Alert, ErrorCodes.D001, $"CurveID:{input.CurveID} 鏁版嵁涓嶅瓨鍦�");
+            }
+            var curveRhs = new Model.PumpCurve(curveModel);
+            var mappingModel = new Service.PumpCurveMapping().GetByID(input.MappingID);
+            if (mappingModel == null)
+            {
+                throw YOops.Oh(eResultCode.Alert, ErrorCodes.D001, $"MappingID:{input.MappingID} 鏁版嵁涓嶅瓨鍦�");
+            }
+            var mappingRhs = new Model.PumpCurveMapping(mappingModel);
+
+            input.Adapt(curveRhs);
+            input.Adapt(mappingRhs);
+
+            var bol = _service.Update(curveRhs, mappingRhs);
             return bol;
         }
 
         #endregion
 
+        #region Delete
+
+        /// <summary>
+        /// 閫氳繃 ID 鍒犻櫎锛堝鏋滄洸绾挎病鏈夊叾浠栧叧鑱斿叧绯伙紝鍒欏悓鏃跺垹闄ゆ洸绾匡級
+        /// </summary>
+        public bool DeleteByID(long ID)
+        {
+            var bol = new Service.PumpCurveMapping().DeleteExByID(ID, out string Msg);
+            if (!bol)
+            {
+                throw YOops.Oh(eResultCode.Alert, ErrorCodes.D999, Msg);
+            }
+            return bol;
+        }
+
+        #endregion
 
     }
 }
\ No newline at end of file

--
Gitblit v1.9.3