From bc715a35e44cba3fd6a44b3a7fc4fd1e10715825 Mon Sep 17 00:00:00 2001 From: lch <1627445470@qq.com> Date: Thu, 30 May 2024 21:39:49 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=20=E6=97=B6=E9=97=B4?= =?UTF-8?q?=E6=AE=B5=E5=88=A4=E6=96=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BasicConfig/BaseConfigController.cs | 81 +++++++++++++------ 1 file changed, 58 insertions(+), 23 deletions(-) diff --git a/WebStarter/Controllers/BasicConfig/BaseConfigController.cs b/WebStarter/Controllers/BasicConfig/BaseConfigController.cs index ec66407..f46c424 100644 --- a/WebStarter/Controllers/BasicConfig/BaseConfigController.cs +++ b/WebStarter/Controllers/BasicConfig/BaseConfigController.cs @@ -263,50 +263,85 @@ namespace WebStarter.Controllers.BasicConfig /// /// [HttpPost("AddStationElecPriceInfoList")] - public async Task> AddStationElecPriceInfoList([FromBody] List model) + public async Task> AddStationElecPriceInfoList([FromBody] List model) { if (null == model || model.Count == 0) { Result.Fail("参数不能为空"); } - - var queryByClauseAsync = - _elecPriceModelVersionDetailServices.QueryByClauseAsync(u => u.Version == model[0].Version); - if (queryByClauseAsync != null) - await _elecPriceModelVersionDetailServices.DeleteAsync(i => i.Version == model[0].Version); - if (TimeListIfContains(model)) + + List elecPriceModelVersionDetails = new List(); + foreach (var item in model) { - await _elecPriceModelVersionDetailServices.InsertAsync(model); - return Result.Success(true); + elecPriceModelVersionDetails.Add(new ElecPriceModelVersionDetail() + { + Version = item.Version, + StartHour = item.StartTime.Hour, + StartMinute = item.StartTime.Minute, + StartSecond = item.StartTime.Second, + EndHour = item.EndTime.Hour, + EndMinute = item.EndTime.Minute, + EndSecond = item.EndTime.Second, + Price = item.Price, + Type = item.Type + }); + } + + List modelFromDbs = await _elecPriceModelVersionDetailServices.QueryListByClauseAsync(u => u.Version == model[0].Version); + if (modelFromDbs != null) + { + modelFromDbs.AddRange(elecPriceModelVersionDetails); + if ( TimeListIfContains(modelFromDbs)) + { + await _elecPriceModelVersionDetailServices.InsertAsync(elecPriceModelVersionDetails); + return Result.Success(true); + } } return Result.Fail("时间区间重复请检查"); } - - + /// - /// 修改电价信息 + /// 更新电价信息 /// /// /// - [HttpPost("UpdateStationElecPriceInfo")] - public async Task> UpdateStationElecPriceInfo([FromBody] List model) + [HttpPost("UpdateStationElecPriceInfoList")] + public async Task> UpdateStationElecPriceInfoList([FromBody] List model) { if (null == model || model.Count == 0) { Result.Fail("参数不能为空"); } - - var queryByClauseAsync = - _elecPriceModelVersionDetailServices.QueryByClauseAsync(u => u.Version == model[0].Version); - if (queryByClauseAsync != null) + + List modelFromDbs = await _elecPriceModelVersionDetailServices.QueryListByClauseAsync(u => u.Version == model[0].Version); + if (modelFromDbs != null) + { await _elecPriceModelVersionDetailServices.DeleteAsync(i => i.Version == model[0].Version); - if (TimeListIfContains(model)) + } + + List elecPriceModelVersionDetails = new List(); + foreach (var item in model) { - await _elecPriceModelVersionDetailServices.InsertAsync(model); - return Result.Success(true); + elecPriceModelVersionDetails.Add(new ElecPriceModelVersionDetail() + { + Version = item.Version, + StartHour = item.StartTime.Hour, + StartMinute = item.StartTime.Minute, + StartSecond = item.StartTime.Second, + EndHour = item.EndTime.Hour, + EndMinute = item.EndTime.Minute, + EndSecond = item.EndTime.Second, + Price = item.Price, + Type = item.Type + }); } + if ( TimeListIfContains(elecPriceModelVersionDetails)) + { + await _elecPriceModelVersionDetailServices.InsertAsync(elecPriceModelVersionDetails); + return Result.Success(true); + } return Result.Fail("时间区间重复请检查"); } @@ -319,7 +354,7 @@ namespace WebStarter.Controllers.BasicConfig [ApiExplorerSettings(IgnoreApi = true)] public bool TimeListIfContains(List timePeriods) { - bool hasOverlap = false; + bool hasOverlap = true; for (int i = 0; i < timePeriods.Count; i++) { @@ -327,7 +362,7 @@ namespace WebStarter.Controllers.BasicConfig { if (timePeriods[i].Contains(timePeriods[j]) || timePeriods[j].Contains(timePeriods[i])) { - hasOverlap = true; + hasOverlap = false; return hasOverlap; } }